From 82faa5cd3440e83abdbe1b73f05d343c6a97893d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 30 Dec 2021 18:20:12 +0800 Subject: [PATCH 01/56] [td-11818] send table name instead of full name. --- source/dnode/mnode/impl/src/mndStb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 918f43f2bd..f81a19a780 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -207,7 +207,10 @@ static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb SMsgHead * pMsgHead; req.ver = 0; - req.name = pStb->name; + SName name = {0}; + tNameFromString(&name, pStb->name, T_NAME_ACCT|T_NAME_DB|T_NAME_TABLE); + + req.name = (char*) tNameGetTableName(&name); req.ttl = 0; req.keep = 0; req.type = TD_SUPER_TABLE; From 9859acf6eccaccbc986731305cff3d0d1f50f583 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 30 Dec 2021 22:56:30 +0800 Subject: [PATCH 02/56] [td-11818] fix compiler warning. --- source/client/test/clientTests.cpp | 28 ++++++++++++++++++++++++++ source/libs/parser/inc/astGenerator.h | 1 - source/libs/parser/inc/sql.y | 2 +- source/libs/parser/src/astGenerator.c | 1 - source/libs/parser/src/dCDAstProcess.c | 17 ---------------- source/libs/parser/src/parserUtil.c | 9 +++++++-- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 013cf794e3..f2c79bfd5a 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -462,3 +462,31 @@ TEST(testCase, show_table_Test) { taos_free_result(pRes); taos_close(pConn); } + +TEST(testCase, create_multiple_tables) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st2 tags(2)"); + if (taos_errno(pRes) != 0) { + printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + TAOS_ROW pRow = NULL; + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_free_result(pRes); + taos_close(pConn); +} diff --git a/source/libs/parser/inc/astGenerator.h b/source/libs/parser/inc/astGenerator.h index 0febc5ea33..22806969af 100644 --- a/source/libs/parser/inc/astGenerator.h +++ b/source/libs/parser/inc/astGenerator.h @@ -125,7 +125,6 @@ typedef struct SCreatedTableInfo { SArray *pTagNames; // create by using super table, tag name SArray *pTagVals; // create by using super table, tag value char *fullname; // table full name - STagData tagdata; // true tag data, super table full name is in STagData int8_t igExist; // ignore if exists } SCreatedTableInfo; diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index bf59a0f80a..789f5a98e2 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -188,7 +188,7 @@ cmd ::= COMPACT VNODES IN LP exprlist(Y) RP. { setCompactVnodeSql(pInfo, TSDB // And "ids" is an identifer-or-string. %type ids {SToken} ids(A) ::= ID(X). {A = X; } -ids(A) ::= STRING(X). {A = X; } +//ids(A) ::= STRING(X). {A = X; } %type ifexists {SToken} ifexists(X) ::= IF EXISTS. { X.n = 1;} diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index 3d12f0f3b7..9122b0df96 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -692,7 +692,6 @@ void freeCreateTableInfo(void* p) { taosArrayDestroy(pInfo->pTagNames); taosArrayDestroyEx(pInfo->pTagVals, freeItem); tfree(pInfo->fullname); - tfree(pInfo->tagdata.data); } SSqlInfo* setSqlInfo(SSqlInfo *pInfo, void *pSqlExprInfo, SToken *pTableName, int32_t type) { diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 6aa4ad8275..fd99cb6f66 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -363,7 +363,6 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p // too long tag values will return invalid sql, not be truncated automatically SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); STableComInfo tinfo = getTableInfo(pSuperTableMeta); - STagData* pTag = &pCreateTableInfo->tagdata; SKVRowBuilder kvRowBuilder = {0}; if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { @@ -463,22 +462,6 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SSchema* pSchema = &pTagSchema[i]; SToken* pItem = taosArrayGet(pValList, i); - if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { - if (pItem->n > pSchema->bytes) { - tdDestroyKVRowBuilder(&kvRowBuilder); - return buildInvalidOperationMsg(pMsgBuf, msg3); - } - } else if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) { - // if (pItem->pVar.nType == TSDB_DATA_TYPE_BINARY) { - //// code = convertTimestampStrToInt64(&(pItem->pVar), tinfo.precision); - // if (code != TSDB_CODE_SUCCESS) { - // return buildInvalidOperationMsg(pMsgBuf, msg4); - // } - // } else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) { - // pItem->pVar.i = convertTimePrecision(pItem->pVar.i, TSDB_TIME_PRECISION_NANO, tinfo.precision); - // } - } - char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; SKvParam param = {.builder = &kvRowBuilder, .schema = pSchema}; diff --git a/source/libs/parser/src/parserUtil.c b/source/libs/parser/src/parserUtil.c index 6c7ecbe0ed..22545255a3 100644 --- a/source/libs/parser/src/parserUtil.c +++ b/source/libs/parser/src/parserUtil.c @@ -571,7 +571,9 @@ void setColumn(SColumn* pColumn, uint64_t uid, const char* tableName, int8_t fla pColumn->info.type = pSchema->type; if (tableName != NULL) { - snprintf(pColumn->name, tListLen(pColumn->name), "%s.%s", tableName, pSchema->name); + char n[TSDB_COL_NAME_LEN + 1 + TSDB_TABLE_NAME_LEN] = {0}; + snprintf(n, tListLen(n), "%s.%s", tableName, pSchema->name); + tstrncpy(pColumn->name, n, tListLen(pColumn->name)); } else { tstrncpy(pColumn->name, pSchema->name, tListLen(pColumn->name)); } @@ -586,7 +588,10 @@ SColumn createColumn(uint64_t uid, const char* tableName, int8_t flag, const SSc c.info.type = pSchema->type; if (tableName != NULL) { - snprintf(c.name, tListLen(c.name), "%s.%s", tableName, pSchema->name); + char n[TSDB_COL_NAME_LEN + 1 + TSDB_TABLE_NAME_LEN] = {0}; + snprintf(n, tListLen(n), "%s.%s", tableName, pSchema->name); + + tstrncpy(c.name, n, tListLen(c.name)); } else { tstrncpy(c.name, pSchema->name, tListLen(c.name)); } From 4ff8072d3291f3082930517176e0074a58c313b8 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 31 Dec 2021 11:18:59 +0800 Subject: [PATCH 03/56] [td-11818] fix bug in show tables; --- source/client/test/clientTests.cpp | 54 ++++++++++++------------ source/dnode/vnode/impl/src/vnodeQuery.c | 4 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index f2c79bfd5a..97692d71b4 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -463,30 +463,30 @@ TEST(testCase, show_table_Test) { taos_close(pConn); } -TEST(testCase, create_multiple_tables) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "use abc1"); - taos_free_result(pRes); - - pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st2 tags(2)"); - if (taos_errno(pRes) != 0) { - printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - ASSERT_TRUE(false); - } - - TAOS_ROW pRow = NULL; - TAOS_FIELD* pFields = taos_fetch_fields(pRes); - int32_t numOfFields = taos_num_fields(pRes); - - char str[512] = {0}; - while((pRow = taos_fetch_row(pRes)) != NULL) { - int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); - } - - taos_free_result(pRes); - taos_close(pConn); -} +//TEST(testCase, create_multiple_tables) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st2 tags(2)"); +// if (taos_errno(pRes) != 0) { +// printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } +// +// TAOS_ROW pRow = NULL; +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// int32_t numOfFields = taos_num_fields(pRes); +// +// char str[512] = {0}; +// while((pRow = taos_fetch_row(pRes)) != NULL) { +// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); +// printf("%s\n", str); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index a80828b6f7..01df929080 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -136,7 +136,7 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { metaCloseTbCursor(pCur); - int32_t rowLen = (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4 + (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4; + int32_t rowLen = (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 2 + (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4; int32_t numOfTables = (int32_t) taosArrayGetSize(pArray); int32_t payloadLen = rowLen * numOfTables; @@ -150,7 +150,7 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { char* n = taosArrayGetP(pArray, i); STR_TO_VARSTR(p, n); - p += rowLen; + p += (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); } pFetchRsp->numOfRows = htonl(numOfTables); From ccc91cec3aa759b0550a58100d81225a684591ea Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 31 Dec 2021 11:23:44 +0800 Subject: [PATCH 04/56] feature/qnode --- include/libs/qcom/query.h | 2 +- include/libs/scheduler/scheduler.h | 22 +- source/libs/catalog/inc/catalogInt.h | 26 +- source/libs/catalog/src/catalog.c | 135 ++++-- source/libs/catalog/test/catalogTests.cpp | 442 +++++++++++++++++- source/libs/scheduler/inc/schedulerInt.h | 4 +- source/libs/scheduler/src/scheduler.c | 31 +- source/libs/scheduler/test/schedulerTests.cpp | 7 +- source/util/src/thash.c | 18 +- 9 files changed, 577 insertions(+), 110 deletions(-) diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 4ea35f1d2c..4d5b1a8bd3 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -75,7 +75,7 @@ typedef struct STableMeta { } STableMeta; typedef struct SDBVgroupInfo { - int32_t lock; + SRWLatch lock; int32_t vgVersion; int8_t hashMethod; SHashObj *vgInfo; //key:vgId, value:SVgroupInfo diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h index ddcfcab4db..d6cac976d4 100644 --- a/include/libs/scheduler/scheduler.h +++ b/include/libs/scheduler/scheduler.h @@ -50,23 +50,37 @@ typedef struct SQueryProfileSummary { uint64_t resultSize; // generated result size in Kb. } SQueryProfileSummary; +typedef struct SQueryNodeAddr{ + int32_t nodeId; //vgId or qnodeId + int8_t inUse; + int8_t numOfEps; + SEpAddrMsg epAddr[TSDB_MAX_REPLICA]; +} SQueryNodeAddr; + +typedef struct SQueryResult { + int32_t code; + uint64_t numOfRows; + int32_t msgSize; + char *msg; +} SQueryResult; + int32_t schedulerInit(SSchedulerCfg *cfg); /** * Process the query job, generated according to the query physical plan. * This is a synchronized API, and is also thread-safety. - * @param qnodeList Qnode address list, element is SEpAddr + * @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr * @return */ -int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob, uint64_t *numOfRows); +int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob, SQueryResult *pRes); /** * Process the query job, generated according to the query physical plan. * This is a asynchronized API, and is also thread-safety. - * @param qnodeList Qnode address list, element is SEpAddr + * @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr * @return */ -int32_t scheduleAsyncExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob); +int32_t scheduleAsyncExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob); int32_t scheduleFetchRows(void *pJob, void **data); diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 31b5939463..f426139c14 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -77,27 +77,37 @@ typedef uint32_t (*tableNameHashFp)(const char *, uint32_t); #define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0) #define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000 + #define CTG_LOCK(type, _lock) do { \ if (CTG_READ == (type)) { \ - if ((*(_lock)) < 0) assert(0); \ + assert(atomic_load_32((_lock)) >= 0); \ + ctgDebug("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ taosRLockLatch(_lock); \ - ctgDebug("CTG RLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + ctgDebug("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) > 0); \ } else { \ - if ((*(_lock)) < 0) assert(0); \ + assert(atomic_load_32((_lock)) >= 0); \ + ctgDebug("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ taosWLockLatch(_lock); \ - ctgDebug("CTG WLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + ctgDebug("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ } \ } while (0) #define CTG_UNLOCK(type, _lock) do { \ if (CTG_READ == (type)) { \ - if ((*(_lock)) <= 0) assert(0); \ + assert(atomic_load_32((_lock)) > 0); \ + ctgDebug("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ taosRUnLockLatch(_lock); \ - ctgDebug("CTG RULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + ctgDebug("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) >= 0); \ } else { \ - if ((*(_lock)) <= 0) assert(0); \ + assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ + ctgDebug("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ taosWUnLockLatch(_lock); \ - ctgDebug("CTG WULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \ + ctgDebug("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) >= 0); \ } \ } while (0) diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index b632ac772c..d881f226e4 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -23,21 +23,32 @@ SCatalogMgmt ctgMgmt = {0}; int32_t ctgGetDBVgroupFromCache(struct SCatalog* pCatalog, const char *dbName, SDBVgroupInfo **dbInfo, bool *inCache) { if (NULL == pCatalog->dbCache.cache) { *inCache = false; + ctgWarn("no db cache"); return TSDB_CODE_SUCCESS; } - SDBVgroupInfo *info = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); + SDBVgroupInfo *info = NULL; - if (NULL == info) { - *inCache = false; - return TSDB_CODE_SUCCESS; - } + while (true) { + info = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); - CTG_LOCK(CTG_READ, &info->lock); - if (NULL == info->vgInfo) { - CTG_UNLOCK(CTG_READ, &info->lock); - *inCache = false; - return TSDB_CODE_SUCCESS; + if (NULL == info) { + *inCache = false; + assert(0); + ctgWarn("no db cache, dbName:%s", dbName); + return TSDB_CODE_SUCCESS; + } + + CTG_LOCK(CTG_READ, &info->lock); + if (NULL == info->vgInfo) { + CTG_UNLOCK(CTG_READ, &info->lock); + taosHashRelease(pCatalog->dbCache.cache, info); + ctgWarn("db cache vgInfo is NULL, dbName:%s", dbName); + + continue; + } + + break; } *dbInfo = info; @@ -271,8 +282,6 @@ _return: int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup) { int32_t code = 0; - CTG_LOCK(CTG_READ, &dbInfo->lock); - int32_t vgNum = taosHashGetSize(dbInfo->vgInfo); char db[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(pTableName, db); @@ -311,8 +320,6 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName *pVgroup = *vgInfo; _return: - - CTG_UNLOCK(CTG_READ, &dbInfo->lock); CTG_RET(TSDB_CODE_SUCCESS); } @@ -422,6 +429,8 @@ int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgm if (0 == forceUpdate) { CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &inCache)); + assert(inCache); + if (inCache) { return TSDB_CODE_SUCCESS; } @@ -434,11 +443,47 @@ int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgm input.db[sizeof(input.db) - 1] = 0; input.vgVersion = CTG_DEFAULT_INVALID_VERSION; - CTG_ERR_RET(ctgGetDBVgroupFromMnode(pCatalog, pRpc, pMgmtEps, &input, &DbOut)); + while (true) { + CTG_ERR_RET(ctgGetDBVgroupFromMnode(pCatalog, pRpc, pMgmtEps, &input, &DbOut)); - CTG_ERR_RET(catalogUpdateDBVgroup(pCatalog, dbName, &DbOut.dbVgroup)); + CTG_ERR_RET(catalogUpdateDBVgroup(pCatalog, dbName, &DbOut.dbVgroup)); - CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &inCache)); + CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &inCache)); + + if (!inCache) { + ctgWarn("get db vgroup from cache failed, db:%s", dbName); + continue; + } + + break; + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t ctgValidateAndRemoveDb(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo) { + SDBVgroupInfo *oldInfo = (SDBVgroupInfo *)taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); + if (oldInfo) { + CTG_LOCK(CTG_WRITE, &oldInfo->lock); + if (dbInfo->vgVersion <= oldInfo->vgVersion) { + ctgInfo("dbName:%s vg will not update, vgVersion:%d , current:%d", dbName, dbInfo->vgVersion, oldInfo->vgVersion); + CTG_UNLOCK(CTG_WRITE, &oldInfo->lock); + taosHashRelease(pCatalog->dbCache.cache, oldInfo); + + return TSDB_CODE_SUCCESS; + } + + if (oldInfo->vgInfo) { + ctgInfo("dbName:%s vg will be cleanup", dbName); + taosHashCleanup(oldInfo->vgInfo); + oldInfo->vgInfo = NULL; + } + + CTG_UNLOCK(CTG_WRITE, &oldInfo->lock); + + taosHashRelease(pCatalog->dbCache.cache, oldInfo); + } return TSDB_CODE_SUCCESS; } @@ -581,55 +626,57 @@ _return: int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo) { + int32_t code = 0; + if (NULL == pCatalog || NULL == dbName || NULL == dbInfo) { - CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); + CTG_ERR_JRET(TSDB_CODE_CTG_INVALID_INPUT); + } + + if (NULL == dbInfo->vgInfo || dbInfo->vgVersion < 0 || taosHashGetSize(dbInfo->vgInfo) <= 0) { + ctgError("invalid db vg, dbName:%s", dbName); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } if (dbInfo->vgVersion < 0) { - if (pCatalog->dbCache.cache) { - SDBVgroupInfo *oldInfo = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); - if (oldInfo) { - CTG_LOCK(CTG_WRITE, &oldInfo->lock); - if (oldInfo->vgInfo) { - taosHashCleanup(oldInfo->vgInfo); - oldInfo->vgInfo = NULL; - } - CTG_UNLOCK(CTG_WRITE, &oldInfo->lock); + ctgWarn("invalid db vgVersion:%d, dbName:%s", dbInfo->vgVersion, dbName); - taosHashRelease(pCatalog->dbCache.cache, oldInfo); - } + if (pCatalog->dbCache.cache) { + CTG_ERR_JRET(ctgValidateAndRemoveDb(pCatalog, dbName, dbInfo)); + + CTG_ERR_JRET(taosHashRemove(pCatalog->dbCache.cache, dbName, strlen(dbName))); } ctgWarn("remove db [%s] from cache", dbName); - return TSDB_CODE_SUCCESS; + goto _return; } if (NULL == pCatalog->dbCache.cache) { pCatalog->dbCache.cache = taosHashInit(ctgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (NULL == pCatalog->dbCache.cache) { ctgError("init hash[%d] for db cache failed", CTG_DEFAULT_CACHE_DB_NUMBER); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } } else { - SDBVgroupInfo *oldInfo = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName)); - if (oldInfo) { - CTG_LOCK(CTG_WRITE, &oldInfo->lock); - if (oldInfo->vgInfo) { - taosHashCleanup(oldInfo->vgInfo); - oldInfo->vgInfo = NULL; - } - CTG_UNLOCK(CTG_WRITE, &oldInfo->lock); - - taosHashRelease(pCatalog->dbCache.cache, oldInfo); - } + CTG_ERR_JRET(ctgValidateAndRemoveDb(pCatalog, dbName, dbInfo)); } if (taosHashPut(pCatalog->dbCache.cache, dbName, strlen(dbName), dbInfo, sizeof(*dbInfo)) != 0) { ctgError("push to vgroup hash cache failed"); - CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } - return TSDB_CODE_SUCCESS; + ctgDebug("dbName:%s vgroup updated, vgVersion:%d", dbName, dbInfo->vgVersion); + + dbInfo->vgInfo = NULL; + +_return: + + if (dbInfo && dbInfo->vgInfo) { + taosHashCleanup(dbInfo->vgInfo); + dbInfo->vgInfo = NULL; + } + + CTG_RET(code); } int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 0ad00046cd..5bacbbd7e7 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -36,11 +36,19 @@ namespace { +extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableName, STableMeta** pTableMeta, int32_t *exist); +extern "C" int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output); + void ctgTestSetPrepareTableMeta(); void ctgTestSetPrepareCTableMeta(); void ctgTestSetPrepareSTableMeta(); +bool ctgTestStop = false; +bool ctgTestEnableSleep = false; +bool ctgTestDeadLoop = true; +int32_t ctgTestCurrentVgVersion = 0; +int32_t ctgTestVgVersion = 1; int32_t ctgTestVgNum = 10; int32_t ctgTestColNum = 2; int32_t ctgTestTagNum = 1; @@ -89,6 +97,113 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { ASSERT_EQ(rpcRsp.code, 0); } +void ctgTestInitLogFile() { + const char *defaultLogFileNamePrefix = "taoslog"; + const int32_t maxLogFileNum = 10; + + ctgDebugFlag = 159; + tsAsyncLog = 0; + + char temp[128] = {0}; + sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix); + if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) { + printf("failed to open log file in directory:%s\n", tsLogDir); + } + +} + +int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) { + return ((vgVersion % 2) == 0) ? ctgTestVgNum - 2 : ctgTestVgNum; +} + +void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) { + SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; + strcpy(cn.dbname, "db1"); + strcpy(cn.tname, ctgTestCTablename); + + SName sn = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; + strcpy(sn.dbname, "db1"); + strcpy(sn.tname, ctgTestSTablename); + + char tbFullName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(&cn, tbFullName); + + output->metaNum = 2; + + strcpy(output->ctbFname, tbFullName); + + tNameExtractFullName(&cn, tbFullName); + strcpy(output->tbFname, tbFullName); + + output->ctbMeta.vgId = 9; + output->ctbMeta.tableType = TSDB_CHILD_TABLE; + output->ctbMeta.uid = 3; + output->ctbMeta.suid = 2; + + output->tbMeta = (STableMeta *)calloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum)); + output->tbMeta->vgId = 9; + output->tbMeta->tableType = TSDB_SUPER_TABLE; + output->tbMeta->uid = 2; + output->tbMeta->suid = 2; + + output->tbMeta->tableInfo.numOfColumns = ctgTestColNum; + output->tbMeta->tableInfo.numOfTags = ctgTestTagNum; + + output->tbMeta->sversion = ctgTestSVersion; + output->tbMeta->tversion = ctgTestTVersion; + + SSchema *s = NULL; + s = &output->tbMeta->schema[0]; + s->type = TSDB_DATA_TYPE_TIMESTAMP; + s->colId = 1; + s->bytes = 8; + strcpy(s->name, "ts"); + + s = &output->tbMeta->schema[1]; + s->type = TSDB_DATA_TYPE_INT; + s->colId = 2; + s->bytes = 4; + strcpy(s->name, "col1s"); + + s = &output->tbMeta->schema[2]; + s->type = TSDB_DATA_TYPE_BINARY; + s->colId = 3; + s->bytes = 12; + strcpy(s->name, "tag1s"); + +} + +void ctgTestBuildDBVgroup(SDBVgroupInfo *dbVgroup) { + static int32_t vgVersion = ctgTestVgVersion + 1; + int32_t vgNum = 0; + SVgroupInfo vgInfo = {0}; + + dbVgroup->vgVersion = vgVersion++; + + ctgTestCurrentVgVersion = dbVgroup->vgVersion; + + dbVgroup->hashMethod = 0; + dbVgroup->vgInfo = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); + + vgNum = ctgTestGetVgNumFromVgVersion(dbVgroup->vgVersion); + uint32_t hashUnit = UINT32_MAX / vgNum; + + for (int32_t i = 0; i < vgNum; ++i) { + vgInfo.vgId = i + 1; + vgInfo.hashBegin = i * hashUnit; + vgInfo.hashEnd = hashUnit * (i + 1) - 1; + vgInfo.numOfEps = i % TSDB_MAX_REPLICA + 1; + vgInfo.inUse = i % vgInfo.numOfEps; + for (int32_t n = 0; n < vgInfo.numOfEps; ++n) { + SEpAddrMsg *addr = &vgInfo.epAddr[n]; + strcpy(addr->fqdn, "a0"); + addr->port = htons(n + 22); + } + + taosHashPut(dbVgroup->vgInfo, &vgInfo.vgId, sizeof(vgInfo.vgId), &vgInfo, sizeof(vgInfo)); + } +} + void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { SUseDbRsp *rspMsg = NULL; //todo @@ -97,7 +212,8 @@ void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcM pRsp->pCont = calloc(1, pRsp->contLen); rspMsg = (SUseDbRsp *)pRsp->pCont; strcpy(rspMsg->db, ctgTestDbname); - rspMsg->vgVersion = htonl(1); + rspMsg->vgVersion = htonl(ctgTestVgVersion); + ctgTestCurrentVgVersion = ctgTestVgVersion; rspMsg->vgNum = htonl(ctgTestVgNum); rspMsg->hashMethod = 0; @@ -148,13 +264,13 @@ void ctgTestPrepareTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcM SSchema *s = NULL; s = &rspMsg->pSchema[0]; s->type = TSDB_DATA_TYPE_TIMESTAMP; - s->colId = htonl(0); + s->colId = htonl(1); s->bytes = htonl(8); strcpy(s->name, "ts"); s = &rspMsg->pSchema[1]; s->type = TSDB_DATA_TYPE_INT; - s->colId = htonl(1); + s->colId = htonl(2); s->bytes = htonl(4); strcpy(s->name, "col1"); @@ -185,19 +301,19 @@ void ctgTestPrepareCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpc SSchema *s = NULL; s = &rspMsg->pSchema[0]; s->type = TSDB_DATA_TYPE_TIMESTAMP; - s->colId = htonl(0); + s->colId = htonl(1); s->bytes = htonl(8); strcpy(s->name, "ts"); s = &rspMsg->pSchema[1]; s->type = TSDB_DATA_TYPE_INT; - s->colId = htonl(1); + s->colId = htonl(2); s->bytes = htonl(4); strcpy(s->name, "col1s"); s = &rspMsg->pSchema[2]; s->type = TSDB_DATA_TYPE_BINARY; - s->colId = htonl(2); + s->colId = htonl(3); s->bytes = htonl(12); strcpy(s->name, "tag1s"); @@ -229,19 +345,19 @@ void ctgTestPrepareSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpc SSchema *s = NULL; s = &rspMsg->pSchema[0]; s->type = TSDB_DATA_TYPE_TIMESTAMP; - s->colId = htonl(0); + s->colId = htonl(1); s->bytes = htonl(8); strcpy(s->name, "ts"); s = &rspMsg->pSchema[1]; s->type = TSDB_DATA_TYPE_INT; - s->colId = htonl(1); + s->colId = htonl(2); s->bytes = htonl(4); strcpy(s->name, "col1s"); s = &rspMsg->pSchema[2]; s->type = TSDB_DATA_TYPE_BINARY; - s->colId = htonl(2); + s->colId = htonl(3); s->bytes = htonl(12); strcpy(s->name, "tag1s"); @@ -371,6 +487,117 @@ void ctgTestSetPrepareDbVgroupsAndSuperMeta() { } +void *ctgTestGetDbVgroupThread(void *param) { + struct SCatalog* pCtg = (struct SCatalog*)param; + int32_t code = 0; + void *mockPointer = (void *)0x1; + SArray *vgList = NULL; + int32_t n = 0; + + while (!ctgTestStop) { + code = catalogGetDBVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, ctgTestDbname, false, &vgList); + if (code) { + assert(0); + } + + if (vgList) { + taosArrayDestroy(vgList); + } + + if (ctgTestEnableSleep) { + usleep(rand()%5); + } + if (++n % 50000 == 0) { + printf("Get:%d\n", n); + } + } + + return NULL; +} + +void *ctgTestSetDbVgroupThread(void *param) { + struct SCatalog* pCtg = (struct SCatalog*)param; + int32_t code = 0; + SDBVgroupInfo dbVgroup = {0}; + int32_t n = 0; + + while (!ctgTestStop) { + ctgTestBuildDBVgroup(&dbVgroup); + code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, &dbVgroup); + if (code) { + assert(0); + } + + if (ctgTestEnableSleep) { + usleep(rand()%5); + } + if (++n % 50000 == 0) { + printf("Set:%d\n", n); + } + } + + return NULL; + +} + +void *ctgTestGetCtableMetaThread(void *param) { + struct SCatalog* pCtg = (struct SCatalog*)param; + int32_t code = 0; + int32_t n = 0; + STableMeta* tbMeta = NULL; + int32_t exist = 0; + + SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; + strcpy(cn.dbname, "db1"); + strcpy(cn.tname, ctgTestCTablename); + + while (!ctgTestStop) { + code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &exist); + if (code || 0 == exist) { + assert(0); + } + + if (ctgTestEnableSleep) { + usleep(rand()%5); + } + + if (++n % 50000 == 0) { + printf("Get:%d\n", n); + } + } + + return NULL; +} + +void *ctgTestSetCtableMetaThread(void *param) { + struct SCatalog* pCtg = (struct SCatalog*)param; + int32_t code = 0; + SDBVgroupInfo dbVgroup = {0}; + int32_t n = 0; + STableMetaOutput output = {0}; + + ctgTestBuildCTableMetaOutput(&output); + + while (!ctgTestStop) { + code = ctgUpdateTableMetaCache(pCtg, &output); + if (code) { + assert(0); + } + + if (ctgTestEnableSleep) { + usleep(rand()%5); + } + if (++n % 50000 == 0) { + printf("Set:%d\n", n); + } + } + + return NULL; + +} + +#if 0 + TEST(tableMeta, normalTable) { struct SCatalog* pCtg = NULL; void *mockPointer = (void *)0x1; @@ -388,7 +615,7 @@ TEST(tableMeta, normalTable) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = {.type = T_NAME_TABLE, .acctId = 1}; + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -436,11 +663,13 @@ TEST(tableMeta, childTableCase) { initQueryModuleMsgHandle(); //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); - int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg); + code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = {.type = T_NAME_TABLE, .acctId = 1}; + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestCTablename); @@ -494,11 +723,14 @@ TEST(tableMeta, superTableCase) { initQueryModuleMsgHandle(); - //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); - int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg); + int32_t code = catalogInit(NULL); ASSERT_EQ(code, 0); - SName n = {.type = T_NAME_TABLE, .acctId = 1}; + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestSTablename); @@ -558,12 +790,15 @@ TEST(tableDistVgroup, normalTable) { initQueryModuleMsgHandle(); - //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); - - int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg); + int32_t code = catalogInit(NULL); ASSERT_EQ(code, 0); - SName n = {.type = T_NAME_TABLE, .acctId = 1}; + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -595,7 +830,7 @@ TEST(tableDistVgroup, childTableCase) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = {.type = T_NAME_TABLE, .acctId = 1}; + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestCTablename); @@ -620,11 +855,14 @@ TEST(tableDistVgroup, superTableCase) { initQueryModuleMsgHandle(); - //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); - int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg); + int32_t code = catalogInit(NULL); ASSERT_EQ(code, 0); - SName n = {.type = T_NAME_TABLE, .acctId = 1}; + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestSTablename); @@ -645,6 +883,164 @@ TEST(tableDistVgroup, superTableCase) { catalogDestroy(); } +TEST(dbVgroup, getSetDbVgroupCase) { + struct SCatalog* pCtg = NULL; + void *mockPointer = (void *)0x1; + SVgroupInfo vgInfo = {0}; + SVgroupInfo *pvgInfo = NULL; + SDBVgroupInfo dbVgroup = {0}; + SArray *vgList = NULL; + + ctgTestSetPrepareDbVgroupsAndNormalMeta(); + + initQueryModuleMsgHandle(); + + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestTablename); + + code = catalogGetDBVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, ctgTestDbname, false, &vgList); + ASSERT_EQ(code, 0); + ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum); + + code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); + ASSERT_EQ(code, 0); + ASSERT_EQ(vgInfo.vgId, 8); + ASSERT_EQ(vgInfo.numOfEps, 3); + + code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList); + ASSERT_EQ(code, 0); + ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1); + pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); + ASSERT_EQ(pvgInfo->vgId, 8); + ASSERT_EQ(pvgInfo->numOfEps, 3); + taosArrayDestroy(vgList); + + ctgTestBuildDBVgroup(&dbVgroup); + code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, &dbVgroup); + ASSERT_EQ(code, 0); + + code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); + ASSERT_EQ(code, 0); + ASSERT_EQ(vgInfo.vgId, 7); + ASSERT_EQ(vgInfo.numOfEps, 2); + + code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList); + ASSERT_EQ(code, 0); + ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1); + pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); + ASSERT_EQ(pvgInfo->vgId, 8); + ASSERT_EQ(pvgInfo->numOfEps, 3); + taosArrayDestroy(vgList); + + catalogDestroy(); +} + +#endif + +TEST(multiThread, getSetDbVgroupCase) { + struct SCatalog* pCtg = NULL; + void *mockPointer = (void *)0x1; + SVgroupInfo vgInfo = {0}; + SVgroupInfo *pvgInfo = NULL; + SDBVgroupInfo dbVgroup = {0}; + SArray *vgList = NULL; + + ctgTestInitLogFile(); + + ctgTestSetPrepareDbVgroups(); + + initQueryModuleMsgHandle(); + + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestTablename); + + pthread_attr_t thattr; + pthread_attr_init(&thattr); + + pthread_t thread1, thread2; + pthread_create(&(thread1), &thattr, ctgTestSetDbVgroupThread, pCtg); + + sleep(1); + pthread_create(&(thread1), &thattr, ctgTestGetDbVgroupThread, pCtg); + + while (true) { + if (ctgTestDeadLoop) { + sleep(1); + } else { + sleep(600); + break; + } + } + + ctgTestStop = true; + sleep(1); + + catalogDestroy(); +} + +TEST(multiThread, ctableMeta) { + struct SCatalog* pCtg = NULL; + void *mockPointer = (void *)0x1; + SVgroupInfo vgInfo = {0}; + SVgroupInfo *pvgInfo = NULL; + SDBVgroupInfo dbVgroup = {0}; + SArray *vgList = NULL; + + ctgTestSetPrepareDbVgroupsAndChildMeta(); + + initQueryModuleMsgHandle(); + + //sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestTablename); + + pthread_attr_t thattr; + pthread_attr_init(&thattr); + + pthread_t thread1, thread2; + pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg); + pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg); + + while (true) { + if (ctgTestDeadLoop) { + sleep(1); + } else { + sleep(600); + break; + } + } + + ctgTestStop = true; + sleep(1); + + catalogDestroy(); +} int main(int argc, char** argv) { diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index c327e4cfea..2770f7e21a 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -89,12 +89,12 @@ typedef struct SSchJob { SEpSet dataSrcEps; SEpAddr resEp; void *transport; - SArray *qnodeList; + SArray *nodeList; // qnode/vnode list, element is SQueryNodeAddr tsem_t rspSem; int32_t userFetch; int32_t remoteFetch; - SSchTask *fetchTask; + SSchTask *fetchTask; int32_t errCode; void *res; int32_t resNumOfRows; diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 7bd2205e43..429211bdb8 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -220,10 +220,10 @@ int32_t schSetTaskExecEpSet(SSchJob *job, SEpSet *epSet) { return TSDB_CODE_SUCCESS; } - int32_t qnodeNum = taosArrayGetSize(job->qnodeList); + int32_t nodeNum = taosArrayGetSize(job->nodeList); - for (int32_t i = 0; i < qnodeNum && epSet->numOfEps < tListLen(epSet->port); ++i) { - SEpAddr *addr = taosArrayGet(job->qnodeList, i); + for (int32_t i = 0; i < nodeNum && epSet->numOfEps < tListLen(epSet->port); ++i) { + SEpAddr *addr = taosArrayGet(job->nodeList, i); strncpy(epSet->fqdn[epSet->numOfEps], addr->fqdn, sizeof(addr->fqdn)); epSet->port[epSet->numOfEps] = addr->port; @@ -829,8 +829,8 @@ int32_t schedulerInit(SSchedulerCfg *cfg) { } -int32_t scheduleExecJobImpl(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob, bool syncSchedule) { - if (qnodeList && taosArrayGetSize(qnodeList) <= 0) { +int32_t scheduleExecJobImpl(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob, bool syncSchedule) { + if (nodeList && taosArrayGetSize(nodeList) <= 0) { qInfo("qnodeList is empty"); } @@ -842,7 +842,7 @@ int32_t scheduleExecJobImpl(void *transport, SArray *qnodeList, SQueryDag* pDag, job->attr.syncSchedule = syncSchedule; job->transport = transport; - job->qnodeList = qnodeList; + job->nodeList = nodeList; SCH_ERR_JRET(schValidateAndBuildJob(pDag, job)); @@ -897,28 +897,27 @@ _return: SCH_RET(code); } -int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob, uint64_t *numOfRows) { - if (NULL == transport || /* NULL == qnodeList || */ NULL == pDag || NULL == pDag->pSubplans || NULL == pJob || NULL == numOfRows) { +int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob, SQueryResult *pRes) { + if (NULL == transport || /* NULL == nodeList || */ NULL == pDag || NULL == pDag->pSubplans || NULL == pJob || NULL == pRes) { SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - *numOfRows = 0; - - SCH_ERR_RET(scheduleExecJobImpl(transport, qnodeList, pDag, pJob, true)); + SCH_ERR_RET(scheduleExecJobImpl(transport, nodeList, pDag, pJob, true)); SSchJob *job = *(SSchJob **)pJob; - *numOfRows = job->resNumOfRows; - + pRes->code = job->errCode; + pRes->numOfRows = job->resNumOfRows; + return TSDB_CODE_SUCCESS; } -int32_t scheduleAsyncExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob) { - if (NULL == transport || NULL == qnodeList ||NULL == pDag || NULL == pDag->pSubplans || NULL == pJob) { +int32_t scheduleAsyncExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob) { + if (NULL == transport || NULL == nodeList ||NULL == pDag || NULL == pDag->pSubplans || NULL == pJob) { SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - return scheduleExecJobImpl(transport, qnodeList, pDag, pJob, false); + return scheduleExecJobImpl(transport, nodeList, pDag, pJob, false); } diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index 6163bc0c1a..b418ade172 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -321,10 +321,11 @@ TEST(insertTest, normalCase) { pthread_t thread1; pthread_create(&(thread1), &thattr, schtSendRsp, &pInsertJob); - - code = scheduleExecJob(mockPointer, qnodeList, &dag, &pInsertJob, &numOfRows); + + SQueryResult res = {0}; + code = scheduleExecJob(mockPointer, qnodeList, &dag, &pInsertJob, &res); ASSERT_EQ(code, 0); - ASSERT_EQ(numOfRows, 20); + ASSERT_EQ(res.numOfRows, 20); scheduleFreeJob(pInsertJob); } diff --git a/source/util/src/thash.c b/source/util/src/thash.c index 840a1ef390..2841f27da4 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -132,7 +132,7 @@ static FORCE_INLINE SHashNode *doUpdateHashNode(SHashObj *pHashObj, SHashEntry* } else { pNewNode->next = pNode; pe->num++; - atomic_add_fetch_64(&pHashObj->size, 1); + atomic_add_fetch_32(&pHashObj->size, 1); } return pNewNode; @@ -209,7 +209,7 @@ int32_t taosHashGetSize(const SHashObj *pHashObj) { if (!pHashObj) { return 0; } - return (int32_t)atomic_load_64(&pHashObj->size); + return (int32_t)atomic_load_32(&pHashObj->size); } static FORCE_INLINE bool taosHashTableEmpty(const SHashObj *pHashObj) { @@ -273,7 +273,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da // enable resize __rd_unlock(&pHashObj->lock, pHashObj->type); - atomic_add_fetch_64(&pHashObj->size, 1); + atomic_add_fetch_32(&pHashObj->size, 1); return 0; } else { @@ -405,7 +405,7 @@ void* taosHashGetCloneImpl(SHashObj *pHashObj, const void *key, size_t keyLen, v } if (acquire) { - pNode->count++; + atomic_add_fetch_16(&pNode->count, 1); } data = GET_HASH_NODE_DATA(pNode); @@ -482,7 +482,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, voi // if (data) memcpy(data, GET_HASH_NODE_DATA(pNode), dsize); pe->num--; - atomic_sub_fetch_64(&pHashObj->size, 1); + atomic_sub_fetch_32(&pHashObj->size, 1); FREE_HASH_NODE(pHashObj, pNode); } } @@ -520,7 +520,7 @@ int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), voi while((pNode = pEntry->next) != NULL) { if (fp && (!fp(param, GET_HASH_NODE_DATA(pNode)))) { pEntry->num -= 1; - atomic_sub_fetch_64(&pHashObj->size, 1); + atomic_sub_fetch_32(&pHashObj->size, 1); pEntry->next = pNode->next; @@ -546,7 +546,7 @@ int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), voi if (fp && (!fp(param, GET_HASH_NODE_DATA(pNext)))) { pNode->next = pNext->next; pEntry->num -= 1; - atomic_sub_fetch_64(&pHashObj->size, 1); + atomic_sub_fetch_32(&pHashObj->size, 1); if (pEntry->num == 0) { assert(pEntry->next == NULL); @@ -600,7 +600,7 @@ void taosHashClear(SHashObj *pHashObj) { pEntry->next = NULL; } - pHashObj->size = 0; + atomic_store_32(&pHashObj->size, 0); __wr_unlock(&pHashObj->lock, pHashObj->type); } @@ -847,7 +847,7 @@ static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) { } pe->num--; - atomic_sub_fetch_64(&pHashObj->size, 1); + atomic_sub_fetch_32(&pHashObj->size, 1); FREE_HASH_NODE(pHashObj, pOld); } } else { From 8e9183a04a4b64d489ddc51d95cec7ef912f5120 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 31 Dec 2021 03:39:51 +0000 Subject: [PATCH 05/56] more --- include/common/tmsg.h | 5 +++++ include/dnode/vnode/meta/meta.h | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 17a4d4ad2c..6bb5406bba 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1271,6 +1271,11 @@ typedef struct SVCreateTbReq { }; } SVCreateTbReq; +typedef struct { + uint64_t ver; // use a general definition + SArray* pArray; +} SVCreateTbBatchReq; + int tmsgSVCreateTbReqEncode(SMsgEncoder* pCoder, SVCreateTbReq* pReq); int tmsgSVCreateTbReqDecode(SMsgDecoder* pCoder, SVCreateTbReq* pReq); int tSerializeSVCreateTbReq(void** buf, const SVCreateTbReq* pReq); diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index b75e478add..d587107270 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -59,9 +59,9 @@ STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid); STbCfg * metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid); SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline); -SMTbCursor * metaOpenTbCursor(SMeta *pMeta); -void metaCloseTbCursor(SMTbCursor *pTbCur); -char *metaTbCursorNext(SMTbCursor *pTbCur); +SMTbCursor *metaOpenTbCursor(SMeta *pMeta); +void metaCloseTbCursor(SMTbCursor *pTbCur); +char * metaTbCursorNext(SMTbCursor *pTbCur); // Options void metaOptionsInit(SMetaCfg *pMetaCfg); From dc8bad19df35ad3a3300deb5f03a36f67940c42e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 31 Dec 2021 03:45:44 +0000 Subject: [PATCH 06/56] more --- include/common/tmsg.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 6bb5406bba..80dec89611 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -23,6 +23,7 @@ extern "C" { #include "encode.h" #include "taosdef.h" #include "taoserror.h" +#include "tarray.h" #include "tcoding.h" #include "tdataformat.h" #include "tlist.h" From b4203385514d5ccabf281ad14c4b07ab7b0a14be Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 31 Dec 2021 13:34:38 +0800 Subject: [PATCH 07/56] feature/qnode --- include/common/tmsg.h | 7 +++++-- source/dnode/mgmt/impl/src/dndTransport.c | 4 ++-- source/dnode/vnode/impl/src/vnodeQuery.c | 18 ++++++++++++++++-- source/libs/catalog/src/catalog.c | 14 +++++--------- source/libs/qcom/src/querymsg.c | 2 +- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 17a4d4ad2c..0b7ba24c6b 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -774,8 +774,8 @@ typedef struct { } SAuthVnodeMsg; typedef struct { - int32_t vgId; - char tableFname[TSDB_TABLE_FNAME_LEN]; + SMsgHead header; + char tableFname[TSDB_TABLE_FNAME_LEN]; } STableInfoMsg; typedef struct { @@ -1059,6 +1059,7 @@ typedef struct { } SUpdateTagValRsp; typedef struct SSubQueryMsg { + SMsgHead header; uint64_t sId; uint64_t queryId; uint64_t taskId; @@ -1067,6 +1068,7 @@ typedef struct SSubQueryMsg { } SSubQueryMsg; typedef struct SResReadyMsg { + SMsgHead header; uint64_t sId; uint64_t queryId; uint64_t taskId; @@ -1077,6 +1079,7 @@ typedef struct SResReadyRsp { } SResReadyRsp; typedef struct SResFetchMsg { + SMsgHead header; uint64_t sId; uint64_t queryId; uint64_t taskId; diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index e5be16937b..dc5248c8e0 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -121,8 +121,8 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { pMgmt->msgFp[TMSG_INDEX(TDMT_VND_FETCH)] = dndProcessVnodeFetchMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_VND_UPDATE_TAG_VAL)] = dndProcessVnodeWriteMsg; - pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLE_META)] = dndProcessVnodeQueryMsg; - pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLES_META)] = dndProcessVnodeQueryMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLE_META)] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLES_META)] = dndProcessVnodeFetchMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONSUME)] = dndProcessVnodeQueryMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_QUERY)] = dndProcessVnodeQueryMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONNECT)] = dndProcessVnodeWriteMsg; diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index 01df929080..daa1e964de 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -17,6 +17,7 @@ #include "vnodeDef.h" static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg); +static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int vnodeQueryOpen(SVnode *pVnode) { return qWorkerInit(NULL, &pVnode->pQuery); } @@ -43,6 +44,8 @@ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { case TDMT_VND_SHOW_TABLES_FETCH: return vnodeGetTableList(pVnode, pMsg); // return qWorkerProcessShowFetchMsg(pVnode->pMeta, pVnode->pQuery, pMsg); + case TDMT_VND_TABLE_META: + return vnodeGetTableMeta(pVnode, pMsg, pRsp); default: vError("unknown msg type:%d in fetch queue", pMsg->msgType); return TSDB_CODE_VND_APP_ERROR; @@ -88,7 +91,8 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { pTagSchema = NULL; } - pTbMetaMsg = (STableMetaMsg *)calloc(1, sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols)); + int msgLen = sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols); + pTbMetaMsg = (STableMetaMsg *)rpcMallocCont(msgLen); if (pTbMetaMsg == NULL) { return -1; } @@ -115,6 +119,16 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { pSch->bytes = htonl(pSch->bytes); } + SRpcMsg rpcMsg = { + .handle = pMsg->handle, + .ahandle = pMsg->ahandle, + .pCont = pTbMetaMsg, + .contLen = msgLen, + .code = 0, + }; + + rpcSendResponse(&rpcMsg); + return 0; } @@ -166,4 +180,4 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { rpcSendResponse(&rpcMsg); return 0; -} \ No newline at end of file +} diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index b8fa779e70..68ff1b8557 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -34,7 +34,6 @@ int32_t ctgGetDBVgroupFromCache(struct SCatalog* pCatalog, const char *dbName, S if (NULL == info) { *inCache = false; - assert(0); ctgWarn("no db cache, dbName:%s", dbName); return TSDB_CODE_SUCCESS; } @@ -190,14 +189,13 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE } -int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char *pDBName, const char* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* output) { - if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pDBName || NULL == pTableName || NULL == vgroupInfo || NULL == output) { +int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* output) { + if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == vgroupInfo || NULL == output) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } char tbFullName[TSDB_TABLE_FNAME_LEN]; - - snprintf(tbFullName, sizeof(tbFullName), "%s.%s", pDBName, pTableName); + tNameExtractFullName(pTableName, tbFullName); SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .tableFullName = tbFullName}; char *msg = NULL; @@ -429,8 +427,6 @@ int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgm if (0 == forceUpdate) { CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &inCache)); - assert(inCache); - if (inCache) { return TSDB_CODE_SUCCESS; } @@ -694,9 +690,9 @@ int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSe STableMetaOutput output = {0}; - //CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, &vgroupInfo, &output)); + CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pRpc, pMgmtEps, pTableName, &vgroupInfo, &output)); - CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pTableName, &output)); + //CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pTableName, &output)); CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, &output)); diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 27ca406fc4..117297b9ff 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -40,7 +40,7 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3 STableInfoMsg *bMsg = (STableInfoMsg *)*msg; - bMsg->vgId = bInput->vgId; + bMsg->header.vgId = htonl(bInput->vgId); strncpy(bMsg->tableFname, bInput->tableFullName, sizeof(bMsg->tableFname)); bMsg->tableFname[sizeof(bMsg->tableFname) - 1] = 0; From 76e393d4a8f354eef5e4ce6feb5ea300278ff856 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 31 Dec 2021 05:41:58 +0000 Subject: [PATCH 08/56] more --- include/common/tmsg.h | 18 +++++----- include/util/freelist.h | 59 +++++++++++++++++++++++++++++++ source/util/test/CMakeLists.txt | 8 +++++ source/util/test/freelistTest.cpp | 16 +++++++++ 4 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 include/util/freelist.h create mode 100644 source/util/test/freelistTest.cpp diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 80dec89611..bf7a6ea11b 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -355,9 +355,9 @@ typedef struct SEpSet { } SEpSet; static FORCE_INLINE int taosEncodeSEpSet(void** buf, const SEpSet* pEp) { - if(buf == NULL) return sizeof(SEpSet); + if (buf == NULL) return sizeof(SEpSet); memcpy(buf, pEp, sizeof(SEpSet)); - //TODO: endian conversion + // TODO: endian conversion return sizeof(SEpSet); } @@ -1119,10 +1119,10 @@ typedef struct STaskDropRsp { } STaskDropRsp; typedef struct { - int8_t igExists; - char* name; - char* physicalPlan; - char* logicalPlan; + int8_t igExists; + char* name; + char* physicalPlan; + char* logicalPlan; } SCMCreateTopicReq; static FORCE_INLINE int tSerializeSCMCreateTopicReq(void** buf, const SCMCreateTopicReq* pReq) { @@ -1158,8 +1158,8 @@ static FORCE_INLINE void* tDeserializeSCMCreateTopicRsp(void* buf, SCMCreateTopi } typedef struct { - char* topicName; - char* consumerGroup; + char* topicName; + char* consumerGroup; int64_t consumerId; } SCMSubscribeReq; @@ -1180,7 +1180,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq typedef struct { int32_t vgId; - SEpSet pEpSet; + SEpSet pEpSet; } SCMSubscribeRsp; static FORCE_INLINE int tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribeRsp* pRsp) { diff --git a/include/util/freelist.h b/include/util/freelist.h new file mode 100644 index 0000000000..497a6d58c3 --- /dev/null +++ b/include/util/freelist.h @@ -0,0 +1,59 @@ +/* + * 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_UTIL_FREELIST_H_ +#define _TD_UTIL_FREELIST_H_ + +#include "os.h" +#include "tlist.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct SFreeListNode { + TD_SLIST_NODE(SFreeListNode); + char payload[]; +}; + +typedef TD_SLIST(SFreeListNode) SFreeList; + +#define TFL_MALLOC(SIZE, LIST) \ + ({ \ + void *ptr = malloc((SIZE) + sizeof(struct SFreeListNode)); \ + if (ptr) { \ + TD_SLIST_PUSH((LIST), (struct SFreeListNode *)ptr); \ + ptr = ((struct SFreeListNode *)ptr)->payload; \ + } \ + ptr; \ + }) + +#define tFreeListInit(pFL) TD_SLIST_INIT(pFL) + +static FORCE_INLINE void tFreeListClear(SFreeList *pFL) { + struct SFreeListNode *pNode; + for (;;) { + pNode = TD_SLIST_HEAD(pFL); + if (pNode == NULL) break; + TD_SLIST_POP(pFL); + free(pNode); + } +} + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_UTIL_FREELIST_H_*/ \ No newline at end of file diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index 79aaa1beb0..bfc3906f79 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -33,4 +33,12 @@ ENDIF() INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +# freelistTest +add_executable(freelistTest "") +target_sources(freelistTest + PRIVATE + "freelistTest.cpp" +) +target_link_libraries(freelistTest os util gtest gtest_main) + diff --git a/source/util/test/freelistTest.cpp b/source/util/test/freelistTest.cpp new file mode 100644 index 0000000000..7a4e8be5b7 --- /dev/null +++ b/source/util/test/freelistTest.cpp @@ -0,0 +1,16 @@ +#include "gtest/gtest.h" + +#include "freelist.h" + +TEST(TD_UTIL_FREELIST_TEST, simple_test) { + SFreeList fl; + + tFreeListInit(&fl); + + for (size_t i = 0; i < 1000; i++) { + void *ptr = TFL_MALLOC(1024, &fl); + GTEST_ASSERT_NE(ptr, nullptr); + } + + tFreeListClear(&fl); +} \ No newline at end of file From 5ee6cbd4e383c8b40871c0a5731d56757087140f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 31 Dec 2021 06:02:48 +0000 Subject: [PATCH 09/56] more --- source/dnode/vnode/impl/src/vnodeQuery.c | 50 ++++++++++++------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index daa1e964de..d869c245d9 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -17,7 +17,7 @@ #include "vnodeDef.h" static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg); -static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); +static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int vnodeQueryOpen(SVnode *pVnode) { return qWorkerInit(NULL, &pVnode->pQuery); } @@ -43,7 +43,7 @@ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { return qWorkerProcessShowMsg(pVnode, pVnode->pQuery, pMsg); case TDMT_VND_SHOW_TABLES_FETCH: return vnodeGetTableList(pVnode, pMsg); -// return qWorkerProcessShowFetchMsg(pVnode->pMeta, pVnode->pQuery, pMsg); + // return qWorkerProcessShowFetchMsg(pVnode->pMeta, pVnode->pQuery, pMsg); case TDMT_VND_TABLE_META: return vnodeGetTableMeta(pVnode, pMsg, pRsp); default: @@ -62,16 +62,17 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { SSchemaWrapper *pSW; STableMetaMsg * pTbMetaMsg; SSchema * pTagSchema; + SRpcMsg rpcMsg; pTbCfg = metaGetTbInfoByName(pVnode->pMeta, pReq->tableFname, &uid); if (pTbCfg == NULL) { - return -1; + goto _exit; } if (pTbCfg->type == META_CHILD_TABLE) { pStbCfg = metaGetTbInfoByUid(pVnode->pMeta, pTbCfg->ctbCfg.suid); if (pStbCfg == NULL) { - return -1; + goto _exit; } pSW = metaGetTableSchema(pVnode->pMeta, pTbCfg->ctbCfg.suid, 0, true); @@ -94,7 +95,7 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { int msgLen = sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols); pTbMetaMsg = (STableMetaMsg *)rpcMallocCont(msgLen); if (pTbMetaMsg == NULL) { - return -1; + goto _exit; } strcpy(pTbMetaMsg->tbFname, pTbCfg->name); @@ -119,13 +120,13 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { pSch->bytes = htonl(pSch->bytes); } - SRpcMsg rpcMsg = { - .handle = pMsg->handle, - .ahandle = pMsg->ahandle, - .pCont = pTbMetaMsg, - .contLen = msgLen, - .code = 0, - }; +_exit: + + rpcMsg.handle = pMsg->handle; + rpcMsg.ahandle = pMsg->ahandle; + rpcMsg.pCont = pTbMetaMsg; + rpcMsg.contLen = msgLen; + rpcMsg.code = 0; rpcSendResponse(&rpcMsg); @@ -138,10 +139,10 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { * @param pRsp */ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { - SMTbCursor* pCur = metaOpenTbCursor(pVnode->pMeta); - SArray* pArray = taosArrayInit(10, POINTER_BYTES); + SMTbCursor *pCur = metaOpenTbCursor(pVnode->pMeta); + SArray * pArray = taosArrayInit(10, POINTER_BYTES); - char* name = NULL; + char * name = NULL; int32_t totalLen = 0; while ((name = metaTbCursorNext(pCur)) != NULL) { taosArrayPush(pArray, &name); @@ -150,18 +151,19 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { metaCloseTbCursor(pCur); - int32_t rowLen = (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 2 + (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4; - int32_t numOfTables = (int32_t) taosArrayGetSize(pArray); + int32_t rowLen = + (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 2 + (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4; + int32_t numOfTables = (int32_t)taosArrayGetSize(pArray); int32_t payloadLen = rowLen * numOfTables; -// SVShowTablesFetchReq *pFetchReq = pMsg->pCont; + // SVShowTablesFetchReq *pFetchReq = pMsg->pCont; SVShowTablesFetchRsp *pFetchRsp = (SVShowTablesFetchRsp *)rpcMallocCont(sizeof(SVShowTablesFetchRsp) + payloadLen); memset(pFetchRsp, 0, sizeof(struct SVShowTablesFetchRsp) + payloadLen); - char* p = pFetchRsp->data; - for(int32_t i = 0; i < numOfTables; ++i) { - char* n = taosArrayGetP(pArray, i); + char *p = pFetchRsp->data; + for (int32_t i = 0; i < numOfTables; ++i) { + char *n = taosArrayGetP(pArray, i); STR_TO_VARSTR(p, n); p += (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); @@ -171,11 +173,11 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { pFetchRsp->precision = 0; SRpcMsg rpcMsg = { - .handle = pMsg->handle, + .handle = pMsg->handle, .ahandle = pMsg->ahandle, - .pCont = pFetchRsp, + .pCont = pFetchRsp, .contLen = sizeof(SVShowTablesFetchRsp) + payloadLen, - .code = 0, + .code = 0, }; rpcSendResponse(&rpcMsg); From 953ef456ef6def74e884b6653110d8a6f1c07639 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 31 Dec 2021 14:26:05 +0800 Subject: [PATCH 10/56] feature/qnode --- include/common/tmsg.h | 2 ++ source/libs/catalog/src/catalog.c | 29 ++++++++++------------- source/libs/catalog/test/catalogTests.cpp | 11 +++++++-- source/libs/qcom/src/querymsg.c | 5 ++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 5cf027591f..483337f43b 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -174,6 +174,7 @@ typedef enum _mgmt_table { typedef struct SBuildTableMetaInput { int32_t vgId; + char* dbName; char* tableFullName; } SBuildTableMetaInput; @@ -776,6 +777,7 @@ typedef struct { typedef struct { SMsgHead header; + char dbFname[TSDB_DB_FNAME_LEN]; char tableFname[TSDB_TABLE_FNAME_LEN]; } STableInfoMsg; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 68ff1b8557..236264873e 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -161,7 +161,7 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE char tbFullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pTableName, tbFullName); - SBuildTableMetaInput bInput = {.vgId = 0, .tableFullName = tbFullName}; + SBuildTableMetaInput bInput = {.vgId = 0, .dbName = NULL, .tableFullName = tbFullName}; char *msg = NULL; SEpSet *pVnodeEpSet = NULL; int32_t msgLen = 0; @@ -194,10 +194,10 @@ int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SE CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } - char tbFullName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(pTableName, tbFullName); + char dbFullName[TSDB_DB_FNAME_LEN]; + tNameGetFullDbName(pTableName, dbFullName); - SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .tableFullName = tbFullName}; + SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .dbName = dbFullName, .tableFullName = pTableName->tname}; char *msg = NULL; SEpSet *pVnodeEpSet = NULL; int32_t msgLen = 0; @@ -355,19 +355,19 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out if (output->metaNum != 1 && output->metaNum != 2) { ctgError("invalid table meta number[%d] got from meta rsp", output->metaNum); - CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } if (NULL == output->tbMeta) { ctgError("no valid table meta got from meta rsp"); - CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } if (NULL == pCatalog->tableCache.cache) { pCatalog->tableCache.cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (NULL == pCatalog->tableCache.cache) { ctgError("init hash[%d] for tablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); - CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } } @@ -375,19 +375,19 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out pCatalog->tableCache.stableCache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_ENTRY_LOCK); if (NULL == pCatalog->tableCache.stableCache) { ctgError("init hash[%d] for stablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); - CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } } if (output->metaNum == 2) { if (taosHashPut(pCatalog->tableCache.cache, output->ctbFname, strlen(output->ctbFname), &output->ctbMeta, sizeof(output->ctbMeta)) != 0) { ctgError("push ctable[%s] to table cache failed", output->ctbFname); - CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } if (TSDB_SUPER_TABLE != output->tbMeta->tableType) { ctgError("table type[%d] error, expected:%d", output->tbMeta->tableType, TSDB_SUPER_TABLE); - CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } } @@ -398,26 +398,23 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out if (taosHashPut(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname), output->tbMeta, tbSize) != 0) { CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock); ctgError("push table[%s] to table cache failed", output->tbFname); - CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } STableMeta *tbMeta = taosHashGet(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname)); if (taosHashPut(pCatalog->tableCache.stableCache, &output->tbMeta->suid, sizeof(output->tbMeta->suid), &tbMeta, POINTER_BYTES) != 0) { CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock); ctgError("push suid[%"PRIu64"] to stable cache failed", output->tbMeta->suid); - CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock); } else { if (taosHashPut(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname), output->tbMeta, tbSize) != 0) { ctgError("push table[%s] to table cache failed", output->tbFname); - CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } } -_return: - tfree(output->tbMeta); - CTG_RET(code); } diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 5979d3a147..1d8a48dfcb 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -557,6 +557,8 @@ void *ctgTestGetCtableMetaThread(void *param) { assert(0); } + tfree(tbMeta); + if (ctgTestEnableSleep) { usleep(rand()%5); } @@ -592,6 +594,8 @@ void *ctgTestSetCtableMetaThread(void *param) { } } + tfree(output.tbMeta); + return NULL; } @@ -944,7 +948,6 @@ TEST(dbVgroup, getSetDbVgroupCase) { catalogDestroy(); } -#endif TEST(multiThread, getSetDbVgroupCase) { struct SCatalog* pCtg = NULL; @@ -996,6 +999,9 @@ TEST(multiThread, getSetDbVgroupCase) { catalogDestroy(); } +#endif + + TEST(multiThread, ctableMeta) { struct SCatalog* pCtg = NULL; void *mockPointer = (void *)0x1; @@ -1024,8 +1030,9 @@ TEST(multiThread, ctableMeta) { pthread_attr_init(&thattr); pthread_t thread1, thread2; - pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg); pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg); + sleep(1); + pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg); while (true) { if (ctgTestDeadLoop) { diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 117297b9ff..1e27749a1a 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -42,6 +42,11 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3 bMsg->header.vgId = htonl(bInput->vgId); + if (bInput->dbName) { + strncpy(bMsg->dbFname, bInput->dbName, sizeof(bMsg->dbFname)); + bMsg->dbFname[sizeof(bMsg->dbFname) - 1] = 0; + } + strncpy(bMsg->tableFname, bInput->tableFullName, sizeof(bMsg->tableFname)); bMsg->tableFname[sizeof(bMsg->tableFname) - 1] = 0; From 86c2d4b42e6452c8496918408961aced4d4e6215 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 31 Dec 2021 14:43:04 +0800 Subject: [PATCH 11/56] [td-11818] support create table in batch. --- source/client/test/clientTests.cpp | 60 ++++++++++++------------- source/libs/parser/src/dCDAstProcess.c | 62 +++++++++++++++----------- 2 files changed, 65 insertions(+), 57 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 97692d71b4..7a87acfc36 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -435,42 +435,14 @@ TEST(testCase, connect_Test) { // taos_close(pConn); //} -TEST(testCase, show_table_Test) { - TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); - - TAOS_RES* pRes = taos_query(pConn, "use abc1"); - taos_free_result(pRes); - - pRes = taos_query(pConn, "show tables"); - if (taos_errno(pRes) != 0) { - printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - ASSERT_TRUE(false); - } - - TAOS_ROW pRow = NULL; - TAOS_FIELD* pFields = taos_fetch_fields(pRes); - int32_t numOfFields = taos_num_fields(pRes); - - char str[512] = {0}; - while((pRow = taos_fetch_row(pRes)) != NULL) { - int32_t code = taos_print_row(str, pRow, pFields, numOfFields); - printf("%s\n", str); - } - - taos_free_result(pRes); - taos_close(pConn); -} - -//TEST(testCase, create_multiple_tables) { +//TEST(testCase, show_table_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); // // TAOS_RES* pRes = taos_query(pConn, "use abc1"); // taos_free_result(pRes); // -// pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st2 tags(2)"); +// pRes = taos_query(pConn, "show tables"); // if (taos_errno(pRes) != 0) { // printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); // taos_free_result(pRes); @@ -490,3 +462,31 @@ TEST(testCase, show_table_Test) { // taos_free_result(pRes); // taos_close(pConn); //} + +TEST(testCase, create_multiple_tables) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)"); + if (taos_errno(pRes) != 0) { + printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + TAOS_ROW pRow = NULL; + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_free_result(pRes); + taos_close(pConn); +} diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index fd99cb6f66..024870014b 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -321,6 +321,11 @@ int32_t doCheckForCreateTable(SSqlInfo* pInfo, SMsgBuf* pMsgBuf) { return TSDB_CODE_SUCCESS; } +typedef struct SVgroupTablesBatch { + SVCreateTbBatchReq req; + SVgroupInfo info; +} SVgroupTablesBatch; + int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len, SEpSet* pEpSet) { const char* msg1 = "invalid table name"; @@ -330,17 +335,14 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + // super table name, create table by using dst - int32_t numOfTables = (int32_t)taosArrayGetSize(pCreateTable->childTableInfo); + size_t numOfTables = taosArrayGetSize(pCreateTable->childTableInfo); for (int32_t j = 0; j < numOfTables; ++j) { SCreatedTableInfo* pCreateTableInfo = taosArrayGet(pCreateTable->childTableInfo, j); SToken* pSTableNameToken = &pCreateTableInfo->stbName; - - char buf[TSDB_TABLE_FNAME_LEN]; - SToken sTblToken; - sTblToken.z = buf; - int32_t code = parserValidateNameToken(pSTableNameToken); if (code != TSDB_CODE_SUCCESS) { return buildInvalidOperationMsg(pMsgBuf, msg1); @@ -460,12 +462,13 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p for (int32_t i = 0; i < numOfInputTag; ++i) { SSchema* pSchema = &pTagSchema[i]; - SToken* pItem = taosArrayGet(pValList, i); - - char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; - SKvParam param = {.builder = &kvRowBuilder, .schema = pSchema}; char* endPtr = NULL; + char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; + + SKvParam param = {.builder = &kvRowBuilder, .schema = pSchema}; + + SToken* pItem = taosArrayGet(pValList, i); code = parseValueToken(&endPtr, pItem, pSchema, tinfo.precision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); if (code != TSDB_CODE_SUCCESS) { @@ -478,7 +481,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder); if (row == NULL) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; } tdSortKVRowByColIdx(row); @@ -489,31 +492,36 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p return code; } + SVgroupInfo info = {0}; + catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); + struct SVCreateTbReq req = {0}; req.type = TD_CHILD_TABLE; req.name = strdup(tNameGetTableName(&tableName)); req.ctbCfg.suid = pSuperTableMeta->suid; req.ctbCfg.pTag = row; - int32_t serLen = sizeof(SMsgHead) + tSerializeSVCreateTbReq(NULL, &req); - char* buf1 = calloc(1, serLen); - *pOutput = buf1; - buf1 += sizeof(SMsgHead); - tSerializeSVCreateTbReq((void*)&buf1, &req); - *len = serLen; +// pEpSet->inUse = info.inUse; +// pEpSet->numOfEps = info.numOfEps; +// for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { +// pEpSet->port[i] = info.epAddr[i].port; +// tstrncpy(pEpSet->fqdn[i], info.epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); +// } +// ((SMsgHead*)(*pOutput))->vgId = htonl(info.vgId); +// ((SMsgHead*)(*pOutput))->contLen = htonl(serLen); + SVgroupTablesBatch *pTableBatch = taosHashGet(pVgroupHashmap, &info.vgId, sizeof(info.vgId)); + if (pTableBatch == NULL) { + SVgroupTablesBatch tBatch = {0}; + tBatch.info = info; - SVgroupInfo info = {0}; - catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); + tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq)); + taosArrayPush(tBatch.req.pArray, &req); - pEpSet->inUse = info.inUse; - pEpSet->numOfEps = info.numOfEps; - for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { - pEpSet->port[i] = info.epAddr[i].port; - tstrncpy(pEpSet->fqdn[i], info.epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); + taosHashPut(pVgroupHashmap, &info.vgId, sizeof(info.vgId), &tBatch, sizeof(tBatch)); + } else { // add to the correct vgroup + assert(info.vgId == pTableBatch->info.vgId); + taosArrayPush(pTableBatch->req.pArray, &req); } - - ((SMsgHead*)(*pOutput))->vgId = htonl(info.vgId); - ((SMsgHead*)(*pOutput))->contLen = htonl(serLen); } return TSDB_CODE_SUCCESS; From 36437b65cecaa32a697fafccce3402606e5a8e0e Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 31 Dec 2021 14:43:13 +0800 Subject: [PATCH 12/56] feature/qnode --- include/common/tmsg.h | 1 + source/dnode/vnode/impl/src/vnodeQuery.c | 19 ++++++++++++------- source/libs/qcom/src/querymsg.c | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index cf3712b444..39f50e0496 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -812,6 +812,7 @@ typedef struct { typedef struct { char tbFname[TSDB_TABLE_FNAME_LEN]; // table full name char stbFname[TSDB_TABLE_FNAME_LEN]; + char dbFname[TSDB_DB_FNAME_LEN]; int32_t numOfTags; int32_t numOfColumns; int8_t precision; diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index d869c245d9..cbc4d75e8b 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -60,9 +60,11 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { int32_t nCols; int32_t nTagCols; SSchemaWrapper *pSW; - STableMetaMsg * pTbMetaMsg; + STableMetaMsg * pTbMetaMsg = NULL; SSchema * pTagSchema; SRpcMsg rpcMsg; + int msgLen = 0; + int32_t code = TSDB_CODE_VND_APP_ERROR; pTbCfg = metaGetTbInfoByName(pVnode->pMeta, pReq->tableFname, &uid); if (pTbCfg == NULL) { @@ -92,12 +94,13 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { pTagSchema = NULL; } - int msgLen = sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols); + msgLen = sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols); pTbMetaMsg = (STableMetaMsg *)rpcMallocCont(msgLen); if (pTbMetaMsg == NULL) { goto _exit; } + memcpy(pTbMetaMsg->dbFname, pReq->dbFname, sizeof(pTbMetaMsg->dbFname)); strcpy(pTbMetaMsg->tbFname, pTbCfg->name); if (pTbCfg->type == META_CHILD_TABLE) { strcpy(pTbMetaMsg->stbFname, pStbCfg->name); @@ -120,13 +123,15 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { pSch->bytes = htonl(pSch->bytes); } + code = 0; + _exit: - rpcMsg.handle = pMsg->handle; - rpcMsg.ahandle = pMsg->ahandle; - rpcMsg.pCont = pTbMetaMsg; - rpcMsg.contLen = msgLen; - rpcMsg.code = 0; + rpcMsg.handle = pMsg->handle; + rpcMsg.ahandle = pMsg->ahandle; + rpcMsg.pCont = pTbMetaMsg; + rpcMsg.contLen = msgLen; + rpcMsg.code = code; rpcSendResponse(&rpcMsg); diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 1e27749a1a..29f84ddcd0 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -248,9 +248,14 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { if (pMetaMsg->tableType == TSDB_CHILD_TABLE) { pOut->metaNum = 2; - - memcpy(pOut->ctbFname, pMetaMsg->tbFname, sizeof(pOut->ctbFname)); - memcpy(pOut->tbFname, pMetaMsg->stbFname, sizeof(pOut->tbFname)); + + if (pMetaMsg->dbFname[0]) { + snprintf(pOut->ctbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); + snprintf(pOut->tbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); + } else { + memcpy(pOut->ctbFname, pMetaMsg->tbFname, sizeof(pOut->ctbFname)); + memcpy(pOut->tbFname, pMetaMsg->stbFname, sizeof(pOut->tbFname)); + } pOut->ctbMeta.vgId = pMetaMsg->vgId; pOut->ctbMeta.tableType = pMetaMsg->tableType; @@ -261,7 +266,11 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { } else { pOut->metaNum = 1; - memcpy(pOut->tbFname, pMetaMsg->tbFname, sizeof(pOut->tbFname)); + if (pMetaMsg->dbFname[0]) { + snprintf(pOut->tbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); + } else { + memcpy(pOut->tbFname, pMetaMsg->tbFname, sizeof(pOut->tbFname)); + } code = queryCreateTableMetaFromMsg(pMetaMsg, false, &pOut->tbMeta); } From d9cd1a7a0f74f22b1ed880e06910b349d316a527 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 31 Dec 2021 07:32:02 +0000 Subject: [PATCH 13/56] fix table meta query problem --- include/dnode/vnode/meta/meta.h | 2 +- source/dnode/vnode/meta/src/metaBDBImpl.c | 101 ++++++++++------------ 2 files changed, 49 insertions(+), 54 deletions(-) diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index d587107270..b8b8bad74a 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -38,7 +38,7 @@ typedef struct SMetaCfg { } SMetaCfg; typedef struct { - int32_t nCols; + uint32_t nCols; SSchema *pSchema; } SSchemaWrapper; diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index af8af6a052..4254ad0acd 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -23,6 +23,7 @@ typedef struct { tb_uid_t uid; int32_t sver; + int32_t padding; } SSchemaKey; struct SMetaDB { @@ -55,6 +56,8 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT * static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg); static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg); static void metaClearTbCfg(STbCfg *pTbCfg); +static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW); +static void * metaDecodeSchema(void *buf, SSchemaWrapper *pSW); #define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code)) @@ -169,18 +172,13 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { pBuf = buf; memset(&key, 0, sizeof(key)); memset(&value, 0, sizeof(key)); - SSchemaKey schemaKey = {uid, 0 /*TODO*/}; + SSchemaKey schemaKey = {uid, 0 /*TODO*/, 0}; key.data = &schemaKey; key.size = sizeof(schemaKey); - taosEncodeFixedU32(&pBuf, ncols); - for (size_t i = 0; i < ncols; i++) { - taosEncodeFixedI8(&pBuf, pSchema[i].type); - taosEncodeFixedI32(&pBuf, pSchema[i].colId); - taosEncodeFixedI32(&pBuf, pSchema[i].bytes); - taosEncodeString(&pBuf, pSchema[i].name); - } + SSchemaWrapper sw = {.nCols = ncols, .pSchema = pSchema}; + metaEncodeSchema(&pBuf, &sw); value.data = buf; value.size = POINTER_DISTANCE(pBuf, buf); @@ -197,6 +195,38 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) { } /* ------------------------ STATIC METHODS ------------------------ */ +static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) { + int tlen = 0; + SSchema *pSchema; + + tlen += taosEncodeFixedU32(buf, pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + pSchema = pSW->pSchema + i; + tlen += taosEncodeFixedI8(buf, pSchema->type); + tlen += taosEncodeFixedI32(buf, pSchema->colId); + tlen += taosEncodeFixedI32(buf, pSchema->bytes); + tlen += taosEncodeString(buf, pSchema->name); + } + + return tlen; +} + +static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { + SSchema *pSchema; + + buf = taosDecodeFixedU32(buf, &pSW->nCols); + pSW->pSchema = (SSchema *)malloc(sizeof(SSchema) * pSW->nCols); + for (int i = 0; i < pSW->nCols; i++) { + pSchema = pSW->pSchema + i; + buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosDecodeFixedI32(buf, &pSchema->colId); + buf = taosDecodeFixedI32(buf, &pSchema->bytes); + buf = taosDecodeStringTo(buf, pSchema->name); + } + + return buf; +} + static SMetaDB *metaNewDB() { SMetaDB *pDB = NULL; pDB = (SMetaDB *)calloc(1, sizeof(*pDB)); @@ -376,15 +406,8 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) { tsize += taosEncodeFixedU8(buf, pTbCfg->type); if (pTbCfg->type == META_SUPER_TABLE) { - tsize += taosEncodeVariantU32(buf, pTbCfg->stbCfg.nTagCols); - for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) { - tsize += taosEncodeFixedI8(buf, pTbCfg->stbCfg.pTagSchema[i].type); - tsize += taosEncodeFixedI32(buf, pTbCfg->stbCfg.pTagSchema[i].colId); - tsize += taosEncodeFixedI32(buf, pTbCfg->stbCfg.pTagSchema[i].bytes); - tsize += taosEncodeString(buf, pTbCfg->stbCfg.pTagSchema[i].name); - } - - // tsize += tdEncodeSchema(buf, pTbCfg->stbCfg.pTagSchema); + SSchemaWrapper sw = {.nCols = pTbCfg->stbCfg.nTagCols, .pSchema = pTbCfg->stbCfg.pTagSchema}; + tsize += metaEncodeSchema(buf, &sw); } else if (pTbCfg->type == META_CHILD_TABLE) { tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid); tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag); @@ -403,14 +426,10 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) { buf = taosDecodeFixedU8(buf, &(pTbCfg->type)); if (pTbCfg->type == META_SUPER_TABLE) { - buf = taosDecodeVariantU32(buf, &(pTbCfg->stbCfg.nTagCols)); - pTbCfg->stbCfg.pTagSchema = (SSchema *)malloc(sizeof(SSchema) * pTbCfg->stbCfg.nTagCols); - for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) { - buf = taosDecodeFixedI8(buf, &(pTbCfg->stbCfg.pTagSchema[i].type)); - buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pTagSchema[i].colId); - buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pTagSchema[i].bytes); - buf = taosDecodeStringTo(buf, pTbCfg->stbCfg.pTagSchema[i].name); - } + SSchemaWrapper sw; + buf = metaDecodeSchema(buf, &sw); + pTbCfg->stbCfg.nTagCols = sw.nCols; + pTbCfg->stbCfg.pTagSchema = sw.pSchema; } else if (pTbCfg->type == META_CHILD_TABLE) { buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid)); buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag)); @@ -496,7 +515,7 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo int ret; void * pBuf; SSchema * pSchema; - SSchemaKey schemaKey = {uid, sver}; + SSchemaKey schemaKey = {uid, sver, 0}; DBT key = {0}; DBT value = {0}; @@ -507,38 +526,14 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo // Query ret = pDB->pSchemaDB->get(pDB->pSchemaDB, NULL, &key, &value, 0); if (ret != 0) { + printf("failed to query schema DB since %s================\n", db_strerror(ret)); return NULL; } // Decode the schema pBuf = value.data; - taosDecodeFixedI32(&pBuf, &nCols); - if (isinline) { - pSW = (SSchemaWrapper *)malloc(sizeof(*pSW) + sizeof(SSchema) * nCols); - if (pSW == NULL) { - return NULL; - } - pSW->pSchema = POINTER_SHIFT(pSW, sizeof(*pSW)); - } else { - pSW = (SSchemaWrapper *)malloc(sizeof(*pSW)); - if (pSW == NULL) { - return NULL; - } - - pSW->pSchema = (SSchema *)malloc(sizeof(SSchema) * nCols); - if (pSW->pSchema == NULL) { - free(pSW); - return NULL; - } - } - - for (int i = 0; i < nCols; i++) { - pSchema = pSW->pSchema + i; - taosDecodeFixedI8(&pBuf, &(pSchema->type)); - taosDecodeFixedI32(&pBuf, &(pSchema->colId)); - taosDecodeFixedI32(&pBuf, &(pSchema->bytes)); - taosDecodeStringTo(&pBuf, pSchema->name); - } + pSW = malloc(sizeof(*pSW)); + metaDecodeSchema(pBuf, pSW); return pSW; } From 54af08bc98f2111b953f34ce146a96878dd8c0c6 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 31 Dec 2021 07:48:21 +0000 Subject: [PATCH 14/56] fix more --- include/common/tmsg.h | 6 +++--- include/dnode/vnode/meta/meta.h | 8 ++++---- source/dnode/vnode/meta/inc/metaTbCfg.h | 4 ---- source/libs/parser/src/dCDAstProcess.c | 3 +++ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 39f50e0496..10aba94656 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1255,9 +1255,9 @@ typedef struct SVCreateTbReq { char* name; uint32_t ttl; uint32_t keep; -#define TD_SUPER_TABLE 0 -#define TD_CHILD_TABLE 1 -#define TD_NORMAL_TABLE 2 +#define TD_SUPER_TABLE TSDB_SUPER_TABLE +#define TD_CHILD_TABLE TSDB_CHILD_TABLE +#define TD_NORMAL_TABLE TSDB_NORMAL_TABLE uint8_t type; union { struct { diff --git a/include/dnode/vnode/meta/meta.h b/include/dnode/vnode/meta/meta.h index b8b8bad74a..86ebb643a4 100644 --- a/include/dnode/vnode/meta/meta.h +++ b/include/dnode/vnode/meta/meta.h @@ -25,13 +25,13 @@ extern "C" { #endif +#define META_SUPER_TABLE TD_SUPER_TABLE +#define META_CHILD_TABLE TD_CHILD_TABLE +#define META_NORMAL_TABLE TD_NORMAL_TABLE + // Types exported typedef struct SMeta SMeta; -#define META_SUPER_TABLE 0 -#define META_CHILD_TABLE 1 -#define META_NORMAL_TABLE 2 - typedef struct SMetaCfg { /// LRU cache size uint64_t lruSize; diff --git a/source/dnode/vnode/meta/inc/metaTbCfg.h b/source/dnode/vnode/meta/inc/metaTbCfg.h index b4ee095967..b7b3924d14 100644 --- a/source/dnode/vnode/meta/inc/metaTbCfg.h +++ b/source/dnode/vnode/meta/inc/metaTbCfg.h @@ -22,10 +22,6 @@ extern "C" { #endif -#define META_SUPER_TABLE TD_SUPER_TABLE -#define META_CHILD_TABLE TD_CHILD_TABLE -#define META_NORMAL_TABLE TD_NORMAL_TABLE - int metaValidateTbCfg(SMeta *pMeta, const STbCfg *); size_t metaEncodeTbObjFromTbOptions(const STbCfg *, void *pBuf, size_t bsize); diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 024870014b..8c11f6e528 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -524,6 +524,9 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p } } + // TODO: serialize and + void *pBuf = NULL; + return TSDB_CODE_SUCCESS; } From 1c57b5e74675b1408d65674d685bb1f2f2fe583f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 31 Dec 2021 08:30:40 +0000 Subject: [PATCH 15/56] batch create table --- include/common/tmsg.h | 4 +- source/common/src/tmsg.c | 29 ++++++++++++- source/dnode/vnode/impl/src/vnodeWrite.c | 17 ++++++-- source/libs/parser/src/dCDAstProcess.c | 55 ++++++++++++++++-------- 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 10aba94656..af250bff03 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1285,8 +1285,10 @@ typedef struct { int tmsgSVCreateTbReqEncode(SMsgEncoder* pCoder, SVCreateTbReq* pReq); int tmsgSVCreateTbReqDecode(SMsgDecoder* pCoder, SVCreateTbReq* pReq); -int tSerializeSVCreateTbReq(void** buf, const SVCreateTbReq* pReq); +int tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq); void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq); +int tSVCreateTbBatchReqSerialize(void** buf, SVCreateTbBatchReq* pReq); +void* tSVCreateTbBatchReqDeserialize(void* buf, SVCreateTbBatchReq* pReq); typedef struct SVCreateTbRsp { } SVCreateTbRsp; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b81143ee62..a18a472dba 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -98,7 +98,7 @@ int tmsgSVCreateTbReqDecode(SMsgDecoder *pCoder, SVCreateTbReq *pReq) { return 0; } -int tSerializeSVCreateTbReq(void **buf, const SVCreateTbReq *pReq) { +int tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { int tlen = 0; tlen += taosEncodeFixedU64(buf, pReq->ver); @@ -193,6 +193,33 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { return buf; } +int tSVCreateTbBatchReqSerialize(void **buf, SVCreateTbBatchReq *pReq) { + int tlen = 0; + + tlen += taosEncodeFixedU64(buf, pReq->ver); + tlen += taosEncodeFixedU32(buf, taosArrayGetSize(pReq->pArray)); + for (size_t i = 0; i < taosArrayGetSize(pReq->pArray); i++) { + SVCreateTbReq *pCreateTbReq = taosArrayGet(pReq->pArray, i); + tlen += tSerializeSVCreateTbReq(buf, pCreateTbReq); + } + + return tlen; +} + +void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) { + uint32_t nsize = 0; + + buf = taosDecodeFixedU64(buf, &pReq->ver); + buf = taosDecodeFixedU32(buf, &nsize); + for (size_t i = 0; i < nsize; i++) { + SVCreateTbReq req; + buf = tDeserializeSVCreateTbReq(buf, &req); + taosArrayPush(pReq->pArray, &req); + } + + return buf; +} + /* ------------------------ STATIC METHODS ------------------------ */ static int tmsgStartEncode(SMsgEncoder *pME) { struct SMEListNode *pNode = (struct SMEListNode *)malloc(sizeof(*pNode)); diff --git a/source/dnode/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c index 3b1442a02c..88a73ca174 100644 --- a/source/dnode/vnode/impl/src/vnodeWrite.c +++ b/source/dnode/vnode/impl/src/vnodeWrite.c @@ -27,7 +27,7 @@ int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) { } int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { - SRpcMsg * pMsg; + SRpcMsg *pMsg; for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); @@ -50,8 +50,9 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { } int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - SVCreateTbReq vCreateTbReq; - void * ptr = vnodeMalloc(pVnode, pMsg->contLen); + SVCreateTbReq vCreateTbReq; + SVCreateTbBatchReq vCreateTbBatchReq; + void * ptr = vnodeMalloc(pVnode, pMsg->contLen); if (ptr == NULL) { // TODO: handle error } @@ -68,7 +69,6 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { switch (pMsg->msgType) { case TDMT_VND_CREATE_STB: - case TDMT_VND_CREATE_TABLE: tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbReq); if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { // TODO: handle error @@ -76,6 +76,15 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // TODO: maybe need to clear the requst struct break; + case TDMT_VND_CREATE_TABLE: + tSVCreateTbBatchReqDeserialize(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbBatchReq); + for (int i = 0; i < taosArrayGetSize(vCreateTbBatchReq.pArray); i++) { + SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i); + if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { + // TODO: handle error + } + } + case TDMT_VND_DROP_STB: case TDMT_VND_DROP_TABLE: // if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) { diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 8c11f6e528..ecea48f583 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -35,7 +35,7 @@ static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx* pCtx, void** ou SVShowTablesReq* pShowReq = calloc(1, sizeof(SVShowTablesReq)); SArray* array = NULL; - SName name = {0}; + SName name = {0}; tNameSetDbName(&name, pCtx->acctId, pCtx->db, strlen(pCtx->db)); char dbFname[TSDB_DB_FNAME_LEN] = {0}; @@ -48,7 +48,7 @@ static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx* pCtx, void** ou pEpSet->numOfEps = info->numOfEps; pEpSet->inUse = info->inUse; - for(int32_t i = 0; i < pEpSet->numOfEps; ++i) { + for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { strncpy(pEpSet->fqdn[i], info->epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); pEpSet->port[i] = info->epAddr[i].port; } @@ -190,7 +190,7 @@ static int32_t doCheckDbOptions(SCreateDbMsg* pCreate, SMsgBuf* pMsgBuf) { val = htonl(pCreate->numOfVgroups); if (val < TSDB_MIN_VNODES_PER_DB || val > TSDB_MAX_VNODES_PER_DB) { snprintf(msg, tListLen(msg), "invalid number of vgroups for DB:%d valid range: [%d, %d]", val, - TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB); + TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB); } return TSDB_CODE_SUCCESS; @@ -468,7 +468,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SKvParam param = {.builder = &kvRowBuilder, .schema = pSchema}; - SToken* pItem = taosArrayGet(pValList, i); + SToken* pItem = taosArrayGet(pValList, i); code = parseValueToken(&endPtr, pItem, pSchema, tinfo.precision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); if (code != TSDB_CODE_SUCCESS) { @@ -481,7 +481,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder); if (row == NULL) { - return TSDB_CODE_QRY_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; } tdSortKVRowByColIdx(row); @@ -501,15 +501,15 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p req.ctbCfg.suid = pSuperTableMeta->suid; req.ctbCfg.pTag = row; -// pEpSet->inUse = info.inUse; -// pEpSet->numOfEps = info.numOfEps; -// for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { -// pEpSet->port[i] = info.epAddr[i].port; -// tstrncpy(pEpSet->fqdn[i], info.epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); -// } -// ((SMsgHead*)(*pOutput))->vgId = htonl(info.vgId); -// ((SMsgHead*)(*pOutput))->contLen = htonl(serLen); - SVgroupTablesBatch *pTableBatch = taosHashGet(pVgroupHashmap, &info.vgId, sizeof(info.vgId)); + // pEpSet->inUse = info.inUse; + // pEpSet->numOfEps = info.numOfEps; + // for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { + // pEpSet->port[i] = info.epAddr[i].port; + // tstrncpy(pEpSet->fqdn[i], info.epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); + // } + // ((SMsgHead*)(*pOutput))->vgId = htonl(info.vgId); + // ((SMsgHead*)(*pOutput))->contLen = htonl(serLen); + SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &info.vgId, sizeof(info.vgId)); if (pTableBatch == NULL) { SVgroupTablesBatch tBatch = {0}; tBatch.info = info; @@ -518,14 +518,35 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p taosArrayPush(tBatch.req.pArray, &req); taosHashPut(pVgroupHashmap, &info.vgId, sizeof(info.vgId), &tBatch, sizeof(tBatch)); - } else { // add to the correct vgroup + } else { // add to the correct vgroup assert(info.vgId == pTableBatch->info.vgId); taosArrayPush(pTableBatch->req.pArray, &req); } } // TODO: serialize and - void *pBuf = NULL; + SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); + SVgroupTablesBatch** ppTbBatch = NULL; + do { + ppTbBatch = taosHashIterate(pVgroupHashmap, ppTbBatch); + if (ppTbBatch == NULL) break; + SVgroupTablesBatch* pTbBatch = *ppTbBatch; + + int tlen = sizeof(SMsgHead) + tSVCreateTbBatchReqSerialize(NULL, &(pTbBatch->req)); + void* buf = malloc(tlen); + if (buf == NULL) { + // TODO: handle error + } + + ((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId); + ((SMsgHead*)buf)->contLen = htonl(tlen); + + void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + tSVCreateTbBatchReqSerialize(&pBuf, &(pTbBatch->req)); + + taosArrayPush(pBufArray, &buf); + + } while (true); return TSDB_CODE_SUCCESS; } @@ -634,7 +655,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm case TSDB_SQL_SHOW: { SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt; code = setShowInfo(pShowInfo, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, &pDcl->epSet, &pDcl->pExtension, pMsgBuf); - pDcl->msgType = (pShowInfo->showType == TSDB_MGMT_TABLE_TABLE)? TDMT_VND_SHOW_TABLES:TDMT_MND_SHOW; + pDcl->msgType = (pShowInfo->showType == TSDB_MGMT_TABLE_TABLE) ? TDMT_VND_SHOW_TABLES : TDMT_MND_SHOW; break; } From 14d83eda1ce7eaa073b855ea4a08acf648a57546 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 31 Dec 2021 16:41:50 +0800 Subject: [PATCH 16/56] feature/qnode --- source/libs/qcom/src/querymsg.c | 2 +- source/libs/scheduler/src/scheduler.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 29f84ddcd0..b50eb2c92d 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -267,7 +267,7 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { pOut->metaNum = 1; if (pMetaMsg->dbFname[0]) { - snprintf(pOut->tbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); + snprintf(pOut->tbFname, sizeof(pOut->tbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); } else { memcpy(pOut->tbFname, pMetaMsg->tbFname, sizeof(pOut->tbFname)); } diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 3f1799507d..20eb94c2ff 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -664,7 +664,7 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { } SSubQueryMsg *pMsg = msg; - + pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); From a04f78c7602393d1d7b20c294a5d4375582f177a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 31 Dec 2021 09:41:04 +0000 Subject: [PATCH 17/56] mroe --- source/util/src/encode.c | 132 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 source/util/src/encode.c diff --git a/source/util/src/encode.c b/source/util/src/encode.c new file mode 100644 index 0000000000..9e648bb281 --- /dev/null +++ b/source/util/src/encode.c @@ -0,0 +1,132 @@ +/* + * 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 "encode.h" +#include "freelist.h" + +#define CODER_NODE_FIELDS \ + uint8_t* data; \ + int32_t size; \ + int32_t pos; + +struct SCoderNode { + TD_SLIST_NODE(SCoderNode); + CODER_NODE_FIELDS +}; + +typedef struct { + td_endian_t endian; + SFreeList fl; + CODER_NODE_FIELDS + TD_SLIST(SCoderNode) stack; +} SCoder; + +bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); } + +void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size) { + pCoder->endian = endian; + pCoder->data = data; + pCoder->size = size; + pCoder->pos = 0; + tFreeListInit(&(pCoder->fl)); + TD_SLIST_INIT(&(pCoder->stack)); +} + +void tCoderClear(SCoder* pCoder) { + tFreeListClear(&(pCoder->fl)); + struct SCoderNode* pNode; + for (;;) { + pNode = TD_SLIST_HEAD(&(pCoder->stack)); + if (pNode == NULL) break; + TD_SLIST_POP(&(pCoder->stack)); + free(pNode); + } +} + +int tStartEncode(SCoder* pCoder) { + if (pCoder->data) { + struct SCoderNode* pNode = malloc(sizeof(*pNode)); + if (pNode == NULL) return -1; + + pNode->data = pCoder->data; + pNode->pos = pCoder->pos; + pNode->size = pCoder->size; + + pCoder->data = pNode->data + sizeof(int32_t); + pCoder->pos = 0; + pCoder->size = pNode->size - pNode->pos - sizeof(int32_t); + + TD_SLIST_PUSH(&(pCoder->stack), pNode); + } else { + pCoder->pos += sizeof(int32_t); + } + return 0; +} + +void tEndEncode(SCoder* pCoder) { + struct SCoderNode* pNode; + + if (pCoder->data) { + pNode = TD_SLIST_HEAD(&(pCoder->stack)); + ASSERT(pNode); + TD_SLIST_POP(&(pCoder->stack)); + + // TODO: tEncodeI32(pNode, pCoder->pos); + + pCoder->data = pNode->data; + pCoder->size = pNode->size; + pCoder->pos = pNode->pos + pCoder->pos; + + free(pNode); + } +} + +int tStartDecode(SCoder* pCoder) { + int32_t size; + struct SCoderNode* pNode; + + pNode = malloc(sizeof(*pNode)); + if (pNode == NULL) return -1; + + // TODO: tDecodeI32(pCoder, &size); + + pNode->data = pCoder->data; + pNode->pos = pCoder->pos; + pNode->size = pCoder->size; + + pCoder->data = pCoder->data; + pCoder->size = size; + pCoder->pos = 0; + + TD_SLIST_PUSH(&(pCoder->stack), pNode); + + return 0; +} + +void tEndDecode(SCoder* pCoder) { + ASSERT(tDecodeIsEnd(pCoder)); + + struct SCoderNode* pNode; + + pNode = TD_SLIST_HEAD(&(pCoder->stack)); + ASSERT(pNode); + TD_SLIST_POP(&(pCoder->stack)); + + pCoder->data = pNode->data; + pCoder->size = pNode->size; + pCoder->pos = pCoder->pos + pNode->pos; + + free(pNode); +} From 9920b43be5997caadbd15c9745da7b265a5b59ed Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 31 Dec 2021 18:06:13 +0800 Subject: [PATCH 18/56] fix fst bug --- source/libs/index/src/index.c | 2 + source/libs/index/src/index_cache.c | 5 +- source/libs/index/src/index_fst.c | 4 +- source/libs/index/src/index_tfile.c | 6 +- source/libs/index/test/fstTest.cc | 115 ++++++++++++++++++++++++++- source/libs/index/test/indexTests.cc | 15 +--- 6 files changed, 127 insertions(+), 20 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 5167196031..6398259a96 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -360,6 +360,7 @@ static void indexMergeSameKey(SArray* result, TFileValue* tv) { if (sz > 0) { // TODO(yihao): remove duplicate tableid TFileValue* lv = taosArrayGetP(result, sz - 1); + // indexError("merge colVal: %s", lv->colVal); if (strcmp(lv->colVal, tv->colVal) == 0) { taosArrayAddAll(lv->tableId, tv->tableId); tfileValueDestroy(tv); @@ -368,6 +369,7 @@ static void indexMergeSameKey(SArray* result, TFileValue* tv) { } } else { taosArrayPush(result, &tv); + // indexError("merge colVal: %s", tv->colVal); } } static void indexDestroyTempResult(SArray* result) { diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index 0e46445a00..503d7cd928 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -20,7 +20,7 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later -#define MEM_TERM_LIMIT 10000 * 10 +#define MEM_TERM_LIMIT 10 * 10000 // ref index_cache.h:22 //#define CACHE_KEY_LEN(p) \ // (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + @@ -353,6 +353,9 @@ static bool indexCacheIteratorNext(Iterate* itera) { SSkipListIterator* iter = itera->iter; if (iter == NULL) { return false; } IterateValue* iv = &itera->val; + if (iv->colVal != NULL && iv->val != NULL) { + // indexError("value in cache: colVal: %s, size: %d", iv->colVal, (int)taosArrayGetSize(iv->val)); + } iterateValueDestroy(iv, false); bool next = tSkipListIterNext(iter); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 04a08dafd2..088c7369d5 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -319,7 +319,7 @@ void fstStateSetCommInput(FstState* s, uint8_t inp) { assert(s->state == OneTransNext || s->state == OneTrans); uint8_t val; - COMMON_INDEX(inp, 0x111111, val); + COMMON_INDEX(inp, 0b111111, val); s->val = (s->val & fstStateDict[s->state].val) | val; } @@ -369,7 +369,7 @@ uint8_t fstStateInput(FstState* s, FstNode* node) { bool null = false; uint8_t inp = fstStateCommInput(s, &null); uint8_t* data = fstSliceData(slice, NULL); - return null == false ? inp : data[-1]; + return null == false ? inp : data[node->start - 1]; } uint8_t fstStateInputForAnyTrans(FstState* s, FstNode* node, uint64_t i) { assert(s->state == AnyTrans); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index fc4f8593a1..6669198861 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -385,8 +385,10 @@ int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) { } static bool tfileIteratorNext(Iterate* iiter) { IterateValue* iv = &iiter->val; + if (iv->colVal != NULL && iv->val != NULL) { + // indexError("value in fst: colVal: %s, size: %d", iv->colVal, (int)taosArrayGetSize(iv->val)); + } iterateValueDestroy(iv, false); - // SArray* tblIds = iv->val; char* colVal = NULL; uint64_t offset = 0; @@ -406,7 +408,7 @@ static bool tfileIteratorNext(Iterate* iiter) { if (tfileReaderLoadTableIds(tIter->rdr, offset, iv->val) != 0) { return false; } iv->colVal = colVal; - + return true; // std::string key(ch, sz); } diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc index da974ce6c4..3d978c05a5 100644 --- a/source/libs/index/test/fstTest.cc +++ b/source/libs/index/test/fstTest.cc @@ -24,8 +24,13 @@ class FstWriter { _b = fstBuilderCreate(_wc, 0); } bool Put(const std::string& key, uint64_t val) { + // char buf[128] = {0}; + // int len = 0; + // taosMbsToUcs4(key.c_str(), key.size(), buf, 128, &len); + // FstSlice skey = fstSliceCreate((uint8_t*)buf, len); FstSlice skey = fstSliceCreate((uint8_t*)key.c_str(), key.size()); bool ok = fstBuilderInsert(_b, skey, val); + fstSliceDestroy(&skey); return ok; } @@ -61,6 +66,11 @@ class FstReadMemory { return _fst != NULL; } bool Get(const std::string& key, uint64_t* val) { + // char buf[128] = {0}; + // int len = 0; + // taosMbsToUcs4(key.c_str(), key.size(), buf, 128, &len); + // FstSlice skey = fstSliceCreate((uint8_t*)buf, len); + FstSlice skey = fstSliceCreate((uint8_t*)key.c_str(), key.size()); bool ok = fstGet(_fst, &skey, val); fstSliceDestroy(&skey); @@ -135,15 +145,109 @@ int Performance_fstWriteRecords(FstWriter* b) { } return L * M * N; } +void Performance_fstReadRecords(FstReadMemory* m) { + std::string str("aa"); + for (int i = 0; i < M; i++) { + str[0] = 'a' + i; + str.resize(2); + for (int j = 0; j < N; j++) { + str[1] = 'a' + j; + str.resize(2); + for (int k = 0; k < L; k++) { + str.push_back('a'); + uint64_t val, cost; + if (m->GetWithTimeCostUs(str, &val, &cost)) { + printf("succes to get kv(%s, %" PRId64 "), cost: %" PRId64 "\n", str.c_str(), val, cost); + } else { + printf("failed to get key: %s\n", str.c_str()); + } + } + } + } +} + +void checkMillonWriteAndReadOfFst() { + tfInit(); + FstWriter* fw = new FstWriter; + Performance_fstWriteRecords(fw); + delete fw; + FstReadMemory* fr = new FstReadMemory(1024 * 64 * 1024); + + if (fr->init()) { printf("success to init fst read"); } + + Performance_fstReadRecords(fr); + tfCleanup(); + delete fr; +} +void checkFstLongTerm() { + tfInit(); + FstWriter* fw = new FstWriter; + // Performance_fstWriteRecords(fw); + + fw->Put("A B", 1); + fw->Put("C", 2); + fw->Put("a", 3); + delete fw; + + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; + delete m; + return; + } + { + uint64_t val = 0; + if (m->Get("A B", &val)) { + std::cout << "success to Get: " << val << std::endl; + } else { + std::cout << "failed to Get:" << val << std::endl; + } + } + { + uint64_t val = 0; + if (m->Get("C", &val)) { + std::cout << "success to Get: " << val << std::endl; + } else { + std::cout << "failed to Get:" << val << std::endl; + } + } + { + uint64_t val = 0; + if (m->Get("a", &val)) { + std::cout << "success to Get: " << val << std::endl; + } else { + std::cout << "failed to Get:" << val << std::endl; + } + } + + // prefix search + // std::vector result; + + // AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS); + // m->Search(ctx, result); + // std::cout << "size: " << result.size() << std::endl; + // assert(result.size() == count); + // for (int i = 0; i < result.size(); i++) { + // assert(result[i] == i); // check result + //} + tfCleanup(); + // free(ctx); + // delete m; +} void checkFstCheckIterator() { tfInit(); FstWriter* fw = new FstWriter; int64_t s = taosGetTimestampUs(); int count = 2; - Performance_fstWriteRecords(fw); + // Performance_fstWriteRecords(fw); int64_t e = taosGetTimestampUs(); std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; + + fw->Put("Hello world", 1); + fw->Put("hello world", 2); + fw->Put("hello worle", 3); + fw->Put("hello worlf", 4); delete fw; FstReadMemory* m = new FstReadMemory(1024 * 64); @@ -171,7 +275,7 @@ void checkFstCheckIterator() { void fst_get(Fst* fst) { for (int i = 0; i < 10000; i++) { - std::string term = "Hello"; + std::string term = "Hello World"; FstSlice key = fstSliceCreate((uint8_t*)term.c_str(), term.size()); uint64_t offset = 0; bool ret = fstGet(fst, &key, &offset); @@ -189,7 +293,7 @@ void validateTFile(char* arg) { std::thread threads[NUM_OF_THREAD]; // std::vector threads; - TFileReader* reader = tfileReaderOpen(arg, 0, 295868, "tag1"); + TFileReader* reader = tfileReaderOpen(arg, 0, 999992, "tag1"); for (int i = 0; i < NUM_OF_THREAD; i++) { threads[i] = std::thread(fst_get, reader->fst); @@ -203,9 +307,12 @@ void validateTFile(char* arg) { tfCleanup(); } int main(int argc, char* argv[]) { - if (argc > 1) { validateTFile(argv[1]); } + // tool to check all kind of fst test + // if (argc > 1) { validateTFile(argv[1]); } // checkFstCheckIterator(); + // checkFstLongTerm(); // checkFstPrefixSearch(); + checkMillonWriteAndReadOfFst(); return 1; } diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 080becccf1..3ad64cd03e 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -787,14 +787,15 @@ TEST_F(IndexEnv2, testIndexOpen) { } TEST_F(IndexEnv2, testIndex_TrigeFlush) { - std::string path = "/tmp/test"; + std::string path = "/tmp/test1"; if (index->Init(path) != 0) { // r std::cout << "failed to init" << std::endl; } int numOfTable = 100 * 10000; - index->WriteMillonData("tag1", "Hello", numOfTable); - int target = index->SearchOne("tag1", "Hello"); + index->WriteMillonData("tag1", "Hello Wolrd", numOfTable); + int target = index->SearchOne("tag1", "Hello Wolrd"); + std::cout << "Get Index: " << target << std::endl; assert(numOfTable == target); } @@ -821,14 +822,6 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { threads[i].join(); } } -TEST_F(IndexEnv2, testIndex_multi_thread_write) { - std::string path = "/tmp"; - if (index->Init(path) != 0) {} -} -TEST_F(IndexEnv2, testIndex_multi_thread_read) { - std::string path = "/tmp"; - if (index->Init(path) != 0) {} -} TEST_F(IndexEnv2, testIndex_restart) { std::string path = "/tmp"; From 97df31ebad2192258ac8b3fce15b1927bed1b314 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 31 Dec 2021 02:40:49 -0800 Subject: [PATCH 19/56] unitest for create user --- include/common/tmsg.h | 55 ++++---- source/dnode/mgmt/impl/src/dndTransport.c | 2 +- source/dnode/mgmt/impl/test/user/user.cpp | 149 +++++++++++++++++++++- 3 files changed, 172 insertions(+), 34 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 17a4d4ad2c..479fd3c4e8 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -354,9 +354,9 @@ typedef struct SEpSet { } SEpSet; static FORCE_INLINE int taosEncodeSEpSet(void** buf, const SEpSet* pEp) { - if(buf == NULL) return sizeof(SEpSet); + if (buf == NULL) return sizeof(SEpSet); memcpy(buf, pEp, sizeof(SEpSet)); - //TODO: endian conversion + // TODO: endian conversion return sizeof(SEpSet); } @@ -370,7 +370,7 @@ typedef struct { int64_t clusterId; int32_t connId; int8_t superUser; - int8_t reserved[5]; + int8_t align[3]; SEpSet epSet; } SConnectRsp; @@ -383,20 +383,17 @@ typedef struct { int32_t maxStreams; int32_t accessState; // Configured only by command int64_t maxStorage; // In unit of GB - int32_t reserve[8]; } SCreateAcctMsg, SAlterAcctMsg; typedef struct { - char user[TSDB_USER_LEN]; - int32_t reserve[8]; + char user[TSDB_USER_LEN]; } SDropUserMsg, SDropAcctMsg; typedef struct { - int8_t type; - char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; - int8_t superUser; // denote if it is a super user or not - int32_t reserve[8]; + int8_t type; + char user[TSDB_USER_LEN]; + char pass[TSDB_PASSWORD_LEN]; + int8_t superUser; // denote if it is a super user or not } SCreateUserMsg, SAlterUserMsg; typedef struct { @@ -585,7 +582,6 @@ typedef struct { int8_t update; int8_t cacheLastRow; int8_t ignoreExist; - int32_t reserve[8]; } SCreateDbMsg; typedef struct { @@ -598,29 +594,24 @@ typedef struct { int8_t walLevel; int8_t quorum; int8_t cacheLastRow; - int32_t reserve[8]; } SAlterDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int8_t ignoreNotExists; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; + int8_t ignoreNotExists; } SDropDbMsg; typedef struct { char db[TSDB_TABLE_FNAME_LEN]; int32_t vgVersion; - int32_t reserve[8]; } SUseDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; } SSyncDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; } SCompactDbMsg; typedef struct { @@ -676,7 +667,7 @@ typedef struct { typedef struct { int32_t vgId; int8_t role; - int8_t reserved[3]; + int8_t align[3]; int64_t totalStorage; int64_t compStorage; int64_t pointsWritten; @@ -713,7 +704,7 @@ typedef struct { typedef struct { int32_t id; int8_t isMnode; - int8_t reserved; + int8_t align; uint16_t port; char fqdn[TSDB_FQDN_LEN]; } SDnodeEp; @@ -947,7 +938,7 @@ typedef struct { int32_t totalDnodes; int32_t onlineDnodes; int8_t killConnection; - int8_t reserved[3]; + int8_t align[3]; SEpSet epSet; } SHeartBeatRsp; @@ -975,7 +966,7 @@ typedef struct { typedef struct { int8_t finished; - int8_t reserved1[7]; + int8_t align[7]; char name[TSDB_STEP_NAME_LEN]; char desc[TSDB_STEP_DESC_LEN]; } SStartupMsg; @@ -1118,10 +1109,10 @@ typedef struct STaskDropRsp { } STaskDropRsp; typedef struct { - int8_t igExists; - char* name; - char* physicalPlan; - char* logicalPlan; + int8_t igExists; + char* name; + char* physicalPlan; + char* logicalPlan; } SCMCreateTopicReq; static FORCE_INLINE int tSerializeSCMCreateTopicReq(void** buf, const SCMCreateTopicReq* pReq) { @@ -1157,8 +1148,8 @@ static FORCE_INLINE void* tDeserializeSCMCreateTopicRsp(void* buf, SCMCreateTopi } typedef struct { - char* topicName; - char* consumerGroup; + char* topicName; + char* consumerGroup; int64_t consumerId; } SCMSubscribeReq; @@ -1179,7 +1170,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq typedef struct { int32_t vgId; - SEpSet pEpSet; + SEpSet pEpSet; } SCMSubscribeRsp; static FORCE_INLINE int tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribeRsp* pRsp) { diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index e5be16937b..eaa611e6c8 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -160,8 +160,8 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)]; if (fp != NULL) { + dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF); (*fp)(pDnode, pMsg, pEpSet); - dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF); } else { dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType)); rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/impl/test/user/user.cpp b/source/dnode/mgmt/impl/test/user/user.cpp index aa160304c8..aecce0bdc9 100644 --- a/source/dnode/mgmt/impl/test/user/user.cpp +++ b/source/dnode/mgmt/impl/test/user/user.cpp @@ -43,6 +43,153 @@ TEST_F(DndTestUser, 01_ShowUser) { CheckBinary("root", TSDB_USER_LEN); } +TEST_F(DndTestUser, 02_Create_User) { + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, ""); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); + } + + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "root"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_ALREADY_EXIST); + } + + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); +} + +TEST_F(DndTestUser, 03_Alter_User) { + { + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, ""); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); + } + + { + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u4"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } +} + +TEST_F(DndTestUser, 04_Drop_User) { + { + int32_t contLen = sizeof(SDropUserMsg); + + SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SDropUserMsg); + + SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u4"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SDropUserMsg); + + SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); +} + TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { { int32_t contLen = sizeof(SCreateUserMsg); @@ -161,4 +308,4 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { CheckTimestamp(); CheckBinary("root", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN); -} +} \ No newline at end of file From f0044d826f1d5814d106bfa4cb3529f36f8b5b76 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 31 Dec 2021 18:57:57 +0800 Subject: [PATCH 20/56] [td-11818]support create multiple tables. --- include/common/tmsgtype.h | 3 +- include/libs/parser/parsenodes.h | 4 +- source/client/src/clientImpl.c | 2 +- source/libs/parser/inc/parserInt.h | 4 +- source/libs/parser/src/dCDAstProcess.c | 139 ++++++++++++++++-------- source/libs/parser/src/parser.c | 29 +++-- source/libs/parser/test/parserTests.cpp | 10 +- source/libs/planner/inc/plannerInt.h | 2 +- source/libs/planner/src/logicPlan.c | 15 ++- source/libs/planner/src/physicalPlan.c | 22 ++-- 10 files changed, 151 insertions(+), 79 deletions(-) diff --git a/include/common/tmsgtype.h b/include/common/tmsgtype.h index 8e7ad87a0a..ebbf99b942 100644 --- a/include/common/tmsgtype.h +++ b/include/common/tmsgtype.h @@ -40,8 +40,9 @@ enum { // the SQL below is for mgmt node TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MGMT, "mgmt" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_DB, "create-db" ) + TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_STABLE, "create-stable" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_TABLE, "create-table" ) - TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_FUNCTION, "create-function" ) + TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_FUNCTION, "create-function" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_DB, "drop-db" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_TABLE, "drop-table" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_FUNCTION, "drop-function" ) diff --git a/include/libs/parser/parsenodes.h b/include/libs/parser/parsenodes.h index 041adbb582..b326ac032c 100644 --- a/include/libs/parser/parsenodes.h +++ b/include/libs/parser/parsenodes.h @@ -27,7 +27,7 @@ extern "C" { #include "tname.h" #include "tvariant.h" -/* +/** * The first field of a node of any type is guaranteed to be the int16_t. * Hence the type of any node can be gotten by casting it to SQueryNode. */ @@ -157,7 +157,7 @@ typedef struct SVgDataBlocks { typedef struct SInsertStmtInfo { int16_t nodeType; SArray* pDataBlocks; // data block for each vgroup, SArray. - int8_t schemaAttache; // denote if submit block is built with table schema or not + int8_t schemaAttache; // denote if submit block is built with table schema or not uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert uint32_t insertType; // insert data from [file|sql statement| bound statement] const char* sql; // current sql statement position diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 050e763919..b0b2c57ee4 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -202,7 +202,7 @@ int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { } int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { - if (TSDB_SQL_INSERT == pRequest->type) { + if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) { return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows); } return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); diff --git a/source/libs/parser/inc/parserInt.h b/source/libs/parser/inc/parserInt.h index 4bbe6ab907..346bd0cbe4 100644 --- a/source/libs/parser/inc/parserInt.h +++ b/source/libs/parser/inc/parserInt.h @@ -68,7 +68,9 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQ * @param type * @return */ -int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStmtInfo* pDcl, char* msgBuf, int32_t msgBufLen); +SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen); + +SInsertStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen); /** * Evaluate the numeric and timestamp arithmetic expression in the WHERE clause. diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index ecea48f583..76e26c159b 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -326,8 +326,7 @@ typedef struct SVgroupTablesBatch { SVgroupInfo info; } SVgroupTablesBatch; -int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len, - SEpSet* pEpSet) { +int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) { const char* msg1 = "invalid table name"; const char* msg2 = "tags number not matched"; const char* msg3 = "tag value too long"; @@ -359,7 +358,11 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p size_t numOfInputTag = taosArrayGetSize(pValList); STableMeta* pSuperTableMeta = NULL; - catalogGetTableMeta(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &name, &pSuperTableMeta); + code = catalogGetTableMeta(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &name, &pSuperTableMeta); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + assert(pSuperTableMeta != NULL); // too long tag values will return invalid sql, not be truncated automatically @@ -501,14 +504,6 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p req.ctbCfg.suid = pSuperTableMeta->suid; req.ctbCfg.pTag = row; - // pEpSet->inUse = info.inUse; - // pEpSet->numOfEps = info.numOfEps; - // for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { - // pEpSet->port[i] = info.epAddr[i].port; - // tstrncpy(pEpSet->fqdn[i], info.epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); - // } - // ((SMsgHead*)(*pOutput))->vgId = htonl(info.vgId); - // ((SMsgHead*)(*pOutput))->contLen = htonl(serLen); SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &info.vgId, sizeof(info.vgId)); if (pTableBatch == NULL) { SVgroupTablesBatch tBatch = {0}; @@ -525,12 +520,12 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p } // TODO: serialize and - SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); - SVgroupTablesBatch** ppTbBatch = NULL; + SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); + + SVgroupTablesBatch* pTbBatch = NULL; do { - ppTbBatch = taosHashIterate(pVgroupHashmap, ppTbBatch); - if (ppTbBatch == NULL) break; - SVgroupTablesBatch* pTbBatch = *ppTbBatch; + pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch); + if (pTbBatch == NULL) break; int tlen = sizeof(SMsgHead) + tSVCreateTbBatchReqSerialize(NULL, &(pTbBatch->req)); void* buf = malloc(tlen); @@ -544,17 +539,29 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); tSVCreateTbBatchReqSerialize(&pBuf, &(pTbBatch->req)); - taosArrayPush(pBufArray, &buf); + SVgDataBlocks* pVgData = calloc(1, sizeof(SVgDataBlocks)); + pVgData->vg = pTbBatch->info; + pVgData->pData = buf; + pVgData->size = tlen; + pVgData->numOfTables = (int32_t) taosArrayGetSize(pTbBatch->req.pArray); + taosArrayPush(pBufArray, &pVgData); } while (true); + SInsertStmtInfo* pStmtInfo = calloc(1, sizeof(SInsertStmtInfo)); + pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE; + pStmtInfo->pDataBlocks = pBufArray; + *pOutput = pStmtInfo; + *len = sizeof(SInsertStmtInfo); + return TSDB_CODE_SUCCESS; } -int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStmtInfo* pDcl, char* msgBuf, - int32_t msgBufLen) { +SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { int32_t code = 0; + SDclStmtInfo* pDcl = calloc(1, sizeof(SDclStmtInfo)); + SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; SMsgBuf* pMsgBuf = &m; @@ -571,21 +578,25 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm SToken* pPwd = &pUser->passwd; if (pName->n >= TSDB_USER_LEN) { - return buildInvalidOperationMsg(pMsgBuf, msg3); + code = buildInvalidOperationMsg(pMsgBuf, msg3); + goto _error; } if (parserValidateIdToken(pName) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg2); + code = buildInvalidOperationMsg(pMsgBuf, msg2); + goto _error; } if (pInfo->type == TSDB_SQL_CREATE_USER) { if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; + code = TSDB_CODE_TSC_INVALID_OPERATION; + goto _error; } } else { if (pUser->type == TSDB_ALTER_USER_PASSWD) { if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; + code = TSDB_CODE_TSC_INVALID_OPERATION; + goto _error; } } else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { assert(pPwd->type == TSDB_DATA_TYPE_NULL); @@ -596,10 +607,12 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm } else if (strncasecmp(pPrivilege->z, "normal", 4) == 0 && pPrivilege->n == 4) { // pCmd->count = 2; } else { - return buildInvalidOperationMsg(pMsgBuf, msg4); + code = buildInvalidOperationMsg(pMsgBuf, msg4); + goto _error; } } else { - return buildInvalidOperationMsg(pMsgBuf, msg1); + code = buildInvalidOperationMsg(pMsgBuf, msg1); + goto _error; } } @@ -618,15 +631,18 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm SToken* pPwd = &pInfo->pMiscInfo->user.passwd; if (parserValidatePassword(pPwd, pMsgBuf) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; + code = TSDB_CODE_TSC_INVALID_OPERATION; + goto _error; } if (pName->n >= TSDB_USER_LEN) { - return buildInvalidOperationMsg(pMsgBuf, msg3); + code = buildInvalidOperationMsg(pMsgBuf, msg3); + goto _error; } if (parserValidateNameToken(pName) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg2); + code = buildInvalidOperationMsg(pMsgBuf, msg2); + goto _error; } SCreateAcctInfo* pAcctOpt = &pInfo->pMiscInfo->acctOpt; @@ -636,7 +652,8 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm } else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) { } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { } else { - return buildInvalidOperationMsg(pMsgBuf, msg1); + code = buildInvalidOperationMsg(pMsgBuf, msg1); + goto _error; } } @@ -655,6 +672,10 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm case TSDB_SQL_SHOW: { SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt; code = setShowInfo(pShowInfo, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, &pDcl->epSet, &pDcl->pExtension, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pDcl->msgType = (pShowInfo->showType == TSDB_MGMT_TABLE_TABLE) ? TDMT_VND_SHOW_TABLES : TDMT_MND_SHOW; break; } @@ -664,13 +685,15 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm SToken* pToken = taosArrayGet(pInfo->pMiscInfo->a, 0); if (parserValidateNameToken(pToken) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg); + code = buildInvalidOperationMsg(pMsgBuf, msg); + goto _error; } SName n = {0}; int32_t ret = tNameSetDbName(&n, pCtx->acctId, pToken->z, pToken->n); if (ret != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg); + code = buildInvalidOperationMsg(pMsgBuf, msg); + goto _error; } SUseDbMsg* pUseDbMsg = (SUseDbMsg*)calloc(1, sizeof(SUseDbMsg)); @@ -689,19 +712,22 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt); if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) { - return buildInvalidOperationMsg(pMsgBuf, msg2); + code = buildInvalidOperationMsg(pMsgBuf, msg2); + goto _error; } char buf[TSDB_DB_NAME_LEN] = {0}; SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf)); if (parserValidateNameToken(&token) != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg1); + code = buildInvalidOperationMsg(pMsgBuf, msg1); + goto _error; } SCreateDbMsg* pCreateMsg = buildCreateDbMsg(pCreateDB, pCtx, pMsgBuf); if (doCheckDbOptions(pCreateMsg, pMsgBuf) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; + code = TSDB_CODE_TSC_INVALID_OPERATION; + goto _error; } pDcl->pMsg = (char*)pCreateMsg; @@ -719,7 +745,8 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm SName name = {0}; code = tNameSetDbName(&name, pCtx->acctId, dbName->z, dbName->n); if (code != TSDB_CODE_SUCCESS) { - return buildInvalidOperationMsg(pMsgBuf, msg1); + code = buildInvalidOperationMsg(pMsgBuf, msg1); + goto _error; } SDropDbMsg* pDropDbMsg = (SDropDbMsg*)calloc(1, sizeof(SDropDbMsg)); @@ -731,7 +758,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm pDcl->msgType = TDMT_MND_DROP_DB; pDcl->msgLen = sizeof(SDropDbMsg); pDcl->pMsg = (char*)pDropDbMsg; - return TSDB_CODE_SUCCESS; + break; } case TSDB_SQL_CREATE_TABLE: { @@ -739,14 +766,16 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { if ((code = doCheckForCreateTable(pInfo, pMsgBuf)) != TSDB_CODE_SUCCESS) { - return code; + terrno = code; + goto _error; } + pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE) ? TDMT_VND_CREATE_TABLE : TDMT_MND_CREATE_STB; } else if (pCreateTable->type == TSQL_CREATE_CTABLE) { - if ((code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, &pDcl->pMsg, &pDcl->msgLen, &pDcl->epSet)) != + if ((code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, &pDcl->pMsg, &pDcl->msgLen)) != TSDB_CODE_SUCCESS) { - return code; + goto _error; } pDcl->msgType = TDMT_VND_CREATE_TABLE; @@ -761,7 +790,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm case TSDB_SQL_DROP_TABLE: { pDcl->pMsg = (char*)buildDropStableMsg(pInfo, &pDcl->msgLen, pCtx, pMsgBuf); if (pDcl->pMsg == NULL) { - code = terrno; + goto _error; } pDcl->msgType = TDMT_MND_DROP_STB; @@ -771,7 +800,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm case TSDB_SQL_CREATE_DNODE: { pDcl->pMsg = (char*)buildCreateDnodeMsg(pInfo, &pDcl->msgLen, pMsgBuf); if (pDcl->pMsg == NULL) { - code = terrno; + goto _error; } pDcl->msgType = TDMT_MND_CREATE_DNODE; @@ -781,7 +810,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm case TSDB_SQL_DROP_DNODE: { pDcl->pMsg = (char*)buildDropDnodeMsg(pInfo, &pDcl->msgLen, pMsgBuf); if (pDcl->pMsg == NULL) { - code = terrno; + goto _error; } pDcl->msgType = TDMT_MND_DROP_DNODE; @@ -792,5 +821,29 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm break; } - return code; + return pDcl; + + _error: + terrno = code; + tfree(pDcl); + return NULL; } + +SInsertStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { + SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + assert(pCreateTable->type == TSQL_CREATE_CTABLE); + + SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; + SMsgBuf* pMsgBuf = &m; + + SInsertStmtInfo* pInsertStmt = NULL; + + int32_t msgLen = 0; + int32_t code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, (char**) &pInsertStmt, &msgLen); + if (code != TSDB_CODE_SUCCESS) { + tfree(pInsertStmt); + return NULL; + } + + return pInsertStmt; +} \ No newline at end of file diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 710cf4b5d0..1b4d05808c 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -32,7 +32,7 @@ bool isInsertSql(const char* pStr, size_t length) { } bool qIsDdlQuery(const SQueryNode* pQuery) { - return TSDB_SQL_INSERT != pQuery->type && TSDB_SQL_SELECT != pQuery->type; + return TSDB_SQL_INSERT != pQuery->type && TSDB_SQL_SELECT != pQuery->type && TSDB_SQL_CREATE_TABLE != pQuery->type; } int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { @@ -44,16 +44,29 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { } if (!isDqlSqlStatement(&info)) { - SDclStmtInfo* pDcl = calloc(1, sizeof(SDclStmtInfo)); - if (NULL == pDcl) { - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; // set correct error code. - return terrno; + bool toVnode = false; + if (info.type == TSDB_SQL_CREATE_TABLE) { + SCreateTableSql* pCreateSql = info.pCreateTableInfo; + if (pCreateSql->type == TSQL_CREATE_CTABLE || pCreateSql->type == TSQL_CREATE_TABLE) { + toVnode = true; + } } - pDcl->nodeType = info.type; - int32_t code = qParserValidateDclSqlNode(&info, &pCxt->ctx, pDcl, pCxt->pMsg, pCxt->msgLen); - if (code == TSDB_CODE_SUCCESS) { + if (toVnode) { + SInsertStmtInfo *pInsertInfo = qParserValidateCreateTbSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); + if (pInsertInfo == NULL) { + return terrno; + } + + *pQuery = (SQueryNode*) pInsertInfo; + } else { + SDclStmtInfo* pDcl = qParserValidateDclSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); + if (pDcl == NULL) { + return terrno; + } + *pQuery = (SQueryNode*)pDcl; + pDcl->nodeType = info.type; } } else { SQueryStmtInfo* pQueryInfo = calloc(1, sizeof(SQueryStmtInfo)); diff --git a/source/libs/parser/test/parserTests.cpp b/source/libs/parser/test/parserTests.cpp index a67a9a8be8..fe430c5f5e 100644 --- a/source/libs/parser/test/parserTests.cpp +++ b/source/libs/parser/test/parserTests.cpp @@ -714,10 +714,9 @@ TEST(testCase, show_user_Test) { SSqlInfo info1 = doGenerateAST(sql1); ASSERT_EQ(info1.valid, true); - SDclStmtInfo output; SParseBasicCtx ct= {.requestId = 1, .acctId = 1, .db = "abc", .pTransporter = NULL}; - int32_t code = qParserValidateDclSqlNode(&info1, &ct, &output, msg, buf.len); - ASSERT_EQ(code, 0); + SDclStmtInfo* output = qParserValidateDclSqlNode(&info1, &ct, msg, buf.len); + ASSERT_NE(output, nullptr); // convert the show command to be the select query // select name, privilege, create_time, account from information_schema.users; @@ -735,10 +734,9 @@ TEST(testCase, create_user_Test) { ASSERT_EQ(info1.valid, true); ASSERT_EQ(isDclSqlStatement(&info1), true); - SDclStmtInfo output; SParseBasicCtx ct= {.requestId = 1, .acctId = 1, .db = "abc"}; - int32_t code = qParserValidateDclSqlNode(&info1, &ct, &output, msg, buf.len); - ASSERT_EQ(code, 0); + SDclStmtInfo* output = qParserValidateDclSqlNode(&info1, &ct, msg, buf.len); + ASSERT_NE(output, nullptr); destroySqlInfo(&info1); } \ No newline at end of file diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index 35c6d59ffe..a68102ea6e 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -40,7 +40,7 @@ extern "C" { #define QNODE_SESSIONWINDOW 12 #define QNODE_STATEWINDOW 13 #define QNODE_FILL 14 -#define QNODE_INSERT 15 +#define QNODE_MODIFY 15 typedef struct SQueryDistPlanNodeInfo { bool stableQuery; // super table query or not diff --git a/source/libs/planner/src/logicPlan.c b/source/libs/planner/src/logicPlan.c index 136073aa60..5f95f86d4a 100644 --- a/source/libs/planner/src/logicPlan.c +++ b/source/libs/planner/src/logicPlan.c @@ -37,15 +37,19 @@ int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode) { return 0; } -int32_t createInsertPlan(const SInsertStmtInfo* pInsert, SQueryPlanNode** pQueryPlan) { +static int32_t createInsertPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { + SInsertStmtInfo* pInsert = (SInsertStmtInfo*)pNode; + *pQueryPlan = calloc(1, sizeof(SQueryPlanNode)); SArray* blocks = taosArrayInit(taosArrayGetSize(pInsert->pDataBlocks), POINTER_BYTES); if (NULL == *pQueryPlan || NULL == blocks) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - (*pQueryPlan)->info.type = QNODE_INSERT; + + (*pQueryPlan)->info.type = QNODE_MODIFY; taosArrayAddAll(blocks, pInsert->pDataBlocks); (*pQueryPlan)->pExtInfo = blocks; + return TSDB_CODE_SUCCESS; } @@ -62,13 +66,14 @@ int32_t createQueryPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { case TSDB_SQL_SELECT: { return createSelectPlan((const SQueryStmtInfo*)pNode, pQueryPlan); } + case TSDB_SQL_INSERT: - return createInsertPlan((const SInsertStmtInfo*)pNode, pQueryPlan); + case TSDB_SQL_CREATE_TABLE: + return createInsertPlan(pNode, pQueryPlan); + default: return TSDB_CODE_FAILED; } - - return TSDB_CODE_SUCCESS; } int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql) { diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 97c9cec7c7..978b1554f3 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -34,7 +34,7 @@ static const char* gOpName[] = { #undef INCLUDE_AS_NAME }; -static void* vailidPointer(void* p) { +static void* validPointer(void* p) { if (NULL == p) { THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } @@ -76,7 +76,7 @@ int32_t dsinkNameToDsinkType(const char* name) { } static SDataSink* initDataSink(int32_t type, int32_t size) { - SDataSink* sink = (SDataSink*)vailidPointer(calloc(1, size)); + SDataSink* sink = (SDataSink*)validPointer(calloc(1, size)); sink->info.type = type; sink->info.name = dsinkTypeToDsinkName(type); return sink; @@ -121,7 +121,7 @@ static bool cloneExprArray(SArray** dst, SArray* src) { } static SPhyNode* initPhyNode(SQueryPlanNode* pPlanNode, int32_t type, int32_t size) { - SPhyNode* node = (SPhyNode*)vailidPointer(calloc(1, size)); + SPhyNode* node = (SPhyNode*)validPointer(calloc(1, size)); node->info.type = type; node->info.name = opTypeToOpName(type); if (!cloneExprArray(&node->pTargets, pPlanNode->pExpr) || !toDataBlockSchema(pPlanNode, &(node->targetSchema))) { @@ -184,7 +184,7 @@ static SPhyNode* createMultiTableScanNode(SQueryPlanNode* pPlanNode, SQueryTable } static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { - SSubplan* subplan = vailidPointer(calloc(1, sizeof(SSubplan))); + SSubplan* subplan = validPointer(calloc(1, sizeof(SSubplan))); subplan->id = pCxt->nextId; ++(pCxt->nextId.subplanId); subplan->type = type; @@ -192,15 +192,15 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { if (NULL != pCxt->pCurrentSubplan) { subplan->level = pCxt->pCurrentSubplan->level + 1; if (NULL == pCxt->pCurrentSubplan->pChildern) { - pCxt->pCurrentSubplan->pChildern = vailidPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); + pCxt->pCurrentSubplan->pChildern = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); } taosArrayPush(pCxt->pCurrentSubplan->pChildern, &subplan); - subplan->pParents = vailidPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); + subplan->pParents = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); taosArrayPush(subplan->pParents, &pCxt->pCurrentSubplan); } SArray* currentLevel; if (subplan->level >= taosArrayGetSize(pCxt->pDag->pSubplans)) { - currentLevel = vailidPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); + currentLevel = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); taosArrayPush(pCxt->pDag->pSubplans, ¤tLevel); } else { currentLevel = taosArrayGetP(pCxt->pDag->pSubplans, subplan->level); @@ -272,7 +272,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { case QNODE_TABLESCAN: node = createTableScanNode(pCxt, pPlanNode); break; - case QNODE_INSERT: + case QNODE_MODIFY: // Insert is not an operator in a physical plan. break; default: @@ -306,7 +306,7 @@ static void splitInsertSubplan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { } static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { - if (QNODE_INSERT == pRoot->info.type) { + if (QNODE_MODIFY == pRoot->info.type) { splitInsertSubplan(pCxt, pRoot); } else { SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); @@ -321,12 +321,12 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD TRY(TSDB_MAX_TAG_CONDITIONS) { SPlanContext context = { .pCatalog = pCatalog, - .pDag = vailidPointer(calloc(1, sizeof(SQueryDag))), + .pDag = validPointer(calloc(1, sizeof(SQueryDag))), .pCurrentSubplan = NULL, .nextId = {0} // todo queryid }; *pDag = context.pDag; - context.pDag->pSubplans = vailidPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); + context.pDag->pSubplans = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); createSubplanByLevel(&context, pQueryNode); } CATCH(code) { CLEANUP_EXECUTE(); From db474b20789740c325b4094f6af96a583672338e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 2 Jan 2022 14:28:38 +0800 Subject: [PATCH 21/56] refactor code --- source/libs/index/inc/indexInt.h | 9 ++++ source/libs/index/inc/index_cache.h | 3 +- source/libs/index/inc/index_tfile.h | 13 ++--- source/libs/index/inc/index_util.h | 2 +- source/libs/index/src/index.c | 59 ++++++++++++++++------ source/libs/index/src/index_cache.c | 4 +- source/libs/index/src/index_tfile.c | 73 +++++++++++++--------------- source/libs/index/test/indexTests.cc | 2 +- 8 files changed, 94 insertions(+), 71 deletions(-) diff --git a/source/libs/index/inc/indexInt.h b/source/libs/index/inc/indexInt.h index 048c9e804e..6e1256d857 100644 --- a/source/libs/index/inc/indexInt.h +++ b/source/libs/index/inc/indexInt.h @@ -108,8 +108,17 @@ void iterateValueDestroy(IterateValue* iv, bool destroy); extern void* indexQhandle; +typedef struct TFileCacheKey { + uint64_t suid; + uint8_t colType; + char* colName; + int32_t nColName; +} ICacheKey; + int indexFlushCacheTFile(SIndex* sIdx, void*); +int32_t indexSerialCacheKey(ICacheKey* key, char* buf); + #define indexFatal(...) \ do { \ if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("index FATAL ", 255, __VA_ARGS__); } \ diff --git a/source/libs/index/inc/index_cache.h b/source/libs/index/inc/index_cache.h index 12b66bca2c..805137ccaf 100644 --- a/source/libs/index/inc/index_cache.h +++ b/source/libs/index/inc/index_cache.h @@ -42,6 +42,7 @@ typedef struct IndexCache { int32_t version; int32_t nTerm; int8_t type; + uint64_t suid; pthread_mutex_t mtx; } IndexCache; @@ -58,7 +59,7 @@ typedef struct CacheTerm { } CacheTerm; // -IndexCache* indexCacheCreate(SIndex* idx, const char* colName, int8_t type); +IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type); void indexCacheDestroy(void* cache); diff --git a/source/libs/index/inc/index_tfile.h b/source/libs/index/inc/index_tfile.h index 4928e01a63..675203fa1a 100644 --- a/source/libs/index/inc/index_tfile.h +++ b/source/libs/index/inc/index_tfile.h @@ -49,13 +49,6 @@ typedef struct TFileValue { int32_t offset; } TFileValue; -typedef struct TFileCacheKey { - uint64_t suid; - uint8_t colType; - char* colName; - int32_t nColName; -} TFileCacheKey; - // table cache // refactor to LRU cache later typedef struct TFileCache { @@ -103,10 +96,10 @@ typedef struct TFileReaderOpt { // tfile cache, manage tindex reader TFileCache* tfileCacheCreate(const char* path); void tfileCacheDestroy(TFileCache* tcache); -TFileReader* tfileCacheGet(TFileCache* tcache, TFileCacheKey* key); -void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader); +TFileReader* tfileCacheGet(TFileCache* tcache, ICacheKey* key); +void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader); -TFileReader* tfileGetReaderByCol(IndexTFile* tf, char* colName); +TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName); TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const char* colName); TFileReader* tfileReaderCreate(WriterCtx* ctx); diff --git a/source/libs/index/inc/index_util.h b/source/libs/index/inc/index_util.h index 21c5ca155b..adeb52bb8c 100644 --- a/source/libs/index/inc/index_util.h +++ b/source/libs/index/inc/index_util.h @@ -34,7 +34,7 @@ extern "C" { #define SERIALIZE_VAR_TO_BUF(buf, var, type) \ do { \ type c = var; \ - assert(sizeof(var) == sizeof(type)); \ + assert(sizeof(type) == sizeof(c)); \ memcpy((void*)buf, (void*)&c, sizeof(c)); \ buf += sizeof(c); \ } while (0) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 6398259a96..11a2aa5e5f 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -17,6 +17,7 @@ #include "indexInt.h" #include "index_cache.h" #include "index_tfile.h" +#include "index_util.h" #include "tdef.h" #include "tsched.h" @@ -130,18 +131,28 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { // TODO(yihao): reduce the lock range pthread_mutex_lock(&index->mtx); for (int i = 0; i < taosArrayGetSize(fVals); i++) { - SIndexTerm* p = taosArrayGetP(fVals, i); - IndexCache** cache = taosHashGet(index->colObj, p->colName, p->nColName); + SIndexTerm* p = taosArrayGetP(fVals, i); + + char buf[128] = {0}; + ICacheKey key = {.suid = p->suid, .colName = p->colName}; + int32_t sz = indexSerialCacheKey(&key, buf); + + IndexCache** cache = taosHashGet(index->colObj, buf, sz); if (cache == NULL) { - IndexCache* pCache = indexCacheCreate(index, p->colName, p->colType); - taosHashPut(index->colObj, p->colName, p->nColName, &pCache, sizeof(void*)); + IndexCache* pCache = indexCacheCreate(index, p->suid, p->colName, p->colType); + taosHashPut(index->colObj, buf, sz, &pCache, sizeof(void*)); } } pthread_mutex_unlock(&index->mtx); for (int i = 0; i < taosArrayGetSize(fVals); i++) { - SIndexTerm* p = taosArrayGetP(fVals, i); - IndexCache** cache = taosHashGet(index->colObj, p->colName, p->nColName); + SIndexTerm* p = taosArrayGetP(fVals, i); + + char buf[128] = {0}; + ICacheKey key = {.suid = p->suid, .colName = p->colName}; + int32_t sz = indexSerialCacheKey(&key, buf); + + IndexCache** cache = taosHashGet(index->colObj, buf, sz); assert(*cache != NULL); int ret = indexCachePut(*cache, p, uid); if (ret != 0) { return ret; } @@ -296,7 +307,12 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result // Get col info IndexCache* cache = NULL; pthread_mutex_lock(&sIdx->mtx); - IndexCache** pCache = taosHashGet(sIdx->colObj, colName, nColName); + + char buf[128] = {0}; + ICacheKey key = {.suid = term->suid, .colName = term->colName}; + int32_t sz = indexSerialCacheKey(&key, buf); + + IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz); if (pCache == NULL) { pthread_mutex_unlock(&sIdx->mtx); return -1; @@ -385,10 +401,12 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) { indexWarn("suid %" PRIu64 " merge cache into tindex", sIdx->suid); IndexCache* pCache = (IndexCache*)cache; - TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->colName); + TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName); + if (pReader == NULL) { indexWarn("empty pReader found"); } // handle flush Iterate* cacheIter = indexCacheIteratorCreate(pCache); Iterate* tfileIter = tfileIteratorCreate(pReader); + if (tfileIter == NULL) { indexWarn("empty tfile reader iterator"); } SArray* result = taosArrayInit(1024, sizeof(void*)); @@ -468,7 +486,7 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { int32_t version = CACHE_VERSION(cache); uint8_t colType = cache->type; - TFileWriter* tw = tfileWriterOpen(sIdx->path, sIdx->suid, version, cache->colName, colType); + TFileWriter* tw = tfileWriterOpen(sIdx->path, cache->suid, version, cache->colName, colType); if (tw == NULL) { indexError("failed to open file to write"); return -1; @@ -481,14 +499,13 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { } tfileWriterClose(tw); - TFileReader* reader = tfileReaderOpen(sIdx->path, sIdx->suid, version, cache->colName); + TFileReader* reader = tfileReaderOpen(sIdx->path, cache->suid, version, cache->colName); + + char buf[128] = {0}; + TFileHeader* header = &reader->header; + ICacheKey key = { + .suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; - char buf[128] = {0}; - TFileHeader* header = &reader->header; - TFileCacheKey key = {.suid = header->suid, - .colName = header->colName, - .nColName = strlen(header->colName), - .colType = header->colType}; pthread_mutex_lock(&sIdx->mtx); IndexTFile* ifile = (IndexTFile*)sIdx->tindex; @@ -499,3 +516,13 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { END: tfileWriterClose(tw); } + +int32_t indexSerialCacheKey(ICacheKey* key, char* buf) { + char* p = buf; + SERIALIZE_MEM_TO_BUF(buf, key, suid); + SERIALIZE_VAR_TO_BUF(buf, '_', char); + // SERIALIZE_MEM_TO_BUF(buf, key, colType); + // SERIALIZE_VAR_TO_BUF(buf, '_', char); + SERIALIZE_STR_MEM_TO_BUF(buf, key, colName, key->nColName); + return buf - p; +} diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index 503d7cd928..0f00d9d4af 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -40,7 +40,7 @@ static bool indexCacheIteratorNext(Iterate* itera); static IterateValue* indexCacheIteratorGetValue(Iterate* iter); -IndexCache* indexCacheCreate(SIndex* idx, const char* colName, int8_t type) { +IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type) { IndexCache* cache = calloc(1, sizeof(IndexCache)); if (cache == NULL) { indexError("failed to create index cache"); @@ -53,7 +53,7 @@ IndexCache* indexCacheCreate(SIndex* idx, const char* colName, int8_t type) { cache->type = type; cache->index = idx; cache->version = 0; - + cache->suid = suid; pthread_mutex_init(&cache->mtx, NULL); indexCacheRef(cache); return cache; diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 6669198861..fe54b5ebb3 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -51,7 +51,6 @@ static void tfileDestroyFileName(void* elem); static int tfileCompare(const void* a, const void* b); static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId, int* version); static void tfileGenFileName(char* filename, uint64_t suid, int colId, int version); -static void tfileSerialCacheKey(TFileCacheKey* key, char* buf); TFileCache* tfileCacheCreate(const char* path) { TFileCache* tcache = calloc(1, sizeof(TFileCache)); @@ -80,18 +79,18 @@ TFileCache* tfileCacheCreate(const char* path) { goto End; } - char buf[128] = {0}; - TFileReader* reader = tfileReaderCreate(wc); - TFileHeader* header = &reader->header; - TFileCacheKey key = {.suid = header->suid, - .colName = header->colName, - .nColName = strlen(header->colName), - .colType = header->colType}; - tfileSerialCacheKey(&key, buf); + char buf[128] = {0}; + TFileReader* reader = tfileReaderCreate(wc); + TFileHeader* header = &reader->header; + ICacheKey key = {.suid = header->suid, + .colName = header->colName, + .nColName = strlen(header->colName), + .colType = header->colType}; + int32_t sz = indexSerialCacheKey(&key, buf); + assert(sz < sizeof(buf)); + taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*)); tfileReaderRef(reader); - // indexTable - taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void*)); } taosArrayDestroyEx(files, tfileDestroyFileName); return tcache; @@ -117,30 +116,30 @@ void tfileCacheDestroy(TFileCache* tcache) { free(tcache); } -TFileReader* tfileCacheGet(TFileCache* tcache, TFileCacheKey* key) { - char buf[128] = {0}; - tfileSerialCacheKey(key, buf); - - TFileReader** reader = taosHashGet(tcache->tableCache, buf, strlen(buf)); +TFileReader* tfileCacheGet(TFileCache* tcache, ICacheKey* key) { + char buf[128] = {0}; + int32_t sz = indexSerialCacheKey(key, buf); + assert(sz < sizeof(buf)); + TFileReader** reader = taosHashGet(tcache->tableCache, buf, sz); if (reader == NULL) { return NULL; } tfileReaderRef(*reader); return *reader; } -void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader) { - char buf[128] = {0}; - tfileSerialCacheKey(key, buf); +void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) { + char buf[128] = {0}; + int32_t sz = indexSerialCacheKey(key, buf); // remove last version index reader - TFileReader** p = taosHashGet(tcache->tableCache, buf, strlen(buf)); + TFileReader** p = taosHashGet(tcache->tableCache, buf, sz); if (p != NULL) { TFileReader* oldReader = *p; - taosHashRemove(tcache->tableCache, buf, strlen(buf)); + taosHashRemove(tcache->tableCache, buf, sz); oldReader->remove = true; tfileReaderUnRef(oldReader); } + taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*)); tfileReaderRef(reader); - taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void*)); return; } TFileReader* tfileReaderCreate(WriterCtx* ctx) { @@ -230,8 +229,6 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const c TFileReader* reader = tfileReaderCreate(wc); return reader; - - // tfileSerialCacheKey(&key, buf); } TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) { // char pathBuf[128] = {0}; @@ -325,15 +322,19 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { tfileWriterClose(tw); return -1; } - // write fst + + // write data indexError("--------Begin----------------"); for (size_t i = 0; i < sz; i++) { // TODO, fst batch write later TFileValue* v = taosArrayGetP((SArray*)data, i); - if (tfileWriteData(tw, v) == 0) { - // + if (tfileWriteData(tw, v) != 0) { + indexError("failed to write data: %s, offset: %d len: %d", v->colVal, v->offset, + (int)taosArrayGetSize(v->tableId)); + } else { + indexInfo("success to write data: %s, offset: %d len: %d", v->colVal, v->offset, + (int)taosArrayGetSize(v->tableId)); } - indexError("data: %s, offset: %d len: %d", v->colVal, v->offset, (int)taosArrayGetSize(v->tableId)); } indexError("--------End----------------"); fstBuilderFinish(tw->fb); @@ -369,9 +370,8 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { if (tfile == NULL) { return ret; } IndexTFile* pTfile = (IndexTFile*)tfile; - SIndexTerm* term = query->term; - TFileCacheKey key = { - .suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; + SIndexTerm* term = query->term; + ICacheKey key = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; TFileReader* reader = tfileCacheGet(pTfile->cache, &key); if (reader == NULL) { return 0; } @@ -453,9 +453,9 @@ void tfileIteratorDestroy(Iterate* iter) { free(iter); } -TFileReader* tfileGetReaderByCol(IndexTFile* tf, char* colName) { +TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) { if (tf == NULL) { return NULL; } - TFileCacheKey key = {.suid = 0, .colType = TSDB_DATA_TYPE_BINARY, .colName = colName, .nColName = strlen(colName)}; + ICacheKey key = {.suid = suid, .colType = TSDB_DATA_TYPE_BINARY, .colName = colName, .nColName = strlen(colName)}; return tfileCacheGet(tf->cache, &key); } @@ -650,10 +650,3 @@ static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId, } return -1; } -static void tfileSerialCacheKey(TFileCacheKey* key, char* buf) { - // SERIALIZE_MEM_TO_BUF(buf, key, suid); - // SERIALIZE_VAR_TO_BUF(buf, '_', char); - // SERIALIZE_MEM_TO_BUF(buf, key, colType); - // SERIALIZE_VAR_TO_BUF(buf, '_', char); - SERIALIZE_STR_MEM_TO_BUF(buf, key, colName, key->nColName); -} diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 3ad64cd03e..7bf40bc7b3 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -477,7 +477,7 @@ class CacheObj { public: CacheObj() { // TODO - cache = indexCacheCreate(NULL, "voltage", TSDB_DATA_TYPE_BINARY); + cache = indexCacheCreate(NULL, 0, "voltage", TSDB_DATA_TYPE_BINARY); } int Put(SIndexTerm* term, int16_t colId, int32_t version, uint64_t uid) { int ret = indexCachePut(cache, term, uid); From 734ff3f83938a2adb69e34c78aac6b61e080e949 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 06:48:48 +0000 Subject: [PATCH 22/56] refact --- include/util/encode.h | 14 +++++++------- source/util/src/encode.c | 10 +++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index ee35791012..a3cbc9a42c 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -23,13 +23,6 @@ extern "C" { #endif -typedef struct { - td_endian_t endian; - uint8_t* data; - int32_t size; - int32_t pos; -} SEncoder, SDecoder; - #define tPut(TYPE, BUF, VAL) ((TYPE*)(BUF))[0] = (VAL) #define tGet(TYPE, BUF, VAL) (VAL) = ((TYPE*)(BUF))[0] @@ -57,6 +50,13 @@ typedef struct { #define tRGet32 tRPut32 #define tRGet64 tRPut64 +typedef struct { + td_endian_t endian; + uint8_t* data; + int32_t size; + int32_t pos; +} SEncoder, SDecoder; + #define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos) #define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE)) #define TD_CHECK_CODER_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE)) diff --git a/source/util/src/encode.c b/source/util/src/encode.c index 9e648bb281..dc1b926db0 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -56,8 +56,12 @@ void tCoderClear(SCoder* pCoder) { } int tStartEncode(SCoder* pCoder) { + struct SCoderNode* pNode; + if (pCoder->data) { - struct SCoderNode* pNode = malloc(sizeof(*pNode)); + if (pCoder->size - pCoder->pos < sizeof(int32_t)) return -1; + + pNode = malloc(sizeof(*pNode)); if (pNode == NULL) return -1; pNode->data = pCoder->data; @@ -97,11 +101,11 @@ int tStartDecode(SCoder* pCoder) { int32_t size; struct SCoderNode* pNode; + // TODO: if (tDecodeI32(pCoder, &size) < 0) return -1; + pNode = malloc(sizeof(*pNode)); if (pNode == NULL) return -1; - // TODO: tDecodeI32(pCoder, &size); - pNode->data = pCoder->data; pNode->pos = pCoder->pos; pNode->size = pCoder->size; From 6420811c8a2f4ff7e483de96758efb82d917e297 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 08:47:28 +0000 Subject: [PATCH 23/56] mor --- include/util/encode.h | 479 ++++++++++++++------------------------- source/util/src/encode.c | 29 +-- 2 files changed, 176 insertions(+), 332 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index a3cbc9a42c..6aa132060b 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -16,6 +16,7 @@ #ifndef _TD_UTIL_ENCODE_H_ #define _TD_UTIL_ENCODE_H_ +#include "freelist.h" #include "tcoding.h" #include "tmacro.h" @@ -50,38 +51,150 @@ extern "C" { #define tRGet32 tRPut32 #define tRGet64 tRPut64 -typedef struct { - td_endian_t endian; - uint8_t* data; - int32_t size; - int32_t pos; -} SEncoder, SDecoder; +typedef enum { TD_ENCODER, TD_DECODER } td_coder_t; +#define CODER_NODE_FIELDS \ + uint8_t* data; \ + int32_t size; \ + int32_t pos; + +struct SCoderNode { + TD_SLIST_NODE(SCoderNode); + CODER_NODE_FIELDS +}; + +typedef struct { + td_coder_t type; + td_endian_t endian; + SFreeList fl; + CODER_NODE_FIELDS + TD_SLIST(SCoderNode) stack; +} SCoder; + +#define TD_CODER_POS(CODER) ((CODER)->pos) #define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos) #define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE)) #define TD_CHECK_CODER_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE)) -/* ------------------------ FOR ENCODER ------------------------ */ -static FORCE_INLINE void tInitEncoder(SEncoder* pEncoder, td_endian_t endian, uint8_t* data, int32_t size) { - pEncoder->endian = endian; - pEncoder->data = data; - pEncoder->size = (data) ? size : 0; - pEncoder->pos = 0; -} +void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type); +void tCoderClear(SCoder* pCoder); + +/* ------------------------ ENCODE ------------------------ */ +int tStartEncode(SCoder* pEncoder); +void tEndEncode(SCoder* pEncoder); +int tEncodeU8(SCoder* pEncoder, uint8_t val); +int tEncodeI8(SCoder* pEncoder, int8_t val); +int tEncodeU16(SCoder* pEncoder, uint16_t val); +int tEncodeI16(SCoder* pEncoder, int16_t val); +int tEncodeU32(SCoder* pEncoder, uint32_t val); +int tEncodeI32(SCoder* pEncoder, int32_t val); +int tEncodeU64(SCoder* pEncoder, uint64_t val); +int tEncodeI64(SCoder* pEncoder, int64_t val); +int tEncodeU16v(SCoder* pEncoder, uint16_t val); +int tEncodeI16v(SCoder* pEncoder, int16_t val); +int tEncodeU32v(SCoder* pEncoder, uint32_t val); +int tEncodeI32v(SCoder* pEncoder, int32_t val); +int tEncodeU64v(SCoder* pEncoder, uint64_t val); +int tEncodeI64v(SCoder* pEncoder, int64_t val); +int tEncodeFloat(SCoder* pEncoder, float val); +int tEncodeDouble(SCoder* pEncoder, double val); +int tEncodeCStr(SCoder* pEncoder, const char* val); + +/* ------------------------ DECODE ------------------------ */ +int tStartDecode(SCoder* pDecoder); +void tEndDecode(SCoder* pDecoder); +int tDecodeU8(SCoder* pDecoder, uint8_t* val); +int tDecodeI8(SCoder* pDecoder, int8_t* val); +int tDecodeU16(SCoder* pDecoder, uint16_t* val); +int tDecodeI16(SCoder* pDecoder, int16_t* val); +int tDecodeU32(SCoder* pDecoder, uint32_t* val); +int tDecodeI32(SCoder* pDecoder, int32_t* val); +int tDecodeU64(SCoder* pDecoder, uint64_t* val); +int tDecodeI64(SCoder* pDecoder, int64_t* val); +int tDecodeU16v(SCoder* pDecoder, uint16_t* val); +int tDecodeI16v(SCoder* pDecoder, int16_t* val); +int tDecodeU32v(SCoder* pDecoder, uint32_t* val); +int tDecodeI32v(SCoder* pDecoder, int32_t* val); +int tDecodeU64v(SCoder* pDecoder, uint64_t* val); +int tDecodeI64v(SCoder* pDecoder, int64_t* val); +int tDecodeFloat(SCoder* pDecoder, float* val); +int tDecodeDouble(SCoder* pDecoder, double* val); +int tDecodeCStr(SCoder* pEncoder, const char** val); + +/* ------------------------ IMPL ------------------------ */ +#define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \ + if ((CODER)->data) { \ + if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, sizeof(VAL))) return -1; \ + if (TD_RT_ENDIAN() == (CODER)->endian) { \ + tPut(TYPE, TD_CODER_CURRENT(CODER), (VAL)); \ + } else { \ + tRPut##BITS(TD_CODER_CURRENT(CODER), &(VAL)); \ + } \ + } \ + TD_CODER_MOVE_POS(CODER, sizeof(VAL)); \ + return 0; + +#define TD_ENCODE_VARIANT_MACRO(CODER, VAL) \ + while ((VAL) > ENCODE_LIMIT) { \ + if ((CODER)->data) { \ + if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, 1)) return -1; \ + TD_CODER_CURRENT(CODER)[0] = ((VAL) | ENCODE_LIMIT) & 0xff; \ + } \ + \ + (VAL) >>= 7; \ + TD_CODER_MOVE_POS(CODER, 1); \ + } \ + \ + if ((CODER)->data) { \ + if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, 1)) return -1; \ + TD_CODER_CURRENT(CODER)[0] = (uint8_t)(VAL); \ + } \ + TD_CODER_MOVE_POS(CODER, 1); \ + return 0; + +#define TD_DECODE_MACRO(CODER, PVAL, TYPE, BITS) \ + if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, sizeof(*(PVAL)))) return -1; \ + if (TD_RT_ENDIAN() == (CODER)->endian) { \ + tGet(TYPE, TD_CODER_CURRENT(CODER), *(PVAL)); \ + } else { \ + tRGet##BITS(PVAL, TD_CODER_CURRENT(CODER)); \ + } \ + \ + TD_CODER_MOVE_POS(CODER, sizeof(*(PVAL))); \ + return 0; + +#define TD_DECODE_VARIANT_MACRO(CODER, PVAL, TYPE) \ + int32_t i = 0; \ + *(PVAL) = 0; \ + for (;;) { \ + if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, 1)) return -1; \ + TYPE tval = TD_CODER_CURRENT(CODER)[0]; \ + if (tval < ENCODE_LIMIT) { \ + *(PVAL) |= (tval << (7 * i)); \ + TD_CODER_MOVE_POS(pDecoder, 1); \ + break; \ + } else { \ + *(PVAL) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); \ + i++; \ + TD_CODER_MOVE_POS(pDecoder, 1); \ + } \ + } \ + \ + return 0; // 8 -static FORCE_INLINE int tEncodeU8(SEncoder* pEncoder, uint8_t val) { +static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) { if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val); } TD_CODER_MOVE_POS(pEncoder, sizeof(val)); return 0; } -static FORCE_INLINE int tEncodeI8(SEncoder* pEncoder, int8_t val) { +static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) { if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; + if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; tPut(int8_t, TD_CODER_CURRENT(pEncoder), val); } TD_CODER_MOVE_POS(pEncoder, sizeof(val)); @@ -89,303 +202,77 @@ static FORCE_INLINE int tEncodeI8(SEncoder* pEncoder, int8_t val) { } // 16 -static FORCE_INLINE int tEncodeU16(SEncoder* pEncoder, uint16_t val) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; - if (TD_RT_ENDIAN() == pEncoder->endian) { - tPut(uint16_t, TD_CODER_CURRENT(pEncoder), val); - } else { - tRPut16(TD_CODER_CURRENT(pEncoder), &val); - } - } - TD_CODER_MOVE_POS(pEncoder, sizeof(val)); - return 0; -} - -static FORCE_INLINE int tEncodeI16(SEncoder* pEncoder, int16_t val) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; - if (TD_RT_ENDIAN() == pEncoder->endian) { - tPut(int16_t, TD_CODER_CURRENT(pEncoder), val); - } else { - tRPut16(TD_CODER_CURRENT(pEncoder), &val); - } - } - TD_CODER_MOVE_POS(pEncoder, sizeof(val)); - return 0; -} - +static FORCE_INLINE int tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); } +static FORCE_INLINE int tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); } // 32 -static FORCE_INLINE int tEncodeU32(SEncoder* pEncoder, uint32_t val) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; - if (TD_RT_ENDIAN() == pEncoder->endian) { - tPut(uint32_t, TD_CODER_CURRENT(pEncoder), val); - } else { - tRPut32(TD_CODER_CURRENT(pEncoder), &val); - } - } - TD_CODER_MOVE_POS(pEncoder, sizeof(val)); - return 0; -} - -static FORCE_INLINE int tEncodeI32(SEncoder* pEncoder, int32_t val) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; - if (TD_RT_ENDIAN() == pEncoder->endian) { - tPut(int32_t, TD_CODER_CURRENT(pEncoder), val); - } else { - tRPut32(TD_CODER_CURRENT(pEncoder), &val); - } - } - TD_CODER_MOVE_POS(pEncoder, sizeof(val)); - return 0; -} - +static FORCE_INLINE int tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); } +static FORCE_INLINE int tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); } // 64 -static FORCE_INLINE int tEncodeU64(SEncoder* pEncoder, uint64_t val) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; - if (TD_RT_ENDIAN() == pEncoder->endian) { - tPut(uint64_t, TD_CODER_CURRENT(pEncoder), val); - } else { - tRPut64(TD_CODER_CURRENT(pEncoder), &val); - } - } - TD_CODER_MOVE_POS(pEncoder, sizeof(val)); - return 0; -} - -static FORCE_INLINE int tEncodeI64(SEncoder* pEncoder, int64_t val) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1; - if (TD_RT_ENDIAN() == pEncoder->endian) { - tPut(int64_t, TD_CODER_CURRENT(pEncoder), val); - } else { - tRPut64(TD_CODER_CURRENT(pEncoder), &val); - } - } - TD_CODER_MOVE_POS(pEncoder, sizeof(val)); - return 0; -} - +static FORCE_INLINE int tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); } +static FORCE_INLINE int tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); } // 16v -static FORCE_INLINE int tEncodeU16v(SEncoder* pEncoder, uint16_t val) { - int64_t i = 0; - while (val >= ENCODE_LIMIT) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; - TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff; - } - - val >>= 7; - i++; - } - - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; - TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val; - } - - TD_CODER_MOVE_POS(pEncoder, i + 1); - - return 0; -} - -static FORCE_INLINE int tEncodeI16v(SEncoder* pEncoder, int16_t val) { +static FORCE_INLINE int tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } +static FORCE_INLINE int tEncodeI16v(SCoder* pEncoder, int16_t val) { return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val)); } - // 32v -static FORCE_INLINE int tEncodeU32v(SEncoder* pEncoder, uint32_t val) { - int64_t i = 0; - while (val >= ENCODE_LIMIT) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; - TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff; - } - - val >>= 7; - i++; - } - - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; - TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val; - } - - TD_CODER_MOVE_POS(pEncoder, i + 1); - - return 0; -} - -static FORCE_INLINE int tEncodeI32v(SEncoder* pEncoder, int32_t val) { +static FORCE_INLINE int tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } +static FORCE_INLINE int tEncodeI32v(SCoder* pEncoder, int32_t val) { return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val)); } - // 64v -static FORCE_INLINE int tEncodeU64v(SEncoder* pEncoder, uint64_t val) { - int64_t i = 0; - while (val >= ENCODE_LIMIT) { - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; - TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff; - } - - val >>= 7; - i++; - } - - if (pEncoder->data) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1; - TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val; - } - - TD_CODER_MOVE_POS(pEncoder, i + 1); - - return 0; -} - -static FORCE_INLINE int tEncodeI64v(SEncoder* pEncoder, int64_t val) { +static FORCE_INLINE int tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); } +static FORCE_INLINE int tEncodeI64v(SCoder* pEncoder, int64_t val) { return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val)); } -static FORCE_INLINE int tEncodeFloat(SEncoder* pEncoder, float val) { +static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) { // TODO return 0; } -static FORCE_INLINE int tEncodeDouble(SEncoder* pEncoder, double val) { +static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { // TODO return 0; } -static FORCE_INLINE int tEncodeCStr(SEncoder* pEncoder, const char* val) { +static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { // TODO return 0; } /* ------------------------ FOR DECODER ------------------------ */ -static FORCE_INLINE void tInitDecoder(SDecoder* pDecoder, td_endian_t endian, uint8_t* data, int32_t size) { - ASSERT(!TD_IS_NULL(data)); - pDecoder->endian = endian; - pDecoder->data = data; - pDecoder->size = size; - pDecoder->pos = 0; -} - // 8 -static FORCE_INLINE int tDecodeU8(SDecoder* pDecoder, uint8_t* val) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; +static FORCE_INLINE int tDecodeU8(SCoder* pDecoder, uint8_t* val) { + if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val); TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); return 0; } -static FORCE_INLINE int tDecodeI8(SDecoder* pDecoder, int8_t* val) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; +static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) { + if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val); TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); return 0; } // 16 -static FORCE_INLINE int tDecodeU16(SDecoder* pDecoder, uint16_t* val) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; - if (TD_RT_ENDIAN() == pDecoder->endian) { - tGet(uint16_t, TD_CODER_CURRENT(pDecoder), *val); - } else { - tRGet16(val, TD_CODER_CURRENT(pDecoder)); - } - - TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); - return 0; -} - -static FORCE_INLINE int tDecodeI16(SDecoder* pDecoder, int16_t* val) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; - if (TD_RT_ENDIAN() == pDecoder->endian) { - tGet(int16_t, TD_CODER_CURRENT(pDecoder), *val); - } else { - tRGet16(val, TD_CODER_CURRENT(pDecoder)); - } - - TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); - return 0; -} - +static FORCE_INLINE int tDecodeU16(SCoder* pDecoder, uint16_t* val) { TD_DECODE_MACRO(pDecoder, val, uint16_t, 16); } +static FORCE_INLINE int tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); } // 32 -static FORCE_INLINE int tDecodeU32(SDecoder* pDecoder, uint32_t* val) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; - if (TD_RT_ENDIAN() == pDecoder->endian) { - tGet(uint32_t, TD_CODER_CURRENT(pDecoder), *val); - } else { - tRGet32(val, TD_CODER_CURRENT(pDecoder)); - } - - TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); - return 0; -} - -static FORCE_INLINE int tDecodeI32(SDecoder* pDecoder, int32_t* val) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; - if (TD_RT_ENDIAN() == pDecoder->endian) { - tGet(int32_t, TD_CODER_CURRENT(pDecoder), *val); - } else { - tRGet32(val, TD_CODER_CURRENT(pDecoder)); - } - - TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); - return 0; -} - +static FORCE_INLINE int tDecodeU32(SCoder* pDecoder, uint32_t* val) { TD_DECODE_MACRO(pDecoder, val, uint32_t, 32); } +static FORCE_INLINE int tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); } // 64 -static FORCE_INLINE int tDecodeU64(SDecoder* pDecoder, uint64_t* val) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; - if (TD_RT_ENDIAN() == pDecoder->endian) { - tGet(uint64_t, TD_CODER_CURRENT(pDecoder), *val); - } else { - tRGet64(val, TD_CODER_CURRENT(pDecoder)); - } - - TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); - return 0; -} - -static FORCE_INLINE int tDecodeI64(SDecoder* pDecoder, int64_t* val) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1; - if (TD_RT_ENDIAN() == pDecoder->endian) { - tGet(int64_t, TD_CODER_CURRENT(pDecoder), *val); - } else { - tRGet64(val, TD_CODER_CURRENT(pDecoder)); - } - - TD_CODER_MOVE_POS(pDecoder, sizeof(*val)); - return 0; -} +static FORCE_INLINE int tDecodeU64(SCoder* pDecoder, uint64_t* val) { TD_DECODE_MACRO(pDecoder, val, uint64_t, 64); } +static FORCE_INLINE int tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); } // 16v -static FORCE_INLINE int tDecodeU16v(SDecoder* pDecoder, uint16_t* val) { - int64_t i = 0; - *val = 0; - for (;;) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1; - uint16_t tval = TD_CODER_CURRENT(pDecoder)[i]; - if (tval < ENCODE_LIMIT) { - (*val) |= (tval << (7 * i)); - break; - } else { - (*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); - i++; - } - } - - TD_CODER_MOVE_POS(pDecoder, i); - - return 0; +static FORCE_INLINE int tDecodeU16v(SCoder* pDecoder, uint16_t* val) { + TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t); } -static FORCE_INLINE int tDecodeI16v(SDecoder* pDecoder, int16_t* val) { +static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) { uint16_t tval; if (tDecodeU16v(pDecoder, &tval) < 0) { return -1; @@ -395,27 +282,11 @@ static FORCE_INLINE int tDecodeI16v(SDecoder* pDecoder, int16_t* val) { } // 32v -static FORCE_INLINE int tDecodeU32v(SDecoder* pDecoder, uint32_t* val) { - int64_t i = 0; - *val = 0; - for (;;) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1; - uint32_t tval = TD_CODER_CURRENT(pDecoder)[i]; - if (tval < ENCODE_LIMIT) { - (*val) |= (tval << (7 * i)); - break; - } else { - (*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); - i++; - } - } - - TD_CODER_MOVE_POS(pDecoder, i); - - return 0; +static FORCE_INLINE int tDecodeU32v(SCoder* pDecoder, uint32_t* val) { + TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t); } -static FORCE_INLINE int tDecodeI32v(SDecoder* pDecoder, int32_t* val) { +static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) { uint32_t tval; if (tDecodeU32v(pDecoder, &tval) < 0) { return -1; @@ -425,27 +296,11 @@ static FORCE_INLINE int tDecodeI32v(SDecoder* pDecoder, int32_t* val) { } // 64v -static FORCE_INLINE int tDecodeU64v(SDecoder* pDecoder, uint64_t* val) { - int64_t i = 0; - *val = 0; - for (;;) { - if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1; - uint64_t tval = TD_CODER_CURRENT(pDecoder)[i]; - if (tval < ENCODE_LIMIT) { - (*val) |= (tval << (7 * i)); - break; - } else { - (*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); - i++; - } - } - - TD_CODER_MOVE_POS(pDecoder, i); - - return 0; +static FORCE_INLINE int tDecodeU64v(SCoder* pDecoder, uint64_t* val) { + TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t); } -static FORCE_INLINE int tDecodeI64v(SDecoder* pDecoder, int64_t* val) { +static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) { uint64_t tval; if (tDecodeU64v(pDecoder, &tval) < 0) { return -1; @@ -454,17 +309,17 @@ static FORCE_INLINE int tDecodeI64v(SDecoder* pDecoder, int64_t* val) { return 0; } -static FORCE_INLINE int tDecodeFloat(SDecoder* pDecoder, float* val) { +static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) { // TODO return 0; } -static FORCE_INLINE int tDecodeDouble(SDecoder* pDecoder, double* val) { +static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { // TODO return 0; } -static FORCE_INLINE int tDecodeCStr(SDecoder* pEncoder, const char** val) { +static FORCE_INLINE int tDecodeCStr(SCoder* pEncoder, const char** val) { // TODO return 0; } diff --git a/source/util/src/encode.c b/source/util/src/encode.c index dc1b926db0..192ecefe43 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -14,28 +14,15 @@ */ #include "encode.h" -#include "freelist.h" -#define CODER_NODE_FIELDS \ - uint8_t* data; \ - int32_t size; \ - int32_t pos; +void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type) { + if (type == TD_ENCODER) { + if (data == NULL) size = 0; + } else { + ASSERT(data && size > 0); + } -struct SCoderNode { - TD_SLIST_NODE(SCoderNode); - CODER_NODE_FIELDS -}; - -typedef struct { - td_endian_t endian; - SFreeList fl; - CODER_NODE_FIELDS - TD_SLIST(SCoderNode) stack; -} SCoder; - -bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); } - -void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size) { + pCoder->type = type; pCoder->endian = endian; pCoder->data = data; pCoder->size = size; @@ -55,6 +42,8 @@ void tCoderClear(SCoder* pCoder) { } } +bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); } + int tStartEncode(SCoder* pCoder) { struct SCoderNode* pNode; From 6b6f3f75af8240c8120ca0b902b87952091ae2ba Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 09:27:33 +0000 Subject: [PATCH 24/56] refact --- include/common/tmsg.h | 6 ++- include/util/encode.h | 78 ++++++++++++++-------------- source/client/CMakeLists.txt | 4 +- source/common/CMakeLists.txt | 4 +- source/common/src/tmsg.c | 10 +++- source/libs/catalog/CMakeLists.txt | 4 +- source/libs/parser/CMakeLists.txt | 4 +- source/libs/planner/CMakeLists.txt | 4 +- source/libs/qcom/CMakeLists.txt | 8 +-- source/libs/qworker/CMakeLists.txt | 4 +- source/libs/scheduler/CMakeLists.txt | 4 +- source/util/CMakeLists.txt | 5 +- 12 files changed, 82 insertions(+), 53 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index af250bff03..5365a0ee36 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -58,6 +58,7 @@ extern int tMsgDict[]; typedef uint16_t tmsg_t; /* ------------------------ ENCODE/DECODE FUNCTIONS AND MACROS ------------------------ */ +#if 0 struct SMEListNode { TD_SLIST_NODE(SMEListNode); SEncoder coder; @@ -96,6 +97,7 @@ typedef struct SMsgDecoder { void tmsgInitMsgDecoder(SMsgDecoder* pMD, td_endian_t endian, uint8_t* data, int64_t size); void tmsgClearMsgDecoder(SMsgDecoder* pMD); +#endif /* ------------------------ OTHER DEFINITIONS ------------------------ */ // IE type @@ -1283,8 +1285,8 @@ typedef struct { SArray* pArray; } SVCreateTbBatchReq; -int tmsgSVCreateTbReqEncode(SMsgEncoder* pCoder, SVCreateTbReq* pReq); -int tmsgSVCreateTbReqDecode(SMsgDecoder* pCoder, SVCreateTbReq* pReq); +// int tmsgSVCreateTbReqEncode(SMsgEncoder* pCoder, SVCreateTbReq* pReq); +// int tmsgSVCreateTbReqDecode(SMsgDecoder* pCoder, SVCreateTbReq* pReq); int tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq); void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq); int tSVCreateTbBatchReqSerialize(void** buf, SVCreateTbBatchReq* pReq); diff --git a/include/util/encode.h b/include/util/encode.h index 6aa132060b..5c7d3134ae 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -74,52 +74,52 @@ typedef struct { #define TD_CODER_POS(CODER) ((CODER)->pos) #define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos) #define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE)) -#define TD_CHECK_CODER_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE)) +#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE)) void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type); void tCoderClear(SCoder* pCoder); /* ------------------------ ENCODE ------------------------ */ -int tStartEncode(SCoder* pEncoder); -void tEndEncode(SCoder* pEncoder); -int tEncodeU8(SCoder* pEncoder, uint8_t val); -int tEncodeI8(SCoder* pEncoder, int8_t val); -int tEncodeU16(SCoder* pEncoder, uint16_t val); -int tEncodeI16(SCoder* pEncoder, int16_t val); -int tEncodeU32(SCoder* pEncoder, uint32_t val); -int tEncodeI32(SCoder* pEncoder, int32_t val); -int tEncodeU64(SCoder* pEncoder, uint64_t val); -int tEncodeI64(SCoder* pEncoder, int64_t val); -int tEncodeU16v(SCoder* pEncoder, uint16_t val); -int tEncodeI16v(SCoder* pEncoder, int16_t val); -int tEncodeU32v(SCoder* pEncoder, uint32_t val); -int tEncodeI32v(SCoder* pEncoder, int32_t val); -int tEncodeU64v(SCoder* pEncoder, uint64_t val); -int tEncodeI64v(SCoder* pEncoder, int64_t val); -int tEncodeFloat(SCoder* pEncoder, float val); -int tEncodeDouble(SCoder* pEncoder, double val); -int tEncodeCStr(SCoder* pEncoder, const char* val); +static int tStartEncode(SCoder* pEncoder); +static void tEndEncode(SCoder* pEncoder); +static int tEncodeU8(SCoder* pEncoder, uint8_t val); +static int tEncodeI8(SCoder* pEncoder, int8_t val); +static int tEncodeU16(SCoder* pEncoder, uint16_t val); +static int tEncodeI16(SCoder* pEncoder, int16_t val); +static int tEncodeU32(SCoder* pEncoder, uint32_t val); +static int tEncodeI32(SCoder* pEncoder, int32_t val); +static int tEncodeU64(SCoder* pEncoder, uint64_t val); +static int tEncodeI64(SCoder* pEncoder, int64_t val); +static int tEncodeU16v(SCoder* pEncoder, uint16_t val); +static int tEncodeI16v(SCoder* pEncoder, int16_t val); +static int tEncodeU32v(SCoder* pEncoder, uint32_t val); +static int tEncodeI32v(SCoder* pEncoder, int32_t val); +static int tEncodeU64v(SCoder* pEncoder, uint64_t val); +static int tEncodeI64v(SCoder* pEncoder, int64_t val); +static int tEncodeFloat(SCoder* pEncoder, float val); +static int tEncodeDouble(SCoder* pEncoder, double val); +static int tEncodeCStr(SCoder* pEncoder, const char* val); /* ------------------------ DECODE ------------------------ */ -int tStartDecode(SCoder* pDecoder); -void tEndDecode(SCoder* pDecoder); -int tDecodeU8(SCoder* pDecoder, uint8_t* val); -int tDecodeI8(SCoder* pDecoder, int8_t* val); -int tDecodeU16(SCoder* pDecoder, uint16_t* val); -int tDecodeI16(SCoder* pDecoder, int16_t* val); -int tDecodeU32(SCoder* pDecoder, uint32_t* val); -int tDecodeI32(SCoder* pDecoder, int32_t* val); -int tDecodeU64(SCoder* pDecoder, uint64_t* val); -int tDecodeI64(SCoder* pDecoder, int64_t* val); -int tDecodeU16v(SCoder* pDecoder, uint16_t* val); -int tDecodeI16v(SCoder* pDecoder, int16_t* val); -int tDecodeU32v(SCoder* pDecoder, uint32_t* val); -int tDecodeI32v(SCoder* pDecoder, int32_t* val); -int tDecodeU64v(SCoder* pDecoder, uint64_t* val); -int tDecodeI64v(SCoder* pDecoder, int64_t* val); -int tDecodeFloat(SCoder* pDecoder, float* val); -int tDecodeDouble(SCoder* pDecoder, double* val); -int tDecodeCStr(SCoder* pEncoder, const char** val); +static int tStartDecode(SCoder* pDecoder); +static void tEndDecode(SCoder* pDecoder); +static int tDecodeU8(SCoder* pDecoder, uint8_t* val); +static int tDecodeI8(SCoder* pDecoder, int8_t* val); +static int tDecodeU16(SCoder* pDecoder, uint16_t* val); +static int tDecodeI16(SCoder* pDecoder, int16_t* val); +static int tDecodeU32(SCoder* pDecoder, uint32_t* val); +static int tDecodeI32(SCoder* pDecoder, int32_t* val); +static int tDecodeU64(SCoder* pDecoder, uint64_t* val); +static int tDecodeI64(SCoder* pDecoder, int64_t* val); +static int tDecodeU16v(SCoder* pDecoder, uint16_t* val); +static int tDecodeI16v(SCoder* pDecoder, int16_t* val); +static int tDecodeU32v(SCoder* pDecoder, uint32_t* val); +static int tDecodeI32v(SCoder* pDecoder, int32_t* val); +static int tDecodeU64v(SCoder* pDecoder, uint64_t* val); +static int tDecodeI64v(SCoder* pDecoder, int64_t* val); +static int tDecodeFloat(SCoder* pDecoder, float* val); +static int tDecodeDouble(SCoder* pDecoder, double* val); +static int tDecodeCStr(SCoder* pEncoder, const char** val); /* ------------------------ IMPL ------------------------ */ #define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \ diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index ad6a93415c..3210c0c6de 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -11,4 +11,6 @@ target_link_libraries( PRIVATE os util common transport parser planner catalog scheduler function qcom ) -ADD_SUBDIRECTORY(test) \ No newline at end of file +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index 1ff83b091d..04e5a36e86 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -12,4 +12,6 @@ target_link_libraries( INTERFACE api ) -ADD_SUBDIRECTORY(test) +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index a18a472dba..c0baa1e411 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -27,12 +27,15 @@ #undef TD_MSG_SEG_CODE_ #include "tmsgdef.h" +#if 0 static int tmsgStartEncode(SMsgEncoder *pME); static void tmsgEndEncode(SMsgEncoder *pME); static int tmsgStartDecode(SMsgDecoder *pMD); static void tmsgEndDecode(SMsgDecoder *pMD); +#endif /* ------------------------ ENCODE/DECODE FUNCTIONS ------------------------ */ +#if 0 void tmsgInitMsgEncoder(SMsgEncoder *pME, td_endian_t endian, uint8_t *data, int64_t size) { tInitEncoder(&(pME->coder), endian, data, size); TD_SLIST_INIT(&(pME->eStack)); @@ -74,8 +77,10 @@ void tmsgClearMsgDecoder(SMsgDecoder *pMD) { } } } +#endif /* ------------------------ MESSAGE ENCODE/DECODE ------------------------ */ +#if 0 int tmsgSVCreateTbReqEncode(SMsgEncoder *pCoder, SVCreateTbReq *pReq) { tmsgStartEncode(pCoder); // TODO @@ -97,6 +102,7 @@ int tmsgSVCreateTbReqDecode(SMsgDecoder *pCoder, SVCreateTbReq *pReq) { tmsgEndDecode(pCoder); return 0; } +#endif int tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { int tlen = 0; @@ -221,6 +227,7 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) { } /* ------------------------ STATIC METHODS ------------------------ */ +#if 0 static int tmsgStartEncode(SMsgEncoder *pME) { struct SMEListNode *pNode = (struct SMEListNode *)malloc(sizeof(*pNode)); if (TD_IS_NULL(pNode)) return -1; @@ -278,4 +285,5 @@ static void tmsgEndDecode(SMsgDecoder *pMD) { pMD->coder = pNode->coder; free(pNode); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/source/libs/catalog/CMakeLists.txt b/source/libs/catalog/CMakeLists.txt index f47e105b8a..bb9ed686a7 100644 --- a/source/libs/catalog/CMakeLists.txt +++ b/source/libs/catalog/CMakeLists.txt @@ -11,4 +11,6 @@ target_link_libraries( PRIVATE os util transport qcom ) -ADD_SUBDIRECTORY(test) \ No newline at end of file +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/libs/parser/CMakeLists.txt b/source/libs/parser/CMakeLists.txt index 6ab3020935..7f77876c4c 100644 --- a/source/libs/parser/CMakeLists.txt +++ b/source/libs/parser/CMakeLists.txt @@ -11,4 +11,6 @@ target_link_libraries( PRIVATE os util catalog function transport qcom ) -ADD_SUBDIRECTORY(test) +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) diff --git a/source/libs/planner/CMakeLists.txt b/source/libs/planner/CMakeLists.txt index 7f8c118663..6234dbe0ac 100644 --- a/source/libs/planner/CMakeLists.txt +++ b/source/libs/planner/CMakeLists.txt @@ -11,4 +11,6 @@ target_link_libraries( PRIVATE os util catalog cjson parser transport function qcom ) -ADD_SUBDIRECTORY(test) +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) diff --git a/source/libs/qcom/CMakeLists.txt b/source/libs/qcom/CMakeLists.txt index 8e09f3d97a..c63e54fb9b 100644 --- a/source/libs/qcom/CMakeLists.txt +++ b/source/libs/qcom/CMakeLists.txt @@ -7,8 +7,10 @@ target_include_directories( ) target_link_libraries( - qcom - PRIVATE os util transport + qcom + PRIVATE os util transport ) -ADD_SUBDIRECTORY(test) +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) diff --git a/source/libs/qworker/CMakeLists.txt b/source/libs/qworker/CMakeLists.txt index 001756d7c3..ea3e97057b 100644 --- a/source/libs/qworker/CMakeLists.txt +++ b/source/libs/qworker/CMakeLists.txt @@ -11,4 +11,6 @@ target_link_libraries( PRIVATE os util transport planner qcom ) -ADD_SUBDIRECTORY(test) \ No newline at end of file +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/libs/scheduler/CMakeLists.txt b/source/libs/scheduler/CMakeLists.txt index 6baaab1ef4..4e297f4e17 100644 --- a/source/libs/scheduler/CMakeLists.txt +++ b/source/libs/scheduler/CMakeLists.txt @@ -12,4 +12,6 @@ target_link_libraries( PRIVATE os util planner qcom common catalog transport ) -ADD_SUBDIRECTORY(test) \ No newline at end of file +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/util/CMakeLists.txt b/source/util/CMakeLists.txt index bf1774b45b..ed936e90f6 100644 --- a/source/util/CMakeLists.txt +++ b/source/util/CMakeLists.txt @@ -14,4 +14,7 @@ target_link_libraries( PUBLIC api ) -ADD_SUBDIRECTORY(test) +if(${BUILD_TEST}) + ADD_SUBDIRECTORY(test) +endif(${BUILD_TEST}) + From 6d3032d538c82715784eb0c1dd80dc96faa242f6 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 09:40:11 +0000 Subject: [PATCH 25/56] more --- include/util/encode.h | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index 5c7d3134ae..4164a7660f 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -227,13 +227,21 @@ static FORCE_INLINE int tEncodeI64v(SCoder* pEncoder, int64_t val) { } static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) { - // TODO - return 0; + union { + uint32_t ui; + float f; + } v = {.f = val}; + + return tEncodeU32(pEncoder, v.ui); } static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { - // TODO - return 0; + union { + uint64_t ui; + double d; + } v = {.d = val}; + + return tEncodeU64(pEncoder, v.ui); } static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { @@ -310,12 +318,30 @@ static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) { } static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) { - // TODO + union { + uint32_t ui; + float f; + } v; + + if (tDecodeU32(pDecoder, &(v.ui)) < 0) { + return -1; + } + + *val = v.f; return 0; } static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { - // TODO + union { + uint64_t ui; + double d; + } v; + + if (tDecodeU64(pEncoder, &(v.ui)) < 0) { + return -1; + } + + *val = v.d; return 0; } From e4252065d1a4d113ae66baace85765433e2085dd Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 09:41:00 +0000 Subject: [PATCH 26/56] refact --- include/util/encode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/util/encode.h b/include/util/encode.h index 4164a7660f..3c98e8108f 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -236,7 +236,7 @@ static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) { } static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { - union { + union { uint64_t ui; double d; } v = {.d = val}; From ec03a0eb8fdb7059fad42bac3ee991ec88d36e44 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 09:42:57 +0000 Subject: [PATCH 27/56] more --- source/util/src/encode.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/util/src/encode.c b/source/util/src/encode.c index 192ecefe43..a3946daf5c 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -15,6 +15,11 @@ #include "encode.h" +#if __STDC_VERSION__ >= 201112L +static_assert(sizeof(float) == sizeof(uint32_t), "sizeof(float) must equal to sizeof(uint32_t)"); +static_assert(sizeof(double) == sizeof(uint64_t), "sizeof(double) must equal to sizeof(uint64_t)"); +#endif + void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type) { if (type == TD_ENCODER) { if (data == NULL) size = 0; From 40fc4b6cf38c0373de43be0f68638fd858c1a562 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 2 Jan 2022 17:50:40 +0800 Subject: [PATCH 28/56] fix mem leak and invalid read/write found by valgrind --- source/libs/index/inc/index_tfile.h | 1 + source/libs/index/src/index.c | 3 ++- source/libs/index/src/index_cache.c | 1 + source/libs/index/src/index_fst.c | 2 ++ source/libs/index/src/index_tfile.c | 9 ++++++--- source/libs/index/test/indexTests.cc | 29 +++++++++++++++++++++++++--- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/source/libs/index/inc/index_tfile.h b/source/libs/index/inc/index_tfile.h index 675203fa1a..4618a39197 100644 --- a/source/libs/index/inc/index_tfile.h +++ b/source/libs/index/inc/index_tfile.h @@ -117,6 +117,7 @@ int tfileWriterFinish(TFileWriter* tw); // IndexTFile* indexTFileCreate(const char* path); +void indexTFileDestroy(IndexTFile* tfile); int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid); int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result); diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 11a2aa5e5f..9c7320b301 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -103,6 +103,7 @@ void indexClose(SIndex* sIdx) { } taosHashCleanup(sIdx->colObj); pthread_mutex_destroy(&sIdx->mtx); + indexTFileDestroy(sIdx->tindex); #endif free(sIdx->path); free(sIdx); @@ -479,7 +480,7 @@ void iterateValueDestroy(IterateValue* value, bool destroy) { } else { if (value->val != NULL) { taosArrayClear(value->val); } } - // free(value->colVal); + free(value->colVal); value->colVal = NULL; } static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index 0f00d9d4af..b4c533e998 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -150,6 +150,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) { MemTable* tbl = cache->imm; iiter->val.val = taosArrayInit(1, sizeof(uint64_t)); + iiter->val.colVal = NULL; iiter->iter = tbl != NULL ? tSkipListCreateIter(tbl->mem) : NULL; iiter->next = indexCacheIteratorNext; iiter->getValue = indexCacheIteratorGetValue; diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 088c7369d5..bfaeeaaa33 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -1062,6 +1062,7 @@ Output fstEmptyFinalOutput(Fst* fst, bool* null) { } else { *null = true; } + fstNodeDestroy(node); return res; } @@ -1286,6 +1287,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb StreamWithStateResult* result = swsResultCreate(&slice, fOutput, tState); free(buf); fstSliceDestroy(&slice); + taosArrayDestroy(nodes); return result; } free(buf); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index fe54b5ebb3..95c713fb0a 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -360,7 +360,7 @@ IndexTFile* indexTFileCreate(const char* path) { tfile->cache = tfileCacheCreate(path); return tfile; } -void IndexTFileDestroy(IndexTFile* tfile) { +void indexTFileDestroy(IndexTFile* tfile) { tfileCacheDestroy(tfile->cache); free(tfile); } @@ -415,7 +415,7 @@ static bool tfileIteratorNext(Iterate* iiter) { static IterateValue* tifileIterateGetValue(Iterate* iter) { return &iter->val; } static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) { - TFileFstIter* tIter = calloc(1, sizeof(Iterate)); + TFileFstIter* tIter = calloc(1, sizeof(TFileFstIter)); if (tIter == NULL) { return NULL; } tIter->ctx = automCtxCreate(NULL, AUTOMATION_ALWAYS); @@ -437,6 +437,7 @@ Iterate* tfileIteratorCreate(TFileReader* reader) { iter->next = tfileIteratorNext; iter->getValue = tifileIterateGetValue; iter->val.val = taosArrayInit(1, sizeof(uint64_t)); + iter->val.colVal = NULL; return iter; } void tfileIteratorDestroy(Iterate* iter) { @@ -449,6 +450,7 @@ void tfileIteratorDestroy(Iterate* iter) { streamWithStateDestroy(tIter->st); fstStreamBuilderDestroy(tIter->fb); automCtxDestroy(tIter->ctx); + free(tIter); free(iter); } @@ -482,7 +484,7 @@ static int tfileValueCompare(const void* a, const void* b, const void* param) { TFileValue* tfileValueCreate(char* val) { TFileValue* tf = calloc(1, sizeof(TFileValue)); if (tf == NULL) { return NULL; } - tf->colVal = val; + tf->colVal = tstrdup(val); tf->tableId = taosArrayInit(32, sizeof(uint64_t)); return tf; } @@ -493,6 +495,7 @@ int tfileValuePush(TFileValue* tf, uint64_t val) { } void tfileValueDestroy(TFileValue* tf) { taosArrayDestroy(tf->tableId); + free(tf->colVal); free(tf); } static void tfileSerialTableIdsToBuf(char* buf, SArray* ids) { diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 7bf40bc7b3..bdfb86ce17 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -457,7 +457,10 @@ TEST_F(IndexTFileEnv, test_tfile_write) { // taosArrayPush(data, &v4); fObj->Put(data); - for (size_t i = 0; i < taosArrayGetSize(data); i++) { destroyTFileValue(taosArrayGetP(data, i)); } + for (size_t i = 0; i < taosArrayGetSize(data); i++) { + // data + destroyTFileValue(taosArrayGetP(data, i)); + } taosArrayDestroy(data); std::string colName("voltage"); @@ -470,6 +473,7 @@ TEST_F(IndexTFileEnv, test_tfile_write) { fObj->Get(&query, result); assert(taosArrayGetSize(result) == 200); indexTermDestroy(term); + taosArrayDestroy(result); // tfileWriterDestroy(twrite); } @@ -534,6 +538,7 @@ TEST_F(IndexCacheEnv, cache_test) { SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); coj->Put(term, colId, version++, suid++); + indexTermDestroy(term); // indexTermDestry(term); } { @@ -541,24 +546,28 @@ TEST_F(IndexCacheEnv, cache_test) { SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); coj->Put(term, colId, version++, suid++); + indexTermDestroy(term); } { std::string colVal("v2"); SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); coj->Put(term, colId, version++, suid++); + indexTermDestroy(term); } { std::string colVal("v3"); SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); coj->Put(term, colId, version++, suid++); + indexTermDestroy(term); } { std::string colVal("v3"); SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); coj->Put(term, colId, version++, suid++); + indexTermDestroy(term); } coj->Debug(); std::cout << "--------first----------" << std::endl; @@ -567,12 +576,14 @@ TEST_F(IndexCacheEnv, cache_test) { SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); coj->Put(term, othColId, version++, suid++); + indexTermDestroy(term); } { std::string colVal("v4"); SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); coj->Put(term, othColId, version++, suid++); + indexTermDestroy(term); } coj->Debug(); std::cout << "--------second----------" << std::endl; @@ -583,6 +594,7 @@ TEST_F(IndexCacheEnv, cache_test) { SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); coj->Put(term, colId, version++, suid++); + indexTermDestroy(term); } } coj->Debug(); @@ -598,6 +610,9 @@ TEST_F(IndexCacheEnv, cache_test) { coj->Get(&query, colId, 10000, ret, &valType); std::cout << "size : " << taosArrayGetSize(ret) << std::endl; assert(taosArrayGetSize(ret) == 4); + taosArrayDestroy(ret); + + indexTermDestroy(term); } { std::string colVal("v2"); @@ -609,6 +624,9 @@ TEST_F(IndexCacheEnv, cache_test) { coj->Get(&query, colId, 10000, ret, &valType); assert(taosArrayGetSize(ret) == 1); + taosArrayDestroy(ret); + + indexTermDestroy(term); } } class IndexObj { @@ -678,13 +696,16 @@ class IndexObj { SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t)); if (Search(mq, result) == 0) { std::cout << "search one successfully" << std::endl; } - return taosArrayGetSize(result); + int sz = taosArrayGetSize(result); + indexMultiTermQueryDestroy(mq); + taosArrayDestroy(result); + return sz; // assert(taosArrayGetSize(result) == targetSize); } void PutOne(const std::string& colName, const std::string& colVal) { + SIndexMultiTerm* terms = indexMultiTermCreate(); SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); - SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); Put(terms, 10); indexMultiTermDestroy(terms); @@ -783,6 +804,8 @@ TEST_F(IndexEnv2, testIndexOpen) { index->Search(mq, result); std::cout << "target size: " << taosArrayGetSize(result) << std::endl; assert(taosArrayGetSize(result) == 400); + taosArrayDestroy(result); + indexMultiTermQueryDestroy(mq); } } From 82be83a22616c8868231ca02eb8489d4bd3f9acf Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 09:51:47 +0000 Subject: [PATCH 29/56] more --- include/util/encode.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index 3c98e8108f..7dc8d07f0a 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -244,11 +244,20 @@ static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { return tEncodeU64(pEncoder, v.ui); } -static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { - // TODO +static FORCE_INLINE int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, size_t len) { + if (tEncodeI32v(pEncoder, len) < 0) return -1; + if (pEncoder->data) { + if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len + 1)) return -1; + memcpy(TD_CODER_CURRENT(pEncoder), val, len + 1); + } + TD_CODER_MOVE_POS(pEncoder, len + 1); return 0; } +static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { + return tEncodeCstrWithLen(pEncoder, val, strlen(val)); +} + /* ------------------------ FOR DECODER ------------------------ */ // 8 static FORCE_INLINE int tDecodeU8(SCoder* pDecoder, uint8_t* val) { From 6835e4956be283f2bb1184772a96e284f919cac7 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:03:21 +0000 Subject: [PATCH 30/56] more --- include/util/encode.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index 7dc8d07f0a..0b90d66f5a 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -98,6 +98,7 @@ static int tEncodeU64v(SCoder* pEncoder, uint64_t val); static int tEncodeI64v(SCoder* pEncoder, int64_t val); static int tEncodeFloat(SCoder* pEncoder, float val); static int tEncodeDouble(SCoder* pEncoder, double val); +static int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, uint64_t len); static int tEncodeCStr(SCoder* pEncoder, const char* val); /* ------------------------ DECODE ------------------------ */ @@ -119,6 +120,7 @@ static int tDecodeU64v(SCoder* pDecoder, uint64_t* val); static int tDecodeI64v(SCoder* pDecoder, int64_t* val); static int tDecodeFloat(SCoder* pDecoder, float* val); static int tDecodeDouble(SCoder* pDecoder, double* val); +static int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len); static int tDecodeCStr(SCoder* pEncoder, const char** val); /* ------------------------ IMPL ------------------------ */ @@ -244,8 +246,8 @@ static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { return tEncodeU64(pEncoder, v.ui); } -static FORCE_INLINE int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, size_t len) { - if (tEncodeI32v(pEncoder, len) < 0) return -1; +static FORCE_INLINE int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, uint64_t len) { + if (tEncodeU64v(pEncoder, len) < 0) return -1; if (pEncoder->data) { if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len + 1)) return -1; memcpy(TD_CODER_CURRENT(pEncoder), val, len + 1); @@ -255,7 +257,7 @@ static FORCE_INLINE int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, si } static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { - return tEncodeCstrWithLen(pEncoder, val, strlen(val)); + return tEncodeCstrWithLen(pEncoder, val, (uint64_t)strlen(val)); } /* ------------------------ FOR DECODER ------------------------ */ @@ -346,7 +348,7 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { double d; } v; - if (tDecodeU64(pEncoder, &(v.ui)) < 0) { + if (tDecodeU64(pDecoder, &(v.ui)) < 0) { return -1; } @@ -354,11 +356,21 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { return 0; } -static FORCE_INLINE int tDecodeCStr(SCoder* pEncoder, const char** val) { - // TODO +static FORCE_INLINE int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) { + if (tDecodeU64v(pDecoder, len) < 0) return -1; + + if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len + 1)) return -1; + *val = (char *)TD_CODER_CURRENT(pDecoder); + + TD_CODER_MOVE_POS(pDecoder, *len + 1); return 0; } +static FORCE_INLINE int tDecodeCStr(SCoder* pDecoder, const char** val) { + uint64_t len; + return tDecodeCStrAndLen(pDecoder, val, &len); +} + #ifdef __cplusplus } #endif From 17852c2c431f558cae31182f9b5af5555661013f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:05:05 +0000 Subject: [PATCH 31/56] more --- include/util/encode.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/util/encode.h b/include/util/encode.h index 0b90d66f5a..b3ebda4ed7 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -75,6 +75,7 @@ typedef struct { #define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos) #define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE)) #define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE)) +#define TCODER_MALLOC(SIZE, CODER) TFL_MALLOC(SIZE, &((CODER)->fl)) void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type); void tCoderClear(SCoder* pCoder); From bac6f05b96a9998b8e5ef7d8b4228f7b56c4105f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:06:00 +0000 Subject: [PATCH 32/56] refact --- include/util/encode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/util/encode.h b/include/util/encode.h index b3ebda4ed7..7585566dc9 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -361,7 +361,7 @@ static FORCE_INLINE int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, ui if (tDecodeU64v(pDecoder, len) < 0) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len + 1)) return -1; - *val = (char *)TD_CODER_CURRENT(pDecoder); + *val = (char*)TD_CODER_CURRENT(pDecoder); TD_CODER_MOVE_POS(pDecoder, *len + 1); return 0; From ecaf4268987976a679ac4ba9ac1e7d60c168f2a3 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:15:52 +0000 Subject: [PATCH 33/56] more --- include/util/encode.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/include/util/encode.h b/include/util/encode.h index 7585566dc9..c916d8fc6a 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -99,6 +99,7 @@ static int tEncodeU64v(SCoder* pEncoder, uint64_t val); static int tEncodeI64v(SCoder* pEncoder, int64_t val); static int tEncodeFloat(SCoder* pEncoder, float val); static int tEncodeDouble(SCoder* pEncoder, double val); +static int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len); static int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, uint64_t len); static int tEncodeCStr(SCoder* pEncoder, const char* val); @@ -121,8 +122,9 @@ static int tDecodeU64v(SCoder* pDecoder, uint64_t* val); static int tDecodeI64v(SCoder* pDecoder, int64_t* val); static int tDecodeFloat(SCoder* pDecoder, float* val); static int tDecodeDouble(SCoder* pDecoder, double* val); +static int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len); static int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len); -static int tDecodeCStr(SCoder* pEncoder, const char** val); +static int tDecodeCStr(SCoder* pDecoder, const char** val); /* ------------------------ IMPL ------------------------ */ #define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \ @@ -247,6 +249,17 @@ static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) { return tEncodeU64(pEncoder, v.ui); } +static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) { + if (tEncodeU64v(pEncoder, len) < 0) return -1; + if (pEncoder->data) { + if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1; + memcpy(TD_CODER_CURRENT(pEncoder), len); + } + + TD_CODER_MOVE_POS(pEncoder, len); + return 0; +} + static FORCE_INLINE int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, uint64_t len) { if (tEncodeU64v(pEncoder, len) < 0) return -1; if (pEncoder->data) { @@ -357,6 +370,16 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { return 0; } +static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) { + if (tDecodeU64v(pDecoder, &len) < 0) return -1; + + if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1; + *val = (void*)TD_CODER_CURRENT(pDecoder); + + TD_CODER_MOVE_POS(pDecoder, *len); + return 0; +} + static FORCE_INLINE int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) { if (tDecodeU64v(pDecoder, len) < 0) return -1; From da8e603c49f9091780e0aa5fda324ebbf535b64b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:21:37 +0000 Subject: [PATCH 34/56] more --- include/util/encode.h | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index c916d8fc6a..f5c8db0b5a 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -253,7 +253,7 @@ static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_ if (tEncodeU64v(pEncoder, len) < 0) return -1; if (pEncoder->data) { if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1; - memcpy(TD_CODER_CURRENT(pEncoder), len); + memcpy(TD_CODER_CURRENT(pEncoder), val, len); } TD_CODER_MOVE_POS(pEncoder, len); @@ -261,13 +261,7 @@ static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_ } static FORCE_INLINE int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, uint64_t len) { - if (tEncodeU64v(pEncoder, len) < 0) return -1; - if (pEncoder->data) { - if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len + 1)) return -1; - memcpy(TD_CODER_CURRENT(pEncoder), val, len + 1); - } - TD_CODER_MOVE_POS(pEncoder, len + 1); - return 0; + return tEncodeBinary(pEncoder, (void*)val, len + 1); } static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { @@ -371,7 +365,7 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) { } static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) { - if (tDecodeU64v(pDecoder, &len) < 0) return -1; + if (tDecodeU64v(pDecoder, len) < 0) return -1; if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1; *val = (void*)TD_CODER_CURRENT(pDecoder); @@ -381,12 +375,8 @@ static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64 } static FORCE_INLINE int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) { - if (tDecodeU64v(pDecoder, len) < 0) return -1; - - if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len + 1)) return -1; - *val = (char*)TD_CODER_CURRENT(pDecoder); - - TD_CODER_MOVE_POS(pDecoder, *len + 1); + if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1; + (*len) -= 1; return 0; } From 8f1a1b7bbc5b5d15ea49d9e8e5944c518e71984c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:26:32 +0000 Subject: [PATCH 35/56] refact --- include/common/tmsg.h | 42 ------------ source/common/src/tmsg.c | 141 +-------------------------------------- 2 files changed, 1 insertion(+), 182 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 5365a0ee36..6c2b4a1acc 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -57,48 +57,6 @@ extern int tMsgDict[]; typedef uint16_t tmsg_t; -/* ------------------------ ENCODE/DECODE FUNCTIONS AND MACROS ------------------------ */ -#if 0 -struct SMEListNode { - TD_SLIST_NODE(SMEListNode); - SEncoder coder; -}; - -typedef struct SMsgEncoder { - SEncoder coder; - TD_SLIST(SMEListNode) eStack; // encode stack -} SMsgEncoder; - -struct SMDFreeListNode { - TD_SLIST_NODE(SMDFreeListNode); - char payload[]; -}; - -struct SMDListNode { - TD_SLIST_NODE(SMDListNode); - SDecoder coder; -}; - -typedef struct SMsgDecoder { - SDecoder coder; - TD_SLIST(SMDListNode) dStack; - TD_SLIST(SMDFreeListNode) freeList; -} SMsgDecoder; - -#define TMSG_MALLOC(SIZE, DECODER) \ - ({ \ - void* ptr = malloc((SIZE) + sizeof(struct SMDFreeListNode)); \ - if (ptr) { \ - TD_SLIST_PUSH(&((DECODER)->freeList), (struct SMDFreeListNode*)ptr); \ - ptr = POINTER_SHIFT(ptr, sizeof(struct SMDFreeListNode*)); \ - } \ - ptr; \ - }) - -void tmsgInitMsgDecoder(SMsgDecoder* pMD, td_endian_t endian, uint8_t* data, int64_t size); -void tmsgClearMsgDecoder(SMsgDecoder* pMD); -#endif - /* ------------------------ OTHER DEFINITIONS ------------------------ */ // IE type #define TSDB_IE_TYPE_SEC 1 diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c0baa1e411..0874c471aa 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -27,83 +27,6 @@ #undef TD_MSG_SEG_CODE_ #include "tmsgdef.h" -#if 0 -static int tmsgStartEncode(SMsgEncoder *pME); -static void tmsgEndEncode(SMsgEncoder *pME); -static int tmsgStartDecode(SMsgDecoder *pMD); -static void tmsgEndDecode(SMsgDecoder *pMD); -#endif - -/* ------------------------ ENCODE/DECODE FUNCTIONS ------------------------ */ -#if 0 -void tmsgInitMsgEncoder(SMsgEncoder *pME, td_endian_t endian, uint8_t *data, int64_t size) { - tInitEncoder(&(pME->coder), endian, data, size); - TD_SLIST_INIT(&(pME->eStack)); -} - -void tmsgClearMsgEncoder(SMsgEncoder *pME) { - struct SMEListNode *pNode; - for (;;) { - pNode = TD_SLIST_HEAD(&(pME->eStack)); - if (TD_IS_NULL(pNode)) break; - TD_SLIST_POP(&(pME->eStack)); - free(pNode); - } -} - -void tmsgInitMsgDecoder(SMsgDecoder *pMD, td_endian_t endian, uint8_t *data, int64_t size) { - tInitDecoder(&pMD->coder, endian, data, size); - TD_SLIST_INIT(&(pMD->dStack)); - TD_SLIST_INIT(&(pMD->freeList)); -} - -void tmsgClearMsgDecoder(SMsgDecoder *pMD) { - { - struct SMDFreeListNode *pNode; - for (;;) { - pNode = TD_SLIST_HEAD(&(pMD->freeList)); - if (TD_IS_NULL(pNode)) break; - TD_SLIST_POP(&(pMD->freeList)); - free(pNode); - } - } - { - struct SMDListNode *pNode; - for (;;) { - pNode = TD_SLIST_HEAD(&(pMD->dStack)); - if (TD_IS_NULL(pNode)) break; - TD_SLIST_POP(&(pMD->dStack)); - free(pNode); - } - } -} -#endif - -/* ------------------------ MESSAGE ENCODE/DECODE ------------------------ */ -#if 0 -int tmsgSVCreateTbReqEncode(SMsgEncoder *pCoder, SVCreateTbReq *pReq) { - tmsgStartEncode(pCoder); - // TODO - - tmsgEndEncode(pCoder); - return 0; -} - -int tmsgSVCreateTbReqDecode(SMsgDecoder *pCoder, SVCreateTbReq *pReq) { - tmsgStartDecode(pCoder); - - // TODO: decode - - // Decode is not end - if (pCoder->coder.pos != pCoder->coder.size) { - // Continue decode - } - - tmsgEndDecode(pCoder); - return 0; -} -#endif - int tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { int tlen = 0; @@ -224,66 +147,4 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) { } return buf; -} - -/* ------------------------ STATIC METHODS ------------------------ */ -#if 0 -static int tmsgStartEncode(SMsgEncoder *pME) { - struct SMEListNode *pNode = (struct SMEListNode *)malloc(sizeof(*pNode)); - if (TD_IS_NULL(pNode)) return -1; - - pNode->coder = pME->coder; - TD_SLIST_PUSH(&(pME->eStack), pNode); - TD_CODER_MOVE_POS(&(pME->coder), sizeof(int32_t)); - - return 0; -} - -static void tmsgEndEncode(SMsgEncoder *pME) { - int32_t size; - struct SMEListNode *pNode; - - pNode = TD_SLIST_HEAD(&(pME->eStack)); - ASSERT(pNode); - TD_SLIST_POP(&(pME->eStack)); - - size = pME->coder.pos - pNode->coder.pos; - tEncodeI32(&(pNode->coder), size); - - free(pNode); -} - -static int tmsgStartDecode(SMsgDecoder *pMD) { - struct SMDListNode *pNode; - int32_t size; - - pNode = (struct SMDListNode *)malloc(sizeof(*pNode)); - if (pNode == NULL) return -1; - - tDecodeI32(&(pMD->coder), &size); - - pNode->coder = pMD->coder; - TD_SLIST_PUSH(&(pMD->dStack), pNode); - - pMD->coder.pos = 0; - pMD->coder.size = size - sizeof(int32_t); - pMD->coder.data = TD_CODER_CURRENT(&(pNode->coder)); - - return 0; -} - -static void tmsgEndDecode(SMsgDecoder *pMD) { - ASSERT(pMD->coder.pos == pMD->coder.size); - struct SMDListNode *pNode; - - pNode = TD_SLIST_HEAD(&(pMD->dStack)); - ASSERT(pNode); - TD_SLIST_POP(&(pMD->dStack)); - - pNode->coder.pos += pMD->coder.size; - - pMD->coder = pNode->coder; - - free(pNode); -} -#endif \ No newline at end of file +} \ No newline at end of file From 729aabca1591540002121139c3d002276f077ef4 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:29:47 +0000 Subject: [PATCH 36/56] refact --- include/common/tmsg.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 6c2b4a1acc..85e75139ce 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1243,8 +1243,6 @@ typedef struct { SArray* pArray; } SVCreateTbBatchReq; -// int tmsgSVCreateTbReqEncode(SMsgEncoder* pCoder, SVCreateTbReq* pReq); -// int tmsgSVCreateTbReqDecode(SMsgDecoder* pCoder, SVCreateTbReq* pReq); int tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq); void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq); int tSVCreateTbBatchReqSerialize(void** buf, SVCreateTbBatchReq* pReq); From eaca069a45b8b9ff4b98245f91a58edfeca5d16c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 2 Jan 2022 10:34:31 +0000 Subject: [PATCH 37/56] more --- include/util/encode.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/util/encode.h b/include/util/encode.h index f5c8db0b5a..02edbe888e 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -125,6 +125,7 @@ static int tDecodeDouble(SCoder* pDecoder, double* val); static int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len); static int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len); static int tDecodeCStr(SCoder* pDecoder, const char** val); +static int tDecodeCStrTo(SCoder* pDecoder, char* val); /* ------------------------ IMPL ------------------------ */ #define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \ @@ -385,6 +386,15 @@ static FORCE_INLINE int tDecodeCStr(SCoder* pDecoder, const char** val) { return tDecodeCStrAndLen(pDecoder, val, &len); } +static int tDecodeCStrTo(SCoder* pDecoder, char* val) { + const char* pStr; + uint64_t len; + if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1; + + memcpy(val, pStr, len+1); + return 0; +} + #ifdef __cplusplus } #endif From 5326356375a0ea7278bd3eefd63803f2d6712c3a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 2 Jan 2022 23:24:22 +0800 Subject: [PATCH 38/56] [td-11818] create multiple tables. --- include/libs/planner/planner.h | 7 +- source/client/src/clientMain.c | 4 +- source/client/test/clientTests.cpp | 6 +- source/libs/parser/inc/sql.y | 2 +- source/libs/parser/src/astGenerator.c | 2 +- source/libs/parser/src/dCDAstProcess.c | 10 +- source/libs/parser/src/sql.c | 2033 ++++++++--------- source/libs/planner/inc/plannerInt.h | 5 + source/libs/planner/src/logicPlan.c | 18 +- source/libs/planner/src/physicalPlan.c | 30 +- source/libs/planner/src/physicalPlanJson.c | 5 +- source/libs/planner/src/planner.c | 3 + source/libs/scheduler/src/scheduler.c | 26 +- source/libs/scheduler/test/schedulerTests.cpp | 10 +- 14 files changed, 1094 insertions(+), 1067 deletions(-) diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 3ca923b0aa..5ad53703c7 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -119,11 +119,12 @@ typedef struct SSubplanId { } SSubplanId; typedef struct SSubplan { - SSubplanId id; // unique id of the subplan + SSubplanId id; // unique id of the subplan int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN|QUERY_TYPE_MODIFY - int32_t level; // the execution level of current subplan, starting from 0. + int32_t msgType; // message type for subplan, used to denote the send message type to vnode. + int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner. SEpSet execEpSet; // for the scan/modify subplan, the optional execution node - SArray *pChildern; // the datasource subplan,from which to fetch the result + SArray *pChildren; // the datasource subplan,from which to fetch the result SArray *pParents; // the data destination subplan, get data from current subplan SPhyNode *pNode; // physical plan of current subplan SDataSink *pDataSink; // data of the subplan flow into the datasink diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 894b810d7b..e7c44d9f28 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -140,7 +140,9 @@ TAOS_ROW taos_fetch_row(TAOS_RES *pRes) { SRequestObj *pRequest = (SRequestObj *) pRes; if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || - pRequest->type == TSDB_SQL_INSERT || pRequest->code != TSDB_CODE_SUCCESS) { + pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || + taos_num_fields(pRes) == 0) { return NULL; } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 7a87acfc36..a3116fecea 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -279,7 +279,7 @@ TEST(testCase, connect_Test) { // taos_free_result(pRes); // taos_close(pConn); //} -// + //TEST(testCase, create_table_Test) { // // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // // assert(pConn != NULL); @@ -470,9 +470,9 @@ TEST(testCase, create_multiple_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)"); + pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); if (taos_errno(pRes) != 0) { - printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); + printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 789f5a98e2..c6e1c004e3 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -392,7 +392,7 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. { %type create_stable_args{SCreateTableSql*} create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. { A = tSetCreateTableInfo(X, Y, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); + setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_STABLE); V.n += Z.n; setCreatedTableName(pInfo, &V, &U); diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index 9122b0df96..3f45012405 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -785,7 +785,7 @@ void destroySqlInfo(SSqlInfo *pInfo) { taosArrayDestroy(pInfo->funcs); if (pInfo->type == TSDB_SQL_SELECT) { destroyAllSqlNode(&pInfo->sub); - } else if (pInfo->type == TSDB_SQL_CREATE_TABLE) { + } else if (pInfo->type == TSDB_SQL_CREATE_STABLE) { pInfo->pCreateTableInfo = destroyCreateTableSql(pInfo->pCreateTableInfo); } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) { taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeItem); diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 76e26c159b..6b42a93b73 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -761,8 +761,9 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c break; } - case TSDB_SQL_CREATE_TABLE: { + case TSDB_SQL_CREATE_STABLE: { SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + assert(pCreateTable->type != TSQL_CREATE_CTABLE); if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { if ((code = doCheckForCreateTable(pInfo, pMsgBuf)) != TSDB_CODE_SUCCESS) { @@ -772,13 +773,6 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE) ? TDMT_VND_CREATE_TABLE : TDMT_MND_CREATE_STB; - } else if (pCreateTable->type == TSQL_CREATE_CTABLE) { - if ((code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, &pDcl->pMsg, &pDcl->msgLen)) != - TSDB_CODE_SUCCESS) { - goto _error; - } - - pDcl->msgType = TDMT_VND_CREATE_TABLE; } else if (pCreateTable->type == TSQL_CREATE_STREAM) { // if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) { // return code; diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index f7f56510da..d265031a81 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -131,16 +131,16 @@ typedef union { #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 #define YYNSTATE 366 -#define YYNRULE 303 +#define YYNRULE 302 #define YYNTOKEN 191 #define YY_MAX_SHIFT 365 -#define YY_MIN_SHIFTREDUCE 587 -#define YY_MAX_SHIFTREDUCE 889 -#define YY_ERROR_ACTION 890 -#define YY_ACCEPT_ACTION 891 -#define YY_NO_ACTION 892 -#define YY_MIN_REDUCE 893 -#define YY_MAX_REDUCE 1195 +#define YY_MIN_SHIFTREDUCE 586 +#define YY_MAX_SHIFTREDUCE 887 +#define YY_ERROR_ACTION 888 +#define YY_ACCEPT_ACTION 889 +#define YY_NO_ACTION 890 +#define YY_MIN_REDUCE 891 +#define YY_MAX_REDUCE 1192 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -206,168 +206,167 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (782) +#define YY_ACTTAB_COUNT (777) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 249, 638, 364, 230, 162, 639, 248, 55, 56, 638, - /* 10 */ 59, 60, 1031, 639, 252, 49, 48, 47, 94, 58, - /* 20 */ 323, 63, 61, 64, 62, 674, 1080, 891, 365, 54, - /* 30 */ 53, 206, 82, 52, 51, 50, 253, 55, 56, 638, - /* 40 */ 59, 60, 1171, 639, 252, 49, 48, 47, 21, 58, - /* 50 */ 323, 63, 61, 64, 62, 1017, 203, 1015, 1016, 54, - /* 60 */ 53, 206, 1018, 52, 51, 50, 1019, 206, 1020, 1021, - /* 70 */ 832, 835, 1172, 55, 56, 1070, 59, 60, 1172, 1118, - /* 80 */ 252, 49, 48, 47, 81, 58, 323, 63, 61, 64, - /* 90 */ 62, 321, 319, 274, 1077, 54, 53, 206, 638, 52, - /* 100 */ 51, 50, 639, 55, 57, 353, 59, 60, 1172, 826, - /* 110 */ 252, 49, 48, 47, 155, 58, 323, 63, 61, 64, - /* 120 */ 62, 42, 319, 359, 358, 54, 53, 162, 357, 52, - /* 130 */ 51, 50, 356, 87, 355, 354, 162, 162, 588, 589, - /* 140 */ 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, - /* 150 */ 600, 601, 153, 56, 231, 59, 60, 236, 1057, 252, - /* 160 */ 49, 48, 47, 87, 58, 323, 63, 61, 64, 62, - /* 170 */ 772, 43, 32, 86, 54, 53, 255, 204, 52, 51, - /* 180 */ 50, 309, 209, 280, 279, 59, 60, 941, 839, 252, - /* 190 */ 49, 48, 47, 188, 58, 323, 63, 61, 64, 62, - /* 200 */ 294, 43, 92, 242, 54, 53, 300, 1045, 52, 51, - /* 210 */ 50, 1119, 93, 292, 42, 317, 359, 358, 316, 315, - /* 220 */ 314, 357, 313, 312, 311, 356, 310, 355, 354, 99, - /* 230 */ 22, 1010, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, - /* 240 */ 1006, 1007, 1008, 1009, 1011, 1012, 1013, 215, 251, 841, - /* 250 */ 830, 833, 836, 256, 216, 254, 776, 331, 330, 250, - /* 260 */ 137, 136, 135, 217, 1033, 266, 719, 328, 87, 251, - /* 270 */ 841, 830, 833, 836, 270, 269, 228, 229, 831, 834, - /* 280 */ 324, 4, 63, 61, 64, 62, 755, 752, 753, 754, - /* 290 */ 54, 53, 343, 342, 52, 51, 50, 228, 229, 747, - /* 300 */ 744, 745, 746, 52, 51, 50, 43, 3, 39, 178, - /* 310 */ 152, 150, 149, 257, 258, 105, 77, 101, 108, 1039, - /* 320 */ 96, 791, 792, 260, 36, 65, 244, 245, 273, 36, - /* 330 */ 79, 197, 195, 193, 36, 305, 210, 224, 192, 141, - /* 340 */ 140, 139, 138, 36, 36, 36, 65, 122, 116, 126, - /* 350 */ 36, 211, 1028, 1029, 33, 1032, 131, 134, 125, 638, - /* 360 */ 36, 842, 837, 639, 243, 128, 36, 232, 838, 54, - /* 370 */ 53, 1042, 240, 52, 51, 50, 1042, 241, 36, 36, - /* 380 */ 36, 1042, 842, 837, 1166, 261, 332, 333, 334, 838, - /* 390 */ 1042, 1042, 1042, 335, 176, 12, 840, 1042, 756, 757, - /* 400 */ 262, 95, 259, 339, 338, 337, 171, 1042, 363, 362, - /* 410 */ 146, 748, 749, 1041, 246, 80, 808, 1070, 1045, 1070, - /* 420 */ 261, 340, 341, 345, 282, 1042, 1042, 1042, 124, 177, - /* 430 */ 98, 261, 952, 942, 769, 233, 27, 234, 188, 188, - /* 440 */ 1043, 275, 353, 360, 979, 84, 85, 788, 1030, 798, - /* 450 */ 799, 71, 74, 729, 297, 731, 299, 37, 325, 7, - /* 460 */ 742, 743, 730, 157, 828, 66, 24, 740, 741, 37, - /* 470 */ 37, 67, 97, 864, 807, 760, 761, 843, 67, 637, - /* 480 */ 14, 78, 13, 70, 70, 115, 1165, 114, 16, 23, - /* 490 */ 15, 75, 72, 23, 1111, 23, 829, 758, 759, 133, - /* 500 */ 132, 18, 121, 17, 120, 20, 1164, 19, 1129, 226, - /* 510 */ 322, 227, 207, 1056, 718, 208, 212, 205, 213, 214, - /* 520 */ 1044, 219, 1072, 220, 1191, 221, 218, 202, 1128, 1183, - /* 530 */ 238, 1125, 1124, 239, 344, 271, 154, 44, 172, 1079, - /* 540 */ 151, 1110, 1090, 1087, 1088, 1071, 277, 1092, 1040, 156, - /* 550 */ 1068, 281, 235, 283, 31, 161, 285, 165, 288, 173, - /* 560 */ 163, 168, 787, 845, 164, 276, 1038, 174, 166, 169, - /* 570 */ 167, 291, 175, 956, 302, 303, 304, 76, 307, 308, - /* 580 */ 200, 40, 320, 951, 950, 329, 1190, 112, 73, 1189, - /* 590 */ 1186, 179, 46, 336, 295, 1182, 118, 287, 1181, 1178, - /* 600 */ 180, 976, 41, 38, 201, 939, 127, 937, 129, 130, - /* 610 */ 935, 934, 263, 190, 191, 931, 930, 929, 928, 293, - /* 620 */ 927, 926, 925, 194, 196, 922, 920, 918, 916, 198, - /* 630 */ 913, 199, 909, 289, 284, 83, 88, 45, 286, 1112, - /* 640 */ 306, 123, 346, 225, 247, 347, 301, 348, 349, 351, - /* 650 */ 222, 223, 350, 352, 361, 955, 954, 106, 889, 264, - /* 660 */ 265, 888, 267, 268, 887, 870, 933, 869, 272, 183, - /* 670 */ 182, 977, 932, 181, 142, 184, 185, 187, 186, 143, - /* 680 */ 144, 924, 978, 923, 2, 70, 145, 915, 914, 296, - /* 690 */ 8, 28, 1, 763, 278, 170, 789, 89, 158, 160, - /* 700 */ 800, 159, 237, 794, 90, 29, 796, 91, 290, 9, - /* 710 */ 30, 10, 11, 25, 26, 298, 100, 34, 98, 103, - /* 720 */ 652, 102, 690, 35, 104, 687, 685, 684, 683, 681, - /* 730 */ 680, 679, 676, 642, 326, 327, 107, 111, 109, 318, - /* 740 */ 113, 110, 5, 68, 844, 846, 6, 69, 721, 37, - /* 750 */ 117, 119, 720, 717, 668, 666, 658, 664, 660, 662, - /* 760 */ 656, 654, 689, 688, 686, 682, 678, 677, 189, 640, - /* 770 */ 893, 605, 892, 892, 892, 892, 892, 892, 892, 892, - /* 780 */ 147, 148, + /* 0 */ 249, 637, 637, 1077, 83, 717, 248, 55, 56, 88, + /* 10 */ 59, 60, 364, 230, 252, 49, 48, 47, 78, 58, + /* 20 */ 323, 63, 61, 64, 62, 236, 1054, 889, 365, 54, + /* 30 */ 53, 343, 342, 52, 51, 50, 253, 55, 56, 242, + /* 40 */ 59, 60, 1027, 1042, 252, 49, 48, 47, 104, 58, + /* 50 */ 323, 63, 61, 64, 62, 1014, 637, 1012, 1013, 54, + /* 60 */ 53, 206, 1015, 52, 51, 50, 1016, 206, 1017, 1018, + /* 70 */ 121, 1074, 1169, 55, 56, 1067, 59, 60, 1169, 27, + /* 80 */ 252, 49, 48, 47, 89, 58, 323, 63, 61, 64, + /* 90 */ 62, 206, 39, 274, 246, 54, 53, 206, 1042, 52, + /* 100 */ 51, 50, 1168, 55, 57, 1030, 59, 60, 1169, 824, + /* 110 */ 252, 49, 48, 47, 80, 58, 323, 63, 61, 64, + /* 120 */ 62, 294, 637, 81, 159, 54, 53, 91, 319, 52, + /* 130 */ 51, 50, 104, 1067, 56, 232, 59, 60, 353, 1039, + /* 140 */ 252, 49, 48, 47, 261, 58, 323, 63, 61, 64, + /* 150 */ 62, 233, 43, 124, 79, 54, 53, 80, 39, 52, + /* 160 */ 51, 50, 587, 588, 589, 590, 591, 592, 593, 594, + /* 170 */ 595, 596, 597, 598, 599, 600, 199, 309, 231, 59, + /* 180 */ 60, 939, 1067, 252, 49, 48, 47, 158, 58, 323, + /* 190 */ 63, 61, 64, 62, 353, 43, 280, 279, 54, 53, + /* 200 */ 234, 240, 52, 51, 50, 1039, 14, 1116, 13, 292, + /* 210 */ 42, 317, 359, 358, 316, 315, 314, 357, 313, 312, + /* 220 */ 311, 356, 310, 355, 354, 1007, 995, 996, 997, 998, + /* 230 */ 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1008, 1009, + /* 240 */ 1010, 266, 12, 22, 63, 61, 64, 62, 84, 21, + /* 250 */ 270, 269, 54, 53, 789, 790, 52, 51, 50, 946, + /* 260 */ 215, 113, 251, 839, 828, 831, 834, 216, 753, 750, + /* 270 */ 751, 752, 672, 175, 174, 172, 217, 119, 261, 282, + /* 280 */ 328, 80, 251, 839, 828, 831, 834, 127, 116, 203, + /* 290 */ 228, 229, 255, 39, 324, 257, 258, 745, 742, 743, + /* 300 */ 744, 204, 39, 1036, 3, 32, 131, 261, 209, 260, + /* 310 */ 228, 229, 129, 85, 123, 133, 1040, 39, 39, 43, + /* 320 */ 1025, 1026, 30, 1029, 244, 245, 189, 186, 183, 52, + /* 330 */ 51, 50, 305, 181, 179, 178, 177, 176, 319, 65, + /* 340 */ 1038, 273, 637, 86, 42, 241, 359, 358, 243, 1039, + /* 350 */ 224, 357, 770, 830, 833, 356, 39, 355, 354, 65, + /* 360 */ 332, 333, 54, 53, 1039, 1039, 52, 51, 50, 256, + /* 370 */ 39, 254, 39, 331, 330, 840, 835, 104, 39, 39, + /* 380 */ 754, 755, 836, 149, 142, 162, 262, 39, 259, 806, + /* 390 */ 338, 337, 167, 170, 160, 840, 835, 829, 832, 334, + /* 400 */ 104, 164, 836, 1039, 826, 363, 362, 190, 767, 746, + /* 410 */ 747, 92, 949, 335, 940, 339, 93, 1039, 158, 1039, + /* 420 */ 158, 340, 341, 71, 321, 1039, 1039, 198, 195, 193, + /* 430 */ 345, 360, 976, 7, 1039, 275, 827, 786, 774, 796, + /* 440 */ 797, 74, 727, 297, 729, 299, 325, 805, 35, 70, + /* 450 */ 210, 40, 1115, 97, 70, 66, 24, 728, 40, 40, + /* 460 */ 67, 117, 740, 741, 72, 738, 739, 862, 841, 250, + /* 470 */ 636, 837, 140, 67, 139, 82, 16, 18, 15, 17, + /* 480 */ 75, 211, 300, 23, 23, 77, 23, 758, 759, 169, + /* 490 */ 168, 4, 756, 757, 147, 20, 146, 19, 1163, 1162, + /* 500 */ 1161, 226, 227, 207, 208, 212, 1053, 1041, 205, 1126, + /* 510 */ 213, 214, 219, 220, 221, 838, 218, 202, 716, 1188, + /* 520 */ 1180, 1125, 1069, 238, 1122, 1121, 239, 44, 1068, 344, + /* 530 */ 277, 114, 322, 1108, 1107, 196, 271, 785, 1037, 276, + /* 540 */ 1065, 87, 1076, 1087, 281, 235, 73, 90, 1084, 1085, + /* 550 */ 76, 843, 283, 1089, 295, 46, 105, 106, 94, 107, + /* 560 */ 293, 95, 101, 108, 285, 291, 288, 286, 109, 1109, + /* 570 */ 289, 110, 287, 111, 284, 112, 29, 45, 225, 115, + /* 580 */ 1035, 306, 150, 247, 118, 952, 346, 120, 301, 953, + /* 590 */ 302, 303, 304, 974, 307, 308, 200, 347, 348, 38, + /* 600 */ 320, 349, 948, 951, 947, 130, 329, 350, 1187, 351, + /* 610 */ 352, 361, 137, 1186, 1183, 887, 141, 222, 336, 1179, + /* 620 */ 152, 144, 1178, 265, 1175, 886, 148, 223, 973, 268, + /* 630 */ 885, 868, 867, 70, 296, 8, 28, 41, 31, 761, + /* 640 */ 278, 96, 153, 201, 937, 151, 154, 156, 157, 155, + /* 650 */ 163, 935, 165, 1, 166, 933, 264, 932, 263, 171, + /* 660 */ 267, 975, 931, 930, 173, 929, 928, 927, 926, 925, + /* 670 */ 924, 272, 923, 787, 180, 184, 98, 182, 922, 798, + /* 680 */ 185, 921, 99, 188, 187, 920, 918, 792, 100, 916, + /* 690 */ 914, 102, 194, 913, 911, 912, 197, 907, 794, 2, + /* 700 */ 237, 103, 290, 9, 33, 34, 10, 11, 25, 298, + /* 710 */ 26, 122, 119, 36, 126, 125, 650, 688, 37, 128, + /* 720 */ 685, 683, 682, 681, 679, 678, 677, 674, 640, 132, + /* 730 */ 5, 134, 135, 842, 318, 844, 6, 326, 327, 68, + /* 740 */ 136, 40, 69, 719, 718, 138, 143, 145, 715, 666, + /* 750 */ 664, 656, 662, 658, 660, 654, 652, 687, 686, 684, + /* 760 */ 680, 676, 675, 161, 604, 638, 891, 890, 890, 890, + /* 770 */ 890, 890, 890, 890, 890, 191, 192, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 200, 1, 194, 195, 194, 5, 200, 7, 8, 1, - /* 10 */ 10, 11, 0, 5, 14, 15, 16, 17, 245, 19, - /* 20 */ 20, 21, 22, 23, 24, 3, 194, 192, 193, 29, - /* 30 */ 30, 261, 259, 33, 34, 35, 200, 7, 8, 1, - /* 40 */ 10, 11, 272, 5, 14, 15, 16, 17, 261, 19, - /* 50 */ 20, 21, 22, 23, 24, 216, 261, 218, 219, 29, + /* 0 */ 200, 1, 1, 194, 245, 3, 200, 7, 8, 201, + /* 10 */ 10, 11, 194, 195, 14, 15, 16, 17, 259, 19, + /* 20 */ 20, 21, 22, 23, 24, 243, 244, 192, 193, 29, + /* 30 */ 30, 29, 30, 33, 34, 35, 200, 7, 8, 238, + /* 40 */ 10, 11, 234, 242, 14, 15, 16, 17, 194, 19, + /* 50 */ 20, 21, 22, 23, 24, 216, 1, 218, 219, 29, /* 60 */ 30, 261, 223, 33, 34, 35, 227, 261, 229, 230, - /* 70 */ 3, 4, 272, 7, 8, 240, 10, 11, 272, 269, + /* 70 */ 201, 262, 272, 7, 8, 240, 10, 11, 272, 78, /* 80 */ 14, 15, 16, 17, 84, 19, 20, 21, 22, 23, - /* 90 */ 24, 83, 80, 258, 262, 29, 30, 261, 1, 33, - /* 100 */ 34, 35, 5, 7, 8, 88, 10, 11, 272, 79, - /* 110 */ 14, 15, 16, 17, 194, 19, 20, 21, 22, 23, - /* 120 */ 24, 96, 80, 98, 99, 29, 30, 194, 103, 33, - /* 130 */ 34, 35, 107, 78, 109, 110, 194, 194, 41, 42, - /* 140 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, - /* 150 */ 53, 54, 55, 8, 57, 10, 11, 243, 244, 14, - /* 160 */ 15, 16, 17, 78, 19, 20, 21, 22, 23, 24, - /* 170 */ 33, 116, 78, 118, 29, 30, 64, 261, 33, 34, - /* 180 */ 35, 63, 261, 263, 264, 10, 11, 199, 121, 14, - /* 190 */ 15, 16, 17, 205, 19, 20, 21, 22, 23, 24, - /* 200 */ 267, 116, 269, 238, 29, 30, 112, 242, 33, 34, - /* 210 */ 35, 269, 269, 271, 96, 97, 98, 99, 100, 101, - /* 220 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 201, - /* 230 */ 40, 216, 217, 218, 219, 220, 221, 222, 223, 224, - /* 240 */ 225, 226, 227, 228, 229, 230, 231, 57, 1, 2, - /* 250 */ 3, 4, 5, 141, 64, 143, 119, 145, 146, 56, - /* 260 */ 70, 71, 72, 73, 236, 139, 3, 77, 78, 1, - /* 270 */ 2, 3, 4, 5, 148, 149, 29, 30, 3, 4, - /* 280 */ 33, 78, 21, 22, 23, 24, 2, 3, 4, 5, - /* 290 */ 29, 30, 29, 30, 33, 34, 35, 29, 30, 2, - /* 300 */ 3, 4, 5, 33, 34, 35, 116, 58, 59, 60, - /* 310 */ 58, 59, 60, 29, 30, 66, 67, 68, 69, 194, - /* 320 */ 201, 122, 123, 64, 194, 78, 29, 30, 138, 194, - /* 330 */ 140, 58, 59, 60, 194, 86, 261, 147, 65, 66, - /* 340 */ 67, 68, 69, 194, 194, 194, 78, 58, 59, 60, - /* 350 */ 194, 261, 233, 234, 235, 236, 67, 68, 69, 1, - /* 360 */ 194, 114, 115, 5, 239, 76, 194, 237, 121, 29, - /* 370 */ 30, 241, 237, 33, 34, 35, 241, 237, 194, 194, - /* 380 */ 194, 241, 114, 115, 261, 194, 237, 237, 237, 121, - /* 390 */ 241, 241, 241, 237, 203, 78, 121, 241, 114, 115, - /* 400 */ 141, 84, 143, 237, 145, 146, 248, 241, 61, 62, - /* 410 */ 63, 114, 115, 241, 238, 201, 72, 240, 242, 240, - /* 420 */ 194, 237, 237, 237, 266, 241, 241, 241, 74, 203, - /* 430 */ 113, 194, 199, 199, 95, 258, 78, 258, 205, 205, - /* 440 */ 203, 79, 88, 214, 215, 79, 79, 79, 234, 79, - /* 450 */ 79, 95, 95, 79, 79, 79, 79, 95, 9, 120, - /* 460 */ 3, 4, 79, 95, 1, 95, 95, 3, 4, 95, - /* 470 */ 95, 95, 95, 79, 130, 3, 4, 79, 95, 79, - /* 480 */ 142, 78, 144, 117, 117, 142, 261, 144, 142, 95, - /* 490 */ 144, 134, 136, 95, 270, 95, 33, 3, 4, 74, - /* 500 */ 75, 142, 142, 144, 144, 142, 261, 144, 232, 261, - /* 510 */ 194, 261, 261, 244, 111, 261, 261, 261, 261, 261, - /* 520 */ 242, 261, 240, 261, 244, 261, 261, 261, 232, 244, - /* 530 */ 232, 232, 232, 232, 232, 194, 194, 260, 246, 194, - /* 540 */ 56, 270, 194, 194, 194, 240, 240, 194, 240, 194, - /* 550 */ 257, 265, 265, 265, 247, 194, 265, 254, 194, 194, - /* 560 */ 256, 251, 121, 114, 255, 196, 194, 194, 253, 250, - /* 570 */ 252, 126, 194, 194, 194, 194, 194, 133, 194, 194, - /* 580 */ 194, 194, 194, 194, 194, 194, 194, 194, 135, 194, - /* 590 */ 194, 194, 132, 194, 128, 194, 194, 124, 194, 194, - /* 600 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 610 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 131, - /* 620 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 630 */ 194, 194, 194, 125, 127, 196, 196, 137, 196, 196, - /* 640 */ 87, 94, 93, 196, 196, 47, 196, 90, 92, 91, - /* 650 */ 196, 196, 51, 89, 80, 204, 204, 201, 3, 150, - /* 660 */ 3, 3, 150, 3, 3, 98, 196, 97, 139, 207, - /* 670 */ 211, 213, 196, 212, 197, 210, 208, 206, 209, 197, - /* 680 */ 197, 196, 215, 196, 198, 117, 197, 196, 196, 112, - /* 690 */ 78, 78, 202, 79, 95, 249, 79, 95, 78, 95, - /* 700 */ 79, 78, 1, 79, 78, 95, 79, 78, 78, 129, - /* 710 */ 95, 129, 78, 78, 78, 112, 74, 85, 113, 66, - /* 720 */ 3, 84, 3, 85, 84, 5, 3, 3, 3, 3, - /* 730 */ 3, 3, 3, 81, 20, 55, 74, 144, 82, 9, - /* 740 */ 144, 82, 78, 10, 79, 114, 78, 10, 3, 95, - /* 750 */ 144, 144, 3, 79, 3, 3, 3, 3, 3, 3, - /* 760 */ 3, 3, 3, 3, 3, 3, 3, 3, 95, 81, - /* 770 */ 0, 56, 273, 273, 273, 273, 273, 273, 273, 273, - /* 780 */ 15, 15, 273, 273, 273, 273, 273, 273, 273, 273, + /* 90 */ 24, 261, 194, 258, 238, 29, 30, 261, 242, 33, + /* 100 */ 34, 35, 272, 7, 8, 236, 10, 11, 272, 79, + /* 110 */ 14, 15, 16, 17, 78, 19, 20, 21, 22, 23, + /* 120 */ 24, 267, 1, 269, 74, 29, 30, 194, 80, 33, + /* 130 */ 34, 35, 194, 240, 8, 237, 10, 11, 88, 241, + /* 140 */ 14, 15, 16, 17, 194, 19, 20, 21, 22, 23, + /* 150 */ 24, 258, 116, 203, 118, 29, 30, 78, 194, 33, + /* 160 */ 34, 35, 41, 42, 43, 44, 45, 46, 47, 48, + /* 170 */ 49, 50, 51, 52, 53, 54, 55, 63, 57, 10, + /* 180 */ 11, 199, 240, 14, 15, 16, 17, 205, 19, 20, + /* 190 */ 21, 22, 23, 24, 88, 116, 263, 264, 29, 30, + /* 200 */ 258, 237, 33, 34, 35, 241, 142, 269, 144, 271, + /* 210 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + /* 220 */ 106, 107, 108, 109, 110, 216, 217, 218, 219, 220, + /* 230 */ 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + /* 240 */ 231, 139, 78, 40, 21, 22, 23, 24, 84, 261, + /* 250 */ 148, 149, 29, 30, 122, 123, 33, 34, 35, 1, + /* 260 */ 57, 248, 1, 2, 3, 4, 5, 64, 2, 3, + /* 270 */ 4, 5, 3, 70, 71, 72, 73, 113, 194, 266, + /* 280 */ 77, 78, 1, 2, 3, 4, 5, 203, 201, 261, + /* 290 */ 29, 30, 64, 194, 33, 29, 30, 2, 3, 4, + /* 300 */ 5, 261, 194, 194, 58, 59, 60, 194, 261, 64, + /* 310 */ 29, 30, 66, 67, 68, 69, 203, 194, 194, 116, + /* 320 */ 233, 234, 235, 236, 29, 30, 58, 59, 60, 33, + /* 330 */ 34, 35, 86, 65, 66, 67, 68, 69, 80, 78, + /* 340 */ 241, 138, 1, 140, 96, 237, 98, 99, 239, 241, + /* 350 */ 147, 103, 33, 3, 4, 107, 194, 109, 110, 78, + /* 360 */ 237, 237, 29, 30, 241, 241, 33, 34, 35, 141, + /* 370 */ 194, 143, 194, 145, 146, 114, 115, 194, 194, 194, + /* 380 */ 114, 115, 121, 58, 59, 60, 141, 194, 143, 72, + /* 390 */ 145, 146, 67, 68, 69, 114, 115, 3, 4, 237, + /* 400 */ 194, 76, 121, 241, 1, 61, 62, 63, 95, 114, + /* 410 */ 115, 79, 199, 237, 199, 237, 79, 241, 205, 241, + /* 420 */ 205, 237, 237, 95, 83, 241, 241, 58, 59, 60, + /* 430 */ 237, 214, 215, 120, 241, 79, 33, 79, 119, 79, + /* 440 */ 79, 95, 79, 79, 79, 79, 9, 130, 78, 117, + /* 450 */ 261, 95, 269, 95, 117, 95, 95, 79, 95, 95, + /* 460 */ 95, 95, 3, 4, 136, 3, 4, 79, 79, 56, + /* 470 */ 79, 121, 142, 95, 144, 269, 142, 142, 144, 144, + /* 480 */ 134, 261, 112, 95, 95, 78, 95, 3, 4, 74, + /* 490 */ 75, 78, 3, 4, 142, 142, 144, 144, 261, 261, + /* 500 */ 261, 261, 261, 261, 261, 261, 244, 242, 261, 232, + /* 510 */ 261, 261, 261, 261, 261, 121, 261, 261, 111, 244, + /* 520 */ 244, 232, 240, 232, 232, 232, 232, 260, 240, 232, + /* 530 */ 240, 246, 194, 270, 270, 56, 194, 121, 240, 196, + /* 540 */ 257, 194, 194, 194, 265, 265, 135, 196, 194, 194, + /* 550 */ 133, 114, 265, 194, 128, 132, 256, 255, 196, 254, + /* 560 */ 131, 194, 194, 253, 265, 126, 194, 196, 252, 196, + /* 570 */ 125, 251, 124, 250, 127, 249, 247, 137, 196, 194, + /* 580 */ 194, 87, 94, 196, 194, 204, 93, 194, 196, 194, + /* 590 */ 194, 194, 194, 213, 194, 194, 194, 47, 90, 194, + /* 600 */ 194, 92, 194, 204, 194, 201, 194, 51, 194, 91, + /* 610 */ 89, 80, 194, 194, 194, 3, 194, 196, 194, 194, + /* 620 */ 211, 194, 194, 3, 194, 3, 194, 196, 194, 3, + /* 630 */ 3, 98, 97, 117, 112, 78, 78, 194, 194, 79, + /* 640 */ 95, 95, 207, 194, 194, 212, 210, 209, 206, 208, + /* 650 */ 194, 194, 194, 202, 194, 194, 150, 194, 194, 194, + /* 660 */ 150, 215, 196, 196, 194, 194, 194, 194, 194, 194, + /* 670 */ 194, 139, 194, 79, 197, 194, 78, 197, 196, 79, + /* 680 */ 197, 196, 78, 197, 194, 194, 194, 79, 95, 194, + /* 690 */ 194, 78, 194, 196, 194, 196, 194, 194, 79, 198, + /* 700 */ 1, 78, 78, 129, 95, 95, 129, 78, 78, 112, + /* 710 */ 78, 74, 113, 85, 66, 84, 3, 3, 85, 84, + /* 720 */ 5, 3, 3, 3, 3, 3, 3, 3, 81, 74, + /* 730 */ 78, 82, 82, 79, 9, 114, 78, 20, 55, 10, + /* 740 */ 144, 95, 10, 3, 3, 144, 144, 144, 79, 3, + /* 750 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 760 */ 3, 3, 3, 95, 56, 81, 0, 273, 273, 273, + /* 770 */ 273, 273, 273, 273, 273, 15, 15, 273, 273, 273, + /* 780 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 790 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 800 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 810 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, @@ -385,115 +384,114 @@ static const YYCODETYPE yy_lookahead[] = { /* 930 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 940 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 950 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, - /* 960 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, - /* 970 */ 273, 273, 273, + /* 960 */ 273, 273, 273, 273, 273, 273, 273, 273, }; #define YY_SHIFT_COUNT (365) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (770) +#define YY_SHIFT_MAX (766) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 190, 118, 25, 42, 247, 268, 268, 358, 38, 38, - /* 10 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 20 */ 38, 0, 97, 268, 284, 297, 297, 85, 85, 38, - /* 30 */ 38, 199, 38, 12, 38, 38, 38, 38, 354, 42, - /* 40 */ 17, 17, 22, 782, 268, 268, 268, 268, 268, 268, - /* 50 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 60 */ 268, 268, 268, 268, 268, 268, 284, 297, 284, 284, - /* 70 */ 55, 263, 263, 263, 263, 263, 263, 8, 263, 38, - /* 80 */ 38, 38, 137, 38, 38, 38, 85, 85, 38, 38, - /* 90 */ 38, 38, 344, 344, 339, 85, 38, 38, 38, 38, - /* 100 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 110 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 120 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 130 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 140 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 150 */ 38, 38, 38, 38, 484, 484, 484, 441, 441, 441, - /* 160 */ 441, 484, 484, 444, 453, 466, 460, 488, 445, 508, - /* 170 */ 473, 507, 500, 484, 484, 484, 553, 553, 42, 484, - /* 180 */ 484, 547, 549, 598, 557, 556, 601, 558, 564, 22, - /* 190 */ 484, 484, 574, 574, 484, 574, 484, 574, 484, 484, - /* 200 */ 782, 782, 30, 66, 66, 96, 66, 145, 175, 261, - /* 210 */ 261, 261, 261, 261, 261, 249, 273, 289, 340, 340, - /* 220 */ 340, 340, 112, 259, 126, 317, 270, 270, 67, 275, - /* 230 */ 347, 252, 362, 366, 367, 368, 370, 371, 356, 357, - /* 240 */ 374, 375, 376, 377, 457, 464, 383, 94, 394, 398, - /* 250 */ 463, 203, 449, 400, 338, 343, 346, 472, 494, 359, - /* 260 */ 360, 403, 363, 425, 655, 509, 657, 658, 512, 660, - /* 270 */ 661, 567, 570, 529, 568, 577, 612, 614, 613, 599, - /* 280 */ 602, 617, 620, 621, 623, 624, 604, 626, 627, 629, - /* 290 */ 701, 630, 610, 580, 615, 582, 634, 577, 635, 603, - /* 300 */ 636, 605, 642, 632, 637, 653, 717, 638, 640, 719, - /* 310 */ 720, 723, 724, 725, 726, 727, 728, 729, 652, 730, - /* 320 */ 662, 656, 659, 664, 665, 631, 668, 714, 680, 733, - /* 330 */ 593, 596, 654, 654, 654, 654, 737, 606, 607, 654, - /* 340 */ 654, 654, 745, 749, 674, 654, 751, 752, 753, 754, - /* 350 */ 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, - /* 360 */ 673, 688, 765, 766, 715, 770, + /* 0 */ 203, 114, 248, 48, 261, 281, 281, 1, 55, 55, + /* 10 */ 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + /* 20 */ 55, 0, 121, 281, 266, 295, 295, 79, 79, 132, + /* 30 */ 258, 50, 48, 55, 55, 55, 55, 55, 106, 55, + /* 40 */ 55, 106, 269, 777, 281, 281, 281, 281, 281, 281, + /* 50 */ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, + /* 60 */ 281, 281, 281, 281, 281, 281, 266, 295, 266, 266, + /* 70 */ 36, 2, 2, 2, 2, 2, 2, 2, 319, 79, + /* 80 */ 79, 317, 317, 313, 79, 341, 55, 479, 55, 55, + /* 90 */ 55, 479, 55, 55, 55, 479, 55, 416, 416, 416, + /* 100 */ 416, 479, 55, 55, 479, 417, 411, 426, 423, 429, + /* 110 */ 439, 445, 448, 447, 440, 479, 55, 55, 479, 55, + /* 120 */ 479, 55, 55, 55, 494, 55, 55, 494, 55, 55, + /* 130 */ 55, 48, 55, 55, 55, 55, 55, 55, 55, 55, + /* 140 */ 55, 479, 55, 55, 55, 55, 55, 55, 479, 55, + /* 150 */ 55, 488, 493, 550, 508, 509, 556, 518, 521, 55, + /* 160 */ 55, 269, 55, 55, 55, 55, 55, 55, 55, 55, + /* 170 */ 55, 479, 55, 479, 55, 55, 55, 55, 55, 55, + /* 180 */ 55, 531, 55, 531, 479, 55, 531, 479, 55, 531, + /* 190 */ 55, 55, 55, 55, 479, 55, 55, 479, 55, 55, + /* 200 */ 777, 777, 30, 66, 66, 96, 66, 126, 169, 223, + /* 210 */ 223, 223, 223, 223, 223, 246, 268, 325, 333, 333, + /* 220 */ 333, 333, 228, 245, 102, 164, 296, 296, 350, 394, + /* 230 */ 344, 369, 356, 332, 337, 358, 360, 361, 328, 346, + /* 240 */ 363, 364, 365, 366, 459, 462, 378, 370, 388, 389, + /* 250 */ 403, 413, 437, 391, 64, 330, 334, 484, 489, 335, + /* 260 */ 352, 407, 353, 415, 612, 506, 620, 622, 510, 626, + /* 270 */ 627, 533, 535, 532, 516, 522, 557, 560, 558, 545, + /* 280 */ 546, 594, 598, 600, 604, 608, 593, 613, 619, 623, + /* 290 */ 699, 624, 609, 574, 610, 577, 629, 522, 630, 597, + /* 300 */ 632, 599, 637, 628, 631, 648, 713, 633, 635, 714, + /* 310 */ 715, 718, 719, 720, 721, 722, 723, 724, 647, 725, + /* 320 */ 655, 649, 650, 652, 654, 621, 658, 717, 683, 729, + /* 330 */ 596, 601, 646, 646, 646, 646, 732, 602, 603, 646, + /* 340 */ 646, 646, 740, 741, 669, 646, 746, 747, 748, 749, + /* 350 */ 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, + /* 360 */ 668, 684, 760, 761, 708, 766, }; #define YY_REDUCE_COUNT (201) -#define YY_REDUCE_MIN (-230) -#define YY_REDUCE_MAX (492) +#define YY_REDUCE_MIN (-241) +#define YY_REDUCE_MAX (503) static const short yy_reduce_ofst[] = { - /* 0 */ -165, 15, -161, 119, -200, -194, -164, -80, 130, -58, - /* 10 */ -67, 135, 140, 149, 150, 151, 156, 166, 184, 185, - /* 20 */ 186, -168, -192, -230, -86, -35, 176, 177, 179, -190, - /* 30 */ -57, 158, 125, 28, 191, 226, 237, 172, -12, 214, - /* 40 */ 233, 234, 229, -227, -213, -205, -84, -79, 75, 90, - /* 50 */ 123, 225, 245, 248, 250, 251, 254, 255, 256, 257, - /* 60 */ 258, 260, 262, 264, 265, 266, 269, 278, 280, 285, - /* 70 */ 282, 276, 296, 298, 299, 300, 301, 316, 302, 341, - /* 80 */ 342, 345, 277, 348, 349, 350, 305, 306, 353, 355, - /* 90 */ 361, 364, 224, 271, 292, 308, 365, 372, 373, 378, - /* 100 */ 379, 380, 381, 382, 384, 385, 386, 387, 388, 389, - /* 110 */ 390, 391, 392, 393, 395, 396, 397, 399, 401, 402, - /* 120 */ 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - /* 130 */ 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - /* 140 */ 424, 426, 427, 428, 429, 430, 431, 432, 433, 434, - /* 150 */ 435, 436, 437, 438, 369, 439, 440, 286, 287, 288, - /* 160 */ 291, 442, 443, 293, 304, 309, 303, 315, 318, 310, - /* 170 */ 319, 446, 307, 447, 448, 450, 451, 452, 456, 454, - /* 180 */ 455, 458, 461, 459, 462, 465, 468, 469, 471, 467, - /* 190 */ 470, 476, 477, 482, 485, 483, 487, 489, 491, 492, - /* 200 */ 490, 486, + /* 0 */ -165, 9, -161, 87, -200, -194, -164, -67, -102, -62, + /* 10 */ -146, -36, 108, 123, 124, 162, 176, 178, 184, 185, + /* 20 */ 193, -191, -182, -170, -218, -199, -144, -107, -58, 13, + /* 30 */ -131, -18, -192, 183, 206, 109, -50, 84, 213, 113, + /* 40 */ 99, 215, 217, -241, -12, 28, 40, 47, 189, 220, + /* 50 */ 237, 238, 239, 240, 241, 242, 243, 244, 247, 249, + /* 60 */ 250, 251, 252, 253, 255, 256, 262, 265, 275, 276, + /* 70 */ 282, 277, 289, 291, 292, 293, 294, 297, 267, 288, + /* 80 */ 290, 263, 264, 285, 298, 338, 342, 343, 347, 348, + /* 90 */ 349, 351, 354, 355, 359, 362, 367, 279, 280, 287, + /* 100 */ 299, 371, 368, 372, 373, 283, 300, 302, 305, 310, + /* 110 */ 316, 320, 323, 326, 329, 382, 385, 386, 387, 390, + /* 120 */ 392, 393, 395, 396, 381, 397, 398, 399, 400, 401, + /* 130 */ 402, 404, 405, 406, 408, 410, 412, 414, 418, 419, + /* 140 */ 420, 421, 422, 424, 425, 427, 428, 430, 431, 432, + /* 150 */ 434, 380, 433, 409, 435, 436, 441, 438, 442, 443, + /* 160 */ 444, 446, 449, 450, 456, 457, 458, 460, 461, 463, + /* 170 */ 464, 466, 465, 467, 470, 471, 472, 473, 474, 475, + /* 180 */ 476, 477, 478, 480, 482, 481, 483, 485, 490, 486, + /* 190 */ 491, 492, 495, 496, 497, 498, 500, 499, 502, 503, + /* 200 */ 451, 501, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 890, 953, 940, 949, 1174, 1174, 1174, 890, 890, 890, - /* 10 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 20 */ 890, 1081, 910, 1174, 890, 890, 890, 890, 890, 890, - /* 30 */ 890, 1096, 890, 949, 890, 890, 890, 890, 959, 949, - /* 40 */ 959, 959, 890, 1076, 890, 890, 890, 890, 890, 890, - /* 50 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 60 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 70 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 80 */ 890, 890, 1083, 1089, 1086, 890, 890, 890, 1091, 890, - /* 90 */ 890, 890, 1115, 1115, 1074, 890, 890, 890, 890, 890, - /* 100 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 110 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 120 */ 890, 890, 890, 890, 890, 890, 890, 938, 890, 936, - /* 130 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 140 */ 890, 890, 890, 890, 890, 890, 921, 890, 890, 890, - /* 150 */ 890, 890, 890, 908, 912, 912, 912, 890, 890, 890, - /* 160 */ 890, 912, 912, 1122, 1126, 1108, 1120, 1116, 1103, 1101, - /* 170 */ 1099, 1107, 1130, 912, 912, 912, 957, 957, 949, 912, - /* 180 */ 912, 975, 973, 971, 963, 969, 965, 967, 961, 890, - /* 190 */ 912, 912, 947, 947, 912, 947, 912, 947, 912, 912, - /* 200 */ 997, 1014, 890, 1131, 1121, 890, 1173, 1161, 1160, 1169, - /* 210 */ 1168, 1167, 1159, 1158, 1157, 890, 890, 890, 1153, 1156, - /* 220 */ 1155, 1154, 890, 890, 890, 890, 1163, 1162, 890, 890, - /* 230 */ 890, 890, 890, 890, 890, 890, 890, 890, 1127, 1123, - /* 240 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 250 */ 890, 1133, 890, 890, 890, 890, 890, 890, 890, 890, - /* 260 */ 890, 1022, 890, 890, 890, 890, 890, 890, 890, 890, - /* 270 */ 890, 890, 890, 890, 1073, 890, 890, 890, 890, 1085, - /* 280 */ 1084, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 290 */ 890, 890, 1117, 890, 1109, 890, 890, 1034, 890, 890, - /* 300 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 310 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 320 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 330 */ 890, 890, 1192, 1187, 1188, 1185, 890, 890, 890, 1184, - /* 340 */ 1179, 1180, 890, 890, 890, 1177, 890, 890, 890, 890, - /* 350 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 360 */ 981, 890, 919, 917, 890, 890, + /* 0 */ 888, 950, 938, 946, 1171, 1171, 1171, 888, 888, 888, + /* 10 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 20 */ 888, 1078, 908, 1171, 888, 888, 888, 888, 888, 1093, + /* 30 */ 1028, 956, 946, 888, 888, 888, 888, 888, 956, 888, + /* 40 */ 888, 956, 888, 1073, 888, 888, 888, 888, 888, 888, + /* 50 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 60 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 70 */ 888, 888, 888, 888, 888, 888, 888, 888, 1080, 888, + /* 80 */ 888, 1112, 1112, 1071, 888, 888, 888, 910, 888, 888, + /* 90 */ 1086, 910, 1083, 888, 1088, 910, 888, 888, 888, 888, + /* 100 */ 888, 910, 888, 888, 910, 1119, 1123, 1105, 1117, 1113, + /* 110 */ 1100, 1098, 1096, 1104, 1127, 910, 888, 888, 910, 888, + /* 120 */ 910, 888, 888, 888, 954, 888, 888, 954, 888, 888, + /* 130 */ 888, 946, 888, 888, 888, 888, 888, 888, 888, 888, + /* 140 */ 888, 910, 888, 888, 888, 888, 888, 888, 910, 888, + /* 150 */ 888, 972, 970, 968, 960, 966, 962, 964, 958, 888, + /* 160 */ 888, 888, 888, 936, 888, 934, 888, 888, 888, 888, + /* 170 */ 888, 910, 888, 910, 888, 888, 888, 888, 888, 888, + /* 180 */ 888, 944, 888, 944, 910, 888, 944, 910, 888, 944, + /* 190 */ 919, 888, 888, 888, 910, 888, 888, 910, 888, 906, + /* 200 */ 994, 1011, 888, 1128, 1118, 888, 1170, 1158, 1157, 1166, + /* 210 */ 1165, 1164, 1156, 1155, 1154, 888, 888, 888, 1150, 1153, + /* 220 */ 1152, 1151, 888, 888, 888, 888, 1160, 1159, 888, 888, + /* 230 */ 888, 888, 888, 888, 888, 888, 888, 888, 1124, 1120, + /* 240 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 250 */ 888, 1130, 888, 888, 888, 888, 888, 888, 888, 888, + /* 260 */ 888, 1019, 888, 888, 888, 888, 888, 888, 888, 888, + /* 270 */ 888, 888, 888, 888, 1070, 888, 888, 888, 888, 1082, + /* 280 */ 1081, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 290 */ 888, 888, 1114, 888, 1106, 888, 888, 1031, 888, 888, + /* 300 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 310 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 320 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 330 */ 888, 888, 1189, 1184, 1185, 1182, 888, 888, 888, 1181, + /* 340 */ 1176, 1177, 888, 888, 888, 1174, 888, 888, 888, 888, + /* 350 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 360 */ 978, 888, 917, 915, 888, 888, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1122,257 +1120,256 @@ static const char *const yyRuleName[] = { /* 49 */ "cmd ::= ALTER ACCOUNT ids PASS ids acct_optr", /* 50 */ "cmd ::= COMPACT VNODES IN LP exprlist RP", /* 51 */ "ids ::= ID", - /* 52 */ "ids ::= STRING", - /* 53 */ "ifexists ::= IF EXISTS", - /* 54 */ "ifexists ::=", - /* 55 */ "ifnotexists ::= IF NOT EXISTS", - /* 56 */ "ifnotexists ::=", - /* 57 */ "cmd ::= CREATE DNODE ids PORT ids", - /* 58 */ "cmd ::= CREATE DNODE IPTOKEN PORT ids", - /* 59 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", - /* 60 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", - /* 61 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 62 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 63 */ "cmd ::= CREATE USER ids PASS ids", - /* 64 */ "bufsize ::=", - /* 65 */ "bufsize ::= BUFSIZE INTEGER", - /* 66 */ "pps ::=", - /* 67 */ "pps ::= PPS INTEGER", - /* 68 */ "tseries ::=", - /* 69 */ "tseries ::= TSERIES INTEGER", - /* 70 */ "dbs ::=", - /* 71 */ "dbs ::= DBS INTEGER", - /* 72 */ "streams ::=", - /* 73 */ "streams ::= STREAMS INTEGER", - /* 74 */ "storage ::=", - /* 75 */ "storage ::= STORAGE INTEGER", - /* 76 */ "qtime ::=", - /* 77 */ "qtime ::= QTIME INTEGER", - /* 78 */ "users ::=", - /* 79 */ "users ::= USERS INTEGER", - /* 80 */ "conns ::=", - /* 81 */ "conns ::= CONNS INTEGER", - /* 82 */ "state ::=", - /* 83 */ "state ::= STATE ids", - /* 84 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", - /* 85 */ "intitemlist ::= intitemlist COMMA intitem", - /* 86 */ "intitemlist ::= intitem", - /* 87 */ "intitem ::= INTEGER", - /* 88 */ "keep ::= KEEP intitemlist", - /* 89 */ "cache ::= CACHE INTEGER", - /* 90 */ "replica ::= REPLICA INTEGER", - /* 91 */ "quorum ::= QUORUM INTEGER", - /* 92 */ "days ::= DAYS INTEGER", - /* 93 */ "minrows ::= MINROWS INTEGER", - /* 94 */ "maxrows ::= MAXROWS INTEGER", - /* 95 */ "blocks ::= BLOCKS INTEGER", - /* 96 */ "ctime ::= CTIME INTEGER", - /* 97 */ "wal ::= WAL INTEGER", - /* 98 */ "fsync ::= FSYNC INTEGER", - /* 99 */ "comp ::= COMP INTEGER", - /* 100 */ "prec ::= PRECISION STRING", - /* 101 */ "update ::= UPDATE INTEGER", - /* 102 */ "cachelast ::= CACHELAST INTEGER", - /* 103 */ "vgroups ::= VGROUPS INTEGER", - /* 104 */ "db_optr ::=", - /* 105 */ "db_optr ::= db_optr cache", - /* 106 */ "db_optr ::= db_optr replica", - /* 107 */ "db_optr ::= db_optr quorum", - /* 108 */ "db_optr ::= db_optr days", - /* 109 */ "db_optr ::= db_optr minrows", - /* 110 */ "db_optr ::= db_optr maxrows", - /* 111 */ "db_optr ::= db_optr blocks", - /* 112 */ "db_optr ::= db_optr ctime", - /* 113 */ "db_optr ::= db_optr wal", - /* 114 */ "db_optr ::= db_optr fsync", - /* 115 */ "db_optr ::= db_optr comp", - /* 116 */ "db_optr ::= db_optr prec", - /* 117 */ "db_optr ::= db_optr keep", - /* 118 */ "db_optr ::= db_optr update", - /* 119 */ "db_optr ::= db_optr cachelast", - /* 120 */ "db_optr ::= db_optr vgroups", - /* 121 */ "alter_db_optr ::=", - /* 122 */ "alter_db_optr ::= alter_db_optr replica", - /* 123 */ "alter_db_optr ::= alter_db_optr quorum", - /* 124 */ "alter_db_optr ::= alter_db_optr keep", - /* 125 */ "alter_db_optr ::= alter_db_optr blocks", - /* 126 */ "alter_db_optr ::= alter_db_optr comp", - /* 127 */ "alter_db_optr ::= alter_db_optr update", - /* 128 */ "alter_db_optr ::= alter_db_optr cachelast", - /* 129 */ "typename ::= ids", - /* 130 */ "typename ::= ids LP signed RP", - /* 131 */ "typename ::= ids UNSIGNED", - /* 132 */ "signed ::= INTEGER", - /* 133 */ "signed ::= PLUS INTEGER", - /* 134 */ "signed ::= MINUS INTEGER", - /* 135 */ "cmd ::= CREATE TABLE create_table_args", - /* 136 */ "cmd ::= CREATE TABLE create_stable_args", - /* 137 */ "cmd ::= CREATE STABLE create_stable_args", - /* 138 */ "cmd ::= CREATE TABLE create_table_list", - /* 139 */ "create_table_list ::= create_from_stable", - /* 140 */ "create_table_list ::= create_table_list create_from_stable", - /* 141 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", - /* 142 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", - /* 143 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP", - /* 144 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP", - /* 145 */ "tagNamelist ::= tagNamelist COMMA ids", - /* 146 */ "tagNamelist ::= ids", - /* 147 */ "create_table_args ::= ifnotexists ids cpxName AS select", - /* 148 */ "columnlist ::= columnlist COMMA column", - /* 149 */ "columnlist ::= column", - /* 150 */ "column ::= ids typename", - /* 151 */ "tagitemlist1 ::= tagitemlist1 COMMA tagitem1", - /* 152 */ "tagitemlist1 ::= tagitem1", - /* 153 */ "tagitem1 ::= MINUS INTEGER", - /* 154 */ "tagitem1 ::= MINUS FLOAT", - /* 155 */ "tagitem1 ::= PLUS INTEGER", - /* 156 */ "tagitem1 ::= PLUS FLOAT", - /* 157 */ "tagitem1 ::= INTEGER", - /* 158 */ "tagitem1 ::= FLOAT", - /* 159 */ "tagitem1 ::= STRING", - /* 160 */ "tagitem1 ::= BOOL", - /* 161 */ "tagitem1 ::= NULL", - /* 162 */ "tagitem1 ::= NOW", - /* 163 */ "tagitemlist ::= tagitemlist COMMA tagitem", - /* 164 */ "tagitemlist ::= tagitem", - /* 165 */ "tagitem ::= INTEGER", - /* 166 */ "tagitem ::= FLOAT", - /* 167 */ "tagitem ::= STRING", - /* 168 */ "tagitem ::= BOOL", - /* 169 */ "tagitem ::= NULL", - /* 170 */ "tagitem ::= NOW", - /* 171 */ "tagitem ::= MINUS INTEGER", - /* 172 */ "tagitem ::= MINUS FLOAT", - /* 173 */ "tagitem ::= PLUS INTEGER", - /* 174 */ "tagitem ::= PLUS FLOAT", - /* 175 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", - /* 176 */ "select ::= LP select RP", - /* 177 */ "union ::= select", - /* 178 */ "union ::= union UNION ALL select", - /* 179 */ "union ::= union UNION select", - /* 180 */ "cmd ::= union", - /* 181 */ "select ::= SELECT selcollist", - /* 182 */ "sclp ::= selcollist COMMA", - /* 183 */ "sclp ::=", - /* 184 */ "selcollist ::= sclp distinct expr as", - /* 185 */ "selcollist ::= sclp STAR", - /* 186 */ "as ::= AS ids", - /* 187 */ "as ::= ids", - /* 188 */ "as ::=", - /* 189 */ "distinct ::= DISTINCT", - /* 190 */ "distinct ::=", - /* 191 */ "from ::= FROM tablelist", - /* 192 */ "from ::= FROM sub", - /* 193 */ "sub ::= LP union RP", - /* 194 */ "sub ::= LP union RP ids", - /* 195 */ "sub ::= sub COMMA LP union RP ids", - /* 196 */ "tablelist ::= ids cpxName", - /* 197 */ "tablelist ::= ids cpxName ids", - /* 198 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 199 */ "tablelist ::= tablelist COMMA ids cpxName ids", - /* 200 */ "tmvar ::= VARIABLE", - /* 201 */ "interval_option ::= intervalKey LP tmvar RP", - /* 202 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", - /* 203 */ "interval_option ::=", - /* 204 */ "intervalKey ::= INTERVAL", - /* 205 */ "intervalKey ::= EVERY", - /* 206 */ "session_option ::=", - /* 207 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 208 */ "windowstate_option ::=", - /* 209 */ "windowstate_option ::= STATE_WINDOW LP ids RP", - /* 210 */ "fill_opt ::=", - /* 211 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 212 */ "fill_opt ::= FILL LP ID RP", - /* 213 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 214 */ "sliding_opt ::=", - /* 215 */ "orderby_opt ::=", - /* 216 */ "orderby_opt ::= ORDER BY sortlist", - /* 217 */ "sortlist ::= sortlist COMMA item sortorder", - /* 218 */ "sortlist ::= item sortorder", - /* 219 */ "item ::= ids cpxName", - /* 220 */ "sortorder ::= ASC", - /* 221 */ "sortorder ::= DESC", - /* 222 */ "sortorder ::=", - /* 223 */ "groupby_opt ::=", - /* 224 */ "groupby_opt ::= GROUP BY grouplist", - /* 225 */ "grouplist ::= grouplist COMMA item", - /* 226 */ "grouplist ::= item", - /* 227 */ "having_opt ::=", - /* 228 */ "having_opt ::= HAVING expr", - /* 229 */ "limit_opt ::=", - /* 230 */ "limit_opt ::= LIMIT signed", - /* 231 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 232 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 233 */ "slimit_opt ::=", - /* 234 */ "slimit_opt ::= SLIMIT signed", - /* 235 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 236 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 237 */ "where_opt ::=", - /* 238 */ "where_opt ::= WHERE expr", - /* 239 */ "expr ::= LP expr RP", - /* 240 */ "expr ::= ID", - /* 241 */ "expr ::= ID DOT ID", - /* 242 */ "expr ::= ID DOT STAR", - /* 243 */ "expr ::= INTEGER", - /* 244 */ "expr ::= MINUS INTEGER", - /* 245 */ "expr ::= PLUS INTEGER", - /* 246 */ "expr ::= FLOAT", - /* 247 */ "expr ::= MINUS FLOAT", - /* 248 */ "expr ::= PLUS FLOAT", - /* 249 */ "expr ::= STRING", - /* 250 */ "expr ::= NOW", - /* 251 */ "expr ::= VARIABLE", - /* 252 */ "expr ::= PLUS VARIABLE", - /* 253 */ "expr ::= MINUS VARIABLE", - /* 254 */ "expr ::= BOOL", - /* 255 */ "expr ::= NULL", - /* 256 */ "expr ::= ID LP exprlist RP", - /* 257 */ "expr ::= ID LP STAR RP", - /* 258 */ "expr ::= expr IS NULL", - /* 259 */ "expr ::= expr IS NOT NULL", - /* 260 */ "expr ::= expr LT expr", - /* 261 */ "expr ::= expr GT expr", - /* 262 */ "expr ::= expr LE expr", - /* 263 */ "expr ::= expr GE expr", - /* 264 */ "expr ::= expr NE expr", - /* 265 */ "expr ::= expr EQ expr", - /* 266 */ "expr ::= expr BETWEEN expr AND expr", - /* 267 */ "expr ::= expr AND expr", - /* 268 */ "expr ::= expr OR expr", - /* 269 */ "expr ::= expr PLUS expr", - /* 270 */ "expr ::= expr MINUS expr", - /* 271 */ "expr ::= expr STAR expr", - /* 272 */ "expr ::= expr SLASH expr", - /* 273 */ "expr ::= expr REM expr", - /* 274 */ "expr ::= expr LIKE expr", - /* 275 */ "expr ::= expr MATCH expr", - /* 276 */ "expr ::= expr NMATCH expr", - /* 277 */ "expr ::= expr IN LP exprlist RP", - /* 278 */ "exprlist ::= exprlist COMMA expritem", - /* 279 */ "exprlist ::= expritem", - /* 280 */ "expritem ::= expr", - /* 281 */ "expritem ::=", - /* 282 */ "cmd ::= RESET QUERY CACHE", - /* 283 */ "cmd ::= SYNCDB ids REPLICA", - /* 284 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 285 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 286 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", - /* 287 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 288 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 289 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 290 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 291 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", - /* 292 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 293 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 294 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", - /* 295 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 296 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 297 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 298 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", - /* 299 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", - /* 300 */ "cmd ::= KILL CONNECTION INTEGER", - /* 301 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 302 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 52 */ "ifexists ::= IF EXISTS", + /* 53 */ "ifexists ::=", + /* 54 */ "ifnotexists ::= IF NOT EXISTS", + /* 55 */ "ifnotexists ::=", + /* 56 */ "cmd ::= CREATE DNODE ids PORT ids", + /* 57 */ "cmd ::= CREATE DNODE IPTOKEN PORT ids", + /* 58 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", + /* 59 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", + /* 60 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 61 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 62 */ "cmd ::= CREATE USER ids PASS ids", + /* 63 */ "bufsize ::=", + /* 64 */ "bufsize ::= BUFSIZE INTEGER", + /* 65 */ "pps ::=", + /* 66 */ "pps ::= PPS INTEGER", + /* 67 */ "tseries ::=", + /* 68 */ "tseries ::= TSERIES INTEGER", + /* 69 */ "dbs ::=", + /* 70 */ "dbs ::= DBS INTEGER", + /* 71 */ "streams ::=", + /* 72 */ "streams ::= STREAMS INTEGER", + /* 73 */ "storage ::=", + /* 74 */ "storage ::= STORAGE INTEGER", + /* 75 */ "qtime ::=", + /* 76 */ "qtime ::= QTIME INTEGER", + /* 77 */ "users ::=", + /* 78 */ "users ::= USERS INTEGER", + /* 79 */ "conns ::=", + /* 80 */ "conns ::= CONNS INTEGER", + /* 81 */ "state ::=", + /* 82 */ "state ::= STATE ids", + /* 83 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", + /* 84 */ "intitemlist ::= intitemlist COMMA intitem", + /* 85 */ "intitemlist ::= intitem", + /* 86 */ "intitem ::= INTEGER", + /* 87 */ "keep ::= KEEP intitemlist", + /* 88 */ "cache ::= CACHE INTEGER", + /* 89 */ "replica ::= REPLICA INTEGER", + /* 90 */ "quorum ::= QUORUM INTEGER", + /* 91 */ "days ::= DAYS INTEGER", + /* 92 */ "minrows ::= MINROWS INTEGER", + /* 93 */ "maxrows ::= MAXROWS INTEGER", + /* 94 */ "blocks ::= BLOCKS INTEGER", + /* 95 */ "ctime ::= CTIME INTEGER", + /* 96 */ "wal ::= WAL INTEGER", + /* 97 */ "fsync ::= FSYNC INTEGER", + /* 98 */ "comp ::= COMP INTEGER", + /* 99 */ "prec ::= PRECISION STRING", + /* 100 */ "update ::= UPDATE INTEGER", + /* 101 */ "cachelast ::= CACHELAST INTEGER", + /* 102 */ "vgroups ::= VGROUPS INTEGER", + /* 103 */ "db_optr ::=", + /* 104 */ "db_optr ::= db_optr cache", + /* 105 */ "db_optr ::= db_optr replica", + /* 106 */ "db_optr ::= db_optr quorum", + /* 107 */ "db_optr ::= db_optr days", + /* 108 */ "db_optr ::= db_optr minrows", + /* 109 */ "db_optr ::= db_optr maxrows", + /* 110 */ "db_optr ::= db_optr blocks", + /* 111 */ "db_optr ::= db_optr ctime", + /* 112 */ "db_optr ::= db_optr wal", + /* 113 */ "db_optr ::= db_optr fsync", + /* 114 */ "db_optr ::= db_optr comp", + /* 115 */ "db_optr ::= db_optr prec", + /* 116 */ "db_optr ::= db_optr keep", + /* 117 */ "db_optr ::= db_optr update", + /* 118 */ "db_optr ::= db_optr cachelast", + /* 119 */ "db_optr ::= db_optr vgroups", + /* 120 */ "alter_db_optr ::=", + /* 121 */ "alter_db_optr ::= alter_db_optr replica", + /* 122 */ "alter_db_optr ::= alter_db_optr quorum", + /* 123 */ "alter_db_optr ::= alter_db_optr keep", + /* 124 */ "alter_db_optr ::= alter_db_optr blocks", + /* 125 */ "alter_db_optr ::= alter_db_optr comp", + /* 126 */ "alter_db_optr ::= alter_db_optr update", + /* 127 */ "alter_db_optr ::= alter_db_optr cachelast", + /* 128 */ "typename ::= ids", + /* 129 */ "typename ::= ids LP signed RP", + /* 130 */ "typename ::= ids UNSIGNED", + /* 131 */ "signed ::= INTEGER", + /* 132 */ "signed ::= PLUS INTEGER", + /* 133 */ "signed ::= MINUS INTEGER", + /* 134 */ "cmd ::= CREATE TABLE create_table_args", + /* 135 */ "cmd ::= CREATE TABLE create_stable_args", + /* 136 */ "cmd ::= CREATE STABLE create_stable_args", + /* 137 */ "cmd ::= CREATE TABLE create_table_list", + /* 138 */ "create_table_list ::= create_from_stable", + /* 139 */ "create_table_list ::= create_table_list create_from_stable", + /* 140 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", + /* 141 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", + /* 142 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP", + /* 143 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP", + /* 144 */ "tagNamelist ::= tagNamelist COMMA ids", + /* 145 */ "tagNamelist ::= ids", + /* 146 */ "create_table_args ::= ifnotexists ids cpxName AS select", + /* 147 */ "columnlist ::= columnlist COMMA column", + /* 148 */ "columnlist ::= column", + /* 149 */ "column ::= ids typename", + /* 150 */ "tagitemlist1 ::= tagitemlist1 COMMA tagitem1", + /* 151 */ "tagitemlist1 ::= tagitem1", + /* 152 */ "tagitem1 ::= MINUS INTEGER", + /* 153 */ "tagitem1 ::= MINUS FLOAT", + /* 154 */ "tagitem1 ::= PLUS INTEGER", + /* 155 */ "tagitem1 ::= PLUS FLOAT", + /* 156 */ "tagitem1 ::= INTEGER", + /* 157 */ "tagitem1 ::= FLOAT", + /* 158 */ "tagitem1 ::= STRING", + /* 159 */ "tagitem1 ::= BOOL", + /* 160 */ "tagitem1 ::= NULL", + /* 161 */ "tagitem1 ::= NOW", + /* 162 */ "tagitemlist ::= tagitemlist COMMA tagitem", + /* 163 */ "tagitemlist ::= tagitem", + /* 164 */ "tagitem ::= INTEGER", + /* 165 */ "tagitem ::= FLOAT", + /* 166 */ "tagitem ::= STRING", + /* 167 */ "tagitem ::= BOOL", + /* 168 */ "tagitem ::= NULL", + /* 169 */ "tagitem ::= NOW", + /* 170 */ "tagitem ::= MINUS INTEGER", + /* 171 */ "tagitem ::= MINUS FLOAT", + /* 172 */ "tagitem ::= PLUS INTEGER", + /* 173 */ "tagitem ::= PLUS FLOAT", + /* 174 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", + /* 175 */ "select ::= LP select RP", + /* 176 */ "union ::= select", + /* 177 */ "union ::= union UNION ALL select", + /* 178 */ "union ::= union UNION select", + /* 179 */ "cmd ::= union", + /* 180 */ "select ::= SELECT selcollist", + /* 181 */ "sclp ::= selcollist COMMA", + /* 182 */ "sclp ::=", + /* 183 */ "selcollist ::= sclp distinct expr as", + /* 184 */ "selcollist ::= sclp STAR", + /* 185 */ "as ::= AS ids", + /* 186 */ "as ::= ids", + /* 187 */ "as ::=", + /* 188 */ "distinct ::= DISTINCT", + /* 189 */ "distinct ::=", + /* 190 */ "from ::= FROM tablelist", + /* 191 */ "from ::= FROM sub", + /* 192 */ "sub ::= LP union RP", + /* 193 */ "sub ::= LP union RP ids", + /* 194 */ "sub ::= sub COMMA LP union RP ids", + /* 195 */ "tablelist ::= ids cpxName", + /* 196 */ "tablelist ::= ids cpxName ids", + /* 197 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 198 */ "tablelist ::= tablelist COMMA ids cpxName ids", + /* 199 */ "tmvar ::= VARIABLE", + /* 200 */ "interval_option ::= intervalKey LP tmvar RP", + /* 201 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", + /* 202 */ "interval_option ::=", + /* 203 */ "intervalKey ::= INTERVAL", + /* 204 */ "intervalKey ::= EVERY", + /* 205 */ "session_option ::=", + /* 206 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 207 */ "windowstate_option ::=", + /* 208 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 209 */ "fill_opt ::=", + /* 210 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 211 */ "fill_opt ::= FILL LP ID RP", + /* 212 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 213 */ "sliding_opt ::=", + /* 214 */ "orderby_opt ::=", + /* 215 */ "orderby_opt ::= ORDER BY sortlist", + /* 216 */ "sortlist ::= sortlist COMMA item sortorder", + /* 217 */ "sortlist ::= item sortorder", + /* 218 */ "item ::= ids cpxName", + /* 219 */ "sortorder ::= ASC", + /* 220 */ "sortorder ::= DESC", + /* 221 */ "sortorder ::=", + /* 222 */ "groupby_opt ::=", + /* 223 */ "groupby_opt ::= GROUP BY grouplist", + /* 224 */ "grouplist ::= grouplist COMMA item", + /* 225 */ "grouplist ::= item", + /* 226 */ "having_opt ::=", + /* 227 */ "having_opt ::= HAVING expr", + /* 228 */ "limit_opt ::=", + /* 229 */ "limit_opt ::= LIMIT signed", + /* 230 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 231 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 232 */ "slimit_opt ::=", + /* 233 */ "slimit_opt ::= SLIMIT signed", + /* 234 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 235 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 236 */ "where_opt ::=", + /* 237 */ "where_opt ::= WHERE expr", + /* 238 */ "expr ::= LP expr RP", + /* 239 */ "expr ::= ID", + /* 240 */ "expr ::= ID DOT ID", + /* 241 */ "expr ::= ID DOT STAR", + /* 242 */ "expr ::= INTEGER", + /* 243 */ "expr ::= MINUS INTEGER", + /* 244 */ "expr ::= PLUS INTEGER", + /* 245 */ "expr ::= FLOAT", + /* 246 */ "expr ::= MINUS FLOAT", + /* 247 */ "expr ::= PLUS FLOAT", + /* 248 */ "expr ::= STRING", + /* 249 */ "expr ::= NOW", + /* 250 */ "expr ::= VARIABLE", + /* 251 */ "expr ::= PLUS VARIABLE", + /* 252 */ "expr ::= MINUS VARIABLE", + /* 253 */ "expr ::= BOOL", + /* 254 */ "expr ::= NULL", + /* 255 */ "expr ::= ID LP exprlist RP", + /* 256 */ "expr ::= ID LP STAR RP", + /* 257 */ "expr ::= expr IS NULL", + /* 258 */ "expr ::= expr IS NOT NULL", + /* 259 */ "expr ::= expr LT expr", + /* 260 */ "expr ::= expr GT expr", + /* 261 */ "expr ::= expr LE expr", + /* 262 */ "expr ::= expr GE expr", + /* 263 */ "expr ::= expr NE expr", + /* 264 */ "expr ::= expr EQ expr", + /* 265 */ "expr ::= expr BETWEEN expr AND expr", + /* 266 */ "expr ::= expr AND expr", + /* 267 */ "expr ::= expr OR expr", + /* 268 */ "expr ::= expr PLUS expr", + /* 269 */ "expr ::= expr MINUS expr", + /* 270 */ "expr ::= expr STAR expr", + /* 271 */ "expr ::= expr SLASH expr", + /* 272 */ "expr ::= expr REM expr", + /* 273 */ "expr ::= expr LIKE expr", + /* 274 */ "expr ::= expr MATCH expr", + /* 275 */ "expr ::= expr NMATCH expr", + /* 276 */ "expr ::= expr IN LP exprlist RP", + /* 277 */ "exprlist ::= exprlist COMMA expritem", + /* 278 */ "exprlist ::= expritem", + /* 279 */ "expritem ::= expr", + /* 280 */ "expritem ::=", + /* 281 */ "cmd ::= RESET QUERY CACHE", + /* 282 */ "cmd ::= SYNCDB ids REPLICA", + /* 283 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 284 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 285 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", + /* 286 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 287 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 288 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 289 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 290 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", + /* 291 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 292 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 293 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", + /* 294 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 295 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 296 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 297 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", + /* 298 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", + /* 299 */ "cmd ::= KILL CONNECTION INTEGER", + /* 300 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 301 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1893,257 +1890,256 @@ static const struct { { 193, -6 }, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ { 193, -6 }, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ { 194, -1 }, /* (51) ids ::= ID */ - { 194, -1 }, /* (52) ids ::= STRING */ - { 197, -2 }, /* (53) ifexists ::= IF EXISTS */ - { 197, 0 }, /* (54) ifexists ::= */ - { 201, -3 }, /* (55) ifnotexists ::= IF NOT EXISTS */ - { 201, 0 }, /* (56) ifnotexists ::= */ - { 193, -5 }, /* (57) cmd ::= CREATE DNODE ids PORT ids */ - { 193, -5 }, /* (58) cmd ::= CREATE DNODE IPTOKEN PORT ids */ - { 193, -6 }, /* (59) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 193, -5 }, /* (60) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 193, -8 }, /* (61) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 193, -9 }, /* (62) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 193, -5 }, /* (63) cmd ::= CREATE USER ids PASS ids */ - { 204, 0 }, /* (64) bufsize ::= */ - { 204, -2 }, /* (65) bufsize ::= BUFSIZE INTEGER */ - { 205, 0 }, /* (66) pps ::= */ - { 205, -2 }, /* (67) pps ::= PPS INTEGER */ - { 206, 0 }, /* (68) tseries ::= */ - { 206, -2 }, /* (69) tseries ::= TSERIES INTEGER */ - { 207, 0 }, /* (70) dbs ::= */ - { 207, -2 }, /* (71) dbs ::= DBS INTEGER */ - { 208, 0 }, /* (72) streams ::= */ - { 208, -2 }, /* (73) streams ::= STREAMS INTEGER */ - { 209, 0 }, /* (74) storage ::= */ - { 209, -2 }, /* (75) storage ::= STORAGE INTEGER */ - { 210, 0 }, /* (76) qtime ::= */ - { 210, -2 }, /* (77) qtime ::= QTIME INTEGER */ - { 211, 0 }, /* (78) users ::= */ - { 211, -2 }, /* (79) users ::= USERS INTEGER */ - { 212, 0 }, /* (80) conns ::= */ - { 212, -2 }, /* (81) conns ::= CONNS INTEGER */ - { 213, 0 }, /* (82) state ::= */ - { 213, -2 }, /* (83) state ::= STATE ids */ - { 199, -9 }, /* (84) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 214, -3 }, /* (85) intitemlist ::= intitemlist COMMA intitem */ - { 214, -1 }, /* (86) intitemlist ::= intitem */ - { 215, -1 }, /* (87) intitem ::= INTEGER */ - { 216, -2 }, /* (88) keep ::= KEEP intitemlist */ - { 217, -2 }, /* (89) cache ::= CACHE INTEGER */ - { 218, -2 }, /* (90) replica ::= REPLICA INTEGER */ - { 219, -2 }, /* (91) quorum ::= QUORUM INTEGER */ - { 220, -2 }, /* (92) days ::= DAYS INTEGER */ - { 221, -2 }, /* (93) minrows ::= MINROWS INTEGER */ - { 222, -2 }, /* (94) maxrows ::= MAXROWS INTEGER */ - { 223, -2 }, /* (95) blocks ::= BLOCKS INTEGER */ - { 224, -2 }, /* (96) ctime ::= CTIME INTEGER */ - { 225, -2 }, /* (97) wal ::= WAL INTEGER */ - { 226, -2 }, /* (98) fsync ::= FSYNC INTEGER */ - { 227, -2 }, /* (99) comp ::= COMP INTEGER */ - { 228, -2 }, /* (100) prec ::= PRECISION STRING */ - { 229, -2 }, /* (101) update ::= UPDATE INTEGER */ - { 230, -2 }, /* (102) cachelast ::= CACHELAST INTEGER */ - { 231, -2 }, /* (103) vgroups ::= VGROUPS INTEGER */ - { 202, 0 }, /* (104) db_optr ::= */ - { 202, -2 }, /* (105) db_optr ::= db_optr cache */ - { 202, -2 }, /* (106) db_optr ::= db_optr replica */ - { 202, -2 }, /* (107) db_optr ::= db_optr quorum */ - { 202, -2 }, /* (108) db_optr ::= db_optr days */ - { 202, -2 }, /* (109) db_optr ::= db_optr minrows */ - { 202, -2 }, /* (110) db_optr ::= db_optr maxrows */ - { 202, -2 }, /* (111) db_optr ::= db_optr blocks */ - { 202, -2 }, /* (112) db_optr ::= db_optr ctime */ - { 202, -2 }, /* (113) db_optr ::= db_optr wal */ - { 202, -2 }, /* (114) db_optr ::= db_optr fsync */ - { 202, -2 }, /* (115) db_optr ::= db_optr comp */ - { 202, -2 }, /* (116) db_optr ::= db_optr prec */ - { 202, -2 }, /* (117) db_optr ::= db_optr keep */ - { 202, -2 }, /* (118) db_optr ::= db_optr update */ - { 202, -2 }, /* (119) db_optr ::= db_optr cachelast */ - { 202, -2 }, /* (120) db_optr ::= db_optr vgroups */ - { 198, 0 }, /* (121) alter_db_optr ::= */ - { 198, -2 }, /* (122) alter_db_optr ::= alter_db_optr replica */ - { 198, -2 }, /* (123) alter_db_optr ::= alter_db_optr quorum */ - { 198, -2 }, /* (124) alter_db_optr ::= alter_db_optr keep */ - { 198, -2 }, /* (125) alter_db_optr ::= alter_db_optr blocks */ - { 198, -2 }, /* (126) alter_db_optr ::= alter_db_optr comp */ - { 198, -2 }, /* (127) alter_db_optr ::= alter_db_optr update */ - { 198, -2 }, /* (128) alter_db_optr ::= alter_db_optr cachelast */ - { 203, -1 }, /* (129) typename ::= ids */ - { 203, -4 }, /* (130) typename ::= ids LP signed RP */ - { 203, -2 }, /* (131) typename ::= ids UNSIGNED */ - { 232, -1 }, /* (132) signed ::= INTEGER */ - { 232, -2 }, /* (133) signed ::= PLUS INTEGER */ - { 232, -2 }, /* (134) signed ::= MINUS INTEGER */ - { 193, -3 }, /* (135) cmd ::= CREATE TABLE create_table_args */ - { 193, -3 }, /* (136) cmd ::= CREATE TABLE create_stable_args */ - { 193, -3 }, /* (137) cmd ::= CREATE STABLE create_stable_args */ - { 193, -3 }, /* (138) cmd ::= CREATE TABLE create_table_list */ - { 235, -1 }, /* (139) create_table_list ::= create_from_stable */ - { 235, -2 }, /* (140) create_table_list ::= create_table_list create_from_stable */ - { 233, -6 }, /* (141) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 234, -10 }, /* (142) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 236, -10 }, /* (143) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ - { 236, -13 }, /* (144) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ - { 239, -3 }, /* (145) tagNamelist ::= tagNamelist COMMA ids */ - { 239, -1 }, /* (146) tagNamelist ::= ids */ - { 233, -5 }, /* (147) create_table_args ::= ifnotexists ids cpxName AS select */ - { 237, -3 }, /* (148) columnlist ::= columnlist COMMA column */ - { 237, -1 }, /* (149) columnlist ::= column */ - { 241, -2 }, /* (150) column ::= ids typename */ - { 238, -3 }, /* (151) tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ - { 238, -1 }, /* (152) tagitemlist1 ::= tagitem1 */ - { 242, -2 }, /* (153) tagitem1 ::= MINUS INTEGER */ - { 242, -2 }, /* (154) tagitem1 ::= MINUS FLOAT */ - { 242, -2 }, /* (155) tagitem1 ::= PLUS INTEGER */ - { 242, -2 }, /* (156) tagitem1 ::= PLUS FLOAT */ - { 242, -1 }, /* (157) tagitem1 ::= INTEGER */ - { 242, -1 }, /* (158) tagitem1 ::= FLOAT */ - { 242, -1 }, /* (159) tagitem1 ::= STRING */ - { 242, -1 }, /* (160) tagitem1 ::= BOOL */ - { 242, -1 }, /* (161) tagitem1 ::= NULL */ - { 242, -1 }, /* (162) tagitem1 ::= NOW */ - { 243, -3 }, /* (163) tagitemlist ::= tagitemlist COMMA tagitem */ - { 243, -1 }, /* (164) tagitemlist ::= tagitem */ - { 244, -1 }, /* (165) tagitem ::= INTEGER */ - { 244, -1 }, /* (166) tagitem ::= FLOAT */ - { 244, -1 }, /* (167) tagitem ::= STRING */ - { 244, -1 }, /* (168) tagitem ::= BOOL */ - { 244, -1 }, /* (169) tagitem ::= NULL */ - { 244, -1 }, /* (170) tagitem ::= NOW */ - { 244, -2 }, /* (171) tagitem ::= MINUS INTEGER */ - { 244, -2 }, /* (172) tagitem ::= MINUS FLOAT */ - { 244, -2 }, /* (173) tagitem ::= PLUS INTEGER */ - { 244, -2 }, /* (174) tagitem ::= PLUS FLOAT */ - { 240, -14 }, /* (175) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ - { 240, -3 }, /* (176) select ::= LP select RP */ - { 258, -1 }, /* (177) union ::= select */ - { 258, -4 }, /* (178) union ::= union UNION ALL select */ - { 258, -3 }, /* (179) union ::= union UNION select */ - { 193, -1 }, /* (180) cmd ::= union */ - { 240, -2 }, /* (181) select ::= SELECT selcollist */ - { 259, -2 }, /* (182) sclp ::= selcollist COMMA */ - { 259, 0 }, /* (183) sclp ::= */ - { 245, -4 }, /* (184) selcollist ::= sclp distinct expr as */ - { 245, -2 }, /* (185) selcollist ::= sclp STAR */ - { 262, -2 }, /* (186) as ::= AS ids */ - { 262, -1 }, /* (187) as ::= ids */ - { 262, 0 }, /* (188) as ::= */ - { 260, -1 }, /* (189) distinct ::= DISTINCT */ - { 260, 0 }, /* (190) distinct ::= */ - { 246, -2 }, /* (191) from ::= FROM tablelist */ - { 246, -2 }, /* (192) from ::= FROM sub */ - { 264, -3 }, /* (193) sub ::= LP union RP */ - { 264, -4 }, /* (194) sub ::= LP union RP ids */ - { 264, -6 }, /* (195) sub ::= sub COMMA LP union RP ids */ - { 263, -2 }, /* (196) tablelist ::= ids cpxName */ - { 263, -3 }, /* (197) tablelist ::= ids cpxName ids */ - { 263, -4 }, /* (198) tablelist ::= tablelist COMMA ids cpxName */ - { 263, -5 }, /* (199) tablelist ::= tablelist COMMA ids cpxName ids */ - { 265, -1 }, /* (200) tmvar ::= VARIABLE */ - { 248, -4 }, /* (201) interval_option ::= intervalKey LP tmvar RP */ - { 248, -6 }, /* (202) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ - { 248, 0 }, /* (203) interval_option ::= */ - { 266, -1 }, /* (204) intervalKey ::= INTERVAL */ - { 266, -1 }, /* (205) intervalKey ::= EVERY */ - { 250, 0 }, /* (206) session_option ::= */ - { 250, -7 }, /* (207) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 251, 0 }, /* (208) windowstate_option ::= */ - { 251, -4 }, /* (209) windowstate_option ::= STATE_WINDOW LP ids RP */ - { 252, 0 }, /* (210) fill_opt ::= */ - { 252, -6 }, /* (211) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 252, -4 }, /* (212) fill_opt ::= FILL LP ID RP */ - { 249, -4 }, /* (213) sliding_opt ::= SLIDING LP tmvar RP */ - { 249, 0 }, /* (214) sliding_opt ::= */ - { 255, 0 }, /* (215) orderby_opt ::= */ - { 255, -3 }, /* (216) orderby_opt ::= ORDER BY sortlist */ - { 267, -4 }, /* (217) sortlist ::= sortlist COMMA item sortorder */ - { 267, -2 }, /* (218) sortlist ::= item sortorder */ - { 269, -2 }, /* (219) item ::= ids cpxName */ - { 270, -1 }, /* (220) sortorder ::= ASC */ - { 270, -1 }, /* (221) sortorder ::= DESC */ - { 270, 0 }, /* (222) sortorder ::= */ - { 253, 0 }, /* (223) groupby_opt ::= */ - { 253, -3 }, /* (224) groupby_opt ::= GROUP BY grouplist */ - { 271, -3 }, /* (225) grouplist ::= grouplist COMMA item */ - { 271, -1 }, /* (226) grouplist ::= item */ - { 254, 0 }, /* (227) having_opt ::= */ - { 254, -2 }, /* (228) having_opt ::= HAVING expr */ - { 257, 0 }, /* (229) limit_opt ::= */ - { 257, -2 }, /* (230) limit_opt ::= LIMIT signed */ - { 257, -4 }, /* (231) limit_opt ::= LIMIT signed OFFSET signed */ - { 257, -4 }, /* (232) limit_opt ::= LIMIT signed COMMA signed */ - { 256, 0 }, /* (233) slimit_opt ::= */ - { 256, -2 }, /* (234) slimit_opt ::= SLIMIT signed */ - { 256, -4 }, /* (235) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 256, -4 }, /* (236) slimit_opt ::= SLIMIT signed COMMA signed */ - { 247, 0 }, /* (237) where_opt ::= */ - { 247, -2 }, /* (238) where_opt ::= WHERE expr */ - { 261, -3 }, /* (239) expr ::= LP expr RP */ - { 261, -1 }, /* (240) expr ::= ID */ - { 261, -3 }, /* (241) expr ::= ID DOT ID */ - { 261, -3 }, /* (242) expr ::= ID DOT STAR */ - { 261, -1 }, /* (243) expr ::= INTEGER */ - { 261, -2 }, /* (244) expr ::= MINUS INTEGER */ - { 261, -2 }, /* (245) expr ::= PLUS INTEGER */ - { 261, -1 }, /* (246) expr ::= FLOAT */ - { 261, -2 }, /* (247) expr ::= MINUS FLOAT */ - { 261, -2 }, /* (248) expr ::= PLUS FLOAT */ - { 261, -1 }, /* (249) expr ::= STRING */ - { 261, -1 }, /* (250) expr ::= NOW */ - { 261, -1 }, /* (251) expr ::= VARIABLE */ - { 261, -2 }, /* (252) expr ::= PLUS VARIABLE */ - { 261, -2 }, /* (253) expr ::= MINUS VARIABLE */ - { 261, -1 }, /* (254) expr ::= BOOL */ - { 261, -1 }, /* (255) expr ::= NULL */ - { 261, -4 }, /* (256) expr ::= ID LP exprlist RP */ - { 261, -4 }, /* (257) expr ::= ID LP STAR RP */ - { 261, -3 }, /* (258) expr ::= expr IS NULL */ - { 261, -4 }, /* (259) expr ::= expr IS NOT NULL */ - { 261, -3 }, /* (260) expr ::= expr LT expr */ - { 261, -3 }, /* (261) expr ::= expr GT expr */ - { 261, -3 }, /* (262) expr ::= expr LE expr */ - { 261, -3 }, /* (263) expr ::= expr GE expr */ - { 261, -3 }, /* (264) expr ::= expr NE expr */ - { 261, -3 }, /* (265) expr ::= expr EQ expr */ - { 261, -5 }, /* (266) expr ::= expr BETWEEN expr AND expr */ - { 261, -3 }, /* (267) expr ::= expr AND expr */ - { 261, -3 }, /* (268) expr ::= expr OR expr */ - { 261, -3 }, /* (269) expr ::= expr PLUS expr */ - { 261, -3 }, /* (270) expr ::= expr MINUS expr */ - { 261, -3 }, /* (271) expr ::= expr STAR expr */ - { 261, -3 }, /* (272) expr ::= expr SLASH expr */ - { 261, -3 }, /* (273) expr ::= expr REM expr */ - { 261, -3 }, /* (274) expr ::= expr LIKE expr */ - { 261, -3 }, /* (275) expr ::= expr MATCH expr */ - { 261, -3 }, /* (276) expr ::= expr NMATCH expr */ - { 261, -5 }, /* (277) expr ::= expr IN LP exprlist RP */ - { 200, -3 }, /* (278) exprlist ::= exprlist COMMA expritem */ - { 200, -1 }, /* (279) exprlist ::= expritem */ - { 272, -1 }, /* (280) expritem ::= expr */ - { 272, 0 }, /* (281) expritem ::= */ - { 193, -3 }, /* (282) cmd ::= RESET QUERY CACHE */ - { 193, -3 }, /* (283) cmd ::= SYNCDB ids REPLICA */ - { 193, -7 }, /* (284) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 193, -7 }, /* (285) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 193, -7 }, /* (286) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - { 193, -7 }, /* (287) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 193, -7 }, /* (288) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 193, -8 }, /* (289) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 193, -9 }, /* (290) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 193, -7 }, /* (291) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - { 193, -7 }, /* (292) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 193, -7 }, /* (293) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 193, -7 }, /* (294) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - { 193, -7 }, /* (295) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 193, -7 }, /* (296) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 193, -8 }, /* (297) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 193, -9 }, /* (298) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - { 193, -7 }, /* (299) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - { 193, -3 }, /* (300) cmd ::= KILL CONNECTION INTEGER */ - { 193, -5 }, /* (301) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 193, -5 }, /* (302) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + { 197, -2 }, /* (52) ifexists ::= IF EXISTS */ + { 197, 0 }, /* (53) ifexists ::= */ + { 201, -3 }, /* (54) ifnotexists ::= IF NOT EXISTS */ + { 201, 0 }, /* (55) ifnotexists ::= */ + { 193, -5 }, /* (56) cmd ::= CREATE DNODE ids PORT ids */ + { 193, -5 }, /* (57) cmd ::= CREATE DNODE IPTOKEN PORT ids */ + { 193, -6 }, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 193, -5 }, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 193, -8 }, /* (60) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 193, -9 }, /* (61) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 193, -5 }, /* (62) cmd ::= CREATE USER ids PASS ids */ + { 204, 0 }, /* (63) bufsize ::= */ + { 204, -2 }, /* (64) bufsize ::= BUFSIZE INTEGER */ + { 205, 0 }, /* (65) pps ::= */ + { 205, -2 }, /* (66) pps ::= PPS INTEGER */ + { 206, 0 }, /* (67) tseries ::= */ + { 206, -2 }, /* (68) tseries ::= TSERIES INTEGER */ + { 207, 0 }, /* (69) dbs ::= */ + { 207, -2 }, /* (70) dbs ::= DBS INTEGER */ + { 208, 0 }, /* (71) streams ::= */ + { 208, -2 }, /* (72) streams ::= STREAMS INTEGER */ + { 209, 0 }, /* (73) storage ::= */ + { 209, -2 }, /* (74) storage ::= STORAGE INTEGER */ + { 210, 0 }, /* (75) qtime ::= */ + { 210, -2 }, /* (76) qtime ::= QTIME INTEGER */ + { 211, 0 }, /* (77) users ::= */ + { 211, -2 }, /* (78) users ::= USERS INTEGER */ + { 212, 0 }, /* (79) conns ::= */ + { 212, -2 }, /* (80) conns ::= CONNS INTEGER */ + { 213, 0 }, /* (81) state ::= */ + { 213, -2 }, /* (82) state ::= STATE ids */ + { 199, -9 }, /* (83) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 214, -3 }, /* (84) intitemlist ::= intitemlist COMMA intitem */ + { 214, -1 }, /* (85) intitemlist ::= intitem */ + { 215, -1 }, /* (86) intitem ::= INTEGER */ + { 216, -2 }, /* (87) keep ::= KEEP intitemlist */ + { 217, -2 }, /* (88) cache ::= CACHE INTEGER */ + { 218, -2 }, /* (89) replica ::= REPLICA INTEGER */ + { 219, -2 }, /* (90) quorum ::= QUORUM INTEGER */ + { 220, -2 }, /* (91) days ::= DAYS INTEGER */ + { 221, -2 }, /* (92) minrows ::= MINROWS INTEGER */ + { 222, -2 }, /* (93) maxrows ::= MAXROWS INTEGER */ + { 223, -2 }, /* (94) blocks ::= BLOCKS INTEGER */ + { 224, -2 }, /* (95) ctime ::= CTIME INTEGER */ + { 225, -2 }, /* (96) wal ::= WAL INTEGER */ + { 226, -2 }, /* (97) fsync ::= FSYNC INTEGER */ + { 227, -2 }, /* (98) comp ::= COMP INTEGER */ + { 228, -2 }, /* (99) prec ::= PRECISION STRING */ + { 229, -2 }, /* (100) update ::= UPDATE INTEGER */ + { 230, -2 }, /* (101) cachelast ::= CACHELAST INTEGER */ + { 231, -2 }, /* (102) vgroups ::= VGROUPS INTEGER */ + { 202, 0 }, /* (103) db_optr ::= */ + { 202, -2 }, /* (104) db_optr ::= db_optr cache */ + { 202, -2 }, /* (105) db_optr ::= db_optr replica */ + { 202, -2 }, /* (106) db_optr ::= db_optr quorum */ + { 202, -2 }, /* (107) db_optr ::= db_optr days */ + { 202, -2 }, /* (108) db_optr ::= db_optr minrows */ + { 202, -2 }, /* (109) db_optr ::= db_optr maxrows */ + { 202, -2 }, /* (110) db_optr ::= db_optr blocks */ + { 202, -2 }, /* (111) db_optr ::= db_optr ctime */ + { 202, -2 }, /* (112) db_optr ::= db_optr wal */ + { 202, -2 }, /* (113) db_optr ::= db_optr fsync */ + { 202, -2 }, /* (114) db_optr ::= db_optr comp */ + { 202, -2 }, /* (115) db_optr ::= db_optr prec */ + { 202, -2 }, /* (116) db_optr ::= db_optr keep */ + { 202, -2 }, /* (117) db_optr ::= db_optr update */ + { 202, -2 }, /* (118) db_optr ::= db_optr cachelast */ + { 202, -2 }, /* (119) db_optr ::= db_optr vgroups */ + { 198, 0 }, /* (120) alter_db_optr ::= */ + { 198, -2 }, /* (121) alter_db_optr ::= alter_db_optr replica */ + { 198, -2 }, /* (122) alter_db_optr ::= alter_db_optr quorum */ + { 198, -2 }, /* (123) alter_db_optr ::= alter_db_optr keep */ + { 198, -2 }, /* (124) alter_db_optr ::= alter_db_optr blocks */ + { 198, -2 }, /* (125) alter_db_optr ::= alter_db_optr comp */ + { 198, -2 }, /* (126) alter_db_optr ::= alter_db_optr update */ + { 198, -2 }, /* (127) alter_db_optr ::= alter_db_optr cachelast */ + { 203, -1 }, /* (128) typename ::= ids */ + { 203, -4 }, /* (129) typename ::= ids LP signed RP */ + { 203, -2 }, /* (130) typename ::= ids UNSIGNED */ + { 232, -1 }, /* (131) signed ::= INTEGER */ + { 232, -2 }, /* (132) signed ::= PLUS INTEGER */ + { 232, -2 }, /* (133) signed ::= MINUS INTEGER */ + { 193, -3 }, /* (134) cmd ::= CREATE TABLE create_table_args */ + { 193, -3 }, /* (135) cmd ::= CREATE TABLE create_stable_args */ + { 193, -3 }, /* (136) cmd ::= CREATE STABLE create_stable_args */ + { 193, -3 }, /* (137) cmd ::= CREATE TABLE create_table_list */ + { 235, -1 }, /* (138) create_table_list ::= create_from_stable */ + { 235, -2 }, /* (139) create_table_list ::= create_table_list create_from_stable */ + { 233, -6 }, /* (140) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 234, -10 }, /* (141) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 236, -10 }, /* (142) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ + { 236, -13 }, /* (143) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ + { 239, -3 }, /* (144) tagNamelist ::= tagNamelist COMMA ids */ + { 239, -1 }, /* (145) tagNamelist ::= ids */ + { 233, -5 }, /* (146) create_table_args ::= ifnotexists ids cpxName AS select */ + { 237, -3 }, /* (147) columnlist ::= columnlist COMMA column */ + { 237, -1 }, /* (148) columnlist ::= column */ + { 241, -2 }, /* (149) column ::= ids typename */ + { 238, -3 }, /* (150) tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ + { 238, -1 }, /* (151) tagitemlist1 ::= tagitem1 */ + { 242, -2 }, /* (152) tagitem1 ::= MINUS INTEGER */ + { 242, -2 }, /* (153) tagitem1 ::= MINUS FLOAT */ + { 242, -2 }, /* (154) tagitem1 ::= PLUS INTEGER */ + { 242, -2 }, /* (155) tagitem1 ::= PLUS FLOAT */ + { 242, -1 }, /* (156) tagitem1 ::= INTEGER */ + { 242, -1 }, /* (157) tagitem1 ::= FLOAT */ + { 242, -1 }, /* (158) tagitem1 ::= STRING */ + { 242, -1 }, /* (159) tagitem1 ::= BOOL */ + { 242, -1 }, /* (160) tagitem1 ::= NULL */ + { 242, -1 }, /* (161) tagitem1 ::= NOW */ + { 243, -3 }, /* (162) tagitemlist ::= tagitemlist COMMA tagitem */ + { 243, -1 }, /* (163) tagitemlist ::= tagitem */ + { 244, -1 }, /* (164) tagitem ::= INTEGER */ + { 244, -1 }, /* (165) tagitem ::= FLOAT */ + { 244, -1 }, /* (166) tagitem ::= STRING */ + { 244, -1 }, /* (167) tagitem ::= BOOL */ + { 244, -1 }, /* (168) tagitem ::= NULL */ + { 244, -1 }, /* (169) tagitem ::= NOW */ + { 244, -2 }, /* (170) tagitem ::= MINUS INTEGER */ + { 244, -2 }, /* (171) tagitem ::= MINUS FLOAT */ + { 244, -2 }, /* (172) tagitem ::= PLUS INTEGER */ + { 244, -2 }, /* (173) tagitem ::= PLUS FLOAT */ + { 240, -14 }, /* (174) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + { 240, -3 }, /* (175) select ::= LP select RP */ + { 258, -1 }, /* (176) union ::= select */ + { 258, -4 }, /* (177) union ::= union UNION ALL select */ + { 258, -3 }, /* (178) union ::= union UNION select */ + { 193, -1 }, /* (179) cmd ::= union */ + { 240, -2 }, /* (180) select ::= SELECT selcollist */ + { 259, -2 }, /* (181) sclp ::= selcollist COMMA */ + { 259, 0 }, /* (182) sclp ::= */ + { 245, -4 }, /* (183) selcollist ::= sclp distinct expr as */ + { 245, -2 }, /* (184) selcollist ::= sclp STAR */ + { 262, -2 }, /* (185) as ::= AS ids */ + { 262, -1 }, /* (186) as ::= ids */ + { 262, 0 }, /* (187) as ::= */ + { 260, -1 }, /* (188) distinct ::= DISTINCT */ + { 260, 0 }, /* (189) distinct ::= */ + { 246, -2 }, /* (190) from ::= FROM tablelist */ + { 246, -2 }, /* (191) from ::= FROM sub */ + { 264, -3 }, /* (192) sub ::= LP union RP */ + { 264, -4 }, /* (193) sub ::= LP union RP ids */ + { 264, -6 }, /* (194) sub ::= sub COMMA LP union RP ids */ + { 263, -2 }, /* (195) tablelist ::= ids cpxName */ + { 263, -3 }, /* (196) tablelist ::= ids cpxName ids */ + { 263, -4 }, /* (197) tablelist ::= tablelist COMMA ids cpxName */ + { 263, -5 }, /* (198) tablelist ::= tablelist COMMA ids cpxName ids */ + { 265, -1 }, /* (199) tmvar ::= VARIABLE */ + { 248, -4 }, /* (200) interval_option ::= intervalKey LP tmvar RP */ + { 248, -6 }, /* (201) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + { 248, 0 }, /* (202) interval_option ::= */ + { 266, -1 }, /* (203) intervalKey ::= INTERVAL */ + { 266, -1 }, /* (204) intervalKey ::= EVERY */ + { 250, 0 }, /* (205) session_option ::= */ + { 250, -7 }, /* (206) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 251, 0 }, /* (207) windowstate_option ::= */ + { 251, -4 }, /* (208) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 252, 0 }, /* (209) fill_opt ::= */ + { 252, -6 }, /* (210) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 252, -4 }, /* (211) fill_opt ::= FILL LP ID RP */ + { 249, -4 }, /* (212) sliding_opt ::= SLIDING LP tmvar RP */ + { 249, 0 }, /* (213) sliding_opt ::= */ + { 255, 0 }, /* (214) orderby_opt ::= */ + { 255, -3 }, /* (215) orderby_opt ::= ORDER BY sortlist */ + { 267, -4 }, /* (216) sortlist ::= sortlist COMMA item sortorder */ + { 267, -2 }, /* (217) sortlist ::= item sortorder */ + { 269, -2 }, /* (218) item ::= ids cpxName */ + { 270, -1 }, /* (219) sortorder ::= ASC */ + { 270, -1 }, /* (220) sortorder ::= DESC */ + { 270, 0 }, /* (221) sortorder ::= */ + { 253, 0 }, /* (222) groupby_opt ::= */ + { 253, -3 }, /* (223) groupby_opt ::= GROUP BY grouplist */ + { 271, -3 }, /* (224) grouplist ::= grouplist COMMA item */ + { 271, -1 }, /* (225) grouplist ::= item */ + { 254, 0 }, /* (226) having_opt ::= */ + { 254, -2 }, /* (227) having_opt ::= HAVING expr */ + { 257, 0 }, /* (228) limit_opt ::= */ + { 257, -2 }, /* (229) limit_opt ::= LIMIT signed */ + { 257, -4 }, /* (230) limit_opt ::= LIMIT signed OFFSET signed */ + { 257, -4 }, /* (231) limit_opt ::= LIMIT signed COMMA signed */ + { 256, 0 }, /* (232) slimit_opt ::= */ + { 256, -2 }, /* (233) slimit_opt ::= SLIMIT signed */ + { 256, -4 }, /* (234) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 256, -4 }, /* (235) slimit_opt ::= SLIMIT signed COMMA signed */ + { 247, 0 }, /* (236) where_opt ::= */ + { 247, -2 }, /* (237) where_opt ::= WHERE expr */ + { 261, -3 }, /* (238) expr ::= LP expr RP */ + { 261, -1 }, /* (239) expr ::= ID */ + { 261, -3 }, /* (240) expr ::= ID DOT ID */ + { 261, -3 }, /* (241) expr ::= ID DOT STAR */ + { 261, -1 }, /* (242) expr ::= INTEGER */ + { 261, -2 }, /* (243) expr ::= MINUS INTEGER */ + { 261, -2 }, /* (244) expr ::= PLUS INTEGER */ + { 261, -1 }, /* (245) expr ::= FLOAT */ + { 261, -2 }, /* (246) expr ::= MINUS FLOAT */ + { 261, -2 }, /* (247) expr ::= PLUS FLOAT */ + { 261, -1 }, /* (248) expr ::= STRING */ + { 261, -1 }, /* (249) expr ::= NOW */ + { 261, -1 }, /* (250) expr ::= VARIABLE */ + { 261, -2 }, /* (251) expr ::= PLUS VARIABLE */ + { 261, -2 }, /* (252) expr ::= MINUS VARIABLE */ + { 261, -1 }, /* (253) expr ::= BOOL */ + { 261, -1 }, /* (254) expr ::= NULL */ + { 261, -4 }, /* (255) expr ::= ID LP exprlist RP */ + { 261, -4 }, /* (256) expr ::= ID LP STAR RP */ + { 261, -3 }, /* (257) expr ::= expr IS NULL */ + { 261, -4 }, /* (258) expr ::= expr IS NOT NULL */ + { 261, -3 }, /* (259) expr ::= expr LT expr */ + { 261, -3 }, /* (260) expr ::= expr GT expr */ + { 261, -3 }, /* (261) expr ::= expr LE expr */ + { 261, -3 }, /* (262) expr ::= expr GE expr */ + { 261, -3 }, /* (263) expr ::= expr NE expr */ + { 261, -3 }, /* (264) expr ::= expr EQ expr */ + { 261, -5 }, /* (265) expr ::= expr BETWEEN expr AND expr */ + { 261, -3 }, /* (266) expr ::= expr AND expr */ + { 261, -3 }, /* (267) expr ::= expr OR expr */ + { 261, -3 }, /* (268) expr ::= expr PLUS expr */ + { 261, -3 }, /* (269) expr ::= expr MINUS expr */ + { 261, -3 }, /* (270) expr ::= expr STAR expr */ + { 261, -3 }, /* (271) expr ::= expr SLASH expr */ + { 261, -3 }, /* (272) expr ::= expr REM expr */ + { 261, -3 }, /* (273) expr ::= expr LIKE expr */ + { 261, -3 }, /* (274) expr ::= expr MATCH expr */ + { 261, -3 }, /* (275) expr ::= expr NMATCH expr */ + { 261, -5 }, /* (276) expr ::= expr IN LP exprlist RP */ + { 200, -3 }, /* (277) exprlist ::= exprlist COMMA expritem */ + { 200, -1 }, /* (278) exprlist ::= expritem */ + { 272, -1 }, /* (279) expritem ::= expr */ + { 272, 0 }, /* (280) expritem ::= */ + { 193, -3 }, /* (281) cmd ::= RESET QUERY CACHE */ + { 193, -3 }, /* (282) cmd ::= SYNCDB ids REPLICA */ + { 193, -7 }, /* (283) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 193, -7 }, /* (284) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 193, -7 }, /* (285) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + { 193, -7 }, /* (286) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 193, -7 }, /* (287) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 193, -8 }, /* (288) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 193, -9 }, /* (289) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 193, -7 }, /* (290) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + { 193, -7 }, /* (291) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 193, -7 }, /* (292) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 193, -7 }, /* (293) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + { 193, -7 }, /* (294) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 193, -7 }, /* (295) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 193, -8 }, /* (296) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 193, -9 }, /* (297) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + { 193, -7 }, /* (298) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + { 193, -3 }, /* (299) cmd ::= KILL CONNECTION INTEGER */ + { 193, -5 }, /* (300) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 193, -5 }, /* (301) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2224,9 +2220,9 @@ static void yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ - case 135: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==135); - case 136: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==136); - case 137: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==137); + case 134: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==134); + case 135: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==135); + case 136: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==136); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -2414,65 +2410,64 @@ static void yy_reduce( { setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy165);} break; case 51: /* ids ::= ID */ - case 52: /* ids ::= STRING */ yytestcase(yyruleno==52); {yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 53: /* ifexists ::= IF EXISTS */ + case 52: /* ifexists ::= IF EXISTS */ { yymsp[-1].minor.yy0.n = 1;} break; - case 54: /* ifexists ::= */ - case 56: /* ifnotexists ::= */ yytestcase(yyruleno==56); - case 190: /* distinct ::= */ yytestcase(yyruleno==190); + case 53: /* ifexists ::= */ + case 55: /* ifnotexists ::= */ yytestcase(yyruleno==55); + case 189: /* distinct ::= */ yytestcase(yyruleno==189); { yymsp[1].minor.yy0.n = 0;} break; - case 55: /* ifnotexists ::= IF NOT EXISTS */ + case 54: /* ifnotexists ::= IF NOT EXISTS */ { yymsp[-2].minor.yy0.n = 1;} break; - case 57: /* cmd ::= CREATE DNODE ids PORT ids */ - case 58: /* cmd ::= CREATE DNODE IPTOKEN PORT ids */ yytestcase(yyruleno==58); + case 56: /* cmd ::= CREATE DNODE ids PORT ids */ + case 57: /* cmd ::= CREATE DNODE IPTOKEN PORT ids */ yytestcase(yyruleno==57); { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 2, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 59: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + case 58: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ { setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy211);} break; - case 60: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + case 59: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy16, &yymsp[-2].minor.yy0);} break; - case 61: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + case 60: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy106, &yymsp[0].minor.yy0, 1);} break; - case 62: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + case 61: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy106, &yymsp[0].minor.yy0, 2);} break; - case 63: /* cmd ::= CREATE USER ids PASS ids */ + case 62: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 64: /* bufsize ::= */ - case 66: /* pps ::= */ yytestcase(yyruleno==66); - case 68: /* tseries ::= */ yytestcase(yyruleno==68); - case 70: /* dbs ::= */ yytestcase(yyruleno==70); - case 72: /* streams ::= */ yytestcase(yyruleno==72); - case 74: /* storage ::= */ yytestcase(yyruleno==74); - case 76: /* qtime ::= */ yytestcase(yyruleno==76); - case 78: /* users ::= */ yytestcase(yyruleno==78); - case 80: /* conns ::= */ yytestcase(yyruleno==80); - case 82: /* state ::= */ yytestcase(yyruleno==82); + case 63: /* bufsize ::= */ + case 65: /* pps ::= */ yytestcase(yyruleno==65); + case 67: /* tseries ::= */ yytestcase(yyruleno==67); + case 69: /* dbs ::= */ yytestcase(yyruleno==69); + case 71: /* streams ::= */ yytestcase(yyruleno==71); + case 73: /* storage ::= */ yytestcase(yyruleno==73); + case 75: /* qtime ::= */ yytestcase(yyruleno==75); + case 77: /* users ::= */ yytestcase(yyruleno==77); + case 79: /* conns ::= */ yytestcase(yyruleno==79); + case 81: /* state ::= */ yytestcase(yyruleno==81); { yymsp[1].minor.yy0.n = 0; } break; - case 65: /* bufsize ::= BUFSIZE INTEGER */ - case 67: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==67); - case 69: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==69); - case 71: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==71); - case 73: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==73); - case 75: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==75); - case 77: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==77); - case 79: /* users ::= USERS INTEGER */ yytestcase(yyruleno==79); - case 81: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==81); - case 83: /* state ::= STATE ids */ yytestcase(yyruleno==83); + case 64: /* bufsize ::= BUFSIZE INTEGER */ + case 66: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==66); + case 68: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==68); + case 70: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==70); + case 72: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==72); + case 74: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==74); + case 76: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==76); + case 78: /* users ::= USERS INTEGER */ yytestcase(yyruleno==78); + case 80: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==80); + case 82: /* state ::= STATE ids */ yytestcase(yyruleno==82); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 84: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + case 83: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { yylhsminor.yy211.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; yylhsminor.yy211.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; @@ -2486,129 +2481,129 @@ static void yy_reduce( } yymsp[-8].minor.yy211 = yylhsminor.yy211; break; - case 85: /* intitemlist ::= intitemlist COMMA intitem */ - case 163: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==163); + case 84: /* intitemlist ::= intitemlist COMMA intitem */ + case 162: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==162); { yylhsminor.yy165 = tListItemAppend(yymsp[-2].minor.yy165, &yymsp[0].minor.yy425, -1); } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 86: /* intitemlist ::= intitem */ - case 164: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==164); + case 85: /* intitemlist ::= intitem */ + case 163: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==163); { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[0].minor.yy425, -1); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 87: /* intitem ::= INTEGER */ - case 165: /* tagitem ::= INTEGER */ yytestcase(yyruleno==165); - case 166: /* tagitem ::= FLOAT */ yytestcase(yyruleno==166); - case 167: /* tagitem ::= STRING */ yytestcase(yyruleno==167); - case 168: /* tagitem ::= BOOL */ yytestcase(yyruleno==168); + case 86: /* intitem ::= INTEGER */ + case 164: /* tagitem ::= INTEGER */ yytestcase(yyruleno==164); + case 165: /* tagitem ::= FLOAT */ yytestcase(yyruleno==165); + case 166: /* tagitem ::= STRING */ yytestcase(yyruleno==166); + case 167: /* tagitem ::= BOOL */ yytestcase(yyruleno==167); { toTSDBType(yymsp[0].minor.yy0.type); taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 88: /* keep ::= KEEP intitemlist */ + case 87: /* keep ::= KEEP intitemlist */ { yymsp[-1].minor.yy165 = yymsp[0].minor.yy165; } break; - case 89: /* cache ::= CACHE INTEGER */ - case 90: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==90); - case 91: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==91); - case 92: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==92); - case 93: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==93); - case 94: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==94); - case 95: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==95); - case 96: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==96); - case 97: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==97); - case 98: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==98); - case 99: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==99); - case 100: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==100); - case 101: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==101); - case 102: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==102); - case 103: /* vgroups ::= VGROUPS INTEGER */ yytestcase(yyruleno==103); + case 88: /* cache ::= CACHE INTEGER */ + case 89: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==89); + case 90: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==90); + case 91: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==91); + case 92: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==92); + case 93: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==93); + case 94: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==94); + case 95: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==95); + case 96: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==96); + case 97: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==97); + case 98: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==98); + case 99: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==99); + case 100: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==100); + case 101: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==101); + case 102: /* vgroups ::= VGROUPS INTEGER */ yytestcase(yyruleno==102); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 104: /* db_optr ::= */ + case 103: /* db_optr ::= */ {setDefaultCreateDbOption(&yymsp[1].minor.yy16);} break; - case 105: /* db_optr ::= db_optr cache */ + case 104: /* db_optr ::= db_optr cache */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 106: /* db_optr ::= db_optr replica */ - case 122: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==122); + case 105: /* db_optr ::= db_optr replica */ + case 121: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==121); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 107: /* db_optr ::= db_optr quorum */ - case 123: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==123); + case 106: /* db_optr ::= db_optr quorum */ + case 122: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==122); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 108: /* db_optr ::= db_optr days */ + case 107: /* db_optr ::= db_optr days */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 109: /* db_optr ::= db_optr minrows */ + case 108: /* db_optr ::= db_optr minrows */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 110: /* db_optr ::= db_optr maxrows */ + case 109: /* db_optr ::= db_optr maxrows */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 111: /* db_optr ::= db_optr blocks */ - case 125: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==125); + case 110: /* db_optr ::= db_optr blocks */ + case 124: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==124); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 112: /* db_optr ::= db_optr ctime */ + case 111: /* db_optr ::= db_optr ctime */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 113: /* db_optr ::= db_optr wal */ + case 112: /* db_optr ::= db_optr wal */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 114: /* db_optr ::= db_optr fsync */ + case 113: /* db_optr ::= db_optr fsync */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 115: /* db_optr ::= db_optr comp */ - case 126: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==126); + case 114: /* db_optr ::= db_optr comp */ + case 125: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==125); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 116: /* db_optr ::= db_optr prec */ + case 115: /* db_optr ::= db_optr prec */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.precision = yymsp[0].minor.yy0; } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 117: /* db_optr ::= db_optr keep */ - case 124: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==124); + case 116: /* db_optr ::= db_optr keep */ + case 123: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==123); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.keep = yymsp[0].minor.yy165; } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 118: /* db_optr ::= db_optr update */ - case 127: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==127); + case 117: /* db_optr ::= db_optr update */ + case 126: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==126); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 119: /* db_optr ::= db_optr cachelast */ - case 128: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==128); + case 118: /* db_optr ::= db_optr cachelast */ + case 127: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==127); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 120: /* db_optr ::= db_optr vgroups */ + case 119: /* db_optr ::= db_optr vgroups */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.numOfVgroups = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 121: /* alter_db_optr ::= */ + case 120: /* alter_db_optr ::= */ { setDefaultCreateDbOption(&yymsp[1].minor.yy16);} break; - case 129: /* typename ::= ids */ + case 128: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; tSetColumnType (&yylhsminor.yy106, &yymsp[0].minor.yy0); } yymsp[0].minor.yy106 = yylhsminor.yy106; break; - case 130: /* typename ::= ids LP signed RP */ + case 129: /* typename ::= ids LP signed RP */ { if (yymsp[-1].minor.yy207 <= 0) { yymsp[-3].minor.yy0.type = 0; @@ -2620,7 +2615,7 @@ static void yy_reduce( } yymsp[-3].minor.yy106 = yylhsminor.yy106; break; - case 131: /* typename ::= ids UNSIGNED */ + case 130: /* typename ::= ids UNSIGNED */ { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); @@ -2628,20 +2623,20 @@ static void yy_reduce( } yymsp[-1].minor.yy106 = yylhsminor.yy106; break; - case 132: /* signed ::= INTEGER */ + case 131: /* signed ::= INTEGER */ { yylhsminor.yy207 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[0].minor.yy207 = yylhsminor.yy207; break; - case 133: /* signed ::= PLUS INTEGER */ + case 132: /* signed ::= PLUS INTEGER */ { yymsp[-1].minor.yy207 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 134: /* signed ::= MINUS INTEGER */ + case 133: /* signed ::= MINUS INTEGER */ { yymsp[-1].minor.yy207 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; - case 138: /* cmd ::= CREATE TABLE create_table_list */ + case 137: /* cmd ::= CREATE TABLE create_table_list */ { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy326;} break; - case 139: /* create_table_list ::= create_from_stable */ + case 138: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); @@ -2652,14 +2647,14 @@ static void yy_reduce( } yymsp[0].minor.yy326 = yylhsminor.yy326; break; - case 140: /* create_table_list ::= create_table_list create_from_stable */ + case 139: /* create_table_list ::= create_table_list create_from_stable */ { taosArrayPush(yymsp[-1].minor.yy326->childTableInfo, &yymsp[0].minor.yy150); yylhsminor.yy326 = yymsp[-1].minor.yy326; } yymsp[-1].minor.yy326 = yylhsminor.yy326; break; - case 141: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + case 140: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-1].minor.yy165, NULL, NULL, TSQL_CREATE_TABLE); setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); @@ -2669,17 +2664,17 @@ static void yy_reduce( } yymsp[-5].minor.yy326 = yylhsminor.yy326; break; - case 142: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + case 141: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-5].minor.yy165, yymsp[-1].minor.yy165, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_STABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } yymsp[-9].minor.yy326 = yylhsminor.yy326; break; - case 143: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ + case 142: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; @@ -2687,7 +2682,7 @@ static void yy_reduce( } yymsp[-9].minor.yy150 = yylhsminor.yy150; break; - case 144: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ + case 143: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; @@ -2695,15 +2690,15 @@ static void yy_reduce( } yymsp[-12].minor.yy150 = yylhsminor.yy150; break; - case 145: /* tagNamelist ::= tagNamelist COMMA ids */ + case 144: /* tagNamelist ::= tagNamelist COMMA ids */ {taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy0); yylhsminor.yy165 = yymsp[-2].minor.yy165; } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 146: /* tagNamelist ::= ids */ + case 145: /* tagNamelist ::= ids */ {yylhsminor.yy165 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy0);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 147: /* create_table_args ::= ifnotexists ids cpxName AS select */ + case 146: /* create_table_args ::= ifnotexists ids cpxName AS select */ { yylhsminor.yy326 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy278, TSQL_CREATE_STREAM); setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); @@ -2713,56 +2708,56 @@ static void yy_reduce( } yymsp[-4].minor.yy326 = yylhsminor.yy326; break; - case 148: /* columnlist ::= columnlist COMMA column */ + case 147: /* columnlist ::= columnlist COMMA column */ {taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy106); yylhsminor.yy165 = yymsp[-2].minor.yy165; } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 149: /* columnlist ::= column */ + case 148: /* columnlist ::= column */ {yylhsminor.yy165 = taosArrayInit(4, sizeof(SField)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy106);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 150: /* column ::= ids typename */ + case 149: /* column ::= ids typename */ { tSetColumnInfo(&yylhsminor.yy106, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy106); } yymsp[-1].minor.yy106 = yylhsminor.yy106; break; - case 151: /* tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ + case 150: /* tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ { taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy0); yylhsminor.yy165 = yymsp[-2].minor.yy165;} yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 152: /* tagitemlist1 ::= tagitem1 */ + case 151: /* tagitemlist1 ::= tagitem1 */ { yylhsminor.yy165 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy0); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 153: /* tagitem1 ::= MINUS INTEGER */ - case 154: /* tagitem1 ::= MINUS FLOAT */ yytestcase(yyruleno==154); - case 155: /* tagitem1 ::= PLUS INTEGER */ yytestcase(yyruleno==155); - case 156: /* tagitem1 ::= PLUS FLOAT */ yytestcase(yyruleno==156); + case 152: /* tagitem1 ::= MINUS INTEGER */ + case 153: /* tagitem1 ::= MINUS FLOAT */ yytestcase(yyruleno==153); + case 154: /* tagitem1 ::= PLUS INTEGER */ yytestcase(yyruleno==154); + case 155: /* tagitem1 ::= PLUS FLOAT */ yytestcase(yyruleno==155); { yylhsminor.yy0.n = yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n; yylhsminor.yy0.type = yymsp[0].minor.yy0.type; } yymsp[-1].minor.yy0 = yylhsminor.yy0; break; - case 157: /* tagitem1 ::= INTEGER */ - case 158: /* tagitem1 ::= FLOAT */ yytestcase(yyruleno==158); - case 159: /* tagitem1 ::= STRING */ yytestcase(yyruleno==159); - case 160: /* tagitem1 ::= BOOL */ yytestcase(yyruleno==160); - case 161: /* tagitem1 ::= NULL */ yytestcase(yyruleno==161); - case 162: /* tagitem1 ::= NOW */ yytestcase(yyruleno==162); + case 156: /* tagitem1 ::= INTEGER */ + case 157: /* tagitem1 ::= FLOAT */ yytestcase(yyruleno==157); + case 158: /* tagitem1 ::= STRING */ yytestcase(yyruleno==158); + case 159: /* tagitem1 ::= BOOL */ yytestcase(yyruleno==159); + case 160: /* tagitem1 ::= NULL */ yytestcase(yyruleno==160); + case 161: /* tagitem1 ::= NOW */ yytestcase(yyruleno==161); { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 169: /* tagitem ::= NULL */ + case 168: /* tagitem ::= NULL */ { yymsp[0].minor.yy0.type = 0; taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 170: /* tagitem ::= NOW */ + case 169: /* tagitem ::= NOW */ { yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type);} yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 171: /* tagitem ::= MINUS INTEGER */ - case 172: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==172); - case 173: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==173); - case 174: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==174); + case 170: /* tagitem ::= MINUS INTEGER */ + case 171: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==171); + case 172: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==172); + case 173: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==173); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; @@ -2771,154 +2766,154 @@ static void yy_reduce( } yymsp[-1].minor.yy425 = yylhsminor.yy425; break; - case 175: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + case 174: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ { yylhsminor.yy278 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy165, yymsp[-11].minor.yy10, yymsp[-10].minor.yy202, yymsp[-4].minor.yy165, yymsp[-2].minor.yy165, &yymsp[-9].minor.yy532, &yymsp[-7].minor.yy97, &yymsp[-6].minor.yy6, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy165, &yymsp[0].minor.yy367, &yymsp[-1].minor.yy367, yymsp[-3].minor.yy202); } yymsp[-13].minor.yy278 = yylhsminor.yy278; break; - case 176: /* select ::= LP select RP */ + case 175: /* select ::= LP select RP */ {yymsp[-2].minor.yy278 = yymsp[-1].minor.yy278;} break; - case 177: /* union ::= select */ + case 176: /* union ::= select */ { yylhsminor.yy503 = setSubclause(NULL, yymsp[0].minor.yy278); } yymsp[0].minor.yy503 = yylhsminor.yy503; break; - case 178: /* union ::= union UNION ALL select */ + case 177: /* union ::= union UNION ALL select */ { yylhsminor.yy503 = appendSelectClause(yymsp[-3].minor.yy503, SQL_TYPE_UNIONALL, yymsp[0].minor.yy278); } yymsp[-3].minor.yy503 = yylhsminor.yy503; break; - case 179: /* union ::= union UNION select */ + case 178: /* union ::= union UNION select */ { yylhsminor.yy503 = appendSelectClause(yymsp[-2].minor.yy503, SQL_TYPE_UNION, yymsp[0].minor.yy278); } yymsp[-2].minor.yy503 = yylhsminor.yy503; break; - case 180: /* cmd ::= union */ + case 179: /* cmd ::= union */ { setSqlInfo(pInfo, yymsp[0].minor.yy503, NULL, TSDB_SQL_SELECT); } break; - case 181: /* select ::= SELECT selcollist */ + case 180: /* select ::= SELECT selcollist */ { yylhsminor.yy278 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy165, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } yymsp[-1].minor.yy278 = yylhsminor.yy278; break; - case 182: /* sclp ::= selcollist COMMA */ + case 181: /* sclp ::= selcollist COMMA */ {yylhsminor.yy165 = yymsp[-1].minor.yy165;} yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 183: /* sclp ::= */ - case 215: /* orderby_opt ::= */ yytestcase(yyruleno==215); + case 182: /* sclp ::= */ + case 214: /* orderby_opt ::= */ yytestcase(yyruleno==214); {yymsp[1].minor.yy165 = 0;} break; - case 184: /* selcollist ::= sclp distinct expr as */ + case 183: /* selcollist ::= sclp distinct expr as */ { yylhsminor.yy165 = tSqlExprListAppend(yymsp[-3].minor.yy165, yymsp[-1].minor.yy202, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } yymsp[-3].minor.yy165 = yylhsminor.yy165; break; - case 185: /* selcollist ::= sclp STAR */ + case 184: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); yylhsminor.yy165 = tSqlExprListAppend(yymsp[-1].minor.yy165, pNode, 0, 0); } yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 186: /* as ::= AS ids */ + case 185: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 187: /* as ::= ids */ + case 186: /* as ::= ids */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 188: /* as ::= */ + case 187: /* as ::= */ { yymsp[1].minor.yy0.n = 0; } break; - case 189: /* distinct ::= DISTINCT */ + case 188: /* distinct ::= DISTINCT */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 191: /* from ::= FROM tablelist */ - case 192: /* from ::= FROM sub */ yytestcase(yyruleno==192); + case 190: /* from ::= FROM tablelist */ + case 191: /* from ::= FROM sub */ yytestcase(yyruleno==191); {yymsp[-1].minor.yy10 = yymsp[0].minor.yy10;} break; - case 193: /* sub ::= LP union RP */ + case 192: /* sub ::= LP union RP */ {yymsp[-2].minor.yy10 = addSubquery(NULL, yymsp[-1].minor.yy503, NULL);} break; - case 194: /* sub ::= LP union RP ids */ + case 193: /* sub ::= LP union RP ids */ {yymsp[-3].minor.yy10 = addSubquery(NULL, yymsp[-2].minor.yy503, &yymsp[0].minor.yy0);} break; - case 195: /* sub ::= sub COMMA LP union RP ids */ + case 194: /* sub ::= sub COMMA LP union RP ids */ {yylhsminor.yy10 = addSubquery(yymsp[-5].minor.yy10, yymsp[-2].minor.yy503, &yymsp[0].minor.yy0);} yymsp[-5].minor.yy10 = yylhsminor.yy10; break; - case 196: /* tablelist ::= ids cpxName */ + case 195: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy10 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } yymsp[-1].minor.yy10 = yylhsminor.yy10; break; - case 197: /* tablelist ::= ids cpxName ids */ + case 196: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yylhsminor.yy10 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy10 = yylhsminor.yy10; break; - case 198: /* tablelist ::= tablelist COMMA ids cpxName */ + case 197: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy10 = setTableNameList(yymsp[-3].minor.yy10, &yymsp[-1].minor.yy0, NULL); } yymsp[-3].minor.yy10 = yylhsminor.yy10; break; - case 199: /* tablelist ::= tablelist COMMA ids cpxName ids */ + case 198: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yylhsminor.yy10 = setTableNameList(yymsp[-4].minor.yy10, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } yymsp[-4].minor.yy10 = yylhsminor.yy10; break; - case 200: /* tmvar ::= VARIABLE */ + case 199: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 201: /* interval_option ::= intervalKey LP tmvar RP */ + case 200: /* interval_option ::= intervalKey LP tmvar RP */ {yylhsminor.yy532.interval = yymsp[-1].minor.yy0; yylhsminor.yy532.offset.n = 0; yylhsminor.yy532.token = yymsp[-3].minor.yy46;} yymsp[-3].minor.yy532 = yylhsminor.yy532; break; - case 202: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + case 201: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ {yylhsminor.yy532.interval = yymsp[-3].minor.yy0; yylhsminor.yy532.offset = yymsp[-1].minor.yy0; yylhsminor.yy532.token = yymsp[-5].minor.yy46;} yymsp[-5].minor.yy532 = yylhsminor.yy532; break; - case 203: /* interval_option ::= */ + case 202: /* interval_option ::= */ {memset(&yymsp[1].minor.yy532, 0, sizeof(yymsp[1].minor.yy532));} break; - case 204: /* intervalKey ::= INTERVAL */ + case 203: /* intervalKey ::= INTERVAL */ {yymsp[0].minor.yy46 = TK_INTERVAL;} break; - case 205: /* intervalKey ::= EVERY */ + case 204: /* intervalKey ::= EVERY */ {yymsp[0].minor.yy46 = TK_EVERY; } break; - case 206: /* session_option ::= */ + case 205: /* session_option ::= */ {yymsp[1].minor.yy97.col.n = 0; yymsp[1].minor.yy97.gap.n = 0;} break; - case 207: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 206: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-6].minor.yy97.col = yymsp[-4].minor.yy0; yymsp[-6].minor.yy97.gap = yymsp[-1].minor.yy0; } break; - case 208: /* windowstate_option ::= */ + case 207: /* windowstate_option ::= */ { yymsp[1].minor.yy6.col.n = 0; yymsp[1].minor.yy6.col.z = NULL;} break; - case 209: /* windowstate_option ::= STATE_WINDOW LP ids RP */ + case 208: /* windowstate_option ::= STATE_WINDOW LP ids RP */ { yymsp[-3].minor.yy6.col = yymsp[-1].minor.yy0; } break; - case 210: /* fill_opt ::= */ + case 209: /* fill_opt ::= */ { yymsp[1].minor.yy165 = 0; } break; - case 211: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 210: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { SVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); @@ -2928,34 +2923,34 @@ static void yy_reduce( yymsp[-5].minor.yy165 = yymsp[-1].minor.yy165; } break; - case 212: /* fill_opt ::= FILL LP ID RP */ + case 211: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-3].minor.yy165 = tListItemAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 213: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 212: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 214: /* sliding_opt ::= */ + case 213: /* sliding_opt ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 216: /* orderby_opt ::= ORDER BY sortlist */ + case 215: /* orderby_opt ::= ORDER BY sortlist */ {yymsp[-2].minor.yy165 = yymsp[0].minor.yy165;} break; - case 217: /* sortlist ::= sortlist COMMA item sortorder */ + case 216: /* sortlist ::= sortlist COMMA item sortorder */ { yylhsminor.yy165 = tListItemAppend(yymsp[-3].minor.yy165, &yymsp[-1].minor.yy425, yymsp[0].minor.yy47); } yymsp[-3].minor.yy165 = yylhsminor.yy165; break; - case 218: /* sortlist ::= item sortorder */ + case 217: /* sortlist ::= item sortorder */ { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[-1].minor.yy425, yymsp[0].minor.yy47); } yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 219: /* item ::= ids cpxName */ + case 218: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; @@ -2964,235 +2959,235 @@ static void yy_reduce( } yymsp[-1].minor.yy425 = yylhsminor.yy425; break; - case 220: /* sortorder ::= ASC */ + case 219: /* sortorder ::= ASC */ { yymsp[0].minor.yy47 = TSDB_ORDER_ASC; } break; - case 221: /* sortorder ::= DESC */ + case 220: /* sortorder ::= DESC */ { yymsp[0].minor.yy47 = TSDB_ORDER_DESC;} break; - case 222: /* sortorder ::= */ + case 221: /* sortorder ::= */ { yymsp[1].minor.yy47 = TSDB_ORDER_ASC; } break; - case 223: /* groupby_opt ::= */ + case 222: /* groupby_opt ::= */ { yymsp[1].minor.yy165 = 0;} break; - case 224: /* groupby_opt ::= GROUP BY grouplist */ + case 223: /* groupby_opt ::= GROUP BY grouplist */ { yymsp[-2].minor.yy165 = yymsp[0].minor.yy165;} break; - case 225: /* grouplist ::= grouplist COMMA item */ + case 224: /* grouplist ::= grouplist COMMA item */ { yylhsminor.yy165 = tListItemAppend(yymsp[-2].minor.yy165, &yymsp[0].minor.yy425, -1); } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 226: /* grouplist ::= item */ + case 225: /* grouplist ::= item */ { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[0].minor.yy425, -1); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 227: /* having_opt ::= */ - case 237: /* where_opt ::= */ yytestcase(yyruleno==237); - case 281: /* expritem ::= */ yytestcase(yyruleno==281); + case 226: /* having_opt ::= */ + case 236: /* where_opt ::= */ yytestcase(yyruleno==236); + case 280: /* expritem ::= */ yytestcase(yyruleno==280); {yymsp[1].minor.yy202 = 0;} break; - case 228: /* having_opt ::= HAVING expr */ - case 238: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==238); + case 227: /* having_opt ::= HAVING expr */ + case 237: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==237); {yymsp[-1].minor.yy202 = yymsp[0].minor.yy202;} break; - case 229: /* limit_opt ::= */ - case 233: /* slimit_opt ::= */ yytestcase(yyruleno==233); + case 228: /* limit_opt ::= */ + case 232: /* slimit_opt ::= */ yytestcase(yyruleno==232); {yymsp[1].minor.yy367.limit = -1; yymsp[1].minor.yy367.offset = 0;} break; - case 230: /* limit_opt ::= LIMIT signed */ - case 234: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==234); + case 229: /* limit_opt ::= LIMIT signed */ + case 233: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==233); {yymsp[-1].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-1].minor.yy367.offset = 0;} break; - case 231: /* limit_opt ::= LIMIT signed OFFSET signed */ + case 230: /* limit_opt ::= LIMIT signed OFFSET signed */ { yymsp[-3].minor.yy367.limit = yymsp[-2].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[0].minor.yy207;} break; - case 232: /* limit_opt ::= LIMIT signed COMMA signed */ + case 231: /* limit_opt ::= LIMIT signed COMMA signed */ { yymsp[-3].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[-2].minor.yy207;} break; - case 235: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ + case 234: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ {yymsp[-3].minor.yy367.limit = yymsp[-2].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[0].minor.yy207;} break; - case 236: /* slimit_opt ::= SLIMIT signed COMMA signed */ + case 235: /* slimit_opt ::= SLIMIT signed COMMA signed */ {yymsp[-3].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[-2].minor.yy207;} break; - case 239: /* expr ::= LP expr RP */ + case 238: /* expr ::= LP expr RP */ {yylhsminor.yy202 = yymsp[-1].minor.yy202; yylhsminor.yy202->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy202->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 240: /* expr ::= ID */ + case 239: /* expr ::= ID */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 241: /* expr ::= ID DOT ID */ + case 240: /* expr ::= ID DOT ID */ { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 242: /* expr ::= ID DOT STAR */ + case 241: /* expr ::= ID DOT STAR */ { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 243: /* expr ::= INTEGER */ + case 242: /* expr ::= INTEGER */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 244: /* expr ::= MINUS INTEGER */ - case 245: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==245); + case 243: /* expr ::= MINUS INTEGER */ + case 244: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==244); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 246: /* expr ::= FLOAT */ + case 245: /* expr ::= FLOAT */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 247: /* expr ::= MINUS FLOAT */ - case 248: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==248); + case 246: /* expr ::= MINUS FLOAT */ + case 247: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==247); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 249: /* expr ::= STRING */ + case 248: /* expr ::= STRING */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 250: /* expr ::= NOW */ + case 249: /* expr ::= NOW */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 251: /* expr ::= VARIABLE */ + case 250: /* expr ::= VARIABLE */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 252: /* expr ::= PLUS VARIABLE */ - case 253: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==253); + case 251: /* expr ::= PLUS VARIABLE */ + case 252: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==252); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 254: /* expr ::= BOOL */ + case 253: /* expr ::= BOOL */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 255: /* expr ::= NULL */ + case 254: /* expr ::= NULL */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 256: /* expr ::= ID LP exprlist RP */ + case 255: /* expr ::= ID LP exprlist RP */ { tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy202 = tSqlExprCreateFunction(yymsp[-1].minor.yy165, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 257: /* expr ::= ID LP STAR RP */ + case 256: /* expr ::= ID LP STAR RP */ { tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy202 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 258: /* expr ::= expr IS NULL */ + case 257: /* expr ::= expr IS NULL */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, NULL, TK_ISNULL);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 259: /* expr ::= expr IS NOT NULL */ + case 258: /* expr ::= expr IS NOT NULL */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-3].minor.yy202, NULL, TK_NOTNULL);} yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 260: /* expr ::= expr LT expr */ + case 259: /* expr ::= expr LT expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LT);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 261: /* expr ::= expr GT expr */ + case 260: /* expr ::= expr GT expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_GT);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 262: /* expr ::= expr LE expr */ + case 261: /* expr ::= expr LE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 263: /* expr ::= expr GE expr */ + case 262: /* expr ::= expr GE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_GE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 264: /* expr ::= expr NE expr */ + case 263: /* expr ::= expr NE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_NE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 265: /* expr ::= expr EQ expr */ + case 264: /* expr ::= expr EQ expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_EQ);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 266: /* expr ::= expr BETWEEN expr AND expr */ + case 265: /* expr ::= expr BETWEEN expr AND expr */ { tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy202); yylhsminor.yy202 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy202, yymsp[-2].minor.yy202, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy202, TK_LE), TK_AND);} yymsp[-4].minor.yy202 = yylhsminor.yy202; break; - case 267: /* expr ::= expr AND expr */ + case 266: /* expr ::= expr AND expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_AND);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 268: /* expr ::= expr OR expr */ + case 267: /* expr ::= expr OR expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_OR); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 269: /* expr ::= expr PLUS expr */ + case 268: /* expr ::= expr PLUS expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_PLUS); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 270: /* expr ::= expr MINUS expr */ + case 269: /* expr ::= expr MINUS expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_MINUS); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 271: /* expr ::= expr STAR expr */ + case 270: /* expr ::= expr STAR expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_STAR); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 272: /* expr ::= expr SLASH expr */ + case 271: /* expr ::= expr SLASH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_DIVIDE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 273: /* expr ::= expr REM expr */ + case 272: /* expr ::= expr REM expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_REM); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 274: /* expr ::= expr LIKE expr */ + case 273: /* expr ::= expr LIKE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LIKE); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 275: /* expr ::= expr MATCH expr */ + case 274: /* expr ::= expr MATCH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_MATCH); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 276: /* expr ::= expr NMATCH expr */ + case 275: /* expr ::= expr NMATCH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_NMATCH); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 277: /* expr ::= expr IN LP exprlist RP */ + case 276: /* expr ::= expr IN LP exprlist RP */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-4].minor.yy202, (tSqlExpr*)yymsp[-1].minor.yy165, TK_IN); } yymsp[-4].minor.yy202 = yylhsminor.yy202; break; - case 278: /* exprlist ::= exprlist COMMA expritem */ + case 277: /* exprlist ::= exprlist COMMA expritem */ {yylhsminor.yy165 = tSqlExprListAppend(yymsp[-2].minor.yy165,yymsp[0].minor.yy202,0, 0);} yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 279: /* exprlist ::= expritem */ + case 278: /* exprlist ::= expritem */ {yylhsminor.yy165 = tSqlExprListAppend(0,yymsp[0].minor.yy202,0, 0);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 280: /* expritem ::= expr */ + case 279: /* expritem ::= expr */ {yylhsminor.yy202 = yymsp[0].minor.yy202;} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 282: /* cmd ::= RESET QUERY CACHE */ + case 281: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 283: /* cmd ::= SYNCDB ids REPLICA */ + case 282: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 284: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 283: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 285: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 284: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; toTSDBType(yymsp[0].minor.yy0.type); @@ -3201,21 +3196,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 286: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + case 285: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 287: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 286: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 288: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 287: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3226,7 +3221,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 289: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 288: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3240,7 +3235,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 290: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 289: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3252,21 +3247,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 291: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + case 290: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 292: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 291: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 293: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 292: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3277,21 +3272,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 294: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + case 293: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 295: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 294: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 296: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 295: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3302,7 +3297,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 297: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 296: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3316,7 +3311,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 298: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + case 297: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3328,20 +3323,20 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 299: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + case 298: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 300: /* cmd ::= KILL CONNECTION INTEGER */ + case 299: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 301: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 300: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 302: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 301: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index a68102ea6e..4b248f90e7 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -70,6 +70,11 @@ typedef struct SQueryPlanNode { struct SQueryPlanNode *pParent; } SQueryPlanNode; +typedef struct SDataPayloadInfo { + int32_t msgType; + SArray *payload; +} SDataPayloadInfo; + /** * Optimize the query execution plan, currently not implement yet. * @param pQueryNode diff --git a/source/libs/planner/src/logicPlan.c b/source/libs/planner/src/logicPlan.c index 5f95f86d4a..2de0ae2da3 100644 --- a/source/libs/planner/src/logicPlan.c +++ b/source/libs/planner/src/logicPlan.c @@ -37,18 +37,28 @@ int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode) { return 0; } -static int32_t createInsertPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { +static int32_t createModificationOpPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { SInsertStmtInfo* pInsert = (SInsertStmtInfo*)pNode; *pQueryPlan = calloc(1, sizeof(SQueryPlanNode)); SArray* blocks = taosArrayInit(taosArrayGetSize(pInsert->pDataBlocks), POINTER_BYTES); - if (NULL == *pQueryPlan || NULL == blocks) { + + SDataPayloadInfo* pPayload = calloc(1, sizeof(SDataPayloadInfo)); + if (NULL == *pQueryPlan || NULL == blocks || NULL == pPayload) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } (*pQueryPlan)->info.type = QNODE_MODIFY; taosArrayAddAll(blocks, pInsert->pDataBlocks); - (*pQueryPlan)->pExtInfo = blocks; + + if (pNode->type == TSDB_SQL_INSERT) { + pPayload->msgType = TDMT_VND_SUBMIT; + } else if (pNode->type == TSDB_SQL_CREATE_TABLE) { + pPayload->msgType = TDMT_VND_CREATE_TABLE; + } + + pPayload->payload = blocks; + (*pQueryPlan)->pExtInfo = pPayload; return TSDB_CODE_SUCCESS; } @@ -69,7 +79,7 @@ int32_t createQueryPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { case TSDB_SQL_INSERT: case TSDB_SQL_CREATE_TABLE: - return createInsertPlan(pNode, pQueryPlan); + return createModificationOpPlan(pNode, pQueryPlan); default: return TSDB_CODE_FAILED; diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 978b1554f3..9e1eea2b35 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -191,13 +191,15 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { subplan->level = 0; if (NULL != pCxt->pCurrentSubplan) { subplan->level = pCxt->pCurrentSubplan->level + 1; - if (NULL == pCxt->pCurrentSubplan->pChildern) { - pCxt->pCurrentSubplan->pChildern = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); + if (NULL == pCxt->pCurrentSubplan->pChildren) { + pCxt->pCurrentSubplan->pChildren = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); } - taosArrayPush(pCxt->pCurrentSubplan->pChildern, &subplan); + + taosArrayPush(pCxt->pCurrentSubplan->pChildren, &subplan); subplan->pParents = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); taosArrayPush(subplan->pParents, &pCxt->pCurrentSubplan); } + SArray* currentLevel; if (subplan->level >= taosArrayGetSize(pCxt->pDag->pSubplans)) { currentLevel = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); @@ -205,6 +207,7 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { } else { currentLevel = taosArrayGetP(pCxt->pDag->pSubplans, subplan->level); } + taosArrayPush(currentLevel, &subplan); pCxt->pCurrentSubplan = subplan; ++(pCxt->pDag->numOfSubplans); @@ -290,24 +293,28 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { return node; } -static void splitInsertSubplan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { - SArray* vgs = (SArray*)pPlanNode->pExtInfo; - size_t numOfVg = taosArrayGetSize(vgs); - for (int32_t i = 0; i < numOfVg; ++i) { +static void splitModificationOpSubPlan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { + SDataPayloadInfo* pPayload = (SDataPayloadInfo*) pPlanNode->pExtInfo; + + size_t numOfVgroups = taosArrayGetSize(pPayload->payload); + for (int32_t i = 0; i < numOfVgroups; ++i) { STORE_CURRENT_SUBPLAN(pCxt); SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MODIFY); - SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(vgs, i); + SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(pPayload->payload, i); + vgroupInfoToEpSet(&blocks->vg, &subplan->execEpSet); - subplan->pNode = NULL; subplan->pDataSink = createDataInserter(pCxt, blocks); - subplan->type = QUERY_TYPE_MODIFY; + subplan->pNode = NULL; + subplan->type = QUERY_TYPE_MODIFY; + subplan->msgType = pPayload->msgType; + RECOVERY_CURRENT_SUBPLAN(pCxt); } } static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { if (QNODE_MODIFY == pRoot->info.type) { - splitInsertSubplan(pCxt, pRoot); + splitModificationOpSubPlan(pCxt, pRoot); } else { SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); ++(pCxt->nextId.templateId); @@ -325,6 +332,7 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD .pCurrentSubplan = NULL, .nextId = {0} // todo queryid }; + *pDag = context.pDag; context.pDag->pSubplans = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); createSubplanByLevel(&context, pQueryNode); diff --git a/source/libs/planner/src/physicalPlanJson.c b/source/libs/planner/src/physicalPlanJson.c index 9b2c9c1796..b25d9a3627 100644 --- a/source/libs/planner/src/physicalPlanJson.c +++ b/source/libs/planner/src/physicalPlanJson.c @@ -793,7 +793,7 @@ static cJSON* subplanToJson(const SSubplan* subplan) { return NULL; } - // The 'type', 'level', 'execEpSet', 'pChildern' and 'pParents' fields do not need to be serialized. + // The 'type', 'level', 'execEpSet', 'pChildren' and 'pParents' fields do not need to be serialized. bool res = addObject(jSubplan, jkSubplanId, subplanIdToJson, &subplan->id); if (res) { @@ -835,7 +835,7 @@ int32_t subPlanToString(const SSubplan* subplan, char** str, int32_t* len) { SDataInserter* insert = (SDataInserter*)(subplan->pDataSink); *len = insert->size; *str = insert->pData; - insert->pData == NULL; + insert->pData = NULL; return TSDB_CODE_SUCCESS; } @@ -844,6 +844,7 @@ int32_t subPlanToString(const SSubplan* subplan, char** str, int32_t* len) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_FAILED; } + *str = cJSON_Print(json); *len = strlen(*str) + 1; return TSDB_CODE_SUCCESS; diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 6381771400..9621c2e227 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -31,17 +31,20 @@ int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) destroyQueryPlan(logicPlan); return code; } + code = optimizeQueryPlan(logicPlan); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); return code; } + code = createDag(logicPlan, NULL, pDag); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); qDestroyQueryDag(*pDag); return code; } + destroyQueryPlan(logicPlan); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 20eb94c2ff..8ef67a8e93 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -28,7 +28,7 @@ int32_t schBuildTaskRalation(SSchJob *job, SHashObj *planToTask) { for (int32_t m = 0; m < level->taskNum; ++m) { SSchTask *task = taosArrayGet(level->subTasks, m); SSubplan *plan = task->plan; - int32_t childNum = plan->pChildern ? (int32_t)taosArrayGetSize(plan->pChildern) : 0; + int32_t childNum = plan->pChildren ? (int32_t)taosArrayGetSize(plan->pChildren) : 0; int32_t parentNum = plan->pParents ? (int32_t)taosArrayGetSize(plan->pParents) : 0; if (childNum > 0) { @@ -40,7 +40,7 @@ int32_t schBuildTaskRalation(SSchJob *job, SHashObj *planToTask) { } for (int32_t n = 0; n < childNum; ++n) { - SSubplan **child = taosArrayGet(plan->pChildern, n); + SSubplan **child = taosArrayGet(plan->pChildren, n); SSchTask **childTask = taosHashGet(planToTask, child, POINTER_BYTES); if (NULL == childTask || NULL == *childTask) { qError("subplan relationship error, level:%d, taskIdx:%d, childIdx:%d", i, m, n); @@ -122,6 +122,7 @@ int32_t schValidateAndBuildJob(SQueryDag *dag, SSchJob *job) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + //?? job->attr.needFetch = true; job->levelNum = levelNum; @@ -547,22 +548,29 @@ int32_t schHandleCallback(void* param, const SDataBuf* pMsg, int32_t msgType, in _return: tfree(param); - SCH_RET(code); } int32_t schHandleSubmitCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_SUBMIT_RSP, code); } + +int32_t schHandleCreateTableCallback(void* param, const SDataBuf* pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_CREATE_TABLE_RSP, code); +} + int32_t schHandleQueryCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_QUERY_RSP, code); } + int32_t schHandleFetchCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_FETCH_RSP, code); } + int32_t schHandleReadyCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_RES_READY_RSP, code); } + int32_t schHandleDropCallback(void* param, const SDataBuf* pMsg, int32_t code) { SSchCallbackParam *pParam = (SSchCallbackParam *)param; qDebug("drop task rsp received, queryId:%"PRIx64 ",taksId:%"PRIx64 ",code:%d", pParam->queryId, pParam->taskId, code); @@ -570,6 +578,9 @@ int32_t schHandleDropCallback(void* param, const SDataBuf* pMsg, int32_t code) { int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { switch (msgType) { + case TDMT_VND_CREATE_TABLE: + *fp = schHandleCreateTableCallback; + break; case TDMT_VND_SUBMIT: *fp = schHandleSubmitCallback; break; @@ -640,6 +651,7 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { int32_t code = 0; switch (msgType) { + case TDMT_VND_CREATE_TABLE: case TDMT_VND_SUBMIT: { if (NULL == task->msg || task->msgLen <= 0) { qError("submit msg is NULL"); @@ -746,19 +758,15 @@ int32_t schLaunchTask(SSchJob *job, SSchTask *task) { SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - int32_t msgType = (plan->type == QUERY_TYPE_MODIFY) ? TDMT_VND_SUBMIT : TDMT_VND_QUERY; +// int32_t msgType = (plan->type == QUERY_TYPE_MODIFY)? TDMT_VND_SUBMIT : TDMT_VND_QUERY; - SCH_ERR_RET(schBuildAndSendMsg(job, task, msgType)); - + SCH_ERR_RET(schBuildAndSendMsg(job, task, plan->msgType)); SCH_ERR_RET(schPushTaskToExecList(job, task)); task->status = JOB_TASK_STATUS_EXECUTING; - return TSDB_CODE_SUCCESS; } - - int32_t schLaunchJob(SSchJob *job) { SSchLevel *level = taosArrayGet(job->levels, job->levelIdx); for (int32_t i = 0; i < level->taskNum; ++i) { diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index b418ade172..338ad1a2c0 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -58,7 +58,7 @@ void schtBuildQueryDag(SQueryDag *dag) { scanPlan.execEpSet.numOfEps = 1; scanPlan.execEpSet.port[0] = 6030; strcpy(scanPlan.execEpSet.fqdn[0], "ep0"); - scanPlan.pChildern = NULL; + scanPlan.pChildren = NULL; scanPlan.pParents = taosArrayInit(1, POINTER_BYTES); scanPlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); @@ -68,14 +68,14 @@ void schtBuildQueryDag(SQueryDag *dag) { mergePlan.type = QUERY_TYPE_MERGE; mergePlan.level = 0; mergePlan.execEpSet.numOfEps = 0; - mergePlan.pChildern = taosArrayInit(1, POINTER_BYTES); + mergePlan.pChildren = taosArrayInit(1, POINTER_BYTES); mergePlan.pParents = NULL; mergePlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); SSubplan *mergePointer = (SSubplan *)taosArrayPush(merge, &mergePlan); SSubplan *scanPointer = (SSubplan *)taosArrayPush(scan, &scanPlan); - taosArrayPush(mergePointer->pChildern, &scanPointer); + taosArrayPush(mergePointer->pChildren, &scanPointer); taosArrayPush(scanPointer->pParents, &mergePointer); taosArrayPush(dag->pSubplans, &merge); @@ -100,7 +100,7 @@ void schtBuildInsertDag(SQueryDag *dag) { insertPlan[0].execEpSet.numOfEps = 1; insertPlan[0].execEpSet.port[0] = 6030; strcpy(insertPlan[0].execEpSet.fqdn[0], "ep0"); - insertPlan[0].pChildern = NULL; + insertPlan[0].pChildren = NULL; insertPlan[0].pParents = NULL; insertPlan[0].pNode = NULL; insertPlan[0].pDataSink = (SDataSink*)calloc(1, sizeof(SDataSink)); @@ -113,7 +113,7 @@ void schtBuildInsertDag(SQueryDag *dag) { insertPlan[1].execEpSet.numOfEps = 1; insertPlan[1].execEpSet.port[0] = 6030; strcpy(insertPlan[1].execEpSet.fqdn[0], "ep1"); - insertPlan[1].pChildern = NULL; + insertPlan[1].pChildren = NULL; insertPlan[1].pParents = NULL; insertPlan[1].pNode = NULL; insertPlan[1].pDataSink = (SDataSink*)calloc(1, sizeof(SDataSink)); From 5d63e31262ae943afc6cbcb2049134c9820164a3 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sun, 2 Jan 2022 23:28:17 +0800 Subject: [PATCH 39/56] [td-11818] fix bugs. --- source/libs/planner/src/physicalPlan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 9e1eea2b35..a53cbe836d 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -281,6 +281,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { default: assert(false); } + if (pPlanNode->pChildren != NULL && taosArrayGetSize(pPlanNode->pChildren) > 0) { node->pChildren = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); size_t size = taosArrayGetSize(pPlanNode->pChildren); @@ -290,6 +291,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { taosArrayPush(node->pChildren, &child); } } + return node; } @@ -316,9 +318,11 @@ static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { if (QNODE_MODIFY == pRoot->info.type) { splitModificationOpSubPlan(pCxt, pRoot); } else { - SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); + SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); ++(pCxt->nextId.templateId); - subplan->pNode = createPhyNode(pCxt, pRoot); + + subplan->msgType = TDMT_VND_QUERY; + subplan->pNode = createPhyNode(pCxt, pRoot); subplan->pDataSink = createDataDispatcher(pCxt, pRoot); } // todo deal subquery From 62b60991f39b92b6b86f64ca90839b6819d818b2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 06:04:15 +0000 Subject: [PATCH 40/56] add encode test --- source/util/test/CMakeLists.txt | 4 + source/util/test/encodeTest.cpp | 166 ++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 source/util/test/encodeTest.cpp diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index bfc3906f79..4b6311022d 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -41,4 +41,8 @@ target_sources(freelistTest ) target_link_libraries(freelistTest os util gtest gtest_main) +# encodeTest +add_executable(encodeTest "encodeTest.cpp") +target_link_libraries(encodeTest os util gtest gtest_main) + diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp new file mode 100644 index 0000000000..e89c84d8d2 --- /dev/null +++ b/source/util/test/encodeTest.cpp @@ -0,0 +1,166 @@ +#include + +#include "gtest/gtest.h" + +#include "encode.h" + +#define BUF_SIZE 64 +td_endian_t endian_arr[2] = {TD_LITTLE_ENDIAN, TD_BIG_ENDIAN}; + +static int encode(SCoder *pCoder, int8_t val) { return tEncodeI8(pCoder, val); } +static int encode(SCoder *pCoder, uint8_t val) { return tEncodeU8(pCoder, val); } +static int encode(SCoder *pCoder, int16_t val) { return tEncodeI16(pCoder, val); } +static int encode(SCoder *pCoder, uint16_t val) { return tEncodeU16(pCoder, val); } +static int encode(SCoder *pCoder, int32_t val) { return tEncodeI32(pCoder, val); } +static int encode(SCoder *pCoder, uint32_t val) { return tEncodeU32(pCoder, val); } +static int encode(SCoder *pCoder, int64_t val) { return tEncodeI64(pCoder, val); } +static int encode(SCoder *pCoder, uint64_t val) { return tEncodeU64(pCoder, val); } + +static int decode(SCoder *pCoder, int8_t *val) { return tDecodeI8(pCoder, val); } +static int decode(SCoder *pCoder, uint8_t *val) { return tDecodeU8(pCoder, val); } +static int decode(SCoder *pCoder, int16_t *val) { return tDecodeI16(pCoder, val); } +static int decode(SCoder *pCoder, uint16_t *val) { return tDecodeU16(pCoder, val); } +static int decode(SCoder *pCoder, int32_t *val) { return tDecodeI32(pCoder, val); } +static int decode(SCoder *pCoder, uint32_t *val) { return tDecodeU32(pCoder, val); } +static int decode(SCoder *pCoder, int64_t *val) { return tDecodeI64(pCoder, val); } +static int decode(SCoder *pCoder, uint64_t *val) { return tDecodeU64(pCoder, val); } + +static int encodev(SCoder *pCoder, int8_t val) { return tEncodeI8(pCoder, val); } +static int encodev(SCoder *pCoder, uint8_t val) { return tEncodeU8(pCoder, val); } +static int encodev(SCoder *pCoder, int16_t val) { return tEncodeI16v(pCoder, val); } +static int encodev(SCoder *pCoder, uint16_t val) { return tEncodeU16v(pCoder, val); } +static int encodev(SCoder *pCoder, int32_t val) { return tEncodeI32v(pCoder, val); } +static int encodev(SCoder *pCoder, uint32_t val) { return tEncodeU32v(pCoder, val); } +static int encodev(SCoder *pCoder, int64_t val) { return tEncodeI64v(pCoder, val); } +static int encodev(SCoder *pCoder, uint64_t val) { return tEncodeU64v(pCoder, val); } + +static int decodev(SCoder *pCoder, int8_t *val) { return tDecodeI8(pCoder, val); } +static int decodev(SCoder *pCoder, uint8_t *val) { return tDecodeU8(pCoder, val); } +static int decodev(SCoder *pCoder, int16_t *val) { return tDecodeI16v(pCoder, val); } +static int decodev(SCoder *pCoder, uint16_t *val) { return tDecodeU16v(pCoder, val); } +static int decodev(SCoder *pCoder, int32_t *val) { return tDecodeI32v(pCoder, val); } +static int decodev(SCoder *pCoder, uint32_t *val) { return tDecodeU32v(pCoder, val); } +static int decodev(SCoder *pCoder, int64_t *val) { return tDecodeI64v(pCoder, val); } +static int decodev(SCoder *pCoder, uint64_t *val) { return tDecodeU64v(pCoder, val); } + +template +static void simple_encode_decode_func(bool var_len) { + uint8_t buf[BUF_SIZE]; + SCoder coder; + T min_val, max_val; + T step = 1; + + if (typeid(T) == typeid(int8_t)) { + min_val = INT8_MIN; + max_val = INT8_MAX; + step = 1; + } else if (typeid(T) == typeid(uint8_t)) { + min_val = 0; + max_val = UINT8_MAX; + step = 1; + } else if (typeid(T) == typeid(int16_t)) { + min_val = INT16_MIN; + max_val = INT16_MAX; + step = 1; + } else if (typeid(T) == typeid(uint16_t)) { + min_val = 0; + max_val = UINT16_MAX; + step = 1; + } else if (typeid(T) == typeid(int32_t)) { + min_val = INT32_MIN; + max_val = INT32_MAX; + step = ((T)1) << 16; + } else if (typeid(T) == typeid(uint32_t)) { + min_val = 0; + max_val = UINT32_MAX; + step = ((T)1) << 16; + } else if (typeid(T) == typeid(int64_t)) { + min_val = INT64_MIN; + max_val = INT64_MAX; + step = ((T)1) << 48; + } else if (typeid(T) == typeid(uint64_t)) { + min_val = 0; + max_val = UINT64_MAX; + step = ((T)1) << 48; + } + + T i = min_val; + for (;; /*T i = min_val; i <= max_val; i += step*/) { + T dval; + + // Encode NULL + for (td_endian_t endian : endian_arr) { + tCoderInit(&coder, endian, NULL, 0, TD_ENCODER); + + if (var_len) { + GTEST_ASSERT_EQ(encodev(&coder, i), 0); + } else { + GTEST_ASSERT_EQ(encode(&coder, i), 0); + GTEST_ASSERT_EQ(coder.pos, sizeof(T)); + } + + tCoderClear(&coder); + } + + // Encode and decode + for (td_endian_t e_endian : endian_arr) { + for (td_endian_t d_endian : endian_arr) { + // Encode + tCoderInit(&coder, e_endian, buf, BUF_SIZE, TD_ENCODER); + + if (var_len) { + GTEST_ASSERT_EQ(encodev(&coder, i), 0); + } else { + GTEST_ASSERT_EQ(encode(&coder, i), 0); + GTEST_ASSERT_EQ(coder.pos, sizeof(T)); + } + + tCoderClear(&coder); + // Decode + tCoderInit(&coder, d_endian, buf, BUF_SIZE, TD_DECODER); + + if (var_len) { + GTEST_ASSERT_EQ(decodev(&coder, &dval), 0); + } else { + GTEST_ASSERT_EQ(decode(&coder, &dval), 0); + GTEST_ASSERT_EQ(coder.pos, sizeof(T)); + } + + if (typeid(T) == typeid(int8_t) || typeid(T) == typeid(uint8_t) || e_endian == d_endian) { + GTEST_ASSERT_EQ(i, dval); + } + + tCoderClear(&coder); + } + } + + if (i == max_val) break; + + if (max_val - i < step) { + i = max_val; + } else { + i = i + step; + } + } +} + +TEST(td_encode_test, simple_encode_and_decode_test) { + uint8_t buf[10]; + SCoder encoder, decoder; + + simple_encode_decode_func(false); + simple_encode_decode_func(false); + simple_encode_decode_func(false); + simple_encode_decode_func(false); + simple_encode_decode_func(false); + simple_encode_decode_func(false); + simple_encode_decode_func(false); + simple_encode_decode_func(false); + + simple_encode_decode_func(true); + simple_encode_decode_func(true); + simple_encode_decode_func(true); + simple_encode_decode_func(true); + simple_encode_decode_func(true); + simple_encode_decode_func(true); +} \ No newline at end of file From ad3374477197c399db8d12df658a4d0417862c76 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 06:15:52 +0000 Subject: [PATCH 41/56] Fix variant encoding bug --- include/util/encode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index 02edbe888e..42548c03e3 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -141,7 +141,7 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val); return 0; #define TD_ENCODE_VARIANT_MACRO(CODER, VAL) \ - while ((VAL) > ENCODE_LIMIT) { \ + while ((VAL) >= ENCODE_LIMIT) { \ if ((CODER)->data) { \ if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, 1)) return -1; \ TD_CODER_CURRENT(CODER)[0] = ((VAL) | ENCODE_LIMIT) & 0xff; \ @@ -391,7 +391,7 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val) { uint64_t len; if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1; - memcpy(val, pStr, len+1); + memcpy(val, pStr, len + 1); return 0; } From 99510b689c3e7f1c8e7bda3bd8d75ab745aeabf9 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 06:18:07 +0000 Subject: [PATCH 42/56] add more check --- source/util/test/encodeTest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index e89c84d8d2..0e276e4338 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -115,6 +115,8 @@ static void simple_encode_decode_func(bool var_len) { GTEST_ASSERT_EQ(coder.pos, sizeof(T)); } + int32_t epos = coder.pos; + tCoderClear(&coder); // Decode tCoderInit(&coder, d_endian, buf, BUF_SIZE, TD_DECODER); @@ -126,6 +128,8 @@ static void simple_encode_decode_func(bool var_len) { GTEST_ASSERT_EQ(coder.pos, sizeof(T)); } + GTEST_ASSERT_EQ(coder.pos, epos); + if (typeid(T) == typeid(int8_t) || typeid(T) == typeid(uint8_t) || e_endian == d_endian) { GTEST_ASSERT_EQ(i, dval); } From 8aaf22ae7549b1f306d6fb53f63f877174896c42 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 06:21:33 +0000 Subject: [PATCH 43/56] more --- source/util/test/encodeTest.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index 0e276e4338..59a37386d3 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -148,10 +148,7 @@ static void simple_encode_decode_func(bool var_len) { } } -TEST(td_encode_test, simple_encode_and_decode_test) { - uint8_t buf[10]; - SCoder encoder, decoder; - +TEST(td_encode_test, encode_decode_fixed_len_integer) { simple_encode_decode_func(false); simple_encode_decode_func(false); simple_encode_decode_func(false); @@ -160,7 +157,9 @@ TEST(td_encode_test, simple_encode_and_decode_test) { simple_encode_decode_func(false); simple_encode_decode_func(false); simple_encode_decode_func(false); +} +TEST(td_encode_test, encode_decode_variant_len_integer) { simple_encode_decode_func(true); simple_encode_decode_func(true); simple_encode_decode_func(true); From 7b3a04c4dd196e896ab66ccbf70a72e736e87e98 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 06:34:54 +0000 Subject: [PATCH 44/56] more --- include/util/encode.h | 8 ++++---- source/util/test/encodeTest.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index 42548c03e3..31d386c450 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -100,7 +100,7 @@ static int tEncodeI64v(SCoder* pEncoder, int64_t val); static int tEncodeFloat(SCoder* pEncoder, float val); static int tEncodeDouble(SCoder* pEncoder, double val); static int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len); -static int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, uint64_t len); +static int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len); static int tEncodeCStr(SCoder* pEncoder, const char* val); /* ------------------------ DECODE ------------------------ */ @@ -141,7 +141,7 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val); return 0; #define TD_ENCODE_VARIANT_MACRO(CODER, VAL) \ - while ((VAL) >= ENCODE_LIMIT) { \ + while ((VAL) >= ENCODE_LIMIT) { \ if ((CODER)->data) { \ if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, 1)) return -1; \ TD_CODER_CURRENT(CODER)[0] = ((VAL) | ENCODE_LIMIT) & 0xff; \ @@ -261,12 +261,12 @@ static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_ return 0; } -static FORCE_INLINE int tEncodeCstrWithLen(SCoder* pEncoder, const char* val, uint64_t len) { +static FORCE_INLINE int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) { return tEncodeBinary(pEncoder, (void*)val, len + 1); } static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) { - return tEncodeCstrWithLen(pEncoder, val, (uint64_t)strlen(val)); + return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val)); } /* ------------------------ FOR DECODER ------------------------ */ diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index 59a37386d3..dc10cec443 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -166,4 +166,36 @@ TEST(td_encode_test, encode_decode_variant_len_integer) { simple_encode_decode_func(true); simple_encode_decode_func(true); simple_encode_decode_func(true); +} + +TEST(td_encode_test, encode_decode_cstr) { + uint8_t * buf = new uint8_t[1024 * 1024]; + char * cstr = new char[1024 * 1024]; + const char *dcstr; + SCoder encoder; + SCoder decoder; + + for (size_t i = 0; i < 1024 * 2 - 1; i++) { + memset(cstr, 'a', i); + cstr[i] = '\0'; + for (td_endian_t endian : endian_arr) { + // Encode + tCoderInit(&encoder, endian, buf, 1024 * 1024, TD_ENCODER); + + GTEST_ASSERT_EQ(tEncodeCStr(&encoder, cstr), 0); + + tCoderClear(&encoder); + + // Decode + tCoderInit(&decoder, endian, buf, 1024 * 1024, TD_DECODER); + + GTEST_ASSERT_EQ(tDecodeCStr(&decoder, &dcstr), 0); + GTEST_ASSERT_EQ(memcmp(dcstr, cstr, i + 1), 0); + + tCoderClear(&decoder); + } + } + + delete buf; + delete cstr; } \ No newline at end of file From 086a2202ce9c807f776bf4cc8e2f9385760ceba2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 08:45:31 +0000 Subject: [PATCH 45/56] more --- include/util/encode.h | 49 ++++---- source/util/src/encode.c | 21 ++-- source/util/test/encodeTest.cpp | 199 ++++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+), 32 deletions(-) diff --git a/include/util/encode.h b/include/util/encode.h index 31d386c450..ba63759737 100644 --- a/include/util/encode.h +++ b/include/util/encode.h @@ -81,31 +81,32 @@ void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, void tCoderClear(SCoder* pCoder); /* ------------------------ ENCODE ------------------------ */ -static int tStartEncode(SCoder* pEncoder); -static void tEndEncode(SCoder* pEncoder); -static int tEncodeU8(SCoder* pEncoder, uint8_t val); -static int tEncodeI8(SCoder* pEncoder, int8_t val); -static int tEncodeU16(SCoder* pEncoder, uint16_t val); -static int tEncodeI16(SCoder* pEncoder, int16_t val); -static int tEncodeU32(SCoder* pEncoder, uint32_t val); -static int tEncodeI32(SCoder* pEncoder, int32_t val); -static int tEncodeU64(SCoder* pEncoder, uint64_t val); -static int tEncodeI64(SCoder* pEncoder, int64_t val); -static int tEncodeU16v(SCoder* pEncoder, uint16_t val); -static int tEncodeI16v(SCoder* pEncoder, int16_t val); -static int tEncodeU32v(SCoder* pEncoder, uint32_t val); -static int tEncodeI32v(SCoder* pEncoder, int32_t val); -static int tEncodeU64v(SCoder* pEncoder, uint64_t val); -static int tEncodeI64v(SCoder* pEncoder, int64_t val); -static int tEncodeFloat(SCoder* pEncoder, float val); -static int tEncodeDouble(SCoder* pEncoder, double val); -static int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len); -static int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len); -static int tEncodeCStr(SCoder* pEncoder, const char* val); +int tStartEncode(SCoder* pEncoder); +void tEndEncode(SCoder* pEncoder); +static int tEncodeU8(SCoder* pEncoder, uint8_t val); +static int tEncodeI8(SCoder* pEncoder, int8_t val); +static int tEncodeU16(SCoder* pEncoder, uint16_t val); +static int tEncodeI16(SCoder* pEncoder, int16_t val); +static int tEncodeU32(SCoder* pEncoder, uint32_t val); +static int tEncodeI32(SCoder* pEncoder, int32_t val); +static int tEncodeU64(SCoder* pEncoder, uint64_t val); +static int tEncodeI64(SCoder* pEncoder, int64_t val); +static int tEncodeU16v(SCoder* pEncoder, uint16_t val); +static int tEncodeI16v(SCoder* pEncoder, int16_t val); +static int tEncodeU32v(SCoder* pEncoder, uint32_t val); +static int tEncodeI32v(SCoder* pEncoder, int32_t val); +static int tEncodeU64v(SCoder* pEncoder, uint64_t val); +static int tEncodeI64v(SCoder* pEncoder, int64_t val); +static int tEncodeFloat(SCoder* pEncoder, float val); +static int tEncodeDouble(SCoder* pEncoder, double val); +static int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len); +static int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len); +static int tEncodeCStr(SCoder* pEncoder, const char* val); /* ------------------------ DECODE ------------------------ */ -static int tStartDecode(SCoder* pDecoder); -static void tEndDecode(SCoder* pDecoder); +int tStartDecode(SCoder* pDecoder); +void tEndDecode(SCoder* pDecoder); +static bool tDecodeIsEnd(SCoder* pCoder); static int tDecodeU8(SCoder* pDecoder, uint8_t* val); static int tDecodeI8(SCoder* pDecoder, int8_t* val); static int tDecodeU16(SCoder* pDecoder, uint16_t* val); @@ -395,6 +396,8 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val) { return 0; } +static FORCE_INLINE bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); } + #ifdef __cplusplus } #endif diff --git a/source/util/src/encode.c b/source/util/src/encode.c index a3946daf5c..24d033f697 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -47,8 +47,6 @@ void tCoderClear(SCoder* pCoder) { } } -bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); } - int tStartEncode(SCoder* pCoder) { struct SCoderNode* pNode; @@ -62,7 +60,7 @@ int tStartEncode(SCoder* pCoder) { pNode->pos = pCoder->pos; pNode->size = pCoder->size; - pCoder->data = pNode->data + sizeof(int32_t); + pCoder->data = pNode->data + pNode->pos + sizeof(int32_t); pCoder->pos = 0; pCoder->size = pNode->size - pNode->pos - sizeof(int32_t); @@ -75,27 +73,32 @@ int tStartEncode(SCoder* pCoder) { void tEndEncode(SCoder* pCoder) { struct SCoderNode* pNode; + int32_t len; if (pCoder->data) { pNode = TD_SLIST_HEAD(&(pCoder->stack)); ASSERT(pNode); TD_SLIST_POP(&(pCoder->stack)); - // TODO: tEncodeI32(pNode, pCoder->pos); + len = pCoder->pos; pCoder->data = pNode->data; pCoder->size = pNode->size; - pCoder->pos = pNode->pos + pCoder->pos; + pCoder->pos = pNode->pos; + + tEncodeI32(pCoder, len); + + TD_CODER_MOVE_POS(pCoder, len); free(pNode); } } int tStartDecode(SCoder* pCoder) { - int32_t size; + int32_t len; struct SCoderNode* pNode; - // TODO: if (tDecodeI32(pCoder, &size) < 0) return -1; + if (tDecodeI32(pCoder, &len) < 0) return -1; pNode = malloc(sizeof(*pNode)); if (pNode == NULL) return -1; @@ -104,8 +107,8 @@ int tStartDecode(SCoder* pCoder) { pNode->pos = pCoder->pos; pNode->size = pCoder->size; - pCoder->data = pCoder->data; - pCoder->size = size; + pCoder->data = pNode->data + pNode->pos; + pCoder->size = len; pCoder->pos = 0; TD_SLIST_PUSH(&(pCoder->stack), pNode); diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index dc10cec443..b0e970eb07 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -198,4 +198,203 @@ TEST(td_encode_test, encode_decode_cstr) { delete buf; delete cstr; +} + +typedef struct { + int32_t A_a; + int64_t A_b; + char * A_c; +} SStructA_v1; + +static int tSStructA_v1_encode(SCoder *pCoder, const SStructA_v1 *pSAV1) { + if (tStartEncode(pCoder) < 0) return -1; + + if (tEncodeI32(pCoder, pSAV1->A_a) < 0) return -1; + if (tEncodeI64(pCoder, pSAV1->A_b) < 0) return -1; + if (tEncodeCStr(pCoder, pSAV1->A_c) < 0) return -1; + + tEndEncode(pCoder); + return 0; +} + +static int tSStructA_v1_decode(SCoder *pCoder, SStructA_v1 *pSAV1) { + if (tStartDecode(pCoder) < 0) return -1; + + if (tDecodeI32(pCoder, &pSAV1->A_a) < 0) return -1; + if (tDecodeI64(pCoder, &pSAV1->A_b) < 0) return -1; + const char *tstr; + uint64_t len; + if (tDecodeCStrAndLen(pCoder, &tstr, &len) < 0) return -1; + pSAV1->A_c = (char *)TCODER_MALLOC(len + 1, pCoder); + memcpy(pSAV1->A_c, tstr, len + 1); + + tEndDecode(pCoder); + return 0; +} + +typedef struct { + int32_t A_a; + int64_t A_b; + char * A_c; + // -------------------BELOW FEILDS ARE ADDED IN A NEW VERSION-------------- + int16_t A_d; + int16_t A_e; +} SStructA_v2; + +static int tSStructA_v2_encode(SCoder *pCoder, const SStructA_v2 *pSAV2) { + if (tStartEncode(pCoder) < 0) return -1; + + if (tEncodeI32(pCoder, pSAV2->A_a) < 0) return -1; + if (tEncodeI64(pCoder, pSAV2->A_b) < 0) return -1; + if (tEncodeCStr(pCoder, pSAV2->A_c) < 0) return -1; + + // ------------------------NEW FIELDS ENCODE------------------------------- + if (tEncodeI16(pCoder, pSAV2->A_d) < 0) return -1; + if (tEncodeI16(pCoder, pSAV2->A_e) < 0) return -1; + + tEndEncode(pCoder); + return 0; +} + +static int tSStructA_v2_decode(SCoder *pCoder, SStructA_v2 *pSAV2) { + if (tStartDecode(pCoder) < 0) return -1; + + if (tDecodeI32(pCoder, &pSAV2->A_a) < 0) return -1; + if (tDecodeI64(pCoder, &pSAV2->A_b) < 0) return -1; + const char *tstr; + uint64_t len; + if (tDecodeCStrAndLen(pCoder, &tstr, &len) < 0) return -1; + pSAV2->A_c = (char *)TCODER_MALLOC(len + 1, pCoder); + memcpy(pSAV2->A_c, tstr, len + 1); + + // ------------------------NEW FIELDS DECODE------------------------------- + if (!tDecodeIsEnd(pCoder)) { + if (tDecodeI16(pCoder, &pSAV2->A_d) < 0) return -1; + if (tDecodeI16(pCoder, &pSAV2->A_e) < 0) return -1; + } else { + pSAV2->A_d = 0; + pSAV2->A_e = 0; + } + + tEndDecode(pCoder); + return 0; +} + +typedef struct { + SStructA_v1 *pA; + int32_t v_a; + int8_t v_b; +} SFinalReq_v1; + +static int tSFinalReq_v1_encode(SCoder *pCoder, const SFinalReq_v1 *ps1) { + if (tStartEncode(pCoder) < 0) return -1; + + if (tSStructA_v1_encode(pCoder, ps1->pA) < 0) return -1; + if (tEncodeI32(pCoder, ps1->v_a) < 0) return -1; + if (tEncodeI8(pCoder, ps1->v_b) < 0) return -1; + + tEndEncode(pCoder); + return 0; +} + +static int tSFinalReq_v1_decode(SCoder *pCoder, SFinalReq_v1 *ps1) { + if (tStartDecode(pCoder) < 0) return -1; + + ps1->pA = (SStructA_v1 *)TCODER_MALLOC(sizeof(*(ps1->pA)), pCoder); + if (tSStructA_v1_decode(pCoder, ps1->pA) < 0) return -1; + if (tDecodeI32(pCoder, &ps1->v_a) < 0) return -1; + if (tDecodeI8(pCoder, &ps1->v_b) < 0) return -1; + + tEndEncode(pCoder); + return 0; +} + +typedef struct { + SStructA_v2 *pA; + int32_t v_a; + int8_t v_b; + // ----------------------- Feilds added ----------------------- + int16_t v_c; +} SFinalReq_v2; + +static int tSFinalReq_v2_encode(SCoder *pCoder, const SFinalReq_v2 *ps2) { + if (tStartEncode(pCoder) < 0) return -1; + + if (tSStructA_v2_encode(pCoder, ps2->pA) < 0) return -1; + if (tEncodeI32(pCoder, ps2->v_a) < 0) return -1; + if (tEncodeI8(pCoder, ps2->v_b) < 0) return -1; + + // ----------------------- Feilds added encode ----------------------- + if (tEncodeI16(pCoder, ps2->v_c) < 0) return -1; + + tEndEncode(pCoder); + return 0; +} + +static int tSFinalReq_v2_decode(SCoder *pCoder, SFinalReq_v2 *ps2) { + if (tStartDecode(pCoder) < 0) return -1; + + ps2->pA = (SStructA_v2 *)TCODER_MALLOC(sizeof(*(ps2->pA)), pCoder); + if (tSStructA_v2_decode(pCoder, ps2->pA) < 0) return -1; + if (tDecodeI32(pCoder, &ps2->v_a) < 0) return -1; + if (tDecodeI8(pCoder, &ps2->v_b) < 0) return -1; + + // ----------------------- Feilds added decode ----------------------- + if (tDecodeIsEnd(pCoder)) { + ps2->v_c = 0; + } else { + if (tDecodeI16(pCoder, &ps2->v_c) < 0) return -1; + } + + tEndEncode(pCoder); + return 0; +} + +TEST(td_encode_test, compound_struct_encode_test) { + SCoder encoder, decoder; + uint8_t * buf1; + int32_t buf1size; + uint8_t * buf2; + int32_t buf2size; + SStructA_v1 sa1 = {.A_a = 10, .A_b = 65478, .A_c = "Hello"}; + SStructA_v2 sa2 = {.A_a = 10, .A_b = 65478, .A_c = "Hello", .A_d = 67, .A_e = 13}; + SFinalReq_v1 req1 = {.pA = &sa1, .v_a = 15, .v_b = 35}; + SFinalReq_v2 req2 = {.pA = &sa2, .v_a = 15, .v_b = 32, .v_c = 37}; + SFinalReq_v1 dreq1; + SFinalReq_v2 dreq21, dreq22; + + // Get size + tCoderInit(&encoder, TD_LITTLE_ENDIAN, nullptr, 0, TD_ENCODER); + GTEST_ASSERT_EQ(tSFinalReq_v1_encode(&encoder, &req1), 0); + buf1size = encoder.pos; + buf1 = new uint8_t[encoder.pos]; + tCoderClear(&encoder); + + tCoderInit(&encoder, TD_LITTLE_ENDIAN, nullptr, 0, TD_ENCODER); + GTEST_ASSERT_EQ(tSFinalReq_v2_encode(&encoder, &req2), 0); + buf2size = encoder.pos; + buf2 = new uint8_t[encoder.pos]; + tCoderClear(&encoder); + + // Encode + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_ENCODER); + GTEST_ASSERT_EQ(tSFinalReq_v1_encode(&encoder, &req1), 0); + tCoderClear(&encoder); + + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_ENCODER); + GTEST_ASSERT_EQ(tSFinalReq_v2_encode(&encoder, &req2), 0); + tCoderClear(&encoder); + + // Decode + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER); + GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq1), 0); + tCoderClear(&decoder); + + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER); + GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq21), 0); + tCoderClear(&decoder); + + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_DECODER); + GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq22), 0); + tCoderClear(&decoder); } \ No newline at end of file From 97d26ef10d28cc41620e0819d2902dc0d484a9f4 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 09:34:20 +0000 Subject: [PATCH 46/56] fix bug --- source/util/src/encode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/util/src/encode.c b/source/util/src/encode.c index 24d033f697..71985845af 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -86,7 +86,11 @@ void tEndEncode(SCoder* pCoder) { pCoder->size = pNode->size; pCoder->pos = pNode->pos; - tEncodeI32(pCoder, len); + if (TD_RT_ENDIAN() == pCoder->endian) { + tPut(int32_t, pCoder->data + pCoder->pos, len); + } else { + tRPut32(pCoder->data + pCoder->pos, len); + } TD_CODER_MOVE_POS(pCoder, len); From 1fde98815b40f4819ae89f2a3a8d98763e840a3e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 10:02:21 +0000 Subject: [PATCH 47/56] refact and fix some bugs --- source/util/src/encode.c | 10 +++++++--- source/util/test/encodeTest.cpp | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/util/src/encode.c b/source/util/src/encode.c index 71985845af..40c03ea051 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -50,6 +50,7 @@ void tCoderClear(SCoder* pCoder) { int tStartEncode(SCoder* pCoder) { struct SCoderNode* pNode; + ASSERT(pCoder->type == TD_ENCODER); if (pCoder->data) { if (pCoder->size - pCoder->pos < sizeof(int32_t)) return -1; @@ -75,6 +76,7 @@ void tEndEncode(SCoder* pCoder) { struct SCoderNode* pNode; int32_t len; + ASSERT(pCoder->type == TD_ENCODER); if (pCoder->data) { pNode = TD_SLIST_HEAD(&(pCoder->stack)); ASSERT(pNode); @@ -92,7 +94,7 @@ void tEndEncode(SCoder* pCoder) { tRPut32(pCoder->data + pCoder->pos, len); } - TD_CODER_MOVE_POS(pCoder, len); + TD_CODER_MOVE_POS(pCoder, len + sizeof(int32_t)); free(pNode); } @@ -102,6 +104,7 @@ int tStartDecode(SCoder* pCoder) { int32_t len; struct SCoderNode* pNode; + ASSERT(pCoder->type == TD_DECODER); if (tDecodeI32(pCoder, &len) < 0) return -1; pNode = malloc(sizeof(*pNode)); @@ -121,10 +124,11 @@ int tStartDecode(SCoder* pCoder) { } void tEndDecode(SCoder* pCoder) { - ASSERT(tDecodeIsEnd(pCoder)); - struct SCoderNode* pNode; + ASSERT(pCoder->type == TD_DECODER); + ASSERT(tDecodeIsEnd(pCoder)); + pNode = TD_SLIST_HEAD(&(pCoder->stack)); ASSERT(pNode); TD_SLIST_POP(&(pCoder->stack)); diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index b0e970eb07..ec4d9cd182 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -305,7 +305,7 @@ static int tSFinalReq_v1_decode(SCoder *pCoder, SFinalReq_v1 *ps1) { if (tDecodeI32(pCoder, &ps1->v_a) < 0) return -1; if (tDecodeI8(pCoder, &ps1->v_b) < 0) return -1; - tEndEncode(pCoder); + tEndDecode(pCoder); return 0; } @@ -346,7 +346,7 @@ static int tSFinalReq_v2_decode(SCoder *pCoder, SFinalReq_v2 *ps2) { if (tDecodeI16(pCoder, &ps2->v_c) < 0) return -1; } - tEndEncode(pCoder); + tEndDecode(pCoder); return 0; } From 395b2bbeab93586d1616778544e507cfa3810b61 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 3 Jan 2022 10:07:42 +0000 Subject: [PATCH 48/56] add more test --- source/util/test/encodeTest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index ec4d9cd182..1a861701d7 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -388,13 +388,34 @@ TEST(td_encode_test, compound_struct_encode_test) { // Decode tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER); GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq1), 0); + GTEST_ASSERT_EQ(dreq1.pA->A_a, req1.pA->A_a); + GTEST_ASSERT_EQ(dreq1.pA->A_b, req1.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq1.pA->A_c, req1.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq1.v_a, req1.v_a); + GTEST_ASSERT_EQ(dreq1.v_b, req1.v_b); tCoderClear(&decoder); tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER); GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq21), 0); + GTEST_ASSERT_EQ(dreq21.pA->A_a, req1.pA->A_a); + GTEST_ASSERT_EQ(dreq21.pA->A_b, req1.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq21.pA->A_c, req1.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq21.pA->A_d, 0); + GTEST_ASSERT_EQ(dreq21.pA->A_e, 0); + GTEST_ASSERT_EQ(dreq21.v_a, req1.v_a); + GTEST_ASSERT_EQ(dreq21.v_b, req1.v_b); + GTEST_ASSERT_EQ(dreq21.v_c, 0); tCoderClear(&decoder); tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_DECODER); GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq22), 0); + GTEST_ASSERT_EQ(dreq22.pA->A_a, req2.pA->A_a); + GTEST_ASSERT_EQ(dreq22.pA->A_b, req2.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq22.pA->A_c, req2.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq22.pA->A_d, req2.pA->A_d); + GTEST_ASSERT_EQ(dreq22.pA->A_e, req2.pA->A_e); + GTEST_ASSERT_EQ(dreq22.v_a, req2.v_a); + GTEST_ASSERT_EQ(dreq22.v_b, req2.v_b); + GTEST_ASSERT_EQ(dreq22.v_c, req2.v_c); tCoderClear(&decoder); } \ No newline at end of file From 88ba5faec9ff06f6f492cec61b6301e164ce9dd2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 3 Jan 2022 22:12:28 +0800 Subject: [PATCH 49/56] refactor code --- .../index/inc/index_fst_counting_writer.h | 1 + source/libs/index/src/index.c | 8 +- source/libs/index/src/index_cache.c | 2 +- .../index/src/index_fst_counting_writer.c | 7 ++ source/libs/index/src/index_tfile.c | 90 +++++++++++-------- source/libs/index/test/indexTests.cc | 35 +++++--- 6 files changed, 89 insertions(+), 54 deletions(-) diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/index_fst_counting_writer.h index 1504a69a08..fcc0d5a0b3 100644 --- a/source/libs/index/inc/index_fst_counting_writer.h +++ b/source/libs/index/inc/index_fst_counting_writer.h @@ -38,6 +38,7 @@ typedef struct WriterCtx { int fd; bool readOnly; char buf[256]; + int size; } file; struct { int32_t capa; diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 9c7320b301..ff973dd7e3 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -135,7 +135,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { SIndexTerm* p = taosArrayGetP(fVals, i); char buf[128] = {0}; - ICacheKey key = {.suid = p->suid, .colName = p->colName}; + ICacheKey key = {.suid = p->suid, .colName = p->colName, .nColName = strlen(p->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); IndexCache** cache = taosHashGet(index->colObj, buf, sz); @@ -150,7 +150,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { SIndexTerm* p = taosArrayGetP(fVals, i); char buf[128] = {0}; - ICacheKey key = {.suid = p->suid, .colName = p->colName}; + ICacheKey key = {.suid = p->suid, .colName = p->colName, .nColName = strlen(p->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); IndexCache** cache = taosHashGet(index->colObj, buf, sz); @@ -212,7 +212,7 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result indexInterResultsDestroy(interResults); #endif - return 1; + return 0; } int indexDelete(SIndex* index, SIndexMultiTermQuery* query) { @@ -310,7 +310,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result pthread_mutex_lock(&sIdx->mtx); char buf[128] = {0}; - ICacheKey key = {.suid = term->suid, .colName = term->colName}; + ICacheKey key = {.suid = term->suid, .colName = term->colName, .nColName = strlen(term->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz); diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index b4c533e998..e95de9286e 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -20,7 +20,7 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later -#define MEM_TERM_LIMIT 10 * 10000 +#define MEM_TERM_LIMIT 5 * 10000 // ref index_cache.h:22 //#define CACHE_KEY_LEN(p) \ // (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index 7906dfea11..fb730d5f70 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -72,9 +72,15 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int if (readOnly == false) { // ctx->file.fd = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO); ctx->file.fd = tfOpenCreateWriteAppend(path); + struct stat fstat; + stat(path, &fstat); + ctx->file.size = fstat.st_size; } else { // ctx->file.fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO); ctx->file.fd = tfOpenRead(path); + struct stat fstat; + stat(path, &fstat); + ctx->file.size = fstat.st_size; } memcpy(ctx->file.buf, path, strlen(path)); if (ctx->file.fd < 0) { @@ -104,6 +110,7 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { free(ctx->mem.buf); } else { tfClose(ctx->file.fd); + ctx->flush(ctx); if (remove) { unlink(ctx->file.buf); } } free(ctx); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 95c713fb0a..9c4d1d1139 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2019 TAOS Data, Inc. - * +p * * 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. @@ -45,12 +45,13 @@ static int tfileReaderLoadHeader(TFileReader* reader); static int tfileReaderLoadFst(TFileReader* reader); static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray* result); -static int tfileGetFileList(const char* path, SArray* result); -static int tfileRmExpireFile(SArray* result); -static void tfileDestroyFileName(void* elem); -static int tfileCompare(const void* a, const void* b); -static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId, int* version); -static void tfileGenFileName(char* filename, uint64_t suid, int colId, int version); +static SArray* tfileGetFileList(const char* path); +static int tfileRmExpireFile(SArray* result); +static void tfileDestroyFileName(void* elem); +static int tfileCompare(const void* a, const void* b); +static int tfileParseFileName(const char* filename, uint64_t* suid, char* col, int* version); +static void tfileGenFileName(char* filename, uint64_t suid, const char* col, int version); +static void tfileGenFileFullName(char* fullname, const char* path, uint64_t suid, const char* col, int32_t version); TFileCache* tfileCacheCreate(const char* path) { TFileCache* tcache = calloc(1, sizeof(TFileCache)); @@ -59,21 +60,22 @@ TFileCache* tfileCacheCreate(const char* path) { tcache->tableCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); tcache->capacity = 64; - SArray* files = taosArrayInit(4, sizeof(void*)); - tfileGetFileList(path, files); - taosArraySort(files, tfileCompare); - tfileRmExpireFile(files); + SArray* files = tfileGetFileList(path); uint64_t suid; int32_t colId, version; for (size_t i = 0; i < taosArrayGetSize(files); i++) { char* file = taosArrayGetP(files, i); - if (0 != tfileParseFileName(file, &suid, (int*)&colId, (int*)&version)) { + char colName[256] = {0}; + if (0 != tfileParseFileName(file, &suid, colName, (int*)&version)) { indexInfo("try parse invalid file: %s, skip it", file); continue; } + // use version info later + char fullName[256] = {0}; + sprintf(fullName, "%s/%s", path, file); - WriterCtx* wc = writerCtxCreate(TFile, file, true, 1024 * 1024 * 64); + WriterCtx* wc = writerCtxCreate(TFile, fullName, true, 1024 * 1024 * 64); if (wc == NULL) { indexError("failed to open index:%s", file); goto End; @@ -200,12 +202,9 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SArray* resul } TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const char* colName, uint8_t colType) { - char filename[128] = {0}; - int32_t coldId = 1; - tfileGenFileName(filename, suid, coldId, version); - char fullname[256] = {0}; - snprintf(fullname, sizeof(fullname), "%s/%s", path, filename); + tfileGenFileFullName(fullname, path, suid, colName, version); + indexInfo("open write file name %s", fullname); WriterCtx* wcx = writerCtxCreate(TFile, fullname, false, 1024 * 1024 * 64); if (wcx == NULL) { return NULL; } @@ -218,13 +217,11 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const c return tfileWriterCreate(wcx, &tfh); } TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const char* colName) { - char filename[128] = {0}; - int32_t coldId = 1; - tfileGenFileName(filename, suid, coldId, version); - char fullname[256] = {0}; - snprintf(fullname, sizeof(fullname), "%s/%s", path, filename); + tfileGenFileFullName(fullname, path, suid, colName, version); + WriterCtx* wc = writerCtxCreate(TFile, fullname, true, 1024 * 1024 * 1024); + indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size); if (wc == NULL) { return NULL; } TFileReader* reader = tfileReaderCreate(wc); @@ -324,7 +321,6 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { } // write data - indexError("--------Begin----------------"); for (size_t i = 0; i < sz; i++) { // TODO, fst batch write later TFileValue* v = taosArrayGetP((SArray*)data, i); @@ -332,11 +328,10 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { indexError("failed to write data: %s, offset: %d len: %d", v->colVal, v->offset, (int)taosArrayGetSize(v->tableId)); } else { - indexInfo("success to write data: %s, offset: %d len: %d", v->colVal, v->offset, - (int)taosArrayGetSize(v->tableId)); + // indexInfo("success to write data: %s, offset: %d len: %d", v->colVal, v->offset, + // (int)taosArrayGetSize(v->tableId)); } } - indexError("--------End----------------"); fstBuilderFinish(tw->fb); fstBuilderDestroy(tw->fb); tw->fb = NULL; @@ -550,6 +545,9 @@ static int tfileReaderLoadHeader(TFileReader* reader) { // indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.fd, reader->ctx->file.buf); + } else { + indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), + errno, reader->ctx->file.fd, reader->ctx->file.buf); } // assert(nread == sizeof(buf)); memcpy(&reader->header, buf, sizeof(buf)); @@ -558,13 +556,14 @@ static int tfileReaderLoadHeader(TFileReader* reader) { } static int tfileReaderLoadFst(TFileReader* reader) { // current load fst into memory, refactor it later - static int FST_MAX_SIZE = 64 * 1024; + static int FST_MAX_SIZE = 64 * 1024 * 1024; char* buf = calloc(1, sizeof(char) * FST_MAX_SIZE); if (buf == NULL) { return -1; } WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); + indexError("nread = %d, and fst offset=%d, filename: %s ", nread, reader->header.fstOffset, ctx->file.buf); // we assuse fst size less than FST_MAX_SIZE assert(nread > 0 && nread < FST_MAX_SIZE); @@ -608,19 +607,26 @@ void tfileReaderUnRef(TFileReader* reader) { } } -static int tfileGetFileList(const char* path, SArray* result) { +static SArray* tfileGetFileList(const char* path) { + SArray* files = taosArrayInit(4, sizeof(void*)); + DIR* dir = opendir(path); - if (NULL == dir) { return -1; } + if (NULL == dir) { return NULL; } struct dirent* entry; while ((entry = readdir(dir)) != NULL) { + if (entry->d_type && DT_DIR) { continue; } size_t len = strlen(entry->d_name); char* buf = calloc(1, len + 1); memcpy(buf, entry->d_name, len); - taosArrayPush(result, &buf); + taosArrayPush(files, &buf); } closedir(dir); - return 0; + + taosArraySort(files, tfileCompare); + tfileRmExpireFile(files); + + return files; } static int tfileRmExpireFile(SArray* result) { // TODO(yihao): remove expire tindex after restart @@ -641,15 +647,21 @@ static int tfileCompare(const void* a, const void* b) { if (ret == 0) { return ret; } return ret < 0 ? -1 : 1; } -// tfile name suid-colId-version.tindex -static void tfileGenFileName(char* filename, uint64_t suid, int colId, int version) { - sprintf(filename, "%" PRIu64 "-%d-%d.tindex", suid, colId, version); - return; -} -static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId, int* version) { - if (3 == sscanf(filename, "%" PRIu64 "-%d-%d.tindex", suid, colId, version)) { + +static int tfileParseFileName(const char* filename, uint64_t* suid, char* col, int* version) { + if (3 == sscanf(filename, "%" PRIu64 "-%[^-]-%d.tindex", suid, col, version)) { // read suid & colid & version success return 0; } return -1; } +// tfile name suid-colId-version.tindex +static void tfileGenFileName(char* filename, uint64_t suid, const char* col, int version) { + sprintf(filename, "%" PRIu64 "-%s-%d.tindex", suid, col, version); + return; +} +static void tfileGenFileFullName(char* fullname, const char* path, uint64_t suid, const char* col, int32_t version) { + char filename[128] = {0}; + tfileGenFileName(filename, suid, col, version); + sprintf(fullname, "%s/%s", path, filename); +} diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index bdfb86ce17..3a8a880b3b 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -13,6 +13,7 @@ * along with this program. If not, see . */ #include +#include #include #include #include @@ -638,7 +639,7 @@ class IndexObj { indexInit(); } int Init(const std::string& dir) { - taosRemoveDir(dir.c_str()); + // taosRemoveDir(dir.c_str()); taosMkDir(dir.c_str()); int ret = indexOpen(&opts, dir.c_str(), &idx); if (ret != 0) { @@ -663,10 +664,11 @@ class IndexObj { int WriteMultiMillonData(const std::string& colName, const std::string& colVal = "Hello world", size_t numOfTable = 100 * 10000) { std::string tColVal = colVal; + size_t colValSize = tColVal.size(); for (int i = 0; i < numOfTable; i++) { - tColVal[tColVal.size() - 1] = 'a' + i % 26; + tColVal[i % colValSize] = 'a' + i % 26; SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); + tColVal.c_str(), tColVal.size()); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); for (size_t i = 0; i < 10; i++) { @@ -695,7 +697,13 @@ class IndexObj { indexMultiTermQueryAdd(mq, term, QUERY_TERM); SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t)); - if (Search(mq, result) == 0) { std::cout << "search one successfully" << std::endl; } + + int64_t s = taosGetTimestampUs(); + if (Search(mq, result) == 0) { + int64_t e = taosGetTimestampUs(); + std::cout << "search one successfully and time cost:" << e - s << std::endl; + } else { + } int sz = taosArrayGetSize(result); indexMultiTermQueryDestroy(mq); taosArrayDestroy(result); @@ -810,12 +818,12 @@ TEST_F(IndexEnv2, testIndexOpen) { } TEST_F(IndexEnv2, testIndex_TrigeFlush) { - std::string path = "/tmp/test1"; + std::string path = "/tmp/testxxx"; if (index->Init(path) != 0) { // r std::cout << "failed to init" << std::endl; } - int numOfTable = 100 * 10000; + int numOfTable = 2 * 10000; index->WriteMillonData("tag1", "Hello Wolrd", numOfTable); int target = index->SearchOne("tag1", "Hello Wolrd"); std::cout << "Get Index: " << target << std::endl; @@ -826,6 +834,10 @@ static void write_and_search(IndexObj* idx) { std::string colName("tag1"), colVal("Hello"); int target = idx->SearchOne("tag1", "Hello"); + std::cout << "search: " << target << std::endl; + target = idx->SearchOne("tag2", "Test"); + std::cout << "search: " << target << std::endl; + idx->PutOne(colName, colVal); } TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { @@ -833,7 +845,10 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { if (index->Init(path) != 0) { // opt } - index->WriteMultiMillonData("tag1", "Hello", 200000); + index->PutOne("tag1", "Hello"); + index->PutOne("tag2", "Test"); + index->WriteMultiMillonData("tag1", "Hello", 5 * 10000); + index->WriteMultiMillonData("tag2", "Test", 5 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { @@ -847,15 +862,15 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { } TEST_F(IndexEnv2, testIndex_restart) { - std::string path = "/tmp"; + std::string path = "/tmp/test1"; if (index->Init(path) != 0) {} } TEST_F(IndexEnv2, testIndex_performance) { - std::string path = "/tmp"; + std::string path = "/tmp/test2"; if (index->Init(path) != 0) {} } TEST_F(IndexEnv2, testIndexMultiTag) { - std::string path = "/tmp"; + std::string path = "/tmp/test3"; if (index->Init(path) != 0) {} } From c1a2366d673702e5939604b40e56df159f850efd Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 3 Jan 2022 22:28:01 +0800 Subject: [PATCH 50/56] refactor code --- source/libs/index/src/index.c | 3 +++ source/libs/index/src/index_fst_counting_writer.c | 2 ++ source/libs/index/src/index_tfile.c | 11 +++++++---- source/libs/index/test/indexTests.cc | 6 +++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index ff973dd7e3..0657c68458 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -73,6 +73,7 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { #ifdef USE_INVERTED_INDEX // sIdx->cache = (void*)indexCacheCreate(sIdx); sIdx->tindex = indexTFileCreate(path); + if (sIdx->tindex == NULL) { goto END; } sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); sIdx->cVersion = 1; sIdx->path = calloc(1, strlen(path) + 1); @@ -83,6 +84,8 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { return 0; #endif +END: + if (sIdx != NULL) { indexClose(sIdx); } *index = NULL; return -1; diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index fb730d5f70..0f29da1c27 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -72,12 +72,14 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int if (readOnly == false) { // ctx->file.fd = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO); ctx->file.fd = tfOpenCreateWriteAppend(path); + struct stat fstat; stat(path, &fstat); ctx->file.size = fstat.st_size; } else { // ctx->file.fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO); ctx->file.fd = tfOpenRead(path); + struct stat fstat; stat(path, &fstat); ctx->file.size = fstat.st_size; diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 9c4d1d1139..d4d13ddf19 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -66,12 +66,14 @@ TFileCache* tfileCacheCreate(const char* path) { int32_t colId, version; for (size_t i = 0; i < taosArrayGetSize(files); i++) { char* file = taosArrayGetP(files, i); - char colName[256] = {0}; + + // refactor later, use colname and version info + char colName[256] = {0}; if (0 != tfileParseFileName(file, &suid, colName, (int*)&version)) { indexInfo("try parse invalid file: %s, skip it", file); continue; } - // use version info later + char fullName[256] = {0}; sprintf(fullName, "%s/%s", path, file); @@ -204,7 +206,7 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SArray* resul TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const char* colName, uint8_t colType) { char fullname[256] = {0}; tfileGenFileFullName(fullname, path, suid, colName, version); - indexInfo("open write file name %s", fullname); + // indexInfo("open write file name %s", fullname); WriterCtx* wcx = writerCtxCreate(TFile, fullname, false, 1024 * 1024 * 64); if (wcx == NULL) { return NULL; } @@ -221,7 +223,7 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const c tfileGenFileFullName(fullname, path, suid, colName, version); WriterCtx* wc = writerCtxCreate(TFile, fullname, true, 1024 * 1024 * 1024); - indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size); + // indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size); if (wc == NULL) { return NULL; } TFileReader* reader = tfileReaderCreate(wc); @@ -356,6 +358,7 @@ IndexTFile* indexTFileCreate(const char* path) { return tfile; } void indexTFileDestroy(IndexTFile* tfile) { + if (tfile == NULL) { return; } tfileCacheDestroy(tfile->cache); free(tfile); } diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 3a8a880b3b..77b6e02f18 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -823,7 +823,7 @@ TEST_F(IndexEnv2, testIndex_TrigeFlush) { // r std::cout << "failed to init" << std::endl; } - int numOfTable = 2 * 10000; + int numOfTable = 100 * 10000; index->WriteMillonData("tag1", "Hello Wolrd", numOfTable); int target = index->SearchOne("tag1", "Hello Wolrd"); std::cout << "Get Index: " << target << std::endl; @@ -847,8 +847,8 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { } index->PutOne("tag1", "Hello"); index->PutOne("tag2", "Test"); - index->WriteMultiMillonData("tag1", "Hello", 5 * 10000); - index->WriteMultiMillonData("tag2", "Test", 5 * 10000); + index->WriteMultiMillonData("tag1", "Hello", 50 * 10000); + index->WriteMultiMillonData("tag2", "Test", 50 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { From 513ba4b9a9faf899f37385d32da908c978f09134 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 02:23:46 +0000 Subject: [PATCH 51/56] more --- .devcontainer/devcontainer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fd0ada95d9..65d0b1915c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -19,7 +19,9 @@ "ms-vscode.cmake-tools", "austin.code-gnu-global", "visualstudioexptteam.vscodeintel", - "eamodio.gitlens" + "eamodio.gitlens", + "matepek.vscode-catch2-test-adapter", + "spmeesseman.vscode-taskexplorer" ], // Use 'forwardPorts' to make a list of ports inside the container available locally. From 2b7b433a95637390a2ed130c51ad181475b90854 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 10:30:57 +0800 Subject: [PATCH 52/56] [td-11818] fix deadlock. --- source/client/src/clientMain.c | 4 +++- source/libs/scheduler/src/scheduler.c | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index e7c44d9f28..e5f3eba5c2 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -29,7 +29,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { // this function may be called by user or system, or by both simultaneously. void taos_cleanup(void) { - tscDebug("start to cleanup client environment"); + tscInfo("start to cleanup client environment"); if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) { return; @@ -47,6 +47,8 @@ void taos_cleanup(void) { rpcCleanup(); taosCloseLog(); + + tscInfo("all local resources released"); } TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 8ef67a8e93..bcdbc57798 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -456,15 +456,27 @@ int32_t schProcessOnTaskFailure(SSchJob *job, SSchTask *task, int32_t errCode) { int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, int32_t rspCode) { int32_t code = 0; - + + switch (msgType) { + case TDMT_VND_CREATE_TABLE_RSP: { + if (rspCode != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); + } else { +// job->resNumOfRows += rsp->affectedRows; + code = schProcessOnTaskSuccess(job, task); + if (code) { + goto _task_error; + } + } + } case TDMT_VND_SUBMIT_RSP: { - SShellSubmitRspMsg *rsp = (SShellSubmitRspMsg *)msg; - if (rsp->code != TSDB_CODE_SUCCESS) { - SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rsp->code)); + if (rspCode != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); } else { + SShellSubmitRspMsg *rsp = (SShellSubmitRspMsg *)msg; job->resNumOfRows += rsp->affectedRows; - + code = schProcessOnTaskSuccess(job, task); if (code) { goto _task_error; From 26796d19a709fea7ebe707855c374f900fe5165f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 4 Jan 2022 02:49:54 +0000 Subject: [PATCH 53/56] fix encode and decode bug --- source/common/src/tmsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 0874c471aa..c1048f8482 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -140,6 +140,7 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) { buf = taosDecodeFixedU64(buf, &pReq->ver); buf = taosDecodeFixedU32(buf, &nsize); + pReq->pArray = taosArrayInit(nsize, sizeof(SVCreateTbReq)); for (size_t i = 0; i < nsize; i++) { SVCreateTbReq req; buf = tDeserializeSVCreateTbReq(buf, &req); From 961ffa77e123d1a9983737d689fbf48cb3b7bd6e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 10:55:28 +0800 Subject: [PATCH 54/56] [td-11818] fix bug in create multiple tables; --- source/client/test/clientTests.cpp | 33 ++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index a3116fecea..ae1a36bd36 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -465,12 +465,12 @@ TEST(testCase, connect_Test) { TEST(testCase, create_multiple_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); + ASSERT_NE(pConn, nullptr); TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); + pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)"); if (taos_errno(pRes) != 0) { printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); @@ -490,3 +490,32 @@ TEST(testCase, create_multiple_tables) { taos_free_result(pRes); taos_close(pConn); } + +//TEST(testCase, projection_query_tables) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// ASSERT_EQ(pConn, nullptr); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "select * from t_2"); +// if (taos_errno(pRes) != 0) { +// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } +// +// TAOS_ROW pRow = NULL; +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// int32_t numOfFields = taos_num_fields(pRes); +// +// char str[512] = {0}; +// while((pRow = taos_fetch_row(pRes)) != NULL) { +// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); +// printf("%s\n", str); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} + From d862dcae8387d85fdb620b31467b437dc877d722 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 12:58:39 +0800 Subject: [PATCH 55/56] [td-11818] refactor, fix bug in repeat create table, add request id for each query. --- include/libs/planner/planner.h | 2 +- include/os/osSysinfo.h | 2 - source/client/inc/clientInt.h | 2 + source/client/src/clientEnv.c | 34 ++++++- source/client/src/clientImpl.c | 3 +- source/client/test/clientTests.cpp | 135 +++++++++++++++---------- source/libs/planner/inc/plannerInt.h | 2 +- source/libs/planner/src/physicalPlan.c | 5 +- source/libs/planner/src/planner.c | 4 +- source/libs/transport/src/rpcMain.c | 2 +- source/os/src/osSysinfo.c | 4 - 11 files changed, 126 insertions(+), 69 deletions(-) diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 5ad53703c7..a310b04e9e 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -141,7 +141,7 @@ struct SQueryNode; /** * Create the physical plan for the query, according to the AST. */ -int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag); +int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag, uint64_t requestId); // Set datasource of this subplan, multiple calls may be made to a subplan. // @subplan subplan to be schedule diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 6952b91742..b410255ea4 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -68,8 +68,6 @@ typedef struct { SysNameInfo taosGetSysNameInfo(); -int64_t taosGetPid(); - #ifdef __cplusplus } #endif diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 7aa4bc9ee9..705d6ef786 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -146,6 +146,8 @@ int taos_init(); void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo); void destroyTscObj(void*pObj); +uint64_t generateRequestId(); + void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type); void destroyRequest(SRequestObj* pRequest); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 960ba95324..bfb884c57e 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -87,6 +87,7 @@ static void tscInitLogFile() { } } +// todo close the transporter properly void closeTransporter(STscObj* pTscObj) { if (pTscObj == NULL || pTscObj->pTransporter == NULL) { return; @@ -166,8 +167,7 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty return NULL; } - // TODO generated request uuid - pRequest->requestId = 0; + pRequest->requestId = generateRequestId(); pRequest->metric.start = taosGetTimestampMs(); pRequest->type = type; @@ -410,6 +410,36 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { return 0; } +/** + * The request id is an unsigned integer format of 64bit. + *+------------+-----+-----------+---------------+ + *| uid|localIp| PId | timestamp | serial number | + *+------------+-----+-----------+---------------+ + *| 16bit |12bit|20bit |16bit | + *+------------+-----+-----------+---------------+ + * @return + */ +static int32_t requestSerialId = 0; +uint64_t generateRequestId() { + uint64_t hashId = 0; + + char uid[64] = {0}; + int32_t code = taosGetSystemUid(uid, tListLen(uid)); + if (code != TSDB_CODE_SUCCESS) { + tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead", tstrerror(TAOS_SYSTEM_ERROR(errno))); + + } else { + hashId = MurmurHash3_32(uid, strlen(uid)); + } + + int64_t ts = taosGetTimestampUs(); + uint64_t pid = taosGetPId(); + int32_t val = atomic_add_fetch_32(&requestSerialId, 1); + + uint64_t id = ((hashId & 0xFFFF) << 48) | ((pid & 0x0FFF) << 36) | ((ts & 0xFFFFF) << 16) | (val & 0xFFFF); + return id; +} + #if 0 #include "cJSON.h" static setConfRet taos_set_config_imp(const char *config){ diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index b0b2c57ee4..0d590235ad 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -198,13 +198,14 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) { int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { pRequest->type = pQuery->type; - return qCreateQueryDag(pQuery, pDag); + return qCreateQueryDag(pQuery, pDag, pRequest->requestId); } int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) { return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows); } + return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index ae1a36bd36..bb40d9ada2 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -147,29 +147,29 @@ TEST(testCase, connect_Test) { // taos_close(pConn); //} -//TEST(testCase, create_db_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create database abc1 vgroups 4"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_close(pConn); -//} +TEST(testCase, create_db_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database abc1 vgroups 4"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + taos_close(pConn); +} // //TEST(testCase, create_dnode_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -249,36 +249,36 @@ TEST(testCase, connect_Test) { //// taos_close(pConn); //} -// TEST(testCase, create_stable_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// 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)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); -// if (taos_errno(pRes) != 0) { -// printf("error in create stable, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_free_result(pRes); -// taos_close(pConn); -//} + TEST(testCase, create_stable_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + 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)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); + if (taos_errno(pRes) != 0) { + printf("error in create stable, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + taos_close(pConn); +} //TEST(testCase, create_table_Test) { // // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -470,7 +470,15 @@ TEST(testCase, create_multiple_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)"); + pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); + if (taos_errno(pRes) != 0) { + printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + taos_free_result(pRes); + pRes = taos_query(pConn, "create table t_3 using st1 tags(2)"); if (taos_errno(pRes) != 0) { printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); @@ -491,6 +499,25 @@ TEST(testCase, create_multiple_tables) { taos_close(pConn); } +TEST(testCase, generated_request_id_test) { + uint64_t id0 = generateRequestId(); + + uint64_t id1 = generateRequestId(); + uint64_t id2 = generateRequestId(); + uint64_t id3 = generateRequestId(); + uint64_t id4 = generateRequestId(); + + ASSERT_NE(id0, id1); + ASSERT_NE(id1, id2); + ASSERT_NE(id2, id3); + ASSERT_NE(id4, id3); + ASSERT_NE(id0, id2); + ASSERT_NE(id0, id4); + ASSERT_NE(id0, id3); + +// SHashObj *phash = taosHashInit() +} + //TEST(testCase, projection_query_tables) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // ASSERT_EQ(pConn, nullptr); diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index 4b248f90e7..ebd75b9a82 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -105,7 +105,7 @@ int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str); */ int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql); -int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag); +int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag, uint64_t requestId); int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep); int32_t subPlanToString(const SSubplan *pPhyNode, char** str, int32_t* len); int32_t stringToSubplan(const char* str, SSubplan** subplan); diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index a53cbe836d..4ff9881ccd 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -309,6 +309,7 @@ static void splitModificationOpSubPlan(SPlanContext* pCxt, SQueryPlanNode* pPlan subplan->pNode = NULL; subplan->type = QUERY_TYPE_MODIFY; subplan->msgType = pPayload->msgType; + subplan->id.queryId = pCxt->pDag->queryId; RECOVERY_CURRENT_SUBPLAN(pCxt); } @@ -328,7 +329,7 @@ static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { // todo deal subquery } -int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag) { +int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag, uint64_t requestId) { TRY(TSDB_MAX_TAG_CONDITIONS) { SPlanContext context = { .pCatalog = pCatalog, @@ -338,6 +339,8 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD }; *pDag = context.pDag; + context.pDag->queryId = requestId; + context.pDag->pSubplans = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); createSubplanByLevel(&context, pQueryNode); } CATCH(code) { diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 9621c2e227..388a57c7e3 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -24,7 +24,7 @@ void qDestroyQueryDag(struct SQueryDag* pDag) { // todo } -int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) { +int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag, uint64_t requestId) { SQueryPlanNode* logicPlan; int32_t code = createQueryPlan(pNode, &logicPlan); if (TSDB_CODE_SUCCESS != code) { @@ -38,7 +38,7 @@ int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) return code; } - code = createDag(logicPlan, NULL, pDag); + code = createDag(logicPlan, NULL, pDag, requestId); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); qDestroyQueryDag(*pDag); diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 19fe803035..310944e9b6 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -700,7 +700,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { pConn->sid = sid; pConn->tranId = (uint16_t)(taosRand() & 0xFFFF); pConn->ownId = htonl(pConn->sid); - pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPid() + (int64_t)pConn->tranId); + pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPId() + (int64_t)pConn->tranId); pConn->spi = pRpc->spi; pConn->encrypt = pRpc->encrypt; if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_PASSWORD_LEN); diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index cb231e15a0..df006f44eb 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -1130,8 +1130,4 @@ SysNameInfo taosGetSysNameInfo() { return info; } -int64_t taosGetPid() { - getpid(); -} - #endif \ No newline at end of file From 0d3972ed277cf4b22675e0739b2aec6e0bea8e9e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 13:00:49 +0800 Subject: [PATCH 56/56] [td-11818] fix compiler error in a unit test. --- source/libs/planner/test/phyPlanTests.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/planner/test/phyPlanTests.cpp b/source/libs/planner/test/phyPlanTests.cpp index 02d06bb49d..b6f9612653 100644 --- a/source/libs/planner/test/phyPlanTests.cpp +++ b/source/libs/planner/test/phyPlanTests.cpp @@ -45,7 +45,8 @@ protected: int32_t run() { SQueryDag* dag = nullptr; - int32_t code = createDag(logicPlan_.get(), nullptr, &dag); + uint64_t requestId = 20; + int32_t code = createDag(logicPlan_.get(), nullptr, &dag, requestId); dag_.reset(dag); return code; } @@ -60,7 +61,8 @@ protected: return code; } SQueryDag* dag = nullptr; - code = qCreateQueryDag(query, &dag); + uint64_t requestId = 20; + code = qCreateQueryDag(query, &dag, requestId); dag_.reset(dag); return code; }