From ddaae71391c7362ef01e0eb0720201076558542e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 17 Mar 2022 13:11:06 +0800 Subject: [PATCH 01/68] [td-13039] support write in and retrieve from vnode. --- include/common/tdatablock.h | 4 +- source/client/inc/clientInt.h | 33 +++++--- source/client/src/clientImpl.c | 92 ++++++++++++++++------- source/client/test/clientTests.cpp | 27 ++++--- source/common/src/tdatablock.c | 30 ++++---- source/dnode/vnode/src/tsdb/tsdbRead.c | 7 +- source/libs/executor/src/dataDispatcher.c | 60 +++++++++------ source/libs/executor/src/executorimpl.c | 8 +- source/libs/executor/src/tsort.c | 6 +- source/libs/parser/src/parInsert.c | 8 +- source/libs/qworker/src/qworker.c | 9 +-- 11 files changed, 180 insertions(+), 104 deletions(-) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 7e60013aa1..e3ff81be3a 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -106,7 +106,7 @@ int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock); int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf); size_t blockDataGetSize(const SSDataBlock* pBlock); -size_t blockDataGetRowSize(const SSDataBlock* pBlock); +size_t blockDataGetRowSize(SSDataBlock* pBlock); double blockDataGetSerialRowSize(const SSDataBlock* pBlock); size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock); @@ -117,7 +117,7 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); -void blockDataClearup(SSDataBlock* pDataBlock); +void blockDataCleanup(SSDataBlock* pDataBlock); SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock); size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize); void* blockDataDestroy(SSDataBlock* pBlock); diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 321e8ab77b..f5a370cf53 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -141,18 +141,27 @@ typedef struct STscObj { SAppInstInfo* pAppInfo; } STscObj; +typedef struct SResultColumn { + union { + char* nullbitmap; // bitmap, one bit for each item in the list + int32_t* offset; + }; + char* pData; +} SResultColumn; + typedef struct SReqResultInfo { - const char* pRspMsg; - const char* pData; - TAOS_FIELD* fields; - uint32_t numOfCols; - int32_t* length; - TAOS_ROW row; - char** pCol; - uint32_t numOfRows; - uint64_t totalRows; - uint32_t current; - bool completed; + const char* pRspMsg; + const char* pData; + TAOS_FIELD* fields; + uint32_t numOfCols; + int32_t* length; + TAOS_ROW row; + SResultColumn* pCol; + uint32_t numOfRows; + uint64_t totalRows; + uint32_t current; + bool completed; + int32_t payloadLen; } SReqResultInfo; typedef struct SShowReqInfo { @@ -224,7 +233,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, void* doFetchRow(SRequestObj* pRequest); -void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows); +int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows); int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 646b443fb7..96761facd0 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -14,7 +14,7 @@ static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet); static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest); static void destroySendMsgInfo(SMsgSendInfo* pMsgBody); -static void setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp); +static int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp); static bool stringLengthCheck(const char* str, size_t maxsize) { if (str == NULL) { @@ -483,13 +483,16 @@ void* doFetchRow(SRequestObj* pRequest) { } SReqResultInfo* pResInfo = &pRequest->body.resInfo; - int32_t code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData); - if (code != TSDB_CODE_SUCCESS) { - pRequest->code = code; + pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData); + if (pRequest->code != TSDB_CODE_SUCCESS) { + return NULL; + } + + pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData); + if (pRequest->code != TSDB_CODE_SUCCESS) { return NULL; } - setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData); tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64, pRequest->self, pResInfo->numOfRows, pResInfo->totalRows, pResInfo->completed, pRequest->requestId); @@ -556,10 +559,23 @@ void* doFetchRow(SRequestObj* pRequest) { _return: for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { - pResultInfo->row[i] = pResultInfo->pCol[i] + pResultInfo->fields[i].bytes * pResultInfo->current; + SResultColumn* pCol = &pResultInfo->pCol[i]; + if (IS_VAR_DATA_TYPE(pResultInfo->fields[i].type)) { - pResultInfo->length[i] = varDataLen(pResultInfo->row[i]); - pResultInfo->row[i] = varDataVal(pResultInfo->row[i]); + if (pCol->offset[pResultInfo->current] != -1) { + char* pStart = pResultInfo->pCol[i].offset[pResultInfo->current] + pResultInfo->pCol[i].pData; + + pResultInfo->length[i] = varDataLen(pStart); + pResultInfo->row[i] = varDataVal(pStart); + } else { + pResultInfo->row[i] = NULL; + } + } else { + if (!colDataIsNull_f(pCol->nullbitmap, pResultInfo->current)) { + pResultInfo->row[i] = pResultInfo->pCol[i].pData + pResultInfo->fields[i].bytes * pResultInfo->current; + } else { + pResultInfo->row[i] = NULL; + } } } @@ -567,30 +583,52 @@ _return: return pResultInfo->row; } -static void doPrepareResPtr(SReqResultInfo* pResInfo) { +static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { if (pResInfo->row == NULL) { - pResInfo->row = calloc(pResInfo->numOfCols, POINTER_BYTES); - pResInfo->pCol = calloc(pResInfo->numOfCols, POINTER_BYTES); + pResInfo->row = calloc(pResInfo->numOfCols, POINTER_BYTES); + pResInfo->pCol = calloc(pResInfo->numOfCols, sizeof(SResultColumn)); pResInfo->length = calloc(pResInfo->numOfCols, sizeof(int32_t)); } + + if (pResInfo->row == NULL || pResInfo->pCol == NULL || pResInfo->length == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } else { + return TSDB_CODE_SUCCESS; + } } -void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) { +int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) { assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL); if (numOfRows == 0) { - return; + return TSDB_CODE_SUCCESS; } - // todo check for the failure of malloc - doPrepareResPtr(pResultInfo); + int32_t code = doPrepareResPtr(pResultInfo); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - int32_t offset = 0; + int32_t* colLength = (int32_t*)pResultInfo->pData; + char* pStart = ((char*)pResultInfo->pData) + sizeof(int32_t) * numOfCols; for (int32_t i = 0; i < numOfCols; ++i) { + colLength[i] = htonl(colLength[i]); + + if (IS_VAR_DATA_TYPE(pResultInfo->fields[i].type)) { + pResultInfo->pCol[i].offset = (int32_t*)pStart; + pStart += numOfRows * sizeof(int32_t); + } else { + pResultInfo->pCol[i].nullbitmap = pStart; + pStart += BitmapLen(pResultInfo->numOfRows); + } + + pResultInfo->pCol[i].pData = pStart; pResultInfo->length[i] = pResultInfo->fields[i].bytes; - pResultInfo->row[i] = (char*)(pResultInfo->pData + offset * pResultInfo->numOfRows); - pResultInfo->pCol[i] = pResultInfo->row[i]; - offset += pResultInfo->fields[i].bytes; + pResultInfo->row[i] = pResultInfo->pCol[i].pData; + + pStart += colLength[i]; } + + return TSDB_CODE_SUCCESS; } char* getDbOfConnection(STscObj* pObj) { @@ -612,15 +650,17 @@ void setConnectionDB(STscObj* pTscObj, const char* db) { pthread_mutex_unlock(&pTscObj->mutex); } -void setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) { +int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) { assert(pResultInfo != NULL && pRsp != NULL); - pResultInfo->pRspMsg = (const char*)pRsp; - pResultInfo->pData = (void*)pRsp->data; - pResultInfo->numOfRows = htonl(pRsp->numOfRows); - pResultInfo->current = 0; - pResultInfo->completed = (pRsp->completed == 1); + pResultInfo->pRspMsg = (const char*)pRsp; + pResultInfo->pData = (void*)pRsp->data; + pResultInfo->numOfRows = htonl(pRsp->numOfRows); + pResultInfo->current = 0; + pResultInfo->completed = (pRsp->completed == 1); + pResultInfo->payloadLen = htonl(pRsp->compLen); + // TODO handle the compressed case pResultInfo->totalRows += pResultInfo->numOfRows; - setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows); + return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows); } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 1a155beb90..7d03040efb 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -52,7 +52,7 @@ TEST(testCase, driverInit_Test) { // taosInitGlobalCfg(); // taos_init(); } - +#if 0 TEST(testCase, connect_Test) { // taos_options(TSDB_OPTION_CONFIGDIR, "/home/ubuntu/first/cfg"); @@ -648,6 +648,7 @@ TEST(testCase, projection_query_stables) { taos_free_result(pRes); taos_close(pConn); } +#endif TEST(testCase, agg_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -656,18 +657,20 @@ TEST(testCase, agg_query_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "create table tx using st1 tags(111111111111111)"); - if (taos_errno(pRes) != 0) { - printf("failed to create table, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); + pRes = taos_query(pConn, "select * from tu"); - pRes = taos_query(pConn, "select count(*) from t_x_19"); - if (taos_errno(pRes) != 0) { - printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - ASSERT_TRUE(false); - } +// pRes = taos_query(pConn, "create table tx using st1 tags(111111111111111)"); +// if (taos_errno(pRes) != 0) { +// printf("failed to create table, reason:%s\n", taos_errstr(pRes)); +// } +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "select count(*) from tu"); +// if (taos_errno(pRes) != 0) { +// printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } TAOS_ROW pRow = NULL; TAOS_FIELD* pFields = taos_fetch_fields(pRes); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 7e4f1d9025..93fe314c10 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -430,11 +430,11 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3 /** * - * +------------------+---------------+--------------------+ - * |the number of rows| column length | column #1 | - * | (4 bytes) | (4 bytes) |--------------------+ - * | | | null bitmap| values| - * +------------------+---------------+--------------------+ + * +------------------+---------------------------------------------+ + * |the number of rows| column #1 | + * | (4 bytes) |------------+-----------------------+--------+ + * | | null bitmap| column length(4bytes) | values | + * +------------------+------------+-----------------------+--------+ * @param buf * @param pBlock * @return @@ -515,17 +515,21 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) { return TSDB_CODE_SUCCESS; } -size_t blockDataGetRowSize(const SSDataBlock* pBlock) { +size_t blockDataGetRowSize(SSDataBlock* pBlock) { ASSERT(pBlock != NULL); - size_t rowSize = 0; + if (pBlock->info.rowSize == 0) { + size_t rowSize = 0; - size_t numOfCols = pBlock->info.numOfCols; - for(int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); - rowSize += pColInfo->info.bytes; + size_t numOfCols = pBlock->info.numOfCols; + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); + rowSize += pColInfo->info.bytes; + } + + pBlock->info.rowSize = rowSize; } - return rowSize; + return pBlock->info.rowSize; } /** @@ -1059,7 +1063,7 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF // destroyTupleIndex(index); } -void blockDataClearup(SSDataBlock* pDataBlock) { +void blockDataCleanup(SSDataBlock* pDataBlock) { pDataBlock->info.rows = 0; if (pDataBlock->info.hasVarCol) { diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 97c52f44eb..572b572167 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -404,7 +404,12 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, colInfo.info = pCond->colList[i]; colInfo.pData = calloc(1, EXTRA_BYTES + pReadHandle->outputCapacity * pCond->colList[i].bytes); - if (colInfo.pData == NULL) { + + if (!IS_VAR_DATA_TYPE(colInfo.info.type)) { + colInfo.nullbitmap = calloc(1, BitmapLen(pReadHandle->outputCapacity)); + } + + if (colInfo.pData == NULL || (colInfo.nullbitmap == NULL && (!IS_VAR_DATA_TYPE(colInfo.info.type)))) { goto _end; } diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index a0ee048d82..e185c5444f 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -15,11 +15,12 @@ #include "dataSinkInt.h" #include "dataSinkMgt.h" +#include "executorimpl.h" #include "planner.h" #include "tcompression.h" #include "tglobal.h" #include "tqueue.h" -#include "executorimpl.h" +#include "tdatablock.h" typedef struct SDataDispatchBuf { int32_t useSize; @@ -64,29 +65,47 @@ static bool needCompress(const SSDataBlock* pData, const SDataBlockDescNode* pSc } static int32_t compressColData(SColumnInfoData *pColRes, int32_t numOfRows, char *data, int8_t compressed) { - int32_t colSize = pColRes->info.bytes * numOfRows; + int32_t colSize = colDataGetLength(pColRes, numOfRows); return (*(tDataTypes[pColRes->info.type].compFunc))( pColRes->pData, colSize, numOfRows, data, colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0); } -static void copyData(const SInputData* pInput, const SDataBlockDescNode* pSchema, char* data, int8_t compressed, int32_t *compLen) { +static void copyData(const SInputData* pInput, const SDataBlockDescNode* pSchema, char* data, int8_t compressed, int32_t * dataLen) { int32_t numOfCols = LIST_LENGTH(pSchema->pSlots); - int32_t *compSizes = (int32_t*)data; - if (compressed) { - data += numOfCols * sizeof(int32_t); - } + int32_t * colSizes = (int32_t*)data; + data += numOfCols * sizeof(int32_t); + *dataLen = (numOfCols * sizeof(int32_t)); + + int32_t numOfRows = pInput->pData->info.rows; for (int32_t col = 0; col < numOfCols; ++col) { SColumnInfoData* pColRes = taosArrayGet(pInput->pData->pDataBlock, col); - if (compressed) { - compSizes[col] = compressColData(pColRes, pInput->pData->info.rows, data, compressed); - data += compSizes[col]; - *compLen += compSizes[col]; - compSizes[col] = htonl(compSizes[col]); + + // copy the null bitmap + if (IS_VAR_DATA_TYPE(pColRes->info.type)) { + size_t metaSize = numOfRows * sizeof(int32_t); + memcpy(data, pColRes->varmeta.offset, metaSize); + data += metaSize; + (*dataLen) += metaSize; } else { - memmove(data, pColRes->pData, pColRes->info.bytes * pInput->pData->info.rows); - data += pColRes->info.bytes * pInput->pData->info.rows; + int32_t len = BitmapLen(numOfRows); + memcpy(data, pColRes->nullbitmap, len); + data += len; + (*dataLen) += len; } + + if (compressed) { + colSizes[col] = compressColData(pColRes, numOfRows, data, compressed); + data += colSizes[col]; + (*dataLen) += colSizes[col]; + } else { + colSizes[col] = colDataGetLength(pColRes, numOfRows); + (*dataLen) += colSizes[col]; + memmove(data, pColRes->pData, colSizes[col]); + data += colSizes[col]; + } + + colSizes[col] = htonl(colSizes[col]); } } @@ -95,16 +114,14 @@ static void copyData(const SInputData* pInput, const SDataBlockDescNode* pSchema static void toDataCacheEntry(const SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) { SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData; pEntry->compressed = (int8_t)needCompress(pInput->pData, pHandle->pSchema); - pEntry->numOfRows = pInput->pData->info.rows; - pEntry->dataLen = 0; + pEntry->numOfRows = pInput->pData->info.rows; + pEntry->dataLen = 0; pBuf->useSize = sizeof(SRetrieveTableRsp); copyData(pInput, pHandle->pSchema, pEntry->data, pEntry->compressed, &pEntry->dataLen); - if (0 == pEntry->compressed) { - pEntry->dataLen = pHandle->pSchema->resultRowSize * pInput->pData->info.rows; - } - pBuf->useSize += pEntry->dataLen; - // todo completed + + pEntry->dataLen = pEntry->dataLen; + pBuf->useSize += pEntry->dataLen; } static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, SDataDispatchBuf* pBuf) { @@ -169,6 +186,7 @@ static void getDataLength(SDataSinkHandle* pHandle, int32_t* pLen, bool* pQueryE *pLen = 0; return; } + SDataDispatchBuf* pBuf = NULL; taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf); memcpy(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf)); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 947fb08ff9..1127afe47b 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -3986,7 +3986,7 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf *pBuf, SGroupResInfo* pGroupResI static void toSDatablock(SGroupResInfo *pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset) { assert(pGroupResInfo->currentGroup <= pGroupResInfo->totalGroup); - blockDataClearup(pBlock); + blockDataCleanup(pBlock); if (!hasRemainDataInCurrentGroup(pGroupResInfo)) { return; } @@ -5794,7 +5794,7 @@ static void appendOneRowToDataBlock(SSDataBlock *pBlock, STupleHandle* pTupleHan } static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, bool hasVarCol, int32_t capacity) { - blockDataClearup(pDataBlock); + blockDataCleanup(pDataBlock); while(1) { STupleHandle* pTupleHandle = tsortNextTuple(pHandle); @@ -5950,7 +5950,7 @@ static SSDataBlock* doMerge(SOperatorInfo* pOperator) { while(1) { - blockDataClearup(pDataBlock); + blockDataCleanup(pDataBlock); while (1) { STupleHandle* pTupleHandle = tsortNextTuple(pHandle); if (pTupleHandle == NULL) { @@ -6366,7 +6366,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) SOptrBasicInfo *pInfo = &pProjectInfo->binfo; SSDataBlock* pRes = pInfo->pRes; - blockDataClearup(pRes); + blockDataCleanup(pRes); if (pProjectInfo->existDataBlock) { // TODO refactor // STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 08bab762be..d424599758 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -182,7 +182,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { start = stop + 1; } - blockDataClearup(pDataBlock); + blockDataCleanup(pDataBlock); SSDataBlock* pBlock = createOneDataBlock(pDataBlock); int32_t code = doAddNewExternalMemSource(pHandle->pBuf, pHandle->pOrderedSource, pBlock, &pHandle->sourceId); @@ -312,7 +312,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa } static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SMsortComparParam* cmpParam, int32_t capacity) { - blockDataClearup(pHandle->pDataBlock); + blockDataCleanup(pHandle->pDataBlock); while(1) { if (cmpParam->numOfSources == pHandle->numOfCompletedSources) { @@ -478,7 +478,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { setBufPageDirty(pPage, true); releaseBufPage(pHandle->pBuf, pPage); - blockDataClearup(pDataBlock); + blockDataCleanup(pDataBlock); } tMergeTreeDestroy(pHandle->pMergeTree); diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 43cc308483..5ff6e5f709 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -453,7 +453,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return func(&tmpVal, pSchema->bytes, param); } - return func(getNullValue(pSchema->type), 0, param); + return func(NULL, 0, param); } switch (pSchema->type) { @@ -628,7 +628,11 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p varDataSetLen(rowEnd, output); tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx); } else { - tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, true, pa->toffset, pa->colIdx); + if (value == NULL) { // it is a null data + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, true, pa->toffset, pa->colIdx); + } else { + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, true, pa->toffset, pa->colIdx); + } } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 42890ab38a..5f7d0ff827 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -603,28 +603,21 @@ int32_t qwGetResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void } QW_TASK_DLOG("no data in sink and query end, phase:%d", ctx->phase); - QW_ERR_RET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_SUCCEED)); - QW_ERR_RET(qwMallocFetchRsp(len, &rsp)); + *rspMsg = rsp; *dataLen = 0; - return TSDB_CODE_SUCCESS; } pOutput->bufStatus = DS_BUF_EMPTY; - QW_TASK_DLOG("no res data in sink, need response later, queryEnd:%d", queryEnd); - return TSDB_CODE_SUCCESS; } - // Got data from sink - *dataLen = len; - QW_TASK_DLOG("task got data in sink, dataLength:%d", len); QW_ERR_RET(qwMallocFetchRsp(len, &rsp)); From 554f12db50bf2252aa5a59b20210895a05ced4a9 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 17 Mar 2022 13:42:49 +0800 Subject: [PATCH 02/68] [td-13039] fix bugs. --- source/common/src/tdatablock.c | 2 +- source/libs/executor/src/dataDispatcher.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 9f03e179e3..e26f3ca128 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -570,7 +570,7 @@ double blockDataGetSerialRowSize(const SSDataBlock* pBlock) { if (IS_VAR_DATA_TYPE(pColInfo->info.type)) { rowSize += sizeof(int32_t); } else { - rowSize += 1/8.0; + rowSize += 1/8.0; // one bit for each record } } diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index e185c5444f..64b54ab135 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -109,8 +109,13 @@ static void copyData(const SInputData* pInput, const SDataBlockDescNode* pSchema } } -// data format with compress: SDataCacheEntry | cols_data_offset | col1_data col2_data ... | numOfTables | STableIdInfo STableIdInfo ... -// data format: SDataCacheEntry | col1_data col2_data ... | numOfTables | STableIdInfo STableIdInfo ... +// data format: +// +----------------+--------------------------------------+-------------+-----------+-------------+-----------+ +// |SDataCacheEntry | column#1 length, column#2 length ... | col1 bitmap | col1 data | col2 bitmap | col2 data | .... +// | | sizeof(int32_t) * numOfCols | actual size | | actual size | | +// +----------------+--------------------------------------+-------------+-----------+-------------+-----------+ +// The length of bitmap is decided by number of rows of this data block, and the length of each column data is +// recorded in the first segment, next to the struct header static void toDataCacheEntry(const SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) { SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData; pEntry->compressed = (int8_t)needCompress(pInput->pData, pHandle->pSchema); @@ -132,8 +137,11 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, return false; } - // struct size + data payload + length for each column - pBuf->allocSize = sizeof(SRetrieveTableRsp) + pDispatcher->pSchema->resultRowSize * pInput->pData->info.rows + pInput->pData->info.numOfCols * sizeof(int32_t); + // NOTE: there are four bytes of an integer more than the required buffer space. + // struct size + data payload + length for each column + bitmap length + pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockDataGetSerialMetaSize(pInput->pData) + + __ceill(blockDataGetSerialRowSize(pInput->pData) * pInput->pData->info.rows); + pBuf->pData = malloc(pBuf->allocSize); if (pBuf->pData == NULL) { qError("SinkNode failed to malloc memory, size:%d, code:%d", pBuf->allocSize, TAOS_SYSTEM_ERROR(errno)); From c503c00ff8b6f5efee3cd5a43eb231226700ee2e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 17 Mar 2022 13:52:35 +0800 Subject: [PATCH 03/68] [td-13039] fix compiler error. --- source/libs/executor/src/dataDispatcher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 64b54ab135..0e1fa5267d 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -140,7 +140,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, // NOTE: there are four bytes of an integer more than the required buffer space. // struct size + data payload + length for each column + bitmap length pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockDataGetSerialMetaSize(pInput->pData) + - __ceill(blockDataGetSerialRowSize(pInput->pData) * pInput->pData->info.rows); + ceil(blockDataGetSerialRowSize(pInput->pData) * pInput->pData->info.rows); pBuf->pData = malloc(pBuf->allocSize); if (pBuf->pData == NULL) { From 51a6e6355ff72724227090844c0b11606e409bcf Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 17 Mar 2022 14:33:31 +0800 Subject: [PATCH 04/68] [td-13039] refactor. --- include/common/ttypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 5aa22bdcad..43c1d082f2 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -46,7 +46,7 @@ typedef struct { #define varDataCopy(dst, v) memcpy((dst), (void *)(v), varDataTLen(v)) #define varDataLenByData(v) (*(VarDataLenT *)(((char *)(v)) - VARSTR_HEADER_SIZE)) #define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT)(_len)) -#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR)) +#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR)) #define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0])) #define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v)) From cf1e4507f3f5904b6c69bf07f980a1575a62b9f4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 19 Mar 2022 23:12:58 +0800 Subject: [PATCH 05/68] [td-13039] refactor. --- source/libs/function/src/builtins.c | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index edb0acf075..9f0a03b647 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -61,6 +61,76 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .processFunc = maxFunction, .finalizeFunc = functionFinalizer }, + { + .name = "stddev", + .type = FUNCTION_TYPE_STDDEV, + .classification = FUNC_MGT_AGG_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalizer + }, + { + .name = "percentile", + .type = FUNCTION_TYPE_PERCENTILE, + .classification = FUNC_MGT_AGG_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalizer + }, + { + .name = "apercentile", + .type = FUNCTION_TYPE_APERCENTILE, + .classification = FUNC_MGT_AGG_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalizer + }, + { + .name = "top", + .type = FUNCTION_TYPE_TOP, + .classification = FUNC_MGT_AGG_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalizer + }, + { + .name = "bottom", + .type = FUNCTION_TYPE_BOTTOM, + .classification = FUNC_MGT_AGG_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalizer + }, + { + .name = "spread", + .type = FUNCTION_TYPE_SPREAD, + .classification = FUNC_MGT_AGG_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalizer + }, + { + .name = "last_row", + .type = FUNCTION_TYPE_LAST_ROW, + .classification = FUNC_MGT_AGG_FUNC, + .checkFunc = stubCheckAndGetResultType, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalizer + }, { .name = "concat", .type = FUNCTION_TYPE_CONCAT, From 84818987b3873a697dee8f959f03066e4ec6f77d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 21 Mar 2022 15:25:13 +0800 Subject: [PATCH 06/68] [td-13039] fix bug in show tables; --- include/libs/executor/executor.h | 6 ++- source/libs/executor/src/executor.c | 19 ++++--- source/libs/function/inc/builtinsimpl.h | 6 ++- source/libs/function/src/builtins.c | 24 ++++----- source/libs/function/src/builtinsimpl.c | 71 ++++++++++++++++++++++++- 5 files changed, 103 insertions(+), 23 deletions(-) diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index d4af51fc21..6091456780 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -32,6 +32,9 @@ typedef struct SReadHandle { void* meta; } SReadHandle; +#define STREAM_DATA_TYPE_SUBMITBLK 0x1u +#define STREAM_DATA_TYPE_SSDATABLK 0x2u + /** * Create the exec task for streaming mode * @param pMsg @@ -44,9 +47,10 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void *msg, void* streamReadHandle); * Set the input data block for the stream scan. * @param tinfo * @param input + * @param type * @return */ -int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input); +int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type); /** * Update the table id list, add or remove. diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index a8602b7c77..3720e1c179 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -18,7 +18,7 @@ #include "planner.h" #include "tq.h" -static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, char* id) { +static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, int32_t type, char* id) { ASSERT(pOperator != NULL); if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { if (pOperator->numOfDownstream == 0) { @@ -31,18 +31,23 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, char* id) return TSDB_CODE_QRY_APP_ERROR; } - return doSetStreamBlock(pOperator->pDownstream[0], input, id); + // TODO handle the join case + return doSetStreamBlock(pOperator->pDownstream[0], input, type, id); } else { SStreamBlockScanInfo* pInfo = pOperator->info; - if (tqReadHandleSetMsg(pInfo->readerHandle, input, 0) < 0) { - qError("submit msg messed up when initing stream block, %s" PRIx64, id); - return TSDB_CODE_QRY_APP_ERROR; + if (type == STREAM_DATA_TYPE_SUBMITBLK) { + if (tqReadHandleSetMsg(pInfo->readerHandle, input, 0) < 0) { + qError("submit msg messed up when initing stream block, %s" PRIx64, id); + return TSDB_CODE_QRY_APP_ERROR; + } + } else { // TODO + } return TSDB_CODE_SUCCESS; } } -int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input) { +int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type) { if (tinfo == NULL) { return TSDB_CODE_QRY_APP_ERROR; } @@ -53,7 +58,7 @@ int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; - int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void*)input, GET_TASKID(pTaskInfo)); + int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void*)input, type, GET_TASKID(pTaskInfo)); if (code != TSDB_CODE_SUCCESS) { qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo)); } else { diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 7ba7d7bdcc..e67215dfa5 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -23,7 +23,7 @@ extern "C" { #include "function.h" bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -void functionFinalizer(SqlFunctionCtx *pCtx); +void functionFinalize(SqlFunctionCtx *pCtx); bool getCountFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); void countFunction(SqlFunctionCtx *pCtx); @@ -37,6 +37,10 @@ bool getMinmaxFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); void minFunction(SqlFunctionCtx* pCtx); void maxFunction(SqlFunctionCtx *pCtx); +bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); +void stddevFunction(SqlFunctionCtx* pCtx); +void stddevFinalize(SqlFunctionCtx* pCtx); + #ifdef __cplusplus } #endif diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 9f0a03b647..15f8ca2d10 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -29,7 +29,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getCountFuncEnv, .initFunc = functionSetup, .processFunc = countFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "sum", @@ -39,7 +39,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getSumFuncEnv, .initFunc = functionSetup, .processFunc = sumFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "min", @@ -49,7 +49,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getMinmaxFuncEnv, .initFunc = minFunctionSetup, .processFunc = minFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "max", @@ -59,17 +59,17 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "stddev", .type = FUNCTION_TYPE_STDDEV, .classification = FUNC_MGT_AGG_FUNC, .checkFunc = stubCheckAndGetResultType, - .getEnvFunc = getMinmaxFuncEnv, + .getEnvFunc = getStddevFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "percentile", @@ -79,7 +79,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "apercentile", @@ -89,7 +89,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "top", @@ -99,7 +99,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "bottom", @@ -109,7 +109,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "spread", @@ -119,7 +119,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "last_row", @@ -129,7 +129,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, - .finalizeFunc = functionFinalizer + .finalizeFunc = functionFinalize }, { .name = "concat", diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index f0f00434f0..fd3c022739 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -50,7 +50,7 @@ bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { static void doFinalizer(SResultRowEntryInfo* pResInfo) { cleanupResultRowEntry(pResInfo); } -void functionFinalizer(SqlFunctionCtx *pCtx) { +void functionFinalize(SqlFunctionCtx *pCtx) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); doFinalizer(pResInfo); } @@ -441,4 +441,71 @@ void minFunction(SqlFunctionCtx *pCtx) { void maxFunction(SqlFunctionCtx *pCtx) { int32_t numOfElems = doMinMaxHelper(pCtx, 0); SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); -} \ No newline at end of file +} + +typedef struct STopBotRes { + int32_t num; +} STopBotRes; + +bool getTopBotFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { + SColumnNode* pColNode = (SColumnNode*) nodesListGetNode(pFunc->pParameterList, 0); + int32_t bytes = pColNode->node.resType.bytes; + SValueNode* pkNode = (SValueNode*) nodesListGetNode(pFunc->pParameterList, 1); + return true; +} + +typedef struct SStddevRes { + int64_t count; + union {double quadraticDSum; int64_t quadraticISum;}; + union {double dsum; int64_t isum;}; +} SStddevRes; + +bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { + pEnv->calcMemSize = sizeof(SStddevRes); + return true; +} + +void stddevFunction(SqlFunctionCtx* pCtx) { + int32_t numOfElem = 0; + + // Only the pre-computing information loaded and actual data does not loaded + SInputColumnInfoData* pInput = &pCtx->input; + SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0]; + int32_t type = pInput->pData[0]->info.type; + + SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + +// } else { // computing based on the true data block + SColumnInfoData* pCol = pInput->pData[0]; + + int32_t start = pInput->startRowIndex; + int32_t numOfRows = pInput->numOfRows; + + switch(type) { + case TSDB_DATA_TYPE_INT: { + int32_t* plist = (int32_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + pStddevRes->count += 1; + pStddevRes->isum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; + } + } + break; + } + + // data in the check operation are all null, not output + SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1); +} + +void stddevFinalize(SqlFunctionCtx* pCtx) { + functionFinalize(pCtx); + + SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + double res = pStddevRes->quadraticISum/pStddevRes->count - (pStddevRes->isum / pStddevRes->count) * (pStddevRes->isum / pStddevRes->count); +} + + From 0c9e64f0d2002da2404e54d62996fd317ee6246a Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 22 Mar 2022 13:18:29 +0800 Subject: [PATCH 07/68] sync refactor --- source/libs/sync/test/CMakeLists.txt | 14 +++ source/libs/sync/test/syncElectTest3.cpp | 138 +++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 source/libs/sync/test/syncElectTest3.cpp diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index f02ba29218..653763b96b 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -29,6 +29,7 @@ add_executable(syncPingTimerTest2 "") add_executable(syncPingSelfTest "") add_executable(syncElectTest "") add_executable(syncElectTest2 "") +add_executable(syncElectTest3 "") add_executable(syncEncodeTest "") add_executable(syncWriteTest "") add_executable(syncReplicateTest "") @@ -159,6 +160,10 @@ target_sources(syncElectTest2 PRIVATE "syncElectTest2.cpp" ) +target_sources(syncElectTest3 + PRIVATE + "syncElectTest3.cpp" +) target_sources(syncEncodeTest PRIVATE "syncEncodeTest.cpp" @@ -332,6 +337,11 @@ target_include_directories(syncElectTest2 "${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncElectTest3 + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_include_directories(syncEncodeTest PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync" @@ -478,6 +488,10 @@ target_link_libraries(syncElectTest2 sync gtest_main ) +target_link_libraries(syncElectTest3 + sync + gtest_main +) target_link_libraries(syncEncodeTest sync gtest_main diff --git a/source/libs/sync/test/syncElectTest3.cpp b/source/libs/sync/test/syncElectTest3.cpp new file mode 100644 index 0000000000..45c5488c60 --- /dev/null +++ b/source/libs/sync/test/syncElectTest3.cpp @@ -0,0 +1,138 @@ +#include +#include +#include "syncEnv.h" +#include "syncIO.h" +#include "syncInt.h" +#include "syncRaftLog.h" +#include "syncRaftStore.h" +#include "syncUtil.h" +#include "tref.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 3; +int32_t myIndex = 0; + +SRaftId ids[TSDB_MAX_REPLICA]; +SSyncInfo syncInfo; +SSyncFSM* pFsm; +SWal* pWal; + +int64_t syncNodeInit() { + syncInfo.vgId = 1234; + syncInfo.rpcClient = gSyncIO->clientRpc; + syncInfo.FpSendMsg = syncIOSendMsg; + syncInfo.queue = gSyncIO->pMsgQ; + syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.pFsm = pFsm; + snprintf(syncInfo.path, sizeof(syncInfo.path), "./elect3_test_%d", myIndex); + + int code = walInit(); + assert(code == 0); + SWalCfg walCfg; + memset(&walCfg, 0, sizeof(SWalCfg)); + walCfg.vgId = syncInfo.vgId; + walCfg.fsyncPeriod = 1000; + walCfg.retentionPeriod = 1000; + walCfg.rollPeriod = 1000; + walCfg.retentionSize = 1000; + walCfg.segSize = 1000; + walCfg.level = TAOS_WAL_FSYNC; + + char tmpdir[128]; + snprintf(tmpdir, sizeof(tmpdir), "./elect3_test_wal_%d", myIndex); + pWal = walOpen(tmpdir, &walCfg); + assert(pWal != NULL); + + syncInfo.pWal = pWal; + + SSyncCfg* pCfg = &syncInfo.syncCfg; + pCfg->myIndex = myIndex; + pCfg->replicaNum = replicaNum; + + for (int i = 0; i < replicaNum; ++i) { + pCfg->nodeInfo[i].nodePort = ports[i]; + snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1"); + // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); + } + + int64_t rid = syncStart(&syncInfo); + assert(rid > 0); + + SSyncNode* pSyncNode = (SSyncNode*)syncNodeAcquire(rid); + assert(pSyncNode != NULL); + + pSyncNode->hbBaseLine = 500; + pSyncNode->electBaseLine = 1500; + + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; + gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; + gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; + gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; + gSyncIO->pSyncNode = pSyncNode; + + syncNodeRelease(pSyncNode); + + return rid; +} + +void initRaftId(SSyncNode* pSyncNode) { + for (int i = 0; i < replicaNum; ++i) { + ids[i] = pSyncNode->replicasId[i]; + char* s = syncUtilRaftId2Str(&ids[i]); + printf("raftId[%d] : %s\n", i, s); + free(s); + } +} + +int main(int argc, char** argv) { + // taosInitLog((char *)"syncTest.log", 100000, 10); + tsAsyncLog = 0; + sDebugFlag = 143 + 64; + + myIndex = 0; + if (argc >= 2) { + myIndex = atoi(argv[1]); + } + + int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); + assert(ret == 0); + + ret = syncInit(); + assert(ret == 0); + + int64_t rid = syncNodeInit(); + assert(rid > 0); + + SSyncNode* pSyncNode = (SSyncNode*)syncNodeAcquire(rid); + assert(pSyncNode != NULL); + + syncNodePrint2((char*)"", pSyncNode); + initRaftId(pSyncNode); + + //--------------------------- + while (1) { + sTrace( + "elect sleep, state: %d, %s, term:%lu electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, electTimerMS:%d", + pSyncNode->state, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, + pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser, pSyncNode->electTimerMS); + taosMsleep(1000); + } + + syncNodeRelease(pSyncNode); + + return 0; +} From 0081c145aedc65b2a576d0acc3f36f0e1fd25e7a Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Tue, 22 Mar 2022 13:57:50 +0800 Subject: [PATCH 08/68] rename vnodes to vnode --- source/dnode/mgmt/vnode/src/vmInt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mgmt/vnode/src/vmInt.c b/source/dnode/mgmt/vnode/src/vmInt.c index 1c6c7d089e..c6122c0501 100644 --- a/source/dnode/mgmt/vnode/src/vmInt.c +++ b/source/dnode/mgmt/vnode/src/vmInt.c @@ -342,7 +342,7 @@ void vmGetMgmtFp(SMgmtWrapper *pWrapper) { mgmtFp.requiredFp = vmRequire; vmInitMsgHandles(pWrapper); - pWrapper->name = "vnodes"; + pWrapper->name = "vnode"; pWrapper->fp = mgmtFp; } From 3cdeed0d447bc8bee039cdc62fc912b7d7fe1db9 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Tue, 22 Mar 2022 13:59:48 +0800 Subject: [PATCH 09/68] rename TDB to TSDB for log --- source/dnode/vnode/src/inc/tsdbLog.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdbLog.h b/source/dnode/vnode/src/inc/tsdbLog.h index 56dc8ab2a0..3afe628198 100644 --- a/source/dnode/vnode/src/inc/tsdbLog.h +++ b/source/dnode/vnode/src/inc/tsdbLog.h @@ -24,12 +24,12 @@ extern "C" { extern int32_t tsdbDebugFlag; -#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) -#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) -#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) -#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) -#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) -#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) #ifdef __cplusplus } From 746ed7d795ea4a25f3ce8618b8d8b1951724714c Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 22 Mar 2022 02:09:15 -0400 Subject: [PATCH 10/68] TD-14221 bugfix --- source/libs/parser/inc/sql.y | 25 +- source/libs/parser/src/sql.c | 2687 +++++++++++++++++----------------- 2 files changed, 1402 insertions(+), 1310 deletions(-) diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 2298ae0761..0fcd7e8d35 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -337,10 +337,31 @@ literal(A) ::= duration_literal(B). duration_literal(A) ::= NK_VARIABLE(B). { A = createRawExprNode(pCxt, &B, createDurationValueNode(pCxt, &B)); } +signed(A) ::= NK_INTEGER(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } +signed(A) ::= NK_PLUS NK_INTEGER(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } +signed(A) ::= NK_MINUS(B) NK_INTEGER(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + } +signed(A) ::= NK_FLOAT(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B); } +signed(A) ::= NK_PLUS NK_FLOAT(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B); } +signed(A) ::= NK_MINUS(B) NK_FLOAT(C). { + SToken t = B; + t.n = (C.z + C.n) - B.z; + A = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + } + +signed_literal(A) ::= signed(B). { A = B; } +signed_literal(A) ::= NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } +signed_literal(A) ::= NK_BOOL(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B); } +signed_literal(A) ::= TIMESTAMP NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &B); } +signed_literal(A) ::= duration_literal(B). { A = releaseRawExprNode(pCxt, B); } + %type literal_list { SNodeList* } %destructor literal_list { nodesDestroyList($$); } -literal_list(A) ::= literal(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); } -literal_list(A) ::= literal_list(B) NK_COMMA literal(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); } +literal_list(A) ::= signed_literal(B). { A = createNodeList(pCxt, B); } +literal_list(A) ::= literal_list(B) NK_COMMA signed_literal(C). { A = addNodeToList(pCxt, B, C); } /************************************************ names and identifiers ***********************************************/ %type db_name { SToken } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 3d88eb5336..923476bd62 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -99,24 +99,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned char -#define YYNOCODE 249 +#define YYNOCODE 251 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SNode* yy26; - EOrder yy32; - SNodeList* yy64; - EOperatorType yy80; - bool yy107; - EFillMode yy192; - SToken yy353; - SDataType yy370; - EJoinType yy372; - ENullOrder yy391; - SAlterOption yy443; - int32_t yy448; + int32_t yy88; + EJoinType yy184; + EOperatorType yy194; + SDataType yy218; + SAlterOption yy233; + EFillMode yy256; + SToken yy269; + ENullOrder yy339; + bool yy345; + SNode* yy348; + SNodeList* yy358; + EOrder yy368; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -131,17 +131,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 414 -#define YYNRULE 316 +#define YYNSTATE 417 +#define YYNRULE 327 #define YYNTOKEN 160 -#define YY_MAX_SHIFT 413 -#define YY_MIN_SHIFTREDUCE 631 -#define YY_MAX_SHIFTREDUCE 946 -#define YY_ERROR_ACTION 947 -#define YY_ACCEPT_ACTION 948 -#define YY_NO_ACTION 949 -#define YY_MIN_REDUCE 950 -#define YY_MAX_REDUCE 1265 +#define YY_MAX_SHIFT 416 +#define YY_MIN_SHIFTREDUCE 645 +#define YY_MAX_SHIFTREDUCE 971 +#define YY_ERROR_ACTION 972 +#define YY_ACCEPT_ACTION 973 +#define YY_NO_ACTION 974 +#define YY_MIN_REDUCE 975 +#define YY_MAX_REDUCE 1301 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -208,379 +208,381 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1182) +#define YY_ACTTAB_COUNT (1198) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 996, 347, 347, 24, 162, 334, 253, 1057, 227, 1049, - /* 10 */ 108, 1115, 1158, 31, 29, 27, 26, 25, 951, 331, - /* 20 */ 347, 1098, 1060, 1060, 103, 64, 962, 31, 29, 27, - /* 30 */ 26, 25, 263, 233, 1051, 973, 1106, 1108, 304, 76, - /* 40 */ 346, 1060, 75, 74, 73, 72, 71, 70, 69, 68, - /* 50 */ 67, 201, 398, 397, 396, 395, 394, 393, 392, 391, - /* 60 */ 390, 389, 388, 387, 386, 385, 384, 383, 382, 381, - /* 70 */ 380, 1130, 1130, 30, 28, 829, 31, 29, 27, 26, - /* 80 */ 25, 224, 346, 808, 76, 852, 42, 75, 74, 73, - /* 90 */ 72, 71, 70, 69, 68, 67, 275, 102, 270, 42, - /* 100 */ 806, 274, 1244, 1056, 273, 1063, 271, 1105, 88, 272, - /* 110 */ 289, 12, 950, 214, 201, 1243, 1055, 815, 1103, 1242, - /* 120 */ 23, 222, 346, 847, 848, 849, 850, 851, 853, 855, - /* 130 */ 856, 857, 807, 254, 1, 10, 86, 85, 84, 83, - /* 140 */ 82, 81, 80, 79, 78, 1132, 290, 303, 852, 747, - /* 150 */ 369, 368, 367, 751, 366, 753, 754, 365, 756, 362, - /* 160 */ 410, 762, 359, 764, 765, 356, 353, 287, 1244, 215, - /* 170 */ 942, 943, 817, 310, 305, 10, 913, 1143, 809, 812, - /* 180 */ 285, 116, 1130, 23, 222, 1242, 847, 848, 849, 850, - /* 190 */ 851, 853, 855, 856, 857, 117, 117, 1158, 300, 911, - /* 200 */ 912, 914, 915, 1132, 331, 31, 29, 27, 26, 25, - /* 210 */ 333, 347, 347, 888, 1130, 1143, 344, 345, 815, 319, - /* 220 */ 105, 1025, 60, 1144, 1147, 1183, 948, 230, 249, 200, - /* 230 */ 1179, 117, 1060, 1060, 347, 1158, 972, 292, 248, 64, - /* 240 */ 1130, 1244, 318, 247, 315, 246, 269, 309, 333, 379, - /* 250 */ 1158, 96, 1130, 1197, 116, 1060, 180, 331, 1242, 1090, - /* 260 */ 61, 1144, 1147, 1183, 243, 91, 1105, 217, 1179, 111, - /* 270 */ 1194, 237, 229, 1130, 245, 244, 308, 1103, 1143, 406, - /* 280 */ 405, 158, 30, 28, 889, 89, 347, 296, 1210, 819, - /* 290 */ 224, 175, 808, 1244, 317, 112, 1190, 1191, 1158, 1195, - /* 300 */ 228, 315, 27, 26, 25, 318, 116, 1060, 102, 806, - /* 310 */ 1242, 333, 51, 1143, 239, 1130, 1062, 58, 1202, 884, - /* 320 */ 12, 818, 91, 61, 1144, 1147, 1183, 92, 1036, 1053, - /* 330 */ 217, 1179, 111, 1158, 1052, 31, 29, 27, 26, 25, - /* 340 */ 331, 807, 89, 1, 887, 267, 333, 232, 1143, 266, - /* 350 */ 1130, 1211, 113, 1190, 1191, 102, 1195, 910, 61, 1144, - /* 360 */ 1147, 1183, 235, 1062, 117, 217, 1179, 1256, 1158, 410, - /* 370 */ 102, 77, 372, 971, 268, 331, 1217, 254, 1062, 1143, - /* 380 */ 1105, 333, 30, 28, 157, 1130, 234, 809, 812, 1035, - /* 390 */ 224, 1103, 808, 61, 1144, 1147, 1183, 829, 347, 1158, - /* 400 */ 217, 1179, 1256, 236, 9, 8, 331, 30, 28, 806, - /* 410 */ 1130, 1240, 333, 30, 28, 224, 1130, 808, 1143, 1060, - /* 420 */ 12, 224, 334, 808, 61, 1144, 1147, 1183, 1116, 1197, - /* 430 */ 808, 217, 1179, 1256, 806, 669, 970, 670, 1158, 669, - /* 440 */ 806, 807, 1201, 1, 1045, 331, 1193, 806, 1047, 376, - /* 450 */ 1105, 333, 261, 375, 969, 1130, 1143, 1034, 671, 21, - /* 460 */ 319, 1107, 322, 190, 1144, 1147, 807, 854, 7, 410, - /* 470 */ 858, 149, 807, 1130, 7, 1105, 1158, 865, 377, 807, - /* 480 */ 57, 6, 1244, 331, 968, 147, 1104, 809, 812, 333, - /* 490 */ 1143, 1130, 53, 1130, 410, 116, 967, 374, 373, 1242, - /* 500 */ 410, 62, 1144, 1147, 1183, 820, 379, 410, 1182, 1179, - /* 510 */ 1158, 315, 809, 812, 30, 28, 332, 331, 809, 812, - /* 520 */ 966, 1130, 224, 333, 808, 809, 812, 1130, 896, 117, - /* 530 */ 965, 964, 91, 1130, 817, 62, 1144, 1147, 1183, 1133, - /* 540 */ 961, 806, 329, 1179, 960, 30, 28, 319, 945, 946, - /* 550 */ 959, 1143, 89, 224, 958, 808, 957, 1130, 131, 9, - /* 560 */ 8, 129, 155, 1190, 314, 413, 313, 1130, 1130, 1244, - /* 570 */ 884, 1158, 806, 807, 956, 7, 1130, 1130, 331, 178, - /* 580 */ 1043, 1130, 116, 87, 333, 955, 1242, 1130, 1130, 402, - /* 590 */ 1143, 1130, 177, 1130, 954, 323, 106, 1144, 1147, 330, - /* 600 */ 144, 410, 953, 126, 807, 326, 1, 110, 1197, 321, - /* 610 */ 1158, 1130, 371, 259, 963, 242, 125, 331, 59, 809, - /* 620 */ 812, 173, 1130, 333, 1026, 1192, 133, 1130, 1143, 132, - /* 630 */ 159, 1130, 410, 320, 1257, 62, 1144, 1147, 1183, 1130, - /* 640 */ 991, 135, 43, 1180, 134, 123, 137, 301, 1158, 136, - /* 650 */ 809, 812, 1143, 859, 343, 331, 986, 295, 152, 324, - /* 660 */ 141, 333, 276, 1143, 185, 1130, 984, 32, 223, 187, - /* 670 */ 844, 327, 1158, 196, 1144, 1147, 1099, 826, 278, 331, - /* 680 */ 122, 186, 104, 1158, 120, 333, 1143, 260, 281, 1130, - /* 690 */ 331, 32, 297, 1137, 118, 1213, 333, 196, 1144, 1147, - /* 700 */ 1130, 1143, 316, 798, 167, 1159, 1158, 1135, 195, 1144, - /* 710 */ 1147, 1033, 339, 331, 161, 172, 1143, 32, 165, 333, - /* 720 */ 2, 1158, 250, 1130, 238, 815, 93, 823, 331, 94, - /* 730 */ 119, 106, 1144, 1147, 333, 816, 1158, 1143, 1130, 311, - /* 740 */ 251, 221, 252, 331, 740, 735, 196, 1144, 1147, 333, - /* 750 */ 822, 41, 1143, 1130, 255, 124, 225, 1158, 96, 77, - /* 760 */ 821, 196, 1144, 1147, 331, 262, 264, 768, 1143, 1258, - /* 770 */ 333, 376, 1158, 772, 1130, 375, 778, 1050, 777, 331, - /* 780 */ 117, 351, 194, 1144, 1147, 333, 66, 94, 1158, 1130, - /* 790 */ 95, 1143, 96, 128, 97, 331, 1143, 197, 1144, 1147, - /* 800 */ 377, 333, 1046, 291, 130, 1130, 98, 1143, 94, 99, - /* 810 */ 1048, 1158, 1143, 188, 1144, 1147, 1158, 1044, 331, 374, - /* 820 */ 373, 140, 100, 331, 333, 101, 213, 1158, 1130, 333, - /* 830 */ 820, 1214, 1158, 1130, 331, 293, 198, 1144, 1147, 331, - /* 840 */ 333, 189, 1144, 1147, 1130, 333, 1224, 1143, 294, 1130, - /* 850 */ 1143, 302, 199, 1144, 1147, 337, 145, 1155, 1144, 1147, - /* 860 */ 812, 148, 299, 216, 298, 5, 1204, 1158, 1223, 312, - /* 870 */ 1158, 4, 884, 90, 331, 819, 151, 331, 109, 1198, - /* 880 */ 333, 33, 153, 333, 1130, 1143, 154, 1130, 218, 328, - /* 890 */ 17, 1241, 1154, 1144, 1147, 1153, 1144, 1147, 1259, 325, - /* 900 */ 1143, 160, 1165, 340, 1114, 1158, 335, 169, 336, 50, - /* 910 */ 341, 1113, 331, 226, 1061, 342, 1143, 179, 333, 52, - /* 920 */ 1158, 1143, 1130, 315, 181, 176, 409, 331, 191, 349, - /* 930 */ 204, 1144, 1147, 333, 183, 184, 1158, 1130, 1124, 192, - /* 940 */ 999, 1158, 1123, 331, 91, 203, 1144, 1147, 331, 333, - /* 950 */ 1122, 240, 1143, 1130, 333, 241, 1121, 208, 1130, 1039, - /* 960 */ 1038, 205, 1144, 1147, 89, 998, 202, 1144, 1147, 1000, - /* 970 */ 995, 983, 1158, 121, 114, 1190, 1191, 280, 1195, 331, - /* 980 */ 978, 1120, 267, 1111, 1037, 333, 266, 684, 997, 1130, - /* 990 */ 994, 256, 288, 258, 257, 982, 981, 193, 1144, 1147, - /* 1000 */ 209, 977, 207, 206, 1041, 265, 139, 65, 127, 781, - /* 1010 */ 283, 268, 1040, 783, 782, 277, 713, 712, 711, 138, - /* 1020 */ 992, 275, 210, 270, 710, 709, 274, 987, 708, 273, - /* 1030 */ 211, 271, 279, 985, 272, 212, 282, 976, 284, 975, - /* 1040 */ 286, 63, 1119, 1118, 1110, 38, 36, 142, 37, 44, - /* 1050 */ 3, 20, 32, 143, 14, 39, 146, 15, 306, 34, - /* 1060 */ 307, 31, 29, 27, 26, 25, 22, 909, 903, 47, - /* 1070 */ 11, 107, 150, 931, 930, 45, 31, 29, 27, 26, - /* 1080 */ 25, 902, 46, 8, 881, 880, 219, 935, 1109, 934, - /* 1090 */ 220, 993, 1135, 980, 19, 949, 936, 170, 827, 164, - /* 1100 */ 350, 156, 13, 35, 115, 18, 231, 354, 357, 360, - /* 1110 */ 907, 16, 845, 163, 166, 363, 53, 746, 168, 48, - /* 1120 */ 774, 704, 776, 775, 348, 49, 400, 1134, 769, 40, - /* 1130 */ 352, 399, 766, 355, 401, 378, 763, 757, 682, 358, - /* 1140 */ 171, 338, 174, 703, 361, 702, 755, 364, 701, 700, - /* 1150 */ 699, 698, 54, 55, 697, 56, 696, 705, 695, 694, - /* 1160 */ 761, 693, 692, 691, 690, 689, 403, 370, 688, 687, - /* 1170 */ 404, 979, 974, 407, 760, 408, 759, 810, 758, 182, - /* 1180 */ 411, 412, + /* 0 */ 1021, 1167, 180, 43, 1194, 1115, 215, 1163, 1169, 24, + /* 10 */ 162, 333, 88, 31, 29, 27, 26, 25, 976, 1167, + /* 20 */ 1080, 232, 27, 26, 25, 1163, 1168, 31, 29, 27, + /* 30 */ 26, 25, 306, 235, 1167, 1076, 1131, 1133, 1074, 77, + /* 40 */ 1163, 1168, 76, 75, 74, 73, 72, 71, 70, 69, + /* 50 */ 68, 201, 401, 400, 399, 398, 397, 396, 395, 394, + /* 60 */ 393, 392, 391, 390, 389, 388, 387, 386, 385, 384, + /* 70 */ 383, 840, 1155, 30, 28, 854, 31, 29, 27, 26, + /* 80 */ 25, 224, 348, 822, 77, 877, 43, 76, 75, 74, + /* 90 */ 73, 72, 71, 70, 69, 68, 277, 349, 272, 1130, + /* 100 */ 820, 276, 255, 1081, 275, 214, 273, 9, 8, 274, + /* 110 */ 1128, 12, 975, 336, 201, 348, 227, 6, 1085, 1140, + /* 120 */ 23, 222, 108, 872, 873, 874, 875, 876, 878, 880, + /* 130 */ 881, 882, 821, 1123, 1, 10, 86, 85, 84, 83, + /* 140 */ 82, 81, 80, 79, 78, 291, 409, 408, 877, 761, + /* 150 */ 372, 371, 370, 765, 369, 767, 768, 368, 770, 365, + /* 160 */ 413, 776, 362, 778, 779, 359, 356, 103, 10, 987, + /* 170 */ 967, 968, 31, 29, 27, 26, 25, 1179, 823, 826, + /* 180 */ 890, 292, 844, 23, 222, 117, 872, 873, 874, 875, + /* 190 */ 876, 878, 880, 881, 882, 117, 117, 1194, 126, 348, + /* 200 */ 1194, 842, 110, 1280, 333, 1280, 909, 333, 261, 1061, + /* 210 */ 335, 125, 349, 237, 1155, 1179, 1279, 1082, 116, 321, + /* 220 */ 1278, 102, 1278, 305, 61, 1180, 1183, 1219, 310, 1087, + /* 230 */ 228, 200, 1215, 1085, 854, 1194, 349, 44, 102, 1179, + /* 240 */ 123, 346, 320, 1280, 998, 234, 1087, 1179, 335, 312, + /* 250 */ 307, 52, 1155, 102, 105, 1050, 116, 1085, 256, 1194, + /* 260 */ 1278, 1087, 62, 1180, 1183, 1219, 333, 1194, 1078, 217, + /* 270 */ 1215, 111, 335, 117, 333, 122, 1155, 157, 1179, 120, + /* 280 */ 335, 1155, 59, 158, 1155, 997, 106, 1180, 1183, 298, + /* 290 */ 1246, 325, 92, 973, 63, 1180, 1183, 1219, 1194, 1077, + /* 300 */ 269, 1218, 1215, 822, 268, 320, 31, 29, 27, 26, + /* 310 */ 25, 335, 311, 185, 996, 1155, 256, 1179, 187, 684, + /* 320 */ 820, 683, 1155, 322, 1293, 62, 1180, 1183, 1219, 270, + /* 330 */ 186, 104, 217, 1215, 111, 20, 131, 1194, 239, 129, + /* 340 */ 685, 1179, 1233, 118, 333, 31, 29, 27, 26, 25, + /* 350 */ 335, 1155, 821, 1247, 1155, 326, 995, 336, 1130, 1230, + /* 360 */ 1233, 1194, 1280, 1141, 62, 1180, 1183, 1219, 333, 1132, + /* 370 */ 1130, 217, 1215, 1292, 335, 116, 229, 1229, 1155, 1278, + /* 380 */ 413, 1128, 1253, 1179, 30, 28, 914, 994, 62, 1180, + /* 390 */ 1183, 1219, 224, 1155, 822, 217, 1215, 1292, 823, 826, + /* 400 */ 349, 102, 349, 1194, 21, 347, 1276, 65, 1130, 1088, + /* 410 */ 333, 820, 879, 349, 265, 883, 335, 845, 65, 1129, + /* 420 */ 1155, 1085, 12, 1085, 1155, 271, 1179, 970, 971, 117, + /* 430 */ 62, 1180, 1183, 1219, 1085, 993, 1130, 217, 1215, 1292, + /* 440 */ 1016, 683, 236, 821, 349, 1, 1194, 1128, 1237, 175, + /* 450 */ 992, 1059, 324, 333, 1025, 843, 30, 28, 263, 335, + /* 460 */ 1238, 909, 278, 1155, 224, 1085, 822, 317, 321, 30, + /* 470 */ 28, 413, 1155, 190, 1180, 1183, 349, 224, 921, 822, + /* 480 */ 913, 238, 133, 820, 842, 132, 991, 1155, 91, 823, + /* 490 */ 826, 382, 1280, 375, 12, 990, 820, 1085, 1179, 989, + /* 500 */ 382, 986, 985, 321, 135, 116, 277, 134, 272, 1278, + /* 510 */ 89, 276, 144, 984, 275, 821, 273, 1, 1194, 274, + /* 520 */ 155, 1226, 316, 1155, 315, 333, 983, 1280, 821, 982, + /* 530 */ 7, 335, 1155, 9, 8, 1155, 1155, 1233, 1155, 1155, + /* 540 */ 116, 30, 28, 413, 1278, 63, 1180, 1183, 1219, 224, + /* 550 */ 1155, 822, 331, 1215, 1228, 317, 413, 30, 28, 334, + /* 560 */ 289, 823, 826, 1155, 981, 224, 1155, 822, 820, 416, + /* 570 */ 30, 28, 328, 287, 823, 826, 91, 980, 224, 137, + /* 580 */ 822, 294, 136, 178, 820, 244, 1179, 87, 829, 979, + /* 590 */ 978, 117, 828, 405, 1070, 96, 177, 820, 89, 323, + /* 600 */ 821, 1155, 7, 988, 1072, 1068, 1194, 319, 112, 1226, + /* 610 */ 1227, 912, 1231, 333, 1155, 1011, 821, 1009, 7, 335, + /* 620 */ 832, 332, 60, 1155, 831, 173, 1155, 1155, 413, 821, + /* 630 */ 374, 1, 1179, 63, 1180, 1183, 1219, 280, 329, 283, + /* 640 */ 935, 1216, 149, 58, 413, 208, 823, 826, 1051, 159, + /* 650 */ 1249, 303, 1194, 1124, 41, 54, 147, 413, 345, 333, + /* 660 */ 262, 297, 823, 826, 141, 335, 152, 1179, 884, 1155, + /* 670 */ 269, 1195, 223, 161, 268, 823, 826, 318, 2, 196, + /* 680 */ 1180, 1183, 32, 851, 1173, 1179, 240, 1194, 209, 840, + /* 690 */ 207, 206, 869, 267, 333, 848, 812, 32, 1171, 270, + /* 700 */ 335, 252, 938, 841, 1155, 1194, 167, 299, 119, 1179, + /* 710 */ 32, 253, 333, 1060, 196, 1180, 1183, 341, 335, 847, + /* 720 */ 165, 254, 1155, 42, 302, 936, 937, 939, 940, 1194, + /* 730 */ 257, 93, 195, 1180, 1183, 1179, 333, 172, 754, 840, + /* 740 */ 749, 846, 335, 264, 124, 266, 1155, 1075, 128, 251, + /* 750 */ 1071, 94, 96, 67, 41, 1194, 106, 1180, 1183, 250, + /* 760 */ 1179, 213, 333, 313, 249, 782, 248, 786, 335, 130, + /* 770 */ 98, 99, 1155, 379, 792, 221, 1073, 378, 1058, 354, + /* 780 */ 1194, 94, 196, 1180, 1183, 245, 1069, 333, 95, 791, + /* 790 */ 97, 100, 1179, 335, 1294, 247, 246, 1155, 140, 101, + /* 800 */ 225, 296, 380, 96, 94, 231, 230, 196, 1180, 1183, + /* 810 */ 1179, 293, 1194, 295, 845, 834, 304, 339, 1260, 333, + /* 820 */ 145, 377, 376, 1250, 826, 335, 301, 216, 1179, 1155, + /* 830 */ 1194, 1259, 827, 1179, 148, 241, 1179, 333, 379, 194, + /* 840 */ 1180, 1183, 378, 335, 5, 314, 300, 1155, 1194, 1240, + /* 850 */ 4, 109, 153, 1194, 844, 333, 1194, 197, 1180, 1183, + /* 860 */ 333, 335, 909, 333, 830, 1155, 335, 380, 1179, 335, + /* 870 */ 1155, 1179, 151, 1155, 90, 188, 1180, 1183, 33, 1234, + /* 880 */ 198, 1180, 1183, 189, 1180, 1183, 377, 376, 1194, 218, + /* 890 */ 1295, 1194, 350, 1277, 330, 333, 327, 154, 333, 160, + /* 900 */ 17, 335, 1201, 1179, 335, 1155, 1179, 337, 1155, 342, + /* 910 */ 835, 826, 1139, 1138, 344, 199, 1180, 1183, 1191, 1180, + /* 920 */ 1183, 343, 338, 1194, 226, 169, 1194, 179, 51, 1086, + /* 930 */ 333, 53, 352, 333, 181, 176, 335, 412, 191, 335, + /* 940 */ 1155, 192, 1149, 1155, 1179, 317, 22, 1179, 184, 183, + /* 950 */ 1190, 1180, 1183, 1189, 1180, 1183, 31, 29, 27, 26, + /* 960 */ 25, 1024, 1148, 1147, 1194, 242, 91, 1194, 243, 1146, + /* 970 */ 1064, 333, 1063, 1023, 333, 1020, 1008, 335, 1003, 1145, + /* 980 */ 335, 1155, 1136, 1179, 1155, 121, 1062, 698, 89, 1022, + /* 990 */ 1019, 204, 1180, 1183, 203, 1180, 1183, 258, 113, 1226, + /* 1000 */ 1227, 1179, 1231, 1194, 259, 1007, 1006, 1002, 260, 1066, + /* 1010 */ 333, 66, 127, 797, 795, 1065, 335, 1017, 1012, 1179, + /* 1020 */ 1155, 1194, 796, 727, 726, 210, 725, 724, 333, 1010, + /* 1030 */ 205, 1180, 1183, 317, 335, 723, 282, 722, 1155, 1194, + /* 1040 */ 281, 211, 212, 284, 1001, 286, 333, 1000, 202, 1180, + /* 1050 */ 1183, 290, 335, 288, 91, 64, 1155, 1144, 1143, 1135, + /* 1060 */ 36, 143, 14, 308, 45, 139, 193, 1180, 1183, 285, + /* 1070 */ 142, 146, 15, 934, 279, 107, 89, 11, 138, 34, + /* 1080 */ 48, 3, 32, 37, 150, 46, 114, 1226, 1227, 309, + /* 1090 */ 1231, 956, 955, 219, 960, 928, 927, 1171, 47, 959, + /* 1100 */ 220, 19, 906, 156, 40, 8, 1134, 39, 905, 170, + /* 1110 */ 961, 836, 852, 13, 18, 35, 164, 115, 353, 932, + /* 1120 */ 233, 16, 166, 168, 163, 357, 360, 340, 54, 870, + /* 1130 */ 783, 363, 366, 1170, 351, 49, 50, 38, 174, 355, + /* 1140 */ 760, 780, 358, 790, 777, 361, 789, 771, 364, 171, + /* 1150 */ 788, 769, 696, 367, 718, 381, 55, 56, 57, 719, + /* 1160 */ 717, 716, 715, 714, 713, 712, 711, 710, 709, 775, + /* 1170 */ 708, 373, 774, 707, 706, 773, 705, 704, 703, 772, + /* 1180 */ 702, 701, 1018, 402, 403, 1005, 407, 404, 406, 1004, + /* 1190 */ 999, 410, 411, 974, 824, 182, 414, 415, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 0, 169, 169, 212, 213, 196, 174, 174, 199, 184, - /* 10 */ 182, 202, 183, 12, 13, 14, 15, 16, 0, 190, - /* 20 */ 169, 193, 190, 190, 162, 174, 164, 12, 13, 14, - /* 30 */ 15, 16, 181, 192, 163, 163, 195, 196, 209, 21, - /* 40 */ 20, 190, 24, 25, 26, 27, 28, 29, 30, 31, + /* 0 */ 0, 200, 176, 171, 183, 179, 187, 206, 207, 214, + /* 10 */ 215, 190, 180, 12, 13, 14, 15, 16, 0, 200, + /* 20 */ 188, 187, 14, 15, 16, 206, 207, 12, 13, 14, + /* 30 */ 15, 16, 211, 192, 200, 163, 195, 196, 184, 21, + /* 40 */ 206, 207, 24, 25, 26, 27, 28, 29, 30, 31, /* 50 */ 32, 50, 52, 53, 54, 55, 56, 57, 58, 59, /* 60 */ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, - /* 70 */ 70, 200, 200, 12, 13, 74, 12, 13, 14, 15, + /* 70 */ 70, 20, 200, 12, 13, 74, 12, 13, 14, 15, /* 80 */ 16, 20, 20, 22, 21, 84, 171, 24, 25, 26, - /* 90 */ 27, 28, 29, 30, 31, 32, 52, 183, 54, 171, - /* 100 */ 39, 57, 227, 188, 60, 191, 62, 183, 180, 65, - /* 110 */ 169, 50, 0, 189, 50, 240, 188, 20, 194, 244, - /* 120 */ 119, 120, 20, 122, 123, 124, 125, 126, 127, 128, - /* 130 */ 129, 130, 71, 49, 73, 73, 24, 25, 26, 27, - /* 140 */ 28, 29, 30, 31, 32, 163, 205, 113, 84, 90, + /* 90 */ 27, 28, 29, 30, 31, 32, 52, 169, 54, 183, + /* 100 */ 39, 57, 174, 188, 60, 189, 62, 1, 2, 65, + /* 110 */ 194, 50, 0, 196, 50, 20, 199, 44, 190, 202, + /* 120 */ 119, 120, 182, 122, 123, 124, 125, 126, 127, 128, + /* 130 */ 129, 130, 71, 193, 73, 73, 24, 25, 26, 27, + /* 140 */ 28, 29, 30, 31, 32, 169, 166, 167, 84, 90, /* 150 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - /* 160 */ 99, 102, 103, 104, 105, 106, 107, 21, 227, 187, - /* 170 */ 155, 156, 20, 139, 140, 73, 121, 163, 117, 118, - /* 180 */ 34, 240, 200, 119, 120, 244, 122, 123, 124, 125, - /* 190 */ 126, 127, 128, 129, 130, 134, 134, 183, 143, 144, - /* 200 */ 145, 146, 147, 163, 190, 12, 13, 14, 15, 16, - /* 210 */ 196, 169, 169, 4, 200, 163, 174, 174, 20, 205, - /* 220 */ 172, 173, 208, 209, 210, 211, 160, 187, 30, 215, - /* 230 */ 216, 134, 190, 190, 169, 183, 163, 74, 40, 174, - /* 240 */ 200, 227, 190, 45, 169, 47, 181, 20, 196, 49, - /* 250 */ 183, 88, 200, 206, 240, 190, 176, 190, 244, 179, - /* 260 */ 208, 209, 210, 211, 66, 190, 183, 215, 216, 217, - /* 270 */ 223, 205, 189, 200, 76, 77, 209, 194, 163, 166, - /* 280 */ 167, 229, 12, 13, 14, 210, 169, 235, 236, 20, - /* 290 */ 20, 174, 22, 227, 219, 220, 221, 222, 183, 224, - /* 300 */ 175, 169, 14, 15, 16, 190, 240, 190, 183, 39, - /* 310 */ 244, 196, 168, 163, 116, 200, 191, 168, 132, 133, - /* 320 */ 50, 20, 190, 208, 209, 210, 211, 178, 0, 185, - /* 330 */ 215, 216, 217, 183, 185, 12, 13, 14, 15, 16, - /* 340 */ 190, 71, 210, 73, 135, 60, 196, 175, 163, 64, - /* 350 */ 200, 236, 220, 221, 222, 183, 224, 74, 208, 209, - /* 360 */ 210, 211, 175, 191, 134, 215, 216, 217, 183, 99, - /* 370 */ 183, 88, 86, 163, 89, 190, 226, 49, 191, 163, - /* 380 */ 183, 196, 12, 13, 115, 200, 189, 117, 118, 0, - /* 390 */ 20, 194, 22, 208, 209, 210, 211, 74, 169, 183, - /* 400 */ 215, 216, 217, 174, 1, 2, 190, 12, 13, 39, - /* 410 */ 200, 226, 196, 12, 13, 20, 200, 22, 163, 190, - /* 420 */ 50, 20, 196, 22, 208, 209, 210, 211, 202, 206, - /* 430 */ 22, 215, 216, 217, 39, 22, 163, 20, 183, 22, - /* 440 */ 39, 71, 226, 73, 184, 190, 223, 39, 184, 60, - /* 450 */ 183, 196, 39, 64, 163, 200, 163, 0, 41, 119, - /* 460 */ 205, 194, 3, 208, 209, 210, 71, 127, 73, 99, - /* 470 */ 130, 74, 71, 200, 73, 183, 183, 74, 89, 71, - /* 480 */ 73, 44, 227, 190, 163, 88, 194, 117, 118, 196, - /* 490 */ 163, 200, 85, 200, 99, 240, 163, 108, 109, 244, - /* 500 */ 99, 208, 209, 210, 211, 20, 49, 99, 215, 216, - /* 510 */ 183, 169, 117, 118, 12, 13, 14, 190, 117, 118, - /* 520 */ 163, 200, 20, 196, 22, 117, 118, 200, 14, 134, - /* 530 */ 163, 163, 190, 200, 20, 208, 209, 210, 211, 163, - /* 540 */ 163, 39, 215, 216, 163, 12, 13, 205, 158, 159, - /* 550 */ 163, 163, 210, 20, 163, 22, 163, 200, 79, 1, - /* 560 */ 2, 82, 220, 221, 222, 19, 224, 200, 200, 227, - /* 570 */ 133, 183, 39, 71, 163, 73, 200, 200, 190, 33, - /* 580 */ 184, 200, 240, 37, 196, 163, 244, 200, 200, 43, - /* 590 */ 163, 200, 46, 200, 163, 88, 208, 209, 210, 50, - /* 600 */ 115, 99, 163, 33, 71, 88, 73, 37, 206, 150, - /* 610 */ 183, 200, 184, 43, 164, 169, 46, 190, 72, 117, - /* 620 */ 118, 75, 200, 196, 173, 223, 79, 200, 163, 82, - /* 630 */ 247, 200, 99, 245, 246, 208, 209, 210, 211, 200, - /* 640 */ 0, 79, 72, 216, 82, 75, 79, 238, 183, 82, - /* 650 */ 117, 118, 163, 74, 108, 190, 0, 111, 232, 152, - /* 660 */ 114, 196, 22, 163, 18, 200, 0, 88, 203, 23, - /* 670 */ 121, 154, 183, 208, 209, 210, 193, 74, 22, 190, - /* 680 */ 110, 35, 36, 183, 114, 196, 163, 166, 22, 200, - /* 690 */ 190, 88, 203, 73, 48, 207, 196, 208, 209, 210, - /* 700 */ 200, 163, 225, 74, 74, 183, 183, 87, 208, 209, - /* 710 */ 210, 0, 74, 190, 241, 74, 163, 88, 88, 196, - /* 720 */ 228, 183, 204, 200, 169, 20, 88, 20, 190, 88, - /* 730 */ 171, 208, 209, 210, 196, 20, 183, 163, 200, 239, - /* 740 */ 190, 203, 197, 190, 74, 74, 208, 209, 210, 196, - /* 750 */ 20, 171, 163, 200, 169, 171, 203, 183, 88, 88, - /* 760 */ 20, 208, 209, 210, 190, 165, 183, 74, 163, 246, - /* 770 */ 196, 60, 183, 74, 200, 64, 74, 183, 74, 190, - /* 780 */ 134, 88, 208, 209, 210, 196, 169, 88, 183, 200, - /* 790 */ 88, 163, 88, 183, 74, 190, 163, 208, 209, 210, - /* 800 */ 89, 196, 183, 204, 183, 200, 183, 163, 88, 183, - /* 810 */ 183, 183, 163, 208, 209, 210, 183, 183, 190, 108, - /* 820 */ 109, 168, 183, 190, 196, 183, 165, 183, 200, 196, - /* 830 */ 20, 207, 183, 200, 190, 190, 208, 209, 210, 190, - /* 840 */ 196, 208, 209, 210, 200, 196, 237, 163, 197, 200, - /* 850 */ 163, 142, 208, 209, 210, 141, 201, 208, 209, 210, - /* 860 */ 118, 201, 200, 200, 137, 149, 234, 183, 237, 148, - /* 870 */ 183, 136, 133, 190, 190, 20, 233, 190, 231, 206, - /* 880 */ 196, 131, 230, 196, 200, 163, 218, 200, 157, 153, - /* 890 */ 73, 243, 208, 209, 210, 208, 209, 210, 248, 151, - /* 900 */ 163, 242, 214, 112, 201, 183, 200, 190, 200, 168, - /* 910 */ 198, 201, 190, 200, 190, 197, 163, 179, 196, 73, - /* 920 */ 183, 163, 200, 169, 169, 168, 165, 190, 177, 186, - /* 930 */ 208, 209, 210, 196, 170, 161, 183, 200, 0, 177, - /* 940 */ 0, 183, 0, 190, 190, 208, 209, 210, 190, 196, - /* 950 */ 0, 66, 163, 200, 196, 87, 0, 35, 200, 0, - /* 960 */ 0, 208, 209, 210, 210, 0, 208, 209, 210, 0, - /* 970 */ 0, 0, 183, 44, 220, 221, 222, 4, 224, 190, - /* 980 */ 0, 0, 60, 0, 0, 196, 64, 51, 0, 200, - /* 990 */ 0, 39, 19, 44, 37, 0, 0, 208, 209, 210, - /* 1000 */ 78, 0, 80, 81, 0, 83, 33, 84, 82, 22, - /* 1010 */ 37, 89, 0, 39, 39, 42, 39, 39, 39, 46, - /* 1020 */ 0, 52, 22, 54, 39, 39, 57, 0, 39, 60, - /* 1030 */ 22, 62, 40, 0, 65, 22, 39, 0, 22, 0, - /* 1040 */ 22, 20, 0, 0, 0, 72, 115, 44, 75, 73, - /* 1050 */ 88, 2, 88, 110, 138, 88, 74, 138, 39, 132, - /* 1060 */ 88, 12, 13, 14, 15, 16, 2, 74, 74, 4, - /* 1070 */ 138, 73, 73, 39, 39, 73, 12, 13, 14, 15, - /* 1080 */ 16, 74, 73, 2, 74, 74, 39, 39, 0, 39, - /* 1090 */ 39, 0, 87, 0, 88, 249, 74, 44, 74, 74, - /* 1100 */ 39, 87, 73, 88, 87, 73, 39, 39, 39, 39, - /* 1110 */ 74, 88, 121, 87, 73, 39, 85, 22, 73, 73, - /* 1120 */ 22, 22, 39, 39, 86, 73, 37, 87, 74, 73, - /* 1130 */ 73, 39, 74, 73, 44, 50, 74, 74, 51, 73, - /* 1140 */ 110, 113, 87, 39, 73, 39, 74, 73, 39, 39, - /* 1150 */ 39, 39, 73, 73, 39, 73, 22, 71, 39, 39, - /* 1160 */ 101, 39, 39, 39, 39, 39, 39, 89, 39, 39, - /* 1170 */ 38, 0, 0, 22, 101, 21, 101, 22, 101, 22, - /* 1180 */ 21, 20, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1190 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1200 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1210 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1220 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1230 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1240 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1250 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1260 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1270 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1280 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1290 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1300 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1310 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1320 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1330 */ 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, - /* 1340 */ 249, 249, + /* 160 */ 99, 102, 103, 104, 105, 106, 107, 162, 73, 164, + /* 170 */ 155, 156, 12, 13, 14, 15, 16, 163, 117, 118, + /* 180 */ 74, 205, 20, 119, 120, 134, 122, 123, 124, 125, + /* 190 */ 126, 127, 128, 129, 130, 134, 134, 183, 33, 20, + /* 200 */ 183, 20, 37, 229, 190, 229, 133, 190, 43, 0, + /* 210 */ 196, 46, 169, 175, 200, 163, 242, 174, 242, 205, + /* 220 */ 246, 183, 246, 113, 210, 211, 212, 213, 211, 191, + /* 230 */ 175, 217, 218, 190, 74, 183, 169, 72, 183, 163, + /* 240 */ 75, 174, 190, 229, 163, 175, 191, 163, 196, 139, + /* 250 */ 140, 168, 200, 183, 172, 173, 242, 190, 49, 183, + /* 260 */ 246, 191, 210, 211, 212, 213, 190, 183, 185, 217, + /* 270 */ 218, 219, 196, 134, 190, 110, 200, 115, 163, 114, + /* 280 */ 196, 200, 168, 231, 200, 163, 210, 211, 212, 237, + /* 290 */ 238, 88, 178, 160, 210, 211, 212, 213, 183, 185, + /* 300 */ 60, 217, 218, 22, 64, 190, 12, 13, 14, 15, + /* 310 */ 16, 196, 20, 18, 163, 200, 49, 163, 23, 20, + /* 320 */ 39, 22, 200, 247, 248, 210, 211, 212, 213, 89, + /* 330 */ 35, 36, 217, 218, 219, 2, 79, 183, 205, 82, + /* 340 */ 41, 163, 208, 48, 190, 12, 13, 14, 15, 16, + /* 350 */ 196, 200, 71, 238, 200, 152, 163, 196, 183, 225, + /* 360 */ 208, 183, 229, 202, 210, 211, 212, 213, 190, 194, + /* 370 */ 183, 217, 218, 219, 196, 242, 189, 225, 200, 246, + /* 380 */ 99, 194, 228, 163, 12, 13, 14, 163, 210, 211, + /* 390 */ 212, 213, 20, 200, 22, 217, 218, 219, 117, 118, + /* 400 */ 169, 183, 169, 183, 119, 174, 228, 174, 183, 191, + /* 410 */ 190, 39, 127, 169, 181, 130, 196, 20, 174, 194, + /* 420 */ 200, 190, 50, 190, 200, 181, 163, 158, 159, 134, + /* 430 */ 210, 211, 212, 213, 190, 163, 183, 217, 218, 219, + /* 440 */ 0, 22, 189, 71, 169, 73, 183, 194, 228, 174, + /* 450 */ 163, 0, 3, 190, 0, 20, 12, 13, 39, 196, + /* 460 */ 132, 133, 22, 200, 20, 190, 22, 169, 205, 12, + /* 470 */ 13, 99, 200, 210, 211, 212, 169, 20, 14, 22, + /* 480 */ 4, 174, 79, 39, 20, 82, 163, 200, 190, 117, + /* 490 */ 118, 49, 229, 86, 50, 163, 39, 190, 163, 163, + /* 500 */ 49, 163, 163, 205, 79, 242, 52, 82, 54, 246, + /* 510 */ 212, 57, 115, 163, 60, 71, 62, 73, 183, 65, + /* 520 */ 222, 223, 224, 200, 226, 190, 163, 229, 71, 163, + /* 530 */ 73, 196, 200, 1, 2, 200, 200, 208, 200, 200, + /* 540 */ 242, 12, 13, 99, 246, 210, 211, 212, 213, 20, + /* 550 */ 200, 22, 217, 218, 225, 169, 99, 12, 13, 14, + /* 560 */ 21, 117, 118, 200, 163, 20, 200, 22, 39, 19, + /* 570 */ 12, 13, 88, 34, 117, 118, 190, 163, 20, 79, + /* 580 */ 22, 74, 82, 33, 39, 169, 163, 37, 39, 163, + /* 590 */ 163, 134, 39, 43, 184, 88, 46, 39, 212, 150, + /* 600 */ 71, 200, 73, 164, 184, 184, 183, 221, 222, 223, + /* 610 */ 224, 135, 226, 190, 200, 0, 71, 0, 73, 196, + /* 620 */ 71, 50, 72, 200, 71, 75, 200, 200, 99, 71, + /* 630 */ 184, 73, 163, 210, 211, 212, 213, 22, 154, 22, + /* 640 */ 74, 218, 74, 73, 99, 35, 117, 118, 173, 249, + /* 650 */ 209, 240, 183, 193, 88, 85, 88, 99, 108, 190, + /* 660 */ 166, 111, 117, 118, 114, 196, 234, 163, 74, 200, + /* 670 */ 60, 183, 203, 243, 64, 117, 118, 227, 230, 210, + /* 680 */ 211, 212, 88, 74, 73, 163, 169, 183, 78, 20, + /* 690 */ 80, 81, 121, 83, 190, 20, 74, 88, 87, 89, + /* 700 */ 196, 204, 121, 20, 200, 183, 74, 203, 171, 163, + /* 710 */ 88, 190, 190, 0, 210, 211, 212, 74, 196, 20, + /* 720 */ 88, 197, 200, 171, 143, 144, 145, 146, 147, 183, + /* 730 */ 169, 88, 210, 211, 212, 163, 190, 74, 74, 20, + /* 740 */ 74, 20, 196, 165, 171, 183, 200, 183, 183, 30, + /* 750 */ 183, 88, 88, 169, 88, 183, 210, 211, 212, 40, + /* 760 */ 163, 165, 190, 241, 45, 74, 47, 74, 196, 183, + /* 770 */ 183, 183, 200, 60, 74, 203, 183, 64, 0, 88, + /* 780 */ 183, 88, 210, 211, 212, 66, 183, 190, 88, 74, + /* 790 */ 74, 183, 163, 196, 248, 76, 77, 200, 168, 183, + /* 800 */ 203, 197, 89, 88, 88, 12, 13, 210, 211, 212, + /* 810 */ 163, 204, 183, 190, 20, 22, 142, 141, 239, 190, + /* 820 */ 201, 108, 109, 209, 118, 196, 200, 200, 163, 200, + /* 830 */ 183, 239, 39, 163, 201, 116, 163, 190, 60, 210, + /* 840 */ 211, 212, 64, 196, 149, 148, 137, 200, 183, 236, + /* 850 */ 136, 233, 232, 183, 20, 190, 183, 210, 211, 212, + /* 860 */ 190, 196, 133, 190, 71, 200, 196, 89, 163, 196, + /* 870 */ 200, 163, 235, 200, 190, 210, 211, 212, 131, 208, + /* 880 */ 210, 211, 212, 210, 211, 212, 108, 109, 183, 157, + /* 890 */ 250, 183, 99, 245, 153, 190, 151, 220, 190, 244, + /* 900 */ 73, 196, 216, 163, 196, 200, 163, 200, 200, 112, + /* 910 */ 117, 118, 201, 201, 197, 210, 211, 212, 210, 211, + /* 920 */ 212, 198, 200, 183, 200, 190, 183, 179, 168, 190, + /* 930 */ 190, 73, 186, 190, 169, 168, 196, 165, 177, 196, + /* 940 */ 200, 177, 0, 200, 163, 169, 2, 163, 161, 170, + /* 950 */ 210, 211, 212, 210, 211, 212, 12, 13, 14, 15, + /* 960 */ 16, 0, 0, 0, 183, 66, 190, 183, 87, 0, + /* 970 */ 0, 190, 0, 0, 190, 0, 0, 196, 0, 0, + /* 980 */ 196, 200, 0, 163, 200, 44, 0, 51, 212, 0, + /* 990 */ 0, 210, 211, 212, 210, 211, 212, 39, 222, 223, + /* 1000 */ 224, 163, 226, 183, 37, 0, 0, 0, 44, 0, + /* 1010 */ 190, 84, 82, 39, 22, 0, 196, 0, 0, 163, + /* 1020 */ 200, 183, 39, 39, 39, 22, 39, 39, 190, 0, + /* 1030 */ 210, 211, 212, 169, 196, 39, 4, 39, 200, 183, + /* 1040 */ 40, 22, 22, 39, 0, 22, 190, 0, 210, 211, + /* 1050 */ 212, 19, 196, 22, 190, 20, 200, 0, 0, 0, + /* 1060 */ 115, 110, 138, 39, 73, 33, 210, 211, 212, 37, + /* 1070 */ 44, 74, 138, 74, 42, 73, 212, 138, 46, 132, + /* 1080 */ 4, 88, 88, 88, 73, 73, 222, 223, 224, 88, + /* 1090 */ 226, 39, 39, 39, 39, 74, 74, 87, 73, 39, + /* 1100 */ 39, 88, 74, 87, 72, 2, 0, 75, 74, 44, + /* 1110 */ 74, 22, 74, 73, 73, 88, 74, 87, 39, 74, + /* 1120 */ 39, 88, 73, 73, 87, 39, 39, 113, 85, 121, + /* 1130 */ 74, 39, 39, 87, 86, 73, 73, 73, 87, 73, + /* 1140 */ 22, 74, 73, 39, 74, 73, 39, 74, 73, 110, + /* 1150 */ 22, 74, 51, 73, 22, 50, 73, 73, 73, 71, + /* 1160 */ 39, 39, 39, 39, 39, 39, 39, 22, 39, 101, + /* 1170 */ 39, 89, 101, 39, 39, 101, 39, 39, 39, 101, + /* 1180 */ 39, 39, 0, 39, 37, 0, 38, 44, 39, 0, + /* 1190 */ 0, 22, 21, 251, 22, 22, 21, 20, 251, 251, + /* 1200 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1210 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1220 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1230 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1240 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1250 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1260 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1270 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1280 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1290 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1300 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1310 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1320 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1330 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1340 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 1350 */ 251, 251, 251, 251, 251, 251, 251, 251, }; -#define YY_SHIFT_COUNT (413) +#define YY_SHIFT_COUNT (416) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1172) +#define YY_SHIFT_MAX (1190) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 646, 61, 270, 370, 370, 370, 370, 395, 370, 370, - /* 10 */ 62, 401, 533, 502, 401, 401, 401, 401, 401, 401, - /* 20 */ 401, 401, 401, 401, 401, 401, 401, 401, 401, 401, - /* 30 */ 401, 401, 401, 102, 102, 102, 97, 20, 20, 408, - /* 40 */ 408, 20, 20, 84, 152, 227, 227, 230, 301, 152, - /* 50 */ 20, 20, 152, 20, 152, 301, 152, 152, 20, 200, - /* 60 */ 1, 64, 64, 63, 922, 408, 44, 408, 408, 408, - /* 70 */ 408, 408, 408, 408, 408, 408, 408, 408, 408, 408, - /* 80 */ 408, 408, 408, 408, 408, 408, 408, 417, 328, 269, - /* 90 */ 269, 269, 457, 301, 152, 152, 152, 286, 59, 59, - /* 100 */ 59, 59, 59, 18, 198, 969, 15, 55, 285, 34, - /* 110 */ 413, 485, 186, 437, 186, 514, 459, 209, 705, 707, - /* 120 */ 84, 715, 730, 84, 705, 84, 740, 152, 152, 152, - /* 130 */ 152, 152, 152, 152, 152, 152, 152, 152, 705, 740, - /* 140 */ 707, 200, 715, 730, 810, 709, 714, 742, 709, 714, - /* 150 */ 742, 716, 721, 727, 735, 739, 715, 855, 750, 731, - /* 160 */ 736, 748, 817, 152, 714, 742, 742, 714, 742, 791, - /* 170 */ 715, 730, 286, 200, 715, 846, 705, 200, 740, 1182, - /* 180 */ 1182, 1182, 1182, 0, 112, 546, 570, 973, 1049, 1064, - /* 190 */ 323, 389, 711, 193, 193, 193, 193, 193, 193, 193, - /* 200 */ 403, 340, 288, 288, 288, 288, 479, 547, 562, 567, - /* 210 */ 640, 656, 666, 146, 163, 283, 397, 558, 390, 507, - /* 220 */ 517, 579, 549, 603, 620, 629, 630, 638, 641, 670, - /* 230 */ 671, 693, 699, 702, 704, 720, 407, 938, 940, 942, - /* 240 */ 950, 885, 868, 956, 959, 960, 965, 970, 971, 980, - /* 250 */ 981, 983, 929, 984, 936, 988, 990, 952, 957, 949, - /* 260 */ 995, 996, 1001, 1004, 923, 926, 974, 975, 987, 1012, - /* 270 */ 977, 978, 979, 985, 986, 989, 1020, 1000, 1027, 1008, - /* 280 */ 992, 1033, 1013, 997, 1037, 1016, 1039, 1018, 1021, 1042, - /* 290 */ 1043, 931, 1044, 976, 1003, 943, 962, 964, 916, 982, - /* 300 */ 967, 993, 998, 999, 994, 1002, 1007, 1019, 972, 1005, - /* 310 */ 1009, 1006, 919, 1010, 1011, 1014, 927, 1015, 1017, 1022, - /* 320 */ 1023, 932, 1065, 1034, 1035, 1047, 1048, 1050, 1051, 1081, - /* 330 */ 991, 1026, 1024, 1029, 1032, 1025, 1036, 1041, 1045, 1028, - /* 340 */ 1046, 1088, 1053, 1030, 1052, 1031, 1040, 1055, 1056, 1038, - /* 350 */ 1054, 1061, 1067, 1057, 1058, 1068, 1060, 1062, 1069, 1066, - /* 360 */ 1063, 1070, 1071, 1072, 1076, 1074, 1059, 1073, 1075, 1077, - /* 370 */ 1095, 1078, 1079, 1080, 1082, 1083, 1084, 1098, 1087, 1085, - /* 380 */ 1086, 1099, 1104, 1106, 1109, 1110, 1111, 1112, 1115, 1134, - /* 390 */ 1119, 1120, 1122, 1123, 1124, 1125, 1126, 1129, 1130, 1091, - /* 400 */ 1092, 1089, 1090, 1093, 1127, 1132, 1171, 1172, 1151, 1154, - /* 410 */ 1155, 1157, 1159, 1161, + /* 0 */ 295, 61, 372, 444, 444, 444, 444, 457, 444, 444, + /* 10 */ 62, 529, 558, 545, 529, 529, 529, 529, 529, 529, + /* 20 */ 529, 529, 529, 529, 529, 529, 529, 529, 529, 529, + /* 30 */ 529, 529, 529, 95, 95, 95, 51, 793, 793, 179, + /* 40 */ 179, 793, 179, 179, 267, 181, 292, 292, 139, 435, + /* 50 */ 181, 179, 179, 181, 179, 181, 435, 181, 181, 179, + /* 60 */ 442, 1, 64, 64, 63, 610, 281, 44, 281, 281, + /* 70 */ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, + /* 80 */ 281, 281, 281, 281, 281, 281, 281, 299, 209, 162, + /* 90 */ 162, 162, 451, 435, 181, 181, 181, 407, 59, 59, + /* 100 */ 59, 59, 59, 18, 719, 454, 15, 581, 240, 110, + /* 110 */ 419, 397, 328, 73, 328, 464, 449, 476, 669, 675, + /* 120 */ 267, 683, 699, 267, 669, 267, 721, 181, 181, 181, + /* 130 */ 181, 181, 181, 181, 181, 181, 181, 181, 669, 721, + /* 140 */ 675, 442, 683, 699, 794, 674, 676, 706, 674, 676, + /* 150 */ 706, 695, 697, 709, 714, 729, 683, 834, 747, 732, + /* 160 */ 741, 745, 827, 181, 676, 706, 706, 676, 706, 797, + /* 170 */ 683, 699, 407, 442, 683, 858, 669, 442, 721, 1198, + /* 180 */ 1198, 1198, 1198, 0, 112, 550, 165, 1032, 333, 944, + /* 190 */ 160, 713, 778, 294, 294, 294, 294, 294, 294, 294, + /* 200 */ 106, 285, 8, 8, 8, 8, 257, 403, 425, 500, + /* 210 */ 440, 615, 617, 539, 507, 566, 568, 532, 269, 203, + /* 220 */ 484, 594, 571, 609, 611, 622, 632, 643, 663, 664, + /* 230 */ 549, 553, 666, 691, 693, 700, 715, 716, 570, 942, + /* 240 */ 961, 962, 963, 899, 881, 969, 970, 972, 973, 975, + /* 250 */ 976, 978, 979, 982, 941, 986, 936, 989, 990, 958, + /* 260 */ 967, 964, 1005, 1006, 1007, 1009, 927, 930, 974, 983, + /* 270 */ 992, 1015, 984, 985, 987, 988, 996, 998, 1017, 1003, + /* 280 */ 1018, 1019, 1000, 1029, 1020, 1004, 1044, 1023, 1047, 1031, + /* 290 */ 1035, 1057, 1058, 945, 1059, 991, 1026, 951, 993, 994, + /* 300 */ 924, 997, 995, 999, 1002, 1011, 1021, 1012, 1022, 1024, + /* 310 */ 1001, 1010, 1025, 1013, 934, 1028, 1034, 1016, 947, 1027, + /* 320 */ 1030, 1036, 1033, 939, 1076, 1052, 1053, 1054, 1055, 1060, + /* 330 */ 1061, 1103, 1008, 1037, 1038, 1040, 1041, 1042, 1045, 1049, + /* 340 */ 1050, 1014, 1062, 1106, 1065, 1039, 1063, 1043, 1046, 1051, + /* 350 */ 1089, 1064, 1048, 1056, 1079, 1081, 1066, 1067, 1086, 1069, + /* 360 */ 1070, 1087, 1072, 1073, 1092, 1075, 1077, 1093, 1080, 1068, + /* 370 */ 1071, 1074, 1078, 1118, 1082, 1083, 1084, 1085, 1104, 1107, + /* 380 */ 1128, 1101, 1105, 1088, 1132, 1121, 1122, 1123, 1124, 1125, + /* 390 */ 1126, 1127, 1145, 1129, 1131, 1134, 1135, 1137, 1138, 1139, + /* 400 */ 1141, 1142, 1182, 1144, 1147, 1143, 1185, 1149, 1148, 1189, + /* 410 */ 1190, 1169, 1171, 1172, 1173, 1175, 1177, }; #define YY_REDUCE_COUNT (182) -#define YY_REDUCE_MIN (-209) -#define YY_REDUCE_MAX (789) +#define YY_REDUCE_MIN (-205) +#define YY_REDUCE_MAX (864) static const short yy_reduce_ofst[] = { - /* 0 */ 66, 14, 52, 115, 150, 185, 216, 255, 293, 327, - /* 10 */ 342, 388, 427, 465, 489, 500, 523, 538, 553, 574, - /* 20 */ 589, 605, 628, 633, 644, 649, 684, 687, 722, 737, - /* 30 */ 753, 758, 789, 75, 132, 754, -59, -149, 65, -18, - /* 40 */ 40, -168, -167, -72, -76, -171, 67, -125, -191, 125, - /* 50 */ 42, 43, 83, 117, 172, -159, 197, 187, 229, 149, - /* 60 */ -209, -209, -209, -138, -172, -129, 48, -128, 73, 210, - /* 70 */ 273, 291, 321, 333, 357, 367, 368, 376, 377, 381, - /* 80 */ 387, 391, 393, 411, 422, 431, 439, 113, -85, 47, - /* 90 */ 223, 402, 144, 226, -86, 267, 292, 80, -175, 260, - /* 100 */ 264, 396, 428, 450, 446, 451, 383, 409, 483, 426, - /* 110 */ 521, 488, 477, 477, 477, 522, 473, 492, 555, 518, - /* 120 */ 559, 550, 545, 580, 585, 584, 600, 583, 594, 610, - /* 130 */ 619, 621, 623, 626, 627, 634, 639, 642, 617, 661, - /* 140 */ 599, 653, 645, 651, 624, 609, 655, 662, 631, 660, - /* 150 */ 663, 632, 643, 647, 652, 477, 683, 673, 668, 650, - /* 160 */ 648, 659, 688, 522, 703, 706, 708, 710, 713, 712, - /* 170 */ 717, 718, 738, 741, 724, 743, 755, 757, 761, 751, - /* 180 */ 762, 764, 774, + /* 0 */ 133, 14, 52, 115, 154, 178, 220, 263, 84, 335, + /* 10 */ 298, 76, 423, 469, 504, 522, 546, 572, 597, 629, + /* 20 */ 647, 665, 670, 673, 705, 708, 740, 743, 781, 784, + /* 30 */ 820, 838, 856, 386, 776, 864, -24, -181, -166, 233, + /* 40 */ 244, -199, -72, 43, -168, -84, -179, 17, -26, -83, + /* 50 */ 55, 67, 231, 187, 275, 70, -159, 253, 38, 307, + /* 60 */ 114, -205, -205, -205, 5, -60, -128, 82, 81, 122, + /* 70 */ 151, 193, 224, 272, 287, 323, 332, 336, 338, 339, + /* 80 */ 350, 363, 366, 401, 414, 426, 427, -20, -85, 134, + /* 90 */ 152, 329, 83, 161, 218, 175, 225, -174, -146, 410, + /* 100 */ 420, 421, 446, 439, 416, 475, 400, 411, 460, 432, + /* 110 */ 494, 441, 450, 450, 450, 488, 430, 448, 517, 497, + /* 120 */ 537, 521, 524, 552, 561, 573, 578, 562, 564, 565, + /* 130 */ 567, 586, 587, 588, 593, 603, 608, 616, 584, 596, + /* 140 */ 607, 630, 623, 604, 614, 579, 619, 626, 592, 633, + /* 150 */ 627, 613, 637, 618, 620, 450, 684, 671, 677, 640, + /* 160 */ 648, 655, 686, 488, 711, 707, 722, 712, 724, 723, + /* 170 */ 735, 717, 748, 760, 739, 746, 765, 767, 772, 761, + /* 180 */ 764, 779, 787, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 10 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 20 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 30 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 40 */ 947, 947, 947, 1004, 947, 947, 947, 947, 947, 947, - /* 50 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 1002, - /* 60 */ 947, 1185, 947, 947, 947, 947, 947, 947, 947, 947, - /* 70 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 80 */ 947, 947, 947, 947, 947, 947, 947, 947, 1004, 1196, - /* 90 */ 1196, 1196, 1002, 947, 947, 947, 947, 1089, 947, 947, - /* 100 */ 947, 947, 947, 947, 947, 947, 1260, 947, 1042, 1220, - /* 110 */ 947, 1212, 1188, 1202, 1189, 947, 1245, 1205, 947, 947, - /* 120 */ 1004, 947, 947, 1004, 947, 1004, 947, 947, 947, 947, - /* 130 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 140 */ 947, 1002, 947, 947, 947, 1227, 1225, 947, 1227, 1225, - /* 150 */ 947, 1239, 1235, 1218, 1216, 1202, 947, 947, 947, 1263, - /* 160 */ 1251, 1247, 947, 947, 1225, 947, 947, 1225, 947, 1112, - /* 170 */ 947, 947, 947, 1002, 947, 1058, 947, 1002, 947, 1092, - /* 180 */ 1092, 1005, 952, 947, 947, 947, 947, 947, 947, 947, - /* 190 */ 947, 947, 947, 1157, 1238, 1237, 1156, 1162, 1161, 1160, - /* 200 */ 947, 947, 1151, 1152, 1150, 1149, 947, 947, 947, 947, - /* 210 */ 947, 947, 947, 947, 947, 947, 947, 1186, 947, 1248, - /* 220 */ 1252, 947, 947, 947, 1136, 947, 947, 947, 947, 947, - /* 230 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 240 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 250 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 260 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 270 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 280 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 290 */ 947, 947, 947, 947, 947, 947, 1209, 1219, 947, 947, - /* 300 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 1136, - /* 310 */ 947, 1236, 947, 1195, 1191, 947, 947, 1187, 947, 947, - /* 320 */ 1246, 947, 947, 947, 947, 947, 947, 947, 947, 1181, - /* 330 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 340 */ 947, 947, 947, 947, 947, 947, 1135, 947, 947, 947, - /* 350 */ 947, 947, 947, 1086, 947, 947, 947, 947, 947, 947, - /* 360 */ 947, 947, 947, 947, 947, 947, 1071, 1069, 1068, 1067, - /* 370 */ 947, 1064, 947, 947, 947, 947, 947, 947, 947, 947, - /* 380 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 390 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 400 */ 947, 947, 947, 947, 947, 947, 947, 947, 947, 947, - /* 410 */ 947, 947, 947, 947, + /* 0 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 10 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 20 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 30 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 40 */ 972, 972, 972, 972, 1029, 972, 972, 972, 972, 972, + /* 50 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 60 */ 1027, 972, 1221, 972, 972, 972, 972, 972, 972, 972, + /* 70 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 80 */ 972, 972, 972, 972, 972, 972, 972, 972, 1029, 1232, + /* 90 */ 1232, 1232, 1027, 972, 972, 972, 972, 1114, 972, 972, + /* 100 */ 972, 972, 972, 972, 972, 972, 1296, 972, 1067, 1256, + /* 110 */ 972, 1248, 1224, 1238, 1225, 972, 1281, 1241, 972, 972, + /* 120 */ 1029, 972, 972, 1029, 972, 1029, 972, 972, 972, 972, + /* 130 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 140 */ 972, 1027, 972, 972, 972, 1263, 1261, 972, 1263, 1261, + /* 150 */ 972, 1275, 1271, 1254, 1252, 1238, 972, 972, 972, 1299, + /* 160 */ 1287, 1283, 972, 972, 1261, 972, 972, 1261, 972, 1137, + /* 170 */ 972, 972, 972, 1027, 972, 1083, 972, 1027, 972, 1117, + /* 180 */ 1117, 1030, 977, 972, 972, 972, 972, 972, 972, 972, + /* 190 */ 972, 972, 972, 1193, 1274, 1273, 1192, 1198, 1197, 1196, + /* 200 */ 972, 972, 1187, 1188, 1186, 1185, 972, 972, 972, 972, + /* 210 */ 972, 972, 972, 972, 972, 972, 972, 1222, 972, 1284, + /* 220 */ 1288, 972, 972, 972, 1172, 972, 972, 972, 972, 972, + /* 230 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 240 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 250 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 260 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 270 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 280 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 290 */ 972, 972, 972, 972, 972, 972, 972, 972, 1245, 1255, + /* 300 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 310 */ 972, 1172, 972, 1272, 972, 1231, 1227, 972, 972, 1223, + /* 320 */ 972, 972, 1282, 972, 972, 972, 972, 972, 972, 972, + /* 330 */ 972, 1217, 972, 972, 972, 972, 972, 972, 972, 972, + /* 340 */ 972, 972, 972, 972, 972, 972, 972, 972, 1171, 972, + /* 350 */ 972, 972, 972, 972, 972, 972, 1111, 972, 972, 972, + /* 360 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 1096, + /* 370 */ 1094, 1093, 1092, 972, 1089, 972, 972, 972, 972, 972, + /* 380 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 390 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 400 */ 972, 972, 972, 972, 972, 972, 972, 972, 972, 972, + /* 410 */ 972, 972, 972, 972, 972, 972, 972, }; /********** End of lemon-generated parsing tables *****************************/ @@ -893,49 +895,51 @@ static const char *const yyTokenName[] = { /* 203 */ "expression_list", /* 204 */ "topic_name", /* 205 */ "query_expression", - /* 206 */ "table_alias", - /* 207 */ "column_alias", - /* 208 */ "expression", - /* 209 */ "column_reference", - /* 210 */ "subquery", - /* 211 */ "predicate", - /* 212 */ "compare_op", - /* 213 */ "in_op", - /* 214 */ "in_predicate_value", - /* 215 */ "boolean_value_expression", - /* 216 */ "boolean_primary", - /* 217 */ "common_expression", - /* 218 */ "from_clause", - /* 219 */ "table_reference_list", - /* 220 */ "table_reference", - /* 221 */ "table_primary", - /* 222 */ "joined_table", - /* 223 */ "alias_opt", - /* 224 */ "parenthesized_joined_table", - /* 225 */ "join_type", - /* 226 */ "search_condition", - /* 227 */ "query_specification", - /* 228 */ "set_quantifier_opt", - /* 229 */ "select_list", - /* 230 */ "where_clause_opt", - /* 231 */ "partition_by_clause_opt", - /* 232 */ "twindow_clause_opt", - /* 233 */ "group_by_clause_opt", - /* 234 */ "having_clause_opt", - /* 235 */ "select_sublist", - /* 236 */ "select_item", - /* 237 */ "fill_opt", - /* 238 */ "fill_mode", - /* 239 */ "group_by_list", - /* 240 */ "query_expression_body", - /* 241 */ "order_by_clause_opt", - /* 242 */ "slimit_clause_opt", - /* 243 */ "limit_clause_opt", - /* 244 */ "query_primary", - /* 245 */ "sort_specification_list", - /* 246 */ "sort_specification", - /* 247 */ "ordering_specification_opt", - /* 248 */ "null_ordering_opt", + /* 206 */ "signed", + /* 207 */ "signed_literal", + /* 208 */ "table_alias", + /* 209 */ "column_alias", + /* 210 */ "expression", + /* 211 */ "column_reference", + /* 212 */ "subquery", + /* 213 */ "predicate", + /* 214 */ "compare_op", + /* 215 */ "in_op", + /* 216 */ "in_predicate_value", + /* 217 */ "boolean_value_expression", + /* 218 */ "boolean_primary", + /* 219 */ "common_expression", + /* 220 */ "from_clause", + /* 221 */ "table_reference_list", + /* 222 */ "table_reference", + /* 223 */ "table_primary", + /* 224 */ "joined_table", + /* 225 */ "alias_opt", + /* 226 */ "parenthesized_joined_table", + /* 227 */ "join_type", + /* 228 */ "search_condition", + /* 229 */ "query_specification", + /* 230 */ "set_quantifier_opt", + /* 231 */ "select_list", + /* 232 */ "where_clause_opt", + /* 233 */ "partition_by_clause_opt", + /* 234 */ "twindow_clause_opt", + /* 235 */ "group_by_clause_opt", + /* 236 */ "having_clause_opt", + /* 237 */ "select_sublist", + /* 238 */ "select_item", + /* 239 */ "fill_opt", + /* 240 */ "fill_mode", + /* 241 */ "group_by_list", + /* 242 */ "query_expression_body", + /* 243 */ "order_by_clause_opt", + /* 244 */ "slimit_clause_opt", + /* 245 */ "limit_clause_opt", + /* 246 */ "query_primary", + /* 247 */ "sort_specification_list", + /* 248 */ "sort_specification", + /* 249 */ "ordering_specification_opt", + /* 250 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1125,140 +1129,151 @@ static const char *const yyRuleName[] = { /* 179 */ "literal ::= TIMESTAMP NK_STRING", /* 180 */ "literal ::= duration_literal", /* 181 */ "duration_literal ::= NK_VARIABLE", - /* 182 */ "literal_list ::= literal", - /* 183 */ "literal_list ::= literal_list NK_COMMA literal", - /* 184 */ "db_name ::= NK_ID", - /* 185 */ "table_name ::= NK_ID", - /* 186 */ "column_name ::= NK_ID", - /* 187 */ "function_name ::= NK_ID", - /* 188 */ "table_alias ::= NK_ID", - /* 189 */ "column_alias ::= NK_ID", - /* 190 */ "user_name ::= NK_ID", - /* 191 */ "index_name ::= NK_ID", - /* 192 */ "topic_name ::= NK_ID", - /* 193 */ "expression ::= literal", - /* 194 */ "expression ::= column_reference", - /* 195 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 196 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 197 */ "expression ::= subquery", - /* 198 */ "expression ::= NK_LP expression NK_RP", - /* 199 */ "expression ::= NK_PLUS expression", - /* 200 */ "expression ::= NK_MINUS expression", - /* 201 */ "expression ::= expression NK_PLUS expression", - /* 202 */ "expression ::= expression NK_MINUS expression", - /* 203 */ "expression ::= expression NK_STAR expression", - /* 204 */ "expression ::= expression NK_SLASH expression", - /* 205 */ "expression ::= expression NK_REM expression", - /* 206 */ "expression_list ::= expression", - /* 207 */ "expression_list ::= expression_list NK_COMMA expression", - /* 208 */ "column_reference ::= column_name", - /* 209 */ "column_reference ::= table_name NK_DOT column_name", - /* 210 */ "predicate ::= expression compare_op expression", - /* 211 */ "predicate ::= expression BETWEEN expression AND expression", - /* 212 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 213 */ "predicate ::= expression IS NULL", - /* 214 */ "predicate ::= expression IS NOT NULL", - /* 215 */ "predicate ::= expression in_op in_predicate_value", - /* 216 */ "compare_op ::= NK_LT", - /* 217 */ "compare_op ::= NK_GT", - /* 218 */ "compare_op ::= NK_LE", - /* 219 */ "compare_op ::= NK_GE", - /* 220 */ "compare_op ::= NK_NE", - /* 221 */ "compare_op ::= NK_EQ", - /* 222 */ "compare_op ::= LIKE", - /* 223 */ "compare_op ::= NOT LIKE", - /* 224 */ "compare_op ::= MATCH", - /* 225 */ "compare_op ::= NMATCH", - /* 226 */ "in_op ::= IN", - /* 227 */ "in_op ::= NOT IN", - /* 228 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 229 */ "boolean_value_expression ::= boolean_primary", - /* 230 */ "boolean_value_expression ::= NOT boolean_primary", - /* 231 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 232 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 233 */ "boolean_primary ::= predicate", - /* 234 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 235 */ "common_expression ::= expression", - /* 236 */ "common_expression ::= boolean_value_expression", - /* 237 */ "from_clause ::= FROM table_reference_list", - /* 238 */ "table_reference_list ::= table_reference", - /* 239 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 240 */ "table_reference ::= table_primary", - /* 241 */ "table_reference ::= joined_table", - /* 242 */ "table_primary ::= table_name alias_opt", - /* 243 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 244 */ "table_primary ::= subquery alias_opt", - /* 245 */ "table_primary ::= parenthesized_joined_table", - /* 246 */ "alias_opt ::=", - /* 247 */ "alias_opt ::= table_alias", - /* 248 */ "alias_opt ::= AS table_alias", - /* 249 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 250 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 251 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 252 */ "join_type ::=", - /* 253 */ "join_type ::= INNER", - /* 254 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 255 */ "set_quantifier_opt ::=", - /* 256 */ "set_quantifier_opt ::= DISTINCT", - /* 257 */ "set_quantifier_opt ::= ALL", - /* 258 */ "select_list ::= NK_STAR", - /* 259 */ "select_list ::= select_sublist", - /* 260 */ "select_sublist ::= select_item", - /* 261 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 262 */ "select_item ::= common_expression", - /* 263 */ "select_item ::= common_expression column_alias", - /* 264 */ "select_item ::= common_expression AS column_alias", - /* 265 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 266 */ "where_clause_opt ::=", - /* 267 */ "where_clause_opt ::= WHERE search_condition", - /* 268 */ "partition_by_clause_opt ::=", - /* 269 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 270 */ "twindow_clause_opt ::=", - /* 271 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP", - /* 272 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", - /* 273 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 274 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 275 */ "sliding_opt ::=", - /* 276 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 277 */ "fill_opt ::=", - /* 278 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 279 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 280 */ "fill_mode ::= NONE", - /* 281 */ "fill_mode ::= PREV", - /* 282 */ "fill_mode ::= NULL", - /* 283 */ "fill_mode ::= LINEAR", - /* 284 */ "fill_mode ::= NEXT", - /* 285 */ "group_by_clause_opt ::=", - /* 286 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 287 */ "group_by_list ::= expression", - /* 288 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 289 */ "having_clause_opt ::=", - /* 290 */ "having_clause_opt ::= HAVING search_condition", - /* 291 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 292 */ "query_expression_body ::= query_primary", - /* 293 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 294 */ "query_primary ::= query_specification", - /* 295 */ "order_by_clause_opt ::=", - /* 296 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 297 */ "slimit_clause_opt ::=", - /* 298 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 299 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 300 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 301 */ "limit_clause_opt ::=", - /* 302 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 303 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 304 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 305 */ "subquery ::= NK_LP query_expression NK_RP", - /* 306 */ "search_condition ::= common_expression", - /* 307 */ "sort_specification_list ::= sort_specification", - /* 308 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 309 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 310 */ "ordering_specification_opt ::=", - /* 311 */ "ordering_specification_opt ::= ASC", - /* 312 */ "ordering_specification_opt ::= DESC", - /* 313 */ "null_ordering_opt ::=", - /* 314 */ "null_ordering_opt ::= NULLS FIRST", - /* 315 */ "null_ordering_opt ::= NULLS LAST", + /* 182 */ "signed ::= NK_INTEGER", + /* 183 */ "signed ::= NK_PLUS NK_INTEGER", + /* 184 */ "signed ::= NK_MINUS NK_INTEGER", + /* 185 */ "signed ::= NK_FLOAT", + /* 186 */ "signed ::= NK_PLUS NK_FLOAT", + /* 187 */ "signed ::= NK_MINUS NK_FLOAT", + /* 188 */ "signed_literal ::= signed", + /* 189 */ "signed_literal ::= NK_STRING", + /* 190 */ "signed_literal ::= NK_BOOL", + /* 191 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 192 */ "signed_literal ::= duration_literal", + /* 193 */ "literal_list ::= signed_literal", + /* 194 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 195 */ "db_name ::= NK_ID", + /* 196 */ "table_name ::= NK_ID", + /* 197 */ "column_name ::= NK_ID", + /* 198 */ "function_name ::= NK_ID", + /* 199 */ "table_alias ::= NK_ID", + /* 200 */ "column_alias ::= NK_ID", + /* 201 */ "user_name ::= NK_ID", + /* 202 */ "index_name ::= NK_ID", + /* 203 */ "topic_name ::= NK_ID", + /* 204 */ "expression ::= literal", + /* 205 */ "expression ::= column_reference", + /* 206 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 207 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 208 */ "expression ::= subquery", + /* 209 */ "expression ::= NK_LP expression NK_RP", + /* 210 */ "expression ::= NK_PLUS expression", + /* 211 */ "expression ::= NK_MINUS expression", + /* 212 */ "expression ::= expression NK_PLUS expression", + /* 213 */ "expression ::= expression NK_MINUS expression", + /* 214 */ "expression ::= expression NK_STAR expression", + /* 215 */ "expression ::= expression NK_SLASH expression", + /* 216 */ "expression ::= expression NK_REM expression", + /* 217 */ "expression_list ::= expression", + /* 218 */ "expression_list ::= expression_list NK_COMMA expression", + /* 219 */ "column_reference ::= column_name", + /* 220 */ "column_reference ::= table_name NK_DOT column_name", + /* 221 */ "predicate ::= expression compare_op expression", + /* 222 */ "predicate ::= expression BETWEEN expression AND expression", + /* 223 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 224 */ "predicate ::= expression IS NULL", + /* 225 */ "predicate ::= expression IS NOT NULL", + /* 226 */ "predicate ::= expression in_op in_predicate_value", + /* 227 */ "compare_op ::= NK_LT", + /* 228 */ "compare_op ::= NK_GT", + /* 229 */ "compare_op ::= NK_LE", + /* 230 */ "compare_op ::= NK_GE", + /* 231 */ "compare_op ::= NK_NE", + /* 232 */ "compare_op ::= NK_EQ", + /* 233 */ "compare_op ::= LIKE", + /* 234 */ "compare_op ::= NOT LIKE", + /* 235 */ "compare_op ::= MATCH", + /* 236 */ "compare_op ::= NMATCH", + /* 237 */ "in_op ::= IN", + /* 238 */ "in_op ::= NOT IN", + /* 239 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 240 */ "boolean_value_expression ::= boolean_primary", + /* 241 */ "boolean_value_expression ::= NOT boolean_primary", + /* 242 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 243 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 244 */ "boolean_primary ::= predicate", + /* 245 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 246 */ "common_expression ::= expression", + /* 247 */ "common_expression ::= boolean_value_expression", + /* 248 */ "from_clause ::= FROM table_reference_list", + /* 249 */ "table_reference_list ::= table_reference", + /* 250 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 251 */ "table_reference ::= table_primary", + /* 252 */ "table_reference ::= joined_table", + /* 253 */ "table_primary ::= table_name alias_opt", + /* 254 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 255 */ "table_primary ::= subquery alias_opt", + /* 256 */ "table_primary ::= parenthesized_joined_table", + /* 257 */ "alias_opt ::=", + /* 258 */ "alias_opt ::= table_alias", + /* 259 */ "alias_opt ::= AS table_alias", + /* 260 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 261 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 262 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 263 */ "join_type ::=", + /* 264 */ "join_type ::= INNER", + /* 265 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 266 */ "set_quantifier_opt ::=", + /* 267 */ "set_quantifier_opt ::= DISTINCT", + /* 268 */ "set_quantifier_opt ::= ALL", + /* 269 */ "select_list ::= NK_STAR", + /* 270 */ "select_list ::= select_sublist", + /* 271 */ "select_sublist ::= select_item", + /* 272 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 273 */ "select_item ::= common_expression", + /* 274 */ "select_item ::= common_expression column_alias", + /* 275 */ "select_item ::= common_expression AS column_alias", + /* 276 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 277 */ "where_clause_opt ::=", + /* 278 */ "where_clause_opt ::= WHERE search_condition", + /* 279 */ "partition_by_clause_opt ::=", + /* 280 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 281 */ "twindow_clause_opt ::=", + /* 282 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP", + /* 283 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP", + /* 284 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 285 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 286 */ "sliding_opt ::=", + /* 287 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 288 */ "fill_opt ::=", + /* 289 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 290 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 291 */ "fill_mode ::= NONE", + /* 292 */ "fill_mode ::= PREV", + /* 293 */ "fill_mode ::= NULL", + /* 294 */ "fill_mode ::= LINEAR", + /* 295 */ "fill_mode ::= NEXT", + /* 296 */ "group_by_clause_opt ::=", + /* 297 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 298 */ "group_by_list ::= expression", + /* 299 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 300 */ "having_clause_opt ::=", + /* 301 */ "having_clause_opt ::= HAVING search_condition", + /* 302 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 303 */ "query_expression_body ::= query_primary", + /* 304 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 305 */ "query_primary ::= query_specification", + /* 306 */ "order_by_clause_opt ::=", + /* 307 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 308 */ "slimit_clause_opt ::=", + /* 309 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 310 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 311 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 312 */ "limit_clause_opt ::=", + /* 313 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 314 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 315 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 316 */ "subquery ::= NK_LP query_expression NK_RP", + /* 317 */ "search_condition ::= common_expression", + /* 318 */ "sort_specification_list ::= sort_specification", + /* 319 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 320 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 321 */ "ordering_specification_opt ::=", + /* 322 */ "ordering_specification_opt ::= ASC", + /* 323 */ "ordering_specification_opt ::= DESC", + /* 324 */ "null_ordering_opt ::=", + /* 325 */ "null_ordering_opt ::= NULLS FIRST", + /* 326 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1403,34 +1418,36 @@ static void yy_destructor( case 201: /* sliding_opt */ case 202: /* func */ case 205: /* query_expression */ - case 208: /* expression */ - case 209: /* column_reference */ - case 210: /* subquery */ - case 211: /* predicate */ - case 214: /* in_predicate_value */ - case 215: /* boolean_value_expression */ - case 216: /* boolean_primary */ - case 217: /* common_expression */ - case 218: /* from_clause */ - case 219: /* table_reference_list */ - case 220: /* table_reference */ - case 221: /* table_primary */ - case 222: /* joined_table */ - case 224: /* parenthesized_joined_table */ - case 226: /* search_condition */ - case 227: /* query_specification */ - case 230: /* where_clause_opt */ - case 232: /* twindow_clause_opt */ - case 234: /* having_clause_opt */ - case 236: /* select_item */ - case 237: /* fill_opt */ - case 240: /* query_expression_body */ - case 242: /* slimit_clause_opt */ - case 243: /* limit_clause_opt */ - case 244: /* query_primary */ - case 246: /* sort_specification */ + case 206: /* signed */ + case 207: /* signed_literal */ + case 210: /* expression */ + case 211: /* column_reference */ + case 212: /* subquery */ + case 213: /* predicate */ + case 216: /* in_predicate_value */ + case 217: /* boolean_value_expression */ + case 218: /* boolean_primary */ + case 219: /* common_expression */ + case 220: /* from_clause */ + case 221: /* table_reference_list */ + case 222: /* table_reference */ + case 223: /* table_primary */ + case 224: /* joined_table */ + case 226: /* parenthesized_joined_table */ + case 228: /* search_condition */ + case 229: /* query_specification */ + case 232: /* where_clause_opt */ + case 234: /* twindow_clause_opt */ + case 236: /* having_clause_opt */ + case 238: /* select_item */ + case 239: /* fill_opt */ + case 242: /* query_expression_body */ + case 244: /* slimit_clause_opt */ + case 245: /* limit_clause_opt */ + case 246: /* query_primary */ + case 248: /* sort_specification */ { - nodesDestroyNode((yypminor->yy26)); + nodesDestroyNode((yypminor->yy348)); } break; case 161: /* account_options */ @@ -1449,16 +1466,16 @@ static void yy_destructor( case 196: /* function_name */ case 197: /* index_name */ case 204: /* topic_name */ - case 206: /* table_alias */ - case 207: /* column_alias */ - case 223: /* alias_opt */ + case 208: /* table_alias */ + case 209: /* column_alias */ + case 225: /* alias_opt */ { } break; case 168: /* not_exists_opt */ case 171: /* exists_opt */ - case 228: /* set_quantifier_opt */ + case 230: /* set_quantifier_opt */ { } @@ -1480,15 +1497,15 @@ static void yy_destructor( case 192: /* func_name_list */ case 199: /* func_list */ case 203: /* expression_list */ - case 229: /* select_list */ - case 231: /* partition_by_clause_opt */ - case 233: /* group_by_clause_opt */ - case 235: /* select_sublist */ - case 239: /* group_by_list */ - case 241: /* order_by_clause_opt */ - case 245: /* sort_specification_list */ + case 231: /* select_list */ + case 233: /* partition_by_clause_opt */ + case 235: /* group_by_clause_opt */ + case 237: /* select_sublist */ + case 241: /* group_by_list */ + case 243: /* order_by_clause_opt */ + case 247: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy64)); + nodesDestroyList((yypminor->yy358)); } break; case 184: /* type_name */ @@ -1496,28 +1513,28 @@ static void yy_destructor( } break; - case 212: /* compare_op */ - case 213: /* in_op */ + case 214: /* compare_op */ + case 215: /* in_op */ { } break; - case 225: /* join_type */ + case 227: /* join_type */ { } break; - case 238: /* fill_mode */ + case 240: /* fill_mode */ { } break; - case 247: /* ordering_specification_opt */ + case 249: /* ordering_specification_opt */ { } break; - case 248: /* null_ordering_opt */ + case 250: /* null_ordering_opt */ { } @@ -1998,140 +2015,151 @@ static const struct { { 163, -2 }, /* (179) literal ::= TIMESTAMP NK_STRING */ { 163, -1 }, /* (180) literal ::= duration_literal */ { 200, -1 }, /* (181) duration_literal ::= NK_VARIABLE */ - { 187, -1 }, /* (182) literal_list ::= literal */ - { 187, -3 }, /* (183) literal_list ::= literal_list NK_COMMA literal */ - { 169, -1 }, /* (184) db_name ::= NK_ID */ - { 190, -1 }, /* (185) table_name ::= NK_ID */ - { 183, -1 }, /* (186) column_name ::= NK_ID */ - { 196, -1 }, /* (187) function_name ::= NK_ID */ - { 206, -1 }, /* (188) table_alias ::= NK_ID */ - { 207, -1 }, /* (189) column_alias ::= NK_ID */ - { 165, -1 }, /* (190) user_name ::= NK_ID */ - { 197, -1 }, /* (191) index_name ::= NK_ID */ - { 204, -1 }, /* (192) topic_name ::= NK_ID */ - { 208, -1 }, /* (193) expression ::= literal */ - { 208, -1 }, /* (194) expression ::= column_reference */ - { 208, -4 }, /* (195) expression ::= function_name NK_LP expression_list NK_RP */ - { 208, -4 }, /* (196) expression ::= function_name NK_LP NK_STAR NK_RP */ - { 208, -1 }, /* (197) expression ::= subquery */ - { 208, -3 }, /* (198) expression ::= NK_LP expression NK_RP */ - { 208, -2 }, /* (199) expression ::= NK_PLUS expression */ - { 208, -2 }, /* (200) expression ::= NK_MINUS expression */ - { 208, -3 }, /* (201) expression ::= expression NK_PLUS expression */ - { 208, -3 }, /* (202) expression ::= expression NK_MINUS expression */ - { 208, -3 }, /* (203) expression ::= expression NK_STAR expression */ - { 208, -3 }, /* (204) expression ::= expression NK_SLASH expression */ - { 208, -3 }, /* (205) expression ::= expression NK_REM expression */ - { 203, -1 }, /* (206) expression_list ::= expression */ - { 203, -3 }, /* (207) expression_list ::= expression_list NK_COMMA expression */ - { 209, -1 }, /* (208) column_reference ::= column_name */ - { 209, -3 }, /* (209) column_reference ::= table_name NK_DOT column_name */ - { 211, -3 }, /* (210) predicate ::= expression compare_op expression */ - { 211, -5 }, /* (211) predicate ::= expression BETWEEN expression AND expression */ - { 211, -6 }, /* (212) predicate ::= expression NOT BETWEEN expression AND expression */ - { 211, -3 }, /* (213) predicate ::= expression IS NULL */ - { 211, -4 }, /* (214) predicate ::= expression IS NOT NULL */ - { 211, -3 }, /* (215) predicate ::= expression in_op in_predicate_value */ - { 212, -1 }, /* (216) compare_op ::= NK_LT */ - { 212, -1 }, /* (217) compare_op ::= NK_GT */ - { 212, -1 }, /* (218) compare_op ::= NK_LE */ - { 212, -1 }, /* (219) compare_op ::= NK_GE */ - { 212, -1 }, /* (220) compare_op ::= NK_NE */ - { 212, -1 }, /* (221) compare_op ::= NK_EQ */ - { 212, -1 }, /* (222) compare_op ::= LIKE */ - { 212, -2 }, /* (223) compare_op ::= NOT LIKE */ - { 212, -1 }, /* (224) compare_op ::= MATCH */ - { 212, -1 }, /* (225) compare_op ::= NMATCH */ - { 213, -1 }, /* (226) in_op ::= IN */ - { 213, -2 }, /* (227) in_op ::= NOT IN */ - { 214, -3 }, /* (228) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 215, -1 }, /* (229) boolean_value_expression ::= boolean_primary */ - { 215, -2 }, /* (230) boolean_value_expression ::= NOT boolean_primary */ - { 215, -3 }, /* (231) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 215, -3 }, /* (232) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 216, -1 }, /* (233) boolean_primary ::= predicate */ - { 216, -3 }, /* (234) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 217, -1 }, /* (235) common_expression ::= expression */ - { 217, -1 }, /* (236) common_expression ::= boolean_value_expression */ - { 218, -2 }, /* (237) from_clause ::= FROM table_reference_list */ - { 219, -1 }, /* (238) table_reference_list ::= table_reference */ - { 219, -3 }, /* (239) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 220, -1 }, /* (240) table_reference ::= table_primary */ - { 220, -1 }, /* (241) table_reference ::= joined_table */ - { 221, -2 }, /* (242) table_primary ::= table_name alias_opt */ - { 221, -4 }, /* (243) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 221, -2 }, /* (244) table_primary ::= subquery alias_opt */ - { 221, -1 }, /* (245) table_primary ::= parenthesized_joined_table */ - { 223, 0 }, /* (246) alias_opt ::= */ - { 223, -1 }, /* (247) alias_opt ::= table_alias */ - { 223, -2 }, /* (248) alias_opt ::= AS table_alias */ - { 224, -3 }, /* (249) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 224, -3 }, /* (250) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 222, -6 }, /* (251) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 225, 0 }, /* (252) join_type ::= */ - { 225, -1 }, /* (253) join_type ::= INNER */ - { 227, -9 }, /* (254) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 228, 0 }, /* (255) set_quantifier_opt ::= */ - { 228, -1 }, /* (256) set_quantifier_opt ::= DISTINCT */ - { 228, -1 }, /* (257) set_quantifier_opt ::= ALL */ - { 229, -1 }, /* (258) select_list ::= NK_STAR */ - { 229, -1 }, /* (259) select_list ::= select_sublist */ - { 235, -1 }, /* (260) select_sublist ::= select_item */ - { 235, -3 }, /* (261) select_sublist ::= select_sublist NK_COMMA select_item */ - { 236, -1 }, /* (262) select_item ::= common_expression */ - { 236, -2 }, /* (263) select_item ::= common_expression column_alias */ - { 236, -3 }, /* (264) select_item ::= common_expression AS column_alias */ - { 236, -3 }, /* (265) select_item ::= table_name NK_DOT NK_STAR */ - { 230, 0 }, /* (266) where_clause_opt ::= */ - { 230, -2 }, /* (267) where_clause_opt ::= WHERE search_condition */ - { 231, 0 }, /* (268) partition_by_clause_opt ::= */ - { 231, -3 }, /* (269) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 232, 0 }, /* (270) twindow_clause_opt ::= */ - { 232, -6 }, /* (271) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ - { 232, -4 }, /* (272) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ - { 232, -6 }, /* (273) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 232, -8 }, /* (274) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 201, 0 }, /* (275) sliding_opt ::= */ - { 201, -4 }, /* (276) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 237, 0 }, /* (277) fill_opt ::= */ - { 237, -4 }, /* (278) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 237, -6 }, /* (279) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 238, -1 }, /* (280) fill_mode ::= NONE */ - { 238, -1 }, /* (281) fill_mode ::= PREV */ - { 238, -1 }, /* (282) fill_mode ::= NULL */ - { 238, -1 }, /* (283) fill_mode ::= LINEAR */ - { 238, -1 }, /* (284) fill_mode ::= NEXT */ - { 233, 0 }, /* (285) group_by_clause_opt ::= */ - { 233, -3 }, /* (286) group_by_clause_opt ::= GROUP BY group_by_list */ - { 239, -1 }, /* (287) group_by_list ::= expression */ - { 239, -3 }, /* (288) group_by_list ::= group_by_list NK_COMMA expression */ - { 234, 0 }, /* (289) having_clause_opt ::= */ - { 234, -2 }, /* (290) having_clause_opt ::= HAVING search_condition */ - { 205, -4 }, /* (291) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 240, -1 }, /* (292) query_expression_body ::= query_primary */ - { 240, -4 }, /* (293) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 244, -1 }, /* (294) query_primary ::= query_specification */ - { 241, 0 }, /* (295) order_by_clause_opt ::= */ - { 241, -3 }, /* (296) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 242, 0 }, /* (297) slimit_clause_opt ::= */ - { 242, -2 }, /* (298) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 242, -4 }, /* (299) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 242, -4 }, /* (300) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 243, 0 }, /* (301) limit_clause_opt ::= */ - { 243, -2 }, /* (302) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 243, -4 }, /* (303) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 243, -4 }, /* (304) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 210, -3 }, /* (305) subquery ::= NK_LP query_expression NK_RP */ - { 226, -1 }, /* (306) search_condition ::= common_expression */ - { 245, -1 }, /* (307) sort_specification_list ::= sort_specification */ - { 245, -3 }, /* (308) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 246, -3 }, /* (309) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 247, 0 }, /* (310) ordering_specification_opt ::= */ - { 247, -1 }, /* (311) ordering_specification_opt ::= ASC */ - { 247, -1 }, /* (312) ordering_specification_opt ::= DESC */ - { 248, 0 }, /* (313) null_ordering_opt ::= */ - { 248, -2 }, /* (314) null_ordering_opt ::= NULLS FIRST */ - { 248, -2 }, /* (315) null_ordering_opt ::= NULLS LAST */ + { 206, -1 }, /* (182) signed ::= NK_INTEGER */ + { 206, -2 }, /* (183) signed ::= NK_PLUS NK_INTEGER */ + { 206, -2 }, /* (184) signed ::= NK_MINUS NK_INTEGER */ + { 206, -1 }, /* (185) signed ::= NK_FLOAT */ + { 206, -2 }, /* (186) signed ::= NK_PLUS NK_FLOAT */ + { 206, -2 }, /* (187) signed ::= NK_MINUS NK_FLOAT */ + { 207, -1 }, /* (188) signed_literal ::= signed */ + { 207, -1 }, /* (189) signed_literal ::= NK_STRING */ + { 207, -1 }, /* (190) signed_literal ::= NK_BOOL */ + { 207, -2 }, /* (191) signed_literal ::= TIMESTAMP NK_STRING */ + { 207, -1 }, /* (192) signed_literal ::= duration_literal */ + { 187, -1 }, /* (193) literal_list ::= signed_literal */ + { 187, -3 }, /* (194) literal_list ::= literal_list NK_COMMA signed_literal */ + { 169, -1 }, /* (195) db_name ::= NK_ID */ + { 190, -1 }, /* (196) table_name ::= NK_ID */ + { 183, -1 }, /* (197) column_name ::= NK_ID */ + { 196, -1 }, /* (198) function_name ::= NK_ID */ + { 208, -1 }, /* (199) table_alias ::= NK_ID */ + { 209, -1 }, /* (200) column_alias ::= NK_ID */ + { 165, -1 }, /* (201) user_name ::= NK_ID */ + { 197, -1 }, /* (202) index_name ::= NK_ID */ + { 204, -1 }, /* (203) topic_name ::= NK_ID */ + { 210, -1 }, /* (204) expression ::= literal */ + { 210, -1 }, /* (205) expression ::= column_reference */ + { 210, -4 }, /* (206) expression ::= function_name NK_LP expression_list NK_RP */ + { 210, -4 }, /* (207) expression ::= function_name NK_LP NK_STAR NK_RP */ + { 210, -1 }, /* (208) expression ::= subquery */ + { 210, -3 }, /* (209) expression ::= NK_LP expression NK_RP */ + { 210, -2 }, /* (210) expression ::= NK_PLUS expression */ + { 210, -2 }, /* (211) expression ::= NK_MINUS expression */ + { 210, -3 }, /* (212) expression ::= expression NK_PLUS expression */ + { 210, -3 }, /* (213) expression ::= expression NK_MINUS expression */ + { 210, -3 }, /* (214) expression ::= expression NK_STAR expression */ + { 210, -3 }, /* (215) expression ::= expression NK_SLASH expression */ + { 210, -3 }, /* (216) expression ::= expression NK_REM expression */ + { 203, -1 }, /* (217) expression_list ::= expression */ + { 203, -3 }, /* (218) expression_list ::= expression_list NK_COMMA expression */ + { 211, -1 }, /* (219) column_reference ::= column_name */ + { 211, -3 }, /* (220) column_reference ::= table_name NK_DOT column_name */ + { 213, -3 }, /* (221) predicate ::= expression compare_op expression */ + { 213, -5 }, /* (222) predicate ::= expression BETWEEN expression AND expression */ + { 213, -6 }, /* (223) predicate ::= expression NOT BETWEEN expression AND expression */ + { 213, -3 }, /* (224) predicate ::= expression IS NULL */ + { 213, -4 }, /* (225) predicate ::= expression IS NOT NULL */ + { 213, -3 }, /* (226) predicate ::= expression in_op in_predicate_value */ + { 214, -1 }, /* (227) compare_op ::= NK_LT */ + { 214, -1 }, /* (228) compare_op ::= NK_GT */ + { 214, -1 }, /* (229) compare_op ::= NK_LE */ + { 214, -1 }, /* (230) compare_op ::= NK_GE */ + { 214, -1 }, /* (231) compare_op ::= NK_NE */ + { 214, -1 }, /* (232) compare_op ::= NK_EQ */ + { 214, -1 }, /* (233) compare_op ::= LIKE */ + { 214, -2 }, /* (234) compare_op ::= NOT LIKE */ + { 214, -1 }, /* (235) compare_op ::= MATCH */ + { 214, -1 }, /* (236) compare_op ::= NMATCH */ + { 215, -1 }, /* (237) in_op ::= IN */ + { 215, -2 }, /* (238) in_op ::= NOT IN */ + { 216, -3 }, /* (239) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 217, -1 }, /* (240) boolean_value_expression ::= boolean_primary */ + { 217, -2 }, /* (241) boolean_value_expression ::= NOT boolean_primary */ + { 217, -3 }, /* (242) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 217, -3 }, /* (243) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 218, -1 }, /* (244) boolean_primary ::= predicate */ + { 218, -3 }, /* (245) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 219, -1 }, /* (246) common_expression ::= expression */ + { 219, -1 }, /* (247) common_expression ::= boolean_value_expression */ + { 220, -2 }, /* (248) from_clause ::= FROM table_reference_list */ + { 221, -1 }, /* (249) table_reference_list ::= table_reference */ + { 221, -3 }, /* (250) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 222, -1 }, /* (251) table_reference ::= table_primary */ + { 222, -1 }, /* (252) table_reference ::= joined_table */ + { 223, -2 }, /* (253) table_primary ::= table_name alias_opt */ + { 223, -4 }, /* (254) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 223, -2 }, /* (255) table_primary ::= subquery alias_opt */ + { 223, -1 }, /* (256) table_primary ::= parenthesized_joined_table */ + { 225, 0 }, /* (257) alias_opt ::= */ + { 225, -1 }, /* (258) alias_opt ::= table_alias */ + { 225, -2 }, /* (259) alias_opt ::= AS table_alias */ + { 226, -3 }, /* (260) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 226, -3 }, /* (261) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 224, -6 }, /* (262) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 227, 0 }, /* (263) join_type ::= */ + { 227, -1 }, /* (264) join_type ::= INNER */ + { 229, -9 }, /* (265) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 230, 0 }, /* (266) set_quantifier_opt ::= */ + { 230, -1 }, /* (267) set_quantifier_opt ::= DISTINCT */ + { 230, -1 }, /* (268) set_quantifier_opt ::= ALL */ + { 231, -1 }, /* (269) select_list ::= NK_STAR */ + { 231, -1 }, /* (270) select_list ::= select_sublist */ + { 237, -1 }, /* (271) select_sublist ::= select_item */ + { 237, -3 }, /* (272) select_sublist ::= select_sublist NK_COMMA select_item */ + { 238, -1 }, /* (273) select_item ::= common_expression */ + { 238, -2 }, /* (274) select_item ::= common_expression column_alias */ + { 238, -3 }, /* (275) select_item ::= common_expression AS column_alias */ + { 238, -3 }, /* (276) select_item ::= table_name NK_DOT NK_STAR */ + { 232, 0 }, /* (277) where_clause_opt ::= */ + { 232, -2 }, /* (278) where_clause_opt ::= WHERE search_condition */ + { 233, 0 }, /* (279) partition_by_clause_opt ::= */ + { 233, -3 }, /* (280) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 234, 0 }, /* (281) twindow_clause_opt ::= */ + { 234, -6 }, /* (282) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ + { 234, -4 }, /* (283) twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ + { 234, -6 }, /* (284) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 234, -8 }, /* (285) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 201, 0 }, /* (286) sliding_opt ::= */ + { 201, -4 }, /* (287) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 239, 0 }, /* (288) fill_opt ::= */ + { 239, -4 }, /* (289) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 239, -6 }, /* (290) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 240, -1 }, /* (291) fill_mode ::= NONE */ + { 240, -1 }, /* (292) fill_mode ::= PREV */ + { 240, -1 }, /* (293) fill_mode ::= NULL */ + { 240, -1 }, /* (294) fill_mode ::= LINEAR */ + { 240, -1 }, /* (295) fill_mode ::= NEXT */ + { 235, 0 }, /* (296) group_by_clause_opt ::= */ + { 235, -3 }, /* (297) group_by_clause_opt ::= GROUP BY group_by_list */ + { 241, -1 }, /* (298) group_by_list ::= expression */ + { 241, -3 }, /* (299) group_by_list ::= group_by_list NK_COMMA expression */ + { 236, 0 }, /* (300) having_clause_opt ::= */ + { 236, -2 }, /* (301) having_clause_opt ::= HAVING search_condition */ + { 205, -4 }, /* (302) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 242, -1 }, /* (303) query_expression_body ::= query_primary */ + { 242, -4 }, /* (304) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 246, -1 }, /* (305) query_primary ::= query_specification */ + { 243, 0 }, /* (306) order_by_clause_opt ::= */ + { 243, -3 }, /* (307) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 244, 0 }, /* (308) slimit_clause_opt ::= */ + { 244, -2 }, /* (309) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 244, -4 }, /* (310) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 244, -4 }, /* (311) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 245, 0 }, /* (312) limit_clause_opt ::= */ + { 245, -2 }, /* (313) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 245, -4 }, /* (314) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 245, -4 }, /* (315) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 212, -3 }, /* (316) subquery ::= NK_LP query_expression NK_RP */ + { 228, -1 }, /* (317) search_condition ::= common_expression */ + { 247, -1 }, /* (318) sort_specification_list ::= sort_specification */ + { 247, -3 }, /* (319) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 248, -3 }, /* (320) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 249, 0 }, /* (321) ordering_specification_opt ::= */ + { 249, -1 }, /* (322) ordering_specification_opt ::= ASC */ + { 249, -1 }, /* (323) ordering_specification_opt ::= DESC */ + { 250, 0 }, /* (324) null_ordering_opt ::= */ + { 250, -2 }, /* (325) null_ordering_opt ::= NULLS FIRST */ + { 250, -2 }, /* (326) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2268,31 +2296,31 @@ static YYACTIONTYPE yy_reduce( yy_destructor(yypParser,163,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy353, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy269, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy353, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy269, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy353, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy269, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy353); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy269); } break; case 28: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy353, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy269, NULL); } break; case 30: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy353, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy269, &yymsp[0].minor.yy0); } break; case 31: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 32: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy353); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy269); } break; case 33: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); } @@ -2312,17 +2340,17 @@ static YYACTIONTYPE yy_reduce( case 38: /* dnode_endpoint ::= NK_STRING */ case 39: /* dnode_host_name ::= NK_ID */ yytestcase(yyruleno==39); case 40: /* dnode_host_name ::= NK_IPTOKEN */ yytestcase(yyruleno==40); - case 184: /* db_name ::= NK_ID */ yytestcase(yyruleno==184); - case 185: /* table_name ::= NK_ID */ yytestcase(yyruleno==185); - case 186: /* column_name ::= NK_ID */ yytestcase(yyruleno==186); - case 187: /* function_name ::= NK_ID */ yytestcase(yyruleno==187); - case 188: /* table_alias ::= NK_ID */ yytestcase(yyruleno==188); - case 189: /* column_alias ::= NK_ID */ yytestcase(yyruleno==189); - case 190: /* user_name ::= NK_ID */ yytestcase(yyruleno==190); - case 191: /* index_name ::= NK_ID */ yytestcase(yyruleno==191); - case 192: /* topic_name ::= NK_ID */ yytestcase(yyruleno==192); -{ yylhsminor.yy353 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy353 = yylhsminor.yy353; + case 195: /* db_name ::= NK_ID */ yytestcase(yyruleno==195); + case 196: /* table_name ::= NK_ID */ yytestcase(yyruleno==196); + case 197: /* column_name ::= NK_ID */ yytestcase(yyruleno==197); + case 198: /* function_name ::= NK_ID */ yytestcase(yyruleno==198); + case 199: /* table_alias ::= NK_ID */ yytestcase(yyruleno==199); + case 200: /* column_alias ::= NK_ID */ yytestcase(yyruleno==200); + case 201: /* user_name ::= NK_ID */ yytestcase(yyruleno==201); + case 202: /* index_name ::= NK_ID */ yytestcase(yyruleno==202); + case 203: /* topic_name ::= NK_ID */ yytestcase(yyruleno==203); +{ yylhsminor.yy269 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy269 = yylhsminor.yy269; break; case 41: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -2340,148 +2368,148 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL); } break; case 46: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy107, &yymsp[-1].minor.yy353, yymsp[0].minor.yy26); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy345, &yymsp[-1].minor.yy269, yymsp[0].minor.yy348); } break; case 47: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy107, &yymsp[0].minor.yy353); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy345, &yymsp[0].minor.yy269); } break; case 48: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); } break; case 49: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy353); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy269); } break; case 50: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy353, yymsp[0].minor.yy26); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy269, yymsp[0].minor.yy348); } break; case 51: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy107 = true; } +{ yymsp[-2].minor.yy345 = true; } break; case 52: /* not_exists_opt ::= */ case 54: /* exists_opt ::= */ yytestcase(yyruleno==54); - case 255: /* set_quantifier_opt ::= */ yytestcase(yyruleno==255); -{ yymsp[1].minor.yy107 = false; } + case 266: /* set_quantifier_opt ::= */ yytestcase(yyruleno==266); +{ yymsp[1].minor.yy345 = false; } break; case 53: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy107 = true; } +{ yymsp[-1].minor.yy345 = true; } break; case 55: /* db_options ::= */ -{ yymsp[1].minor.yy26 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy348 = createDefaultDatabaseOptions(pCxt); } break; case 56: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_BLOCKS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 57: /* db_options ::= db_options CACHE NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_CACHE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 58: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 59: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 60: /* db_options ::= db_options DAYS NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 61: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 62: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 63: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 64: /* db_options ::= db_options KEEP NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 65: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 66: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_QUORUM, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 67: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 68: /* db_options ::= db_options TTL NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 69: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 70: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 71: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 72: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_STREAM_MODE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 73: /* db_options ::= db_options RETENTIONS NK_STRING */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_RETENTIONS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 74: /* db_options ::= db_options FILE_FACTOR NK_FLOAT */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-2].minor.yy26, DB_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-2].minor.yy348, DB_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 75: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy26 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy26 = setDatabaseOption(pCxt, yylhsminor.yy26, yymsp[0].minor.yy443.type, &yymsp[0].minor.yy443.val); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createDefaultAlterDatabaseOptions(pCxt); yylhsminor.yy348 = setDatabaseOption(pCxt, yylhsminor.yy348, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 76: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy26 = setDatabaseOption(pCxt, yymsp[-1].minor.yy26, yymsp[0].minor.yy443.type, &yymsp[0].minor.yy443.val); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setDatabaseOption(pCxt, yymsp[-1].minor.yy348, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; case 77: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy443.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 78: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy443.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 79: /* alter_db_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy443.type = DB_OPTION_KEEP; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = DB_OPTION_KEEP; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 80: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy443.type = DB_OPTION_WAL; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = DB_OPTION_WAL; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 81: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy443.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 82: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy443.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 83: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 85: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==85); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy107, yymsp[-5].minor.yy26, yymsp[-3].minor.yy64, yymsp[-1].minor.yy64, yymsp[0].minor.yy26); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy345, yymsp[-5].minor.yy348, yymsp[-3].minor.yy358, yymsp[-1].minor.yy358, yymsp[0].minor.yy348); } break; case 84: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy64); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy358); } break; case 86: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy64); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy358); } break; case 87: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy107, yymsp[0].minor.yy26); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy345, yymsp[0].minor.yy348); } break; case 88: /* cmd ::= SHOW TABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); } @@ -2492,47 +2520,47 @@ static YYACTIONTYPE yy_reduce( case 90: /* cmd ::= ALTER TABLE alter_table_clause */ case 91: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==91); case 174: /* cmd ::= query_expression */ yytestcase(yyruleno==174); -{ pCxt->pRootNode = yymsp[0].minor.yy26; } +{ pCxt->pRootNode = yymsp[0].minor.yy348; } break; case 92: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy26 = createAlterTableOption(pCxt, yymsp[-1].minor.yy26, yymsp[0].minor.yy26); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableOption(pCxt, yymsp[-1].minor.yy348, yymsp[0].minor.yy348); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; case 93: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy26 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy26, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy353, yymsp[0].minor.yy370); } - yymsp[-4].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy348, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy269, yymsp[0].minor.yy218); } + yymsp[-4].minor.yy348 = yylhsminor.yy348; break; case 94: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy26 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy26, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy353); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy348, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy269); } + yymsp[-3].minor.yy348 = yylhsminor.yy348; break; case 95: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy26 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy26, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy353, yymsp[0].minor.yy370); } - yymsp[-4].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy348, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy269, yymsp[0].minor.yy218); } + yymsp[-4].minor.yy348 = yylhsminor.yy348; break; case 96: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy26 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy26, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy353, &yymsp[0].minor.yy353); } - yymsp[-4].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy348, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy269, &yymsp[0].minor.yy269); } + yymsp[-4].minor.yy348 = yylhsminor.yy348; break; case 97: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy26 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy26, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy353, yymsp[0].minor.yy370); } - yymsp[-4].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy348, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy269, yymsp[0].minor.yy218); } + yymsp[-4].minor.yy348 = yylhsminor.yy348; break; case 98: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy26 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy26, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy353); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy348, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy269); } + yymsp[-3].minor.yy348 = yylhsminor.yy348; break; case 99: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy26 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy26, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy353, yymsp[0].minor.yy370); } - yymsp[-4].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy348, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy269, yymsp[0].minor.yy218); } + yymsp[-4].minor.yy348 = yylhsminor.yy348; break; case 100: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy26 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy26, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy353, &yymsp[0].minor.yy353); } - yymsp[-4].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy348, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy269, &yymsp[0].minor.yy269); } + yymsp[-4].minor.yy348 = yylhsminor.yy348; break; case 101: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy26 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy26, &yymsp[-2].minor.yy353, yymsp[0].minor.yy26); } - yymsp[-5].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy348, &yymsp[-2].minor.yy269, yymsp[0].minor.yy348); } + yymsp[-5].minor.yy348 = yylhsminor.yy348; break; case 102: /* multi_create_clause ::= create_subtable_clause */ case 105: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==105); @@ -2540,642 +2568,685 @@ static YYACTIONTYPE yy_reduce( case 153: /* col_name_list ::= col_name */ yytestcase(yyruleno==153); case 156: /* func_name_list ::= func_name */ yytestcase(yyruleno==156); case 165: /* func_list ::= func */ yytestcase(yyruleno==165); - case 260: /* select_sublist ::= select_item */ yytestcase(yyruleno==260); - case 307: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==307); -{ yylhsminor.yy64 = createNodeList(pCxt, yymsp[0].minor.yy26); } - yymsp[0].minor.yy64 = yylhsminor.yy64; + case 193: /* literal_list ::= signed_literal */ yytestcase(yyruleno==193); + case 271: /* select_sublist ::= select_item */ yytestcase(yyruleno==271); + case 318: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==318); +{ yylhsminor.yy358 = createNodeList(pCxt, yymsp[0].minor.yy348); } + yymsp[0].minor.yy358 = yylhsminor.yy358; break; case 103: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ case 106: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==106); -{ yylhsminor.yy64 = addNodeToList(pCxt, yymsp[-1].minor.yy64, yymsp[0].minor.yy26); } - yymsp[-1].minor.yy64 = yylhsminor.yy64; +{ yylhsminor.yy358 = addNodeToList(pCxt, yymsp[-1].minor.yy358, yymsp[0].minor.yy348); } + yymsp[-1].minor.yy358 = yylhsminor.yy358; break; case 104: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy26 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy107, yymsp[-7].minor.yy26, yymsp[-5].minor.yy26, yymsp[-4].minor.yy64, yymsp[-1].minor.yy64); } - yymsp[-8].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy345, yymsp[-7].minor.yy348, yymsp[-5].minor.yy348, yymsp[-4].minor.yy358, yymsp[-1].minor.yy358); } + yymsp[-8].minor.yy348 = yylhsminor.yy348; break; case 107: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy26 = createDropTableClause(pCxt, yymsp[-1].minor.yy107, yymsp[0].minor.yy26); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createDropTableClause(pCxt, yymsp[-1].minor.yy345, yymsp[0].minor.yy348); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; case 108: /* specific_tags_opt ::= */ case 139: /* tags_def_opt ::= */ yytestcase(yyruleno==139); - case 268: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==268); - case 285: /* group_by_clause_opt ::= */ yytestcase(yyruleno==285); - case 295: /* order_by_clause_opt ::= */ yytestcase(yyruleno==295); -{ yymsp[1].minor.yy64 = NULL; } + case 279: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==279); + case 296: /* group_by_clause_opt ::= */ yytestcase(yyruleno==296); + case 306: /* order_by_clause_opt ::= */ yytestcase(yyruleno==306); +{ yymsp[1].minor.yy358 = NULL; } break; case 109: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy64 = yymsp[-1].minor.yy64; } +{ yymsp[-2].minor.yy358 = yymsp[-1].minor.yy358; } break; case 110: /* full_table_name ::= table_name */ -{ yylhsminor.yy26 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy353, NULL); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy269, NULL); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 111: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy26 = createRealTableNode(pCxt, &yymsp[-2].minor.yy353, &yymsp[0].minor.yy353, NULL); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createRealTableNode(pCxt, &yymsp[-2].minor.yy269, &yymsp[0].minor.yy269, NULL); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 113: /* column_def_list ::= column_def_list NK_COMMA column_def */ case 154: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==154); case 157: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==157); case 166: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==166); - case 261: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==261); - case 308: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==308); -{ yylhsminor.yy64 = addNodeToList(pCxt, yymsp[-2].minor.yy64, yymsp[0].minor.yy26); } - yymsp[-2].minor.yy64 = yylhsminor.yy64; + case 194: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==194); + case 272: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==272); + case 319: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==319); +{ yylhsminor.yy358 = addNodeToList(pCxt, yymsp[-2].minor.yy358, yymsp[0].minor.yy348); } + yymsp[-2].minor.yy358 = yylhsminor.yy358; break; case 114: /* column_def ::= column_name type_name */ -{ yylhsminor.yy26 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy353, yymsp[0].minor.yy370, NULL); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy269, yymsp[0].minor.yy218, NULL); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; case 115: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy26 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy353, yymsp[-2].minor.yy370, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy269, yymsp[-2].minor.yy218, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy348 = yylhsminor.yy348; break; case 116: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 117: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 118: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 119: /* type_name ::= INT */ case 120: /* type_name ::= INTEGER */ yytestcase(yyruleno==120); -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_INT); } break; case 121: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 122: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 123: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 124: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy370 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy218 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 125: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 126: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy370 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy218 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 127: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy370 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy218 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 128: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy370 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy218 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 129: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy370 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy218 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 130: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy370 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy218 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 131: /* type_name ::= JSON */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 132: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy370 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy218 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 133: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 134: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 135: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy370 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy218 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 136: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy370 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy218 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 137: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy370 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy218 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 138: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy370 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy218 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 140: /* tags_def_opt ::= tags_def */ - case 259: /* select_list ::= select_sublist */ yytestcase(yyruleno==259); -{ yylhsminor.yy64 = yymsp[0].minor.yy64; } - yymsp[0].minor.yy64 = yylhsminor.yy64; + case 270: /* select_list ::= select_sublist */ yytestcase(yyruleno==270); +{ yylhsminor.yy358 = yymsp[0].minor.yy358; } + yymsp[0].minor.yy358 = yylhsminor.yy358; break; case 141: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy64 = yymsp[-1].minor.yy64; } +{ yymsp[-3].minor.yy358 = yymsp[-1].minor.yy358; } break; case 142: /* table_options ::= */ -{ yymsp[1].minor.yy26 = createDefaultTableOptions(pCxt); } +{ yymsp[1].minor.yy348 = createDefaultTableOptions(pCxt); } break; case 143: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy26 = setTableOption(pCxt, yymsp[-2].minor.yy26, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setTableOption(pCxt, yymsp[-2].minor.yy348, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 144: /* table_options ::= table_options KEEP NK_INTEGER */ -{ yylhsminor.yy26 = setTableOption(pCxt, yymsp[-2].minor.yy26, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setTableOption(pCxt, yymsp[-2].minor.yy348, TABLE_OPTION_KEEP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 145: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy26 = setTableOption(pCxt, yymsp[-2].minor.yy26, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setTableOption(pCxt, yymsp[-2].minor.yy348, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; case 146: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy26 = setTableSmaOption(pCxt, yymsp[-4].minor.yy26, yymsp[-1].minor.yy64); } - yymsp[-4].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setTableSmaOption(pCxt, yymsp[-4].minor.yy348, yymsp[-1].minor.yy358); } + yymsp[-4].minor.yy348 = yylhsminor.yy348; break; case 147: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ yylhsminor.yy26 = setTableRollupOption(pCxt, yymsp[-4].minor.yy26, yymsp[-1].minor.yy64); } - yymsp[-4].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setTableRollupOption(pCxt, yymsp[-4].minor.yy348, yymsp[-1].minor.yy358); } + yymsp[-4].minor.yy348 = yylhsminor.yy348; break; case 148: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy26 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy26 = setTableOption(pCxt, yylhsminor.yy26, yymsp[0].minor.yy443.type, &yymsp[0].minor.yy443.val); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createDefaultAlterTableOptions(pCxt); yylhsminor.yy348 = setTableOption(pCxt, yylhsminor.yy348, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 149: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy26 = setTableOption(pCxt, yymsp[-1].minor.yy26, yymsp[0].minor.yy443.type, &yymsp[0].minor.yy443.val); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = setTableOption(pCxt, yymsp[-1].minor.yy348, yymsp[0].minor.yy233.type, &yymsp[0].minor.yy233.val); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; case 150: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy443.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 151: /* alter_table_option ::= KEEP NK_INTEGER */ -{ yymsp[-1].minor.yy443.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 152: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy443.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy443.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy233.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy233.val = yymsp[0].minor.yy0; } break; case 155: /* col_name ::= column_name */ -{ yylhsminor.yy26 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy353); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy269); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 158: /* func_name ::= function_name */ -{ yylhsminor.yy26 = createFunctionNode(pCxt, &yymsp[0].minor.yy353, NULL); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createFunctionNode(pCxt, &yymsp[0].minor.yy269, NULL); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 159: /* cmd ::= CREATE SMA INDEX index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &yymsp[-3].minor.yy353, &yymsp[-1].minor.yy353, NULL, yymsp[0].minor.yy26); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &yymsp[-3].minor.yy269, &yymsp[-1].minor.yy269, NULL, yymsp[0].minor.yy348); } break; case 160: /* cmd ::= CREATE FULLTEXT INDEX index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, &yymsp[-5].minor.yy353, &yymsp[-3].minor.yy353, yymsp[-1].minor.yy64, NULL); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, &yymsp[-5].minor.yy269, &yymsp[-3].minor.yy269, yymsp[-1].minor.yy358, NULL); } break; case 161: /* cmd ::= DROP INDEX index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, &yymsp[-2].minor.yy353, &yymsp[0].minor.yy353); } +{ pCxt->pRootNode = createDropIndexStmt(pCxt, &yymsp[-2].minor.yy269, &yymsp[0].minor.yy269); } break; case 162: /* index_options ::= */ - case 266: /* where_clause_opt ::= */ yytestcase(yyruleno==266); - case 270: /* twindow_clause_opt ::= */ yytestcase(yyruleno==270); - case 275: /* sliding_opt ::= */ yytestcase(yyruleno==275); - case 277: /* fill_opt ::= */ yytestcase(yyruleno==277); - case 289: /* having_clause_opt ::= */ yytestcase(yyruleno==289); - case 297: /* slimit_clause_opt ::= */ yytestcase(yyruleno==297); - case 301: /* limit_clause_opt ::= */ yytestcase(yyruleno==301); -{ yymsp[1].minor.yy26 = NULL; } + case 277: /* where_clause_opt ::= */ yytestcase(yyruleno==277); + case 281: /* twindow_clause_opt ::= */ yytestcase(yyruleno==281); + case 286: /* sliding_opt ::= */ yytestcase(yyruleno==286); + case 288: /* fill_opt ::= */ yytestcase(yyruleno==288); + case 300: /* having_clause_opt ::= */ yytestcase(yyruleno==300); + case 308: /* slimit_clause_opt ::= */ yytestcase(yyruleno==308); + case 312: /* limit_clause_opt ::= */ yytestcase(yyruleno==312); +{ yymsp[1].minor.yy348 = NULL; } break; case 163: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy26 = createIndexOption(pCxt, yymsp[-6].minor.yy64, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), NULL, yymsp[0].minor.yy26); } +{ yymsp[-8].minor.yy348 = createIndexOption(pCxt, yymsp[-6].minor.yy358, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), NULL, yymsp[0].minor.yy348); } break; case 164: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy26 = createIndexOption(pCxt, yymsp[-8].minor.yy64, releaseRawExprNode(pCxt, yymsp[-4].minor.yy26), releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), yymsp[0].minor.yy26); } +{ yymsp[-10].minor.yy348 = createIndexOption(pCxt, yymsp[-8].minor.yy358, releaseRawExprNode(pCxt, yymsp[-4].minor.yy348), releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), yymsp[0].minor.yy348); } break; case 167: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy26 = createFunctionNode(pCxt, &yymsp[-3].minor.yy353, yymsp[-1].minor.yy64); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createFunctionNode(pCxt, &yymsp[-3].minor.yy269, yymsp[-1].minor.yy358); } + yymsp[-3].minor.yy348 = yylhsminor.yy348; break; case 168: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy107, &yymsp[-2].minor.yy353, yymsp[0].minor.yy26, NULL); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy345, &yymsp[-2].minor.yy269, yymsp[0].minor.yy348, NULL); } break; case 169: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy107, &yymsp[-2].minor.yy353, NULL, &yymsp[0].minor.yy353); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy345, &yymsp[-2].minor.yy269, NULL, &yymsp[0].minor.yy269); } break; case 170: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy107, &yymsp[0].minor.yy353); } +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy345, &yymsp[0].minor.yy269); } break; case 171: /* cmd ::= SHOW VGROUPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); } break; case 172: /* cmd ::= SHOW db_name NK_DOT VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &yymsp[-2].minor.yy353); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &yymsp[-2].minor.yy269); } break; case 173: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL); } break; case 175: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy26 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 176: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy26 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 177: /* literal ::= NK_STRING */ -{ yylhsminor.yy26 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 178: /* literal ::= NK_BOOL */ -{ yylhsminor.yy26 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 179: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; case 180: /* literal ::= duration_literal */ - case 193: /* expression ::= literal */ yytestcase(yyruleno==193); - case 194: /* expression ::= column_reference */ yytestcase(yyruleno==194); - case 197: /* expression ::= subquery */ yytestcase(yyruleno==197); - case 229: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==229); - case 233: /* boolean_primary ::= predicate */ yytestcase(yyruleno==233); - case 235: /* common_expression ::= expression */ yytestcase(yyruleno==235); - case 236: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==236); - case 238: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==238); - case 240: /* table_reference ::= table_primary */ yytestcase(yyruleno==240); - case 241: /* table_reference ::= joined_table */ yytestcase(yyruleno==241); - case 245: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==245); - case 292: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==292); - case 294: /* query_primary ::= query_specification */ yytestcase(yyruleno==294); -{ yylhsminor.yy26 = yymsp[0].minor.yy26; } - yymsp[0].minor.yy26 = yylhsminor.yy26; + case 188: /* signed_literal ::= signed */ yytestcase(yyruleno==188); + case 204: /* expression ::= literal */ yytestcase(yyruleno==204); + case 205: /* expression ::= column_reference */ yytestcase(yyruleno==205); + case 208: /* expression ::= subquery */ yytestcase(yyruleno==208); + case 240: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==240); + case 244: /* boolean_primary ::= predicate */ yytestcase(yyruleno==244); + case 246: /* common_expression ::= expression */ yytestcase(yyruleno==246); + case 247: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==247); + case 249: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==249); + case 251: /* table_reference ::= table_primary */ yytestcase(yyruleno==251); + case 252: /* table_reference ::= joined_table */ yytestcase(yyruleno==252); + case 256: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==256); + case 303: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==303); + case 305: /* query_primary ::= query_specification */ yytestcase(yyruleno==305); +{ yylhsminor.yy348 = yymsp[0].minor.yy348; } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; case 181: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy26 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy26 = yylhsminor.yy26; +{ yylhsminor.yy348 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; - case 182: /* literal_list ::= literal */ - case 206: /* expression_list ::= expression */ yytestcase(yyruleno==206); -{ yylhsminor.yy64 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy26)); } - yymsp[0].minor.yy64 = yylhsminor.yy64; + case 182: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; - case 183: /* literal_list ::= literal_list NK_COMMA literal */ - case 207: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==207); -{ yylhsminor.yy64 = addNodeToList(pCxt, yymsp[-2].minor.yy64, releaseRawExprNode(pCxt, yymsp[0].minor.yy26)); } - yymsp[-2].minor.yy64 = yylhsminor.yy64; + case 183: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; - case 195: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy353, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy353, yymsp[-1].minor.yy64)); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; - break; - case 196: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy353, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy353, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; - break; - case 198: /* expression ::= NK_LP expression NK_RP */ - case 234: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==234); -{ yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy26)); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 199: /* expression ::= NK_PLUS expression */ -{ - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy26)); - } - yymsp[-1].minor.yy26 = yylhsminor.yy26; - break; - case 200: /* expression ::= NK_MINUS expression */ -{ - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy26), NULL)); - } - yymsp[-1].minor.yy26 = yylhsminor.yy26; - break; - case 201: /* expression ::= expression NK_PLUS expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 202: /* expression ::= expression NK_MINUS expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 203: /* expression ::= expression NK_STAR expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 204: /* expression ::= expression NK_SLASH expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 205: /* expression ::= expression NK_REM expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 208: /* column_reference ::= column_name */ -{ yylhsminor.yy26 = createRawExprNode(pCxt, &yymsp[0].minor.yy353, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy353)); } - yymsp[0].minor.yy26 = yylhsminor.yy26; - break; - case 209: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy353, &yymsp[0].minor.yy353, createColumnNode(pCxt, &yymsp[-2].minor.yy353, &yymsp[0].minor.yy353)); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 210: /* predicate ::= expression compare_op expression */ - case 215: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==215); -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy80, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 211: /* predicate ::= expression BETWEEN expression AND expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy26), releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-4].minor.yy26 = yylhsminor.yy26; - break; - case 212: /* predicate ::= expression NOT BETWEEN expression AND expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[-5].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-5].minor.yy26 = yylhsminor.yy26; - break; - case 213: /* predicate ::= expression IS NULL */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), NULL)); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 214: /* predicate ::= expression IS NOT NULL */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy26), NULL)); - } - yymsp[-3].minor.yy26 = yylhsminor.yy26; - break; - case 216: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy80 = OP_TYPE_LOWER_THAN; } - break; - case 217: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy80 = OP_TYPE_GREATER_THAN; } - break; - case 218: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy80 = OP_TYPE_LOWER_EQUAL; } - break; - case 219: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy80 = OP_TYPE_GREATER_EQUAL; } - break; - case 220: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy80 = OP_TYPE_NOT_EQUAL; } - break; - case 221: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy80 = OP_TYPE_EQUAL; } - break; - case 222: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy80 = OP_TYPE_LIKE; } - break; - case 223: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy80 = OP_TYPE_NOT_LIKE; } - break; - case 224: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy80 = OP_TYPE_MATCH; } - break; - case 225: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy80 = OP_TYPE_NMATCH; } - break; - case 226: /* in_op ::= IN */ -{ yymsp[0].minor.yy80 = OP_TYPE_IN; } - break; - case 227: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy80 = OP_TYPE_NOT_IN; } - break; - case 228: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy64)); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 230: /* boolean_value_expression ::= NOT boolean_primary */ -{ - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy26), NULL)); - } - yymsp[-1].minor.yy26 = yylhsminor.yy26; - break; - case 231: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 232: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ -{ - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy26); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); - } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 237: /* from_clause ::= FROM table_reference_list */ - case 267: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==267); - case 290: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==290); -{ yymsp[-1].minor.yy26 = yymsp[0].minor.yy26; } - break; - case 239: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy26 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy26, yymsp[0].minor.yy26, NULL); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 242: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy26 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy353, &yymsp[0].minor.yy353); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; - break; - case 243: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy26 = createRealTableNode(pCxt, &yymsp[-3].minor.yy353, &yymsp[-1].minor.yy353, &yymsp[0].minor.yy353); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; - break; - case 244: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy26 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy26), &yymsp[0].minor.yy353); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; - break; - case 246: /* alias_opt ::= */ -{ yymsp[1].minor.yy353 = nil_token; } - break; - case 247: /* alias_opt ::= table_alias */ -{ yylhsminor.yy353 = yymsp[0].minor.yy353; } - yymsp[0].minor.yy353 = yylhsminor.yy353; - break; - case 248: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy353 = yymsp[0].minor.yy353; } - break; - case 249: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 250: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==250); -{ yymsp[-2].minor.yy26 = yymsp[-1].minor.yy26; } - break; - case 251: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy26 = createJoinTableNode(pCxt, yymsp[-4].minor.yy372, yymsp[-5].minor.yy26, yymsp[-2].minor.yy26, yymsp[0].minor.yy26); } - yymsp[-5].minor.yy26 = yylhsminor.yy26; - break; - case 252: /* join_type ::= */ -{ yymsp[1].minor.yy372 = JOIN_TYPE_INNER; } - break; - case 253: /* join_type ::= INNER */ -{ yymsp[0].minor.yy372 = JOIN_TYPE_INNER; } - break; - case 254: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 184: /* signed ::= NK_MINUS NK_INTEGER */ { - yymsp[-8].minor.yy26 = createSelectStmt(pCxt, yymsp[-7].minor.yy107, yymsp[-6].minor.yy64, yymsp[-5].minor.yy26); - yymsp[-8].minor.yy26 = addWhereClause(pCxt, yymsp[-8].minor.yy26, yymsp[-4].minor.yy26); - yymsp[-8].minor.yy26 = addPartitionByClause(pCxt, yymsp[-8].minor.yy26, yymsp[-3].minor.yy64); - yymsp[-8].minor.yy26 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy26, yymsp[-2].minor.yy26); - yymsp[-8].minor.yy26 = addGroupByClause(pCxt, yymsp[-8].minor.yy26, yymsp[-1].minor.yy64); - yymsp[-8].minor.yy26 = addHavingClause(pCxt, yymsp[-8].minor.yy26, yymsp[0].minor.yy26); + SToken t = yymsp[-1].minor.yy0; + t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; + yylhsminor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; - case 256: /* set_quantifier_opt ::= DISTINCT */ -{ yymsp[0].minor.yy107 = true; } + case 185: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; - case 257: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy107 = false; } + case 186: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 258: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy64 = NULL; } - break; - case 262: /* select_item ::= common_expression */ -{ - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy26); - yylhsminor.yy26 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy26), &t); - } - yymsp[0].minor.yy26 = yylhsminor.yy26; - break; - case 263: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy26 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy26), &yymsp[0].minor.yy353); } - yymsp[-1].minor.yy26 = yylhsminor.yy26; - break; - case 264: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy26 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), &yymsp[0].minor.yy353); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 265: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy26 = createColumnNode(pCxt, &yymsp[-2].minor.yy353, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; - break; - case 269: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 286: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==286); - case 296: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==296); -{ yymsp[-2].minor.yy64 = yymsp[0].minor.yy64; } - break; - case 271: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy26 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy26), &yymsp[-1].minor.yy0); } - break; - case 272: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ -{ yymsp[-3].minor.yy26 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy26)); } - break; - case 273: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy26 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy26), NULL, yymsp[-1].minor.yy26, yymsp[0].minor.yy26); } - break; - case 274: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy26 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy26), releaseRawExprNode(pCxt, yymsp[-3].minor.yy26), yymsp[-1].minor.yy26, yymsp[0].minor.yy26); } - break; - case 276: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy26 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy26); } - break; - case 278: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy26 = createFillNode(pCxt, yymsp[-1].minor.yy192, NULL); } - break; - case 279: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy26 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy64)); } - break; - case 280: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy192 = FILL_MODE_NONE; } - break; - case 281: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy192 = FILL_MODE_PREV; } - break; - case 282: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy192 = FILL_MODE_NULL; } - break; - case 283: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy192 = FILL_MODE_LINEAR; } - break; - case 284: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy192 = FILL_MODE_NEXT; } - break; - case 287: /* group_by_list ::= expression */ -{ yylhsminor.yy64 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); } - yymsp[0].minor.yy64 = yylhsminor.yy64; - break; - case 288: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy64 = addNodeToList(pCxt, yymsp[-2].minor.yy64, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy26))); } - yymsp[-2].minor.yy64 = yylhsminor.yy64; - break; - case 291: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 187: /* signed ::= NK_MINUS NK_FLOAT */ { - yylhsminor.yy26 = addOrderByClause(pCxt, yymsp[-3].minor.yy26, yymsp[-2].minor.yy64); - yylhsminor.yy26 = addSlimitClause(pCxt, yylhsminor.yy26, yymsp[-1].minor.yy26); - yylhsminor.yy26 = addLimitClause(pCxt, yylhsminor.yy26, yymsp[0].minor.yy26); + SToken t = yymsp[-1].minor.yy0; + t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; + yylhsminor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; - case 293: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy26 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy26, yymsp[0].minor.yy26); } - yymsp[-3].minor.yy26 = yylhsminor.yy26; + case 189: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; - case 298: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 302: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==302); -{ yymsp[-1].minor.yy26 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 190: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; - case 299: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 303: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==303); -{ yymsp[-3].minor.yy26 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 191: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy348 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 300: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 304: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==304); -{ yymsp[-3].minor.yy26 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 192: /* signed_literal ::= duration_literal */ + case 317: /* search_condition ::= common_expression */ yytestcase(yyruleno==317); +{ yylhsminor.yy348 = releaseRawExprNode(pCxt, yymsp[0].minor.yy348); } + yymsp[0].minor.yy348 = yylhsminor.yy348; break; - case 305: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy26 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy26); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; + case 206: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy269, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy269, yymsp[-1].minor.yy358)); } + yymsp[-3].minor.yy348 = yylhsminor.yy348; break; - case 306: /* search_condition ::= common_expression */ -{ yylhsminor.yy26 = releaseRawExprNode(pCxt, yymsp[0].minor.yy26); } - yymsp[0].minor.yy26 = yylhsminor.yy26; + case 207: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy269, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy269, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy348 = yylhsminor.yy348; break; - case 309: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy26 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy26), yymsp[-1].minor.yy32, yymsp[0].minor.yy391); } - yymsp[-2].minor.yy26 = yylhsminor.yy26; + case 209: /* expression ::= NK_LP expression NK_RP */ + case 245: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==245); +{ yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy348)); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; - case 310: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy32 = ORDER_ASC; } + case 210: /* expression ::= NK_PLUS expression */ +{ + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy348)); + } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; - case 311: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy32 = ORDER_ASC; } + case 211: /* expression ::= NK_MINUS expression */ +{ + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy348), NULL)); + } + yymsp[-1].minor.yy348 = yylhsminor.yy348; break; - case 312: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy32 = ORDER_DESC; } + case 212: /* expression ::= expression NK_PLUS expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; - case 313: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy391 = NULL_ORDER_DEFAULT; } + case 213: /* expression ::= expression NK_MINUS expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; - case 314: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy391 = NULL_ORDER_FIRST; } + case 214: /* expression ::= expression NK_STAR expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; break; - case 315: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy391 = NULL_ORDER_LAST; } + case 215: /* expression ::= expression NK_SLASH expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 216: /* expression ::= expression NK_REM expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 217: /* expression_list ::= expression */ +{ yylhsminor.yy358 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy348)); } + yymsp[0].minor.yy358 = yylhsminor.yy358; + break; + case 218: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy358 = addNodeToList(pCxt, yymsp[-2].minor.yy358, releaseRawExprNode(pCxt, yymsp[0].minor.yy348)); } + yymsp[-2].minor.yy358 = yylhsminor.yy358; + break; + case 219: /* column_reference ::= column_name */ +{ yylhsminor.yy348 = createRawExprNode(pCxt, &yymsp[0].minor.yy269, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy269)); } + yymsp[0].minor.yy348 = yylhsminor.yy348; + break; + case 220: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy269, &yymsp[0].minor.yy269, createColumnNode(pCxt, &yymsp[-2].minor.yy269, &yymsp[0].minor.yy269)); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 221: /* predicate ::= expression compare_op expression */ + case 226: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==226); +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy194, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 222: /* predicate ::= expression BETWEEN expression AND expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy348), releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-4].minor.yy348 = yylhsminor.yy348; + break; + case 223: /* predicate ::= expression NOT BETWEEN expression AND expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[-5].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-5].minor.yy348 = yylhsminor.yy348; + break; + case 224: /* predicate ::= expression IS NULL */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), NULL)); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 225: /* predicate ::= expression IS NOT NULL */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy348), NULL)); + } + yymsp[-3].minor.yy348 = yylhsminor.yy348; + break; + case 227: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy194 = OP_TYPE_LOWER_THAN; } + break; + case 228: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy194 = OP_TYPE_GREATER_THAN; } + break; + case 229: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy194 = OP_TYPE_LOWER_EQUAL; } + break; + case 230: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy194 = OP_TYPE_GREATER_EQUAL; } + break; + case 231: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy194 = OP_TYPE_NOT_EQUAL; } + break; + case 232: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy194 = OP_TYPE_EQUAL; } + break; + case 233: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy194 = OP_TYPE_LIKE; } + break; + case 234: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy194 = OP_TYPE_NOT_LIKE; } + break; + case 235: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy194 = OP_TYPE_MATCH; } + break; + case 236: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy194 = OP_TYPE_NMATCH; } + break; + case 237: /* in_op ::= IN */ +{ yymsp[0].minor.yy194 = OP_TYPE_IN; } + break; + case 238: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy194 = OP_TYPE_NOT_IN; } + break; + case 239: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy358)); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 241: /* boolean_value_expression ::= NOT boolean_primary */ +{ + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy348), NULL)); + } + yymsp[-1].minor.yy348 = yylhsminor.yy348; + break; + case 242: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 243: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy348); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); + } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 248: /* from_clause ::= FROM table_reference_list */ + case 278: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==278); + case 301: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==301); +{ yymsp[-1].minor.yy348 = yymsp[0].minor.yy348; } + break; + case 250: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy348 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy348, yymsp[0].minor.yy348, NULL); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 253: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy348 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy269, &yymsp[0].minor.yy269); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; + break; + case 254: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy348 = createRealTableNode(pCxt, &yymsp[-3].minor.yy269, &yymsp[-1].minor.yy269, &yymsp[0].minor.yy269); } + yymsp[-3].minor.yy348 = yylhsminor.yy348; + break; + case 255: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy348 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy348), &yymsp[0].minor.yy269); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; + break; + case 257: /* alias_opt ::= */ +{ yymsp[1].minor.yy269 = nil_token; } + break; + case 258: /* alias_opt ::= table_alias */ +{ yylhsminor.yy269 = yymsp[0].minor.yy269; } + yymsp[0].minor.yy269 = yylhsminor.yy269; + break; + case 259: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy269 = yymsp[0].minor.yy269; } + break; + case 260: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 261: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==261); +{ yymsp[-2].minor.yy348 = yymsp[-1].minor.yy348; } + break; + case 262: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy348 = createJoinTableNode(pCxt, yymsp[-4].minor.yy184, yymsp[-5].minor.yy348, yymsp[-2].minor.yy348, yymsp[0].minor.yy348); } + yymsp[-5].minor.yy348 = yylhsminor.yy348; + break; + case 263: /* join_type ::= */ +{ yymsp[1].minor.yy184 = JOIN_TYPE_INNER; } + break; + case 264: /* join_type ::= INNER */ +{ yymsp[0].minor.yy184 = JOIN_TYPE_INNER; } + break; + case 265: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ +{ + yymsp[-8].minor.yy348 = createSelectStmt(pCxt, yymsp[-7].minor.yy345, yymsp[-6].minor.yy358, yymsp[-5].minor.yy348); + yymsp[-8].minor.yy348 = addWhereClause(pCxt, yymsp[-8].minor.yy348, yymsp[-4].minor.yy348); + yymsp[-8].minor.yy348 = addPartitionByClause(pCxt, yymsp[-8].minor.yy348, yymsp[-3].minor.yy358); + yymsp[-8].minor.yy348 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy348, yymsp[-2].minor.yy348); + yymsp[-8].minor.yy348 = addGroupByClause(pCxt, yymsp[-8].minor.yy348, yymsp[-1].minor.yy358); + yymsp[-8].minor.yy348 = addHavingClause(pCxt, yymsp[-8].minor.yy348, yymsp[0].minor.yy348); + } + break; + case 267: /* set_quantifier_opt ::= DISTINCT */ +{ yymsp[0].minor.yy345 = true; } + break; + case 268: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy345 = false; } + break; + case 269: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy358 = NULL; } + break; + case 273: /* select_item ::= common_expression */ +{ + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy348); + yylhsminor.yy348 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy348), &t); + } + yymsp[0].minor.yy348 = yylhsminor.yy348; + break; + case 274: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy348 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy348), &yymsp[0].minor.yy269); } + yymsp[-1].minor.yy348 = yylhsminor.yy348; + break; + case 275: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy348 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), &yymsp[0].minor.yy269); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 276: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy348 = createColumnNode(pCxt, &yymsp[-2].minor.yy269, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 280: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 297: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==297); + case 307: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==307); +{ yymsp[-2].minor.yy358 = yymsp[0].minor.yy358; } + break; + case 282: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy348 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy348), &yymsp[-1].minor.yy0); } + break; + case 283: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */ +{ yymsp[-3].minor.yy348 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy348)); } + break; + case 284: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy348 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy348), NULL, yymsp[-1].minor.yy348, yymsp[0].minor.yy348); } + break; + case 285: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy348 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy348), releaseRawExprNode(pCxt, yymsp[-3].minor.yy348), yymsp[-1].minor.yy348, yymsp[0].minor.yy348); } + break; + case 287: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy348 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy348); } + break; + case 289: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy348 = createFillNode(pCxt, yymsp[-1].minor.yy256, NULL); } + break; + case 290: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy348 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy358)); } + break; + case 291: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy256 = FILL_MODE_NONE; } + break; + case 292: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy256 = FILL_MODE_PREV; } + break; + case 293: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy256 = FILL_MODE_NULL; } + break; + case 294: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy256 = FILL_MODE_LINEAR; } + break; + case 295: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy256 = FILL_MODE_NEXT; } + break; + case 298: /* group_by_list ::= expression */ +{ yylhsminor.yy358 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); } + yymsp[0].minor.yy358 = yylhsminor.yy358; + break; + case 299: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy358 = addNodeToList(pCxt, yymsp[-2].minor.yy358, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy348))); } + yymsp[-2].minor.yy358 = yylhsminor.yy358; + break; + case 302: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ +{ + yylhsminor.yy348 = addOrderByClause(pCxt, yymsp[-3].minor.yy348, yymsp[-2].minor.yy358); + yylhsminor.yy348 = addSlimitClause(pCxt, yylhsminor.yy348, yymsp[-1].minor.yy348); + yylhsminor.yy348 = addLimitClause(pCxt, yylhsminor.yy348, yymsp[0].minor.yy348); + } + yymsp[-3].minor.yy348 = yylhsminor.yy348; + break; + case 304: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy348 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy348, yymsp[0].minor.yy348); } + yymsp[-3].minor.yy348 = yylhsminor.yy348; + break; + case 309: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 313: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==313); +{ yymsp[-1].minor.yy348 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + break; + case 310: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 314: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==314); +{ yymsp[-3].minor.yy348 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + break; + case 311: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 315: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==315); +{ yymsp[-3].minor.yy348 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + break; + case 316: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy348 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy348); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 320: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy348 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy348), yymsp[-1].minor.yy368, yymsp[0].minor.yy339); } + yymsp[-2].minor.yy348 = yylhsminor.yy348; + break; + case 321: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy368 = ORDER_ASC; } + break; + case 322: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy368 = ORDER_ASC; } + break; + case 323: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy368 = ORDER_DESC; } + break; + case 324: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy339 = NULL_ORDER_DEFAULT; } + break; + case 325: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy339 = NULL_ORDER_FIRST; } + break; + case 326: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy339 = NULL_ORDER_LAST; } break; default: break; From 559f570ea0cd2bba43e76e9efdb04c2a22f5a880 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 22 Mar 2022 14:43:58 +0800 Subject: [PATCH 11/68] sync refactor --- source/libs/sync/src/syncIO.c | 13 +- source/libs/sync/src/syncMain.c | 2 +- source/libs/sync/src/syncMessage.c | 12 +- source/libs/sync/test/CMakeLists.txt | 14 ++ source/libs/sync/test/syncReplicateTest2.cpp | 199 +++++++++++++++++++ 5 files changed, 223 insertions(+), 17 deletions(-) create mode 100644 source/libs/sync/test/syncReplicateTest2.cpp diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index 19121632e2..fcfffea9c3 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -29,7 +29,7 @@ static int32_t syncIODestroy(SSyncIO *io); static int32_t syncIOStartInternal(SSyncIO *io); static int32_t syncIOStopInternal(SSyncIO *io); -static void * syncIOConsumerFunc(void *param); +static void *syncIOConsumerFunc(void *param); static void syncIOProcessRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static void syncIOProcessReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static int32_t syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey); @@ -234,9 +234,9 @@ static int32_t syncIOStopInternal(SSyncIO *io) { } static void *syncIOConsumerFunc(void *param) { - SSyncIO * io = param; + SSyncIO *io = param; STaosQall *qall; - SRpcMsg * pRpcMsg, rpcMsg; + SRpcMsg *pRpcMsg, rpcMsg; qall = taosAllocateQall(); while (1) { @@ -257,13 +257,6 @@ static void *syncIOConsumerFunc(void *param) { assert(pSyncMsg != NULL); io->FpOnSyncPing(io->pSyncNode, pSyncMsg); syncPingDestroy(pSyncMsg); - /* - pSyncMsg = syncPingBuild(pRpcMsg->contLen); - syncPingFromRpcMsg(pRpcMsg, pSyncMsg); - // memcpy(pSyncMsg, tmpRpcMsg.pCont, tmpRpcMsg.contLen); - io->FpOnSyncPing(io->pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - */ } } else if (pRpcMsg->msgType == SYNC_PING_REPLY) { diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index b92317ef3f..98cf025093 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -122,7 +122,7 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) { ret = 0; } else { - sTrace("syncForwardToPeer not leader, %s", syncUtilState2String(pSyncNode->state)); + sTrace("syncPropose not leader, %s", syncUtilState2String(pSyncNode->state)); ret = -1; // todo : need define err code !! } diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 3ac4a7a1c0..f2344c6b6d 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -834,7 +834,7 @@ cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) { snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogIndex); + snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->lastLogIndex); cJSON_AddStringToObject(pRoot, "lastLogIndex", u64buf); snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogTerm); cJSON_AddStringToObject(pRoot, "lastLogTerm", u64buf); @@ -1127,14 +1127,14 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) { snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogIndex); - cJSON_AddStringToObject(pRoot, "pre_log_index", u64buf); + snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->prevLogIndex); + cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf); snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogTerm); cJSON_AddStringToObject(pRoot, "pre_log_term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->commitIndex); - cJSON_AddStringToObject(pRoot, "commit_index", u64buf); + snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->commitIndex); + cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); char* s; @@ -1288,7 +1288,7 @@ cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) { snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); cJSON_AddNumberToObject(pRoot, "success", pMsg->success); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->matchIndex); + snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->matchIndex); cJSON_AddStringToObject(pRoot, "matchIndex", u64buf); } diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index 653763b96b..ec43517974 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -33,6 +33,7 @@ add_executable(syncElectTest3 "") add_executable(syncEncodeTest "") add_executable(syncWriteTest "") add_executable(syncReplicateTest "") +add_executable(syncReplicateTest2 "") add_executable(syncRefTest "") @@ -176,6 +177,10 @@ target_sources(syncReplicateTest PRIVATE "syncReplicateTest.cpp" ) +target_sources(syncReplicateTest2 + PRIVATE + "syncReplicateTest2.cpp" +) target_sources(syncRefTest PRIVATE "syncRefTest.cpp" @@ -357,6 +362,11 @@ target_include_directories(syncReplicateTest "${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncReplicateTest2 + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_include_directories(syncRefTest PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync" @@ -504,6 +514,10 @@ target_link_libraries(syncReplicateTest sync gtest_main ) +target_link_libraries(syncReplicateTest2 + sync + gtest_main +) target_link_libraries(syncRefTest sync gtest_main diff --git a/source/libs/sync/test/syncReplicateTest2.cpp b/source/libs/sync/test/syncReplicateTest2.cpp new file mode 100644 index 0000000000..352d2892bf --- /dev/null +++ b/source/libs/sync/test/syncReplicateTest2.cpp @@ -0,0 +1,199 @@ +#include +#include +#include "syncEnv.h" +#include "syncIO.h" +#include "syncInt.h" +#include "syncMessage.h" +#include "syncRaftEntry.h" +#include "syncRaftLog.h" +#include "syncRaftStore.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 3; +int32_t myIndex = 0; + +SRaftId ids[TSDB_MAX_REPLICA]; +SSyncInfo syncInfo; +SSyncFSM *pFsm; +SWal * pWal; + +void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, + isWeak, code); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); +} + +void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, + index, isWeak, code); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); +} + +void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, + isWeak, code); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); +} + +void initFsm() { + pFsm = (SSyncFSM *)malloc(sizeof(SSyncFSM)); + pFsm->FpCommitCb = CommitCb; + pFsm->FpPreCommitCb = PreCommitCb; + pFsm->FpRollBackCb = RollBackCb; +} + +int64_t syncNodeInit() { + syncInfo.vgId = 1234; + syncInfo.rpcClient = gSyncIO->clientRpc; + syncInfo.FpSendMsg = syncIOSendMsg; + syncInfo.queue = gSyncIO->pMsgQ; + syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.pFsm = pFsm; + snprintf(syncInfo.path, sizeof(syncInfo.path), "./replicate2_test_%d", myIndex); + + int code = walInit(); + assert(code == 0); + SWalCfg walCfg; + memset(&walCfg, 0, sizeof(SWalCfg)); + walCfg.vgId = syncInfo.vgId; + walCfg.fsyncPeriod = 1000; + walCfg.retentionPeriod = 1000; + walCfg.rollPeriod = 1000; + walCfg.retentionSize = 1000; + walCfg.segSize = 1000; + walCfg.level = TAOS_WAL_FSYNC; + + char tmpdir[128]; + snprintf(tmpdir, sizeof(tmpdir), "./replicate2_test_wal_%d", myIndex); + pWal = walOpen(tmpdir, &walCfg); + assert(pWal != NULL); + + syncInfo.pWal = pWal; + + SSyncCfg *pCfg = &syncInfo.syncCfg; + pCfg->myIndex = myIndex; + pCfg->replicaNum = replicaNum; + + for (int i = 0; i < replicaNum; ++i) { + pCfg->nodeInfo[i].nodePort = ports[i]; + snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1"); + // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); + } + + int64_t rid = syncStart(&syncInfo); + assert(rid > 0); + + SSyncNode *pSyncNode = (SSyncNode *)syncNodeAcquire(rid); + assert(pSyncNode != NULL); + + // pSyncNode->hbBaseLine = 500; + // pSyncNode->electBaseLine = 1500; + + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; + gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; + gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; + gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; + gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; + gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest; + gSyncIO->pSyncNode = pSyncNode; + + syncNodeRelease(pSyncNode); + + return rid; +} + +void initRaftId(SSyncNode *pSyncNode) { + for (int i = 0; i < replicaNum; ++i) { + ids[i] = pSyncNode->replicasId[i]; + char *s = syncUtilRaftId2Str(&ids[i]); + printf("raftId[%d] : %s\n", i, s); + free(s); + } +} + +SRpcMsg *step0(int i) { + SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + memset(pMsg, 0, sizeof(SRpcMsg)); + pMsg->msgType = 9999; + pMsg->contLen = 128; + pMsg->pCont = malloc(pMsg->contLen); + snprintf((char *)(pMsg->pCont), pMsg->contLen, "value-%u-%d", ports[myIndex], i); + return pMsg; +} + +SyncClientRequest *step1(const SRpcMsg *pMsg) { + SyncClientRequest *pRetMsg = syncClientRequestBuild2(pMsg, 123, true); + return pRetMsg; +} + +int main(int argc, char **argv) { + // taosInitLog((char *)"syncTest.log", 100000, 10); + tsAsyncLog = 0; + sDebugFlag = 143 + 64; + void logTest(); + + myIndex = 0; + if (argc >= 2) { + myIndex = atoi(argv[1]); + } + + int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]); + assert(ret == 0); + + initFsm(); + + ret = syncInit(); + assert(ret == 0); + + int64_t rid = syncNodeInit(); + assert(rid > 0); + + SSyncNode *pSyncNode = (SSyncNode *)syncNodeAcquire(rid); + assert(pSyncNode != NULL); + + syncNodePrint2((char *)"", pSyncNode); + initRaftId(pSyncNode); + + for (int i = 0; i < 30; ++i) { + // step0 + SRpcMsg *pMsg0 = step0(i); + syncRpcMsgPrint2((char *)"==step0==", pMsg0); + + syncPropose(rid, pMsg0, true); + taosMsleep(1000); + + free(pMsg0); + + sTrace( + "syncPropose sleep, state: %d, %s, term:%lu electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, " + "electTimerMS:%d", + pSyncNode->state, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, + pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser, pSyncNode->electTimerMS); + } + + while (1) { + sTrace( + "replicate sleep, state: %d, %s, term:%lu electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, " + "electTimerMS:%d", + pSyncNode->state, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, + pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser, pSyncNode->electTimerMS); + taosMsleep(1000); + } + + return 0; +} From 48822785e1548b4543e3c80f2619a174a296da43 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 22 Mar 2022 02:56:51 -0400 Subject: [PATCH 12/68] TD-14178 bugfix --- source/libs/parser/src/parTranslater.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index f20bc5f2e6..e0b11938f4 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -255,7 +255,7 @@ static int32_t trimStringWithVarFormat(const char* src, int32_t len, bool format static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { if (pVal->isDuration) { - if (parseAbsoluteDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, pVal->node.resType.precision) != TSDB_CODE_SUCCESS) { + if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, pVal->node.resType.precision) != TSDB_CODE_SUCCESS) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); } } else { From eb5471fdd62b0d349b58efea27e1139181a8aa7f Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Tue, 22 Mar 2022 14:57:16 +0800 Subject: [PATCH 13/68] tsdb merge --- include/common/trow.h | 8 ++++++-- source/dnode/vnode/src/tsdb/tsdbReadImpl.c | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/common/trow.h b/include/common/trow.h index 47edf6f1ad..4ae5a2277d 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -968,10 +968,14 @@ static FORCE_INLINE int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, in #endif return TSDB_CODE_SUCCESS; } - if (tdGetBitmapValType(pCol->pBitmap, row, &(pVal->valType)) < 0) { + + if (TD_COL_ROWS_NORM(pCol)) { + pVal->valType = TD_VTYPE_NORM; + } else if (tdGetBitmapValType(pCol->pBitmap, row, &(pVal->valType)) < 0) { return terrno; } - if (TD_COL_ROWS_NORM(pCol) || tdValTypeIsNorm(pVal->valType)) { + + if (tdValTypeIsNorm(pVal->valType)) { if (IS_VAR_DATA_TYPE(pCol->type)) { pVal->val = POINTER_SHIFT(pCol->pData, pCol->dataOff[row]); } else { diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index f6827eaae1..9619ac036e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -727,9 +727,9 @@ static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols * } ASSERT(pBlockCol->colId == pDataCol->colId); - // set the bitmap - pDataCol->bitmap = pBlockCol->bitmap; } + // set the bitmap + pDataCol->bitmap = pBlockCol->bitmap; if (tsdbLoadColData(pReadh, pDFile, pBlock, pBlockCol, pDataCol) < 0) return -1; } From 1a1008548eadc5ab8686976f1fb7eeeadf14aa94 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Tue, 22 Mar 2022 15:17:45 +0800 Subject: [PATCH 14/68] trigger CI From 944bb33156535d054794e2cac3e3cbdb8092c7a6 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 22 Mar 2022 15:29:32 +0800 Subject: [PATCH 15/68] sync refactor --- source/libs/sync/src/syncAppendEntries.c | 26 ++++++++++++++++++++---- source/libs/sync/src/syncMain.c | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index e4df93ca47..9922357134 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -120,6 +120,11 @@ 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)) { + sTrace( + "syncNodeOnAppendEntriesCb --> reject, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, ths->state:%d, " + "logOK:%d", + pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK); + SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(); pReply->srcId = ths->myRaftId; pReply->destId = pMsg->srcId; @@ -137,6 +142,11 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // return to follower state if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) { + sTrace( + "syncNodeOnAppendEntriesCb --> return to follower, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, " + "ths->state:%d, logOK:%d", + pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK); + syncNodeBecomeFollower(ths); // ret or reply? @@ -159,6 +169,11 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncEntryDestory(pPreEntry); } + sTrace( + "syncNodeOnAppendEntriesCb --> accept, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, " + "ths->state:%d, logOK:%d, preMatch:%d", + pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK, preMatch); + if (preMatch) { // must has preIndex in local log assert(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)); @@ -167,7 +182,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { bool hasAppendEntries = pMsg->dataLen > 0; if (hasExtraEntries && hasAppendEntries) { - // conflict + // not conflict by default bool conflict = false; SyncIndex extraIndex = pMsg->prevLogIndex + 1; @@ -177,8 +192,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); assert(pAppendEntry != NULL); + // log not match, conflict assert(extraIndex == pAppendEntry->index); - if (pExtraEntry->term == pAppendEntry->term) { + if (pExtraEntry->term != pAppendEntry->term) { conflict = true; } @@ -187,6 +203,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { SyncIndex delBegin = ths->pLogStore->getLastIndex(ths->pLogStore); SyncIndex delEnd = extraIndex; + sTrace("syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%ld, delEnd:%ld", conflict, delBegin, delEnd); + // notice! reverse roll back! for (SyncIndex index = delEnd; index >= delBegin; --index) { if (ths->pFsm->FpRollBackCb != NULL) { @@ -212,7 +230,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncEntry2OriginalRpc(pAppendEntry, &rpcMsg); if (ths->pFsm != NULL) { if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 0); + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 2); } } rpcFreeCont(rpcMsg.pCont); @@ -237,7 +255,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncEntry2OriginalRpc(pAppendEntry, &rpcMsg); if (ths->pFsm != NULL) { if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 0); + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 3); } } rpcFreeCont(rpcMsg.pCont); diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 98cf025093..a896ac5ff4 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -863,7 +863,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg if (ths->pFsm != NULL) { if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, -2); + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 1); } } rpcFreeCont(rpcMsg.pCont); From 2dc845fba9856c24263190fa628e9f27781fd4c7 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Tue, 22 Mar 2022 15:32:36 +0800 Subject: [PATCH 16/68] restore --- source/dnode/mgmt/vnode/src/vmInt.c | 2 +- source/dnode/vnode/src/inc/tsdbLog.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/dnode/mgmt/vnode/src/vmInt.c b/source/dnode/mgmt/vnode/src/vmInt.c index c6122c0501..1c6c7d089e 100644 --- a/source/dnode/mgmt/vnode/src/vmInt.c +++ b/source/dnode/mgmt/vnode/src/vmInt.c @@ -342,7 +342,7 @@ void vmGetMgmtFp(SMgmtWrapper *pWrapper) { mgmtFp.requiredFp = vmRequire; vmInitMsgHandles(pWrapper); - pWrapper->name = "vnode"; + pWrapper->name = "vnodes"; pWrapper->fp = mgmtFp; } diff --git a/source/dnode/vnode/src/inc/tsdbLog.h b/source/dnode/vnode/src/inc/tsdbLog.h index 3afe628198..56dc8ab2a0 100644 --- a/source/dnode/vnode/src/inc/tsdbLog.h +++ b/source/dnode/vnode/src/inc/tsdbLog.h @@ -24,12 +24,12 @@ extern "C" { extern int32_t tsdbDebugFlag; -#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) -#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) -#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) -#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) -#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) -#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) #ifdef __cplusplus } From 1c3113686e0f00e5a186cc0b9a8d8f4629e05755 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 22 Mar 2022 16:17:17 +0800 Subject: [PATCH 17/68] sync refactor --- include/libs/sync/sync.h | 2 +- source/libs/sync/src/syncMain.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index a38431a1b2..74d9dfd970 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -35,6 +35,7 @@ typedef enum { TAOS_SYNC_STATE_FOLLOWER = 100, TAOS_SYNC_STATE_CANDIDATE = 101, TAOS_SYNC_STATE_LEADER = 102, + TAOS_SYNC_STATE_ERROR = 103, } ESyncState; typedef struct SSyncBuffer { @@ -160,7 +161,6 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg); int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // use this function int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // just for compatibility ESyncState syncGetMyRole(int64_t rid); -void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole); extern int32_t sDebugFlag; diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index a896ac5ff4..18213ca62c 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -136,13 +136,14 @@ int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak) { } ESyncState syncGetMyRole(int64_t rid) { - // todo : get pointer from rid - SSyncNode* pSyncNode = NULL; + SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + if (pSyncNode == NULL) { + return TAOS_SYNC_STATE_ERROR; + } + assert(rid == pSyncNode->rid); return pSyncNode->state; } -void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {} - // open/close -------------- SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { SSyncNode* pSyncNode = (SSyncNode*)malloc(sizeof(SSyncNode)); From f7432337fd1846a0561adf80b08d44dd0bb0b90f Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 22 Mar 2022 16:43:30 +0800 Subject: [PATCH 18/68] sync refactor --- include/libs/sync/sync.h | 23 +++++++++------- source/libs/sync/src/syncAppendEntries.c | 8 +++--- source/libs/sync/src/syncCommit.c | 2 +- source/libs/sync/src/syncIO.c | 6 ++--- source/libs/sync/src/syncMain.c | 4 +-- source/libs/sync/test/syncReplicateTest.cpp | 28 +++++++++++++------- source/libs/sync/test/syncReplicateTest2.cpp | 22 ++++++++------- source/libs/sync/test/syncWriteTest.cpp | 28 +++++++++++++------- 8 files changed, 74 insertions(+), 47 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 74d9dfd970..44efc33dbb 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -69,17 +69,20 @@ typedef struct SSnapshot { typedef struct SSyncFSM { void* data; - // when value in pBuf finish a raft flow, FpCommitCb is called, code indicates the result + // when value in pMsg finish a raft flow, FpCommitCb is called, code indicates the result // user can do something according to the code and isWeak. for example, write data into tsdb - void (*FpCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pBuf, SyncIndex index, bool isWeak, int32_t code); + void (*FpCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state); - // when value in pBuf has been written into local log store, FpPreCommitCb is called, code indicates the result + // when value in pMsg has been written into local log store, FpPreCommitCb is called, code indicates the result // user can do something according to the code and isWeak. for example, write data into tsdb - void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pBuf, SyncIndex index, bool isWeak, int32_t code); + void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state); // when log entry is updated by a new one, FpRollBackCb is called // user can do something to roll back. for example, delete data from tsdb, or just ignore it - void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pBuf, SyncIndex index, bool isWeak, int32_t code); + void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state); // user should implement this function, use "data" to take snapshot into "snapshot" int32_t (*FpTakeSnapshot)(SSnapshot* snapshot); @@ -155,11 +158,11 @@ typedef struct SSyncNode SSyncNode; int32_t syncInit(); void syncCleanUp(); -int64_t syncStart(const SSyncInfo* pSyncInfo); -void syncStop(int64_t rid); -int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg); -int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // use this function -int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // just for compatibility +int64_t syncStart(const SSyncInfo* pSyncInfo); +void syncStop(int64_t rid); +int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg); +int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // use this function +int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // for compatibility, the same as syncPropose ESyncState syncGetMyRole(int64_t rid); extern int32_t sDebugFlag; diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 9922357134..960fc6d55e 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -213,7 +213,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { SRpcMsg rpcMsg; syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg); - ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, pRollBackEntry->index, pRollBackEntry->isWeak, 0); + ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, pRollBackEntry->index, pRollBackEntry->isWeak, 0, ths->state); rpcFreeCont(rpcMsg.pCont); syncEntryDestory(pRollBackEntry); } @@ -230,7 +230,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncEntry2OriginalRpc(pAppendEntry, &rpcMsg); if (ths->pFsm != NULL) { if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 2); + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 2, ths->state); } } rpcFreeCont(rpcMsg.pCont); @@ -255,7 +255,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncEntry2OriginalRpc(pAppendEntry, &rpcMsg); if (ths->pFsm != NULL) { if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 3); + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 3, ths->state); } } rpcFreeCont(rpcMsg.pCont); @@ -326,7 +326,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncEntry2OriginalRpc(pEntry, &rpcMsg); if (ths->pFsm->FpCommitCb != NULL) { - ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0); + ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0, ths->state); } rpcFreeCont(rpcMsg.pCont); diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 0d4df8e6cf..89b5f0b39c 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -91,7 +91,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { syncEntry2OriginalRpc(pEntry, &rpcMsg); if (pSyncNode->pFsm->FpCommitCb != NULL) { - pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0); + pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0, pSyncNode->state); } rpcFreeCont(rpcMsg.pCont); diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index fcfffea9c3..b05d2e397d 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -29,7 +29,7 @@ static int32_t syncIODestroy(SSyncIO *io); static int32_t syncIOStartInternal(SSyncIO *io); static int32_t syncIOStopInternal(SSyncIO *io); -static void *syncIOConsumerFunc(void *param); +static void * syncIOConsumerFunc(void *param); static void syncIOProcessRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static void syncIOProcessReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static int32_t syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey); @@ -234,9 +234,9 @@ static int32_t syncIOStopInternal(SSyncIO *io) { } static void *syncIOConsumerFunc(void *param) { - SSyncIO *io = param; + SSyncIO * io = param; STaosQall *qall; - SRpcMsg *pRpcMsg, rpcMsg; + SRpcMsg * pRpcMsg, rpcMsg; qall = taosAllocateQall(); while (1) { diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 18213ca62c..bbb0142584 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -849,7 +849,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg if (ths->pFsm != NULL) { if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0); + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0, ths->state); } } rpcFreeCont(rpcMsg.pCont); @@ -864,7 +864,7 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg if (ths->pFsm != NULL) { if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 1); + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 1, ths->state); } } rpcFreeCont(rpcMsg.pCont); diff --git a/source/libs/sync/test/syncReplicateTest.cpp b/source/libs/sync/test/syncReplicateTest.cpp index 4d6e6f3a25..47399eeb3c 100644 --- a/source/libs/sync/test/syncReplicateTest.cpp +++ b/source/libs/sync/test/syncReplicateTest.cpp @@ -28,19 +28,29 @@ SSyncFSM * pFsm; SWal * pWal; SSyncNode *gSyncNode; -void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) { - printf("==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code); - syncRpcMsgPrint2((char *)"==CommitCb==", (SRpcMsg *)pBuf); +void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, index, isWeak, code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } -void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) { - printf("==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code); - syncRpcMsgPrint2((char *)"==PreCommitCb==", (SRpcMsg *)pBuf); +void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, index, isWeak, + code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } -void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) { - printf("==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code); - syncRpcMsgPrint2((char *)"==RollBackCb==", (SRpcMsg *)pBuf); +void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, index, isWeak, code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } void initFsm() { diff --git a/source/libs/sync/test/syncReplicateTest2.cpp b/source/libs/sync/test/syncReplicateTest2.cpp index 352d2892bf..09dbc0e2ed 100644 --- a/source/libs/sync/test/syncReplicateTest2.cpp +++ b/source/libs/sync/test/syncReplicateTest2.cpp @@ -27,24 +27,28 @@ SSyncInfo syncInfo; SSyncFSM *pFsm; SWal * pWal; -void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code) { +void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, - isWeak, code); + snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, index, isWeak, code, state, syncUtilState2String(state)); syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } -void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code) { +void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, - index, isWeak, code); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, index, isWeak, + code, state, syncUtilState2String(state)); syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } -void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code) { +void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, - isWeak, code); + snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, index, isWeak, code, state, syncUtilState2String(state)); syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } diff --git a/source/libs/sync/test/syncWriteTest.cpp b/source/libs/sync/test/syncWriteTest.cpp index 2598abbddd..732bcf140b 100644 --- a/source/libs/sync/test/syncWriteTest.cpp +++ b/source/libs/sync/test/syncWriteTest.cpp @@ -28,19 +28,29 @@ SSyncFSM * pFsm; SWal * pWal; SSyncNode *gSyncNode; -void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) { - printf("==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code); - syncRpcMsgPrint2((char *)"==CommitCb==", (SRpcMsg *)pBuf); +void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, index, isWeak, code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } -void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) { - printf("==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code); - syncRpcMsgPrint2((char *)"==PreCommitCb==", (SRpcMsg *)pBuf); +void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, index, isWeak, + code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } -void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) { - printf("==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code); - syncRpcMsgPrint2((char *)"==RollBackCb==", (SRpcMsg *)pBuf); +void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, index, isWeak, code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); } void initFsm() { From 7c6fbbfbd12689e172cd2fd994a44a4a4a9a5501 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 22 Mar 2022 16:58:36 +0800 Subject: [PATCH 19/68] sync refactor --- include/libs/sync/sync.h | 3 ++ source/libs/sync/src/syncMain.c | 49 +++++++++++++++++---------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 44efc33dbb..7802aaca96 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -165,6 +165,9 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // us int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // for compatibility, the same as syncPropose ESyncState syncGetMyRole(int64_t rid); +// propose with sequence number, to implement linearizable semantics +int32_t syncPropose2(int64_t rid, const SRpcMsg* pMsg, bool isWeak, uint64_t seqNum); + extern int32_t sDebugFlag; #ifdef __cplusplus diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index bbb0142584..f2341ef521 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -104,29 +104,7 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) { } int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) { - int32_t ret = 0; - - // todo : get pointer from rid - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return -1; - } - assert(rid == pSyncNode->rid); - - if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { - SyncClientRequest* pSyncMsg = syncClientRequestBuild2(pMsg, 0, isWeak); - SRpcMsg rpcMsg; - syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg); - pSyncNode->FpEqMsg(pSyncNode->queue, &rpcMsg); - syncClientRequestDestroy(pSyncMsg); - ret = 0; - - } else { - sTrace("syncPropose not leader, %s", syncUtilState2String(pSyncNode->state)); - ret = -1; // todo : need define err code !! - } - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + int32_t ret = syncPropose2(rid, pMsg, isWeak, 0); return ret; } @@ -144,6 +122,31 @@ ESyncState syncGetMyRole(int64_t rid) { return pSyncNode->state; } +int32_t syncPropose2(int64_t rid, const SRpcMsg* pMsg, bool isWeak, uint64_t seqNum) { + int32_t ret = 0; + SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + if (pSyncNode == NULL) { + return -1; + } + assert(rid == pSyncNode->rid); + + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + SyncClientRequest* pSyncMsg = syncClientRequestBuild2(pMsg, seqNum, isWeak); + SRpcMsg rpcMsg; + syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg); + pSyncNode->FpEqMsg(pSyncNode->queue, &rpcMsg); + syncClientRequestDestroy(pSyncMsg); + ret = 0; + + } else { + sTrace("syncPropose not leader, %s", syncUtilState2String(pSyncNode->state)); + ret = -1; // todo : need define err code !! + } + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return ret; +} + // open/close -------------- SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { SSyncNode* pSyncNode = (SSyncNode*)malloc(sizeof(SSyncNode)); From e3a3c1386be8d5f766ee9e9ecd7ebb326b0b8753 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 22 Mar 2022 17:53:43 +0800 Subject: [PATCH 20/68] sync refactor --- include/libs/sync/sync.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 7802aaca96..b2ed9ea3c4 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -161,13 +161,15 @@ void syncCleanUp(); int64_t syncStart(const SSyncInfo* pSyncInfo); void syncStop(int64_t rid); int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg); -int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // use this function -int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); // for compatibility, the same as syncPropose +int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); ESyncState syncGetMyRole(int64_t rid); // propose with sequence number, to implement linearizable semantics int32_t syncPropose2(int64_t rid, const SRpcMsg* pMsg, bool isWeak, uint64_t seqNum); +// for compatibility, the same as syncPropose +int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); + extern int32_t sDebugFlag; #ifdef __cplusplus From a25de3475bf1a9ba04ab16bb81cd7009da13f0d5 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 22 Mar 2022 05:55:45 -0400 Subject: [PATCH 21/68] ignore test generated file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3eda69f60d..1bfbf00cd5 100644 --- a/.gitignore +++ b/.gitignore @@ -88,6 +88,7 @@ tests/examples/JDBC/JDBCDemo/.classpath tests/examples/JDBC/JDBCDemo/.project tests/examples/JDBC/JDBCDemo/.settings/ source/libs/parser/inc/sql.* +tests/script/tmqResult.txt # Emacs # -*- mode: gitignore; -*- From d3104e78ece4fda40715d98fb6662aa76df3431e Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Tue, 22 Mar 2022 18:00:03 +0800 Subject: [PATCH 22/68] stream task exec --- example/CMakeLists.txt | 30 ++- example/src/tstream.c | 224 +++++++++++++++++++++ include/client/taos.h | 8 +- include/common/tcommon.h | 3 + include/common/tmsg.h | 14 +- include/libs/executor/executor.h | 50 ++--- source/client/src/tmq.c | 4 +- source/common/src/tdatablock.c | 23 +++ source/common/src/tmsg.c | 8 +- source/dnode/mgmt/vnode/src/vmMsg.c | 1 + source/dnode/mnode/impl/inc/mndSnode.h | 1 + source/dnode/mnode/impl/src/mndScheduler.c | 62 +++--- source/dnode/mnode/impl/src/mndSnode.c | 9 + source/dnode/snode/src/snode.c | 4 +- source/dnode/vnode/src/tq/tq.c | 164 ++++++++++++++- source/libs/executor/src/executor.c | 7 +- 16 files changed, 531 insertions(+), 81 deletions(-) create mode 100644 example/src/tstream.c diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 51e1e996dc..acb99caffc 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,12 +1,30 @@ -aux_source_directory(src TMQ_DEMO_SRC) +add_executable(tmq "") +add_executable(tstream "") -add_executable(tmq ${TMQ_DEMO_SRC}) -target_link_libraries( - tmq taos +target_sources(tmq + PRIVATE + "src/tmq.c" ) -target_include_directories( - tmq + +target_sources(tstream + PRIVATE + "src/tstream.c" +) +target_link_libraries(tmq + taos +) + +target_link_libraries(tstream + taos +) + +target_include_directories(tmq + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_include_directories(tstream PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) SET_TARGET_PROPERTIES(tmq PROPERTIES OUTPUT_NAME tmq) +SET_TARGET_PROPERTIES(tstream PROPERTIES OUTPUT_NAME tstream) diff --git a/example/src/tstream.c b/example/src/tstream.c new file mode 100644 index 0000000000..73ab655fbd --- /dev/null +++ b/example/src/tstream.c @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include "taos.h" + +static int running = 1; +static void msg_process(tmq_message_t* message) { tmqShowMsg(message); } + +int32_t init_env() { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + return -1; + } + + TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create stable if not exists st1 (ts timestamp, k int) tags(a int)"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists tu1 using st1 tags(1)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table tu1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists tu2 using st1 tags(2)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table tu2, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + return 0; +} + +int32_t create_stream() { + printf("create topic\n"); + TAOS_RES* pRes; + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + return -1; + } + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + const char* sql = "select ts,k from tu1"; + pRes = tmq_create_stream(pConn, "stream1", "out1", sql); + if (taos_errno(pRes) != 0) { + printf("failed to create stream out1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + taos_close(pConn); + return 0; +} + +void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_t* offsets, void* param) { + printf("commit %d\n", resp); +} + +tmq_t* build_consumer() { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + tmq_conf_t* conf = tmq_conf_new(); + tmq_conf_set(conf, "group.id", "tg2"); + tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print); + tmq_t* tmq = tmq_consumer_new(pConn, conf, NULL, 0); + return tmq; +} + +tmq_list_t* build_topic_list() { + tmq_list_t* topic_list = tmq_list_new(); + tmq_list_append(topic_list, "test_stb_topic_1"); + return topic_list; +} + +void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { + tmq_resp_err_t err; + + if ((err = tmq_subscribe(tmq, topics))) { + fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err)); + printf("subscribe err\n"); + return; + } + /*int32_t cnt = 0;*/ + /*clock_t startTime = clock();*/ + while (running) { + tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 500); + if (tmqmessage) { + /*cnt++;*/ + msg_process(tmqmessage); + tmq_message_destroy(tmqmessage); + /*} else {*/ + /*break;*/ + } + } + /*clock_t endTime = clock();*/ + /*printf("log cnt: %d %f s\n", cnt, (double)(endTime - startTime) / CLOCKS_PER_SEC);*/ + + err = tmq_consumer_close(tmq); + if (err) + fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); + else + fprintf(stderr, "%% Consumer closed\n"); +} + +void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { + static const int MIN_COMMIT_COUNT = 1; + + int msg_count = 0; + tmq_resp_err_t err; + + if ((err = tmq_subscribe(tmq, topics))) { + fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err)); + return; + } + + while (running) { + tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1000); + if (tmqmessage) { + msg_process(tmqmessage); + tmq_message_destroy(tmqmessage); + + if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0); + } + } + + err = tmq_consumer_close(tmq); + if (err) + fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); + else + fprintf(stderr, "%% Consumer closed\n"); +} + +void perf_loop(tmq_t* tmq, tmq_list_t* topics) { + tmq_resp_err_t err; + + if ((err = tmq_subscribe(tmq, topics))) { + fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err)); + printf("subscribe err\n"); + return; + } + int32_t batchCnt = 0; + int32_t skipLogNum = 0; + clock_t startTime = clock(); + while (running) { + tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 500); + if (tmqmessage) { + batchCnt++; + skipLogNum += tmqGetSkipLogNum(tmqmessage); + /*msg_process(tmqmessage);*/ + tmq_message_destroy(tmqmessage); + } else { + break; + } + } + clock_t endTime = clock(); + printf("log batch cnt: %d, skip log cnt: %d, time used:%f s\n", batchCnt, skipLogNum, + (double)(endTime - startTime) / CLOCKS_PER_SEC); + + err = tmq_consumer_close(tmq); + if (err) + fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); + else + fprintf(stderr, "%% Consumer closed\n"); +} + +int main(int argc, char* argv[]) { + int code; + if (argc > 1) { + printf("env init\n"); + code = init_env(); + } + create_topic(); + tmq_t* tmq = build_consumer(); + tmq_list_t* topic_list = build_topic_list(); + /*perf_loop(tmq, topic_list);*/ + /*basic_consume_loop(tmq, topic_list);*/ + sync_consume_loop(tmq, topic_list); +} diff --git a/include/client/taos.h b/include/client/taos.h index da24136d80..82f0635612 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -214,7 +214,6 @@ typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *, v DLL_EXPORT tmq_list_t *tmq_list_new(); DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *); -DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen); DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen); DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message); DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t); @@ -258,7 +257,12 @@ int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message); DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message); DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message); -/* ---------------------- OTHER ---------------------------- */ +/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */ +DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen); + +DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const char *tbName, const char *sql); + +/* -------------------------------- OTHER -------------------------------- */ typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code); DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 5308be72bb..15e39d2bad 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -101,6 +101,9 @@ void* blockDataDestroy(SSDataBlock* pBlock); int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock); void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock); +int32_t tEncodeDataBlocks(void** buf, const SArray* blocks); +void* tDecodeDataBlocks(const void* buf, SArray* blocks); + static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) { // WARNING: do not use info.numOfCols, // sometimes info.numOfCols != array size diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ca4e6b97a4..5000dbfd18 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2271,20 +2271,22 @@ enum { typedef struct { void* inputHandle; - void* executor[4]; -} SStreamTaskParRunner; + void* executor; +} SStreamRunner; typedef struct { int64_t streamId; int32_t taskId; int32_t level; int8_t status; - int8_t pipeEnd; - int8_t parallel; + int8_t pipeSource; + int8_t pipeSink; + int8_t numOfRunners; + int8_t parallelizable; SEpSet NextOpEp; char* qmsg; // not applied to encoder and decoder - SStreamTaskParRunner runner; + SStreamRunner runner[8]; // void* executor; // void* stateStore; // storage handle @@ -2316,7 +2318,7 @@ typedef struct { typedef struct { SStreamExecMsgHead head; - // TODO: other info needed by task + SArray* data; // SArray } SStreamTaskExecReq; typedef struct { diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index b08ee5303d..a342c33afa 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -33,15 +33,15 @@ typedef struct SReadHandle { } SReadHandle; #define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1 -#define STREAM_DATA_TYPE_SSDAT_BLOCK 0x2 +#define STREAM_DATA_TYPE_SSDATA_BLOCK 0x2 - /** - * Create the exec task for streaming mode - * @param pMsg - * @param streamReadHandle - * @return - */ -qTaskInfo_t qCreateStreamExecTaskInfo(void *msg, void* streamReadHandle); +/** + * Create the exec task for streaming mode + * @param pMsg + * @param streamReadHandle + * @return + */ +qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle); /** * Set the input data block for the stream scan. @@ -62,16 +62,17 @@ int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type); */ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isAdd); - /** - * Create the exec task object according to task json - * @param readHandle - * @param vgId - * @param pTaskInfoMsg - * @param pTaskInfo - * @param qId - * @return - */ -int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan, qTaskInfo_t* pTaskInfo, DataSinkHandle* handle); +/** + * Create the exec task object according to task json + * @param readHandle + * @param vgId + * @param pTaskInfoMsg + * @param pTaskInfo + * @param qId + * @return + */ +int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan, + qTaskInfo_t* pTaskInfo, DataSinkHandle* handle); /** * The main task execution function, including query on both table and multiple tables, @@ -81,7 +82,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, * @param handle * @return */ -int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds); +int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds); /** * Retrieve the produced results information, if current query is not paused or completed, @@ -144,7 +145,8 @@ int32_t qGetQualifiedTableIdList(void* pTableList, const char* tagCond, int32_t * @param numOfIndex * @return */ -//int32_t qCreateTableGroupByGroupExpr(SArray* pTableIdList, TSKEY skey, STableGroupInfo groupInfo, SColIndex* groupByIndex, int32_t numOfIndex); +// int32_t qCreateTableGroupByGroupExpr(SArray* pTableIdList, TSKEY skey, STableGroupInfo groupInfo, SColIndex* +// groupByIndex, int32_t numOfIndex); /** * Update the table id list of a given query. @@ -167,19 +169,19 @@ void* qOpenTaskMgmt(int32_t vgId); * broadcast the close information and wait for all query stop. * @param pExecutor */ -void qTaskMgmtNotifyClosing(void* pExecutor); +void qTaskMgmtNotifyClosing(void* pExecutor); /** * Re-open the query handle management module when opening the vnode again. * @param pExecutor */ -void qQueryMgmtReOpen(void *pExecutor); +void qQueryMgmtReOpen(void* pExecutor); /** * Close query mgmt and clean up resources. * @param pExecutor */ -void qCleanupTaskMgmt(void* pExecutor); +void qCleanupTaskMgmt(void* pExecutor); /** * Add the query into the query mgmt object @@ -188,7 +190,7 @@ void qCleanupTaskMgmt(void* pExecutor); * @param qInfo * @return */ -void** qRegisterTask(void* pMgmt, uint64_t qId, void *qInfo); +void** qRegisterTask(void* pMgmt, uint64_t qId, void* qInfo); /** * acquire the query handle according to the key from query mgmt object. diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 7c35b7c149..9208d1f634 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -471,8 +471,8 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa } sqlLen = strlen(sql); - if (strlen(streamName) >= TSDB_TABLE_NAME_LEN) { - tscError("stream name too long, max length:%d", TSDB_TABLE_NAME_LEN - 1); + if (strlen(tbName) >= TSDB_TABLE_NAME_LEN) { + tscError("output tb name too long, max length:%d", TSDB_TABLE_NAME_LEN - 1); terrno = TSDB_CODE_TSC_INVALID_INPUT; goto _return; } diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 0d48d7cc14..3e32f9d58b 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1250,3 +1250,26 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock) { } return (void*)buf; } + +int32_t tEncodeDataBlocks(void** buf, const SArray* blocks) { + int32_t tlen = 0; + int32_t sz = taosArrayGetSize(blocks); + tlen += taosEncodeFixedI32(buf, sz); + + for (int32_t i = 0; i < sz; i++) { + SSDataBlock* pBlock = taosArrayGet(blocks, i); + tlen += tEncodeDataBlock(buf, pBlock); + } + + return tlen; +} + +void* tDecodeDataBlocks(const void* buf, SArray* blocks) { + int32_t sz; + buf = taosDecodeFixedI32(buf, &sz); + for (int32_t i = 0; i < sz; i++) { + SSDataBlock pBlock = {0}; + buf = tDecodeDataBlock(buf, &pBlock); + } + return (void*)buf; +} diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b4caf5ba97..44a8334848 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2720,8 +2720,8 @@ int32_t tEncodeSStreamTask(SCoder *pEncoder, const SStreamTask *pTask) { if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->level) < 0) return -1; if (tEncodeI8(pEncoder, pTask->status) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->pipeEnd) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->parallel) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->pipeSink) < 0) return -1; + // if (tEncodeI8(pEncoder, pTask->numOfRunners) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->NextOpEp) < 0) return -1; if (tEncodeCStr(pEncoder, pTask->qmsg) < 0) return -1; tEndEncode(pEncoder); @@ -2734,8 +2734,8 @@ int32_t tDecodeSStreamTask(SCoder *pDecoder, SStreamTask *pTask) { if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->level) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->pipeEnd) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->parallel) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->pipeSink) < 0) return -1; + // if (tDecodeI8(pDecoder, &pTask->numOfRunners) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->NextOpEp) < 0) return -1; if (tDecodeCStrAlloc(pDecoder, &pTask->qmsg) < 0) return -1; tEndDecode(pDecoder); diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vnode/src/vmMsg.c index 9f86351985..597a9862fc 100644 --- a/source/dnode/mgmt/vnode/src/vmMsg.c +++ b/source/dnode/mgmt/vnode/src/vmMsg.c @@ -273,6 +273,7 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_EXEC, (NodeMsgFp)vmProcessFetchMsg, 0); diff --git a/source/dnode/mnode/impl/inc/mndSnode.h b/source/dnode/mnode/impl/inc/mndSnode.h index 8d64879605..180f18a6dd 100644 --- a/source/dnode/mnode/impl/inc/mndSnode.h +++ b/source/dnode/mnode/impl/inc/mndSnode.h @@ -24,6 +24,7 @@ extern "C" { int32_t mndInitSnode(SMnode *pMnode); void mndCleanupSnode(SMnode *pMnode); +SEpSet mndAcquireEpFromSnode(SMnode *pMnode, const SSnodeObj *pSnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index c28c0d76c4..b95574ea41 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -20,6 +20,7 @@ #include "mndMnode.h" #include "mndOffset.h" #include "mndShow.h" +#include "mndSnode.h" #include "mndStb.h" #include "mndStream.h" #include "mndSubscribe.h" @@ -31,7 +32,7 @@ #include "tname.h" #include "tuuid.h" -int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet* pEpSet) { +int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet* pEpSet, tmsg_t type) { SCoder encoder; tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); tEncodeSStreamTask(&encoder, pTask); @@ -52,7 +53,7 @@ int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet memcpy(&action.epSet, pEpSet, sizeof(SEpSet)); action.pCont = buf; action.contLen = tlen; - action.msgType = TDMT_SND_TASK_DEPLOY; + action.msgType = type; if (mndTransAppendRedoAction(pTrans, &action) != 0) { rpcFreeCont(buf); return -1; @@ -69,12 +70,27 @@ int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SS terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } - mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet); + mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_VND_TASK_DEPLOY); return 0; } +SSnodeObj* mndSchedFetchSnode(SMnode* pMnode) { + SSnodeObj* pObj = NULL; + pObj = sdbFetch(pMnode->pSdb, SDB_SNODE, NULL, (void**)&pObj); + return pObj; +} + int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SSubplan* plan, const SSnodeObj* pSnode) { + int32_t msgLen; + plan->execNode.nodeId = pSnode->id; + plan->execNode.epSet = mndAcquireEpFromSnode(pMnode, pSnode); + + if (qSubPlanToString(plan, &pTask->qmsg, &msgLen) < 0) { + terrno = TSDB_CODE_QRY_INVALID_INPUT; + return -1; + } + mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_SND_TASK_DEPLOY); return 0; } @@ -113,8 +129,8 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { // send to vnode SStreamTask* pTask = streamTaskNew(pStream->uid, level); + pTask->pipeSink = level == totLevel - 1 ? 1 : 0; // TODO: set to - pTask->parallel = 4; if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) { sdbRelease(pSdb, pVgroup); qDestroyQueryPlan(pPlan); @@ -122,34 +138,20 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { } taosArrayPush(taskOneLevel, pTask); } - - } else if (plan->subplanType == SUBPLAN_TYPE_SCAN) { - // duplicatable - - int32_t parallel = 0; - // if no snode, parallel set to fetch thread num in vnode - - // if has snode, set to shared thread num in snode - parallel = SND_SHARED_THREAD_NUM; - - SStreamTask* pTask = streamTaskNew(pStream->uid, level); - pTask->parallel = parallel; - // TODO:get snode id and ep - if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) { - sdbRelease(pSdb, pVgroup); - qDestroyQueryPlan(pPlan); - return -1; - } - taosArrayPush(taskOneLevel, pTask); } else { - // not duplicatable SStreamTask* pTask = streamTaskNew(pStream->uid, level); - - // TODO: get snode - if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) { - sdbRelease(pSdb, pVgroup); - qDestroyQueryPlan(pPlan); - return -1; + pTask->pipeSink = level == totLevel - 1 ? 1 : 0; + SSnodeObj* pSnode = mndSchedFetchSnode(pMnode); + if (pSnode != NULL) { + if (mndAssignTaskToSnode(pMnode, pTrans, pTask, plan, pSnode) < 0) { + sdbRelease(pSdb, pSnode); + qDestroyQueryPlan(pPlan); + return -1; + } + sdbRelease(pMnode->pSdb, pSnode); + } else { + // TODO: assign to one vg + ASSERT(0); } taosArrayPush(taskOneLevel, pTask); } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index dda02fecf2..f01b143fbc 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -60,6 +60,15 @@ int32_t mndInitSnode(SMnode *pMnode) { void mndCleanupSnode(SMnode *pMnode) {} +SEpSet mndAcquireEpFromSnode(SMnode *pMnode, const SSnodeObj *pSnode) { + SEpSet epSet; + memcpy(epSet.eps->fqdn, pSnode->pDnode->fqdn, 128); + epSet.eps->port = pSnode->pDnode->port; + epSet.numOfEps = 1; + epSet.inUse = 0; + return epSet; +} + static SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) { SSnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_SNODE, &snodeId); if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index 147f44b260..afa5930821 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -57,8 +57,8 @@ void sndMetaDelete(SStreamMeta *pMeta) { } int32_t sndMetaDeployTask(SStreamMeta *pMeta, SStreamTask *pTask) { - for (int i = 0; i < pTask->parallel; i++) { - pTask->runner.executor[i] = qCreateStreamExecTaskInfo(pTask->qmsg, NULL); + for (int i = 0; i < pTask->numOfRunners; i++) { + pTask->runner[i].executor = qCreateStreamExecTaskInfo(pTask->qmsg, NULL); } return taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), pTask, sizeof(void *)); } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 87c670a4e9..3af79ca461 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -70,6 +70,46 @@ void tqClose(STQ* pTq) { int tqPushMsg(STQ* pTq, void* msg, tmsg_t msgType, int64_t version) { if (msgType != TDMT_VND_SUBMIT) return 0; + + void* pIter = NULL; + + while (1) { + pIter = taosHashIterate(pTq->pStreamTasks, pIter); + if (pIter == NULL) break; + SStreamTask* pTask = (SStreamTask*)pIter; + if (!pTask->pipeSource) continue; + + int32_t workerId = 0; + void* exec = pTask->runner[workerId].executor; + qSetStreamInput(exec, msg, STREAM_DATA_TYPE_SUBMIT_BLOCK); + SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); + while (1) { + SSDataBlock* output; + uint64_t ts; + if (qExecTask(exec, &output, &ts) < 0) { + ASSERT(false); + } + if (output == NULL) { + break; + } + taosArrayPush(pRes, output); + } + if (pTask->pipeSink) { + // write back + } else { + int32_t tlen = sizeof(SStreamExecMsgHead) + tEncodeDataBlocks(NULL, pRes); + void* buf = rpcMallocCont(tlen); + if (buf == NULL) { + return -1; + } + void* abuf = POINTER_SHIFT(buf, sizeof(SStreamExecMsgHead)); + tEncodeDataBlocks(abuf, pRes); + // serialize + // to next level + } + } + +#if 0 void* pIter = taosHashIterate(pTq->tqPushMgr->pHash, NULL); while (pIter != NULL) { STqPusher* pusher = *(STqPusher**)pIter; @@ -97,6 +137,7 @@ int tqPushMsg(STQ* pTq, void* msg, tmsg_t msgType, int64_t version) { // if handle waiting, launch query and response to consumer // // if no waiting handle, return +#endif return 0; } @@ -420,6 +461,21 @@ int32_t tqProcessSetConnReq(STQ* pTq, char* msg) { return 0; } +int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) { + ASSERT(parallel <= 8); + pTask->numOfRunners = parallel; + for (int32_t i = 0; i < parallel; i++) { + STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta); + SReadHandle handle = { + .reader = pReadHandle, + .meta = pTq->pVnodeMeta, + }; + pTask->runner[i].inputHandle = pReadHandle; + pTask->runner[i].executor = qCreateStreamExecTaskInfo(pTask->qmsg, &handle); + } + return 0; +} + int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { SStreamTask* pTask = malloc(sizeof(SStreamTask)); if (pTask == NULL) { @@ -430,12 +486,118 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { tDecodeSStreamTask(&decoder, pTask); tCoderClear(&decoder); + tqExpandTask(pTq, pTask, 8); taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask)); return 0; } +static char* formatTimestamp(char* buf, int64_t val, int precision) { + time_t tt; + int32_t ms = 0; + if (precision == TSDB_TIME_PRECISION_NANO) { + tt = (time_t)(val / 1000000000); + ms = val % 1000000000; + } else if (precision == TSDB_TIME_PRECISION_MICRO) { + tt = (time_t)(val / 1000000); + ms = val % 1000000; + } else { + tt = (time_t)(val / 1000); + ms = val % 1000; + } + + /* comment out as it make testcases like select_with_tags.sim fail. + but in windows, this may cause the call to localtime crash if tt < 0, + need to find a better solution. + if (tt < 0) { + tt = 0; + } + */ + +#ifdef WINDOWS + if (tt < 0) tt = 0; +#endif + if (tt <= 0 && ms < 0) { + tt--; + if (precision == TSDB_TIME_PRECISION_NANO) { + ms += 1000000000; + } else if (precision == TSDB_TIME_PRECISION_MICRO) { + ms += 1000000; + } else { + ms += 1000; + } + } + + struct tm* ptm = localtime(&tt); + size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm); + + if (precision == TSDB_TIME_PRECISION_NANO) { + sprintf(buf + pos, ".%09d", ms); + } else if (precision == TSDB_TIME_PRECISION_MICRO) { + sprintf(buf + pos, ".%06d", ms); + } else { + sprintf(buf + pos, ".%03d", ms); + } + + return buf; +} +void tqDebugShowSSData(SArray* dataBlocks) { + char pBuf[128]; + int32_t sz = taosArrayGetSize(dataBlocks); + for (int32_t i = 0; i < sz; i++) { + SSDataBlock* pDataBlock = taosArrayGet(dataBlocks, i); + int32_t colNum = pDataBlock->info.numOfCols; + int32_t rows = pDataBlock->info.rows; + for (int32_t j = 0; j < rows; j++) { + printf("|"); + for (int32_t k = 0; k < colNum; k++) { + SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k); + void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); + switch (pColInfoData->info.type) { + case TSDB_DATA_TYPE_TIMESTAMP: + formatTimestamp(pBuf, *(uint64_t*)var, TSDB_TIME_PRECISION_MILLI); + printf(" %25s |", pBuf); + break; + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + printf(" %15u |", *(uint32_t*)var); + break; + } + } + printf("\n"); + } + } +} + int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg) { - // + SStreamTaskExecReq* pReq = msg->pCont; + + int32_t taskId = pReq->head.streamTaskId; + int32_t workerType = pReq->head.workerType; + + SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + // assume worker id is 1 + int32_t workerId = 1; + void* exec = pTask->runner[workerId].executor; + int32_t sz = taosArrayGetSize(pReq->data); + printf("input data:\n"); + tqDebugShowSSData(pReq->data); + SArray* pRes = taosArrayInit(0, sizeof(void*)); + for (int32_t i = 0; i < sz; i++) { + SSDataBlock* input = taosArrayGet(pReq->data, i); + SSDataBlock* output; + uint64_t ts; + qSetStreamInput(exec, input, STREAM_DATA_TYPE_SSDATA_BLOCK); + if (qExecTask(exec, &output, &ts) < 0) { + ASSERT(0); + } + if (output == NULL) { + break; + } + taosArrayPush(pRes, &output); + } + printf("output data:\n"); + tqDebugShowSSData(pRes); + return 0; } diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index e6cdbcf10f..edacfc339f 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -52,9 +52,8 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, int32_t t SSDataBlock* pDataBlock = input; pInfo->pRes->info = pDataBlock->info; - for(int32_t i = 0; i < pInfo->pRes->info.numOfCols; ++i) { - pInfo->pRes->pDataBlock = pDataBlock->pDataBlock; - } + taosArrayClear(pInfo->pRes->pDataBlock); + taosArrayAddAll(pInfo->pRes->pDataBlock, pDataBlock->pDataBlock); // set current block valid. pInfo->blockValid = true; @@ -121,7 +120,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isA // traverse to the streamscan node to add this table id SOperatorInfo* pInfo = pTaskInfo->pRoot; - while(pInfo->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { + while (pInfo->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { pInfo = pInfo->pDownstream[0]; } From afe8439095abadb8e559f3a644a46b3ef46f176c Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Tue, 22 Mar 2022 18:58:43 +0800 Subject: [PATCH 23/68] fix typo --- example/src/tstream.c | 4 +++- source/libs/executor/src/executorimpl.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example/src/tstream.c b/example/src/tstream.c index 73ab655fbd..a606024cf1 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -215,10 +215,12 @@ int main(int argc, char* argv[]) { printf("env init\n"); code = init_env(); } - create_topic(); + create_stream(); +#if 0 tmq_t* tmq = build_consumer(); tmq_list_t* topic_list = build_topic_list(); /*perf_loop(tmq, topic_list);*/ /*basic_consume_loop(tmq, topic_list);*/ sync_consume_loop(tmq, topic_list); +#endif } diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index befb210b80..0e3e76faf0 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -4873,7 +4873,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo *pOperator, bool* newgroup) SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStreamBlockScanInfo* pInfo = pOperator->info; - if (pInfo->blockType == STREAM_DATA_TYPE_SSDAT_BLOCK) { + if (pInfo->blockType == STREAM_DATA_TYPE_SSDATA_BLOCK) { if (pInfo->blockValid) { pInfo->blockValid = false; // this block can only be used once. return pInfo->pRes; From c74b88afbbd63d3d384bc2845caf48462c7ce6ab Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Tue, 22 Mar 2022 19:47:57 +0800 Subject: [PATCH 24/68] put tq header input vnd --- example/src/tstream.c | 121 ------------------- source/dnode/vnode/inc/tq.h | 66 ---------- source/dnode/vnode/src/inc/tqInt.h | 7 +- source/dnode/vnode/src/inc/vnd.h | 22 +++- source/dnode/vnode/src/vnd/vnodeQuery.c | 1 + source/dnode/vnode/src/vnd/vnodeWrite.c | 3 +- source/dnode/vnode/test/tqSerializerTest.cpp | 13 -- source/libs/executor/src/executor.c | 2 +- 8 files changed, 30 insertions(+), 205 deletions(-) delete mode 100644 source/dnode/vnode/inc/tq.h delete mode 100644 source/dnode/vnode/test/tqSerializerTest.cpp diff --git a/example/src/tstream.c b/example/src/tstream.c index a606024cf1..62d94b041d 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -19,9 +19,6 @@ #include #include "taos.h" -static int running = 1; -static void msg_process(tmq_message_t* message) { tmqShowMsg(message); } - int32_t init_env() { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); if (pConn == NULL) { @@ -91,124 +88,6 @@ int32_t create_stream() { return 0; } -void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_t* offsets, void* param) { - printf("commit %d\n", resp); -} - -tmq_t* build_consumer() { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "use abc1"); - if (taos_errno(pRes) != 0) { - printf("error in use db, reason:%s\n", taos_errstr(pRes)); - } - taos_free_result(pRes); - - tmq_conf_t* conf = tmq_conf_new(); - tmq_conf_set(conf, "group.id", "tg2"); - tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print); - tmq_t* tmq = tmq_consumer_new(pConn, conf, NULL, 0); - return tmq; -} - -tmq_list_t* build_topic_list() { - tmq_list_t* topic_list = tmq_list_new(); - tmq_list_append(topic_list, "test_stb_topic_1"); - return topic_list; -} - -void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { - tmq_resp_err_t err; - - if ((err = tmq_subscribe(tmq, topics))) { - fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err)); - printf("subscribe err\n"); - return; - } - /*int32_t cnt = 0;*/ - /*clock_t startTime = clock();*/ - while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 500); - if (tmqmessage) { - /*cnt++;*/ - msg_process(tmqmessage); - tmq_message_destroy(tmqmessage); - /*} else {*/ - /*break;*/ - } - } - /*clock_t endTime = clock();*/ - /*printf("log cnt: %d %f s\n", cnt, (double)(endTime - startTime) / CLOCKS_PER_SEC);*/ - - err = tmq_consumer_close(tmq); - if (err) - fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); - else - fprintf(stderr, "%% Consumer closed\n"); -} - -void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { - static const int MIN_COMMIT_COUNT = 1; - - int msg_count = 0; - tmq_resp_err_t err; - - if ((err = tmq_subscribe(tmq, topics))) { - fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err)); - return; - } - - while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1000); - if (tmqmessage) { - msg_process(tmqmessage); - tmq_message_destroy(tmqmessage); - - if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0); - } - } - - err = tmq_consumer_close(tmq); - if (err) - fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); - else - fprintf(stderr, "%% Consumer closed\n"); -} - -void perf_loop(tmq_t* tmq, tmq_list_t* topics) { - tmq_resp_err_t err; - - if ((err = tmq_subscribe(tmq, topics))) { - fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(err)); - printf("subscribe err\n"); - return; - } - int32_t batchCnt = 0; - int32_t skipLogNum = 0; - clock_t startTime = clock(); - while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 500); - if (tmqmessage) { - batchCnt++; - skipLogNum += tmqGetSkipLogNum(tmqmessage); - /*msg_process(tmqmessage);*/ - tmq_message_destroy(tmqmessage); - } else { - break; - } - } - clock_t endTime = clock(); - printf("log batch cnt: %d, skip log cnt: %d, time used:%f s\n", batchCnt, skipLogNum, - (double)(endTime - startTime) / CLOCKS_PER_SEC); - - err = tmq_consumer_close(tmq); - if (err) - fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); - else - fprintf(stderr, "%% Consumer closed\n"); -} - int main(int argc, char* argv[]) { int code; if (argc > 1) { diff --git a/source/dnode/vnode/inc/tq.h b/source/dnode/vnode/inc/tq.h deleted file mode 100644 index 6391eaffea..0000000000 --- a/source/dnode/vnode/inc/tq.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TQ_H_ -#define _TQ_H_ - -#include "executor.h" -#include "meta.h" -#include "taoserror.h" -#include "tcommon.h" -#include "tmallocator.h" -#include "tmsg.h" -#include "trpc.h" -#include "ttimer.h" -#include "tutil.h" -#include "vnode.h" -#include "wal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct STQ STQ; - -// memory allocator provided by vnode -typedef struct { - SMemAllocatorFactory* pAllocatorFactory; - SMemAllocator* pAllocator; -} STqMemRef; - -// init once -int tqInit(); -void tqCleanUp(); - -// open in each vnode -STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAllocatorFactory* allocFac); -void tqClose(STQ*); - -// required by vnode -int tqPushMsg(STQ*, void* msg, tmsg_t msgType, int64_t version); -int tqCommit(STQ*); - -int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); -int32_t tqProcessSetConnReq(STQ* pTq, char* msg); -int32_t tqProcessRebReq(STQ* pTq, char* msg); -int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg); - -int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); - -#ifdef __cplusplus -} -#endif - -#endif /*_TQ_H_*/ diff --git a/source/dnode/vnode/src/inc/tqInt.h b/source/dnode/vnode/src/inc/tqInt.h index 9b21cf92ce..4d4bb12a21 100644 --- a/source/dnode/vnode/src/inc/tqInt.h +++ b/source/dnode/vnode/src/inc/tqInt.h @@ -18,8 +18,8 @@ #include "meta.h" #include "tlog.h" -#include "tq.h" #include "tqPush.h" +#include "vnd.h" #ifdef __cplusplus extern "C" { @@ -153,6 +153,11 @@ typedef struct { FTqDelete pDeleter; } STqMetaStore; +typedef struct { + SMemAllocatorFactory* pAllocatorFactory; + SMemAllocator* pAllocator; +} STqMemRef; + struct STQ { // the collection of groups // the handle of meta kvstore diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index c911f95e4a..ed9aad9277 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -23,7 +23,6 @@ #include "tlist.h" #include "tlockfree.h" #include "tmacro.h" -#include "tq.h" #include "wal.h" #include "vnode.h" @@ -34,6 +33,8 @@ extern "C" { #endif +typedef struct STQ STQ; + typedef struct SVState SVState; typedef struct SVBufPool SVBufPool; @@ -171,6 +172,25 @@ void* vmaMalloc(SVMemAllocator* pVMA, uint64_t size); void vmaFree(SVMemAllocator* pVMA, void* ptr); bool vmaIsFull(SVMemAllocator* pVMA); +// init once +int tqInit(); +void tqCleanUp(); + +// open in each vnode +STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAllocatorFactory* allocFac); +void tqClose(STQ*); + +// required by vnode +int tqPushMsg(STQ*, void* msg, tmsg_t msgType, int64_t version); +int tqCommit(STQ*); + +int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); +int32_t tqProcessSetConnReq(STQ* pTq, char* msg); +int32_t tqProcessRebReq(STQ* pTq, char* msg); +int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg); + +int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index d7af04c462..ef755b10ec 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -14,6 +14,7 @@ */ #include "vnodeQuery.h" +#include "executor.h" #include "vnd.h" static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg); diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index d3769b8a30..5443194efd 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -13,12 +13,11 @@ * along with this program. If not, see . */ -#include "tq.h" #include "vnd.h" void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { SNodeMsg *pMsg; - SRpcMsg *pRpc; + SRpcMsg *pRpc; for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { pMsg = *(SNodeMsg **)taosArrayGet(pMsgs, i); diff --git a/source/dnode/vnode/test/tqSerializerTest.cpp b/source/dnode/vnode/test/tqSerializerTest.cpp deleted file mode 100644 index 0d76322c17..0000000000 --- a/source/dnode/vnode/test/tqSerializerTest.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include - -#include "tq.h" - -using namespace std; - -TEST(TqSerializerTest, basicTest) { - TqGroupHandle* gHandle = (TqGroupHandle*)malloc(sizeof(TqGroupHandle)); - -} diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index edacfc339f..19100d7560 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -16,7 +16,7 @@ #include "executor.h" #include "executorimpl.h" #include "planner.h" -#include "tq.h" +#include "vnode.h" static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, int32_t type, char* id) { ASSERT(pOperator != NULL); From 997a0a939548cfdde96a476ed85f99514b0bad91 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Tue, 22 Mar 2022 20:07:01 +0800 Subject: [PATCH 25/68] remove duplicate msg handler --- source/dnode/mgmt/mnode/src/mmMsg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/dnode/mgmt/mnode/src/mmMsg.c b/source/dnode/mgmt/mnode/src/mmMsg.c index 8445e73787..56a580ed93 100644 --- a/source/dnode/mgmt/mnode/src/mmMsg.c +++ b/source/dnode/mgmt/mnode/src/mmMsg.c @@ -149,5 +149,4 @@ void mmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)mmProcessWriteMsg, 0); } From cf95e5a7697a726b033335f5e635a7766016b44d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 22 Mar 2022 23:33:03 +0800 Subject: [PATCH 26/68] [td-13039] update test. --- source/client/test/clientTests.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 1b2c955946..ac092c8f10 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -660,20 +660,12 @@ TEST(testCase, agg_query_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "select * from tu"); - -// pRes = taos_query(pConn, "create table tx using st1 tags(111111111111111)"); -// if (taos_errno(pRes) != 0) { -// printf("failed to create table, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "select count(*) from tu"); -// if (taos_errno(pRes) != 0) { -// printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); -// taos_free_result(pRes); -// ASSERT_TRUE(false); -// } + pRes = taos_query(pConn, "select count(*), sum(k),min(k),max(k) from tu"); + if (taos_errno(pRes) != 0) { + printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } TAOS_ROW pRow = NULL; TAOS_FIELD* pFields = taos_fetch_fields(pRes); From 636edd5568067de3a838d17ab75920234d9882d1 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 22 Mar 2022 23:33:53 +0800 Subject: [PATCH 27/68] [td-13039] update test. --- tools/shell/src/shellMain.c | 671 ------------------------------------ 1 file changed, 671 deletions(-) delete mode 100644 tools/shell/src/shellMain.c diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c deleted file mode 100644 index 78d6f74df1..0000000000 --- a/tools/shell/src/shellMain.c +++ /dev/null @@ -1,671 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define __USE_XOPEN -#include "os.h" -#include "shell.h" -#include "tglobal.h" -#include "shellCommand.h" -#include "tbase64.h" -#include "tlog.h" -#include "version.h" - -#include -#include -#include - -#define OPT_ABORT 1 /* abort */ - - -int indicator = 1; - -void insertChar(Command *cmd, char *c, int size); -const char *argp_program_version = version; -const char *argp_program_bug_address = ""; -static char doc[] = ""; -static char args_doc[] = ""; - -TdThread pid; -static tsem_t cancelSem; - -static struct argp_option options[] = { - {"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."}, - {"password", 'p', 0, 0, "The password to use when connecting to the server."}, - {"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."}, - {"user", 'u', "USER", 0, "The user name to use when connecting to the server."}, - {"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."}, - {"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."}, - {"dump-config", 'C', 0, 0, "Dump configuration."}, - {"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."}, - {"raw-time", 'r', 0, 0, "Output time as uint64_t."}, - {"file", 'f', "FILE", 0, "Script to run without enter the shell."}, - {"directory", 'D', "DIRECTORY", 0, "Use multi-thread to import all SQL files in the directory separately."}, - {"thread", 'T', "THREADNUM", 0, "Number of threads when using multi-thread to import data."}, - {"check", 'k', "CHECK", 0, "Check tables."}, - {"database", 'd', "DATABASE", 0, "Database to use when connecting to the server."}, - {"timezone", 'z', "TIMEZONE", 0, "Time zone of the shell, default is local."}, - {"netrole", 'n', "NETROLE", 0, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync|speen|fqdn."}, - {"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."}, - {"pktnum", 'N', "PKTNUM", 0, "Packet numbers used for net test, default is 100."}, - {"pkttype", 'S', "PKTTYPE", 0, "Packet type used for net test, default is TCP."}, - {0}}; - -static error_t parse_opt(int key, char *arg, struct argp_state *state) { - /* Get the input argument from argp_parse, which we - know is a pointer to our arguments structure. */ - SShellArguments *arguments = state->input; - wordexp_t full_path; - - switch (key) { - case 'h': - arguments->host = arg; - break; - case 'p': - break; - case 'P': - if (arg) { - arguments->port = atoi(arg); - } else { - fprintf(stderr, "Invalid port\n"); - return -1; - } - - break; - case 'z': - arguments->timezone = arg; - break; - case 'u': - arguments->user = arg; - break; - case 'A': - arguments->auth = arg; - break; - case 'c': - if (wordexp(arg, &full_path, 0) != 0) { - fprintf(stderr, "Invalid path %s\n", arg); - return -1; - } - if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) { - fprintf(stderr, "config file path: %s overflow max len %d\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1); - wordfree(&full_path); - return -1; - } - tstrncpy(configDir, full_path.we_wordv[0], TSDB_FILENAME_LEN); - wordfree(&full_path); - break; - case 'C': - arguments->dump_config = true; - break; - case 's': - arguments->commands = arg; - break; - case 'r': - arguments->is_raw_time = true; - break; - case 'f': - if ((0 == strlen(arg)) || (wordexp(arg, &full_path, 0) != 0)) { - fprintf(stderr, "Invalid path %s\n", arg); - return -1; - } - tstrncpy(arguments->file, full_path.we_wordv[0], TSDB_FILENAME_LEN); - wordfree(&full_path); - break; - case 'D': - if (wordexp(arg, &full_path, 0) != 0) { - fprintf(stderr, "Invalid path %s\n", arg); - return -1; - } - tstrncpy(arguments->dir, full_path.we_wordv[0], TSDB_FILENAME_LEN); - wordfree(&full_path); - break; - case 'T': - if (arg) { - arguments->threadNum = atoi(arg); - } else { - fprintf(stderr, "Invalid number of threads\n"); - return -1; - } - break; - case 'k': - arguments->check = atoi(arg); - break; - case 'd': - arguments->database = arg; - break; - case 'n': - arguments->netTestRole = arg; - break; - case 'l': - if (arg) { - arguments->pktLen = atoi(arg); - } else { - fprintf(stderr, "Invalid packet length\n"); - return -1; - } - break; - case 'N': - if (arg) { - arguments->pktNum = atoi(arg); - } else { - fprintf(stderr, "Invalid packet number\n"); - return -1; - } - break; - case 'S': - arguments->pktType = arg; - break; - case OPT_ABORT: - arguments->abort = 1; - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -/* Our argp parser. */ -static struct argp argp = {options, parse_opt, args_doc, doc}; - -char LINUXCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n" - "Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n"; -char g_password[SHELL_MAX_PASSWORD_LEN]; - -static void parse_args( - int argc, char *argv[], SShellArguments *arguments) { - for (int i = 1; i < argc; i++) { - if ((strncmp(argv[i], "-p", 2) == 0) - || (strncmp(argv[i], "--password", 10) == 0)) { - printf(LINUXCLIENT_VERSION, tsOsName, taos_get_client_info()); - if ((strlen(argv[i]) == 2) - || (strncmp(argv[i], "--password", 10) == 0)) { - printf("Enter password: "); - taosSetConsoleEcho(false); - if (scanf("%20s", g_password) > 1) { - fprintf(stderr, "password reading error\n"); - } - taosSetConsoleEcho(true); - if (EOF == getchar()) { - fprintf(stderr, "getchar() return EOF\n"); - } - } else { - tstrncpy(g_password, (char *)(argv[i] + 2), SHELL_MAX_PASSWORD_LEN); - strcpy(argv[i], "-p"); - } - arguments->password = g_password; - arguments->is_use_passwd = true; - } - } -} - -void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { - static char verType[32] = {0}; - sprintf(verType, "version: %s\n", version); - - argp_program_version = verType; - - if (argc > 1) { - parse_args(argc, argv, arguments); - } - - argp_parse(&argp, argc, argv, 0, 0, arguments); - if (arguments->abort) { - #ifndef _ALPINE - #if 0 - error(10, 0, "ABORTED"); - #endif - #else - abort(); - #endif - } -} - -int32_t shellReadCommand(TAOS *con, char *command) { - unsigned hist_counter = history.hend; - char utf8_array[10] = "\0"; - Command cmd; - memset(&cmd, 0, sizeof(cmd)); - cmd.buffer = (char *)calloc(1, MAX_COMMAND_SIZE); - cmd.command = (char *)calloc(1, MAX_COMMAND_SIZE); - showOnScreen(&cmd); - - // Read input. - char c; - while (1) { - c = (char)getchar(); // getchar() return an 'int' value - - if (c == EOF) { - return c; - } - - if (c < 0) { // For UTF-8 - int count = countPrefixOnes(c); - utf8_array[0] = c; - for (int k = 1; k < count; k++) { - c = (char)getchar(); - utf8_array[k] = c; - } - insertChar(&cmd, utf8_array, count); - } else if (c < '\033') { - // Ctrl keys. TODO: Implement ctrl combinations - switch (c) { - case 1: // ctrl A - positionCursorHome(&cmd); - break; - case 3: - printf("\n"); - resetCommand(&cmd, ""); - kill(0, SIGINT); - break; - case 4: // EOF or Ctrl+D - printf("\n"); - taos_close(con); - // write the history - write_history(); - exitShell(); - break; - case 5: // ctrl E - positionCursorEnd(&cmd); - break; - case 8: - backspaceChar(&cmd); - break; - case '\n': - case '\r': - printf("\n"); - if (isReadyGo(&cmd)) { - sprintf(command, "%s%s", cmd.buffer, cmd.command); - tfree(cmd.buffer); - tfree(cmd.command); - return 0; - } else { - updateBuffer(&cmd); - } - break; - case 11: // Ctrl + K; - clearLineAfter(&cmd); - break; - case 12: // Ctrl + L; - system("clear"); - showOnScreen(&cmd); - break; - case 21: // Ctrl + U; - clearLineBefore(&cmd); - break; - } - } else if (c == '\033') { - c = (char)getchar(); - switch (c) { - case '[': - c = (char)getchar(); - switch (c) { - case 'A': // Up arrow - if (hist_counter != history.hstart) { - hist_counter = (hist_counter + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE; - resetCommand(&cmd, (history.hist[hist_counter] == NULL) ? "" : history.hist[hist_counter]); - } - break; - case 'B': // Down arrow - if (hist_counter != history.hend) { - int next_hist = (hist_counter + 1) % MAX_HISTORY_SIZE; - - if (next_hist != history.hend) { - resetCommand(&cmd, (history.hist[next_hist] == NULL) ? "" : history.hist[next_hist]); - } else { - resetCommand(&cmd, ""); - } - hist_counter = next_hist; - } - break; - case 'C': // Right arrow - moveCursorRight(&cmd); - break; - case 'D': // Left arrow - moveCursorLeft(&cmd); - break; - case '1': - if ((c = (char)getchar()) == '~') { - // Home key - positionCursorHome(&cmd); - } - break; - case '2': - if ((c = (char)getchar()) == '~') { - // Insert key - } - break; - case '3': - if ((c = (char)getchar()) == '~') { - // Delete key - deleteChar(&cmd); - } - break; - case '4': - if ((c = (char)getchar()) == '~') { - // End key - positionCursorEnd(&cmd); - } - break; - case '5': - if ((c = (char)getchar()) == '~') { - // Page up key - } - break; - case '6': - if ((c = (char)getchar()) == '~') { - // Page down key - } - break; - case 72: - // Home key - positionCursorHome(&cmd); - break; - case 70: - // End key - positionCursorEnd(&cmd); - break; - } - break; - } - } else if (c == 0x7f) { - // press delete key - backspaceChar(&cmd); - } else { - insertChar(&cmd, &c, 1); - } - } - - return 0; -} - -void *shellLoopQuery(void *arg) { - if (indicator) { - getOldTerminalMode(); - indicator = 0; - } - - TAOS *con = (TAOS *)arg; - - setThreadName("shellLoopQuery"); - - taosThreadCleanupPush(cleanup_handler, NULL); - - char *command = malloc(MAX_COMMAND_SIZE); - if (command == NULL){ - uError("failed to malloc command"); - return NULL; - } - - int32_t err = 0; - - do { - // Read command from shell. - memset(command, 0, MAX_COMMAND_SIZE); - setTerminalMode(); - err = shellReadCommand(con, command); - if (err) { - break; - } - resetTerminalMode(); - } while (shellRunCommand(con, command) == 0); - - tfree(command); - exitShell(); - - taosThreadCleanupPop(1); - - return NULL; -} - -void get_history_path(char *_history) { snprintf(_history, TSDB_FILENAME_LEN, "%s/%s", getenv("HOME"), HISTORY_FILE); } - -void clearScreen(int ecmd_pos, int cursor_pos) { - struct winsize w; - if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) { - //fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n"); - w.ws_col = 120; - w.ws_row = 30; - } - - int cursor_x = cursor_pos / w.ws_col; - int cursor_y = cursor_pos % w.ws_col; - int command_x = ecmd_pos / w.ws_col; - positionCursor(cursor_y, LEFT); - positionCursor(command_x - cursor_x, DOWN); - fprintf(stdout, "\033[2K"); - for (int i = 0; i < command_x; i++) { - positionCursor(1, UP); - fprintf(stdout, "\033[2K"); - } - fflush(stdout); -} - -void showOnScreen(Command *cmd) { - struct winsize w; - if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) { - //fprintf(stderr, "No stream device\n"); - w.ws_col = 120; - w.ws_row = 30; - } - - TdWchar wc; - int size = 0; - - // Print out the command. - char *total_string = malloc(MAX_COMMAND_SIZE); - memset(total_string, '\0', MAX_COMMAND_SIZE); - if (strcmp(cmd->buffer, "") == 0) { - sprintf(total_string, "%s%s", PROMPT_HEADER, cmd->command); - } else { - sprintf(total_string, "%s%s", CONTINUE_PROMPT, cmd->command); - } - - int remain_column = w.ws_col; - /* size = cmd->commandSize + prompt_size; */ - for (char *str = total_string; size < cmd->commandSize + prompt_size;) { - int ret = taosMbToWchar(&wc, str, MB_CUR_MAX); - if (ret < 0) break; - size += ret; - /* assert(size >= 0); */ - int width = taosWcharWidth(wc); - if (remain_column > width) { - printf("%lc", wc); - remain_column -= width; - } else { - if (remain_column == width) { - printf("%lc\n\r", wc); - remain_column = w.ws_col; - } else { - printf("\n\r%lc", wc); - remain_column = w.ws_col - width; - } - } - - str = total_string + size; - } - - free(total_string); - /* for (int i = 0; i < size; i++){ */ - /* char c = total_string[i]; */ - /* if (k % w.ws_col == 0) { */ - /* printf("%c\n\r", c); */ - /* } */ - /* else { */ - /* printf("%c", c); */ - /* } */ - /* k += 1; */ - /* } */ - - // Position the cursor - int cursor_pos = cmd->screenOffset + prompt_size; - int ecmd_pos = cmd->endOffset + prompt_size; - - int cursor_x = cursor_pos / w.ws_col; - int cursor_y = cursor_pos % w.ws_col; - // int cursor_y = cursor % w.ws_col; - int command_x = ecmd_pos / w.ws_col; - int command_y = ecmd_pos % w.ws_col; - // int command_y = (command.size() + prompt_size) % w.ws_col; - positionCursor(command_y, LEFT); - positionCursor(command_x, UP); - positionCursor(cursor_x, DOWN); - positionCursor(cursor_y, RIGHT); - fflush(stdout); -} - -void cleanup_handler(void *arg) { resetTerminalMode(); } - -void exitShell() { - /*int32_t ret =*/ resetTerminalMode(); - taos_cleanup(); - exit(EXIT_SUCCESS); -} -void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { - tsem_post(&cancelSem); -} - -void *cancelHandler(void *arg) { - setThreadName("cancelHandler"); - - while (1) { - if (tsem_wait(&cancelSem) != 0) { - taosMsleep(10); - continue; - } - -#ifdef LINUX -#if 0 - int64_t rid = atomic_val_compare_exchange_64(&result, result, 0); - SSqlObj* pSql = taosAcquireRef(tscObjRef, rid); - taos_stop_query(pSql); - taosReleaseRef(tscObjRef, rid); -#endif -#else - resetTerminalMode(); - printf("\nReceive ctrl+c or other signal, quit shell.\n"); - exit(0); -#endif - resetTerminalMode(); - printf("\nReceive ctrl+c or other signal, quit shell.\n"); - exit(0); - } - - return NULL; -} - -int checkVersion() { - if (sizeof(int8_t) != 1) { - printf("taos int8 size is %d(!= 1)", (int)sizeof(int8_t)); - return 0; - } - if (sizeof(int16_t) != 2) { - printf("taos int16 size is %d(!= 2)", (int)sizeof(int16_t)); - return 0; - } - if (sizeof(int32_t) != 4) { - printf("taos int32 size is %d(!= 4)", (int)sizeof(int32_t)); - return 0; - } - if (sizeof(int64_t) != 8) { - printf("taos int64 size is %d(!= 8)", (int)sizeof(int64_t)); - return 0; - } - return 1; -} - -// Global configurations -SShellArguments args = {.host = NULL, -#ifndef TD_WINDOWS - .password = NULL, -#endif - .user = NULL, - .database = NULL, - .timezone = NULL, - .is_raw_time = false, - .is_use_passwd = false, - .dump_config = false, - .file = "\0", - .dir = "\0", - .threadNum = 5, - .commands = NULL, - .pktLen = 1000, - .pktNum = 100, - .pktType = "TCP", - .netTestRole = NULL}; - -/* - * Main function. - */ -int main(int argc, char *argv[]) { - /*setlocale(LC_ALL, "en_US.UTF-8"); */ - - if (!checkVersion()) { - exit(EXIT_FAILURE); - } - - shellParseArgument(argc, argv, &args); - -#if 0 - if (args.dump_config) { - taosInitGlobalCfg(); - taosReadGlobalLogCfg(); - - if (taosReadGlobalCfg() ! =0) { - printf("TDengine read global config failed"); - exit(EXIT_FAILURE); - } - - taosDumpGlobalCfg(); - exit(0); - } - - if (args.netTestRole && args.netTestRole[0] != 0) { - if (taos_init()) { - printf("Failed to init taos"); - exit(EXIT_FAILURE); - } - taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType); - exit(0); - } -#endif - - /* Initialize the shell */ - TAOS *con = shellInit(&args); - if (con == NULL) { - exit(EXIT_FAILURE); - } - - if (tsem_init(&cancelSem, 0, 0) != 0) { - printf("failed to create cancel semphore\n"); - exit(EXIT_FAILURE); - } - - TdThread spid; - taosThreadCreate(&spid, NULL, cancelHandler, NULL); - - /* Interrupt handler. */ - taosSetSignal(SIGTERM, shellQueryInterruptHandler); - taosSetSignal(SIGINT, shellQueryInterruptHandler); - taosSetSignal(SIGHUP, shellQueryInterruptHandler); - taosSetSignal(SIGABRT, shellQueryInterruptHandler); - - /* Get grant information */ - shellGetGrantInfo(con); - - /* Loop to query the input. */ - while (1) { - taosThreadCreate(&pid, NULL, shellLoopQuery, con); - taosThreadJoin(pid, NULL); - } -} From 044db54e741f516e8cd62efcb6402f016a650349 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 23 Mar 2022 06:25:24 +0800 Subject: [PATCH 28/68] refactor --- source/dnode/mgmt/vnode/src/vmInt.c | 2 +- source/dnode/vnode/src/inc/tsdbLog.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/dnode/mgmt/vnode/src/vmInt.c b/source/dnode/mgmt/vnode/src/vmInt.c index a324c60618..746fcd4855 100644 --- a/source/dnode/mgmt/vnode/src/vmInt.c +++ b/source/dnode/mgmt/vnode/src/vmInt.c @@ -343,7 +343,7 @@ void vmGetMgmtFp(SMgmtWrapper *pWrapper) { mgmtFp.requiredFp = vmRequire; vmInitMsgHandles(pWrapper); - pWrapper->name = "vnodes"; + pWrapper->name = "vnode"; pWrapper->fp = mgmtFp; } diff --git a/source/dnode/vnode/src/inc/tsdbLog.h b/source/dnode/vnode/src/inc/tsdbLog.h index 56dc8ab2a0..3afe628198 100644 --- a/source/dnode/vnode/src/inc/tsdbLog.h +++ b/source/dnode/vnode/src/inc/tsdbLog.h @@ -24,12 +24,12 @@ extern "C" { extern int32_t tsdbDebugFlag; -#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) -#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) -#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) -#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) -#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) -#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) #ifdef __cplusplus } From d4cc6c1fe7e888bfcb55fc50446be4921c68be5c Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 23 Mar 2022 07:58:07 +0800 Subject: [PATCH 29/68] add bSma/rSma param --- include/common/tmsg.h | 36 +++++++--- source/common/src/tmsg.c | 84 ++++++++++++++++++++++- source/dnode/vnode/src/meta/metaBDBImpl.c | 2 +- source/dnode/vnode/test/tsdbSmaTest.cpp | 55 +++++++++++++++ 4 files changed, 166 insertions(+), 11 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 560490569a..583496a4c6 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1363,28 +1363,48 @@ typedef struct { int64_t tuid; } SDDropTopicReq; +typedef struct { + float xFilesFactor; + int8_t delayUnit; + int8_t nFuncIds; + int32_t* pFuncIds; + int64_t delay; +} SRSmaParam; + typedef struct SVCreateTbReq { int64_t ver; // use a general definition char* dbFName; char* name; uint32_t ttl; uint32_t keep; - uint8_t type; + union { + uint8_t info; + struct { + uint8_t rollup : 1; // 1 means rollup sma + uint8_t type : 7; + }; + }; union { struct { - tb_uid_t suid; - uint32_t nCols; - SSchema* pSchema; - uint32_t nTagCols; - SSchema* pTagSchema; + tb_uid_t suid; + uint32_t nCols; + SSchema* pSchema; + uint32_t nTagCols; + SSchema* pTagSchema; + col_id_t nBSmaCols; + col_id_t* pBSmaCols; + SRSmaParam* pRSmaParam; } stbCfg; struct { tb_uid_t suid; SKVRow pTag; } ctbCfg; struct { - uint32_t nCols; - SSchema* pSchema; + uint32_t nCols; + SSchema* pSchema; + col_id_t nBSmaCols; + col_id_t* pBSmaCols; + SRSmaParam* pRSmaParam; } ntbCfg; }; } SVCreateTbReq, SVUpdateTbReq; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 47872b89d5..1ea00566f4 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -290,7 +290,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeString(buf, pReq->name); tlen += taosEncodeFixedU32(buf, pReq->ttl); tlen += taosEncodeFixedU32(buf, pReq->keep); - tlen += taosEncodeFixedU8(buf, pReq->type); + tlen += taosEncodeFixedU8(buf, pReq->info); switch (pReq->type) { case TD_SUPER_TABLE: @@ -309,6 +309,20 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes); tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name); } + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols); + for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); + } + if(pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { + SRSmaParam *param = pReq->stbCfg.pRSmaParam; + tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); + tlen += taosEncodeFixedI8(buf, param->delayUnit); + tlen += taosEncodeFixedI8(buf, param->nFuncIds); + for(int8_t i=0; i< param->nFuncIds; ++i) { + tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); + } + tlen += taosEncodeFixedI64(buf, param->delay); + } break; case TD_CHILD_TABLE: tlen += taosEncodeFixedI64(buf, pReq->ctbCfg.suid); @@ -322,6 +336,20 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes); tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name); } + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols); + for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { + tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); + } + if(pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { + SRSmaParam *param = pReq->stbCfg.pRSmaParam; + tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); + tlen += taosEncodeFixedI8(buf, param->delayUnit); + tlen += taosEncodeFixedI8(buf, param->nFuncIds); + for(int8_t i=0; i< param->nFuncIds; ++i) { + tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); + } + tlen += taosEncodeFixedI64(buf, param->delay); + } break; default: ASSERT(0); @@ -335,7 +363,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeString(buf, &(pReq->name)); buf = taosDecodeFixedU32(buf, &(pReq->ttl)); buf = taosDecodeFixedU32(buf, &(pReq->keep)); - buf = taosDecodeFixedU8(buf, &(pReq->type)); + buf = taosDecodeFixedU8(buf, &(pReq->info)); switch (pReq->type) { case TD_SUPER_TABLE: @@ -356,6 +384,32 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name); } + buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); + if(pReq->stbCfg.nBSmaCols > 0) { + pReq->stbCfg.pBSmaCols = (col_id_t *)malloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); + for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { + buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); + } + } else { + pReq->stbCfg.pBSmaCols = NULL; + } + if(pReq->rollup) { + pReq->stbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); + SRSmaParam *param = pReq->stbCfg.pRSmaParam; + buf = taosDecodeFixedU32(buf, (uint32_t*)¶m->xFilesFactor); + buf = taosDecodeFixedI8(buf, ¶m->delayUnit); + buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); + if(param->nFuncIds > 0) { + for (int8_t i = 0; i< param->nFuncIds; ++i) { + buf = taosDecodeFixedI32(buf, param->pFuncIds + i); + } + } else { + param->pFuncIds = NULL; + } + buf = taosDecodeFixedI64(buf, ¶m->delay); + } else { + pReq->stbCfg.pRSmaParam = NULL; + } break; case TD_CHILD_TABLE: buf = taosDecodeFixedI64(buf, &pReq->ctbCfg.suid); @@ -370,6 +424,32 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name); } + buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); + if(pReq->stbCfg.nBSmaCols > 0) { + pReq->stbCfg.pBSmaCols = (col_id_t *)malloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); + for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { + buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); + } + } else { + pReq->stbCfg.pBSmaCols = NULL; + } + if(pReq->rollup) { + pReq->stbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); + SRSmaParam *param = pReq->stbCfg.pRSmaParam; + buf = taosDecodeFixedU32(buf, (uint32_t*)¶m->xFilesFactor); + buf = taosDecodeFixedI8(buf, ¶m->delayUnit); + buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); + if(param->nFuncIds > 0) { + for (int8_t i = 0; i< param->nFuncIds; ++i) { + buf = taosDecodeFixedI32(buf, param->pFuncIds + i); + } + } else { + param->pFuncIds = NULL; + } + buf = taosDecodeFixedI64(buf, ¶m->delay); + } else { + pReq->stbCfg.pRSmaParam = NULL; + } break; default: ASSERT(0); diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index 3eb9a480ac..0a93ea67b3 100644 --- a/source/dnode/vnode/src/meta/metaBDBImpl.c +++ b/source/dnode/vnode/src/meta/metaBDBImpl.c @@ -527,7 +527,7 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) { buf = taosDecodeString(buf, &(pTbCfg->name)); buf = taosDecodeFixedU32(buf, &(pTbCfg->ttl)); buf = taosDecodeFixedU32(buf, &(pTbCfg->keep)); - buf = taosDecodeFixedU8(buf, &(pTbCfg->type)); + buf = taosDecodeFixedU8(buf, &(pTbCfg->info)); if (pTbCfg->type == META_SUPER_TABLE) { SSchemaWrapper sw; diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index b9bf432a72..3c51ad5d71 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -33,6 +33,61 @@ int main(int argc, char **argv) { return RUN_ALL_TESTS(); } +TEST(testCase, unionEncodeDecodeTest) { + typedef struct { + union { + uint8_t info; + struct { + uint8_t rollup : 1; // 1 means rollup sma + uint8_t type : 7; + }; + }; + col_id_t nBSmaCols; + col_id_t* pBSmaCols; + } SUnionTest; + + SUnionTest sut = {0}; + sut.rollup = 1; + sut.type = 1; + + sut.nBSmaCols = 2; + sut.pBSmaCols = (col_id_t*)malloc(sut.nBSmaCols * sizeof(col_id_t)); + for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { + sut.pBSmaCols[i] = i + 100; + } + + void* buf = malloc(1024); + void * pBuf = buf; + int32_t tlen = 0; + tlen += taosEncodeFixedU8(&buf, sut.info); + tlen += taosEncodeFixedI16(&buf, sut.nBSmaCols); + for (col_id_t i = 0; i < sut.nBSmaCols; ++i) { + tlen += taosEncodeFixedI16(&buf, sut.pBSmaCols[i]); + } + + SUnionTest dut = {0}; + pBuf = taosDecodeFixedU8(pBuf, &dut.info); + pBuf = taosDecodeFixedI16(pBuf, &dut.nBSmaCols); + if(dut.nBSmaCols > 0) { + dut.pBSmaCols = (col_id_t*)malloc(dut.nBSmaCols * sizeof(col_id_t)); + for(col_id_t i=0; i < dut.nBSmaCols; ++i) { + pBuf = taosDecodeFixedI16(pBuf, dut.pBSmaCols + i); + } + } else { + dut.pBSmaCols = NULL; + } + + printf("sut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", sut.rollup, sut.type, sut.info); + printf("dut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", dut.rollup, dut.type, dut.info); + + ASSERT_EQ(sut.rollup, dut.rollup); + ASSERT_EQ(sut.type, dut.type); + ASSERT_EQ(sut.nBSmaCols, dut.nBSmaCols); + for (col_id_t i = 0; i< sut.nBSmaCols; ++i) { + ASSERT_EQ(*(col_id_t*)(sut.pBSmaCols + i), sut.pBSmaCols[i]); + ASSERT_EQ(*(col_id_t*)(sut.pBSmaCols + i), dut.pBSmaCols[i]); + } +} #if 1 TEST(testCase, tSma_Meta_Encode_Decode_Test) { // encode From ea034335bba3db3432438ee38336ce9ce82b703b Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 23 Mar 2022 09:36:22 +0800 Subject: [PATCH 30/68] encode info --- source/dnode/vnode/src/meta/metaBDBImpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index 0a93ea67b3..2dd8386d7a 100644 --- a/source/dnode/vnode/src/meta/metaBDBImpl.c +++ b/source/dnode/vnode/src/meta/metaBDBImpl.c @@ -507,7 +507,7 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) { tsize += taosEncodeString(buf, pTbCfg->name); tsize += taosEncodeFixedU32(buf, pTbCfg->ttl); tsize += taosEncodeFixedU32(buf, pTbCfg->keep); - tsize += taosEncodeFixedU8(buf, pTbCfg->type); + tsize += taosEncodeFixedU8(buf, pTbCfg->info); if (pTbCfg->type == META_SUPER_TABLE) { SSchemaWrapper sw = {.nCols = pTbCfg->stbCfg.nTagCols, .pSchema = pTbCfg->stbCfg.pTagSchema}; From b4bd6b6bb89c231fac014eb77a31f5926aba8312 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 23 Mar 2022 10:10:40 +0800 Subject: [PATCH 31/68] [td-13039] fix compiler error. --- tools/shell/src/shellMain.c | 671 ++++++++++++++++++++++++++++++++++++ 1 file changed, 671 insertions(+) create mode 100644 tools/shell/src/shellMain.c diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c new file mode 100644 index 0000000000..78d6f74df1 --- /dev/null +++ b/tools/shell/src/shellMain.c @@ -0,0 +1,671 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define __USE_XOPEN +#include "os.h" +#include "shell.h" +#include "tglobal.h" +#include "shellCommand.h" +#include "tbase64.h" +#include "tlog.h" +#include "version.h" + +#include +#include +#include + +#define OPT_ABORT 1 /* abort */ + + +int indicator = 1; + +void insertChar(Command *cmd, char *c, int size); +const char *argp_program_version = version; +const char *argp_program_bug_address = ""; +static char doc[] = ""; +static char args_doc[] = ""; + +TdThread pid; +static tsem_t cancelSem; + +static struct argp_option options[] = { + {"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."}, + {"password", 'p', 0, 0, "The password to use when connecting to the server."}, + {"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."}, + {"user", 'u', "USER", 0, "The user name to use when connecting to the server."}, + {"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."}, + {"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."}, + {"dump-config", 'C', 0, 0, "Dump configuration."}, + {"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."}, + {"raw-time", 'r', 0, 0, "Output time as uint64_t."}, + {"file", 'f', "FILE", 0, "Script to run without enter the shell."}, + {"directory", 'D', "DIRECTORY", 0, "Use multi-thread to import all SQL files in the directory separately."}, + {"thread", 'T', "THREADNUM", 0, "Number of threads when using multi-thread to import data."}, + {"check", 'k', "CHECK", 0, "Check tables."}, + {"database", 'd', "DATABASE", 0, "Database to use when connecting to the server."}, + {"timezone", 'z', "TIMEZONE", 0, "Time zone of the shell, default is local."}, + {"netrole", 'n', "NETROLE", 0, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync|speen|fqdn."}, + {"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."}, + {"pktnum", 'N', "PKTNUM", 0, "Packet numbers used for net test, default is 100."}, + {"pkttype", 'S', "PKTTYPE", 0, "Packet type used for net test, default is TCP."}, + {0}}; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) { + /* Get the input argument from argp_parse, which we + know is a pointer to our arguments structure. */ + SShellArguments *arguments = state->input; + wordexp_t full_path; + + switch (key) { + case 'h': + arguments->host = arg; + break; + case 'p': + break; + case 'P': + if (arg) { + arguments->port = atoi(arg); + } else { + fprintf(stderr, "Invalid port\n"); + return -1; + } + + break; + case 'z': + arguments->timezone = arg; + break; + case 'u': + arguments->user = arg; + break; + case 'A': + arguments->auth = arg; + break; + case 'c': + if (wordexp(arg, &full_path, 0) != 0) { + fprintf(stderr, "Invalid path %s\n", arg); + return -1; + } + if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) { + fprintf(stderr, "config file path: %s overflow max len %d\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1); + wordfree(&full_path); + return -1; + } + tstrncpy(configDir, full_path.we_wordv[0], TSDB_FILENAME_LEN); + wordfree(&full_path); + break; + case 'C': + arguments->dump_config = true; + break; + case 's': + arguments->commands = arg; + break; + case 'r': + arguments->is_raw_time = true; + break; + case 'f': + if ((0 == strlen(arg)) || (wordexp(arg, &full_path, 0) != 0)) { + fprintf(stderr, "Invalid path %s\n", arg); + return -1; + } + tstrncpy(arguments->file, full_path.we_wordv[0], TSDB_FILENAME_LEN); + wordfree(&full_path); + break; + case 'D': + if (wordexp(arg, &full_path, 0) != 0) { + fprintf(stderr, "Invalid path %s\n", arg); + return -1; + } + tstrncpy(arguments->dir, full_path.we_wordv[0], TSDB_FILENAME_LEN); + wordfree(&full_path); + break; + case 'T': + if (arg) { + arguments->threadNum = atoi(arg); + } else { + fprintf(stderr, "Invalid number of threads\n"); + return -1; + } + break; + case 'k': + arguments->check = atoi(arg); + break; + case 'd': + arguments->database = arg; + break; + case 'n': + arguments->netTestRole = arg; + break; + case 'l': + if (arg) { + arguments->pktLen = atoi(arg); + } else { + fprintf(stderr, "Invalid packet length\n"); + return -1; + } + break; + case 'N': + if (arg) { + arguments->pktNum = atoi(arg); + } else { + fprintf(stderr, "Invalid packet number\n"); + return -1; + } + break; + case 'S': + arguments->pktType = arg; + break; + case OPT_ABORT: + arguments->abort = 1; + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +/* Our argp parser. */ +static struct argp argp = {options, parse_opt, args_doc, doc}; + +char LINUXCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n" + "Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n"; +char g_password[SHELL_MAX_PASSWORD_LEN]; + +static void parse_args( + int argc, char *argv[], SShellArguments *arguments) { + for (int i = 1; i < argc; i++) { + if ((strncmp(argv[i], "-p", 2) == 0) + || (strncmp(argv[i], "--password", 10) == 0)) { + printf(LINUXCLIENT_VERSION, tsOsName, taos_get_client_info()); + if ((strlen(argv[i]) == 2) + || (strncmp(argv[i], "--password", 10) == 0)) { + printf("Enter password: "); + taosSetConsoleEcho(false); + if (scanf("%20s", g_password) > 1) { + fprintf(stderr, "password reading error\n"); + } + taosSetConsoleEcho(true); + if (EOF == getchar()) { + fprintf(stderr, "getchar() return EOF\n"); + } + } else { + tstrncpy(g_password, (char *)(argv[i] + 2), SHELL_MAX_PASSWORD_LEN); + strcpy(argv[i], "-p"); + } + arguments->password = g_password; + arguments->is_use_passwd = true; + } + } +} + +void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { + static char verType[32] = {0}; + sprintf(verType, "version: %s\n", version); + + argp_program_version = verType; + + if (argc > 1) { + parse_args(argc, argv, arguments); + } + + argp_parse(&argp, argc, argv, 0, 0, arguments); + if (arguments->abort) { + #ifndef _ALPINE + #if 0 + error(10, 0, "ABORTED"); + #endif + #else + abort(); + #endif + } +} + +int32_t shellReadCommand(TAOS *con, char *command) { + unsigned hist_counter = history.hend; + char utf8_array[10] = "\0"; + Command cmd; + memset(&cmd, 0, sizeof(cmd)); + cmd.buffer = (char *)calloc(1, MAX_COMMAND_SIZE); + cmd.command = (char *)calloc(1, MAX_COMMAND_SIZE); + showOnScreen(&cmd); + + // Read input. + char c; + while (1) { + c = (char)getchar(); // getchar() return an 'int' value + + if (c == EOF) { + return c; + } + + if (c < 0) { // For UTF-8 + int count = countPrefixOnes(c); + utf8_array[0] = c; + for (int k = 1; k < count; k++) { + c = (char)getchar(); + utf8_array[k] = c; + } + insertChar(&cmd, utf8_array, count); + } else if (c < '\033') { + // Ctrl keys. TODO: Implement ctrl combinations + switch (c) { + case 1: // ctrl A + positionCursorHome(&cmd); + break; + case 3: + printf("\n"); + resetCommand(&cmd, ""); + kill(0, SIGINT); + break; + case 4: // EOF or Ctrl+D + printf("\n"); + taos_close(con); + // write the history + write_history(); + exitShell(); + break; + case 5: // ctrl E + positionCursorEnd(&cmd); + break; + case 8: + backspaceChar(&cmd); + break; + case '\n': + case '\r': + printf("\n"); + if (isReadyGo(&cmd)) { + sprintf(command, "%s%s", cmd.buffer, cmd.command); + tfree(cmd.buffer); + tfree(cmd.command); + return 0; + } else { + updateBuffer(&cmd); + } + break; + case 11: // Ctrl + K; + clearLineAfter(&cmd); + break; + case 12: // Ctrl + L; + system("clear"); + showOnScreen(&cmd); + break; + case 21: // Ctrl + U; + clearLineBefore(&cmd); + break; + } + } else if (c == '\033') { + c = (char)getchar(); + switch (c) { + case '[': + c = (char)getchar(); + switch (c) { + case 'A': // Up arrow + if (hist_counter != history.hstart) { + hist_counter = (hist_counter + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE; + resetCommand(&cmd, (history.hist[hist_counter] == NULL) ? "" : history.hist[hist_counter]); + } + break; + case 'B': // Down arrow + if (hist_counter != history.hend) { + int next_hist = (hist_counter + 1) % MAX_HISTORY_SIZE; + + if (next_hist != history.hend) { + resetCommand(&cmd, (history.hist[next_hist] == NULL) ? "" : history.hist[next_hist]); + } else { + resetCommand(&cmd, ""); + } + hist_counter = next_hist; + } + break; + case 'C': // Right arrow + moveCursorRight(&cmd); + break; + case 'D': // Left arrow + moveCursorLeft(&cmd); + break; + case '1': + if ((c = (char)getchar()) == '~') { + // Home key + positionCursorHome(&cmd); + } + break; + case '2': + if ((c = (char)getchar()) == '~') { + // Insert key + } + break; + case '3': + if ((c = (char)getchar()) == '~') { + // Delete key + deleteChar(&cmd); + } + break; + case '4': + if ((c = (char)getchar()) == '~') { + // End key + positionCursorEnd(&cmd); + } + break; + case '5': + if ((c = (char)getchar()) == '~') { + // Page up key + } + break; + case '6': + if ((c = (char)getchar()) == '~') { + // Page down key + } + break; + case 72: + // Home key + positionCursorHome(&cmd); + break; + case 70: + // End key + positionCursorEnd(&cmd); + break; + } + break; + } + } else if (c == 0x7f) { + // press delete key + backspaceChar(&cmd); + } else { + insertChar(&cmd, &c, 1); + } + } + + return 0; +} + +void *shellLoopQuery(void *arg) { + if (indicator) { + getOldTerminalMode(); + indicator = 0; + } + + TAOS *con = (TAOS *)arg; + + setThreadName("shellLoopQuery"); + + taosThreadCleanupPush(cleanup_handler, NULL); + + char *command = malloc(MAX_COMMAND_SIZE); + if (command == NULL){ + uError("failed to malloc command"); + return NULL; + } + + int32_t err = 0; + + do { + // Read command from shell. + memset(command, 0, MAX_COMMAND_SIZE); + setTerminalMode(); + err = shellReadCommand(con, command); + if (err) { + break; + } + resetTerminalMode(); + } while (shellRunCommand(con, command) == 0); + + tfree(command); + exitShell(); + + taosThreadCleanupPop(1); + + return NULL; +} + +void get_history_path(char *_history) { snprintf(_history, TSDB_FILENAME_LEN, "%s/%s", getenv("HOME"), HISTORY_FILE); } + +void clearScreen(int ecmd_pos, int cursor_pos) { + struct winsize w; + if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) { + //fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n"); + w.ws_col = 120; + w.ws_row = 30; + } + + int cursor_x = cursor_pos / w.ws_col; + int cursor_y = cursor_pos % w.ws_col; + int command_x = ecmd_pos / w.ws_col; + positionCursor(cursor_y, LEFT); + positionCursor(command_x - cursor_x, DOWN); + fprintf(stdout, "\033[2K"); + for (int i = 0; i < command_x; i++) { + positionCursor(1, UP); + fprintf(stdout, "\033[2K"); + } + fflush(stdout); +} + +void showOnScreen(Command *cmd) { + struct winsize w; + if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) { + //fprintf(stderr, "No stream device\n"); + w.ws_col = 120; + w.ws_row = 30; + } + + TdWchar wc; + int size = 0; + + // Print out the command. + char *total_string = malloc(MAX_COMMAND_SIZE); + memset(total_string, '\0', MAX_COMMAND_SIZE); + if (strcmp(cmd->buffer, "") == 0) { + sprintf(total_string, "%s%s", PROMPT_HEADER, cmd->command); + } else { + sprintf(total_string, "%s%s", CONTINUE_PROMPT, cmd->command); + } + + int remain_column = w.ws_col; + /* size = cmd->commandSize + prompt_size; */ + for (char *str = total_string; size < cmd->commandSize + prompt_size;) { + int ret = taosMbToWchar(&wc, str, MB_CUR_MAX); + if (ret < 0) break; + size += ret; + /* assert(size >= 0); */ + int width = taosWcharWidth(wc); + if (remain_column > width) { + printf("%lc", wc); + remain_column -= width; + } else { + if (remain_column == width) { + printf("%lc\n\r", wc); + remain_column = w.ws_col; + } else { + printf("\n\r%lc", wc); + remain_column = w.ws_col - width; + } + } + + str = total_string + size; + } + + free(total_string); + /* for (int i = 0; i < size; i++){ */ + /* char c = total_string[i]; */ + /* if (k % w.ws_col == 0) { */ + /* printf("%c\n\r", c); */ + /* } */ + /* else { */ + /* printf("%c", c); */ + /* } */ + /* k += 1; */ + /* } */ + + // Position the cursor + int cursor_pos = cmd->screenOffset + prompt_size; + int ecmd_pos = cmd->endOffset + prompt_size; + + int cursor_x = cursor_pos / w.ws_col; + int cursor_y = cursor_pos % w.ws_col; + // int cursor_y = cursor % w.ws_col; + int command_x = ecmd_pos / w.ws_col; + int command_y = ecmd_pos % w.ws_col; + // int command_y = (command.size() + prompt_size) % w.ws_col; + positionCursor(command_y, LEFT); + positionCursor(command_x, UP); + positionCursor(cursor_x, DOWN); + positionCursor(cursor_y, RIGHT); + fflush(stdout); +} + +void cleanup_handler(void *arg) { resetTerminalMode(); } + +void exitShell() { + /*int32_t ret =*/ resetTerminalMode(); + taos_cleanup(); + exit(EXIT_SUCCESS); +} +void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { + tsem_post(&cancelSem); +} + +void *cancelHandler(void *arg) { + setThreadName("cancelHandler"); + + while (1) { + if (tsem_wait(&cancelSem) != 0) { + taosMsleep(10); + continue; + } + +#ifdef LINUX +#if 0 + int64_t rid = atomic_val_compare_exchange_64(&result, result, 0); + SSqlObj* pSql = taosAcquireRef(tscObjRef, rid); + taos_stop_query(pSql); + taosReleaseRef(tscObjRef, rid); +#endif +#else + resetTerminalMode(); + printf("\nReceive ctrl+c or other signal, quit shell.\n"); + exit(0); +#endif + resetTerminalMode(); + printf("\nReceive ctrl+c or other signal, quit shell.\n"); + exit(0); + } + + return NULL; +} + +int checkVersion() { + if (sizeof(int8_t) != 1) { + printf("taos int8 size is %d(!= 1)", (int)sizeof(int8_t)); + return 0; + } + if (sizeof(int16_t) != 2) { + printf("taos int16 size is %d(!= 2)", (int)sizeof(int16_t)); + return 0; + } + if (sizeof(int32_t) != 4) { + printf("taos int32 size is %d(!= 4)", (int)sizeof(int32_t)); + return 0; + } + if (sizeof(int64_t) != 8) { + printf("taos int64 size is %d(!= 8)", (int)sizeof(int64_t)); + return 0; + } + return 1; +} + +// Global configurations +SShellArguments args = {.host = NULL, +#ifndef TD_WINDOWS + .password = NULL, +#endif + .user = NULL, + .database = NULL, + .timezone = NULL, + .is_raw_time = false, + .is_use_passwd = false, + .dump_config = false, + .file = "\0", + .dir = "\0", + .threadNum = 5, + .commands = NULL, + .pktLen = 1000, + .pktNum = 100, + .pktType = "TCP", + .netTestRole = NULL}; + +/* + * Main function. + */ +int main(int argc, char *argv[]) { + /*setlocale(LC_ALL, "en_US.UTF-8"); */ + + if (!checkVersion()) { + exit(EXIT_FAILURE); + } + + shellParseArgument(argc, argv, &args); + +#if 0 + if (args.dump_config) { + taosInitGlobalCfg(); + taosReadGlobalLogCfg(); + + if (taosReadGlobalCfg() ! =0) { + printf("TDengine read global config failed"); + exit(EXIT_FAILURE); + } + + taosDumpGlobalCfg(); + exit(0); + } + + if (args.netTestRole && args.netTestRole[0] != 0) { + if (taos_init()) { + printf("Failed to init taos"); + exit(EXIT_FAILURE); + } + taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType); + exit(0); + } +#endif + + /* Initialize the shell */ + TAOS *con = shellInit(&args); + if (con == NULL) { + exit(EXIT_FAILURE); + } + + if (tsem_init(&cancelSem, 0, 0) != 0) { + printf("failed to create cancel semphore\n"); + exit(EXIT_FAILURE); + } + + TdThread spid; + taosThreadCreate(&spid, NULL, cancelHandler, NULL); + + /* Interrupt handler. */ + taosSetSignal(SIGTERM, shellQueryInterruptHandler); + taosSetSignal(SIGINT, shellQueryInterruptHandler); + taosSetSignal(SIGHUP, shellQueryInterruptHandler); + taosSetSignal(SIGABRT, shellQueryInterruptHandler); + + /* Get grant information */ + shellGetGrantInfo(con); + + /* Loop to query the input. */ + while (1) { + taosThreadCreate(&pid, NULL, shellLoopQuery, con); + taosThreadJoin(pid, NULL); + } +} From 3d4b60312be38ecd57990422fc688bc7a343fe41 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 23 Mar 2022 10:35:14 +0800 Subject: [PATCH 32/68] copy bitmap --- source/common/src/tdataformat.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index f39b20b934..87e3cf0c24 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -431,6 +431,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) { for (int i = 0; i < pDataCols->numOfCols; i++) { pRet->cols[i].type = pDataCols->cols[i].type; + pRet->cols[i].bitmap = pDataCols->cols[i].bitmap; pRet->cols[i].colId = pDataCols->cols[i].colId; pRet->cols[i].bytes = pDataCols->cols[i].bytes; pRet->cols[i].offset = pDataCols->cols[i].offset; From 93347bec42e7a0525747658133cf129ff5fc0921 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 23 Mar 2022 10:44:32 +0800 Subject: [PATCH 33/68] put next level info into task --- example/src/tstream.c | 4 +-- include/common/tmsg.h | 36 ++++++++++++---------- source/common/src/tglobal.c | 5 ++- source/common/src/tmsg.c | 17 ++++++---- source/dnode/mnode/impl/src/mndScheduler.c | 36 +++++++++++++++++----- source/dnode/vnode/src/inc/tqInt.h | 1 + source/dnode/vnode/src/inc/vnd.h | 4 +-- source/dnode/vnode/src/tq/tq.c | 21 +++++++++++-- source/dnode/vnode/src/vnd/vnodeMain.c | 5 +-- 9 files changed, 90 insertions(+), 39 deletions(-) diff --git a/example/src/tstream.c b/example/src/tstream.c index 62d94b041d..56650634c5 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -63,7 +63,7 @@ int32_t init_env() { } int32_t create_stream() { - printf("create topic\n"); + printf("create stream\n"); TAOS_RES* pRes; TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); if (pConn == NULL) { @@ -77,7 +77,7 @@ int32_t create_stream() { } taos_free_result(pRes); - const char* sql = "select ts,k from tu1"; + const char* sql = "select ts,sum(k) from tu1"; pRes = tmq_create_stream(pConn, "stream1", "out1", sql); if (taos_errno(pRes) != 0) { printf("failed to create stream out1, reason:%s\n", taos_errstr(pRes)); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 560490569a..5d01f1cfe7 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -23,8 +23,8 @@ #include "tencode.h" #include "thash.h" #include "tlist.h" -#include "trow.h" #include "tname.h" +#include "trow.h" #include "tuuid.h" #ifdef __cplusplus @@ -472,10 +472,9 @@ typedef struct { int32_t code; } SQueryTableRsp; -int32_t tSerializeSQueryTableRsp(void *buf, int32_t bufLen, SQueryTableRsp *pRsp); - -int32_t tDeserializeSQueryTableRsp(void *buf, int32_t bufLen, SQueryTableRsp *pRsp); +int32_t tSerializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp); +int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pRsp); typedef struct { char db[TSDB_DB_FNAME_LEN]; @@ -888,14 +887,14 @@ typedef struct { } SRetrieveTableRsp; typedef struct { - int64_t handle; - int64_t useconds; - int8_t completed; // all results are returned to client - int8_t precision; - int8_t compressed; - int32_t compLen; - int32_t numOfRows; - char data[]; + int64_t handle; + int64_t useconds; + int8_t completed; // all results are returned to client + int8_t precision; + int8_t compressed; + int32_t compLen; + int32_t numOfRows; + char data[]; } SRetrieveMetaTableRsp; typedef struct { @@ -1405,12 +1404,11 @@ int32_t tSerializeSVCreateTbBatchReq(void** buf, SVCreateTbBatchReq* pReq); void* tDeserializeSVCreateTbBatchReq(void* buf, SVCreateTbBatchReq* pReq); typedef struct { - SArray* rspList; // SArray + SArray* rspList; // SArray } SVCreateTbBatchRsp; -int32_t tSerializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchRsp *pRsp); -int32_t tDeserializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchRsp *pRsp); - +int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp); +int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp); typedef struct { int64_t ver; @@ -2292,6 +2290,11 @@ enum { STREAM_TASK_STATUS__STOP, }; +enum { + STREAM_NEXT_OP_DST__VND = 1, + STREAM_NEXT_OP_DST__SND, +}; + typedef struct { void* inputHandle; void* executor; @@ -2306,6 +2309,7 @@ typedef struct { int8_t pipeSink; int8_t numOfRunners; int8_t parallelizable; + int8_t nextOpDst; // vnode or snode SEpSet NextOpEp; char* qmsg; // not applied to encoder and decoder diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 841824a7c7..506e017deb 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -132,6 +132,9 @@ bool tsdbForceKeepFile = false; int32_t tsDiskCfgNum = 0; SDiskCfg tsDiskCfg[TFS_MAX_DISKS] = {0}; +// stream scheduler +bool tsStreamSchedV = true; + /* * minimum scale for whole system, millisecond by default * for TSDB_TIME_PRECISION_MILLI: 86400000L @@ -585,4 +588,4 @@ void taosCfgDynamicOptions(const char *option, const char *value) { taosResetLog(); cfgDumpCfg(tsCfg, 1, false); } -} \ No newline at end of file +} diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 47872b89d5..e493c651fa 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2629,7 +2629,7 @@ int32_t tSerializeSQueryTableRsp(void *buf, int32_t bufLen, SQueryTableRsp *pRsp tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI32(&encoder, pRsp->code) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->code) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -2656,13 +2656,13 @@ int32_t tSerializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchR if (tStartEncode(&encoder) < 0) return -1; if (pRsp->rspList) { int32_t num = taosArrayGetSize(pRsp->rspList); - if (tEncodeI32(&encoder, num) < 0) return -1; + if (tEncodeI32(&encoder, num) < 0) return -1; for (int32_t i = 0; i < num; ++i) { SVCreateTbRsp *rsp = taosArrayGet(pRsp->rspList, i); - if (tEncodeI32(&encoder, rsp->code) < 0) return -1; + if (tEncodeI32(&encoder, rsp->code) < 0) return -1; } } else { - if (tEncodeI32(&encoder, 0) < 0) return -1; + if (tEncodeI32(&encoder, 0) < 0) return -1; } tEndEncode(&encoder); @@ -2672,7 +2672,7 @@ int32_t tSerializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchR } int32_t tDeserializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchRsp *pRsp) { - SCoder decoder = {0}; + SCoder decoder = {0}; int32_t num = 0; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2695,7 +2695,6 @@ int32_t tDeserializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatc return 0; } - int32_t tSerializeSVCreateTSmaReq(void **buf, SVCreateTSmaReq *pReq) { int32_t tlen = 0; @@ -2797,7 +2796,10 @@ int32_t tEncodeSStreamTask(SCoder *pEncoder, const SStreamTask *pTask) { if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->level) < 0) return -1; if (tEncodeI8(pEncoder, pTask->status) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->pipeSource) < 0) return -1; if (tEncodeI8(pEncoder, pTask->pipeSink) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->parallelizable) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->nextOpDst) < 0) return -1; // if (tEncodeI8(pEncoder, pTask->numOfRunners) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->NextOpEp) < 0) return -1; if (tEncodeCStr(pEncoder, pTask->qmsg) < 0) return -1; @@ -2811,7 +2813,10 @@ int32_t tDecodeSStreamTask(SCoder *pDecoder, SStreamTask *pTask) { if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->level) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->pipeSource) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->pipeSink) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->parallelizable) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->nextOpDst) < 0) return -1; // if (tDecodeI8(pDecoder, &pTask->numOfRunners) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->NextOpEp) < 0) return -1; if (tDecodeCStrAlloc(pDecoder, &pTask->qmsg) < 0) return -1; diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index b95574ea41..a6d27ffa44 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -32,6 +32,8 @@ #include "tname.h" #include "tuuid.h" +extern bool tsStreamSchedV; + int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet* pEpSet, tmsg_t type) { SCoder encoder; tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); @@ -106,6 +108,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { int32_t totLevel = LIST_LENGTH(pPlan->pSubplans); pStream->tasks = taosArrayInit(totLevel, sizeof(SArray)); + int32_t lastUsedVgId = 0; for (int32_t level = 0; level < totLevel; level++) { SArray* taskOneLevel = taosArrayInit(0, sizeof(SStreamTask)); @@ -125,11 +128,14 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { continue; } + lastUsedVgId = pVgroup->vgId; pStream->vgNum++; // send to vnode SStreamTask* pTask = streamTaskNew(pStream->uid, level); + pTask->pipeSource = 1; pTask->pipeSink = level == totLevel - 1 ? 1 : 0; + pTask->parallelizable = 1; // TODO: set to if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) { sdbRelease(pSdb, pVgroup); @@ -140,19 +146,35 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { } } else { SStreamTask* pTask = streamTaskNew(pStream->uid, level); + pTask->pipeSource = 0; pTask->pipeSink = level == totLevel - 1 ? 1 : 0; - SSnodeObj* pSnode = mndSchedFetchSnode(pMnode); - if (pSnode != NULL) { - if (mndAssignTaskToSnode(pMnode, pTrans, pTask, plan, pSnode) < 0) { - sdbRelease(pSdb, pSnode); + pTask->parallelizable = plan->type == SUBPLAN_TYPE_SCAN; + pTask->nextOpDst = STREAM_NEXT_OP_DST__VND; + + if (tsStreamSchedV) { + ASSERT(lastUsedVgId != 0); + SVgObj* pVg = mndAcquireVgroup(pMnode, lastUsedVgId); + if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVg) < 0) { + sdbRelease(pSdb, pVg); qDestroyQueryPlan(pPlan); return -1; } - sdbRelease(pMnode->pSdb, pSnode); + sdbRelease(pSdb, pVg); } else { - // TODO: assign to one vg - ASSERT(0); + SSnodeObj* pSnode = mndSchedFetchSnode(pMnode); + if (pSnode != NULL) { + if (mndAssignTaskToSnode(pMnode, pTrans, pTask, plan, pSnode) < 0) { + sdbRelease(pSdb, pSnode); + qDestroyQueryPlan(pPlan); + return -1; + } + sdbRelease(pMnode->pSdb, pSnode); + } else { + // TODO: assign to one vg + ASSERT(0); + } } + taosArrayPush(taskOneLevel, pTask); } taosArrayPush(pStream->tasks, taskOneLevel); diff --git a/source/dnode/vnode/src/inc/tqInt.h b/source/dnode/vnode/src/inc/tqInt.h index 4d4bb12a21..deb3cae617 100644 --- a/source/dnode/vnode/src/inc/tqInt.h +++ b/source/dnode/vnode/src/inc/tqInt.h @@ -167,6 +167,7 @@ struct STQ { STqMetaStore* tqMeta; STqPushMgr* tqPushMgr; SHashObj* pStreamTasks; + SVnode* pVnode; SWal* pWal; SMeta* pVnodeMeta; }; diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index ed9aad9277..bad5b7c6a2 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -177,7 +177,8 @@ int tqInit(); void tqCleanUp(); // open in each vnode -STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAllocatorFactory* allocFac); +STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, + SMemAllocatorFactory* allocFac); void tqClose(STQ*); // required by vnode @@ -188,7 +189,6 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessSetConnReq(STQ* pTq, char* msg); int32_t tqProcessRebReq(STQ* pTq, char* msg); int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg); - int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); #ifdef __cplusplus diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 3af79ca461..0615ea31d4 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -21,7 +21,8 @@ int32_t tqInit() { return tqPushMgrInit(); } void tqCleanUp() { tqPushMgrCleanUp(); } -STQ* tqOpen(const char* path, SWal* pWal, SMeta* pVnodeMeta, STqCfg* tqConfig, SMemAllocatorFactory* allocFac) { +STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STqCfg* tqConfig, + SMemAllocatorFactory* allocFac) { STQ* pTq = malloc(sizeof(STQ)); if (pTq == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; @@ -29,6 +30,7 @@ STQ* tqOpen(const char* path, SWal* pWal, SMeta* pVnodeMeta, STqCfg* tqConfig, S } pTq->path = strdup(path); pTq->tqConfig = tqConfig; + pTq->pVnode = pVnode; pTq->pWal = pWal; pTq->pVnodeMeta = pVnodeMeta; #if 0 @@ -104,8 +106,21 @@ int tqPushMsg(STQ* pTq, void* msg, tmsg_t msgType, int64_t version) { } void* abuf = POINTER_SHIFT(buf, sizeof(SStreamExecMsgHead)); tEncodeDataBlocks(abuf, pRes); - // serialize - // to next level + tmsg_t type; + + if (pTask->nextOpDst == STREAM_NEXT_OP_DST__VND) { + type = TDMT_VND_TASK_EXEC; + } else { + type = TDMT_SND_TASK_EXEC; + } + + SRpcMsg msg = { + .pCont = buf, + .contLen = tlen, + .code = 0, + .msgType = type, + }; + /*vnodeSendReq(pTq->pVnode, &pTask->NextOpEp, &msg);*/ } } diff --git a/source/dnode/vnode/src/vnd/vnodeMain.c b/source/dnode/vnode/src/vnd/vnodeMain.c index 86e670d533..70f4117976 100644 --- a/source/dnode/vnode/src/vnd/vnodeMain.c +++ b/source/dnode/vnode/src/vnd/vnodeMain.c @@ -115,7 +115,8 @@ static int vnodeOpenImpl(SVnode *pVnode) { // Open tsdb sprintf(dir, "%s/tsdb", pVnode->path); - pVnode->pTsdb = tsdbOpen(dir, pVnode->vgId, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode), pVnode->pMeta, pVnode->pTfs); + pVnode->pTsdb = + tsdbOpen(dir, pVnode->vgId, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode), pVnode->pMeta, pVnode->pTfs); if (pVnode->pTsdb == NULL) { // TODO: handle error return -1; @@ -131,7 +132,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { // Open TQ sprintf(dir, "%s/tq", pVnode->path); - pVnode->pTq = tqOpen(dir, pVnode->pWal, pVnode->pMeta, &(pVnode->config.tqCfg), vBufPoolGetMAF(pVnode)); + pVnode->pTq = tqOpen(dir, pVnode, pVnode->pWal, pVnode->pMeta, &(pVnode->config.tqCfg), vBufPoolGetMAF(pVnode)); if (pVnode->pTq == NULL) { // TODO: handle error return -1; From 3442e20916854a6504fe5607486d26f73ecd7f44 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 22 Mar 2022 22:45:57 -0400 Subject: [PATCH 34/68] TD-13077 identifier implement --- source/libs/parser/inc/parAst.h | 20 +++++----- source/libs/parser/src/parAstCreater.c | 53 +++++++++++++++++--------- source/util/src/tutil.c | 2 +- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 45216be6ef..2dd0b531a2 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -84,7 +84,7 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode); SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode); SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode); -SNode* createColumnNode(SAstCreateContext* pCxt, const SToken* pTableAlias, const SToken* pColumnName); +SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName); SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral); SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral); SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt); @@ -95,7 +95,7 @@ SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNo SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList); SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList); -SNode* createRealTableNode(SAstCreateContext* pCxt, const SToken* pDbName, const SToken* pTableName, const SToken* pTableAlias); +SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias); SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const SToken* pTableAlias); SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft, SNode* pRight, SNode* pJoinCond); SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset); @@ -120,9 +120,9 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt); SNode* createDefaultAlterDatabaseOptions(SAstCreateContext* pCxt); SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, const SToken* pVal); -SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SNode* pOptions); -SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName); -SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName, SNode* pOptions); +SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions); +SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); +SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); SNode* createDefaultTableOptions(SAstCreateContext* pCxt); SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt); SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, const SToken* pVal); @@ -144,15 +144,15 @@ SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal); SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern); -SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword); -SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int8_t alterType, const SToken* pVal); -SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName); +SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword); +SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal); +SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName); SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort); SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode); SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue); -SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, const SToken* pIndexName, const SToken* pTableName, SNodeList* pCols, SNode* pOptions); +SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions); SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding); -SNode* createDropIndexStmt(SAstCreateContext* pCxt, const SToken* pIndexName, const SToken* pTableName); +SNode* createDropIndexStmt(SAstCreateContext* pCxt, SToken* pIndexName, SToken* pTableName); SNode* createCreateQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId); SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId); SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName); diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index c4839f0004..020296e9b6 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -331,7 +331,14 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) { initSetTableOptionFp(); } -static bool checkUserName(SAstCreateContext* pCxt, const SToken* pUserName) { +static void trimEscape(SToken* pName) { + if (NULL != pName && pName->n > 1 && '`' == pName->z[0]) { + pName->z += 1; + pName->n -= 2; + } +} + +static bool checkUserName(SAstCreateContext* pCxt, SToken* pUserName) { if (NULL == pUserName) { pCxt->valid = false; } else { @@ -340,6 +347,7 @@ static bool checkUserName(SAstCreateContext* pCxt, const SToken* pUserName) { pCxt->valid = false; } } + trimEscape(pUserName); return pCxt->valid; } @@ -412,38 +420,43 @@ static bool checkPort(SAstCreateContext* pCxt, const SToken* pPortToken, int32_t return pCxt->valid; } -static bool checkDbName(SAstCreateContext* pCxt, const SToken* pDbName, bool query) { +static bool checkDbName(SAstCreateContext* pCxt, SToken* pDbName, bool query) { if (NULL == pDbName) { pCxt->valid = (query ? NULL != pCxt->pQueryCxt->db : true); } else { pCxt->valid = pDbName->n < TSDB_DB_NAME_LEN ? true : false; } + trimEscape(pDbName); return pCxt->valid; } -static bool checkTableName(SAstCreateContext* pCxt, const SToken* pTableName) { +static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) { if (NULL == pTableName) { pCxt->valid = true; } else { pCxt->valid = pTableName->n < TSDB_TABLE_NAME_LEN ? true : false; } + trimEscape(pTableName); return pCxt->valid; } -static bool checkColumnName(SAstCreateContext* pCxt, const SToken* pColumnName) { +static bool checkColumnName(SAstCreateContext* pCxt, SToken* pColumnName) { if (NULL == pColumnName) { pCxt->valid = true; } else { pCxt->valid = pColumnName->n < TSDB_COL_NAME_LEN ? true : false; } + trimEscape(pColumnName); return pCxt->valid; } -static bool checkIndexName(SAstCreateContext* pCxt, const SToken* pIndexName) { +static bool checkIndexName(SAstCreateContext* pCxt, SToken* pIndexName) { if (NULL == pIndexName) { - return false; + pCxt->valid = false; + } else { + pCxt->valid = pIndexName->n < TSDB_INDEX_NAME_LEN ? true : false; } - pCxt->valid = pIndexName->n < TSDB_INDEX_NAME_LEN ? true : false; + trimEscape(pIndexName); return pCxt->valid; } @@ -498,7 +511,7 @@ SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode return pList; } -SNode* createColumnNode(SAstCreateContext* pCxt, const SToken* pTableAlias, const SToken* pColumnName) { +SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName) { if (!checkTableName(pCxt, pTableAlias) || !checkColumnName(pCxt, pColumnName)) { return NULL; } @@ -603,8 +616,8 @@ SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList) { return (SNode*)list; } -SNode* createRealTableNode(SAstCreateContext* pCxt, const SToken* pDbName, const SToken* pTableName, const SToken* pTableAlias) { - if (!checkDbName(pCxt, pDbName, true) || !checkTableName(pCxt, pTableName)) { +SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias) { + if (!checkDbName(pCxt, pDbName, true) || !checkTableName(pCxt, pTableName) || !checkTableName(pCxt, pTableAlias)) { return NULL; } SRealTableNode* realTable = (SRealTableNode*)nodesMakeNode(QUERY_NODE_REAL_TABLE); @@ -620,7 +633,9 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, const SToken* pDbName, const strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n); } strncpy(realTable->table.tableName, pTableName->z, pTableName->n); - strcpy(realTable->useDbName, pCxt->pQueryCxt->db); + if (NULL != pCxt->pQueryCxt->db) { + strcpy(realTable->useDbName, pCxt->pQueryCxt->db); + } return (SNode*)realTable; } @@ -839,7 +854,7 @@ SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOpti return (SNode*)setDbOptionFuncs[type](pCxt, (SDatabaseOptions*)pOptions, pVal); } -SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SNode* pOptions) { +SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions) { if (!checkDbName(pCxt, pDbName, false)) { return NULL; } @@ -851,7 +866,7 @@ SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, cons return (SNode*)pStmt; } -SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName) { +SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName) { if (!checkDbName(pCxt, pDbName, false)) { return NULL; } @@ -862,7 +877,7 @@ SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, con return (SNode*)pStmt; } -SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName, SNode* pOptions) { +SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions) { if (!checkDbName(pCxt, pDbName, false)) { return NULL; } @@ -1055,7 +1070,7 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S return (SNode*)pStmt; } -SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword) { +SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword) { char password[TSDB_USET_PASSWORD_LEN] = {0}; if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) { return NULL; @@ -1067,7 +1082,7 @@ SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, co return (SNode*)pStmt; } -SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int8_t alterType, const SToken* pVal) { +SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal) { if (!checkUserName(pCxt, pUserName)) { return NULL; } @@ -1086,7 +1101,7 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int return (SNode*)pStmt; } -SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName) { +SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) { if (!checkUserName(pCxt, pUserName)) { return NULL; } @@ -1142,7 +1157,7 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const return (SNode*)pStmt; } -SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, const SToken* pIndexName, const SToken* pTableName, SNodeList* pCols, SNode* pOptions) { +SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions) { if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) { return NULL; } @@ -1166,7 +1181,7 @@ SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInt return (SNode*)pOptions; } -SNode* createDropIndexStmt(SAstCreateContext* pCxt, const SToken* pIndexName, const SToken* pTableName) { +SNode* createDropIndexStmt(SAstCreateContext* pCxt, SToken* pIndexName, SToken* pTableName) { if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) { return NULL; } diff --git a/source/util/src/tutil.c b/source/util/src/tutil.c index 7bd671a56c..dc982596ad 100644 --- a/source/util/src/tutil.c +++ b/source/util/src/tutil.c @@ -233,7 +233,7 @@ char *strntolower(char *dst, const char *src, int32_t n) { } } else if (c >= 'A' && c <= 'Z') { c -= 'A' - 'a'; - } else if (c == '\'' || c == '"') { + } else if (c == '\'' || c == '"' || c == '`') { quote = c; } *p++ = c; From 255777ec099a6b751e09de3346f52679ccf8c026 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 22 Mar 2022 22:59:20 -0400 Subject: [PATCH 35/68] TD-13077 `string` identifier implement --- source/libs/parser/inc/parAst.h | 2 +- source/libs/parser/src/parAstCreater.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 2dd0b531a2..eb33dec721 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -142,7 +142,7 @@ SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName); SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName); SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal); -SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName); +SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern); SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword); SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal); diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 020296e9b6..fbf74b96a3 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1046,7 +1046,10 @@ SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const return (SNode*)pStmt; } -SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) { +SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) { + if (!checkDbName(pCxt, pDbName, false)) { + return NULL; + } SUseDatabaseStmt* pStmt = (SUseDatabaseStmt*)nodesMakeNode(QUERY_NODE_USE_DATABASE_STMT); CHECK_OUT_OF_MEM(pStmt); strncpy(pStmt->dbName, pDbName->z, pDbName->n); From a4bb0e660d2fe7551bc002a098e772320a1101b2 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 23 Mar 2022 13:04:59 +0800 Subject: [PATCH 36/68] [modify] --- tests/script/tsim/insert/basic0.sim | 9 +++++- tests/script/tsim/insert/basic1.sim | 46 ++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/tests/script/tsim/insert/basic0.sim b/tests/script/tsim/insert/basic0.sim index 50c64a660d..8592624cf3 100644 --- a/tests/script/tsim/insert/basic0.sim +++ b/tests/script/tsim/insert/basic0.sim @@ -51,7 +51,14 @@ sql insert into ct3 values('2021-01-01 00:00:00.000', 10, 2.0, 3.0) #=================================================================== print =============== query data from child table sql select * from ct1 - +print rows: $rows +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +print $data30 $data31 +print $data40 $data41 +print $data50 $data51 +print $data60 $data61 if $rows != 7 then return -1 endi diff --git a/tests/script/tsim/insert/basic1.sim b/tests/script/tsim/insert/basic1.sim index 3fc635532a..131044ac68 100644 --- a/tests/script/tsim/insert/basic1.sim +++ b/tests/script/tsim/insert/basic1.sim @@ -7,7 +7,7 @@ sql connect print =============== create database sql create database d1 sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -46,6 +46,11 @@ sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1 print =============== query data sql select * from c1 +print rows: $rows +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +print $data30 $data31 if $rows != 4 then return -1 endi @@ -62,19 +67,40 @@ if $data03 != -2 then return -1 endi -print =============== query data from st -sql select * from st -if $rows != 4 then - return -1 -endi +print =============== query data from st, but not support select * from super table, waiting fix +#sql select * from st +#if $rows != 4 then +# return -1 +#endi print =============== stop and restart taosd system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start -sleep 2000 +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 100 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + print =============== query data sql select * from c1 +print rows: $rows +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +print $data30 $data31 if $rows != 4 then return -1 endi @@ -91,4 +117,10 @@ if $data03 != -2 then return -1 endi +print =============== query data from st, but not support select * from super table, waiting fix +#sql select * from st +#if $rows != 4 then +# return -1 +#endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT From 411b9a2d33b9d27d2a6da3d9573a1c77fbdd0099 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Mar 2022 13:50:53 +0800 Subject: [PATCH 37/68] add tsma --- include/common/tmsg.h | 29 +++++++++ include/common/tmsgdef.h | 2 + source/common/src/tmsg.c | 93 ++++++++++++++++++++++++++++ source/dnode/mnode/impl/inc/mndDef.h | 46 +++++++++----- source/dnode/mnode/impl/src/mndStb.c | 42 ++++++++++++- 5 files changed, 195 insertions(+), 17 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ca4e6b97a4..33e5431333 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1897,6 +1897,35 @@ static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) } return buf; } + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + char stb[TSDB_TABLE_FNAME_LEN]; + int8_t igExists; + int8_t intervalUnit; + int8_t slidingUnit; + int8_t timezone; + int64_t interval; + int64_t offset; + int64_t sliding; + int32_t exprLen; + int32_t tagsFilterLen; + char* expr; + char* tagsFilter; +} SMCreateTSmaReq; + +int32_t tSerializeSMCreateTSmaReq(void* buf, int32_t bufLen, SMCreateTSmaReq* pReq); +int32_t tDeserializeSMCreateTSmaReq(void* buf, int32_t bufLen, SMCreateTSmaReq* pReq); +void tFreeSMCreateTSmaReq(SMCreateTSmaReq* pReq); + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + int8_t igNotExists; +} SMDropTSmaReq; + +int32_t tSerializeSMDropTSmaReq(void* buf, int32_t bufLen, SMDropTSmaReq* pReq); +int32_t tDeserializeSMDropTSmaReq(void* buf, int32_t bufLen, SMDropTSmaReq* pReq); + typedef struct { int8_t version; // for compatibility(default 0) int8_t intervalUnit; // MACRO: TIME_UNIT_XXX diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 73a78131dc..c707ec847f 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -127,6 +127,8 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "mnode-create-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "mnode-alter-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SMA, "mnode-create-tsma", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_SMA, "mnode-drop-tsma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TABLE_META, "mnode-table-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "mnode-vgroup-list", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_QNODE_LIST, "mnode-qnode-list", NULL, NULL) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b4caf5ba97..ece2332b64 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -589,6 +589,99 @@ void tFreeSMAltertbReq(SMAltertbReq *pReq) { pReq->pFields = NULL; } +int32_t tSerializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateTSmaReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->stb) < 0) return -1; + if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; + if (tEncodeI8(&encoder, pReq->intervalUnit) < 0) return -1; + if (tEncodeI8(&encoder, pReq->slidingUnit) < 0) return -1; + if (tEncodeI8(&encoder, pReq->timezone) < 0) return -1; + if (tEncodeI64(&encoder, pReq->interval) < 0) return -1; + if (tEncodeI64(&encoder, pReq->offset) < 0) return -1; + if (tEncodeI64(&encoder, pReq->sliding) < 0) return -1; + if (tEncodeI32(&encoder, pReq->exprLen) < 0) return -1; + if (pReq->exprLen > 0) { + if (tEncodeBinary(&encoder, pReq->expr, pReq->exprLen) < 0) return -1; + } + if (tEncodeI32(&encoder, pReq->tagsFilterLen) < 0) return -1; + if (pReq->tagsFilterLen > 0) { + if (tEncodeBinary(&encoder, pReq->tagsFilter, pReq->tagsFilterLen) < 0) return -1; + } + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateTSmaReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->stb) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->intervalUnit) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->slidingUnit) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->timezone) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->interval) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->offset) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->sliding) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->exprLen) < 0) return -1; + if (pReq->exprLen > 0) { + pReq->expr = malloc(pReq->exprLen); + if (pReq->expr == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->expr) < 0) return -1; + } + if (tDecodeI32(&decoder, &pReq->tagsFilterLen) < 0) return -1; + if (pReq->tagsFilterLen > 0) { + pReq->tagsFilter = malloc(pReq->tagsFilterLen); + if (pReq->tagsFilter == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->tagsFilter) < 0) return -1; + } + + tEndDecode(&decoder); + tCoderClear(&decoder); + return 0; +} + +void tFreeSMCreateSmaReq(SMCreateTSmaReq *pReq) { + tfree(pReq->expr); + tfree(pReq->tagsFilter); +} + +int32_t tSerializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropTSmaReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; + if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropTSmaReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 909486aaac..79c110af94 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -306,20 +306,38 @@ typedef struct { } SVgObj; typedef struct { - char name[TSDB_TABLE_FNAME_LEN]; - char db[TSDB_DB_FNAME_LEN]; - int64_t createdTime; - int64_t updateTime; - int64_t uid; - int64_t dbUid; - int32_t version; - int32_t nextColId; - int32_t numOfColumns; - int32_t numOfTags; - SSchema* pColumns; - SSchema* pTags; - SRWLatch lock; - char comment[TSDB_STB_COMMENT_LEN]; + char name[TSDB_TABLE_FNAME_LEN]; + int64_t createdTime; + int64_t uid; + int8_t intervalUnit; + int8_t slidingUnit; + int8_t timezone; + int64_t interval; + int64_t offset; + int64_t sliding; + int32_t exprLen; + int32_t tagsFilterLen; + char* expr; + char* tagsFilter; +} STSmaObj; + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int64_t createdTime; + int64_t updateTime; + int64_t uid; + int64_t dbUid; + int32_t version; + int32_t nextColId; + int32_t numOfColumns; + int32_t numOfTags; + int32_t numOfTSmas; + SSchema* pColumns; + SSchema* pTags; + STSmaObj* pTSmas; + SRWLatch lock; + char comment[TSDB_STB_COMMENT_LEN]; } SStbObj; typedef struct { diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 121720f48f..8ad3135ab0 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -18,15 +18,15 @@ #include "mndAuth.h" #include "mndDb.h" #include "mndDnode.h" +#include "mndInfoSchema.h" #include "mndMnode.h" #include "mndShow.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" -#include "mndInfoSchema.h" #include "tname.h" -#define TSDB_STB_VER_NUMBER 1 +#define TSDB_STB_VER_NUMBER 1 #define TSDB_STB_RESERVE_SIZE 64 static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw); @@ -88,6 +88,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->numOfTSmas, STB_ENCODE_OVER) for (int32_t i = 0; i < pStb->numOfColumns; ++i) { SSchema *pSchema = &pStb->pColumns[i]; @@ -105,6 +106,23 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER) } + for (int32_t i = 0; i < pStb->numOfTSmas; ++i) { + STSmaObj *pTSma = &pStb->pTSmas[i]; + SDB_SET_BINARY(pRaw, dataPos, pTSma->name, TSDB_TABLE_FNAME_LEN, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTSma->createdTime, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTSma->uid, STB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pTSma->intervalUnit, STB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pTSma->slidingUnit, STB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pTSma->timezone, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTSma->interval, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTSma->offset, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pTSma->sliding, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pTSma->exprLen, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pTSma->tagsFilterLen, STB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pTSma->expr, pTSma->exprLen, STB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pTSma->tagsFilter, pTSma->tagsFilterLen, STB_ENCODE_OVER) + } + SDB_SET_BINARY(pRaw, dataPos, pStb->comment, TSDB_STB_COMMENT_LEN, STB_ENCODE_OVER) SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_ENCODE_OVER) SDB_SET_DATALEN(pRaw, dataPos, STB_ENCODE_OVER) @@ -150,6 +168,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pStb->nextColId, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTSmas, STB_DECODE_OVER) pStb->pColumns = calloc(pStb->numOfColumns, sizeof(SSchema)); pStb->pTags = calloc(pStb->numOfTags, sizeof(SSchema)); @@ -173,6 +192,23 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER) } + for (int32_t i = 0; i < pStb->numOfTSmas; ++i) { + STSmaObj *pTSma = &pStb->pTSmas[i]; + SDB_GET_BINARY(pRaw, dataPos, pTSma->name, TSDB_TABLE_FNAME_LEN, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTSma->createdTime, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTSma->uid, STB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pTSma->intervalUnit, STB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pTSma->slidingUnit, STB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pTSma->timezone, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTSma->interval, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTSma->offset, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pTSma->sliding, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pTSma->exprLen, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pTSma->tagsFilterLen, STB_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pTSma->expr, pTSma->exprLen, STB_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pTSma->tagsFilter, pTSma->tagsFilterLen, STB_DECODE_OVER) + } + SDB_GET_BINARY(pRaw, dataPos, pStb->comment, TSDB_STB_COMMENT_LEN, STB_DECODE_OVER) SDB_GET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_DECODE_OVER) @@ -1162,7 +1198,7 @@ static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * static int32_t mndDropStb(SMnode *pMnode, SNodeMsg *pReq, SDbObj *pDb, SStbObj *pStb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK,TRN_TYPE_DROP_STB, &pReq->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_STB, &pReq->rpcMsg); if (pTrans == NULL) goto DROP_STB_OVER; mDebug("trans:%d, used to drop stb:%s", pTrans->id, pStb->name); From d1363d9cb2283974826fbc4a37ba73e309063313 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 23 Mar 2022 14:47:24 +0800 Subject: [PATCH 38/68] task running --- example/src/tstream.c | 3 +- include/common/tmsg.h | 2 + source/common/src/tmsg.c | 31 ++++++------- source/dnode/mgmt/mnode/src/mmMsg.c | 2 + source/dnode/mnode/impl/src/mndScheduler.c | 17 ++++---- source/dnode/mnode/impl/src/mndStream.c | 51 +++++++++++++++++++--- source/dnode/mnode/impl/src/mndTopic.c | 2 +- source/dnode/vnode/src/inc/vnd.h | 6 --- source/dnode/vnode/src/tq/tq.c | 6 ++- 9 files changed, 82 insertions(+), 38 deletions(-) diff --git a/example/src/tstream.c b/example/src/tstream.c index 56650634c5..17073e14a6 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -77,7 +77,8 @@ int32_t create_stream() { } taos_free_result(pRes); - const char* sql = "select ts,sum(k) from tu1"; + const char* sql = "select sum(k) from tu1"; + /*const char* sql = "select sum(k) from tu1 interval(10m)";*/ pRes = tmq_create_stream(pConn, "stream1", "out1", sql); if (taos_errno(pRes) != 0) { printf("failed to create stream out1, reason:%s\n", taos_errstr(pRes)); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index f14fb3d246..812025e8e4 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2345,6 +2345,8 @@ static FORCE_INLINE SStreamTask* streamTaskNew(int64_t streamId, int32_t level) return NULL; } pTask->taskId = tGenIdPI32(); + pTask->streamId = streamId; + pTask->level = level; pTask->status = STREAM_TASK_STATUS__RUNNING; pTask->qmsg = NULL; return pTask; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 5b0c01a3a2..41c37cb7f2 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -313,12 +313,12 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); } - if(pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { + if (pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { SRSmaParam *param = pReq->stbCfg.pRSmaParam; tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); tlen += taosEncodeFixedI8(buf, param->delayUnit); tlen += taosEncodeFixedI8(buf, param->nFuncIds); - for(int8_t i=0; i< param->nFuncIds; ++i) { + for (int8_t i = 0; i < param->nFuncIds; ++i) { tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); } tlen += taosEncodeFixedI64(buf, param->delay); @@ -340,12 +340,12 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); } - if(pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { + if (pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { SRSmaParam *param = pReq->stbCfg.pRSmaParam; tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); tlen += taosEncodeFixedI8(buf, param->delayUnit); tlen += taosEncodeFixedI8(buf, param->nFuncIds); - for(int8_t i=0; i< param->nFuncIds; ++i) { + for (int8_t i = 0; i < param->nFuncIds; ++i) { tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); } tlen += taosEncodeFixedI64(buf, param->delay); @@ -385,7 +385,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name); } buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); - if(pReq->stbCfg.nBSmaCols > 0) { + if (pReq->stbCfg.nBSmaCols > 0) { pReq->stbCfg.pBSmaCols = (col_id_t *)malloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); @@ -393,14 +393,14 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { } else { pReq->stbCfg.pBSmaCols = NULL; } - if(pReq->rollup) { + if (pReq->rollup) { pReq->stbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); SRSmaParam *param = pReq->stbCfg.pRSmaParam; - buf = taosDecodeFixedU32(buf, (uint32_t*)¶m->xFilesFactor); + buf = taosDecodeFixedU32(buf, (uint32_t *)¶m->xFilesFactor); buf = taosDecodeFixedI8(buf, ¶m->delayUnit); buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); - if(param->nFuncIds > 0) { - for (int8_t i = 0; i< param->nFuncIds; ++i) { + if (param->nFuncIds > 0) { + for (int8_t i = 0; i < param->nFuncIds; ++i) { buf = taosDecodeFixedI32(buf, param->pFuncIds + i); } } else { @@ -425,7 +425,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name); } buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); - if(pReq->stbCfg.nBSmaCols > 0) { + if (pReq->stbCfg.nBSmaCols > 0) { pReq->stbCfg.pBSmaCols = (col_id_t *)malloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); @@ -433,14 +433,14 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { } else { pReq->stbCfg.pBSmaCols = NULL; } - if(pReq->rollup) { + if (pReq->rollup) { pReq->stbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); SRSmaParam *param = pReq->stbCfg.pRSmaParam; - buf = taosDecodeFixedU32(buf, (uint32_t*)¶m->xFilesFactor); + buf = taosDecodeFixedU32(buf, (uint32_t *)¶m->xFilesFactor); buf = taosDecodeFixedI8(buf, ¶m->delayUnit); buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); - if(param->nFuncIds > 0) { - for (int8_t i = 0; i< param->nFuncIds; ++i) { + if (param->nFuncIds > 0) { + for (int8_t i = 0; i < param->nFuncIds; ++i) { buf = taosDecodeFixedI32(buf, param->pFuncIds + i); } } else { @@ -2823,7 +2823,8 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeCStr(&encoder, pReq->outputTbName) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1; + if (tEncodeI32(&encoder, sqlLen) < 0) return -1; + if (tEncodeI32(&encoder, astLen) < 0) return -1; if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1; if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1; diff --git a/source/dnode/mgmt/mnode/src/mmMsg.c b/source/dnode/mgmt/mnode/src/mmMsg.c index 56a580ed93..fee568d20b 100644 --- a/source/dnode/mgmt/mnode/src/mmMsg.c +++ b/source/dnode/mgmt/mnode/src/mmMsg.c @@ -142,6 +142,8 @@ void mmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, (NodeMsgFp)mmProcessReadMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, (NodeMsgFp)mmProcessWriteMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); // Requests handled by VNODE dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index a6d27ffa44..3793d10537 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -34,20 +34,21 @@ extern bool tsStreamSchedV; -int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet* pEpSet, tmsg_t type) { +int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet* pEpSet, tmsg_t type, int32_t nodeId) { SCoder encoder; tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); tEncodeSStreamTask(&encoder, pTask); - int32_t tlen = sizeof(SMsgHead) + encoder.pos; + int32_t size = encoder.pos; + int32_t tlen = sizeof(SMsgHead) + size; tCoderClear(&encoder); void* buf = malloc(tlen); if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - ((SMsgHead*)buf)->streamTaskId = pTask->taskId; + ((SMsgHead*)buf)->streamTaskId = htonl(nodeId); void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tCoderInit(&encoder, TD_LITTLE_ENDIAN, abuf, tlen, TD_ENCODER); + tCoderInit(&encoder, TD_LITTLE_ENDIAN, abuf, size, TD_ENCODER); tEncodeSStreamTask(&encoder, pTask); tCoderClear(&encoder); @@ -72,7 +73,7 @@ int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SS terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } - mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_VND_TASK_DEPLOY); + mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId); return 0; } @@ -92,7 +93,7 @@ int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } - mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_SND_TASK_DEPLOY); + mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_SND_TASK_DEPLOY, 0); return 0; } @@ -118,7 +119,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { SSubplan* plan = nodesListGetNode(inner->pNodeList, level); if (level == 0) { - ASSERT(plan->type == SUBPLAN_TYPE_SCAN); + ASSERT(plan->subplanType == SUBPLAN_TYPE_SCAN); void* pIter = NULL; while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup); @@ -148,7 +149,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { SStreamTask* pTask = streamTaskNew(pStream->uid, level); pTask->pipeSource = 0; pTask->pipeSink = level == totLevel - 1 ? 1 : 0; - pTask->parallelizable = plan->type == SUBPLAN_TYPE_SCAN; + pTask->parallelizable = plan->subplanType == SUBPLAN_TYPE_SCAN; pTask->nextOpDst = STREAM_NEXT_OP_DST__VND; if (tsStreamSchedV) { diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 99aded0292..2ca4e10f68 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -21,6 +21,7 @@ #include "mndScheduler.h" #include "mndShow.h" #include "mndStb.h" +#include "mndTopic.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" @@ -33,6 +34,7 @@ static int32_t mndStreamActionInsert(SSdb *pSdb, SStreamObj *pStream); static int32_t mndStreamActionDelete(SSdb *pSdb, SStreamObj *pStream); static int32_t mndStreamActionUpdate(SSdb *pSdb, SStreamObj *pStream, SStreamObj *pNewStream); static int32_t mndProcessCreateStreamReq(SNodeMsg *pReq); +static int32_t mndProcessTaskDeployInternalRsp(SNodeMsg *pRsp); /*static int32_t mndProcessDropStreamReq(SNodeMsg *pReq);*/ /*static int32_t mndProcessDropStreamInRsp(SNodeMsg *pRsp);*/ static int32_t mndProcessStreamMetaReq(SNodeMsg *pReq); @@ -50,6 +52,8 @@ int32_t mndInitStream(SMnode *pMnode) { .deleteFp = (SdbDeleteFp)mndStreamActionDelete}; mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STREAM, mndProcessCreateStreamReq); + mndSetMsgHandle(pMnode, TDMT_VND_TASK_DEPLOY_RSP, mndProcessTaskDeployInternalRsp); + mndSetMsgHandle(pMnode, TDMT_SND_TASK_DEPLOY_RSP, mndProcessTaskDeployInternalRsp); /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM, mndProcessDropStreamReq);*/ /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM_RSP, mndProcessDropStreamInRsp);*/ @@ -68,7 +72,7 @@ SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) { SCoder encoder; tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); - if (tEncodeSStreamObj(NULL, pStream) < 0) { + if (tEncodeSStreamObj(&encoder, pStream) < 0) { tCoderClear(&encoder); goto STREAM_ENCODE_OVER; } @@ -83,7 +87,7 @@ SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) { if (buf == NULL) goto STREAM_ENCODE_OVER; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, tlen, TD_ENCODER); - if (tEncodeSStreamObj(NULL, pStream) < 0) { + if (tEncodeSStreamObj(&encoder, pStream) < 0) { tCoderClear(&encoder); goto STREAM_ENCODE_OVER; } @@ -135,7 +139,7 @@ SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) { SDB_GET_BINARY(pRaw, dataPos, buf, tlen, STREAM_DECODE_OVER); SCoder decoder; - tCoderInit(&decoder, TD_LITTLE_ENDIAN, NULL, 0, TD_DECODER); + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, tlen + 1, TD_DECODER); if (tDecodeSStreamObj(&decoder, pStream) < 0) { goto STREAM_DECODE_OVER; } @@ -191,6 +195,11 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream) { sdbRelease(pSdb, pStream); } +static int32_t mndProcessTaskDeployInternalRsp(SNodeMsg *pRsp) { + mndTransProcessRsp(pRsp); + return 0; +} + static SDbObj *mndAcquireDbByStream(SMnode *pMnode, char *streamName) { SName name = {0}; tNameFromString(&name, streamName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); @@ -209,6 +218,33 @@ static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) { return 0; } +static int32_t mndStreamGetPlanString(const SCMCreateStreamReq *pCreate, char **pStr) { + if (NULL == pCreate->ast) { + return TSDB_CODE_SUCCESS; + } + + SNode *pAst = NULL; + int32_t code = nodesStringToNode(pCreate->ast, &pAst); + + SQueryPlan *pPlan = NULL; + if (TSDB_CODE_SUCCESS == code) { + SPlanContext cxt = { + .pAstRoot = pAst, + .topicQuery = false, + .streamQuery = true, + }; + code = qCreateQueryPlan(&cxt, &pPlan, NULL); + } + + if (TSDB_CODE_SUCCESS == code) { + code = nodesNodeToString(pPlan, false, pStr, NULL); + } + nodesDestroyNode(pAst); + nodesDestroyNode(pPlan); + terrno = code; + return code; +} + static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamReq *pCreate, SDbObj *pDb) { mDebug("stream:%s to create", pCreate->name); SStreamObj streamObj = {0}; @@ -220,8 +256,13 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe streamObj.dbUid = pDb->uid; streamObj.version = 1; streamObj.sql = pCreate->sql; - streamObj.physicalPlan = ""; - streamObj.logicalPlan = ""; + /*streamObj.physicalPlan = "";*/ + streamObj.logicalPlan = "not implemented"; + + if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(pCreate, &streamObj.physicalPlan)) { + mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr()); + return -1; + } STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_STREAM, &pReq->rpcMsg); if (pTrans == NULL) { diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index bd0fd0e612..95dce5d8f1 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -236,7 +236,7 @@ static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) { return 0; } -static int32_t mndGetPlanString(SCMCreateTopicReq *pCreate, char **pStr) { +static int32_t mndGetPlanString(const SCMCreateTopicReq *pCreate, char **pStr) { if (NULL == pCreate->ast) { return TSDB_CODE_SUCCESS; } diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index bad5b7c6a2..2c9a5368ac 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -82,12 +82,6 @@ struct SVnode { int vnodeScheduleTask(SVnodeTask* task); -int32_t vnodePutToVQueryQ(SVnode* pVnode, struct SRpcMsg* pReq); -int32_t vnodePutToVFetchQ(SVnode* pVnode, struct SRpcMsg* pReq); -int32_t vnodeSendReq(SVnode* pVnode, struct SEpSet* epSet, struct SRpcMsg* pReq); -int32_t vnodeSendMnodeReq(SVnode* pVnode, struct SRpcMsg* pReq); -void vnodeSendRsp(SVnode* pVnode, struct SEpSet* epSet, struct SRpcMsg* pRsp); - #define vFatal(...) \ do { \ if (vDebugFlag & DEBUG_FATAL) { \ diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 0615ea31d4..099f6896b1 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -120,7 +120,7 @@ int tqPushMsg(STQ* pTq, void* msg, tmsg_t msgType, int64_t version) { .code = 0, .msgType = type, }; - /*vnodeSendReq(pTq->pVnode, &pTask->NextOpEp, &msg);*/ + tmsgSendReq(&pTq->pVnode->msgCb, &pTask->NextOpEp, &msg); } } @@ -498,7 +498,9 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { } SCoder decoder; tCoderInit(&decoder, TD_LITTLE_ENDIAN, (uint8_t*)msg, msgLen, TD_DECODER); - tDecodeSStreamTask(&decoder, pTask); + if (tDecodeSStreamTask(&decoder, pTask) < 0) { + ASSERT(0); + } tCoderClear(&decoder); tqExpandTask(pTq, pTask, 8); From 9006b0f576e67600ae409483a0ea9ebed7060388 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Mar 2022 13:50:53 +0800 Subject: [PATCH 39/68] add tsma --- include/common/tmsg.h | 29 ++++++++ include/common/tmsgdef.h | 2 + include/util/taoserror.h | 26 ++++--- source/common/src/tmsg.c | 93 ++++++++++++++++++++++++++ source/dnode/mgmt/mnode/src/mmMsg.c | 2 + source/dnode/mnode/impl/inc/mndDef.h | 48 +++++++++---- source/dnode/mnode/impl/inc/mndSma.h | 34 ++++++++++ source/dnode/mnode/impl/src/mndStb.c | 6 +- source/dnode/mnode/impl/src/mndTrans.c | 4 ++ source/util/src/terror.c | 4 ++ 10 files changed, 220 insertions(+), 28 deletions(-) create mode 100644 source/dnode/mnode/impl/inc/mndSma.h diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ca4e6b97a4..dd38873cf4 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1897,6 +1897,35 @@ static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) } return buf; } + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + char stb[TSDB_TABLE_FNAME_LEN]; + int8_t igExists; + int8_t intervalUnit; + int8_t slidingUnit; + int8_t timezone; + int64_t interval; + int64_t offset; + int64_t sliding; + int32_t exprLen; + int32_t tagsFilterLen; + char* expr; + char* tagsFilter; +} SMCreateSmaReq; + +int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq); +int32_t tDeserializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq); +void tFreeSMCreateSmaReq(SMCreateSmaReq* pReq); + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + int8_t igNotExists; +} SMDropSmaReq; + +int32_t tSerializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq); +int32_t tDeserializeSMDropSmaReq(void* buf, int32_t bufLen, SMDropSmaReq* pReq); + typedef struct { int8_t version; // for compatibility(default 0) int8_t intervalUnit; // MACRO: TIME_UNIT_XXX diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 73a78131dc..8cdb8dc8da 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -127,6 +127,8 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "mnode-create-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "mnode-alter-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SMA, "mnode-create-sma", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DROP_SMA, "mnode-drop-sma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TABLE_META, "mnode-table-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "mnode-vgroup-list", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_QNODE_LIST, "mnode-qnode-list", NULL, NULL) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 9f95848865..09b9ac7121 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -274,18 +274,22 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_STREAM_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03F1) #define TSDB_CODE_MND_INVALID_STREAM_OPTION TAOS_DEF_ERROR_CODE(0, 0x03F2) +// mnode-sma +#define TSDB_CODE_MND_SMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0400) +#define TSDB_CODE_MND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0401) + // dnode -#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400) -#define TSDB_CODE_DND_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x0401) -#define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0402) -#define TSDB_CODE_NODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0403) -#define TSDB_CODE_NODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0404) -#define TSDB_CODE_NODE_PARSE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0405) -#define TSDB_CODE_NODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0406) -#define TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0410) -#define TSDB_CODE_DND_VNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0411) -#define TSDB_CODE_DND_VNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0412) -#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0413) +#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x04A0) +#define TSDB_CODE_DND_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x04A1) +#define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x04A2) +#define TSDB_CODE_NODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x04A3) +#define TSDB_CODE_NODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x04A4) +#define TSDB_CODE_NODE_PARSE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x04A5) +#define TSDB_CODE_NODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x04A6) +#define TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x04A7) +#define TSDB_CODE_DND_VNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x04A8) +#define TSDB_CODE_DND_VNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x04A9) +#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x04AA) // vnode #define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b4caf5ba97..d4e9dfed73 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -589,6 +589,99 @@ void tFreeSMAltertbReq(SMAltertbReq *pReq) { pReq->pFields = NULL; } +int32_t tSerializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->stb) < 0) return -1; + if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; + if (tEncodeI8(&encoder, pReq->intervalUnit) < 0) return -1; + if (tEncodeI8(&encoder, pReq->slidingUnit) < 0) return -1; + if (tEncodeI8(&encoder, pReq->timezone) < 0) return -1; + if (tEncodeI64(&encoder, pReq->interval) < 0) return -1; + if (tEncodeI64(&encoder, pReq->offset) < 0) return -1; + if (tEncodeI64(&encoder, pReq->sliding) < 0) return -1; + if (tEncodeI32(&encoder, pReq->exprLen) < 0) return -1; + if (pReq->exprLen > 0) { + if (tEncodeBinary(&encoder, pReq->expr, pReq->exprLen) < 0) return -1; + } + if (tEncodeI32(&encoder, pReq->tagsFilterLen) < 0) return -1; + if (pReq->tagsFilterLen > 0) { + if (tEncodeBinary(&encoder, pReq->tagsFilter, pReq->tagsFilterLen) < 0) return -1; + } + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->stb) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->intervalUnit) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->slidingUnit) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->timezone) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->interval) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->offset) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->sliding) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->exprLen) < 0) return -1; + if (pReq->exprLen > 0) { + pReq->expr = malloc(pReq->exprLen); + if (pReq->expr == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->expr) < 0) return -1; + } + if (tDecodeI32(&decoder, &pReq->tagsFilterLen) < 0) return -1; + if (pReq->tagsFilterLen > 0) { + pReq->tagsFilter = malloc(pReq->tagsFilterLen); + if (pReq->tagsFilter == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->tagsFilter) < 0) return -1; + } + + tEndDecode(&decoder); + tCoderClear(&decoder); + return 0; +} + +void tFreeSMCreateSmaReq(SMCreateSmaReq *pReq) { + tfree(pReq->expr); + tfree(pReq->tagsFilter); +} + +int32_t tSerializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropSmaReq *pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; + if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropSmaReq *pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); diff --git a/source/dnode/mgmt/mnode/src/mmMsg.c b/source/dnode/mgmt/mnode/src/mmMsg.c index 333c4954ba..b6ff4f3ae1 100644 --- a/source/dnode/mgmt/mnode/src/mmMsg.c +++ b/source/dnode/mgmt/mnode/src/mmMsg.c @@ -123,6 +123,8 @@ void mmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, (NodeMsgFp)mmProcessWriteMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, (NodeMsgFp)mmProcessWriteMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, (NodeMsgFp)mmProcessReadMsg, 0); dndSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, (NodeMsgFp)mmProcessReadMsg, 0); dndSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, (NodeMsgFp)mmProcessWriteMsg, 0); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 909486aaac..4f97e03f16 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -103,6 +103,8 @@ typedef enum { TRN_TYPE_CREATE_STB = 4001, TRN_TYPE_ALTER_STB = 4002, TRN_TYPE_DROP_STB = 4003, + TRN_TYPE_CREATE_SMA = 4004, + TRN_TYPE_DROP_SMA = 4005, TRN_TYPE_STB_SCOPE_END, } ETrnType; @@ -306,20 +308,38 @@ typedef struct { } SVgObj; typedef struct { - char name[TSDB_TABLE_FNAME_LEN]; - char db[TSDB_DB_FNAME_LEN]; - int64_t createdTime; - int64_t updateTime; - int64_t uid; - int64_t dbUid; - int32_t version; - int32_t nextColId; - int32_t numOfColumns; - int32_t numOfTags; - SSchema* pColumns; - SSchema* pTags; - SRWLatch lock; - char comment[TSDB_STB_COMMENT_LEN]; + char name[TSDB_TABLE_FNAME_LEN]; + char stb[TSDB_DB_FNAME_LEN]; + int64_t createdTime; + int64_t uid; + int64_t stbUid; + int8_t intervalUnit; + int8_t slidingUnit; + int8_t timezone; + int64_t interval; + int64_t offset; + int64_t sliding; + int32_t exprLen; + int32_t tagsFilterLen; + char* expr; + char* tagsFilter; +} SSmaObj; + +typedef struct { + char name[TSDB_TABLE_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int64_t createdTime; + int64_t updateTime; + int64_t uid; + int64_t dbUid; + int32_t version; + int32_t nextColId; + int32_t numOfColumns; + int32_t numOfTags; + SSchema* pColumns; + SSchema* pTags; + SRWLatch lock; + char comment[TSDB_STB_COMMENT_LEN]; } SStbObj; typedef struct { diff --git a/source/dnode/mnode/impl/inc/mndSma.h b/source/dnode/mnode/impl/inc/mndSma.h new file mode 100644 index 0000000000..a47260d262 --- /dev/null +++ b/source/dnode/mnode/impl/inc/mndSma.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_MND_SMA_H_ +#define _TD_MND_SMA_H_ + +#include "mndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t mndInitSma(SMnode *pMnode); +void mndCleanupSma(SMnode *pMnode); +SSmaObj *mndAcquireSma(SMnode *pMnode, char *smaName); +void mndReleaseSma(SMnode *pMnode, SStbObj *pStb); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_SMA_H_*/ diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 121720f48f..99b7154c3f 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -18,15 +18,15 @@ #include "mndAuth.h" #include "mndDb.h" #include "mndDnode.h" +#include "mndInfoSchema.h" #include "mndMnode.h" #include "mndShow.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" -#include "mndInfoSchema.h" #include "tname.h" -#define TSDB_STB_VER_NUMBER 1 +#define TSDB_STB_VER_NUMBER 1 #define TSDB_STB_RESERVE_SIZE 64 static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw); @@ -1162,7 +1162,7 @@ static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * static int32_t mndDropStb(SMnode *pMnode, SNodeMsg *pReq, SDbObj *pDb, SStbObj *pStb) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK,TRN_TYPE_DROP_STB, &pReq->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_STB, &pReq->rpcMsg); if (pTrans == NULL) goto DROP_STB_OVER; mDebug("trans:%d, used to drop stb:%s", pTrans->id, pStb->name); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index e2a6e49b56..aa39c740ad 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -406,6 +406,10 @@ static const char *mndTransType(ETrnType type) { return "alter-stb"; case TRN_TYPE_DROP_STB: return "drop-stb"; + case TRN_TYPE_CREATE_SMA: + return "create-sma"; + case TRN_TYPE_DROP_SMA: + return "drop-sma"; default: return "invalid"; } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 8dd41a8fa8..04da9a4d09 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -270,6 +270,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_CANT_PARALLEL, "Invalid stage to kill // mnode-topic TAOS_DEFINE_ERROR(TSDB_CODE_MND_UNSUPPORTED_TOPIC, "Topic with aggregation is unsupported") +// mnode-sma +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SMA_ALREADY_EXIST, "SMA already exists") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SMA_NOT_EXIST, "SMA does not exist") + // dnode TAOS_DEFINE_ERROR(TSDB_CODE_DND_ACTION_IN_PROGRESS, "Action in progress") TAOS_DEFINE_ERROR(TSDB_CODE_DND_OFFLINE, "Dnode is offline") From ec790acc3ccfd95594db43a934cf6fa8c4a3c313 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Mar 2022 15:01:47 +0800 Subject: [PATCH 40/68] minor changes --- source/dnode/mnode/impl/inc/mndDef.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 4f97e03f16..47345e852a 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -326,20 +326,20 @@ typedef struct { } SSmaObj; typedef struct { - char name[TSDB_TABLE_FNAME_LEN]; - char db[TSDB_DB_FNAME_LEN]; - int64_t createdTime; - int64_t updateTime; - int64_t uid; - int64_t dbUid; - int32_t version; - int32_t nextColId; - int32_t numOfColumns; - int32_t numOfTags; - SSchema* pColumns; - SSchema* pTags; - SRWLatch lock; - char comment[TSDB_STB_COMMENT_LEN]; + char name[TSDB_TABLE_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int64_t createdTime; + int64_t updateTime; + int64_t uid; + int64_t dbUid; + int32_t version; + int32_t nextColId; + int32_t numOfColumns; + int32_t numOfTags; + SSchema* pColumns; + SSchema* pTags; + SRWLatch lock; + char comment[TSDB_STB_COMMENT_LEN]; } SStbObj; typedef struct { From bd6cde63cd3dbd92316b810b058a509d0b5e38c2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Mar 2022 15:03:02 +0800 Subject: [PATCH 41/68] sma --- source/dnode/mnode/impl/src/mndStb.c | 36 ---------------------------- 1 file changed, 36 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 8ad3135ab0..99b7154c3f 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -88,7 +88,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, STB_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pStb->numOfTSmas, STB_ENCODE_OVER) for (int32_t i = 0; i < pStb->numOfColumns; ++i) { SSchema *pSchema = &pStb->pColumns[i]; @@ -106,23 +105,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER) } - for (int32_t i = 0; i < pStb->numOfTSmas; ++i) { - STSmaObj *pTSma = &pStb->pTSmas[i]; - SDB_SET_BINARY(pRaw, dataPos, pTSma->name, TSDB_TABLE_FNAME_LEN, STB_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pTSma->createdTime, STB_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pTSma->uid, STB_ENCODE_OVER) - SDB_SET_INT8(pRaw, dataPos, pTSma->intervalUnit, STB_ENCODE_OVER) - SDB_SET_INT8(pRaw, dataPos, pTSma->slidingUnit, STB_ENCODE_OVER) - SDB_SET_INT8(pRaw, dataPos, pTSma->timezone, STB_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pTSma->interval, STB_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pTSma->offset, STB_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pTSma->sliding, STB_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pTSma->exprLen, STB_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pTSma->tagsFilterLen, STB_ENCODE_OVER) - SDB_SET_BINARY(pRaw, dataPos, pTSma->expr, pTSma->exprLen, STB_ENCODE_OVER) - SDB_SET_BINARY(pRaw, dataPos, pTSma->tagsFilter, pTSma->tagsFilterLen, STB_ENCODE_OVER) - } - SDB_SET_BINARY(pRaw, dataPos, pStb->comment, TSDB_STB_COMMENT_LEN, STB_ENCODE_OVER) SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_ENCODE_OVER) SDB_SET_DATALEN(pRaw, dataPos, STB_ENCODE_OVER) @@ -168,7 +150,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pStb->nextColId, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, STB_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTSmas, STB_DECODE_OVER) pStb->pColumns = calloc(pStb->numOfColumns, sizeof(SSchema)); pStb->pTags = calloc(pStb->numOfTags, sizeof(SSchema)); @@ -192,23 +173,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER) } - for (int32_t i = 0; i < pStb->numOfTSmas; ++i) { - STSmaObj *pTSma = &pStb->pTSmas[i]; - SDB_GET_BINARY(pRaw, dataPos, pTSma->name, TSDB_TABLE_FNAME_LEN, STB_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pTSma->createdTime, STB_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pTSma->uid, STB_DECODE_OVER) - SDB_GET_INT8(pRaw, dataPos, &pTSma->intervalUnit, STB_DECODE_OVER) - SDB_GET_INT8(pRaw, dataPos, &pTSma->slidingUnit, STB_DECODE_OVER) - SDB_GET_INT8(pRaw, dataPos, &pTSma->timezone, STB_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pTSma->interval, STB_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pTSma->offset, STB_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pTSma->sliding, STB_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pTSma->exprLen, STB_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pTSma->tagsFilterLen, STB_DECODE_OVER) - SDB_GET_BINARY(pRaw, dataPos, pTSma->expr, pTSma->exprLen, STB_DECODE_OVER) - SDB_GET_BINARY(pRaw, dataPos, pTSma->tagsFilter, pTSma->tagsFilterLen, STB_DECODE_OVER) - } - SDB_GET_BINARY(pRaw, dataPos, pStb->comment, TSDB_STB_COMMENT_LEN, STB_DECODE_OVER) SDB_GET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_DECODE_OVER) From d27329d651f5b6de9a2502f276dad6ee64817e20 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 23 Mar 2022 15:45:13 +0800 Subject: [PATCH 42/68] [add cases] --- tests/script/tsim/insert/backquote.sim | 343 +++++++++++++++++++++++++ tests/script/tsim/testCaseSuite.sim | 18 ++ 2 files changed, 361 insertions(+) create mode 100644 tests/script/tsim/insert/backquote.sim create mode 100644 tests/script/tsim/testCaseSuite.sim diff --git a/tests/script/tsim/insert/backquote.sim b/tests/script/tsim/insert/backquote.sim new file mode 100644 index 0000000000..59191fa2a5 --- /dev/null +++ b/tests/script/tsim/insert/backquote.sim @@ -0,0 +1,343 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +print =============== create database +sql create database `database` +sql create database `DataBase` +sql show databases +print rows: $rows +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +if $rows != 3 then + return -1 +endi +if $data00 != database then + return -1 +endi +if $data10 != DataBase then + return -1 +endi +if $data20 != information_schema then + return -1 +endi + +$dbCnt = 0 +while $dbCnt < 2 + if $dbCnt == 0 then + sql use `database` + else + sql use `DataBase` + endi + + $dbCnt = $dbCnt + 1 + + print =============== create super table, include all type + sql create table `stable` (`timestamp` timestamp, `int` int, `binary` binary(16), `nchar` nchar(16)) tags (`float` float, `Binary` binary(16), `Nchar` nchar(16)) + sql create table `Stable` (`timestamp` timestamp, `int` int, `Binary` binary(32), `Nchar` nchar(32)) tags (`float` float, `binary` binary(16), `nchar` nchar(16)) + + sql show stables + print rows: $rows + print $data00 $data01 + print $data10 $data11 + if $rows != 2 then + return -1 + endi + if $data00 != Stable then + return -1 + endi + if $data10 != stable then + return -1 + endi + + print =============== create child table + sql create table `table` using `stable` tags(100.0, 'stable+table', 'stable+table') + sql create table `Table` using `stable` tags(100.1, 'stable+Table', 'stable+Table') + + sql create table `TAble` using `Stable` tags(100.0, 'Stable+TAble', 'Stable+TAble') + sql create table `TABle` using `Stable` tags(100.1, 'Stable+TABle', 'Stable+TABle') + + sql show tables + print rows: $rows + print $data00 $data01 + print $data10 $data11 + print $data20 $data21 + print $data30 $data31 + if $rows != 4 then + return -1 + endi + + print =============== insert data + sql insert into `table` values(now+0s, 10, 'table', 'table')(now+1s, 11, 'table', 'table') + sql insert into `Table` values(now+0s, 20, 'Table', 'Table')(now+1s, 21, 'Table', 'Table') + sql insert into `TAble` values(now+0s, 30, 'TAble', 'TAble')(now+1s, 31, 'TAble', 'TAble') + sql insert into `TABle` values(now+0s, 40, 'TABle', 'TABle')(now+4s, 41, 'TABle', 'TABle') + + print =============== query data + sql select * from `table` + print rows: $rows + print $data00 $data01 $data02 $data03 + print $data10 $data11 $data12 $data13 + if $rows != 2 then + return -1 + endi + if $data01 != 10 then + return -1 + endi + if $data02 != table then + return -1 + endi + if $data03 != table then + return -1 + endi + + sql select * from `Table` + print rows: $rows + print $data00 $data01 $data02 $data03 + print $data10 $data11 $data12 $data13 + if $rows != 2 then + return -1 + endi + if $data01 != 20 then + return -1 + endi + if $data02 != Table then + return -1 + endi + if $data03 != Table then + return -1 + endi + + sql select * from `TAble` + print rows: $rows + print $data00 $data01 $data02 $data03 + print $data10 $data11 $data12 $data13 + if $rows != 2 then + return -1 + endi + if $data01 != 30 then + return -1 + endi + if $data02 != TAble then + return -1 + endi + if $data03 != TAble then + return -1 + endi + + sql select * from `TABle` + print rows: $rows + print $data00 $data01 $data02 $data03 + print $data10 $data11 $data12 $data13 + if $rows != 2 then + return -1 + endi + if $data01 != 40 then + return -1 + endi + if $data02 != TABle then + return -1 + endi + if $data03 != TABle then + return -1 + endi + + print =============== query data from st, but not support select * from super table, waiting fix + sql select count(*) from `stable` + print rows: $rows + print $data00 $data01 $data02 $data03 + if $rows != 1 then + return -1 + endi + if $data00 != 4 then + return -1 + endi + sql select count(*) from `Stable` + print rows: $rows + print $data00 $data01 $data02 $data03 + if $rows != 1 then + return -1 + endi + if $data00 != 4 then + return -1 + endi + #sql select * from st + #if $rows != 4 then + # return -1 + #endi + +endw + +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: + $loop_cnt = $loop_cnt + 1 + sleep 100 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql show databases +print rows: $rows +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +if $rows != 3 then + return -1 +endi +if $data00 != database then + return -1 +endi +if $data10 != DataBase then + return -1 +endi +if $data20 != information_schema then + return -1 +endi + +$dbCnt = 0 +while $dbCnt < 2 + if $dbCnt == 0 then + sql use `database` + else + sql use `DataBase` + endi + + $dbCnt = $dbCnt + 1 + + sql show stables + print rows: $rows + print $data00 $data01 + print $data10 $data11 + if $rows != 2 then + return -1 + endi + if $data00 != Stable then + return -1 + endi + if $data10 != stable then + return -1 + endi + + sql show tables + print rows: $rows + print $data00 $data01 + print $data10 $data11 + print $data20 $data21 + print $data30 $data31 + if $rows != 4 then + return -1 + endi + + print =============== query data + sql select * from `table` + print rows: $rows + print $data00 $data01 $data02 $data03 + print $data10 $data11 $data12 $data13 + if $rows != 2 then + return -1 + endi + if $data01 != 10 then + return -1 + endi + if $data02 != table then + return -1 + endi + if $data03 != table then + return -1 + endi + + sql select * from `Table` + print rows: $rows + print $data00 $data01 $data02 $data03 + print $data10 $data11 $data12 $data13 + if $rows != 2 then + return -1 + endi + if $data01 != 20 then + return -1 + endi + if $data02 != Table then + return -1 + endi + if $data03 != Table then + return -1 + endi + + sql select * from `TAble` + print rows: $rows + print $data00 $data01 $data02 $data03 + print $data10 $data11 $data12 $data13 + if $rows != 2 then + return -1 + endi + if $data01 != 30 then + return -1 + endi + if $data02 != TAble then + return -1 + endi + if $data03 != TAble then + return -1 + endi + + sql select * from `TABle` + print rows: $rows + print $data00 $data01 $data02 $data03 + print $data10 $data11 $data12 $data13 + if $rows != 2 then + return -1 + endi + if $data01 != 40 then + return -1 + endi + if $data02 != TABle then + return -1 + endi + if $data03 != TABle then + return -1 + endi + + print =============== query data from st, but not support select * from super table, waiting fix + sql select count(*) from `stable` + print rows: $rows + print $data00 $data01 $data02 $data03 + if $rows != 1 then + return -1 + endi + if $data00 != 4 then + return -1 + endi + sql select count(*) from `Stable` + print rows: $rows + print $data00 $data01 $data02 $data03 + if $rows != 1 then + return -1 + endi + if $data00 != 4 then + return -1 + endi + #sql select * from st + #if $rows != 4 then + # return -1 + #endi + +endw + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/testCaseSuite.sim b/tests/script/tsim/testCaseSuite.sim new file mode 100644 index 0000000000..88f1911a2b --- /dev/null +++ b/tests/script/tsim/testCaseSuite.sim @@ -0,0 +1,18 @@ + +run tsim/db/basic1.sim +run tsim/db/basic6.sim +run tsim/db/basic7.sim +run tsim/db/error1.sim + +run tsim/dnode/basic1.sim + +run tsim/insert/basic0.sim +run tsim/insert/basic1.sim +run tsim/insert/null.sim + +run tsim/query/interval-offset.sim +run tsim/query/interval.sim + +run tsim/table/basic1.sim + +run tsim/user/basic1.sim From 6f11fd217e49f4013ab9077c5e0bf7dad2fcdcef Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 23 Mar 2022 15:56:49 +0800 Subject: [PATCH 43/68] [td-13039] support group by multi-columns. --- source/libs/executor/inc/executorimpl.h | 12 +- source/libs/executor/src/executorimpl.c | 211 ++++++++++++++++++------ 2 files changed, 168 insertions(+), 55 deletions(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index f170d5c529..c3f5b37a09 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -541,10 +541,20 @@ typedef struct SFillOperatorInfo { bool multigroupResult; } SFillOperatorInfo; +typedef struct SGroupKeys { + char *pData; + bool isNull; + int16_t type; + int32_t bytes; +}SGroupKeys; + typedef struct SGroupbyOperatorInfo { SOptrBasicInfo binfo; SArray* pGroupCols; - char* prevData; // previous group by value + SArray* pGroupColVals; // current group column values, SArray + bool isInit; // denote if current val is initialized or not + char* keyBuf; // group by keys for hash + int32_t groupKeyLen; // total group by column width SGroupResInfo groupResInfo; SAggSupporter aggSup; } SGroupbyOperatorInfo; diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index e927b577de..d643500927 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -1623,67 +1623,142 @@ static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe // updateResultRowInfoActiveIndex(pResultRowInfo, pQueryAttr, pRuntimeEnv->current->lastKey); } -static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pInfo, SSDataBlock *pBlock) { - SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; +static bool groupKeyCompare(SGroupbyOperatorInfo* pInfo, SSDataBlock* pBlock, int32_t rowIndex, int32_t numOfGroupCols) { + SColumnDataAgg* pColAgg = NULL; + for (int32_t i = 0; i < numOfGroupCols; ++i) { + SColumn* pCol = taosArrayGet(pInfo->pGroupCols, i); + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pCol->slotId); + if (pBlock->pBlockAgg != NULL) { + pColAgg = &pBlock->pBlockAgg[pCol->slotId]; // TODO is agg data matched? + } - // TODO multiple group by columns - SColumn* pCol = taosArrayGet(pInfo->pGroupCols, 0); - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pCol->slotId); + bool isNull = colDataIsNull(pColInfoData, pBlock->info.rows, rowIndex, pColAgg); - int16_t bytes = pColInfoData->info.bytes; - int16_t type = pColInfoData->info.type; - if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE) { - //qError("QInfo:0x%"PRIx64" group by not supported on double/float columns, abort", GET_TASKID(pRuntimeEnv)); - return; + SGroupKeys* pkey = taosArrayGet(pInfo->pGroupColVals, i); + if (pkey->isNull && isNull) { + continue; + } + + if (isNull || pkey->isNull) { + return false; + } + + char* val = colDataGetData(pColInfoData, rowIndex); + + if (IS_VAR_DATA_TYPE(pkey->type)) { + int32_t len = varDataLen(val); + if (len == varDataLen(pkey->pData) && memcmp(varDataVal(pkey->pData), varDataVal(val), len) == 0) { + continue; + } else { + return false; + } + } else { + if (memcmp(pkey->pData, val, pkey->bytes) != 0) { + return false; + } + } } + return true; +} + +static void keepGroupKeys(SGroupbyOperatorInfo* pInfo, SSDataBlock* pBlock, int32_t rowIndex, int32_t numOfGroupCols) { + SColumnDataAgg* pColAgg = NULL; + + for (int32_t i = 0; i < numOfGroupCols; ++i) { + SColumn* pCol = taosArrayGet(pInfo->pGroupCols, i); + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pCol->slotId); + + if (pBlock->pBlockAgg != NULL) { + pColAgg = &pBlock->pBlockAgg[pCol->slotId]; // TODO is agg data matched? + } + + SGroupKeys* pkey = taosArrayGet(pInfo->pGroupColVals, i); + if (colDataIsNull(pColInfoData, pBlock->info.rows, rowIndex, pColAgg)) { + pkey->isNull = true; + } else { + char* val = colDataGetData(pColInfoData, rowIndex); + if (IS_VAR_DATA_TYPE(pkey->type)) { + memcpy(pkey->pData, val, varDataTLen(val)); + } else { + memcpy(pkey->pData, val, pkey->bytes); + } + } + } +} + +static int32_t generatedHashKey(void* pKey, int32_t* length, SArray* pGroupColVals) { + ASSERT(pKey != NULL); + size_t numOfGroupCols = taosArrayGetSize(pGroupColVals); + + char* isNull = (char*) pKey; + char* pStart = (char*) pKey + sizeof(int8_t) * numOfGroupCols; + for(int32_t i = 0; i < numOfGroupCols; ++i) { + SGroupKeys* pkey = taosArrayGet(pGroupColVals, i); + if (pkey->isNull) { + isNull[i] = 1; + continue; + } + + isNull[i] = 0; + if (IS_VAR_DATA_TYPE(pkey->type)) { + varDataCopy(pStart, pkey->pData); + pStart += varDataTLen(pkey->pData); + ASSERT(varDataTLen(pkey->pData) <= pkey->bytes); + } else { + memcpy(pStart, pkey->pData, pkey->bytes); + pStart += pkey->bytes; + } + } + + *length = (pStart - (char*) pKey); + return 0; +} + +static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock *pBlock) { + SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; + SGroupbyOperatorInfo *pInfo = pOperator->info; + + int32_t numOfGroupCols = taosArrayGetSize(pInfo->pGroupCols); +// if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE) { + //qError("QInfo:0x%"PRIx64" group by not supported on double/float columns, abort", GET_TASKID(pRuntimeEnv)); +// return; +// } + + int32_t len = 0; STimeWindow w = TSWINDOW_INITIALIZER; int32_t num = 0; for (int32_t j = 0; j < pBlock->info.rows; ++j) { - if (colDataIsNull(pColInfoData, pBlock->info.rows, j, NULL)) { // TODO - continue; - } - - char* val = colDataGetData(pColInfoData, j); - // Compare with the previous row of this column, and do not set the output buffer again if they are identical. - if (pInfo->prevData == NULL) { - pInfo->prevData = malloc(bytes); - memcpy(pInfo->prevData, val, bytes); + if (!pInfo->isInit) { + keepGroupKeys(pInfo, pBlock, j, numOfGroupCols); + pInfo->isInit = true; num++; continue; } - if (IS_VAR_DATA_TYPE(type)) { - int32_t len = varDataLen(val); - if(len == varDataLen(pInfo->prevData) && memcmp(varDataVal(pInfo->prevData), varDataVal(val), len) == 0) { - num++; - continue; - } - } else { - if (memcmp(pInfo->prevData, val, bytes) == 0) { - num++; - continue; - } + bool equal = groupKeyCompare(pInfo, pBlock, j, numOfGroupCols); + if (equal) { + num++; + continue; } - int32_t ret = setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->prevData, type, bytes, 0, - pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup); + /*int32_t ret = */generatedHashKey(pInfo->keyBuf, &len, pInfo->pGroupColVals); + int32_t ret = setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, + pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } doApplyFunctions(pInfo->binfo.pCtx, &w, j - num, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); - + keepGroupKeys(pInfo, pBlock, j, numOfGroupCols); num = 1; - memcpy(pInfo->prevData, val, bytes); } if (num > 0) { - char* val = ((char*)pColInfoData->pData) + bytes * (pBlock->info.rows - num); - memcpy(pInfo->prevData, val, bytes); - int32_t ret = setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->prevData, type, bytes, 0, + /*int32_t ret = */generatedHashKey(pInfo->keyBuf, &len, pInfo->pGroupColVals); + int32_t ret = setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup); if (ret != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); @@ -1691,8 +1766,6 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn doApplyFunctions(pInfo->binfo.pCtx, &w, pBlock->info.rows - num, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); } - - tfree(pInfo->prevData); } static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { @@ -1783,20 +1856,11 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo *binfo, int32_t numOfCols, char *pData, int16_t type, int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup) { - int32_t *rowCellInfoOffset = binfo->rowCellInfoOffset; SResultRowInfo *pResultRowInfo = &binfo->resultRowInfo; SqlFunctionCtx *pCtx = binfo->pCtx; - // not assign result buffer yet, add new result buffer, TODO remove it - char* d = pData; - int16_t len = bytes; - if (IS_VAR_DATA_TYPE(type)) { - d = varDataVal(pData); - len = varDataLen(pData); - } - - int64_t tid = 0; - SResultRow *pResultRow = doSetResultOutBufByKey_rv(pBuf, pResultRowInfo, groupId, (char *)pData, TSDB_KEYSIZE, true, groupId, pTaskInfo, true, pAggSup); + SResultRow *pResultRow = doSetResultOutBufByKey_rv(pBuf, pResultRowInfo, groupId, (char *)pData, bytes, true, groupId, + pTaskInfo, true, pAggSup); assert (pResultRow != NULL); setResultRowKey(pResultRow, pData, type); @@ -6969,7 +7033,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo *pOperator, bool* newgrou // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); // setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput); - doHashGroupbyAgg(pOperator, pInfo, pBlock); + doHashGroupbyAgg(pOperator, pBlock); } pOperator->status = OP_RES_TO_RETURN; @@ -7281,7 +7345,9 @@ void destroySFillOperatorInfo(void* param, int32_t numOfOutput) { void destroyGroupbyOperatorInfo(void* param, int32_t numOfOutput) { SGroupbyOperatorInfo* pInfo = (SGroupbyOperatorInfo*) param; doDestroyBasicInfo(&pInfo->binfo, numOfOutput); - tfree(pInfo->prevData); + tfree(pInfo->keyBuf); + taosArrayDestroy(pInfo->pGroupCols); + taosArrayDestroy(pInfo->pGroupColVals); } static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) { @@ -7664,6 +7730,39 @@ SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRun return pOperator; } +static int32_t initGroupOptrInfo(SGroupbyOperatorInfo *pInfo, SArray* pGroupColList) { + pInfo->pGroupColVals = taosArrayInit(4, sizeof(SGroupKeys)); + if (pInfo->pGroupColVals == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); + for(int32_t i = 0; i < numOfGroupCols; ++i) { + SColumn* pCol = taosArrayGet(pGroupColList, i); + pInfo->groupKeyLen += pCol->bytes; + + struct SGroupKeys key = {0}; + key.bytes = pCol->bytes; + key.type = pCol->type; + key.isNull = false; + key.pData = calloc(1, pCol->bytes); + if (key.pData == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + taosArrayPush(pInfo->pGroupColVals, &key); + } + + int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols; + pInfo->keyBuf = calloc(1, pInfo->groupKeyLen + nullFlagSize); + + if (pInfo->keyBuf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + return TSDB_CODE_SUCCESS; +} + SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { SGroupbyOperatorInfo* pInfo = calloc(1, sizeof(SGroupbyOperatorInfo)); @@ -7674,9 +7773,13 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pInfo->pGroupCols = pGroupColList; initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, 4096, pResultBlock, pTaskInfo->id.str); - initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); + int32_t code = initGroupOptrInfo(pInfo, pGroupColList); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pOperator->name = "GroupbyAggOperator"; pOperator->blockingOptr = true; pOperator->status = OP_NOT_OPENED; @@ -7688,7 +7791,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pOperator->getNextFn = hashGroupbyAggregate; pOperator->closeFn = destroyGroupbyOperatorInfo; - int32_t code = appendDownstream(pOperator, &downstream, 1); + code = appendDownstream(pOperator, &downstream, 1); return pOperator; _error: From 1ad4440b56a7cebc5b25cfe9769ef8d503b43aa2 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 23 Mar 2022 16:08:08 +0800 Subject: [PATCH 44/68] [modify] --- tests/script/tsim/query/interval-offset.sim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/tsim/query/interval-offset.sim b/tests/script/tsim/query/interval-offset.sim index a463d69fe5..ffc9995ef5 100644 --- a/tests/script/tsim/query/interval-offset.sim +++ b/tests/script/tsim/query/interval-offset.sim @@ -9,7 +9,7 @@ sql drop database d0 -x step1 step1: sql create database d0 sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi From 47d325519073a1b4da2b9d92c7d6968295df512c Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 23 Mar 2022 16:26:18 +0800 Subject: [PATCH 45/68] [td-14192] fix bug --- source/libs/executor/src/executorimpl.c | 4 +++- tests/script/tsim/query/interval-offset.sim | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index d643500927..2e769936eb 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -8448,7 +8448,9 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->pFuncs, NULL, &num); SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); - SInterval interval = {.interval = pIntervalPhyNode->interval, .sliding = pIntervalPhyNode->sliding, .intervalUnit = 'a', .slidingUnit = 'a'}; + SInterval interval = {.interval = pIntervalPhyNode->interval, .sliding = pIntervalPhyNode->sliding, + .intervalUnit = pIntervalPhyNode->intervalUnit, + .slidingUnit = pIntervalPhyNode->slidingUnit, .offset = pIntervalPhyNode->offset}; return createIntervalOperatorInfo(op, pExprInfo, num, pResBlock, &interval, pTableGroupInfo, pTaskInfo); } } /*else if (pPhyNode->info.type == OP_MultiTableAggregate) { diff --git a/tests/script/tsim/query/interval-offset.sim b/tests/script/tsim/query/interval-offset.sim index a463d69fe5..2ff1c7a155 100644 --- a/tests/script/tsim/query/interval-offset.sim +++ b/tests/script/tsim/query/interval-offset.sim @@ -9,7 +9,7 @@ sql drop database d0 -x step1 step1: sql create database d0 sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi From 69b2ec09f436f8ac3a75c22a0e417e4f4ba41db5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Mar 2022 16:45:59 +0800 Subject: [PATCH 46/68] sma --- include/common/tmsg.h | 8 +- include/dnode/mnode/sdb/sdb.h | 9 +- source/dnode/mnode/impl/inc/mndDef.h | 4 +- source/dnode/mnode/impl/inc/mndSma.h | 2 +- source/dnode/mnode/impl/src/mndSma.c | 737 +++++++++++++++++++++++++++ source/dnode/mnode/impl/src/mndStb.c | 1 - 6 files changed, 751 insertions(+), 10 deletions(-) create mode 100644 source/dnode/mnode/impl/src/mndSma.c diff --git a/include/common/tmsg.h b/include/common/tmsg.h index dd38873cf4..4fc3f6ce8f 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -108,6 +108,7 @@ typedef enum _mgmt_table { TSDB_MGMT_TABLE_STREAMTABLES, TSDB_MGMT_TABLE_TP, TSDB_MGMT_TABLE_FUNC, + TSDB_MGMT_TABLE_INDEX, TSDB_MGMT_TABLE_MAX, } EShowType; @@ -1930,8 +1931,9 @@ typedef struct { int8_t version; // for compatibility(default 0) int8_t intervalUnit; // MACRO: TIME_UNIT_XXX int8_t slidingUnit; // MACRO: TIME_UNIT_XXX + int8_t timezoneInt; // sma data expired if timezone changes. char indexName[TSDB_INDEX_NAME_LEN]; - char timezone[TD_TIMEZONE_LEN]; // sma data expired if timezone changes. + char timezone[TD_TIMEZONE_LEN]; int32_t exprLen; int32_t tagsFilterLen; int64_t indexUid; @@ -2038,8 +2040,8 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) { tlen += taosEncodeFixedI8(buf, pSma->version); tlen += taosEncodeFixedI8(buf, pSma->intervalUnit); tlen += taosEncodeFixedI8(buf, pSma->slidingUnit); + tlen += taosEncodeFixedI8(buf, pSma->timezoneInt); tlen += taosEncodeString(buf, pSma->indexName); - tlen += taosEncodeString(buf, pSma->timezone); tlen += taosEncodeFixedI32(buf, pSma->exprLen); tlen += taosEncodeFixedI32(buf, pSma->tagsFilterLen); tlen += taosEncodeFixedI64(buf, pSma->indexUid); @@ -2073,8 +2075,8 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) { buf = taosDecodeFixedI8(buf, &pSma->version); buf = taosDecodeFixedI8(buf, &pSma->intervalUnit); buf = taosDecodeFixedI8(buf, &pSma->slidingUnit); + buf = taosDecodeFixedI8(buf, &pSma->timezoneInt); buf = taosDecodeStringTo(buf, pSma->indexName); - buf = taosDecodeStringTo(buf, pSma->timezone); buf = taosDecodeFixedI32(buf, &pSma->exprLen); buf = taosDecodeFixedI32(buf, &pSma->tagsFilterLen); buf = taosDecodeFixedI64(buf, &pSma->indexUid); diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index d04e9f817e..a28c093e85 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -119,10 +119,11 @@ typedef enum { SDB_CONSUMER = 13, SDB_TOPIC = 14, SDB_VGROUP = 15, - SDB_STB = 16, - SDB_DB = 17, - SDB_FUNC = 18, - SDB_MAX = 19 + SDB_SMA = 16, + SDB_STB = 17, + SDB_DB = 18, + SDB_FUNC = 19, + SDB_MAX = 20 } ESdbType; typedef struct SSdb SSdb; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 47345e852a..1be5279d17 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -309,10 +309,12 @@ typedef struct { typedef struct { char name[TSDB_TABLE_FNAME_LEN]; - char stb[TSDB_DB_FNAME_LEN]; + char stb[TSDB_TABLE_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; int64_t createdTime; int64_t uid; int64_t stbUid; + int64_t dbUid; int8_t intervalUnit; int8_t slidingUnit; int8_t timezone; diff --git a/source/dnode/mnode/impl/inc/mndSma.h b/source/dnode/mnode/impl/inc/mndSma.h index a47260d262..4a80f619d3 100644 --- a/source/dnode/mnode/impl/inc/mndSma.h +++ b/source/dnode/mnode/impl/inc/mndSma.h @@ -25,7 +25,7 @@ extern "C" { int32_t mndInitSma(SMnode *pMnode); void mndCleanupSma(SMnode *pMnode); SSmaObj *mndAcquireSma(SMnode *pMnode, char *smaName); -void mndReleaseSma(SMnode *pMnode, SStbObj *pStb); +void mndReleaseSma(SMnode *pMnode, SSmaObj *pSma); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c new file mode 100644 index 0000000000..bd459b873b --- /dev/null +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -0,0 +1,737 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "mndSma.h" +#include "mndAuth.h" +#include "mndDb.h" +#include "mndDnode.h" +#include "mndInfoSchema.h" +#include "mndMnode.h" +#include "mndShow.h" +#include "mndStb.c" +#include "mndTrans.h" +#include "mndUser.h" +#include "mndVgroup.h" +#include "tname.h" + +#define TSDB_SMA_VER_NUMBER 1 +#define TSDB_SMA_RESERVE_SIZE 64 + +static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma); +static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw); +static int32_t mndSmaActionInsert(SSdb *pSdb, SSmaObj *pSma); +static int32_t mndSmaActionDelete(SSdb *pSdb, SSmaObj *pSpSmatb); +static int32_t mndSmaActionUpdate(SSdb *pSdb, SSmaObj *pOld, SSmaObj *pNew); +static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq); +static int32_t mndProcessMDropSmaReq(SNodeMsg *pReq); +static int32_t mndProcessVCreateSmaRsp(SNodeMsg *pRsp); +static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp); +static int32_t mndGetSmaMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); +static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static void mndCancelGetNextSma(SMnode *pMnode, void *pIter); + +int32_t mndInitSma(SMnode *pMnode) { + SSdbTable table = {.sdbType = SDB_SMA, + .keyType = SDB_KEY_BINARY, + .encodeFp = (SdbEncodeFp)mndSmaActionEncode, + .decodeFp = (SdbDecodeFp)mndSmaActionDecode, + .insertFp = (SdbInsertFp)mndSmaActionInsert, + .updateFp = (SdbUpdateFp)mndSmaActionUpdate, + .deleteFp = (SdbDeleteFp)mndSmaActionDelete}; + + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_SMA, mndProcessMCreateSmaReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_SMA, mndProcessMDropSmaReq); + mndSetMsgHandle(pMnode, TDMT_VND_CREATE_SMA_RSP, mndProcessVCreateSmaRsp); + mndSetMsgHandle(pMnode, TDMT_VND_DROP_SMA_RSP, mndProcessVDropSmaRsp); + + mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndGetSmaMeta); + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndRetrieveSma); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndCancelGetNextSma); + return sdbSetTable(pMnode->pSdb, table); +} + +void mndCleanupSma(SMnode *pMnode) {} + +static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + + int32_t size = sizeof(SSmaObj) + pSma->exprLen + pSma->tagsFilterLen + TSDB_SMA_RESERVE_SIZE; + SSdbRaw *pRaw = sdbAllocRaw(SDB_SMA, TSDB_SMA_VER_NUMBER, size); + if (pRaw == NULL) goto _OVER; + + int32_t dataPos = 0; + + SDB_SET_BINARY(pRaw, dataPos, pSma->name, TSDB_TABLE_FNAME_LEN, _OVER) + SDB_SET_BINARY(pRaw, dataPos, pSma->stb, TSDB_TABLE_FNAME_LEN, _OVER) + SDB_SET_BINARY(pRaw, dataPos, pSma->db, TSDB_DB_FNAME_LEN, _OVER) + SDB_SET_INT64(pRaw, dataPos, pSma->createdTime, _OVER) + SDB_SET_INT64(pRaw, dataPos, pSma->uid, _OVER) + SDB_SET_INT64(pRaw, dataPos, pSma->stbUid, _OVER) + SDB_SET_INT64(pRaw, dataPos, pSma->dbUid, _OVER) + SDB_SET_INT8(pRaw, dataPos, pSma->intervalUnit, _OVER) + SDB_SET_INT8(pRaw, dataPos, pSma->slidingUnit, _OVER) + SDB_SET_INT8(pRaw, dataPos, pSma->timezone, _OVER) + SDB_SET_INT64(pRaw, dataPos, pSma->interval, _OVER) + SDB_SET_INT64(pRaw, dataPos, pSma->offset, _OVER) + SDB_SET_INT64(pRaw, dataPos, pSma->sliding, _OVER) + SDB_SET_INT32(pRaw, dataPos, pSma->exprLen, _OVER) + SDB_SET_INT32(pRaw, dataPos, pSma->tagsFilterLen, _OVER) + SDB_SET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER) + SDB_SET_BINARY(pRaw, dataPos, pSma->tagsFilter, pSma->tagsFilterLen, _OVER) + + SDB_SET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER) + SDB_SET_DATALEN(pRaw, dataPos, _OVER) + + terrno = 0; + +_OVER: + if (terrno != 0) { + mError("sma:%s, failed to encode to raw:%p since %s", pSma->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("sma:%s, encode to raw:%p, row:%p", pSma->name, pRaw, pSma); + return pRaw; +} + +static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER; + + if (sver != TSDB_SMA_VER_NUMBER) { + terrno = TSDB_CODE_SDB_INVALID_DATA_VER; + goto _OVER; + } + + SSdbRow *pRow = sdbAllocRow(sizeof(SSmaObj)); + if (pRow == NULL) goto _OVER; + + SSmaObj *pSma = sdbGetRowObj(pRow); + if (pSma == NULL) goto _OVER; + + int32_t dataPos = 0; + + SDB_GET_BINARY(pRaw, dataPos, pSma->name, TSDB_TABLE_FNAME_LEN, _OVER) + SDB_GET_BINARY(pRaw, dataPos, pSma->stb, TSDB_TABLE_FNAME_LEN, _OVER) + SDB_GET_BINARY(pRaw, dataPos, pSma->db, TSDB_DB_FNAME_LEN, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pSma->createdTime, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pSma->uid, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pSma->stbUid, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pSma->dbUid, _OVER) + SDB_GET_INT8(pRaw, dataPos, &pSma->intervalUnit, _OVER) + SDB_GET_INT8(pRaw, dataPos, &pSma->slidingUnit, _OVER) + SDB_GET_INT8(pRaw, dataPos, &pSma->timezone, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pSma->interval, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pSma->offset, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pSma->sliding, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pSma->exprLen, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pSma->tagsFilterLen, _OVER) + + pSma->expr = calloc(pSma->exprLen, 1); + pSma->tagsFilter = calloc(pSma->tagsFilterLen, 1); + if (pSma->expr == NULL || pSma->tagsFilter == NULL) { + goto _OVER; + } + + SDB_GET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER) + SDB_GET_BINARY(pRaw, dataPos, pSma->tagsFilter, pSma->tagsFilterLen, _OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER) + + terrno = 0; + +_OVER: + if (terrno != 0) { + mError("sma:%s, failed to decode from raw:%p since %s", pSma->name, pRaw, terrstr()); + tfree(pSma->expr); + tfree(pSma->tagsFilter); + tfree(pRow); + return NULL; + } + + mTrace("sma:%s, decode from raw:%p, row:%p", pSma->name, pRaw, pSma); + return pRow; +} + +static int32_t mndSmaActionInsert(SSdb *pSdb, SSmaObj *pSma) { + mTrace("sma:%s, perform insert action, row:%p", pSma->name, pSma); + return 0; +} + +static int32_t mndSmaActionDelete(SSdb *pSdb, SSmaObj *pSma) { + mTrace("sma:%s, perform delete action, row:%p", pSma->name, pSma); + tfree(pSma->tagsFilter); + tfree(pSma->expr); + return 0; +} + +static int32_t mndSmaActionUpdate(SSdb *pSdb, SSmaObj *pOld, SSmaObj *pNew) { + mTrace("sma:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew); + return 0; +} + +SSmaObj *mndAcquireSma(SMnode *pMnode, char *smaName) { + SSdb *pSdb = pMnode->pSdb; + SSmaObj *pSma = sdbAcquire(pSdb, SDB_SMA, smaName); + if (pSma == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { + terrno = TSDB_CODE_MND_SMA_NOT_EXIST; + } + return pSma; +} + +void mndReleaseSma(SMnode *pMnode, SSmaObj *pSma) { + SSdb *pSdb = pMnode->pSdb; + sdbRelease(pSdb, pSma); +} + +SDbObj *mndAcquireDbBySma(SMnode *pMnode, const char *smaName) { + SName name = {0}; + tNameFromString(&name, smaName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + + char db[TSDB_TABLE_FNAME_LEN] = {0}; + tNameGetFullDbName(&name, db); + + return mndAcquireDb(pMnode, db); +} + +static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSma, int32_t *pContLen) { + SName name = {0}; + tNameFromString(&name, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + + SVCreateTSmaReq req = {0}; + req.tSma.version = 0; + req.tSma.intervalUnit = pSma->intervalUnit; + req.tSma.slidingUnit = pSma->slidingUnit; + req.tSma.slidingUnit = pSma->timezone; + tstrncpy(req.tSma.indexName, (char *)tNameGetTableName(&name), TSDB_INDEX_NAME_LEN); + req.tSma.exprLen = pSma->exprLen; + req.tSma.tagsFilterLen = pSma->tagsFilterLen; + req.tSma.indexUid = pSma->uid; + req.tSma.tableUid = pSma->stbUid; + req.tSma.interval = pSma->interval; + req.tSma.offset = pSma->offset; + req.tSma.sliding = pSma->sliding; + req.tSma.expr = pSma->expr; + req.tSma.tagsFilter = pSma->tagsFilter; + + int32_t contLen = tSerializeSVCreateTSmaReq(NULL, &req) + sizeof(SMsgHead); + SMsgHead *pHead = malloc(contLen); + if (pHead == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pHead->contLen = htonl(contLen); + pHead->vgId = htonl(pVgroup->vgId); + + void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead)); + tSerializeSVCreateTSmaReq(&pBuf, &req); + + *pContLen = contLen; + return pHead; +} + +static void *mndBuildVDropSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSma, int32_t *pContLen) { + SName name = {0}; + tNameFromString(&name, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + + SVDropTSmaReq req = {0}; + req.ver = 0; + req.indexUid = pSma->uid; + tstrncpy(req.indexName, (char *)tNameGetTableName(&name), TSDB_INDEX_NAME_LEN); + + int32_t contLen = tSerializeSVDropTSmaReq(NULL, &req) + sizeof(SMsgHead); + SMsgHead *pHead = malloc(contLen); + if (pHead == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pHead->contLen = htonl(contLen); + pHead->vgId = htonl(pVgroup->vgId); + + void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead)); + tDeserializeSVDropTSmaReq(&pBuf, &req); + + *pContLen = contLen; + return pHead; +} + +static int32_t mndSetCreateSmaRedoLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + SSdbRaw *pRedoRaw = mndSmaActionEncode(pSma); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1; + + return 0; +} + +static int32_t mndSetCreateSmaUndoLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + SSdbRaw *pUndoRaw = mndSmaActionEncode(pSma); + if (pUndoRaw == NULL) return -1; + if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; + if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; + + return 0; +} + +static int32_t mndSetCreateSmaCommitLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + SSdbRaw *pCommitRaw = mndSmaActionEncode(pSma); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + + return 0; +} + +static int32_t mndSetCreateSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SSmaObj *pSma) { + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + int32_t contLen; + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + if (pVgroup->dbUid != pDb->uid) { + sdbRelease(pSdb, pVgroup); + continue; + } + + void *pReq = mndBuildVCreateSmaReq(pMnode, pVgroup, pSma, &contLen); + if (pReq == NULL) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + STransAction action = {0}; + action.epSet = mndGetVgroupEpset(pMnode, pVgroup); + action.pCont = pReq; + action.contLen = contLen; + action.msgType = TDMT_VND_CREATE_SMA; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pReq); + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + sdbRelease(pSdb, pVgroup); + } + + return 0; +} + +static int32_t mndSetCreateSmaUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SSmaObj *pSma) { + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + if (pVgroup->dbUid != pDb->uid) { + sdbRelease(pSdb, pVgroup); + continue; + } + + int32_t contLen = 0; + void *pReq = mndBuildVDropSmaReq(pMnode, pVgroup, pSma, &contLen); + if (pReq == NULL) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + STransAction action = {0}; + action.epSet = mndGetVgroupEpset(pMnode, pVgroup); + action.pCont = pReq; + action.contLen = contLen; + action.msgType = TDMT_VND_DROP_SMA; + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + free(pReq); + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + sdbRelease(pSdb, pVgroup); + } + + return 0; +} + +static int32_t mndCreateTSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCreate, SDbObj *pDb, SStbObj *pStb) { + SSmaObj smaObj = {0}; + memcpy(smaObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN); + memcpy(smaObj.stb, pStb->name, TSDB_TABLE_FNAME_LEN); + smaObj.createdTime = taosGetTimestampMs(); + smaObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN); + smaObj.stbUid = pStb->uid; + smaObj.intervalUnit = pCreate->intervalUnit; + smaObj.slidingUnit = pCreate->slidingUnit; + smaObj.timezone = pCreate->timezone; + smaObj.interval = pCreate->interval; + smaObj.offset = pCreate->offset; + smaObj.sliding = pCreate->sliding; + smaObj.exprLen = pCreate->exprLen; + smaObj.tagsFilterLen = pCreate->tagsFilterLen; + smaObj.expr = pCreate->expr; + pCreate->expr = NULL; + smaObj.tagsFilter = pCreate->tagsFilter; + pCreate->tagsFilter = NULL; + + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_SMA, &pReq->rpcMsg); + if (pTrans == NULL) goto _OVER; + + mDebug("trans:%d, used to create sma:%s", pTrans->id, pCreate->name); + mndTransSetDbInfo(pTrans, pDb); + + if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; + if (mndSetCreateSmaUndoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; + if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; + if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; + if (mndSetCreateSmaUndoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + + code = 0; + +_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndCheckCreateSmaReq(SMCreateSmaReq *pCreate) { + if (pCreate->igExists < 0 || pCreate->igExists > 1) { + terrno = TSDB_CODE_MND_INVALID_STB_OPTION; + return -1; + } + + return 0; +} + +static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) { + SMnode *pMnode = pReq->pNode; + int32_t code = -1; + SStbObj *pStb = NULL; + SSmaObj *pSma = NULL; + SDbObj *pDb = NULL; + SUserObj *pUser = NULL; + SMCreateSmaReq createReq = {0}; + + if (tDeserializeSMCreateSmaReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto _OVER; + } + + mDebug("sma:%s, start to create", createReq.name); + if (mndCheckCreateSmaReq(&createReq) != 0) { + goto _OVER; + } + + pStb = mndAcquireStb(pMnode, createReq.stb); + if (pStb == NULL) { + mError("sma:%s, failed to create since stb:%s not exist", createReq.name, createReq.stb); + goto _OVER; + } + + pSma = mndAcquireSma(pMnode, createReq.name); + if (pSma != NULL) { + if (createReq.igExists) { + mDebug("sma:%s, already exist in sma:%s, ignore exist is set", createReq.name, pSma->name); + code = 0; + goto _OVER; + } else { + terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST; + goto _OVER; + } + } + + pDb = mndAcquireDbBySma(pMnode, createReq.name); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + goto _OVER; + } + + pUser = mndAcquireUser(pMnode, pReq->user); + if (pUser == NULL) { + goto _OVER; + } + + if (mndCheckWriteAuth(pUser, pDb) != 0) { + goto _OVER; + } + + code = mndCreateTSma(pMnode, pReq, &createReq, pDb, pStb); + if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; + +_OVER: + if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + mError("sma:%s, failed to create since %s", createReq.name, terrstr()); + } + + mndReleaseStb(pMnode, pStb); + mndReleaseSma(pMnode, pSma); + mndReleaseDb(pMnode, pDb); + mndReleaseUser(pMnode, pUser); + tFreeSMCreateSmaReq(&createReq); + + return code; +} + +static int32_t mndProcessVCreateSmaRsp(SNodeMsg *pRsp) { + mndTransProcessRsp(pRsp); + return 0; +} + +static int32_t mndSetDropSmaRedoLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + SSdbRaw *pRedoRaw = mndSmaActionEncode(pSma); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1; + + return 0; +} + +static int32_t mndSetDropSmaCommitLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { + SSdbRaw *pCommitRaw = mndSmaActionEncode(pSma); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + + return 0; +} + +static int32_t mndSetDropSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SSmaObj *pSma) { + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + int32_t contLen; + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + if (pVgroup->dbUid != pDb->uid) { + sdbRelease(pSdb, pVgroup); + continue; + } + + int32_t contLen = 0; + void *pReq = mndBuildVDropSmaReq(pMnode, pVgroup, pSma, &contLen); + if (pReq == NULL) { + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + STransAction action = {0}; + action.epSet = mndGetVgroupEpset(pMnode, pVgroup); + action.pCont = pReq; + action.contLen = contLen; + action.msgType = TDMT_VND_DROP_SMA; + action.acceptableCode = TSDB_CODE_VND_TB_NOT_EXIST; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + free(pReq); + sdbCancelFetch(pSdb, pIter); + sdbRelease(pSdb, pVgroup); + return -1; + } + sdbRelease(pSdb, pVgroup); + } + + return 0; +} + +static int32_t mndDropSma(SMnode *pMnode, SNodeMsg *pReq, SDbObj *pDb, SSmaObj *pSma) { + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_STB, &pReq->rpcMsg); + if (pTrans == NULL) goto _OVER; + + mDebug("trans:%d, used to drop sma:%s", pTrans->id, pSma->name); + mndTransSetDbInfo(pTrans, pDb); + + if (mndSetDropSmaRedoLogs(pMnode, pTrans, pSma) != 0) goto _OVER; + if (mndSetDropSmaCommitLogs(pMnode, pTrans, pSma) != 0) goto _OVER; + if (mndSetDropSmaRedoActions(pMnode, pTrans, pDb, pSma) != 0) goto _OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + + code = 0; + +_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessMDropSmaReq(SNodeMsg *pReq) { + SMnode *pMnode = pReq->pNode; + int32_t code = -1; + SUserObj *pUser = NULL; + SDbObj *pDb = NULL; + SSmaObj *pSma = NULL; + SMDropSmaReq dropReq = {0}; + + if (tDeserializeSMDropSmaReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto _OVER; + } + + mDebug("sma:%s, start to drop", dropReq.name); + + pSma = mndAcquireSma(pMnode, dropReq.name); + if (pSma == NULL) { + if (dropReq.igNotExists) { + mDebug("sma:%s, not exist, ignore not exist is set", dropReq.name); + code = 0; + goto _OVER; + } else { + terrno = TSDB_CODE_MND_SMA_NOT_EXIST; + goto _OVER; + } + } + + pDb = mndAcquireDbBySma(pMnode, dropReq.name); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + goto _OVER; + } + + pUser = mndAcquireUser(pMnode, pReq->user); + if (pUser == NULL) { + goto _OVER; + } + + if (mndCheckWriteAuth(pUser, pDb) != 0) { + goto _OVER; + } + + code = mndDropSma(pMnode, pReq, pDb, pSma); + if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; + +_OVER: + if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + mError("sma:%s, failed to drop since %s", dropReq.name, terrstr()); + } + + mndReleaseDb(pMnode, pDb); + mndReleaseSma(pMnode, pSma); + mndReleaseUser(pMnode, pUser); + + return code; +} + +static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp) { + mndTransProcessRsp(pRsp); + return 0; +} + +static int32_t mndGetSmaMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { + SMnode *pMnode = pReq->pNode; + SSdb *pSdb = pMnode->pSdb; + + int32_t cols = 0; + SSchema *pSchema = pMeta->pSchemas; + + pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "name"); + pSchema[cols].bytes = pShow->bytes[cols]; + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "create_time"); + pSchema[cols].bytes = pShow->bytes[cols]; + cols++; + + pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "name"); + pSchema[cols].bytes = pShow->bytes[cols]; + cols++; + + pMeta->numOfColumns = cols; + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } + + pShow->numOfRows = sdbGetSize(pSdb, SDB_SMA); + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbName, mndShowStr(pShow->type)); + + return 0; +} + +static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pNode; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + SSmaObj *pSma = NULL; + int32_t cols = 0; + char *pWrite; + char prefix[TSDB_DB_FNAME_LEN] = {0}; + + SDbObj *pDb = mndAcquireDb(pMnode, pShow->db); + if (pDb == NULL) return 0; + + while (numOfRows < rows) { + pShow->pIter = sdbFetch(pSdb, SDB_SMA, pShow->pIter, (void **)&pSma); + if (pShow->pIter == NULL) break; + + if (pSma->dbUid != pDb->uid) { + sdbRelease(pSdb, pSma); + continue; + } + + cols = 0; + + SName smaName = {0}; + tNameFromString(&smaName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_TO_VARSTR(pWrite, (char *)tNameGetTableName(&smaName)); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pSma->createdTime; + cols++; + + SName stbName = {0}; + tNameFromString(&stbName, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_TO_VARSTR(pWrite, (char *)tNameGetTableName(&stbName)); + cols++; + + numOfRows++; + sdbRelease(pSdb, pSma); + } + + mndReleaseDb(pMnode, pDb); + pShow->numOfReads += numOfRows; + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + return numOfRows; +} + +static void mndCancelGetNextSma(SMnode *pMnode, void *pIter) { + SSdb *pSdb = pMnode->pSdb; + sdbCancelFetch(pSdb, pIter); +} diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 99b7154c3f..6bf0b383ef 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -13,7 +13,6 @@ * along with this program. If not, see . */ -#define _DEFAULT_SOURCE #include "mndStb.h" #include "mndAuth.h" #include "mndDb.h" From 867ca85ab1bd4d706d687a140e68a762f9757275 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 23 Mar 2022 16:51:43 +0800 Subject: [PATCH 47/68] reset buf --- include/common/trow.h | 3 ++ source/common/src/tdataformat.c | 2 ++ source/common/src/trow.c | 52 ++++++++++++++++++++++++++++----- tests/script/jenkins/basic.txt | 2 +- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/include/common/trow.h b/include/common/trow.h index 4ae5a2277d..fc99cbc5b2 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -166,6 +166,7 @@ typedef struct { #define TD_ROW_HEAD_LEN (sizeof(STSRow)) #define TD_ROW_NCOLS_LEN (sizeof(col_id_t)) +#define TD_ROW_INFO(r) ((r)->info) #define TD_ROW_TYPE(r) ((r)->type) #define TD_ROW_DELETE(r) ((r)->del) #define TD_ROW_ENDIAN(r) ((r)->endian) @@ -180,6 +181,7 @@ typedef struct { // (int32_t)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined. #define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) (schemaTLen(s) + TD_ROW_HEAD_LEN) +#define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i)) #define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t)) #define TD_ROW_SET_DELETE(r) (TD_ROW_DELETE(r) = 1) #define TD_ROW_SET_SVER(r, v) (TD_ROW_SVER(r) = (v)) @@ -473,6 +475,7 @@ static int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { return terrno; } + TD_ROW_SET_INFO(pBuilder->pBuf, 0); TD_ROW_SET_TYPE(pBuilder->pBuf, pBuilder->rowType); uint32_t len = 0; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 87e3cf0c24..ed5441fe99 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -421,6 +421,7 @@ SDataCols *tdFreeDataCols(SDataCols *pCols) { return NULL; } +#if 0 SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) { SDataCols *pRet = tdNewDataCols(pDataCols->maxCols, pDataCols->maxPoints); if (pRet == NULL) return NULL; @@ -454,6 +455,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) { return pRet; } +#endif void tdResetDataCols(SDataCols *pCols) { if (pCols != NULL) { diff --git a/source/common/src/trow.c b/source/common/src/trow.c index db4bc49425..48a63799f5 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -78,7 +78,7 @@ static FORCE_INLINE void dataColSetNoneAt(SDataCol *pCol, int index, bool setBit setNull(POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * index), pCol->type, pCol->bytes); pCol->len += TYPE_BYTES[pCol->type]; } - if(setBitmap) { + if (setBitmap) { tdSetBitmapValType(pCol->pBitmap, index, TD_VTYPE_NONE); } } @@ -118,8 +118,8 @@ int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) { #endif -STSRow* tdRowDup(STSRow *row) { - STSRow* trow = malloc(TD_ROW_LEN(row)); +STSRow *tdRowDup(STSRow *row) { + STSRow *trow = malloc(TD_ROW_LEN(row)); if (trow == NULL) return NULL; tdRowCpy(trow, row); @@ -176,7 +176,7 @@ static int32_t tdAppendTpRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols SDataCol *pDataCol = &(pCols->cols[0]); if (pDataCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { - tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints); + tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints); } while (dcol < pCols->numOfCols) { @@ -378,9 +378,7 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i } } - - -STSRow* mergeTwoRows(void *buffer, STSRow* row1, STSRow *row2, STSchema *pSchema1, STSchema *pSchema2) { +STSRow *mergeTwoRows(void *buffer, STSRow *row1, STSRow *row2, STSchema *pSchema1, STSchema *pSchema2) { #if 0 ASSERT(TD_ROW_KEY(row1) == TD_ROW_KEY(row2)); ASSERT(schemaVersion(pSchema1) == TD_ROW_SVER(row1)); @@ -473,6 +471,44 @@ STSRow* mergeTwoRows(void *buffer, STSRow* row1, STSRow *row2, STSchema *pSchema } taosArrayDestroy(stashRow); return buffer; - #endif +#endif return NULL; } + +SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) { + SDataCols *pRet = tdNewDataCols(pDataCols->maxCols, pDataCols->maxPoints); + if (pRet == NULL) return NULL; + + pRet->numOfCols = pDataCols->numOfCols; + pRet->sversion = pDataCols->sversion; + if (keepData) pRet->numOfRows = pDataCols->numOfRows; + + for (int i = 0; i < pDataCols->numOfCols; i++) { + pRet->cols[i].type = pDataCols->cols[i].type; + pRet->cols[i].bitmap = pDataCols->cols[i].bitmap; + pRet->cols[i].colId = pDataCols->cols[i].colId; + pRet->cols[i].bytes = pDataCols->cols[i].bytes; + pRet->cols[i].offset = pDataCols->cols[i].offset; + + if (keepData) { + if (pDataCols->cols[i].len > 0) { + if (tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints) < 0) { + tdFreeDataCols(pRet); + return NULL; + } + pRet->cols[i].len = pDataCols->cols[i].len; + memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len); + if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) { + int dataOffSize = sizeof(VarDataOffsetT) * pDataCols->maxPoints; + memcpy(pRet->cols[i].dataOff, pDataCols->cols[i].dataOff, dataOffSize); + } + if (!TD_COL_ROWS_NORM(pRet->cols + i)) { + int32_t nBitmapBytes = (int32_t)TD_BITMAP_BYTES(pDataCols->maxPoints); + memcpy(pRet->cols[i].pBitmap, pDataCols->cols[i].pBitmap, nBitmapBytes); + } + } + } + } + + return pRet; +} \ No newline at end of file diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 821789de0a..cc0576e1f3 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -17,7 +17,7 @@ ./test.sh -f tsim/dnode/basic1.sim # ---- insert -#./test.sh -f tsim/insert/basic0.sim +./test.sh -f tsim/insert/basic0.sim # ---- query ./test.sh -f tsim/query/interval.sim From c419d03b5f141d7693df7889fd4f882e6ac02bfd Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 23 Mar 2022 16:54:10 +0800 Subject: [PATCH 48/68] [modify] --- tests/script/tsim/insert/basic0.sim | 266 +++++++++++++++++++--------- 1 file changed, 183 insertions(+), 83 deletions(-) diff --git a/tests/script/tsim/insert/basic0.sim b/tests/script/tsim/insert/basic0.sim index 8592624cf3..fa4c210ad4 100644 --- a/tests/script/tsim/insert/basic0.sim +++ b/tests/script/tsim/insert/basic0.sim @@ -36,14 +36,14 @@ endi print =============== insert data, mode1: one row one table in sql print =============== insert data, mode1: mulit rows one table in sql -print =============== insert data, mode1: one rows mulit table in sql -print =============== insert data, mode1: mulit rows mulit table in sql +#print =============== insert data, mode1: one rows mulit table in sql +#print =============== insert data, mode1: mulit rows mulit table in sql sql insert into ct1 values(now+0s, 10, 2.0, 3.0) -sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, 12, 2.2, 3.2)(now+3s, 13, 2.3, 3.3) +sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) sql insert into ct2 values(now+0s, 10, 2.0, 3.0) -sql insert into ct2 values(now+1s, 11, 2.1, 3.1)(now+2s, 12, 2.2, 3.2)(now+3s, 13, 2.3, 3.3) -sql insert into ct1 values(now+4s, -14, -2.4, -3.4) ct2 values(now+4s, -14, -2.4, -3.4) -sql insert into ct1 values(now+5s, -15, -2.5, -3.5)(now+6s, -16, -2.6, -3.6) ct2 values(now+5s, -15, -2.5, -3.5)(now+6s, -16, -2.6, -3.6) +sql insert into ct2 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) +#sql insert into ct1 values(now+4s, -14, -2.4, -3.4) ct2 values(now+4s, -14, -2.4, -3.4) +#sql insert into ct1 values(now+5s, -15, -2.5, -3.5)(now+6s, -16, -2.6, -3.6) ct2 values(now+5s, -15, -2.5, -3.5)(now+6s, -16, -2.6, -3.6) sql insert into ct3 values('2021-01-01 00:00:00.000', 10, 2.0, 3.0) @@ -52,14 +52,11 @@ sql insert into ct3 values('2021-01-01 00:00:00.000', 10, 2.0, 3.0) print =============== query data from child table sql select * from ct1 print rows: $rows -print $data00 $data01 -print $data10 $data11 -print $data20 $data21 -print $data30 $data31 -print $data40 $data41 -print $data50 $data51 -print $data60 $data61 -if $rows != 7 then +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +print $data20 $data21 $data22 $data23 +print $data30 $data31 $data32 $data33 +if $rows != 4 then return -1 endi if $data01 != 10 then @@ -84,28 +81,29 @@ endi print =============== select count(*) from child table sql select count(*) from ct1 +print rows: $rows +print $data00 $data01 $data02 $data03 if $rows != 1 then return -1 endi - -print $data00 $data01 $data02 -if $data00 != 7 then +if $data00 != 4 then return -1 endi print =============== select count(column) from child table sql select count(ts), count(c1), count(c2), count(c3) from ct1 -print $data00 $data01 $data02 $data03 -if $data00 != 7 then +print rows: $rows +print $data00 $data01 $data02 $data03 +if $data00 != 4 then return -1 endi -if $data01 != 7 then +if $data01 != 4 then return -1 endi -if $data02 != 7 then +if $data02 != 4 then return -1 endi -if $data03 != 7 then +if $data03 != 4 then return -1 endi @@ -115,17 +113,18 @@ endi print =============== select min(column) from child table sql select min(c1), min(c2), min(c3) from ct1 -print $data00 $data01 $data02 $data03 +print rows: $rows +print $data00 $data01 $data02 $data03 if $rows != 1 then return -1 endi -if $data00 != -16 then +if $data00 != -13 then return -1 endi -if $data01 != -2.60000 then +if $data01 != -2.30000 then return -1 endi -if $data02 != -3.600000000 then +if $data02 != -3.300000000 then return -1 endi @@ -135,13 +134,13 @@ print $data00 $data01 $data02 $data03 if $rows != 1 then return -1 endi -if $data00 != 13 then +if $data00 != 11 then return -1 endi -if $data01 != 2.30000 then +if $data01 != 2.10000 then return -1 endi -if $data02 != 3.300000000 then +if $data02 != 3.100000000 then return -1 endi @@ -151,49 +150,53 @@ print $data00 $data01 $data02 $data03 if $rows != 1 then return -1 endi -if $data00 != 1 then +if $data00 != -4 then return -1 endi -if $data01 != 1.099999905 then +if $data01 != -0.400000095 then return -1 endi -if $data02 != 2.100000000 then +if $data02 != -0.400000000 then return -1 endi -print =============== select column, from child table +print =============== select column without timestamp, from child table sql select c1, c2, c3 from ct1 +print rows: $rows print $data00 $data01 $data02 -#if $rows != 4 then -# return -1 -#endi -#if $data00 != 10 then -# return -1 -#endi -#if $data01 != 2.00000 then -# return -1 -#endi -#if $data02 != 3.000000000 then -# return -1 -#endi -#if $data10 != 11 then -# return -1 -#endi -#if $data11 != 2.10000 then -# return -1 -#endi -#if $data12 != 3.100000000 then -# return -1 -#endi -#if $data30 != 13 then -# return -1 -#endi -#if $data31 != 2.30000 then -# return -1 -#endi -#if $data32 != 3.300000000 then -# return -1 -#endi +print $data10 $data11 $data12 +print $data20 $data21 $data22 +print $data30 $data31 $data32 +if $rows != 4 then + return -1 +endi +if $data00 != 10 then + return -1 +endi +if $data01 != 2.00000 then + return -1 +endi +if $data02 != 3.000000000 then + return -1 +endi +if $data10 != 11 then + return -1 +endi +if $data11 != 2.10000 then + return -1 +endi +if $data12 != 3.100000000 then + return -1 +endi +if $data30 != -13 then + return -1 +endi +if $data31 != -2.30000 then + return -1 +endi +if $data32 != -3.300000000 then + return -1 +endi #=================================================================== #=================================================================== @@ -237,9 +240,31 @@ print =============== stop and restart taosd, then again do query above system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start -sleep 2000 +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +print =============== query data from child table sql select * from ct1 -if $rows != 7 then +print rows: $rows +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +print $data20 $data21 $data22 $data23 +print $data30 $data31 $data32 $data33 +if $rows != 4 then return -1 endi if $data01 != 10 then @@ -264,28 +289,29 @@ endi print =============== select count(*) from child table sql select count(*) from ct1 +print rows: $rows +print $data00 $data01 $data02 $data03 if $rows != 1 then return -1 endi - -print $data00 $data01 $data02 -if $data00 != 7 then +if $data00 != 4 then return -1 endi print =============== select count(column) from child table sql select count(ts), count(c1), count(c2), count(c3) from ct1 -print $data00 $data01 $data02 $data03 -if $data00 != 7 then +print rows: $rows +print $data00 $data01 $data02 $data03 +if $data00 != 4 then return -1 endi -if $data01 != 7 then +if $data01 != 4 then return -1 endi -if $data02 != 7 then +if $data02 != 4 then return -1 endi -if $data03 != 7 then +if $data03 != 4 then return -1 endi @@ -295,17 +321,18 @@ endi print =============== select min(column) from child table sql select min(c1), min(c2), min(c3) from ct1 -print $data00 $data01 $data02 $data03 +print rows: $rows +print $data00 $data01 $data02 $data03 if $rows != 1 then return -1 endi -if $data00 != -16 then +if $data00 != -13 then return -1 endi -if $data01 != -2.60000 then +if $data01 != -2.30000 then return -1 endi -if $data02 != -3.600000000 then +if $data02 != -3.300000000 then return -1 endi @@ -315,13 +342,13 @@ print $data00 $data01 $data02 $data03 if $rows != 1 then return -1 endi -if $data00 != 13 then +if $data00 != 11 then return -1 endi -if $data01 != 2.30000 then +if $data01 != 2.10000 then return -1 endi -if $data02 != 3.300000000 then +if $data02 != 3.100000000 then return -1 endi @@ -331,14 +358,87 @@ print $data00 $data01 $data02 $data03 if $rows != 1 then return -1 endi -if $data00 != 1 then +if $data00 != -4 then return -1 endi -if $data01 != 1.099999905 then +if $data01 != -0.400000095 then return -1 endi -if $data02 != 2.100000000 then +if $data02 != -0.400000000 then return -1 endi +print =============== select column without timestamp, from child table +sql select c1, c2, c3 from ct1 +print rows: $rows +print $data00 $data01 $data02 +print $data10 $data11 $data12 +print $data20 $data21 $data22 +print $data30 $data31 $data32 +if $rows != 4 then + return -1 +endi +if $data00 != 10 then + return -1 +endi +if $data01 != 2.00000 then + return -1 +endi +if $data02 != 3.000000000 then + return -1 +endi +if $data10 != 11 then + return -1 +endi +if $data11 != 2.10000 then + return -1 +endi +if $data12 != 3.100000000 then + return -1 +endi +if $data30 != -13 then + return -1 +endi +if $data31 != -2.30000 then + return -1 +endi +if $data32 != -3.300000000 then + return -1 +endi +#=================================================================== +#=================================================================== + +#print =============== query data from stb +#sql select * from stb +#if $rows != 4 then +# return -1 +#endi +#print =============== select count(*) from supter table +#sql select count(*) from stb +#if $rows != 1 then +# return -1 +#endi +# +#print $data00 $data01 $data02 +#if $data00 != 8 then +# return -1 +#endi +# +#print =============== select count(column) from supter table +#sql select count(ts), count(c1), count(c2), count(c3) from stb +#print $data00 $data01 $data02 $data03 +#if $data00 != 8 then +# return -1 +#endi +#if $data01 != 8 then +# return -1 +#endi +#if $data02 != 8 then +# return -1 +#endi +#if $data03 != 8 then +# return -1 +#endi + + #system sh/exec.sh -n dnode1 -s stop -x SIGINT From 58122d07d7efd39035a1789b715879078b1d835e Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 23 Mar 2022 17:00:21 +0800 Subject: [PATCH 49/68] add stream trigger --- example/src/tstream.c | 3 +- include/common/tmsgdef.h | 1 + source/common/src/tmsg.c | 8 +- source/dnode/mgmt/vnode/src/vmMsg.c | 1 + source/dnode/mnode/impl/src/mndScheduler.c | 2 +- source/dnode/vnode/src/inc/vnd.h | 3 +- source/dnode/vnode/src/tq/tq.c | 126 ++++++++++++--------- source/dnode/vnode/src/tq/tqRead.c | 45 +++++++- source/dnode/vnode/src/vnd/vnodeQuery.c | 4 +- source/dnode/vnode/src/vnd/vnodeWrite.c | 12 +- source/libs/executor/src/executor.c | 2 +- 11 files changed, 138 insertions(+), 69 deletions(-) diff --git a/example/src/tstream.c b/example/src/tstream.c index 17073e14a6..6976d9e398 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -77,7 +77,8 @@ int32_t create_stream() { } taos_free_result(pRes); - const char* sql = "select sum(k) from tu1"; + /*const char* sql = "select min(k), max(k), sum(k) from tu1";*/ + const char* sql = "select min(k), max(k), sum(k) from st1"; /*const char* sql = "select sum(k) from tu1 interval(10m)";*/ pRes = tmq_create_stream(pConn, "stream1", "out1", sql); if (taos_errno(pRes) != 0) { diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 73a78131dc..ad8a839095 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -191,6 +191,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqCVConsumeReq, SMqCVConsumeRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_DEPLOY, "vnode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_EXEC, "vnode-task-exec", SStreamTaskExecReq, SStreamTaskExecRsp) + TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 41c37cb7f2..b2fb92600b 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2872,7 +2872,7 @@ void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) { } int32_t tEncodeSStreamTask(SCoder *pEncoder, const SStreamTask *pTask) { - if (tStartEncode(pEncoder) < 0) return -1; + /*if (tStartEncode(pEncoder) < 0) return -1;*/ if (tEncodeI64(pEncoder, pTask->streamId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->level) < 0) return -1; @@ -2884,12 +2884,12 @@ int32_t tEncodeSStreamTask(SCoder *pEncoder, const SStreamTask *pTask) { // if (tEncodeI8(pEncoder, pTask->numOfRunners) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->NextOpEp) < 0) return -1; if (tEncodeCStr(pEncoder, pTask->qmsg) < 0) return -1; - tEndEncode(pEncoder); + /*tEndEncode(pEncoder);*/ return pEncoder->pos; } int32_t tDecodeSStreamTask(SCoder *pDecoder, SStreamTask *pTask) { - if (tStartDecode(pDecoder) < 0) return -1; + /*if (tStartDecode(pDecoder) < 0) return -1;*/ if (tDecodeI64(pDecoder, &pTask->streamId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->level) < 0) return -1; @@ -2901,7 +2901,7 @@ int32_t tDecodeSStreamTask(SCoder *pDecoder, SStreamTask *pTask) { // if (tDecodeI8(pDecoder, &pTask->numOfRunners) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->NextOpEp) < 0) return -1; if (tDecodeCStrAlloc(pDecoder, &pTask->qmsg) < 0) return -1; - tEndDecode(pDecoder); + /*tEndDecode(pDecoder);*/ return 0; } diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vnode/src/vmMsg.c index d4af82b382..7bbf730744 100644 --- a/source/dnode/mgmt/vnode/src/vmMsg.c +++ b/source/dnode/mgmt/vnode/src/vmMsg.c @@ -277,6 +277,7 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_EXEC, (NodeMsgFp)vmProcessFetchMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, 0); dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, (NodeMsgFp)vmProcessMgmtMsg, 0); dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, (NodeMsgFp)vmProcessMgmtMsg, 0); diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 3793d10537..8ccfd6be5d 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -117,7 +117,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { int32_t opNum = LIST_LENGTH(inner->pNodeList); ASSERT(opNum == 1); - SSubplan* plan = nodesListGetNode(inner->pNodeList, level); + SSubplan* plan = nodesListGetNode(inner->pNodeList, 0); if (level == 0) { ASSERT(plan->subplanType == SUBPLAN_TYPE_SCAN); void* pIter = NULL; diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 2c9a5368ac..78ff9f1062 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -176,7 +176,7 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pMeta, STqCfg* void tqClose(STQ*); // required by vnode -int tqPushMsg(STQ*, void* msg, tmsg_t msgType, int64_t version); +int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version); int tqCommit(STQ*); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); @@ -184,6 +184,7 @@ int32_t tqProcessSetConnReq(STQ* pTq, char* msg); int32_t tqProcessRebReq(STQ* pTq, char* msg); int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg); int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); +int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen); #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 099f6896b1..25fe963799 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -17,6 +17,8 @@ #include "tqInt.h" #include "tqMetaStore.h" +void tqDebugShowSSData(SArray* dataBlocks); + int32_t tqInit() { return tqPushMgrInit(); } void tqCleanUp() { tqPushMgrCleanUp(); } @@ -70,59 +72,19 @@ void tqClose(STQ* pTq) { // TODO } -int tqPushMsg(STQ* pTq, void* msg, tmsg_t msgType, int64_t version) { +int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version) { if (msgType != TDMT_VND_SUBMIT) return 0; - - void* pIter = NULL; - - while (1) { - pIter = taosHashIterate(pTq->pStreamTasks, pIter); - if (pIter == NULL) break; - SStreamTask* pTask = (SStreamTask*)pIter; - if (!pTask->pipeSource) continue; - - int32_t workerId = 0; - void* exec = pTask->runner[workerId].executor; - qSetStreamInput(exec, msg, STREAM_DATA_TYPE_SUBMIT_BLOCK); - SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); - while (1) { - SSDataBlock* output; - uint64_t ts; - if (qExecTask(exec, &output, &ts) < 0) { - ASSERT(false); - } - if (output == NULL) { - break; - } - taosArrayPush(pRes, output); - } - if (pTask->pipeSink) { - // write back - } else { - int32_t tlen = sizeof(SStreamExecMsgHead) + tEncodeDataBlocks(NULL, pRes); - void* buf = rpcMallocCont(tlen); - if (buf == NULL) { - return -1; - } - void* abuf = POINTER_SHIFT(buf, sizeof(SStreamExecMsgHead)); - tEncodeDataBlocks(abuf, pRes); - tmsg_t type; - - if (pTask->nextOpDst == STREAM_NEXT_OP_DST__VND) { - type = TDMT_VND_TASK_EXEC; - } else { - type = TDMT_SND_TASK_EXEC; - } - - SRpcMsg msg = { - .pCont = buf, - .contLen = tlen, - .code = 0, - .msgType = type, - }; - tmsgSendReq(&pTq->pVnode->msgCb, &pTask->NextOpEp, &msg); - } + void* data = malloc(msgLen); + if (data == NULL) { + return -1; } + memcpy(data, msg, msgLen); + SRpcMsg req = { + .msgType = TDMT_VND_STREAM_TRIGGER, + .pCont = data, + .contLen = msgLen, + }; + tmsgPutToQueue(&pTq->pVnode->msgCb, FETCH_QUEUE, &req); #if 0 void* pIter = taosHashIterate(pTq->tqPushMgr->pHash, NULL); @@ -577,7 +539,11 @@ void tqDebugShowSSData(SArray* dataBlocks) { break; case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_UINT: - printf(" %15u |", *(uint32_t*)var); + printf(" %15d |", *(int32_t*)var); + break; + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + printf(" %15ld |", *(int64_t*)var); break; } } @@ -586,6 +552,62 @@ void tqDebugShowSSData(SArray* dataBlocks) { } } +int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) { + void* pIter = NULL; + + while (1) { + pIter = taosHashIterate(pTq->pStreamTasks, pIter); + if (pIter == NULL) break; + SStreamTask* pTask = (SStreamTask*)pIter; + if (!pTask->pipeSource) continue; + + int32_t workerId = 0; + void* exec = pTask->runner[workerId].executor; + qSetStreamInput(exec, data, STREAM_DATA_TYPE_SUBMIT_BLOCK); + SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); + while (1) { + SSDataBlock* output; + uint64_t ts; + if (qExecTask(exec, &output, &ts) < 0) { + ASSERT(false); + } + if (output == NULL) { + break; + } + taosArrayPush(pRes, output); + } + if (pTask->pipeSink) { + // write back + /*printf("reach end\n");*/ + tqDebugShowSSData(pRes); + } else { + int32_t tlen = sizeof(SStreamExecMsgHead) + tEncodeDataBlocks(NULL, pRes); + void* buf = rpcMallocCont(tlen); + if (buf == NULL) { + return -1; + } + void* abuf = POINTER_SHIFT(buf, sizeof(SStreamExecMsgHead)); + tEncodeDataBlocks(abuf, pRes); + tmsg_t type; + + if (pTask->nextOpDst == STREAM_NEXT_OP_DST__VND) { + type = TDMT_VND_TASK_EXEC; + } else { + type = TDMT_SND_TASK_EXEC; + } + + SRpcMsg reqMsg = { + .pCont = buf, + .contLen = tlen, + .code = 0, + .msgType = type, + }; + tmsgSendReq(&pTq->pVnode->msgCb, &pTask->NextOpEp, &reqMsg); + } + } + return 0; +} + int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg) { SStreamTaskExecReq* pReq = msg->pCont; diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 0c4b933c19..8c58b5ce07 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -126,6 +126,36 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { if (pArray == NULL) { return NULL; } + int32_t colMeta = 0; + int32_t colNeed = 0; + while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) { + SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta]; + int16_t colIdSchema = pColSchema->colId; + int16_t colIdNeed = *(int16_t*)taosArrayGet(pHandle->pColIdList, colNeed); + if (colIdSchema < colIdNeed) { + colMeta++; + } else if (colIdSchema > colIdNeed) { + colNeed++; + } else { + SColumnInfoData colInfo = {0}; + int sz = numOfRows * pColSchema->bytes; + colInfo.info.bytes = pColSchema->bytes; + colInfo.info.colId = pColSchema->colId; + colInfo.info.type = pColSchema->type; + + colInfo.pData = calloc(1, sz); + if (colInfo.pData == NULL) { + // TODO free + taosArrayDestroy(pArray); + return NULL; + } + + blockDataEnsureColumnCapacity(&colInfo, numOfRows); + taosArrayPush(pArray, &colInfo); + colMeta++; + colNeed++; + } + } int j = 0; for (int32_t i = 0; i < colNumNeed; i++) { @@ -163,11 +193,23 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) { tdSTSRowIterReset(&iter, row); // get all wanted col of that block + int32_t colTot = taosArrayGetSize(pArray); + for (int32_t i = 0; i < colTot; i++) { + SColumnInfoData* pColData = taosArrayGet(pArray, i); + SCellVal sVal = {0}; + if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { + break; + } + memcpy(POINTER_SHIFT(pColData->pData, curRow * pColData->info.bytes), sVal.val, pColData->info.bytes); + } +#if 0 for (int32_t i = 0; i < colNumNeed; i++) { SColumnInfoData* pColData = taosArrayGet(pArray, i); STColumn* pCol = schemaColAt(pTschema, i); // TODO - ASSERT(pCol->colId == pColData->info.colId); + if(pCol->colId != pColData->info.colId) { + continue; + } // void* val = tdGetMemRowDataOfColEx(row, pCol->colId, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset, &kvIdx); SCellVal sVal = {0}; if (!tdSTSRowIterNext(&iter, pCol->colId, pCol->type, &sVal)) { @@ -176,6 +218,7 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { } memcpy(POINTER_SHIFT(pColData->pData, curRow * pCol->bytes), sVal.val, pCol->bytes); } +#endif curRow++; } return pArray; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 2f5f94b55f..a3258044c8 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -68,6 +68,8 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { return tqProcessPollReq(pVnode->pTq, pMsg); case TDMT_VND_TASK_EXEC: return tqProcessTaskExec(pVnode->pTq, pMsg); + case TDMT_VND_STREAM_TRIGGER: + return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen); case TDMT_VND_QUERY_HEARTBEAT: return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); default: @@ -163,7 +165,6 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { memcpy(POINTER_SHIFT(metaRsp.pSchemas, sizeof(SSchema) * pSW->nCols), pTagSchema, sizeof(SSchema) * nTagCols); } - _exit: rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp); @@ -179,7 +180,6 @@ _exit: } tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp); - tFreeSTableMetaRsp(&metaRsp); if (pSW != NULL) { tfree(pSW->pSchema); diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index ade9adb1e1..5eeecc5d24 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -59,7 +59,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // todo: change the interface here int64_t ver; taosDecodeFixedI64(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &ver); - if (tqPushMsg(pVnode->pTq, ptr, pMsg->msgType, ver) < 0) { + if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, ver) < 0) { // TODO: handle error } @@ -85,10 +85,10 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { for (int i = 0; i < reqNum; i++) { SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i); - char tableFName[TSDB_TABLE_FNAME_LEN]; + char tableFName[TSDB_TABLE_FNAME_LEN]; SMsgHead *pHead = (SMsgHead *)pMsg->pCont; sprintf(tableFName, "%s.%s", pCreateTbReq->dbFName, pCreateTbReq->name); - + int32_t code = vnodeValidateTableHash(&pVnode->config, tableFName); if (code) { SVCreateTbRsp rsp; @@ -96,7 +96,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { taosArrayPush(vCreateTbBatchRsp.rspList, &rsp); } - + if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { // TODO: handle error vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name); @@ -116,10 +116,10 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { taosArrayDestroy(vCreateTbBatchReq.pArray); if (vCreateTbBatchRsp.rspList) { int32_t contLen = tSerializeSVCreateTbBatchRsp(NULL, 0, &vCreateTbBatchRsp); - void *msg = rpcMallocCont(contLen); + void *msg = rpcMallocCont(contLen); tSerializeSVCreateTbBatchRsp(msg, contLen, &vCreateTbBatchRsp); taosArrayDestroy(vCreateTbBatchRsp.rspList); - + *pRsp = calloc(1, sizeof(SRpcMsg)); (*pRsp)->msgType = TDMT_VND_CREATE_TABLE_RSP; (*pRsp)->pCont = msg; diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 19100d7560..e89bc5df0e 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -30,7 +30,7 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, int32_t t qError("join not supported for stream block scan, %s" PRIx64, id); return TSDB_CODE_QRY_APP_ERROR; } - + pOperator->status = OP_NOT_OPENED; return doSetStreamBlock(pOperator->pDownstream[0], input, type, id); } else { SStreamBlockScanInfo* pInfo = pOperator->info; From 996886e72679331f83e72e0890f355f39b33db33 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 23 Mar 2022 17:08:07 +0800 Subject: [PATCH 50/68] sync refactor --- source/libs/sync/inc/syncRaftLog.h | 7 + source/libs/sync/src/syncAppendEntries.c | 72 ++++--- source/libs/sync/src/syncAppendEntriesReply.c | 6 + source/libs/sync/src/syncRaftLog.c | 55 +++++ source/libs/sync/src/syncReplication.c | 6 + source/libs/sync/test/CMakeLists.txt | 28 +++ source/libs/sync/test/syncLogStoreCheck.cpp | 107 ++++++++++ .../libs/sync/test/syncReplicateLoadTest.cpp | 188 ++++++++++++++++++ 8 files changed, 437 insertions(+), 32 deletions(-) create mode 100644 source/libs/sync/test/syncLogStoreCheck.cpp create mode 100644 source/libs/sync/test/syncReplicateLoadTest.cpp diff --git a/source/libs/sync/inc/syncRaftLog.h b/source/libs/sync/inc/syncRaftLog.h index d979e0df15..2196d6c207 100644 --- a/source/libs/sync/inc/syncRaftLog.h +++ b/source/libs/sync/inc/syncRaftLog.h @@ -47,6 +47,8 @@ SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore); SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore); cJSON* logStore2Json(SSyncLogStore* pLogStore); char* logStore2Str(SSyncLogStore* pLogStore); +cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore); +char* logStoreSimple2Str(SSyncLogStore* pLogStore); // for debug void logStorePrint(SSyncLogStore* pLogStore); @@ -54,6 +56,11 @@ void logStorePrint2(char* s, SSyncLogStore* pLogStore); void logStoreLog(SSyncLogStore* pLogStore); void logStoreLog2(char* s, SSyncLogStore* pLogStore); +void logStoreSimplePrint(SSyncLogStore* pLogStore); +void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore); +void logStoreSimpleLog(SSyncLogStore* pLogStore); +void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore); + #ifdef __cplusplus } #endif diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 960fc6d55e..5ea810180d 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -155,30 +155,35 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // accept request if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_FOLLOWER && logOK) { - bool preMatch = false; - if (pMsg->prevLogIndex == SYNC_INDEX_INVALID && - ths->pLogStore->getLastIndex(ths->pLogStore) == SYNC_INDEX_INVALID) { - preMatch = true; - } - if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) { - SSyncRaftEntry* pPreEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogIndex); - assert(pPreEntry != NULL); - if (pMsg->prevLogTerm == pPreEntry->term) { - preMatch = true; - } - syncEntryDestory(pPreEntry); - } + /* + bool preMatch = false; + if (pMsg->prevLogIndex == SYNC_INDEX_INVALID && + ths->pLogStore->getLastIndex(ths->pLogStore) == SYNC_INDEX_INVALID) { + preMatch = true; + } + if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= + ths->pLogStore->getLastIndex(ths->pLogStore)) { SSyncRaftEntry* pPreEntry = logStoreGetEntry(ths->pLogStore, + pMsg->prevLogIndex); assert(pPreEntry != NULL); if (pMsg->prevLogTerm == pPreEntry->term) { preMatch = true; + } + syncEntryDestory(pPreEntry); + } - sTrace( - "syncNodeOnAppendEntriesCb --> accept, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, " - "ths->state:%d, logOK:%d, preMatch:%d", - pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK, preMatch); + sTrace( + "syncNodeOnAppendEntriesCb --> accept, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, " + "ths->state:%d, logOK:%d, preMatch:%d", + pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK, preMatch); - if (preMatch) { - // must has preIndex in local log + if (preMatch) { + */ + + { + // preIndex = -1, or has preIndex entry in local log assert(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)); + // has extra entries (> preIndex) in local log bool hasExtraEntries = pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore); + + // has entries in SyncAppendEntries msg bool hasAppendEntries = pMsg->dataLen > 0; if (hasExtraEntries && hasAppendEntries) { @@ -287,21 +292,24 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); syncAppendEntriesReplyDestroy(pReply); - - } else { - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->success = false; - pReply->matchIndex = SYNC_INDEX_INVALID; - - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); } + /* + else { + SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(); + pReply->srcId = ths->myRaftId; + pReply->destId = pMsg->srcId; + pReply->term = ths->pRaftStore->currentTerm; + pReply->success = false; + pReply->matchIndex = SYNC_INDEX_INVALID; + + SRpcMsg rpcMsg; + syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); + syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); + syncAppendEntriesReplyDestroy(pReply); + } + */ + // maybe update commit index from leader if (pMsg->commitIndex > ths->commitIndex) { // has commit entry in local diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 817974fd26..790ac7f8e1 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -48,6 +48,9 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p return ret; } + 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); @@ -77,5 +80,8 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex); } + syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== after pNextIndex", ths->pNextIndex); + syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== after pMatchIndex", ths->pMatchIndex); + return ret; } diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index 620e923629..f569c5d621 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -165,6 +165,34 @@ char* logStore2Str(SSyncLogStore* pLogStore) { return serialized; } +cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore) { + char u64buf[128]; + SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; + cJSON* pRoot = cJSON_CreateObject(); + + if (pData != NULL && pData->pWal != NULL) { + snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); + cJSON_AddStringToObject(pRoot, "pWal", u64buf); + snprintf(u64buf, sizeof(u64buf), "%ld", logStoreLastIndex(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", logStoreLastTerm(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SSyncLogStoreSimple", pRoot); + return pJson; +} + +char* logStoreSimple2Str(SSyncLogStore* pLogStore) { + cJSON* pJson = logStoreSimple2Json(pLogStore); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + // for debug ----------------- void logStorePrint(SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); @@ -191,3 +219,30 @@ void logStoreLog2(char* s, SSyncLogStore* pLogStore) { sTrace("logStorePrint | len:%lu | %s | %s", strlen(serialized), s, serialized); free(serialized); } + +// for debug ----------------- +void logStoreSimplePrint(SSyncLogStore* pLogStore) { + char* serialized = logStoreSimple2Str(pLogStore); + printf("logStoreSimplePrint | len:%lu | %s \n", strlen(serialized), serialized); + fflush(NULL); + free(serialized); +} + +void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) { + char* serialized = logStoreSimple2Str(pLogStore); + printf("logStoreSimplePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + fflush(NULL); + free(serialized); +} + +void logStoreSimpleLog(SSyncLogStore* pLogStore) { + char* serialized = logStoreSimple2Str(pLogStore); + sTrace("logStoreSimpleLog | len:%lu | %s", strlen(serialized), serialized); + free(serialized); +} + +void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) { + char* serialized = logStoreSimple2Str(pLogStore); + sTrace("logStoreSimpleLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + free(serialized); +} \ No newline at end of file diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 0bb701fc09..943b268cd3 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -49,6 +49,10 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) { assert(pSyncNode->state == TAOS_SYNC_STATE_LEADER); + syncIndexMgrLog2("==syncNodeAppendEntriesPeers== pNextIndex", pSyncNode->pNextIndex); + syncIndexMgrLog2("==syncNodeAppendEntriesPeers== pMatchIndex", pSyncNode->pMatchIndex); + logStoreSimpleLog2("==syncNodeAppendEntriesPeers==", pSyncNode->pLogStore); + int32_t ret = 0; for (int i = 0; i < pSyncNode->peersNum; ++i) { SRaftId* pDestId = &(pSyncNode->peersId[i]); @@ -99,6 +103,8 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) { pMsg->prevLogTerm = preLogTerm; pMsg->commitIndex = pSyncNode->commitIndex; + syncAppendEntriesLog2("==syncNodeAppendEntriesPeers==", pMsg); + // send AppendEntries syncNodeAppendEntries(pSyncNode, pDestId, pMsg); syncAppendEntriesDestroy(pMsg); diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index ec43517974..dcf380e7e4 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -34,7 +34,9 @@ add_executable(syncEncodeTest "") add_executable(syncWriteTest "") add_executable(syncReplicateTest "") add_executable(syncReplicateTest2 "") +add_executable(syncReplicateLoadTest "") add_executable(syncRefTest "") +add_executable(syncLogStoreCheck "") target_sources(syncTest @@ -181,10 +183,18 @@ target_sources(syncReplicateTest2 PRIVATE "syncReplicateTest2.cpp" ) +target_sources(syncReplicateLoadTest + PRIVATE + "syncReplicateLoadTest.cpp" +) target_sources(syncRefTest PRIVATE "syncRefTest.cpp" ) +target_sources(syncLogStoreCheck + PRIVATE + "syncLogStoreCheck.cpp" +) target_include_directories(syncTest @@ -367,11 +377,21 @@ target_include_directories(syncReplicateTest2 "${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncReplicateLoadTest + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_include_directories(syncRefTest PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncLogStoreCheck + PUBLIC + "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_link_libraries(syncTest @@ -518,10 +538,18 @@ target_link_libraries(syncReplicateTest2 sync gtest_main ) +target_link_libraries(syncReplicateLoadTest + sync + gtest_main +) target_link_libraries(syncRefTest sync gtest_main ) +target_link_libraries(syncLogStoreCheck + sync + gtest_main +) enable_testing() diff --git a/source/libs/sync/test/syncLogStoreCheck.cpp b/source/libs/sync/test/syncLogStoreCheck.cpp new file mode 100644 index 0000000000..5e5e43af01 --- /dev/null +++ b/source/libs/sync/test/syncLogStoreCheck.cpp @@ -0,0 +1,107 @@ +#include +#include +#include "syncEnv.h" +#include "syncIO.h" +#include "syncInt.h" +#include "syncRaftLog.h" +#include "syncRaftStore.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 1; +int32_t myIndex = 0; + +SRaftId ids[TSDB_MAX_REPLICA]; +SSyncInfo syncInfo; +SSyncFSM* pFsm; +SWal* pWal; +SSyncNode* pSyncNode; + +SSyncNode* syncNodeInit(const char *path) { + syncInfo.vgId = 1234; + syncInfo.rpcClient = gSyncIO->clientRpc; + syncInfo.FpSendMsg = syncIOSendMsg; + syncInfo.queue = gSyncIO->pMsgQ; + syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.pFsm = pFsm; + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./log_check"); + + int code = walInit(); + assert(code == 0); + SWalCfg walCfg; + memset(&walCfg, 0, sizeof(SWalCfg)); + walCfg.vgId = syncInfo.vgId; + walCfg.fsyncPeriod = 1000; + walCfg.retentionPeriod = 1000; + walCfg.rollPeriod = 1000; + walCfg.retentionSize = 1000; + walCfg.segSize = 1000; + walCfg.level = TAOS_WAL_FSYNC; + pWal = walOpen(path, &walCfg); + assert(pWal != NULL); + + syncInfo.pWal = pWal; + + SSyncCfg* pCfg = &syncInfo.syncCfg; + pCfg->myIndex = myIndex; + pCfg->replicaNum = replicaNum; + + for (int i = 0; i < replicaNum; ++i) { + pCfg->nodeInfo[i].nodePort = ports[i]; + snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1"); + // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); + } + + pSyncNode = syncNodeOpen(&syncInfo); + assert(pSyncNode != NULL); + + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; + gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; + gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; + gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; + gSyncIO->pSyncNode = pSyncNode; + + return pSyncNode; +} + +SSyncNode* logStoreCheck(const char *path) { return syncNodeInit(path); } + + + +int main(int argc, char** argv) { + // taosInitLog((char *)"syncTest.log", 100000, 10); + tsAsyncLog = 0; + sDebugFlag = 143 + 64; + + myIndex = 0; + if (argc >= 2) { + myIndex = atoi(argv[1]); + } + + int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); + assert(ret == 0); + + ret = syncEnvStart(); + assert(ret == 0); + + pSyncNode = logStoreCheck(argv[1]); + assert(pSyncNode != NULL); + + logStorePrint2((char*)"logStoreCheck", pSyncNode->pLogStore); + + return 0; +} diff --git a/source/libs/sync/test/syncReplicateLoadTest.cpp b/source/libs/sync/test/syncReplicateLoadTest.cpp new file mode 100644 index 0000000000..d53ceca473 --- /dev/null +++ b/source/libs/sync/test/syncReplicateLoadTest.cpp @@ -0,0 +1,188 @@ +#include +#include +#include "syncEnv.h" +#include "syncIO.h" +#include "syncInt.h" +#include "syncMessage.h" +#include "syncRaftEntry.h" +#include "syncRaftLog.h" +#include "syncRaftStore.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +uint16_t ports[] = {7010, 7110, 7210, 7310, 7410}; +int32_t replicaNum = 3; +int32_t myIndex = 0; + +SRaftId ids[TSDB_MAX_REPLICA]; +SSyncInfo syncInfo; +SSyncFSM *pFsm; +SWal * pWal; + +void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, index, isWeak, code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); +} + +void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, index, isWeak, + code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); +} + +void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SyncIndex index, bool isWeak, int32_t code, + ESyncState state) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, index, isWeak, code, state, syncUtilState2String(state)); + syncRpcMsgPrint2(logBuf, (SRpcMsg *)pMsg); +} + +void initFsm() { + pFsm = (SSyncFSM *)malloc(sizeof(SSyncFSM)); + pFsm->FpCommitCb = CommitCb; + pFsm->FpPreCommitCb = PreCommitCb; + pFsm->FpRollBackCb = RollBackCb; +} + +int64_t syncNodeInit() { + syncInfo.vgId = 1234; + syncInfo.rpcClient = gSyncIO->clientRpc; + syncInfo.FpSendMsg = syncIOSendMsg; + syncInfo.queue = gSyncIO->pMsgQ; + syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.pFsm = pFsm; + snprintf(syncInfo.path, sizeof(syncInfo.path), "./replicate2_test_%d", myIndex); + + int code = walInit(); + assert(code == 0); + SWalCfg walCfg; + memset(&walCfg, 0, sizeof(SWalCfg)); + walCfg.vgId = syncInfo.vgId; + walCfg.fsyncPeriod = 1000; + walCfg.retentionPeriod = 1000; + walCfg.rollPeriod = 1000; + walCfg.retentionSize = 1000; + walCfg.segSize = 1000; + walCfg.level = TAOS_WAL_FSYNC; + + char tmpdir[128]; + snprintf(tmpdir, sizeof(tmpdir), "./replicate2_test_wal_%d", myIndex); + pWal = walOpen(tmpdir, &walCfg); + assert(pWal != NULL); + + syncInfo.pWal = pWal; + + SSyncCfg *pCfg = &syncInfo.syncCfg; + pCfg->myIndex = myIndex; + pCfg->replicaNum = replicaNum; + + for (int i = 0; i < replicaNum; ++i) { + pCfg->nodeInfo[i].nodePort = ports[i]; + snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1"); + // taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn); + } + + int64_t rid = syncStart(&syncInfo); + assert(rid > 0); + + SSyncNode *pSyncNode = (SSyncNode *)syncNodeAcquire(rid); + assert(pSyncNode != NULL); + + // pSyncNode->hbBaseLine = 500; + // pSyncNode->electBaseLine = 1500; + + gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing; + gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; + gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; + gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; + gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; + gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; + gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; + gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest; + gSyncIO->pSyncNode = pSyncNode; + + syncNodeRelease(pSyncNode); + + return rid; +} + +void initRaftId(SSyncNode *pSyncNode) { + for (int i = 0; i < replicaNum; ++i) { + ids[i] = pSyncNode->replicasId[i]; + char *s = syncUtilRaftId2Str(&ids[i]); + printf("raftId[%d] : %s\n", i, s); + free(s); + } +} + +SRpcMsg *step0(int i) { + SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg)); + memset(pMsg, 0, sizeof(SRpcMsg)); + pMsg->msgType = 9999; + pMsg->contLen = 128; + pMsg->pCont = malloc(pMsg->contLen); + snprintf((char *)(pMsg->pCont), pMsg->contLen, "value-%u-%d", ports[myIndex], i); + return pMsg; +} + +SyncClientRequest *step1(const SRpcMsg *pMsg) { + SyncClientRequest *pRetMsg = syncClientRequestBuild2(pMsg, 123, true); + return pRetMsg; +} + +int main(int argc, char **argv) { + // taosInitLog((char *)"syncTest.log", 100000, 10); + tsAsyncLog = 0; + sDebugFlag = 143 + 64; + void logTest(); + + myIndex = 0; + if (argc >= 2) { + myIndex = atoi(argv[1]); + } + + int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]); + assert(ret == 0); + + initFsm(); + + ret = syncInit(); + assert(ret == 0); + + int64_t rid = syncNodeInit(); + assert(rid > 0); + + SSyncNode *pSyncNode = (SSyncNode *)syncNodeAcquire(rid); + assert(pSyncNode != NULL); + + syncNodePrint2((char *)"", pSyncNode); + initRaftId(pSyncNode); + + // only load ... + + while (1) { + sTrace( + "replicate sleep, state: %d, %s, term:%lu electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, " + "electTimerMS:%d", + pSyncNode->state, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, + pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser, pSyncNode->electTimerMS); + taosMsleep(1000); + } + + return 0; +} From 7d72c8d4e74613e422f8cda6dbd903947ad8f142 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 23 Mar 2022 17:19:58 +0800 Subject: [PATCH 51/68] [add cases] --- tests/script/tsim/table/basic1.sim | 47 +++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/tests/script/tsim/table/basic1.sim b/tests/script/tsim/table/basic1.sim index a7f45ece08..e7fdf54983 100644 --- a/tests/script/tsim/table/basic1.sim +++ b/tests/script/tsim/table/basic1.sim @@ -3,10 +3,33 @@ system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start sql connect +#=========== TD-14042 start +sql create database db1; +sql create database db2; +sql create database db3; + +sql use db1; +sql create table st1 (ts timestamp, i int) tags (j int); +sql create table tb1 using st1 tags(1); + +sql use db2; +sql create table st2 (ts timestamp, i int) tags (j int); +sql create table tb2 using st2 tags(1); + +sql use db3; +sql create table st3 (ts timestamp, i int) tags (j int); +sql create table tb3 using st3 tags(1); + +sql show tables +if $rows != 1 then + return -1 +endi +#=========== TD-14042 end + print =============== create database sql create database d1 sql show databases -if $rows != 2 then +if $rows != 5 then return -1 endi @@ -186,10 +209,26 @@ if $rows != 21 then return -1 endi -#system sh/exec.sh -n dnode1 -s stop -x SIGINT -#system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi -sleep 2000 print =============== query data sql select * from c1 if $rows != 3 then From 0646a099b2e8ff8bf40cec0c76081eb2c085da93 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 23 Mar 2022 17:38:06 +0800 Subject: [PATCH 52/68] [modify] --- tests/script/jenkins/basic.txt | 7 ++++--- tests/script/tsim/testCaseSuite.sim | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index cc0576e1f3..f2bbb1f348 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -10,9 +10,6 @@ ./test.sh -f tsim/db/basic7.sim ./test.sh -f tsim/db/error1.sim -# ---- table -./test.sh -f tsim/table/basic1.sim - # ---- dnode ./test.sh -f tsim/dnode/basic1.sim @@ -22,6 +19,10 @@ # ---- query ./test.sh -f tsim/query/interval.sim +# ---- table +./test.sh -f tsim/table/basic1.sim + # ---- tmq ./test.sh -f tsim/tmq/basic.sim + #======================b1-end=============== diff --git a/tests/script/tsim/testCaseSuite.sim b/tests/script/tsim/testCaseSuite.sim index 88f1911a2b..bca0204e63 100644 --- a/tests/script/tsim/testCaseSuite.sim +++ b/tests/script/tsim/testCaseSuite.sim @@ -1,4 +1,6 @@ +run tsim/user/basic1.sim + run tsim/db/basic1.sim run tsim/db/basic6.sim run tsim/db/basic7.sim @@ -7,12 +9,14 @@ run tsim/db/error1.sim run tsim/dnode/basic1.sim run tsim/insert/basic0.sim -run tsim/insert/basic1.sim -run tsim/insert/null.sim +#run tsim/insert/basic1.sim # TD-14246 +#run tsim/insert/backquote.sim # TD-14261 +#run tsim/insert/null.sim -run tsim/query/interval-offset.sim run tsim/query/interval.sim +#run tsim/query/interval-offset.sim # TD-14266 run tsim/table/basic1.sim -run tsim/user/basic1.sim +run tsim/tmq/basic.sim + From d5188f14f9fc7cea5b16a8114ab599fa989a52ee Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 23 Mar 2022 17:56:32 +0800 Subject: [PATCH 53/68] sync refactor --- include/libs/sync/sync.h | 10 +- source/libs/sync/src/syncAppendEntries.c | 225 +++++++++----------- source/libs/sync/src/syncCommit.c | 7 + source/libs/sync/test/syncLogStoreCheck.cpp | 6 +- 4 files changed, 109 insertions(+), 139 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index b2ed9ea3c4..a2f88490f0 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -158,17 +158,17 @@ typedef struct SSyncNode SSyncNode; int32_t syncInit(); void syncCleanUp(); -int64_t syncStart(const SSyncInfo* pSyncInfo); -void syncStop(int64_t rid); -int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg); -int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); +int64_t syncStart(const SSyncInfo* pSyncInfo); +void syncStop(int64_t rid); +int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg); +int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); ESyncState syncGetMyRole(int64_t rid); // propose with sequence number, to implement linearizable semantics int32_t syncPropose2(int64_t rid, const SRpcMsg* pMsg, bool isWeak, uint64_t seqNum); // for compatibility, the same as syncPropose -int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); +int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); extern int32_t sDebugFlag; diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 5ea810180d..1116c1a905 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -155,102 +155,60 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // accept request if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_FOLLOWER && logOK) { - /* - bool preMatch = false; - if (pMsg->prevLogIndex == SYNC_INDEX_INVALID && - ths->pLogStore->getLastIndex(ths->pLogStore) == SYNC_INDEX_INVALID) { - preMatch = true; - } - if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= - ths->pLogStore->getLastIndex(ths->pLogStore)) { SSyncRaftEntry* pPreEntry = logStoreGetEntry(ths->pLogStore, - pMsg->prevLogIndex); assert(pPreEntry != NULL); if (pMsg->prevLogTerm == pPreEntry->term) { preMatch = true; + // preIndex = -1, or has preIndex entry in local log + assert(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)); + + // has extra entries (> preIndex) in local log + bool hasExtraEntries = pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore); + + // has entries in SyncAppendEntries msg + bool hasAppendEntries = pMsg->dataLen > 0; + + sTrace( + "syncNodeOnAppendEntriesCb --> accept, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, ths->state:%d, " + "logOK:%d, hasExtraEntries:%d, hasAppendEntries:%d", + pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK, hasExtraEntries, hasAppendEntries); + + if (hasExtraEntries && hasAppendEntries) { + // not conflict by default + bool conflict = false; + + SyncIndex extraIndex = pMsg->prevLogIndex + 1; + SSyncRaftEntry* pExtraEntry = logStoreGetEntry(ths->pLogStore, extraIndex); + assert(pExtraEntry != NULL); + + SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); + assert(pAppendEntry != NULL); + + // log not match, conflict + assert(extraIndex == pAppendEntry->index); + if (pExtraEntry->term != pAppendEntry->term) { + conflict = true; + } + + if (conflict) { + // roll back + SyncIndex delBegin = ths->pLogStore->getLastIndex(ths->pLogStore); + SyncIndex delEnd = extraIndex; + + sTrace("syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%ld, delEnd:%ld", conflict, delBegin, delEnd); + + // notice! reverse roll back! + for (SyncIndex index = delEnd; index >= delBegin; --index) { + if (ths->pFsm->FpRollBackCb != NULL) { + SSyncRaftEntry* pRollBackEntry = logStoreGetEntry(ths->pLogStore, index); + assert(pRollBackEntry != NULL); + + SRpcMsg rpcMsg; + syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg); + ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, pRollBackEntry->index, pRollBackEntry->isWeak, 0, ths->state); + rpcFreeCont(rpcMsg.pCont); + syncEntryDestory(pRollBackEntry); } - syncEntryDestory(pPreEntry); } - sTrace( - "syncNodeOnAppendEntriesCb --> accept, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, " - "ths->state:%d, logOK:%d, preMatch:%d", - pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK, preMatch); - - if (preMatch) { - */ - - { - // preIndex = -1, or has preIndex entry in local log - assert(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)); - - // has extra entries (> preIndex) in local log - bool hasExtraEntries = pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore); - - // has entries in SyncAppendEntries msg - bool hasAppendEntries = pMsg->dataLen > 0; - - if (hasExtraEntries && hasAppendEntries) { - // not conflict by default - bool conflict = false; - - SyncIndex extraIndex = pMsg->prevLogIndex + 1; - SSyncRaftEntry* pExtraEntry = logStoreGetEntry(ths->pLogStore, extraIndex); - assert(pExtraEntry != NULL); - - SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); - assert(pAppendEntry != NULL); - - // log not match, conflict - assert(extraIndex == pAppendEntry->index); - if (pExtraEntry->term != pAppendEntry->term) { - conflict = true; - } - - if (conflict) { - // roll back - SyncIndex delBegin = ths->pLogStore->getLastIndex(ths->pLogStore); - SyncIndex delEnd = extraIndex; - - sTrace("syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%ld, delEnd:%ld", conflict, delBegin, delEnd); - - // notice! reverse roll back! - for (SyncIndex index = delEnd; index >= delBegin; --index) { - if (ths->pFsm->FpRollBackCb != NULL) { - SSyncRaftEntry* pRollBackEntry = logStoreGetEntry(ths->pLogStore, index); - assert(pRollBackEntry != NULL); - - SRpcMsg rpcMsg; - syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg); - ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, pRollBackEntry->index, pRollBackEntry->isWeak, 0, ths->state); - rpcFreeCont(rpcMsg.pCont); - syncEntryDestory(pRollBackEntry); - } - } - - // delete confict entries - ths->pLogStore->truncate(ths->pLogStore, extraIndex); - - // append new entries - ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry); - - // pre commit - SRpcMsg rpcMsg; - syncEntry2OriginalRpc(pAppendEntry, &rpcMsg); - if (ths->pFsm != NULL) { - if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 2, ths->state); - } - } - rpcFreeCont(rpcMsg.pCont); - } - - // free memory - syncEntryDestory(pExtraEntry); - syncEntryDestory(pAppendEntry); - - } else if (hasExtraEntries && !hasAppendEntries) { - // do nothing - - } else if (!hasExtraEntries && hasAppendEntries) { - SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); - assert(pAppendEntry != NULL); + // delete confict entries + ths->pLogStore->truncate(ths->pLogStore, extraIndex); // append new entries ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry); @@ -260,55 +218,62 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { syncEntry2OriginalRpc(pAppendEntry, &rpcMsg); if (ths->pFsm != NULL) { if (ths->pFsm->FpPreCommitCb != NULL) { - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 3, ths->state); + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 2, ths->state); } } rpcFreeCont(rpcMsg.pCont); - - // free memory - syncEntryDestory(pAppendEntry); - - } else if (!hasExtraEntries && !hasAppendEntries) { - // do nothing - - } else { - assert(0); } - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->success = true; + // free memory + syncEntryDestory(pExtraEntry); + syncEntryDestory(pAppendEntry); - if (hasAppendEntries) { - pReply->matchIndex = pMsg->prevLogIndex + 1; - } else { - pReply->matchIndex = pMsg->prevLogIndex; - } + } else if (hasExtraEntries && !hasAppendEntries) { + // do nothing + } else if (!hasExtraEntries && hasAppendEntries) { + SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); + assert(pAppendEntry != NULL); + + // append new entries + ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry); + + // pre commit SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); + syncEntry2OriginalRpc(pAppendEntry, &rpcMsg); + if (ths->pFsm != NULL) { + if (ths->pFsm->FpPreCommitCb != NULL) { + ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 3, ths->state); + } + } + rpcFreeCont(rpcMsg.pCont); - syncAppendEntriesReplyDestroy(pReply); + // free memory + syncEntryDestory(pAppendEntry); + + } else if (!hasExtraEntries && !hasAppendEntries) { + // do nothing + + } else { + assert(0); } - /* - else { - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->success = false; - pReply->matchIndex = SYNC_INDEX_INVALID; + SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(); + pReply->srcId = ths->myRaftId; + pReply->destId = pMsg->srcId; + pReply->term = ths->pRaftStore->currentTerm; + pReply->success = true; - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - } - */ + if (hasAppendEntries) { + pReply->matchIndex = pMsg->prevLogIndex + 1; + } else { + pReply->matchIndex = pMsg->prevLogIndex; + } + + SRpcMsg rpcMsg; + syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); + syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); + syncAppendEntriesReplyDestroy(pReply); // maybe update commit index from leader if (pMsg->commitIndex > ths->commitIndex) { diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 89b5f0b39c..f581b31c4b 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -63,7 +63,14 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { if (pEntry->term == pSyncNode->pRaftStore->currentTerm) { // update commit index newCommitIndex = index; + sTrace("syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%ld commit, pSyncNode->commitIndex:%ld", + newCommitIndex, pSyncNode->commitIndex); break; + } else { + sTrace( + "syncMaybeAdvanceCommitIndex can not commit due to term not equal, pEntry->term:%lu, " + "pSyncNode->pRaftStore->currentTerm:%lu", + pEntry->term, pSyncNode->pRaftStore->currentTerm); } } } diff --git a/source/libs/sync/test/syncLogStoreCheck.cpp b/source/libs/sync/test/syncLogStoreCheck.cpp index 5e5e43af01..85e39a61c5 100644 --- a/source/libs/sync/test/syncLogStoreCheck.cpp +++ b/source/libs/sync/test/syncLogStoreCheck.cpp @@ -26,7 +26,7 @@ SSyncFSM* pFsm; SWal* pWal; SSyncNode* pSyncNode; -SSyncNode* syncNodeInit(const char *path) { +SSyncNode* syncNodeInit(const char* path) { syncInfo.vgId = 1234; syncInfo.rpcClient = gSyncIO->clientRpc; syncInfo.FpSendMsg = syncIOSendMsg; @@ -78,9 +78,7 @@ SSyncNode* syncNodeInit(const char *path) { return pSyncNode; } -SSyncNode* logStoreCheck(const char *path) { return syncNodeInit(path); } - - +SSyncNode* logStoreCheck(const char* path) { return syncNodeInit(path); } int main(int argc, char** argv) { // taosInitLog((char *)"syncTest.log", 100000, 10); From aeec766394141a8599cfa312f0801124f58f0d99 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 23 Mar 2022 18:48:54 +0800 Subject: [PATCH 54/68] [add cases] --- tests/script/jenkins/basic.txt | 1 + tests/script/tsim/insert/basic0.sim | 18 +- tests/script/tsim/insert/null.sim | 272 ++++++++++++++++++++-------- 3 files changed, 205 insertions(+), 86 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index f2bbb1f348..c526bfe5c6 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -15,6 +15,7 @@ # ---- insert ./test.sh -f tsim/insert/basic0.sim +./test.sh -f tsim/insert/null.sim # ---- query ./test.sh -f tsim/query/interval.sim diff --git a/tests/script/tsim/insert/basic0.sim b/tests/script/tsim/insert/basic0.sim index fa4c210ad4..46aa99127b 100644 --- a/tests/script/tsim/insert/basic0.sim +++ b/tests/script/tsim/insert/basic0.sim @@ -205,17 +205,17 @@ endi #if $rows != 4 then # return -1 #endi + #print =============== select count(*) from supter table #sql select count(*) from stb +#print $data00 $data01 $data02 #if $rows != 1 then # return -1 #endi -# -#print $data00 $data01 $data02 -#if $data00 != 8 then +#if $data00 != 9 then # return -1 #endi -# + #print =============== select count(column) from supter table #sql select count(ts), count(c1), count(c2), count(c3) from stb #print $data00 $data01 $data02 $data03 @@ -412,18 +412,18 @@ endi #sql select * from stb #if $rows != 4 then # return -1 -#endi +#endi + #print =============== select count(*) from supter table #sql select count(*) from stb +#print $data00 $data01 $data02 #if $rows != 1 then # return -1 #endi -# -#print $data00 $data01 $data02 -#if $data00 != 8 then +#if $data00 != 9 then # return -1 #endi -# + #print =============== select count(column) from supter table #sql select count(ts), count(c1), count(c2), count(c3) from stb #print $data00 $data01 $data02 $data03 diff --git a/tests/script/tsim/insert/null.sim b/tests/script/tsim/insert/null.sim index 9dcc435486..156a618fb6 100644 --- a/tests/script/tsim/insert/null.sim +++ b/tests/script/tsim/insert/null.sim @@ -7,7 +7,7 @@ sql connect print =============== create database sql create database d0 sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -40,7 +40,7 @@ sql insert into ct1 values (now+7s, 14, NULL, 3.5, 95) sql insert into ct1 values (now+8s, 15, 2.5, NULL, 96) sql insert into ct1 values (now+9s, 16, 2.6, 3.6, NULL) sql insert into ct1 values (now+10s, NULL, NULL, NULL, NULL) -sql insert into ct1 values (now+11s, -2147483648, 2.7, 3.7, 97) +sql insert into ct1 values (now+11s, -2147483647, 2.7, 3.7, 97) #=================================================================== #=================================================================== @@ -75,7 +75,6 @@ endi # return -1 #endi - print =============== select count(*) from child table sql select count(*) from ct1 print ===> select count(*) from ct1 @@ -84,9 +83,7 @@ print ===> rows0: $data00 $data01 $data02 $data03 $data04 if $rows != 1 then return -1 endi - -print $data00 $data01 $data02 -if $data00 != 4 then +if $data00 != 12 then return -1 endi @@ -95,17 +92,16 @@ sql select count(ts), count(c1), count(c2), count(c3) from ct1 print ===> select count(ts), count(c1), count(c2), count(c3) from ct1 print ===> rows: $rows print ===> rows0: $data00 $data01 $data02 $data03 $data04 - -if $data00 != 4 then +if $data00 != 12 then return -1 endi -if $data01 != 4 then +if $data01 != 8 then return -1 endi -if $data02 != 4 then +if $data02 != 8 then return -1 endi -if $data03 != 4 then +if $data03 != 8 then return -1 endi @@ -121,7 +117,7 @@ print ===> rows0: $data00 $data01 $data02 $data03 $data04 if $rows != 1 then return -1 endi -if $data00 != 10 then +if $data00 != -2147483647 then return -1 endi if $data01 != 2.00000 then @@ -139,13 +135,13 @@ print ===> rows0: $data00 $data01 $data02 $data03 $data04 if $rows != 1 then return -1 endi -if $data00 != 13 then +if $data00 != 16 then return -1 endi -if $data01 != 2.30000 then +if $data01 != 2.70000 then return -1 endi -if $data02 != 3.300000000 then +if $data02 != 3.700000000 then return -1 endi @@ -157,13 +153,13 @@ print ===> rows0: $data00 $data01 $data02 $data03 $data04 if $rows != 1 then return -1 endi -if $data00 != 46 then +if $data00 != -2147483556 then return -1 endi -if $data01 != 8.599999905 then +if $data01 != 18.799999952 then return -1 endi -if $data02 != 12.600000000 then +if $data02 != 26.800000000 then return -1 endi @@ -172,42 +168,48 @@ sql select c1, c2, c3 from ct1 print ===> select c1, c2, c3 from ct1 print ===> rows: $rows print ===> rows0: $data00 $data01 $data02 $data03 $data04 -#if $rows != 4 then -# return -1 -#endi -#if $data00 != 10 then -# return -1 -#endi -#if $data01 != 2.00000 then -# return -1 -#endi -#if $data02 != 3.000000000 then -# return -1 -#endi -#if $data10 != 11 then -# return -1 -#endi -#if $data11 != 2.10000 then -# return -1 -#endi -#if $data12 != 3.100000000 then -# return -1 -#endi -#if $data30 != 13 then -# return -1 -#endi -#if $data31 != 2.30000 then -# return -1 -#endi -#if $data32 != 3.300000000 then -# return -1 -#endi +if $rows != 12 then + return -1 +endi +if $data00 != 10 then + return -1 +endi +if $data01 != 2.00000 then + return -1 +endi +if $data02 != 3.000000000 then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data12 != NULL then + return -1 +endi +if $data30 != 11 then + return -1 +endi +if $data31 != NULL then + return -1 +endi +if $data32 != 3.200000000 then + return -1 +endi +if $data90 != 16 then + return -1 +endi +if $data91 != 2.60000 then + return -1 +endi +if $data92 != 3.600000000 then + return -1 +endi #=================================================================== #=================================================================== - -return - #print =============== query data from stb #sql select * from stb #print ===> @@ -218,19 +220,18 @@ return #endi #print =============== select count(*) from supter table #sql select count(*) from stb +#print $data00 $data01 $data02 #if $rows != 1 then # return -1 #endi -# -#print $data00 $data01 $data02 -#if $data00 != 8 then +#if $data00 != 12 then # return -1 #endi -# + #print =============== select count(column) from supter table #sql select count(ts), count(c1), count(c2), count(c3) from stb #print $data00 $data01 $data02 $data03 -#if $data00 != 8 then +#if $data00 != 12 then # return -1 #endi #if $data01 != 8 then @@ -243,6 +244,7 @@ return # return -1 #endi +return #=================================================================== #=================================================================== @@ -251,9 +253,36 @@ print =============== stop and restart taosd, then again do query above system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start -sleep 2000 +print ===> waiting dnode ready +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +#=================================================================== +#=================================================================== +print =============== query data from child table sql select * from ct1 -if $rows != 4 then # after fix bug, modify 4 to 7 +print ===> select * from ct1 +print ===> rows: $rows +print ===> rows0: $data00 $data01 $data02 $data03 $data04 +print ===> rows1: $data10 $data11 $data12 $data13 $data14 +print ===> rows2: $data20 $data21 $data22 $data23 $data24 +print ===> rows3: $data30 $data31 $data32 $data33 $data34 +print ===> rows4: $data40 $data41 $data42 $data43 $data44 +if $rows != 12 then return -1 endi if $data01 != 10 then @@ -275,31 +304,33 @@ endi # return -1 #endi - print =============== select count(*) from child table sql select count(*) from ct1 +print ===> select count(*) from ct1 +print ===> rows: $rows +print ===> rows0: $data00 $data01 $data02 $data03 $data04 if $rows != 1 then return -1 endi - -print $data00 $data01 $data02 -if $data00 != 4 then +if $data00 != 12 then return -1 endi print =============== select count(column) from child table sql select count(ts), count(c1), count(c2), count(c3) from ct1 -print $data00 $data01 $data02 $data03 -if $data00 != 4 then +print ===> select count(ts), count(c1), count(c2), count(c3) from ct1 +print ===> rows: $rows +print ===> rows0: $data00 $data01 $data02 $data03 $data04 +if $data00 != 12 then return -1 endi -if $data01 != 4 then +if $data01 != 8 then return -1 endi -if $data02 != 4 then +if $data02 != 8 then return -1 endi -if $data03 != 4 then +if $data03 != 8 then return -1 endi @@ -309,11 +340,13 @@ endi print =============== select min(column) from child table sql select min(c1), min(c2), min(c3) from ct1 -print $data00 $data01 $data02 $data03 +print ===> select min(c1), min(c2), min(c3) from ct1 +print ===> rows: $rows +print ===> rows0: $data00 $data01 $data02 $data03 $data04 if $rows != 1 then return -1 endi -if $data00 != 10 then +if $data00 != -2147483647 then return -1 endi if $data01 != 2.00000 then @@ -325,34 +358,119 @@ endi print =============== select max(column) from child table sql select max(c1), max(c2), max(c3) from ct1 -print $data00 $data01 $data02 $data03 +print ===> select max(c1), max(c2), max(c3) from ct1 +print ===> rows: $rows +print ===> rows0: $data00 $data01 $data02 $data03 $data04 if $rows != 1 then return -1 endi -if $data00 != 13 then +if $data00 != 16 then return -1 endi -if $data01 != 2.30000 then +if $data01 != 2.70000 then return -1 endi -if $data02 != 3.300000000 then +if $data02 != 3.700000000 then return -1 endi print =============== select sum(column) from child table sql select sum(c1), sum(c2), sum(c3) from ct1 -print $data00 $data01 $data02 $data03 +print ===> select sum(c1), sum(c2), sum(c3) from ct1 +print ===> rows: $rows +print ===> rows0: $data00 $data01 $data02 $data03 $data04 if $rows != 1 then return -1 endi -if $data00 != 46 then +if $data00 != -2147483556 then return -1 endi -if $data01 != 8.599999905 then +if $data01 != 18.799999952 then return -1 endi -if $data02 != 12.600000000 then +if $data02 != 26.800000000 then return -1 endi +print =============== select column, from child table +sql select c1, c2, c3 from ct1 +print ===> select c1, c2, c3 from ct1 +print ===> rows: $rows +print ===> rows0: $data00 $data01 $data02 $data03 $data04 +if $rows != 12 then + return -1 +endi +if $data00 != 10 then + return -1 +endi +if $data01 != 2.00000 then + return -1 +endi +if $data02 != 3.000000000 then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data12 != NULL then + return -1 +endi +if $data30 != 11 then + return -1 +endi +if $data31 != NULL then + return -1 +endi +if $data32 != 3.200000000 then + return -1 +endi +if $data90 != 16 then + return -1 +endi +if $data91 != 2.60000 then + return -1 +endi +if $data92 != 3.600000000 then + return -1 +endi +#=================================================================== +#=================================================================== + +#print =============== query data from stb +#sql select * from stb +#print ===> +#print ===> rows: $rows +#print ===> rows0: $data00 $data01 $data02 $data03 $data04 +#if $rows != 4 then +# return -1 +#endi +#print =============== select count(*) from supter table +#sql select count(*) from stb +#print $data00 $data01 $data02 +#if $rows != 1 then +# return -1 +#endi +#if $data00 != 12 then +# return -1 +#endi + +#print =============== select count(column) from supter table +#sql select count(ts), count(c1), count(c2), count(c3) from stb +#print $data00 $data01 $data02 $data03 +#if $data00 != 12 then +# return -1 +#endi +#if $data01 != 8 then +# return -1 +#endi +#if $data02 != 8 then +# return -1 +#endi +#if $data03 != 8 then +# return -1 +#endi + #system sh/exec.sh -n dnode1 -s stop -x SIGINT From 21aaecd016aae4dd8071fa53d03caeb0eaf1f6d8 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 23 Mar 2022 19:10:24 +0800 Subject: [PATCH 55/68] [td-13039] fix null value retrieval. --- source/dnode/vnode/src/tsdb/tsdbRead.c | 63 ++++++++++---------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 5af9e18ee1..6c79fe3726 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -403,18 +403,12 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, SColumnInfoData colInfo = {{0}, 0}; colInfo.info = pCond->colList[i]; - colInfo.pData = calloc(1, EXTRA_BYTES + pReadHandle->outputCapacity * pCond->colList[i].bytes); - if (!IS_VAR_DATA_TYPE(colInfo.info.type)) { - colInfo.nullbitmap = calloc(1, BitmapLen(pReadHandle->outputCapacity)); - } - - if (colInfo.pData == NULL || (colInfo.nullbitmap == NULL && (!IS_VAR_DATA_TYPE(colInfo.info.type)))) { + int32_t code = blockDataEnsureColumnCapacity(&colInfo, pReadHandle->outputCapacity); + if (code != TSDB_CODE_SUCCESS) { goto _end; } taosArrayPush(pReadHandle->pColumns, &colInfo); - - pReadHandle->statis[i].colId = colInfo.info.colId; } @@ -1418,34 +1412,37 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t } if (!isAllRowsNull(src) && pColInfo->info.colId == src->colId) { - if (pColInfo->info.type != TSDB_DATA_TYPE_BINARY && pColInfo->info.type != TSDB_DATA_TYPE_NCHAR) { - memmove(pData, (char*)src->pData + bytes * start, bytes * num); - } else { // handle the var-string - char* dst = pData; + if (!IS_VAR_DATA_TYPE(pColInfo->info.type)) { // todo opt performance +// memmove(pData, (char*)src->pData + bytes * start, bytes * num); + for(int32_t k = start; k < num + start; ++k) { + SCellVal sVal = {0}; + if (tdGetColDataOfRow(&sVal, src, k) < 0) { + TASSERT(0); + } + if (sVal.valType == TD_VTYPE_NULL) { + colDataAppend(pColInfo, k, NULL, true); + } else { + colDataAppend(pColInfo, k, sVal.val, false); + } + } + } else { // handle the var-string // todo refactor, only copy one-by-one for (int32_t k = start; k < num + start; ++k) { - SCellVal sVal = {0}; + SCellVal sVal = {0}; if(tdGetColDataOfRow(&sVal, src, k) < 0){ TASSERT(0); } - memcpy(dst, sVal.val, varDataTLen(sVal.val)); - dst += bytes; + + colDataAppend(pColInfo, k, sVal.val, false); } } j++; i++; } else { // pColInfo->info.colId < src->colId, it is a NULL data - if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { - char* dst = pData; - - for(int32_t k = start; k < num + start; ++k) { - setVardataNull(dst, pColInfo->info.type); - dst += bytes; - } - } else { - setNullN(pData, pColInfo->info.type, pColInfo->info.bytes, num); + for(int32_t k = start; k < num + start; ++k) { // TODO opt performance + colDataAppend(pColInfo, k, NULL, true); } i++; } @@ -1453,23 +1450,9 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t while (i < requiredNumOfCols) { // the remain columns are all null data SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; - } else { - pData = (char*)pColInfo->pData + (capacity - numOfRows - num) * pColInfo->info.bytes; + for(int32_t k = start; k < num + start; ++k) { + colDataAppend(pColInfo, k, NULL, true); // TODO add a fast version to set a number of consecutive NULL value. } - - if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { - char* dst = pData; - - for(int32_t k = start; k < num + start; ++k) { - setVardataNull(dst, pColInfo->info.type); - dst += pColInfo->info.bytes; - } - } else { - setNullN(pData, pColInfo->info.type, pColInfo->info.bytes, num); - } - i++; } From 4d7bb97f54e25a3962032deb3322f7db5f2ad36f Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 23 Mar 2022 19:27:27 +0800 Subject: [PATCH 56/68] Feature/sangshuduo/td 13558 taos shell refactor (#10946) * [TD-13558]: taos shell refactor add taosTools as submodule * add tools/taos-tools * add more client interface for taosTools compile * update taos-tools * update taos-tools * refactor shell * [TD-13558]: taos shell test speed --- include/common/taosdef.h | 2 + .../inc => include/libs/transport}/rpcHead.h | 0 include/os/osSocket.h | 39 ++++- source/os/src/osSocket.c | 11 -- tools/CMakeLists.txt | 1 + tools/shell/CMakeLists.txt | 4 +- tools/shell/inc/syncMsg.h | 141 ++++++++++++++++++ tools/shell/inc/tsync.h | 127 ++++++++++++++++ tools/shell/src/shellMain.c | 18 ++- tools/shell/src/{backup => }/tnettest.c | 134 +++++++++++------ 10 files changed, 410 insertions(+), 67 deletions(-) rename {source/libs/transport/inc => include/libs/transport}/rpcHead.h (100%) create mode 100644 tools/shell/inc/syncMsg.h create mode 100644 tools/shell/inc/tsync.h rename tools/shell/src/{backup => }/tnettest.c (85%) diff --git a/include/common/taosdef.h b/include/common/taosdef.h index f252143fa6..29d711d6d6 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -75,6 +75,8 @@ typedef enum { extern char *qtypeStr[]; +#define TSDB_PORT_DNODEDNODE 5 +#define TSDB_PORT_SYNC 10 #define TSDB_PORT_HTTP 11 #ifdef __cplusplus diff --git a/source/libs/transport/inc/rpcHead.h b/include/libs/transport/rpcHead.h similarity index 100% rename from source/libs/transport/inc/rpcHead.h rename to include/libs/transport/rpcHead.h diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 3c8cc8abd1..7af8dd37bf 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -51,10 +51,31 @@ extern "C" { #endif -#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) +#if defined(WINDOWS) #define htobe64 htonll #endif +#if defined(WINDOWS) + #define TAOS_EPOLL_WAIT_TIME 100 + typedef SOCKET eventfd_t; + #define eventfd(a, b) -1 + typedef SOCKET EpollFd; + #define EpollClose(pollFd) epoll_close(pollFd) + #ifndef EPOLLWAKEUP + #define EPOLLWAKEUP (1u << 29) + #endif +#elif defined(_TD_DARWIN_64) + #define TAOS_EPOLL_WAIT_TIME 500 + typedef int32_t SOCKET; + typedef SOCKET EpollFd; + #define EpollClose(pollFd) epoll_close(pollFd) +#else + #define TAOS_EPOLL_WAIT_TIME 500 + typedef int32_t SOCKET; + typedef SOCKET EpollFd; + #define EpollClose(pollFd) taosCloseSocket(pollFd) +#endif + #if defined(_TD_DARWIN_64) // #define htobe64 htonll @@ -64,12 +85,12 @@ extern "C" { # define htole16(x) OSSwapHostToLittleInt16(x) # define be16toh(x) OSSwapBigToHostInt16(x) # define le16toh(x) OSSwapLittleToHostInt16(x) - + # define htobe32(x) OSSwapHostToBigInt32(x) # define htole32(x) OSSwapHostToLittleInt32(x) # define be32toh(x) OSSwapBigToHostInt32(x) # define le32toh(x) OSSwapLittleToHostInt32(x) - + # define htobe64(x) OSSwapHostToBigInt64(x) # define htole64(x) OSSwapHostToLittleInt64(x) # define be64toh(x) OSSwapBigToHostInt64(x) @@ -83,6 +104,17 @@ extern "C" { #define TAOS_EPOLL_WAIT_TIME 500 +typedef int32_t SocketFd; +typedef SocketFd EpollFd; + +typedef struct TdSocket { +#if SOCKET_WITH_LOCK + TdThreadRwlock rwlock; +#endif + int refId; + SocketFd fd; +} *TdSocketPtr, TdSocket; + typedef struct TdSocketServer *TdSocketServerPtr; typedef struct TdSocket *TdSocketPtr; typedef struct TdEpoll *TdEpollPtr; @@ -91,6 +123,7 @@ int32_t taosSendto(TdSocketPtr pSocket, void * msg, int len, unsigned int flags, int32_t taosWriteSocket(TdSocketPtr pSocket, void *msg, int len); int32_t taosReadSocket(TdSocketPtr pSocket, void *msg, int len); int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t flags, struct sockaddr *destAddr, socklen_t *addrLen); +int32_t taosCloseSocketNoCheck1(SocketFd fd); int32_t taosCloseSocket(TdSocketPtr *ppSocket); int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer); int32_t taosShutDownSocketRD(TdSocketPtr pSocket); diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 0e6abb5785..f693ad74de 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -47,9 +47,6 @@ #endif #endif -typedef int32_t SocketFd; -typedef SocketFd EpollFd; - typedef struct TdSocketServer { #if SOCKET_WITH_LOCK TdThreadRwlock rwlock; @@ -58,14 +55,6 @@ typedef struct TdSocketServer { SocketFd fd; } *TdSocketServerPtr, TdSocketServer; -typedef struct TdSocket { -#if SOCKET_WITH_LOCK - TdThreadRwlock rwlock; -#endif - int refId; - SocketFd fd; -} *TdSocketPtr, TdSocket; - typedef struct TdEpoll { #if SOCKET_WITH_LOCK TdThreadRwlock rwlock; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index dae0a1c840..f064833691 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -4,6 +4,7 @@ IF (TD_TAOS_TOOLS) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/common) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/util) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/os) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/libs/transport) ADD_SUBDIRECTORY(taos-tools) ENDIF () diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index b351675e47..284693795e 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -4,9 +4,7 @@ add_executable(shell ${SHELL_SRC}) target_link_libraries( shell PUBLIC taos - PUBLIC util - PUBLIC common - PUBLIC os + PRIVATE os common transport util ) target_include_directories( shell diff --git a/tools/shell/inc/syncMsg.h b/tools/shell/inc/syncMsg.h new file mode 100644 index 0000000000..85ac9c78af --- /dev/null +++ b/tools/shell/inc/syncMsg.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_SYNC_MSG_H +#define TDENGINE_SYNC_MSG_H + +#ifdef __cplusplus +extern "C" { +#endif +#include "tsync.h" + +typedef enum { + TAOS_SMSG_START = 0, + TAOS_SMSG_SYNC_DATA = 1, + TAOS_SMSG_SYNC_DATA_RSP = 2, + TAOS_SMSG_SYNC_FWD = 3, + TAOS_SMSG_SYNC_FWD_RSP = 4, + TAOS_SMSG_SYNC_REQ = 5, + TAOS_SMSG_SYNC_REQ_RSP = 6, + TAOS_SMSG_SYNC_MUST = 7, + TAOS_SMSG_SYNC_MUST_RSP = 8, + TAOS_SMSG_STATUS = 9, + TAOS_SMSG_STATUS_RSP = 10, + TAOS_SMSG_SETUP = 11, + TAOS_SMSG_SETUP_RSP = 12, + TAOS_SMSG_SYNC_FILE = 13, + TAOS_SMSG_SYNC_FILE_RSP = 14, + TAOS_SMSG_TEST = 15, + TAOS_SMSG_END = 16 +} ESyncMsgType; + +typedef enum { + SYNC_STATUS_BROADCAST, + SYNC_STATUS_BROADCAST_RSP, + SYNC_STATUS_SETUP_CONN, + SYNC_STATUS_SETUP_CONN_RSP, + SYNC_STATUS_EXCHANGE_DATA, + SYNC_STATUS_EXCHANGE_DATA_RSP, + SYNC_STATUS_CHECK_ROLE, + SYNC_STATUS_CHECK_ROLE_RSP +} ESyncStatusType; + +#pragma pack(push, 1) + +typedef struct { + int8_t type; // msg type + int8_t protocol; // protocol version + uint16_t signature; // fixed value + int32_t code; // + int32_t cId; // cluster Id + int32_t vgId; // vg ID + int32_t len; // content length, does not include head + uint32_t cksum; +} SSyncHead; + +typedef struct { + SSyncHead head; + uint16_t port; + uint16_t tranId; + int32_t sourceId; // only for arbitrator + char fqdn[TSDB_FQDN_LEN]; +} SSyncMsg; + +typedef struct { + SSyncHead head; + int8_t sync; + int8_t reserved; + uint16_t tranId; + int8_t reserverd[4]; +} SSyncRsp; + +typedef struct { + int8_t role; + uint64_t version; +} SPeerStatus; + +typedef struct { + SSyncHead head; + int8_t role; + int8_t ack; + int8_t type; + int8_t reserved[3]; + uint16_t tranId; + uint64_t version; + SPeerStatus peersStatus[TAOS_SYNC_MAX_REPLICA]; +} SPeersStatus; + +typedef struct { + SSyncHead head; + uint64_t fversion; +} SFileVersion; + +typedef struct { + SSyncHead head; + int8_t ack; +} SFileAck; + +typedef struct { + SSyncHead head; + uint64_t version; + int32_t code; +} SFwdRsp; + +#pragma pack(pop) + +#define SYNC_PROTOCOL_VERSION 1 +#define SYNC_SIGNATURE ((uint16_t)(0xCDEF)) + +extern char *statusType[]; + +uint16_t syncGenTranId(); +int32_t syncCheckHead(SSyncHead *pHead); + +void syncBuildSyncFwdMsg(SSyncHead *pHead, int32_t vgId, int32_t len); +void syncBuildSyncFwdRsp(SFwdRsp *pMsg, int32_t vgId, uint64_t version, int32_t code); +void syncBuildSyncReqMsg(SSyncMsg *pMsg, int32_t vgId); +void syncBuildSyncDataMsg(SSyncMsg *pMsg, int32_t vgId); +void syncBuildSyncSetupMsg(SSyncMsg *pMsg, int32_t vgId); +void syncBuildPeersStatus(SPeersStatus *pMsg, int32_t vgId); +void syncBuildSyncTestMsg(SSyncMsg *pMsg, int32_t vgId); + +void syncBuildFileAck(SFileAck *pMsg, int32_t vgId); +void syncBuildFileVersion(SFileVersion *pMsg, int32_t vgId); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_VNODEPEER_H diff --git a/tools/shell/inc/tsync.h b/tools/shell/inc/tsync.h new file mode 100644 index 0000000000..d1b68e3f5a --- /dev/null +++ b/tools/shell/inc/tsync.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_SYNC_H +#define TDENGINE_SYNC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define TAOS_SYNC_MAX_REPLICA 5 +#define TAOS_SYNC_MAX_INDEX 0x7FFFFFFF + +typedef enum { + TAOS_SYNC_ROLE_OFFLINE = 0, + TAOS_SYNC_ROLE_UNSYNCED = 1, + TAOS_SYNC_ROLE_SYNCING = 2, + TAOS_SYNC_ROLE_SLAVE = 3, + TAOS_SYNC_ROLE_MASTER = 4 +} ESyncRole; + +typedef enum { + TAOS_SYNC_STATUS_INIT = 0, + TAOS_SYNC_STATUS_START = 1, + TAOS_SYNC_STATUS_FILE = 2, + TAOS_SYNC_STATUS_CACHE = 3 +} ESyncStatus; + +typedef struct { + uint32_t nodeId; // node ID assigned by TDengine + uint16_t nodePort; // node sync Port + char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN +} SNodeInfo; + +typedef struct { + int8_t quorum; // number of confirms required, >=1 + int8_t replica; // number of replications, >=1 + SNodeInfo nodeInfo[TAOS_SYNC_MAX_REPLICA]; +} SSyncCfg; + +typedef struct { + int32_t selfIndex; + uint32_t nodeId[TAOS_SYNC_MAX_REPLICA]; + int32_t role[TAOS_SYNC_MAX_REPLICA]; +} SNodesRole; + +// get the wal file from index or after +// return value, -1: error, 1:more wal files, 0:last WAL. if name[0]==0, no WAL file +typedef int32_t (*FGetWalInfo)(int32_t vgId, char *fileName, int64_t *fileId); + +// when a forward pkt is received, call this to handle data +typedef int32_t (*FWriteToCache)(int32_t vgId, void *pHead, int32_t qtype, void *pMsg); + +// when forward is confirmed by peer, master call this API to notify app +typedef void (*FConfirmForward)(int32_t vgId, void *mhandle, int32_t code); + +// when role is changed, call this to notify app +typedef void (*FNotifyRole)(int32_t vgId, int8_t role); + +// if a number of retrieving data failed, call this to start flow control +typedef void (*FNotifyFlowCtrl)(int32_t vgId, int32_t level); + +// when data file is synced successfully, notity app +typedef void (*FStartSyncFile)(int32_t vgId); +typedef void (*FStopSyncFile)(int32_t vgId, uint64_t fversion); + +// get file version +typedef int32_t (*FGetVersion)(int32_t vgId, uint64_t *fver, uint64_t *vver); + +typedef int32_t (*FSendFile)(void *tsdb, SOCKET socketFd); +typedef int32_t (*FRecvFile)(void *tsdb, SOCKET socketFd); + +typedef struct { + int32_t vgId; // vgroup ID + uint64_t version; // initial version + SSyncCfg syncCfg; // configuration from mgmt + char path[TSDB_FILENAME_LEN]; // path to the file + void * pTsdb; + FGetWalInfo getWalInfoFp; + FWriteToCache writeToCacheFp; + FConfirmForward confirmForward; + FNotifyRole notifyRoleFp; + FNotifyFlowCtrl notifyFlowCtrlFp; + FStartSyncFile startSyncFileFp; + FStopSyncFile stopSyncFileFp; + FGetVersion getVersionFp; + FSendFile sendFileFp; + FRecvFile recvFileFp; +} SSyncInfo; + +typedef void *tsync_h; + +int32_t syncInit(); +void syncCleanUp(); + +int64_t syncStart(const SSyncInfo *); +void syncStop(int64_t rid); +int32_t syncReconfig(int64_t rid, const SSyncCfg *); +int32_t syncForwardToPeer(int64_t rid, void *pHead, void *mhandle, int32_t qtype, bool force); +void syncConfirmForward(int64_t rid, uint64_t version, int32_t code, bool force); +void syncRecover(int64_t rid); // recover from other nodes: +int32_t syncGetNodesRole(int64_t rid, SNodesRole *); + +extern char *syncRole[]; + +//global configurable parameters +extern int32_t sDebugFlag; +extern char tsArbitrator[]; +extern uint16_t tsSyncPort; + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_SYNC_H diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c index 78d6f74df1..dd5fa2e2a5 100644 --- a/tools/shell/src/shellMain.c +++ b/tools/shell/src/shellMain.c @@ -32,6 +32,8 @@ int indicator = 1; void insertChar(Command *cmd, char *c, int size); +void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen, + int32_t pkgNum, char *pkgType); const char *argp_program_version = version; const char *argp_program_bug_address = ""; static char doc[] = ""; @@ -59,7 +61,8 @@ static struct argp_option options[] = { {"netrole", 'n', "NETROLE", 0, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync|speen|fqdn."}, {"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."}, {"pktnum", 'N', "PKTNUM", 0, "Packet numbers used for net test, default is 100."}, - {"pkttype", 'S', "PKTTYPE", 0, "Packet type used for net test, default is TCP."}, +// Shuduo: 3.0 does not support UDP any more +// {"pkttype", 'S', "PKTTYPE", 0, "Packet type used for net test, default is TCP."}, {0}}; static error_t parse_opt(int key, char *arg, struct argp_state *state) { @@ -629,16 +632,25 @@ int main(int argc, char *argv[]) { taosDumpGlobalCfg(); exit(0); } +#endif if (args.netTestRole && args.netTestRole[0] != 0) { - if (taos_init()) { + TAOS *con = NULL; + if (args.auth == NULL) { + con = taos_connect(args.host, args.user, args.password, args.database, args.port); + } else { + con = taos_connect_auth(args.host, args.user, args.auth, args.database, args.port); + } + +/* if (taos_init()) { printf("Failed to init taos"); exit(EXIT_FAILURE); } + */ taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType); + taos_close(con); exit(0); } -#endif /* Initialize the shell */ TAOS *con = shellInit(&args); diff --git a/tools/shell/src/backup/tnettest.c b/tools/shell/src/tnettest.c similarity index 85% rename from tools/shell/src/backup/tnettest.c rename to tools/shell/src/tnettest.c index ee32bfb6be..d0b5e5f25c 100644 --- a/tools/shell/src/backup/tnettest.c +++ b/tools/shell/src/tnettest.c @@ -14,18 +14,20 @@ */ #define _DEFAULT_SOURCE +#define ALLOW_FORBID_FUNC #include "os.h" #include "taosdef.h" #include "tmsg.h" #include "taoserror.h" #include "tlog.h" #include "tglobal.h" -#include "tsocket.h" #include "trpc.h" #include "rpcHead.h" #include "tchecksum.h" #include "syncMsg.h" +#include "osSocket.h" + #define MAX_PKG_LEN (64 * 1000) #define MAX_SPEED_PKG_LEN (1024 * 1024 * 1024) #define MIN_SPEED_PKG_LEN 1024 @@ -33,7 +35,7 @@ #define MIN_SPEED_PKG_NUM 1 #define BUFFER_SIZE (MAX_PKG_LEN + 1024) -extern int32_t tsRpcMaxUdpSize; +extern int tsRpcMaxUdpSize; typedef struct { char * hostFqdn; @@ -71,15 +73,23 @@ static void *taosNetBindUdpPort(void *sarg) { return NULL; } - if (taosSetSockOpt(serverSocket, SOL_SOCKET, SO_SNDBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { + TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + if (pSocket == NULL) { + taosCloseSocketNoCheck1(serverSocket); + return NULL; + } + pSocket->fd = serverSocket; + pSocket->refId = 0; + + if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_SNDBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { uError("failed to set the send buffer size for UDP socket\n"); - taosCloseSocket(serverSocket); + taosCloseSocket(&pSocket); return NULL; } - if (taosSetSockOpt(serverSocket, SOL_SOCKET, SO_RCVBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { + if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_RCVBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { uError("failed to set the receive buffer size for UDP socket\n"); - taosCloseSocket(serverSocket); + taosCloseSocket(&pSocket); return NULL; } @@ -98,13 +108,13 @@ static void *taosNetBindUdpPort(void *sarg) { uInfo("UDP: recv:%d bytes from %s at %d", iDataNum, taosInetNtoa(clientAddr.sin_addr), port); if (iDataNum > 0) { - iDataNum = taosSendto(serverSocket, buffer, iDataNum, 0, (struct sockaddr *)&clientAddr, (int32_t)sin_size); + iDataNum = taosSendto(pSocket, buffer, iDataNum, 0, (struct sockaddr *)&clientAddr, (int32_t)sin_size); } uInfo("UDP: send:%d bytes to %s at %d", iDataNum, taosInetNtoa(clientAddr.sin_addr), port); } - taosCloseSocket(serverSocket); + taosCloseSocket(&pSocket); return NULL; } @@ -132,25 +142,35 @@ static void *taosNetBindTcpPort(void *sarg) { server_addr.sin_addr.s_addr = htonl(INADDR_ANY); int32_t reuse = 1; - if (taosSetSockOpt(serverSocket, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { + TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + if (pSocket == NULL) { + taosCloseSocketNoCheck1(serverSocket); + return NULL; + } + pSocket->fd = serverSocket; + pSocket->refId = 0; + + if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { uError("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); - taosCloseSocket(serverSocket); + taosCloseSocket(&pSocket); return NULL; } if (bind(serverSocket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { uError("failed to bind TCP port:%d since %s", port, strerror(errno)); + taosCloseSocket(&pSocket); return NULL; } - if (taosKeepTcpAlive(serverSocket) < 0) { + if (taosKeepTcpAlive(pSocket) < 0) { uError("failed to set tcp server keep-alive option since %s", strerror(errno)); - taosCloseSocket(serverSocket); + taosCloseSocket(&pSocket); return NULL; } if (listen(serverSocket, 10) < 0) { uError("failed to listen TCP port:%d since %s", port, strerror(errno)); + taosCloseSocket(&pSocket); return NULL; } @@ -163,26 +183,26 @@ static void *taosNetBindTcpPort(void *sarg) { continue; } - int32_t ret = taosReadMsg(client, buffer, pinfo->pktLen); + int32_t ret = taosReadMsg(pSocket, buffer, pinfo->pktLen); if (ret < 0 || ret != pinfo->pktLen) { uError("TCP: failed to read %d bytes at port:%d since %s", pinfo->pktLen, port, strerror(errno)); - taosCloseSocket(serverSocket); + taosCloseSocket(&pSocket); return NULL; } uInfo("TCP: read:%d bytes from %s at %d", pinfo->pktLen, taosInetNtoa(clientAddr.sin_addr), port); - ret = taosWriteMsg(client, buffer, pinfo->pktLen); + ret = taosWriteMsg(pSocket, buffer, pinfo->pktLen); if (ret < 0) { uError("TCP: failed to write %d bytes at %d since %s", pinfo->pktLen, port, strerror(errno)); - taosCloseSocket(serverSocket); + taosCloseSocket(&pSocket); return NULL; } uInfo("TCP: write:%d bytes to %s at %d", pinfo->pktLen, taosInetNtoa(clientAddr.sin_addr), port); } - taosCloseSocket(serverSocket); + taosCloseSocket(&pSocket); return NULL; } @@ -196,9 +216,17 @@ static int32_t taosNetCheckTcpPort(STestInfo *info) { } int32_t reuse = 1; - if (taosSetSockOpt(clientSocket, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { + TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + if (pSocket == NULL) { + taosCloseSocketNoCheck1(clientSocket); + return -1; + } + pSocket->fd = clientSocket; + pSocket->refId = 0; + + if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { uError("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); - taosCloseSocket(clientSocket); + taosCloseSocket(&pSocket); return -1; } @@ -210,27 +238,30 @@ static int32_t taosNetCheckTcpPort(STestInfo *info) { if (connect(clientSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0) { uError("TCP: failed to connect port %s:%d since %s", taosIpStr(info->hostIp), info->port, strerror(errno)); + taosCloseSocket(&pSocket); return -1; } - taosKeepTcpAlive(clientSocket); + taosKeepTcpAlive(pSocket); sprintf(buffer, "client send TCP pkg to %s:%d, content: 1122334455", taosIpStr(info->hostIp), info->port); sprintf(buffer + info->pktLen - 16, "1122334455667788"); - int32_t ret = taosWriteMsg(clientSocket, buffer, info->pktLen); + int32_t ret = taosWriteMsg(pSocket, buffer, info->pktLen); if (ret < 0) { uError("TCP: failed to write msg to %s:%d since %s", taosIpStr(info->hostIp), info->port, strerror(errno)); + taosCloseSocket(&pSocket); return -1; } - ret = taosReadMsg(clientSocket, buffer, info->pktLen); + ret = taosReadMsg(pSocket, buffer, info->pktLen); if (ret < 0) { uError("TCP: failed to read msg from %s:%d since %s", taosIpStr(info->hostIp), info->port, strerror(errno)); + taosCloseSocket(&pSocket); return -1; } - taosCloseSocket(clientSocket); + taosCloseSocket(&pSocket); return 0; } @@ -247,13 +278,23 @@ static int32_t taosNetCheckUdpPort(STestInfo *info) { return -1; } - if (taosSetSockOpt(clientSocket, SOL_SOCKET, SO_SNDBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { + TdSocketPtr pSocket = (TdSocketPtr)malloc(sizeof(TdSocket)); + if (pSocket == NULL) { + taosCloseSocketNoCheck1(clientSocket); + return -1; + } + pSocket->fd = clientSocket; + pSocket->refId = 0; + + if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_SNDBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { uError("failed to set the send buffer size for UDP socket\n"); + taosCloseSocket(&pSocket); return -1; } - if (taosSetSockOpt(clientSocket, SOL_SOCKET, SO_RCVBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { + if (taosSetSockOpt(pSocket, SOL_SOCKET, SO_RCVBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { uError("failed to set the receive buffer size for UDP socket\n"); + taosCloseSocket(&pSocket); return -1; } @@ -268,9 +309,10 @@ static int32_t taosNetCheckUdpPort(STestInfo *info) { socklen_t sin_size = sizeof(*(struct sockaddr *)&serverAddr); - iDataNum = taosSendto(clientSocket, buffer, info->pktLen, 0, (struct sockaddr *)&serverAddr, (int32_t)sin_size); + iDataNum = taosSendto(pSocket, buffer, info->pktLen, 0, (struct sockaddr *)&serverAddr, (int32_t)sin_size); if (iDataNum < 0 || iDataNum != info->pktLen) { uError("UDP: failed to perform sendto func since %s", strerror(errno)); + taosCloseSocket(&pSocket); return -1; } @@ -280,10 +322,11 @@ static int32_t taosNetCheckUdpPort(STestInfo *info) { if (iDataNum < 0 || iDataNum != info->pktLen) { uError("UDP: received ack:%d bytes(expect:%d) from port:%d since %s", iDataNum, info->pktLen, info->port, strerror(errno)); + taosCloseSocket(&pSocket); return -1; } - taosCloseSocket(clientSocket); + taosCloseSocket(&pSocket); return 0; } @@ -339,7 +382,7 @@ void *taosNetInitRpc(char *secretEncrypt, char spi) { } static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t pktLen, char spi, SStartupReq *pStep) { - SRpcEpSet epSet; + SEpSet epSet; SRpcMsg reqMsg; SRpcMsg rspMsg; void * pRpcConn; @@ -352,11 +395,10 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p return TSDB_CODE_RPC_NETWORK_UNAVAIL; } - memset(&epSet, 0, sizeof(SRpcEpSet)); - epSet.inUse = 0; + memset(&epSet, 0, sizeof(SEpSet)); + strcpy(epSet.eps[0].fqdn, serverFqdn); + epSet.eps[0].port = port; epSet.numOfEps = 1; - epSet.port[0] = port; - strcpy(epSet.fqdn[0], serverFqdn); reqMsg.msgType = TDMT_DND_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pktLen); @@ -425,8 +467,8 @@ static void taosNetCheckSync(char *host, int32_t port) { return; } - SOCKET connFd = taosOpenTcpClientSocket(ip, (uint16_t)port, 0); - if (connFd < 0) { + TdSocketPtr pSocket = taosOpenTcpClientSocket(ip, (uint16_t)port, 0); + if (pSocket == NULL) { uError("failed to create socket while test port:%d since %s", port, strerror(errno)); return; } @@ -443,17 +485,17 @@ static void taosNetCheckSync(char *host, int32_t port) { pHead->len = sizeof(SSyncMsg) - sizeof(SSyncHead); taosCalcChecksumAppend(0, (uint8_t *)pHead, sizeof(SSyncHead)); - if (taosWriteMsg(connFd, &msg, sizeof(SSyncMsg)) != sizeof(SSyncMsg)) { + if (taosWriteMsg(pSocket, &msg, sizeof(SSyncMsg)) != sizeof(SSyncMsg)) { uError("failed to test port:%d while send msg since %s", port, strerror(errno)); return; } - if (taosReadMsg(connFd, &msg, sizeof(SSyncMsg)) != sizeof(SSyncMsg)) { + if (taosReadMsg(pSocket, &msg, sizeof(SSyncMsg)) != sizeof(SSyncMsg)) { uError("failed to test port:%d while recv msg since %s", port, strerror(errno)); } uInfo("successed to test TCP port:%d", port); - taosCloseSocket(connFd); + taosCloseSocket(&pSocket); } static void taosNetTestRpc(char *host, int32_t startPort, int32_t pkgLen) { @@ -494,7 +536,6 @@ static void taosNetTestRpc(char *host, int32_t startPort, int32_t pkgLen) { } taosNetCheckSync(host, startPort + TSDB_PORT_SYNC); - taosNetCheckSync(host, startPort + TSDB_PORT_ARBITRATOR); } static void taosNetTestClient(char *host, int32_t startPort, int32_t pkgLen) { @@ -578,7 +619,7 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, } tsCompressMsgSize = -1; - SRpcEpSet epSet; + SEpSet epSet; SRpcMsg reqMsg; SRpcMsg rspMsg; void * pRpcConn; @@ -596,11 +637,10 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, for (int32_t i = 1; i <= pkgNum; i++) { uint64_t startTime = taosGetTimestampUs(); - memset(&epSet, 0, sizeof(SRpcEpSet)); - epSet.inUse = 0; + memset(&epSet, 0, sizeof(SEpSet)); + strcpy(epSet.eps[0].fqdn, host); + epSet.eps[0].port = port; epSet.numOfEps = 1; - epSet.port[0] = port; - strcpy(epSet.fqdn[0], host); reqMsg.msgType = TDMT_DND_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pkgLen); @@ -641,7 +681,7 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen, int32_t pkgNum, char *pkgType) { - tscEmbedded = 1; + tsLogEmbedded = 1; if (host == NULL) host = tsLocalFqdn; if (port == 0) port = tsServerPort; if (0 == strcmp("speed", role)){ @@ -659,14 +699,14 @@ void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen, } else if (0 == strcmp("server", role)) { taosNetTestServer(host, port, pkgLen); } else if (0 == strcmp("rpc", role)) { - tscEmbedded = 0; + tsLogEmbedded = 0; taosNetTestRpc(host, port, pkgLen); } else if (0 == strcmp("sync", role)) { taosNetCheckSync(host, port); } else if (0 == strcmp("startup", role)) { taosNetTestStartup(host, port); } else if (0 == strcmp("speed", role)) { - tscEmbedded = 0; + tsLogEmbedded = 0; char type[10] = {0}; taosNetCheckSpeed(host, port, pkgLen, pkgNum, strtolower(type, pkgType)); }else if (0 == strcmp("fqdn", role)) { @@ -675,5 +715,5 @@ void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen, taosNetTestStartup(host, port); } - tscEmbedded = 0; + tsLogEmbedded = 0; } From 492cb92348d6e76abd3319627d3bf6013e090361 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 23 Mar 2022 19:58:32 +0800 Subject: [PATCH 57/68] extract output name from ast --- example/src/tstream.c | 2 +- include/common/tmsg.h | 7 +++++ source/dnode/mnode/impl/inc/mndDef.h | 2 +- source/dnode/mnode/impl/src/mndDef.c | 21 +++++++++++++++ source/dnode/mnode/impl/src/mndStream.c | 35 +++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/example/src/tstream.c b/example/src/tstream.c index 6976d9e398..51578bd27b 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -78,7 +78,7 @@ int32_t create_stream() { taos_free_result(pRes); /*const char* sql = "select min(k), max(k), sum(k) from tu1";*/ - const char* sql = "select min(k), max(k), sum(k) from st1"; + const char* sql = "select min(k), max(k), sum(k) as sum_of_k from st1"; /*const char* sql = "select sum(k) from tu1 interval(10m)";*/ pRes = tmq_create_stream(pConn, "stream1", "out1", sql); if (taos_errno(pRes) != 0) { diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 812025e8e4..6a7edb481f 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2374,6 +2374,13 @@ typedef struct { int32_t reserved; } SStreamTaskExecRsp; +typedef struct { + SMsgHead head; + int64_t streamId; + int64_t version; + SArray* res; // SArray +} SStreamSmaSinkReq; + #pragma pack(pop) #ifdef __cplusplus diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 909486aaac..30b4c923d9 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -697,12 +697,12 @@ typedef struct { char* logicalPlan; char* physicalPlan; SArray* tasks; // SArray> + SArray* outputName; } SStreamObj; int32_t tEncodeSStreamObj(SCoder* pEncoder, const SStreamObj* pObj); int32_t tDecodeSStreamObj(SCoder* pDecoder, SStreamObj* pObj); - #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index f81dead325..f0905f88d2 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -16,6 +16,7 @@ #include "mndDef.h" int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { + int32_t outputNameSz = 0; if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1; if (tEncodeCStr(pEncoder, pObj->db) < 0) return -1; if (tEncodeI64(pEncoder, pObj->createTime) < 0) return -1; @@ -43,6 +44,15 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { } else { tEncodeI32(pEncoder, 0); } + + if (pObj->outputName != NULL) { + outputNameSz = taosArrayGetSize(pObj->outputName); + } + if (tEncodeI32(pEncoder, outputNameSz) < 0) return -1; + for (int32_t i = 0; i < outputNameSz; i++) { + char *name = taosArrayGetP(pObj->outputName, i); + if (tEncodeCStr(pEncoder, name) < 0) return -1; + } return pEncoder->pos; } @@ -76,5 +86,16 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) { } else { pObj->tasks = NULL; } + int32_t outputNameSz; + if (tDecodeI32(pDecoder, &outputNameSz) < 0) return -1; + pObj->outputName = taosArrayInit(outputNameSz, sizeof(void *)); + if (pObj->outputName == NULL) { + return -1; + } + for (int32_t i = 0; i < outputNameSz; i++) { + char *name; + if (tDecodeCStrAlloc(pDecoder, &name) < 0) return -1; + taosArrayPush(pObj->outputName, &name); + } return 0; } diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 2ca4e10f68..d9b5341ba1 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -218,6 +218,28 @@ static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) { return 0; } +static SArray *mndExtractNamesFromAst(const SNode *pAst) { + if (pAst->type != QUERY_NODE_SELECT_STMT) return NULL; + + SArray *names = taosArrayInit(0, sizeof(void *)); + if (names == NULL) { + return NULL; + } + SSelectStmt *pSelect = (SSelectStmt *)pAst; + SNodeList *pNodes = pSelect->pProjectionList; + SListCell *pCell = pNodes->pHead; + while (pCell != NULL) { + if (pCell->pNode->type != QUERY_NODE_FUNCTION) { + continue; + } + SFunctionNode *pFunction = (SFunctionNode *)pCell->pNode; + char *name = strdup(pFunction->node.aliasName); + taosArrayPush(names, &name); + pCell = pCell->pNext; + } + return names; +} + static int32_t mndStreamGetPlanString(const SCMCreateStreamReq *pCreate, char **pStr) { if (NULL == pCreate->ast) { return TSDB_CODE_SUCCESS; @@ -259,6 +281,19 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe /*streamObj.physicalPlan = "";*/ streamObj.logicalPlan = "not implemented"; + SNode *pAst = NULL; + if (nodesStringToNode(pCreate->ast, &pAst) < 0) { + return -1; + } + SArray *names = mndExtractNamesFromAst(pAst); + printf("|"); + for (int i = 0; i < taosArrayGetSize(names); i++) { + printf(" %15s |", (char *)taosArrayGetP(names, i)); + } + printf("\n=======================================================\n"); + + streamObj.outputName = names; + if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(pCreate, &streamObj.physicalPlan)) { mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr()); return -1; From e9831674b231110dae66b486c851f547a4b4aa09 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Mar 2022 17:53:00 +0800 Subject: [PATCH 58/68] sma --- include/common/tmsg.h | 14 +- include/util/taoserror.h | 2 + source/common/src/tmsg.c | 38 ++- source/dnode/mgmt/mnode/src/mmMsg.c | 2 + source/dnode/mgmt/vnode/src/vmMsg.c | 3 + source/dnode/mnode/impl/inc/mndDef.h | 10 +- source/dnode/mnode/impl/inc/mndInt.h | 6 +- source/dnode/mnode/impl/src/mndShow.c | 2 + source/dnode/mnode/impl/src/mndSma.c | 177 +++++++------ source/dnode/mnode/impl/src/mndStb.c | 19 +- source/dnode/mnode/impl/src/mndStream.c | 2 +- source/dnode/mnode/impl/src/mnode.c | 10 +- source/dnode/mnode/impl/test/CMakeLists.txt | 1 + .../dnode/mnode/impl/test/sma/CMakeLists.txt | 11 + source/dnode/mnode/impl/test/sma/sma.cpp | 236 ++++++++++++++++++ source/dnode/vnode/src/vnd/vnodeWrite.c | 4 + source/util/src/terror.c | 2 + 17 files changed, 444 insertions(+), 95 deletions(-) create mode 100644 source/dnode/mnode/impl/test/sma/CMakeLists.txt create mode 100644 source/dnode/mnode/impl/test/sma/sma.cpp diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 4fc3f6ce8f..0df8cff670 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -270,9 +270,10 @@ typedef struct { int8_t igExists; int32_t numOfColumns; int32_t numOfTags; + int32_t commentLen; SArray* pColumns; SArray* pTags; - char comment[TSDB_STB_COMMENT_LEN]; + char *comment; } SMCreateStbReq; int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq); @@ -1906,13 +1907,18 @@ typedef struct { int8_t intervalUnit; int8_t slidingUnit; int8_t timezone; + int32_t dstVgId; // for stream int64_t interval; int64_t offset; int64_t sliding; - int32_t exprLen; - int32_t tagsFilterLen; - char* expr; + int32_t exprLen; // strlen + 1 + int32_t tagsFilterLen; // strlen + 1 + int32_t sqlLen; // strlen + 1 + int32_t astLen; // strlen + 1 + char* expr; char* tagsFilter; + char* sql; + char* ast; } SMCreateSmaReq; int32_t tSerializeSMCreateSmaReq(void* buf, int32_t bufLen, SMCreateSmaReq* pReq); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 09b9ac7121..6d394aa2f2 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -277,6 +277,7 @@ int32_t* taosGetErrno(); // mnode-sma #define TSDB_CODE_MND_SMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0400) #define TSDB_CODE_MND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0401) +#define TSDB_CODE_MND_INVALID_SMA_OPTION TAOS_DEF_ERROR_CODE(0, 0x0402) // dnode #define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x04A0) @@ -313,6 +314,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_VND_IS_SYNCING TAOS_DEF_ERROR_CODE(0, 0x0513) #define TSDB_CODE_VND_INVALID_TSDB_STATE TAOS_DEF_ERROR_CODE(0, 0x0514) #define TSDB_CODE_VND_TB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0515) +#define TSDB_CODE_VND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0516) // tsdb #define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index d4e9dfed73..4692a77ff9 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -430,6 +430,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfTags) < 0) return -1; + if (tEncodeI32(&encoder, pReq->commentLen) < 0) return -1; for (int32_t i = 0; i < pReq->numOfColumns; ++i) { SField *pField = taosArrayGet(pReq->pColumns, i); @@ -445,7 +446,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq if (tEncodeCStr(&encoder, pField->name) < 0) return -1; } - if (tEncodeCStr(&encoder, pReq->comment) < 0) return -1; + if (tEncodeBinary(&encoder, pReq->comment, pReq->commentLen) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -462,6 +463,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfTags) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1; pReq->pColumns = taosArrayInit(pReq->numOfColumns, sizeof(SField)); pReq->pTags = taosArrayInit(pReq->numOfTags, sizeof(SField)); @@ -492,6 +494,12 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR } } + if (pReq->commentLen > 0) { + pReq->comment = malloc(pReq->commentLen); + if (pReq->comment == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; + } + if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; tEndDecode(&decoder); @@ -600,17 +608,26 @@ int32_t tSerializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pReq if (tEncodeI8(&encoder, pReq->intervalUnit) < 0) return -1; if (tEncodeI8(&encoder, pReq->slidingUnit) < 0) return -1; if (tEncodeI8(&encoder, pReq->timezone) < 0) return -1; + if (tEncodeI32(&encoder, pReq->dstVgId) < 0) return -1; if (tEncodeI64(&encoder, pReq->interval) < 0) return -1; if (tEncodeI64(&encoder, pReq->offset) < 0) return -1; if (tEncodeI64(&encoder, pReq->sliding) < 0) return -1; if (tEncodeI32(&encoder, pReq->exprLen) < 0) return -1; + if (tEncodeI32(&encoder, pReq->tagsFilterLen) < 0) return -1; + if (tEncodeI32(&encoder, pReq->sqlLen) < 0) return -1; + if (tEncodeI32(&encoder, pReq->astLen) < 0) return -1; if (pReq->exprLen > 0) { if (tEncodeBinary(&encoder, pReq->expr, pReq->exprLen) < 0) return -1; } - if (tEncodeI32(&encoder, pReq->tagsFilterLen) < 0) return -1; if (pReq->tagsFilterLen > 0) { if (tEncodeBinary(&encoder, pReq->tagsFilter, pReq->tagsFilterLen) < 0) return -1; } + if (pReq->sqlLen > 0) { + if (tEncodeBinary(&encoder, pReq->sql, pReq->sqlLen) < 0) return -1; + } + if (pReq->astLen > 0) { + if (tEncodeBinary(&encoder, pReq->ast, pReq->astLen) < 0) return -1; + } tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -629,21 +646,34 @@ int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pR if (tDecodeI8(&decoder, &pReq->intervalUnit) < 0) return -1; if (tDecodeI8(&decoder, &pReq->slidingUnit) < 0) return -1; if (tDecodeI8(&decoder, &pReq->timezone) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->dstVgId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->interval) < 0) return -1; if (tDecodeI64(&decoder, &pReq->offset) < 0) return -1; if (tDecodeI64(&decoder, &pReq->sliding) < 0) return -1; if (tDecodeI32(&decoder, &pReq->exprLen) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->tagsFilterLen) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->sqlLen) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->astLen) < 0) return -1; if (pReq->exprLen > 0) { pReq->expr = malloc(pReq->exprLen); if (pReq->expr == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->expr) < 0) return -1; } - if (tDecodeI32(&decoder, &pReq->tagsFilterLen) < 0) return -1; if (pReq->tagsFilterLen > 0) { pReq->tagsFilter = malloc(pReq->tagsFilterLen); if (pReq->tagsFilter == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->tagsFilter) < 0) return -1; } + if (pReq->sqlLen > 0) { + pReq->sql = malloc(pReq->sqlLen); + if (pReq->sql == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1; + } + if (pReq->astLen > 0) { + pReq->ast = malloc(pReq->astLen); + if (pReq->ast == NULL) return -1; + if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1; + } tEndDecode(&decoder); tCoderClear(&decoder); @@ -653,6 +683,8 @@ int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pR void tFreeSMCreateSmaReq(SMCreateSmaReq *pReq) { tfree(pReq->expr); tfree(pReq->tagsFilter); + tfree(pReq->sql); + tfree(pReq->ast); } int32_t tSerializeSMDropSmaReq(void *buf, int32_t bufLen, SMDropSmaReq *pReq) { diff --git a/source/dnode/mgmt/mnode/src/mmMsg.c b/source/dnode/mgmt/mnode/src/mmMsg.c index b6ff4f3ae1..d6d65be41c 100644 --- a/source/dnode/mgmt/mnode/src/mmMsg.c +++ b/source/dnode/mgmt/mnode/src/mmMsg.c @@ -150,5 +150,7 @@ void mmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, (NodeMsgFp)mmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)mmProcessWriteMsg, 0); } diff --git a/source/dnode/mgmt/vnode/src/vmMsg.c b/source/dnode/mgmt/vnode/src/vmMsg.c index e4a4cfcd9f..08901504f4 100644 --- a/source/dnode/mgmt/vnode/src/vmMsg.c +++ b/source/dnode/mgmt/vnode/src/vmMsg.c @@ -268,6 +268,9 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, 0); + dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)vmProcessFetchMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, (NodeMsgFp)vmProcessFetchMsg, 0); dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, 0); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 1be5279d17..c5372f6875 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -318,13 +318,18 @@ typedef struct { int8_t intervalUnit; int8_t slidingUnit; int8_t timezone; + int32_t dstVgId; // for stream int64_t interval; int64_t offset; int64_t sliding; - int32_t exprLen; + int32_t exprLen; // strlen + 1 int32_t tagsFilterLen; + int32_t sqlLen; + int32_t astLen; char* expr; char* tagsFilter; + char* sql; + char* ast; } SSmaObj; typedef struct { @@ -338,10 +343,11 @@ typedef struct { int32_t nextColId; int32_t numOfColumns; int32_t numOfTags; + int32_t commentLen; SSchema* pColumns; SSchema* pTags; + char* comment; SRWLatch lock; - char comment[TSDB_STB_COMMENT_LEN]; } SStbObj; typedef struct { diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index d5bffada6a..20e85973be 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -122,9 +122,9 @@ typedef struct SMnode { SMsgCb msgCb; } SMnode; -void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); -uint64_t mndGenerateUid(char *name, int32_t len); -void mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); +void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); +int64_t mndGenerateUid(char *name, int32_t len); +void mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 33a8b7fbe5..d675d441ba 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -411,6 +411,8 @@ char *mndShowStr(int32_t showType) { return "show topics"; case TSDB_MGMT_TABLE_FUNC: return "show functions"; + case TSDB_MGMT_TABLE_INDEX: + return "show indexes"; default: return "undefined"; } diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index bd459b873b..2bd13f395f 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -84,17 +84,29 @@ static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) { SDB_SET_INT8(pRaw, dataPos, pSma->intervalUnit, _OVER) SDB_SET_INT8(pRaw, dataPos, pSma->slidingUnit, _OVER) SDB_SET_INT8(pRaw, dataPos, pSma->timezone, _OVER) + SDB_SET_INT32(pRaw, dataPos, pSma->dstVgId, _OVER) SDB_SET_INT64(pRaw, dataPos, pSma->interval, _OVER) SDB_SET_INT64(pRaw, dataPos, pSma->offset, _OVER) SDB_SET_INT64(pRaw, dataPos, pSma->sliding, _OVER) SDB_SET_INT32(pRaw, dataPos, pSma->exprLen, _OVER) SDB_SET_INT32(pRaw, dataPos, pSma->tagsFilterLen, _OVER) - SDB_SET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER) - SDB_SET_BINARY(pRaw, dataPos, pSma->tagsFilter, pSma->tagsFilterLen, _OVER) + SDB_SET_INT32(pRaw, dataPos, pSma->sqlLen, _OVER) + SDB_SET_INT32(pRaw, dataPos, pSma->astLen, _OVER) + if (pSma->exprLen > 0) { + SDB_SET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER) + } + if (pSma->tagsFilterLen > 0) { + SDB_SET_BINARY(pRaw, dataPos, pSma->tagsFilter, pSma->tagsFilterLen, _OVER) + } + if (pSma->sqlLen > 0) { + SDB_SET_BINARY(pRaw, dataPos, pSma->sql, pSma->sqlLen, _OVER) + } + if (pSma->astLen > 0) { + SDB_SET_BINARY(pRaw, dataPos, pSma->ast, pSma->astLen, _OVER) + } SDB_SET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER) SDB_SET_DATALEN(pRaw, dataPos, _OVER) - terrno = 0; _OVER: @@ -137,22 +149,40 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) { SDB_GET_INT8(pRaw, dataPos, &pSma->intervalUnit, _OVER) SDB_GET_INT8(pRaw, dataPos, &pSma->slidingUnit, _OVER) SDB_GET_INT8(pRaw, dataPos, &pSma->timezone, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pSma->dstVgId, _OVER) SDB_GET_INT64(pRaw, dataPos, &pSma->interval, _OVER) SDB_GET_INT64(pRaw, dataPos, &pSma->offset, _OVER) SDB_GET_INT64(pRaw, dataPos, &pSma->sliding, _OVER) SDB_GET_INT32(pRaw, dataPos, &pSma->exprLen, _OVER) SDB_GET_INT32(pRaw, dataPos, &pSma->tagsFilterLen, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pSma->sqlLen, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pSma->astLen, _OVER) - pSma->expr = calloc(pSma->exprLen, 1); - pSma->tagsFilter = calloc(pSma->tagsFilterLen, 1); - if (pSma->expr == NULL || pSma->tagsFilter == NULL) { - goto _OVER; + if (pSma->exprLen > 0) { + pSma->expr = calloc(pSma->exprLen, 1); + if (pSma->expr == NULL) goto _OVER; + SDB_GET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER) } - SDB_GET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER) - SDB_GET_BINARY(pRaw, dataPos, pSma->tagsFilter, pSma->tagsFilterLen, _OVER) - SDB_GET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER) + if (pSma->tagsFilterLen > 0) { + pSma->tagsFilter = calloc(pSma->tagsFilterLen, 1); + if (pSma->tagsFilter == NULL) goto _OVER; + SDB_GET_BINARY(pRaw, dataPos, pSma->tagsFilter, pSma->tagsFilterLen, _OVER) + } + if (pSma->sqlLen > 0) { + pSma->sql = calloc(pSma->sqlLen, 1); + if (pSma->sql == NULL) goto _OVER; + SDB_GET_BINARY(pRaw, dataPos, pSma->sql, pSma->sqlLen, _OVER) + } + + if (pSma->astLen > 0) { + pSma->ast = calloc(pSma->astLen, 1); + if (pSma->ast == NULL) goto _OVER; + SDB_GET_BINARY(pRaw, dataPos, pSma->ast, pSma->astLen, _OVER) + } + + SDB_GET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER) terrno = 0; _OVER: @@ -217,7 +247,7 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm req.tSma.version = 0; req.tSma.intervalUnit = pSma->intervalUnit; req.tSma.slidingUnit = pSma->slidingUnit; - req.tSma.slidingUnit = pSma->timezone; + req.tSma.timezoneInt = pSma->timezone; tstrncpy(req.tSma.indexName, (char *)tNameGetTableName(&name), TSDB_INDEX_NAME_LEN); req.tSma.exprLen = pSma->exprLen; req.tSma.tagsFilterLen = pSma->tagsFilterLen; @@ -281,15 +311,6 @@ static int32_t mndSetCreateSmaRedoLogs(SMnode *pMnode, STrans *pTrans, SSmaObj * return 0; } -static int32_t mndSetCreateSmaUndoLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { - SSdbRaw *pUndoRaw = mndSmaActionEncode(pSma); - if (pUndoRaw == NULL) return -1; - if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; - if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; - - return 0; -} - static int32_t mndSetCreateSmaCommitLogs(SMnode *pMnode, STrans *pTrans, SSmaObj *pSma) { SSdbRaw *pCommitRaw = mndSmaActionEncode(pSma); if (pCommitRaw == NULL) return -1; @@ -338,77 +359,61 @@ static int32_t mndSetCreateSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj return 0; } -static int32_t mndSetCreateSmaUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SSmaObj *pSma) { - SSdb *pSdb = pMnode->pSdb; - SVgObj *pVgroup = NULL; - void *pIter = NULL; - - while (1) { - pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); - if (pIter == NULL) break; - if (pVgroup->dbUid != pDb->uid) { - sdbRelease(pSdb, pVgroup); - continue; - } - - int32_t contLen = 0; - void *pReq = mndBuildVDropSmaReq(pMnode, pVgroup, pSma, &contLen); - if (pReq == NULL) { - sdbCancelFetch(pSdb, pIter); - sdbRelease(pSdb, pVgroup); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - STransAction action = {0}; - action.epSet = mndGetVgroupEpset(pMnode, pVgroup); - action.pCont = pReq; - action.contLen = contLen; - action.msgType = TDMT_VND_DROP_SMA; - if (mndTransAppendUndoAction(pTrans, &action) != 0) { - free(pReq); - sdbCancelFetch(pSdb, pIter); - sdbRelease(pSdb, pVgroup); - return -1; - } - sdbRelease(pSdb, pVgroup); - } - - return 0; -} - -static int32_t mndCreateTSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCreate, SDbObj *pDb, SStbObj *pStb) { +static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCreate, SDbObj *pDb, SStbObj *pStb) { SSmaObj smaObj = {0}; memcpy(smaObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN); memcpy(smaObj.stb, pStb->name, TSDB_TABLE_FNAME_LEN); + memcpy(smaObj.db, pDb->name, TSDB_DB_FNAME_LEN); smaObj.createdTime = taosGetTimestampMs(); smaObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN); smaObj.stbUid = pStb->uid; + smaObj.dbUid = pStb->dbUid; smaObj.intervalUnit = pCreate->intervalUnit; smaObj.slidingUnit = pCreate->slidingUnit; smaObj.timezone = pCreate->timezone; + smaObj.dstVgId = pCreate->dstVgId; smaObj.interval = pCreate->interval; smaObj.offset = pCreate->offset; smaObj.sliding = pCreate->sliding; smaObj.exprLen = pCreate->exprLen; smaObj.tagsFilterLen = pCreate->tagsFilterLen; - smaObj.expr = pCreate->expr; - pCreate->expr = NULL; - smaObj.tagsFilter = pCreate->tagsFilter; - pCreate->tagsFilter = NULL; + smaObj.sqlLen = pCreate->sqlLen; + smaObj.astLen = pCreate->astLen; + + if (smaObj.exprLen > 0) { + smaObj.expr = malloc(smaObj.exprLen); + if (smaObj.expr == NULL) goto _OVER; + memcpy(smaObj.expr, pCreate->expr, smaObj.exprLen); + } + + if (smaObj.tagsFilterLen > 0) { + smaObj.tagsFilter = malloc(smaObj.tagsFilterLen); + if (smaObj.tagsFilter == NULL) goto _OVER; + memcpy(smaObj.tagsFilter, pCreate->tagsFilter, smaObj.tagsFilterLen); + } + + if (smaObj.sqlLen > 0) { + smaObj.sql = malloc(smaObj.sqlLen); + if (smaObj.sql == NULL) goto _OVER; + memcpy(smaObj.sql, pCreate->sql, smaObj.sqlLen); + } + + if (smaObj.astLen > 0) { + smaObj.ast = malloc(smaObj.astLen); + if (smaObj.ast == NULL) goto _OVER; + memcpy(smaObj.ast, pCreate->ast, smaObj.astLen); + } int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_SMA, &pReq->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_SMA, &pReq->rpcMsg); if (pTrans == NULL) goto _OVER; mDebug("trans:%d, used to create sma:%s", pTrans->id, pCreate->name); mndTransSetDbInfo(pTrans, pDb); if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; - if (mndSetCreateSmaUndoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; - if (mndSetCreateSmaUndoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; @@ -419,11 +424,31 @@ _OVER: } static int32_t mndCheckCreateSmaReq(SMCreateSmaReq *pCreate) { - if (pCreate->igExists < 0 || pCreate->igExists > 1) { - terrno = TSDB_CODE_MND_INVALID_STB_OPTION; - return -1; - } + terrno = TSDB_CODE_MND_INVALID_SMA_OPTION; + if (pCreate->name[0] == 0) return -1; + if (pCreate->stb[0] == 0) return -1; + if (pCreate->igExists < 0 || pCreate->igExists > 1) return -1; + if (pCreate->intervalUnit < 0) return -1; + if (pCreate->slidingUnit < 0) return -1; + if (pCreate->timezone < 0) return -1; + if (pCreate->dstVgId < 0) return -1; + if (pCreate->interval < 0) return -1; + if (pCreate->offset < 0) return -1; + if (pCreate->sliding < 0) return -1; + if (pCreate->exprLen < 0) return -1; + if (pCreate->tagsFilterLen < 0) return -1; + if (pCreate->sqlLen < 0) return -1; + if (pCreate->astLen < 0) return -1; + if (pCreate->exprLen != 0 && strlen(pCreate->expr) + 1 != pCreate->exprLen) return -1; + if (pCreate->tagsFilterLen != 0 && strlen(pCreate->tagsFilter) + 1 != pCreate->tagsFilterLen) return -1; + if (pCreate->sqlLen != 0 && strlen(pCreate->sql) + 1 != pCreate->sqlLen) return -1; + if (pCreate->astLen != 0 && strlen(pCreate->ast) + 1 != pCreate->astLen) return -1; + SName smaName = {0}; + if (tNameFromString(&smaName, pCreate->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE) < 0) return -1; + if (*(char *)tNameGetTableName(&smaName) == 0) return -1; + + terrno = 0; return 0; } @@ -479,7 +504,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) { goto _OVER; } - code = mndCreateTSma(pMnode, pReq, &createReq, pDb, pStb); + code = mndCreateSma(pMnode, pReq, &createReq, pDb, pStb); if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; _OVER: @@ -547,7 +572,7 @@ static int32_t mndSetDropSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * action.pCont = pReq; action.contLen = contLen; action.msgType = TDMT_VND_DROP_SMA; - action.acceptableCode = TSDB_CODE_VND_TB_NOT_EXIST; + action.acceptableCode = TSDB_CODE_VND_SMA_NOT_EXIST; if (mndTransAppendRedoAction(pTrans, &action) != 0) { free(pReq); sdbCancelFetch(pSdb, pIter); @@ -562,7 +587,7 @@ static int32_t mndSetDropSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * static int32_t mndDropSma(SMnode *pMnode, SNodeMsg *pReq, SDbObj *pDb, SSmaObj *pSma) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_STB, &pReq->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_SMA, &pReq->rpcMsg); if (pTrans == NULL) goto _OVER; mDebug("trans:%d, used to drop sma:%s", pTrans->id, pSma->name); @@ -649,7 +674,7 @@ static int32_t mndGetSmaMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMe int32_t cols = 0; SSchema *pSchema = pMeta->pSchemas; - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + pShow->bytes[cols] = TSDB_INDEX_NAME_LEN + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "name"); pSchema[cols].bytes = pShow->bytes[cols]; @@ -663,7 +688,7 @@ static int32_t mndGetSmaMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMe pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); + strcpy(pSchema[cols].name, "stb"); pSchema[cols].bytes = pShow->bytes[cols]; cols++; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 6bf0b383ef..47565bec8b 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -87,6 +87,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->commentLen, STB_ENCODE_OVER) for (int32_t i = 0; i < pStb->numOfColumns; ++i) { SSchema *pSchema = &pStb->pColumns[i]; @@ -104,7 +105,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER) } - SDB_SET_BINARY(pRaw, dataPos, pStb->comment, TSDB_STB_COMMENT_LEN, STB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, STB_ENCODE_OVER) SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_ENCODE_OVER) SDB_SET_DATALEN(pRaw, dataPos, STB_ENCODE_OVER) @@ -149,6 +150,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pStb->nextColId, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->commentLen, STB_DECODE_OVER) pStb->pColumns = calloc(pStb->numOfColumns, sizeof(SSchema)); pStb->pTags = calloc(pStb->numOfTags, sizeof(SSchema)); @@ -172,7 +174,11 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER) } - SDB_GET_BINARY(pRaw, dataPos, pStb->comment, TSDB_STB_COMMENT_LEN, STB_DECODE_OVER) + if (pStb->commentLen > 0) { + pStb->comment = calloc(pStb->commentLen, 1); + if (pStb->comment == NULL) goto STB_DECODE_OVER; + SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, STB_DECODE_OVER) + } SDB_GET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_DECODE_OVER) terrno = 0; @@ -182,6 +188,7 @@ STB_DECODE_OVER: mError("stb:%s, failed to decode from raw:%p since %s", pStb->name, pRaw, terrstr()); tfree(pStb->pColumns); tfree(pStb->pTags); + tfree(pStb->comment); tfree(pRow); return NULL; } @@ -199,6 +206,7 @@ static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb) { mTrace("stb:%s, perform delete action, row:%p", pStb->name, pStb); tfree(pStb->pColumns); tfree(pStb->pTags); + tfree(pStb->comment); return 0; } @@ -501,6 +509,13 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre stbObj.nextColId = 1; stbObj.numOfColumns = pCreate->numOfColumns; stbObj.numOfTags = pCreate->numOfTags; + stbObj.commentLen = pCreate->commentLen; + stbObj.comment = calloc(stbObj.commentLen, 1); + if (stbObj.comment == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + memcpy(stbObj.comment, pCreate->comment, stbObj.commentLen); stbObj.pColumns = malloc(stbObj.numOfColumns * sizeof(SSchema)); stbObj.pTags = malloc(stbObj.numOfTags * sizeof(SSchema)); diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 99aded0292..7a48d81d31 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -223,7 +223,7 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe streamObj.physicalPlan = ""; streamObj.logicalPlan = ""; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_STREAM, &pReq->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_STREAM, &pReq->rpcMsg); if (pTrans == NULL) { mError("stream:%s, failed to create since %s", pCreate->name, terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 6400bf69f1..76687fc5cc 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -28,6 +28,7 @@ #include "mndProfile.h" #include "mndQnode.h" #include "mndShow.h" +#include "mndSma.h" #include "mndSnode.h" #include "mndStb.h" #include "mndStream.h" @@ -204,6 +205,7 @@ static int32_t mndInitSteps(SMnode *pMnode) { if (mndAllocStep(pMnode, "mnode-offset", mndInitOffset, mndCleanupOffset) != 0) return -1; if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1; if (mndAllocStep(pMnode, "mnode-stb", mndInitStb, mndCleanupStb) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-stb", mndInitSma, mndCleanupSma) != 0) return -1; if (mndAllocStep(pMnode, "mnode-infos", mndInitInfos, mndCleanupInfos) != 0) return -1; if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; @@ -409,15 +411,15 @@ void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp) { } // Note: uid 0 is reserved -uint64_t mndGenerateUid(char *name, int32_t len) { +int64_t mndGenerateUid(char *name, int32_t len) { int32_t hashval = MurmurHash3_32(name, len); do { int64_t us = taosGetTimestampUs(); - uint64_t x = (us & 0x000000FFFFFFFFFF) << 24; - uint64_t uuid = x + ((hashval & ((1ul << 16) - 1ul)) << 8) + (taosRand() & ((1ul << 8) - 1ul)); + int64_t x = (us & 0x000000FFFFFFFFFF) << 24; + int64_t uuid = x + ((hashval & ((1ul << 16) - 1ul)) << 8) + (taosRand() & ((1ul << 8) - 1ul)); if (uuid) { - return uuid; + return abs(uuid); } } while (true); } diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index df0510f783..61201f33c3 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -12,5 +12,6 @@ add_subdirectory(dnode) add_subdirectory(mnode) add_subdirectory(db) add_subdirectory(stb) +add_subdirectory(sma) add_subdirectory(func) add_subdirectory(topic) diff --git a/source/dnode/mnode/impl/test/sma/CMakeLists.txt b/source/dnode/mnode/impl/test/sma/CMakeLists.txt new file mode 100644 index 0000000000..943695abf3 --- /dev/null +++ b/source/dnode/mnode/impl/test/sma/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. SMA_SRC) +add_executable(mnode_test_sma ${SMA_SRC}) +target_link_libraries( + mnode_test_sma + PUBLIC sut +) + +add_test( + NAME mnode_test_sma + COMMAND mnode_test_sma +) diff --git a/source/dnode/mnode/impl/test/sma/sma.cpp b/source/dnode/mnode/impl/test/sma/sma.cpp new file mode 100644 index 0000000000..5b48906681 --- /dev/null +++ b/source/dnode/mnode/impl/test/sma/sma.cpp @@ -0,0 +1,236 @@ +/** + * @file sma.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module sma tests + * @version 1.0 + * @date 2022-03-23 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class MndTestSma : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_sma", 9035); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} + + void* BuildCreateDbReq(const char* dbname, int32_t* pContLen); + void* BuildDropDbReq(const char* dbname, int32_t* pContLen); + void* BuildCreateStbReq(const char* stbname, int32_t* pContLen); + void* BuildDropStbReq(const char* stbname, int32_t* pContLen); + void* BuildCreateSmaReq(const char* smaname, const char* stbname, int8_t igExists, const char* expr, + const char* tagsFilter, const char* sql, const char* ast, int32_t* pContLen); + void* BuildDropSmaReq(const char* smaname, int8_t igNotExists, int32_t* pContLen); +}; + +Testbase MndTestSma::test; + +void* MndTestSma::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { + SCreateDbReq createReq = {0}; + strcpy(createReq.db, dbname); + createReq.numOfVgroups = 2; + createReq.cacheBlockSize = 16; + createReq.totalBlocks = 10; + createReq.daysPerFile = 10; + createReq.daysToKeep0 = 3650; + createReq.daysToKeep1 = 3650; + createReq.daysToKeep2 = 3650; + createReq.minRows = 100; + createReq.maxRows = 4096; + createReq.commitTime = 3600; + createReq.fsyncPeriod = 3000; + createReq.walLevel = 1; + createReq.precision = 0; + createReq.compression = 2; + createReq.replications = 1; + createReq.quorum = 1; + createReq.update = 0; + createReq.cacheLastRow = 0; + createReq.ignoreExist = 1; + + int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); + void* pReq = rpcMallocCont(contLen); + tSerializeSCreateDbReq(pReq, contLen, &createReq); + + *pContLen = contLen; + return pReq; +} + +void* MndTestSma::BuildDropDbReq(const char* dbname, int32_t* pContLen) { + SDropDbReq dropdbReq = {0}; + strcpy(dropdbReq.db, dbname); + + int32_t contLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq); + void* pReq = rpcMallocCont(contLen); + tSerializeSDropDbReq(pReq, contLen, &dropdbReq); + + *pContLen = contLen; + return pReq; +} + +void* MndTestSma::BuildCreateStbReq(const char* stbname, int32_t* pContLen) { + SMCreateStbReq createReq = {0}; + createReq.numOfColumns = 3; + createReq.numOfTags = 1; + createReq.igExists = 0; + createReq.pColumns = taosArrayInit(createReq.numOfColumns, sizeof(SField)); + createReq.pTags = taosArrayInit(createReq.numOfTags, sizeof(SField)); + strcpy(createReq.name, stbname); + + { + SField field = {0}; + field.bytes = 8; + field.type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(field.name, "ts"); + taosArrayPush(createReq.pColumns, &field); + } + + { + SField field = {0}; + field.bytes = 2; + field.type = TSDB_DATA_TYPE_TINYINT; + strcpy(field.name, "col1"); + taosArrayPush(createReq.pColumns, &field); + } + + { + SField field = {0}; + field.bytes = 8; + field.type = TSDB_DATA_TYPE_BIGINT; + strcpy(field.name, "col2"); + taosArrayPush(createReq.pColumns, &field); + } + + { + SField field = {0}; + field.bytes = 2; + field.type = TSDB_DATA_TYPE_TINYINT; + strcpy(field.name, "tag1"); + taosArrayPush(createReq.pTags, &field); + } + + int32_t tlen = tSerializeSMCreateStbReq(NULL, 0, &createReq); + void* pHead = rpcMallocCont(tlen); + tSerializeSMCreateStbReq(pHead, tlen, &createReq); + tFreeSMCreateStbReq(&createReq); + *pContLen = tlen; + return pHead; +} + +void* MndTestSma::BuildDropStbReq(const char* stbname, int32_t* pContLen) { + SMDropStbReq dropstbReq = {0}; + strcpy(dropstbReq.name, stbname); + + int32_t contLen = tSerializeSMDropStbReq(NULL, 0, &dropstbReq); + void* pReq = rpcMallocCont(contLen); + tSerializeSMDropStbReq(pReq, contLen, &dropstbReq); + + *pContLen = contLen; + return pReq; +} + +void* MndTestSma::BuildCreateSmaReq(const char* smaname, const char* stbname, int8_t igExists, const char* expr, + const char* tagsFilter, const char* sql, const char* ast, int32_t* pContLen) { + SMCreateSmaReq createReq = {0}; + strcpy(createReq.name, smaname); + strcpy(createReq.stb, stbname); + createReq.igExists = igExists; + createReq.intervalUnit = 1; + createReq.slidingUnit = 2; + createReq.timezone = 3; + createReq.dstVgId = 4; + createReq.interval = 10; + createReq.offset = 5; + createReq.sliding = 6; + createReq.expr = (char*)expr; + createReq.exprLen = strlen(createReq.expr) + 1; + createReq.tagsFilter = (char*)tagsFilter; + createReq.tagsFilterLen = strlen(createReq.tagsFilter) + 1; + createReq.sql = (char*)sql; + createReq.sqlLen = strlen(createReq.sql) + 1; + createReq.ast = (char*)expr; + createReq.astLen = strlen(createReq.ast) + 1; + + int32_t tlen = tSerializeSMCreateSmaReq(NULL, 0, &createReq); + void* pHead = rpcMallocCont(tlen); + tSerializeSMCreateSmaReq(pHead, tlen, &createReq); + *pContLen = tlen; + return pHead; +} + +void* MndTestSma::BuildDropSmaReq(const char* smaname, int8_t igNotExists, int32_t* pContLen) { + SMDropSmaReq dropsmaReq = {0}; + dropsmaReq.igNotExists = igNotExists; + strcpy(dropsmaReq.name, smaname); + + int32_t contLen = tSerializeSMDropSmaReq(NULL, 0, &dropsmaReq); + void* pReq = rpcMallocCont(contLen); + tSerializeSMDropSmaReq(pReq, contLen, &dropsmaReq); + + *pContLen = contLen; + return pReq; +} + +TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) { + const char* dbname = "1.d1"; + const char* stbname = "1.d1.stb"; + const char* smaname = "1.d1.sma"; + int32_t contLen = 0; + void* pReq; + SRpcMsg* pRsp; + + { + pReq = BuildCreateDbReq(dbname, &contLen); + pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + } + + { + pReq = BuildCreateStbReq(stbname, &contLen); + pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, dbname); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + } + + { + pReq = BuildCreateSmaReq(smaname, stbname, 0, "expr", "tagsFilter", "sql", "ast", &contLen); + pRsp = test.SendReq(TDMT_MND_CREATE_SMA, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + test.SendShowMetaReq(TSDB_MGMT_TABLE_INDEX, dbname); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + } + + // restart + test.Restart(); + + { + test.SendShowMetaReq(TSDB_MGMT_TABLE_INDEX, dbname); + CHECK_META("show indexes", 3); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckBinary("sma", TSDB_INDEX_NAME_LEN); + CheckTimestamp(); + CheckBinary("stb", TSDB_TABLE_NAME_LEN); + } + + { + pReq = BuildDropSmaReq(smaname, 0, &contLen); + pRsp = test.SendReq(TDMT_MND_DROP_SMA, pReq, contLen); + ASSERT_EQ(pRsp->code, 0); + test.SendShowMetaReq(TSDB_MGMT_TABLE_INDEX, dbname); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 0); + } +} diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index d3769b8a30..06e9c1c5db 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -141,6 +141,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } } break; case TDMT_VND_CREATE_SMA: { // timeRangeSMA +#if 0 SSmaCfg vCreateSmaReq = {0}; if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -162,10 +163,12 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // } tdDestroyTSma(&vCreateSmaReq.tSma); // TODO: return directly or go on follow steps? +#endif } break; case TDMT_VND_CANCEL_SMA: { // timeRangeSMA } break; case TDMT_VND_DROP_SMA: { // timeRangeSMA +#if 0 SVDropTSmaReq vDropSmaReq = {0}; if (tDeserializeSVDropTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vDropSmaReq) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -182,6 +185,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // return -1; // } // TODO: return directly or go on follow steps? +#endif } break; default: ASSERT(0); diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 04da9a4d09..a0eddd3a0d 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -273,6 +273,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_UNSUPPORTED_TOPIC, "Topic with aggregatio // mnode-sma TAOS_DEFINE_ERROR(TSDB_CODE_MND_SMA_ALREADY_EXIST, "SMA already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_SMA_NOT_EXIST, "SMA does not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SMA_OPTION, "Invalid sma option") // dnode TAOS_DEFINE_ERROR(TSDB_CODE_DND_ACTION_IN_PROGRESS, "Action in progress") @@ -309,6 +310,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, "Database write operat TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_SYNCING, "Database is syncing") TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_TSDB_STATE, "Invalid tsdb state") TAOS_DEFINE_ERROR(TSDB_CODE_VND_TB_NOT_EXIST, "Table not exists") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_SMA_NOT_EXIST, "SMA not exists") // tsdb TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, "Invalid table ID") From b7c31e9c06240d80811ffdc864a972fb4110f9e3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Mar 2022 20:22:22 +0800 Subject: [PATCH 59/68] crash while show stables --- source/dnode/mnode/impl/src/mndStb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 09692a729b..e8d6157661 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1582,7 +1582,11 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, pStb->comment); + if (pStb->commentLen != 0) { + STR_TO_VARSTR(pWrite, pStb->comment); + } else { + STR_TO_VARSTR(pWrite, ""); + } cols++; numOfRows++; From 6bd84f7fb204f9e91b8bc3ad81a3578396ba8130 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 23 Mar 2022 21:06:17 +0800 Subject: [PATCH 60/68] drop tSma logic of tsdb --- include/common/taosdef.h | 8 +- include/util/taoserror.h | 5 +- source/common/src/tmsg.c | 30 +-- source/dnode/vnode/inc/meta.h | 2 +- source/dnode/vnode/inc/tsdb.h | 1 + source/dnode/vnode/src/inc/metaDef.h | 2 +- source/dnode/vnode/src/inc/tsdbSma.h | 14 +- source/dnode/vnode/src/meta/metaBDBImpl.c | 2 +- source/dnode/vnode/src/meta/metaIdx.c | 4 +- source/dnode/vnode/src/tsdb/tsdbSma.c | 297 ++++++++++++++++++---- source/dnode/vnode/src/vnd/vnodeWrite.c | 16 +- source/dnode/vnode/test/tsdbSmaTest.cpp | 4 +- source/util/src/terror.c | 3 +- 13 files changed, 297 insertions(+), 91 deletions(-) diff --git a/include/common/taosdef.h b/include/common/taosdef.h index f252143fa6..4d307def10 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -63,9 +63,11 @@ typedef enum { } ETsdbStatisStatus; typedef enum { - TSDB_SMA_STAT_OK = 0, // ready to provide service - TSDB_SMA_STAT_EXPIRED = 1, // not ready or expired -} ETsdbSmaStat; + TSDB_SMA_STAT_UNKNOWN = -1, // unknown + TSDB_SMA_STAT_OK = 0, // ready to provide service + TSDB_SMA_STAT_EXPIRED = 1, // not ready or expired + TSDB_SMA_STAT_DROPPED = 2, // sma dropped +} ETsdbSmaStat; // bit operation typedef enum { TSDB_SMA_TYPE_BLOCK = 0, // Block-wise SMA diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 9e1e1c53dc..4391d58a64 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -336,8 +336,9 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615) #define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0616) #define TSDB_CODE_TDB_TABLE_RECREATED TAOS_DEF_ERROR_CODE(0, 0x0617) -#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x0618) -#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0619) +#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0618) +#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x0619) +#define TSDB_CODE_TDB_INVALID_SMA_STAT TAOS_DEF_ERROR_CODE(0, 0x0620) // query #define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 1ea00566f4..e78015d56f 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -313,7 +313,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); } - if(pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { + if(pReq->rollup && pReq->stbCfg.pRSmaParam) { SRSmaParam *param = pReq->stbCfg.pRSmaParam; tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); tlen += taosEncodeFixedI8(buf, param->delayUnit); @@ -336,12 +336,12 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes); tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name); } - tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols); - for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { - tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pBSmaCols[i]); + tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.nBSmaCols); + for (col_id_t i = 0; i < pReq->ntbCfg.nBSmaCols; ++i) { + tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.pBSmaCols[i]); } - if(pReq->rollup && NULL != pReq->stbCfg.pRSmaParam) { - SRSmaParam *param = pReq->stbCfg.pRSmaParam; + if(pReq->rollup && pReq->ntbCfg.pRSmaParam) { + SRSmaParam *param = pReq->ntbCfg.pRSmaParam; tlen += taosEncodeFixedU32(buf, (uint32_t)param->xFilesFactor); tlen += taosEncodeFixedI8(buf, param->delayUnit); tlen += taosEncodeFixedI8(buf, param->nFuncIds); @@ -424,18 +424,18 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name); } - buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols)); - if(pReq->stbCfg.nBSmaCols > 0) { - pReq->stbCfg.pBSmaCols = (col_id_t *)malloc(pReq->stbCfg.nBSmaCols * sizeof(col_id_t)); - for (col_id_t i = 0; i < pReq->stbCfg.nBSmaCols; ++i) { - buf = taosDecodeFixedI16(buf, pReq->stbCfg.pBSmaCols + i); + buf = taosDecodeFixedI16(buf, &(pReq->ntbCfg.nBSmaCols)); + if(pReq->ntbCfg.nBSmaCols > 0) { + pReq->ntbCfg.pBSmaCols = (col_id_t *)malloc(pReq->ntbCfg.nBSmaCols * sizeof(col_id_t)); + for (col_id_t i = 0; i < pReq->ntbCfg.nBSmaCols; ++i) { + buf = taosDecodeFixedI16(buf, pReq->ntbCfg.pBSmaCols + i); } } else { - pReq->stbCfg.pBSmaCols = NULL; + pReq->ntbCfg.pBSmaCols = NULL; } if(pReq->rollup) { - pReq->stbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); - SRSmaParam *param = pReq->stbCfg.pRSmaParam; + pReq->ntbCfg.pRSmaParam = (SRSmaParam *)malloc(sizeof(SRSmaParam)); + SRSmaParam *param = pReq->ntbCfg.pRSmaParam; buf = taosDecodeFixedU32(buf, (uint32_t*)¶m->xFilesFactor); buf = taosDecodeFixedI8(buf, ¶m->delayUnit); buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); @@ -448,7 +448,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { } buf = taosDecodeFixedI64(buf, ¶m->delay); } else { - pReq->stbCfg.pRSmaParam = NULL; + pReq->ntbCfg.pRSmaParam = NULL; } break; default: diff --git a/source/dnode/vnode/inc/meta.h b/source/dnode/vnode/inc/meta.h index a48f437c97..149aac1206 100644 --- a/source/dnode/vnode/inc/meta.h +++ b/source/dnode/vnode/inc/meta.h @@ -51,7 +51,7 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); int metaDropTable(SMeta *pMeta, tb_uid_t uid); int metaCommit(SMeta *pMeta); int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg); -int32_t metaDropTSma(SMeta *pMeta, char *indexName); +int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid); // For Query STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid); diff --git a/source/dnode/vnode/inc/tsdb.h b/source/dnode/vnode/inc/tsdb.h index 7b93f7580d..2b10c885b9 100644 --- a/source/dnode/vnode/inc/tsdb.h +++ b/source/dnode/vnode/inc/tsdb.h @@ -96,6 +96,7 @@ int tsdbCommit(STsdb *pTsdb); */ int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg); int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, int8_t smaType, char *msg); +int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid); /** * @brief Insert RSma(Time-range-wise Rollup SMA) data. diff --git a/source/dnode/vnode/src/inc/metaDef.h b/source/dnode/vnode/src/inc/metaDef.h index 16a53baef0..bc1017f0c7 100644 --- a/source/dnode/vnode/src/inc/metaDef.h +++ b/source/dnode/vnode/src/inc/metaDef.h @@ -34,7 +34,7 @@ void metaCloseDB(SMeta* pMeta); int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg); int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid); int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg); -int metaRemoveSmaFromDb(SMeta* pMeta, const char* indexName); +int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid); // SMetaCache int metaOpenCache(SMeta* pMeta); diff --git a/source/dnode/vnode/src/inc/tsdbSma.h b/source/dnode/vnode/src/inc/tsdbSma.h index f934b0263d..874f85994a 100644 --- a/source/dnode/vnode/src/inc/tsdbSma.h +++ b/source/dnode/vnode/src/inc/tsdbSma.h @@ -16,15 +16,15 @@ #ifndef _TD_TSDB_SMA_H_ #define _TD_TSDB_SMA_H_ -typedef struct SSmaStat SSmaStat; -typedef struct SSmaEnv SSmaEnv; +typedef struct SSmaStat SSmaStat; +typedef struct SSmaEnv SSmaEnv; struct SSmaEnv { TdThreadRwlock lock; - SDiskID did; - TDBEnv dbEnv; // TODO: If it's better to put it in smaIndex level? - char * path; // relative path - SSmaStat * pStat; + SDiskID did; + TDBEnv dbEnv; // TODO: If it's better to put it in smaIndex level? + char *path; // relative path + SSmaStat *pStat; }; #define SMA_ENV_LOCK(env) ((env)->lock) @@ -77,4 +77,6 @@ static FORCE_INLINE int tsdbUnLockSma(SSmaEnv *pEnv) { return 0; } + + #endif /* _TD_TSDB_SMA_H_ */ \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index 2dd8386d7a..e4bad9e94b 100644 --- a/source/dnode/vnode/src/meta/metaBDBImpl.c +++ b/source/dnode/vnode/src/meta/metaBDBImpl.c @@ -259,7 +259,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { return 0; } -int metaRemoveSmaFromDb(SMeta *pMeta, const char *indexName) { +int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) { // TODO #if 0 DBT key = {0}; diff --git a/source/dnode/vnode/src/meta/metaIdx.c b/source/dnode/vnode/src/meta/metaIdx.c index 881ea4f46d..818da14738 100644 --- a/source/dnode/vnode/src/meta/metaIdx.c +++ b/source/dnode/vnode/src/meta/metaIdx.c @@ -121,11 +121,11 @@ int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg) { return TSDB_CODE_SUCCESS; } -int32_t metaDropTSma(SMeta *pMeta, char* indexName) { +int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) { // TODO: Validate the cfg // TODO: add atomicity - if (metaRemoveSmaFromDb(pMeta, indexName) < 0) { + if (metaRemoveSmaFromDb(pMeta, indexUid) < 0) { // TODO: handle error return -1; } diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index 0eb2d525b3..502ba60709 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -25,6 +25,7 @@ static const char *TSDB_SMA_DNAME[] = { #define SMA_STORAGE_TSDB_TIMES 10 #define SMA_STORAGE_SPLIT_HOURS 24 #define SMA_KEY_LEN 18 // tableUid_colId_TSKEY 8+2+8 +#define SMA_DROP_EXPIRED_TIME 10 // default is 10 seconds #define SMA_STATE_HASH_SLOT 4 #define SMA_STATE_ITEM_HASH_SLOT 32 @@ -60,10 +61,11 @@ typedef struct { typedef struct { /** * @brief The field 'state' is here to demonstrate if one smaIndex is ready to provide service. - * - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open, - * without information about its previous state. * - TSDB_SMA_STAT_OK: 1) The sma calculation of history data is finished; 2) Or recevied information from * Streaming Module or TSDB local persistence. + * - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open, + * without information about its previous state. + * - TSDB_SMA_STAT_DROPPED: 1)sma dropped */ int8_t state; // ETsdbSmaStat SHashObj *expiredWindows; // key: skey of time window, value: N/A @@ -80,6 +82,7 @@ struct SSmaStat { // expired window static int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, ETsdbSmaType smaType, char *msg); static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat); +static void * tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem); static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat); static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did); static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv); @@ -109,7 +112,55 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg); static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg); +// mgmt interface +static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid); + // implementation +static FORCE_INLINE int8_t tsdbSmaStat(SSmaStatItem *pStatItem) { + if (pStatItem) { + return atomic_load_8(&pStatItem->state); + } + return TSDB_SMA_STAT_UNKNOWN; +} + +static FORCE_INLINE bool tsdbSmaStatIsOK(SSmaStatItem *pStatItem, int8_t *state) { + if(!pStatItem) { + return false; + } + + if (state) { + *state = atomic_load_8(&pStatItem->state); + return *state == TSDB_SMA_STAT_OK; + } + return atomic_load_8(&pStatItem->state) == TSDB_SMA_STAT_OK; +} + +static FORCE_INLINE bool tsdbSmaStatIsExpired(SSmaStatItem *pStatItem) { + return pStatItem ? (atomic_load_8(&pStatItem->state) & TSDB_SMA_STAT_EXPIRED) : true; +} + +static FORCE_INLINE bool tsdbSmaStatIsDropped(SSmaStatItem *pStatItem) { + return pStatItem ? (atomic_load_8(&pStatItem->state) & TSDB_SMA_STAT_DROPPED) : true; +} + +static FORCE_INLINE void tsdbSmaStatSetOK(SSmaStatItem *pStatItem) { + if (pStatItem) { + atomic_store_8(&pStatItem->state, TSDB_SMA_STAT_OK); + } +} + +static FORCE_INLINE void tsdbSmaStatSetExpired(SSmaStatItem *pStatItem) { + if (pStatItem) { + atomic_or_fetch_8(&pStatItem->state, TSDB_SMA_STAT_EXPIRED); + } +} + +static FORCE_INLINE void tsdbSmaStatSetDropped(SSmaStatItem *pStatItem) { + if (pStatItem) { + atomic_or_fetch_8(&pStatItem->state, TSDB_SMA_STAT_DROPPED); + } +} + static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) { snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%stsdb%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TD_DIRSEP, TSDB_SMA_DNAME[smaType]); @@ -252,6 +303,16 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) { return pItem; } +static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) { + if (pSmaStatItem != NULL) { + tdDestroyTSma(pSmaStatItem->pSma); + tfree(pSmaStatItem->pSma); + taosHashCleanup(pSmaStatItem->expiredWindows); + tfree(pSmaStatItem); + } + return NULL; +} + /** * @brief Release resources allocated for its member fields, not including itself. * @@ -264,12 +325,7 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) { void *item = taosHashIterate(pSmaStat->smaStatItems, NULL); while (item != NULL) { SSmaStatItem *pItem = *(SSmaStatItem **)item; - if (pItem != NULL) { - tdDestroyTSma(pItem->pSma); - tfree(pItem->pSma); - taosHashCleanup(pItem->expiredWindows); - tfree(pItem); - } + tsdbFreeSmaStatItem(pItem); item = taosHashIterate(pSmaStat->smaStatItems, item); } taosHashCleanup(pSmaStat->smaStatItems); @@ -711,6 +767,148 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { STsdbCfg * pCfg = REPO_CFG(pTsdb); STSmaDataWrapper *pData = (STSmaDataWrapper *)msg; SSmaEnv * pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); + int64_t indexUid = SMA_TEST_INDEX_UID; + + + if (pEnv == NULL) { + terrno = TSDB_CODE_INVALID_PTR; + tsdbWarn("vgId:%d insert tSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb)); + return terrno; + } + + if (pData->dataLen <= 0) { + TASSERT(0); + terrno = TSDB_CODE_INVALID_PARA; + return TSDB_CODE_FAILED; + } + + STSmaWriteH tSmaH = {0}; + + if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData) != 0) { + return TSDB_CODE_FAILED; + } + + SSmaStat *pStat = SMA_ENV_STAT(pTsdb->pTSmaEnv); + SSmaStatItem *pItem = NULL; + + tsdbRefSmaStat(pTsdb, pStat); + + if (pStat && pStat->smaStatItems) { + pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid)); + } + if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) { + terrno = TSDB_CODE_TDB_INVALID_SMA_STAT; + tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_FAILED; + } + + char rPath[TSDB_FILENAME_LEN] = {0}; + char aPath[TSDB_FILENAME_LEN] = {0}; + snprintf(rPath, TSDB_FILENAME_LEN, "%s%s%" PRIi64, SMA_ENV_PATH(pEnv), TD_DIRSEP, indexUid); + tfsAbsoluteName(REPO_TFS(pTsdb), SMA_ENV_DID(pEnv), rPath, aPath); + if (!taosCheckExistFile(aPath)) { + if (tfsMkdirRecurAt(REPO_TFS(pTsdb), rPath, SMA_ENV_DID(pEnv)) != TSDB_CODE_SUCCESS) { + tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_FAILED; + } + } + + // Step 1: Judge the storage level and days + int32_t storageLevel = tsdbGetSmaStorageLevel(pData->interval, pData->intervalUnit); + int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel); + int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision)); + + // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file + // - Set and open the DFile or the B+Tree file + // TODO: tsdbStartTSmaCommit(); + tsdbSetTSmaDataFile(&tSmaH, pData, indexUid, fid); + if (tsdbOpenDBF(pTsdb->pTSmaEnv->dbEnv, &tSmaH.dFile) != 0) { + tsdbWarn("vgId:%d open DB file %s failed since %s", REPO_ID(pTsdb), + tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno)); + tsdbDestroyTSmaWriteH(&tSmaH); + tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_FAILED; + } + + if (tsdbInsertTSmaDataSection(&tSmaH, pData) != 0) { + tsdbWarn("vgId:%d insert tSma data section failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); + tsdbDestroyTSmaWriteH(&tSmaH); + tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_FAILED; + } + // TODO:tsdbEndTSmaCommit(); + + // Step 3: reset the SSmaStat + tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey); + + tsdbDestroyTSmaWriteH(&tSmaH); + tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_SUCCESS; +} + +/** + * @brief Drop tSma data and local cache + * - insert/query reference + * @param pTsdb + * @param msg + * @return int32_t + */ +static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) { + SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv); + + // clear local cache + if (pEnv) { + tsdbDebug("vgId:%d drop tSma local cache for %" PRIi64, REPO_ID(pTsdb), indexUid); + + SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid)); + if ((pItem != NULL) || ((pItem = *(SSmaStatItem **)pItem) != NULL)) { + if (tsdbSmaStatIsDropped(pItem)) { + tsdbDebug("vgId:%d tSma stat is already dropped for %" PRIi64, REPO_ID(pTsdb), indexUid); + return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg should be intercept by mnode + } + + tsdbWLockSma(pEnv); + if (tsdbSmaStatIsDropped(pItem)) { + tsdbUnLockSma(pEnv); + tsdbDebug("vgId:%d tSma stat is already dropped for %" PRIi64, REPO_ID(pTsdb), indexUid); + return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg should be intercept by mnode + } + tsdbSmaStatSetDropped(pItem); + tsdbUnLockSma(pEnv); + + int32_t nSleep = 0; + while (true) { + if (T_REF_VAL_GET(SMA_ENV_STAT(pEnv)) <= 0) { + break; + } + taosSsleep(1); + if (++nSleep > SMA_DROP_EXPIRED_TIME) { + break; + }; + } + + tsdbFreeSmaStatItem(pItem); + tsdbDebug("vgId:%d getTSmaDataImpl failed since no index %" PRIi64 " in local cache", REPO_ID(pTsdb), indexUid); + } + } + // clear sma data files + // TODO: +} + +static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t fid) { + STsdb *pTsdb = pSmaH->pTsdb; + + char tSmaFile[TSDB_FILENAME_LEN] = {0}; + snprintf(tSmaFile, TSDB_FILENAME_LEN, "v%df%d.rsma", REPO_ID(pTsdb), fid); + pSmaH->dFile.path = strdup(tSmaFile); + + return TSDB_CODE_SUCCESS; +} + +static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { + STsdbCfg * pCfg = REPO_CFG(pTsdb); + STSmaDataWrapper *pData = (STSmaDataWrapper *)msg; + SSmaEnv * pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv); if (pEnv == NULL) { terrno = TSDB_CODE_INVALID_PTR; @@ -771,51 +969,6 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) { return TSDB_CODE_SUCCESS; } -static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t fid) { - STsdb *pTsdb = pSmaH->pTsdb; - - char tSmaFile[TSDB_FILENAME_LEN] = {0}; - snprintf(tSmaFile, TSDB_FILENAME_LEN, "v%df%d.rsma", REPO_ID(pTsdb), fid); - pSmaH->dFile.path = strdup(tSmaFile); - - return TSDB_CODE_SUCCESS; -} - -static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) { - STsdbCfg * pCfg = REPO_CFG(pTsdb); - STSmaDataWrapper *pData = (STSmaDataWrapper *)msg; - STSmaWriteH tSmaH = {0}; - - tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData); - - if (pData->dataLen <= 0) { - TASSERT(0); - terrno = TSDB_CODE_INVALID_PARA; - return terrno; - } - - // Step 1: Judge the storage level - int32_t storageLevel = tsdbGetSmaStorageLevel(pData->interval, pData->intervalUnit); - int32_t daysPerFile = storageLevel == SMA_STORAGE_LEVEL_TSDB ? SMA_STORAGE_TSDB_DAYS : pCfg->daysPerFile; - - // Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file - // - Set and open the DFile or the B+Tree file - - int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision)); - - // Save all the TSma data to one file - // TODO: tsdbStartTSmaCommit(); - tsdbSetTSmaDataFile(&tSmaH, pData, storageLevel, fid); - - tsdbInsertTSmaDataSection(&tSmaH, pData); - // TODO:tsdbEndTSmaCommit(); - - // reset the SSmaStat - tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pRSmaEnv), pData->indexUid, pData->skey); - - return TSDB_CODE_SUCCESS; -} - /** * @brief * @@ -934,6 +1087,15 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_ #endif #if 1 + int8_t smaStat = 0; + if (!tsdbSmaStatIsOK(pItem, &smaStat)) { // TODO: multiple check for large scale sma query + tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv)); + terrno = TSDB_CODE_TDB_INVALID_SMA_STAT; + tsdbDebug("vgId:%d getTSmaDataImpl failed from index %" PRIi64 " since %s %" PRIi8, REPO_ID(pTsdb), indexUid, + tstrerror(terrno), smaStat); + return TSDB_CODE_FAILED; + } + if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY)) != NULL) { // TODO: mark this window as expired. tsdbDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, REPO_ID(pTsdb), @@ -1086,6 +1248,20 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg) { return code; } +/** + * @brief Get tSma data + * + * @param pTsdb + * @param pData + * @param indexUid + * @param interval + * @param intervalUnit + * @param tableUid + * @param colId + * @param querySKey + * @param nMaxResult + * @return int32_t + */ int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult) { int32_t code = TSDB_CODE_SUCCESS; @@ -1094,4 +1270,19 @@ int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, tsdbWarn("vgId:%d get tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); } return code; +} + +/** + * @brief Drop tSma Data and caches + * + * @param pTsdb + * @param msg + * @return int32_t + */ +int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid) { + int32_t code = TSDB_CODE_SUCCESS; + if ((code = tsdbDropTSmaDataImpl(pTsdb, indexUid)) < 0) { + tsdbWarn("vgId:%d drop tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); + } + return code; } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index ade9adb1e1..f8234de813 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -199,15 +199,23 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { return -1; } - if (metaDropTSma(pVnode->pMeta, vDropSmaReq.indexName) < 0) { - // TODO: handle error - return -1; - } // TODO: send msg to stream computing to drop tSma // if ((send msg to stream computing) < 0) { // tdDestroyTSma(&vCreateSmaReq); // return -1; // } + // + + if (metaDropTSma(pVnode->pMeta, vDropSmaReq.indexUid) < 0) { + // TODO: handle error + return -1; + } + + if(tsdbDropTSmaData(pVnode->pTsdb, vDropSmaReq.indexUid) < 0) { + // TODO: handle error + return -1; + } + // TODO: return directly or go on follow steps? } break; default: diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 3c51ad5d71..3fa5799f54 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -272,8 +272,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { taosArrayDestroy(pUids); // resource release - metaRemoveSmaFromDb(pMeta, smaIndexName1); - metaRemoveSmaFromDb(pMeta, smaIndexName2); + metaRemoveSmaFromDb(pMeta, indexUid1); + metaRemoveSmaFromDb(pMeta, indexUid2); tdDestroyTSma(&tSma); metaClose(pMeta); diff --git a/source/util/src/terror.c b/source/util/src/terror.c index b7ab007cf5..55fef59ae1 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -332,8 +332,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_MESSED_MSG, "TSDB messed message") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_IVLD_TAG_VAL, "TSDB invalid tag value") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_CACHE_LAST_ROW, "TSDB no cache last row data") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_RECREATED, "Table re-created") -TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_SMA_INDEX_IN_META, "No sma index in meta") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR, "TDB env open error") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_SMA_INDEX_IN_META, "No sma index in meta") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_SMA_STAT, "Invalid sma state") // query TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, "Invalid handle") From 311e65daa7053d42cffda2f6805758db553218be Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 23 Mar 2022 22:53:49 +0800 Subject: [PATCH 61/68] [td-13039] support add group by keys. --- source/dnode/vnode/src/tsdb/tsdbRead.c | 8 ------- source/libs/executor/src/executorimpl.c | 31 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 6c79fe3726..680e517fd2 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -1403,14 +1403,6 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t continue; } - int32_t bytes = pColInfo->info.bytes; - - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; - } else { - pData = (char*)pColInfo->pData + (capacity - numOfRows - num) * pColInfo->info.bytes; - } - if (!isAllRowsNull(src) && pColInfo->info.colId == src->colId) { if (!IS_VAR_DATA_TYPE(pColInfo->info.type)) { // todo opt performance // memmove(pData, (char*)src->pData + bytes * start, bytes * num); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 2e769936eb..787a8979fc 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -1715,10 +1715,31 @@ static int32_t generatedHashKey(void* pKey, int32_t* length, SArray* pGroupColVa return 0; } +// assign the group keys or user input constant values if required +static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t totalRows, int32_t rowIndex) { + for(int32_t i = 0; i < numOfOutput; ++i) { + if (pCtx[i].functionId == -1) { + SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[i]); + + SColumnInfoData* pColInfoData = pCtx[i].input.pData[0]; + if (!colDataIsNull(pColInfoData, totalRows, rowIndex, NULL)) { + char* dest = GET_ROWCELL_INTERBUF(pEntryInfo); + char* data = colDataGetData(pColInfoData, rowIndex); + + // set result exists, todo refactor + memcpy(dest, data, pColInfoData->info.bytes); + pEntryInfo->hasResult = DATA_SET_FLAG; + pEntryInfo->numOfRes = 1; + } + } + } +} + static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock *pBlock) { SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo; SGroupbyOperatorInfo *pInfo = pOperator->info; + SqlFunctionCtx* pCtx = pInfo->binfo.pCtx; int32_t numOfGroupCols = taosArrayGetSize(pInfo->pGroupCols); // if (type == TSDB_DATA_TYPE_FLOAT || type == TSDB_DATA_TYPE_DOUBLE) { //qError("QInfo:0x%"PRIx64" group by not supported on double/float columns, abort", GET_TASKID(pRuntimeEnv)); @@ -1751,7 +1772,11 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock *pBlock) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } - doApplyFunctions(pInfo->binfo.pCtx, &w, j - num, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); + int32_t rowIndex = j - num; + doApplyFunctions(pCtx, &w, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); + + // assign the group keys or user input constant values if required + doAssignGroupKeys(pCtx, pOperator->numOfOutput, pBlock->info.rows, rowIndex); keepGroupKeys(pInfo, pBlock, j, numOfGroupCols); num = 1; } @@ -1764,7 +1789,9 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock *pBlock) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } - doApplyFunctions(pInfo->binfo.pCtx, &w, pBlock->info.rows - num, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); + int32_t rowIndex = pBlock->info.rows - num; + doApplyFunctions(pCtx, &w, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC); + doAssignGroupKeys(pCtx, pOperator->numOfOutput, pBlock->info.rows, rowIndex); } } From c1f25f3ac73bb20fee8ce07c7751d7efd74ac19d Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Thu, 24 Mar 2022 10:13:32 +0800 Subject: [PATCH 62/68] [add check tmq consume result] --- tests/script/tsim/insert/null.sim | 2 -- tests/script/tsim/tmq/basic.sim | 10 ++++++--- tests/test/c/tmqDemo.c | 35 ++++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/tests/script/tsim/insert/null.sim b/tests/script/tsim/insert/null.sim index 156a618fb6..fbaef8cc94 100644 --- a/tests/script/tsim/insert/null.sim +++ b/tests/script/tsim/insert/null.sim @@ -244,8 +244,6 @@ endi # return -1 #endi -return - #=================================================================== #=================================================================== diff --git a/tests/script/tsim/tmq/basic.sim b/tests/script/tsim/tmq/basic.sim index 31836f8580..3e42c2cbd7 100644 --- a/tests/script/tsim/tmq/basic.sim +++ b/tests/script/tsim/tmq/basic.sim @@ -47,9 +47,12 @@ sql drop database useless_db # -m startTimestamp, default is 1640966400000 [2022-01-01 00:00:00] # -g showMsgFlag, default is 0 # -#system_content ../../debug/tests/test/c/tmq_demo -c ../../sim/tsim/cfg -system ../../debug/tests/test/c/tmq_demo -c ../../sim/tsim/cfg -print result-> $system_content +print cmd===> system_content ../../debug/tests/test/c/tmq_demo -sim 1 -b 100 -c ../../sim/tsim/cfg -w ../../sim/dnode1/data/vnode/vnode4/wal +system_content ../../debug/tests/test/c/tmq_demo -sim 1 -b 100 -c ../../sim/tsim/cfg -w ../../sim/dnode1/data/vnode/vnode4/wal +print cmd result----> $system_content +if $system_content != @{consume success: 100}@ then + print not match in pos000 +endi sql show databases print ===> $rows $data00 $data01 $data02 $data03 @@ -78,4 +81,5 @@ endi if $data00 != 10000 then return -1 endi + #system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 866bcb2ea0..15022f648a 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -58,6 +58,7 @@ typedef struct { int32_t totalRowsOfPerTbl; int64_t startTimestamp; int32_t showMsgFlag; + int32_t simCase; int32_t totalRowsOfT2; } SConfInfo; @@ -66,7 +67,7 @@ static SConfInfo g_stConfInfo = { "tmqdb", "stb", "./tmqResult.txt", // output_file - "/data2/dnode/data/vnodes/vnode2/wal", + "/data2/dnode/data/vnode/vnode2/wal", 1, // threads 1, // tables 1, // vgroups @@ -77,6 +78,7 @@ static SConfInfo g_stConfInfo = { 10000, // total rows for per table 0, // 2020-01-01 00:00:00.000 0, // show consume msg switch + 0, // if run in sim case 10000, }; @@ -117,6 +119,8 @@ static void printHelp() { printf("%s%s%s%" PRId64 "\n", indent, indent, "startTimestamp, default is ", g_stConfInfo.startTimestamp); printf("%s%s\n", indent, "-g"); printf("%s%s%s%d\n", indent, indent, "showMsgFlag, default is ", g_stConfInfo.showMsgFlag); + printf("%s%s\n", indent, "-sim"); + printf("%s%s%s%d\n", indent, indent, "simCase, default is ", g_stConfInfo.simCase); exit(EXIT_SUCCESS); } @@ -160,14 +164,17 @@ void parseArgument(int32_t argc, char *argv[]) { g_stConfInfo.startTimestamp = atol(argv[++i]); } else if (strcmp(argv[i], "-g") == 0) { g_stConfInfo.showMsgFlag = atol(argv[++i]); + } else if (strcmp(argv[i], "-sim") == 0) { + g_stConfInfo.simCase = atol(argv[++i]); } else { - pPrint("%s unknow para: %s %s", GREEN, argv[++i], NC); + printf("%s unknow para: %s %s", GREEN, argv[++i], NC); exit(-1); } } g_stConfInfo.totalRowsOfT2 = g_stConfInfo.totalRowsOfPerTbl * g_stConfInfo.ratio; +#if 0 pPrint("%s configDir:%s %s", GREEN, configDir, NC); pPrint("%s dbName:%s %s", GREEN, g_stConfInfo.dbName, NC); pPrint("%s stbName:%s %s", GREEN, g_stConfInfo.stbName, NC); @@ -184,6 +191,7 @@ void parseArgument(int32_t argc, char *argv[]) { pPrint("%s totalRowsOfT2:%d %s", GREEN, g_stConfInfo.totalRowsOfT2, NC); pPrint("%s startTimestamp:%" PRId64" %s", GREEN, g_stConfInfo.startTimestamp, NC); pPrint("%s showMsgFlag:%d %s", GREEN, g_stConfInfo.showMsgFlag, NC); +#endif } static int running = 1; @@ -429,15 +437,21 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog double consumeTime = (double)(endTime - startTime) / 1000000; if (batchCnt != totalMsgs) { - pPrint("%s inserted msgs: %d and consume msgs: %d mismatch %s", GREEN, totalMsgs, batchCnt, NC); + printf("%s inserted msgs: %d and consume msgs: %d mismatch %s", GREEN, totalMsgs, batchCnt, NC); + exit(-1); } - pPrint("consume result: msgs: %d, skip log cnt: %d, time used:%.3f second\n", batchCnt, skipLogNum, consumeTime); + if (0 == g_stConfInfo.simCase) { + printf("consume result: msgs: %d, skip log cnt: %d, time used:%.3f second\n", batchCnt, skipLogNum, consumeTime); + } else { + printf("{consume success: %d}", totalMsgs); + } taosFprintfFile(g_fp, "|%10d | %10.3f | %8.2f | %10.2f| %10.2f |\n", batchCnt, consumeTime, (double)batchCnt / consumeTime, (double)walLogSize / (1024 * 1024.0) / consumeTime, (double)walLogSize / 1024.0 / batchCnt); err = tmq_consumer_close(tmq); if (err) { fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); + exit(-1); } } @@ -679,12 +693,17 @@ int main(int32_t argc, char *argv[]) { walLogSize = getDirectorySize(g_stConfInfo.vnodeWalPath); if (walLogSize <= 0) { - pError("vnode2/wal size incorrect!"); + printf("vnode2/wal size incorrect!"); + exit(-1); } else { - pPrint(".log file size in vnode2/wal: %.3f MBytes\n", (double)walLogSize/(1024 * 1024.0)); + if (0 == g_stConfInfo.simCase) { + pPrint(".log file size in vnode2/wal: %.3f MBytes\n", (double)walLogSize/(1024 * 1024.0)); + } } - - pPrint("insert result: %d rows, %d msgs, time:%.3f sec, speed:%.1f rows/second, %.1f msgs/second\n", totalRows, totalMsgs, seconds, rowsSpeed, msgsSpeed); + + if (0 == g_stConfInfo.simCase) { + pPrint("insert result: %d rows, %d msgs, time:%.3f sec, speed:%.1f rows/second, %.1f msgs/second\n", totalRows, totalMsgs, seconds, rowsSpeed, msgsSpeed); + } taosFprintfFile(g_fp, "|%10d | %10.3f | %8.2f | %10.3f ", totalMsgs, seconds, msgsSpeed, (double)walLogSize/(1024 * 1024.0)); } From 5e2d82b614d59f82bb48d3f7a0a1e042d8bcfff9 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 24 Mar 2022 10:27:38 +0800 Subject: [PATCH 63/68] restore stub cmake --- cmake/stub_CMakeLists.txt.in | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmake/stub_CMakeLists.txt.in b/cmake/stub_CMakeLists.txt.in index c768239006..e227e820d6 100644 --- a/cmake/stub_CMakeLists.txt.in +++ b/cmake/stub_CMakeLists.txt.in @@ -1,12 +1,12 @@ # stub -#ExternalProject_Add(stub -# GIT_REPOSITORY https://github.com/coolxv/cpp-stub.git -# GIT_SUBMODULES "src" -# SOURCE_DIR "${CMAKE_CONTRIB_DIR}/cpp-stub" -# BINARY_DIR "${CMAKE_CONTRIB_DIR}/cpp-stub/src" -# CONFIGURE_COMMAND "" -# BUILD_COMMAND "" -# INSTALL_COMMAND "" -# TEST_COMMAND "" -#) +ExternalProject_Add(stub + GIT_REPOSITORY https://github.com/coolxv/cpp-stub.git + GIT_SUBMODULES "src" + SOURCE_DIR "${CMAKE_CONTRIB_DIR}/cpp-stub" + BINARY_DIR "${CMAKE_CONTRIB_DIR}/cpp-stub/src" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) From 21a4b868e2bc652552725ab0b7b3aef23d2eebdf Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 24 Mar 2022 10:37:27 +0800 Subject: [PATCH 64/68] sma --- source/dnode/mnode/impl/inc/mndStream.h | 2 ++ source/dnode/mnode/impl/src/mndSma.c | 22 ++++++++++++ source/dnode/mnode/impl/src/mndStream.c | 45 ++++++++++++++---------- source/dnode/mnode/impl/test/sma/sma.cpp | 5 +-- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndStream.h b/source/dnode/mnode/impl/inc/mndStream.h index b1145b0c6b..b5d22cb7a5 100644 --- a/source/dnode/mnode/impl/inc/mndStream.h +++ b/source/dnode/mnode/impl/inc/mndStream.h @@ -31,6 +31,8 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream); SSdbRaw *mndStreamActionEncode(SStreamObj *pStream); SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw); +int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 2bd13f395f..ebd34fb2a5 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -22,6 +22,7 @@ #include "mndMnode.h" #include "mndShow.h" #include "mndStb.c" +#include "mndStream.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" @@ -404,6 +405,18 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre memcpy(smaObj.ast, pCreate->ast, smaObj.astLen); } + SStreamObj streamObj = {0}; + tstrncpy(streamObj.name, pCreate->name, TSDB_STREAM_FNAME_LEN); + tstrncpy(streamObj.db, pDb->name, TSDB_DB_FNAME_LEN); + streamObj.createTime = taosGetTimestampMs(); + streamObj.updateTime = streamObj.createTime; + streamObj.uid = mndGenerateUid(pCreate->name, strlen(pCreate->name)); + streamObj.dbUid = pDb->uid; + streamObj.version = 1; + streamObj.sql = pCreate->sql; + /*streamObj.physicalPlan = "";*/ + streamObj.logicalPlan = "not implemented"; + int32_t code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_SMA, &pReq->rpcMsg); if (pTrans == NULL) goto _OVER; @@ -414,6 +427,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; + if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; @@ -457,6 +471,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) { int32_t code = -1; SStbObj *pStb = NULL; SSmaObj *pSma = NULL; + SStreamObj *pStream = NULL; SDbObj *pDb = NULL; SUserObj *pUser = NULL; SMCreateSmaReq createReq = {0}; @@ -476,6 +491,12 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) { mError("sma:%s, failed to create since stb:%s not exist", createReq.name, createReq.stb); goto _OVER; } + + pStream = mndAcquireStream(pMnode, createReq.name); + if (pStream != NULL) { + mError("sma:%s, failed to create since stream:%s already exist", createReq.name, createReq.name); + goto _OVER; + } pSma = mndAcquireSma(pMnode, createReq.name); if (pSma != NULL) { @@ -514,6 +535,7 @@ _OVER: mndReleaseStb(pMnode, pStb); mndReleaseSma(pMnode, pSma); + mndReleaseStream(pMnode, pStream); mndReleaseDb(pMnode, pDb); mndReleaseUser(pMnode, pUser); tFreeSMCreateSmaReq(&createReq); diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index c87bb015b4..490c2f69e9 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -218,13 +218,13 @@ static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) { return 0; } -static int32_t mndStreamGetPlanString(const SCMCreateStreamReq *pCreate, char **pStr) { - if (NULL == pCreate->ast) { +static int32_t mndStreamGetPlanString(const char *ast, char **pStr) { + if (NULL == ast) { return TSDB_CODE_SUCCESS; } SNode *pAst = NULL; - int32_t code = nodesStringToNode(pCreate->ast, &pAst); + int32_t code = nodesStringToNode(ast, &pAst); SQueryPlan *pPlan = NULL; if (TSDB_CODE_SUCCESS == code) { @@ -245,6 +245,28 @@ static int32_t mndStreamGetPlanString(const SCMCreateStreamReq *pCreate, char ** return code; } +int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) { + if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(ast, &pStream->physicalPlan)) { + mError("topic:%s, failed to get plan since %s", pStream->name, terrstr()); + return -1; + } + + if (mndScheduleStream(pMnode, pTrans, pStream) < 0) { + mError("stream:%ld, schedule stream since %s", pStream->uid, terrstr()); + return -1; + } + + SSdbRaw *pRedoRaw = mndStreamActionEncode(pStream); + if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { + mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY); + + return 0; +} + static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamReq *pCreate, SDbObj *pDb) { mDebug("stream:%s to create", pCreate->name); SStreamObj streamObj = {0}; @@ -259,11 +281,6 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe /*streamObj.physicalPlan = "";*/ streamObj.logicalPlan = "not implemented"; - if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(pCreate, &streamObj.physicalPlan)) { - mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr()); - return -1; - } - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_STREAM, &pReq->rpcMsg); if (pTrans == NULL) { mError("stream:%s, failed to create since %s", pCreate->name, terrstr()); @@ -271,20 +288,12 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe } mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name); - if (mndScheduleStream(pMnode, pTrans, &streamObj) < 0) { - mError("stream:%ld, schedule stream since %s", streamObj.uid, terrstr()); + if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) { + mError("trans:%d, failed to add stream since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); return -1; } - SSdbRaw *pRedoRaw = mndStreamActionEncode(&streamObj); - if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { - mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY); - if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); diff --git a/source/dnode/mnode/impl/test/sma/sma.cpp b/source/dnode/mnode/impl/test/sma/sma.cpp index 5b48906681..006524543f 100644 --- a/source/dnode/mnode/impl/test/sma/sma.cpp +++ b/source/dnode/mnode/impl/test/sma/sma.cpp @@ -156,7 +156,7 @@ void* MndTestSma::BuildCreateSmaReq(const char* smaname, const char* stbname, in createReq.tagsFilterLen = strlen(createReq.tagsFilter) + 1; createReq.sql = (char*)sql; createReq.sqlLen = strlen(createReq.sql) + 1; - createReq.ast = (char*)expr; + createReq.ast = (char*)ast; createReq.astLen = strlen(createReq.ast) + 1; int32_t tlen = tSerializeSMCreateSmaReq(NULL, 0, &createReq); @@ -201,7 +201,7 @@ TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) { test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); } - +#if 0 { pReq = BuildCreateSmaReq(smaname, stbname, 0, "expr", "tagsFilter", "sql", "ast", &contLen); pRsp = test.SendReq(TDMT_MND_CREATE_SMA, pReq, contLen); @@ -233,4 +233,5 @@ TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) { test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } +#endif } From 8b8aeabdd1df2e5067164ec1b0f5808d371556dd Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 24 Mar 2022 10:50:16 +0800 Subject: [PATCH 65/68] sma --- include/common/tmsg.h | 5 ++++- source/common/src/tmsg.c | 6 ++++++ source/dnode/mnode/impl/inc/mndDef.h | 3 +++ source/dnode/mnode/impl/src/mndStb.c | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 69f95237ef..e229f2b2c2 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -269,12 +269,15 @@ typedef struct SSchema { typedef struct { char name[TSDB_TABLE_FNAME_LEN]; int8_t igExists; + float xFilesFactor; + int32_t aggregationMethod; + int32_t delay; int32_t numOfColumns; int32_t numOfTags; int32_t commentLen; SArray* pColumns; SArray* pTags; - char *comment; + char* comment; } SMCreateStbReq; int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index e5a0f2a28e..735bc67fcc 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -508,6 +508,9 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq if (tStartEncode(&encoder) < 0) return -1; if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; + if (tEncodeFloat(&encoder, pReq->xFilesFactor) < 0) return -1; + if (tEncodeI32(&encoder, pReq->aggregationMethod) < 0) return -1; + if (tEncodeI32(&encoder, pReq->delay) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfTags) < 0) return -1; if (tEncodeI32(&encoder, pReq->commentLen) < 0) return -1; @@ -541,6 +544,9 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; + if (tDecodeFloat(&decoder, &pReq->xFilesFactor) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->aggregationMethod) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->delay) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfTags) < 0) return -1; if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index c5372f6875..56d904f9c2 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -341,6 +341,9 @@ typedef struct { int64_t dbUid; int32_t version; int32_t nextColId; + float xFilesFactor; + int32_t aggregationMethod; + int32_t delay; int32_t numOfColumns; int32_t numOfTags; int32_t commentLen; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index e8d6157661..52a257eaeb 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -85,6 +85,9 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_INT64(pRaw, dataPos, pStb->dbUid, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->version, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->aggregationMethod, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->delay, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, STB_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pStb->commentLen, STB_ENCODE_OVER) @@ -148,6 +151,11 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT64(pRaw, dataPos, &pStb->dbUid, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->version, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->nextColId, STB_DECODE_OVER) + int32_t xFilesFactor = 0; + SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, STB_DECODE_OVER) + pStb->xFilesFactor = xFilesFactor / 10000.0f; + SDB_GET_INT32(pRaw, dataPos, &pStb->aggregationMethod, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->delay, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, STB_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->commentLen, STB_DECODE_OVER) From 2b4edcf6832b3df8e442bc43c0f68d10c2bbd694 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 24 Mar 2022 11:15:05 +0800 Subject: [PATCH 66/68] [td-13039] support fill. --- include/common/tmsg.h | 3 +- source/libs/executor/inc/executorimpl.h | 27 +++--- source/libs/executor/src/executorimpl.c | 112 ++++++++++++------------ 3 files changed, 73 insertions(+), 69 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 583496a4c6..9572d9d784 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -462,7 +462,8 @@ typedef struct { int32_t tz; // query client timezone char intervalUnit; char slidingUnit; - char offsetUnit; + char offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration. + int8_t precision; int64_t interval; int64_t sliding; int64_t offset; diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index c3f5b37a09..819c0a74f7 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -76,11 +76,12 @@ typedef struct SResultRowCell { * If the number of generated results is greater than this value, * query query will be halt and return results to client immediate. */ -typedef struct SRspResultInfo { - int64_t total; // total generated result size in rows - int32_t capacity; // capacity of current result output buffer - int32_t threshold; // result size threshold in rows. -} SRspResultInfo; +typedef struct SResultInfo { // TODO refactor + int64_t totalRows; // total generated result size in rows + int64_t totalBytes; // total results in bytes. + int32_t capacity; // capacity of current result output buffer + int32_t threshold; // result size threshold in rows. +} SResultInfo; typedef struct SColumnFilterElem { int16_t bytes; // column length @@ -160,8 +161,8 @@ typedef struct STaskCostInfo { typedef struct SOperatorCostInfo { uint64_t openCost; uint64_t execCost; - uint64_t totalRows; - uint64_t totalBytes; +// uint64_t totalRows; +// uint64_t totalBytes; } SOperatorCostInfo; typedef struct { @@ -301,7 +302,7 @@ typedef struct STaskRuntimeEnv { int64_t currentOffset; // dynamic offset value STableQueryInfo* current; - SRspResultInfo resultInfo; + SResultInfo resultInfo; SHashObj* pTableRetrieveTsMap; struct SUdfInfo* pUdfInfo; } STaskRuntimeEnv; @@ -324,7 +325,7 @@ typedef struct SOperatorInfo { STaskRuntimeEnv* pRuntimeEnv; // todo remove it SExecTaskInfo* pTaskInfo; SOperatorCostInfo cost; - + SResultInfo resultInfo; struct SOperatorInfo** pDownstream; // downstram pointer list int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator __optr_fn_t getNextFn; @@ -539,6 +540,8 @@ typedef struct SFillOperatorInfo { void** p; SSDataBlock* existNewGroupBlock; bool multigroupResult; + SInterval intervalInfo; + int32_t capacity; } SFillOperatorInfo; typedef struct SGroupKeys { @@ -649,21 +652,19 @@ SOperatorInfo* createOrderOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName, SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, int32_t numOfDownstream, SLimit* pLimit, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, SLimit* pLimit, SExecTaskInfo* pTaskInfo); SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo); SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); +SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SInterval* pInterval, SSDataBlock* pResBlock, bool multigroupResult, SExecTaskInfo* pTaskInfo); SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); -SOperatorInfo* createFillOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, - int32_t numOfOutput, bool multigroupResult); - SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 787a8979fc..1b555e396b 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -248,7 +248,7 @@ static int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo *binfo, int32_t numOfCo static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size); static void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow *win); -static void setResultBufSize(STaskAttr* pQueryAttr, SRspResultInfo* pResultInfo); +static void setResultBufSize(STaskAttr* pQueryAttr, SResultInfo* pResultInfo); static void setCtxTagForJoin(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, void* pTable); static void setParamForStableStddev(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, SExprInfo* pExpr); static void setParamForStableStddevByColData(STaskRuntimeEnv* pRuntimeEnv, SqlFunctionCtx* pCtx, int32_t numOfOutput, SExprInfo* pExpr, char* val, int16_t bytes); @@ -7113,22 +7113,23 @@ static void doHandleRemainBlockFromNewGroup(SFillOperatorInfo *pInfo, STaskRunti static SSDataBlock* doFill(SOperatorInfo *pOperator, bool* newgroup) { SFillOperatorInfo *pInfo = pOperator->info; - pInfo->pRes->info.rows = 0; + SResultInfo* pResultInfo = &pOperator->resultInfo; + blockDataCleanup(pInfo->pRes); if (pOperator->status == OP_EXEC_DONE) { return NULL; } - STaskRuntimeEnv *pRuntimeEnv = pOperator->pRuntimeEnv; - doHandleRemainBlockFromNewGroup(pInfo, pRuntimeEnv, newgroup); - if (pInfo->pRes->info.rows > pRuntimeEnv->resultInfo.threshold || (!pInfo->multigroupResult && pInfo->pRes->info.rows > 0)) { - return pInfo->pRes; - } +// doHandleRemainBlockFromNewGroup(pInfo, pRuntimeEnv, newgroup); +// if (pInfo->pRes->info.rows > pRuntimeEnv->resultInfo.threshold || (!pInfo->multigroupResult && pInfo->pRes->info.rows > 0)) { +// return pInfo->pRes; +// } + SOperatorInfo* pDownstream = pOperator->pDownstream[0]; while(1) { - publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC); - SSDataBlock* pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup); - publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC); + publishOperatorProfEvent(pDownstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); + SSDataBlock* pBlock = pDownstream->getNextFn(pDownstream, newgroup); + publishOperatorProfEvent(pDownstream, QUERY_PROF_AFTER_OPERATOR_EXEC); if (*newgroup) { assert(pBlock != NULL); @@ -7140,7 +7141,7 @@ static SSDataBlock* doFill(SOperatorInfo *pOperator, bool* newgroup) { // Fill the previous group data block, before handle the data block of new group. // Close the fill operation for previous group data block - taosFillSetStartInfo(pInfo->pFillInfo, 0, pRuntimeEnv->pQueryAttr->window.ekey); +// taosFillSetStartInfo(pInfo->pFillInfo, 0, pRuntimeEnv->pQueryAttr->window.ekey); } else { if (pBlock == NULL) { if (pInfo->totalInputRows == 0) { @@ -7148,7 +7149,7 @@ static SSDataBlock* doFill(SOperatorInfo *pOperator, bool* newgroup) { return NULL; } - taosFillSetStartInfo(pInfo->pFillInfo, 0, pRuntimeEnv->pQueryAttr->window.ekey); +// taosFillSetStartInfo(pInfo->pFillInfo, 0, pRuntimeEnv->pQueryAttr->window.ekey); } else { pInfo->totalInputRows += pBlock->info.rows; taosFillSetStartInfo(pInfo->pFillInfo, pBlock->info.rows, pBlock->info.window.ekey); @@ -7156,25 +7157,25 @@ static SSDataBlock* doFill(SOperatorInfo *pOperator, bool* newgroup) { } } - doFillTimeIntervalGapsInResults(pInfo->pFillInfo, pInfo->pRes, pRuntimeEnv->resultInfo.capacity, pInfo->p); + doFillTimeIntervalGapsInResults(pInfo->pFillInfo, pInfo->pRes, pInfo->capacity, pInfo->p); // current group has no more result to return if (pInfo->pRes->info.rows > 0) { // 1. The result in current group not reach the threshold of output result, continue // 2. If multiple group results existing in one SSDataBlock is not allowed, return immediately - if (pInfo->pRes->info.rows > pRuntimeEnv->resultInfo.threshold || pBlock == NULL || (!pInfo->multigroupResult)) { + if (pInfo->pRes->info.rows > pResultInfo->threshold || pBlock == NULL || (!pInfo->multigroupResult)) { return pInfo->pRes; } - doHandleRemainBlockFromNewGroup(pInfo, pRuntimeEnv, newgroup); - if (pInfo->pRes->info.rows > pRuntimeEnv->resultInfo.threshold || pBlock == NULL) { +// doHandleRemainBlockFromNewGroup(pInfo, pRuntimeEnv, newgroup); + if (pInfo->pRes->info.rows > pOperator->resultInfo.threshold || pBlock == NULL) { return pInfo->pRes; } } else if (pInfo->existNewGroupBlock) { // try next group assert(pBlock != NULL); - doHandleRemainBlockForNewGroupImpl(pInfo, pRuntimeEnv, newgroup); +// doHandleRemainBlockForNewGroupImpl(pInfo, pRuntimeEnv, newgroup); - if (pInfo->pRes->info.rows > pRuntimeEnv->resultInfo.threshold) { + if (pInfo->pRes->info.rows > pResultInfo->threshold) { return pInfo->pRes; } } else { @@ -7537,8 +7538,7 @@ SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int3 return 0; } -SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, int32_t numOfDownstream, SLimit* pLimit, SExecTaskInfo* pTaskInfo) { - ASSERT(numOfDownstream == 1); +SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, SLimit* pLimit, SExecTaskInfo* pTaskInfo) { SLimitOperatorInfo* pInfo = calloc(1, sizeof(SLimitOperatorInfo)); SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -7622,7 +7622,7 @@ SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, S STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); +// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); @@ -7647,7 +7647,7 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper pInfo->colIndex = -1; pInfo->reptScan = false; pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); +// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); @@ -7712,7 +7712,7 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); +// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); @@ -7736,7 +7736,7 @@ SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRun STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); +// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); @@ -7827,52 +7827,58 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx return NULL; } -SOperatorInfo* createFillOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput, bool multigroupResult) { +SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SInterval* pInterval, SSDataBlock* pResBlock, bool multigroupResult, SExecTaskInfo* pTaskInfo) { SFillOperatorInfo* pInfo = calloc(1, sizeof(SFillOperatorInfo)); - pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); - pInfo->multigroupResult = multigroupResult; + SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + pInfo->pRes = pResBlock; + pInfo->multigroupResult = multigroupResult; + pInfo->intervalInfo = *pInterval; + + SResultInfo* pResultInfo = &pOperator->resultInfo; { - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - struct SFillColInfo* pColInfo = createFillColInfo(pExpr, numOfOutput, pQueryAttr->fillVal); +// struct SFillColInfo* pColInfo = createFillColInfo(pExpr, numOfCols, pQueryAttr->fillVal); STimeWindow w = TSWINDOW_INITIALIZER; - TSKEY sk = TMIN(pQueryAttr->window.skey, pQueryAttr->window.ekey); - TSKEY ek = TMAX(pQueryAttr->window.skey, pQueryAttr->window.ekey); -// getAlignQueryTimeWindow(pQueryAttr, pQueryAttr->window.skey, sk, ek, &w); + TSKEY sk = TMIN(pTaskInfo->window.skey, pTaskInfo->window.ekey); + TSKEY ek = TMAX(pTaskInfo->window.skey, pTaskInfo->window.ekey); + getAlignQueryTimeWindow(pInterval, pInterval->precision, pTaskInfo->window.skey, sk, ek, &w); - pInfo->pFillInfo = - taosCreateFillInfo(pQueryAttr->order.order, w.skey, 0, (int32_t)pRuntimeEnv->resultInfo.capacity, numOfOutput, - pQueryAttr->interval.sliding, pQueryAttr->interval.slidingUnit, - (int8_t)pQueryAttr->precision, pQueryAttr->fillType, pColInfo, pRuntimeEnv->qinfo); + int32_t order = TSDB_ORDER_ASC; - pInfo->p = calloc(numOfOutput, POINTER_BYTES); +// pInfo->pFillInfo = +// taosCreateFillInfo(order, w.skey, 0, (int32_t)pResultInfo->capacity, numOfCols, +// pInterval->sliding, pInterval->slidingUnit, +// (int8_t)pInterval->precision, pQueryAttr->fillType, pColInfo, pTaskInfo->id.str); + + pInfo->p = calloc(numOfCols, POINTER_BYTES); } - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); - pOperator->name = "FillOperator"; pOperator->blockingOptr = false; pOperator->status = OP_NOT_OPENED; // pOperator->operatorType = OP_Fill; pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; + pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; - pOperator->pRuntimeEnv = pRuntimeEnv; - pOperator->getNextFn = doFill; - pOperator->closeFn = destroySFillOperatorInfo; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doFill; + pOperator->pTaskInfo = pTaskInfo; - int32_t code = appendDownstream(pOperator, &downstream, 1); + pOperator->closeFn = destroySFillOperatorInfo; + + int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; } SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput, void* pMerger, bool multigroupResult) { SSLimitOperatorInfo* pInfo = calloc(1, sizeof(SSLimitOperatorInfo)); + SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); // pInfo->orderColumnList = getResultGroupCheckColumns(pQueryAttr); // pInfo->slimit = pQueryAttr->slimit; // pInfo->limit = pQueryAttr->limit; -// pInfo->capacity = pRuntimeEnv->resultInfo.capacity; +// pInfo->capacity = pResultInfo->capacity; // pInfo->threshold = (int64_t)(pInfo->capacity * 0.8); // pInfo->currentOffset = pQueryAttr->limit.offset; // pInfo->currentGroupOffset = pQueryAttr->slimit.offset; @@ -7895,9 +7901,8 @@ SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorI offset += pExpr[index->colIndex].base.resSchema.bytes; } - pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); + pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pOperator->resultInfo.capacity); - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); pOperator->name = "SLimitOperator"; // pOperator->operatorType = OP_SLimit; @@ -7920,7 +7925,7 @@ static SSDataBlock* doTagScan(SOperatorInfo *pOperator, bool* newgroup) { } STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; - int32_t maxNumOfTables = (int32_t)pRuntimeEnv->resultInfo.capacity; + int32_t maxNumOfTables = (int32_t)pResultInfo->capacity; STagScanInfo *pInfo = pOperator->info; SSDataBlock *pRes = pInfo->pRes; @@ -8046,7 +8051,7 @@ static SSDataBlock* doTagScan(SOperatorInfo *pOperator, bool* newgroup) { SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput) { STagScanInfo* pInfo = calloc(1, sizeof(STagScanInfo)); - pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); +// pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); size_t numOfGroup = GET_NUM_OF_TABLEGROUP(pRuntimeEnv); assert(numOfGroup == 0 || numOfGroup == 1); @@ -8390,10 +8395,7 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa size_t numOfCols = LIST_LENGTH(pScanPhyNode->pScanCols); tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, (uint64_t)queryId, taskId); - - int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, queryId, taskId); - return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, - pScanPhyNode->reverse, pTaskInfo); + return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, pScanPhyNode->reverse, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == nodeType(pPhyNode)) { SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode; SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc); @@ -8847,7 +8849,7 @@ static void doUpdateExprColumnIndex(STaskAttr *pQueryAttr) { } } -void setResultBufSize(STaskAttr* pQueryAttr, SRspResultInfo* pResultInfo) { +void setResultBufSize(STaskAttr* pQueryAttr, SResultInfo* pResultInfo) { const int32_t DEFAULT_RESULT_MSG_SIZE = 1024 * (1024 + 512); // the minimum number of rows for projection query @@ -8868,7 +8870,7 @@ void setResultBufSize(STaskAttr* pQueryAttr, SRspResultInfo* pResultInfo) { } pResultInfo->threshold = (int32_t)(pResultInfo->capacity * THRESHOLD_RATIO); - pResultInfo->total = 0; + pResultInfo->totalRows = 0; } //TODO refactor From a2d7ce3045ab1c30e9b1441d138e7ae0578d4695 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 24 Mar 2022 11:43:39 +0800 Subject: [PATCH 67/68] [td-14246] fix bug. --- source/dnode/vnode/src/tsdb/tsdbRead.c | 47 ++------------------------ tests/script/tsim/insert/basic1.sim | 7 ++-- 2 files changed, 7 insertions(+), 47 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 680e517fd2..af3d454a86 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -1377,7 +1377,6 @@ static int doBinarySearchKey(char* pValue, int num, TSKEY key, int order) { } static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, int32_t start, int32_t end) { - char* pData = NULL; int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1 : -1; SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; @@ -1454,14 +1453,12 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t return numOfRows + num; } -// TODO fix bug for reverse copy data -// TODO handle the null data +// TODO fix bug for reverse copy data problem // Note: row1 always has high priority static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, STSRow* row1, STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2, bool forceSetNull) { #if 1 - char* pData = NULL; STSchema* pSchema; STSRow* row; int16_t colId; @@ -1503,12 +1500,6 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit while(i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; - } else { - pData = (char*)pColInfo->pData + (capacity - numOfRows - 1) * pColInfo->info.bytes; - } - int32_t colIdOfRow1; if(j >= numOfColsOfRow1) { colIdOfRow1 = INT32_MAX; @@ -1571,43 +1562,11 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit if (colId == pColInfo->info.colId) { if (tdValTypeIsNorm(sVal.valType)) { - switch (pColInfo->info.type) { - case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_NCHAR: - memcpy(pData, sVal.val, varDataTLen(sVal.val)); - break; - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: - *(uint8_t *)pData = *(uint8_t *)sVal.val; - break; - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: - *(uint16_t *)pData = *(uint16_t *)sVal.val; - break; - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: - *(uint32_t *)pData = *(uint32_t *)sVal.val; - break; - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - *(uint64_t *)pData = *(uint64_t *)sVal.val; - break; - case TSDB_DATA_TYPE_FLOAT: - SET_FLOAT_PTR(pData, sVal.val); - break; - case TSDB_DATA_TYPE_DOUBLE: - SET_DOUBLE_PTR(pData, sVal.val); - break; - case TSDB_DATA_TYPE_TIMESTAMP: - *(TSKEY*)pData = *(TSKEY*)sVal.val; - break; - default: - memcpy(pData, sVal.val, pColInfo->info.bytes); - } + colDataAppend(pColInfo, numOfRows, sVal.val, false); } else if (forceSetNull) { colDataAppend(pColInfo, numOfRows, NULL, true); } + i++; if(row == row1) { diff --git a/tests/script/tsim/insert/basic1.sim b/tests/script/tsim/insert/basic1.sim index 131044ac68..653a44a18a 100644 --- a/tests/script/tsim/insert/basic1.sim +++ b/tests/script/tsim/insert/basic1.sim @@ -55,7 +55,8 @@ if $rows != 4 then return -1 endi -if $data01 != true then +if $data01 != 1 then + print expect 1, actual: $data01 return -1 endi @@ -80,7 +81,7 @@ system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 check_dnode_ready: $loop_cnt = $loop_cnt + 1 - sleep 100 + sleep 200 if $loop_cnt == 10 then print ====> dnode not ready! return -1 @@ -105,7 +106,7 @@ if $rows != 4 then return -1 endi -if $data01 != true then +if $data01 != 1 then return -1 endi From 88fa8c586f5c3f04eb4a58bab1ac93f7d3bb6cfe Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Thu, 24 Mar 2022 11:44:47 +0800 Subject: [PATCH 68/68] [modify] --- tests/script/tsim/testCaseSuite.sim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/tsim/testCaseSuite.sim b/tests/script/tsim/testCaseSuite.sim index bca0204e63..c158837da7 100644 --- a/tests/script/tsim/testCaseSuite.sim +++ b/tests/script/tsim/testCaseSuite.sim @@ -11,7 +11,7 @@ run tsim/dnode/basic1.sim run tsim/insert/basic0.sim #run tsim/insert/basic1.sim # TD-14246 #run tsim/insert/backquote.sim # TD-14261 -#run tsim/insert/null.sim +run tsim/insert/null.sim run tsim/query/interval.sim #run tsim/query/interval-offset.sim # TD-14266