diff --git a/include/common/taosmsg.h b/include/common/taosmsg.h index a8281d95a5e5b07cd8958457f53efc8f8ec96e1b..ec51a67808aafdc2c183111a785cf7d0ad3013ef 100644 --- a/include/common/taosmsg.h +++ b/include/common/taosmsg.h @@ -52,6 +52,10 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONNECT, "mq-connect" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_SET_CUR, "mq-set-cur" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RES_READY, "res-ready" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TASKS_STATUS, "tasks-status" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CANCEL_TASK, "cancel-task" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TASK, "drop-task" ) + // message from client to mnode TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONNECT, "connect" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_ACCT, "create-acct" ) @@ -78,8 +82,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB, "create-stb" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB, "alter-stb" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB, "drop-stb" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_VGROUP_LIST, "vgroup-list" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_STREAM, "kill-stream" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_HEARTBEAT, "heartbeat" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW, "show" ) @@ -95,15 +98,15 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" ) // message from mnode to vnode TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB_IN, "create-stb-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB_IN, "alter-stb-internal" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB_IN, "alter-stb-internal" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB_IN, "drop-stb-internal" ) // message from mnode to mnode // message from mnode to qnode // message from mnode to dnode TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_VNODE_IN, "create-vnode-internal" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_VNODE_IN, "alter-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_VNODE_IN, "drop-vnode-internal" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_AUTH_VNODE_IN, "auth-vnode-internal" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_VNODE_IN, "drop-vnode-internal" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_AUTH_VNODE_IN, "auth-vnode-internal" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_VNODE_IN, "sync-vnode-internal" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_VNODE_IN, "compact-vnode-internal" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE_IN, "create-mnode-internal" ) @@ -290,13 +293,52 @@ typedef struct SSchema { char name[TSDB_COL_NAME_LEN]; } SSchema; +typedef struct { + int32_t contLen; + int32_t vgId; + int8_t tableType; + int16_t numOfColumns; + int16_t numOfTags; + int32_t tid; + int32_t sversion; + int32_t tversion; + int32_t tagDataLen; + int32_t sqlDataLen; + uint64_t uid; + uint64_t superTableUid; + uint64_t createdTime; + char tableFname[TSDB_TABLE_FNAME_LEN]; + char stbFname[TSDB_TABLE_FNAME_LEN]; + char data[]; +} SMDCreateTableMsg; + +//typedef struct { +// int32_t len; // one create table message +// char tableName[TSDB_TABLE_FNAME_LEN]; +// int16_t numOfColumns; +// int16_t sqlLen; // the length of SQL, it starts after schema , sql is a null-terminated string +// int8_t igExists; +// int8_t rspMeta; +// int8_t reserved[16]; +// char schema[]; +//} SCreateTableMsg; + +typedef struct { + char tableName[TSDB_TABLE_FNAME_LEN]; + int16_t numOfColumns; + int16_t numOfTags; + int8_t igExists; + int8_t rspMeta; + char schema[]; +} SCreateCTableMsg; + typedef struct { char name[TSDB_TABLE_FNAME_LEN]; int8_t igExists; int32_t numOfTags; int32_t numOfColumns; SSchema pSchema[]; -} SCreateStbMsg; +} SCreateStbMsg, SCreateTableMsg; typedef struct { char name[TSDB_TABLE_FNAME_LEN]; @@ -327,19 +369,6 @@ typedef struct { uint64_t suid; } SDropStbInternalMsg; -typedef struct { - SMsgHead head; - char name[TSDB_TABLE_FNAME_LEN]; - char stbFname[TSDB_TABLE_FNAME_LEN]; - int8_t tableType; - uint64_t suid; - int32_t sversion; - int32_t numOfTags; - int32_t numOfColumns; - int32_t tagDataLen; - char data[]; -} SCreateTableMsg; - typedef struct { SMsgHead head; char name[TSDB_TABLE_FNAME_LEN]; @@ -352,6 +381,7 @@ typedef struct { typedef struct { SMsgHead head; char name[TSDB_TABLE_FNAME_LEN]; + int8_t ignoreNotExists; } SDropTableMsg; typedef struct { @@ -946,18 +976,6 @@ typedef struct { char subSqlInfo[TSDB_SHOW_SUBQUERY_LEN]; // include subqueries' index, Obj IDs and states(C-complete/I-imcomplete) } SQueryDesc; -typedef struct { - char sql[TSDB_SHOW_SQL_LEN]; - char dstTable[TSDB_TABLE_NAME_LEN]; - int32_t streamId; - int64_t num; // number of computing/cycles - int64_t useconds; - int64_t ctime; - int64_t stime; - int64_t slidingTime; - int64_t interval; -} SStreamDesc; - typedef struct { int32_t connId; int32_t pid; @@ -1093,29 +1111,29 @@ typedef struct { /* data */ } SUpdateTagValRsp; -typedef struct SSchedulerQueryMsg { +typedef struct SSubQueryMsg { uint64_t schedulerId; uint64_t queryId; uint64_t taskId; uint32_t contentLen; char msg[]; -} SSchedulerQueryMsg; +} SSubQueryMsg; -typedef struct SSchedulerReadyMsg { +typedef struct SResReadyMsg { uint64_t schedulerId; uint64_t queryId; uint64_t taskId; -} SSchedulerReadyMsg; +} SResReadyMsg; -typedef struct SSchedulerFetchMsg { +typedef struct SResFetchMsg { uint64_t schedulerId; uint64_t queryId; uint64_t taskId; -} SSchedulerFetchMsg; +} SResFetchMsg; -typedef struct SSchedulerStatusMsg { +typedef struct SSchTasksStatusMsg { uint64_t schedulerId; -} SSchedulerStatusMsg; +} SSchTasksStatusMsg; typedef struct STaskStatus { uint64_t queryId; @@ -1129,11 +1147,17 @@ typedef struct SSchedulerStatusRsp { } SSchedulerStatusRsp; -typedef struct SSchedulerCancelMsg { +typedef struct STaskCancelMsg { + uint64_t schedulerId; + uint64_t queryId; + uint64_t taskId; +} STaskCancelMsg; + +typedef struct STaskDropMsg { uint64_t schedulerId; uint64_t queryId; uint64_t taskId; -} SSchedulerCancelMsg; +} STaskDropMsg; #pragma pack(pop) diff --git a/include/common/tmsgtype.h b/include/common/tmsgtype.h index 09765031155679accc6f6d4043e23b3b89409135..8e7ad87a0ac9184e18a6e62837bbf821192b1ec0 100644 --- a/include/common/tmsgtype.h +++ b/include/common/tmsgtype.h @@ -102,14 +102,6 @@ enum { TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MAX, "max" ) }; -// create table operation type -enum TSQL_CREATE_TABLE_TYPE { - TSQL_CREATE_TABLE = 0x1, - TSQL_CREATE_STABLE = 0x2, - TSQL_CREATE_CTABLE = 0x3, - TSQL_CREATE_STREAM = 0x4, -}; - #ifdef __cplusplus } #endif diff --git a/include/common/tname.h b/include/common/tname.h index e31bfd38a67dd5e01e6a3246e490d998bf50331f..de9e309b5508aeb682c09d6df4766700900fdb16 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -16,8 +16,6 @@ #ifndef TDENGINE_TNAME_H #define TDENGINE_TNAME_H -//#include "taosmsg.h" - #define TSDB_DB_NAME_T 1 #define TSDB_TABLE_NAME_T 2 diff --git a/include/dnode/vnode/tq/tq.h b/include/dnode/vnode/tq/tq.h index 60a8c252c0b511e145e611814827626a48ed86bd..f5d5cc9a166bdd99edd22d69aa08d60044c7d9fd 100644 --- a/include/dnode/vnode/tq/tq.h +++ b/include/dnode/vnode/tq/tq.h @@ -22,6 +22,8 @@ #include "taoserror.h" #include "taosmsg.h" #include "tlist.h" +#include "trpc.h" +#include "ttimer.h" #include "tutil.h" #ifdef __cplusplus @@ -54,6 +56,7 @@ typedef struct STqSetCurReq { typedef struct STqConsumeReq { STqMsgHead head; + int64_t blockingTime; // milisec STqAcks acks; } STqConsumeReq; @@ -101,33 +104,44 @@ typedef struct STqTopicVhandle { typedef struct STqExec { void* runtimeEnv; SSDataBlock* (*exec)(void* runtimeEnv); - void* (*assign)(void* runtimeEnv, SSubmitBlk* inputData); + void* (*assign)(void* runtimeEnv, void* inputData); void (*clear)(void* runtimeEnv); char* (*serialize)(struct STqExec*); struct STqExec* (*deserialize)(char*); } STqExec; +typedef struct STqRspHandle { + void* handle; + void* ahandle; +} STqRspHandle; + +typedef enum { TQ_ITEM_READY, TQ_ITEM_PROCESS, TQ_ITEM_EMPTY } STqItemStatus; + +typedef struct STqTopic STqTopic; + typedef struct STqBufferItem { int64_t offset; // executors are identical but not concurrent // so there must be a copy in each item - STqExec* executor; - int32_t status; - int64_t size; - void* content; + STqExec* executor; + int32_t status; + int64_t size; + void* content; + STqTopic* pTopic; } STqMsgItem; -typedef struct STqTopic { +struct STqTopic { // char* topic; //c style, end with '\0' // int64_t cgId; // void* ahandle; + // int32_t head; + // int32_t tail; int64_t nextConsumeOffset; int64_t floatingCursor; int64_t topicId; - int32_t head; - int32_t tail; + void* logReader; STqMsgItem buffer[TQ_BUFFER_SIZE]; -} STqTopic; +}; typedef struct STqListHandle { STqTopic topic; @@ -135,13 +149,13 @@ typedef struct STqListHandle { } STqList; typedef struct STqGroup { - int64_t clientId; - int64_t cgId; - void* ahandle; - int32_t topicNum; - STqList* head; - SList* topicList; // SList - void* returnMsg; // SVReadMsg + int64_t clientId; + int64_t cgId; + void* ahandle; + int32_t topicNum; + STqList* head; + SList* topicList; // SList + STqRspHandle rspHandle; } STqGroup; typedef struct STqQueryMsg { @@ -149,20 +163,23 @@ typedef struct STqQueryMsg { struct STqQueryMsg* next; } STqQueryMsg; -typedef struct STqLogReader { +typedef struct STqLogHandle { void* logHandle; - int32_t (*logRead)(void* logHandle, void** data, int64_t ver); + void* (*openLogReader)(void* logHandle); + void (*closeLogReader)(void* logReader); + int32_t (*logRead)(void* logReader, void** data, int64_t ver); + int64_t (*logGetFirstVer)(void* logHandle); int64_t (*logGetSnapshotVer)(void* logHandle); int64_t (*logGetLastVer)(void* logHandle); -} STqLogReader; +} STqLogHandle; typedef struct STqCfg { // TODO } STqCfg; typedef struct STqMemRef { - SMemAllocatorFactory* pAlloctorFactory; + SMemAllocatorFactory* pAllocatorFactory; SMemAllocator* pAllocator; } STqMemRef; @@ -252,19 +269,30 @@ typedef struct STQ { // the handle of meta kvstore char* path; STqCfg* tqConfig; - STqLogReader* tqLogReader; + STqLogHandle* tqLogHandle; STqMemRef tqMemRef; STqMetaStore* tqMeta; } STQ; +typedef struct STqMgmt { + int8_t inited; + tmr_h timer; +} STqMgmt; + +static STqMgmt tqMgmt; + +// init once +int tqInit(); +void tqCleanUp(); + // open in each vnode -STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemAllocatorFactory* allocFac); +STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogHandle* tqLogHandle, SMemAllocatorFactory* allocFac); void tqClose(STQ*); // void* will be replace by a msg type int tqPushMsg(STQ*, void* msg, int64_t version); int tqCommit(STQ*); -int tqConsume(STQ*, STqConsumeReq*); +int tqConsume(STQ*, SRpcMsg* pReq, SRpcMsg** pRsp); int tqSetCursor(STQ*, STqSetCurReq* pMsg); int tqBufferSetOffset(STqTopic*, int64_t offset); diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index d51ac48f017426cae719d8b8816753da5d7ce753..e708d7b545ac2f644755d7345e0af943bdee77ca 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -122,6 +122,16 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs); */ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); +/** + * @brief Process a consume message. + * + * @param pVnode The vnode object. + * @param pMsg The request message + * @param pRsp The response message + * @return int 0 for success, -1 for failure + */ +int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); + /** * @brief Process the sync request * diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 68eae03f518441aad3aeb17837045cb66b34a92d..592c5f707c25bff03e2fea23c790a9687eea7ef5 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -115,14 +115,14 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S /** * Get a table's vgroup from its name's hash value. * @param pCatalog (input, got with catalogGetHandle) - * @param pRpc (input, rpc object) + * @param pTransporter (input, rpc object) * @param pMgmtEps (input, mnode EPs) * @param pDBName (input, full db name) * @param pTableName (input, table name, NOT including db name) * @param vgInfo (output, vgroup info) * @return error code */ -int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo); +int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo); /** diff --git a/include/libs/parser/parsenodes.h b/include/libs/parser/parsenodes.h new file mode 100644 index 0000000000000000000000000000000000000000..250739c1e649ab47af10b63f5c3355b4b718c9ee --- /dev/null +++ b/include/libs/parser/parsenodes.h @@ -0,0 +1,174 @@ +/* + * 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_PARSENODES_H_ +#define _TD_PARSENODES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "catalog.h" +#include "common.h" +#include "function.h" +#include "tmsgtype.h" +#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. + */ +typedef struct SQueryNode { + int16_t type; +} SQueryNode; + +#define nodeType(nodeptr) (((const SQueryNode*)(nodeptr))->type) + +typedef struct SField { + char name[TSDB_COL_NAME_LEN]; + uint8_t type; + int32_t bytes; +} SField; + +typedef struct SParseBasicCtx { + const char *db; + int32_t acctId; + uint64_t requestId; +} SParseBasicCtx; + +typedef struct SFieldInfo { + int16_t numOfOutput; // number of column in result + SField *final; + SArray *internalField; // SArray +} SFieldInfo; + +typedef struct SCond { + uint64_t uid; + int32_t len; // length of tag query condition data + char * cond; +} SCond; + +typedef struct SJoinNode { + uint64_t uid; + int16_t tagColId; + SArray* tsJoin; + SArray* tagJoin; +} SJoinNode; + +typedef struct SJoinInfo { + bool hasJoin; + SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM]; +} SJoinInfo; + +typedef struct STagCond { + int16_t relType; // relation between tbname list and query condition, including : TK_AND or TK_OR + SCond tbnameCond; // tbname query condition, only support tbname query condition on one table + SJoinInfo joinInfo; // join condition, only support two tables join currently + SArray *pCond; // for different table, the query condition must be seperated +} STagCond; + +typedef struct STableMetaInfo { + STableMeta *pTableMeta; // table meta, cached in client side and acquired by name + SVgroupsInfo *vgroupList; + SName name; + char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql + SArray *tagColList; // SArray, involved tag columns +} STableMetaInfo; + +typedef struct SColumnIndex { + int16_t tableIndex; + int16_t columnIndex; + int16_t type; // normal column/tag/ user input constant column +} SColumnIndex; + +// select statement +typedef struct SQueryStmtInfo { + int16_t command; // the command may be different for each subclause, so keep it seperately. + uint32_t type; // query/insert type + STimeWindow window; // the whole query time window + SInterval interval; // tumble time window + SSessionWindow sessionWindow; // session time window + SStateWindow stateWindow; // state window query + SGroupbyExpr groupbyExpr; // groupby tags info + SArray * colList; // SArray + SFieldInfo fieldsInfo; + SArray** exprList; // SArray + SLimit limit; + SLimit slimit; + STagCond tagCond; + SArray * colCond; + SArray * order; + int16_t numOfTables; + int16_t curTableIdx; + STableMetaInfo **pTableMetaInfo; + struct STSBuf *tsBuf; + + int16_t fillType; // final result fill type + int64_t * fillVal; // default value for fill + int32_t numOfFillVal; // fill value size + + char * msg; // pointer to the pCmd->payload to keep error message temporarily + int64_t clauseLimit; // limit for current sub clause + + int64_t prjOffset; // offset value in the original sql expression, only applied at client side + int64_t vgroupLimit; // table limit in case of super table projection query + global order + limit + + int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX + int32_t bufLen; + char* buf; + SArray *pUdfInfo; + + struct SQueryStmtInfo *sibling; // sibling + struct SQueryStmtInfo *pDownstream; + SMultiFunctionsDesc info; + SArray *pUpstream; // SArray + int32_t havingFieldNum; + int32_t exprListLevelIndex; +} SQueryStmtInfo; + +typedef enum { + PAYLOAD_TYPE_KV = 0, + PAYLOAD_TYPE_RAW = 1, +} EPayloadType; + +typedef struct SVgDataBlocks { + SVgroupInfo vg; + int32_t numOfTables; // number of tables in current submit block + uint32_t size; + char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ... +} 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 + 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 +} SInsertStmtInfo; + +typedef struct SDclStmtInfo { + int16_t nodeType; + int16_t msgType; + char* pMsg; + int32_t msgLen; +} SDclStmtInfo; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_PARSENODES_H_*/ diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index df2170423f899b5ba1a8f2d9472e1fea4ccb72a3..7834bc6913476aff8023c6a2cb8fb51d4208e6bb 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -20,130 +20,18 @@ extern "C" { #endif -#include "catalog.h" -#include "common.h" -#include "tname.h" -#include "tvariant.h" -#include "function.h" - -typedef struct SField { - char name[TSDB_COL_NAME_LEN]; - uint8_t type; - int16_t bytes; -} SField; - -typedef struct SFieldInfo { - int16_t numOfOutput; // number of column in result - SField *final; - SArray *internalField; // SArray -} SFieldInfo; - -typedef struct SCond { - uint64_t uid; - int32_t len; // length of tag query condition data - char * cond; -} SCond; - -typedef struct SJoinNode { - uint64_t uid; - int16_t tagColId; - SArray* tsJoin; - SArray* tagJoin; -} SJoinNode; - -typedef struct SJoinInfo { - bool hasJoin; - SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM]; -} SJoinInfo; - -typedef struct STagCond { - int16_t relType; // relation between tbname list and query condition, including : TK_AND or TK_OR - SCond tbnameCond; // tbname query condition, only support tbname query condition on one table - SJoinInfo joinInfo; // join condition, only support two tables join currently - SArray *pCond; // for different table, the query condition must be seperated -} STagCond; - -typedef struct STableMetaInfo { - STableMeta *pTableMeta; // table meta, cached in client side and acquired by name - SVgroupsInfo *vgroupList; - SName name; - char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql - SArray *tagColList; // SArray, involved tag columns -} STableMetaInfo; - -typedef struct SQueryStmtInfo { - int16_t command; // the command may be different for each subclause, so keep it seperately. - uint32_t type; // query/insert type - STimeWindow window; // the whole query time window - SInterval interval; // tumble time window - SSessionWindow sessionWindow; // session time window - SStateWindow stateWindow; // state window query - SGroupbyExpr groupbyExpr; // groupby tags info - SArray * colList; // SArray - SFieldInfo fieldsInfo; - SArray** exprList; // SArray - SLimit limit; - SLimit slimit; - STagCond tagCond; - SArray * colCond; - SArray * order; - int16_t numOfTables; - int16_t curTableIdx; - STableMetaInfo **pTableMetaInfo; - struct STSBuf *tsBuf; - - int16_t fillType; // final result fill type - int64_t * fillVal; // default value for fill - int32_t numOfFillVal; // fill value size - - char * msg; // pointer to the pCmd->payload to keep error message temporarily - int64_t clauseLimit; // limit for current sub clause - - int64_t prjOffset; // offset value in the original sql expression, only applied at client side - int64_t vgroupLimit; // table limit in case of super table projection query + global order + limit - - int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX - int32_t bufLen; - char* buf; - SArray *pUdfInfo; - - struct SQueryStmtInfo *sibling; // sibling - struct SQueryStmtInfo *pDownstream; - SMultiFunctionsDesc info; - SArray *pUpstream; // SArray - int32_t havingFieldNum; - int32_t exprListLevelIndex; -} SQueryStmtInfo; - -typedef struct SColumnIndex { - int16_t tableIndex; - int16_t columnIndex; - int16_t type; // normal column/tag/ user input constant column -} SColumnIndex; - -struct SInsertStmtInfo; - -/** - * True will be returned if the input sql string is insert, false otherwise. - * @param pStr sql string - * @param length length of the sql string - * @return - */ -bool qIsInsertSql(const char* pStr, size_t length); +#include "parsenodes.h" typedef struct SParseContext { - const char* pAcctId; - const char* pDbname; - void *pRpc; - const char* pClusterId; - struct SCatalog* pCatalog; - const SEpSet* pEpSet; - int64_t id; // query id, generated by uuid generator - int8_t schemaAttached; // denote if submit block is built with table schema or not - const char* pSql; // sql string - size_t sqlLen; // length of the sql string - char* pMsg; // extended error message if exists to help avoid the problem in sql statement. - int32_t msgLen; // max length of the msg + SParseBasicCtx ctx; + void *pRpc; + struct SCatalog *pCatalog; + const SEpSet *pEpSet; + int8_t schemaAttached; // denote if submit block is built with table schema or not + const char *pSql; // sql string + size_t sqlLen; // length of the sql string + char *pMsg; // extended error message if exists to help avoid the problem in sql statement. + int32_t msgLen; // max length of the msg } SParseContext; /** @@ -154,37 +42,9 @@ typedef struct SParseContext { * @param msg extended error message if exists. * @return error code */ -int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t* type, void** pOutput, int32_t* outputLen, char* msg, int32_t msgLen); - -typedef enum { - PAYLOAD_TYPE_KV = 0, - PAYLOAD_TYPE_RAW = 1, -} EPayloadType; - -typedef struct SVgDataBlocks { - int64_t vgId; // virtual group id - int32_t numOfTables; // number of tables in current submit block - uint32_t size; - char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ... -} SVgDataBlocks; +int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery); -typedef struct SInsertStmtInfo { - SArray* pDataBlocks; // data block for each vgroup, SArray. - 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 -} SInsertStmtInfo; - -/** - * Parse the insert sql statement. - * @param pStr sql string - * @param length length of the sql string - * @param id operator id, generated by uuid generator. - * @param msg extended error message if exists to help avoid the problem in sql statement. - * @return data in binary format to submit to vnode directly. - */ - int32_t qParseInsertSql(SParseContext* pContext, struct SInsertStmtInfo** pInfo); +bool qIsDclQuery(const SQueryNode* pQuery); /** * Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that @@ -211,9 +71,9 @@ typedef struct SSourceParam { SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize); int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy); int32_t copyAllExprInfo(SArray* dst, const SArray* src, bool deepcopy); -int32_t getExprFunctionLevel(SQueryStmtInfo* pQueryInfo); +int32_t getExprFunctionLevel(const SQueryStmtInfo* pQueryInfo); -STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex); +STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex); SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex); SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name); diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 8b54b88b28fd908bf2ad9040918cdcf9a4c4eea0..d4469be5e3a5e2a03973b4c1bf0158eaf9875d2a 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -25,6 +25,7 @@ extern "C" { #define QUERY_TYPE_MERGE 1 #define QUERY_TYPE_PARTIAL 2 #define QUERY_TYPE_SCAN 3 +#define QUERY_TYPE_MODIFY 4 enum OPERATOR_TYPE_E { OP_Unknown, @@ -58,18 +59,17 @@ typedef struct SQueryNodeBasicInfo { typedef struct SDataSink { SQueryNodeBasicInfo info; - SDataBlockSchema schema; } SDataSink; typedef struct SDataDispatcher { SDataSink sink; - // todo } SDataDispatcher; typedef struct SDataInserter { SDataSink sink; - uint64_t uid; // unique id of the table - // todo data field + int32_t numOfTables; + uint32_t size; + char *pData; } SDataInserter; typedef struct SPhyNode { @@ -119,12 +119,13 @@ typedef struct SSubplanId { typedef struct SSubplan { SSubplanId id; // unique id of the subplan - int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN - int32_t level; // the execution level of current subplan, starting from 0. - SEpSet execEpSet; // for the scan sub plan, the optional execution node - SArray *pChildern; // 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 + 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. + SEpSet execEpSet; // for the scan/modify subplan, the optional execution node + SArray *pChildern; // 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 } SSubplan; typedef struct SQueryDag { @@ -133,10 +134,12 @@ typedef struct SQueryDag { SArray *pSubplans; // Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0. } SQueryDag; +struct SQueryNode; + /** * Create the physical plan for the query, according to the AST. */ -int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag); +int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag); // Set datasource of this subplan, multiple calls may be made to a subplan. // @subplan subplan to be schedule @@ -144,12 +147,12 @@ int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* // @ep one execution location of this group of datasource subplans int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep); -int32_t qExplainQuery(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, char** str); +int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str); /** * Convert to subplan to string for the scheduler to send to the executor */ -int32_t qSubPlanToString(const SSubplan* subplan, char** str); +int32_t qSubPlanToString(const SSubplan* subplan, char** str, int32_t* len); int32_t qStringToSubplan(const char* str, SSubplan** subplan); diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 4fcbc1c5282a7bf7f1339381ed17be8399a76ad4..877cfb130c3b338d701571c945d4b9b53db6bd91 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -25,12 +25,15 @@ extern "C" { #include "tlog.h" enum { + JOB_TASK_STATUS_NULL = 0, JOB_TASK_STATUS_NOT_START = 1, JOB_TASK_STATUS_EXECUTING, + JOB_TASK_STATUS_PARTIAL_SUCCEED, JOB_TASK_STATUS_SUCCEED, JOB_TASK_STATUS_FAILED, JOB_TASK_STATUS_CANCELLING, - JOB_TASK_STATUS_CANCELLED + JOB_TASK_STATUS_CANCELLED, + JOB_TASK_STATUS_DROPPING, }; typedef struct STableComInfo { @@ -90,15 +93,27 @@ typedef struct STableMetaOutput { STableMeta *tbMeta; } STableMetaOutput; +typedef int32_t __async_exec_fn_t(void* param); + bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); -extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); -extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize); +int32_t initTaskQueue(); +int32_t cleanupTaskQueue(); + +/** + * + * @param execFn The asynchronously execution function + * @param execParam The parameters of the execFn + * @param code The response code during execution the execFn + * @return + */ +int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code); SSchema* tGetTbnameColumnSchema(); -extern void msgInit(); +void initQueryModuleMsgHandle(); -extern int32_t qDebugFlag; +extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); +extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize); #define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0) #define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0) diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h index 63a6b6f89bee7100abd91426b979163a99cfd641..8e361784976c8929249198ff4bffc4366385fe07 100644 --- a/include/libs/qworker/qworker.h +++ b/include/libs/qworker/qworker.h @@ -42,15 +42,17 @@ typedef struct { int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt); -int32_t qWorkerProcessQueryMsg(void *qWorkerMgmt, SSchedulerQueryMsg *msg, SRpcMsg *rsp); +int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg **rsp); -int32_t qWorkerProcessReadyMsg(void *qWorkerMgmt, SSchedulerReadyMsg *msg, SRpcMsg *rsp); +int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); -int32_t qWorkerProcessStatusMsg(void *qWorkerMgmt, SSchedulerStatusMsg *msg, SRpcMsg *rsp); +int32_t qWorkerProcessStatusMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); -int32_t qWorkerProcessFetchMsg(void *qWorkerMgmt, SSchedulerFetchMsg *msg, SRpcMsg *rsp); +int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); -int32_t qWorkerProcessCancelMsg(void *qWorkerMgmt, SSchedulerCancelMsg *msg, SRpcMsg *rsp); +int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); + +int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp); void qWorkerDestroy(void **qWorkerMgmt); diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 89f24cf3a41eeb2b3bb7005bc1094e4068e4035d..67d2009d3b2b4ebe3e96226b6a26f519ff545a87 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -174,8 +174,11 @@ SWalReadHandle *walOpenReadHandle(SWal *); void walCloseReadHandle(SWalReadHandle *); int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver); +// deprecated +#if 0 int32_t walRead(SWal *, SWalHead **, int64_t ver); -// int32_t walReadWithFp(SWal *, FWalWrite writeFp, int64_t verStart, int32_t readNum); +int32_t walReadWithFp(SWal *, FWalWrite writeFp, int64_t verStart, int32_t readNum); +#endif // lifecycle check int64_t walGetFirstVer(SWal *); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 7e8df3add27cd16ca7db47f3e996185e9da49fc1..43629508445dbdcf81449723b3b201befe468c2b 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -314,6 +314,11 @@ int32_t* taosGetErrno(); #define TSDB_CODE_QRY_INVALID_TIME_CONDITION TAOS_DEF_ERROR_CODE(0, 0x070D) //"invalid time condition") #define TSDB_CODE_QRY_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x070E) //"System error") #define TSDB_CODE_QRY_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0x070F) //"invalid input") +#define TSDB_CODE_QRY_SCH_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0710) //"Scheduler not exist") +#define TSDB_CODE_QRY_TASK_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0711) //"Task not exist") +#define TSDB_CODE_QRY_TASK_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0712) //"Task already exist") +#define TSDB_CODE_QRY_RES_CACHE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0713) //"Task result cache not exist") +#define TSDB_CODE_QRY_TASK_CANCELLED TAOS_DEF_ERROR_CODE(0, 0x0714) //"Task cancelled") // grant diff --git a/include/util/thash.h b/include/util/thash.h index ebdc91f0546a7ef9de3801f4eabf13f18c2cdf4c..d0247a0729012b860132cc691e6df745dde12a83 100644 --- a/include/util/thash.h +++ b/include/util/thash.h @@ -33,6 +33,8 @@ typedef void (*_hash_free_fn_t)(void *); #define HASH_INDEX(v, c) ((v) & ((c)-1)) +#define HASH_NODE_EXIST(code) (code == -2) + /** * murmur hash algorithm * @key usually string diff --git a/include/util/ttimer.h b/include/util/ttimer.h index 987d3f3cdc95f983b6d9bb54168da11aa5f8340a..89ec6cd8d9d000bd98effc8804c52be8ce48c740 100644 --- a/include/util/ttimer.h +++ b/include/util/ttimer.h @@ -16,6 +16,8 @@ #ifndef _TD_UTIL_TIMER_H #define _TD_UTIL_TIMER_H +#include "os.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index a1a9155d16d1a46b608e8ae0fe6fe999babc0e21..a34250ccab8f51355e0318bfc65d248234cb4d7e 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -137,24 +137,26 @@ typedef struct SRequestMsgBody { extern SAppInfo appInfo; extern int32_t tscReqRef; -extern void *tscQhandle; extern int32_t tscConnRef; -extern int (*buildRequestMsgFp[TSDB_SQL_MAX])(SRequestObj *pRequest, SRequestMsgBody *pMsgBody); -extern int (*handleRequestRspFp[TSDB_SQL_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); +SRequestMsgBody buildRequestMsgImpl(SRequestObj *pRequest); +extern int (*handleRequestRspFp[TSDB_MSG_TYPE_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); int taos_init(); -void* createTscObj(const char* user, const char* auth, const char *ip, uint32_t port, SAppInstInfo* pAppInfo); +void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo); void destroyTscObj(void*pObj); -void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type); -void destroyRequest(SRequestObj* pRequest); +void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type); +void destroyRequest(SRequestObj* pRequest); + +char *getConnectionDB(STscObj* pObj); +void setConnectionDB(STscObj* pTscObj, const char* db); void taos_init_imp(void); int taos_options_imp(TSDB_OPTION option, const char *str); -void* openTransporter(const char *user, const char *auth); +void* openTransporter(const char *user, const char *auth, int32_t numOfThreads); void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet); void initMsgHandleFp(); diff --git a/source/client/src/tscEnv.c b/source/client/src/clientEnv.c similarity index 95% rename from source/client/src/tscEnv.c rename to source/client/src/clientEnv.c index 182e330df7f9419c09ec1f9643e77df830a9a786..b54f7fedd788ea464714c17f033ac5b1bac48244 100644 --- a/source/client/src/tscEnv.c +++ b/source/client/src/clientEnv.c @@ -13,9 +13,11 @@ * along with this program. If not, see . */ +#include #include "clientInt.h" #include "clientLog.h" #include "os.h" +#include "query.h" #include "taosmsg.h" #include "tcache.h" #include "tconfig.h" @@ -23,7 +25,6 @@ #include "tnote.h" #include "tref.h" #include "trpc.h" -#include "tsched.h" #include "ttime.h" #include "ttimezone.h" @@ -33,10 +34,8 @@ SAppInfo appInfo; int32_t tscReqRef = -1; int32_t tscConnRef = -1; -void *tscQhandle = NULL; static pthread_once_t tscinit = PTHREAD_ONCE_INIT; -int32_t tsNumOfThreads = 1; volatile int32_t tscInitRes = 0; static void registerRequest(SRequestObj* pRequest) { @@ -98,12 +97,12 @@ void closeTransporter(STscObj* pTscObj) { } // TODO refactor -void* openTransporter(const char *user, const char *auth) { +void* openTransporter(const char *user, const char *auth, int32_t numOfThread) { SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.localPort = 0; rpcInit.label = "TSC"; - rpcInit.numOfThreads = tsNumOfThreads; + rpcInit.numOfThreads = numOfThread; rpcInit.cfp = processMsgFromServer; rpcInit.sessions = tsMaxConnections; rpcInit.connType = TAOS_CONN_CLIENT; @@ -131,7 +130,7 @@ void destroyTscObj(void *pObj) { tfree(pTscObj); } -void* createTscObj(const char* user, const char* auth, const char *ip, uint32_t port, SAppInstInfo* pAppInfo) { +void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo) { STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); if (NULL == pObj) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -146,6 +145,10 @@ void* createTscObj(const char* user, const char* auth, const char *ip, uint32_t tstrncpy(pObj->user, user, sizeof(pObj->user)); memcpy(pObj->pass, auth, TSDB_PASSWORD_LEN); + if (db != NULL) { + tstrncpy(pObj->db, db, tListLen(pObj->db)); + } + pthread_mutex_init(&pObj->mutex, NULL); pObj->id = taosAddRef(tscConnRef, pObj); @@ -222,25 +225,19 @@ void taos_init_imp(void) { taosInitNotes(); initMsgHandleFp(); + initQueryModuleMsgHandle(); rpcInit(); + SCatalogCfg cfg = {.enableVgroupCache = true, .maxDBCacheNum = 100, .maxTblCacheNum = 100}; + catalogInit(&cfg); + tscDebug("starting to initialize TAOS driver, local ep: %s", tsLocalEp); taosSetCoreDump(true); - double factor = 4.0; - int32_t numOfThreads = MAX((int)(tsNumOfCores * tsNumOfThreadsPerCore / factor), 2); - - int32_t queueSize = tsMaxConnections * 2; - tscQhandle = taosInitScheduler(queueSize, numOfThreads, "tsc"); - if (NULL == tscQhandle) { - tscError("failed to init task queue"); - tscInitRes = -1; - return; - } + initTaskQueue(); - tscDebug("client task queue is initialized, numOfThreads: %d", numOfThreads); tscConnRef = taosOpenRef(200, destroyTscObj); tscReqRef = taosOpenRef(40960, doDestroyRequest); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index bab1f9cc9b0aa8ece40d6c3e8a5dccbe677aae3e..992d93f39b71550d2c1b60cb7984d45ed0c75128 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -102,9 +102,8 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, SAppInstInfo** pInst = taosHashGet(appInfo.pInstMap, key, strlen(key)); if (pInst == NULL) { SAppInstInfo* p = calloc(1, sizeof(struct SAppInstInfo)); - p->mgmtEp = epSet; - p->pTransporter = openTransporter(user, secretEncrypt); + p->pTransporter = openTransporter(user, secretEncrypt, tsNumOfCores); taosHashPut(appInfo.pInstMap, key, strlen(key), &p, POINTER_BYTES); pInst = &p; @@ -145,33 +144,66 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { tscDebugL("0x%"PRIx64" SQL: %s", pRequest->requestId, pRequest->sqlstr); - int32_t code = 0; - if (qIsInsertSql(pRequest->sqlstr, sqlLen)) { - // todo add - } else { - int32_t type = 0; - void* output = NULL; - int32_t outputLen = 0; - code = qParseQuerySql(pRequest->sqlstr, sqlLen, pRequest->requestId, &type, &output, &outputLen, pRequest->msgBuf, ERROR_MSG_BUF_DEFAULT_SIZE); - if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW || type == TSDB_SQL_DROP_USER || type == TSDB_SQL_DROP_ACCT || type == TSDB_SQL_CREATE_DB || type == TSDB_SQL_CREATE_ACCT) { - pRequest->type = type; - pRequest->body.requestMsg = (SReqMsgInfo){.pMsg = output, .len = outputLen}; + SParseContext cxt = { + .ctx = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj)}, + .pSql = pRequest->sqlstr, + .sqlLen = sqlLen, + .pMsg = pRequest->msgBuf, + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE + }; + SQueryNode* pQuery = NULL; + int32_t code = qParseQuerySql(&cxt, &pQuery); + if (qIsDclQuery(pQuery)) { + SDclStmtInfo* pDcl = (SDclStmtInfo*)pQuery; + pRequest->type = pDcl->msgType; + pRequest->body.requestMsg = (SReqMsgInfo){.pMsg = pDcl->pMsg, .len = pDcl->msgLen}; + + SRequestMsgBody body = buildRequestMsgImpl(pRequest); + SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet; + + if (pDcl->msgType == TSDB_MSG_TYPE_CREATE_TABLE) { + struct SCatalog* pCatalog = NULL; + + char buf[12] = {0}; + sprintf(buf, "%d", pTscObj->pAppInfo->clusterId); + code = catalogGetHandle(buf, &pCatalog); + if (code != 0) { + pRequest->code = code; + return pRequest; + } - SRequestMsgBody body = {0}; - buildRequestMsgFp[type](pRequest, &body); + SCreateTableMsg* pMsg = body.msgInfo.pMsg; - int64_t transporterId = 0; - sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId); + SName t = {0}; + tNameFromString(&t, pMsg->name, T_NAME_ACCT|T_NAME_DB|T_NAME_TABLE); - tsem_wait(&pRequest->body.rspSem); + char db[TSDB_DB_NAME_LEN + TS_PATH_DELIMITER_LEN + TSDB_ACCT_ID_LEN] = {0}; + tNameGetFullDbName(&t, db); + SVgroupInfo info = {0}; + catalogGetTableHashVgroup(pCatalog, pTscObj->pTransporter, pEpSet, db, tNameGetTableName(&t), &info); - destroyRequestMsgBody(&body); + int64_t transporterId = 0; + SEpSet ep = {0}; + ep.inUse = info.inUse; + ep.numOfEps = info.numOfEps; + for(int32_t i = 0; i < ep.numOfEps; ++i) { + ep.port[i] = info.epAddr[i].port; + tstrncpy(ep.fqdn[i], info.epAddr[i].fqdn, tListLen(ep.fqdn[i])); + } + + sendMsgToServer(pTscObj->pTransporter, &ep, &body, &transporterId); } else { - assert(0); + int64_t transporterId = 0; + sendMsgToServer(pTscObj->pTransporter, pEpSet, &body, &transporterId); } + + tsem_wait(&pRequest->body.rspSem); + destroyRequestMsgBody(&body); } + tfree(cxt.ctx.db); + if (code != TSDB_CODE_SUCCESS) { pRequest->code = code; return pRequest; @@ -217,13 +249,13 @@ int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSe } STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, const char *db, uint16_t port, __taos_async_fn_t fp, void *param, SAppInstInfo* pAppInfo) { - STscObj *pTscObj = createTscObj(user, auth, ip, port, pAppInfo); + STscObj *pTscObj = createTscObj(user, auth, db, pAppInfo); if (NULL == pTscObj) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return pTscObj; } - SRequestObj *pRequest = createRequest(pTscObj, fp, param, TSDB_SQL_CONNECT); + SRequestObj *pRequest = createRequest(pTscObj, fp, param, TSDB_MSG_TYPE_CONNECT); if (pRequest == NULL) { destroyTscObj(pTscObj); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -265,16 +297,11 @@ static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) return -1; } - // TODO refactor full_name - char *db; // ugly code to move the space - STscObj *pObj = pRequest->pTscObj; - pthread_mutex_lock(&pObj->mutex); - db = strstr(pObj->db, TS_PATH_DELIMITER); - db = (db == NULL) ? pObj->db : db + 1; + char* db = getConnectionDB(pObj); tstrncpy(pConnect->db, db, sizeof(pConnect->db)); - pthread_mutex_unlock(&pObj->mutex); + tfree(db); pConnect->pid = htonl(appInfo.pid); pConnect->startTime = htobe64(appInfo.startTime); @@ -392,10 +419,9 @@ void* doFetchRow(SRequestObj* pRequest) { SReqResultInfo* pResultInfo = &pRequest->body.resInfo; if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) { - pRequest->type = TSDB_SQL_RETRIEVE_MNODE; + pRequest->type = TSDB_MSG_TYPE_SHOW_RETRIEVE; - SRequestMsgBody body = {0}; - buildRequestMsgFp[pRequest->type](pRequest, &body); + SRequestMsgBody body = buildRequestMsgImpl(pRequest); int64_t transporterId = 0; STscObj* pTscObj = pRequest->pTscObj; @@ -437,8 +463,19 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t } } -const char *taos_get_client_info() { return version; } +char* getConnectionDB(STscObj* pObj) { + char *p = NULL; + pthread_mutex_lock(&pObj->mutex); + p = strndup(pObj->db, tListLen(pObj->db)); + pthread_mutex_unlock(&pObj->mutex); -int taos_affected_rows(TAOS_RES *res) { return 1; } + return p; +} + +void setConnectionDB(STscObj* pTscObj, const char* db) { + assert(db != NULL && pTscObj != NULL); + pthread_mutex_lock(&pTscObj->mutex); + tstrncpy(pTscObj->db, db, tListLen(pTscObj->db)); + pthread_mutex_unlock(&pTscObj->mutex); +} -int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 8a75799ed78323c2cd63e97456e01858be60f30b..f50765d37a82a2836cd671286d9bd64cdfc4f837 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -1,16 +1,11 @@ +#include "os.h" #include "clientInt.h" #include "clientLog.h" -#include "os.h" +#include "query.h" #include "taosmsg.h" -#include "tcache.h" -#include "tconfig.h" #include "tglobal.h" -#include "tnote.h" #include "tref.h" #include "trpc.h" -#include "tsched.h" -#include "ttime.h" -#include "ttimezone.h" #define TSC_VAR_NOT_RELEASE 1 #define TSC_VAR_RELEASED 0 @@ -44,9 +39,7 @@ void taos_cleanup(void) { tscReqRef = -1; taosCloseRef(id); - void* p = tscQhandle; - tscQhandle = NULL; - taosCleanUpScheduler(p); + cleanupTaskQueue(); id = tscConnRef; tscConnRef = -1; @@ -262,3 +255,9 @@ const char *taos_data_type(int type) { default: return "UNKNOWN"; } } + +const char *taos_get_client_info() { return version; } + +int taos_affected_rows(TAOS_RES *res) { return 1; } + +int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index e70dcc63b38f988c055253bed0436aba0834bf4e..2fc5e84bffe0f32ecaa86b6238ab2ba779167a9b 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -14,2782 +14,14 @@ */ #include "os.h" -#include "catalog.h" +#include "tdef.h" #include "tname.h" #include "clientInt.h" #include "clientLog.h" #include "tmsgtype.h" #include "trpc.h" -int (*buildRequestMsgFp[TSDB_SQL_MAX])(SRequestObj *pRequest, SRequestMsgBody *pMsgBody) = {0}; -int (*handleRequestRspFp[TSDB_SQL_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); - -#if 0 -void tscProcessActivityTimer(void *handle, void *tmrId); - -static int32_t extractSTableQueryVgroupId(STableMetaInfo* pTableMetaInfo); - -static int32_t vgIdCompare(const void *lhs, const void *rhs) { - int32_t left = *(int32_t *)lhs; - int32_t right = *(int32_t *)rhs; - - if (left == right) { - return 0; - } else { - return left > right ? 1 : -1; - } -} -static int32_t removeDupVgid(int32_t *src, int32_t sz) { - if (src == NULL || sz <= 0) { - return 0; - } - qsort(src, sz, sizeof(src[0]), vgIdCompare); - - int32_t ret = 1; - for (int i = 1; i < sz; i++) { - if (src[i] != src[i - 1]) { - src[ret++] = src[i]; - } - } - return ret; -} - -static void tscSetDnodeEpSet(SRpcEpSet* pEpSet, SVgroupMsg* pVgroupInfo) { - assert(pEpSet != NULL && pVgroupInfo != NULL && pVgroupInfo->numOfEps > 0); - - // Issue the query to one of the vnode among a vgroup randomly. - // change the inUse property would not affect the isUse attribute of STableMeta - pEpSet->inUse = rand() % pVgroupInfo->numOfEps; - - // apply the FQDN string length check here - bool existed = false; - - pEpSet->numOfEps = pVgroupInfo->numOfEps; - for(int32_t i = 0; i < pVgroupInfo->numOfEps; ++i) { - pEpSet->port[i] = pVgroupInfo->epAddr[i].port; - - int32_t len = (int32_t) strnlen(pVgroupInfo->epAddr[i].fqdn, TSDB_FQDN_LEN); - if (len > 0) { - tstrncpy(pEpSet->fqdn[i], pVgroupInfo->epAddr[i].fqdn, tListLen(pEpSet->fqdn[i])); - existed = true; - } - } - - assert(existed); -} - -static void tscDumpMgmtEpSet(SSqlObj *pSql) { - SCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; - taosCorBeginRead(&pCorEpSet->version); - pSql->epSet = pCorEpSet->epSet; - taosCorEndRead(&pCorEpSet->version); -} -static void tscEpSetHtons(SRpcEpSet *s) { - for (int32_t i = 0; i < s->numOfEps; i++) { - s->port[i] = htons(s->port[i]); - } -} - -bool tscEpSetIsEqual(SRpcEpSet *s1, SRpcEpSet *s2) { - if (s1->numOfEps != s2->numOfEps || s1->inUse != s2->inUse) { - return false; - } - - for (int32_t i = 0; i < s1->numOfEps; i++) { - if (s1->port[i] != s2->port[i] - || strncmp(s1->fqdn[i], s2->fqdn[i], TSDB_FQDN_LEN) != 0) - return false; - } - return true; -} - -void tscUpdateMgmtEpSet(SSqlObj *pSql, SRpcEpSet *pEpSet) { - // no need to update if equal - SCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; - taosCorBeginWrite(&pCorEpSet->version); - pCorEpSet->epSet = *pEpSet; - taosCorEndWrite(&pCorEpSet->version); -} - -static void tscDumpEpSetFromVgroupInfo(SRpcEpSet *pEpSet, SNewVgroupInfo *pVgroupInfo) { - if (pVgroupInfo == NULL) { return;} - int8_t inUse = pVgroupInfo->inUse; - pEpSet->inUse = (inUse >= 0 && inUse < TSDB_MAX_REPLICA) ? inUse: 0; - pEpSet->numOfEps = pVgroupInfo->numOfEps; - for (int32_t i = 0; i < pVgroupInfo->numOfEps; ++i) { - tstrncpy(pEpSet->fqdn[i], pVgroupInfo->ep[i].fqdn, sizeof(pEpSet->fqdn[i])); - pEpSet->port[i] = pVgroupInfo->ep[i].port; - } -} - -static void tscUpdateVgroupInfo(SSqlObj *pSql, SRpcEpSet *pEpSet) { - SSqlCmd *pCmd = &pSql->cmd; - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - if (pTableMetaInfo == NULL || pTableMetaInfo->pTableMeta == NULL) { - return; - } - - int32_t vgId = -1; - if (pTableMetaInfo->pTableMeta->tableType == TSDB_SUPER_TABLE) { - vgId = extractSTableQueryVgroupId(pTableMetaInfo); - } else { - vgId = pTableMetaInfo->pTableMeta->vgId; - } - - assert(vgId > 0); - - SNewVgroupInfo vgroupInfo = {.vgId = -1}; - taosHashGetClone(tscVgroupMap, &vgId, sizeof(vgId), NULL, &vgroupInfo); - assert(vgroupInfo.numOfEps > 0 && vgroupInfo.vgId > 0); - - tscDebug("before: Endpoint in use:%d, numOfEps:%d", vgroupInfo.inUse, vgroupInfo.numOfEps); - vgroupInfo.inUse = pEpSet->inUse; - vgroupInfo.numOfEps = pEpSet->numOfEps; - for (int32_t i = 0; i < vgroupInfo.numOfEps; i++) { - tstrncpy(vgroupInfo.ep[i].fqdn, pEpSet->fqdn[i], TSDB_FQDN_LEN); - vgroupInfo.ep[i].port = pEpSet->port[i]; - } - - tscDebug("after: EndPoint in use:%d, numOfEps:%d", vgroupInfo.inUse, vgroupInfo.numOfEps); - taosHashPut(tscVgroupMap, &vgId, sizeof(vgId), &vgroupInfo, sizeof(SNewVgroupInfo)); - - // Update the local cached epSet info cached by SqlObj - int32_t inUse = pSql->epSet.inUse; - tscDumpEpSetFromVgroupInfo(&pSql->epSet, &vgroupInfo); - tscDebug("0x%"PRIx64" update the epSet in SqlObj, in use before:%d, after:%d", pSql->self, inUse, pSql->epSet.inUse); - -} - -int32_t extractSTableQueryVgroupId(STableMetaInfo* pTableMetaInfo) { - assert(pTableMetaInfo != NULL); - - int32_t vgIndex = pTableMetaInfo->vgroupIndex; - int32_t vgId = -1; - - if (pTableMetaInfo->pVgroupTables == NULL) { - SVgroupsInfo *pVgroupInfo = pTableMetaInfo->vgroupList; - assert(pVgroupInfo->vgroups[vgIndex].vgId > 0 && vgIndex < pTableMetaInfo->vgroupList->numOfVgroups); - vgId = pVgroupInfo->vgroups[vgIndex].vgId; - } else { - int32_t numOfVgroups = (int32_t)taosArrayGetSize(pTableMetaInfo->pVgroupTables); - assert(vgIndex >= 0 && vgIndex < numOfVgroups); - - SVgroupTableInfo *pTableIdList = taosArrayGet(pTableMetaInfo->pVgroupTables, vgIndex); - vgId = pTableIdList->vgInfo.vgId; - } - - return vgId; -} - -void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { - STscObj *pObj = (STscObj *)param; - if (pObj == NULL) return; - - if (pObj != pObj->signature) { - tscError("heartbeat msg, pObj:%p, signature:%p invalid", pObj, pObj->signature); - return; - } - - SSqlObj *pSql = tres; - SSqlRes *pRes = &pSql->res; - - if (code == TSDB_CODE_SUCCESS) { - SHeartBeatRsp *pRsp = (SHeartBeatRsp *)pRes->pRsp; - SRpcEpSet *epSet = &pRsp->epSet; - if (epSet->numOfEps > 0) { - tscEpSetHtons(epSet); - - //SCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; - //if (!tscEpSetIsEqual(&pCorEpSet->epSet, epSet)) { - // tscTrace("%p updating epset: numOfEps: %d, inUse: %d", pSql, epSet->numOfEps, epSet->inUse); - // for (int8_t i = 0; i < epSet->numOfEps; i++) { - // tscTrace("endpoint %d: fqdn=%s, port=%d", i, epSet->fqdn[i], epSet->port[i]); - // } - //} - //concurrency problem, update mgmt epset anyway - tscUpdateMgmtEpSet(pSql, epSet); - } - - pSql->pTscObj->connId = htonl(pRsp->connId); - - if (pRsp->killConnection) { - tscKillConnection(pObj); - return; - } else { - if (pRsp->queryId) { - tscKillQuery(pObj, htonl(pRsp->queryId)); - } - - if (pRsp->streamId) { - tscKillStream(pObj, htonl(pRsp->streamId)); - } - } - - int32_t total = htonl(pRsp->totalDnodes); - int32_t online = htonl(pRsp->onlineDnodes); - assert(online <= total); - - if (online < total) { - tscError("0x%"PRIx64", HB, total dnode:%d, online dnode:%d", pSql->self, total, online); - pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; - } - - if (pRes->length == NULL) { - pRes->length = calloc(2, sizeof(int32_t)); - } - - pRes->length[0] = total; - pRes->length[1] = online; - } else { - tscDebug("%" PRId64 " heartbeat failed, code:%s", pObj->hbrid, tstrerror(code)); - if (pRes->length == NULL) { - pRes->length = calloc(2, sizeof(int32_t)); - } - - pRes->length[1] = 0; - if (pRes->length[0] == 0) { - pRes->length[0] = 1; // make sure that the value of the total node is greater than the online node - } - } - - if (pObj->hbrid != 0) { - int32_t waitingDuring = tsShellActivityTimer * 500; - tscDebug("0x%"PRIx64" send heartbeat in %dms", pSql->self, waitingDuring); - - taosTmrReset(tscProcessActivityTimer, waitingDuring, (void *)pObj->rid, tscTmr, &pObj->pTimer); - } else { - tscDebug("0x%"PRIx64" start to close tscObj:%p, not send heartbeat again", pSql->self, pObj); - } -} - -void tscProcessActivityTimer(void *handle, void *tmrId) { - int64_t rid = (int64_t) handle; - STscObj *pObj = taosAcquireRef(tscRefId, rid); - if (pObj == NULL) { - return; - } - - SSqlObj* pHB = taosAcquireRef(tscObjRef, pObj->hbrid); - if (pHB == NULL) { - taosReleaseRef(tscRefId, rid); - return; - } - - assert(pHB->self == pObj->hbrid); - - pHB->retry = 0; - int32_t code = tscBuildAndSendRequest(pHB, NULL); - taosReleaseRef(tscObjRef, pObj->hbrid); - - if (code != TSDB_CODE_SUCCESS) { - tscError("0x%"PRIx64" failed to sent HB to server, reason:%s", pHB->self, tstrerror(code)); - } - - taosReleaseRef(tscRefId, rid); -} - -// handle three situation -// 1. epset retry, only return last failure ep -// 2. no epset retry, like 'taos -h invalidFqdn', return invalidFqdn -// 3. other situation, no expected -void tscSetFqdnErrorMsg(SSqlObj* pSql, SRpcEpSet* pEpSet) { - SSqlCmd* pCmd = &pSql->cmd; - SSqlRes* pRes = &pSql->res; - - char* msgBuf = tscGetErrorMsgPayload(pCmd); - - if (pEpSet) { - sprintf(msgBuf, "%s\"%s\"", tstrerror(pRes->code),pEpSet->fqdn[(pEpSet->inUse)%(pEpSet->numOfEps)]); - } else if (pCmd->command >= TSDB_SQL_MGMT) { - SRpcEpSet tEpset; - - SCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; - taosCorBeginRead(&pCorEpSet->version); - tEpset = pCorEpSet->epSet; - taosCorEndRead(&pCorEpSet->version); - - sprintf(msgBuf, "%s\"%s\"", tstrerror(pRes->code),tEpset.fqdn[(tEpset.inUse)%(tEpset.numOfEps)]); - } else { - sprintf(msgBuf, "%s", tstrerror(pRes->code)); - } -} - -int doBuildAndSendMsg(SSqlObj *pSql) { - SSqlCmd *pCmd = &pSql->cmd; - SSqlRes *pRes = &pSql->res; - - if (pCmd->command == TSDB_SQL_SELECT || - pCmd->command == TSDB_SQL_FETCH || - pCmd->command == TSDB_SQL_RETRIEVE_MNODE || - pCmd->command == TSDB_SQL_INSERT || - pCmd->command == TSDB_SQL_CONNECT || - pCmd->command == TSDB_SQL_HB || - pCmd->command == TSDB_SQL_RETRIEVE_FUNC || - pCmd->command == TSDB_SQL_STABLEVGROUP) { - pRes->code = tscBuildMsg[pCmd->command](pSql, NULL); - } - - if (pRes->code != TSDB_CODE_SUCCESS) { - tscAsyncResultOnError(pSql); - return TSDB_CODE_SUCCESS; - } - - int32_t code = tscSendMsgToServer(pSql); - - // NOTE: if code is TSDB_CODE_SUCCESS, pSql may have been released here already by other threads. - if (code != TSDB_CODE_SUCCESS) { - pRes->code = code; - tscAsyncResultOnError(pSql); - return TSDB_CODE_SUCCESS; - } - - return TSDB_CODE_SUCCESS; -} - -int tscBuildAndSendRequest(SSqlObj *pSql, SQueryInfo* pQueryInfo) { - char name[TSDB_TABLE_FNAME_LEN] = {0}; - - SSqlCmd *pCmd = &pSql->cmd; - uint32_t type = 0; - - if (pQueryInfo == NULL) { - pQueryInfo = tscGetQueryInfo(pCmd); - } - - STableMetaInfo *pTableMetaInfo = NULL; - - if (pQueryInfo != NULL) { - pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - if (pTableMetaInfo != NULL) { - tNameExtractFullName(&pTableMetaInfo->name, name); - } - - type = pQueryInfo->type; - - // while numOfTables equals to 0, it must be Heartbeat - assert((pQueryInfo->numOfTables == 0 && (pQueryInfo->command == TSDB_SQL_HB || pSql->cmd.command == TSDB_SQL_RETRIEVE_FUNC)) || pQueryInfo->numOfTables > 0); - } - - tscDebug("0x%"PRIx64" SQL cmd:%s will be processed, name:%s, type:%d", pSql->self, sqlCmd[pCmd->command], name, type); - if (pCmd->command < TSDB_SQL_MGMT) { // the pTableMetaInfo cannot be NULL - if (pTableMetaInfo == NULL) { - pSql->res.code = TSDB_CODE_TSC_APP_ERROR; - return pSql->res.code; - } - } else if (pCmd->command >= TSDB_SQL_LOCAL) { - return (*tscProcessMsgRsp[pCmd->command])(pSql); - } - - return doBuildAndSendMsg(pSql); -} - -int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg *) pSql->cmd.payload; - - SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd); - - pRetrieveMsg->free = htons(pQueryInfo->type); - pRetrieveMsg->qId = htobe64(pSql->res.qId); - - // todo valid the vgroupId at the client side - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - - if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { - int32_t vgIndex = pTableMetaInfo->vgroupIndex; - int32_t vgId = -1; - - if (pTableMetaInfo->pVgroupTables == NULL) { - SVgroupsInfo *pVgroupInfo = pTableMetaInfo->vgroupList; - assert(pVgroupInfo->vgroups[vgIndex].vgId > 0 && vgIndex < pTableMetaInfo->vgroupList->numOfVgroups); - vgId = pVgroupInfo->vgroups[vgIndex].vgId; - } else { - int32_t numOfVgroups = (int32_t)taosArrayGetSize(pTableMetaInfo->pVgroupTables); - assert(vgIndex >= 0 && vgIndex < numOfVgroups); - - SVgroupTableInfo* pTableIdList = taosArrayGet(pTableMetaInfo->pVgroupTables, vgIndex); - vgId = pTableIdList->vgInfo.vgId; - } - - pRetrieveMsg->header.vgId = htonl(vgId); - tscDebug("0x%"PRIx64" build fetch msg from vgId:%d, vgIndex:%d, qId:0x%" PRIx64, pSql->self, vgId, vgIndex, pSql->res.qId); - } else { - STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - pRetrieveMsg->header.vgId = htonl(pTableMeta->vgId); - tscDebug("0x%"PRIx64" build fetch msg from only one vgroup, vgId:%d, qId:0x%" PRIx64, pSql->self, pTableMeta->vgId, - pSql->res.qId); - } - - pSql->cmd.payloadLen = sizeof(SRetrieveTableMsg); - pSql->cmd.msgType = TSDB_MSG_TYPE_FETCH; - - pRetrieveMsg->header.contLen = htonl(sizeof(SRetrieveTableMsg)); - - return TSDB_CODE_SUCCESS; -} - -int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd); - STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; - - // pSql->cmd.payloadLen is set during copying data into payload - pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT; - - SNewVgroupInfo vgroupInfo = {0}; - taosHashGetClone(tscVgroupMap, &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo); - tscDumpEpSetFromVgroupInfo(&pSql->epSet, &vgroupInfo); - - tscDebug("0x%"PRIx64" submit msg built, numberOfEP:%d", pSql->self, pSql->epSet.numOfEps); - - return TSDB_CODE_SUCCESS; -} - -/* - * for table query, simply return the size <= 1k - */ -static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { - const static int32_t MIN_QUERY_MSG_PKT_SIZE = TSDB_MAX_BYTES_PER_ROW * 5; - - SSqlCmd* pCmd = &pSql->cmd; - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - - int32_t srcColListSize = (int32_t)(taosArrayGetSize(pQueryInfo->colList) * sizeof(SColumnInfo)); - int32_t srcColFilterSize = 0; - int32_t srcTagFilterSize = tscGetTagFilterSerializeLen(pQueryInfo); - - size_t numOfExprs = tscNumOfExprs(pQueryInfo); - int32_t exprSize = (int32_t)(sizeof(SSqlExpr) * numOfExprs * 2); - - int32_t tsBufSize = (pQueryInfo->tsBuf != NULL) ? pQueryInfo->tsBuf->fileSize : 0; - int32_t sqlLen = (int32_t) strlen(pSql->sqlstr) + 1; - - int32_t tableSerialize = 0; - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; - if (pTableMetaInfo->pVgroupTables != NULL) { - size_t numOfGroups = taosArrayGetSize(pTableMetaInfo->pVgroupTables); - - int32_t totalTables = 0; - for (int32_t i = 0; i < numOfGroups; ++i) { - SVgroupTableInfo *pTableInfo = taosArrayGet(pTableMetaInfo->pVgroupTables, i); - totalTables += (int32_t) taosArrayGetSize(pTableInfo->itemList); - } - - tableSerialize = totalTables * sizeof(STableIdInfo); - } - - if (pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0) { - STblCond *pCond = tsGetTableFilter(pQueryInfo->colCond, pTableMeta->id.uid, 0); - if (pCond != NULL && pCond->cond != NULL) { - srcColFilterSize = pCond->len; - } - } - - SCond* pCond = &pQueryInfo->tagCond.tbnameCond; - if (pCond->len > 0) { - srcColListSize += pCond->len; - } - - return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + srcTagFilterSize + - exprSize + tsBufSize + tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen; -} - -static char *doSerializeTableInfo(SQueryTableMsg *pQueryMsg, SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, char *pMsg, - int32_t *succeed) { - TSKEY dfltKey = htobe64(pQueryMsg->window.skey); - - STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; - if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo) || pTableMetaInfo->pVgroupTables == NULL) { - - int32_t vgId = -1; - if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { - int32_t index = pTableMetaInfo->vgroupIndex; - assert(index >= 0); - - SVgroupMsg* pVgroupInfo = NULL; - if (pTableMetaInfo->vgroupList && pTableMetaInfo->vgroupList->numOfVgroups > 0) { - assert(index < pTableMetaInfo->vgroupList->numOfVgroups); - pVgroupInfo = &pTableMetaInfo->vgroupList->vgroups[index]; - } else { - tscError("0x%"PRIx64" No vgroup info found", pSql->self); - - *succeed = 0; - return pMsg; - } - - vgId = pVgroupInfo->vgId; - tscSetDnodeEpSet(&pSql->epSet, pVgroupInfo); - tscDebug("0x%"PRIx64" query on stable, vgIndex:%d, numOfVgroups:%d", pSql->self, index, pTableMetaInfo->vgroupList->numOfVgroups); - } else { - vgId = pTableMeta->vgId; - - SNewVgroupInfo vgroupInfo = {0}; - taosHashGetClone(tscVgroupMap, &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo); - tscDumpEpSetFromVgroupInfo(&pSql->epSet, &vgroupInfo); - } - - if (pSql->epSet.numOfEps > 0){ - pSql->epSet.inUse = rand()%pSql->epSet.numOfEps; - } - pQueryMsg->head.vgId = htonl(vgId); - - STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg; - pTableIdInfo->tid = htonl(pTableMeta->id.tid); - pTableIdInfo->uid = htobe64(pTableMeta->id.uid); - pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pTableMeta->id.uid, dfltKey)); - - pQueryMsg->numOfTables = htonl(1); // set the number of tables - pMsg += sizeof(STableIdInfo); - } else { // it is a subquery of the super table query, this EP info is acquired from vgroupInfo - int32_t index = pTableMetaInfo->vgroupIndex; - int32_t numOfVgroups = (int32_t)taosArrayGetSize(pTableMetaInfo->pVgroupTables); - assert(index >= 0 && index < numOfVgroups); - - SVgroupTableInfo* pTableIdList = taosArrayGet(pTableMetaInfo->pVgroupTables, index); - - // set the vgroup info - tscSetDnodeEpSet(&pSql->epSet, &pTableIdList->vgInfo); - pQueryMsg->head.vgId = htonl(pTableIdList->vgInfo.vgId); - - int32_t numOfTables = (int32_t)taosArrayGetSize(pTableIdList->itemList); - pQueryMsg->numOfTables = htonl(numOfTables); // set the number of tables - - tscDebug("0x%"PRIx64" query on stable, vgId:%d, numOfTables:%d, vgIndex:%d, numOfVgroups:%d", pSql->self, - pTableIdList->vgInfo.vgId, numOfTables, index, numOfVgroups); - - // serialize each table id info - for(int32_t i = 0; i < numOfTables; ++i) { - STableIdInfo* pItem = taosArrayGet(pTableIdList->itemList, i); - - STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg; - pTableIdInfo->tid = htonl(pItem->tid); - pTableIdInfo->uid = htobe64(pItem->uid); - pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pItem->uid, dfltKey)); - pMsg += sizeof(STableIdInfo); - } - } - - char n[TSDB_TABLE_FNAME_LEN] = {0}; - tNameExtractFullName(&pTableMetaInfo->name, n); - - tscDebug("0x%"PRIx64" vgId:%d, query on table:%s, tid:%d, uid:%" PRIu64, pSql->self, htonl(pQueryMsg->head.vgId), n, pTableMeta->id.tid, pTableMeta->id.uid); - return pMsg; -} - -// TODO refactor -static int32_t serializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t numOfFilters, char** pMsg) { - // append the filter information after the basic column information - for (int32_t f = 0; f < numOfFilters; ++f) { - SColumnFilterInfo *pColFilter = &pColFilters[f]; - - SColumnFilterInfo *pFilterMsg = (SColumnFilterInfo *)(*pMsg); - pFilterMsg->filterstr = htons(pColFilter->filterstr); - - (*pMsg) += sizeof(SColumnFilterInfo); - - if (pColFilter->filterstr) { - pFilterMsg->len = htobe64(pColFilter->len); - memcpy(*pMsg, (void *)pColFilter->pz, (size_t)(pColFilter->len + 1)); - (*pMsg) += (pColFilter->len + 1); // append the additional filter binary info - } else { - pFilterMsg->lowerBndi = htobe64(pColFilter->lowerBndi); - pFilterMsg->upperBndi = htobe64(pColFilter->upperBndi); - } - - pFilterMsg->lowerRelOptr = htons(pColFilter->lowerRelOptr); - pFilterMsg->upperRelOptr = htons(pColFilter->upperRelOptr); - - if (pColFilter->lowerRelOptr == TSDB_RELATION_INVALID && pColFilter->upperRelOptr == TSDB_RELATION_INVALID) { - tscError("invalid filter info"); - return TSDB_CODE_TSC_INVALID_OPERATION; - } - } - - return TSDB_CODE_SUCCESS; -} - -static int32_t serializeSqlExpr(SSqlExpr* pExpr, STableMetaInfo* pTableMetaInfo, char** pMsg, int64_t id, bool validateColumn) { - STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; - - // the queried table has been removed and a new table with the same name has already been created already - // return error msg - if (pExpr->uid != pTableMeta->id.uid) { - tscError("0x%"PRIx64" table has already been destroyed", id); - return TSDB_CODE_TSC_INVALID_TABLE_NAME; - } - - if (validateColumn && !tscValidateColumnId(pTableMetaInfo, pExpr->colInfo.colId, pExpr->numOfParams)) { - tscError("0x%"PRIx64" table schema is not matched with parsed sql", id); - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - assert(pExpr->resColId < 0); - SSqlExpr* pSqlExpr = (SSqlExpr *)(*pMsg); - - SColIndex* pIndex = &pSqlExpr->colInfo; - - pIndex->colId = htons(pExpr->colInfo.colId); - pIndex->colIndex = htons(pExpr->colInfo.colIndex); - pIndex->flag = htons(pExpr->colInfo.flag); - pSqlExpr->uid = htobe64(pExpr->uid); - pSqlExpr->colType = htons(pExpr->colType); - pSqlExpr->colBytes = htons(pExpr->colBytes); - pSqlExpr->resType = htons(pExpr->resType); - pSqlExpr->resBytes = htons(pExpr->resBytes); - pSqlExpr->interBytes = htonl(pExpr->interBytes); - pSqlExpr->functionId = htons(pExpr->functionId); - pSqlExpr->numOfParams = htons(pExpr->numOfParams); - pSqlExpr->resColId = htons(pExpr->resColId); - pSqlExpr->flist.numOfFilters = htons(pExpr->flist.numOfFilters); - - (*pMsg) += sizeof(SSqlExpr); - for (int32_t j = 0; j < pExpr->numOfParams; ++j) { // todo add log - pSqlExpr->param[j].nType = htonl(pExpr->param[j].nType); - pSqlExpr->param[j].nLen = htonl(pExpr->param[j].nLen); - - if (pExpr->param[j].nType == TSDB_DATA_TYPE_BINARY) { - memcpy((*pMsg), pExpr->param[j].pz, pExpr->param[j].nLen); - (*pMsg) += pExpr->param[j].nLen; - } else { - pSqlExpr->param[j].i64 = htobe64(pExpr->param[j].i64); - } - } - - serializeColFilterInfo(pExpr->flist.filterInfo, pExpr->flist.numOfFilters, pMsg); - - return TSDB_CODE_SUCCESS; -} - -int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - - SQueryInfo *pQueryInfo = NULL; - STableMeta *pTableMeta = NULL; - STableMetaInfo *pTableMetaInfo = NULL; - - int32_t code = TSDB_CODE_SUCCESS; - int32_t size = tscEstimateQueryMsgSize(pSql); - assert(size > 0); - - if (TSDB_CODE_SUCCESS != tscAllocPayloadFast(pCmd, size)) { - tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_TSC_INVALID_OPERATION; // todo add test for this - } - - pQueryInfo = tscGetQueryInfo(pCmd); - pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - pTableMeta = pTableMetaInfo->pTableMeta; - - SQueryAttr query = {{0}}; - tscCreateQueryFromQueryInfo(pQueryInfo, &query, pSql); - query.vgId = pTableMeta->vgId; - - SArray* tableScanOperator = createTableScanPlan(&query); - SArray* queryOperator = createExecOperatorPlan(&query); - - SQueryTableMsg *pQueryMsg = (SQueryTableMsg *)pCmd->payload; - tstrncpy(pQueryMsg->version, version, tListLen(pQueryMsg->version)); - - int32_t numOfTags = query.numOfTags; - int32_t sqlLen = (int32_t) strlen(pSql->sqlstr); - - if (taosArrayGetSize(tableScanOperator) == 0) { - pQueryMsg->tableScanOperator = htonl(-1); - } else { - int32_t* tablescanOp = taosArrayGet(tableScanOperator, 0); - pQueryMsg->tableScanOperator = htonl(*tablescanOp); - } - - pQueryMsg->window.skey = htobe64(query.window.skey); - pQueryMsg->window.ekey = htobe64(query.window.ekey); - - pQueryMsg->order = htons(query.order.order); - pQueryMsg->orderColId = htons(query.order.orderColId); - pQueryMsg->fillType = htons(query.fillType); - pQueryMsg->limit = htobe64(query.limit.limit); - pQueryMsg->offset = htobe64(query.limit.offset); - pQueryMsg->numOfCols = htons(query.numOfCols); - - pQueryMsg->interval.interval = htobe64(query.interval.interval); - pQueryMsg->interval.sliding = htobe64(query.interval.sliding); - pQueryMsg->interval.offset = htobe64(query.interval.offset); - pQueryMsg->interval.intervalUnit = query.interval.intervalUnit; - pQueryMsg->interval.slidingUnit = query.interval.slidingUnit; - pQueryMsg->interval.offsetUnit = query.interval.offsetUnit; - - pQueryMsg->stableQuery = query.stableQuery; - pQueryMsg->topBotQuery = query.topBotQuery; - pQueryMsg->groupbyColumn = query.groupbyColumn; - pQueryMsg->hasTagResults = query.hasTagResults; - pQueryMsg->timeWindowInterpo = query.timeWindowInterpo; - pQueryMsg->queryBlockDist = query.queryBlockDist; - pQueryMsg->stabledev = query.stabledev; - pQueryMsg->tsCompQuery = query.tsCompQuery; - pQueryMsg->simpleAgg = query.simpleAgg; - pQueryMsg->pointInterpQuery = query.pointInterpQuery; - pQueryMsg->needReverseScan = query.needReverseScan; - pQueryMsg->stateWindow = query.stateWindow; - pQueryMsg->numOfTags = htonl(numOfTags); - pQueryMsg->sqlstrLen = htonl(sqlLen); - pQueryMsg->sw.gap = htobe64(query.sw.gap); - pQueryMsg->sw.primaryColId = htonl(PRIMARYKEY_TIMESTAMP_COL_INDEX); - - pQueryMsg->secondStageOutput = htonl(query.numOfExpr2); - pQueryMsg->numOfOutput = htons((int16_t)query.numOfOutput); // this is the stage one output column number - - pQueryMsg->numOfGroupCols = htons(pQueryInfo->groupbyExpr.numOfGroupCols); - pQueryMsg->tagNameRelType = htons(pQueryInfo->tagCond.relType); - pQueryMsg->tbnameCondLen = htonl(pQueryInfo->tagCond.tbnameCond.len); - pQueryMsg->queryType = htonl(pQueryInfo->type); - pQueryMsg->prevResultLen = htonl(pQueryInfo->bufLen); - - // set column list ids - size_t numOfCols = taosArrayGetSize(pQueryInfo->colList); - char *pMsg = (char *)(pQueryMsg->tableCols) + numOfCols * sizeof(SColumnInfo); - - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfo *pCol = &query.tableCols[i]; - - pQueryMsg->tableCols[i].colId = htons(pCol->colId); - pQueryMsg->tableCols[i].bytes = htons(pCol->bytes); - pQueryMsg->tableCols[i].type = htons(pCol->type); - //pQueryMsg->tableCols[i].flist.numOfFilters = htons(pCol->flist.numOfFilters); - pQueryMsg->tableCols[i].flist.numOfFilters = 0; - pQueryMsg->tableCols[i].flist.filterInfo = 0; - // append the filter information after the basic column information - //serializeColFilterInfo(pCol->flist.filterInfo, pCol->flist.numOfFilters, &pMsg); - } - - if (pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0 && !onlyQueryTags(&query) ) { - STblCond *pCond = tsGetTableFilter(pQueryInfo->colCond, pTableMeta->id.uid, 0); - if (pCond != NULL && pCond->cond != NULL) { - pQueryMsg->colCondLen = htons(pCond->len); - memcpy(pMsg, pCond->cond, pCond->len); - - pMsg += pCond->len; - } - } else { - pQueryMsg->colCondLen = 0; - } - - for (int32_t i = 0; i < query.numOfOutput; ++i) { - code = serializeSqlExpr(&query.pExpr1[i].base, pTableMetaInfo, &pMsg, pSql->self, true); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } - } - - for (int32_t i = 0; i < query.numOfExpr2; ++i) { - code = serializeSqlExpr(&query.pExpr2[i].base, pTableMetaInfo, &pMsg, pSql->self, false); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } - } - - int32_t succeed = 1; - - // serialize the table info (sid, uid, tags) - pMsg = doSerializeTableInfo(pQueryMsg, pSql, pTableMetaInfo, pMsg, &succeed); - if (succeed == 0) { - code = TSDB_CODE_TSC_APP_ERROR; - goto _end; - } - - SGroupbyExpr *pGroupbyExpr = query.pGroupbyExpr; - if (pGroupbyExpr != NULL && pGroupbyExpr->numOfGroupCols > 0) { - pQueryMsg->orderByIdx = htons(pGroupbyExpr->orderIndex); - pQueryMsg->orderType = htons(pGroupbyExpr->orderType); - - for (int32_t j = 0; j < pGroupbyExpr->numOfGroupCols; ++j) { - SColIndex* pCol = taosArrayGet(pGroupbyExpr->columnInfo, j); - - *((int16_t *)pMsg) = htons(pCol->colId); - pMsg += sizeof(pCol->colId); - - *((int16_t *)pMsg) += htons(pCol->colIndex); - pMsg += sizeof(pCol->colIndex); - - *((int16_t *)pMsg) += htons(pCol->flag); - pMsg += sizeof(pCol->flag); - - memcpy(pMsg, pCol->name, tListLen(pCol->name)); - pMsg += tListLen(pCol->name); - } - } - - if (query.fillType != TSDB_FILL_NONE) { - for (int32_t i = 0; i < query.numOfOutput; ++i) { - *((int64_t *)pMsg) = htobe64(query.fillVal[i]); - pMsg += sizeof(query.fillVal[0]); - } - } - - if (query.numOfTags > 0 && query.tagColList != NULL) { - for (int32_t i = 0; i < query.numOfTags; ++i) { - SColumnInfo* pTag = &query.tagColList[i]; - - SColumnInfo* pTagCol = (SColumnInfo*) pMsg; - pTagCol->colId = htons(pTag->colId); - pTagCol->bytes = htons(pTag->bytes); - pTagCol->type = htons(pTag->type); - pTagCol->flist.numOfFilters = 0; - - pMsg += sizeof(SColumnInfo); - } - } - - // serialize tag column query condition - if (pQueryInfo->tagCond.pCond != NULL && taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0) { - STagCond* pTagCond = &pQueryInfo->tagCond; - - SCond *pCond = tsGetSTableQueryCond(pTagCond, pTableMeta->id.uid); - if (pCond != NULL && pCond->cond != NULL) { - pQueryMsg->tagCondLen = htons(pCond->len); - memcpy(pMsg, pCond->cond, pCond->len); - - pMsg += pCond->len; - } - } else { - pQueryMsg->tagCondLen = 0; - } - - if (pQueryInfo->bufLen > 0) { - memcpy(pMsg, pQueryInfo->buf, pQueryInfo->bufLen); - pMsg += pQueryInfo->bufLen; - } - - SCond* pCond = &pQueryInfo->tagCond.tbnameCond; - if (pCond->len > 0) { - strncpy(pMsg, pCond->cond, pCond->len); - pMsg += pCond->len; - } - - // compressed ts block - pQueryMsg->tsBuf.tsOffset = htonl((int32_t)(pMsg - pCmd->payload)); - - if (pQueryInfo->tsBuf != NULL) { - // note: here used the index instead of actual vnode id. - int32_t vnodeIndex = pTableMetaInfo->vgroupIndex; - code = dumpFileBlockByGroupId(pQueryInfo->tsBuf, vnodeIndex, pMsg, &pQueryMsg->tsBuf.tsLen, &pQueryMsg->tsBuf.tsNumOfBlocks); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } - - pMsg += pQueryMsg->tsBuf.tsLen; - - pQueryMsg->tsBuf.tsOrder = htonl(pQueryInfo->tsBuf->tsOrder); - pQueryMsg->tsBuf.tsLen = htonl(pQueryMsg->tsBuf.tsLen); - pQueryMsg->tsBuf.tsNumOfBlocks = htonl(pQueryMsg->tsBuf.tsNumOfBlocks); - } else { - pQueryMsg->tsBuf.tsLen = 0; - pQueryMsg->tsBuf.tsNumOfBlocks = 0; - } - - int32_t numOfOperator = (int32_t) taosArrayGetSize(queryOperator); - pQueryMsg->numOfOperator = htonl(numOfOperator); - for(int32_t i = 0; i < numOfOperator; ++i) { - int32_t *operator = taosArrayGet(queryOperator, i); - *(int32_t*)pMsg = htonl(*operator); - - pMsg += sizeof(int32_t); - } - - // support only one udf - if (pQueryInfo->pUdfInfo != NULL && taosArrayGetSize(pQueryInfo->pUdfInfo) > 0) { - pQueryMsg->udfContentOffset = htonl((int32_t) (pMsg - pCmd->payload)); - for(int32_t i = 0; i < taosArrayGetSize(pQueryInfo->pUdfInfo); ++i) { - SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, i); - *(int8_t*) pMsg = pUdfInfo->resType; - pMsg += sizeof(pUdfInfo->resType); - - *(int16_t*) pMsg = htons(pUdfInfo->resBytes); - pMsg += sizeof(pUdfInfo->resBytes); - - STR_TO_VARSTR(pMsg, pUdfInfo->name); - - pMsg += varDataTLen(pMsg); - - *(int32_t*) pMsg = htonl(pUdfInfo->funcType); - pMsg += sizeof(pUdfInfo->funcType); - - *(int32_t*) pMsg = htonl(pUdfInfo->bufSize); - pMsg += sizeof(pUdfInfo->bufSize); - - pQueryMsg->udfContentLen = htonl(pUdfInfo->contLen); - memcpy(pMsg, pUdfInfo->content, pUdfInfo->contLen); - - pMsg += pUdfInfo->contLen; - } - } else { - pQueryMsg->udfContentOffset = 0; - pQueryMsg->udfContentLen = 0; - } - - memcpy(pMsg, pSql->sqlstr, sqlLen); - pMsg += sqlLen; - - int32_t msgLen = (int32_t)(pMsg - pCmd->payload); - - tscDebug("0x%"PRIx64" msg built success, len:%d bytes", pSql->self, msgLen); - pCmd->payloadLen = msgLen; - pSql->cmd.msgType = TSDB_MSG_TYPE_QUERY; - - pQueryMsg->head.contLen = htonl(msgLen); - assert(msgLen + minMsgSize() <= (int32_t)pCmd->allocSize); - - _end: - freeQueryAttr(&query); - taosArrayDestroy(tableScanOperator); - taosArrayDestroy(queryOperator); - return code; -} - -int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateDbMsg); - - pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_CREATE_DB : TSDB_MSG_TYPE_CREATE_TP; - - SCreateDbMsg *pCreateDbMsg = (SCreateDbMsg *)pCmd->payload; - -// assert(pCmd->numOfClause == 1); - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pCreateDbMsg->db); - assert(code == TSDB_CODE_SUCCESS); - - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildCreateFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - SCreateFuncMsg *pCreateFuncMsg = (SCreateFuncMsg *)pCmd->payload; - - pCmd->msgType = TSDB_MSG_TYPE_CREATE_FUNCTION; - - pCmd->payloadLen = sizeof(SCreateFuncMsg) + htonl(pCreateFuncMsg->codeLen); - - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateDnodeMsg); - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SCreateDnodeMsg *pCreate = (SCreateDnodeMsg *)pCmd->payload; - - SStrToken* t0 = taosArrayGet(pInfo->pMiscInfo->a, 0); - strncpy(pCreate->ep, t0->z, t0->n); - - pCmd->msgType = TSDB_MSG_TYPE_CREATE_DNODE; - - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateAcctMsg); - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SCreateAcctMsg *pAlterMsg = (SCreateAcctMsg *)pCmd->payload; - - SStrToken *pName = &pInfo->pMiscInfo->user.user; - SStrToken *pPwd = &pInfo->pMiscInfo->user.passwd; - - strncpy(pAlterMsg->user, pName->z, pName->n); - strncpy(pAlterMsg->pass, pPwd->z, pPwd->n); - - SCreateAcctInfo *pAcctOpt = &pInfo->pMiscInfo->acctOpt; - - pAlterMsg->cfg.maxUsers = htonl(pAcctOpt->maxUsers); - pAlterMsg->cfg.maxDbs = htonl(pAcctOpt->maxDbs); - pAlterMsg->cfg.maxTimeSeries = htonl(pAcctOpt->maxTimeSeries); - pAlterMsg->cfg.maxStreams = htonl(pAcctOpt->maxStreams); - pAlterMsg->cfg.maxPointsPerSecond = htonl(pAcctOpt->maxPointsPerSecond); - pAlterMsg->cfg.maxStorage = htobe64(pAcctOpt->maxStorage); - pAlterMsg->cfg.maxQueryTime = htobe64(pAcctOpt->maxQueryTime); - pAlterMsg->cfg.maxConnections = htonl(pAcctOpt->maxConnections); - - if (pAcctOpt->stat.n == 0) { - pAlterMsg->cfg.accessState = -1; - } else { - if (pAcctOpt->stat.z[0] == 'r' && pAcctOpt->stat.n == 1) { - pAlterMsg->cfg.accessState = TSDB_VN_READ_ACCCESS; - } else if (pAcctOpt->stat.z[0] == 'w' && pAcctOpt->stat.n == 1) { - pAlterMsg->cfg.accessState = TSDB_VN_WRITE_ACCCESS; - } else if (strncmp(pAcctOpt->stat.z, "all", 3) == 0 && pAcctOpt->stat.n == 3) { - pAlterMsg->cfg.accessState = TSDB_VN_ALL_ACCCESS; - } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { - pAlterMsg->cfg.accessState = 0; - } - } - - pCmd->msgType = TSDB_MSG_TYPE_CREATE_ACCT; - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateUserMsg); - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SCreateUserMsg *pAlterMsg = (SCreateUserMsg *)pCmd->payload; - - SUserInfo *pUser = &pInfo->pMiscInfo->user; - strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n); - pAlterMsg->flag = (int8_t)pUser->type; - - if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { - pAlterMsg->privilege = (char)pCmd->count; - } else if (pUser->type == TSDB_ALTER_USER_PASSWD) { - strncpy(pAlterMsg->pass, pUser->passwd.z, pUser->passwd.n); - } else { // create user password info - strncpy(pAlterMsg->pass, pUser->passwd.z, pUser->passwd.n); - } - - if (pUser->type == TSDB_ALTER_USER_PASSWD || pUser->type == TSDB_ALTER_USER_PRIVILEGES) { - pCmd->msgType = TSDB_MSG_TYPE_ALTER_USER; - } else { - pCmd->msgType = TSDB_MSG_TYPE_CREATE_USER; - } - - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCfgDnodeMsg); - pCmd->msgType = TSDB_MSG_TYPE_CONFIG_DNODE; - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SDropDbMsg); - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SDropDbMsg *pDropDbMsg = (SDropDbMsg*)pCmd->payload; - - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - - int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pDropDbMsg->db); - assert(code == TSDB_CODE_SUCCESS && pTableMetaInfo->name.type == TSDB_DB_NAME_T); - - pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - - pCmd->msgType = (pInfo->pMiscInfo->dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_DROP_DB : TSDB_MSG_TYPE_DROP_TP; - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildDropFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - - pCmd->msgType = TSDB_MSG_TYPE_DROP_FUNCTION; - - pCmd->payloadLen = sizeof(SDropFuncMsg); - - return TSDB_CODE_SUCCESS; -} - - -int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCMDropTableMsg); - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SCMDropTableMsg *pDropTableMsg = (SCMDropTableMsg*)pCmd->payload; - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - tNameExtractFullName(&pTableMetaInfo->name, pDropTableMsg->name); - - pDropTableMsg->supertable = (pInfo->pMiscInfo->tableType == TSDB_SUPER_TABLE)? 1:0; - pDropTableMsg->igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - pCmd->msgType = TSDB_MSG_TYPE_DROP_TABLE; - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - - char dnodeEp[TSDB_EP_LEN] = {0}; - tstrncpy(dnodeEp, pCmd->payload, TSDB_EP_LEN); - - pCmd->payloadLen = sizeof(SDropDnodeMsg); - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SDropDnodeMsg * pDrop = (SDropDnodeMsg *)pCmd->payload; - tstrncpy(pDrop->ep, dnodeEp, tListLen(pDrop->ep)); - pCmd->msgType = TSDB_MSG_TYPE_DROP_DNODE; - - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - - char user[TSDB_USER_LEN] = {0}; - tstrncpy(user, pCmd->payload, TSDB_USER_LEN); - - pCmd->payloadLen = sizeof(SDropUserMsg); - pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TSDB_MSG_TYPE_DROP_USER:TSDB_MSG_TYPE_DROP_ACCT; - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SDropUserMsg *pDropMsg = (SDropUserMsg *)pCmd->payload; - tstrncpy(pDropMsg->user, user, tListLen(user)); - - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SUseDbMsg); - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SUseDbMsg *pUseDbMsg = (SUseDbMsg *)pCmd->payload; - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - tNameExtractFullName(&pTableMetaInfo->name, pUseDbMsg->db); - pCmd->msgType = TSDB_MSG_TYPE_USE_DB; - - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildSyncDbReplicaMsg(SSqlObj* pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SSyncDbMsg); - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SSyncDbMsg *pSyncMsg = (SSyncDbMsg *)pCmd->payload; - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - tNameExtractFullName(&pTableMetaInfo->name, pSyncMsg->db); - pCmd->msgType = TSDB_MSG_TYPE_SYNC_DB; - - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_SHOW; - pCmd->payloadLen = sizeof(SShowMsg) + 100; - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SShowInfo *pShowInfo = &pInfo->pMiscInfo->showOpt; - SShowMsg *pShowMsg = (SShowMsg *)pCmd->payload; - - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - if (pShowInfo->showType == TSDB_MGMT_TABLE_FUNCTION) { - pShowMsg->type = pShowInfo->showType; - pShowMsg->payloadLen = 0; - pCmd->payloadLen = sizeof(SShowMsg); - - return TSDB_CODE_SUCCESS; - } - - if (tNameIsEmpty(&pTableMetaInfo->name)) { - char *p = cloneCurrentDBName(pSql); - tstrncpy(pShowMsg->db, p, sizeof(pShowMsg->db)); - tfree(p); - } else { - tNameGetFullDbName(&pTableMetaInfo->name, pShowMsg->db); - } - - pShowMsg->type = pShowInfo->showType; - - if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { - SStrToken *pPattern = &pShowInfo->pattern; - if (pPattern->type > 0) { // only show tables support wildcard query - strncpy(pShowMsg->payload, pPattern->z, pPattern->n); - pShowMsg->payloadLen = htons(pPattern->n); - } - } else { - SStrToken *pEpAddr = &pShowInfo->prefix; - assert(pEpAddr->n > 0 && pEpAddr->type > 0); - - strncpy(pShowMsg->payload, pEpAddr->z, pEpAddr->n); - pShowMsg->payloadLen = htons(pEpAddr->n); - } - - pCmd->payloadLen = sizeof(SShowMsg) + htons(pShowMsg->payloadLen); - return TSDB_CODE_SUCCESS; -} - -int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SKillQueryMsg); - - switch (pCmd->command) { - case TSDB_SQL_KILL_QUERY: - pCmd->msgType = TSDB_MSG_TYPE_KILL_QUERY; - break; - case TSDB_SQL_KILL_CONNECTION: - pCmd->msgType = TSDB_MSG_TYPE_KILL_CONN; - break; - case TSDB_SQL_KILL_STREAM: - pCmd->msgType = TSDB_MSG_TYPE_KILL_STREAM; - break; - } - return TSDB_CODE_SUCCESS; -} - -int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &(pSql->cmd); - int32_t size = minMsgSize() + sizeof(SCMCreateTableMsg) + sizeof(SCreateTableMsg); - - SCreateTableSql *pCreateTableInfo = pInfo->pCreateTableInfo; - if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) { - int32_t numOfTables = (int32_t)taosArrayGetSize(pInfo->pCreateTableInfo->childTableInfo); - size += numOfTables * (sizeof(SCreateTableMsg) + TSDB_MAX_TAGS_LEN); - } else { - size += sizeof(SSchema) * (pCmd->numOfCols + pCmd->count); - } - - if (pCreateTableInfo->pSelect != NULL) { - size += (pCreateTableInfo->pSelect->sqlstr.n + 1); - } - - return size + TSDB_EXTRA_PAYLOAD_SIZE; -} - -int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - int msgLen = 0; - int size = 0; - SSchema *pSchema; - SSqlCmd *pCmd = &pSql->cmd; - - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - - // Reallocate the payload size - size = tscEstimateCreateTableMsgLength(pSql, pInfo); - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { - tscError("0x%"PRIx64" failed to malloc for create table msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SCMCreateTableMsg *pCreateTableMsg = (SCMCreateTableMsg *)pCmd->payload; - - SCreateTableMsg* pCreateMsg = (SCreateTableMsg*)((char*) pCreateTableMsg + sizeof(SCMCreateTableMsg)); - char* pMsg = NULL; - - int8_t type = pInfo->pCreateTableInfo->type; - if (type == TSQL_CREATE_TABLE_FROM_STABLE) { // create by using super table, tags value - SArray* list = pInfo->pCreateTableInfo->childTableInfo; - - int32_t numOfTables = (int32_t) taosArrayGetSize(list); - pCreateTableMsg->numOfTables = htonl(numOfTables); - - pMsg = (char*) pCreateMsg; - for(int32_t i = 0; i < numOfTables; ++i) { - SCreateTableMsg* pCreate = (SCreateTableMsg*) pMsg; - - pCreate->numOfColumns = htons(pCmd->numOfCols); - pCreate->numOfTags = htons(pCmd->count); - pMsg += sizeof(SCreateTableMsg); - - SCreatedTableInfo* p = taosArrayGet(list, i); - strcpy(pCreate->tableName, p->fullname); - pCreate->igExists = (p->igExist)? 1 : 0; - - // use dbinfo from table id without modifying current db info - pMsg = serializeTagData(&p->tagdata, pMsg); - - int32_t len = (int32_t)(pMsg - (char*) pCreate); - pCreate->len = htonl(len); - } - } else { // create (super) table - pCreateTableMsg->numOfTables = htonl(1); // only one table will be created - - int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pCreateMsg->tableName); - assert(code == 0); - - SCreateTableSql *pCreateTable = pInfo->pCreateTableInfo; - - pCreateMsg->igExists = pCreateTable->existCheck ? 1 : 0; - pCreateMsg->numOfColumns = htons(pCmd->numOfCols); - pCreateMsg->numOfTags = htons(pCmd->count); - - pCreateMsg->sqlLen = 0; - pMsg = (char *)pCreateMsg->schema; - - pSchema = (SSchema *)pCreateMsg->schema; - - for (int i = 0; i < pCmd->numOfCols + pCmd->count; ++i) { - TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); - - pSchema->type = pField->type; - strcpy(pSchema->name, pField->name); - pSchema->bytes = htons(pField->bytes); - - pSchema++; - } - - pMsg = (char *)pSchema; - if (type == TSQL_CREATE_STREAM) { // check if it is a stream sql - SSqlNode *pQuerySql = pInfo->pCreateTableInfo->pSelect; - - strncpy(pMsg, pQuerySql->sqlstr.z, pQuerySql->sqlstr.n + 1); - pCreateMsg->sqlLen = htons(pQuerySql->sqlstr.n + 1); - pMsg += pQuerySql->sqlstr.n + 1; - } - } - - tscFieldInfoClear(&pQueryInfo->fieldsInfo); - - msgLen = (int32_t)(pMsg - (char*)pCreateTableMsg); - pCreateTableMsg->contLen = htonl(msgLen); - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE; - - assert(msgLen + minMsgSize() <= size); - return TSDB_CODE_SUCCESS; -} - -int tscEstimateAlterTableMsgLength(SSqlCmd *pCmd) { - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - return minMsgSize() + sizeof(SAlterTableMsg) + sizeof(SSchema) * tscNumOfFields(pQueryInfo) + TSDB_EXTRA_PAYLOAD_SIZE; -} - -int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - char *pMsg; - int msgLen = 0; - - SSqlCmd *pCmd = &pSql->cmd; - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - - SAlterTableInfo *pAlterInfo = pInfo->pAlterInfo; - int size = tscEstimateAlterTableMsgLength(pCmd); - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { - tscError("0x%"PRIx64" failed to malloc for alter table msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SAlterTableMsg *pAlterTableMsg = (SAlterTableMsg *)pCmd->payload; - - tNameExtractFullName(&pTableMetaInfo->name, pAlterTableMsg->tableFname); - pAlterTableMsg->type = htons(pAlterInfo->type); - - pAlterTableMsg->numOfCols = htons(tscNumOfFields(pQueryInfo)); - SSchema *pSchema = pAlterTableMsg->schema; - for (int i = 0; i < tscNumOfFields(pQueryInfo); ++i) { - TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); - - pSchema->type = pField->type; - strcpy(pSchema->name, pField->name); - pSchema->bytes = htons(pField->bytes); - pSchema++; - } - - pMsg = (char *)pSchema; - pAlterTableMsg->tagValLen = htonl(pAlterInfo->tagData.dataLen); - if (pAlterInfo->tagData.dataLen > 0) { - memcpy(pMsg, pAlterInfo->tagData.data, pAlterInfo->tagData.dataLen); - } - pMsg += pAlterInfo->tagData.dataLen; - - msgLen = (int32_t)(pMsg - (char*)pAlterTableMsg); - - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE; - - assert(msgLen + minMsgSize() <= size); - - return TSDB_CODE_SUCCESS; -} - -int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) { - SSqlCmd* pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_UPDATE_TAG_VAL; - - SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) pCmd->payload; - pCmd->payloadLen = htonl(pUpdateMsg->head.contLen); - - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - STableMeta *pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; - - SNewVgroupInfo vgroupInfo = {.vgId = -1}; - taosHashGetClone(tscVgroupMap, &pTableMeta->vgId, sizeof(pTableMeta->vgId), NULL, &vgroupInfo); - assert(vgroupInfo.vgId > 0); - - tscDumpEpSetFromVgroupInfo(&pSql->epSet, &vgroupInfo); - - return TSDB_CODE_SUCCESS; -} - -int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SAlterDbMsg); - pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_ALTER_DB : TSDB_MSG_TYPE_ALTER_TP; - - SAlterDbMsg *pAlterDbMsg = (SAlterDbMsg* )pCmd->payload; - pAlterDbMsg->dbType = -1; - - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - tNameExtractFullName(&pTableMetaInfo->name, pAlterDbMsg->db); - - return TSDB_CODE_SUCCESS; -} -int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - if (pInfo->list == NULL || taosArrayGetSize(pInfo->list) <= 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - STscObj *pObj = pSql->pTscObj; - SSqlCmd *pCmd = &pSql->cmd; - SArray *pList = pInfo->list; - int32_t size = (int32_t)taosArrayGetSize(pList); - - int32_t *result = malloc(sizeof(int32_t) * size); - if (result == NULL) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - for (int32_t i = 0; i < size; i++) { - tSqlExprItem* pSub = taosArrayGet(pList, i); - tVariant* pVar = &pSub->pNode->value; - if (pVar->nType >= TSDB_DATA_TYPE_TINYINT && pVar->nType <= TSDB_DATA_TYPE_BIGINT) { - result[i] = (int32_t)(pVar->i64); - } else { - free(result); - return TSDB_CODE_TSC_INVALID_OPERATION; - } - } - - int count = removeDupVgid(result, size); - pCmd->payloadLen = sizeof(SCompactMsg) + count * sizeof(int32_t); - pCmd->msgType = TSDB_MSG_TYPE_COMPACT_VNODE; - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - free(result); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - SCompactMsg *pCompactMsg = (SCompactMsg *)pCmd->payload; - - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - - if (tNameIsEmpty(&pTableMetaInfo->name)) { - pthread_mutex_lock(&pObj->mutex); - tstrncpy(pCompactMsg->db, pObj->db, sizeof(pCompactMsg->db)); - pthread_mutex_unlock(&pObj->mutex); - } else { - tNameGetFullDbName(&pTableMetaInfo->name, pCompactMsg->db); - } - - pCompactMsg->numOfVgroup = htons(count); - for (int32_t i = 0; i < count; i++) { - pCompactMsg->vgid[i] = htons(result[i]); - } - free(result); - - return TSDB_CODE_SUCCESS; -} - -int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - pCmd->payloadLen = sizeof(SRetrieveTableMsg); - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg*)pCmd->payload; - pRetrieveMsg->qId = htobe64(pSql->res.qId); - pRetrieveMsg->free = htons(pQueryInfo->type); - - return TSDB_CODE_SUCCESS; -} - -/* - * this function can only be called once. - * by using pRes->rspType to denote its status - * - * if pRes->rspType is 1, no more result - */ -static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) { - SSqlRes *pRes = &pSql->res; - SSqlCmd *pCmd = &pSql->cmd; - - pRes->code = TSDB_CODE_SUCCESS; - if (pRes->rspType == 0) { - pRes->numOfRows = numOfRes; - pRes->row = 0; - pRes->rspType = 1; - - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - if (tscCreateResPointerInfo(pRes, pQueryInfo) != TSDB_CODE_SUCCESS) { - return pRes->code; - } - - tscSetResRawPtr(pRes, pQueryInfo); - } else { - tscResetForNextRetrieve(pRes); - } - - uint8_t code = pSql->res.code; - if (pSql->fp) { - if (code == TSDB_CODE_SUCCESS) { - (*pSql->fp)(pSql->param, pSql, pSql->res.numOfRows); - } else { - tscAsyncResultOnError(pSql); - } - } - - return code; -} - -int tscProcessDescribeTableRsp(SSqlObj *pSql) { - SSqlCmd * pCmd = &pSql->cmd; - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); - - STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - - int32_t numOfRes = tinfo.numOfColumns + tinfo.numOfTags; - return tscLocalResultCommonBuilder(pSql, numOfRes); -} - -int tscProcessLocalRetrieveRsp(SSqlObj *pSql) { - int32_t numOfRes = 1; - pSql->res.completed = true; - return tscLocalResultCommonBuilder(pSql, numOfRes); -} - -int tscProcessRetrieveGlobalMergeRsp(SSqlObj *pSql) { - SSqlRes *pRes = &pSql->res; - SSqlCmd* pCmd = &pSql->cmd; - - int32_t code = pRes->code; - if (pRes->code != TSDB_CODE_SUCCESS) { - tscAsyncResultOnError(pSql); - return code; - } - - if (pRes->pMerger == NULL) { // no result from subquery, so abort here directly. - (*pSql->fp)(pSql->param, pSql, pRes->numOfRows); - return code; - } - - // global aggregation may be the upstream for parent query - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - if (pQueryInfo->pQInfo == NULL) { - STableGroupInfo tableGroupInfo = {.numOfTables = 1, .pGroupList = taosArrayInit(1, POINTER_BYTES),}; - tableGroupInfo.map = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - - STableKeyInfo tableKeyInfo = {.pTable = NULL, .lastKey = INT64_MIN}; - - SArray* group = taosArrayInit(1, sizeof(STableKeyInfo)); - taosArrayPush(group, &tableKeyInfo); - taosArrayPush(tableGroupInfo.pGroupList, &group); - - tscDebug("0x%"PRIx64" create QInfo 0x%"PRIx64" to execute query processing", pSql->self, pSql->self); - pQueryInfo->pQInfo = createQInfoFromQueryNode(pQueryInfo, &tableGroupInfo, NULL, NULL, pRes->pMerger, MERGE_STAGE, pSql->self); - } - - uint64_t localQueryId = pSql->self; - qTableQuery(pQueryInfo->pQInfo, &localQueryId); - convertQueryResult(pRes, pQueryInfo, pSql->self, true); - - code = pRes->code; - if (pRes->code == TSDB_CODE_SUCCESS) { - (*pSql->fp)(pSql->param, pSql, pRes->numOfRows); - } else { - tscAsyncResultOnError(pSql); - } - - return code; -} - -int tscProcessEmptyResultRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder(pSql, 0); } - -int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - STscObj *pObj = pSql->pTscObj; - SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_CONNECT; - pCmd->payloadLen = sizeof(SConnectMsg); - - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SConnectMsg *pConnect = (SConnectMsg*)pCmd->payload; - - // TODO refactor full_name - char *db; // ugly code to move the space - - pthread_mutex_lock(&pObj->mutex); - db = strstr(pObj->db, TS_PATH_DELIMITER); - - db = (db == NULL) ? pObj->db : db + 1; - tstrncpy(pConnect->db, db, sizeof(pConnect->db)); - pthread_mutex_unlock(&pObj->mutex); - - tstrncpy(pConnect->clientVersion, version, sizeof(pConnect->clientVersion)); - tstrncpy(pConnect->msgVersion, "", sizeof(pConnect->msgVersion)); - - pConnect->pid = htonl(taosGetPId()); - taosGetCurrentAPPName(pConnect->appName, NULL); - - return TSDB_CODE_SUCCESS; -} - -/** - * multi table meta req pkg format: - * |SMultiTableInfoMsg | tableId0 | tableId1 | tableId2 | ...... - * 4B - **/ -int tscBuildMultiTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - - pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; - assert(pCmd->payloadLen + minMsgSize() <= pCmd->allocSize); - - tscDebug("0x%"PRIx64" build load multi-tablemeta msg completed, numOfTables:%d, msg size:%d", pSql->self, pCmd->count, - pCmd->payloadLen); - - return pCmd->payloadLen; -} - -int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - - char* pMsg = pCmd->payload; - SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); - - SSTableVgroupMsg *pStableVgroupMsg = (SSTableVgroupMsg *)pMsg; - pStableVgroupMsg->numOfTables = htonl(pQueryInfo->numOfTables); - pMsg += sizeof(SSTableVgroupMsg); - - for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, i); - int32_t code = tNameExtractFullName(&pTableMetaInfo->name, pMsg); - assert(code == TSDB_CODE_SUCCESS); - - pMsg += TSDB_TABLE_FNAME_LEN; - } - - pCmd->msgType = TSDB_MSG_TYPE_STABLE_VGROUP; - pCmd->payloadLen = (int32_t)(pMsg - pCmd->payload); - - return TSDB_CODE_SUCCESS; -} - -int tscBuildRetrieveFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - - char *pMsg = pCmd->payload; - SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); - int32_t numOfFuncs = (int32_t)taosArrayGetSize(pQueryInfo->pUdfInfo); - - SRetrieveFuncMsg *pRetrieveFuncMsg = (SRetrieveFuncMsg *)pMsg; - pRetrieveFuncMsg->num = htonl(numOfFuncs); - - pMsg += sizeof(SRetrieveFuncMsg); - for(int32_t i = 0; i < numOfFuncs; ++i) { - SUdfInfo* pUdf = taosArrayGet(pQueryInfo->pUdfInfo, i); - STR_TO_NET_VARSTR(pMsg, pUdf->name); - pMsg += varDataNetTLen(pMsg); - } - - pCmd->msgType = TSDB_MSG_TYPE_RETRIEVE_FUNC; - pCmd->payloadLen = (int32_t)(pMsg - pCmd->payload); - - return TSDB_CODE_SUCCESS; -} - -int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SSqlCmd *pCmd = &pSql->cmd; - STscObj *pObj = pSql->pTscObj; - - pthread_mutex_lock(&pObj->mutex); - - int32_t numOfQueries = 2; - SSqlObj *tpSql = pObj->sqlList; - while (tpSql) { - tpSql = tpSql->next; - numOfQueries++; - } - - int32_t numOfStreams = 2; - SSqlStream *pStream = pObj->streamList; - while (pStream) { - pStream = pStream->next; - numOfStreams++; - } - - int size = numOfQueries * sizeof(SQueryDesc) + numOfStreams * sizeof(SStreamDesc) + sizeof(SHeartBeatMsg) + 100; - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { - pthread_mutex_unlock(&pObj->mutex); - tscError("0x%"PRIx64" failed to create heartbeat msg", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - // TODO the expired hb and client can not be identified by server till now. - SHeartBeatMsg *pHeartbeat = (SHeartBeatMsg *)pCmd->payload; - tstrncpy(pHeartbeat->clientVer, version, tListLen(pHeartbeat->clientVer)); - - pHeartbeat->numOfQueries = numOfQueries; - pHeartbeat->numOfStreams = numOfStreams; - - pHeartbeat->pid = htonl(taosGetPId()); - taosGetCurrentAPPName(pHeartbeat->appName, NULL); - - int msgLen = tscBuildQueryStreamDesc(pHeartbeat, pObj); - - pthread_mutex_unlock(&pObj->mutex); - - pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_HEARTBEAT; - - return TSDB_CODE_SUCCESS; -} - -static int32_t tableMetaMsgConvert(STableMetaMsg* pMetaMsg) { - pMetaMsg->tid = htonl(pMetaMsg->tid); - pMetaMsg->sversion = htons(pMetaMsg->sversion); - pMetaMsg->tversion = htons(pMetaMsg->tversion); - pMetaMsg->vgroup.vgId = htonl(pMetaMsg->vgroup.vgId); - - pMetaMsg->uid = htobe64(pMetaMsg->uid); - pMetaMsg->numOfColumns = htons(pMetaMsg->numOfColumns); - - if ((pMetaMsg->tableType != TSDB_SUPER_TABLE) && - (pMetaMsg->tid <= 0 || pMetaMsg->vgroup.vgId < 2 || pMetaMsg->vgroup.numOfEps <= 0)) { - tscError("invalid value in table numOfEps:%d, vgId:%d tid:%d, name:%s", pMetaMsg->vgroup.numOfEps, pMetaMsg->vgroup.vgId, - pMetaMsg->tid, pMetaMsg->tableFname); - return TSDB_CODE_TSC_INVALID_VALUE; - } - - if (pMetaMsg->numOfTags > TSDB_MAX_TAGS) { - tscError("invalid numOfTags:%d", pMetaMsg->numOfTags); - return TSDB_CODE_TSC_INVALID_VALUE; - } - - if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) { - tscError("invalid numOfColumns:%d", pMetaMsg->numOfColumns); - return TSDB_CODE_TSC_INVALID_VALUE; - } - - for (int i = 0; i < pMetaMsg->vgroup.numOfEps; ++i) { - pMetaMsg->vgroup.epAddr[i].port = htons(pMetaMsg->vgroup.epAddr[i].port); - } - - SSchema* pSchema = pMetaMsg->schema; - - int32_t numOfTotalCols = pMetaMsg->numOfColumns + pMetaMsg->numOfTags; - for (int i = 0; i < numOfTotalCols; ++i) { - pSchema->bytes = htons(pSchema->bytes); - pSchema->colId = htons(pSchema->colId); - - if (pSchema->colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { - assert(i == 0); - } - - pSchema++; - } - - return TSDB_CODE_SUCCESS; -} - -// update the vgroupInfo if needed -static void doUpdateVgroupInfo(int32_t vgId, SVgroupMsg *pVgroupMsg) { - assert(vgId > 0); - - SNewVgroupInfo vgroupInfo = {.inUse = -1}; - taosHashGetClone(tscVgroupMap, &vgId, sizeof(vgId), NULL, &vgroupInfo); - - // vgroup info exists, compare with it - if (((vgroupInfo.inUse >= 0) && !vgroupInfoIdentical(&vgroupInfo, pVgroupMsg)) || (vgroupInfo.inUse < 0)) { - vgroupInfo = createNewVgroupInfo(pVgroupMsg); - taosHashPut(tscVgroupMap, &vgId, sizeof(vgId), &vgroupInfo, sizeof(vgroupInfo)); - tscDebug("add/update new VgroupInfo, vgId:%d, total cached:%d", vgId, (int32_t) taosHashGetSize(tscVgroupMap)); - } -} - -static void doAddTableMetaToLocalBuf(STableMeta* pTableMeta, STableMetaMsg* pMetaMsg, bool updateSTable) { - if (pTableMeta->tableType == TSDB_CHILD_TABLE) { - // add or update the corresponding super table meta data info - int32_t len = (int32_t) strnlen(pTableMeta->sTableName, TSDB_TABLE_FNAME_LEN); - - // The super tableMeta already exists, create it according to tableMeta and add it to hash map - if (updateSTable) { - STableMeta* pSupTableMeta = createSuperTableMeta(pMetaMsg); - uint32_t size = tscGetTableMetaSize(pSupTableMeta); - int32_t code = taosHashPut(tscTableMetaMap, pTableMeta->sTableName, len, pSupTableMeta, size); - assert(code == TSDB_CODE_SUCCESS); - - tfree(pSupTableMeta); - } - - CChildTableMeta* cMeta = tscCreateChildMeta(pTableMeta); - taosHashPut(tscTableMetaMap, pMetaMsg->tableFname, strlen(pMetaMsg->tableFname), cMeta, sizeof(CChildTableMeta)); - tfree(cMeta); - } else { - uint32_t s = tscGetTableMetaSize(pTableMeta); - taosHashPut(tscTableMetaMap, pMetaMsg->tableFname, strlen(pMetaMsg->tableFname), pTableMeta, s); - } -} - -int tscProcessTableMetaRsp(SSqlObj *pSql) { - STableMetaMsg *pMetaMsg = (STableMetaMsg *)pSql->res.pRsp; - int32_t code = tableMetaMsgConvert(pMetaMsg); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0); - assert(pTableMetaInfo->pTableMeta == NULL); - - STableMeta* pTableMeta = tscCreateTableMetaFromMsg(pMetaMsg); - if (pTableMeta == NULL){ - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - if (!tIsValidSchema(pTableMeta->schema, pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.numOfTags)) { - tscError("0x%"PRIx64" invalid table meta from mnode, name:%s", pSql->self, tNameGetTableName(&pTableMetaInfo->name)); - tfree(pTableMeta); - return TSDB_CODE_TSC_INVALID_VALUE; - } - - char name[TSDB_TABLE_FNAME_LEN] = {0}; - tNameExtractFullName(&pTableMetaInfo->name, name); - assert(strncmp(pMetaMsg->tableFname, name, tListLen(pMetaMsg->tableFname)) == 0); - - doAddTableMetaToLocalBuf(pTableMeta, pMetaMsg, true); - if (pTableMeta->tableType != TSDB_SUPER_TABLE) { - doUpdateVgroupInfo(pTableMeta->vgId, &pMetaMsg->vgroup); - } - - tscDebug("0x%"PRIx64" recv table meta, uid:%" PRIu64 ", tid:%d, name:%s, numOfCols:%d, numOfTags:%d", pSql->self, - pTableMeta->id.uid, pTableMeta->id.tid, tNameGetTableName(&pTableMetaInfo->name), pTableMeta->tableInfo.numOfColumns, - pTableMeta->tableInfo.numOfTags); - - free(pTableMeta); - return TSDB_CODE_SUCCESS; -} - -static SArray* createVgroupIdListFromMsg(char* pMsg, SHashObj* pSet, char* name, int32_t* size, uint64_t id) { - SVgroupsMsg *pVgroupMsg = (SVgroupsMsg *)pMsg; - - pVgroupMsg->numOfVgroups = htonl(pVgroupMsg->numOfVgroups); - *size = (int32_t)(sizeof(SVgroupMsg) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsMsg)); - - SArray* vgroupIdList = taosArrayInit(pVgroupMsg->numOfVgroups, sizeof(int32_t)); - - if (pVgroupMsg->numOfVgroups <= 0) { - tscDebug("0x%" PRIx64 " empty vgroup id list, no corresponding tables for stable:%s", id, name); - } else { - // just init, no need to lock - for (int32_t j = 0; j < pVgroupMsg->numOfVgroups; ++j) { - SVgroupMsg *vmsg = &pVgroupMsg->vgroups[j]; - vmsg->vgId = htonl(vmsg->vgId); - for (int32_t k = 0; k < vmsg->numOfEps; ++k) { - vmsg->epAddr[k].port = htons(vmsg->epAddr[k].port); - } - - taosArrayPush(vgroupIdList, &vmsg->vgId); - - if (taosHashGet(pSet, &vmsg->vgId, sizeof(vmsg->vgId)) == NULL) { - taosHashPut(pSet, &vmsg->vgId, sizeof(vmsg->vgId), "", 0); - doUpdateVgroupInfo(vmsg->vgId, vmsg); - } - } - } - - return vgroupIdList; -} - -static SVgroupsInfo* createVgroupInfoFromMsg(char* pMsg, int32_t* size, uint64_t id) { - SVgroupsMsg *pVgroupMsg = (SVgroupsMsg *)pMsg; - pVgroupMsg->numOfVgroups = htonl(pVgroupMsg->numOfVgroups); - - *size = (int32_t)(sizeof(SVgroupMsg) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsMsg)); - - size_t vgroupsz = sizeof(SVgroupMsg) * pVgroupMsg->numOfVgroups + sizeof(SVgroupsInfo); - SVgroupsInfo *pVgroupInfo = calloc(1, vgroupsz); - assert(pVgroupInfo != NULL); - - pVgroupInfo->numOfVgroups = pVgroupMsg->numOfVgroups; - if (pVgroupInfo->numOfVgroups <= 0) { - tscDebug("0x%" PRIx64 " empty vgroup info, no corresponding tables for stable", id); - } else { - for (int32_t j = 0; j < pVgroupInfo->numOfVgroups; ++j) { - // just init, no need to lock - SVgroupMsg *pVgroup = &pVgroupInfo->vgroups[j]; - - SVgroupMsg *vmsg = &pVgroupMsg->vgroups[j]; - vmsg->vgId = htonl(vmsg->vgId); - for (int32_t k = 0; k < vmsg->numOfEps; ++k) { - vmsg->epAddr[k].port = htons(vmsg->epAddr[k].port); - } - - pVgroup->numOfEps = vmsg->numOfEps; - pVgroup->vgId = vmsg->vgId; - for (int32_t k = 0; k < vmsg->numOfEps; ++k) { - pVgroup->epAddr[k].port = vmsg->epAddr[k].port; - tstrncpy(pVgroup->epAddr[k].fqdn, vmsg->epAddr[k].fqdn, TSDB_FQDN_LEN); -// pVgroup->epAddr[k].fqdn = strndup(vmsg->epAddr[k].fqdn, TSDB_FQDN_LEN); - } - - doUpdateVgroupInfo(pVgroup->vgId, vmsg); - } - } - - return pVgroupInfo; -} - -int tscProcessRetrieveFuncRsp(SSqlObj* pSql) { - SSqlCmd* pCmd = &pSql->cmd; - SUdfFuncMsg* pFuncMsg = (SUdfFuncMsg *)pSql->res.pRsp; - SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); - - pFuncMsg->num = htonl(pFuncMsg->num); - assert(pFuncMsg->num == taosArrayGetSize(pQueryInfo->pUdfInfo)); - - char* pMsg = pFuncMsg->content; - for(int32_t i = 0; i < pFuncMsg->num; ++i) { - SFunctionInfoMsg* pFunc = (SFunctionInfoMsg*) pMsg; - - for(int32_t j = 0; j < pFuncMsg->num; ++j) { - SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, j); - if (strcmp(pUdfInfo->name, pFunc->name) != 0) { - continue; - } - - if (pUdfInfo->content) { - continue; - } - - pUdfInfo->resBytes = htons(pFunc->resBytes); - pUdfInfo->resType = pFunc->resType; - pUdfInfo->funcType = htonl(pFunc->funcType); - pUdfInfo->contLen = htonl(pFunc->len); - pUdfInfo->bufSize = htonl(pFunc->bufSize); - - pUdfInfo->content = malloc(pUdfInfo->contLen); - memcpy(pUdfInfo->content, pFunc->content, pUdfInfo->contLen); - - pMsg += sizeof(SFunctionInfoMsg) + pUdfInfo->contLen; - } - } - - // master sqlObj locates in param - SSqlObj* parent = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)pSql->param); - if(parent == NULL) { - return pSql->res.code; - } - - SQueryInfo* parQueryInfo = tscGetQueryInfo(&parent->cmd); - - assert(parent->signature == parent && (int64_t)pSql->param == parent->self); - taosArrayDestroy(parQueryInfo->pUdfInfo); - - parQueryInfo->pUdfInfo = pQueryInfo->pUdfInfo; // assigned to parent sql obj. - pQueryInfo->pUdfInfo = NULL; - return TSDB_CODE_SUCCESS; -} - -int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { - char *rsp = pSql->res.pRsp; - - SMultiTableMeta *pMultiMeta = (SMultiTableMeta *)rsp; - pMultiMeta->numOfTables = htonl(pMultiMeta->numOfTables); - pMultiMeta->numOfVgroup = htonl(pMultiMeta->numOfVgroup); - pMultiMeta->numOfUdf = htonl(pMultiMeta->numOfUdf); - - rsp += sizeof(SMultiTableMeta); - - SSqlObj* pParentSql = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)pSql->param); - if(pParentSql == NULL) { - return pSql->res.code; - } - - SSqlCmd *pParentCmd = &pParentSql->cmd; - SHashObj *pSet = taosHashInit(pMultiMeta->numOfVgroup, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); - - char* buf = NULL; - char* pMsg = pMultiMeta->meta; - - // decompresss the message payload - if (pMultiMeta->compressed) { - buf = malloc(pMultiMeta->rawLen - sizeof(SMultiTableMeta)); - int32_t len = tsDecompressString(pMultiMeta->meta, pMultiMeta->contLen - sizeof(SMultiTableMeta), 1, - buf, pMultiMeta->rawLen - sizeof(SMultiTableMeta), ONE_STAGE_COMP, NULL, 0); - assert(len == pMultiMeta->rawLen - sizeof(SMultiTableMeta)); - - pMsg = buf; - } - - if (pParentCmd->pTableMetaMap == NULL) { - pParentCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - } - - for (int32_t i = 0; i < pMultiMeta->numOfTables; i++) { - STableMetaMsg *pMetaMsg = (STableMetaMsg *)pMsg; - int32_t code = tableMetaMsgConvert(pMetaMsg); - if (code != TSDB_CODE_SUCCESS) { - taosHashCleanup(pSet); - taosReleaseRef(tscObjRef, pParentSql->self); - - tfree(buf); - return code; - } - - bool freeMeta = false; - STableMeta* pTableMeta = tscCreateTableMetaFromMsg(pMetaMsg); - if (!tIsValidSchema(pTableMeta->schema, pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.numOfTags)) { - tscError("0x%"PRIx64" invalid table meta from mnode, name:%s", pSql->self, pMetaMsg->tableFname); - tfree(pTableMeta); - taosHashCleanup(pSet); - taosReleaseRef(tscObjRef, pParentSql->self); - - tfree(buf); - return TSDB_CODE_TSC_INVALID_VALUE; - } - - if (pMultiMeta->metaClone == 1 || pTableMeta->tableType == TSDB_SUPER_TABLE) { - STableMetaVgroupInfo p = {.pTableMeta = pTableMeta,}; - size_t keyLen = strnlen(pMetaMsg->tableFname, TSDB_TABLE_FNAME_LEN); - void* t = taosHashGet(pParentCmd->pTableMetaMap, pMetaMsg->tableFname, keyLen); - assert(t == NULL); - - taosHashPut(pParentCmd->pTableMetaMap, pMetaMsg->tableFname, keyLen, &p, sizeof(STableMetaVgroupInfo)); - } else { - freeMeta = true; - } - - // for each super table, only update meta information once - bool updateStableMeta = false; - if (pTableMeta->tableType == TSDB_CHILD_TABLE && taosHashGet(pSet, &pMetaMsg->suid, sizeof(pMetaMsg->suid)) == NULL) { - updateStableMeta = true; - taosHashPut(pSet, &pTableMeta->suid, sizeof(pMetaMsg->suid), "", 0); - } - - // create the tableMeta and add it into the TableMeta map - doAddTableMetaToLocalBuf(pTableMeta, pMetaMsg, updateStableMeta); - - // for each vgroup, only update the information once. - int64_t vgId = pMetaMsg->vgroup.vgId; - if (pTableMeta->tableType != TSDB_SUPER_TABLE && taosHashGet(pSet, &vgId, sizeof(vgId)) == NULL) { - doUpdateVgroupInfo((int32_t) vgId, &pMetaMsg->vgroup); - taosHashPut(pSet, &vgId, sizeof(vgId), "", 0); - } - - pMsg += pMetaMsg->contLen; - if (freeMeta) { - tfree(pTableMeta); - } - } - - for(int32_t i = 0; i < pMultiMeta->numOfVgroup; ++i) { - char fname[TSDB_TABLE_FNAME_LEN] = {0}; - tstrncpy(fname, pMsg, TSDB_TABLE_FNAME_LEN); - size_t len = strnlen(fname, TSDB_TABLE_FNAME_LEN); - - pMsg += TSDB_TABLE_FNAME_LEN; - - STableMetaVgroupInfo* p = taosHashGet(pParentCmd->pTableMetaMap, fname, len); - assert(p != NULL); - - int32_t size = 0; - if (p->vgroupIdList!= NULL) { - taosArrayDestroy(p->vgroupIdList); - } - - p->vgroupIdList = createVgroupIdListFromMsg(pMsg, pSet, fname, &size, pSql->self); - - int32_t numOfVgId = (int32_t) taosArrayGetSize(p->vgroupIdList); - int32_t s = sizeof(tFilePage) + numOfVgId * sizeof(int32_t); - - tFilePage* idList = calloc(1, s); - idList->num = numOfVgId; - memcpy(idList->data, TARRAY_GET_START(p->vgroupIdList), numOfVgId * sizeof(int32_t)); - - void* idListInst = taosCachePut(tscVgroupListBuf, fname, len, idList, s, 5000); - taosCacheRelease(tscVgroupListBuf, (void*) &idListInst, false); - - tfree(idList); - pMsg += size; - } - - SQueryInfo* pQueryInfo = tscGetQueryInfo(pParentCmd); - if (pMultiMeta->numOfUdf > 0) { - assert(pQueryInfo->pUdfInfo != NULL); - } - - for(int32_t i = 0; i < pMultiMeta->numOfUdf; ++i) { - SFunctionInfoMsg* pFunc = (SFunctionInfoMsg*) pMsg; - - for(int32_t j = 0; j < pMultiMeta->numOfUdf; ++j) { - SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, j); - if (strcmp(pUdfInfo->name, pFunc->name) != 0) { - continue; - } - - if (pUdfInfo->content) { - continue; - } - - pUdfInfo->resBytes = htons(pFunc->resBytes); - pUdfInfo->resType = pFunc->resType; - pUdfInfo->funcType = htonl(pFunc->funcType); - pUdfInfo->contLen = htonl(pFunc->len); - pUdfInfo->bufSize = htonl(pFunc->bufSize); - - pUdfInfo->content = malloc(pUdfInfo->contLen); - memcpy(pUdfInfo->content, pFunc->content, pUdfInfo->contLen); - - pMsg += sizeof(SFunctionInfoMsg) + pUdfInfo->contLen; - } - } - - pSql->res.code = TSDB_CODE_SUCCESS; - pSql->res.numOfTotal = pMultiMeta->numOfTables; - tscDebug("0x%"PRIx64" load multi-tableMeta from mnode, numOfTables:%d", pSql->self, pMultiMeta->numOfTables); - - taosHashCleanup(pSet); - taosReleaseRef(tscObjRef, pParentSql->self); - - tfree(buf); - return TSDB_CODE_SUCCESS; -} - -int tscProcessSTableVgroupRsp(SSqlObj *pSql) { - // master sqlObj locates in param - SSqlObj* parent = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)pSql->param); - if(parent == NULL) { - return pSql->res.code; - } - - assert(parent->signature == parent && (int64_t)pSql->param == parent->self); - - SSqlRes* pRes = &pSql->res; - - // NOTE: the order of several table must be preserved. - SSTableVgroupRspMsg *pStableVgroup = (SSTableVgroupRspMsg *)pRes->pRsp; - pStableVgroup->numOfTables = htonl(pStableVgroup->numOfTables); - char *pMsg = pRes->pRsp + sizeof(SSTableVgroupRspMsg); - - SSqlCmd* pCmd = &parent->cmd; - SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); - - char fName[TSDB_TABLE_FNAME_LEN] = {0}; - for(int32_t i = 0; i < pStableVgroup->numOfTables; ++i) { - char* name = pMsg; - pMsg += TSDB_TABLE_FNAME_LEN; - - STableMetaInfo *pInfo = NULL; - for(int32_t j = 0; j < pQueryInfo->numOfTables; ++j) { - STableMetaInfo *pInfo1 = tscGetTableMetaInfoFromCmd(pCmd, j); - memset(fName, 0, tListLen(fName)); - - tNameExtractFullName(&pInfo1->name, fName); - if (strcmp(name, fName) != 0) { - continue; - } - - pInfo = pInfo1; - break; - } - - if (!pInfo){ - continue; - } - int32_t size = 0; - pInfo->vgroupList = createVgroupInfoFromMsg(pMsg, &size, pSql->self); - pMsg += size; - } - - taosReleaseRef(tscObjRef, parent->self); - return pSql->res.code; -} - -int tscProcessShowRsp(SSqlObj *pSql) { - STableMetaMsg *pMetaMsg; - SShowRsp * pShow; - SSchema * pSchema; - - SSqlRes *pRes = &pSql->res; - SSqlCmd *pCmd = &pSql->cmd; - - SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - - pShow = (SShowRsp *)pRes->pRsp; - pShow->qhandle = htobe64(pShow->qhandle); - pRes->qId = pShow->qhandle; - - tscResetForNextRetrieve(pRes); - pMetaMsg = &(pShow->tableMeta); - - pMetaMsg->numOfColumns = ntohs(pMetaMsg->numOfColumns); - - pSchema = pMetaMsg->schema; - pMetaMsg->tid = ntohs(pMetaMsg->tid); - for (int i = 0; i < pMetaMsg->numOfColumns; ++i) { - pSchema->bytes = htons(pSchema->bytes); - pSchema++; - } - - tfree(pTableMetaInfo->pTableMeta); - pTableMetaInfo->pTableMeta = tscCreateTableMetaFromMsg(pMetaMsg); - - SSchema *pTableSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta); - if (pQueryInfo->colList == NULL) { - pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES); - } - - SFieldInfo* pFieldInfo = &pQueryInfo->fieldsInfo; - - SColumnIndex index = {0}; - pSchema = pMetaMsg->schema; - - uint64_t uid = pTableMetaInfo->pTableMeta->id.uid; - for (int16_t i = 0; i < pMetaMsg->numOfColumns; ++i, ++pSchema) { - index.columnIndex = i; - tscColumnListInsert(pQueryInfo->colList, i, uid, pSchema); - - TAOS_FIELD f = tscCreateField(pSchema->type, pSchema->name, pSchema->bytes); - SInternalField* pInfo = tscFieldInfoAppend(pFieldInfo, &f); - - pInfo->pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, - pTableSchema[i].type, pTableSchema[i].bytes, getNewResColId(pCmd), pTableSchema[i].bytes, false); - } - - pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput; - tscFieldInfoUpdateOffset(pQueryInfo); - return 0; -} - -static void createHbObj(STscObj* pObj) { - if (pObj->hbrid != 0) { - return; - } - - SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); - if (NULL == pSql) return; - - pSql->fp = tscProcessHeartBeatRsp; - - SQueryInfo *pQueryInfo = tscGetQueryInfoS(&pSql->cmd); - if (pQueryInfo == NULL) { - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - tfree(pSql); - return; - } - - pQueryInfo->command = TSDB_SQL_HB; - - pSql->cmd.command = pQueryInfo->command; - if (TSDB_CODE_SUCCESS != tscAllocPayload(&(pSql->cmd), TSDB_DEFAULT_PAYLOAD_SIZE)) { - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - tfree(pSql); - return; - } - - pSql->param = pObj; - pSql->pTscObj = pObj; - pSql->signature = pSql; - - registerSqlObj(pSql); - tscDebug("0x%"PRIx64" HB is allocated, pObj:%p", pSql->self, pObj); - - pObj->hbrid = pSql->self; -} - -int tscProcessUseDbRsp(SSqlObj *pSql) { - STscObj * pObj = pSql->pTscObj; - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0); - - pthread_mutex_lock(&pObj->mutex); - int ret = tNameExtractFullName(&pTableMetaInfo->name, pObj->db); - pthread_mutex_unlock(&pObj->mutex); - - return ret; -} - -//todo only invalid the buffered data that belongs to dropped databases -int tscProcessDropDbRsp(SSqlObj *pSql) { - //TODO LOCK DB WHEN MODIFY IT - //pSql->pTscObj->db[0] = 0; - - taosHashClear(tscTableMetaMap); - taosHashClear(tscVgroupMap); - taosCacheEmpty(tscVgroupListBuf); - return 0; -} - -int tscProcessDropTableRsp(SSqlObj *pSql) { - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0); - tscRemoveCachedTableMeta(pTableMetaInfo, pSql->self); - tfree(pTableMetaInfo->pTableMeta); - return 0; -} - -int tscProcessAlterTableMsgRsp(SSqlObj *pSql) { - STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0); - - char name[TSDB_TABLE_FNAME_LEN] = {0}; - tNameExtractFullName(&pTableMetaInfo->name, name); - - tscDebug("0x%"PRIx64" remove tableMeta in hashMap after alter-table: %s", pSql->self, name); - - bool isSuperTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo); - taosHashRemove(tscTableMetaMap, name, strnlen(name, TSDB_TABLE_FNAME_LEN)); - tfree(pTableMetaInfo->pTableMeta); - - if (isSuperTable) { // if it is a super table, iterate the hashTable and remove all the childTableMeta - if (pSql->res.pRsp == NULL) { - tscDebug("0x%"PRIx64" unexpected resp from mnode, super table: %s failed to update super table meta ", pSql->self, name); - return 0; - } - return tscProcessTableMetaRsp(pSql); - } - - return 0; -} - -int tscProcessAlterDbMsgRsp(SSqlObj *pSql) { - UNUSED(pSql); - return 0; -} -int tscProcessCompactRsp(SSqlObj *pSql) { - UNUSED(pSql); - return TSDB_CODE_SUCCESS; -} - -int tscProcessShowCreateRsp(SSqlObj *pSql) { - return tscLocalResultCommonBuilder(pSql, 1); -} - -int tscProcessQueryRsp(SSqlObj *pSql) { - SSqlRes *pRes = &pSql->res; - - SQueryTableRsp *pQueryAttr = (SQueryTableRsp *)pRes->pRsp; - pQueryAttr->qId = htobe64(pQueryAttr->qId); - - pRes->qId = pQueryAttr->qId; - pRes->data = NULL; - - tscResetForNextRetrieve(pRes); - tscDebug("0x%"PRIx64" query rsp received, qId:0x%"PRIx64, pSql->self, pRes->qId); - return 0; -} - -static void decompressQueryColData(SSqlObj *pSql, SSqlRes *pRes, SQueryInfo* pQueryInfo, char **data, int8_t compressed, int32_t compLen) { - int32_t decompLen = 0; - int32_t numOfCols = pQueryInfo->fieldsInfo.numOfOutput; - int32_t *compSizes; - char *pData = *data; - compSizes = (int32_t *)(pData + compLen); - - TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, numOfCols - 1); - int16_t offset = tscFieldInfoGetOffset(pQueryInfo, numOfCols - 1); - char *outputBuf = tcalloc(pRes->numOfRows, (pField->bytes + offset)); - - char *p = outputBuf; - int32_t bufOffset; - for (int32_t i = 0; i < numOfCols; ++i) { - SInternalField* pInfo = (SInternalField*)TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.internalField, i); - bufOffset = pInfo->field.bytes * pRes->numOfRows; - - int32_t flen = (*(tDataTypes[pInfo->field.type].decompFunc))(pData, htonl(compSizes[i]), pRes->numOfRows, p, bufOffset, - compressed, NULL, 0); - - p += flen; - decompLen +=flen; - pData += htonl(compSizes[i]); - } - - /* Resize rsp as decompressed data will occupy more space */ - pRes->rspLen = pRes->rspLen - (compLen + numOfCols * sizeof(int32_t)) + decompLen; - char *new_rsp = (char *)realloc(pRes->pRsp, pRes->rspLen); - if (new_rsp == NULL) { - pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - return; - } else { - pRes->pRsp = new_rsp; - *data = ((SRetrieveTableRsp *)pRes->pRsp)->data; - pData = *data + compLen + numOfCols * sizeof(int32_t); - } - - tscDebug("0x%"PRIx64" decompress col data, compressed size:%d, decompressed size:%d", - pSql->self, (int32_t)(compLen + numOfCols * sizeof(int32_t)), decompLen); - - int32_t tailLen = pRes->rspLen - sizeof(SRetrieveTableRsp) - decompLen; - memmove(*data + decompLen, pData, tailLen); - memmove(*data, outputBuf, decompLen); - - tfree(outputBuf); -} - -int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { - SSqlRes *pRes = &pSql->res; - SSqlCmd *pCmd = &pSql->cmd; - - assert(pRes->rspLen >= sizeof(SRetrieveTableRsp)); - - SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *)pRes->pRsp; - if (pRetrieve == NULL) { - pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - return pRes->code; - } - - pRes->numOfRows = htonl(pRetrieve->numOfRows); - pRes->precision = htons(pRetrieve->precision); - pRes->offset = htobe64(pRetrieve->offset); - pRes->useconds = htobe64(pRetrieve->useconds); - pRes->completed = (pRetrieve->completed == 1); - pRes->data = pRetrieve->data; - - SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); - if (tscCreateResPointerInfo(pRes, pQueryInfo) != TSDB_CODE_SUCCESS) { - return pRes->code; - } - - //Decompress col data if compressed from server - if (pRetrieve->compressed) { - int32_t compLen = htonl(pRetrieve->compLen); - decompressQueryColData(pSql, pRes, pQueryInfo, &pRes->data, pRetrieve->compressed, compLen); - } - - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - if ((pCmd->command == TSDB_SQL_RETRIEVE_MNODE) || - ((UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo) || UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) && - !TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_SUBQUERY)) || - (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && - !TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY) && - !TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE))) { - tscSetResRawPtr(pRes, pQueryInfo); - } - - if (pSql->pSubscription != NULL) { - int32_t numOfCols = pQueryInfo->fieldsInfo.numOfOutput; - - TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, numOfCols - 1); - int16_t offset = tscFieldInfoGetOffset(pQueryInfo, numOfCols - 1); - - char* p = pRes->data + (pField->bytes + offset) * pRes->numOfRows; - - int32_t numOfTables = htonl(*(int32_t*)p); - p += sizeof(int32_t); - for (int i = 0; i < numOfTables; i++) { - int64_t uid = htobe64(*(int64_t*)p); - p += sizeof(int64_t); - p += sizeof(int32_t); // skip tid - TSKEY key = htobe64(*(TSKEY*)p); - p += sizeof(TSKEY); - tscUpdateSubscriptionProgress(pSql->pSubscription, uid, key); - } - } - - pRes->row = 0; - tscDebug("0x%"PRIx64" numOfRows:%d, offset:%" PRId64 ", complete:%d, qId:0x%"PRIx64, pSql->self, pRes->numOfRows, pRes->offset, - pRes->completed, pRes->qId); - - return 0; -} - -void tscTableMetaCallBack(void *param, TAOS_RES *res, int code); - -static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool autocreate) { - SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); - if (NULL == pNew) { - tscError("0x%"PRIx64" malloc failed for new sqlobj to get table meta", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - pNew->pTscObj = pSql->pTscObj; - pNew->signature = pNew; - pNew->cmd.command = TSDB_SQL_META; - - tscAddQueryInfo(&pNew->cmd); - - SQueryInfo *pNewQueryInfo = tscGetQueryInfoS(&pNew->cmd); - if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE + pSql->cmd.payloadLen)) { - tscError("0x%"PRIx64" malloc failed for payload to get table meta", pSql->self); - - tscFreeSqlObj(pNew); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - STableMetaInfo *pNewTableMetaInfo = tscAddEmptyMetaInfo(pNewQueryInfo); - assert(pNewQueryInfo->numOfTables == 1); - - tNameAssign(&pNewTableMetaInfo->name, &pTableMetaInfo->name); - - registerSqlObj(pNew); - - pNew->fp = tscTableMetaCallBack; - pNew->param = (void *)pSql->self; - - tscDebug("0x%"PRIx64" new pSqlObj:0x%"PRIx64" to get tableMeta, auto create:%d, metaRid from %"PRId64" to %"PRId64, - pSql->self, pNew->self, autocreate, pSql->metaRid, pNew->self); - pSql->metaRid = pNew->self; - - { - STableInfoMsg *pInfoMsg = (STableInfoMsg *)pNew->cmd.payload; - int32_t code = tNameExtractFullName(&pNewTableMetaInfo->name, pInfoMsg->tableFname); - if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - pInfoMsg->createFlag = htons(autocreate? 1 : 0); - char *pMsg = (char *)pInfoMsg + sizeof(STableInfoMsg); - - // tag data exists - if (autocreate && pSql->cmd.insertParam.tagData.dataLen != 0) { - pMsg = serializeTagData(&pSql->cmd.insertParam.tagData, pMsg); - } - - pNew->cmd.payloadLen = (int32_t)(pMsg - (char*)pInfoMsg); - pNew->cmd.msgType = TSDB_MSG_TYPE_TABLE_META; - } - - int32_t code = tscBuildAndSendRequest(pNew, NULL); - if (code == TSDB_CODE_SUCCESS) { - code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; // notify application that current process needs to be terminated - } - - return code; -} - -int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVgroupNameList, SArray* pUdfList, __async_cb_func_t fp, bool metaClone) { - SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); - if (NULL == pNew) { - tscError("0x%"PRIx64" failed to allocate sqlobj to get multiple table meta", pSql->self); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - pNew->pTscObj = pSql->pTscObj; - pNew->signature = pNew; - pNew->cmd.command = TSDB_SQL_MULTI_META; - - int32_t numOfTable = (int32_t) taosArrayGetSize(pNameList); - int32_t numOfVgroupList = (int32_t) taosArrayGetSize(pVgroupNameList); - int32_t numOfUdf = pUdfList ? (int32_t)taosArrayGetSize(pUdfList) : 0; - - int32_t size = (numOfTable + numOfVgroupList) * TSDB_TABLE_FNAME_LEN + TSDB_FUNC_NAME_LEN * numOfUdf + sizeof(SMultiTableInfoMsg); - if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, size)) { - tscError("0x%"PRIx64" malloc failed for payload to get table meta", pSql->self); - tscFreeSqlObj(pNew); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SMultiTableInfoMsg* pInfo = (SMultiTableInfoMsg*) pNew->cmd.payload; - pInfo->metaClone = metaClone? 1:0; - pInfo->numOfTables = htonl((uint32_t) taosArrayGetSize(pNameList)); - pInfo->numOfVgroups = htonl((uint32_t) taosArrayGetSize(pVgroupNameList)); - pInfo->numOfUdfs = htonl(numOfUdf); - - char* start = pInfo->tableNames; - int32_t len = 0; - for(int32_t i = 0; i < numOfTable; ++i) { - char* name = taosArrayGetP(pNameList, i); - if (i < numOfTable - 1 || numOfVgroupList > 0 || numOfUdf > 0) { - len = sprintf(start, "%s,", name); - } else { - len = sprintf(start, "%s", name); - } - - start += len; - } - - for(int32_t i = 0; i < numOfVgroupList; ++i) { - char* name = taosArrayGetP(pVgroupNameList, i); - if (i < numOfVgroupList - 1 || numOfUdf > 0) { - len = sprintf(start, "%s,", name); - } else { - len = sprintf(start, "%s", name); - } - - start += len; - } - - for(int32_t i = 0; i < numOfUdf; ++i) { - SUdfInfo * u = taosArrayGet(pUdfList, i); - if (i < numOfUdf - 1) { - len = sprintf(start, "%s,", u->name); - } else { - len = sprintf(start, "%s", u->name); - } - - start += len; - } - - pNew->cmd.payloadLen = (int32_t) ((start - pInfo->tableNames) + sizeof(SMultiTableInfoMsg)); - pNew->cmd.msgType = TSDB_MSG_TYPE_TABLES_META; - - registerSqlObj(pNew); - tscDebug("0x%"PRIx64" new pSqlObj:0x%"PRIx64" to get %d tableMeta, vgroupInfo:%d, udf:%d, msg size:%d", pSql->self, - pNew->self, numOfTable, numOfVgroupList, numOfUdf, pNew->cmd.payloadLen); - - pNew->fp = fp; - pNew->param = (void *)pSql->self; - - tscDebug("0x%"PRIx64" metaRid from 0x%" PRIx64 " to 0x%" PRIx64 , pSql->self, pSql->metaRid, pNew->self); - - pSql->metaRid = pNew->self; - int32_t code = tscBuildAndSendRequest(pNew, NULL); - if (code == TSDB_CODE_SUCCESS) { - code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; // notify application that current process needs to be terminated - } - - return code; -} - -int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) { - assert(tNameIsValid(&pTableMetaInfo->name)); - - char name[TSDB_TABLE_FNAME_LEN] = {0}; - tNameExtractFullName(&pTableMetaInfo->name, name); - - size_t len = strlen(name); - // just make runtime happy - if (pTableMetaInfo->tableMetaCapacity != 0 && pTableMetaInfo->pTableMeta != NULL) { - memset(pTableMetaInfo->pTableMeta, 0, pTableMetaInfo->tableMetaCapacity); - } - - if (NULL == taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&(pTableMetaInfo->pTableMeta), &pTableMetaInfo->tableMetaCapacity)) { - tfree(pTableMetaInfo->pTableMeta); - } - - STableMeta* pMeta = pTableMetaInfo->pTableMeta; - STableMeta* pSTMeta = (STableMeta *)(pSql->pBuf); - - if (pMeta && pMeta->id.uid > 0) { - // in case of child table, here only get the - if (pMeta->tableType == TSDB_CHILD_TABLE) { - int32_t code = tscCreateTableMetaFromSTableMeta(&pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity, (STableMeta **)(&pSTMeta)); - pSql->pBuf = (void *)(pSTMeta); - if (code != TSDB_CODE_SUCCESS) { - return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); - } - } - - tscDebug("0x%"PRIx64 " %s retrieve tableMeta from cache, numOfCols:%d, numOfTags:%d", pSql->self, name, pMeta->tableInfo.numOfColumns, pMeta->tableInfo.numOfTags); - return TSDB_CODE_SUCCESS; - } - - if (onlyLocal) { - return TSDB_CODE_TSC_NO_META_CACHED; - } - - return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); -} - -int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { - return tscGetTableMetaImpl(pSql, pTableMetaInfo, false, false); -} - -int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists, bool onlyLocal) { - return tscGetTableMetaImpl(pSql, pTableMetaInfo, createIfNotExists, onlyLocal); -} - -int32_t tscGetUdfFromNode(SSqlObj *pSql, SQueryInfo* pQueryInfo) { - SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); - if (NULL == pNew) { - tscError("%p malloc failed for new sqlobj to get user-defined functions", pSql); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - pNew->pTscObj = pSql->pTscObj; - pNew->signature = pNew; - pNew->cmd.command = TSDB_SQL_RETRIEVE_FUNC; - - if (tscAddQueryInfo(&pNew->cmd) != TSDB_CODE_SUCCESS) { - tscError("%p malloc failed for new queryinfo", pSql); - tscFreeSqlObj(pNew); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - SQueryInfo *pNewQueryInfo = tscGetQueryInfo(&pNew->cmd); - - pNewQueryInfo->pUdfInfo = taosArrayInit(4, sizeof(SUdfInfo)); - for(int32_t i = 0; i < taosArrayGetSize(pQueryInfo->pUdfInfo); ++i) { - SUdfInfo info = {0}; - SUdfInfo* p1 = taosArrayGet(pQueryInfo->pUdfInfo, i); - info = *p1; - info.name = strdup(p1->name); - taosArrayPush(pNewQueryInfo->pUdfInfo, &info); - } - - pNew->cmd.active = pNewQueryInfo; - - if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE + pSql->cmd.payloadLen)) { - tscError("%p malloc failed for payload to get table meta", pSql); - tscFreeSqlObj(pNew); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - tscDebug("%p new pSqlObj:%p to retrieve udf", pSql, pNew); - registerSqlObj(pNew); - - pNew->fp = tscTableMetaCallBack; - pNew->param = (void *)pSql->self; - - tscDebug("%p metaRid from %" PRId64 " to %" PRId64 , pSql, pSql->metaRid, pNew->self); - - pSql->metaRid = pNew->self; - - int32_t code = tscBuildAndSendRequest(pNew, NULL); - if (code == TSDB_CODE_SUCCESS) { - code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; // notify application that current process needs to be terminated - } - - return code; -} - -static bool allVgroupInfoRetrieved(SQueryInfo* pQueryInfo) { - for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); - if (pTableMetaInfo->vgroupList == NULL) { - return false; - } - } - - // all super tables vgroupinfo are retrieved, no need to retrieve vgroup info anymore - return true; -} - -#endif +int (*handleRequestRspFp[TSDB_MSG_TYPE_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen); int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { pMsgBody->msgType = TSDB_MSG_TYPE_CONNECT; @@ -2834,15 +66,6 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { pConnect->epSet.port[i] = htons(pConnect->epSet.port[i]); } - // TODO refactor - pthread_mutex_lock(&pTscObj->mutex); - char temp[TSDB_TABLE_FNAME_LEN * 2] = {0}; - int32_t len = sprintf(temp, "%d%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pTscObj->db); - - assert(len <= sizeof(pTscObj->db)); - tstrncpy(pTscObj->db, temp, sizeof(pTscObj->db)); - pthread_mutex_unlock(&pTscObj->mutex); - if (!isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, &pConnect->epSet)) { updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pConnect->epSet); } @@ -2863,40 +86,35 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { return 0; } -int32_t doBuildMsgSupp(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { +static int32_t buildRetrieveMnodeMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { + pMsgBody->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; + pMsgBody->msgInfo.len = sizeof(SRetrieveTableMsg); pMsgBody->requestObjRefId = pRequest->self; - pMsgBody->msgInfo = pRequest->body.requestMsg; - switch(pRequest->type) { - case TSDB_SQL_CREATE_USER: - pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_USER; - break; - case TSDB_SQL_DROP_USER: - pMsgBody->msgType = TSDB_MSG_TYPE_DROP_USER; - break; - case TSDB_SQL_CREATE_ACCT: - pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_ACCT; - break; - case TSDB_SQL_DROP_ACCT: - pMsgBody->msgType = TSDB_MSG_TYPE_DROP_ACCT; - break; - case TSDB_SQL_CREATE_DB: { - pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_DB; - - SCreateDbMsg* pCreateMsg = pRequest->body.requestMsg.pMsg; - SName name = {0}; - int32_t ret = tNameSetDbName(&name, pRequest->pTscObj->acctId, pCreateMsg->db, strnlen(pCreateMsg->db, tListLen(pCreateMsg->db))); - if (ret != TSDB_CODE_SUCCESS) { - return -1; - } + SRetrieveTableMsg *pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg)); + if (pRetrieveMsg == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } - tNameGetFullDbName(&name, pCreateMsg->db); + pRetrieveMsg->showId = htonl(pRequest->body.execId); + pMsgBody->msgInfo.pMsg = pRetrieveMsg; + return TSDB_CODE_SUCCESS; +} - break; - } - case TSDB_SQL_SHOW: - pMsgBody->msgType = TSDB_MSG_TYPE_SHOW; - break; +SRequestMsgBody buildRequestMsgImpl(SRequestObj *pRequest) { + if (pRequest->type == TSDB_MSG_TYPE_SHOW_RETRIEVE) { + SRequestMsgBody body = {0}; + buildRetrieveMnodeMsg(pRequest, &body); + return body; + } else { + assert(pRequest != NULL); + SRequestMsgBody body = { + .requestObjRefId = pRequest->self, + .msgInfo = pRequest->body.requestMsg, + .msgType = pRequest->type, + .requestId = pRequest->requestId, + }; + return body; } } @@ -2935,18 +153,6 @@ int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) return 0; } -int buildRetrieveMnodeMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { - pMsgBody->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - pMsgBody->msgInfo.len = sizeof(SRetrieveTableMsg); - pMsgBody->requestObjRefId = pRequest->self; - - SRetrieveTableMsg *pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg)); - pRetrieveMsg->showId = htonl(pRequest->body.execId); - - pMsgBody->msgInfo.pMsg = pRetrieveMsg; - return TSDB_CODE_SUCCESS; -} - int32_t processRetrieveMnodeRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { assert(msgLen >= sizeof(SRetrieveTableRsp)); @@ -2973,6 +179,24 @@ int32_t processCreateDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgL // todo rsp with the vnode id list } +int32_t processUseDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { + SUseDbRsp* pUseDbRsp = (SUseDbRsp*) pMsg; + SName name = {0}; + tNameFromString(&name, pUseDbRsp->db, T_NAME_ACCT|T_NAME_DB); + + char db[TSDB_DB_NAME_LEN] = {0}; + tNameGetDbName(&name, db); + setConnectionDB(pRequest->pTscObj, db); +} + +int32_t processCreateTableRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { + assert(pMsg != NULL); +} + +int32_t processDropDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { + // todo: Remove cache in catalog cache. +} + void initMsgHandleFp() { #if 0 tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg; @@ -3049,21 +273,11 @@ void initMsgHandleFp() { tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp; #endif - buildRequestMsgFp[TSDB_SQL_CONNECT] = buildConnectMsg; - handleRequestRspFp[TSDB_SQL_CONNECT] = processConnectRsp; - - buildRequestMsgFp[TSDB_SQL_CREATE_USER] = doBuildMsgSupp; - buildRequestMsgFp[TSDB_SQL_DROP_USER] = doBuildMsgSupp; - - buildRequestMsgFp[TSDB_SQL_CREATE_ACCT] = doBuildMsgSupp; - buildRequestMsgFp[TSDB_SQL_DROP_ACCT] = doBuildMsgSupp; - - buildRequestMsgFp[TSDB_SQL_SHOW] = doBuildMsgSupp; - handleRequestRspFp[TSDB_SQL_SHOW] = processShowRsp; - - buildRequestMsgFp[TSDB_SQL_RETRIEVE_MNODE] = buildRetrieveMnodeMsg; - handleRequestRspFp[TSDB_SQL_RETRIEVE_MNODE]= processRetrieveMnodeRsp; - - buildRequestMsgFp[TSDB_SQL_CREATE_DB] = doBuildMsgSupp; - handleRequestRspFp[TSDB_SQL_CREATE_DB] = processCreateDbRsp; + handleRequestRspFp[TSDB_MSG_TYPE_CONNECT] = processConnectRsp; + handleRequestRspFp[TSDB_MSG_TYPE_SHOW] = processShowRsp; + handleRequestRspFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = processRetrieveMnodeRsp; + handleRequestRspFp[TSDB_MSG_TYPE_CREATE_DB] = processCreateDbRsp; + handleRequestRspFp[TSDB_MSG_TYPE_USE_DB] = processUseDbRsp; + handleRequestRspFp[TSDB_MSG_TYPE_CREATE_TABLE] = processCreateTableRsp; + handleRequestRspFp[TSDB_MSG_TYPE_DROP_DB] = processDropDbRsp; } \ No newline at end of file diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 1c8cd6a4b6da560f0deec532c008863b6e7eb786..7a1e8ca0c3d19d1dc7913ded540f0454ea639b6a 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -16,7 +16,6 @@ #include #include #include -#include "tglobal.h" #pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wunused-function" @@ -25,8 +24,22 @@ #include "../inc/clientInt.h" #include "taos.h" +#include "tglobal.h" namespace { +void showDB(TAOS* pConn) { + TAOS_RES* pRes = taos_query(pConn, "show databases"); + 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); + } +} } // namespace int main(int argc, char** argv) { @@ -34,92 +47,208 @@ int main(int argc, char** argv) { return RUN_ALL_TESTS(); } -TEST(testCase, driverInit_Test) { - taos_init(); -} +TEST(testCase, driverInit_Test) { taos_init(); } -TEST(testCase, connect_Test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +// TEST(testCase, connect_Test) { +// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +//// assert(pConn != NULL); +// taos_close(pConn); +//} +// +// TEST(testCase, create_user_Test) { +// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); // assert(pConn != NULL); - taos_close(pConn); -} - -TEST(testCase, create_user_Test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +// +// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} +// +// TEST(testCase, create_account_Test) { +// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); // assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} +// +// TEST(testCase, drop_account_Test) { +// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} +// +// TEST(testCase, show_user_Test) { +// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +//// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "show users"); +// 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_close(pConn); +//} +// +// TEST(testCase, drop_user_Test) { +// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "drop user abc"); +// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { +// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} +// +// TEST(testCase, show_db_Test) { +// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +//// assert(pConn != NULL); +// +// TAOS_RES* pRes = taos_query(pConn, "show databases"); +// 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_close(pConn); +//} - TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); - if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); - } - - taos_free_result(pRes); - taos_close(pConn); -} - -TEST(testCase, create_account_Test) { +TEST(testCase, create_db_Test) { TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); assert(pConn != NULL); - TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); - if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + 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); - taos_close(pConn); -} - -TEST(testCase, drop_account_Test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); - assert(pConn != NULL); + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); - TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); - if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); - } + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); - taos_free_result(pRes); taos_close(pConn); } -TEST(testCase, show_user_Test) { +TEST(testCase, use_db_test) { TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); + assert(pConn != NULL); - TAOS_RES* pRes = taos_query(pConn, "show users"); - TAOS_ROW pRow = NULL; + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } TAOS_FIELD* pFields = taos_fetch_fields(pRes); - int32_t numOfFields = taos_num_fields(pRes); + ASSERT_TRUE(pFields == NULL); - 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); - } + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); taos_close(pConn); } -TEST(testCase, drop_user_Test) { +TEST(testCase, drop_db_test) { TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); assert(pConn != NULL); - TAOS_RES* pRes = taos_query(pConn, "drop user abc"); - if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { - printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + showDB(pConn); + + TAOS_RES* pRes = taos_query(pConn, "drop database abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to drop db, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); + + showDB(pConn); taos_close(pConn); } -TEST(testCase, show_db_Test) { - TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); +// TEST(testCase, create_stable_Test) { +// TAOS* pConn = taos_connect("ubuntu", "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("ubuntu", "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 tm0(ts timestamp, k int)"); + // taos_free_result(pRes); + // + // taos_close(pConn); +} - TAOS_RES* pRes = taos_query(pConn, "show databases"); +TEST(testCase, create_ctable_Test) {} + +TEST(testCase, show_stable_Test) { + TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "show stables"); TAOS_ROW pRow = NULL; TAOS_FIELD* pFields = taos_fetch_fields(pRes); @@ -131,20 +260,45 @@ TEST(testCase, show_db_Test) { printf("%s\n", str); } + taos_free_result(pRes); + taos_close(pConn); } -TEST(testCase, create_db_Test) { +TEST(testCase, drop_stable_Test) { TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); assert(pConn != NULL); TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in creating db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); - TAOS_FIELD* pFields = taos_fetch_fields(pRes); - ASSERT_TRUE(pFields == NULL); + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in using db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); - int32_t numOfFields = taos_num_fields(pRes); - ASSERT_EQ(numOfFields, 0); + pRes = taos_query(pConn, "drop stable st1"); + if (taos_errno(pRes) != 0) { + printf("failed to drop stable, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); taos_close(pConn); } + +//TEST(testCase, show_table_Test) { +// TAOS* pConn = taos_connect("ubuntu", "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"); +// taos_free_result(pRes); +// +// taos_close(pConn); +//} diff --git a/source/common/src/tname.c b/source/common/src/tname.c index fa303fe4e923317c276ccc025499593ca3a8b66a..96610164836dfe32d6219cba0f068abccbe3c7b3 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -6,21 +6,6 @@ #define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T) -char* extractDBName(const char* tableId, char* name) { - size_t offset1 = strcspn(tableId, &TS_PATH_DELIMITER[0]); - size_t len = strcspn(&tableId[offset1 + 1], &TS_PATH_DELIMITER[0]); - - return strncpy(name, &tableId[offset1 + 1], len); -} - -// todo remove it -size_t tableIdPrefix(const char* name, char* prefix, int32_t len) { - tstrncpy(prefix, name, len); - strcat(prefix, TS_PATH_DELIMITER); - - return strlen(prefix); -} - bool tscValidateTableNameLength(size_t len) { return len < TSDB_TABLE_NAME_LEN; } @@ -125,7 +110,7 @@ int32_t tNameExtractFullName(const SName* name, char* dst) { return -1; } - int32_t len = snprintf(dst, TSDB_FULL_DB_NAME_LEN, "%s.%s", name->acctId, name->dbname); + int32_t len = snprintf(dst, TSDB_FULL_DB_NAME_LEN, "%d.%s", name->acctId, name->dbname); size_t tnameLen = strlen(name->tname); if (tnameLen > 0) { @@ -141,7 +126,9 @@ int32_t tNameExtractFullName(const SName* name, char* dst) { int32_t tNameLen(const SName* name) { assert(name != NULL); - int32_t len = (int32_t) strlen(name->acctId); + + char tmp[12] = {0}; + int32_t len = sprintf(tmp, "%d", name->acctId); int32_t len1 = (int32_t) strlen(name->dbname); int32_t len2 = (int32_t) strlen(name->tname); @@ -161,10 +148,6 @@ bool tNameIsValid(const SName* name) { return false; } - if (strlen(name->acctId) <= 0) { - return false; - } - if (name->type == TSDB_DB_NAME_T) { return strlen(name->dbname) > 0; } else { @@ -237,13 +220,6 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { return -1; } - int32_t len = (int32_t)(p - str); - - // too long account id or too long db name -// if ((len >= tListLen(dst->acctId)) || (len <= 0)) { -// return -1; -// } -// memcpy (dst->acctId, str, len); dst->acctId = strtoll(str, NULL, 10); } @@ -272,9 +248,8 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { dst->type = TSDB_TABLE_NAME_T; char* start = (char*) ((p == NULL)? str: (p+1)); - int32_t len = (int32_t) strlen(start); - // too long account id or too long db name + int32_t len = (int32_t) strlen(start); if ((len >= tListLen(dst->tname)) || (len <= 0)) { return -1; } diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index 50b1a1cf20fa2db10c401911aff6b8178f374d64..f8556c3e207baf7c6dabdfa0e46420410005331a 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -45,6 +45,10 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_MQ_SET_CUR] = dndProcessVnodeWriteMsg; + pMgmt->msgFp[TSDB_MSG_TYPE_RES_READY] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TSDB_MSG_TYPE_TASKS_STATUS] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TSDB_MSG_TYPE_CANCEL_TASK] = dndProcessVnodeFetchMsg; + pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TASK] = dndProcessVnodeFetchMsg; // msg from client to mnode pMgmt->msgFp[TSDB_MSG_TYPE_CONNECT] = dndProcessMnodeReadMsg; @@ -73,7 +77,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_VGROUP_LIST] = dndProcessMnodeReadMsg; pMgmt->msgFp[TSDB_MSG_TYPE_KILL_QUERY] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TSDB_MSG_TYPE_KILL_STREAM] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_KILL_CONN] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_HEARTBEAT] = dndProcessMnodeReadMsg; pMgmt->msgFp[TSDB_MSG_TYPE_SHOW] = dndProcessMnodeReadMsg; diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index a5ece72f425f8d00bd6d4328350cb48dab186cc5..a29926c8026950028690bf3d07fa224ee1dd5084 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -8,8 +8,8 @@ add_subdirectory(db) add_subdirectory(dnode) # add_subdirectory(func) # add_subdirectory(mnode) -# add_subdirectory(profile) -# add_subdirectory(show) +add_subdirectory(profile) +add_subdirectory(show) add_subdirectory(stb) # add_subdirectory(sync) # add_subdirectory(telem) @@ -17,4 +17,4 @@ add_subdirectory(stb) add_subdirectory(user) add_subdirectory(vgroup) -# add_subdirectory(common) +add_subdirectory(sut) diff --git a/source/dnode/mgmt/impl/test/acct/CMakeLists.txt b/source/dnode/mgmt/impl/test/acct/CMakeLists.txt index 8b160fc446b2f501e8f2ece4e76e1dbc27a77a74..a06becd1279b2f66f73cb3d8fbf347c9e4848e2b 100644 --- a/source/dnode/mgmt/impl/test/acct/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/acct/CMakeLists.txt @@ -1,24 +1,8 @@ -add_executable(dnode_test_acct "") - -target_sources(dnode_test_acct - PRIVATE - "acct.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. ACCT_SRC) +add_executable(dnode_test_acct ${ACCT_SRC}) target_link_libraries( dnode_test_acct - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dnode_test_acct - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + PUBLIC sut ) add_test( diff --git a/source/dnode/mgmt/impl/test/acct/acct.cpp b/source/dnode/mgmt/impl/test/acct/acct.cpp index e2b819da2828dc4f7d4d0a915edf76c1bc29a06c..69ddae675d12e353a610769592565b18d0078ada 100644 --- a/source/dnode/mgmt/impl/test/acct/acct.cpp +++ b/source/dnode/mgmt/impl/test/acct/acct.cpp @@ -9,103 +9,59 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestAcct : public ::testing::Test { protected: - static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - SServer* pServer = createServer(path, fqdn, port, firstEp); - ASSERT(pServer); - return pServer; - } - - static void SetUpTestSuite() { - initLog("/tmp/tdlog"); - - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9012"; - pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9012, firstEp); - pClient = createClient("root", "taosdata", fqdn, 9012); - taosMsleep(300); - } - - static void TearDownTestSuite() { - stopServer(pServer); - dropClient(pClient); - pServer = NULL; - pClient = NULL; - } - - static SServer* pServer; - static SClient* pClient; - static int32_t connId; + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_acct", 9012); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} }; -SServer* DndTestAcct::pServer; -SClient* DndTestAcct::pClient; -int32_t DndTestAcct::connId; +Testbase DndTestAcct::test; TEST_F(DndTestAcct, 01_CreateAcct) { - ASSERT_NE(pClient, nullptr); - - SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(sizeof(SCreateAcctMsg)); + int32_t contLen = sizeof(SCreateAcctMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateAcctMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_ACCT; + SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(contLen); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } TEST_F(DndTestAcct, 02_AlterAcct) { - ASSERT_NE(pClient, nullptr); + int32_t contLen = sizeof(SCreateAcctMsg); - SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(sizeof(SAlterAcctMsg)); + SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(contLen); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SAlterAcctMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_ACCT; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } TEST_F(DndTestAcct, 03_DropAcct) { - ASSERT_NE(pClient, nullptr); - - SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(sizeof(SDropAcctMsg)); + int32_t contLen = sizeof(SDropAcctMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SDropAcctMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_DROP_ACCT; + SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(contLen); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_ACCT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } TEST_F(DndTestAcct, 04_ShowAcct) { - ASSERT_NE(pClient, nullptr); + int32_t contLen = sizeof(SShowMsg); - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); + SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); pReq->type = TSDB_MGMT_TABLE_ACCT; - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SShowMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt b/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt index e97ef7688140bc4d85a7d1a734b21a6b586c1297..a63f3106e6299299adf963427604c7384931f35c 100644 --- a/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt @@ -1,24 +1,8 @@ -add_executable(dnode_test_cluster "") - -target_sources(dnode_test_cluster - PRIVATE - "cluster.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. CLUSTER_SRC) +add_executable(dnode_test_cluster ${CLUSTER_SRC}) target_link_libraries( dnode_test_cluster - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dnode_test_cluster - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + PUBLIC sut ) add_test( diff --git a/source/dnode/mgmt/impl/test/cluster/cluster.cpp b/source/dnode/mgmt/impl/test/cluster/cluster.cpp index 0aca2fde4badaa17b6fa70186ed9ad157c588678..7230c3eb74ca2e0cb08454f1f170b046918c4cc7 100644 --- a/source/dnode/mgmt/impl/test/cluster/cluster.cpp +++ b/source/dnode/mgmt/impl/test/cluster/cluster.cpp @@ -9,162 +9,33 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestCluster : public ::testing::Test { protected: - static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - SServer* pServer = createServer(path, fqdn, port, firstEp); - ASSERT(pServer); - return pServer; - } + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_cluster", 9030); } + static void TearDownTestSuite() { test.Cleanup(); } - static void SetUpTestSuite() { - initLog("/tmp/tdlog"); - - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9030"; - pServer = CreateServer("/tmp/dnode_test_cluster", fqdn, 9030, firstEp); - pClient = createClient("root", "taosdata", fqdn, 9030); - taosMsleep(1100); - } - - static void TearDownTestSuite() { - stopServer(pServer); - dropClient(pClient); - pServer = NULL; - pClient = NULL; - } - - static SServer* pServer; - static SClient* pClient; - static int32_t connId; + static Testbase test; public: void SetUp() override {} void TearDown() override {} - - void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) { - SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pShow->type = showType; - if (db != NULL) { - strcpy(pShow->db, db); - } - SRpcMsg showRpcMsg = {0}; - showRpcMsg.pCont = pShow; - showRpcMsg.contLen = sizeof(SShowMsg); - showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &showRpcMsg); - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont; - ASSERT_NE(pShowRsp, nullptr); - pShowRsp->showId = htonl(pShowRsp->showId); - pMeta = &pShowRsp->tableMeta; - pMeta->numOfTags = htonl(pMeta->numOfTags); - pMeta->numOfColumns = htonl(pMeta->numOfColumns); - pMeta->sversion = htonl(pMeta->sversion); - pMeta->tversion = htonl(pMeta->tversion); - pMeta->tuid = htobe64(pMeta->tuid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pShowRsp->showId; - - EXPECT_NE(pShowRsp->showId, 0); - EXPECT_STREQ(pMeta->tbFname, showName); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->numOfColumns, columns); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->update, 0); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tuid, 0); - EXPECT_EQ(pMeta->suid, 0); - } - - void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { - SSchema* pSchema = &pMeta->pSchema[index]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, type); - EXPECT_EQ(pSchema->bytes, bytes); - EXPECT_STREQ(pSchema->name, name); - } - - void SendThenCheckShowRetrieveMsg(int32_t rows) { - SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pRetrieve->showId = htonl(showId); - pRetrieve->free = 0; - - SRpcMsg retrieveRpcMsg = {0}; - retrieveRpcMsg.pCont = pRetrieve; - retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg); - retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &retrieveRpcMsg); - - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; - ASSERT_NE(pRetrieveRsp, nullptr); - pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); - pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); - pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); - - EXPECT_EQ(pRetrieveRsp->numOfRows, rows); - EXPECT_EQ(pRetrieveRsp->useconds, 0); - // EXPECT_EQ(pRetrieveRsp->completed, completed); - EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRetrieveRsp->compressed, 0); - EXPECT_EQ(pRetrieveRsp->compLen, 0); - - pData = pRetrieveRsp->data; - pos = 0; - } - - void CheckInt32() { - int32_t data = *((int32_t*)(pData + pos)); - pos += sizeof(int32_t); - EXPECT_GT(data, 0); - } - - void CheckTimestamp() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_GT(data, 0); - } - - void CheckBinary(int32_t len) { - pos += sizeof(VarDataLenT); - char* data = (char*)(pData + pos); - pos += len; - } - - int32_t showId; - STableMetaMsg* pMeta; - SRetrieveTableRsp* pRetrieveRsp; - char* pData; - int32_t pos; }; -SServer* DndTestCluster::pServer; -SClient* DndTestCluster::pClient; -int32_t DndTestCluster::connId; +Testbase DndTestCluster::test; TEST_F(DndTestCluster, 01_ShowCluster) { - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, "show cluster", 3, NULL); - CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "id"); - CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name"); - CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, ""); + CHECK_META( "show cluster", 3); + CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); - SendThenCheckShowRetrieveMsg(1); - CheckInt32(); - CheckBinary(TSDB_CLUSTER_ID_LEN); + IgnoreInt32(); + IgnoreBinary(TSDB_CLUSTER_ID_LEN); CheckTimestamp(); } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/db/CMakeLists.txt b/source/dnode/mgmt/impl/test/db/CMakeLists.txt index db96e2bad32eff4e99e6a3c68421608f655f18ec..cb9f1600fc2a76951a5cb81cf94c5d1ef48d5eb1 100644 --- a/source/dnode/mgmt/impl/test/db/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/db/CMakeLists.txt @@ -1,24 +1,8 @@ -add_executable(dnode_test_db "") - -target_sources(dnode_test_db - PRIVATE - "db.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. DB_SRC) +add_executable(dnode_test_db ${DB_SRC}) target_link_libraries( dnode_test_db - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dnode_test_db - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + PUBLIC sut ) add_test( diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 204afa111fdd509aac44937774410a8165905314..378f46aa4defe07fa739b170b3cf04f442d99d60 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -9,199 +9,52 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestDb : public ::testing::Test { protected: - static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - SServer* pServer = createServer(path, fqdn, port, firstEp); - ASSERT(pServer); - return pServer; - } - - static void SetUpTestSuite() { - initLog("/tmp/tdlog"); - - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9040"; - pServer = CreateServer("/tmp/dnode_test_db", fqdn, 9040, firstEp); - pClient = createClient("root", "taosdata", fqdn, 9040); - taosMsleep(1100); - } - - static void TearDownTestSuite() { - stopServer(pServer); - dropClient(pClient); - pServer = NULL; - pClient = NULL; - } + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_db", 9040); } + static void TearDownTestSuite() { test.Cleanup(); } - static SServer* pServer; - static SClient* pClient; - static int32_t connId; + static Testbase test; public: void SetUp() override {} void TearDown() override {} - - void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) { - SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pShow->type = showType; - if (db != NULL) { - strcpy(pShow->db, db); - } - SRpcMsg showRpcMsg = {0}; - showRpcMsg.pCont = pShow; - showRpcMsg.contLen = sizeof(SShowMsg); - showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &showRpcMsg); - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont; - ASSERT_NE(pShowRsp, nullptr); - pShowRsp->showId = htonl(pShowRsp->showId); - pMeta = &pShowRsp->tableMeta; - pMeta->numOfTags = htonl(pMeta->numOfTags); - pMeta->numOfColumns = htonl(pMeta->numOfColumns); - pMeta->sversion = htonl(pMeta->sversion); - pMeta->tversion = htonl(pMeta->tversion); - pMeta->tuid = htobe64(pMeta->tuid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pShowRsp->showId; - - EXPECT_NE(pShowRsp->showId, 0); - EXPECT_STREQ(pMeta->tbFname, showName); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->numOfColumns, columns); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->update, 0); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tuid, 0); - EXPECT_EQ(pMeta->suid, 0); - } - - void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { - SSchema* pSchema = &pMeta->pSchema[index]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, type); - EXPECT_EQ(pSchema->bytes, bytes); - EXPECT_STREQ(pSchema->name, name); - } - - void SendThenCheckShowRetrieveMsg(int32_t rows) { - SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pRetrieve->showId = htonl(showId); - pRetrieve->free = 0; - - SRpcMsg retrieveRpcMsg = {0}; - retrieveRpcMsg.pCont = pRetrieve; - retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg); - retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &retrieveRpcMsg); - - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; - ASSERT_NE(pRetrieveRsp, nullptr); - pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); - pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); - pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); - - EXPECT_EQ(pRetrieveRsp->numOfRows, rows); - EXPECT_EQ(pRetrieveRsp->useconds, 0); - // EXPECT_EQ(pRetrieveRsp->completed, completed); - EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRetrieveRsp->compressed, 0); - EXPECT_EQ(pRetrieveRsp->compLen, 0); - - pData = pRetrieveRsp->data; - pos = 0; - } - - void CheckInt8(int8_t val) { - int8_t data = *((int8_t*)(pData + pos)); - pos += sizeof(int8_t); - EXPECT_EQ(data, val); - } - - void CheckInt16(int16_t val) { - int16_t data = *((int16_t*)(pData + pos)); - pos += sizeof(int16_t); - EXPECT_EQ(data, val); - } - - void CheckInt32(int32_t val) { - int32_t data = *((int32_t*)(pData + pos)); - pos += sizeof(int32_t); - EXPECT_EQ(data, val); - } - - void CheckInt64(int64_t val) { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_EQ(data, val); - } - - void CheckTimestamp() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_GT(data, 0); - } - - void CheckBinary(const char* val, int32_t len) { - pos += sizeof(VarDataLenT); - char* data = (char*)(pData + pos); - pos += len; - EXPECT_STREQ(data, val); - } - - int32_t showId; - STableMetaMsg* pMeta; - SRetrieveTableRsp* pRetrieveRsp; - char* pData; - int32_t pos; }; -SServer* DndTestDb::pServer; -SClient* DndTestDb::pClient; -int32_t DndTestDb::connId; +Testbase DndTestDb::test; TEST_F(DndTestDb, 01_ShowDb) { - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL); - CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name"); - CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups"); - CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica"); - CheckSchema(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum"); - CheckSchema(5, TSDB_DATA_TYPE_SMALLINT, 2, "days"); - CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2"); - CheckSchema(7, TSDB_DATA_TYPE_INT, 4, "cache"); - CheckSchema(8, TSDB_DATA_TYPE_INT, 4, "blocks"); - CheckSchema(9, TSDB_DATA_TYPE_INT, 4, "minrows"); - CheckSchema(10, TSDB_DATA_TYPE_INT, 4, "maxrows"); - CheckSchema(11, TSDB_DATA_TYPE_TINYINT, 1, "wallevel"); - CheckSchema(12, TSDB_DATA_TYPE_INT, 4, "fsync"); - CheckSchema(13, TSDB_DATA_TYPE_TINYINT, 1, "comp"); - CheckSchema(14, TSDB_DATA_TYPE_TINYINT, 1, "cachelast"); - CheckSchema(15, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); - CheckSchema(16, TSDB_DATA_TYPE_TINYINT, 1, "update"); - - SendThenCheckShowRetrieveMsg(0); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + CHECK_META("show databases", 17); + CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica"); + CHECK_SCHEMA(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum"); + CHECK_SCHEMA(5, TSDB_DATA_TYPE_SMALLINT, 2, "days"); + CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2"); + CHECK_SCHEMA(7, TSDB_DATA_TYPE_INT, 4, "cache"); + CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "blocks"); + CHECK_SCHEMA(9, TSDB_DATA_TYPE_INT, 4, "minrows"); + CHECK_SCHEMA(10, TSDB_DATA_TYPE_INT, 4, "maxrows"); + CHECK_SCHEMA(11, TSDB_DATA_TYPE_TINYINT, 1, "wallevel"); + CHECK_SCHEMA(12, TSDB_DATA_TYPE_INT, 4, "fsync"); + CHECK_SCHEMA(13, TSDB_DATA_TYPE_TINYINT, 1, "comp"); + CHECK_SCHEMA(14, TSDB_DATA_TYPE_TINYINT, 1, "cachelast"); + CHECK_SCHEMA(15, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); + CHECK_SCHEMA(16, TSDB_DATA_TYPE_TINYINT, 1, "update"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); } TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { { - SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg)); + int32_t contLen = sizeof(SCreateDbMsg); + + SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d1"); pReq->numOfVgroups = htonl(2); pReq->cacheBlockSize = htonl(16); @@ -223,20 +76,16 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateDbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); - // taosMsleep(1000000); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL); - SendThenCheckShowRetrieveMsg(1); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + CHECK_META("show databases", 17); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups @@ -255,12 +104,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("ms", 3); // precision CheckInt8(0); // update - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_VGROUP, "show vgroups", 4, "1.d1"); - CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "vgId"); - CheckSchema(1, TSDB_DATA_TYPE_INT, 4, "tables"); - CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode"); - CheckSchema(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status"); - SendThenCheckShowRetrieveMsg(2); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_VGROUP, "1.d1"); + CHECK_META("show vgroups", 4); + CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "vgId"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "tables"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); CheckInt32(1); CheckInt32(2); CheckInt32(0); @@ -271,7 +123,9 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("master", 9); { - SAlterDbMsg* pReq = (SAlterDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg)); + int32_t contLen = sizeof(SAlterDbMsg); + + SAlterDbMsg* pReq = (SAlterDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d1"); pReq->totalBlocks = htonl(12); pReq->daysToKeep0 = htonl(300); @@ -282,19 +136,14 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->quorum = 2; pReq->cacheLastRow = 1; - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SAlterDbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_DB; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL); - SendThenCheckShowRetrieveMsg(1); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups @@ -314,19 +163,14 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckInt8(0); // update // restart - stopServer(pServer); - pServer = NULL; - - uInfo("start all server"); + test.Restart(); - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9040"; - pServer = startServer("/tmp/dnode_test_db", fqdn, 9040, firstEp); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + CHECK_META("show databases", 17); - uInfo("all server is running"); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL); - SendThenCheckShowRetrieveMsg(1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); CheckInt16(2); // vgroups @@ -346,27 +190,28 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckInt8(0); // update { - SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(sizeof(SDropDbMsg)); - strcpy(pReq->db, "1.d1"); + int32_t contLen = sizeof(SDropDbMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SDropDbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DB; + SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); + strcpy(pReq->db, "1.d1"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL); - SendThenCheckShowRetrieveMsg(0); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + CHECK_META("show databases", 17); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); } TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { { - SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg)); + int32_t contLen = sizeof(SCreateDbMsg); + + SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d2"); pReq->numOfVgroups = htonl(2); pReq->cacheBlockSize = htonl(16); @@ -388,33 +233,26 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateDbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL); - SendThenCheckShowRetrieveMsg(1); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + CHECK_META("show databases", 17); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d2", TSDB_DB_NAME_LEN - 1); { - SUseDbMsg* pReq = (SUseDbMsg*)rpcMallocCont(sizeof(SUseDbMsg)); + int32_t contLen = sizeof(SUseDbMsg); + + SUseDbMsg* pReq = (SUseDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d2"); pReq->vgVersion = htonl(-1); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SUseDbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_USE_DB; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_USE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); diff --git a/source/dnode/mgmt/impl/test/dnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/dnode/CMakeLists.txt index 48b74a4eff8c0e07f115c8cb4cfcd04448413319..5796590865a0b4d5ec3e66b38441ea67465c79df 100644 --- a/source/dnode/mgmt/impl/test/dnode/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/dnode/CMakeLists.txt @@ -1,24 +1,8 @@ -add_executable(dnode_test_dnode "") - -target_sources(dnode_test_dnode - PRIVATE - "dnode.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. DTEST_SRC) +add_executable(dnode_test_dnode ${DTEST_SRC}) target_link_libraries( dnode_test_dnode - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dnode_test_dnode - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + PUBLIC sut ) add_test( diff --git a/source/dnode/mgmt/impl/test/dnode/dnode.cpp b/source/dnode/mgmt/impl/test/dnode/dnode.cpp index 1fa91f26cb6edb13aa9588ef26d0f4136d0621c9..c9708ec1cfcb8fdec5ddf10cd63918100187c010 100644 --- a/source/dnode/mgmt/impl/test/dnode/dnode.cpp +++ b/source/dnode/mgmt/impl/test/dnode/dnode.cpp @@ -9,189 +9,62 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestDnode : public ::testing::Test { public: - static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - SServer* pServer = createServer(path, fqdn, port, firstEp); - ASSERT(pServer); - return pServer; - } + void SetUp() override {} + void TearDown() override {} + public: static void SetUpTestSuite() { - initLog("/tmp/tdlog"); - + test.Init("/tmp/dnode_test_dnode1", 9041); const char* fqdn = "localhost"; const char* firstEp = "localhost:9041"; - pServer1 = CreateServer("/tmp/dnode_test_dnode1", fqdn, 9041, firstEp); - pServer2 = CreateServer("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp); - pServer3 = CreateServer("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp); - pServer4 = CreateServer("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp); - pServer5 = CreateServer("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp); - pClient = createClient("root", "taosdata", fqdn, 9041); + + server2.Start("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp); + server3.Start("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp); + server4.Start("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp); + server5.Start("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp); taosMsleep(300); } static void TearDownTestSuite() { - stopServer(pServer1); - stopServer(pServer2); - stopServer(pServer3); - stopServer(pServer4); - stopServer(pServer5); - dropClient(pClient); - pServer1 = NULL; - pServer2 = NULL; - pServer3 = NULL; - pServer4 = NULL; - pServer5 = NULL; - pClient = NULL; - } - - static SServer* pServer1; - static SServer* pServer2; - static SServer* pServer3; - static SServer* pServer4; - static SServer* pServer5; - static SClient* pClient; - - public: - void SetUp() override {} - void TearDown() override {} - - void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) { - SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pShow->type = showType; - strcpy(pShow->db, ""); - - SRpcMsg showRpcMsg = {0}; - showRpcMsg.pCont = pShow; - showRpcMsg.contLen = sizeof(SShowMsg); - showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &showRpcMsg); - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont; - ASSERT_NE(pShowRsp, nullptr); - pShowRsp->showId = htonl(pShowRsp->showId); - pMeta = &pShowRsp->tableMeta; - pMeta->numOfTags = htonl(pMeta->numOfTags); - pMeta->numOfColumns = htonl(pMeta->numOfColumns); - pMeta->sversion = htonl(pMeta->sversion); - pMeta->tversion = htonl(pMeta->tversion); - pMeta->tuid = htobe64(pMeta->tuid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pShowRsp->showId; - - EXPECT_NE(pShowRsp->showId, 0); - EXPECT_STREQ(pMeta->tbFname, showName); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->numOfColumns, columns); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->update, 0); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tuid, 0); - EXPECT_EQ(pMeta->suid, 0); - } - - void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { - SSchema* pSchema = &pMeta->pSchema[index]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, type); - EXPECT_EQ(pSchema->bytes, bytes); - EXPECT_STREQ(pSchema->name, name); - } - - void SendThenCheckShowRetrieveMsg(int32_t rows) { - SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pRetrieve->showId = htonl(showId); - pRetrieve->free = 0; - - SRpcMsg retrieveRpcMsg = {0}; - retrieveRpcMsg.pCont = pRetrieve; - retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg); - retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &retrieveRpcMsg); - - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; - ASSERT_NE(pRetrieveRsp, nullptr); - pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); - pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); - pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); - - EXPECT_EQ(pRetrieveRsp->numOfRows, rows); - EXPECT_EQ(pRetrieveRsp->useconds, 0); - // EXPECT_EQ(pRetrieveRsp->completed, completed); - EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRetrieveRsp->compressed, 0); - EXPECT_EQ(pRetrieveRsp->compLen, 0); - - pData = pRetrieveRsp->data; - pos = 0; + server2.Stop(); + server3.Stop(); + server4.Stop(); + server5.Stop(); + test.Cleanup(); } - void CheckInt16(int16_t val) { - int16_t data = *((int16_t*)(pData + pos)); - pos += sizeof(int16_t); - EXPECT_EQ(data, val); - } - - void CheckInt64(int64_t val) { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_EQ(data, val); - } + static Testbase test; + static TestServer server2; + static TestServer server3; + static TestServer server4; + static TestServer server5; +}; - void CheckTimestamp() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_GT(data, 0); - } +Testbase DndTestDnode::test; +TestServer DndTestDnode::server2; +TestServer DndTestDnode::server3; +TestServer DndTestDnode::server4; +TestServer DndTestDnode::server5; - void CheckBinary(const char* val, int32_t len) { - pos += sizeof(VarDataLenT); - char* data = (char*)(pData + pos); - pos += len; - EXPECT_STREQ(data, val); - } +TEST_F(DndTestDnode, 01_ShowDnode) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + CHECK_META("show dnodes", 7); - int32_t showId; - STableMetaMsg* pMeta; - SRetrieveTableRsp* pRetrieveRsp; - char* pData; - int32_t pos; -}; + CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes"); + CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status"); + CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason"); -SServer* DndTestDnode::pServer1; -SServer* DndTestDnode::pServer2; -SServer* DndTestDnode::pServer3; -SServer* DndTestDnode::pServer4; -SServer* DndTestDnode::pServer5; -SClient* DndTestDnode::pClient; + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); -TEST_F(DndTestDnode, 01_ShowDnode) { - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); - CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes"); - CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes"); - CheckSchema(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status"); - CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason"); - - SendThenCheckShowRetrieveMsg(1); CheckInt16(1); CheckBinary("localhost:9041", TSDB_EP_LEN); CheckInt16(0); @@ -202,40 +75,36 @@ TEST_F(DndTestDnode, 01_ShowDnode) { } TEST_F(DndTestDnode, 02_ConfigDnode) { - SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(sizeof(SCfgDnodeMsg)); + int32_t contLen = sizeof(SCfgDnodeMsg); + + SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); strcpy(pReq->config, "ddebugflag 131"); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCfgDnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CONFIG_DNODE; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONFIG_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { { - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg)); - strcpy(pReq->ep, "localhost:9042"); + int32_t contLen = sizeof(SCreateDnodeMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateDnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE; + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->ep, "localhost:9042"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } taosMsleep(1300); - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); - SendThenCheckShowRetrieveMsg(2); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + CHECK_META("show dnodes", 7); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + CheckInt16(1); CheckInt16(2); CheckBinary("localhost:9041", TSDB_EP_LEN); @@ -252,22 +121,21 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { CheckBinary("", 24); { - SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(sizeof(SDropDnodeMsg)); - pReq->dnodeId = htonl(2); + int32_t contLen = sizeof(SDropDnodeMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SDropDnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DNODE; + SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); - SendThenCheckShowRetrieveMsg(1); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + CHECK_META("show dnodes", 7); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + CheckInt16(1); CheckBinary("localhost:9041", TSDB_EP_LEN); CheckInt16(0); @@ -277,53 +145,44 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { CheckBinary("", 24); { - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg)); - strcpy(pReq->ep, "localhost:9043"); + int32_t contLen = sizeof(SCreateDnodeMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateDnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE; + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->ep, "localhost:9043"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } { - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg)); - strcpy(pReq->ep, "localhost:9044"); + int32_t contLen = sizeof(SCreateDnodeMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateDnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE; + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->ep, "localhost:9044"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } { - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg)); - strcpy(pReq->ep, "localhost:9045"); + int32_t contLen = sizeof(SCreateDnodeMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateDnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE; + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->ep, "localhost:9045"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } taosMsleep(1300); - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); - SendThenCheckShowRetrieveMsg(4); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + CHECK_META("show dnodes", 7); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 4); + CheckInt16(1); CheckInt16(3); CheckInt16(4); @@ -355,31 +214,18 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { // restart uInfo("stop all server"); - stopServer(pServer1); - stopServer(pServer2); - stopServer(pServer3); - stopServer(pServer4); - stopServer(pServer5); - pServer1 = NULL; - pServer2 = NULL; - pServer3 = NULL; - pServer4 = NULL; - pServer5 = NULL; - - uInfo("start all server"); - - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9041"; - pServer1 = startServer("/tmp/dnode_test_dnode1", fqdn, 9041, firstEp); - pServer3 = startServer("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp); - pServer4 = startServer("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp); - pServer5 = startServer("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp); - - uInfo("all server is running"); + test.Restart(); + server2.Restart(); + server3.Restart(); + server4.Restart(); + server5.Restart(); taosMsleep(1300); - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); - SendThenCheckShowRetrieveMsg(4); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + CHECK_META("show dnodes", 7); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 4); + CheckInt16(1); CheckInt16(3); CheckInt16(4); diff --git a/source/dnode/mgmt/impl/test/profile/CMakeLists.txt b/source/dnode/mgmt/impl/test/profile/CMakeLists.txt index d8e4eae0426037ecf20a7888a18360ccdd023391..0edd63172034b364e448f5164a4334d1a06f34d4 100644 --- a/source/dnode/mgmt/impl/test/profile/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/profile/CMakeLists.txt @@ -1,27 +1,11 @@ -add_executable(dndTestProfile "") - -target_sources(dndTestProfile - PRIVATE - "profile.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. PROFILE_SRC) +add_executable(dnode_test_profile ${PROFILE_SRC}) target_link_libraries( - dndTestProfile - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dndTestProfile - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + dnode_test_profile + PUBLIC sut ) add_test( - NAME dndTestProfile - COMMAND dndTestProfile + NAME dnode_test_profile + COMMAND dnode_test_profile ) diff --git a/source/dnode/mgmt/impl/test/profile/profile.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp index f1e4704777b1794ce8ff3bc183eeb34551b3db53..2e82d4d1aa6d1c5007ef7453cb4fe956118823c5 100644 --- a/source/dnode/mgmt/impl/test/profile/profile.cpp +++ b/source/dnode/mgmt/impl/test/profile/profile.cpp @@ -9,55 +9,35 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestProfile : public ::testing::Test { protected: - void SetUp() override {} - void TearDown() override {} + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_profile", 9080); } + static void TearDownTestSuite() { test.Cleanup(); } - static void SetUpTestSuite() { - const char* user = "root"; - const char* pass = "taosdata"; - const char* path = "/tmp/dndTestProfile"; - const char* fqdn = "localhost"; - uint16_t port = 9522; + static Testbase test; - pServer = createServer(path, fqdn, port); - ASSERT(pServer); - pClient = createClient(user, pass, fqdn, port); - } - - static void TearDownTestSuite() { - stopServer(pServer); - dropClient(pClient); - } + public: + void SetUp() override {} + void TearDown() override {} - static SServer* pServer; - static SClient* pClient; - static int32_t connId; + int32_t connId; }; -SServer* DndTestProfile::pServer; -SClient* DndTestProfile::pClient; -int32_t DndTestProfile::connId; +Testbase DndTestProfile::test; -TEST_F(DndTestProfile, SConnectMsg_01) { - ASSERT_NE(pClient, nullptr); +TEST_F(DndTestProfile, 01_ConnectMsg) { + int32_t contLen = sizeof(SConnectMsg); - SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg)); + SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen); pReq->pid = htonl(1234); - strcpy(pReq->app, "dndTestProfile"); + strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SConnectMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont; ASSERT_NE(pRsp, nullptr); @@ -69,183 +49,65 @@ TEST_F(DndTestProfile, SConnectMsg_01) { EXPECT_EQ(pRsp->acctId, 1); EXPECT_GT(pRsp->clusterId, 0); EXPECT_EQ(pRsp->connId, 1); - EXPECT_EQ(pRsp->superAuth, 1); - EXPECT_EQ(pRsp->readAuth, 1); - EXPECT_EQ(pRsp->writeAuth, 1); + EXPECT_EQ(pRsp->superUser, 1); EXPECT_EQ(pRsp->epSet.inUse, 0); EXPECT_EQ(pRsp->epSet.numOfEps, 1); - EXPECT_EQ(pRsp->epSet.port[0], 9522); + EXPECT_EQ(pRsp->epSet.port[0], 9080); EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost"); connId = pRsp->connId; } -TEST_F(DndTestProfile, SConnectMsg_02) { - ASSERT_NE(pClient, nullptr); +TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) { + int32_t contLen = sizeof(SConnectMsg); - SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg)); + SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen); pReq->pid = htonl(1234); - strcpy(pReq->app, "dndTestProfile"); + strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, "invalid_db"); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SConnectMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB); ASSERT_EQ(pMsg->contLen, 0); } -TEST_F(DndTestProfile, SConnectMsg_03) { - ASSERT_NE(pClient, nullptr); - int32_t showId = 0; - - { - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pReq->type = TSDB_MGMT_TABLE_CONNS; - strcpy(pReq->db, ""); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SShowMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - - SShowRsp* pRsp = (SShowRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->showId = htonl(pRsp->showId); - STableMetaMsg* pMeta = &pRsp->tableMeta; - pMeta->contLen = htonl(pMeta->contLen); - pMeta->numOfColumns = htons(pMeta->numOfColumns); - pMeta->sversion = htons(pMeta->sversion); - pMeta->tversion = htons(pMeta->tversion); - pMeta->tid = htonl(pMeta->tid); - pMeta->uid = htobe64(pMeta->uid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pRsp->showId; - - EXPECT_NE(pRsp->showId, 0); - EXPECT_EQ(pMeta->contLen, 0); - EXPECT_STREQ(pMeta->tbFname, ""); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->numOfColumns, 7); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tid, 0); - EXPECT_EQ(pMeta->uid, 0); - EXPECT_STREQ(pMeta->sTableName, ""); - EXPECT_EQ(pMeta->suid, 0); - - SSchema* pSchema = NULL; - pSchema = &pMeta->pSchema[0]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); - EXPECT_EQ(pSchema->bytes, 4); - EXPECT_STREQ(pSchema->name, "connId"); - - pSchema = &pMeta->pSchema[1]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "user"); - - pSchema = &pMeta->pSchema[2]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "program"); - - pSchema = &pMeta->pSchema[3]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); - EXPECT_EQ(pSchema->bytes, 4); - EXPECT_STREQ(pSchema->name, "pid"); - - pSchema = &pMeta->pSchema[4]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "ip:port"); - - pSchema = &pMeta->pSchema[5]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP); - EXPECT_EQ(pSchema->bytes, 8); - EXPECT_STREQ(pSchema->name, "login_time"); - - pSchema = &pMeta->pSchema[6]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP); - EXPECT_EQ(pSchema->bytes, 8); - EXPECT_STREQ(pSchema->name, "last_access"); - } - - { - SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pReq->showId = htonl(showId); - pReq->free = 0; - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SRetrieveTableMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->compLen = htonl(pRsp->compLen); - - EXPECT_EQ(pRsp->numOfRows, 1); - EXPECT_EQ(pRsp->useconds, 0); - EXPECT_EQ(pRsp->completed, 1); - EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRsp->compressed, 0); - EXPECT_EQ(pRsp->compLen, 0); - } +TEST_F(DndTestProfile, 03_ConnectMsg_Show) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, ""); + CHECK_META("show connections", 7); + CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "connId"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, "program"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "pid"); + CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port"); + CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time"); + CHECK_SCHEMA(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); + CheckInt32(1); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("dnode_test_profile", TSDB_APP_NAME_LEN); + CheckInt32(1234); + IgnoreBinary(TSDB_IPv4ADDR_LEN + 6); + CheckTimestamp(); + CheckTimestamp(); } -TEST_F(DndTestProfile, SHeartBeatMsg_01) { - ASSERT_NE(pClient, nullptr); +TEST_F(DndTestProfile, 04_HeartBeatMsg) { + int32_t contLen = sizeof(SHeartBeatMsg); - SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg)); + SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen); pReq->connId = htonl(connId); pReq->pid = htonl(1234); pReq->numOfQueries = htonl(0); pReq->numOfStreams = htonl(0); - strcpy(pReq->app, "dndTestProfile"); + strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SHeartBeatMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont; ASSERT_NE(pRsp, nullptr); @@ -265,62 +127,49 @@ TEST_F(DndTestProfile, SHeartBeatMsg_01) { EXPECT_EQ(pRsp->epSet.inUse, 0); EXPECT_EQ(pRsp->epSet.numOfEps, 1); - EXPECT_EQ(pRsp->epSet.port[0], 9522); + EXPECT_EQ(pRsp->epSet.port[0], 9080); EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost"); } -TEST_F(DndTestProfile, SKillConnMsg_01) { - ASSERT_NE(pClient, nullptr); - +TEST_F(DndTestProfile, 05_KillConnMsg) { { - SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(sizeof(SKillConnMsg)); - pReq->connId = htonl(connId); + int32_t contLen = sizeof(SKillConnMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SKillConnMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_KILL_CONN; + SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); + pReq->connId = htonl(connId); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } { - SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg)); + int32_t contLen = sizeof(SHeartBeatMsg); + + SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen); pReq->connId = htonl(connId); pReq->pid = htonl(1234); pReq->numOfQueries = htonl(0); pReq->numOfStreams = htonl(0); - strcpy(pReq->app, "dndTestProfile"); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SHeartBeatMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT; + strcpy(pReq->app, "dnode_test_profile"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION); ASSERT_EQ(pMsg->contLen, 0); } { - SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg)); + int32_t contLen = sizeof(SConnectMsg); + + SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen); pReq->pid = htonl(1234); - strcpy(pReq->app, "dndTestProfile"); + strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SConnectMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont; ASSERT_NE(pRsp, nullptr); @@ -332,71 +181,55 @@ TEST_F(DndTestProfile, SKillConnMsg_01) { EXPECT_EQ(pRsp->acctId, 1); EXPECT_GT(pRsp->clusterId, 0); EXPECT_GT(pRsp->connId, connId); - EXPECT_EQ(pRsp->readAuth, 1); - EXPECT_EQ(pRsp->writeAuth, 1); + EXPECT_EQ(pRsp->superUser, 1); EXPECT_EQ(pRsp->epSet.inUse, 0); EXPECT_EQ(pRsp->epSet.numOfEps, 1); - EXPECT_EQ(pRsp->epSet.port[0], 9522); + EXPECT_EQ(pRsp->epSet.port[0], 9080); EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost"); connId = pRsp->connId; } } -TEST_F(DndTestProfile, SKillConnMsg_02) { - ASSERT_NE(pClient, nullptr); +TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) { + int32_t contLen = sizeof(SKillConnMsg); - SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(sizeof(SKillConnMsg)); + SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(2345); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SKillConnMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_KILL_CONN; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); } -TEST_F(DndTestProfile, SKillQueryMsg_01) { - ASSERT_NE(pClient, nullptr); - +TEST_F(DndTestProfile, 07_KillQueryMsg) { { - SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(sizeof(SKillQueryMsg)); + int32_t contLen = sizeof(SKillQueryMsg); + + SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(contLen); pReq->connId = htonl(connId); pReq->queryId = htonl(1234); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SKillQueryMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_KILL_QUERY; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->contLen, 0); } { - SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg)); + int32_t contLen = sizeof(SHeartBeatMsg); + + SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen); pReq->connId = htonl(connId); pReq->pid = htonl(1234); pReq->numOfQueries = htonl(0); pReq->numOfStreams = htonl(0); - strcpy(pReq->app, "dndTestProfile"); + strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SHeartBeatMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont; ASSERT_NE(pRsp, nullptr); @@ -416,314 +249,42 @@ TEST_F(DndTestProfile, SKillQueryMsg_01) { EXPECT_EQ(pRsp->epSet.inUse, 0); EXPECT_EQ(pRsp->epSet.numOfEps, 1); - EXPECT_EQ(pRsp->epSet.port[0], 9522); + EXPECT_EQ(pRsp->epSet.port[0], 9080); EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost"); } } -TEST_F(DndTestProfile, SKillQueryMsg_02) { - ASSERT_NE(pClient, nullptr); +TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) { + int32_t contLen = sizeof(SKillQueryMsg); - SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(sizeof(SKillQueryMsg)); + SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(contLen); pReq->connId = htonl(2345); pReq->queryId = htonl(1234); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SKillQueryMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_KILL_QUERY; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); } -TEST_F(DndTestProfile, SKillQueryMsg_03) { - ASSERT_NE(pClient, nullptr); - int32_t showId = 0; - - { - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pReq->type = TSDB_MGMT_TABLE_QUERIES; - strcpy(pReq->db, ""); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SShowMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - - SShowRsp* pRsp = (SShowRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->showId = htonl(pRsp->showId); - STableMetaMsg* pMeta = &pRsp->tableMeta; - pMeta->contLen = htonl(pMeta->contLen); - pMeta->numOfColumns = htons(pMeta->numOfColumns); - pMeta->sversion = htons(pMeta->sversion); - pMeta->tversion = htons(pMeta->tversion); - pMeta->tid = htonl(pMeta->tid); - pMeta->uid = htobe64(pMeta->uid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pRsp->showId; - - EXPECT_NE(pRsp->showId, 0); - EXPECT_EQ(pMeta->contLen, 0); - EXPECT_STREQ(pMeta->tbFname, ""); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->numOfColumns, 14); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tid, 0); - EXPECT_EQ(pMeta->uid, 0); - EXPECT_STREQ(pMeta->sTableName, ""); - EXPECT_EQ(pMeta->suid, 0); - - SSchema* pSchema = NULL; - pSchema = &pMeta->pSchema[0]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); - EXPECT_EQ(pSchema->bytes, 4); - EXPECT_STREQ(pSchema->name, "queryId"); - - pSchema = &pMeta->pSchema[1]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); - EXPECT_EQ(pSchema->bytes, 4); - EXPECT_STREQ(pSchema->name, "connId"); - - pSchema = &pMeta->pSchema[2]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "user"); - - pSchema = &pMeta->pSchema[3]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "ip:port"); - } - - { - SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pReq->showId = htonl(showId); - pReq->free = 0; - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SRetrieveTableMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->offset = htobe64(pRsp->offset); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->compLen = htonl(pRsp->compLen); - - EXPECT_EQ(pRsp->numOfRows, 0); - EXPECT_EQ(pRsp->offset, 0); - EXPECT_EQ(pRsp->useconds, 0); - EXPECT_EQ(pRsp->completed, 1); - EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRsp->compressed, 0); - EXPECT_EQ(pRsp->reserved, 0); - EXPECT_EQ(pRsp->compLen, 0); - } -} - -TEST_F(DndTestProfile, SKillStreamMsg_01) { - ASSERT_NE(pClient, nullptr); - - { - SKillStreamMsg* pReq = (SKillStreamMsg*)rpcMallocCont(sizeof(SKillStreamMsg)); - pReq->connId = htonl(connId); - pReq->streamId = htonl(3579); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SKillStreamMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_KILL_STREAM; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - ASSERT_EQ(pMsg->contLen, 0); - } - - { - SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg)); - pReq->connId = htonl(connId); - pReq->pid = htonl(1234); - pReq->numOfQueries = htonl(0); - pReq->numOfStreams = htonl(0); - strcpy(pReq->app, "dndTestProfile"); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SHeartBeatMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - - SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->connId = htonl(pRsp->connId); - pRsp->queryId = htonl(pRsp->queryId); - pRsp->streamId = htonl(pRsp->streamId); - pRsp->totalDnodes = htonl(pRsp->totalDnodes); - pRsp->onlineDnodes = htonl(pRsp->onlineDnodes); - pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]); - - EXPECT_EQ(pRsp->connId, connId); - EXPECT_EQ(pRsp->queryId, 0); - EXPECT_EQ(pRsp->streamId, 3579); - EXPECT_EQ(pRsp->totalDnodes, 1); - EXPECT_EQ(pRsp->onlineDnodes, 1); - EXPECT_EQ(pRsp->killConnection, 0); - - EXPECT_EQ(pRsp->epSet.inUse, 0); - EXPECT_EQ(pRsp->epSet.numOfEps, 1); - EXPECT_EQ(pRsp->epSet.port[0], 9522); - EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost"); - } -} - -TEST_F(DndTestProfile, SKillStreamMsg_02) { - ASSERT_NE(pClient, nullptr); - - SKillStreamMsg* pReq = (SKillStreamMsg*)rpcMallocCont(sizeof(SKillStreamMsg)); - pReq->connId = htonl(2345); - pReq->streamId = htonl(1234); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SKillStreamMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_KILL_QUERY; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); -} - -TEST_F(DndTestProfile, SKillStreamMsg_03) { - ASSERT_NE(pClient, nullptr); - int32_t showId = 0; - - { - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pReq->type = TSDB_MGMT_TABLE_STREAMS; - strcpy(pReq->db, ""); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SShowMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - - SShowRsp* pRsp = (SShowRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->showId = htonl(pRsp->showId); - STableMetaMsg* pMeta = &pRsp->tableMeta; - pMeta->contLen = htonl(pMeta->contLen); - pMeta->numOfColumns = htons(pMeta->numOfColumns); - pMeta->sversion = htons(pMeta->sversion); - pMeta->tversion = htons(pMeta->tversion); - pMeta->tid = htonl(pMeta->tid); - pMeta->uid = htobe64(pMeta->uid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pRsp->showId; - - EXPECT_NE(pRsp->showId, 0); - EXPECT_EQ(pMeta->contLen, 0); - EXPECT_STREQ(pMeta->tbFname, ""); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->numOfColumns, 10); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tid, 0); - EXPECT_EQ(pMeta->uid, 0); - EXPECT_STREQ(pMeta->sTableName, ""); - EXPECT_EQ(pMeta->suid, 0); - - SSchema* pSchema = NULL; - pSchema = &pMeta->pSchema[0]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); - EXPECT_EQ(pSchema->bytes, 4); - EXPECT_STREQ(pSchema->name, "streamId"); - - pSchema = &pMeta->pSchema[1]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); - EXPECT_EQ(pSchema->bytes, 4); - EXPECT_STREQ(pSchema->name, "connId"); - - pSchema = &pMeta->pSchema[2]; - pSchema->bytes = htons(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "user"); - } - - { - SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pReq->showId = htonl(showId); - pReq->free = 0; - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SRetrieveTableMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->offset = htobe64(pRsp->offset); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->compLen = htonl(pRsp->compLen); - - EXPECT_EQ(pRsp->numOfRows, 0); - EXPECT_EQ(pRsp->offset, 0); - EXPECT_EQ(pRsp->useconds, 0); - EXPECT_EQ(pRsp->completed, 1); - EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRsp->compressed, 0); - EXPECT_EQ(pRsp->reserved, 0); - EXPECT_EQ(pRsp->compLen, 0); - } +TEST_F(DndTestProfile, 09_KillQueryMsg) { + test.SendShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, ""); + CHECK_META("show queries", 14); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "queryId"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "connId"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port"); + CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 22 + VARSTR_HEADER_SIZE, "qid"); + CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "created_time"); + CHECK_SCHEMA(6, TSDB_DATA_TYPE_BIGINT, 8, "time"); + CHECK_SCHEMA(7, TSDB_DATA_TYPE_BINARY, 18 + VARSTR_HEADER_SIZE, "sql_obj_id"); + CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "pid"); + CHECK_SCHEMA(9, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "ep"); + CHECK_SCHEMA(10, TSDB_DATA_TYPE_BOOL, 1, "stable_query"); + CHECK_SCHEMA(11, TSDB_DATA_TYPE_INT, 4, "sub_queries"); + CHECK_SCHEMA(12, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, "sub_query_info"); + CHECK_SCHEMA(13, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, "sql"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); } diff --git a/source/dnode/mgmt/impl/test/show/CMakeLists.txt b/source/dnode/mgmt/impl/test/show/CMakeLists.txt index b3dc3297a8a8926707fc3d409555e0cdefff9c70..9786f65605ca25686b8d88e236d8834ce24274d9 100644 --- a/source/dnode/mgmt/impl/test/show/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/show/CMakeLists.txt @@ -1,24 +1,8 @@ -add_executable(dnode_test_show "") - -target_sources(dnode_test_show - PRIVATE - "show.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. SHOW_SRC) +add_executable(dnode_test_show ${SHOW_SRC}) target_link_libraries( dnode_test_show - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dnode_test_show - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + PUBLIC sut ) add_test( diff --git a/source/dnode/mgmt/impl/test/show/show.cpp b/source/dnode/mgmt/impl/test/show/show.cpp index f0c20f71e572640a190c724bab5cf9cf343dab7f..bec681cb8fed2115f70ebbb147a3c21926060a36 100644 --- a/source/dnode/mgmt/impl/test/show/show.cpp +++ b/source/dnode/mgmt/impl/test/show/show.cpp @@ -9,226 +9,79 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestShow : public ::testing::Test { protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_show", 9091); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: void SetUp() override {} void TearDown() override {} - - static void SetUpTestSuite() { - const char* user = "root"; - const char* pass = "taosdata"; - const char* path = "/tmp/dndTestShow"; - const char* fqdn = "localhost"; - uint16_t port = 9523; - - pServer = createServer(path, fqdn, port); - ASSERT(pServer); - pClient = createClient(user, pass, fqdn, port); - } - - static void TearDownTestSuite() { - stopServer(pServer); - dropClient(pClient); - } - - static SServer* pServer; - static SClient* pClient; - static int32_t connId; }; -SServer* DndTestShow::pServer; -SClient* DndTestShow::pClient; -int32_t DndTestShow::connId; +Testbase DndTestShow::test; -TEST_F(DndTestShow, SShowMsg_01) { - ASSERT_NE(pClient, nullptr); +TEST_F(DndTestShow, 01_ShowMsg_InvalidMsgMax) { + int32_t contLen = sizeof(SShowMsg); - SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg)); - pReq->pid = htonl(1234); - strcpy(pReq->app, "dndTestShow"); + SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); + pReq->type = TSDB_MGMT_TABLE_MAX; strcpy(pReq->db, ""); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SConnectMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); - - SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->connId = htonl(pRsp->connId); - - EXPECT_EQ(pRsp->connId, 1); - connId = pRsp->connId; + ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } -TEST_F(DndTestShow, SShowMsg_02) { - ASSERT_NE(pClient, nullptr); +TEST_F(DndTestShow, 02_ShowMsg_InvalidMsgStart) { + int32_t contLen = sizeof(SShowMsg); SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pReq->type = TSDB_MGMT_TABLE_MAX; + pReq->type = TSDB_MGMT_TABLE_START; strcpy(pReq->db, ""); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SShowMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); } -TEST_F(DndTestShow, SShowMsg_03) { - ASSERT_NE(pClient, nullptr); +TEST_F(DndTestShow, 02_ShowMsg_Conn) { + int32_t contLen = sizeof(SConnectMsg); - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pReq->type = TSDB_MGMT_TABLE_START; + SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen); + pReq->pid = htonl(1234); + strcpy(pReq->app, "dnode_test_show"); strcpy(pReq->db, ""); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SShowMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); -} - -TEST_F(DndTestShow, SShowMsg_04) { - ASSERT_NE(pClient, nullptr); - int32_t showId = 0; - - { - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pReq->type = TSDB_MGMT_TABLE_CONNS; - strcpy(pReq->db, ""); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SShowMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - - SShowRsp* pRsp = (SShowRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->showId = htonl(pRsp->showId); - STableMetaMsg* pMeta = &pRsp->tableMeta; - pMeta->contLen = htonl(pMeta->contLen); - pMeta->numOfColumns = htons(pMeta->numOfColumns); - pMeta->sversion = htons(pMeta->sversion); - pMeta->tversion = htons(pMeta->tversion); - pMeta->tid = htonl(pMeta->tid); - pMeta->uid = htobe64(pMeta->uid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pRsp->showId; - - EXPECT_NE(pRsp->showId, 0); - EXPECT_EQ(pMeta->contLen, 0); - EXPECT_STREQ(pMeta->tbFname, ""); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->numOfColumns, 7); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tid, 0); - EXPECT_EQ(pMeta->uid, 0); - EXPECT_STREQ(pMeta->sTableName, ""); - EXPECT_EQ(pMeta->suid, 0); - - SSchema* pSchema = NULL; - pSchema = &pMeta->pSchema[0]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); - EXPECT_EQ(pSchema->bytes, 4); - EXPECT_STREQ(pSchema->name, "connId"); - - pSchema = &pMeta->pSchema[1]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "user"); - - pSchema = &pMeta->pSchema[2]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "program"); - - pSchema = &pMeta->pSchema[3]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); - EXPECT_EQ(pSchema->bytes, 4); - EXPECT_STREQ(pSchema->name, "pid"); - - pSchema = &pMeta->pSchema[4]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); - EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE); - EXPECT_STREQ(pSchema->name, "ip:port"); - - pSchema = &pMeta->pSchema[5]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP); - EXPECT_EQ(pSchema->bytes, 8); - EXPECT_STREQ(pSchema->name, "login_time"); - - pSchema = &pMeta->pSchema[6]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP); - EXPECT_EQ(pSchema->bytes, 8); - EXPECT_STREQ(pSchema->name, "last_access"); - } - - { - SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pReq->showId = htonl(showId); - pReq->free = 0; - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SRetrieveTableMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont; - ASSERT_NE(pRsp, nullptr); - pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->offset = htobe64(pRsp->offset); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->compLen = htonl(pRsp->compLen); - - EXPECT_EQ(pRsp->numOfRows, 1); - EXPECT_EQ(pRsp->offset, 0); - EXPECT_EQ(pRsp->useconds, 0); - EXPECT_EQ(pRsp->completed, 1); - EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRsp->compressed, 0); - EXPECT_EQ(pRsp->reserved, 0); - EXPECT_EQ(pRsp->compLen, 0); - } + ASSERT_EQ(pMsg->code, 0); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, ""); + + STableMetaMsg* pMeta = test.GetShowMeta(); + EXPECT_STREQ(pMeta->tbFname, "show connections"); + EXPECT_EQ(pMeta->numOfTags, 0); + EXPECT_EQ(pMeta->numOfColumns, 7); + EXPECT_EQ(pMeta->precision, 0); + EXPECT_EQ(pMeta->tableType, 0); + EXPECT_EQ(pMeta->update, 0); + EXPECT_EQ(pMeta->sversion, 0); + EXPECT_EQ(pMeta->tversion, 0); + EXPECT_EQ(pMeta->tuid, 0); + EXPECT_EQ(pMeta->suid, 0); + + test.SendShowRetrieveMsg(); + + SRetrieveTableRsp* pRetrieveRsp = test.GetRetrieveRsp(); + EXPECT_EQ(pRetrieveRsp->numOfRows, 1); + EXPECT_EQ(pRetrieveRsp->useconds, 0); + EXPECT_EQ(pRetrieveRsp->completed, 1); + EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); + EXPECT_EQ(pRetrieveRsp->compressed, 0); + EXPECT_EQ(pRetrieveRsp->compLen, 0); } diff --git a/source/dnode/mgmt/impl/test/stb/CMakeLists.txt b/source/dnode/mgmt/impl/test/stb/CMakeLists.txt index 524e3e5c7ee5fdb65830c7cdcb32e5cfa985606b..68e4dfb07f114e7644638938130445549aa023ec 100644 --- a/source/dnode/mgmt/impl/test/stb/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/stb/CMakeLists.txt @@ -1,24 +1,8 @@ -add_executable(dnode_test_stb "") - -target_sources(dnode_test_stb - PRIVATE - "stb.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. STB_SRC) +add_executable(dnode_test_stb ${STB_SRC}) target_link_libraries( dnode_test_stb - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dnode_test_stb - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + PUBLIC sut ) add_test( diff --git a/source/dnode/mgmt/impl/test/stb/stb.cpp b/source/dnode/mgmt/impl/test/stb/stb.cpp index c12e8eadf45111af660126837fa1157212f8bd57..992ebaf902668c8d646d71969891c9d16831a601 100644 --- a/source/dnode/mgmt/impl/test/stb/stb.cpp +++ b/source/dnode/mgmt/impl/test/stb/stb.cpp @@ -9,176 +9,27 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestStb : public ::testing::Test { protected: - static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - SServer* pServer = createServer(path, fqdn, port, firstEp); - ASSERT(pServer); - return pServer; - } - - static void SetUpTestSuite() { - initLog("/tmp/tdlog"); + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_stb", 9101); } + static void TearDownTestSuite() { test.Cleanup(); } - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9101"; - pServer = CreateServer("/tmp/dnode_test_stb", fqdn, 9101, firstEp); - pClient = createClient("root", "taosdata", fqdn, 9101); - taosMsleep(1100); - } - - static void TearDownTestSuite() { - stopServer(pServer); - dropClient(pClient); - pServer = NULL; - pClient = NULL; - } - - static SServer* pServer; - static SClient* pClient; - static int32_t connId; + static Testbase test; public: void SetUp() override {} void TearDown() override {} - - void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) { - SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pShow->type = showType; - if (db != NULL) { - strcpy(pShow->db, db); - } - SRpcMsg showRpcMsg = {0}; - showRpcMsg.pCont = pShow; - showRpcMsg.contLen = sizeof(SShowMsg); - showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &showRpcMsg); - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont; - ASSERT_NE(pShowRsp, nullptr); - pShowRsp->showId = htonl(pShowRsp->showId); - pMeta = &pShowRsp->tableMeta; - pMeta->numOfTags = htonl(pMeta->numOfTags); - pMeta->numOfColumns = htonl(pMeta->numOfColumns); - pMeta->sversion = htonl(pMeta->sversion); - pMeta->tversion = htonl(pMeta->tversion); - pMeta->tuid = htobe64(pMeta->tuid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pShowRsp->showId; - - EXPECT_NE(pShowRsp->showId, 0); - EXPECT_STREQ(pMeta->tbFname, showName); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->numOfColumns, columns); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->update, 0); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tuid, 0); - EXPECT_EQ(pMeta->suid, 0); - } - - void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { - SSchema* pSchema = &pMeta->pSchema[index]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, type); - EXPECT_EQ(pSchema->bytes, bytes); - EXPECT_STREQ(pSchema->name, name); - } - - void SendThenCheckShowRetrieveMsg(int32_t rows) { - SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pRetrieve->showId = htonl(showId); - pRetrieve->free = 0; - - SRpcMsg retrieveRpcMsg = {0}; - retrieveRpcMsg.pCont = pRetrieve; - retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg); - retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &retrieveRpcMsg); - - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; - ASSERT_NE(pRetrieveRsp, nullptr); - pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); - pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); - pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); - - EXPECT_EQ(pRetrieveRsp->numOfRows, rows); - EXPECT_EQ(pRetrieveRsp->useconds, 0); - // EXPECT_EQ(pRetrieveRsp->completed, completed); - EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRetrieveRsp->compressed, 0); - EXPECT_EQ(pRetrieveRsp->compLen, 0); - - pData = pRetrieveRsp->data; - pos = 0; - } - - void CheckInt8(int8_t val) { - int8_t data = *((int8_t*)(pData + pos)); - pos += sizeof(int8_t); - EXPECT_EQ(data, val); - } - - void CheckInt16(int16_t val) { - int16_t data = *((int16_t*)(pData + pos)); - pos += sizeof(int16_t); - EXPECT_EQ(data, val); - } - - void CheckInt32(int32_t val) { - int32_t data = *((int32_t*)(pData + pos)); - pos += sizeof(int32_t); - EXPECT_EQ(data, val); - } - - void CheckInt64(int64_t val) { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_EQ(data, val); - } - - void CheckTimestamp() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_GT(data, 0); - } - - void CheckBinary(const char* val, int32_t len) { - pos += sizeof(VarDataLenT); - char* data = (char*)(pData + pos); - pos += len; - EXPECT_STREQ(data, val); - } - - int32_t showId; - STableMetaMsg* pMeta; - SRetrieveTableRsp* pRetrieveRsp; - char* pData; - int32_t pos; }; -SServer* DndTestStb::pServer; -SClient* DndTestStb::pClient; -int32_t DndTestStb::connId; +Testbase DndTestStb::test; TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { - SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg)); + int32_t contLen = sizeof(SCreateDbMsg); + + SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d1"); pReq->numOfVgroups = htonl(2); pReq->cacheBlockSize = htonl(16); @@ -200,13 +51,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateDbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -214,9 +59,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { { int32_t cols = 2; int32_t tags = 3; - int32_t size = (tags + cols) * sizeof(SSchema) + sizeof(SCreateStbMsg); + int32_t contLen = (tags + cols) * sizeof(SSchema) + sizeof(SCreateStbMsg); - SCreateStbMsg* pReq = (SCreateStbMsg*)rpcMallocCont(size); + SCreateStbMsg* pReq = (SCreateStbMsg*)rpcMallocCont(contLen); strcpy(pReq->name, "1.d1.stb"); pReq->numOfTags = htonl(tags); pReq->numOfColumns = htonl(cols); @@ -261,24 +106,21 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { strcpy(pSchema->name, "tag3"); } - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = size; - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_STB; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_STB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1"); - CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name"); - CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - CheckSchema(2, TSDB_DATA_TYPE_INT, 4, "columns"); - CheckSchema(3, TSDB_DATA_TYPE_INT, 4, "tags"); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + CHECK_META("show stables", 4); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_INT, 4, "columns"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags"); - SendThenCheckShowRetrieveMsg(1); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("stb", TSDB_TABLE_NAME_LEN); CheckTimestamp(); CheckInt32(2); @@ -286,16 +128,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { // ----- meta ------ { - STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(sizeof(STableInfoMsg)); - strcpy(pReq->tableFname, "1.d1.stb"); + int32_t contLen = sizeof(STableInfoMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(STableInfoMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_TABLE_META; + STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen); + strcpy(pReq->tableFname, "1.d1.stb"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_TABLE_META, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -336,39 +174,31 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { } // restart - stopServer(pServer); - pServer = NULL; + test.Restart(); - uInfo("start all server"); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + CHECK_META("show stables", 4); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9101"; - pServer = startServer("/tmp/dnode_test_stb", fqdn, 9101, firstEp); - - uInfo("all server is running"); - - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1"); - SendThenCheckShowRetrieveMsg(1); CheckBinary("stb", TSDB_TABLE_NAME_LEN); CheckTimestamp(); CheckInt32(2); CheckInt32(3); { - SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(sizeof(SDropStbMsg)); - strcpy(pReq->name, "1.d1.stb"); + int32_t contLen = sizeof(SDropStbMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SDropStbMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_DROP_STB; + SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen); + strcpy(pReq->name, "1.d1.stb"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_STB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1"); - SendThenCheckShowRetrieveMsg(0); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + CHECK_META("show stables", 4); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 0); } diff --git a/source/dnode/mgmt/impl/test/sut/CMakeLists.txt b/source/dnode/mgmt/impl/test/sut/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d20c680fad3066e03a0ba6d93ab577b48e959755 --- /dev/null +++ b/source/dnode/mgmt/impl/test/sut/CMakeLists.txt @@ -0,0 +1,14 @@ +aux_source_directory(src SUT_SRC) +add_library(sut STATIC ${SUT_SRC}) +target_link_libraries( + sut + PUBLIC dnode + PUBLIC util + PUBLIC os + PUBLIC gtest_main +) + +target_include_directories( + sut + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) diff --git a/source/dnode/mgmt/impl/test/sut/deploy.cpp b/source/dnode/mgmt/impl/test/sut/deploy.cpp deleted file mode 100644 index 7cf469f8e253f0354b74cbdda7d2e8cf6cc8a2c5..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/sut/deploy.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "deploy.h" - -void initLog(const char* path) { - dDebugFlag = 207; - vDebugFlag = 0; - mDebugFlag = 207; - cDebugFlag = 0; - jniDebugFlag = 0; - tmrDebugFlag = 0; - uDebugFlag = 143; - rpcDebugFlag = 0; - odbcDebugFlag = 0; - qDebugFlag = 0; - wDebugFlag = 0; - sDebugFlag = 0; - tsdbDebugFlag = 0; - cqDebugFlag = 0; - tscEmbeddedInUtil = 1; - - taosRemoveDir(path); - taosMkDir(path); - - char temp[PATH_MAX]; - snprintf(temp, PATH_MAX, "%s/taosdlog", path); - if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) { - printf("failed to init log file\n"); - } -} - -void* runServer(void* param) { - SServer* pServer = (SServer*)param; - while (1) { - taosMsleep(100); - pthread_testcancel(); - } -} - -void initOption(SDnodeOpt* pOption, const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - pOption->sver = 1; - pOption->numOfCores = 1; - pOption->numOfSupportMnodes = 1; - pOption->numOfSupportVnodes = 1; - pOption->numOfSupportQnodes = 1; - pOption->statusInterval = 1; - pOption->numOfThreadsPerCore = 1; - pOption->ratioOfQueryCores = 1; - pOption->maxShellConns = 1000; - pOption->shellActivityTimer = 30; - pOption->serverPort = port; - strcpy(pOption->dataDir, path); - snprintf(pOption->localEp, TSDB_EP_LEN, "%s:%u", fqdn, port); - snprintf(pOption->localFqdn, TSDB_FQDN_LEN, "%s", fqdn); - snprintf(pOption->firstEp, TSDB_EP_LEN, "%s", firstEp); -} - -SServer* startServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - taosMkDir(path); - - SDnodeOpt option = {0}; - initOption(&option, path, fqdn, port, firstEp); - - SDnode* pDnode = dndInit(&option); - ASSERT(pDnode); - - SServer* pServer = (SServer*)calloc(1, sizeof(SServer)); - ASSERT(pServer); - - pServer->pDnode = pDnode; - pServer->threadId = taosCreateThread(runServer, pServer); - ASSERT(pServer->threadId); - - return pServer; -} - -SServer* createServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - taosRemoveDir(path); - return startServer(path, fqdn, port, firstEp); -} - -void stopServer(SServer* pServer) { - if (pServer == NULL) return; - if (pServer->threadId != NULL) { - taosDestoryThread(pServer->threadId); - } - - if (pServer->pDnode != NULL) { - dndCleanup(pServer->pDnode); - pServer->pDnode = NULL; - } -} - -void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { - SClient* pClient = (SClient*)parent; - pClient->pRsp = pMsg; - uInfo("response:%s from dnode, pCont:%p contLen:%d code:0x%X", taosMsg[pMsg->msgType], pMsg->pCont, pMsg->contLen, - pMsg->code); - tsem_post(&pClient->sem); -} - -SClient* createClient(const char* user, const char* pass, const char* fqdn, uint16_t port) { - SClient* pClient = (SClient*)calloc(1, sizeof(SClient)); - ASSERT(pClient); - - char secretEncrypt[TSDB_PASSWORD_LEN] = {0}; - taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt); - - SRpcInit rpcInit; - memset(&rpcInit, 0, sizeof(rpcInit)); - rpcInit.label = (char*)"DND-C"; - rpcInit.numOfThreads = 1; - rpcInit.cfp = processClientRsp; - rpcInit.sessions = 1024; - rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.idleTime = 30 * 1000; - rpcInit.user = (char*)user; - rpcInit.ckey = (char*)"key"; - rpcInit.parent = pClient; - rpcInit.secret = (char*)secretEncrypt; - rpcInit.parent = pClient; - // rpcInit.spi = 1; - - pClient->clientRpc = rpcOpen(&rpcInit); - ASSERT(pClient->clientRpc); - - tsem_init(&pClient->sem, 0, 0); - strcpy(pClient->fqdn, fqdn); - pClient->port = port; - - return pClient; -} - -void dropClient(SClient* pClient) { - tsem_destroy(&pClient->sem); - rpcClose(pClient->clientRpc); -} - -void sendMsg(SClient* pClient, SRpcMsg* pMsg) { - SEpSet epSet = {0}; - epSet.inUse = 0; - epSet.numOfEps = 1; - epSet.port[0] = pClient->port; - memcpy(epSet.fqdn[0], pClient->fqdn, TSDB_FQDN_LEN); - - rpcSendRequest(pClient->clientRpc, &epSet, pMsg, NULL); - tsem_wait(&pClient->sem); -} diff --git a/source/dnode/mgmt/impl/test/sut/deploy.h b/source/dnode/mgmt/impl/test/sut/deploy.h deleted file mode 100644 index 88d9b06fbb52ca421bec4a100fb5849bc2626b1f..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/sut/deploy.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include "os.h" - -#include "dnode.h" -#include "taosmsg.h" -#include "tconfig.h" -#include "tglobal.h" -#include "tnote.h" -#include "trpc.h" -#include "tthread.h" -#include "ulog.h" -#include "tdataformat.h" - -typedef struct { - SDnode* pDnode; - pthread_t* threadId; -} SServer; - -typedef struct { - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - void* clientRpc; - SRpcMsg* pRsp; - tsem_t sem; -} SClient; - -void initLog(const char* path); -SServer* createServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp); -SServer* startServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp); -void stopServer(SServer* pServer); -SClient* createClient(const char* user, const char* pass, const char* fqdn, uint16_t port); -void dropClient(SClient* pClient); -void sendMsg(SClient* pClient, SRpcMsg* pMsg); - diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h new file mode 100644 index 0000000000000000000000000000000000000000..b0de6f5c0c2b878bf57b7eede971126642959156 --- /dev/null +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -0,0 +1,130 @@ +/* + * 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_TEST_BASE_H_ +#define _TD_TEST_BASE_H_ + +#include +#include "os.h" + +#include "dnode.h" +#include "taosmsg.h" +#include "tconfig.h" +#include "tdataformat.h" +#include "tglobal.h" +#include "tnote.h" +#include "trpc.h" +#include "tthread.h" +#include "ulog.h" + +#include "client.h" +#include "server.h" + +class Testbase { + public: + void Init(const char* path, int16_t port); + void Cleanup(); + void Restart(); + SRpcMsg* SendMsg(int8_t msgType, void* pCont, int32_t contLen); + + private: + void InitLog(const char* path); + + private: + TestServer server; + TestClient client; + int32_t connId; + + public: + void SendShowMetaMsg(int8_t showType, const char* db); + void SendShowRetrieveMsg(); + + STableMetaMsg* GetShowMeta(); + SRetrieveTableRsp* GetRetrieveRsp(); + + int32_t GetMetaNum(); + const char* GetMetaTbName(); + int32_t GetMetaColId(int32_t index); + int8_t GetMetaType(int32_t index); + int32_t GetMetaBytes(int32_t index); + const char* GetMetaName(int32_t index); + + const char* GetShowName(); + int32_t GetShowRows(); + int8_t GetShowInt8(); + int16_t GetShowInt16(); + int32_t GetShowInt32(); + int64_t GetShowInt64(); + int64_t GetShowTimestamp(); + const char* GetShowBinary(int32_t len); + + private: + int32_t showId; + STableMetaMsg* pMeta; + SRetrieveTableRsp* pRetrieveRsp; + char* pData; + int32_t pos; +}; + +#define CHECK_META(tbName, numOfColumns) \ + { \ + EXPECT_EQ(test.GetMetaNum(), numOfColumns); \ + EXPECT_STREQ(test.GetMetaTbName(), tbName); \ + } + +#define CHECK_SCHEMA(colId, type, bytes, colName) \ + { \ + EXPECT_EQ(test.GetMetaType(colId), type); \ + EXPECT_EQ(test.GetMetaBytes(colId), bytes); \ + EXPECT_STREQ(test.GetMetaName(colId), colName); \ + } + +#define CheckBinary(val, len) \ + { EXPECT_STREQ(test.GetShowBinary(len), val); } + +#define CheckInt8(val) \ + { EXPECT_EQ(test.GetShowInt8(), val); } + +#define CheckInt16(val) \ + { EXPECT_EQ(test.GetShowInt16(), val); } + +#define CheckInt32(val) \ + { EXPECT_EQ(test.GetShowInt32(), val); } + +#define CheckInt64(val) \ + { EXPECT_EQ(test.GetShowInt64(), val); } + +#define CheckTimestamp() \ + { EXPECT_GT(test.GetShowTimestamp(), 0); } + +#define IgnoreBinary(len) \ + { test.GetShowBinary(len); } + +#define IgnoreInt8() \ + { test.GetShowInt8(); } + +#define IgnoreInt16() \ + { test.GetShowInt16(); } + +#define IgnoreInt32() \ + { test.GetShowInt32(); } + +#define IgnoreInt64() \ + { test.GetShowInt64(); } + +#define IgnoreTimestamp() \ + { test.GetShowTimestamp(); } + +#endif /* _TD_TEST_BASE_H_ */ \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/sut/inc/client.h b/source/dnode/mgmt/impl/test/sut/inc/client.h new file mode 100644 index 0000000000000000000000000000000000000000..e1e430318e891d2cf8c91740ebbc9d8d5de183cb --- /dev/null +++ b/source/dnode/mgmt/impl/test/sut/inc/client.h @@ -0,0 +1,36 @@ +/* + * 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_TEST_CLIENT_H_ +#define _TD_TEST_CLIENT_H_ + +class TestClient { + public: + bool Init(const char* user, const char* pass, const char* fqdn, uint16_t port); + void Cleanup(); + + SRpcMsg* SendMsg(SRpcMsg* pMsg); + void SetRpcRsp(SRpcMsg* pRsp); + tsem_t* GetSem(); + + private: + char fqdn[TSDB_FQDN_LEN]; + uint16_t port; + void* clientRpc; + SRpcMsg* pRsp; + tsem_t sem; +}; + +#endif /* _TD_TEST_CLIENT_H_ */ \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/sut/inc/server.h b/source/dnode/mgmt/impl/test/sut/inc/server.h new file mode 100644 index 0000000000000000000000000000000000000000..aa7b37f22118ca0ca4081235624903dc010f85af --- /dev/null +++ b/source/dnode/mgmt/impl/test/sut/inc/server.h @@ -0,0 +1,38 @@ +/* + * 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_TEST_SERVER_H_ +#define _TD_TEST_SERVER_H_ + +class TestServer { + public: + bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp); + void Stop(); + void Restart(); + + private: + SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); + bool DoStart(); + + private: + SDnode* pDnode; + pthread_t* threadId; + char path[PATH_MAX]; + char fqdn[TSDB_FQDN_LEN]; + char firstEp[TSDB_EP_LEN]; + uint16_t port; +}; + +#endif /* _TD_TEST_SERVER_H_ */ \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp new file mode 100644 index 0000000000000000000000000000000000000000..59e99b1e1d9b740ac78079d2c899dd00e36b141b --- /dev/null +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -0,0 +1,180 @@ +/* + * 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 "base.h" + +void Testbase::InitLog(const char* path) { + dDebugFlag = 207; + vDebugFlag = 0; + mDebugFlag = 207; + cDebugFlag = 0; + jniDebugFlag = 0; + tmrDebugFlag = 0; + uDebugFlag = 143; + rpcDebugFlag = 0; + odbcDebugFlag = 0; + qDebugFlag = 0; + wDebugFlag = 0; + sDebugFlag = 0; + tsdbDebugFlag = 0; + cqDebugFlag = 0; + tscEmbeddedInUtil = 1; + + taosRemoveDir(path); + taosMkDir(path); + + char temp[PATH_MAX]; + snprintf(temp, PATH_MAX, "%s/taosdlog", path); + if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) { + printf("failed to init log file\n"); + } +} + +void Testbase::Init(const char* path, int16_t port) { + char fqdn[] = "localhost"; + char firstEp[TSDB_EP_LEN] = {0}; + snprintf(firstEp, TSDB_EP_LEN, "%s:%u", fqdn, port); + + InitLog("/tmp/tdlog"); + server.Start(path, fqdn, port, firstEp); + client.Init("root", "taosdata", fqdn, port); + taosMsleep(1100); +} + +void Testbase::Cleanup() { + server.Stop(); + client.Cleanup(); +} + +void Testbase::Restart() { server.Restart(); } + +SRpcMsg* Testbase::SendMsg(int8_t msgType, void* pCont, int32_t contLen) { + SRpcMsg rpcMsg = {0}; + rpcMsg.pCont = pCont; + rpcMsg.contLen = contLen; + rpcMsg.msgType = msgType; + + return client.SendMsg(&rpcMsg); +} + +void Testbase::SendShowMetaMsg(int8_t showType, const char* db) { + int32_t contLen = sizeof(SShowMsg); + SShowMsg* pShow = (SShowMsg*)rpcMallocCont(contLen); + pShow->type = showType; + strcpy(pShow->db, db); + + SRpcMsg* pMsg = SendMsg(TSDB_MSG_TYPE_SHOW, pShow, contLen); + SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont; + + ASSERT(pShowRsp != nullptr); + pShowRsp->showId = htonl(pShowRsp->showId); + pMeta = &pShowRsp->tableMeta; + pMeta->numOfTags = htonl(pMeta->numOfTags); + pMeta->numOfColumns = htonl(pMeta->numOfColumns); + pMeta->sversion = htonl(pMeta->sversion); + pMeta->tversion = htonl(pMeta->tversion); + pMeta->tuid = htobe64(pMeta->tuid); + pMeta->suid = htobe64(pMeta->suid); + + showId = pShowRsp->showId; +} + +int32_t Testbase::GetMetaColId(int32_t index) { + SSchema* pSchema = &pMeta->pSchema[index]; + pSchema->colId = htonl(pSchema->colId); + return pSchema->colId; +} + +int8_t Testbase::GetMetaType(int32_t index) { + SSchema* pSchema = &pMeta->pSchema[index]; + return pSchema->type; +} + +int32_t Testbase::GetMetaBytes(int32_t index) { + SSchema* pSchema = &pMeta->pSchema[index]; + pSchema->bytes = htonl(pSchema->bytes); + return pSchema->bytes; +} + +const char* Testbase::GetMetaName(int32_t index) { + SSchema* pSchema = &pMeta->pSchema[index]; + return pSchema->name; +} + +int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; } + +const char* Testbase::GetMetaTbName() { return pMeta->tbFname; } + +void Testbase::SendShowRetrieveMsg() { + int32_t contLen = sizeof(SRetrieveTableMsg); + + SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(contLen); + pRetrieve->showId = htonl(showId); + pRetrieve->free = 0; + + SRpcMsg* pMsg = SendMsg(TSDB_MSG_TYPE_SHOW_RETRIEVE, pRetrieve, contLen); + pRetrieveRsp = (SRetrieveTableRsp*)pMsg->pCont; + pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); + pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); + pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); + + pData = pRetrieveRsp->data; + pos = 0; +} + +const char* Testbase::GetShowName() { return pMeta->tbFname; } + +int8_t Testbase::GetShowInt8() { + int8_t data = *((int8_t*)(pData + pos)); + pos += sizeof(int8_t); + return data; +} + +int16_t Testbase::GetShowInt16() { + int16_t data = *((int16_t*)(pData + pos)); + pos += sizeof(int16_t); + return data; +} + +int32_t Testbase::GetShowInt32() { + int32_t data = *((int32_t*)(pData + pos)); + pos += sizeof(int32_t); + return data; +} + +int64_t Testbase::GetShowInt64() { + int64_t data = *((int64_t*)(pData + pos)); + pos += sizeof(int64_t); + return data; +} + +int64_t Testbase::GetShowTimestamp() { + int64_t data = *((int64_t*)(pData + pos)); + pos += sizeof(int64_t); + return data; +} + +const char* Testbase::GetShowBinary(int32_t len) { + pos += sizeof(VarDataLenT); + char* data = (char*)(pData + pos); + pos += len; + return data; +} + +int32_t Testbase::GetShowRows() { return pRetrieveRsp->numOfRows; } + +STableMetaMsg* Testbase::GetShowMeta() { return pMeta; } + +SRetrieveTableRsp* Testbase::GetRetrieveRsp() { return pRetrieveRsp; } \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/sut/src/client.cpp b/source/dnode/mgmt/impl/test/sut/src/client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fce3da15073e830908390fe95d9b98f0fcc5bada --- /dev/null +++ b/source/dnode/mgmt/impl/test/sut/src/client.cpp @@ -0,0 +1,73 @@ +/* + * 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 "base.h" + +static void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { + TestClient* client = (TestClient*)parent; + client->SetRpcRsp(pMsg); + uInfo("response:%s from dnode, code:0x%x", taosMsg[pMsg->msgType], pMsg->code); + tsem_post(client->GetSem()); +} + +void TestClient::SetRpcRsp(SRpcMsg* pRsp) { this->pRsp = pRsp; }; + +tsem_t* TestClient::GetSem() { return &sem; } + +bool TestClient::Init(const char* user, const char* pass, const char* fqdn, uint16_t port) { + char secretEncrypt[TSDB_PASSWORD_LEN] = {0}; + taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt); + + SRpcInit rpcInit; + memset(&rpcInit, 0, sizeof(rpcInit)); + rpcInit.label = (char*)"DND-C"; + rpcInit.numOfThreads = 1; + rpcInit.cfp = processClientRsp; + rpcInit.sessions = 1024; + rpcInit.connType = TAOS_CONN_CLIENT; + rpcInit.idleTime = 30 * 1000; + rpcInit.user = (char*)user; + rpcInit.ckey = (char*)"key"; + rpcInit.parent = this; + rpcInit.secret = (char*)secretEncrypt; + // rpcInit.spi = 1; + + clientRpc = rpcOpen(&rpcInit); + ASSERT(clientRpc); + + tsem_init(&sem, 0, 0); + strcpy(this->fqdn, fqdn); + this->port = port; + + return true; +} + +void TestClient::Cleanup() { + tsem_destroy(&sem); + rpcClose(clientRpc); +} + +SRpcMsg* TestClient::SendMsg(SRpcMsg* pMsg) { + SEpSet epSet = {0}; + epSet.inUse = 0; + epSet.numOfEps = 1; + epSet.port[0] = port; + memcpy(epSet.fqdn[0], fqdn, TSDB_FQDN_LEN); + + rpcSendRequest(clientRpc, &epSet, pMsg, NULL); + tsem_wait(&sem); + + return pRsp; +} diff --git a/source/dnode/mgmt/impl/test/sut/src/server.cpp b/source/dnode/mgmt/impl/test/sut/src/server.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e96f7deaf5e1c9466a5b94a29cc8d1ad25c8f6d4 --- /dev/null +++ b/source/dnode/mgmt/impl/test/sut/src/server.cpp @@ -0,0 +1,88 @@ +/* + * 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 "base.h" + +void* serverLoop(void* param) { + while (1) { + taosMsleep(100); + pthread_testcancel(); + } +} + +SDnodeOpt TestServer::BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { + SDnodeOpt option = {0}; + option.sver = 1; + option.numOfCores = 1; + option.numOfSupportMnodes = 1; + option.numOfSupportVnodes = 1; + option.numOfSupportQnodes = 1; + option.statusInterval = 1; + option.numOfThreadsPerCore = 1; + option.ratioOfQueryCores = 1; + option.maxShellConns = 1000; + option.shellActivityTimer = 30; + option.serverPort = port; + strcpy(option.dataDir, path); + snprintf(option.localEp, TSDB_EP_LEN, "%s:%u", fqdn, port); + snprintf(option.localFqdn, TSDB_FQDN_LEN, "%s", fqdn); + snprintf(option.firstEp, TSDB_EP_LEN, "%s", firstEp); + return option; +} + +bool TestServer::DoStart() { + SDnodeOpt option = BuildOption(path, fqdn, port, firstEp); + taosMkDir(path); + + pDnode = dndInit(&option); + if (pDnode != NULL) { + return false; + } + + threadId = taosCreateThread(serverLoop, NULL); + if (threadId != NULL) { + return false; + } + return true; +} + +void TestServer::Restart() { + uInfo("start all server"); + Stop(); + DoStart(); + uInfo("all server is running"); +} + +bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { + strcpy(this->path, path); + strcpy(this->fqdn, fqdn); + this->port = port; + strcpy(this->firstEp, firstEp); + + taosRemoveDir(path); + return DoStart(); +} + +void TestServer::Stop() { + if (threadId != NULL) { + taosDestoryThread(threadId); + threadId = NULL; + } + + if (pDnode != NULL) { + dndCleanup(pDnode); + pDnode = NULL; + } +} diff --git a/source/dnode/mgmt/impl/test/user/CMakeLists.txt b/source/dnode/mgmt/impl/test/user/CMakeLists.txt index 0d3215a4d0445ab99c8180b31716b12841e21c34..5068660eba1fea5964664819b9a51686cbde2adf 100644 --- a/source/dnode/mgmt/impl/test/user/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/user/CMakeLists.txt @@ -1,24 +1,8 @@ -add_executable(dnode_test_user "") - -target_sources(dnode_test_user - PRIVATE - "user.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. USER_SRC) +add_executable(dnode_test_user ${USER_SRC}) target_link_libraries( dnode_test_user - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dnode_test_user - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + PUBLIC sut ) add_test( diff --git a/source/dnode/mgmt/impl/test/user/user.cpp b/source/dnode/mgmt/impl/test/user/user.cpp index 32309b106e8f6aef905fb8fd8fb5c72e6d28ecda..a1810e7adaaa7011775dd2e9fbcc3892cce720e6 100644 --- a/source/dnode/mgmt/impl/test/user/user.cpp +++ b/source/dnode/mgmt/impl/test/user/user.cpp @@ -9,168 +9,34 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestUser : public ::testing::Test { protected: - static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - SServer* pServer = createServer(path, fqdn, port, firstEp); - ASSERT(pServer); - return pServer; - } - - static void SetUpTestSuite() { - initLog("/tmp/tdlog"); - - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9140"; - pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9140, firstEp); - pClient = createClient("root", "taosdata", fqdn, 9140); - taosMsleep(300); - } - - static void TearDownTestSuite() { - stopServer(pServer); - dropClient(pClient); - pServer = NULL; - pClient = NULL; - } + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_user", 9140); } + static void TearDownTestSuite() { test.Cleanup(); } - static SServer* pServer; - static SClient* pClient; - static int32_t connId; + static Testbase test; public: void SetUp() override {} void TearDown() override {} - - void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) { - SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pShow->type = showType; - strcpy(pShow->db, ""); - - SRpcMsg showRpcMsg = {0}; - showRpcMsg.pCont = pShow; - showRpcMsg.contLen = sizeof(SShowMsg); - showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &showRpcMsg); - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont; - ASSERT_NE(pShowRsp, nullptr); - pShowRsp->showId = htonl(pShowRsp->showId); - pMeta = &pShowRsp->tableMeta; - pMeta->numOfTags = htonl(pMeta->numOfTags); - pMeta->numOfColumns = htonl(pMeta->numOfColumns); - pMeta->sversion = htonl(pMeta->sversion); - pMeta->tversion = htonl(pMeta->tversion); - pMeta->tuid = htobe64(pMeta->tuid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pShowRsp->showId; - - EXPECT_NE(pShowRsp->showId, 0); - EXPECT_STREQ(pMeta->tbFname, showName); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->numOfColumns, columns); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->update, 0); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tuid, 0); - EXPECT_EQ(pMeta->suid, 0); - } - - void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { - SSchema* pSchema = &pMeta->pSchema[index]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, type); - EXPECT_EQ(pSchema->bytes, bytes); - EXPECT_STREQ(pSchema->name, name); - } - - void SendThenCheckShowRetrieveMsg(int32_t rows) { - SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pRetrieve->showId = htonl(showId); - pRetrieve->free = 0; - - SRpcMsg retrieveRpcMsg = {0}; - retrieveRpcMsg.pCont = pRetrieve; - retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg); - retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &retrieveRpcMsg); - - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; - ASSERT_NE(pRetrieveRsp, nullptr); - pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); - pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); - pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); - - EXPECT_EQ(pRetrieveRsp->numOfRows, rows); - EXPECT_EQ(pRetrieveRsp->useconds, 0); - // EXPECT_EQ(pRetrieveRsp->completed, completed); - EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRetrieveRsp->compressed, 0); - EXPECT_EQ(pRetrieveRsp->compLen, 0); - - pData = pRetrieveRsp->data; - pos = 0; - } - - void CheckInt16(int16_t val) { - int16_t data = *((int16_t*)(pData + pos)); - pos += sizeof(int16_t); - EXPECT_EQ(data, val); - } - - void CheckInt64(int64_t val) { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_EQ(data, val); - } - - void CheckTimestamp() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_GT(data, 0); - } - - void CheckBinary(const char* val, int32_t len) { - pos += sizeof(VarDataLenT); - char* data = (char*)(pData + pos); - pos += len; - EXPECT_STREQ(data, val); - } - - int32_t showId; - STableMetaMsg* pMeta; - SRetrieveTableRsp* pRetrieveRsp; - char* pData; - int32_t pos; }; -SServer* DndTestUser::pServer; -SClient* DndTestUser::pClient; -int32_t DndTestUser::connId; +Testbase DndTestUser::test; TEST_F(DndTestUser, 01_ShowUser) { - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); - CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name"); - CheckSchema(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege"); - CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - CheckSchema(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account"); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account"); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 1); - SendThenCheckShowRetrieveMsg(1); CheckBinary("root", TSDB_USER_LEN); CheckBinary("super", 10); CheckTimestamp(); @@ -179,39 +45,35 @@ TEST_F(DndTestUser, 01_ShowUser) { TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { { - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg)); + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p1"); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateUserMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } { - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg)); + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); strcpy(pReq->user, "u2"); strcpy(pReq->pass, "p2"); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateUserMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); - SendThenCheckShowRetrieveMsg(3); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 3); + CheckBinary("u1", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN); CheckBinary("u2", TSDB_USER_LEN); @@ -226,22 +88,23 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { CheckBinary("root", TSDB_USER_LEN); { - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg)); + int32_t contLen = sizeof(SAlterUserMsg); + + SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); strcpy(pReq->user, "u1"); strcpy(pReq->pass, "p2"); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SAlterUserMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_USER; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); - SendThenCheckShowRetrieveMsg(3); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 3); + CheckBinary("u1", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN); CheckBinary("u2", TSDB_USER_LEN); @@ -256,21 +119,22 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { CheckBinary("root", TSDB_USER_LEN); { - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg)); - strcpy(pReq->user, "u1"); + int32_t contLen = sizeof(SDropUserMsg); - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SDropUserMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_DROP_USER; + SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_USER, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); - SendThenCheckShowRetrieveMsg(2); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + CheckBinary("root", TSDB_USER_LEN); CheckBinary("u2", TSDB_USER_LEN); CheckBinary("super", 10); @@ -281,19 +145,14 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { CheckBinary("root", TSDB_USER_LEN); // restart - stopServer(pServer); - pServer = NULL; - - uInfo("start all server"); + test.Restart(); - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9140"; - pServer = startServer("/tmp/dnode_test_user", fqdn, 9140, firstEp); + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); - uInfo("all server is running"); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); - SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); - SendThenCheckShowRetrieveMsg(2); CheckBinary("root", TSDB_USER_LEN); CheckBinary("u2", TSDB_USER_LEN); CheckBinary("super", 10); diff --git a/source/dnode/mgmt/impl/test/vgroup/CMakeLists.txt b/source/dnode/mgmt/impl/test/vgroup/CMakeLists.txt index 5670f9dbf2c4ac2c3609494f50bd4c82bd77fef1..b864b0593c26d15c4468c381f95c1ac337e1174f 100644 --- a/source/dnode/mgmt/impl/test/vgroup/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/vgroup/CMakeLists.txt @@ -1,24 +1,8 @@ -add_executable(dnode_test_vgroup "") - -target_sources(dnode_test_vgroup - PRIVATE - "vgroup.cpp" - "../sut/deploy.cpp" -) - +aux_source_directory(. VGROUP_SRC) +add_executable(dnode_test_vgroup ${VGROUP_SRC}) target_link_libraries( dnode_test_vgroup - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - -target_include_directories(dnode_test_vgroup - PUBLIC - "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" - "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" - "${CMAKE_CURRENT_SOURCE_DIR}/../sut" + PUBLIC sut ) add_test( diff --git a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp index 9149be9cd838be6ddd708a1fa56e85f6dc5f2dae..c534fcbabe96b28af1a917bbca718ad6210070b5 100644 --- a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp +++ b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp @@ -9,177 +9,28 @@ * */ -#include "deploy.h" +#include "base.h" class DndTestVgroup : public ::testing::Test { protected: - static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - SServer* pServer = createServer(path, fqdn, port, firstEp); - ASSERT(pServer); - return pServer; - } - - static void SetUpTestSuite() { - initLog("/tmp/tdlog"); - - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9150"; - pServer = CreateServer("/tmp/dnode_test_vgroup", fqdn, 9150, firstEp); - pClient = createClient("root", "taosdata", fqdn, 9150); - taosMsleep(1100); - } - - static void TearDownTestSuite() { - stopServer(pServer); - dropClient(pClient); - pServer = NULL; - pClient = NULL; - } + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_vgroup", 9150); } + static void TearDownTestSuite() { test.Cleanup(); } - static SServer* pServer; - static SClient* pClient; - static int32_t connId; + static Testbase test; public: void SetUp() override {} void TearDown() override {} - - void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) { - SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pShow->type = showType; - if (db != NULL) { - strcpy(pShow->db, db); - } - SRpcMsg showRpcMsg = {0}; - showRpcMsg.pCont = pShow; - showRpcMsg.contLen = sizeof(SShowMsg); - showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW; - - sendMsg(pClient, &showRpcMsg); - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont; - ASSERT_NE(pShowRsp, nullptr); - pShowRsp->showId = htonl(pShowRsp->showId); - pMeta = &pShowRsp->tableMeta; - pMeta->numOfTags = htonl(pMeta->numOfTags); - pMeta->numOfColumns = htonl(pMeta->numOfColumns); - pMeta->sversion = htonl(pMeta->sversion); - pMeta->tversion = htonl(pMeta->tversion); - pMeta->tuid = htobe64(pMeta->tuid); - pMeta->suid = htobe64(pMeta->suid); - - showId = pShowRsp->showId; - - EXPECT_NE(pShowRsp->showId, 0); - EXPECT_STREQ(pMeta->tbFname, showName); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->numOfColumns, columns); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->update, 0); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tuid, 0); - EXPECT_EQ(pMeta->suid, 0); - } - - void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { - SSchema* pSchema = &pMeta->pSchema[index]; - pSchema->bytes = htonl(pSchema->bytes); - EXPECT_EQ(pSchema->colId, 0); - EXPECT_EQ(pSchema->type, type); - EXPECT_EQ(pSchema->bytes, bytes); - EXPECT_STREQ(pSchema->name, name); - } - - void SendThenCheckShowRetrieveMsg(int32_t rows) { - SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); - pRetrieve->showId = htonl(showId); - pRetrieve->free = 0; - - SRpcMsg retrieveRpcMsg = {0}; - retrieveRpcMsg.pCont = pRetrieve; - retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg); - retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; - - sendMsg(pClient, &retrieveRpcMsg); - - ASSERT_NE(pClient->pRsp, nullptr); - ASSERT_EQ(pClient->pRsp->code, 0); - ASSERT_NE(pClient->pRsp->pCont, nullptr); - - pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; - ASSERT_NE(pRetrieveRsp, nullptr); - pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); - pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); - pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); - - EXPECT_EQ(pRetrieveRsp->numOfRows, rows); - EXPECT_EQ(pRetrieveRsp->useconds, 0); - // EXPECT_EQ(pRetrieveRsp->completed, completed); - EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRetrieveRsp->compressed, 0); - EXPECT_EQ(pRetrieveRsp->compLen, 0); - - pData = pRetrieveRsp->data; - pos = 0; - } - - void CheckInt8(int8_t val) { - int8_t data = *((int8_t*)(pData + pos)); - pos += sizeof(int8_t); - EXPECT_EQ(data, val); - } - - void CheckInt16(int16_t val) { - int16_t data = *((int16_t*)(pData + pos)); - pos += sizeof(int16_t); - EXPECT_EQ(data, val); - } - - void CheckInt32(int32_t val) { - int32_t data = *((int32_t*)(pData + pos)); - pos += sizeof(int32_t); - EXPECT_EQ(data, val); - } - - void CheckInt64(int64_t val) { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_EQ(data, val); - } - - void CheckTimestamp() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - EXPECT_GT(data, 0); - } - - void CheckBinary(const char* val, int32_t len) { - pos += sizeof(VarDataLenT); - char* data = (char*)(pData + pos); - pos += len; - EXPECT_STREQ(data, val); - } - - int32_t showId; - STableMetaMsg* pMeta; - SRetrieveTableRsp* pRetrieveRsp; - char* pData; - int32_t pos; }; -SServer* DndTestVgroup::pServer; -SClient* DndTestVgroup::pClient; -int32_t DndTestVgroup::connId; +Testbase DndTestVgroup::test; TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { { for (int i = 0; i < 3; ++i) { - SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(sizeof(SCreateVnodeMsg)); + int32_t contLen = sizeof(SCreateVnodeMsg); + + SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(contLen); pReq->vgId = htonl(2); pReq->dnodeId = htonl(1); strcpy(pReq->db, "1.d1"); @@ -209,13 +60,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SCreateVnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_VNODE_IN; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_VNODE_IN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -223,7 +68,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { { for (int i = 0; i < 3; ++i) { - SAlterVnodeMsg* pReq = (SAlterVnodeMsg*)rpcMallocCont(sizeof(SAlterVnodeMsg)); + int32_t contLen = sizeof(SAlterVnodeMsg); + + SAlterVnodeMsg* pReq = (SAlterVnodeMsg*)rpcMallocCont(contLen); pReq->vgId = htonl(2); pReq->dnodeId = htonl(1); strcpy(pReq->db, "1.d1"); @@ -253,13 +100,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pReq; - rpcMsg.contLen = sizeof(SAlterVnodeMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_VNODE_IN; - - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_VNODE_IN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } @@ -267,7 +108,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { { for (int i = 0; i < 3; ++i) { - SDropVnodeMsg* pReq = (SDropVnodeMsg*)rpcMallocCont(sizeof(SDropVnodeMsg)); + int32_t contLen = sizeof(SDropVnodeMsg); + + SDropVnodeMsg* pReq = (SDropVnodeMsg*)rpcMallocCont(contLen); pReq->vgId = htonl(2); pReq->dnodeId = htonl(1); strcpy(pReq->db, "1.d1"); @@ -278,8 +121,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { rpcMsg.contLen = sizeof(SDropVnodeMsg); rpcMsg.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN; - sendMsg(pClient, &rpcMsg); - SRpcMsg* pMsg = pClient->pRsp; + SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_VNODE_IN, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); } diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index bf657fd27aabdbb22ed3b1c01fb85052b60cb506..a4b73e0f3f2547bf6a013eae16c927e1658a0ad7 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -23,29 +23,25 @@ #define QUERY_ID_SIZE 20 #define QUERY_OBJ_ID_SIZE 18 #define SUBQUERY_INFO_SIZE 6 -#define QUERY_STREAM_SAVE_SIZE 20 +#define QUERY_SAVE_SIZE 20 typedef struct { - char user[TSDB_USER_LEN]; - char app[TSDB_APP_NAME_LEN]; // app name that invokes taosc - int32_t pid; // pid of app that invokes taosc - int64_t appStartTime; // app start time - int32_t id; - int8_t killed; - int8_t align; - uint16_t port; - uint32_t ip; - int64_t stime; - int64_t lastAccess; - int32_t queryId; - int32_t streamId; - int32_t numOfQueries; - int32_t numOfStreams; - SStreamDesc *pStreams; - SQueryDesc *pQueries; + int32_t id; + char user[TSDB_USER_LEN]; + char app[TSDB_APP_NAME_LEN]; // app name that invokes taosc + int64_t appStartTimeMs; // app start time + int32_t pid; // pid of app that invokes taosc + uint32_t ip; + uint16_t port; + int8_t killed; + int64_t loginTimeMs; + int64_t lastAccessTimeMs; + int32_t queryId; + int32_t numOfQueries; + SQueryDesc *pQueries; } SConnObj; -static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t port, int32_t pid, const char *app, int64_t startTime); +static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime); static void mndFreeConn(SConnObj *pConn); static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId); static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn); @@ -54,16 +50,12 @@ static void mndCancelGetNextConn(SMnode *pMnode, void *pIter); static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg); static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg); static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg); -static int32_t mndProcessKillStreamMsg(SMnodeMsg *pMsg); static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg); static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); static int32_t mndRetrieveConns(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); static int32_t mndRetrieveQueries(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter); -static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveStreams(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); -static void mndCancelGetNextStream(SMnode *pMnode, void *pIter); int32_t mndInitProfile(SMnode *pMnode) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; @@ -79,7 +71,6 @@ int32_t mndInitProfile(SMnode *pMnode) { mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_HEARTBEAT, mndProcessHeartBeatMsg); mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONNECT, mndProcessConnectMsg); mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_QUERY, mndProcessKillQueryMsg); - mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_STREAM, mndProcessKillStreamMsg); mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_CONN, mndProcessKillConnectionMsg); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndGetConnsMeta); @@ -88,9 +79,6 @@ int32_t mndInitProfile(SMnode *pMnode) { mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndGetQueryMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndRetrieveQueries); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndCancelGetNextQuery); - mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndGetStreamMeta); - mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndRetrieveStreams); - mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndCancelGetNextStream); return 0; } @@ -103,46 +91,43 @@ void mndCleanupProfile(SMnode *pMnode) { } } -static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t port, int32_t pid, const char *app, int64_t startTime) { +static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; int32_t connId = atomic_add_fetch_32(&pMgmt->connId, 1); if (connId == 0) atomic_add_fetch_32(&pMgmt->connId, 1); + if (startTime == 0) startTime = taosGetTimestampMs(); - SConnObj connObj = {.pid = pid, - .appStartTime = startTime, - .id = connId, + SConnObj connObj = {.id = connId, + .appStartTimeMs = startTime, + .pid = pid, + .ip = pInfo->clientIp, + .port = pInfo->clientPort, .killed = 0, - .port = port, - .ip = ip, - .stime = taosGetTimestampMs(), - .lastAccess = 0, + .loginTimeMs = taosGetTimestampMs(), + .lastAccessTimeMs = 0, .queryId = 0, - .streamId = 0, .numOfQueries = 0, - .numOfStreams = 0, - .pStreams = NULL, .pQueries = NULL}; - connObj.lastAccess = connObj.stime; - tstrncpy(connObj.user, user, TSDB_USER_LEN); + connObj.lastAccessTimeMs = connObj.loginTimeMs; + tstrncpy(connObj.user, pInfo->user, TSDB_USER_LEN); tstrncpy(connObj.app, app, TSDB_APP_NAME_LEN); int32_t keepTime = pMnode->cfg.shellActivityTimer * 3; SConnObj *pConn = taosCachePut(pMgmt->cache, &connId, sizeof(int32_t), &connObj, sizeof(connObj), keepTime * 1000); if (pConn == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("conn:%d, data:%p failed to put into cache since %s, user:%s", connId, pConn, user, terrstr()); + mError("conn:%d, data:%p failed to put into cache since %s, user:%s", connId, pConn, pInfo->user, terrstr()); return NULL; } else { - mTrace("conn:%d, data:%p created, user:%s", pConn->id, pConn, user); + mTrace("conn:%d, data:%p created, user:%s", pConn->id, pConn, pInfo->user); return pConn; } } static void mndFreeConn(SConnObj *pConn) { tfree(pConn->pQueries); - tfree(pConn->pStreams); mTrace("conn:%d, data:%p destroyed", pConn->id, pConn); } @@ -156,7 +141,7 @@ static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId) { } int32_t keepTime = pMnode->cfg.shellActivityTimer * 3; - pConn->lastAccess = keepTime * 1000 + (uint64_t)taosGetTimestampMs(); + pConn->lastAccessTimeMs = keepTime * 1000 + (uint64_t)taosGetTimestampMs(); mTrace("conn:%d, data:%p acquired from cache", pConn->id, pConn); return pConn; @@ -219,7 +204,7 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) { mndReleaseDb(pMnode, pDb); } - SConnObj *pConn = mndCreateConn(pMnode, info.user, info.clientIp, info.clientPort, pReq->pid, pReq->app, pReq->startTime); + SConnObj *pConn = mndCreateConn(pMnode, &info, pReq->pid, pReq->app, pReq->startTime); if (pConn == NULL) { mError("user:%s, failed to login from %s while create connection since %s", pMsg->user, ip, terrstr()); return -1; @@ -254,16 +239,14 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) { static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pMsg) { pConn->numOfQueries = 0; - pConn->numOfStreams = 0; int32_t numOfQueries = htonl(pMsg->numOfQueries); - int32_t numOfStreams = htonl(pMsg->numOfStreams); if (numOfQueries > 0) { if (pConn->pQueries == NULL) { - pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_STREAM_SAVE_SIZE); + pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_SAVE_SIZE); } - pConn->numOfQueries = MIN(QUERY_STREAM_SAVE_SIZE, numOfQueries); + pConn->numOfQueries = MIN(QUERY_SAVE_SIZE, numOfQueries); int32_t saveSize = pConn->numOfQueries * sizeof(SQueryDesc); if (saveSize > 0 && pConn->pQueries != NULL) { @@ -271,19 +254,6 @@ static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pMsg) { } } - if (numOfStreams > 0) { - if (pConn->pStreams == NULL) { - pConn->pStreams = calloc(sizeof(SStreamDesc), QUERY_STREAM_SAVE_SIZE); - } - - pConn->numOfStreams = MIN(QUERY_STREAM_SAVE_SIZE, numOfStreams); - - int32_t saveSize = pConn->numOfStreams * sizeof(SStreamDesc); - if (saveSize > 0 && pConn->pStreams != NULL) { - memcpy(pConn->pStreams, pMsg->pData + numOfQueries * sizeof(SQueryDesc), saveSize); - } - } - return TSDB_CODE_SUCCESS; } @@ -303,7 +273,7 @@ static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) { SConnObj *pConn = mndAcquireConn(pMnode, pReq->connId); if (pConn == NULL) { - pConn = mndCreateConn(pMnode, info.user, info.clientIp, info.clientPort, pReq->pid, pReq->app, 0); + pConn = mndCreateConn(pMnode, &info, pReq->pid, pReq->app, 0); if (pConn == NULL) { mError("user:%s, conn:%d is freed and failed to create new conn since %s", pMsg->user, pReq->connId, terrstr()); return -1; @@ -343,11 +313,6 @@ static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) { pRsp->killConnection = 1; } - if (pConn->streamId != 0) { - pRsp->streamId = htonl(pConn->streamId); - pConn->streamId = 0; - } - if (pConn->queryId != 0) { pRsp->queryId = htonl(pConn->queryId); pConn->queryId = 0; @@ -395,37 +360,6 @@ static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg) { } } -static int32_t mndProcessKillStreamMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SProfileMgmt *pMgmt = &pMnode->profileMgmt; - - SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user); - if (pUser == NULL) return 0; - if (!pUser->superUser) { - mndReleaseUser(pMnode, pUser); - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; - } - mndReleaseUser(pMnode, pUser); - - SKillStreamMsg *pKill = pMsg->rpcMsg.pCont; - int32_t connId = htonl(pKill->connId); - int32_t streamId = htonl(pKill->streamId); - mDebug("kill stream msg is received, streamId:%d", streamId); - - SConnObj *pConn = taosCacheAcquireByKey(pMgmt->cache, &connId, sizeof(int32_t)); - if (pConn == NULL) { - mError("connId:%d, failed to kill streamId:%d, conn not exist", connId, streamId); - terrno = TSDB_CODE_MND_INVALID_CONN_ID; - return -1; - } else { - mInfo("connId:%d, streamId:%d is killed by user:%s", connId, streamId, pMsg->user); - pConn->streamId = streamId; - taosCacheRelease(pMgmt->cache, (void **)&pConn, false); - return TSDB_CODE_SUCCESS; - } -} - static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; SProfileMgmt *pMgmt = &pMnode->profileMgmt; @@ -525,6 +459,7 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * pShow->numOfRows = taosHashGetSize(pMgmt->cache->pHashTable); pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbFname, mndShowStr(pShow->type)); return 0; } @@ -567,12 +502,12 @@ static int32_t mndRetrieveConns(SMnodeMsg *pMsg, SShowObj *pShow, char *data, in cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pConn->stime; + *(int64_t *)pWrite = pConn->loginTimeMs; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - if (pConn->lastAccess < pConn->stime) pConn->lastAccess = pConn->stime; - *(int64_t *)pWrite = pConn->lastAccess; + if (pConn->lastAccessTimeMs < pConn->loginTimeMs) pConn->lastAccessTimeMs = pConn->loginTimeMs; + *(int64_t *)pWrite = pConn->lastAccessTimeMs; cols++; numOfRows++; @@ -623,7 +558,7 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * pSchema[cols].bytes = htonl(pShow->bytes[cols]); cols++; - pShow->bytes[cols] = 24; + pShow->bytes[cols] = 22 + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "qid"); pSchema[cols].bytes = htonl(pShow->bytes[cols]); @@ -693,6 +628,7 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * pShow->numOfRows = 1000000; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + strcpy(pMeta->tbFname, mndShowStr(pShow->type)); return 0; } @@ -790,6 +726,7 @@ static int32_t mndRetrieveQueries(SMnodeMsg *pMsg, SShowObj *pShow, char *data, } } + mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); pShow->numOfReads += numOfRows; return numOfRows; } @@ -798,173 +735,3 @@ static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; taosHashCancelIterate(pMgmt->cache->pHashTable, pIter); } - -static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; - SProfileMgmt *pMgmt = &pMnode->profileMgmt; - - SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user); - if (pUser == NULL) return 0; - if (!pUser->superUser) { - mndReleaseUser(pMnode, pUser); - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; - } - mndReleaseUser(pMnode, pUser); - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchema; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "streamId"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "connId"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "user"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "destination"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "ip:port"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "exec"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; - strcpy(pSchema[cols].name, "time(us)"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "cycles"); - pSchema[cols].bytes = htonl(pShow->bytes[cols]); - cols++; - - pMeta->numOfColumns = htonl(cols); - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = 1000000; - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - - return 0; -} - -static int32_t mndRetrieveStreams(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; - int32_t numOfRows = 0; - SConnObj *pConn = NULL; - int32_t cols = 0; - char *pWrite; - void *pIter; - char ipStr[TSDB_IPv4ADDR_LEN + 6]; - - while (numOfRows < rows) { - pIter = mndGetNextConn(pMnode, pShow->pIter, &pConn); - if (pConn == NULL) { - pShow->pIter = pIter; - break; - } - - if (numOfRows + pConn->numOfStreams >= rows) { - mndCancelGetNextConn(pMnode, pIter); - break; - } - - pShow->pIter = pIter; - for (int32_t i = 0; i < pConn->numOfStreams; ++i) { - SStreamDesc *pDesc = pConn->pStreams + i; - cols = 0; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = htobe64(pDesc->streamId); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = htobe64(pConn->id); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConn->user, pShow->bytes[cols]); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->dstTable, pShow->bytes[cols]); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConn->ip), pConn->port); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = htobe64(pDesc->ctime); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = htobe64(pDesc->stime); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = htobe64(pDesc->useconds); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = (int32_t)htobe64(pDesc->num); - cols++; - - numOfRows++; - } - } - - pShow->numOfReads += numOfRows; - return numOfRows; -} - -static void mndCancelGetNextStream(SMnode *pMnode, void *pIter) { - SProfileMgmt *pMgmt = &pMnode->profileMgmt; - taosHashCancelIterate(pMgmt->cache->pHashTable, pIter); -} diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index db6777ebf8129d41fac21b95d373246e96127bb8..41f09e85a99b55637a44388d2bd1106ba43b961d 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -138,7 +138,7 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { ShowMetaFp metaFp = pMgmt->metaFps[type]; if (metaFp == NULL) { terrno = TSDB_CODE_MND_INVALID_MSG_TYPE; - mError("failed to process show-meta msg:%s since no message handle", mndShowStr(type)); + mError("failed to process show-meta msg:%s since %s", mndShowStr(type), terrstr()); return -1; } diff --git a/source/dnode/vnode/tq/CMakeLists.txt b/source/dnode/vnode/tq/CMakeLists.txt index 8d59c7b07a9c3935187ba6b644d7f95f88179776..7cb7499d640b3f1420676dfcbd7e075a52ae4b7d 100644 --- a/source/dnode/vnode/tq/CMakeLists.txt +++ b/source/dnode/vnode/tq/CMakeLists.txt @@ -12,6 +12,7 @@ target_link_libraries( PUBLIC os PUBLIC util PUBLIC common + PUBLIC transport ) if(${BUILD_TEST}) diff --git a/source/dnode/vnode/tq/inc/tqInt.h b/source/dnode/vnode/tq/inc/tqInt.h index 5685a29d03e7dc15a974d9728d0c6ec07d4cceb3..107f5d51038bf5577079c49c40951700c778602a 100644 --- a/source/dnode/vnode/tq/inc/tqInt.h +++ b/source/dnode/vnode/tq/inc/tqInt.h @@ -18,6 +18,7 @@ #include "tq.h" #include "tlog.h" +#include "trpc.h" #ifdef __cplusplus extern "C" { #endif diff --git a/source/dnode/vnode/tq/src/tq.c b/source/dnode/vnode/tq/src/tq.c index 667097e45f0ba482625afac818447c9489ae7f76..5ceb062bf2e5efc94c3b324a26a0ac80c92c5dec 100644 --- a/source/dnode/vnode/tq/src/tq.c +++ b/source/dnode/vnode/tq/src/tq.c @@ -35,7 +35,22 @@ void* tqSerializeItem(STqMsgItem* pItem, void* ptr); const void* tqDeserializeTopic(const void* pBytes, STqTopic* pTopic); const void* tqDeserializeItem(const void* pBytes, STqMsgItem* pItem); -STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemAllocatorFactory* allocFac) { +int tqInit() { + int8_t old = atomic_val_compare_exchange_8(&tqMgmt.inited, 0, 1); + if(old == 1) return 0; + + tqMgmt.timer = taosTmrInit(0, 0, 0, "TQ"); + return 0; +} + +void tqCleanUp() { + int8_t old = atomic_val_compare_exchange_8(&tqMgmt.inited, 1, 0); + if(old == 0) return; + taosTmrStop(tqMgmt.timer); + taosTmrCleanUp(tqMgmt.timer); +} + +STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogHandle* tqLogHandle, SMemAllocatorFactory* allocFac) { STQ* pTq = malloc(sizeof(STQ)); if (pTq == NULL) { terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; @@ -43,9 +58,9 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemA } pTq->path = strdup(path); pTq->tqConfig = tqConfig; - pTq->tqLogReader = tqLogReader; + pTq->tqLogHandle = tqLogHandle; #if 0 - pTq->tqMemRef.pAlloctorFactory = allocFac; + pTq->tqMemRef.pAllocatorFactory = allocFac; pTq->tqMemRef.pAllocator = allocFac->create(allocFac); if (pTq->tqMemRef.pAllocator == NULL) { // TODO: error code of buffer pool @@ -53,16 +68,24 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemA #endif pTq->tqMeta = tqStoreOpen(path, (FTqSerialize)tqSerializeGroup, (FTqDeserialize)tqDeserializeGroup, free, 0); if (pTq->tqMeta == NULL) { - // TODO: free STQ + free(pTq); +#if 0 + allocFac->destroy(allocFac, pTq->tqMemRef.pAllocator); +#endif return NULL; } + return pTq; } + void tqClose(STQ* pTq) { // TODO } -static int tqProtoCheck(STqMsgHead* pMsg) { return pMsg->protoVer == 0; } +static int tqProtoCheck(STqMsgHead* pMsg) { + // TODO + return pMsg->protoVer == 0; +} static int tqAckOneTopic(STqTopic* pTopic, STqOneAck* pAck, STqQueryMsg** ppQuery) { // clean old item and move forward @@ -126,6 +149,13 @@ int tqCreateGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t cId, STqGroup *ppGroup = pGroup; memset(pGroup, 0, sizeof(STqGroup)); + pGroup->topicList = tdListNew(sizeof(STqTopic)); + if(pGroup->topicList == NULL) { + free(pGroup); + return -1; + } + *ppGroup = pGroup; + return 0; } @@ -154,46 +184,55 @@ int tqDropGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t cId) { return 0; } -static int tqFetch(STqGroup* pGroup, void** msg) { - STqList* head = pGroup->head; - STqList* node = head; +static int tqFetch(STqGroup* pGroup, STqConsumeRsp** pRsp) { + STqList* pHead = pGroup->head; + STqList* pNode = pHead; int totSize = 0; + int numOfMsgs = 0; // TODO: make it a macro - int sizeLimit = 4 * 1024; - STqMsgContent* buffer = malloc(sizeLimit); - if (buffer == NULL) { - // TODO:memory insufficient + int sizeLimit = 4 * 1024; + + void* ptr = realloc(*pRsp, sizeof(STqConsumeRsp) + sizeLimit); + if (ptr == NULL) { + terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; return -1; } + *pRsp = ptr; + STqMsgContent* buffer = (*pRsp)->msgs; + // iterate the list to get msgs of all topics // until all topic iterated or msgs over sizeLimit - while (node->next) { - node = node->next; - STqTopic* topicHandle = &node->topic; - int idx = topicHandle->nextConsumeOffset % TQ_BUFFER_SIZE; - if (topicHandle->buffer[idx].content != NULL && topicHandle->buffer[idx].offset == topicHandle->nextConsumeOffset) { - totSize += topicHandle->buffer[idx].size; + while (pNode->next) { + pNode = pNode->next; + STqTopic* pTopic = &pNode->topic; + int idx = pTopic->nextConsumeOffset % TQ_BUFFER_SIZE; + if (pTopic->buffer[idx].content != NULL && pTopic->buffer[idx].offset == pTopic->nextConsumeOffset) { + totSize += pTopic->buffer[idx].size; if (totSize > sizeLimit) { - void* ptr = realloc(buffer, totSize); + void* ptr = realloc(*pRsp, sizeof(STqConsumeRsp) + totSize); if (ptr == NULL) { - totSize -= topicHandle->buffer[idx].size; - // TODO:memory insufficient + totSize -= pTopic->buffer[idx].size; + terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; // return msgs already copied break; } + *pRsp = ptr; + break; } - *((int64_t*)buffer) = topicHandle->topicId; + *((int64_t*)buffer) = pTopic->topicId; buffer = POINTER_SHIFT(buffer, sizeof(int64_t)); - *((int64_t*)buffer) = topicHandle->buffer[idx].size; + *((int64_t*)buffer) = pTopic->buffer[idx].size; buffer = POINTER_SHIFT(buffer, sizeof(int64_t)); - memcpy(buffer, topicHandle->buffer[idx].content, topicHandle->buffer[idx].size); - buffer = POINTER_SHIFT(buffer, topicHandle->buffer[idx].size); + memcpy(buffer, pTopic->buffer[idx].content, pTopic->buffer[idx].size); + buffer = POINTER_SHIFT(buffer, pTopic->buffer[idx].size); + numOfMsgs++; if (totSize > sizeLimit) { break; } } } - return totSize; + (*pRsp)->bodySize = totSize; + return numOfMsgs; } STqGroup* tqGetGroup(STQ* pTq, int64_t clientId) { return tqHandleGet(pTq->tqMeta, clientId); } @@ -275,28 +314,130 @@ int tqSetCursor(STQ* pTq, STqSetCurReq* pMsg) { return 0; } -int tqConsume(STQ* pTq, STqConsumeReq* pMsg) { +// temporary +int tqProcessCMsg(STQ* pTq, STqConsumeReq* pMsg, STqRspHandle* pRsp) { int64_t clientId = pMsg->head.clientId; STqGroup* pGroup = tqGetGroup(pTq, clientId); if (pGroup == NULL) { terrno = TSDB_CODE_TQ_GROUP_NOT_SET; return -1; } + pGroup->rspHandle.handle = pRsp->handle; + pGroup->rspHandle.ahandle = pRsp->ahandle; - STqConsumeRsp* pRsp = (STqConsumeRsp*)pMsg; - int numOfMsgs = tqFetch(pGroup, (void**)&pRsp->msgs); - if (numOfMsgs < 0) { + return 0; +} + +int tqConsume(STQ* pTq, SRpcMsg* pReq, SRpcMsg** pRsp) { + STqConsumeReq *pMsg = pReq->pCont; + int64_t clientId = pMsg->head.clientId; + STqGroup* pGroup = tqGetGroup(pTq, clientId); + if (pGroup == NULL) { + terrno = TSDB_CODE_TQ_GROUP_NOT_SET; return -1; } - if (numOfMsgs == 0) { + + SList* topicList = pGroup->topicList; + + int totSize = 0; + int numOfMsgs = 0; + int sizeLimit = 4096; + + + STqConsumeRsp *pCsmRsp = (*pRsp)->pCont; + void* ptr = realloc((*pRsp)->pCont, sizeof(STqConsumeRsp) + sizeLimit); + if (ptr == NULL) { + terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; + return -1; + } + (*pRsp)->pCont = ptr; + + SListIter iter; + tdListInitIter(topicList, &iter, TD_LIST_FORWARD); + + STqMsgContent* buffer = NULL; + SArray* pArray = taosArrayInit(0, sizeof(void*)); + + SListNode *pn; + while((pn = tdListNext(&iter)) != NULL) { + STqTopic* pTopic = *(STqTopic**)pn->data; + int idx = pTopic->floatingCursor % TQ_BUFFER_SIZE; + STqMsgItem* pItem = &pTopic->buffer[idx]; + if (pItem->content != NULL && pItem->offset == pTopic->floatingCursor) { + if(pItem->status == TQ_ITEM_READY) { + //if has data + totSize += pTopic->buffer[idx].size; + if (totSize > sizeLimit) { + void* ptr = realloc((*pRsp)->pCont, sizeof(STqConsumeRsp) + totSize); + if (ptr == NULL) { + totSize -= pTopic->buffer[idx].size; + terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; + // return msgs already copied + break; + } + (*pRsp)->pCont = ptr; + break; + } + *((int64_t*)buffer) = htobe64(pTopic->topicId); + buffer = POINTER_SHIFT(buffer, sizeof(int64_t)); + *((int64_t*)buffer) = htobe64(pTopic->buffer[idx].size); + buffer = POINTER_SHIFT(buffer, sizeof(int64_t)); + memcpy(buffer, pTopic->buffer[idx].content, pTopic->buffer[idx].size); + buffer = POINTER_SHIFT(buffer, pTopic->buffer[idx].size); + numOfMsgs++; + if (totSize > sizeLimit) { + break; + } + } else if(pItem->status == TQ_ITEM_PROCESS) { + //if not have data but in process + + } else if(pItem->status == TQ_ITEM_EMPTY){ + //if not have data and not in process + int32_t old = atomic_val_compare_exchange_32(&pItem->status, TQ_ITEM_EMPTY, TQ_ITEM_PROCESS); + if(old != TQ_ITEM_EMPTY) { + continue; + } + pItem->offset = pTopic->floatingCursor; + taosArrayPush(pArray, &pItem); + } else { + ASSERT(0); + } + } + } + + if (numOfMsgs > 0) { + // set code and other msg + rpcSendResponse(*pRsp); + } else { // most recent data has been fetched // enable timer for blocking wait - // once new data written during wait time - // launch query and response + // once new data written when waiting, launch query and rsp } // fetched a num of msgs, rpc response + for(int i = 0; i < pArray->size; i++) { + STqMsgItem* pItem = taosArrayGet(pArray, i); + + //read from wal + void* raw = NULL; + /*int code = pTq->tqLogReader->logRead(, &raw, pItem->offset);*/ + int code = pTq->tqLogHandle->logRead(pItem->pTopic->logReader, &raw, pItem->offset); + if(code < 0) { + //TODO: error + } + //get msgType + //if submitblk + pItem->executor->assign(pItem->executor->runtimeEnv, raw); + SSDataBlock* content = pItem->executor->exec(pItem->executor->runtimeEnv); + pItem->content = content; + //if other type, send just put into buffer + /*pItem->content = raw;*/ + + int32_t old = atomic_val_compare_exchange_32(&pItem->status, TQ_ITEM_PROCESS, TQ_ITEM_READY); + ASSERT(old == TQ_ITEM_PROCESS); + } + taosArrayDestroy(pArray); return 0; } @@ -378,10 +519,10 @@ void* tqSerializeTopic(STqTopic* pTopic, void* ptr) { ptr = POINTER_SHIFT(ptr, sizeof(int64_t)); *(int64_t*)ptr = pTopic->topicId; ptr = POINTER_SHIFT(ptr, sizeof(int64_t)); - *(int32_t*)ptr = pTopic->head; - ptr = POINTER_SHIFT(ptr, sizeof(int32_t)); - *(int32_t*)ptr = pTopic->tail; - ptr = POINTER_SHIFT(ptr, sizeof(int32_t)); + /**(int32_t*)ptr = pTopic->head;*/ + /*ptr = POINTER_SHIFT(ptr, sizeof(int32_t));*/ + /**(int32_t*)ptr = pTopic->tail;*/ + /*ptr = POINTER_SHIFT(ptr, sizeof(int32_t));*/ for (int i = 0; i < TQ_BUFFER_SIZE; i++) { ptr = tqSerializeItem(&pTopic->buffer[i], ptr); } @@ -435,10 +576,10 @@ const void* tqDeserializeTopic(const void* pBytes, STqTopic* topic) { ptr = POINTER_SHIFT(ptr, sizeof(int64_t)); topic->topicId = *(int64_t*)ptr; ptr = POINTER_SHIFT(ptr, sizeof(int64_t)); - topic->head = *(int32_t*)ptr; - ptr = POINTER_SHIFT(ptr, sizeof(int32_t)); - topic->tail = *(int32_t*)ptr; - ptr = POINTER_SHIFT(ptr, sizeof(int32_t)); + /*topic->head = *(int32_t*)ptr;*/ + /*ptr = POINTER_SHIFT(ptr, sizeof(int32_t));*/ + /*topic->tail = *(int32_t*)ptr;*/ + /*ptr = POINTER_SHIFT(ptr, sizeof(int32_t));*/ for (int i = 0; i < TQ_BUFFER_SIZE; i++) { ptr = tqDeserializeItem(ptr, &topic->buffer[i]); } diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 7b26079f11da10c538514cb4161eb69ba0f3d792..7f2ddb5723eac9c8e6d6cbd279c05ad1ba2506c2 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -59,8 +59,6 @@ typedef struct SCatalogMgmt { typedef uint32_t (*tableNameHashFp)(const char *, uint32_t); -extern int32_t ctgDebugFlag; - #define ctgFatal(...) do { if (ctgDebugFlag & DEBUG_FATAL) { taosPrintLog("CTG FATAL ", ctgDebugFlag, __VA_ARGS__); }} while(0) #define ctgError(...) do { if (ctgDebugFlag & DEBUG_ERROR) { taosPrintLog("CTG ERROR ", ctgDebugFlag, __VA_ARGS__); }} while(0) #define ctgWarn(...) do { if (ctgDebugFlag & DEBUG_WARN) { taosPrintLog("CTG WARN ", ctgDebugFlag, __VA_ARGS__); }} while(0) @@ -75,7 +73,6 @@ extern int32_t ctgDebugFlag; #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) - #ifdef __cplusplus } #endif diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 1134c7763a88c22e80ad523cbdb63b84313f1872..bc7a8b8aff670a5e8a249f4911d47e0b0f244085 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -371,7 +371,7 @@ int32_t catalogInit(SCatalogCfg *cfg) { return TSDB_CODE_SUCCESS; } -int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) { +int32_t catalogGetHandle(const char* clusterId , struct SCatalog** catalogHandle) { if (NULL == clusterId || NULL == catalogHandle) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } @@ -565,12 +565,12 @@ _return: } -int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pRpc, const SEpSet *pMgmtEps, const char *pDBName, const char *pTableName, SVgroupInfo *pVgroup) { +int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pTransporter, const SEpSet *pMgmtEps, const char *pDBName, const char *pTableName, SVgroupInfo *pVgroup) { SDBVgroupInfo dbInfo = {0}; int32_t code = 0; int32_t vgId = 0; - CTG_ERR_RET(catalogGetDBVgroup(pCatalog, pRpc, pMgmtEps, pDBName, false, &dbInfo)); + CTG_ERR_RET(catalogGetDBVgroup(pCatalog, pTransporter, pMgmtEps, pDBName, false, &dbInfo)); if (dbInfo.vgVersion < 0 || NULL == dbInfo.vgInfo) { ctgError("db[%s] vgroup cache invalid, vgroup version:%d, vgInfo:%p", pDBName, dbInfo.vgVersion, dbInfo.vgInfo); @@ -605,7 +605,7 @@ int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* p SName *name = taosArrayGet(pReq->pTableName, i); STableMeta *pTableMeta = NULL; - snprintf(dbName, sizeof(dbName), "%s.%s", name->acctId, name->dbname); + snprintf(dbName, sizeof(dbName), "%d.%s", name->acctId, name->dbname); CTG_ERR_JRET(catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, dbName, name->tname, &pTableMeta)); diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 29c80ae9ec05453dd23605c39d43fa562c2aa2d9..22b5b7adc4d78c563096c0d1e9765d4689a01993 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -29,6 +29,8 @@ #include "catalog.h" #include "tep.h" #include "trpc.h" +#include "stub.h" +#include "addr_any.h" typedef struct SAppInstInfo { int64_t numOfConns; @@ -86,6 +88,27 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { ASSERT_EQ(rpcRsp.code, 0); } +void __rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + SUseDbRsp *rspMsg = NULL; //todo + + return; +} + + +void initTestEnv() { + static Stub stub; + stub.set(rpcSendRecv, __rpcSendRecv); + { + AddrAny any("libtransport.so"); + std::map result; + any.get_global_func_addr_dynsym("^rpcSendRecv$", result); + for (const auto& f : result) { + stub.set(f.second, __rpcSendRecv); + } + } +} + + } TEST(testCase, normalCase) { @@ -99,7 +122,7 @@ TEST(testCase, normalCase) { void *mockPointer = (void *)0x1; SVgroupInfo vgInfo = {0}; - msgInit(); + initQueryModuleMsgHandle(); sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/index_fst_counting_writer.h index db1f063af3c760ca64a0813b81c2d86902307667..ba0bd52e10280cd0139a6dc852b61c7f75b91a77 100644 --- a/source/libs/index/inc/index_fst_counting_writer.h +++ b/source/libs/index/inc/index_fst_counting_writer.h @@ -31,6 +31,7 @@ typedef struct WriterCtx { int (*write)(struct WriterCtx* ctx, uint8_t* buf, int len); int (*read)(struct WriterCtx* ctx, uint8_t* buf, int len); int (*flush)(struct WriterCtx* ctx); + int (*readFrom)(struct WriterCtx* ctx, uint8_t* buf, int len, int32_t offset); WriterType type; union { struct { @@ -48,6 +49,7 @@ typedef struct WriterCtx { static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len); static int writeCtxDoRead(WriterCtx* ctx, uint8_t* buf, int len); +static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t offset); static int writeCtxDoFlush(WriterCtx* ctx); WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity); diff --git a/source/libs/index/inc/index_tfile.h b/source/libs/index/inc/index_tfile.h index 4da80a6dbeb043ad5bc9c23a33f35380b82fbdd9..416b10bd14c63ebea97b40d80175f033e0e3d7f8 100644 --- a/source/libs/index/inc/index_tfile.h +++ b/source/libs/index/inc/index_tfile.h @@ -27,23 +27,31 @@ extern "C" { #endif // tfile header content -// |<---suid--->|<---version--->|<--colLen-->|<-colName->|<---type-->| -// |<-uint64_t->|<---int32_t--->|<--int32_t->|<-colLen-->|<-uint8_t->| +// |<---suid--->|<---version--->|<-------colName------>|<---type-->|<--fstOffset->| +// |<-uint64_t->|<---int32_t--->|<--TSDB_COL_NAME_LEN-->|<-uint8_t->|<---int32_t-->| +#pragma pack(push, 1) typedef struct TFileHeader { uint64_t suid; int32_t version; - char colName[128]; // + char colName[TSDB_COL_NAME_LEN]; // uint8_t colType; + int32_t fstOffset; } TFileHeader; +#pragma pack(pop) -#define TFILE_HEADER_SIZE (sizeof(TFileHeader) + sizeof(uint32_t)) -#define TFILE_HADER_PRE_SIZE (sizeof(uint64_t) + sizeof(int32_t) + sizeof(int32_t)) +#define TFILE_HEADER_SIZE (sizeof(TFileHeader)) +#define TFILE_HEADER_NO_FST (TFILE_HEADER_SIZE - sizeof(int32_t)) + +typedef struct TFileValue { + char* colVal; // null terminated + SArray* tableId; + int32_t offset; +} TFileValue; typedef struct TFileCacheKey { uint64_t suid; uint8_t colType; - int32_t version; char* colName; int32_t nColName; } TFileCacheKey; @@ -63,6 +71,7 @@ typedef struct TFileWriter { uint32_t offset; } TFileWriter; +// multi reader and single write typedef struct TFileReader { T_REF_DECLARE() Fst* fst; diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index e88cecfd623c86d39ae28c9906c976f60c27927f..f0546afaf591f0f815cb4802f70f73e85ae010c7 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -41,7 +41,7 @@ static pthread_once_t isInit = PTHREAD_ONCE_INIT; static void indexInit(); static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* term, SArray** result); -static int indexMergeCacheIntoTindex(SIndex* sIdx); +static int indexFlushCacheToTindex(SIndex* sIdx); static void indexInterResultsDestroy(SArray* results); static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType, SArray* finalResult); @@ -49,9 +49,7 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oTyp int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { pthread_once(&isInit, indexInit); SIndex* sIdx = calloc(1, sizeof(SIndex)); - if (sIdx == NULL) { - return -1; - } + if (sIdx == NULL) { return -1; } #ifdef USE_LUCENE index_t* index = index_open(path); @@ -131,9 +129,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { int32_t colId = fi->colId; int32_t version = index->cVersion; int ret = indexCachePut(index->cache, p, colId, version, uid); - if (ret != 0) { - return ret; - } + if (ret != 0) { return ret; } } #endif @@ -221,9 +217,7 @@ void indexOptsDestroy(SIndexOpts* opts){ SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType opera) { SIndexMultiTermQuery* p = (SIndexMultiTermQuery*)malloc(sizeof(SIndexMultiTermQuery)); - if (p == NULL) { - return NULL; - } + if (p == NULL) { return NULL; } p->opera = opera; p->query = taosArrayInit(4, sizeof(SIndexTermQuery)); return p; @@ -250,9 +244,7 @@ SIndexTerm* indexTermCreate(int64_t suid, const char* colVal, int32_t nColVal) { SIndexTerm* t = (SIndexTerm*)calloc(1, (sizeof(SIndexTerm))); - if (t == NULL) { - return NULL; - } + if (t == NULL) { return NULL; } t->suid = suid; t->operType = oper; @@ -332,9 +324,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result return 0; } static void indexInterResultsDestroy(SArray* results) { - if (results == NULL) { - return; - } + if (results == NULL) { return; } size_t sz = taosArrayGetSize(results); for (size_t i = 0; i < sz; i++) { @@ -363,10 +353,10 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType } return 0; } -static int indexMergeCacheIntoTindex(SIndex* sIdx) { - if (sIdx == NULL) { - return -1; - } +static int indexFlushCacheToTindex(SIndex* sIdx) { + if (sIdx == NULL) { return -1; } + indexWarn("suid %" PRIu64 " merge cache into tindex", sIdx->suid); + return 0; } diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index 6170642707434b4daaf22bc14c9f8058f841e611..bb6a5e048af60a4822716395baa094a1c9cec600 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -151,8 +151,7 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t EIndexQueryType qtype = query->qType; int32_t keyLen = CACHE_KEY_LEN(term); - - char* buf = calloc(1, keyLen); + char* buf = calloc(1, keyLen); if (qtype == QUERY_TERM) { // } else if (qtype == QUERY_PREFIX) { diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index 60d717efc6e6b6f87d122c252400242419bfe493..c8fbdd7690bc3ec0243a01dab89fb53d959854f2 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -39,6 +39,17 @@ static int writeCtxDoRead(WriterCtx* ctx, uint8_t* buf, int len) { return nRead; } +static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t offset) { + int nRead = 0; + if (ctx->type == TFile) { + tfLseek(ctx->file.fd, offset, 0); + nRead = tfRead(ctx->file.fd, buf, len); + } else { + // refactor later + assert(0); + } + return nRead; +} static int writeCtxDoFlush(WriterCtx* ctx) { if (ctx->type == TFile) { // tfFsync(ctx->fd); @@ -58,9 +69,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int // ugly code, refactor later ctx->file.readOnly = readOnly; if (readOnly == false) { - ctx->file.fd = tfOpenCreateWriteAppend(tmpFile); + ctx->file.fd = tfOpenCreateWriteAppend(path); } else { - ctx->file.fd = tfOpenReadWrite(tmpFile); + ctx->file.fd = tfOpenReadWrite(path); } if (ctx->file.fd < 0) { indexError("open file error %d", errno); @@ -73,6 +84,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int ctx->write = writeCtxDoWrite; ctx->read = writeCtxDoRead; ctx->flush = writeCtxDoFlush; + ctx->readFrom = writeCtxDoReadFrom; ctx->offset = 0; ctx->limit = capacity; @@ -81,6 +93,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int END: if (ctx->type == TMemory) { free(ctx->mem.buf); } free(ctx); + return NULL; } void writerCtxDestroy(WriterCtx* ctx) { if (ctx->type == TMemory) { diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index fb1974a04c69380cef97c52cb41c5485c9a2e5f1..e02a3e03276e659e7decd0ff17d94b7a8e4d9162 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -25,130 +25,27 @@ #define TF_TABLE_TATOAL_SIZE(sz) (sizeof(sz) + sz * sizeof(uint64_t)) -typedef struct TFileValue { - char* colVal; // null terminated - SArray* tableId; - int32_t offset; -} TFileValue; - -// static tfileGetCompareFunc(uint8_t byte) {} -static int tfileValueCompare(const void* a, const void* b, const void* param) { - __compar_fn_t fn = *(__compar_fn_t*)param; - - TFileValue* av = (TFileValue*)a; - TFileValue* bv = (TFileValue*)b; - - return fn(av->colVal, bv->colVal); -} -static void tfileSerialTableIdsToBuf(char* buf, SArray* tableIds) { - int tbSz = taosArrayGetSize(tableIds); - SERIALIZE_VAR_TO_BUF(buf, tbSz, int32_t); - for (size_t i = 0; i < tbSz; i++) { - uint64_t* v = taosArrayGet(tableIds, i); - SERIALIZE_VAR_TO_BUF(buf, *v, uint64_t); - } -} -static FORCE_INLINE int tfileWriteHeader(TFileWriter* writer) { - char buf[TFILE_HEADER_SIZE] = {0}; - char* p = buf; - - TFileHeader* header = &writer->header; - SERIALIZE_MEM_TO_BUF(p, header, suid); - SERIALIZE_MEM_TO_BUF(p, header, version); - SERIALIZE_VAR_TO_BUF(p, strlen(header->colName), int32_t); - - SERIALIZE_STR_MEM_TO_BUF(p, header, colName, strlen(header->colName)); - SERIALIZE_MEM_TO_BUF(p, header, colType); - int offset = p - buf; - int nwrite = writer->ctx->write(writer->ctx, buf, offset); - if (offset != nwrite) { return -1; } - writer->offset = offset; - return 0; -} -static int tfileWriteData(TFileWriter* write, TFileValue* tval) { - TFileHeader* header = &write->header; - uint8_t colType = header->colType; - if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { - FstSlice key = fstSliceCreate((uint8_t*)(tval->colVal), (size_t)strlen(tval->colVal)); - if (fstBuilderInsert(write->fb, key, tval->offset)) { - fstSliceDestroy(&key); - return 0; - } - fstSliceDestroy(&key); - return -1; - } else { - // handle other type later - } -} -static FORCE_INLINE int tfileReadLoadHeader(TFileReader* reader) { - // TODO simple tfile header later - char buf[TFILE_HADER_PRE_SIZE]; - char* p = buf; - - int64_t nread = reader->ctx->read(reader->ctx, buf, TFILE_HADER_PRE_SIZE); - assert(nread == TFILE_HADER_PRE_SIZE); - - TFileHeader* header = &reader->header; - memcpy(&header->suid, p, sizeof(header->suid)); - p += sizeof(header->suid); - - memcpy(&header->version, p, sizeof(header->version)); - p += sizeof(header->version); - - int32_t colLen = 0; - memcpy(&colLen, p, sizeof(colLen)); - assert(colLen < sizeof(header->colName)); - nread = reader->ctx->read(reader->ctx, header->colName, colLen); - assert(nread == colLen); - - nread = reader->ctx->read(reader->ctx, &header->colType, sizeof(header->colType)); - return 0; -} - -static int tfileGetFileList(const char* path, SArray* result) { - DIR* dir = opendir(path); - if (NULL == dir) { return -1; } - - struct dirent* entry; - while ((entry = readdir(dir)) != NULL) { - size_t len = strlen(entry->d_name); - char* buf = calloc(1, len + 1); - memcpy(buf, entry->d_name, len); - taosArrayPush(result, &buf); - } - closedir(dir); - return 0; -} -static void tfileDestroyFileName(void* elem) { - char* p = *(char**)elem; - free(p); -} -static int tfileCompare(const void* a, const void* b) { - const char* aName = *(char**)a; - const char* bName = *(char**)b; - - size_t aLen = strlen(aName); - size_t bLen = strlen(bName); - - return strncmp(aName, bName, aLen > bLen ? aLen : bLen); -} -// tfile name suid-colId-version.tindex -static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId, int* version) { - if (3 == sscanf(filename, "%" PRIu64 "-%d-%d.tindex", suid, colId, version)) { - // read suid & colid & version success - return 0; - } - 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_MEM_TO_BUF(buf, key, version); - SERIALIZE_VAR_TO_BUF(buf, '_', char); - SERIALIZE_STR_MEM_TO_BUF(buf, key, colName, key->nColName); -} +static int tfileStrCompare(const void* a, const void* b); +static int tfileValueCompare(const void* a, const void* b, const void* param); +static void tfileSerialTableIdsToBuf(char* buf, SArray* tableIds); + +static int tfileWriteHeader(TFileWriter* writer); +static int tfileWriteFstOffset(TFileWriter* tw, int32_t offset); +static int tfileWriteData(TFileWriter* write, TFileValue* tval); + +static int tfileReadLoadHeader(TFileReader* reader); +static int tfileReadLoadFst(TFileReader* reader); +static int tfileReadLoadTableIds(TFileReader* reader, int32_t offset, SArray* result); +static void tfileReadRef(TFileReader* reader); +static void tfileReadUnRef(TFileReader* reader); + +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 void tfileSerialCacheKey(TFileCacheKey* key, char* buf); TFileCache* tfileCacheCreate(const char* path) { TFileCache* tcache = calloc(1, sizeof(TFileCache)); @@ -160,6 +57,8 @@ TFileCache* tfileCacheCreate(const char* path) { SArray* files = taosArrayInit(4, sizeof(void*)); tfileGetFileList(path, files); taosArraySort(files, tfileCompare); + tfileRmExpireFile(files); + uint64_t suid; int32_t colId, version; for (size_t i = 0; i < taosArrayGetSize(files); i++) { @@ -168,25 +67,29 @@ TFileCache* tfileCacheCreate(const char* path) { indexInfo("try parse invalid file: %s, skip it", file); continue; } + WriterCtx* wc = writerCtxCreate(TFile, file, true, 1024 * 64); if (wc == NULL) { indexError("failed to open index: %s", file); goto End; } + TFileReader* reader = tfileReaderCreate(wc); if (0 != tfileReadLoadHeader(reader)) { tfileReaderDestroy(reader); - indexError("failed to load index header, index Id: %s", file); + indexError("failed to load index header, index file: %s", file); goto End; } - // loader fst and validate it + if (0 != tfileReadLoadFst(reader)) { + tfileReaderDestroy(reader); + indexError("failed to load index fst, index file: %s", file); + goto End; + } + tfileReadRef(reader); + // loader fst and validate it TFileHeader* header = &reader->header; - TFileCacheKey key = {.suid = header->suid, - .version = header->version, - .colName = header->colName, - .nColName = strlen(header->colName), - .colType = header->colType}; + TFileCacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; char buf[128] = {0}; tfileSerialCacheKey(&key, buf); @@ -208,7 +111,7 @@ void tfileCacheDestroy(TFileCache* tcache) { TFileReader* p = *reader; indexInfo("drop table cache suid: %" PRIu64 ", colName: %s, colType: %d", p->header.suid, p->header.colName, p->header.colType); - tfileReaderDestroy(p); + tfileReadUnRef(p); reader = taosHashIterate(tcache->tableCache, reader); } taosHashCleanup(tcache->tableCache); @@ -218,12 +121,24 @@ void tfileCacheDestroy(TFileCache* tcache) { TFileReader* tfileCacheGet(TFileCache* tcache, TFileCacheKey* key) { char buf[128] = {0}; tfileSerialCacheKey(key, buf); + TFileReader* reader = taosHashGet(tcache->tableCache, buf, strlen(buf)); + tfileReadRef(reader); + return reader; } void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader) { char buf[128] = {0}; tfileSerialCacheKey(key, buf); + // remove last version index reader + TFileReader** p = taosHashGet(tcache->tableCache, buf, strlen(buf)); + if (*p != NULL) { + TFileReader* oldReader = *p; + taosHashRemove(tcache->tableCache, buf, strlen(buf)); + tfileReadUnRef(oldReader); + } + + tfileReadRef(reader); taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void*)); return; } @@ -239,27 +154,35 @@ TFileReader* tfileReaderCreate(WriterCtx* ctx) { void tfileReaderDestroy(TFileReader* reader) { if (reader == NULL) { return; } // T_REF_INC(reader); + fstDestroy(reader->fst); writerCtxDestroy(reader->ctx); free(reader); } int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SArray* result) { - SIndexTerm* term = query->term; + SIndexTerm* term = query->term; + EIndexQueryType qtype = query->qType; + + int ret = -1; // refactor to callback later - if (query->qType == QUERY_TERM) { + if (qtype == QUERY_TERM) { uint64_t offset; FstSlice key = fstSliceCreate(term->colVal, term->nColVal); if (fstGet(reader->fst, &key, &offset)) { - // + indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex", term->suid, term->colName, term->colVal); + ret = tfileReadLoadTableIds(reader, offset, result); } else { - indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found in tindex", term->suid, term->colName, term->colVal); + indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName, term->colVal); } - return 0; - } else if (query->qType == QUERY_PREFIX) { - // + fstSliceDestroy(&key); + } else if (qtype == QUERY_PREFIX) { + // handle later // + } else { + // handle later } - return 0; + tfileReadUnRef(reader); + return ret; } TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) { @@ -282,18 +205,41 @@ TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) { tw->ctx = ctx; tw->header = *header; tfileWriteHeader(tw); + tw->fb = fstBuilderCreate(ctx, 0); + if (tw->fb == NULL) { + tfileWriterDestroy(tw); + return NULL; + } return tw; } -int TFileWriterPut(TFileWriter* tw, void* data) { +int tfileWriterPut(TFileWriter* tw, void* data) { // sort by coltype and write to tindex - __compar_fn_t fn = getComparFunc(tw->header.colType, 0); + __compar_fn_t fn; + + int8_t colType = tw->header.colType; + if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { + fn = tfileStrCompare; + } else { + fn = getComparFunc(colType, 0); + } taosArraySortPWithExt((SArray*)(data), tfileValueCompare, &fn); int32_t bufLimit = 4096, offset = 0; - char* buf = calloc(1, sizeof(bufLimit)); + char* buf = calloc(1, sizeof(char) * bufLimit); char* p = buf; int32_t sz = taosArrayGetSize((SArray*)data); + int32_t fstOffset = tw->offset; + + // ugly code, refactor later + for (size_t i = 0; i < sz; i++) { + TFileValue* v = taosArrayGetP((SArray*)data, i); + + int32_t tbsz = taosArrayGetSize(v->tableId); + fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); + } + tfileWriteFstOffset(tw, fstOffset); + for (size_t i = 0; i < sz; i++) { TFileValue* v = taosArrayGetP((SArray*)data, i); @@ -311,7 +257,7 @@ int TFileWriterPut(TFileWriter* tw, void* data) { tfileSerialTableIdsToBuf(p, v->tableId); offset += ttsz; p = buf + offset; - // set up value offset and + // set up value offset v->offset = tw->offset; tw->offset += ttsz; } @@ -319,6 +265,7 @@ int TFileWriterPut(TFileWriter* tw, void* data) { // write reversed data in buf to tindex tw->ctx->write(tw->ctx, buf, offset); } + tfree(buf); // write fst for (size_t i = 0; i < sz; i++) { @@ -326,11 +273,11 @@ int TFileWriterPut(TFileWriter* tw, void* data) { TFileValue* v = taosArrayGetP((SArray*)data, i); if (tfileWriteData(tw, v) == 0) { // - // } } - - tfree(buf); + fstBuilderFinish(tw->fb); + fstBuilderDestroy(tw->fb); + tw->fb = NULL; return 0; } void tfileWriterDestroy(TFileWriter* tw) { @@ -352,17 +299,184 @@ void IndexTFileDestroy(IndexTFile* tfile) { } int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { - if (tfile == NULL) { return -1; } + int ret = -1; + if (tfile == NULL) { return ret; } IndexTFile* pTfile = (IndexTFile*)tfile; SIndexTerm* term = query->term; - TFileCacheKey key = {.suid = term->suid, .colType = term->colType, .version = 0, .colName = term->colName, .nColName = term->nColName}; + TFileCacheKey key = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; + TFileReader* reader = tfileCacheGet(pTfile->cache, &key); - TFileReader* reader = tfileCacheGet(pTfile->cache, &key); return tfileReaderSearch(reader, query, result); } int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) { - TFileWriterOpt wOpt = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName, .version = 1}; + // TFileWriterOpt wOpt = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName, .version = + // 1}; + + return 0; +} + +static int tfileStrCompare(const void* a, const void* b) { + int ret = strcmp((char*)a, (char*)b); + if (ret == 0) { return ret; } + return ret < 0 ? -1 : 1; +} + +static int tfileValueCompare(const void* a, const void* b, const void* param) { + __compar_fn_t fn = *(__compar_fn_t*)param; + + TFileValue* av = (TFileValue*)a; + TFileValue* bv = (TFileValue*)b; + + return fn(av->colVal, bv->colVal); +} +static void tfileSerialTableIdsToBuf(char* buf, SArray* ids) { + int sz = taosArrayGetSize(ids); + SERIALIZE_VAR_TO_BUF(buf, sz, int32_t); + for (size_t i = 0; i < sz; i++) { + uint64_t* v = taosArrayGet(ids, i); + SERIALIZE_VAR_TO_BUF(buf, *v, uint64_t); + } +} + +static int tfileWriteFstOffset(TFileWriter* tw, int32_t offset) { + int32_t fstOffset = offset + sizeof(tw->header.fstOffset); + tw->header.fstOffset = fstOffset; + if (sizeof(fstOffset) != tw->ctx->write(tw->ctx, (char*)&fstOffset, sizeof(fstOffset))) { return -1; } + return 0; +} +static int tfileWriteHeader(TFileWriter* writer) { + char buf[TFILE_HEADER_NO_FST] = {0}; + + TFileHeader* header = &writer->header; + memcpy(buf, (char*)header, sizeof(buf)); + + int nwrite = writer->ctx->write(writer->ctx, buf, sizeof(buf)); + if (sizeof(buf) != nwrite) { return -1; } + writer->offset = nwrite; + return 0; +} +static int tfileWriteData(TFileWriter* write, TFileValue* tval) { + TFileHeader* header = &write->header; + uint8_t colType = header->colType; + if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { + FstSlice key = fstSliceCreate((uint8_t*)(tval->colVal), (size_t)strlen(tval->colVal)); + if (fstBuilderInsert(write->fb, key, tval->offset)) { + fstSliceDestroy(&key); + return 0; + } + fstSliceDestroy(&key); + return -1; + } else { + // handle other type later + } + return 0; +} +static int tfileReadLoadHeader(TFileReader* reader) { + // TODO simple tfile header later + char buf[TFILE_HEADER_SIZE] = {0}; + + int64_t nread = reader->ctx->read(reader->ctx, buf, sizeof(buf)); + assert(nread == sizeof(buf)); + memcpy(&reader->header, buf, sizeof(buf)); + return 0; +} +static int tfileReadLoadFst(TFileReader* reader) { + // current load fst into memory, refactor it later + static int FST_MAX_SIZE = 16 * 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); + // we assuse fst size less than FST_MAX_SIZE + assert(nread > 0 && nread < FST_MAX_SIZE); + + FstSlice st = fstSliceCreate((uint8_t*)buf, nread); + reader->fst = fstCreate(&st); + free(buf); + fstSliceDestroy(&st); + return reader->fst == NULL ? 0 : -1; +} +static int tfileReadLoadTableIds(TFileReader* reader, int32_t offset, SArray* result) { + int32_t nid; + WriterCtx* ctx = reader->ctx; + + int32_t nread = ctx->readFrom(ctx, (char*)&nid, sizeof(nid), offset); + assert(sizeof(nid) == nread); + + int32_t total = sizeof(uint64_t) * nid; + char* buf = calloc(1, total); + if (buf == NULL) { return -1; } + + nread = ctx->read(ctx, buf, total); + assert(total == nread); + + for (int32_t i = 0; i < nid; i++) { + taosArrayPush(result, (uint64_t*)buf + i); + } + free(buf); + return 0; +} +static void tfileReadRef(TFileReader* reader) { + int ref = T_REF_INC(reader); + UNUSED(ref); +} + +static void tfileReadUnRef(TFileReader* reader) { + int ref = T_REF_DEC(reader); + if (ref == 0) { tfileReaderDestroy(reader); } +} + +static int tfileGetFileList(const char* path, SArray* result) { + DIR* dir = opendir(path); + if (NULL == dir) { return -1; } + + struct dirent* entry; + while ((entry = readdir(dir)) != NULL) { + size_t len = strlen(entry->d_name); + char* buf = calloc(1, len + 1); + memcpy(buf, entry->d_name, len); + taosArrayPush(result, &buf); + } + closedir(dir); return 0; } +static int tfileRmExpireFile(SArray* result) { + // TODO(yihao): remove expire tindex after restart + return 0; +} +static void tfileDestroyFileName(void* elem) { + char* p = *(char**)elem; + free(p); +} +static int tfileCompare(const void* a, const void* b) { + const char* aName = *(char**)a; + const char* bName = *(char**)b; + + size_t aLen = strlen(aName); + size_t bLen = strlen(bName); + + return strncmp(aName, bName, aLen > bLen ? aLen : bLen); +} +// 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)) { + // read suid & colid & version success + return 0; + } + 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 85d76bb716a887bf7e7b07d54afde9ae67f431de..f8dae787b898706b5b194858337613e48df0b93f 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -2,8 +2,7 @@ * 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. + * 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 @@ -13,141 +12,141 @@ * along with this program. If not, see . */ #include -#include #include +#include #include "index.h" -#include "tutil.h" #include "indexInt.h" #include "index_fst.h" -#include "index_fst_util.h" #include "index_fst_counting_writer.h" - +#include "index_fst_util.h" +#include "index_tfile.h" +#include "tutil.h" class FstWriter { - public: - FstWriter() { - _wc = writerCtxCreate(TFile, "/tmp/tindex", false, 0); - _b = fstBuilderCreate(NULL, 0); - } - bool Put(const std::string &key, uint64_t val) { - FstSlice skey = fstSliceCreate((uint8_t *)key.c_str(), key.size()); - bool ok = fstBuilderInsert(_b, skey, val); - fstSliceDestroy(&skey); - return ok; - } - ~FstWriter() { - fstBuilderFinish(_b); - fstBuilderDestroy(_b); - - writerCtxDestroy(_wc); - } - private: - FstBuilder *_b; - WriterCtx *_wc; + public: + FstWriter() { + _wc = writerCtxCreate(TFile, "/tmp/tindex", false, 64 * 1024 * 1024); + _b = fstBuilderCreate(NULL, 0); + } + bool Put(const std::string& key, uint64_t val) { + FstSlice skey = fstSliceCreate((uint8_t*)key.c_str(), key.size()); + bool ok = fstBuilderInsert(_b, skey, val); + fstSliceDestroy(&skey); + return ok; + } + ~FstWriter() { + fstBuilderFinish(_b); + fstBuilderDestroy(_b); + + writerCtxDestroy(_wc); + } + + private: + FstBuilder* _b; + WriterCtx* _wc; }; class FstReadMemory { - public: - FstReadMemory(size_t size) { - _wc = writerCtxCreate(TFile, "/tmp/tindex", true, 0); - _w = fstCountingWriterCreate(_wc); - _size = size; - memset((void *)&_s, 0, sizeof(_s)); - } - bool init() { - char *buf = (char *)calloc(1, sizeof(char) * _size); - int nRead = fstCountingWriterRead(_w, (uint8_t *)buf, _size); - if (nRead <= 0) { return false; } - _size = nRead; - _s = fstSliceCreate((uint8_t *)buf, _size); - _fst = fstCreate(&_s); - free(buf); - return _fst != NULL; - } - bool Get(const std::string &key, uint64_t *val) { - FstSlice skey = fstSliceCreate((uint8_t *)key.c_str(), key.size()); - bool ok = fstGet(_fst, &skey, val); - fstSliceDestroy(&skey); - return ok; - } - bool GetWithTimeCostUs(const std::string &key, uint64_t *val, uint64_t *elapse) { - int64_t s = taosGetTimestampUs(); - bool ok = this->Get(key, val); - int64_t e = taosGetTimestampUs(); - *elapse = e - s; - return ok; - } - // add later - bool Search(AutomationCtx *ctx, std::vector &result) { - FstStreamBuilder *sb = fstSearch(_fst, ctx); - StreamWithState *st = streamBuilderIntoStream(sb); - StreamWithStateResult *rt = NULL; - - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { - result.push_back((uint64_t)(rt->out.out)); - } - return true; - } - bool SearchWithTimeCostUs(AutomationCtx *ctx, std::vector &result) { - int64_t s = taosGetTimestampUs(); - bool ok = this->Search(ctx, result); - int64_t e = taosGetTimestampUs(); - return ok; - } - - ~FstReadMemory() { + public: + FstReadMemory(size_t size) { + _wc = writerCtxCreate(TFile, "/tmp/tindex", true, 64 * 1024); + _w = fstCountingWriterCreate(_wc); + _size = size; + memset((void*)&_s, 0, sizeof(_s)); + } + bool init() { + char* buf = (char*)calloc(1, sizeof(char) * _size); + int nRead = fstCountingWriterRead(_w, (uint8_t*)buf, _size); + if (nRead <= 0) { return false; } + _size = nRead; + _s = fstSliceCreate((uint8_t*)buf, _size); + _fst = fstCreate(&_s); + free(buf); + return _fst != NULL; + } + bool Get(const std::string& key, uint64_t* val) { + FstSlice skey = fstSliceCreate((uint8_t*)key.c_str(), key.size()); + bool ok = fstGet(_fst, &skey, val); + fstSliceDestroy(&skey); + return ok; + } + bool GetWithTimeCostUs(const std::string& key, uint64_t* val, uint64_t* elapse) { + int64_t s = taosGetTimestampUs(); + bool ok = this->Get(key, val); + int64_t e = taosGetTimestampUs(); + *elapse = e - s; + return ok; + } + // add later + bool Search(AutomationCtx* ctx, std::vector& result) { + FstStreamBuilder* sb = fstSearch(_fst, ctx); + StreamWithState* st = streamBuilderIntoStream(sb); + StreamWithStateResult* rt = NULL; + + while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + result.push_back((uint64_t)(rt->out.out)); + } + return true; + } + bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector& result) { + int64_t s = taosGetTimestampUs(); + bool ok = this->Search(ctx, result); + int64_t e = taosGetTimestampUs(); + return ok; + } + + ~FstReadMemory() { fstCountingWriterDestroy(_w); fstDestroy(_fst); fstSliceDestroy(&_s); writerCtxDestroy(_wc); - } - - private: - FstCountingWriter *_w; - Fst *_fst; - FstSlice _s; - WriterCtx *_wc; - size_t _size; - -}; - -//TEST(IndexTest, index_create_test) { + } + + private: + FstCountingWriter* _w; + Fst* _fst; + FstSlice _s; + WriterCtx* _wc; + size_t _size; +}; + +// TEST(IndexTest, index_create_test) { // SIndexOpts *opts = indexOptsCreate(); // SIndex *index = indexOpen(opts, "./test"); // if (index == NULL) { -// std::cout << "index open failed" << std::endl; +// std::cout << "index open failed" << std::endl; // } // -// -// // write +// +// // write // for (int i = 0; i < 100000; i++) { // SIndexMultiTerm* terms = indexMultiTermCreate(); -// std::string val = "field"; +// std::string val = "field"; // // indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size()); // -// val.append(std::to_string(i)); +// val.append(std::to_string(i)); // indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size()); // // val.insert(0, std::to_string(i)); // indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size()); // -// val.append("const"); +// val.append("const"); // indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size()); // -// +// // indexPut(index, terms, i); // indexMultiTermDestroy(terms); -// } -// +// } +// // // // query -// SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST); -// +// SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST); +// // indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX); // indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM); // -// SArray *result = (SArray *)taosArrayInit(10, sizeof(int)); +// SArray *result = (SArray *)taosArrayInit(10, sizeof(int)); // indexSearch(index, multiQuery, result); // // std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl; @@ -155,25 +154,24 @@ class FstReadMemory { // int *v = (int *)taosArrayGet(result, i); // std::cout << "value --->" << *v << std::endl; // } -// // add more test case +// // add more test case // indexMultiTermQueryDestroy(multiQuery); // -// indexOptsDestroy(opts); -// indexClose(index); +// indexOptsDestroy(opts); +// indexClose(index); // // //} - #define L 100 #define M 100 #define N 100 -int Performance_fstWriteRecords(FstWriter *b) { - std::string str("aa"); +int Performance_fstWriteRecords(FstWriter* b) { + std::string str("aa"); for (int i = 0; i < L; i++) { str[0] = 'a' + i; - str.resize(2); - for(int j = 0; j < M; j++) { + str.resize(2); + for (int j = 0; j < M; j++) { str[1] = 'a' + j; str.resize(2); for (int k = 0; k < N; k++) { @@ -181,87 +179,86 @@ int Performance_fstWriteRecords(FstWriter *b) { b->Put(str, k); printf("(%d, %d, %d, %s)\n", i, j, k, str.c_str()); } - } + } } return L * M * N; } -void Performance_fstReadRecords(FstReadMemory *m) { +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.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; + 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); + 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 checkFstPerf() { - FstWriter *fw = new FstWriter; - int64_t s = taosGetTimestampUs(); + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); - int num = Performance_fstWriteRecords(fw); + int num = Performance_fstWriteRecords(fw); int64_t e = taosGetTimestampUs(); - printf("write %d record cost %" PRId64"us\n", num, e - s); + printf("write %d record cost %" PRId64 "us\n", num, e - s); delete fw; - FstReadMemory *m = new FstReadMemory(1024 * 64); - if (m->init()) { - printf("success to init fst read"); - } - Performance_fstReadRecords(m); + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init()) { printf("success to init fst read"); } + Performance_fstReadRecords(m); delete m; -} +} void checkFstPrefixSearch() { - FstWriter *fw = new FstWriter; - int64_t s = taosGetTimestampUs(); - int count = 2; + FstWriter* fw = new FstWriter; + int64_t s = taosGetTimestampUs(); + int count = 2; std::string key("ab"); - + for (int i = 0; i < count; i++) { - key[1] = key[1] + i; - fw->Put(key, i); + key[1] = key[1] + i; + fw->Put(key, i); } int64_t e = taosGetTimestampUs(); - + std::cout << "insert data count : " << count << "elapas time: " << e - s << std::endl; delete fw; - FstReadMemory *m = new FstReadMemory(1024 * 64); + FstReadMemory* m = new FstReadMemory(1024 * 64); if (m->init() == false) { - std::cout << "init readMemory failed" << std::endl; + std::cout << "init readMemory failed" << std::endl; delete m; return; } - - // prefix search + + // prefix search std::vector result; - AutomationCtx *ctx = automCtxCreate((void *)"ab", AUTOMATION_PREFIX); - m->Search(ctx, result); - assert(result.size() == count); + + AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_PREFIX); + m->Search(ctx, result); + assert(result.size() == count); for (int i = 0; i < result.size(); i++) { - assert(result[i] == i); // check result + assert(result[i] == i); // check result } free(ctx); delete m; -} +} void validateFst() { - int val = 100; - int count = 100; - FstWriter *fw = new FstWriter; - // write + int val = 100; + int count = 100; + FstWriter* fw = new FstWriter; + // write { std::string key("ab"); for (int i = 0; i < count; i++) { @@ -272,99 +269,161 @@ void validateFst() { delete fw; // read - FstReadMemory *m = new FstReadMemory(1024 * 64); - if (m->init() == false) { - std::cout << "init readMemory failed" << std::endl; + FstReadMemory* m = new FstReadMemory(1024 * 64); + if (m->init() == false) { + std::cout << "init readMemory failed" << std::endl; delete m; return; } { - std::string key("ab"); - uint64_t out; - if (m->Get(key, &out)) { - printf("success to get (%s, %" PRId64")\n", key.c_str(), out); - } else { - printf("failed to get(%s)\n", key.c_str()); - } - for (int i = 0; i < count; i++) { - key.push_back('a' + i); - if (m->Get(key, &out) ) { - assert(val - i == out); - printf("success to get (%s, %" PRId64")\n", key.c_str(), out); - } else { - printf("failed to get(%s)\n", key.c_str()); + std::string key("ab"); + uint64_t out; + if (m->Get(key, &out)) { + printf("success to get (%s, %" PRId64 ")\n", key.c_str(), out); + } else { + printf("failed to get(%s)\n", key.c_str()); + } + for (int i = 0; i < count; i++) { + key.push_back('a' + i); + if (m->Get(key, &out)) { + assert(val - i == out); + printf("success to get (%s, %" PRId64 ")\n", key.c_str(), out); + } else { + printf("failed to get(%s)\n", key.c_str()); + } } - } - } + } delete m; -} +} class IndexEnv : public ::testing::Test { - protected: - virtual void SetUp() { - taosRemoveDir(path); - opts = indexOptsCreate(); - int ret = indexOpen(opts, path, &index); - assert(ret == 0); - } - virtual void TearDown() { - indexClose(index); - indexOptsDestroy(opts); - } - - const char *path = "/tmp/tindex"; - SIndexOpts *opts; - SIndex *index; + protected: + virtual void SetUp() { + taosRemoveDir(path); + opts = indexOptsCreate(); + int ret = indexOpen(opts, path, &index); + assert(ret == 0); + } + virtual void TearDown() { + indexClose(index); + indexOptsDestroy(opts); + } + + const char* path = "/tmp/tindex"; + SIndexOpts* opts; + SIndex* index; }; -TEST_F(IndexEnv, testPut) { - - // single index column - { - - std::string colName("tag1"), colVal("Hello world"); - 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); - - for (size_t i = 0; i < 100; i++) { - int tableId = i; - int ret = indexPut(index, terms, tableId); - assert(ret == 0); - } - indexMultiTermDestroy(terms); - } - // multi index column - { - - SIndexMultiTerm *terms = indexMultiTermCreate(); - { - std::string colName("tag1"), colVal("Hello world"); - SIndexTerm *term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); - indexMultiTermAdd(terms, term); - } - { - std::string colName("tag2"), colVal("Hello world"); - SIndexTerm *term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); - indexMultiTermAdd(terms, term); - } - - for (int i = 0; i < 100; i++) { - int tableId = i; - int ret = indexPut(index, terms, tableId); - assert(ret == 0); - } - indexMultiTermDestroy(terms); - } - // -} - -TEST_F(IndexEnv, testDel) { - +// TEST_F(IndexEnv, testPut) { +// // single index column +// { +// std::string colName("tag1"), colVal("Hello world"); +// 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); +// +// for (size_t i = 0; i < 100; i++) { +// int tableId = i; +// int ret = indexPut(index, terms, tableId); +// assert(ret == 0); +// } +// indexMultiTermDestroy(terms); +// } +// // multi index column +// { +// SIndexMultiTerm* terms = indexMultiTermCreate(); +// { +// std::string colName("tag1"), colVal("Hello world"); +// SIndexTerm* term = +// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); +// indexMultiTermAdd(terms, term); +// } +// { +// std::string colName("tag2"), colVal("Hello world"); +// SIndexTerm* term = +// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); +// indexMultiTermAdd(terms, term); +// } +// +// for (int i = 0; i < 100; i++) { +// int tableId = i; +// int ret = indexPut(index, terms, tableId); +// assert(ret == 0); +// } +// indexMultiTermDestroy(terms); +// } +// // +//} + +class IndexTFileEnv : public ::testing::Test { + protected: + virtual void SetUp() { + taosRemoveDir(dir); + taosMkDir(dir); + tfInit(); + std::string colName("voltage"); + header.suid = 1; + header.version = 1; + memcpy(header.colName, colName.c_str(), colName.size()); + header.colType = TSDB_DATA_TYPE_BINARY; + + std::string path(dir); + int colId = 2; + char buf[64] = {0}; + sprintf(buf, "%" PRIu64 "-%d-%d.tindex", header.suid, colId, header.version); + path.append("/").append(buf); + + ctx = writerCtxCreate(TFile, path.c_str(), false, 64 * 1024 * 1024); + + twrite = tfileWriterCreate(ctx, &header); + } + + virtual void TearDown() { + // indexClose(index); + // indexeptsDestroy(opts); + tfCleanup(); + tfileWriterDestroy(twrite); + } + const char* dir = "/tmp/tindex"; + WriterCtx* ctx = NULL; + TFileHeader header; + TFileWriter* twrite = NULL; +}; + +static TFileValue* genTFileValue(const char* val) { + TFileValue* tv = (TFileValue*)calloc(1, sizeof(TFileValue)); + int32_t vlen = strlen(val) + 1; + tv->colVal = (char*)calloc(1, vlen); + memcpy(tv->colVal, val, vlen); + + tv->tableId = (SArray*)taosArrayInit(1, sizeof(uint64_t)); + for (size_t i = 0; i < 10; i++) { + uint64_t v = i; + taosArrayPush(tv->tableId, &v); + } + return tv; +} +static void destroyTFileValue(void* val) { + TFileValue* tv = (TFileValue*)val; + free(tv->colVal); + taosArrayDestroy(tv->tableId); + free(tv); } +TEST_F(IndexTFileEnv, test_tfile_write) { + TFileValue* v1 = genTFileValue("c"); + TFileValue* v2 = genTFileValue("a"); + SArray* data = (SArray*)taosArrayInit(4, sizeof(void*)); + taosArrayPush(data, &v1); + taosArrayPush(data, &v2); + tfileWriterPut(twrite, data); + // tfileWriterDestroy(twrite); + for (size_t i = 0; i < taosArrayGetSize(data); i++) { + destroyTFileValue(taosArrayGetP(data, i)); + } + taosArrayDestroy(data); +} diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index 1771bdc0edbeeb649f2c02e583e6d525df20a894..c0c3c8386b5237707881204efd00dcda07896126 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -8,6 +8,8 @@ SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen); -SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, char* msgBuf, int32_t msgLen); +SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf); +SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); +SDropTableMsg* buildDropTableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); #endif // TDENGINE_ASTTOMSG_H diff --git a/source/libs/parser/inc/dataBlockMgt.h b/source/libs/parser/inc/dataBlockMgt.h index fbd92b89f85aa789f3c50360da372ec38b2bd812..69dad4d9f4b792ed573628f05ddb95f301f8cc08 100644 --- a/source/libs/parser/inc/dataBlockMgt.h +++ b/source/libs/parser/inc/dataBlockMgt.h @@ -78,7 +78,7 @@ typedef struct { typedef struct STableDataBlocks { int8_t tsSource; // where does the UNIX timestamp come from, server or client bool ordered; // if current rows are ordered or not - int64_t vgId; // virtual group id + int32_t vgId; // virtual group id int64_t prevTS; // previous timestamp, recorded to decide if the records array is ts ascending int32_t numOfTables; // number of tables in current submit block int32_t rowSize; // row size for current table diff --git a/source/libs/parser/inc/parserInt.h b/source/libs/parser/inc/parserInt.h index 4f506e631f5099f0b31a589c07f46aeff0cf3683..186a4869e67871c48a919d5022fb0b3a4bde0465 100644 --- a/source/libs/parser/inc/parserInt.h +++ b/source/libs/parser/inc/parserInt.h @@ -38,6 +38,14 @@ typedef struct SMsgBuf { char *buf; } SMsgBuf; +// create table operation type +enum TSQL_CREATE_TABLE_TYPE { + TSQL_CREATE_TABLE = 0x1, + TSQL_CREATE_STABLE = 0x2, + TSQL_CREATE_CTABLE = 0x3, + TSQL_CREATE_STREAM = 0x4, +}; + void clearTableMetaInfo(STableMetaInfo* pTableMetaInfo); void clearAllTableMetaInfo(SQueryStmtInfo* pQueryInfo, bool removeMeta, uint64_t id); @@ -60,7 +68,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQ * @param type * @return */ -int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, int32_t* outputLen, int32_t* type, char* msgBuf, int32_t msgBufLen); +int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStmtInfo* pDcl, char* msgBuf, int32_t msgBufLen); /** * Evaluate the numeric and timestamp arithmetic expression in the WHERE clause. diff --git a/source/libs/parser/inc/parserUtil.h b/source/libs/parser/inc/parserUtil.h index c588a34a40771391fd39fe9688277aa4640cb0fc..3d8729e72d57eb9dd8f8b0bbcd46a128ed865766 100644 --- a/source/libs/parser/inc/parserUtil.h +++ b/source/libs/parser/inc/parserUtil.h @@ -67,6 +67,8 @@ int32_t getExprFunctionId(SExprInfo *pExprInfo); STableMeta* tableMetaDup(const STableMeta* pTableMeta); bool isDclSqlStatement(SSqlInfo* pSqlInfo); +bool isDdlSqlStatement(SSqlInfo* pSqlInfo); +bool isDqlSqlStatement(SSqlInfo* pSqlInfo); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index da975b966ea2360a9c9672f15669c8f1bf5f4ff9..183b71483be7d275f5745678e4882bc6ed444db3 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -31,6 +31,7 @@ #include "ttoken.h" #include "ttokendef.h" #include "tvariant.h" +#include "parserInt.h" } %syntax_error { @@ -173,7 +174,7 @@ cmd ::= ALTER DNODE ids(X) ids(Y) ids(Z). { setDCLSqlElems(pInfo, TSDB_SQL cmd ::= ALTER LOCAL ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); } cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y); } cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);} -cmd ::= ALTER TOPIC ids(X) alter_topic_optr(Y). { SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);} +//cmd ::= ALTER TOPIC ids(X) alter_topic_optr(Y). { SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);} cmd ::= ALTER ACCOUNT ids(X) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &X, NULL, &Z);} cmd ::= ALTER ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &X, &Y, &Z);} @@ -203,7 +204,7 @@ cmd ::= CREATE DNODE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);} cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);} -cmd ::= CREATE TOPIC ifnotexists(Z) ids(X) topic_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);} +//cmd ::= CREATE TOPIC ifnotexists(Z) ids(X) topic_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);} cmd ::= CREATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B). { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 1);} cmd ::= CREATE AGGREGATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B). { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 2);} cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSql(pInfo, &X, &Y);} @@ -278,10 +279,10 @@ comp(Y) ::= COMP INTEGER(X). { Y = X; } prec(Y) ::= PRECISION STRING(X). { Y = X; } update(Y) ::= UPDATE INTEGER(X). { Y = X; } cachelast(Y) ::= CACHELAST INTEGER(X). { Y = X; } -partitions(Y) ::= PARTITIONS INTEGER(X). { Y = X; } +//partitions(Y) ::= PARTITIONS INTEGER(X). { Y = X; } %type db_optr {SCreateDbInfo} -db_optr(Y) ::= . {setDefaultCreateDbOption(&Y); Y.dbType = TSDB_DB_TYPE_DEFAULT;} +db_optr(Y) ::= . {setDefaultCreateDbOption(&Y);} db_optr(Y) ::= db_optr(Z) cache(X). { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); } @@ -299,13 +300,13 @@ db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; } db_optr(Y) ::= db_optr(Z) update(X). { Y = Z; Y.update = strtol(X.z, NULL, 10); } db_optr(Y) ::= db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = strtol(X.z, NULL, 10); } -%type topic_optr {SCreateDbInfo} - -topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; } -topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); } +//%type topic_optr {SCreateDbInfo} +// +//topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; } +//topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); } %type alter_db_optr {SCreateDbInfo} -alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y); Y.dbType = TSDB_DB_TYPE_DEFAULT;} +alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y);} alter_db_optr(Y) ::= alter_db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); } alter_db_optr(Y) ::= alter_db_optr(Z) quorum(X). { Y = Z; Y.quorum = strtol(X.z, NULL, 10); } @@ -319,10 +320,10 @@ alter_db_optr(Y) ::= alter_db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = str //alter_db_optr(Y) ::= alter_db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); } //alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); } not support yet -%type alter_topic_optr {SCreateDbInfo} +//%type alter_topic_optr {SCreateDbInfo} -alter_topic_optr(Y) ::= alter_db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; } -alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); } +//alter_topic_optr(Y) ::= alter_db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; } +//alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); } %type typename {SField} typename(A) ::= ids(X). { diff --git a/source/libs/parser/inc/ttokendef.h b/source/libs/parser/inc/ttokendef.h index 9b0ad2cf13b6df01bda56906891a4de677ff08a3..ccb62b33208ef2b5c766cdfeacd4899006db604e 100644 --- a/source/libs/parser/inc/ttokendef.h +++ b/source/libs/parser/inc/ttokendef.h @@ -130,88 +130,88 @@ #define TK_PRECISION 112 #define TK_UPDATE 113 #define TK_CACHELAST 114 -#define TK_PARTITIONS 115 -#define TK_UNSIGNED 116 -#define TK_TAGS 117 -#define TK_USING 118 -#define TK_NULL 119 -#define TK_NOW 120 -#define TK_SELECT 121 -#define TK_UNION 122 -#define TK_ALL 123 -#define TK_DISTINCT 124 -#define TK_FROM 125 -#define TK_VARIABLE 126 -#define TK_INTERVAL 127 -#define TK_EVERY 128 -#define TK_SESSION 129 -#define TK_STATE_WINDOW 130 -#define TK_FILL 131 -#define TK_SLIDING 132 -#define TK_ORDER 133 -#define TK_BY 134 -#define TK_ASC 135 -#define TK_GROUP 136 -#define TK_HAVING 137 -#define TK_LIMIT 138 -#define TK_OFFSET 139 -#define TK_SLIMIT 140 -#define TK_SOFFSET 141 -#define TK_WHERE 142 -#define TK_RESET 143 -#define TK_QUERY 144 -#define TK_SYNCDB 145 -#define TK_ADD 146 -#define TK_COLUMN 147 -#define TK_MODIFY 148 -#define TK_TAG 149 -#define TK_CHANGE 150 -#define TK_SET 151 -#define TK_KILL 152 -#define TK_CONNECTION 153 -#define TK_STREAM 154 -#define TK_COLON 155 -#define TK_ABORT 156 -#define TK_AFTER 157 -#define TK_ATTACH 158 -#define TK_BEFORE 159 -#define TK_BEGIN 160 -#define TK_CASCADE 161 -#define TK_CLUSTER 162 -#define TK_CONFLICT 163 -#define TK_COPY 164 -#define TK_DEFERRED 165 -#define TK_DELIMITERS 166 -#define TK_DETACH 167 -#define TK_EACH 168 -#define TK_END 169 -#define TK_EXPLAIN 170 -#define TK_FAIL 171 -#define TK_FOR 172 -#define TK_IGNORE 173 -#define TK_IMMEDIATE 174 -#define TK_INITIALLY 175 -#define TK_INSTEAD 176 -#define TK_KEY 177 -#define TK_OF 178 -#define TK_RAISE 179 -#define TK_REPLACE 180 -#define TK_RESTRICT 181 -#define TK_ROW 182 -#define TK_STATEMENT 183 -#define TK_TRIGGER 184 -#define TK_VIEW 185 -#define TK_IPTOKEN 186 -#define TK_SEMI 187 -#define TK_NONE 188 -#define TK_PREV 189 -#define TK_LINEAR 190 -#define TK_IMPORT 191 -#define TK_TBNAME 192 -#define TK_JOIN 193 -#define TK_INSERT 194 -#define TK_INTO 195 -#define TK_VALUES 196 +#define TK_UNSIGNED 115 +#define TK_TAGS 116 +#define TK_USING 117 +#define TK_NULL 118 +#define TK_NOW 119 +#define TK_SELECT 120 +#define TK_UNION 121 +#define TK_ALL 122 +#define TK_DISTINCT 123 +#define TK_FROM 124 +#define TK_VARIABLE 125 +#define TK_INTERVAL 126 +#define TK_EVERY 127 +#define TK_SESSION 128 +#define TK_STATE_WINDOW 129 +#define TK_FILL 130 +#define TK_SLIDING 131 +#define TK_ORDER 132 +#define TK_BY 133 +#define TK_ASC 134 +#define TK_GROUP 135 +#define TK_HAVING 136 +#define TK_LIMIT 137 +#define TK_OFFSET 138 +#define TK_SLIMIT 139 +#define TK_SOFFSET 140 +#define TK_WHERE 141 +#define TK_RESET 142 +#define TK_QUERY 143 +#define TK_SYNCDB 144 +#define TK_ADD 145 +#define TK_COLUMN 146 +#define TK_MODIFY 147 +#define TK_TAG 148 +#define TK_CHANGE 149 +#define TK_SET 150 +#define TK_KILL 151 +#define TK_CONNECTION 152 +#define TK_STREAM 153 +#define TK_COLON 154 +#define TK_ABORT 155 +#define TK_AFTER 156 +#define TK_ATTACH 157 +#define TK_BEFORE 158 +#define TK_BEGIN 159 +#define TK_CASCADE 160 +#define TK_CLUSTER 161 +#define TK_CONFLICT 162 +#define TK_COPY 163 +#define TK_DEFERRED 164 +#define TK_DELIMITERS 165 +#define TK_DETACH 166 +#define TK_EACH 167 +#define TK_END 168 +#define TK_EXPLAIN 169 +#define TK_FAIL 170 +#define TK_FOR 171 +#define TK_IGNORE 172 +#define TK_IMMEDIATE 173 +#define TK_INITIALLY 174 +#define TK_INSTEAD 175 +#define TK_KEY 176 +#define TK_OF 177 +#define TK_RAISE 178 +#define TK_REPLACE 179 +#define TK_RESTRICT 180 +#define TK_ROW 181 +#define TK_STATEMENT 182 +#define TK_TRIGGER 183 +#define TK_VIEW 184 +#define TK_IPTOKEN 185 +#define TK_SEMI 186 +#define TK_NONE 187 +#define TK_PREV 188 +#define TK_LINEAR 189 +#define TK_IMPORT 190 +#define TK_TBNAME 191 +#define TK_JOIN 192 +#define TK_INSERT 193 +#define TK_INTO 194 +#define TK_VALUES 195 + #define TK_SPACE 300 diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index dda30c56fc6c9d647659f1fddcf2bcb69ce25c20..b6a6b73ccc258a5a8d5c12a1961d8f22fabba411 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -13,9 +13,10 @@ * along with this program. If not, see . */ -#include "taos.h" -#include "os.h" #include "astGenerator.h" +#include +#include "os.h" +#include "taos.h" #include "tmsgtype.h" SArray *tListItemAppend(SArray *pList, SVariant *pVar, uint8_t sortOrder) { diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index c41ba97e39f3a080190989ee80d5c03a9b50d2e0..00f3d3f7162cb4df8de51d7755fce8911dbfaa57 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -1,3 +1,4 @@ +#include #include "parserInt.h" #include "parserUtil.h" @@ -206,16 +207,166 @@ int32_t setDbOptions(SCreateDbMsg* pCreateDbMsg, const SCreateDbInfo* pCreateDbS return TSDB_CODE_SUCCESS; } -SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, char* msgBuf, int32_t msgLen) { +SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf) { SCreateDbMsg* pCreateMsg = calloc(1, sizeof(SCreateDbMsg)); - - SMsgBuf msg = {.buf = msgBuf, .len = msgLen}; - if (setDbOptions(pCreateMsg, pCreateDbInfo, &msg) != TSDB_CODE_SUCCESS) { + if (setDbOptions(pCreateMsg, pCreateDbInfo, pMsgBuf) != TSDB_CODE_SUCCESS) { tfree(pCreateMsg); terrno = TSDB_CODE_TSC_INVALID_OPERATION; return NULL; } + SName name = {0}; + int32_t ret = tNameSetDbName(&name, pCtx->acctId, pCreateDbInfo->dbname.z, pCreateDbInfo->dbname.n); + if (ret != TSDB_CODE_SUCCESS) { + terrno = ret; + return NULL; + } + + tNameGetFullDbName(&name, pCreateMsg->db); return pCreateMsg; } + +int32_t createSName(SName* pName, SToken* pTableName, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { + const char* msg1 = "name too long"; + const char* msg2 = "acctId too long"; + + int32_t code = TSDB_CODE_SUCCESS; + char* p = strnchr(pTableName->z, TS_PATH_DELIMITER[0], pTableName->n, false); + + if (p != NULL) { // db has been specified in sql string so we ignore current db path + code = tNameSetAcctId(pName, pParseCtx->acctId); + if (code != 0) { + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + char name[TSDB_TABLE_FNAME_LEN] = {0}; + strncpy(name, pTableName->z, pTableName->n); + + code = tNameFromString(pName, name, T_NAME_DB|T_NAME_TABLE); + if (code != 0) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + } else { // get current DB name first, and then set it into path + if (pTableName->n >= TSDB_TABLE_NAME_LEN) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + tNameSetDbName(pName, pParseCtx->acctId, pParseCtx->db, strlen(pParseCtx->db)); + + char name[TSDB_TABLE_FNAME_LEN] = {0}; + strncpy(name, pTableName->z, pTableName->n); + + code = tNameFromString(pName, name, T_NAME_TABLE); + if (code != 0) { + code = buildInvalidOperationMsg(pMsgBuf, msg1); + } + } + + return code; +} + +SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { + SSchema* pSchema; + + int32_t numOfTags = 0; + int32_t numOfCols = (int32_t) taosArrayGetSize(pCreateTableSql->colInfo.pColumns); + if (pCreateTableSql->colInfo.pTagColumns != NULL) { + numOfTags = (int32_t) taosArrayGetSize(pCreateTableSql->colInfo.pTagColumns); + } + + SCreateStbMsg* pCreateTableMsg = (SCreateStbMsg*)calloc(1, sizeof(SCreateStbMsg) + (numOfCols + numOfTags) * sizeof(SSchema)); + + char* pMsg = NULL; + int32_t tableType = pCreateTableSql->type; + if (tableType != TSQL_CREATE_TABLE && tableType != TSQL_CREATE_STABLE) { // create by using super table, tags value +#if 0 + SArray* list = pInfo->pCreateTableInfo->childTableInfo; + + int32_t numOfTables = (int32_t)taosArrayGetSize(list); + pCreateTableMsg->numOfTables = htonl(numOfTables); + + pMsg = (char*)pCreateMsg; + for (int32_t i = 0; i < numOfTables; ++i) { + SCreateTableMsg* pCreate = (SCreateTableMsg*)pMsg; + + pCreate->numOfColumns = htons(pCmd->numOfCols); + pCreate->numOfTags = htons(pCmd->count); + pMsg += sizeof(SCreateTableMsg); + + SCreatedTableInfo* p = taosArrayGet(list, i); + strcpy(pCreate->tableName, p->fullname); + pCreate->igExists = (p->igExist) ? 1 : 0; + + // use dbinfo from table id without modifying current db info + pMsg = serializeTagData(&p->tagdata, pMsg); + + int32_t len = (int32_t)(pMsg - (char*)pCreate); + pCreate->len = htonl(len); + } +#endif + } else { // create (super) table + SName n = {0}; + int32_t code = createSName(&n, &pCreateTableSql->name, pParseCtx, pMsgBuf); + if (code != 0) { + return NULL; + } + + code = tNameExtractFullName(&n, pCreateTableMsg->name); + if (code != 0) { + buildInvalidOperationMsg(pMsgBuf, "invalid table name or database not specified"); + return NULL; + } + + pCreateTableMsg->igExists = pCreateTableSql->existCheck ? 1 : 0; + pCreateTableMsg->numOfColumns = htonl(numOfCols); + pCreateTableMsg->numOfTags = htonl(numOfTags); + + pSchema = (SSchema*) pCreateTableMsg->pSchema; + for (int i = 0; i < numOfCols; ++i) { + SField* pField = taosArrayGet(pCreateTableSql->colInfo.pColumns, i); + pSchema->type = pField->type; + pSchema->bytes = htonl(pField->bytes); + strcpy(pSchema->name, pField->name); + + pSchema++; + } + + for(int32_t i = 0; i < numOfTags; ++i) { + SField* pField = taosArrayGet(pCreateTableSql->colInfo.pTagColumns, i); + pSchema->type = pField->type; + pSchema->bytes = htonl(pField->bytes); + strcpy(pSchema->name, pField->name); + + pSchema++; + } + + pMsg = (char*)pSchema; + } + + int32_t msgLen = (int32_t)(pMsg - (char*)pCreateTableMsg); + *len = msgLen; + + return pCreateTableMsg; +} + +SDropTableMsg* buildDropTableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { + SToken* tableName = taosArrayGet(pInfo->pMiscInfo->a, 0); + + SName name = {0}; + int32_t code = createSName(&name, tableName, pParseCtx, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + terrno = buildInvalidOperationMsg(pMsgBuf, "invalid table name"); + return NULL; + } + + SDropTableMsg *pDropTableMsg = (SDropTableMsg*) calloc(1, sizeof(SDropTableMsg)); + + code = tNameExtractFullName(&name, pDropTableMsg->name); + assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_TABLE_NAME_T); + + pDropTableMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; + *len = sizeof(SDropTableMsg); + return pDropTableMsg; +} + diff --git a/source/libs/parser/src/astValidate.c b/source/libs/parser/src/astValidate.c index accc786bf6787ba52b72721a5da143c4a3d46e86..5d64323332b220be624132bc61513a0db3e0f72d 100644 --- a/source/libs/parser/src/astValidate.c +++ b/source/libs/parser/src/astValidate.c @@ -4028,7 +4028,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer } // todo remove it -static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLen, SMsgBuf* pMsgBuf) { +static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx *pCtx, void** output, int32_t* outputLen, SMsgBuf* pMsgBuf) { const char* msg1 = "invalid name"; const char* msg2 = "wildcard string should be less than %d characters"; const char* msg3 = "database name too long"; @@ -4040,9 +4040,8 @@ static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLe * database prefix in pInfo->pMiscInfo->a[0] * wildcard in like clause in pInfo->pMiscInfo->a[1] */ - SShowInfo* pShowInfo = &pInfo->pMiscInfo->showOpt; int16_t showType = pShowInfo->showType; - if (showType == TSDB_MGMT_TABLE_TABLE || showType == TSDB_MGMT_TABLE_VGROUP) { + if (showType == TSDB_MGMT_TABLE_STB || showType == TSDB_MGMT_TABLE_VGROUP) { SToken* pDbPrefixToken = &pShowInfo->prefix; if (pDbPrefixToken->type != 0) { if (pDbPrefixToken->n >= TSDB_DB_NAME_LEN) { // db name is too long @@ -4091,8 +4090,8 @@ static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLe } } - *output = buildShowMsg(pShowInfo, 0, pMsgBuf->buf, pMsgBuf->len); - *msgLen = sizeof(SShowMsg)/* + htons(pShowMsg->payloadLen)*/; + *output = buildShowMsg(pShowInfo, pCtx->requestId, pMsgBuf->buf, pMsgBuf->len); + *outputLen = sizeof(SShowMsg)/* + htons(pShowMsg->payloadLen)*/; return TSDB_CODE_SUCCESS; } @@ -4171,14 +4170,148 @@ static int32_t doCheckDbOptions(SCreateDbMsg* pCreate, SMsgBuf* pMsgBuf) { return TSDB_CODE_SUCCESS; } -int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, int32_t* outputLen, int32_t* type, char* msgBuf, int32_t msgBufLen) { +/* is contained in pFieldList or not */ +static bool has(SArray* pFieldList, int32_t startIndex, const char* name) { + size_t numOfCols = taosArrayGetSize(pFieldList); + for (int32_t j = startIndex; j < numOfCols; ++j) { + TAOS_FIELD* field = taosArrayGet(pFieldList, j); + if (strncasecmp(name, field->name, sizeof(field->name) - 1) == 0) return true; + } + + return false; +} + +static int32_t validateTableColumns(SArray* pFieldList, int32_t maxRowLength, int32_t maxColumns, SMsgBuf* pMsgBuf) { + const char* msg2 = "row length exceeds max length"; + const char* msg3 = "duplicated column names"; + const char* msg4 = "invalid data type"; + const char* msg5 = "invalid binary/nchar column length"; + const char* msg6 = "invalid column name"; + const char* msg7 = "too many columns"; + const char* msg8 = "illegal number of columns"; + + size_t numOfCols = taosArrayGetSize(pFieldList); + if (numOfCols > maxColumns) { + return buildInvalidOperationMsg(pMsgBuf, msg7); + } + + int32_t rowLen = 0; + for (int32_t i = 0; i < numOfCols; ++i) { + TAOS_FIELD* pField = taosArrayGet(pFieldList, i); + if (!isValidDataType(pField->type)) { + return buildInvalidOperationMsg(pMsgBuf, msg4); + } + + if (pField->bytes == 0) { + return buildInvalidOperationMsg(pMsgBuf, msg5); + } + + if ((pField->type == TSDB_DATA_TYPE_BINARY && (pField->bytes <= 0 || pField->bytes > TSDB_MAX_BINARY_LEN)) || + (pField->type == TSDB_DATA_TYPE_NCHAR && (pField->bytes <= 0 || pField->bytes > TSDB_MAX_NCHAR_LEN))) { + return buildInvalidOperationMsg(pMsgBuf, msg5); + } + + SToken nameToken = {.z = pField->name, .n = strlen(pField->name), .type = TK_ID}; + if (parserValidateNameToken(&nameToken) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg6); + } + + // field name must be unique + if (has(pFieldList, i + 1, pField->name) == true) { + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + + rowLen += pField->bytes; + } + + // max row length must be less than TSDB_MAX_BYTES_PER_ROW + if (rowLen > maxRowLength) { + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) { + assert(pFieldList != NULL); + + const char* msg1 = "first column must be timestamp"; + const char* msg2 = "row length exceeds max length"; + const char* msg3 = "duplicated column names"; + const char* msg4 = "invalid data type"; + const char* msg5 = "invalid binary/nchar column length"; + const char* msg6 = "invalid column name"; + const char* msg7 = "too many columns"; + const char* msg8 = "illegal number of columns"; + + // first column must be timestamp + SField* pField = taosArrayGet(pFieldList, 0); + if (pField->type != TSDB_DATA_TYPE_TIMESTAMP) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + // number of fields no less than 2 + size_t numOfCols = taosArrayGetSize(pFieldList); + if (numOfCols <= 1) { + return buildInvalidOperationMsg(pMsgBuf, msg8); + } + + return validateTableColumns(pFieldList, TSDB_MAX_BYTES_PER_ROW, TSDB_MAX_COLUMNS, pMsgBuf); +} + +static int32_t validateTagParams(SArray* pTagsList, SArray* pFieldList, SMsgBuf* pMsgBuf) { + assert(pTagsList != NULL); + + const char* msg1 = "invalid number of tag columns"; + const char* msg3 = "duplicated column names"; + + // number of fields at least 1 + size_t numOfTags = taosArrayGetSize(pTagsList); + if (numOfTags < 1) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + // field name must be unique + for (int32_t i = 0; i < numOfTags; ++i) { + SField* p = taosArrayGet(pTagsList, i); + if (has(pFieldList, 0, p->name) == true) { + return buildInvalidOperationMsg(pMsgBuf, msg3); + } + } + + return validateTableColumns(pFieldList, TSDB_MAX_TAGS_LEN, TSDB_MAX_TAGS, pMsgBuf); +} + +int32_t doCheckForCreateTable(SSqlInfo* pInfo, SMsgBuf* pMsgBuf) { + const char* msg1 = "invalid table name"; + + SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + + SArray* pFieldList = pCreateTable->colInfo.pColumns; + SArray* pTagList = pCreateTable->colInfo.pTagColumns; + assert(pFieldList != NULL); + + // if sql specifies db, use it, otherwise use default db + SToken* pzTableName = &(pCreateTable->name); + + if (parserValidateNameToken(pzTableName) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + if (validateTableColumnInfo(pFieldList, pMsgBuf) != TSDB_CODE_SUCCESS || + (pTagList != NULL && validateTagParams(pTagList, pFieldList, pMsgBuf) != TSDB_CODE_SUCCESS)) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + return TSDB_CODE_SUCCESS; +} + +int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStmtInfo* pDcl, char* msgBuf, int32_t msgBufLen) { int32_t code = 0; SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; SMsgBuf *pMsgBuf = &m; - *type = pInfo->type; - switch (pInfo->type) { case TSDB_SQL_CREATE_USER: case TSDB_SQL_ALTER_USER: { @@ -4224,7 +4357,8 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in } } - *output = buildUserManipulationMsg(pInfo, outputLen, id, msgBuf, msgBufLen); + pDcl->pMsg = (char*)buildUserManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_USER)? TSDB_MSG_TYPE_CREATE_USER:TSDB_MSG_TYPE_ALTER_USER; break; } @@ -4260,18 +4394,44 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in } } - *output = buildAcctManipulationMsg(pInfo, outputLen, id, msgBuf, msgBufLen); + pDcl->pMsg = (char*)buildAcctManipulationMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_ACCT)? TSDB_MSG_TYPE_CREATE_ACCT:TSDB_MSG_TYPE_ALTER_ACCT; break; } case TSDB_SQL_DROP_ACCT: case TSDB_SQL_DROP_USER: { - *output = buildDropUserMsg(pInfo, outputLen, id, msgBuf, msgBufLen); + pDcl->pMsg = (char*)buildDropUserMsg(pInfo, &pDcl->msgLen, pCtx->requestId, msgBuf, msgBufLen); + pDcl->msgType = (pInfo->type == TSDB_SQL_DROP_ACCT)? TSDB_MSG_TYPE_DROP_ACCT:TSDB_MSG_TYPE_DROP_USER; break; } case TSDB_SQL_SHOW: { - code = setShowInfo(pInfo, output, outputLen, pMsgBuf); + code = setShowInfo(&pInfo->pMiscInfo->showOpt, pCtx, (void**)&pDcl->pMsg, &pDcl->msgLen, pMsgBuf); + pDcl->msgType = TSDB_MSG_TYPE_SHOW; + break; + } + + case TSDB_SQL_USE_DB: { + const char* msg = "invalid db name"; + + SToken* pToken = taosArrayGet(pInfo->pMiscInfo->a, 0); + if (parserValidateNameToken(pToken) != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + SName n = {0}; + int32_t ret = tNameSetDbName(&n, pCtx->acctId, pToken->z, pToken->n); + if (ret != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg); + } + + SUseDbMsg *pUseDbMsg = (SUseDbMsg *) calloc(1, sizeof(SUseDbMsg)); + tNameExtractFullName(&n, pUseDbMsg->db); + + pDcl->pMsg = (char*)pUseDbMsg; + pDcl->msgLen = sizeof(SUseDbMsg); + pDcl->msgType = TSDB_MSG_TYPE_USE_DB; break; } @@ -4292,15 +4452,73 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in return buildInvalidOperationMsg(pMsgBuf, msg1); } - SCreateDbMsg* pCreateMsg = buildCreateDbMsg(pCreateDB, pMsgBuf->buf, pMsgBuf->len); + SCreateDbMsg* pCreateMsg = buildCreateDbMsg(pCreateDB, pCtx, pMsgBuf); if (doCheckDbOptions(pCreateMsg, pMsgBuf) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } strncpy(pCreateMsg->db, token.z, token.n); - *output = pCreateMsg; - *outputLen = sizeof(SCreateDbMsg); + pDcl->pMsg = (char*)pCreateMsg; + pDcl->msgLen = sizeof(SCreateDbMsg); + pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB)? TSDB_MSG_TYPE_CREATE_DB:TSDB_MSG_TYPE_ALTER_DB; + break; + } + + case TSDB_SQL_DROP_DB: { + const char* msg1 = "invalid database name"; + + assert(taosArrayGetSize(pInfo->pMiscInfo->a) == 1); + SToken* dbName = taosArrayGet(pInfo->pMiscInfo->a, 0); + + SName name = {0}; + code = tNameSetDbName(&name, pCtx->acctId, dbName->z, dbName->n); + if (code != TSDB_CODE_SUCCESS) { + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + + SDropDbMsg *pDropDbMsg = (SDropDbMsg*) calloc(1, sizeof(SDropDbMsg)); + + code = tNameExtractFullName(&name, pDropDbMsg->db); + pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; + assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_DB_NAME_T); + + pDcl->msgType = TSDB_MSG_TYPE_DROP_DB; + pDcl->msgLen = sizeof(SDropDbMsg); + pDcl->pMsg = (char*)pDropDbMsg; + return TSDB_CODE_SUCCESS; + } + + case TSDB_SQL_CREATE_TABLE: { + SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; + + if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { + if ((code = doCheckForCreateTable(pInfo, pMsgBuf)) != TSDB_CODE_SUCCESS) { + return code; + } + pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); + pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE)? TSDB_MSG_TYPE_CREATE_TABLE:TSDB_MSG_TYPE_CREATE_STB; + } else if (pCreateTable->type == TSQL_CREATE_CTABLE) { + // if ((code = doCheckForCreateFromStable(pSql, pInfo)) != TSDB_CODE_SUCCESS) { + // return code; + // } + + } else if (pCreateTable->type == TSQL_CREATE_STREAM) { + // if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) { + // return code; + } + + break; + } + + case TSDB_SQL_DROP_TABLE: { + pDcl->pMsg = (char*)buildDropTableMsg(pInfo, &pDcl->msgLen, pCtx, pMsgBuf); + if (pDcl->pMsg == NULL) { + return terrno; + } + + pDcl->msgType = TSDB_MSG_TYPE_DROP_STB; + return TSDB_CODE_SUCCESS; break; } diff --git a/source/libs/parser/src/dataBlockMgt.c b/source/libs/parser/src/dataBlockMgt.c index d37ac74d218ea4df8f3dcbdf22693f5ed2a08c68..2f3d5aab77ecaea9bf30ab2113f6636bcee7e231 100644 --- a/source/libs/parser/src/dataBlockMgt.c +++ b/source/libs/parser/src/dataBlockMgt.c @@ -123,7 +123,6 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star dataBuf->nAllocSize = dataBuf->headerSize * 2; } - //dataBuf->pData = calloc(1, dataBuf->nAllocSize); dataBuf->pData = malloc(dataBuf->nAllocSize); if (dataBuf->pData == NULL) { tfree(dataBuf); @@ -145,8 +144,6 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star dataBuf->tsSource = -1; dataBuf->vgId = dataBuf->pTableMeta->vgId; - // tNameAssign(&dataBuf->tableName, name); - assert(defaultSize > 0 && pTableMeta != NULL && dataBuf->pTableMeta != NULL); *dataBlocks = dataBuf; diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index 2481896f092b650586c77ad8b6ebeede9127b4f7..fb7790452d8ddbbc447c7d9b3753ef094e086808 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -50,15 +50,16 @@ enum { }; typedef struct SInsertParseContext { - SParseContext* pComCxt; - const char* pSql; - SMsgBuf msg; - STableMeta* pTableMeta; - SParsedDataColInfo tags; - SKVRowBuilder tagsBuilder; - SHashObj* pTableBlockHashObj; - SArray* pTableDataBlocks; - SArray* pVgDataBlocks; + SParseContext* pComCxt; // input + const char* pSql; // input + SMsgBuf msg; // input + STableMeta* pTableMeta; // each table + SParsedDataColInfo tags; // each table + SKVRowBuilder tagsBuilder; // each table + SHashObj* pVgroupsHashObj; // global + SHashObj* pTableBlockHashObj; // global + SArray* pTableDataBlocks; // global + SArray* pVgDataBlocks; // global int32_t totalNum; SInsertStmtInfo* pOutput; } SInsertParseContext; @@ -157,14 +158,14 @@ static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullD char* p = strnchr(pStname->z, TS_PATH_DELIMITER[0], pStname->n, false); if (NULL != p) { // db.table - strcpy(fullDbName, pCxt->pComCxt->pAcctId); - fullDbName[strlen(pCxt->pComCxt->pAcctId)] = TS_PATH_DELIMITER[0]; - strncpy(fullDbName, pStname->z, p - pStname->z); + int32_t n = sprintf(fullDbName, "%d.", pCxt->pComCxt->ctx.acctId); + strncpy(fullDbName + n, pStname->z, p - pStname->z); strncpy(tableName, p + 1, pStname->n - (p - pStname->z) - 1); } else { - snprintf(fullDbName, TSDB_FULL_DB_NAME_LEN, "%s.%s", pCxt->pComCxt->pAcctId, pCxt->pComCxt->pDbname); + snprintf(fullDbName, TSDB_FULL_DB_NAME_LEN, "%d.%s", pCxt->pComCxt->ctx.acctId, pCxt->pComCxt->ctx.db); strncpy(tableName, pStname->z, pStname->n); } + return TSDB_CODE_SUCCESS; } @@ -173,10 +174,12 @@ static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) { char tableName[TSDB_TABLE_NAME_LEN] = {0}; CHECK_CODE(buildName(pCxt, pTname, fullDbName, tableName)); CHECK_CODE(catalogGetTableMeta(pCxt->pComCxt->pCatalog, pCxt->pComCxt->pRpc, pCxt->pComCxt->pEpSet, fullDbName, tableName, &pCxt->pTableMeta)); + SVgroupInfo vg; + CHECK_CODE(catalogGetTableHashVgroup(pCxt->pComCxt->pCatalog, pCxt->pComCxt->pRpc, pCxt->pComCxt->pEpSet, fullDbName, tableName, &vg)); + CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); return TSDB_CODE_SUCCESS; } -// todo speedup by using hash list static int32_t findCol(SToken* pColname, int32_t start, int32_t end, SSchema* pSchema) { while (start < end) { if (strlen(pSchema[start].name) == pColname->n && strncmp(pColname->z, pSchema[start].name, pColname->n) == 0) { @@ -187,16 +190,16 @@ static int32_t findCol(SToken* pColname, int32_t start, int32_t end, SSchema* pS return -1; } -static void fillMsgHeader(SVgDataBlocks* dst) { - SMsgDesc* desc = (SMsgDesc*)dst->pData; +static void buildMsgHeader(SVgDataBlocks* blocks) { + SMsgDesc* desc = (SMsgDesc*)blocks->pData; desc->numOfVnodes = htonl(1); SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); - submit->header.vgId = htonl(dst->vgId); - submit->header.contLen = htonl(dst->size - sizeof(SMsgDesc)); + submit->header.vgId = htonl(blocks->vg.vgId); + submit->header.contLen = htonl(blocks->size - sizeof(SMsgDesc)); submit->length = submit->header.contLen; - submit->numOfBlocks = htonl(dst->numOfTables); + submit->numOfBlocks = htonl(blocks->numOfTables); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); - int32_t numOfBlocks = dst->numOfTables; + int32_t numOfBlocks = blocks->numOfTables; while (numOfBlocks--) { int32_t dataLen = blk->dataLen; blk->uid = htobe64(blk->uid); @@ -222,11 +225,11 @@ static int32_t buildOutput(SInsertParseContext* pCxt) { if (NULL == dst) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - dst->vgId = src->vgId; + taosHashGetClone(pCxt->pVgroupsHashObj, (const char*)&src->vgId, sizeof(src->vgId), &dst->vg); dst->numOfTables = src->numOfTables; dst->size = src->size; SWAP(dst->pData, src->pData, char*); - fillMsgHeader(dst); + buildMsgHeader(dst); taosArrayPush(pCxt->pOutput->pDataBlocks, &dst); } return TSDB_CODE_SUCCESS; @@ -546,7 +549,7 @@ static FORCE_INLINE int32_t parseOneValue(SInsertParseContext* pCxt, SToken* pTo } case TSDB_DATA_TYPE_BINARY: { // too long values will return invalid sql, not be truncated automatically - if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { // todo refactor + if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { return buildSyntaxErrMsg(&pCxt->msg, "string data overflow", pToken->z); } return func(pToken->z, pToken->n, param); @@ -644,9 +647,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pTagsSchema, CHECK_CODE(parseOneValue(pCxt, &sToken, pSchema, precision, tmpTokenBuf, KvRowAppend, ¶m)); } - destroyBoundColumnInfo(&pCxt->tags); SKVRow row = tdGetKVRowFromBuilder(&pCxt->tagsBuilder); - tdDestroyKVRowBuilder(&pCxt->tagsBuilder); if (NULL == row) { return buildInvalidOperationMsg(&pCxt->msg, "tag value expected"); } @@ -799,13 +800,30 @@ static int32_t parseValuesClause(SInsertParseContext* pCxt, STableDataBlocks* da return TSDB_CODE_SUCCESS; } +static void destroyInsertParseContextForTable(SInsertParseContext* pCxt) { + tfree(pCxt->pTableMeta); + destroyBoundColumnInfo(&pCxt->tags); + tdDestroyKVRowBuilder(&pCxt->tagsBuilder); +} + +static void destroyInsertParseContext(SInsertParseContext* pCxt) { + destroyInsertParseContextForTable(pCxt); + taosHashCleanup(pCxt->pVgroupsHashObj); + taosHashCleanup(pCxt->pTableBlockHashObj); + destroyBlockArrayList(pCxt->pTableDataBlocks); + destroyBlockArrayList(pCxt->pVgDataBlocks); +} + // tb_name // [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)] // [(field1_name, ...)] // VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path // [...]; static int32_t parseInsertBody(SInsertParseContext* pCxt) { + // for each table while (1) { + destroyInsertParseContextForTable(pCxt); + SToken sToken; // pSql -> tb_name ... NEXT_TOKEN(pCxt->pSql, sToken); @@ -867,15 +885,6 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { return buildOutput(pCxt); } -static void destroyInsertParseContext(SInsertParseContext* pCxt) { - tfree(pCxt->pTableMeta); - destroyBoundColumnInfo(&pCxt->tags); - tdDestroyKVRowBuilder(&pCxt->tagsBuilder); - taosHashCleanup(pCxt->pTableBlockHashObj); - destroyBlockArrayList(pCxt->pTableDataBlocks); - destroyBlockArrayList(pCxt->pVgDataBlocks); -} - // INSERT INTO // tb_name // [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)] @@ -888,17 +897,19 @@ int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) { .pSql = pContext->pSql, .msg = {.buf = pContext->pMsg, .len = pContext->msgLen}, .pTableMeta = NULL, + .pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false), .pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false), .totalNum = 0, .pOutput = calloc(1, sizeof(SInsertStmtInfo)) }; - if (NULL == context.pTableBlockHashObj || NULL == context.pOutput) { + if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pOutput) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_FAILED; } *pInfo = context.pOutput; + context.pOutput->nodeType = TSDB_SQL_INSERT; context.pOutput->schemaAttache = pContext->schemaAttached; context.pOutput->payloadType = PAYLOAD_TYPE_KV; diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index e0ac7c295bc82d5fe9dff60519dd9ede7efe7447..9922642df31e7e86611193a70b3fadd4dfb1bfdd 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -20,7 +20,7 @@ #include "function.h" #include "insertParser.h" -bool qIsInsertSql(const char* pStr, size_t length) { +bool isInsertSql(const char* pStr, size_t length) { int32_t index = 0; do { @@ -31,18 +31,28 @@ bool qIsInsertSql(const char* pStr, size_t length) { } while (1); } -int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t *type, void** pOutput, int32_t* outputLen, char* msg, int32_t msgLen) { - SSqlInfo info = doGenerateAST(pStr); +bool qIsDclQuery(const SQueryNode* pQuery) { + return TSDB_SQL_INSERT != pQuery->type && TSDB_SQL_SELECT != pQuery->type; +} + +int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { + SSqlInfo info = doGenerateAST(pCxt->pSql); if (!info.valid) { - strncpy(msg, info.msg, msgLen); + strncpy(pCxt->pMsg, info.msg, pCxt->msgLen); terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR; return terrno; } - if (isDclSqlStatement(&info)) { - int32_t code = qParserValidateDclSqlNode(&info, id, pOutput, outputLen, type, msg, msgLen); + if (!isDqlSqlStatement(&info)) { + SDclStmtInfo* pDcl = calloc(1, sizeof(SQueryStmtInfo)); + if (NULL == pDcl) { + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; // set correct error code. + return terrno; + } + pDcl->nodeType = info.type; + int32_t code = qParserValidateDclSqlNode(&info, &pCxt->ctx, pDcl, pCxt->pMsg, pCxt->msgLen); if (code == TSDB_CODE_SUCCESS) { - // do nothing + *pQuery = (SQueryNode*)pDcl; } } else { SQueryStmtInfo* pQueryInfo = calloc(1, sizeof(SQueryStmtInfo)); @@ -53,9 +63,9 @@ int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t *typ struct SCatalog* pCatalog = NULL; int32_t code = catalogGetHandle(NULL, &pCatalog); - code = qParserValidateSqlNode(pCatalog, &info, pQueryInfo, id, msg, msgLen); + code = qParserValidateSqlNode(pCatalog, &info, pQueryInfo, pCxt->ctx.requestId, pCxt->pMsg, pCxt->msgLen); if (code == TSDB_CODE_SUCCESS) { - *pOutput = pQueryInfo; + *pQuery = (SQueryNode*)pQueryInfo; } } @@ -63,8 +73,12 @@ int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t *typ return TSDB_CODE_SUCCESS; } -int32_t qParseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) { - return parseInsertSql(pContext, pInfo); +int32_t qParseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { + if (isInsertSql(pCxt->pSql, pCxt->sqlLen)) { + return parseInsertSql(pCxt, (SInsertStmtInfo**)pQuery); + } else { + return parseQuerySql(pCxt, pQuery); + } } int32_t qParserConvertSql(const char* pStr, size_t length, char** pConvertSql) { diff --git a/source/libs/parser/src/parserUtil.c b/source/libs/parser/src/parserUtil.c index b72bc06324d3a33e960b713c421e0af77a3dd86d..307062ef155d952e7c95dcdcfe6b1b480d26fdff 100644 --- a/source/libs/parser/src/parserUtil.c +++ b/source/libs/parser/src/parserUtil.c @@ -1167,7 +1167,7 @@ void cleanupTagCond(STagCond* pTagCond) { * @param tableIndex denote the table index for join query, where more than one table exists * @return */ -STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex) { +STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex) { assert(pQueryInfo != NULL); if (pQueryInfo->pTableMetaInfo == NULL) { assert(pQueryInfo->numOfTables == 0); @@ -1613,7 +1613,18 @@ uint32_t convertRelationalOperator(SToken *pToken) { } bool isDclSqlStatement(SSqlInfo* pSqlInfo) { - return (pSqlInfo->type != TSDB_SQL_SELECT); + int32_t type = pSqlInfo->type; + return (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_CREATE_ACCT || type == TSDB_SQL_DROP_USER || + type == TSDB_SQL_DROP_ACCT || type == TSDB_SQL_SHOW); +} + +bool isDdlSqlStatement(SSqlInfo* pSqlInfo) { + int32_t type = pSqlInfo->type; + return (type == TSDB_SQL_CREATE_TABLE || type == TSDB_SQL_CREATE_DB || type == TSDB_SQL_DROP_DB); +} + +bool isDqlSqlStatement(SSqlInfo* pSqlInfo) { + return pSqlInfo->type == TSDB_SQL_SELECT; } #if 0 diff --git a/source/libs/parser/src/queryInfoUtil.c b/source/libs/parser/src/queryInfoUtil.c index 502946675b40738c8ec7d3e35287669ce04dab71..1ae0d9211a2925b27b415becfab1fc385d242965 100644 --- a/source/libs/parser/src/queryInfoUtil.c +++ b/source/libs/parser/src/queryInfoUtil.c @@ -354,7 +354,7 @@ bool tscHasColumnFilter(SQueryStmtInfo* pQueryInfo) { return false; } -int32_t getExprFunctionLevel(SQueryStmtInfo* pQueryInfo) { +int32_t getExprFunctionLevel(const SQueryStmtInfo* pQueryInfo) { int32_t n = 10; int32_t level = 0; diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index d674462fc0f277fa5be0a7a5988f28eed15c1499..5295faf645c137e749eac0b0f3ed30b2e393a562 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -35,6 +35,7 @@ #include "ttoken.h" #include "ttokendef.h" #include "tvariant.h" +#include "parserInt.h" /**************** End of %include directives **********************************/ /* These constants specify the various numeric values for terminal symbols ** in a format understandable to "makeheaders". This section is blank unless @@ -96,30 +97,30 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 280 +#define YYNOCODE 276 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SCreatedTableInfo yy78; - SCreateTableSql* yy110; - int yy130; - SArray* yy135; - SIntervalVal yy160; - SVariant yy191; - SLimit yy247; - SCreateDbInfo yy256; - SWindowStateVal yy258; - int32_t yy262; - SCreateAcctInfo yy277; - SField yy304; - SRelationInfo* yy460; - SSqlNode* yy488; - SSessionWindowVal yy511; - tSqlExpr* yy526; - int64_t yy531; - SSubclause* yy551; + SSessionWindowVal yy39; + SCreateDbInfo yy42; + SVariant yy43; + int yy44; + tSqlExpr* yy46; + SLimit yy55; + SCreatedTableInfo yy96; + SArray* yy131; + SSqlNode* yy256; + SCreateTableSql* yy272; + SField yy290; + SSubclause* yy303; + int32_t yy310; + SCreateAcctInfo yy341; + int64_t yy459; + SIntervalVal yy530; + SWindowStateVal yy538; + SRelationInfo* yy544; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -129,17 +130,17 @@ typedef union { #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 -#define YYNSTATE 368 -#define YYNRULE 295 -#define YYNTOKEN 197 -#define YY_MAX_SHIFT 367 -#define YY_MIN_SHIFTREDUCE 577 -#define YY_MAX_SHIFTREDUCE 871 -#define YY_ERROR_ACTION 872 -#define YY_ACCEPT_ACTION 873 -#define YY_NO_ACTION 874 -#define YY_MIN_REDUCE 875 -#define YY_MAX_REDUCE 1169 +#define YYNSTATE 358 +#define YYNRULE 288 +#define YYNTOKEN 196 +#define YY_MAX_SHIFT 357 +#define YY_MIN_SHIFTREDUCE 564 +#define YY_MAX_SHIFTREDUCE 851 +#define YY_ERROR_ACTION 852 +#define YY_ACCEPT_ACTION 853 +#define YY_NO_ACTION 854 +#define YY_MIN_REDUCE 855 +#define YY_MAX_REDUCE 1142 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -205,293 +206,287 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (776) +#define YY_ACTTAB_COUNT (762) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 23, 629, 366, 236, 1054, 209, 242, 713, 212, 630, - /* 10 */ 1031, 873, 367, 59, 60, 174, 63, 64, 1044, 1145, - /* 20 */ 256, 53, 52, 51, 629, 62, 324, 67, 65, 68, - /* 30 */ 66, 158, 630, 286, 239, 58, 57, 344, 343, 56, - /* 40 */ 55, 54, 59, 60, 248, 63, 64, 253, 1031, 256, - /* 50 */ 53, 52, 51, 665, 62, 324, 67, 65, 68, 66, - /* 60 */ 1001, 1044, 999, 1000, 58, 57, 210, 1002, 56, 55, - /* 70 */ 54, 1003, 1051, 1004, 1005, 58, 57, 278, 216, 56, - /* 80 */ 55, 54, 59, 60, 165, 63, 64, 38, 83, 256, - /* 90 */ 53, 52, 51, 89, 62, 324, 67, 65, 68, 66, - /* 100 */ 284, 283, 250, 754, 58, 57, 1031, 212, 56, 55, - /* 110 */ 54, 38, 59, 61, 808, 63, 64, 1044, 1146, 256, - /* 120 */ 53, 52, 51, 629, 62, 324, 67, 65, 68, 66, - /* 130 */ 45, 630, 238, 240, 58, 57, 1028, 165, 56, 55, - /* 140 */ 54, 60, 1025, 63, 64, 773, 774, 256, 53, 52, - /* 150 */ 51, 96, 62, 324, 67, 65, 68, 66, 165, 1093, - /* 160 */ 1027, 296, 58, 57, 89, 84, 56, 55, 54, 578, - /* 170 */ 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, - /* 180 */ 589, 590, 591, 156, 322, 237, 63, 64, 758, 249, - /* 190 */ 256, 53, 52, 51, 629, 62, 324, 67, 65, 68, - /* 200 */ 66, 45, 630, 88, 1017, 58, 57, 362, 962, 56, - /* 210 */ 55, 54, 1092, 44, 320, 361, 360, 319, 318, 317, - /* 220 */ 359, 316, 315, 314, 358, 313, 357, 356, 155, 153, - /* 230 */ 152, 298, 24, 94, 993, 981, 982, 983, 984, 985, - /* 240 */ 986, 987, 988, 989, 990, 991, 992, 994, 995, 215, - /* 250 */ 751, 255, 823, 924, 126, 812, 223, 815, 354, 818, - /* 260 */ 193, 98, 140, 139, 138, 222, 354, 255, 823, 329, - /* 270 */ 89, 812, 252, 815, 270, 818, 9, 29, 217, 67, - /* 280 */ 65, 68, 66, 274, 273, 234, 235, 58, 57, 325, - /* 290 */ 322, 56, 55, 54, 1014, 1015, 35, 1018, 814, 218, - /* 300 */ 817, 234, 235, 259, 5, 41, 183, 45, 56, 55, - /* 310 */ 54, 182, 107, 112, 103, 111, 38, 264, 737, 38, - /* 320 */ 934, 734, 742, 735, 743, 736, 165, 193, 257, 277, - /* 330 */ 309, 81, 212, 38, 69, 124, 118, 129, 230, 813, - /* 340 */ 1140, 816, 128, 1146, 134, 137, 127, 203, 201, 199, - /* 350 */ 69, 261, 262, 131, 198, 144, 143, 142, 141, 38, - /* 360 */ 44, 246, 361, 360, 247, 1028, 101, 359, 1028, 824, - /* 370 */ 819, 358, 38, 357, 356, 38, 820, 38, 333, 260, - /* 380 */ 38, 258, 1028, 332, 331, 824, 819, 790, 212, 365, - /* 390 */ 364, 149, 820, 266, 38, 263, 38, 339, 338, 1146, - /* 400 */ 265, 95, 1019, 14, 334, 265, 82, 97, 1028, 86, - /* 410 */ 77, 179, 265, 3, 194, 87, 180, 335, 326, 821, - /* 420 */ 336, 1028, 340, 1029, 1028, 341, 1028, 925, 279, 1028, - /* 430 */ 74, 1, 181, 770, 193, 738, 739, 100, 34, 342, - /* 440 */ 1016, 346, 39, 1028, 789, 1028, 73, 160, 780, 781, - /* 450 */ 78, 723, 73, 301, 725, 303, 724, 810, 254, 846, - /* 460 */ 822, 825, 70, 26, 628, 39, 80, 39, 70, 99, - /* 470 */ 70, 304, 75, 25, 16, 25, 15, 1139, 25, 117, - /* 480 */ 6, 116, 18, 1138, 17, 740, 20, 741, 19, 123, - /* 490 */ 232, 122, 22, 233, 21, 811, 136, 135, 712, 213, - /* 500 */ 275, 214, 219, 211, 220, 221, 225, 1030, 226, 227, - /* 510 */ 224, 208, 1165, 1157, 1103, 1046, 1102, 244, 1099, 1098, - /* 520 */ 245, 345, 827, 157, 48, 1053, 1064, 1085, 1061, 1062, - /* 530 */ 1045, 1084, 281, 1066, 1026, 154, 159, 164, 292, 175, - /* 540 */ 176, 1024, 33, 285, 177, 168, 178, 939, 769, 306, - /* 550 */ 307, 308, 311, 312, 1042, 46, 206, 42, 323, 933, - /* 560 */ 330, 1164, 114, 241, 79, 1163, 287, 1160, 289, 76, - /* 570 */ 166, 299, 184, 337, 167, 1156, 50, 120, 1155, 297, - /* 580 */ 1152, 185, 295, 959, 43, 40, 47, 207, 921, 130, - /* 590 */ 919, 132, 133, 917, 916, 267, 293, 196, 197, 913, - /* 600 */ 912, 911, 910, 291, 909, 908, 907, 200, 202, 904, - /* 610 */ 902, 900, 898, 204, 895, 205, 288, 891, 49, 310, - /* 620 */ 280, 85, 90, 290, 355, 1086, 348, 125, 347, 349, - /* 630 */ 350, 351, 231, 352, 251, 305, 353, 363, 871, 269, - /* 640 */ 870, 268, 271, 228, 229, 108, 938, 937, 109, 272, - /* 650 */ 869, 852, 276, 851, 73, 10, 915, 300, 282, 914, - /* 660 */ 745, 145, 188, 146, 187, 960, 186, 189, 190, 192, - /* 670 */ 191, 906, 905, 961, 147, 997, 2, 30, 148, 897, - /* 680 */ 896, 91, 171, 169, 172, 170, 173, 1007, 771, 4, - /* 690 */ 161, 163, 782, 162, 243, 776, 92, 31, 778, 93, - /* 700 */ 294, 11, 12, 32, 13, 27, 302, 28, 100, 102, - /* 710 */ 105, 36, 104, 643, 37, 106, 678, 676, 675, 674, - /* 720 */ 672, 671, 670, 667, 633, 321, 110, 7, 327, 328, - /* 730 */ 828, 39, 826, 8, 113, 71, 115, 72, 715, 714, - /* 740 */ 119, 711, 659, 121, 657, 649, 655, 651, 653, 647, - /* 750 */ 645, 681, 680, 679, 677, 673, 669, 668, 195, 631, - /* 760 */ 595, 875, 874, 874, 874, 874, 874, 874, 874, 874, - /* 770 */ 874, 874, 874, 874, 150, 151, + /* 0 */ 94, 615, 233, 244, 356, 227, 1004, 239, 243, 616, + /* 10 */ 615, 1004, 21, 55, 56, 241, 59, 60, 616, 1004, + /* 20 */ 247, 49, 48, 47, 200, 58, 315, 63, 61, 64, + /* 30 */ 62, 987, 988, 33, 991, 54, 53, 853, 357, 52, + /* 40 */ 51, 50, 55, 56, 97, 59, 60, 650, 248, 247, + /* 50 */ 49, 48, 47, 201, 58, 315, 63, 61, 64, 62, + /* 60 */ 976, 203, 974, 975, 54, 53, 203, 977, 52, 51, + /* 70 */ 50, 978, 1119, 979, 980, 54, 53, 1119, 992, 52, + /* 80 */ 51, 50, 55, 56, 1017, 59, 60, 159, 79, 247, + /* 90 */ 49, 48, 47, 27, 58, 315, 63, 61, 64, 62, + /* 100 */ 269, 313, 693, 990, 54, 53, 203, 998, 52, 51, + /* 110 */ 50, 345, 55, 57, 788, 59, 60, 1119, 36, 247, + /* 120 */ 49, 48, 47, 615, 58, 315, 63, 61, 64, 62, + /* 130 */ 1017, 616, 335, 334, 54, 53, 152, 615, 52, 51, + /* 140 */ 50, 56, 36, 59, 60, 616, 230, 247, 49, 48, + /* 150 */ 47, 240, 58, 315, 63, 61, 64, 62, 159, 1066, + /* 160 */ 229, 287, 54, 53, 1001, 73, 52, 51, 50, 565, + /* 170 */ 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, + /* 180 */ 576, 577, 578, 150, 237, 228, 59, 60, 1001, 313, + /* 190 */ 247, 49, 48, 47, 250, 58, 315, 63, 61, 64, + /* 200 */ 62, 203, 275, 274, 74, 54, 53, 753, 754, 52, + /* 210 */ 51, 50, 1118, 42, 311, 351, 350, 310, 309, 308, + /* 220 */ 349, 307, 306, 305, 348, 304, 347, 346, 289, 22, + /* 230 */ 90, 970, 958, 959, 960, 961, 962, 963, 964, 965, + /* 240 */ 966, 967, 968, 969, 971, 972, 212, 1017, 246, 803, + /* 250 */ 36, 36, 792, 213, 795, 36, 798, 168, 36, 134, + /* 260 */ 133, 132, 214, 231, 246, 803, 320, 85, 792, 251, + /* 270 */ 795, 249, 798, 323, 322, 277, 63, 61, 64, 62, + /* 280 */ 206, 255, 225, 226, 54, 53, 316, 85, 52, 51, + /* 290 */ 50, 12, 238, 324, 85, 93, 1001, 1001, 225, 226, + /* 300 */ 325, 1000, 717, 43, 1001, 714, 261, 715, 207, 716, + /* 310 */ 194, 192, 190, 159, 1027, 265, 264, 189, 138, 137, + /* 320 */ 136, 135, 36, 43, 96, 268, 42, 77, 351, 350, + /* 330 */ 43, 65, 84, 349, 221, 252, 253, 348, 36, 347, + /* 340 */ 346, 3, 39, 175, 119, 113, 123, 65, 36, 103, + /* 350 */ 107, 99, 106, 128, 131, 122, 257, 36, 254, 36, + /* 360 */ 330, 329, 125, 159, 326, 804, 799, 300, 1001, 734, + /* 370 */ 36, 121, 800, 52, 51, 50, 794, 256, 797, 1024, + /* 380 */ 327, 804, 799, 345, 1001, 1065, 173, 793, 800, 796, + /* 390 */ 331, 149, 147, 146, 1001, 355, 354, 143, 256, 332, + /* 400 */ 256, 333, 903, 1001, 770, 1001, 78, 174, 185, 1002, + /* 410 */ 352, 940, 337, 70, 92, 731, 1001, 913, 718, 719, + /* 420 */ 904, 82, 270, 185, 790, 83, 185, 750, 80, 760, + /* 430 */ 761, 703, 292, 705, 294, 91, 37, 704, 989, 32, + /* 440 */ 7, 154, 826, 66, 24, 37, 37, 66, 95, 805, + /* 450 */ 245, 66, 317, 738, 71, 614, 23, 69, 76, 208, + /* 460 */ 769, 69, 791, 23, 14, 112, 13, 111, 16, 23, + /* 470 */ 15, 295, 4, 722, 720, 723, 721, 18, 118, 17, + /* 480 */ 117, 20, 1113, 19, 130, 129, 1112, 1111, 223, 692, + /* 490 */ 224, 204, 205, 209, 202, 210, 801, 211, 216, 217, + /* 500 */ 218, 215, 199, 1003, 1138, 1130, 1019, 802, 1076, 1075, + /* 510 */ 235, 1072, 1071, 44, 236, 336, 266, 1058, 169, 151, + /* 520 */ 1026, 148, 1037, 1034, 1035, 1018, 272, 1057, 1039, 999, + /* 530 */ 1015, 276, 153, 232, 278, 280, 31, 158, 283, 163, + /* 540 */ 170, 160, 997, 161, 749, 162, 164, 165, 166, 171, + /* 550 */ 172, 301, 917, 297, 290, 807, 284, 298, 299, 302, + /* 560 */ 303, 197, 40, 75, 314, 912, 321, 1137, 109, 72, + /* 570 */ 46, 1136, 1133, 288, 176, 328, 1129, 115, 1128, 1125, + /* 580 */ 177, 286, 937, 41, 38, 198, 901, 279, 124, 899, + /* 590 */ 126, 127, 897, 896, 258, 187, 188, 893, 892, 891, + /* 600 */ 890, 889, 888, 282, 887, 191, 193, 884, 882, 880, + /* 610 */ 878, 195, 875, 196, 871, 45, 120, 271, 81, 86, + /* 620 */ 338, 281, 1059, 339, 340, 341, 222, 343, 342, 242, + /* 630 */ 296, 344, 353, 851, 259, 260, 219, 220, 850, 104, + /* 640 */ 916, 915, 262, 263, 849, 832, 895, 894, 831, 267, + /* 650 */ 291, 139, 69, 886, 180, 140, 179, 938, 178, 181, + /* 660 */ 182, 184, 183, 939, 141, 885, 8, 142, 877, 2, + /* 670 */ 1, 876, 725, 28, 273, 167, 87, 751, 155, 157, + /* 680 */ 762, 156, 234, 756, 88, 29, 758, 89, 285, 9, + /* 690 */ 30, 10, 11, 25, 293, 26, 96, 98, 101, 34, + /* 700 */ 100, 628, 35, 102, 663, 661, 660, 659, 657, 656, + /* 710 */ 655, 652, 619, 312, 105, 5, 318, 806, 319, 6, + /* 720 */ 808, 108, 110, 67, 68, 695, 37, 694, 691, 114, + /* 730 */ 644, 116, 642, 634, 640, 636, 638, 632, 630, 665, + /* 740 */ 664, 662, 658, 654, 653, 186, 617, 144, 582, 855, + /* 750 */ 854, 854, 854, 854, 854, 854, 854, 854, 854, 854, + /* 760 */ 854, 145, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 267, 1, 200, 201, 200, 267, 246, 5, 267, 9, - /* 10 */ 250, 198, 199, 13, 14, 254, 16, 17, 248, 278, - /* 20 */ 20, 21, 22, 23, 1, 25, 26, 27, 28, 29, - /* 30 */ 30, 200, 9, 272, 264, 35, 36, 35, 36, 39, - /* 40 */ 40, 41, 13, 14, 246, 16, 17, 207, 250, 20, - /* 50 */ 21, 22, 23, 5, 25, 26, 27, 28, 29, 30, - /* 60 */ 224, 248, 226, 227, 35, 36, 267, 231, 39, 40, - /* 70 */ 41, 235, 268, 237, 238, 35, 36, 264, 267, 39, - /* 80 */ 40, 41, 13, 14, 200, 16, 17, 200, 88, 20, + /* 0 */ 206, 1, 242, 205, 199, 200, 246, 242, 205, 9, + /* 10 */ 1, 246, 263, 13, 14, 242, 16, 17, 9, 246, + /* 20 */ 20, 21, 22, 23, 263, 25, 26, 27, 28, 29, + /* 30 */ 30, 237, 238, 239, 240, 35, 36, 197, 198, 39, + /* 40 */ 40, 41, 13, 14, 206, 16, 17, 5, 205, 20, + /* 50 */ 21, 22, 23, 263, 25, 26, 27, 28, 29, 30, + /* 60 */ 221, 263, 223, 224, 35, 36, 263, 228, 39, 40, + /* 70 */ 41, 232, 274, 234, 235, 35, 36, 274, 240, 39, + /* 80 */ 40, 41, 13, 14, 244, 16, 17, 199, 88, 20, /* 90 */ 21, 22, 23, 84, 25, 26, 27, 28, 29, 30, - /* 100 */ 269, 270, 246, 39, 35, 36, 250, 267, 39, 40, - /* 110 */ 41, 200, 13, 14, 85, 16, 17, 248, 278, 20, + /* 100 */ 260, 86, 5, 0, 35, 36, 263, 199, 39, 40, + /* 110 */ 41, 92, 13, 14, 85, 16, 17, 274, 199, 20, /* 120 */ 21, 22, 23, 1, 25, 26, 27, 28, 29, 30, - /* 130 */ 121, 9, 245, 264, 35, 36, 249, 200, 39, 40, - /* 140 */ 41, 14, 200, 16, 17, 127, 128, 20, 21, 22, - /* 150 */ 23, 251, 25, 26, 27, 28, 29, 30, 200, 275, - /* 160 */ 249, 277, 35, 36, 84, 265, 39, 40, 41, 47, + /* 130 */ 244, 9, 35, 36, 35, 36, 199, 1, 39, 40, + /* 140 */ 41, 14, 199, 16, 17, 9, 260, 20, 21, 22, + /* 150 */ 23, 243, 25, 26, 27, 28, 29, 30, 199, 271, + /* 160 */ 241, 273, 35, 36, 245, 99, 39, 40, 41, 47, /* 170 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 180 */ 58, 59, 60, 61, 86, 63, 16, 17, 124, 247, - /* 190 */ 20, 21, 22, 23, 1, 25, 26, 27, 28, 29, - /* 200 */ 30, 121, 9, 123, 0, 35, 36, 222, 223, 39, - /* 210 */ 40, 41, 275, 100, 101, 102, 103, 104, 105, 106, - /* 220 */ 107, 108, 109, 110, 111, 112, 113, 114, 64, 65, - /* 230 */ 66, 273, 46, 275, 224, 225, 226, 227, 228, 229, - /* 240 */ 230, 231, 232, 233, 234, 235, 236, 237, 238, 63, - /* 250 */ 99, 1, 2, 206, 80, 5, 70, 7, 92, 9, - /* 260 */ 213, 208, 76, 77, 78, 79, 92, 1, 2, 83, - /* 270 */ 84, 5, 207, 7, 144, 9, 125, 84, 267, 27, - /* 280 */ 28, 29, 30, 153, 154, 35, 36, 35, 36, 39, - /* 290 */ 86, 39, 40, 41, 241, 242, 243, 244, 5, 267, - /* 300 */ 7, 35, 36, 70, 64, 65, 66, 121, 39, 40, - /* 310 */ 41, 71, 72, 73, 74, 75, 200, 70, 2, 200, - /* 320 */ 206, 5, 5, 7, 7, 9, 200, 213, 207, 143, - /* 330 */ 90, 145, 267, 200, 84, 64, 65, 66, 152, 5, - /* 340 */ 267, 7, 71, 278, 73, 74, 75, 64, 65, 66, - /* 350 */ 84, 35, 36, 82, 71, 72, 73, 74, 75, 200, - /* 360 */ 100, 245, 102, 103, 245, 249, 208, 107, 249, 119, - /* 370 */ 120, 111, 200, 113, 114, 200, 126, 200, 245, 146, - /* 380 */ 200, 148, 249, 150, 151, 119, 120, 78, 267, 67, - /* 390 */ 68, 69, 126, 146, 200, 148, 200, 150, 151, 278, - /* 400 */ 200, 275, 244, 84, 245, 200, 208, 88, 249, 85, - /* 410 */ 99, 211, 200, 204, 205, 85, 211, 245, 15, 126, - /* 420 */ 245, 249, 245, 211, 249, 245, 249, 206, 85, 249, - /* 430 */ 99, 209, 210, 85, 213, 119, 120, 118, 84, 245, - /* 440 */ 242, 245, 99, 249, 135, 249, 122, 99, 85, 85, - /* 450 */ 139, 85, 122, 85, 85, 85, 85, 1, 62, 85, - /* 460 */ 126, 85, 99, 99, 85, 99, 84, 99, 99, 99, - /* 470 */ 99, 117, 141, 99, 147, 99, 149, 267, 99, 147, - /* 480 */ 84, 149, 147, 267, 149, 5, 147, 7, 149, 147, - /* 490 */ 267, 149, 147, 267, 149, 39, 80, 81, 116, 267, - /* 500 */ 200, 267, 267, 267, 267, 267, 267, 250, 267, 267, - /* 510 */ 267, 267, 250, 250, 240, 248, 240, 240, 240, 240, - /* 520 */ 240, 240, 119, 200, 266, 200, 200, 276, 200, 200, - /* 530 */ 248, 276, 248, 200, 248, 62, 200, 200, 200, 252, - /* 540 */ 200, 200, 253, 271, 200, 260, 200, 200, 126, 200, - /* 550 */ 200, 200, 200, 200, 263, 200, 200, 200, 200, 200, - /* 560 */ 200, 200, 200, 271, 138, 200, 271, 200, 271, 140, - /* 570 */ 262, 133, 200, 200, 261, 200, 137, 200, 200, 136, - /* 580 */ 200, 200, 131, 200, 200, 200, 200, 200, 200, 200, - /* 590 */ 200, 200, 200, 200, 200, 200, 130, 200, 200, 200, - /* 600 */ 200, 200, 200, 129, 200, 200, 200, 200, 200, 200, - /* 610 */ 200, 200, 200, 200, 200, 200, 132, 200, 142, 91, - /* 620 */ 202, 202, 202, 202, 115, 202, 53, 98, 97, 94, - /* 630 */ 96, 57, 202, 95, 202, 202, 93, 86, 5, 5, - /* 640 */ 5, 155, 155, 202, 202, 208, 212, 212, 208, 5, - /* 650 */ 5, 102, 144, 101, 122, 84, 202, 117, 99, 202, - /* 660 */ 85, 203, 215, 203, 219, 221, 220, 218, 216, 214, - /* 670 */ 217, 202, 202, 223, 203, 239, 209, 84, 203, 202, - /* 680 */ 202, 99, 257, 259, 256, 258, 255, 239, 85, 204, - /* 690 */ 84, 99, 85, 84, 1, 85, 84, 99, 85, 84, - /* 700 */ 84, 134, 134, 99, 84, 84, 117, 84, 118, 80, - /* 710 */ 72, 89, 88, 5, 89, 88, 9, 5, 5, 5, - /* 720 */ 5, 5, 5, 5, 87, 15, 80, 84, 26, 61, - /* 730 */ 119, 99, 85, 84, 149, 16, 149, 16, 5, 5, - /* 740 */ 149, 85, 5, 149, 5, 5, 5, 5, 5, 5, - /* 750 */ 5, 5, 5, 5, 5, 5, 5, 5, 99, 87, - /* 760 */ 62, 0, 279, 279, 279, 279, 279, 279, 279, 279, - /* 770 */ 279, 279, 279, 279, 21, 21, 279, 279, 279, 279, - /* 780 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 790 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 800 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 810 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 820 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 830 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 840 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 850 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 860 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 870 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 880 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 890 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 900 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 910 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 920 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 930 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 940 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 950 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 960 */ 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, - /* 970 */ 279, 279, 279, + /* 180 */ 58, 59, 60, 61, 241, 63, 16, 17, 245, 86, + /* 190 */ 20, 21, 22, 23, 70, 25, 26, 27, 28, 29, + /* 200 */ 30, 263, 265, 266, 138, 35, 36, 126, 127, 39, + /* 210 */ 40, 41, 274, 100, 101, 102, 103, 104, 105, 106, + /* 220 */ 107, 108, 109, 110, 111, 112, 113, 114, 269, 46, + /* 230 */ 271, 221, 222, 223, 224, 225, 226, 227, 228, 229, + /* 240 */ 230, 231, 232, 233, 234, 235, 63, 244, 1, 2, + /* 250 */ 199, 199, 5, 70, 7, 199, 9, 250, 199, 76, + /* 260 */ 77, 78, 79, 260, 1, 2, 83, 84, 5, 145, + /* 270 */ 7, 147, 9, 149, 150, 268, 27, 28, 29, 30, + /* 280 */ 263, 70, 35, 36, 35, 36, 39, 84, 39, 40, + /* 290 */ 41, 84, 241, 241, 84, 88, 245, 245, 35, 36, + /* 300 */ 241, 245, 2, 120, 245, 5, 143, 7, 263, 9, + /* 310 */ 64, 65, 66, 199, 199, 152, 153, 71, 72, 73, + /* 320 */ 74, 75, 199, 120, 117, 142, 100, 144, 102, 103, + /* 330 */ 120, 84, 122, 107, 151, 35, 36, 111, 199, 113, + /* 340 */ 114, 64, 65, 66, 64, 65, 66, 84, 199, 72, + /* 350 */ 73, 74, 75, 73, 74, 75, 145, 199, 147, 199, + /* 360 */ 149, 150, 82, 199, 241, 118, 119, 90, 245, 39, + /* 370 */ 199, 80, 125, 39, 40, 41, 5, 199, 7, 264, + /* 380 */ 241, 118, 119, 92, 245, 271, 208, 5, 125, 7, + /* 390 */ 241, 64, 65, 66, 245, 67, 68, 69, 199, 241, + /* 400 */ 199, 241, 204, 245, 78, 245, 206, 208, 210, 208, + /* 410 */ 219, 220, 241, 99, 247, 99, 245, 204, 118, 119, + /* 420 */ 204, 85, 85, 210, 1, 85, 210, 85, 261, 85, + /* 430 */ 85, 85, 85, 85, 85, 271, 99, 85, 238, 84, + /* 440 */ 124, 99, 85, 99, 99, 99, 99, 99, 99, 85, + /* 450 */ 62, 99, 15, 123, 140, 85, 99, 121, 84, 263, + /* 460 */ 134, 121, 39, 99, 146, 146, 148, 148, 146, 99, + /* 470 */ 148, 116, 84, 5, 5, 7, 7, 146, 146, 148, + /* 480 */ 148, 146, 263, 148, 80, 81, 263, 263, 263, 115, + /* 490 */ 263, 263, 263, 263, 263, 263, 125, 263, 263, 263, + /* 500 */ 263, 263, 263, 246, 246, 246, 244, 125, 236, 236, + /* 510 */ 236, 236, 236, 262, 236, 236, 199, 272, 248, 199, + /* 520 */ 199, 62, 199, 199, 199, 244, 244, 272, 199, 244, + /* 530 */ 259, 267, 199, 267, 267, 267, 249, 199, 199, 255, + /* 540 */ 199, 258, 199, 257, 125, 256, 254, 253, 252, 199, + /* 550 */ 199, 91, 199, 199, 132, 118, 129, 199, 199, 199, + /* 560 */ 199, 199, 199, 137, 199, 199, 199, 199, 199, 139, + /* 570 */ 136, 199, 199, 135, 199, 199, 199, 199, 199, 199, + /* 580 */ 199, 130, 199, 199, 199, 199, 199, 131, 199, 199, + /* 590 */ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + /* 600 */ 199, 199, 199, 128, 199, 199, 199, 199, 199, 199, + /* 610 */ 199, 199, 199, 199, 199, 141, 98, 201, 201, 201, + /* 620 */ 97, 201, 201, 53, 94, 96, 201, 95, 57, 201, + /* 630 */ 201, 93, 86, 5, 154, 5, 201, 201, 5, 206, + /* 640 */ 209, 209, 154, 5, 5, 102, 201, 201, 101, 143, + /* 650 */ 116, 202, 121, 201, 212, 202, 216, 218, 217, 215, + /* 660 */ 213, 211, 214, 220, 202, 201, 84, 202, 201, 203, + /* 670 */ 207, 201, 85, 84, 99, 251, 99, 85, 84, 99, + /* 680 */ 85, 84, 1, 85, 84, 99, 85, 84, 84, 133, + /* 690 */ 99, 133, 84, 84, 116, 84, 117, 80, 72, 89, + /* 700 */ 88, 5, 89, 88, 9, 5, 5, 5, 5, 5, + /* 710 */ 5, 5, 87, 15, 80, 84, 26, 85, 61, 84, + /* 720 */ 118, 148, 148, 16, 16, 5, 99, 5, 85, 148, + /* 730 */ 5, 148, 5, 5, 5, 5, 5, 5, 5, 5, + /* 740 */ 5, 5, 5, 5, 5, 99, 87, 21, 62, 0, + /* 750 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 760 */ 275, 21, 275, 275, 275, 275, 275, 275, 275, 275, + /* 770 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 780 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 790 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 800 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 810 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 820 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 830 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 840 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 850 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 860 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 870 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 880 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 890 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 900 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 910 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 920 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 930 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 940 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 950 */ 275, 275, 275, 275, 275, 275, 275, 275, }; -#define YY_SHIFT_COUNT (367) +#define YY_SHIFT_COUNT (357) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (761) +#define YY_SHIFT_MAX (749) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 186, 113, 113, 260, 260, 98, 250, 266, 266, 193, - /* 10 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 20 */ 23, 23, 23, 0, 122, 266, 316, 316, 316, 9, - /* 30 */ 9, 23, 23, 18, 23, 204, 23, 23, 23, 23, - /* 40 */ 174, 98, 166, 166, 48, 776, 776, 776, 266, 266, - /* 50 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, - /* 60 */ 266, 266, 266, 266, 266, 266, 266, 266, 266, 266, - /* 70 */ 316, 316, 316, 80, 2, 2, 2, 2, 2, 2, - /* 80 */ 2, 23, 23, 23, 64, 23, 23, 23, 9, 9, - /* 90 */ 23, 23, 23, 23, 309, 309, 151, 9, 23, 23, - /* 100 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 110 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 120 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 130 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 140 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 150 */ 23, 23, 23, 23, 23, 23, 23, 473, 473, 473, - /* 160 */ 422, 422, 422, 422, 473, 473, 426, 429, 438, 439, - /* 170 */ 443, 451, 466, 474, 484, 476, 473, 473, 473, 528, - /* 180 */ 528, 509, 98, 98, 473, 473, 529, 531, 573, 535, - /* 190 */ 534, 574, 538, 543, 509, 48, 473, 473, 551, 551, - /* 200 */ 473, 551, 473, 551, 473, 473, 776, 776, 29, 69, - /* 210 */ 69, 99, 69, 127, 170, 240, 252, 252, 252, 252, - /* 220 */ 252, 252, 271, 283, 40, 40, 40, 40, 233, 247, - /* 230 */ 130, 319, 269, 269, 293, 334, 322, 164, 343, 324, - /* 240 */ 330, 348, 363, 364, 331, 311, 366, 368, 369, 370, - /* 250 */ 371, 354, 374, 376, 456, 396, 403, 379, 327, 332, - /* 260 */ 335, 317, 480, 339, 342, 382, 345, 416, 633, 486, - /* 270 */ 634, 635, 487, 644, 645, 549, 552, 508, 532, 540, - /* 280 */ 571, 575, 593, 559, 582, 603, 606, 607, 609, 610, - /* 290 */ 592, 612, 613, 615, 693, 616, 598, 567, 604, 568, - /* 300 */ 620, 540, 621, 589, 623, 590, 629, 622, 624, 638, - /* 310 */ 708, 625, 627, 707, 712, 713, 714, 715, 716, 717, - /* 320 */ 718, 637, 710, 646, 643, 647, 611, 649, 702, 668, - /* 330 */ 719, 585, 587, 632, 632, 632, 632, 721, 591, 594, - /* 340 */ 632, 632, 632, 733, 734, 656, 632, 737, 739, 740, - /* 350 */ 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, - /* 360 */ 751, 752, 659, 672, 753, 754, 698, 761, + /* 0 */ 183, 113, 226, 15, 247, 263, 263, 9, 136, 136, + /* 10 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + /* 20 */ 136, 0, 122, 263, 300, 300, 300, 203, 203, 136, + /* 30 */ 136, 81, 136, 103, 136, 136, 136, 136, 291, 15, + /* 40 */ 19, 19, 42, 762, 263, 263, 263, 263, 263, 263, + /* 50 */ 263, 263, 263, 263, 263, 263, 263, 263, 263, 263, + /* 60 */ 263, 263, 263, 263, 263, 263, 300, 300, 300, 210, + /* 70 */ 97, 97, 97, 97, 97, 97, 97, 136, 136, 136, + /* 80 */ 330, 136, 136, 136, 203, 203, 136, 136, 136, 136, + /* 90 */ 326, 326, 316, 203, 136, 136, 136, 136, 136, 136, + /* 100 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + /* 110 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + /* 120 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + /* 130 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + /* 140 */ 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + /* 150 */ 136, 459, 459, 459, 419, 419, 419, 419, 459, 459, + /* 160 */ 426, 430, 422, 434, 438, 451, 427, 475, 456, 474, + /* 170 */ 459, 459, 459, 460, 460, 15, 459, 459, 518, 523, + /* 180 */ 570, 530, 529, 571, 532, 538, 42, 459, 459, 546, + /* 190 */ 546, 459, 546, 459, 546, 459, 459, 762, 762, 29, + /* 200 */ 69, 69, 99, 69, 127, 170, 249, 249, 249, 249, + /* 210 */ 249, 249, 277, 246, 280, 40, 40, 40, 40, 124, + /* 220 */ 211, 163, 207, 334, 334, 371, 382, 328, 327, 337, + /* 230 */ 336, 340, 342, 344, 345, 314, 66, 346, 347, 348, + /* 240 */ 349, 352, 355, 357, 364, 423, 388, 437, 370, 318, + /* 250 */ 319, 322, 468, 469, 331, 332, 374, 335, 404, 628, + /* 260 */ 480, 630, 633, 488, 638, 639, 543, 547, 506, 531, + /* 270 */ 534, 582, 587, 589, 575, 577, 592, 594, 595, 597, + /* 280 */ 598, 580, 600, 601, 603, 681, 604, 586, 556, 591, + /* 290 */ 558, 608, 534, 609, 578, 611, 579, 617, 610, 612, + /* 300 */ 626, 696, 613, 615, 695, 700, 701, 702, 703, 704, + /* 310 */ 705, 706, 625, 698, 634, 631, 632, 602, 635, 690, + /* 320 */ 657, 707, 573, 574, 627, 627, 627, 627, 708, 581, + /* 330 */ 583, 627, 627, 627, 720, 722, 643, 627, 725, 727, + /* 340 */ 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, + /* 350 */ 738, 739, 646, 659, 726, 740, 686, 749, }; -#define YY_REDUCE_COUNT (207) -#define YY_REDUCE_MIN (-267) -#define YY_REDUCE_MAX (485) +#define YY_REDUCE_COUNT (198) +#define YY_REDUCE_MIN (-251) +#define YY_REDUCE_MAX (470) static const short yy_reduce_ofst[] = { - /* 0 */ -187, 10, 10, -164, -164, 53, -160, 65, 121, -169, - /* 10 */ -113, -116, -42, 116, 119, 133, 159, 172, 175, 177, - /* 20 */ 180, 194, 196, -196, -198, -259, -240, -202, -144, -230, - /* 30 */ -131, -63, 126, -239, -58, 158, 200, 205, 212, -89, - /* 40 */ 47, 198, 114, 221, -15, -100, 222, 209, -267, -262, - /* 50 */ -201, -189, 11, 32, 73, 210, 216, 223, 226, 232, - /* 60 */ 234, 235, 236, 237, 238, 239, 241, 242, 243, 244, - /* 70 */ 257, 262, 263, 267, 274, 276, 277, 278, 279, 280, - /* 80 */ 281, 300, 323, 325, 258, 326, 328, 329, 282, 284, - /* 90 */ 333, 336, 337, 338, 251, 255, 287, 286, 340, 341, - /* 100 */ 344, 346, 347, 349, 350, 351, 352, 353, 355, 356, - /* 110 */ 357, 358, 359, 360, 361, 362, 365, 367, 372, 373, - /* 120 */ 375, 377, 378, 380, 381, 383, 384, 385, 386, 387, - /* 130 */ 388, 389, 390, 391, 392, 393, 394, 395, 397, 398, - /* 140 */ 399, 400, 401, 402, 404, 405, 406, 407, 408, 409, - /* 150 */ 410, 411, 412, 413, 414, 415, 417, 418, 419, 420, - /* 160 */ 272, 292, 295, 297, 421, 423, 291, 308, 313, 285, - /* 170 */ 424, 427, 425, 428, 431, 289, 430, 432, 433, 434, - /* 180 */ 435, 436, 437, 440, 441, 442, 444, 446, 445, 447, - /* 190 */ 449, 452, 453, 455, 448, 450, 454, 457, 458, 460, - /* 200 */ 469, 471, 470, 475, 477, 478, 467, 485, + /* 0 */ -160, 10, -161, -206, -202, -197, -157, -63, -81, -112, + /* 10 */ -41, -57, 51, 52, 59, 123, 139, 149, 158, 160, + /* 20 */ 171, 115, -195, -62, -240, -235, -227, -114, 3, 114, + /* 30 */ 164, 7, -92, -162, 178, 199, 201, 56, 198, 200, + /* 40 */ 213, 216, 191, 167, -251, -239, -210, 17, 45, 196, + /* 50 */ 219, 223, 224, 225, 227, 228, 229, 230, 231, 232, + /* 60 */ 234, 235, 236, 237, 238, 239, 257, 258, 259, 262, + /* 70 */ 272, 273, 274, 275, 276, 278, 279, 317, 320, 321, + /* 80 */ 251, 323, 324, 325, 281, 282, 329, 333, 338, 339, + /* 90 */ 245, 255, 270, 285, 341, 343, 350, 351, 353, 354, + /* 100 */ 358, 359, 360, 361, 362, 363, 365, 366, 367, 368, + /* 110 */ 369, 372, 373, 375, 376, 377, 378, 379, 380, 381, + /* 120 */ 383, 384, 385, 386, 387, 389, 390, 391, 392, 393, + /* 130 */ 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, + /* 140 */ 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + /* 150 */ 415, 416, 417, 418, 264, 266, 267, 268, 420, 421, + /* 160 */ 271, 283, 286, 289, 284, 292, 294, 296, 424, 287, + /* 170 */ 425, 428, 429, 431, 432, 433, 435, 436, 439, 441, + /* 180 */ 440, 442, 444, 447, 448, 450, 443, 445, 446, 449, + /* 190 */ 453, 452, 462, 464, 465, 467, 470, 463, 466, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 872, 996, 935, 1006, 922, 932, 1148, 1148, 1148, 872, - /* 10 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 20 */ 872, 872, 872, 1055, 892, 1148, 872, 872, 872, 872, - /* 30 */ 872, 872, 872, 1070, 872, 932, 872, 872, 872, 872, - /* 40 */ 942, 932, 942, 942, 872, 1050, 980, 998, 872, 872, - /* 50 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 60 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 70 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 80 */ 872, 872, 872, 872, 1057, 1063, 1060, 872, 872, 872, - /* 90 */ 1065, 872, 872, 872, 1089, 1089, 1048, 872, 872, 872, - /* 100 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 110 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 120 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 130 */ 920, 872, 918, 872, 872, 872, 872, 872, 872, 872, - /* 140 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 903, - /* 150 */ 872, 872, 872, 872, 872, 872, 890, 894, 894, 894, - /* 160 */ 872, 872, 872, 872, 894, 894, 1096, 1100, 1082, 1094, - /* 170 */ 1090, 1077, 1075, 1073, 1081, 1104, 894, 894, 894, 940, - /* 180 */ 940, 936, 932, 932, 894, 894, 958, 956, 954, 946, - /* 190 */ 952, 948, 950, 944, 923, 872, 894, 894, 930, 930, - /* 200 */ 894, 930, 894, 930, 894, 894, 980, 998, 872, 1105, - /* 210 */ 1095, 872, 1147, 1135, 1134, 872, 1143, 1142, 1141, 1133, - /* 220 */ 1132, 1131, 872, 872, 1127, 1130, 1129, 1128, 872, 872, - /* 230 */ 872, 872, 1137, 1136, 872, 872, 872, 872, 872, 872, - /* 240 */ 872, 872, 872, 872, 1101, 1097, 872, 872, 872, 872, - /* 250 */ 872, 872, 872, 872, 872, 1107, 872, 872, 872, 872, - /* 260 */ 872, 872, 872, 872, 872, 1008, 872, 872, 872, 872, - /* 270 */ 872, 872, 872, 872, 872, 872, 872, 872, 1047, 872, - /* 280 */ 872, 872, 872, 1059, 1058, 872, 872, 872, 872, 872, - /* 290 */ 872, 872, 872, 872, 872, 872, 1091, 872, 1083, 872, - /* 300 */ 872, 1020, 872, 872, 872, 872, 872, 872, 872, 872, - /* 310 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 320 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 330 */ 872, 872, 872, 1166, 1161, 1162, 1159, 872, 872, 872, - /* 340 */ 1158, 1153, 1154, 872, 872, 872, 1151, 872, 872, 872, - /* 350 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 360 */ 872, 872, 964, 872, 901, 899, 872, 872, + /* 0 */ 852, 914, 902, 911, 1121, 1121, 1121, 852, 852, 852, + /* 10 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 20 */ 852, 1028, 872, 1121, 852, 852, 852, 852, 852, 852, + /* 30 */ 852, 1043, 852, 911, 852, 852, 852, 852, 920, 911, + /* 40 */ 920, 920, 852, 1023, 852, 852, 852, 852, 852, 852, + /* 50 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 60 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 70 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 80 */ 1030, 1036, 1033, 852, 852, 852, 1038, 852, 852, 852, + /* 90 */ 1062, 1062, 1021, 852, 852, 852, 852, 852, 852, 852, + /* 100 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 110 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 120 */ 852, 852, 852, 852, 900, 852, 898, 852, 852, 852, + /* 130 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 140 */ 852, 852, 852, 883, 852, 852, 852, 852, 852, 852, + /* 150 */ 870, 874, 874, 874, 852, 852, 852, 852, 874, 874, + /* 160 */ 1069, 1073, 1055, 1067, 1063, 1050, 1048, 1046, 1054, 1077, + /* 170 */ 874, 874, 874, 918, 918, 911, 874, 874, 936, 934, + /* 180 */ 932, 924, 930, 926, 928, 922, 852, 874, 874, 909, + /* 190 */ 909, 874, 909, 874, 909, 874, 874, 957, 973, 852, + /* 200 */ 1078, 1068, 852, 1120, 1108, 1107, 1116, 1115, 1114, 1106, + /* 210 */ 1105, 1104, 852, 852, 852, 1100, 1103, 1102, 1101, 852, + /* 220 */ 852, 852, 852, 1110, 1109, 852, 852, 852, 852, 852, + /* 230 */ 852, 852, 852, 852, 852, 1074, 1070, 852, 852, 852, + /* 240 */ 852, 852, 852, 852, 852, 852, 1080, 852, 852, 852, + /* 250 */ 852, 852, 852, 852, 852, 852, 981, 852, 852, 852, + /* 260 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 1020, + /* 270 */ 852, 852, 852, 852, 1032, 1031, 852, 852, 852, 852, + /* 280 */ 852, 852, 852, 852, 852, 852, 852, 1064, 852, 1056, + /* 290 */ 852, 852, 993, 852, 852, 852, 852, 852, 852, 852, + /* 300 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 310 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 320 */ 852, 852, 852, 852, 1139, 1134, 1135, 1132, 852, 852, + /* 330 */ 852, 1131, 1126, 1127, 852, 852, 852, 1124, 852, 852, + /* 340 */ 852, 852, 852, 852, 852, 852, 852, 852, 852, 852, + /* 350 */ 852, 852, 942, 852, 881, 879, 852, 852, }; /********** End of lemon-generated parsing tables *****************************/ @@ -626,7 +621,6 @@ static const YYCODETYPE yyFallback[] = { 0, /* PRECISION => nothing */ 0, /* UPDATE => nothing */ 0, /* CACHELAST => nothing */ - 0, /* PARTITIONS => nothing */ 0, /* UNSIGNED => nothing */ 0, /* TAGS => nothing */ 0, /* USING => nothing */ @@ -909,170 +903,166 @@ static const char *const yyTokenName[] = { /* 112 */ "PRECISION", /* 113 */ "UPDATE", /* 114 */ "CACHELAST", - /* 115 */ "PARTITIONS", - /* 116 */ "UNSIGNED", - /* 117 */ "TAGS", - /* 118 */ "USING", - /* 119 */ "NULL", - /* 120 */ "NOW", - /* 121 */ "SELECT", - /* 122 */ "UNION", - /* 123 */ "ALL", - /* 124 */ "DISTINCT", - /* 125 */ "FROM", - /* 126 */ "VARIABLE", - /* 127 */ "INTERVAL", - /* 128 */ "EVERY", - /* 129 */ "SESSION", - /* 130 */ "STATE_WINDOW", - /* 131 */ "FILL", - /* 132 */ "SLIDING", - /* 133 */ "ORDER", - /* 134 */ "BY", - /* 135 */ "ASC", - /* 136 */ "GROUP", - /* 137 */ "HAVING", - /* 138 */ "LIMIT", - /* 139 */ "OFFSET", - /* 140 */ "SLIMIT", - /* 141 */ "SOFFSET", - /* 142 */ "WHERE", - /* 143 */ "RESET", - /* 144 */ "QUERY", - /* 145 */ "SYNCDB", - /* 146 */ "ADD", - /* 147 */ "COLUMN", - /* 148 */ "MODIFY", - /* 149 */ "TAG", - /* 150 */ "CHANGE", - /* 151 */ "SET", - /* 152 */ "KILL", - /* 153 */ "CONNECTION", - /* 154 */ "STREAM", - /* 155 */ "COLON", - /* 156 */ "ABORT", - /* 157 */ "AFTER", - /* 158 */ "ATTACH", - /* 159 */ "BEFORE", - /* 160 */ "BEGIN", - /* 161 */ "CASCADE", - /* 162 */ "CLUSTER", - /* 163 */ "CONFLICT", - /* 164 */ "COPY", - /* 165 */ "DEFERRED", - /* 166 */ "DELIMITERS", - /* 167 */ "DETACH", - /* 168 */ "EACH", - /* 169 */ "END", - /* 170 */ "EXPLAIN", - /* 171 */ "FAIL", - /* 172 */ "FOR", - /* 173 */ "IGNORE", - /* 174 */ "IMMEDIATE", - /* 175 */ "INITIALLY", - /* 176 */ "INSTEAD", - /* 177 */ "KEY", - /* 178 */ "OF", - /* 179 */ "RAISE", - /* 180 */ "REPLACE", - /* 181 */ "RESTRICT", - /* 182 */ "ROW", - /* 183 */ "STATEMENT", - /* 184 */ "TRIGGER", - /* 185 */ "VIEW", - /* 186 */ "IPTOKEN", - /* 187 */ "SEMI", - /* 188 */ "NONE", - /* 189 */ "PREV", - /* 190 */ "LINEAR", - /* 191 */ "IMPORT", - /* 192 */ "TBNAME", - /* 193 */ "JOIN", - /* 194 */ "INSERT", - /* 195 */ "INTO", - /* 196 */ "VALUES", - /* 197 */ "error", - /* 198 */ "program", - /* 199 */ "cmd", - /* 200 */ "ids", - /* 201 */ "dbPrefix", - /* 202 */ "cpxName", - /* 203 */ "ifexists", - /* 204 */ "alter_db_optr", - /* 205 */ "alter_topic_optr", - /* 206 */ "acct_optr", - /* 207 */ "exprlist", - /* 208 */ "ifnotexists", - /* 209 */ "db_optr", - /* 210 */ "topic_optr", - /* 211 */ "typename", - /* 212 */ "bufsize", - /* 213 */ "pps", - /* 214 */ "tseries", - /* 215 */ "dbs", - /* 216 */ "streams", - /* 217 */ "storage", - /* 218 */ "qtime", - /* 219 */ "users", - /* 220 */ "conns", - /* 221 */ "state", - /* 222 */ "intitemlist", - /* 223 */ "intitem", - /* 224 */ "keep", - /* 225 */ "cache", - /* 226 */ "replica", - /* 227 */ "quorum", - /* 228 */ "days", - /* 229 */ "minrows", - /* 230 */ "maxrows", - /* 231 */ "blocks", - /* 232 */ "ctime", - /* 233 */ "wal", - /* 234 */ "fsync", - /* 235 */ "comp", - /* 236 */ "prec", - /* 237 */ "update", - /* 238 */ "cachelast", - /* 239 */ "partitions", - /* 240 */ "signed", - /* 241 */ "create_table_args", - /* 242 */ "create_stable_args", - /* 243 */ "create_table_list", - /* 244 */ "create_from_stable", - /* 245 */ "columnlist", - /* 246 */ "tagitemlist", - /* 247 */ "tagNamelist", - /* 248 */ "select", - /* 249 */ "column", - /* 250 */ "tagitem", - /* 251 */ "selcollist", - /* 252 */ "from", - /* 253 */ "where_opt", - /* 254 */ "interval_option", - /* 255 */ "sliding_opt", - /* 256 */ "session_option", - /* 257 */ "windowstate_option", - /* 258 */ "fill_opt", - /* 259 */ "groupby_opt", - /* 260 */ "having_opt", - /* 261 */ "orderby_opt", - /* 262 */ "slimit_opt", - /* 263 */ "limit_opt", - /* 264 */ "union", - /* 265 */ "sclp", - /* 266 */ "distinct", - /* 267 */ "expr", - /* 268 */ "as", - /* 269 */ "tablelist", - /* 270 */ "sub", - /* 271 */ "tmvar", - /* 272 */ "intervalKey", - /* 273 */ "sortlist", - /* 274 */ "sortitem", - /* 275 */ "item", - /* 276 */ "sortorder", - /* 277 */ "grouplist", - /* 278 */ "expritem", + /* 115 */ "UNSIGNED", + /* 116 */ "TAGS", + /* 117 */ "USING", + /* 118 */ "NULL", + /* 119 */ "NOW", + /* 120 */ "SELECT", + /* 121 */ "UNION", + /* 122 */ "ALL", + /* 123 */ "DISTINCT", + /* 124 */ "FROM", + /* 125 */ "VARIABLE", + /* 126 */ "INTERVAL", + /* 127 */ "EVERY", + /* 128 */ "SESSION", + /* 129 */ "STATE_WINDOW", + /* 130 */ "FILL", + /* 131 */ "SLIDING", + /* 132 */ "ORDER", + /* 133 */ "BY", + /* 134 */ "ASC", + /* 135 */ "GROUP", + /* 136 */ "HAVING", + /* 137 */ "LIMIT", + /* 138 */ "OFFSET", + /* 139 */ "SLIMIT", + /* 140 */ "SOFFSET", + /* 141 */ "WHERE", + /* 142 */ "RESET", + /* 143 */ "QUERY", + /* 144 */ "SYNCDB", + /* 145 */ "ADD", + /* 146 */ "COLUMN", + /* 147 */ "MODIFY", + /* 148 */ "TAG", + /* 149 */ "CHANGE", + /* 150 */ "SET", + /* 151 */ "KILL", + /* 152 */ "CONNECTION", + /* 153 */ "STREAM", + /* 154 */ "COLON", + /* 155 */ "ABORT", + /* 156 */ "AFTER", + /* 157 */ "ATTACH", + /* 158 */ "BEFORE", + /* 159 */ "BEGIN", + /* 160 */ "CASCADE", + /* 161 */ "CLUSTER", + /* 162 */ "CONFLICT", + /* 163 */ "COPY", + /* 164 */ "DEFERRED", + /* 165 */ "DELIMITERS", + /* 166 */ "DETACH", + /* 167 */ "EACH", + /* 168 */ "END", + /* 169 */ "EXPLAIN", + /* 170 */ "FAIL", + /* 171 */ "FOR", + /* 172 */ "IGNORE", + /* 173 */ "IMMEDIATE", + /* 174 */ "INITIALLY", + /* 175 */ "INSTEAD", + /* 176 */ "KEY", + /* 177 */ "OF", + /* 178 */ "RAISE", + /* 179 */ "REPLACE", + /* 180 */ "RESTRICT", + /* 181 */ "ROW", + /* 182 */ "STATEMENT", + /* 183 */ "TRIGGER", + /* 184 */ "VIEW", + /* 185 */ "IPTOKEN", + /* 186 */ "SEMI", + /* 187 */ "NONE", + /* 188 */ "PREV", + /* 189 */ "LINEAR", + /* 190 */ "IMPORT", + /* 191 */ "TBNAME", + /* 192 */ "JOIN", + /* 193 */ "INSERT", + /* 194 */ "INTO", + /* 195 */ "VALUES", + /* 196 */ "error", + /* 197 */ "program", + /* 198 */ "cmd", + /* 199 */ "ids", + /* 200 */ "dbPrefix", + /* 201 */ "cpxName", + /* 202 */ "ifexists", + /* 203 */ "alter_db_optr", + /* 204 */ "acct_optr", + /* 205 */ "exprlist", + /* 206 */ "ifnotexists", + /* 207 */ "db_optr", + /* 208 */ "typename", + /* 209 */ "bufsize", + /* 210 */ "pps", + /* 211 */ "tseries", + /* 212 */ "dbs", + /* 213 */ "streams", + /* 214 */ "storage", + /* 215 */ "qtime", + /* 216 */ "users", + /* 217 */ "conns", + /* 218 */ "state", + /* 219 */ "intitemlist", + /* 220 */ "intitem", + /* 221 */ "keep", + /* 222 */ "cache", + /* 223 */ "replica", + /* 224 */ "quorum", + /* 225 */ "days", + /* 226 */ "minrows", + /* 227 */ "maxrows", + /* 228 */ "blocks", + /* 229 */ "ctime", + /* 230 */ "wal", + /* 231 */ "fsync", + /* 232 */ "comp", + /* 233 */ "prec", + /* 234 */ "update", + /* 235 */ "cachelast", + /* 236 */ "signed", + /* 237 */ "create_table_args", + /* 238 */ "create_stable_args", + /* 239 */ "create_table_list", + /* 240 */ "create_from_stable", + /* 241 */ "columnlist", + /* 242 */ "tagitemlist", + /* 243 */ "tagNamelist", + /* 244 */ "select", + /* 245 */ "column", + /* 246 */ "tagitem", + /* 247 */ "selcollist", + /* 248 */ "from", + /* 249 */ "where_opt", + /* 250 */ "interval_option", + /* 251 */ "sliding_opt", + /* 252 */ "session_option", + /* 253 */ "windowstate_option", + /* 254 */ "fill_opt", + /* 255 */ "groupby_opt", + /* 256 */ "having_opt", + /* 257 */ "orderby_opt", + /* 258 */ "slimit_opt", + /* 259 */ "limit_opt", + /* 260 */ "union", + /* 261 */ "sclp", + /* 262 */ "distinct", + /* 263 */ "expr", + /* 264 */ "as", + /* 265 */ "tablelist", + /* 266 */ "sub", + /* 267 */ "tmvar", + /* 268 */ "intervalKey", + /* 269 */ "sortlist", + /* 270 */ "sortitem", + /* 271 */ "item", + /* 272 */ "sortorder", + /* 273 */ "grouplist", + /* 274 */ "expritem", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1128,253 +1118,246 @@ static const char *const yyRuleName[] = { /* 45 */ "cmd ::= ALTER LOCAL ids", /* 46 */ "cmd ::= ALTER LOCAL ids ids", /* 47 */ "cmd ::= ALTER DATABASE ids alter_db_optr", - /* 48 */ "cmd ::= ALTER TOPIC ids alter_topic_optr", - /* 49 */ "cmd ::= ALTER ACCOUNT ids acct_optr", - /* 50 */ "cmd ::= ALTER ACCOUNT ids PASS ids acct_optr", - /* 51 */ "cmd ::= COMPACT VNODES IN LP exprlist RP", - /* 52 */ "ids ::= ID", - /* 53 */ "ids ::= STRING", - /* 54 */ "ifexists ::= IF EXISTS", - /* 55 */ "ifexists ::=", - /* 56 */ "ifnotexists ::= IF NOT EXISTS", - /* 57 */ "ifnotexists ::=", - /* 58 */ "cmd ::= CREATE DNODE ids", - /* 59 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", - /* 60 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", - /* 61 */ "cmd ::= CREATE TOPIC ifnotexists ids topic_optr", - /* 62 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 63 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 64 */ "cmd ::= CREATE USER ids PASS ids", - /* 65 */ "bufsize ::=", - /* 66 */ "bufsize ::= BUFSIZE INTEGER", - /* 67 */ "pps ::=", - /* 68 */ "pps ::= PPS INTEGER", - /* 69 */ "tseries ::=", - /* 70 */ "tseries ::= TSERIES INTEGER", - /* 71 */ "dbs ::=", - /* 72 */ "dbs ::= DBS INTEGER", - /* 73 */ "streams ::=", - /* 74 */ "streams ::= STREAMS INTEGER", - /* 75 */ "storage ::=", - /* 76 */ "storage ::= STORAGE INTEGER", - /* 77 */ "qtime ::=", - /* 78 */ "qtime ::= QTIME INTEGER", - /* 79 */ "users ::=", - /* 80 */ "users ::= USERS INTEGER", - /* 81 */ "conns ::=", - /* 82 */ "conns ::= CONNS INTEGER", - /* 83 */ "state ::=", - /* 84 */ "state ::= STATE ids", - /* 85 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", - /* 86 */ "intitemlist ::= intitemlist COMMA intitem", - /* 87 */ "intitemlist ::= intitem", - /* 88 */ "intitem ::= INTEGER", - /* 89 */ "keep ::= KEEP intitemlist", - /* 90 */ "cache ::= CACHE INTEGER", - /* 91 */ "replica ::= REPLICA INTEGER", - /* 92 */ "quorum ::= QUORUM INTEGER", - /* 93 */ "days ::= DAYS INTEGER", - /* 94 */ "minrows ::= MINROWS INTEGER", - /* 95 */ "maxrows ::= MAXROWS INTEGER", - /* 96 */ "blocks ::= BLOCKS INTEGER", - /* 97 */ "ctime ::= CTIME INTEGER", - /* 98 */ "wal ::= WAL INTEGER", - /* 99 */ "fsync ::= FSYNC INTEGER", - /* 100 */ "comp ::= COMP INTEGER", - /* 101 */ "prec ::= PRECISION STRING", - /* 102 */ "update ::= UPDATE INTEGER", - /* 103 */ "cachelast ::= CACHELAST INTEGER", - /* 104 */ "partitions ::= PARTITIONS INTEGER", - /* 105 */ "db_optr ::=", - /* 106 */ "db_optr ::= db_optr cache", - /* 107 */ "db_optr ::= db_optr replica", - /* 108 */ "db_optr ::= db_optr quorum", - /* 109 */ "db_optr ::= db_optr days", - /* 110 */ "db_optr ::= db_optr minrows", - /* 111 */ "db_optr ::= db_optr maxrows", - /* 112 */ "db_optr ::= db_optr blocks", - /* 113 */ "db_optr ::= db_optr ctime", - /* 114 */ "db_optr ::= db_optr wal", - /* 115 */ "db_optr ::= db_optr fsync", - /* 116 */ "db_optr ::= db_optr comp", - /* 117 */ "db_optr ::= db_optr prec", - /* 118 */ "db_optr ::= db_optr keep", - /* 119 */ "db_optr ::= db_optr update", - /* 120 */ "db_optr ::= db_optr cachelast", - /* 121 */ "topic_optr ::= db_optr", - /* 122 */ "topic_optr ::= topic_optr partitions", - /* 123 */ "alter_db_optr ::=", - /* 124 */ "alter_db_optr ::= alter_db_optr replica", - /* 125 */ "alter_db_optr ::= alter_db_optr quorum", - /* 126 */ "alter_db_optr ::= alter_db_optr keep", - /* 127 */ "alter_db_optr ::= alter_db_optr blocks", - /* 128 */ "alter_db_optr ::= alter_db_optr comp", - /* 129 */ "alter_db_optr ::= alter_db_optr update", - /* 130 */ "alter_db_optr ::= alter_db_optr cachelast", - /* 131 */ "alter_topic_optr ::= alter_db_optr", - /* 132 */ "alter_topic_optr ::= alter_topic_optr partitions", - /* 133 */ "typename ::= ids", - /* 134 */ "typename ::= ids LP signed RP", - /* 135 */ "typename ::= ids UNSIGNED", - /* 136 */ "signed ::= INTEGER", - /* 137 */ "signed ::= PLUS INTEGER", - /* 138 */ "signed ::= MINUS INTEGER", - /* 139 */ "cmd ::= CREATE TABLE create_table_args", - /* 140 */ "cmd ::= CREATE TABLE create_stable_args", - /* 141 */ "cmd ::= CREATE STABLE create_stable_args", - /* 142 */ "cmd ::= CREATE TABLE create_table_list", - /* 143 */ "create_table_list ::= create_from_stable", - /* 144 */ "create_table_list ::= create_table_list create_from_stable", - /* 145 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", - /* 146 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", - /* 147 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP", - /* 148 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP", - /* 149 */ "tagNamelist ::= tagNamelist COMMA ids", - /* 150 */ "tagNamelist ::= ids", - /* 151 */ "create_table_args ::= ifnotexists ids cpxName AS select", - /* 152 */ "columnlist ::= columnlist COMMA column", - /* 153 */ "columnlist ::= column", - /* 154 */ "column ::= ids typename", - /* 155 */ "tagitemlist ::= tagitemlist COMMA tagitem", - /* 156 */ "tagitemlist ::= tagitem", - /* 157 */ "tagitem ::= INTEGER", - /* 158 */ "tagitem ::= FLOAT", - /* 159 */ "tagitem ::= STRING", - /* 160 */ "tagitem ::= BOOL", - /* 161 */ "tagitem ::= NULL", - /* 162 */ "tagitem ::= NOW", - /* 163 */ "tagitem ::= MINUS INTEGER", - /* 164 */ "tagitem ::= MINUS FLOAT", - /* 165 */ "tagitem ::= PLUS INTEGER", - /* 166 */ "tagitem ::= PLUS FLOAT", - /* 167 */ "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", - /* 168 */ "select ::= LP select RP", - /* 169 */ "union ::= select", - /* 170 */ "union ::= union UNION ALL select", - /* 171 */ "union ::= union UNION select", - /* 172 */ "cmd ::= union", - /* 173 */ "select ::= SELECT selcollist", - /* 174 */ "sclp ::= selcollist COMMA", - /* 175 */ "sclp ::=", - /* 176 */ "selcollist ::= sclp distinct expr as", - /* 177 */ "selcollist ::= sclp STAR", - /* 178 */ "as ::= AS ids", - /* 179 */ "as ::= ids", - /* 180 */ "as ::=", - /* 181 */ "distinct ::= DISTINCT", - /* 182 */ "distinct ::=", - /* 183 */ "from ::= FROM tablelist", - /* 184 */ "from ::= FROM sub", - /* 185 */ "sub ::= LP union RP", - /* 186 */ "sub ::= LP union RP ids", - /* 187 */ "sub ::= sub COMMA LP union RP ids", - /* 188 */ "tablelist ::= ids cpxName", - /* 189 */ "tablelist ::= ids cpxName ids", - /* 190 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 191 */ "tablelist ::= tablelist COMMA ids cpxName ids", - /* 192 */ "tmvar ::= VARIABLE", - /* 193 */ "interval_option ::= intervalKey LP tmvar RP", - /* 194 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", - /* 195 */ "interval_option ::=", - /* 196 */ "intervalKey ::= INTERVAL", - /* 197 */ "intervalKey ::= EVERY", - /* 198 */ "session_option ::=", - /* 199 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 200 */ "windowstate_option ::=", - /* 201 */ "windowstate_option ::= STATE_WINDOW LP ids RP", - /* 202 */ "fill_opt ::=", - /* 203 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 204 */ "fill_opt ::= FILL LP ID RP", - /* 205 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 206 */ "sliding_opt ::=", - /* 207 */ "orderby_opt ::=", - /* 208 */ "orderby_opt ::= ORDER BY sortlist", - /* 209 */ "sortlist ::= sortlist COMMA item sortorder", - /* 210 */ "sortlist ::= item sortorder", - /* 211 */ "item ::= ids cpxName", - /* 212 */ "sortorder ::= ASC", - /* 213 */ "sortorder ::= DESC", - /* 214 */ "sortorder ::=", - /* 215 */ "groupby_opt ::=", - /* 216 */ "groupby_opt ::= GROUP BY grouplist", - /* 217 */ "grouplist ::= grouplist COMMA item", - /* 218 */ "grouplist ::= item", - /* 219 */ "having_opt ::=", - /* 220 */ "having_opt ::= HAVING expr", - /* 221 */ "limit_opt ::=", - /* 222 */ "limit_opt ::= LIMIT signed", - /* 223 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 224 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 225 */ "slimit_opt ::=", - /* 226 */ "slimit_opt ::= SLIMIT signed", - /* 227 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 228 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 229 */ "where_opt ::=", - /* 230 */ "where_opt ::= WHERE expr", - /* 231 */ "expr ::= LP expr RP", - /* 232 */ "expr ::= ID", - /* 233 */ "expr ::= ID DOT ID", - /* 234 */ "expr ::= ID DOT STAR", - /* 235 */ "expr ::= INTEGER", - /* 236 */ "expr ::= MINUS INTEGER", - /* 237 */ "expr ::= PLUS INTEGER", - /* 238 */ "expr ::= FLOAT", - /* 239 */ "expr ::= MINUS FLOAT", - /* 240 */ "expr ::= PLUS FLOAT", - /* 241 */ "expr ::= STRING", - /* 242 */ "expr ::= NOW", - /* 243 */ "expr ::= VARIABLE", - /* 244 */ "expr ::= PLUS VARIABLE", - /* 245 */ "expr ::= MINUS VARIABLE", - /* 246 */ "expr ::= BOOL", - /* 247 */ "expr ::= NULL", - /* 248 */ "expr ::= ID LP exprlist RP", - /* 249 */ "expr ::= ID LP STAR RP", - /* 250 */ "expr ::= expr IS NULL", - /* 251 */ "expr ::= expr IS NOT NULL", - /* 252 */ "expr ::= expr LT expr", - /* 253 */ "expr ::= expr GT expr", - /* 254 */ "expr ::= expr LE expr", - /* 255 */ "expr ::= expr GE expr", - /* 256 */ "expr ::= expr NE expr", - /* 257 */ "expr ::= expr EQ expr", - /* 258 */ "expr ::= expr BETWEEN expr AND expr", - /* 259 */ "expr ::= expr AND expr", - /* 260 */ "expr ::= expr OR expr", - /* 261 */ "expr ::= expr PLUS expr", - /* 262 */ "expr ::= expr MINUS expr", - /* 263 */ "expr ::= expr STAR expr", - /* 264 */ "expr ::= expr SLASH expr", - /* 265 */ "expr ::= expr REM expr", - /* 266 */ "expr ::= expr LIKE expr", - /* 267 */ "expr ::= expr MATCH expr", - /* 268 */ "expr ::= expr NMATCH expr", - /* 269 */ "expr ::= expr IN LP exprlist RP", - /* 270 */ "exprlist ::= exprlist COMMA expritem", - /* 271 */ "exprlist ::= expritem", - /* 272 */ "expritem ::= expr", - /* 273 */ "expritem ::=", - /* 274 */ "cmd ::= RESET QUERY CACHE", - /* 275 */ "cmd ::= SYNCDB ids REPLICA", - /* 276 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 277 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 278 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", - /* 279 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 280 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 281 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 282 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 283 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", - /* 284 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 285 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 286 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", - /* 287 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 288 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 289 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 290 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", - /* 291 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", - /* 292 */ "cmd ::= KILL CONNECTION INTEGER", - /* 293 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 294 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 48 */ "cmd ::= ALTER ACCOUNT ids acct_optr", + /* 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", + /* 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 */ "db_optr ::=", + /* 103 */ "db_optr ::= db_optr cache", + /* 104 */ "db_optr ::= db_optr replica", + /* 105 */ "db_optr ::= db_optr quorum", + /* 106 */ "db_optr ::= db_optr days", + /* 107 */ "db_optr ::= db_optr minrows", + /* 108 */ "db_optr ::= db_optr maxrows", + /* 109 */ "db_optr ::= db_optr blocks", + /* 110 */ "db_optr ::= db_optr ctime", + /* 111 */ "db_optr ::= db_optr wal", + /* 112 */ "db_optr ::= db_optr fsync", + /* 113 */ "db_optr ::= db_optr comp", + /* 114 */ "db_optr ::= db_optr prec", + /* 115 */ "db_optr ::= db_optr keep", + /* 116 */ "db_optr ::= db_optr update", + /* 117 */ "db_optr ::= db_optr cachelast", + /* 118 */ "alter_db_optr ::=", + /* 119 */ "alter_db_optr ::= alter_db_optr replica", + /* 120 */ "alter_db_optr ::= alter_db_optr quorum", + /* 121 */ "alter_db_optr ::= alter_db_optr keep", + /* 122 */ "alter_db_optr ::= alter_db_optr blocks", + /* 123 */ "alter_db_optr ::= alter_db_optr comp", + /* 124 */ "alter_db_optr ::= alter_db_optr update", + /* 125 */ "alter_db_optr ::= alter_db_optr cachelast", + /* 126 */ "typename ::= ids", + /* 127 */ "typename ::= ids LP signed RP", + /* 128 */ "typename ::= ids UNSIGNED", + /* 129 */ "signed ::= INTEGER", + /* 130 */ "signed ::= PLUS INTEGER", + /* 131 */ "signed ::= MINUS INTEGER", + /* 132 */ "cmd ::= CREATE TABLE create_table_args", + /* 133 */ "cmd ::= CREATE TABLE create_stable_args", + /* 134 */ "cmd ::= CREATE STABLE create_stable_args", + /* 135 */ "cmd ::= CREATE TABLE create_table_list", + /* 136 */ "create_table_list ::= create_from_stable", + /* 137 */ "create_table_list ::= create_table_list create_from_stable", + /* 138 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", + /* 139 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", + /* 140 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP", + /* 141 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP", + /* 142 */ "tagNamelist ::= tagNamelist COMMA ids", + /* 143 */ "tagNamelist ::= ids", + /* 144 */ "create_table_args ::= ifnotexists ids cpxName AS select", + /* 145 */ "columnlist ::= columnlist COMMA column", + /* 146 */ "columnlist ::= column", + /* 147 */ "column ::= ids typename", + /* 148 */ "tagitemlist ::= tagitemlist COMMA tagitem", + /* 149 */ "tagitemlist ::= tagitem", + /* 150 */ "tagitem ::= INTEGER", + /* 151 */ "tagitem ::= FLOAT", + /* 152 */ "tagitem ::= STRING", + /* 153 */ "tagitem ::= BOOL", + /* 154 */ "tagitem ::= NULL", + /* 155 */ "tagitem ::= NOW", + /* 156 */ "tagitem ::= MINUS INTEGER", + /* 157 */ "tagitem ::= MINUS FLOAT", + /* 158 */ "tagitem ::= PLUS INTEGER", + /* 159 */ "tagitem ::= PLUS FLOAT", + /* 160 */ "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", + /* 161 */ "select ::= LP select RP", + /* 162 */ "union ::= select", + /* 163 */ "union ::= union UNION ALL select", + /* 164 */ "union ::= union UNION select", + /* 165 */ "cmd ::= union", + /* 166 */ "select ::= SELECT selcollist", + /* 167 */ "sclp ::= selcollist COMMA", + /* 168 */ "sclp ::=", + /* 169 */ "selcollist ::= sclp distinct expr as", + /* 170 */ "selcollist ::= sclp STAR", + /* 171 */ "as ::= AS ids", + /* 172 */ "as ::= ids", + /* 173 */ "as ::=", + /* 174 */ "distinct ::= DISTINCT", + /* 175 */ "distinct ::=", + /* 176 */ "from ::= FROM tablelist", + /* 177 */ "from ::= FROM sub", + /* 178 */ "sub ::= LP union RP", + /* 179 */ "sub ::= LP union RP ids", + /* 180 */ "sub ::= sub COMMA LP union RP ids", + /* 181 */ "tablelist ::= ids cpxName", + /* 182 */ "tablelist ::= ids cpxName ids", + /* 183 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 184 */ "tablelist ::= tablelist COMMA ids cpxName ids", + /* 185 */ "tmvar ::= VARIABLE", + /* 186 */ "interval_option ::= intervalKey LP tmvar RP", + /* 187 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", + /* 188 */ "interval_option ::=", + /* 189 */ "intervalKey ::= INTERVAL", + /* 190 */ "intervalKey ::= EVERY", + /* 191 */ "session_option ::=", + /* 192 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 193 */ "windowstate_option ::=", + /* 194 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 195 */ "fill_opt ::=", + /* 196 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 197 */ "fill_opt ::= FILL LP ID RP", + /* 198 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 199 */ "sliding_opt ::=", + /* 200 */ "orderby_opt ::=", + /* 201 */ "orderby_opt ::= ORDER BY sortlist", + /* 202 */ "sortlist ::= sortlist COMMA item sortorder", + /* 203 */ "sortlist ::= item sortorder", + /* 204 */ "item ::= ids cpxName", + /* 205 */ "sortorder ::= ASC", + /* 206 */ "sortorder ::= DESC", + /* 207 */ "sortorder ::=", + /* 208 */ "groupby_opt ::=", + /* 209 */ "groupby_opt ::= GROUP BY grouplist", + /* 210 */ "grouplist ::= grouplist COMMA item", + /* 211 */ "grouplist ::= item", + /* 212 */ "having_opt ::=", + /* 213 */ "having_opt ::= HAVING expr", + /* 214 */ "limit_opt ::=", + /* 215 */ "limit_opt ::= LIMIT signed", + /* 216 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 217 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 218 */ "slimit_opt ::=", + /* 219 */ "slimit_opt ::= SLIMIT signed", + /* 220 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 221 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 222 */ "where_opt ::=", + /* 223 */ "where_opt ::= WHERE expr", + /* 224 */ "expr ::= LP expr RP", + /* 225 */ "expr ::= ID", + /* 226 */ "expr ::= ID DOT ID", + /* 227 */ "expr ::= ID DOT STAR", + /* 228 */ "expr ::= INTEGER", + /* 229 */ "expr ::= MINUS INTEGER", + /* 230 */ "expr ::= PLUS INTEGER", + /* 231 */ "expr ::= FLOAT", + /* 232 */ "expr ::= MINUS FLOAT", + /* 233 */ "expr ::= PLUS FLOAT", + /* 234 */ "expr ::= STRING", + /* 235 */ "expr ::= NOW", + /* 236 */ "expr ::= VARIABLE", + /* 237 */ "expr ::= PLUS VARIABLE", + /* 238 */ "expr ::= MINUS VARIABLE", + /* 239 */ "expr ::= BOOL", + /* 240 */ "expr ::= NULL", + /* 241 */ "expr ::= ID LP exprlist RP", + /* 242 */ "expr ::= ID LP STAR RP", + /* 243 */ "expr ::= expr IS NULL", + /* 244 */ "expr ::= expr IS NOT NULL", + /* 245 */ "expr ::= expr LT expr", + /* 246 */ "expr ::= expr GT expr", + /* 247 */ "expr ::= expr LE expr", + /* 248 */ "expr ::= expr GE expr", + /* 249 */ "expr ::= expr NE expr", + /* 250 */ "expr ::= expr EQ expr", + /* 251 */ "expr ::= expr BETWEEN expr AND expr", + /* 252 */ "expr ::= expr AND expr", + /* 253 */ "expr ::= expr OR expr", + /* 254 */ "expr ::= expr PLUS expr", + /* 255 */ "expr ::= expr MINUS expr", + /* 256 */ "expr ::= expr STAR expr", + /* 257 */ "expr ::= expr SLASH expr", + /* 258 */ "expr ::= expr REM expr", + /* 259 */ "expr ::= expr LIKE expr", + /* 260 */ "expr ::= expr MATCH expr", + /* 261 */ "expr ::= expr NMATCH expr", + /* 262 */ "expr ::= expr IN LP exprlist RP", + /* 263 */ "exprlist ::= exprlist COMMA expritem", + /* 264 */ "exprlist ::= expritem", + /* 265 */ "expritem ::= expr", + /* 266 */ "expritem ::=", + /* 267 */ "cmd ::= RESET QUERY CACHE", + /* 268 */ "cmd ::= SYNCDB ids REPLICA", + /* 269 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 270 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 271 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", + /* 272 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 273 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 274 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 275 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 276 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", + /* 277 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 278 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 279 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", + /* 280 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 281 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 282 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 283 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", + /* 284 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", + /* 285 */ "cmd ::= KILL CONNECTION INTEGER", + /* 286 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 287 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1495,60 +1478,60 @@ static void yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 207: /* exprlist */ - case 251: /* selcollist */ - case 265: /* sclp */ + case 205: /* exprlist */ + case 247: /* selcollist */ + case 261: /* sclp */ { -tSqlExprListDestroy((yypminor->yy135)); +tSqlExprListDestroy((yypminor->yy131)); } break; - case 222: /* intitemlist */ - case 224: /* keep */ - case 245: /* columnlist */ - case 246: /* tagitemlist */ - case 247: /* tagNamelist */ - case 258: /* fill_opt */ - case 259: /* groupby_opt */ - case 261: /* orderby_opt */ - case 273: /* sortlist */ - case 277: /* grouplist */ -{ -taosArrayDestroy((yypminor->yy135)); + case 219: /* intitemlist */ + case 221: /* keep */ + case 241: /* columnlist */ + case 242: /* tagitemlist */ + case 243: /* tagNamelist */ + case 254: /* fill_opt */ + case 255: /* groupby_opt */ + case 257: /* orderby_opt */ + case 269: /* sortlist */ + case 273: /* grouplist */ +{ +taosArrayDestroy((yypminor->yy131)); } break; - case 243: /* create_table_list */ + case 239: /* create_table_list */ { -destroyCreateTableSql((yypminor->yy110)); +destroyCreateTableSql((yypminor->yy272)); } break; - case 248: /* select */ + case 244: /* select */ { -destroySqlNode((yypminor->yy488)); +destroySqlNode((yypminor->yy256)); } break; - case 252: /* from */ - case 269: /* tablelist */ - case 270: /* sub */ + case 248: /* from */ + case 265: /* tablelist */ + case 266: /* sub */ { -destroyRelationInfo((yypminor->yy460)); +destroyRelationInfo((yypminor->yy544)); } break; - case 253: /* where_opt */ - case 260: /* having_opt */ - case 267: /* expr */ - case 278: /* expritem */ + case 249: /* where_opt */ + case 256: /* having_opt */ + case 263: /* expr */ + case 274: /* expritem */ { -tSqlExprDestroy((yypminor->yy526)); +tSqlExprDestroy((yypminor->yy46)); } break; - case 264: /* union */ + case 260: /* union */ { -destroyAllSqlNode((yypminor->yy551)); +destroyAllSqlNode((yypminor->yy303)); } break; - case 274: /* sortitem */ + case 270: /* sortitem */ { -taosVariantDestroy(&(yypminor->yy191)); +taosVariantDestroy(&(yypminor->yy43)); } break; /********* End destructor definitions *****************************************/ @@ -1842,301 +1825,294 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 198, -1 }, /* (0) program ::= cmd */ - { 199, -2 }, /* (1) cmd ::= SHOW DATABASES */ - { 199, -2 }, /* (2) cmd ::= SHOW TOPICS */ - { 199, -2 }, /* (3) cmd ::= SHOW FUNCTIONS */ - { 199, -2 }, /* (4) cmd ::= SHOW MNODES */ - { 199, -2 }, /* (5) cmd ::= SHOW DNODES */ - { 199, -2 }, /* (6) cmd ::= SHOW ACCOUNTS */ - { 199, -2 }, /* (7) cmd ::= SHOW USERS */ - { 199, -2 }, /* (8) cmd ::= SHOW MODULES */ - { 199, -2 }, /* (9) cmd ::= SHOW QUERIES */ - { 199, -2 }, /* (10) cmd ::= SHOW CONNECTIONS */ - { 199, -2 }, /* (11) cmd ::= SHOW STREAMS */ - { 199, -2 }, /* (12) cmd ::= SHOW VARIABLES */ - { 199, -2 }, /* (13) cmd ::= SHOW SCORES */ - { 199, -2 }, /* (14) cmd ::= SHOW GRANTS */ - { 199, -2 }, /* (15) cmd ::= SHOW VNODES */ - { 199, -3 }, /* (16) cmd ::= SHOW VNODES ids */ - { 201, 0 }, /* (17) dbPrefix ::= */ - { 201, -2 }, /* (18) dbPrefix ::= ids DOT */ - { 202, 0 }, /* (19) cpxName ::= */ - { 202, -2 }, /* (20) cpxName ::= DOT ids */ - { 199, -5 }, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ - { 199, -5 }, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ - { 199, -4 }, /* (23) cmd ::= SHOW CREATE DATABASE ids */ - { 199, -3 }, /* (24) cmd ::= SHOW dbPrefix TABLES */ - { 199, -5 }, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - { 199, -3 }, /* (26) cmd ::= SHOW dbPrefix STABLES */ - { 199, -5 }, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - { 199, -3 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ - { 199, -4 }, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ - { 199, -5 }, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ - { 199, -5 }, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ - { 199, -4 }, /* (32) cmd ::= DROP DATABASE ifexists ids */ - { 199, -4 }, /* (33) cmd ::= DROP TOPIC ifexists ids */ - { 199, -3 }, /* (34) cmd ::= DROP FUNCTION ids */ - { 199, -3 }, /* (35) cmd ::= DROP DNODE ids */ - { 199, -3 }, /* (36) cmd ::= DROP USER ids */ - { 199, -3 }, /* (37) cmd ::= DROP ACCOUNT ids */ - { 199, -2 }, /* (38) cmd ::= USE ids */ - { 199, -3 }, /* (39) cmd ::= DESCRIBE ids cpxName */ - { 199, -3 }, /* (40) cmd ::= DESC ids cpxName */ - { 199, -5 }, /* (41) cmd ::= ALTER USER ids PASS ids */ - { 199, -5 }, /* (42) cmd ::= ALTER USER ids PRIVILEGE ids */ - { 199, -4 }, /* (43) cmd ::= ALTER DNODE ids ids */ - { 199, -5 }, /* (44) cmd ::= ALTER DNODE ids ids ids */ - { 199, -3 }, /* (45) cmd ::= ALTER LOCAL ids */ - { 199, -4 }, /* (46) cmd ::= ALTER LOCAL ids ids */ - { 199, -4 }, /* (47) cmd ::= ALTER DATABASE ids alter_db_optr */ - { 199, -4 }, /* (48) cmd ::= ALTER TOPIC ids alter_topic_optr */ - { 199, -4 }, /* (49) cmd ::= ALTER ACCOUNT ids acct_optr */ - { 199, -6 }, /* (50) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - { 199, -6 }, /* (51) cmd ::= COMPACT VNODES IN LP exprlist RP */ - { 200, -1 }, /* (52) ids ::= ID */ - { 200, -1 }, /* (53) ids ::= STRING */ - { 203, -2 }, /* (54) ifexists ::= IF EXISTS */ - { 203, 0 }, /* (55) ifexists ::= */ - { 208, -3 }, /* (56) ifnotexists ::= IF NOT EXISTS */ - { 208, 0 }, /* (57) ifnotexists ::= */ - { 199, -3 }, /* (58) cmd ::= CREATE DNODE ids */ - { 199, -6 }, /* (59) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 199, -5 }, /* (60) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 199, -5 }, /* (61) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ - { 199, -8 }, /* (62) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 199, -9 }, /* (63) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 199, -5 }, /* (64) cmd ::= CREATE USER ids PASS ids */ - { 212, 0 }, /* (65) bufsize ::= */ - { 212, -2 }, /* (66) bufsize ::= BUFSIZE INTEGER */ - { 213, 0 }, /* (67) pps ::= */ - { 213, -2 }, /* (68) pps ::= PPS INTEGER */ - { 214, 0 }, /* (69) tseries ::= */ - { 214, -2 }, /* (70) tseries ::= TSERIES INTEGER */ - { 215, 0 }, /* (71) dbs ::= */ - { 215, -2 }, /* (72) dbs ::= DBS INTEGER */ - { 216, 0 }, /* (73) streams ::= */ - { 216, -2 }, /* (74) streams ::= STREAMS INTEGER */ - { 217, 0 }, /* (75) storage ::= */ - { 217, -2 }, /* (76) storage ::= STORAGE INTEGER */ - { 218, 0 }, /* (77) qtime ::= */ - { 218, -2 }, /* (78) qtime ::= QTIME INTEGER */ - { 219, 0 }, /* (79) users ::= */ - { 219, -2 }, /* (80) users ::= USERS INTEGER */ - { 220, 0 }, /* (81) conns ::= */ - { 220, -2 }, /* (82) conns ::= CONNS INTEGER */ - { 221, 0 }, /* (83) state ::= */ - { 221, -2 }, /* (84) state ::= STATE ids */ - { 206, -9 }, /* (85) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 222, -3 }, /* (86) intitemlist ::= intitemlist COMMA intitem */ - { 222, -1 }, /* (87) intitemlist ::= intitem */ - { 223, -1 }, /* (88) intitem ::= INTEGER */ - { 224, -2 }, /* (89) keep ::= KEEP intitemlist */ - { 225, -2 }, /* (90) cache ::= CACHE INTEGER */ - { 226, -2 }, /* (91) replica ::= REPLICA INTEGER */ - { 227, -2 }, /* (92) quorum ::= QUORUM INTEGER */ - { 228, -2 }, /* (93) days ::= DAYS INTEGER */ - { 229, -2 }, /* (94) minrows ::= MINROWS INTEGER */ - { 230, -2 }, /* (95) maxrows ::= MAXROWS INTEGER */ - { 231, -2 }, /* (96) blocks ::= BLOCKS INTEGER */ - { 232, -2 }, /* (97) ctime ::= CTIME INTEGER */ - { 233, -2 }, /* (98) wal ::= WAL INTEGER */ - { 234, -2 }, /* (99) fsync ::= FSYNC INTEGER */ - { 235, -2 }, /* (100) comp ::= COMP INTEGER */ - { 236, -2 }, /* (101) prec ::= PRECISION STRING */ - { 237, -2 }, /* (102) update ::= UPDATE INTEGER */ - { 238, -2 }, /* (103) cachelast ::= CACHELAST INTEGER */ - { 239, -2 }, /* (104) partitions ::= PARTITIONS INTEGER */ - { 209, 0 }, /* (105) db_optr ::= */ - { 209, -2 }, /* (106) db_optr ::= db_optr cache */ - { 209, -2 }, /* (107) db_optr ::= db_optr replica */ - { 209, -2 }, /* (108) db_optr ::= db_optr quorum */ - { 209, -2 }, /* (109) db_optr ::= db_optr days */ - { 209, -2 }, /* (110) db_optr ::= db_optr minrows */ - { 209, -2 }, /* (111) db_optr ::= db_optr maxrows */ - { 209, -2 }, /* (112) db_optr ::= db_optr blocks */ - { 209, -2 }, /* (113) db_optr ::= db_optr ctime */ - { 209, -2 }, /* (114) db_optr ::= db_optr wal */ - { 209, -2 }, /* (115) db_optr ::= db_optr fsync */ - { 209, -2 }, /* (116) db_optr ::= db_optr comp */ - { 209, -2 }, /* (117) db_optr ::= db_optr prec */ - { 209, -2 }, /* (118) db_optr ::= db_optr keep */ - { 209, -2 }, /* (119) db_optr ::= db_optr update */ - { 209, -2 }, /* (120) db_optr ::= db_optr cachelast */ - { 210, -1 }, /* (121) topic_optr ::= db_optr */ - { 210, -2 }, /* (122) topic_optr ::= topic_optr partitions */ - { 204, 0 }, /* (123) alter_db_optr ::= */ - { 204, -2 }, /* (124) alter_db_optr ::= alter_db_optr replica */ - { 204, -2 }, /* (125) alter_db_optr ::= alter_db_optr quorum */ - { 204, -2 }, /* (126) alter_db_optr ::= alter_db_optr keep */ - { 204, -2 }, /* (127) alter_db_optr ::= alter_db_optr blocks */ - { 204, -2 }, /* (128) alter_db_optr ::= alter_db_optr comp */ - { 204, -2 }, /* (129) alter_db_optr ::= alter_db_optr update */ - { 204, -2 }, /* (130) alter_db_optr ::= alter_db_optr cachelast */ - { 205, -1 }, /* (131) alter_topic_optr ::= alter_db_optr */ - { 205, -2 }, /* (132) alter_topic_optr ::= alter_topic_optr partitions */ - { 211, -1 }, /* (133) typename ::= ids */ - { 211, -4 }, /* (134) typename ::= ids LP signed RP */ - { 211, -2 }, /* (135) typename ::= ids UNSIGNED */ - { 240, -1 }, /* (136) signed ::= INTEGER */ - { 240, -2 }, /* (137) signed ::= PLUS INTEGER */ - { 240, -2 }, /* (138) signed ::= MINUS INTEGER */ - { 199, -3 }, /* (139) cmd ::= CREATE TABLE create_table_args */ - { 199, -3 }, /* (140) cmd ::= CREATE TABLE create_stable_args */ - { 199, -3 }, /* (141) cmd ::= CREATE STABLE create_stable_args */ - { 199, -3 }, /* (142) cmd ::= CREATE TABLE create_table_list */ - { 243, -1 }, /* (143) create_table_list ::= create_from_stable */ - { 243, -2 }, /* (144) create_table_list ::= create_table_list create_from_stable */ - { 241, -6 }, /* (145) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 242, -10 }, /* (146) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 244, -10 }, /* (147) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ - { 244, -13 }, /* (148) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ - { 247, -3 }, /* (149) tagNamelist ::= tagNamelist COMMA ids */ - { 247, -1 }, /* (150) tagNamelist ::= ids */ - { 241, -5 }, /* (151) create_table_args ::= ifnotexists ids cpxName AS select */ - { 245, -3 }, /* (152) columnlist ::= columnlist COMMA column */ - { 245, -1 }, /* (153) columnlist ::= column */ - { 249, -2 }, /* (154) column ::= ids typename */ - { 246, -3 }, /* (155) tagitemlist ::= tagitemlist COMMA tagitem */ - { 246, -1 }, /* (156) tagitemlist ::= tagitem */ - { 250, -1 }, /* (157) tagitem ::= INTEGER */ - { 250, -1 }, /* (158) tagitem ::= FLOAT */ - { 250, -1 }, /* (159) tagitem ::= STRING */ - { 250, -1 }, /* (160) tagitem ::= BOOL */ - { 250, -1 }, /* (161) tagitem ::= NULL */ - { 250, -1 }, /* (162) tagitem ::= NOW */ - { 250, -2 }, /* (163) tagitem ::= MINUS INTEGER */ - { 250, -2 }, /* (164) tagitem ::= MINUS FLOAT */ - { 250, -2 }, /* (165) tagitem ::= PLUS INTEGER */ - { 250, -2 }, /* (166) tagitem ::= PLUS FLOAT */ - { 248, -14 }, /* (167) 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 */ - { 248, -3 }, /* (168) select ::= LP select RP */ - { 264, -1 }, /* (169) union ::= select */ - { 264, -4 }, /* (170) union ::= union UNION ALL select */ - { 264, -3 }, /* (171) union ::= union UNION select */ - { 199, -1 }, /* (172) cmd ::= union */ - { 248, -2 }, /* (173) select ::= SELECT selcollist */ - { 265, -2 }, /* (174) sclp ::= selcollist COMMA */ - { 265, 0 }, /* (175) sclp ::= */ - { 251, -4 }, /* (176) selcollist ::= sclp distinct expr as */ - { 251, -2 }, /* (177) selcollist ::= sclp STAR */ - { 268, -2 }, /* (178) as ::= AS ids */ - { 268, -1 }, /* (179) as ::= ids */ - { 268, 0 }, /* (180) as ::= */ - { 266, -1 }, /* (181) distinct ::= DISTINCT */ - { 266, 0 }, /* (182) distinct ::= */ - { 252, -2 }, /* (183) from ::= FROM tablelist */ - { 252, -2 }, /* (184) from ::= FROM sub */ - { 270, -3 }, /* (185) sub ::= LP union RP */ - { 270, -4 }, /* (186) sub ::= LP union RP ids */ - { 270, -6 }, /* (187) sub ::= sub COMMA LP union RP ids */ - { 269, -2 }, /* (188) tablelist ::= ids cpxName */ - { 269, -3 }, /* (189) tablelist ::= ids cpxName ids */ - { 269, -4 }, /* (190) tablelist ::= tablelist COMMA ids cpxName */ - { 269, -5 }, /* (191) tablelist ::= tablelist COMMA ids cpxName ids */ - { 271, -1 }, /* (192) tmvar ::= VARIABLE */ - { 254, -4 }, /* (193) interval_option ::= intervalKey LP tmvar RP */ - { 254, -6 }, /* (194) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ - { 254, 0 }, /* (195) interval_option ::= */ - { 272, -1 }, /* (196) intervalKey ::= INTERVAL */ - { 272, -1 }, /* (197) intervalKey ::= EVERY */ - { 256, 0 }, /* (198) session_option ::= */ - { 256, -7 }, /* (199) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 257, 0 }, /* (200) windowstate_option ::= */ - { 257, -4 }, /* (201) windowstate_option ::= STATE_WINDOW LP ids RP */ - { 258, 0 }, /* (202) fill_opt ::= */ - { 258, -6 }, /* (203) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 258, -4 }, /* (204) fill_opt ::= FILL LP ID RP */ - { 255, -4 }, /* (205) sliding_opt ::= SLIDING LP tmvar RP */ - { 255, 0 }, /* (206) sliding_opt ::= */ - { 261, 0 }, /* (207) orderby_opt ::= */ - { 261, -3 }, /* (208) orderby_opt ::= ORDER BY sortlist */ - { 273, -4 }, /* (209) sortlist ::= sortlist COMMA item sortorder */ - { 273, -2 }, /* (210) sortlist ::= item sortorder */ - { 275, -2 }, /* (211) item ::= ids cpxName */ - { 276, -1 }, /* (212) sortorder ::= ASC */ - { 276, -1 }, /* (213) sortorder ::= DESC */ - { 276, 0 }, /* (214) sortorder ::= */ - { 259, 0 }, /* (215) groupby_opt ::= */ - { 259, -3 }, /* (216) groupby_opt ::= GROUP BY grouplist */ - { 277, -3 }, /* (217) grouplist ::= grouplist COMMA item */ - { 277, -1 }, /* (218) grouplist ::= item */ - { 260, 0 }, /* (219) having_opt ::= */ - { 260, -2 }, /* (220) having_opt ::= HAVING expr */ - { 263, 0 }, /* (221) limit_opt ::= */ - { 263, -2 }, /* (222) limit_opt ::= LIMIT signed */ - { 263, -4 }, /* (223) limit_opt ::= LIMIT signed OFFSET signed */ - { 263, -4 }, /* (224) limit_opt ::= LIMIT signed COMMA signed */ - { 262, 0 }, /* (225) slimit_opt ::= */ - { 262, -2 }, /* (226) slimit_opt ::= SLIMIT signed */ - { 262, -4 }, /* (227) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 262, -4 }, /* (228) slimit_opt ::= SLIMIT signed COMMA signed */ - { 253, 0 }, /* (229) where_opt ::= */ - { 253, -2 }, /* (230) where_opt ::= WHERE expr */ - { 267, -3 }, /* (231) expr ::= LP expr RP */ - { 267, -1 }, /* (232) expr ::= ID */ - { 267, -3 }, /* (233) expr ::= ID DOT ID */ - { 267, -3 }, /* (234) expr ::= ID DOT STAR */ - { 267, -1 }, /* (235) expr ::= INTEGER */ - { 267, -2 }, /* (236) expr ::= MINUS INTEGER */ - { 267, -2 }, /* (237) expr ::= PLUS INTEGER */ - { 267, -1 }, /* (238) expr ::= FLOAT */ - { 267, -2 }, /* (239) expr ::= MINUS FLOAT */ - { 267, -2 }, /* (240) expr ::= PLUS FLOAT */ - { 267, -1 }, /* (241) expr ::= STRING */ - { 267, -1 }, /* (242) expr ::= NOW */ - { 267, -1 }, /* (243) expr ::= VARIABLE */ - { 267, -2 }, /* (244) expr ::= PLUS VARIABLE */ - { 267, -2 }, /* (245) expr ::= MINUS VARIABLE */ - { 267, -1 }, /* (246) expr ::= BOOL */ - { 267, -1 }, /* (247) expr ::= NULL */ - { 267, -4 }, /* (248) expr ::= ID LP exprlist RP */ - { 267, -4 }, /* (249) expr ::= ID LP STAR RP */ - { 267, -3 }, /* (250) expr ::= expr IS NULL */ - { 267, -4 }, /* (251) expr ::= expr IS NOT NULL */ - { 267, -3 }, /* (252) expr ::= expr LT expr */ - { 267, -3 }, /* (253) expr ::= expr GT expr */ - { 267, -3 }, /* (254) expr ::= expr LE expr */ - { 267, -3 }, /* (255) expr ::= expr GE expr */ - { 267, -3 }, /* (256) expr ::= expr NE expr */ - { 267, -3 }, /* (257) expr ::= expr EQ expr */ - { 267, -5 }, /* (258) expr ::= expr BETWEEN expr AND expr */ - { 267, -3 }, /* (259) expr ::= expr AND expr */ - { 267, -3 }, /* (260) expr ::= expr OR expr */ - { 267, -3 }, /* (261) expr ::= expr PLUS expr */ - { 267, -3 }, /* (262) expr ::= expr MINUS expr */ - { 267, -3 }, /* (263) expr ::= expr STAR expr */ - { 267, -3 }, /* (264) expr ::= expr SLASH expr */ - { 267, -3 }, /* (265) expr ::= expr REM expr */ - { 267, -3 }, /* (266) expr ::= expr LIKE expr */ - { 267, -3 }, /* (267) expr ::= expr MATCH expr */ - { 267, -3 }, /* (268) expr ::= expr NMATCH expr */ - { 267, -5 }, /* (269) expr ::= expr IN LP exprlist RP */ - { 207, -3 }, /* (270) exprlist ::= exprlist COMMA expritem */ - { 207, -1 }, /* (271) exprlist ::= expritem */ - { 278, -1 }, /* (272) expritem ::= expr */ - { 278, 0 }, /* (273) expritem ::= */ - { 199, -3 }, /* (274) cmd ::= RESET QUERY CACHE */ - { 199, -3 }, /* (275) cmd ::= SYNCDB ids REPLICA */ - { 199, -7 }, /* (276) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 199, -7 }, /* (277) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 199, -7 }, /* (278) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - { 199, -7 }, /* (279) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 199, -7 }, /* (280) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 199, -8 }, /* (281) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 199, -9 }, /* (282) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 199, -7 }, /* (283) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - { 199, -7 }, /* (284) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 199, -7 }, /* (285) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 199, -7 }, /* (286) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - { 199, -7 }, /* (287) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 199, -7 }, /* (288) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 199, -8 }, /* (289) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 199, -9 }, /* (290) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - { 199, -7 }, /* (291) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - { 199, -3 }, /* (292) cmd ::= KILL CONNECTION INTEGER */ - { 199, -5 }, /* (293) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 199, -5 }, /* (294) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + { 197, -1 }, /* (0) program ::= cmd */ + { 198, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 198, -2 }, /* (2) cmd ::= SHOW TOPICS */ + { 198, -2 }, /* (3) cmd ::= SHOW FUNCTIONS */ + { 198, -2 }, /* (4) cmd ::= SHOW MNODES */ + { 198, -2 }, /* (5) cmd ::= SHOW DNODES */ + { 198, -2 }, /* (6) cmd ::= SHOW ACCOUNTS */ + { 198, -2 }, /* (7) cmd ::= SHOW USERS */ + { 198, -2 }, /* (8) cmd ::= SHOW MODULES */ + { 198, -2 }, /* (9) cmd ::= SHOW QUERIES */ + { 198, -2 }, /* (10) cmd ::= SHOW CONNECTIONS */ + { 198, -2 }, /* (11) cmd ::= SHOW STREAMS */ + { 198, -2 }, /* (12) cmd ::= SHOW VARIABLES */ + { 198, -2 }, /* (13) cmd ::= SHOW SCORES */ + { 198, -2 }, /* (14) cmd ::= SHOW GRANTS */ + { 198, -2 }, /* (15) cmd ::= SHOW VNODES */ + { 198, -3 }, /* (16) cmd ::= SHOW VNODES ids */ + { 200, 0 }, /* (17) dbPrefix ::= */ + { 200, -2 }, /* (18) dbPrefix ::= ids DOT */ + { 201, 0 }, /* (19) cpxName ::= */ + { 201, -2 }, /* (20) cpxName ::= DOT ids */ + { 198, -5 }, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ + { 198, -5 }, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ + { 198, -4 }, /* (23) cmd ::= SHOW CREATE DATABASE ids */ + { 198, -3 }, /* (24) cmd ::= SHOW dbPrefix TABLES */ + { 198, -5 }, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 198, -3 }, /* (26) cmd ::= SHOW dbPrefix STABLES */ + { 198, -5 }, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 198, -3 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ + { 198, -4 }, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ + { 198, -5 }, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ + { 198, -5 }, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ + { 198, -4 }, /* (32) cmd ::= DROP DATABASE ifexists ids */ + { 198, -4 }, /* (33) cmd ::= DROP TOPIC ifexists ids */ + { 198, -3 }, /* (34) cmd ::= DROP FUNCTION ids */ + { 198, -3 }, /* (35) cmd ::= DROP DNODE ids */ + { 198, -3 }, /* (36) cmd ::= DROP USER ids */ + { 198, -3 }, /* (37) cmd ::= DROP ACCOUNT ids */ + { 198, -2 }, /* (38) cmd ::= USE ids */ + { 198, -3 }, /* (39) cmd ::= DESCRIBE ids cpxName */ + { 198, -3 }, /* (40) cmd ::= DESC ids cpxName */ + { 198, -5 }, /* (41) cmd ::= ALTER USER ids PASS ids */ + { 198, -5 }, /* (42) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 198, -4 }, /* (43) cmd ::= ALTER DNODE ids ids */ + { 198, -5 }, /* (44) cmd ::= ALTER DNODE ids ids ids */ + { 198, -3 }, /* (45) cmd ::= ALTER LOCAL ids */ + { 198, -4 }, /* (46) cmd ::= ALTER LOCAL ids ids */ + { 198, -4 }, /* (47) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 198, -4 }, /* (48) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 198, -6 }, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 198, -6 }, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ + { 199, -1 }, /* (51) ids ::= ID */ + { 199, -1 }, /* (52) ids ::= STRING */ + { 202, -2 }, /* (53) ifexists ::= IF EXISTS */ + { 202, 0 }, /* (54) ifexists ::= */ + { 206, -3 }, /* (55) ifnotexists ::= IF NOT EXISTS */ + { 206, 0 }, /* (56) ifnotexists ::= */ + { 198, -3 }, /* (57) cmd ::= CREATE DNODE ids */ + { 198, -6 }, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 198, -5 }, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 198, -8 }, /* (60) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 198, -9 }, /* (61) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 198, -5 }, /* (62) cmd ::= CREATE USER ids PASS ids */ + { 209, 0 }, /* (63) bufsize ::= */ + { 209, -2 }, /* (64) bufsize ::= BUFSIZE INTEGER */ + { 210, 0 }, /* (65) pps ::= */ + { 210, -2 }, /* (66) pps ::= PPS INTEGER */ + { 211, 0 }, /* (67) tseries ::= */ + { 211, -2 }, /* (68) tseries ::= TSERIES INTEGER */ + { 212, 0 }, /* (69) dbs ::= */ + { 212, -2 }, /* (70) dbs ::= DBS INTEGER */ + { 213, 0 }, /* (71) streams ::= */ + { 213, -2 }, /* (72) streams ::= STREAMS INTEGER */ + { 214, 0 }, /* (73) storage ::= */ + { 214, -2 }, /* (74) storage ::= STORAGE INTEGER */ + { 215, 0 }, /* (75) qtime ::= */ + { 215, -2 }, /* (76) qtime ::= QTIME INTEGER */ + { 216, 0 }, /* (77) users ::= */ + { 216, -2 }, /* (78) users ::= USERS INTEGER */ + { 217, 0 }, /* (79) conns ::= */ + { 217, -2 }, /* (80) conns ::= CONNS INTEGER */ + { 218, 0 }, /* (81) state ::= */ + { 218, -2 }, /* (82) state ::= STATE ids */ + { 204, -9 }, /* (83) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 219, -3 }, /* (84) intitemlist ::= intitemlist COMMA intitem */ + { 219, -1 }, /* (85) intitemlist ::= intitem */ + { 220, -1 }, /* (86) intitem ::= INTEGER */ + { 221, -2 }, /* (87) keep ::= KEEP intitemlist */ + { 222, -2 }, /* (88) cache ::= CACHE INTEGER */ + { 223, -2 }, /* (89) replica ::= REPLICA INTEGER */ + { 224, -2 }, /* (90) quorum ::= QUORUM INTEGER */ + { 225, -2 }, /* (91) days ::= DAYS INTEGER */ + { 226, -2 }, /* (92) minrows ::= MINROWS INTEGER */ + { 227, -2 }, /* (93) maxrows ::= MAXROWS INTEGER */ + { 228, -2 }, /* (94) blocks ::= BLOCKS INTEGER */ + { 229, -2 }, /* (95) ctime ::= CTIME INTEGER */ + { 230, -2 }, /* (96) wal ::= WAL INTEGER */ + { 231, -2 }, /* (97) fsync ::= FSYNC INTEGER */ + { 232, -2 }, /* (98) comp ::= COMP INTEGER */ + { 233, -2 }, /* (99) prec ::= PRECISION STRING */ + { 234, -2 }, /* (100) update ::= UPDATE INTEGER */ + { 235, -2 }, /* (101) cachelast ::= CACHELAST INTEGER */ + { 207, 0 }, /* (102) db_optr ::= */ + { 207, -2 }, /* (103) db_optr ::= db_optr cache */ + { 207, -2 }, /* (104) db_optr ::= db_optr replica */ + { 207, -2 }, /* (105) db_optr ::= db_optr quorum */ + { 207, -2 }, /* (106) db_optr ::= db_optr days */ + { 207, -2 }, /* (107) db_optr ::= db_optr minrows */ + { 207, -2 }, /* (108) db_optr ::= db_optr maxrows */ + { 207, -2 }, /* (109) db_optr ::= db_optr blocks */ + { 207, -2 }, /* (110) db_optr ::= db_optr ctime */ + { 207, -2 }, /* (111) db_optr ::= db_optr wal */ + { 207, -2 }, /* (112) db_optr ::= db_optr fsync */ + { 207, -2 }, /* (113) db_optr ::= db_optr comp */ + { 207, -2 }, /* (114) db_optr ::= db_optr prec */ + { 207, -2 }, /* (115) db_optr ::= db_optr keep */ + { 207, -2 }, /* (116) db_optr ::= db_optr update */ + { 207, -2 }, /* (117) db_optr ::= db_optr cachelast */ + { 203, 0 }, /* (118) alter_db_optr ::= */ + { 203, -2 }, /* (119) alter_db_optr ::= alter_db_optr replica */ + { 203, -2 }, /* (120) alter_db_optr ::= alter_db_optr quorum */ + { 203, -2 }, /* (121) alter_db_optr ::= alter_db_optr keep */ + { 203, -2 }, /* (122) alter_db_optr ::= alter_db_optr blocks */ + { 203, -2 }, /* (123) alter_db_optr ::= alter_db_optr comp */ + { 203, -2 }, /* (124) alter_db_optr ::= alter_db_optr update */ + { 203, -2 }, /* (125) alter_db_optr ::= alter_db_optr cachelast */ + { 208, -1 }, /* (126) typename ::= ids */ + { 208, -4 }, /* (127) typename ::= ids LP signed RP */ + { 208, -2 }, /* (128) typename ::= ids UNSIGNED */ + { 236, -1 }, /* (129) signed ::= INTEGER */ + { 236, -2 }, /* (130) signed ::= PLUS INTEGER */ + { 236, -2 }, /* (131) signed ::= MINUS INTEGER */ + { 198, -3 }, /* (132) cmd ::= CREATE TABLE create_table_args */ + { 198, -3 }, /* (133) cmd ::= CREATE TABLE create_stable_args */ + { 198, -3 }, /* (134) cmd ::= CREATE STABLE create_stable_args */ + { 198, -3 }, /* (135) cmd ::= CREATE TABLE create_table_list */ + { 239, -1 }, /* (136) create_table_list ::= create_from_stable */ + { 239, -2 }, /* (137) create_table_list ::= create_table_list create_from_stable */ + { 237, -6 }, /* (138) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 238, -10 }, /* (139) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 240, -10 }, /* (140) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + { 240, -13 }, /* (141) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + { 243, -3 }, /* (142) tagNamelist ::= tagNamelist COMMA ids */ + { 243, -1 }, /* (143) tagNamelist ::= ids */ + { 237, -5 }, /* (144) create_table_args ::= ifnotexists ids cpxName AS select */ + { 241, -3 }, /* (145) columnlist ::= columnlist COMMA column */ + { 241, -1 }, /* (146) columnlist ::= column */ + { 245, -2 }, /* (147) column ::= ids typename */ + { 242, -3 }, /* (148) tagitemlist ::= tagitemlist COMMA tagitem */ + { 242, -1 }, /* (149) tagitemlist ::= tagitem */ + { 246, -1 }, /* (150) tagitem ::= INTEGER */ + { 246, -1 }, /* (151) tagitem ::= FLOAT */ + { 246, -1 }, /* (152) tagitem ::= STRING */ + { 246, -1 }, /* (153) tagitem ::= BOOL */ + { 246, -1 }, /* (154) tagitem ::= NULL */ + { 246, -1 }, /* (155) tagitem ::= NOW */ + { 246, -2 }, /* (156) tagitem ::= MINUS INTEGER */ + { 246, -2 }, /* (157) tagitem ::= MINUS FLOAT */ + { 246, -2 }, /* (158) tagitem ::= PLUS INTEGER */ + { 246, -2 }, /* (159) tagitem ::= PLUS FLOAT */ + { 244, -14 }, /* (160) 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 */ + { 244, -3 }, /* (161) select ::= LP select RP */ + { 260, -1 }, /* (162) union ::= select */ + { 260, -4 }, /* (163) union ::= union UNION ALL select */ + { 260, -3 }, /* (164) union ::= union UNION select */ + { 198, -1 }, /* (165) cmd ::= union */ + { 244, -2 }, /* (166) select ::= SELECT selcollist */ + { 261, -2 }, /* (167) sclp ::= selcollist COMMA */ + { 261, 0 }, /* (168) sclp ::= */ + { 247, -4 }, /* (169) selcollist ::= sclp distinct expr as */ + { 247, -2 }, /* (170) selcollist ::= sclp STAR */ + { 264, -2 }, /* (171) as ::= AS ids */ + { 264, -1 }, /* (172) as ::= ids */ + { 264, 0 }, /* (173) as ::= */ + { 262, -1 }, /* (174) distinct ::= DISTINCT */ + { 262, 0 }, /* (175) distinct ::= */ + { 248, -2 }, /* (176) from ::= FROM tablelist */ + { 248, -2 }, /* (177) from ::= FROM sub */ + { 266, -3 }, /* (178) sub ::= LP union RP */ + { 266, -4 }, /* (179) sub ::= LP union RP ids */ + { 266, -6 }, /* (180) sub ::= sub COMMA LP union RP ids */ + { 265, -2 }, /* (181) tablelist ::= ids cpxName */ + { 265, -3 }, /* (182) tablelist ::= ids cpxName ids */ + { 265, -4 }, /* (183) tablelist ::= tablelist COMMA ids cpxName */ + { 265, -5 }, /* (184) tablelist ::= tablelist COMMA ids cpxName ids */ + { 267, -1 }, /* (185) tmvar ::= VARIABLE */ + { 250, -4 }, /* (186) interval_option ::= intervalKey LP tmvar RP */ + { 250, -6 }, /* (187) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + { 250, 0 }, /* (188) interval_option ::= */ + { 268, -1 }, /* (189) intervalKey ::= INTERVAL */ + { 268, -1 }, /* (190) intervalKey ::= EVERY */ + { 252, 0 }, /* (191) session_option ::= */ + { 252, -7 }, /* (192) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 253, 0 }, /* (193) windowstate_option ::= */ + { 253, -4 }, /* (194) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 254, 0 }, /* (195) fill_opt ::= */ + { 254, -6 }, /* (196) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 254, -4 }, /* (197) fill_opt ::= FILL LP ID RP */ + { 251, -4 }, /* (198) sliding_opt ::= SLIDING LP tmvar RP */ + { 251, 0 }, /* (199) sliding_opt ::= */ + { 257, 0 }, /* (200) orderby_opt ::= */ + { 257, -3 }, /* (201) orderby_opt ::= ORDER BY sortlist */ + { 269, -4 }, /* (202) sortlist ::= sortlist COMMA item sortorder */ + { 269, -2 }, /* (203) sortlist ::= item sortorder */ + { 271, -2 }, /* (204) item ::= ids cpxName */ + { 272, -1 }, /* (205) sortorder ::= ASC */ + { 272, -1 }, /* (206) sortorder ::= DESC */ + { 272, 0 }, /* (207) sortorder ::= */ + { 255, 0 }, /* (208) groupby_opt ::= */ + { 255, -3 }, /* (209) groupby_opt ::= GROUP BY grouplist */ + { 273, -3 }, /* (210) grouplist ::= grouplist COMMA item */ + { 273, -1 }, /* (211) grouplist ::= item */ + { 256, 0 }, /* (212) having_opt ::= */ + { 256, -2 }, /* (213) having_opt ::= HAVING expr */ + { 259, 0 }, /* (214) limit_opt ::= */ + { 259, -2 }, /* (215) limit_opt ::= LIMIT signed */ + { 259, -4 }, /* (216) limit_opt ::= LIMIT signed OFFSET signed */ + { 259, -4 }, /* (217) limit_opt ::= LIMIT signed COMMA signed */ + { 258, 0 }, /* (218) slimit_opt ::= */ + { 258, -2 }, /* (219) slimit_opt ::= SLIMIT signed */ + { 258, -4 }, /* (220) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 258, -4 }, /* (221) slimit_opt ::= SLIMIT signed COMMA signed */ + { 249, 0 }, /* (222) where_opt ::= */ + { 249, -2 }, /* (223) where_opt ::= WHERE expr */ + { 263, -3 }, /* (224) expr ::= LP expr RP */ + { 263, -1 }, /* (225) expr ::= ID */ + { 263, -3 }, /* (226) expr ::= ID DOT ID */ + { 263, -3 }, /* (227) expr ::= ID DOT STAR */ + { 263, -1 }, /* (228) expr ::= INTEGER */ + { 263, -2 }, /* (229) expr ::= MINUS INTEGER */ + { 263, -2 }, /* (230) expr ::= PLUS INTEGER */ + { 263, -1 }, /* (231) expr ::= FLOAT */ + { 263, -2 }, /* (232) expr ::= MINUS FLOAT */ + { 263, -2 }, /* (233) expr ::= PLUS FLOAT */ + { 263, -1 }, /* (234) expr ::= STRING */ + { 263, -1 }, /* (235) expr ::= NOW */ + { 263, -1 }, /* (236) expr ::= VARIABLE */ + { 263, -2 }, /* (237) expr ::= PLUS VARIABLE */ + { 263, -2 }, /* (238) expr ::= MINUS VARIABLE */ + { 263, -1 }, /* (239) expr ::= BOOL */ + { 263, -1 }, /* (240) expr ::= NULL */ + { 263, -4 }, /* (241) expr ::= ID LP exprlist RP */ + { 263, -4 }, /* (242) expr ::= ID LP STAR RP */ + { 263, -3 }, /* (243) expr ::= expr IS NULL */ + { 263, -4 }, /* (244) expr ::= expr IS NOT NULL */ + { 263, -3 }, /* (245) expr ::= expr LT expr */ + { 263, -3 }, /* (246) expr ::= expr GT expr */ + { 263, -3 }, /* (247) expr ::= expr LE expr */ + { 263, -3 }, /* (248) expr ::= expr GE expr */ + { 263, -3 }, /* (249) expr ::= expr NE expr */ + { 263, -3 }, /* (250) expr ::= expr EQ expr */ + { 263, -5 }, /* (251) expr ::= expr BETWEEN expr AND expr */ + { 263, -3 }, /* (252) expr ::= expr AND expr */ + { 263, -3 }, /* (253) expr ::= expr OR expr */ + { 263, -3 }, /* (254) expr ::= expr PLUS expr */ + { 263, -3 }, /* (255) expr ::= expr MINUS expr */ + { 263, -3 }, /* (256) expr ::= expr STAR expr */ + { 263, -3 }, /* (257) expr ::= expr SLASH expr */ + { 263, -3 }, /* (258) expr ::= expr REM expr */ + { 263, -3 }, /* (259) expr ::= expr LIKE expr */ + { 263, -3 }, /* (260) expr ::= expr MATCH expr */ + { 263, -3 }, /* (261) expr ::= expr NMATCH expr */ + { 263, -5 }, /* (262) expr ::= expr IN LP exprlist RP */ + { 205, -3 }, /* (263) exprlist ::= exprlist COMMA expritem */ + { 205, -1 }, /* (264) exprlist ::= expritem */ + { 274, -1 }, /* (265) expritem ::= expr */ + { 274, 0 }, /* (266) expritem ::= */ + { 198, -3 }, /* (267) cmd ::= RESET QUERY CACHE */ + { 198, -3 }, /* (268) cmd ::= SYNCDB ids REPLICA */ + { 198, -7 }, /* (269) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 198, -7 }, /* (270) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 198, -7 }, /* (271) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + { 198, -7 }, /* (272) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 198, -7 }, /* (273) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 198, -8 }, /* (274) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 198, -9 }, /* (275) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 198, -7 }, /* (276) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + { 198, -7 }, /* (277) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 198, -7 }, /* (278) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 198, -7 }, /* (279) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + { 198, -7 }, /* (280) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 198, -7 }, /* (281) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 198, -8 }, /* (282) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 198, -9 }, /* (283) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + { 198, -7 }, /* (284) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + { 198, -3 }, /* (285) cmd ::= KILL CONNECTION INTEGER */ + { 198, -5 }, /* (286) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 198, -5 }, /* (287) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2217,9 +2193,9 @@ static void yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ - case 139: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==139); - case 140: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==140); - case 141: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==141); + case 132: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==132); + case 133: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==133); + case 134: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==134); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -2395,780 +2371,767 @@ static void yy_reduce( { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 47: /* cmd ::= ALTER DATABASE ids alter_db_optr */ - case 48: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==48); -{ SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy256, &t);} +{ SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy42, &t);} break; - case 49: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy277);} + case 48: /* cmd ::= ALTER ACCOUNT ids acct_optr */ +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy341);} break; - case 50: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy277);} + case 49: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy341);} break; - case 51: /* cmd ::= COMPACT VNODES IN LP exprlist RP */ -{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy135);} + case 50: /* cmd ::= COMPACT VNODES IN LP exprlist RP */ +{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy131);} break; - case 52: /* ids ::= ID */ - case 53: /* ids ::= STRING */ yytestcase(yyruleno==53); + 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 54: /* ifexists ::= IF EXISTS */ + case 53: /* ifexists ::= IF EXISTS */ { yymsp[-1].minor.yy0.n = 1;} break; - case 55: /* ifexists ::= */ - case 57: /* ifnotexists ::= */ yytestcase(yyruleno==57); - case 182: /* distinct ::= */ yytestcase(yyruleno==182); + case 54: /* ifexists ::= */ + case 56: /* ifnotexists ::= */ yytestcase(yyruleno==56); + case 175: /* distinct ::= */ yytestcase(yyruleno==175); { yymsp[1].minor.yy0.n = 0;} break; - case 56: /* ifnotexists ::= IF NOT EXISTS */ + case 55: /* ifnotexists ::= IF NOT EXISTS */ { yymsp[-2].minor.yy0.n = 1;} break; - case 58: /* cmd ::= CREATE DNODE ids */ + case 57: /* cmd ::= CREATE DNODE ids */ { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; - case 59: /* 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.yy277);} + 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.yy341);} break; - case 60: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - case 61: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==61); -{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy256, &yymsp[-2].minor.yy0);} + case 59: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ +{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy42, &yymsp[-2].minor.yy0);} break; - case 62: /* 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.yy304, &yymsp[0].minor.yy0, 1);} + 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.yy290, &yymsp[0].minor.yy0, 1);} break; - case 63: /* 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.yy304, &yymsp[0].minor.yy0, 2);} + 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.yy290, &yymsp[0].minor.yy0, 2);} break; - case 64: /* 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 65: /* bufsize ::= */ - case 67: /* pps ::= */ yytestcase(yyruleno==67); - case 69: /* tseries ::= */ yytestcase(yyruleno==69); - case 71: /* dbs ::= */ yytestcase(yyruleno==71); - case 73: /* streams ::= */ yytestcase(yyruleno==73); - case 75: /* storage ::= */ yytestcase(yyruleno==75); - case 77: /* qtime ::= */ yytestcase(yyruleno==77); - case 79: /* users ::= */ yytestcase(yyruleno==79); - case 81: /* conns ::= */ yytestcase(yyruleno==81); - case 83: /* state ::= */ yytestcase(yyruleno==83); + 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 66: /* bufsize ::= BUFSIZE INTEGER */ - case 68: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==68); - case 70: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==70); - case 72: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==72); - case 74: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==74); - case 76: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==76); - case 78: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==78); - case 80: /* users ::= USERS INTEGER */ yytestcase(yyruleno==80); - case 82: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==82); - case 84: /* state ::= STATE ids */ yytestcase(yyruleno==84); + 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 85: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ -{ - yylhsminor.yy277.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yylhsminor.yy277.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yylhsminor.yy277.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yylhsminor.yy277.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yylhsminor.yy277.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yylhsminor.yy277.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy277.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy277.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yylhsminor.yy277.stat = yymsp[0].minor.yy0; -} - yymsp[-8].minor.yy277 = yylhsminor.yy277; - break; - case 86: /* intitemlist ::= intitemlist COMMA intitem */ - case 155: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==155); -{ yylhsminor.yy135 = tListItemAppend(yymsp[-2].minor.yy135, &yymsp[0].minor.yy191, -1); } - yymsp[-2].minor.yy135 = yylhsminor.yy135; - break; - case 87: /* intitemlist ::= intitem */ - case 156: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==156); -{ yylhsminor.yy135 = tListItemAppend(NULL, &yymsp[0].minor.yy191, -1); } - yymsp[0].minor.yy135 = yylhsminor.yy135; - break; - case 88: /* intitem ::= INTEGER */ - case 157: /* tagitem ::= INTEGER */ yytestcase(yyruleno==157); - case 158: /* tagitem ::= FLOAT */ yytestcase(yyruleno==158); - case 159: /* tagitem ::= STRING */ yytestcase(yyruleno==159); - case 160: /* tagitem ::= BOOL */ yytestcase(yyruleno==160); -{ toTSDBType(yymsp[0].minor.yy0.type); taosVariantCreate(&yylhsminor.yy191, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } - yymsp[0].minor.yy191 = yylhsminor.yy191; - break; - case 89: /* keep ::= KEEP intitemlist */ -{ yymsp[-1].minor.yy135 = yymsp[0].minor.yy135; } - break; - case 90: /* cache ::= CACHE INTEGER */ - case 91: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==91); - case 92: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==92); - case 93: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==93); - case 94: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==94); - case 95: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==95); - case 96: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==96); - case 97: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==97); - case 98: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==98); - case 99: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==99); - case 100: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==100); - case 101: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==101); - case 102: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==102); - case 103: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==103); - case 104: /* partitions ::= PARTITIONS INTEGER */ yytestcase(yyruleno==104); + case 83: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ +{ + yylhsminor.yy341.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy341.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy341.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy341.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy341.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy341.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy341.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy341.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy341.stat = yymsp[0].minor.yy0; +} + yymsp[-8].minor.yy341 = yylhsminor.yy341; + break; + case 84: /* intitemlist ::= intitemlist COMMA intitem */ + case 148: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==148); +{ yylhsminor.yy131 = tListItemAppend(yymsp[-2].minor.yy131, &yymsp[0].minor.yy43, -1); } + yymsp[-2].minor.yy131 = yylhsminor.yy131; + break; + case 85: /* intitemlist ::= intitem */ + case 149: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==149); +{ yylhsminor.yy131 = tListItemAppend(NULL, &yymsp[0].minor.yy43, -1); } + yymsp[0].minor.yy131 = yylhsminor.yy131; + break; + case 86: /* intitem ::= INTEGER */ + case 150: /* tagitem ::= INTEGER */ yytestcase(yyruleno==150); + case 151: /* tagitem ::= FLOAT */ yytestcase(yyruleno==151); + case 152: /* tagitem ::= STRING */ yytestcase(yyruleno==152); + case 153: /* tagitem ::= BOOL */ yytestcase(yyruleno==153); +{ toTSDBType(yymsp[0].minor.yy0.type); taosVariantCreate(&yylhsminor.yy43, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } + yymsp[0].minor.yy43 = yylhsminor.yy43; + break; + case 87: /* keep ::= KEEP intitemlist */ +{ yymsp[-1].minor.yy131 = yymsp[0].minor.yy131; } + break; + 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); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 105: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy256);} + case 102: /* db_optr ::= */ +{setDefaultCreateDbOption(&yymsp[1].minor.yy42);} break; - case 106: /* db_optr ::= db_optr cache */ -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 103: /* db_optr ::= db_optr cache */ +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 107: /* db_optr ::= db_optr replica */ - case 124: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==124); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 104: /* db_optr ::= db_optr replica */ + case 119: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==119); +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 108: /* db_optr ::= db_optr quorum */ - case 125: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==125); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 105: /* db_optr ::= db_optr quorum */ + case 120: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==120); +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 109: /* db_optr ::= db_optr days */ -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 106: /* db_optr ::= db_optr days */ +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 110: /* db_optr ::= db_optr minrows */ -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 107: /* db_optr ::= db_optr minrows */ +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 111: /* db_optr ::= db_optr maxrows */ -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 108: /* db_optr ::= db_optr maxrows */ +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 112: /* db_optr ::= db_optr blocks */ - case 127: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==127); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 109: /* db_optr ::= db_optr blocks */ + case 122: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==122); +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 113: /* db_optr ::= db_optr ctime */ -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 110: /* db_optr ::= db_optr ctime */ +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 114: /* db_optr ::= db_optr wal */ -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 111: /* db_optr ::= db_optr wal */ +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 115: /* db_optr ::= db_optr fsync */ -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 112: /* db_optr ::= db_optr fsync */ +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 116: /* db_optr ::= db_optr comp */ - case 128: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==128); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 113: /* db_optr ::= db_optr comp */ + case 123: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==123); +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 117: /* db_optr ::= db_optr prec */ -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.precision = yymsp[0].minor.yy0; } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 114: /* db_optr ::= db_optr prec */ +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 118: /* db_optr ::= db_optr keep */ - case 126: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==126); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.keep = yymsp[0].minor.yy135; } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 115: /* db_optr ::= db_optr keep */ + case 121: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==121); +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.keep = yymsp[0].minor.yy131; } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 119: /* db_optr ::= db_optr update */ - case 129: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==129); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 116: /* db_optr ::= db_optr update */ + case 124: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==124); +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 120: /* db_optr ::= db_optr cachelast */ - case 130: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==130); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy256 = yylhsminor.yy256; + case 117: /* db_optr ::= db_optr cachelast */ + case 125: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==125); +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; - case 121: /* topic_optr ::= db_optr */ - case 131: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==131); -{ yylhsminor.yy256 = yymsp[0].minor.yy256;} - yymsp[0].minor.yy256 = yylhsminor.yy256; + case 118: /* alter_db_optr ::= */ +{ setDefaultCreateDbOption(&yymsp[1].minor.yy42);} break; - case 122: /* topic_optr ::= topic_optr partitions */ - case 132: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==132); -{ yylhsminor.yy256 = yymsp[-1].minor.yy256; } - yymsp[-1].minor.yy256 = yylhsminor.yy256; - break; - case 123: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy256); } - break; - case 133: /* typename ::= ids */ + case 126: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yylhsminor.yy304, &yymsp[0].minor.yy0); + tSetColumnType (&yylhsminor.yy290, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy304 = yylhsminor.yy304; + yymsp[0].minor.yy290 = yylhsminor.yy290; break; - case 134: /* typename ::= ids LP signed RP */ + case 127: /* typename ::= ids LP signed RP */ { - if (yymsp[-1].minor.yy531 <= 0) { + if (yymsp[-1].minor.yy459 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yylhsminor.yy304, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy290, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy531; // negative value of name length - tSetColumnType(&yylhsminor.yy304, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy459; // negative value of name length + tSetColumnType(&yylhsminor.yy290, &yymsp[-3].minor.yy0); } } - yymsp[-3].minor.yy304 = yylhsminor.yy304; + yymsp[-3].minor.yy290 = yylhsminor.yy290; break; - case 135: /* typename ::= ids UNSIGNED */ + case 128: /* 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); - tSetColumnType (&yylhsminor.yy304, &yymsp[-1].minor.yy0); + tSetColumnType (&yylhsminor.yy290, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy304 = yylhsminor.yy304; + yymsp[-1].minor.yy290 = yylhsminor.yy290; break; - case 136: /* signed ::= INTEGER */ -{ yylhsminor.yy531 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[0].minor.yy531 = yylhsminor.yy531; + case 129: /* signed ::= INTEGER */ +{ yylhsminor.yy459 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy459 = yylhsminor.yy459; break; - case 137: /* signed ::= PLUS INTEGER */ -{ yymsp[-1].minor.yy531 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 130: /* signed ::= PLUS INTEGER */ +{ yymsp[-1].minor.yy459 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 138: /* signed ::= MINUS INTEGER */ -{ yymsp[-1].minor.yy531 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} + case 131: /* signed ::= MINUS INTEGER */ +{ yymsp[-1].minor.yy459 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; - case 142: /* cmd ::= CREATE TABLE create_table_list */ -{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy110;} + case 135: /* cmd ::= CREATE TABLE create_table_list */ +{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy272;} break; - case 143: /* create_table_list ::= create_from_stable */ + case 136: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); - taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy78); + taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy96); pCreateTable->type = TSQL_CREATE_CTABLE; - yylhsminor.yy110 = pCreateTable; + yylhsminor.yy272 = pCreateTable; } - yymsp[0].minor.yy110 = yylhsminor.yy110; + yymsp[0].minor.yy272 = yylhsminor.yy272; break; - case 144: /* create_table_list ::= create_table_list create_from_stable */ + case 137: /* create_table_list ::= create_table_list create_from_stable */ { - taosArrayPush(yymsp[-1].minor.yy110->childTableInfo, &yymsp[0].minor.yy78); - yylhsminor.yy110 = yymsp[-1].minor.yy110; + taosArrayPush(yymsp[-1].minor.yy272->childTableInfo, &yymsp[0].minor.yy96); + yylhsminor.yy272 = yymsp[-1].minor.yy272; } - yymsp[-1].minor.yy110 = yylhsminor.yy110; + yymsp[-1].minor.yy272 = yylhsminor.yy272; break; - case 145: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + case 138: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yylhsminor.yy110 = tSetCreateTableInfo(yymsp[-1].minor.yy135, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yylhsminor.yy110, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy272 = tSetCreateTableInfo(yymsp[-1].minor.yy131, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0); } - yymsp[-5].minor.yy110 = yylhsminor.yy110; + yymsp[-5].minor.yy272 = yylhsminor.yy272; break; - case 146: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + case 139: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yylhsminor.yy110 = tSetCreateTableInfo(yymsp[-5].minor.yy135, yymsp[-1].minor.yy135, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy110, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy272 = tSetCreateTableInfo(yymsp[-5].minor.yy131, yymsp[-1].minor.yy131, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy110 = yylhsminor.yy110; + yymsp[-9].minor.yy272 = yylhsminor.yy272; break; - case 147: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + case 140: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; - yylhsminor.yy78 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy135, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yylhsminor.yy96 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy131, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy78 = yylhsminor.yy78; + yymsp[-9].minor.yy96 = yylhsminor.yy96; break; - case 148: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + case 141: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; - yylhsminor.yy78 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy135, yymsp[-1].minor.yy135, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yylhsminor.yy96 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy131, yymsp[-1].minor.yy131, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } - yymsp[-12].minor.yy78 = yylhsminor.yy78; + yymsp[-12].minor.yy96 = yylhsminor.yy96; break; - case 149: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy135, &yymsp[0].minor.yy0); yylhsminor.yy135 = yymsp[-2].minor.yy135; } - yymsp[-2].minor.yy135 = yylhsminor.yy135; + case 142: /* tagNamelist ::= tagNamelist COMMA ids */ +{taosArrayPush(yymsp[-2].minor.yy131, &yymsp[0].minor.yy0); yylhsminor.yy131 = yymsp[-2].minor.yy131; } + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; - case 150: /* tagNamelist ::= ids */ -{yylhsminor.yy135 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy135, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy135 = yylhsminor.yy135; + case 143: /* tagNamelist ::= ids */ +{yylhsminor.yy131 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy131, &yymsp[0].minor.yy0);} + yymsp[0].minor.yy131 = yylhsminor.yy131; break; - case 151: /* create_table_args ::= ifnotexists ids cpxName AS select */ + case 144: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yylhsminor.yy110 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy488, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy110, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy272 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy256, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } - yymsp[-4].minor.yy110 = yylhsminor.yy110; + yymsp[-4].minor.yy272 = yylhsminor.yy272; break; - case 152: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy135, &yymsp[0].minor.yy304); yylhsminor.yy135 = yymsp[-2].minor.yy135; } - yymsp[-2].minor.yy135 = yylhsminor.yy135; + case 145: /* columnlist ::= columnlist COMMA column */ +{taosArrayPush(yymsp[-2].minor.yy131, &yymsp[0].minor.yy290); yylhsminor.yy131 = yymsp[-2].minor.yy131; } + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; - case 153: /* columnlist ::= column */ -{yylhsminor.yy135 = taosArrayInit(4, sizeof(SField)); taosArrayPush(yylhsminor.yy135, &yymsp[0].minor.yy304);} - yymsp[0].minor.yy135 = yylhsminor.yy135; + case 146: /* columnlist ::= column */ +{yylhsminor.yy131 = taosArrayInit(4, sizeof(SField)); taosArrayPush(yylhsminor.yy131, &yymsp[0].minor.yy290);} + yymsp[0].minor.yy131 = yylhsminor.yy131; break; - case 154: /* column ::= ids typename */ + case 147: /* column ::= ids typename */ { - tSetColumnInfo(&yylhsminor.yy304, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy304); + tSetColumnInfo(&yylhsminor.yy290, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy290); } - yymsp[-1].minor.yy304 = yylhsminor.yy304; + yymsp[-1].minor.yy290 = yylhsminor.yy290; break; - case 161: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; taosVariantCreate(&yylhsminor.yy191, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } - yymsp[0].minor.yy191 = yylhsminor.yy191; + case 154: /* tagitem ::= NULL */ +{ yymsp[0].minor.yy0.type = 0; taosVariantCreate(&yylhsminor.yy43, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } + yymsp[0].minor.yy43 = yylhsminor.yy43; break; - case 162: /* tagitem ::= NOW */ -{ yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&yylhsminor.yy191, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type);} - yymsp[0].minor.yy191 = yylhsminor.yy191; + case 155: /* tagitem ::= NOW */ +{ yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&yylhsminor.yy43, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type);} + yymsp[0].minor.yy43 = yylhsminor.yy43; break; - case 163: /* tagitem ::= MINUS INTEGER */ - case 164: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==164); - case 165: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==165); - case 166: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==166); + case 156: /* tagitem ::= MINUS INTEGER */ + case 157: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==157); + case 158: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==158); + case 159: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==159); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - taosVariantCreate(&yylhsminor.yy191, yymsp[-1].minor.yy0.z, yymsp[-1].minor.yy0.n, yymsp[-1].minor.yy0.type); + taosVariantCreate(&yylhsminor.yy43, yymsp[-1].minor.yy0.z, yymsp[-1].minor.yy0.n, yymsp[-1].minor.yy0.type); } - yymsp[-1].minor.yy191 = yylhsminor.yy191; + yymsp[-1].minor.yy43 = yylhsminor.yy43; break; - case 167: /* 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 160: /* 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.yy488 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy135, yymsp[-11].minor.yy460, yymsp[-10].minor.yy526, yymsp[-4].minor.yy135, yymsp[-2].minor.yy135, &yymsp[-9].minor.yy160, &yymsp[-7].minor.yy511, &yymsp[-6].minor.yy258, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy135, &yymsp[0].minor.yy247, &yymsp[-1].minor.yy247, yymsp[-3].minor.yy526); + yylhsminor.yy256 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy131, yymsp[-11].minor.yy544, yymsp[-10].minor.yy46, yymsp[-4].minor.yy131, yymsp[-2].minor.yy131, &yymsp[-9].minor.yy530, &yymsp[-7].minor.yy39, &yymsp[-6].minor.yy538, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy131, &yymsp[0].minor.yy55, &yymsp[-1].minor.yy55, yymsp[-3].minor.yy46); } - yymsp[-13].minor.yy488 = yylhsminor.yy488; + yymsp[-13].minor.yy256 = yylhsminor.yy256; break; - case 168: /* select ::= LP select RP */ -{yymsp[-2].minor.yy488 = yymsp[-1].minor.yy488;} + case 161: /* select ::= LP select RP */ +{yymsp[-2].minor.yy256 = yymsp[-1].minor.yy256;} break; - case 169: /* union ::= select */ -{ yylhsminor.yy551 = setSubclause(NULL, yymsp[0].minor.yy488); } - yymsp[0].minor.yy551 = yylhsminor.yy551; + case 162: /* union ::= select */ +{ yylhsminor.yy303 = setSubclause(NULL, yymsp[0].minor.yy256); } + yymsp[0].minor.yy303 = yylhsminor.yy303; break; - case 170: /* union ::= union UNION ALL select */ -{ yylhsminor.yy551 = appendSelectClause(yymsp[-3].minor.yy551, SQL_TYPE_UNIONALL, yymsp[0].minor.yy488); } - yymsp[-3].minor.yy551 = yylhsminor.yy551; + case 163: /* union ::= union UNION ALL select */ +{ yylhsminor.yy303 = appendSelectClause(yymsp[-3].minor.yy303, SQL_TYPE_UNIONALL, yymsp[0].minor.yy256); } + yymsp[-3].minor.yy303 = yylhsminor.yy303; break; - case 171: /* union ::= union UNION select */ -{ yylhsminor.yy551 = appendSelectClause(yymsp[-2].minor.yy551, SQL_TYPE_UNION, yymsp[0].minor.yy488); } - yymsp[-2].minor.yy551 = yylhsminor.yy551; + case 164: /* union ::= union UNION select */ +{ yylhsminor.yy303 = appendSelectClause(yymsp[-2].minor.yy303, SQL_TYPE_UNION, yymsp[0].minor.yy256); } + yymsp[-2].minor.yy303 = yylhsminor.yy303; break; - case 172: /* cmd ::= union */ -{ setSqlInfo(pInfo, yymsp[0].minor.yy551, NULL, TSDB_SQL_SELECT); } + case 165: /* cmd ::= union */ +{ setSqlInfo(pInfo, yymsp[0].minor.yy303, NULL, TSDB_SQL_SELECT); } break; - case 173: /* select ::= SELECT selcollist */ + case 166: /* select ::= SELECT selcollist */ { - yylhsminor.yy488 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy135, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy256 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy131, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - yymsp[-1].minor.yy488 = yylhsminor.yy488; + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; - case 174: /* sclp ::= selcollist COMMA */ -{yylhsminor.yy135 = yymsp[-1].minor.yy135;} - yymsp[-1].minor.yy135 = yylhsminor.yy135; + case 167: /* sclp ::= selcollist COMMA */ +{yylhsminor.yy131 = yymsp[-1].minor.yy131;} + yymsp[-1].minor.yy131 = yylhsminor.yy131; break; - case 175: /* sclp ::= */ - case 207: /* orderby_opt ::= */ yytestcase(yyruleno==207); -{yymsp[1].minor.yy135 = 0;} + case 168: /* sclp ::= */ + case 200: /* orderby_opt ::= */ yytestcase(yyruleno==200); +{yymsp[1].minor.yy131 = 0;} break; - case 176: /* selcollist ::= sclp distinct expr as */ + case 169: /* selcollist ::= sclp distinct expr as */ { - yylhsminor.yy135 = tSqlExprListAppend(yymsp[-3].minor.yy135, yymsp[-1].minor.yy526, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy131 = tSqlExprListAppend(yymsp[-3].minor.yy131, yymsp[-1].minor.yy46, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } - yymsp[-3].minor.yy135 = yylhsminor.yy135; + yymsp[-3].minor.yy131 = yylhsminor.yy131; break; - case 177: /* selcollist ::= sclp STAR */ + case 170: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); - yylhsminor.yy135 = tSqlExprListAppend(yymsp[-1].minor.yy135, pNode, 0, 0); + yylhsminor.yy131 = tSqlExprListAppend(yymsp[-1].minor.yy131, pNode, 0, 0); } - yymsp[-1].minor.yy135 = yylhsminor.yy135; + yymsp[-1].minor.yy131 = yylhsminor.yy131; break; - case 178: /* as ::= AS ids */ + case 171: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 179: /* as ::= ids */ + case 172: /* as ::= ids */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 180: /* as ::= */ + case 173: /* as ::= */ { yymsp[1].minor.yy0.n = 0; } break; - case 181: /* distinct ::= DISTINCT */ + case 174: /* distinct ::= DISTINCT */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 183: /* from ::= FROM tablelist */ - case 184: /* from ::= FROM sub */ yytestcase(yyruleno==184); -{yymsp[-1].minor.yy460 = yymsp[0].minor.yy460;} + case 176: /* from ::= FROM tablelist */ + case 177: /* from ::= FROM sub */ yytestcase(yyruleno==177); +{yymsp[-1].minor.yy544 = yymsp[0].minor.yy544;} break; - case 185: /* sub ::= LP union RP */ -{yymsp[-2].minor.yy460 = addSubquery(NULL, yymsp[-1].minor.yy551, NULL);} + case 178: /* sub ::= LP union RP */ +{yymsp[-2].minor.yy544 = addSubquery(NULL, yymsp[-1].minor.yy303, NULL);} break; - case 186: /* sub ::= LP union RP ids */ -{yymsp[-3].minor.yy460 = addSubquery(NULL, yymsp[-2].minor.yy551, &yymsp[0].minor.yy0);} + case 179: /* sub ::= LP union RP ids */ +{yymsp[-3].minor.yy544 = addSubquery(NULL, yymsp[-2].minor.yy303, &yymsp[0].minor.yy0);} break; - case 187: /* sub ::= sub COMMA LP union RP ids */ -{yylhsminor.yy460 = addSubquery(yymsp[-5].minor.yy460, yymsp[-2].minor.yy551, &yymsp[0].minor.yy0);} - yymsp[-5].minor.yy460 = yylhsminor.yy460; + case 180: /* sub ::= sub COMMA LP union RP ids */ +{yylhsminor.yy544 = addSubquery(yymsp[-5].minor.yy544, yymsp[-2].minor.yy303, &yymsp[0].minor.yy0);} + yymsp[-5].minor.yy544 = yylhsminor.yy544; break; - case 188: /* tablelist ::= ids cpxName */ + case 181: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy460 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy544 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } - yymsp[-1].minor.yy460 = yylhsminor.yy460; + yymsp[-1].minor.yy544 = yylhsminor.yy544; break; - case 189: /* tablelist ::= ids cpxName ids */ + case 182: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy460 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy544 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy460 = yylhsminor.yy460; + yymsp[-2].minor.yy544 = yylhsminor.yy544; break; - case 190: /* tablelist ::= tablelist COMMA ids cpxName */ + case 183: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy460 = setTableNameList(yymsp[-3].minor.yy460, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy544 = setTableNameList(yymsp[-3].minor.yy544, &yymsp[-1].minor.yy0, NULL); } - yymsp[-3].minor.yy460 = yylhsminor.yy460; + yymsp[-3].minor.yy544 = yylhsminor.yy544; break; - case 191: /* tablelist ::= tablelist COMMA ids cpxName ids */ + case 184: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy460 = setTableNameList(yymsp[-4].minor.yy460, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy544 = setTableNameList(yymsp[-4].minor.yy544, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-4].minor.yy460 = yylhsminor.yy460; + yymsp[-4].minor.yy544 = yylhsminor.yy544; break; - case 192: /* tmvar ::= VARIABLE */ + case 185: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 193: /* interval_option ::= intervalKey LP tmvar RP */ -{yylhsminor.yy160.interval = yymsp[-1].minor.yy0; yylhsminor.yy160.offset.n = 0; yylhsminor.yy160.token = yymsp[-3].minor.yy262;} - yymsp[-3].minor.yy160 = yylhsminor.yy160; + case 186: /* interval_option ::= intervalKey LP tmvar RP */ +{yylhsminor.yy530.interval = yymsp[-1].minor.yy0; yylhsminor.yy530.offset.n = 0; yylhsminor.yy530.token = yymsp[-3].minor.yy310;} + yymsp[-3].minor.yy530 = yylhsminor.yy530; break; - case 194: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ -{yylhsminor.yy160.interval = yymsp[-3].minor.yy0; yylhsminor.yy160.offset = yymsp[-1].minor.yy0; yylhsminor.yy160.token = yymsp[-5].minor.yy262;} - yymsp[-5].minor.yy160 = yylhsminor.yy160; + case 187: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ +{yylhsminor.yy530.interval = yymsp[-3].minor.yy0; yylhsminor.yy530.offset = yymsp[-1].minor.yy0; yylhsminor.yy530.token = yymsp[-5].minor.yy310;} + yymsp[-5].minor.yy530 = yylhsminor.yy530; break; - case 195: /* interval_option ::= */ -{memset(&yymsp[1].minor.yy160, 0, sizeof(yymsp[1].minor.yy160));} + case 188: /* interval_option ::= */ +{memset(&yymsp[1].minor.yy530, 0, sizeof(yymsp[1].minor.yy530));} break; - case 196: /* intervalKey ::= INTERVAL */ -{yymsp[0].minor.yy262 = TK_INTERVAL;} + case 189: /* intervalKey ::= INTERVAL */ +{yymsp[0].minor.yy310 = TK_INTERVAL;} break; - case 197: /* intervalKey ::= EVERY */ -{yymsp[0].minor.yy262 = TK_EVERY; } + case 190: /* intervalKey ::= EVERY */ +{yymsp[0].minor.yy310 = TK_EVERY; } break; - case 198: /* session_option ::= */ -{yymsp[1].minor.yy511.col.n = 0; yymsp[1].minor.yy511.gap.n = 0;} + case 191: /* session_option ::= */ +{yymsp[1].minor.yy39.col.n = 0; yymsp[1].minor.yy39.gap.n = 0;} break; - case 199: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 192: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - yymsp[-6].minor.yy511.col = yymsp[-4].minor.yy0; - yymsp[-6].minor.yy511.gap = yymsp[-1].minor.yy0; + yymsp[-6].minor.yy39.col = yymsp[-4].minor.yy0; + yymsp[-6].minor.yy39.gap = yymsp[-1].minor.yy0; } break; - case 200: /* windowstate_option ::= */ -{ yymsp[1].minor.yy258.col.n = 0; yymsp[1].minor.yy258.col.z = NULL;} + case 193: /* windowstate_option ::= */ +{ yymsp[1].minor.yy538.col.n = 0; yymsp[1].minor.yy538.col.z = NULL;} break; - case 201: /* windowstate_option ::= STATE_WINDOW LP ids RP */ -{ yymsp[-3].minor.yy258.col = yymsp[-1].minor.yy0; } + case 194: /* windowstate_option ::= STATE_WINDOW LP ids RP */ +{ yymsp[-3].minor.yy538.col = yymsp[-1].minor.yy0; } break; - case 202: /* fill_opt ::= */ -{ yymsp[1].minor.yy135 = 0; } + case 195: /* fill_opt ::= */ +{ yymsp[1].minor.yy131 = 0; } break; - case 203: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 196: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { SVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); taosVariantCreate(&A, yymsp[-3].minor.yy0.z, yymsp[-3].minor.yy0.n, yymsp[-3].minor.yy0.type); - tListItemInsert(yymsp[-1].minor.yy135, &A, -1, 0); - yymsp[-5].minor.yy135 = yymsp[-1].minor.yy135; + tListItemInsert(yymsp[-1].minor.yy131, &A, -1, 0); + yymsp[-5].minor.yy131 = yymsp[-1].minor.yy131; } break; - case 204: /* fill_opt ::= FILL LP ID RP */ + case 197: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yymsp[-3].minor.yy135 = tListItemAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy131 = tListItemAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 205: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 198: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 206: /* sliding_opt ::= */ + case 199: /* sliding_opt ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 208: /* orderby_opt ::= ORDER BY sortlist */ -{yymsp[-2].minor.yy135 = yymsp[0].minor.yy135;} + case 201: /* orderby_opt ::= ORDER BY sortlist */ +{yymsp[-2].minor.yy131 = yymsp[0].minor.yy131;} break; - case 209: /* sortlist ::= sortlist COMMA item sortorder */ + case 202: /* sortlist ::= sortlist COMMA item sortorder */ { - yylhsminor.yy135 = tListItemAppend(yymsp[-3].minor.yy135, &yymsp[-1].minor.yy191, yymsp[0].minor.yy130); + yylhsminor.yy131 = tListItemAppend(yymsp[-3].minor.yy131, &yymsp[-1].minor.yy43, yymsp[0].minor.yy44); } - yymsp[-3].minor.yy135 = yylhsminor.yy135; + yymsp[-3].minor.yy131 = yylhsminor.yy131; break; - case 210: /* sortlist ::= item sortorder */ + case 203: /* sortlist ::= item sortorder */ { - yylhsminor.yy135 = tListItemAppend(NULL, &yymsp[-1].minor.yy191, yymsp[0].minor.yy130); + yylhsminor.yy131 = tListItemAppend(NULL, &yymsp[-1].minor.yy43, yymsp[0].minor.yy44); } - yymsp[-1].minor.yy135 = yylhsminor.yy135; + yymsp[-1].minor.yy131 = yylhsminor.yy131; break; - case 211: /* item ::= ids cpxName */ + case 204: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - taosVariantCreate(&yylhsminor.yy191, yymsp[-1].minor.yy0.z, yymsp[-1].minor.yy0.n, yymsp[-1].minor.yy0.type); + taosVariantCreate(&yylhsminor.yy43, yymsp[-1].minor.yy0.z, yymsp[-1].minor.yy0.n, yymsp[-1].minor.yy0.type); } - yymsp[-1].minor.yy191 = yylhsminor.yy191; + yymsp[-1].minor.yy43 = yylhsminor.yy43; break; - case 212: /* sortorder ::= ASC */ -{ yymsp[0].minor.yy130 = TSDB_ORDER_ASC; } + case 205: /* sortorder ::= ASC */ +{ yymsp[0].minor.yy44 = TSDB_ORDER_ASC; } break; - case 213: /* sortorder ::= DESC */ -{ yymsp[0].minor.yy130 = TSDB_ORDER_DESC;} + case 206: /* sortorder ::= DESC */ +{ yymsp[0].minor.yy44 = TSDB_ORDER_DESC;} break; - case 214: /* sortorder ::= */ -{ yymsp[1].minor.yy130 = TSDB_ORDER_ASC; } + case 207: /* sortorder ::= */ +{ yymsp[1].minor.yy44 = TSDB_ORDER_ASC; } break; - case 215: /* groupby_opt ::= */ -{ yymsp[1].minor.yy135 = 0;} + case 208: /* groupby_opt ::= */ +{ yymsp[1].minor.yy131 = 0;} break; - case 216: /* groupby_opt ::= GROUP BY grouplist */ -{ yymsp[-2].minor.yy135 = yymsp[0].minor.yy135;} + case 209: /* groupby_opt ::= GROUP BY grouplist */ +{ yymsp[-2].minor.yy131 = yymsp[0].minor.yy131;} break; - case 217: /* grouplist ::= grouplist COMMA item */ + case 210: /* grouplist ::= grouplist COMMA item */ { - yylhsminor.yy135 = tListItemAppend(yymsp[-2].minor.yy135, &yymsp[0].minor.yy191, -1); + yylhsminor.yy131 = tListItemAppend(yymsp[-2].minor.yy131, &yymsp[0].minor.yy43, -1); } - yymsp[-2].minor.yy135 = yylhsminor.yy135; + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; - case 218: /* grouplist ::= item */ + case 211: /* grouplist ::= item */ { - yylhsminor.yy135 = tListItemAppend(NULL, &yymsp[0].minor.yy191, -1); + yylhsminor.yy131 = tListItemAppend(NULL, &yymsp[0].minor.yy43, -1); } - yymsp[0].minor.yy135 = yylhsminor.yy135; + yymsp[0].minor.yy131 = yylhsminor.yy131; break; - case 219: /* having_opt ::= */ - case 229: /* where_opt ::= */ yytestcase(yyruleno==229); - case 273: /* expritem ::= */ yytestcase(yyruleno==273); -{yymsp[1].minor.yy526 = 0;} + case 212: /* having_opt ::= */ + case 222: /* where_opt ::= */ yytestcase(yyruleno==222); + case 266: /* expritem ::= */ yytestcase(yyruleno==266); +{yymsp[1].minor.yy46 = 0;} break; - case 220: /* having_opt ::= HAVING expr */ - case 230: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==230); -{yymsp[-1].minor.yy526 = yymsp[0].minor.yy526;} + case 213: /* having_opt ::= HAVING expr */ + case 223: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==223); +{yymsp[-1].minor.yy46 = yymsp[0].minor.yy46;} break; - case 221: /* limit_opt ::= */ - case 225: /* slimit_opt ::= */ yytestcase(yyruleno==225); -{yymsp[1].minor.yy247.limit = -1; yymsp[1].minor.yy247.offset = 0;} + case 214: /* limit_opt ::= */ + case 218: /* slimit_opt ::= */ yytestcase(yyruleno==218); +{yymsp[1].minor.yy55.limit = -1; yymsp[1].minor.yy55.offset = 0;} break; - case 222: /* limit_opt ::= LIMIT signed */ - case 226: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==226); -{yymsp[-1].minor.yy247.limit = yymsp[0].minor.yy531; yymsp[-1].minor.yy247.offset = 0;} + case 215: /* limit_opt ::= LIMIT signed */ + case 219: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==219); +{yymsp[-1].minor.yy55.limit = yymsp[0].minor.yy459; yymsp[-1].minor.yy55.offset = 0;} break; - case 223: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yymsp[-3].minor.yy247.limit = yymsp[-2].minor.yy531; yymsp[-3].minor.yy247.offset = yymsp[0].minor.yy531;} + case 216: /* limit_opt ::= LIMIT signed OFFSET signed */ +{ yymsp[-3].minor.yy55.limit = yymsp[-2].minor.yy459; yymsp[-3].minor.yy55.offset = yymsp[0].minor.yy459;} break; - case 224: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yymsp[-3].minor.yy247.limit = yymsp[0].minor.yy531; yymsp[-3].minor.yy247.offset = yymsp[-2].minor.yy531;} + case 217: /* limit_opt ::= LIMIT signed COMMA signed */ +{ yymsp[-3].minor.yy55.limit = yymsp[0].minor.yy459; yymsp[-3].minor.yy55.offset = yymsp[-2].minor.yy459;} break; - case 227: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yymsp[-3].minor.yy247.limit = yymsp[-2].minor.yy531; yymsp[-3].minor.yy247.offset = yymsp[0].minor.yy531;} + case 220: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ +{yymsp[-3].minor.yy55.limit = yymsp[-2].minor.yy459; yymsp[-3].minor.yy55.offset = yymsp[0].minor.yy459;} break; - case 228: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yymsp[-3].minor.yy247.limit = yymsp[0].minor.yy531; yymsp[-3].minor.yy247.offset = yymsp[-2].minor.yy531;} + case 221: /* slimit_opt ::= SLIMIT signed COMMA signed */ +{yymsp[-3].minor.yy55.limit = yymsp[0].minor.yy459; yymsp[-3].minor.yy55.offset = yymsp[-2].minor.yy459;} break; - case 231: /* expr ::= LP expr RP */ -{yylhsminor.yy526 = yymsp[-1].minor.yy526; yylhsminor.yy526->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy526->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 224: /* expr ::= LP expr RP */ +{yylhsminor.yy46 = yymsp[-1].minor.yy46; yylhsminor.yy46->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy46->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 232: /* expr ::= ID */ -{ yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 225: /* expr ::= ID */ +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 233: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 226: /* expr ::= ID DOT ID */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 234: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 227: /* expr ::= ID DOT STAR */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 235: /* expr ::= INTEGER */ -{ yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 228: /* expr ::= INTEGER */ +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 236: /* expr ::= MINUS INTEGER */ - case 237: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==237); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} - yymsp[-1].minor.yy526 = yylhsminor.yy526; + case 229: /* expr ::= MINUS INTEGER */ + case 230: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==230); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy46 = yylhsminor.yy46; break; - case 238: /* expr ::= FLOAT */ -{ yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 231: /* expr ::= FLOAT */ +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 239: /* expr ::= MINUS FLOAT */ - case 240: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==240); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} - yymsp[-1].minor.yy526 = yylhsminor.yy526; + case 232: /* expr ::= MINUS FLOAT */ + case 233: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==233); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy46 = yylhsminor.yy46; break; - case 241: /* expr ::= STRING */ -{ yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 234: /* expr ::= STRING */ +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 242: /* expr ::= NOW */ -{ yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 235: /* expr ::= NOW */ +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 243: /* expr ::= VARIABLE */ -{ yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 236: /* expr ::= VARIABLE */ +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 244: /* expr ::= PLUS VARIABLE */ - case 245: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==245); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} - yymsp[-1].minor.yy526 = yylhsminor.yy526; + case 237: /* expr ::= PLUS VARIABLE */ + case 238: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==238); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} + yymsp[-1].minor.yy46 = yylhsminor.yy46; break; - case 246: /* expr ::= BOOL */ -{ yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 239: /* expr ::= BOOL */ +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 247: /* expr ::= NULL */ -{ yylhsminor.yy526 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 240: /* expr ::= NULL */ +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 248: /* expr ::= ID LP exprlist RP */ -{ tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy526 = tSqlExprCreateFunction(yymsp[-1].minor.yy135, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy526 = yylhsminor.yy526; + case 241: /* expr ::= ID LP exprlist RP */ +{ tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy46 = tSqlExprCreateFunction(yymsp[-1].minor.yy131, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy46 = yylhsminor.yy46; break; - case 249: /* expr ::= ID LP STAR RP */ -{ tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy526 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy526 = yylhsminor.yy526; + case 242: /* expr ::= ID LP STAR RP */ +{ tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy46 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy46 = yylhsminor.yy46; break; - case 250: /* expr ::= expr IS NULL */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, NULL, TK_ISNULL);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 243: /* expr ::= expr IS NULL */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, NULL, TK_ISNULL);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 251: /* expr ::= expr IS NOT NULL */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-3].minor.yy526, NULL, TK_NOTNULL);} - yymsp[-3].minor.yy526 = yylhsminor.yy526; + case 244: /* expr ::= expr IS NOT NULL */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-3].minor.yy46, NULL, TK_NOTNULL);} + yymsp[-3].minor.yy46 = yylhsminor.yy46; break; - case 252: /* expr ::= expr LT expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_LT);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 245: /* expr ::= expr LT expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LT);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 253: /* expr ::= expr GT expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_GT);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 246: /* expr ::= expr GT expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_GT);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 254: /* expr ::= expr LE expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_LE);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 247: /* expr ::= expr LE expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LE);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 255: /* expr ::= expr GE expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_GE);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 248: /* expr ::= expr GE expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_GE);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 256: /* expr ::= expr NE expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_NE);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 249: /* expr ::= expr NE expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_NE);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 257: /* expr ::= expr EQ expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_EQ);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 250: /* expr ::= expr EQ expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_EQ);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 258: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy526); yylhsminor.yy526 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy526, yymsp[-2].minor.yy526, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy526, TK_LE), TK_AND);} - yymsp[-4].minor.yy526 = yylhsminor.yy526; + case 251: /* expr ::= expr BETWEEN expr AND expr */ +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy46); yylhsminor.yy46 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy46, yymsp[-2].minor.yy46, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy46, TK_LE), TK_AND);} + yymsp[-4].minor.yy46 = yylhsminor.yy46; break; - case 259: /* expr ::= expr AND expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_AND);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 252: /* expr ::= expr AND expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_AND);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 260: /* expr ::= expr OR expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_OR); } - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 253: /* expr ::= expr OR expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_OR); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 261: /* expr ::= expr PLUS expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_PLUS); } - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 254: /* expr ::= expr PLUS expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_PLUS); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 262: /* expr ::= expr MINUS expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_MINUS); } - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 255: /* expr ::= expr MINUS expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_MINUS); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 263: /* expr ::= expr STAR expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_STAR); } - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 256: /* expr ::= expr STAR expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_STAR); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 264: /* expr ::= expr SLASH expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_DIVIDE);} - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 257: /* expr ::= expr SLASH expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_DIVIDE);} + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 265: /* expr ::= expr REM expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_REM); } - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 258: /* expr ::= expr REM expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_REM); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 266: /* expr ::= expr LIKE expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_LIKE); } - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 259: /* expr ::= expr LIKE expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LIKE); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 267: /* expr ::= expr MATCH expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_MATCH); } - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 260: /* expr ::= expr MATCH expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_MATCH); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 268: /* expr ::= expr NMATCH expr */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-2].minor.yy526, yymsp[0].minor.yy526, TK_NMATCH); } - yymsp[-2].minor.yy526 = yylhsminor.yy526; + case 261: /* expr ::= expr NMATCH expr */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_NMATCH); } + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; - case 269: /* expr ::= expr IN LP exprlist RP */ -{yylhsminor.yy526 = tSqlExprCreate(yymsp[-4].minor.yy526, (tSqlExpr*)yymsp[-1].minor.yy135, TK_IN); } - yymsp[-4].minor.yy526 = yylhsminor.yy526; + case 262: /* expr ::= expr IN LP exprlist RP */ +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-4].minor.yy46, (tSqlExpr*)yymsp[-1].minor.yy131, TK_IN); } + yymsp[-4].minor.yy46 = yylhsminor.yy46; break; - case 270: /* exprlist ::= exprlist COMMA expritem */ -{yylhsminor.yy135 = tSqlExprListAppend(yymsp[-2].minor.yy135,yymsp[0].minor.yy526,0, 0);} - yymsp[-2].minor.yy135 = yylhsminor.yy135; + case 263: /* exprlist ::= exprlist COMMA expritem */ +{yylhsminor.yy131 = tSqlExprListAppend(yymsp[-2].minor.yy131,yymsp[0].minor.yy46,0, 0);} + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; - case 271: /* exprlist ::= expritem */ -{yylhsminor.yy135 = tSqlExprListAppend(0,yymsp[0].minor.yy526,0, 0);} - yymsp[0].minor.yy135 = yylhsminor.yy135; + case 264: /* exprlist ::= expritem */ +{yylhsminor.yy131 = tSqlExprListAppend(0,yymsp[0].minor.yy46,0, 0);} + yymsp[0].minor.yy131 = yylhsminor.yy131; break; - case 272: /* expritem ::= expr */ -{yylhsminor.yy526 = yymsp[0].minor.yy526;} - yymsp[0].minor.yy526 = yylhsminor.yy526; + case 265: /* expritem ::= expr */ +{yylhsminor.yy46 = yymsp[0].minor.yy46;} + yymsp[0].minor.yy46 = yylhsminor.yy46; break; - case 274: /* cmd ::= RESET QUERY CACHE */ + case 267: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 275: /* cmd ::= SYNCDB ids REPLICA */ + case 268: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 276: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 269: /* 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.yy135, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 277: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 270: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; toTSDBType(yymsp[0].minor.yy0.type); @@ -3177,21 +3140,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 278: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + case 271: /* 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.yy135, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 279: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 272: /* 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.yy135, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 280: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 273: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3202,7 +3165,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 281: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 274: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3216,33 +3179,33 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 282: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 275: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tListItemAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tListItemAppend(A, &yymsp[0].minor.yy191, -1); + A = tListItemAppend(A, &yymsp[0].minor.yy43, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 283: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + case 276: /* 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.yy135, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 284: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 277: /* 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.yy135, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 285: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 278: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3253,21 +3216,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 286: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + case 279: /* 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.yy135, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 287: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 280: /* 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.yy135, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 288: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 281: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3278,7 +3241,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 289: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 282: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3292,32 +3255,32 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 290: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + case 283: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tListItemAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tListItemAppend(A, &yymsp[0].minor.yy191, -1); + A = tListItemAppend(A, &yymsp[0].minor.yy43, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 291: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + case 284: /* 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.yy135, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 292: /* cmd ::= KILL CONNECTION INTEGER */ + case 285: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 293: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 286: /* 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 294: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 287: /* 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/parser/src/ttokenizer.c b/source/libs/parser/src/ttokenizer.c index d69fa2b95b0feb6fdd8e57f54d34331070baca90..4e6b77a3d653088f091b8711b6e5843b59fe7ce7 100644 --- a/source/libs/parser/src/ttokenizer.c +++ b/source/libs/parser/src/ttokenizer.c @@ -217,7 +217,7 @@ static SKeyword keywordTable[] = { {"UNION", TK_UNION}, {"CACHELAST", TK_CACHELAST}, {"DISTINCT", TK_DISTINCT}, - {"PARTITIONS", TK_PARTITIONS}, +// {"PARTITIONS", TK_PARTITIONS}, {"TOPIC", TK_TOPIC}, {"TOPICS", TK_TOPICS}, {"COMPACT", TK_COMPACT}, diff --git a/source/libs/parser/test/insertParserTest.cpp b/source/libs/parser/test/insertParserTest.cpp index 433d189a453053c84bb11672e4f9586d30c02566..9e681c7ccb8b8d5412892c3b41413c0f455cf69b 100644 --- a/source/libs/parser/test/insertParserTest.cpp +++ b/source/libs/parser/test/insertParserTest.cpp @@ -43,8 +43,8 @@ protected: void bind(const char* sql) { reset(); - cxt_.pAcctId = acctId_.c_str(); - cxt_.pDbname = db_.c_str(); + cxt_.ctx.acctId = atoi(acctId_.c_str()); + cxt_.ctx.db = (char*) db_.c_str(); strcpy(sqlBuf_, sql); cxt_.sqlLen = strlen(sql); sqlBuf_[cxt_.sqlLen] = '\0'; @@ -69,7 +69,7 @@ protected: cout << "schemaAttache:" << (int32_t)res_->schemaAttache << ", payloadType:" << (int32_t)res_->payloadType << ", insertType:" << res_->insertType << ", numOfVgs:" << num << endl; for (size_t i = 0; i < num; ++i) { SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(res_->pDataBlocks, i); - cout << "vgId:" << vg->vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl; + cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl; SMsgDesc* desc = (SMsgDesc*)(vg->pData); cout << "numOfVnodes:" << ntohl(desc->numOfVnodes) << endl; SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index fdcb6e0433b89a84f05646690d506387765a9d9d..d7f410a01eadc3cc7151a660b09dc3ee33d45884 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -23,30 +23,34 @@ namespace { void generateTestT1(MockCatalogService* mcs) { - ITableBuilder& builder = mcs->createTableBuilder("root.test", "t1", TSDB_NORMAL_TABLE, 3) + ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 3) .setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) .addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20); builder.done(); } void generateTestST1(MockCatalogService* mcs) { - ITableBuilder& builder = mcs->createTableBuilder("root.test", "st1", TSDB_SUPER_TABLE, 3, 2) + ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2) .setPrecision(TSDB_TIME_PRECISION_MILLI).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) .addTag("tag1", TSDB_DATA_TYPE_INT).addTag("tag2", TSDB_DATA_TYPE_BINARY, 20) .addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20); builder.done(); - mcs->createSubTable("root.test", "st1", "st1s1", 1); - mcs->createSubTable("root.test", "st1", "st1s2", 2); + mcs->createSubTable("test", "st1", "st1s1", 1); + mcs->createSubTable("test", "st1", "st1s2", 2); } } int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) { - return mockCatalogService->catalogGetHandle(clusterId, catalogHandle); + return 0; } int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) { - return mockCatalogService->catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, pTableMeta); + return mockCatalogService->catalogGetTableMeta(pDBName, pTableName, pTableMeta); +} + +int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo) { + return mockCatalogService->catalogGetTableHashVgroup(pDBName, pTableName, vgInfo); } void initMetaDataEnv() { @@ -55,6 +59,7 @@ void initMetaDataEnv() { static Stub stub; stub.set(catalogGetHandle, __catalogGetHandle); stub.set(catalogGetTableMeta, __catalogGetTableMeta); + stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup); { AddrAny any("libcatalog.so"); std::map result; @@ -71,6 +76,14 @@ void initMetaDataEnv() { stub.set(f.second, __catalogGetTableMeta); } } + { + AddrAny any("libcatalog.so"); + std::map result; + any.get_global_func_addr_dynsym("^catalogGetTableHashVgroup$", result); + for (const auto& f : result) { + stub.set(f.second, __catalogGetTableHashVgroup); + } + } } void generateMetaData() { diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index ad366e8f744ccb81bab33fc8f02cf426ee1eff4b..520ef3a89bd25a10e8e125ac54bcd3c2e2e4a4ea 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -90,13 +90,13 @@ public: MockCatalogServiceImpl() : id_(1) { } - int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) const { + int32_t catalogGetHandle() const { return 0; } - int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) const { + int32_t catalogGetTableMeta(const char* pDbFullName, const char* pTableName, STableMeta** pTableMeta) const { std::unique_ptr table; - int32_t code = copyTableSchemaMeta(pDBName, pTableName, &table); + int32_t code = copyTableSchemaMeta(toDbname(pDbFullName), pTableName, &table); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -104,6 +104,11 @@ public: return TSDB_CODE_SUCCESS; } + int32_t catalogGetTableHashVgroup(const char* pDbFullName, const char* pTableName, SVgroupInfo* vgInfo) const { + // todo + return 0; + } + TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { builder_ = TableBuilder::createTableBuilder(tableType, numOfColumns, numOfTags); meta_[db][tbname] = builder_->table(); @@ -190,6 +195,14 @@ private: typedef std::map> TableMetaCache; typedef std::map DbMetaCache; + std::string toDbname(const std::string& dbFullName) const { + std::string::size_type n = dbFullName.find("."); + if (n == std::string::npos) { + return dbFullName; + } + return dbFullName.substr(n + 1); + } + std::string ttToString(int8_t tableType) const { switch (tableType) { case TSDB_SUPER_TABLE: @@ -270,10 +283,10 @@ std::shared_ptr MockCatalogService::getTableMeta(const std::strin return impl_->getTableMeta(db, tbname); } -int32_t MockCatalogService::catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) const { - return impl_->catalogGetHandle(clusterId, catalogHandle); +int32_t MockCatalogService::catalogGetTableMeta(const char* pDBName, const char* pTableName, STableMeta** pTableMeta) const { + return impl_->catalogGetTableMeta(pDBName, pTableName, pTableMeta); } -int32_t MockCatalogService::catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) const { - return impl_->catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, pTableMeta); -} +int32_t MockCatalogService::catalogGetTableHashVgroup(const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo) const { + return impl_->catalogGetTableHashVgroup(pDBName, pTableName, vgInfo); +} \ No newline at end of file diff --git a/source/libs/parser/test/mockCatalogService.h b/source/libs/parser/test/mockCatalogService.h index cd01db09cce7ff4c5949671ff44af041a47d80cb..889a45439715792d09a33d4c9073b4175a275dca 100644 --- a/source/libs/parser/test/mockCatalogService.h +++ b/source/libs/parser/test/mockCatalogService.h @@ -57,9 +57,8 @@ public: void showTables() const; std::shared_ptr getTableMeta(const std::string& db, const std::string& tbname) const; - // mock interface - int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) const; - int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta) const; + int32_t catalogGetTableMeta(const char* pDBName, const char* pTableName, STableMeta** pTableMeta) const; + int32_t catalogGetTableHashVgroup(const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo) const; private: std::unique_ptr impl_; diff --git a/source/libs/parser/test/parserTests.cpp b/source/libs/parser/test/parserTests.cpp index 396e8a12fe584cdd2a4af47279c1ac01b4ba5f98..f2cb4864fba79e06e16b454ea8e0f9f695e828b0 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); - void* output = NULL; - int32_t type = 0; - int32_t len = 0; - int32_t code = qParserValidateDclSqlNode(&info1, 1, &output, &len, &type, msg, buf.len); + SDclStmtInfo output; + SParseBasicCtx ct= {.db= "abc", .acctId = 1, .requestId = 1}; + int32_t code = qParserValidateDclSqlNode(&info1, &ct, &output, msg, buf.len); ASSERT_EQ(code, 0); // convert the show command to be the select query @@ -734,13 +733,11 @@ TEST(testCase, create_user_Test) { SSqlInfo info1 = doGenerateAST(sql); ASSERT_EQ(info1.valid, true); - ASSERT_EQ(isDclSqlStatement(&info1), true); - void* output = NULL; - int32_t type = 0; - int32_t len = 0; - int32_t code = qParserValidateDclSqlNode(&info1, 1, &output, &len, &type, msg, buf.len); + SDclStmtInfo output; + SParseBasicCtx ct= {.db= "abc", .acctId = 1, .requestId = 1}; + int32_t code = qParserValidateDclSqlNode(&info1, &ct, &output, msg, buf.len); ASSERT_EQ(code, 0); destroySqlInfo(&info1); diff --git a/source/libs/parser/test/plannerTest.cpp b/source/libs/parser/test/plannerTest.cpp index a2078defdaf1acbe5b9e0824f08a934371345d6c..f9b172210627cede4727f8e1a3eeaa2eb9ee3ae1 100644 --- a/source/libs/parser/test/plannerTest.cpp +++ b/source/libs/parser/test/plannerTest.cpp @@ -93,7 +93,7 @@ void generateLogicplan(const char* sql) { ASSERT_EQ(ret, 0); struct SQueryPlanNode* n = nullptr; - code = createQueryPlan(pQueryInfo, &n); + code = createQueryPlan((const SQueryNode*)pQueryInfo, &n); char* str = NULL; queryPlanToString(n, &str); @@ -156,7 +156,7 @@ TEST(testCase, planner_test) { ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 2); struct SQueryPlanNode* n = nullptr; - code = createQueryPlan(pQueryInfo, &n); + code = createQueryPlan((const SQueryNode*)pQueryInfo, &n); char* str = NULL; queryPlanToString(n, &str); diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index b1c4643f154f56be96a096d09161e1f0aa74540a..ed29839905d47f2e40753123b3c50bd8464d9f84 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -40,6 +40,7 @@ extern "C" { #define QNODE_SESSIONWINDOW 12 #define QNODE_STATEWINDOW 13 #define QNODE_FILL 14 +#define QNODE_INSERT 15 typedef struct SQueryDistPlanNodeInfo { bool stableQuery; // super table query or not @@ -82,7 +83,7 @@ int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode); * @param pQueryNode * @return */ -int32_t createQueryPlan(const struct SQueryStmtInfo* pQueryInfo, struct SQueryPlanNode** pQueryNode); +int32_t createQueryPlan(const SQueryNode* pNode, struct SQueryPlanNode** pQueryPlan); /** * Convert the query plan to string, in order to display it in the shell. @@ -101,7 +102,7 @@ int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql); int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag); int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep); -int32_t subPlanToString(const SSubplan *pPhyNode, char** str); +int32_t subPlanToString(const SSubplan *pPhyNode, char** str, int32_t* len); int32_t stringToSubplan(const char* str, SSubplan** subplan); /** @@ -120,6 +121,9 @@ void* destroyQueryPhyPlan(struct SPhyNode* pQueryPhyNode); const char* opTypeToOpName(int32_t type); int32_t opNameToOpType(const char* name); +const char* dsinkTypeToDsinkName(int32_t type); +int32_t dsinkNameToDsinkType(const char* name); + #ifdef __cplusplus } #endif diff --git a/source/libs/planner/src/logicPlan.c b/source/libs/planner/src/logicPlan.c index ce923314bd9530b6425fff926cb3b9662f57b813..136073aa6030945962b6740bfd3f74d55b30fc78 100644 --- a/source/libs/planner/src/logicPlan.c +++ b/source/libs/planner/src/logicPlan.c @@ -29,7 +29,7 @@ typedef struct SJoinCond { SColumn *colCond[2]; } SJoinCond; -static SArray* createQueryPlanImpl(SQueryStmtInfo* pQueryInfo); +static SArray* createQueryPlanImpl(const SQueryStmtInfo* pQueryInfo); static void doDestroyQueryNode(SQueryPlanNode* pQueryNode); int32_t printExprInfo(char* buf, const SQueryPlanNode* pQueryNode, int32_t len); @@ -37,13 +37,37 @@ int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode) { return 0; } -int32_t createQueryPlan(const struct SQueryStmtInfo* pQueryInfo, struct SQueryPlanNode** pQueryNode) { - SArray* upstream = createQueryPlanImpl((struct SQueryStmtInfo*) pQueryInfo); +int32_t createInsertPlan(const SInsertStmtInfo* pInsert, SQueryPlanNode** pQueryPlan) { + *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; + taosArrayAddAll(blocks, pInsert->pDataBlocks); + (*pQueryPlan)->pExtInfo = blocks; + return TSDB_CODE_SUCCESS; +} + +int32_t createSelectPlan(const SQueryStmtInfo* pSelect, SQueryPlanNode** pQueryPlan) { + SArray* upstream = createQueryPlanImpl(pSelect); assert(taosArrayGetSize(upstream) == 1); + *pQueryPlan = taosArrayGetP(upstream, 0); + taosArrayDestroy(upstream); + return TSDB_CODE_SUCCESS; +} - *pQueryNode = taosArrayGetP(upstream, 0); +int32_t createQueryPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { + switch (nodeType(pNode)) { + case TSDB_SQL_SELECT: { + return createSelectPlan((const SQueryStmtInfo*)pNode, pQueryPlan); + } + case TSDB_SQL_INSERT: + return createInsertPlan((const SInsertStmtInfo*)pNode, pQueryPlan); + default: + return TSDB_CODE_FAILED; + } - taosArrayDestroy(upstream); return TSDB_CODE_SUCCESS; } @@ -62,7 +86,7 @@ void destroyQueryPlan(SQueryPlanNode* pQueryNode) { //====================================================================================================================== static SQueryPlanNode* createQueryNode(int32_t type, const char* name, SQueryPlanNode** prev, int32_t numOfPrev, - SExprInfo** pExpr, int32_t numOfOutput, void* pExtInfo) { + SExprInfo** pExpr, int32_t numOfOutput, const void* pExtInfo) { SQueryPlanNode* pNode = calloc(1, sizeof(SQueryPlanNode)); pNode->info.type = type; @@ -123,7 +147,7 @@ static SQueryPlanNode* createQueryNode(int32_t type, const char* name, SQueryPla } case QNODE_FILL: { // todo !! - pNode->pExtInfo = pExtInfo; + pNode->pExtInfo = (void*)pExtInfo; break; } @@ -145,7 +169,7 @@ static SQueryPlanNode* createQueryNode(int32_t type, const char* name, SQueryPla return pNode; } -static SQueryPlanNode* doAddTableColumnNode(SQueryStmtInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SQueryTableInfo* info, +static SQueryPlanNode* doAddTableColumnNode(const SQueryStmtInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SQueryTableInfo* info, SArray* pExprs, SArray* tableCols) { if (pQueryInfo->info.onlyTagQuery) { int32_t num = (int32_t) taosArrayGetSize(pExprs); @@ -186,7 +210,7 @@ static SQueryPlanNode* doAddTableColumnNode(SQueryStmtInfo* pQueryInfo, STableMe return pNode; } -static SQueryPlanNode* doCreateQueryPlanForSingleTableImpl(SQueryStmtInfo* pQueryInfo, SQueryPlanNode* pNode, SQueryTableInfo* info) { +static SQueryPlanNode* doCreateQueryPlanForSingleTableImpl(const SQueryStmtInfo* pQueryInfo, SQueryPlanNode* pNode, SQueryTableInfo* info) { // group by column not by tag size_t numOfGroupCols = taosArrayGetSize(pQueryInfo->groupbyExpr.columnInfo); @@ -239,7 +263,7 @@ static SQueryPlanNode* doCreateQueryPlanForSingleTableImpl(SQueryStmtInfo* pQuer memcpy(pInfo->val, pQueryInfo->fillVal, pNode->numOfExpr); SArray* p = pQueryInfo->exprList[0]; // top expression in select clause - pNode = createQueryNode(QNODE_FILL, "Fill", &pNode, 1, p, taosArrayGetSize(p), pInfo); + pNode = createQueryNode(QNODE_FILL, "Fill", &pNode, 1, p->pData, taosArrayGetSize(p), pInfo); } if (pQueryInfo->order != NULL) { @@ -254,7 +278,7 @@ static SQueryPlanNode* doCreateQueryPlanForSingleTableImpl(SQueryStmtInfo* pQuer return pNode; } -static SQueryPlanNode* doCreateQueryPlanForSingleTable(SQueryStmtInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SArray* pExprs, +static SQueryPlanNode* doCreateQueryPlanForSingleTable(const SQueryStmtInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SArray* pExprs, SArray* tableCols) { char name[TSDB_TABLE_FNAME_LEN] = {0}; tstrncpy(name, pTableMetaInfo->name.tname, TSDB_TABLE_FNAME_LEN); @@ -286,7 +310,7 @@ static bool isAllAggExpr(SArray* pList) { return true; } -SArray* createQueryPlanImpl(SQueryStmtInfo* pQueryInfo) { +SArray* createQueryPlanImpl(const SQueryStmtInfo* pQueryInfo) { SArray* upstream = NULL; if (pQueryInfo->pUpstream != NULL && taosArrayGetSize(pQueryInfo->pUpstream) > 0) { // subquery in the from clause diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 0696a5b24e82b771d897257d1de008853b93dc08..8388458b4c0ea0d04d505aac5f765d890a485d88 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -14,6 +14,7 @@ */ #include "plannerInt.h" +#include "exception.h" #include "parser.h" #define STORE_CURRENT_SUBPLAN(cxt) SSubplan* _ = cxt->pCurrentSubplan @@ -33,19 +34,67 @@ static const char* gOpName[] = { #undef INCLUDE_AS_NAME }; +static void* vailidPointer(void* p) { + if (NULL == p) { + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); + } + return p; +} + const char* opTypeToOpName(int32_t type) { return gOpName[type]; } int32_t opNameToOpType(const char* name) { for (int32_t i = 1; i < sizeof(gOpName) / sizeof(gOpName[0]); ++i) { - if (strcmp(name, gOpName[i])) { + if (0 == strcmp(name, gOpName[i])) { return i; } } return OP_Unknown; } +const char* dsinkTypeToDsinkName(int32_t type) { + switch (type) { + case DSINK_Dispatch: + return "Dispatch"; + case DSINK_Insert: + return "Insert"; + default: + break; + } + return "Unknown"; +} + +int32_t dsinkNameToDsinkType(const char* name) { + if (0 == strcmp(name, "Dispatch")) { + return DSINK_Dispatch; + } else if (0 == strcmp(name, "Insert")) { + return DSINK_Insert; + } + return DSINK_Unknown; +} + +static SDataSink* initDataSink(int32_t type, int32_t size) { + SDataSink* sink = (SDataSink*)vailidPointer(calloc(1, size)); + sink->info.type = type; + sink->info.name = dsinkTypeToDsinkName(type); + return sink; +} + +static SDataSink* createDataDispatcher(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { + SDataDispatcher* dispatcher = (SDataDispatcher*)initDataSink(DSINK_Dispatch, sizeof(SDataDispatcher)); + return (SDataSink*)dispatcher; +} + +static SDataSink* createDataInserter(SPlanContext* pCxt, SVgDataBlocks* pBlocks) { + SDataInserter* inserter = (SDataInserter*)initDataSink(DSINK_Insert, sizeof(SDataInserter)); + inserter->numOfTables = pBlocks->numOfTables; + inserter->size = pBlocks->size; + SWAP(inserter->pData, pBlocks->pData, char*); + return (SDataSink*)inserter; +} + static bool toDataBlockSchema(SQueryPlanNode* pPlanNode, SDataBlockSchema* dataBlockSchema) { dataBlockSchema->numOfCols = pPlanNode->numOfCols; dataBlockSchema->pSchema = malloc(sizeof(SSlotSchema) * pPlanNode->numOfCols); @@ -72,10 +121,7 @@ static bool cloneExprArray(SArray** dst, SArray* src) { } static SPhyNode* initPhyNode(SQueryPlanNode* pPlanNode, int32_t type, int32_t size) { - SPhyNode* node = (SPhyNode*)calloc(1, size); - if (NULL == node) { - return NULL; - } + SPhyNode* node = (SPhyNode*)vailidPointer(calloc(1, size)); node->info.type = type; node->info.name = opTypeToOpName(type); if (!cloneExprArray(&node->pTargets, pPlanNode->pExpr) || !toDataBlockSchema(pPlanNode, &(node->targetSchema))) { @@ -138,7 +184,7 @@ static SPhyNode* createMultiTableScanNode(SQueryPlanNode* pPlanNode, SQueryTable } static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { - SSubplan* subplan = calloc(1, sizeof(SSubplan)); + SSubplan* subplan = vailidPointer(calloc(1, sizeof(SSubplan))); subplan->id = pCxt->nextId; ++(pCxt->nextId.subplanId); subplan->type = type; @@ -146,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 = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); + pCxt->pCurrentSubplan->pChildern = vailidPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); } taosArrayPush(pCxt->pCurrentSubplan->pChildern, &subplan); - subplan->pParents = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); + subplan->pParents = vailidPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); taosArrayPush(subplan->pParents, &pCxt->pCurrentSubplan); } SArray* currentLevel; if (subplan->level >= taosArrayGetSize(pCxt->pDag->pSubplans)) { - currentLevel = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); + currentLevel = vailidPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); taosArrayPush(pCxt->pDag->pSubplans, ¤tLevel); } else { currentLevel = taosArrayGetP(pCxt->pDag->pSubplans, subplan->level); @@ -164,7 +210,17 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { return subplan; } -static void vgroupToEpSet(const SVgroupMsg* vg, SEpSet* epSet) { +static void vgroupInfoToEpSet(const SVgroupInfo* vg, SEpSet* epSet) { + epSet->inUse = 0; // todo + epSet->numOfEps = vg->numOfEps; + for (int8_t i = 0; i < vg->numOfEps; ++i) { + epSet->port[i] = vg->epAddr[i].port; + strcpy(epSet->fqdn[i], vg->epAddr[i].fqdn); + } + return; +} + +static void vgroupMsgToEpSet(const SVgroupMsg* vg, SEpSet* epSet) { epSet->inUse = 0; // todo epSet->numOfEps = vg->numOfEps; for (int8_t i = 0; i < vg->numOfEps; ++i) { @@ -179,8 +235,9 @@ static uint64_t splitSubplanByTable(SPlanContext* pCxt, SQueryPlanNode* pPlanNod for (int32_t i = 0; i < pTable->pMeta->vgroupList->numOfVgroups; ++i) { STORE_CURRENT_SUBPLAN(pCxt); SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_SCAN); - vgroupToEpSet(&(pTable->pMeta->vgroupList->vgroups[i]), &subplan->execEpSet); + vgroupMsgToEpSet(&(pTable->pMeta->vgroupList->vgroups[i]), &subplan->execEpSet); subplan->pNode = createMultiTableScanNode(pPlanNode, pTable); + subplan->pDataSink = createDataDispatcher(pCxt, pPlanNode); RECOVERY_CURRENT_SUBPLAN(pCxt); } return pCxt->nextId.templateId++; @@ -214,6 +271,9 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { case QNODE_TABLESCAN: node = createTableScanNode(pCxt, pPlanNode); break; + case QNODE_INSERT: + // Insert is not an operator in a physical plan. + break; default: assert(false); } @@ -229,26 +289,46 @@ 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) { + SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MODIFY); + SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(vgs, i); + vgroupInfoToEpSet(&blocks->vg, &subplan->execEpSet); + subplan->pNode = NULL; + subplan->pDataSink = createDataInserter(pCxt, blocks); + } +} + static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { - SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); - ++(pCxt->nextId.templateId); - subplan->pNode = createPhyNode(pCxt, pRoot); + if (QNODE_INSERT == pRoot->info.type) { + splitInsertSubplan(pCxt, pRoot); + } else { + SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); + ++(pCxt->nextId.templateId); + subplan->pNode = createPhyNode(pCxt, pRoot); + subplan->pDataSink = createDataDispatcher(pCxt, pRoot); + } // todo deal subquery } int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag) { - SPlanContext context = { - .pCatalog = pCatalog, - .pDag = calloc(1, sizeof(SQueryDag)), - .pCurrentSubplan = NULL, - .nextId = {0} // todo queryid - }; - if (NULL == context.pDag) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - context.pDag->pSubplans = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); - createSubplanByLevel(&context, pQueryNode); - *pDag = context.pDag; + TRY(TSDB_MAX_TAG_CONDITIONS) { + SPlanContext context = { + .pCatalog = pCatalog, + .pDag = vailidPointer(calloc(1, sizeof(SQueryDag))), + .pCurrentSubplan = NULL, + .nextId = {0} // todo queryid + }; + *pDag = context.pDag; + context.pDag->pSubplans = vailidPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); + createSubplanByLevel(&context, pQueryNode); + } CATCH(code) { + CLEANUP_EXECUTE(); + terrno = code; + return TSDB_CODE_FAILED; + } END_TRY return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/src/physicalPlanJson.c b/source/libs/planner/src/physicalPlanJson.c index 2510797158978e3ba8fc4f0a6732a2f0a7c40ac6..5a1b2a6da298d03c81e6e3bae15052693d2f27f7 100644 --- a/source/libs/planner/src/physicalPlanJson.c +++ b/source/libs/planner/src/physicalPlanJson.c @@ -651,7 +651,7 @@ static bool specificPhyNodeFromJson(const cJSON* json, void* obj) { static const char* jkPnodeName = "Name"; static const char* jkPnodeTargets = "Targets"; static const char* jkPnodeConditions = "Conditions"; -static const char* jkPnodeSchema = "Schema"; +static const char* jkPnodeSchema = "InputSchema"; static const char* jkPnodeChildren = "Children"; // The 'pParent' field do not need to be serialized. static bool phyNodeToJson(const void* obj, cJSON* jNode) { @@ -695,6 +695,70 @@ static bool phyNodeFromJson(const cJSON* json, void* obj) { return res; } +static const char* jkInserterNumOfTables = "NumOfTables"; +static const char* jkInserterDataSize = "DataSize"; + +static bool inserterToJson(const void* obj, cJSON* json) { + const SDataInserter* inserter = (const SDataInserter*)obj; + bool res = cJSON_AddNumberToObject(json, jkInserterNumOfTables, inserter->numOfTables); + if (res) { + res = cJSON_AddNumberToObject(json, jkInserterDataSize, inserter->size); + } + // todo pData + return res; +} + +static bool inserterFromJson(const cJSON* json, void* obj) { + SDataInserter* inserter = (SDataInserter*)obj; + inserter->numOfTables = getNumber(json, jkInserterNumOfTables); + inserter->size = getNumber(json, jkInserterDataSize); + // todo pData +} + +static bool specificDataSinkToJson(const void* obj, cJSON* json) { + const SDataSink* dsink = (const SDataSink*)obj; + switch (dsink->info.type) { + case DSINK_Dispatch: + return true; + case DSINK_Insert: + return inserterToJson(obj, json); + default: + break; + } + return false; +} + +static bool specificDataSinkFromJson(const cJSON* json, void* obj) { + SDataSink* dsink = (SDataSink*)obj; + switch (dsink->info.type) { + case DSINK_Dispatch: + return true; + case DSINK_Insert: + return inserterFromJson(json, obj); + default: + break; + } + return false; +} + +static const char* jkDataSinkName = "Name"; + +static bool dataSinkToJson(const void* obj, cJSON* json) { + const SDataSink* dsink = (const SDataSink*)obj; + bool res = cJSON_AddStringToObject(json, jkDataSinkName, dsink->info.name); + if (res) { + res = addObject(json, dsink->info.name, specificDataSinkToJson, dsink); + } + return res; +} + +static bool dataSinkFromJson(const cJSON* json, void* obj) { + SDataSink* dsink = (SDataSink*)obj; + dsink->info.name = getString(json, jkDataSinkName); + dsink->info.type = dsinkNameToDsinkType(dsink->info.name); + return fromObject(json, dsink->info.name, specificDataSinkFromJson, dsink, true); +} + static const char* jkIdQueryId = "QueryId"; static const char* jkIdTemplateId = "TemplateId"; static const char* jkIdSubplanId = "SubplanId"; @@ -721,6 +785,7 @@ static bool subplanIdFromJson(const cJSON* json, void* obj) { static const char* jkSubplanId = "Id"; static const char* jkSubplanNode = "Node"; +static const char* jkSubplanDataSink = "DataSink"; static cJSON* subplanToJson(const SSubplan* subplan) { cJSON* jSubplan = cJSON_CreateObject(); @@ -734,6 +799,9 @@ static cJSON* subplanToJson(const SSubplan* subplan) { if (res) { res = addObject(jSubplan, jkSubplanNode, phyNodeToJson, subplan->pNode); } + if (res) { + res = addObject(jSubplan, jkSubplanDataSink, dataSinkToJson, subplan->pDataSink); + } if (!res) { cJSON_Delete(jSubplan); @@ -751,6 +819,9 @@ static SSubplan* subplanFromJson(const cJSON* json) { if (res) { res = fromObjectWithAlloc(json, jkSubplanNode, phyNodeFromJson, (void**)&subplan->pNode, sizeof(SPhyNode), false); } + if (res) { + res = fromObjectWithAlloc(json, jkSubplanDataSink, dataSinkFromJson, (void**)&subplan->pDataSink, sizeof(SDataSink), false); + } if (!res) { qDestroySubplan(subplan); @@ -759,13 +830,22 @@ static SSubplan* subplanFromJson(const cJSON* json) { return subplan; } -int32_t subPlanToString(const SSubplan* subplan, char** str) { +int32_t subPlanToString(const SSubplan* subplan, char** str, int32_t* len) { + if (QUERY_TYPE_MODIFY == subplan->type) { + SDataInserter* insert = (SDataInserter*)(subplan->pDataSink); + *len = insert->size; + *str = insert->pData; + insert->pData == NULL; + return TSDB_CODE_SUCCESS; + } + cJSON* json = subplanToJson(subplan); if (NULL == json) { 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 e9a4591d4afe8b4b0efed0f322c9be6ba5c4ee40..e8523249e4cede000d0e6114409c3893ad3fa55b 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -24,9 +24,9 @@ void qDestroyQueryDag(struct SQueryDag* pDag) { // todo } -int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag) { +int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SEpSet* pEpSet, struct SQueryDag** pDag) { SQueryPlanNode* logicPlan; - int32_t code = createQueryPlan(pQueryInfo, &logicPlan); + int32_t code = createQueryPlan(pNode, &logicPlan); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); return code; @@ -50,8 +50,8 @@ int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr return setSubplanExecutionNode(subplan, templateId, ep); } -int32_t qSubPlanToString(const SSubplan *subplan, char** str) { - return subPlanToString(subplan, str); +int32_t qSubPlanToString(const SSubplan *subplan, char** str, int32_t* len) { + return subPlanToString(subplan, str, len); } int32_t qStringToSubplan(const char* str, SSubplan** subplan) { diff --git a/source/libs/planner/test/phyPlanTests.cpp b/source/libs/planner/test/phyPlanTests.cpp index 3be3337304534efa3d02a068585ec5f1a916ae3c..f14fd50e034f950b4b048fd8d19dabe6b606f1d4 100644 --- a/source/libs/planner/test/phyPlanTests.cpp +++ b/source/libs/planner/test/phyPlanTests.cpp @@ -33,10 +33,6 @@ protected: void pushScan(const string& db, const string& table, int32_t scanOp) { shared_ptr meta = mockCatalogService->getTableMeta(db, table); EXPECT_TRUE(meta); -// typedef struct SQueryPlanNode { -// SArray *pExpr; // the query functions or sql aggregations -// int32_t numOfExpr; // number of result columns, which is also the number of pExprs -// } SQueryPlanNode; unique_ptr scan((SQueryPlanNode*)calloc(1, sizeof(SQueryPlanNode))); scan->info.type = scanOp; scan->numOfCols = meta->schema->tableInfo.numOfColumns; @@ -54,6 +50,21 @@ protected: return code; } + int32_t run(const string& db, const string& sql) { + SParseContext cxt; + buildParseContext(db, sql, &cxt); + SQueryNode* query; + int32_t code = qParseQuerySql(&cxt, &query); + if (TSDB_CODE_SUCCESS != code) { + cout << "error no:" << code << ", msg:" << cxt.pMsg << endl; + return code; + } + SQueryDag* dag = nullptr; + code = qCreateQueryDag(query, nullptr, &dag); + dag_.reset(dag); + return code; + } + void explain() { size_t level = taosArrayGetSize(dag_->pSubplans); for (size_t i = 0; i < level; ++i) { @@ -62,8 +73,10 @@ protected: size_t num = taosArrayGetSize(subplans); for (size_t j = 0; j < num; ++j) { std::cout << "no " << j << ":" << std::endl; + int32_t len = 0; char* str = nullptr; - ASSERT_EQ (TSDB_CODE_SUCCESS, qSubPlanToString((const SSubplan*)taosArrayGetP(subplans, j), &str)); + ASSERT_EQ(TSDB_CODE_SUCCESS, qSubPlanToString((const SSubplan*)taosArrayGetP(subplans, j), &str, &len)); + std::cout << "len:" << len << std::endl; std::cout << str << std::endl; free(str); } @@ -107,6 +120,25 @@ private: return info; } + void buildParseContext(const string& db, const string& sql, SParseContext* pCxt) { + static string _db; + static string _sql; + static const int32_t _msgMaxLen = 4096; + static char _msg[_msgMaxLen]; + + _db = db; + _sql = sql; + memset(_msg, 0, _msgMaxLen); + + pCxt->ctx.acctId = 1; + pCxt->ctx.db = _db.c_str(); + pCxt->ctx.requestId = 1; + pCxt->pSql = _sql.c_str(); + pCxt->sqlLen = _sql.length(); + pCxt->pMsg = _msg; + pCxt->msgLen = _msgMaxLen; + } + shared_ptr meta_; unique_ptr logicPlan_; unique_ptr dag_; @@ -114,7 +146,7 @@ private: // select * from table TEST_F(PhyPlanTest, tableScanTest) { - pushScan("root.test", "t1", QNODE_TABLESCAN); + pushScan("test", "t1", QNODE_TABLESCAN); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); explain(); SQueryDag* dag = reslut(); @@ -123,9 +155,17 @@ TEST_F(PhyPlanTest, tableScanTest) { // select * from supertable TEST_F(PhyPlanTest, superTableScanTest) { - pushScan("root.test", "st1", QNODE_TABLESCAN); + pushScan("test", "st1", QNODE_TABLESCAN); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); explain(); SQueryDag* dag = reslut(); // todo check } + +// insert into t values(...) +TEST_F(PhyPlanTest, insertTest) { + ASSERT_EQ(run("test", "insert into t1 values (now, 1, \"beijing\")"), TSDB_CODE_SUCCESS); + explain(); + SQueryDag* dag = reslut(); + // todo check +} diff --git a/source/libs/qcom/CMakeLists.txt b/source/libs/qcom/CMakeLists.txt index 41cf1826bcd5e99a20093bf33dde102811f31039..8e09f3d97a7637a16d1617d5b675a6470dd2622d 100644 --- a/source/libs/qcom/CMakeLists.txt +++ b/source/libs/qcom/CMakeLists.txt @@ -10,3 +10,5 @@ target_link_libraries( qcom PRIVATE os util transport ) + +ADD_SUBDIRECTORY(test) diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 2a13b708ec537a0eb3d7ff8611c681b8b4e285f9..829f426c9ddf1e2be1d3cab0220188eb1ad0d0c8 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -1,5 +1,8 @@ #include "os.h" #include "taosmsg.h" +#include "query.h" +#include "tglobal.h" +#include "tsched.h" #define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS) #define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS) @@ -75,4 +78,46 @@ bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTag } return true; -} \ No newline at end of file +} + +static void* pTaskQueue = NULL; + +int32_t initTaskQueue() { + double factor = 4.0; + int32_t numOfThreads = MAX((int)(tsNumOfCores * tsNumOfThreadsPerCore / factor), 2); + + int32_t queueSize = tsMaxConnections * 2; + pTaskQueue = taosInitScheduler(queueSize, numOfThreads, "tsc"); + if (NULL == pTaskQueue) { + qError("failed to init task queue"); + return -1; + } + + qDebug("task queue is initialized, numOfThreads: %d", numOfThreads); +} + +int32_t cleanupTaskQueue() { + taosCleanUpScheduler(pTaskQueue); +} + +static void execHelper(struct SSchedMsg* pSchedMsg) { + assert(pSchedMsg != NULL && pSchedMsg->ahandle != NULL); + + __async_exec_fn_t* execFn = (__async_exec_fn_t*) pSchedMsg->ahandle; + int32_t code = execFn(pSchedMsg->thandle); + if (code != 0 && pSchedMsg->msg != NULL) { + *(int32_t*) pSchedMsg->msg = code; + } +} + +int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code) { + assert(execFn != NULL); + + SSchedMsg schedMsg = {0}; + schedMsg.fp = execHelper; + schedMsg.ahandle = execFn; + schedMsg.thandle = execParam; + schedMsg.msg = code; + + taosScheduleTask(pTaskQueue, &schedMsg); +} diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 728c47af1e71e4c8b15d1f2a921c34149f3c098f..eb5527f076f7e5ca59607af66d3582c9d0264dfc 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -263,87 +263,12 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { } -void msgInit() { +void initQueryModuleMsgHandle() { queryBuildMsg[TSDB_MSG_TYPE_TABLE_META] = queryBuildTableMetaReqMsg; queryBuildMsg[TSDB_MSG_TYPE_USE_DB] = queryBuildUseDbMsg; queryProcessMsgRsp[TSDB_MSG_TYPE_TABLE_META] = queryProcessTableMetaRsp; queryProcessMsgRsp[TSDB_MSG_TYPE_USE_DB] = queryProcessUseDBRsp; - -/* - tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg; - tscBuildMsg[TSDB_SQL_INSERT] = tscBuildSubmitMsg; - tscBuildMsg[TSDB_SQL_FETCH] = tscBuildFetchMsg; - - tscBuildMsg[TSDB_SQL_CREATE_DB] = tscBuildCreateDbMsg; - tscBuildMsg[TSDB_SQL_CREATE_USER] = tscBuildUserMsg; - tscBuildMsg[TSDB_SQL_CREATE_FUNCTION] = tscBuildCreateFuncMsg; - - tscBuildMsg[TSDB_SQL_CREATE_ACCT] = tscBuildAcctMsg; - tscBuildMsg[TSDB_SQL_ALTER_ACCT] = tscBuildAcctMsg; - - tscBuildMsg[TSDB_SQL_CREATE_TABLE] = tscBuildCreateTableMsg; - tscBuildMsg[TSDB_SQL_DROP_USER] = tscBuildDropUserAcctMsg; - tscBuildMsg[TSDB_SQL_DROP_ACCT] = tscBuildDropUserAcctMsg; - tscBuildMsg[TSDB_SQL_DROP_DB] = tscBuildDropDbMsg; - tscBuildMsg[TSDB_SQL_DROP_FUNCTION] = tscBuildDropFuncMsg; - tscBuildMsg[TSDB_SQL_SYNC_DB_REPLICA] = tscBuildSyncDbReplicaMsg; - tscBuildMsg[TSDB_SQL_DROP_TABLE] = tscBuildDropTableMsg; - tscBuildMsg[TSDB_SQL_ALTER_USER] = tscBuildUserMsg; - tscBuildMsg[TSDB_SQL_CREATE_DNODE] = tscBuildCreateDnodeMsg; - tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg; - tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg; - tscBuildMsg[TSDB_SQL_ALTER_TABLE] = tscBuildAlterTableMsg; - tscBuildMsg[TSDB_SQL_UPDATE_TAG_VAL] = tscBuildUpdateTagMsg; - tscBuildMsg[TSDB_SQL_ALTER_DB] = tscAlterDbMsg; - tscBuildMsg[TSDB_SQL_COMPACT_VNODE] = tscBuildCompactMsg; - - tscBuildMsg[TSDB_SQL_CONNECT] = tscBuildConnectMsg; - tscBuildMsg[TSDB_SQL_USE_DB] = tscBuildUseDbMsg; - tscBuildMsg[TSDB_SQL_STABLEVGROUP] = tscBuildSTableVgroupMsg; - tscBuildMsg[TSDB_SQL_RETRIEVE_FUNC] = tscBuildRetrieveFuncMsg; - - tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg; - tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg; - tscBuildMsg[TSDB_SQL_RETRIEVE_MNODE] = tscBuildRetrieveFromMgmtMsg; - tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg; - tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg; - tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg; - - tscProcessMsgRsp[TSDB_SQL_SELECT] = tscProcessQueryRsp; - tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromNode; - - tscProcessMsgRsp[TSDB_SQL_DROP_DB] = tscProcessDropDbRsp; - tscProcessMsgRsp[TSDB_SQL_DROP_TABLE] = tscProcessDropTableRsp; - tscProcessMsgRsp[TSDB_SQL_CONNECT] = tscProcessConnectRsp; - tscProcessMsgRsp[TSDB_SQL_USE_DB] = tscProcessUseDbRsp; - tscProcessMsgRsp[TSDB_SQL_META] = tscProcessTableMetaRsp; - tscProcessMsgRsp[TSDB_SQL_STABLEVGROUP] = tscProcessSTableVgroupRsp; - tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiTableMetaRsp; - tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp; - - tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; - tscProcessMsgRsp[TSDB_SQL_RETRIEVE_MNODE] = tscProcessRetrieveRspFromNode; // rsp handled by same function. - tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; - - tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp; - tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessLocalRetrieveRsp; - tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessLocalRetrieveRsp; - tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessLocalRetrieveRsp; - tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessLocalRetrieveRsp; - - tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; - - tscProcessMsgRsp[TSDB_SQL_RETRIEVE_GLOBALMERGE] = tscProcessRetrieveGlobalMergeRsp; - - tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp; - tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp; - tscProcessMsgRsp[TSDB_SQL_COMPACT_VNODE] = tscProcessCompactRsp; - - tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_TABLE] = tscProcessShowCreateRsp; - tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_STABLE] = tscProcessShowCreateRsp; - tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp; -*/ } diff --git a/source/libs/qcom/test/CMakeLists.txt b/source/libs/qcom/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7adec3752aeadefb791b203b66d5c40bb3fcae5b --- /dev/null +++ b/source/libs/qcom/test/CMakeLists.txt @@ -0,0 +1,19 @@ + +MESSAGE(STATUS "build qcom unit test") + +# GoogleTest requires at least C++11 +SET(CMAKE_CXX_STANDARD 11) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + +ADD_EXECUTABLE(queryUtilTest ${SOURCE_LIST}) + +TARGET_INCLUDE_DIRECTORIES( + queryUtilTest + PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/qcom/" + PRIVATE "${CMAKE_SOURCE_DIR}/source/libs/qcom/inc" +) + +TARGET_LINK_LIBRARIES( + queryUtilTest + PUBLIC os util gtest qcom common +) diff --git a/source/libs/qcom/test/queryTest.cpp b/source/libs/qcom/test/queryTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d2aedff8fdee781d1531e3aeea04e523f1a90beb --- /dev/null +++ b/source/libs/qcom/test/queryTest.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "taosmsg.h" +#include "query.h" +#pragma GCC diagnostic ignored "-Wwrite-strings" + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" + +namespace { +typedef struct SParam { + int32_t v; +} SParam; +int32_t testPrint(void* p) { + SParam* param = (SParam*)p; + printf("hello world, %d\n", param->v); + tfree(p); + return 0; +} + +int32_t testPrintError(void* p) { + SParam* param = (SParam*) p; + tfree(p); + + return -1; +} +} // namespace + +class QueryTestEnv : public testing::Environment { + public: + virtual void SetUp() { initTaskQueue(); } + + virtual void TearDown() { cleanupTaskQueue(); } + + QueryTestEnv() {} + virtual ~QueryTestEnv() {} +}; + +int main(int argc, char** argv) { + testing::AddGlobalTestEnvironment(new QueryTestEnv()); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +TEST(testCase, async_task_test) { + SParam* p = (SParam*)calloc(1, sizeof(SParam)); + taosAsyncExec(testPrint, p, NULL); + usleep(5000); +} + +TEST(testCase, many_async_task_test) { + for(int32_t i = 0; i < 50; ++i) { + SParam* p = (SParam*) calloc(1, sizeof(SParam)); + p->v = i; + taosAsyncExec(testPrint, p, NULL); + } + + usleep(10000); +} + +TEST(testCase, error_in_async_test) { + int32_t code = 0; + SParam* p = (SParam*) calloc(1, sizeof(SParam)); + taosAsyncExec(testPrintError, p, &code); + usleep(1000); + printf("Error code:%d after asynchronously exec function\n", code); +} \ No newline at end of file diff --git a/source/libs/qworker/inc/qworkerInt.h b/source/libs/qworker/inc/qworkerInt.h index 1adc09def41234a26d3557916eb40917e6e1b57e..6f454e2f8199404778e076bfb7b183601cf51dee 100644 --- a/source/libs/qworker/inc/qworkerInt.h +++ b/source/libs/qworker/inc/qworkerInt.h @@ -20,6 +20,8 @@ extern "C" { #endif +#include "tlockfree.h" + #define QWORKER_DEFAULT_SCHEDULER_NUMBER 10000 #define QWORKER_DEFAULT_RES_CACHE_NUMBER 10000 #define QWORKER_DEFAULT_SCH_TASK_NUMBER 10000 @@ -30,36 +32,63 @@ enum { QW_READY_RESPONSED, }; -typedef struct SQWorkerTaskStatus { - int8_t status; - int8_t ready; +enum { + QW_TASK_INFO_STATUS = 1, + QW_TASK_INFO_READY, +}; + +enum { + QW_READ = 1, + QW_WRITE, +}; + +typedef struct SQWorkerTaskStatus { + SRWLatch lock; + int32_t code; + int8_t status; + int8_t ready; + bool cancel; + bool drop; } SQWorkerTaskStatus; typedef struct SQWorkerResCache { + SRWLatch lock; void *data; } SQWorkerResCache; -typedef struct SQWorkerSchTaskStatus { +typedef struct SQWorkerSchStatus { int32_t lastAccessTs; // timestamp in second - SHashObj *taskStatus; // key:queryId+taskId, value: SQWorkerTaskStatus -} SQWorkerSchTaskStatus; + SRWLatch tasksLock; + SHashObj *tasksHash; // key:queryId+taskId, value: SQWorkerTaskStatus +} SQWorkerSchStatus; // Qnode/Vnode level task management typedef struct SQWorkerMgmt { SQWorkerCfg cfg; - SHashObj *scheduleHash; //key: schedulerId, value: SQWorkerSchTaskStatus + SRWLatch schLock; + SRWLatch resLock; + SHashObj *schHash; //key: schedulerId, value: SQWorkerSchStatus SHashObj *resHash; //key: queryId+taskId, value: SQWorkerResCache } SQWorkerMgmt; -#define QW_TASK_DONE(status) (status == JOB_TASK_STATUS_SUCCEED || status == JOB_TASK_STATUS_FAILED || status == status == JOB_TASK_STATUS_CANCELLED) +#define QW_GOT_RES_DATA(data) (false) +#define QW_LOW_RES_DATA(data) (false) + +#define QW_TASK_NOT_EXIST(code) (TSDB_CODE_QRY_SCH_NOT_EXIST == (code) || TSDB_CODE_QRY_TASK_NOT_EXIST == (code)) +#define QW_TASK_ALREADY_EXIST(code) (TSDB_CODE_QRY_TASK_ALREADY_EXIST == (code)) +#define QW_TASK_READY_RESP(status) (status == JOB_TASK_STATUS_SUCCEED || status == JOB_TASK_STATUS_FAILED || status == JOB_TASK_STATUS_CANCELLED || status == JOB_TASK_STATUS_PARTIAL_SUCCEED) #define QW_SET_QTID(id, qid, tid) do { *(uint64_t *)(id) = (qid); *(uint64_t *)((char *)(id) + sizeof(qid)) = (tid); } while (0) #define QW_GET_QTID(id, qid, tid) do { (qid) = *(uint64_t *)(id); (tid) = *(uint64_t *)((char *)(id) + sizeof(qid)); } while (0) + #define QW_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) #define QW_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) #define QW_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); terrno = _code; return _code; } } while (0) #define QW_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +#define QW_LOCK(type, _lock) (QW_READ == (type) ? taosRLockLatch(_lock) : taosWLockLatch(_lock)) +#define QW_UNLOCK(type, _lock) (QW_READ == (type) ? taosRUnLockLatch(_lock) : taosWUnLockLatch(_lock)) + #ifdef __cplusplus } diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 82bfd75b6a1d2ffb22a4c11b6f286b185d6a643a..628077a0208f8ce3c8d7e6df74254f6b1c130e90 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -4,69 +4,79 @@ #include "qworkerInt.h" #include "planner.h" -int32_t qwAddTaskStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, int8_t taskStatus) { - SQWorkerTaskStatus tStatus = {0}; - tStatus.status = taskStatus; - - char id[sizeof(queryId) + sizeof(taskId)] = {0}; - QW_SET_QTID(id, queryId, taskId); +int32_t qwCheckStatusSwitch(int8_t oriStatus, int8_t newStatus) { + int32_t code = 0; - SQWorkerSchTaskStatus *schStatus = taosHashGet(mgmt->scheduleHash, &schedulerId, sizeof(schedulerId)); - if (NULL == schStatus) { - SQWorkerSchTaskStatus newSchStatus = {0}; - newSchStatus.taskStatus = taosHashInit(mgmt->cfg.maxSchTaskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); - if (NULL == newSchStatus.taskStatus) { - qError("taosHashInit %d failed", mgmt->cfg.maxSchTaskNum); - return TSDB_CODE_QRY_OUT_OF_MEMORY; + if (oriStatus == newStatus) { + if (newStatus == JOB_TASK_STATUS_CANCELLING) { + return TSDB_CODE_SUCCESS; } - - if (0 != taosHashPut(newSchStatus.taskStatus, id, sizeof(id), &tStatus, sizeof(tStatus))) { - qError("taosHashPut schedulerId[%"PRIx64"]queryId[%"PRIx64"] taskId[%"PRIx64"] to scheduleHash failed", schedulerId, queryId, taskId); - taosHashCleanup(newSchStatus.taskStatus); - return TSDB_CODE_QRY_APP_ERROR; - } - - newSchStatus.lastAccessTs = taosGetTimestampSec(); - - if (0 != taosHashPut(mgmt->scheduleHash, &schedulerId, sizeof(schedulerId), &newSchStatus, sizeof(newSchStatus))) { - qError("taosHashPut schedulerId[%"PRIx64"] to scheduleHash failed", schedulerId); - taosHashCleanup(newSchStatus.taskStatus); + + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + switch (oriStatus) { + case JOB_TASK_STATUS_NULL: + if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_FAILED ) { + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + break; + case JOB_TASK_STATUS_NOT_START: + if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_FAILED) { + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + break; + case JOB_TASK_STATUS_EXECUTING: + if (newStatus != JOB_TASK_STATUS_SUCCEED && newStatus != JOB_TASK_STATUS_FAILED && newStatus != JOB_TASK_STATUS_CANCELLING) { + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + break; + case JOB_TASK_STATUS_PARTIAL_SUCCEED: + if (newStatus != JOB_TASK_STATUS_EXECUTING && newStatus != JOB_TASK_STATUS_CANCELLING) { + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + break; + case JOB_TASK_STATUS_SUCCEED: + case JOB_TASK_STATUS_FAILED: + case JOB_TASK_STATUS_CANCELLING: + if (newStatus != JOB_TASK_STATUS_CANCELLED) { + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + break; + case JOB_TASK_STATUS_CANCELLED: + default: + qError("invalid task status:%d", oriStatus); return TSDB_CODE_QRY_APP_ERROR; - } - - return TSDB_CODE_SUCCESS; } - schStatus->lastAccessTs = taosGetTimestampSec(); + return TSDB_CODE_SUCCESS; - if (0 != taosHashPut(schStatus->taskStatus, id, sizeof(id), &tStatus, sizeof(tStatus))) { - qError("taosHashPut schedulerId[%"PRIx64"]queryId[%"PRIx64"] taskId[%"PRIx64"] to scheduleHash failed", schedulerId, queryId, taskId); - return TSDB_CODE_QRY_APP_ERROR; - } +_return: - return TSDB_CODE_SUCCESS; + qError("invalid task status:%d", oriStatus); + QW_ERR_RET(code); } -int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, SQWorkerTaskStatus **taskStatus) { - SQWorkerSchTaskStatus *schStatus = taosHashGet(mgmt->scheduleHash, &schedulerId, sizeof(schedulerId)); - if (NULL == schStatus) { - qError("no scheduler for schedulerId[%"PRIx64"]", schedulerId); - return TSDB_CODE_QRY_APP_ERROR; - } - - schStatus->lastAccessTs = taosGetTimestampSec(); +int32_t qwUpdateTaskInfo(SQWorkerTaskStatus *task, int8_t type, void *data) { + int32_t code = 0; - char id[sizeof(queryId) + sizeof(taskId)] = {0}; - QW_SET_QTID(id, queryId, taskId); - - SQWorkerTaskStatus *tStatus = taosHashGet(schStatus->taskStatus, id, sizeof(id)); - if (NULL == tStatus) { - qError("no task status for schedulerId[%"PRIx64"] queryId[%"PRIx64"] taskId[%"PRIx64"]", schedulerId, queryId, taskId); - return TSDB_CODE_QRY_APP_ERROR; + switch (type) { + case QW_TASK_INFO_STATUS: { + int8_t newStatus = *(int8_t *)data; + QW_ERR_RET(qwCheckStatusSwitch(task->status, newStatus)); + task->status = newStatus; + break; + } + default: + qError("uknown task info type:%d", type); + return TSDB_CODE_QRY_APP_ERROR; } - - *taskStatus = tStatus; - + return TSDB_CODE_SUCCESS; } @@ -76,12 +86,16 @@ int32_t qwAddTaskResult(SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, v SQWorkerResCache resCache = {0}; resCache.data = data; - + + QW_LOCK(QW_WRITE, &mgmt->resLock); if (0 != taosHashPut(mgmt->resHash, id, sizeof(id), &resCache, sizeof(SQWorkerResCache))) { + QW_UNLOCK(QW_WRITE, &mgmt->resLock); qError("taosHashPut queryId[%"PRIx64"] taskId[%"PRIx64"] to resHash failed", queryId, taskId); return TSDB_CODE_QRY_APP_ERROR; } + QW_UNLOCK(QW_WRITE, &mgmt->resLock); + return TSDB_CODE_SUCCESS; } @@ -101,62 +115,693 @@ int32_t qwGetTaskResult(SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, v return TSDB_CODE_SUCCESS; } -int32_t qwUpdateSchLastAccess(SQWorkerMgmt *mgmt, uint64_t schedulerId) { - SQWorkerSchTaskStatus *schStatus = taosHashGet(mgmt->scheduleHash, &schedulerId, sizeof(schedulerId)); - if (NULL == schStatus) { - qError("no scheduler for schedulerId[%"PRIx64"]", schedulerId); - return TSDB_CODE_QRY_APP_ERROR; + +static FORCE_INLINE int32_t qwAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t schedulerId, SQWorkerSchStatus **sch) { + QW_LOCK(rwType, &mgmt->schLock); + *sch = taosHashGet(mgmt->schHash, &schedulerId, sizeof(schedulerId)); + if (NULL == (*sch)) { + QW_LOCK(rwType, &mgmt->schLock); + return TSDB_CODE_QRY_SCH_NOT_EXIST; } - schStatus->lastAccessTs = taosGetTimestampSec(); + return TSDB_CODE_SUCCESS; +} + + +static FORCE_INLINE int32_t qwInsertAndAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t schedulerId, SQWorkerSchStatus **sch) { + SQWorkerSchStatus newSch = {0}; + newSch.tasksHash = taosHashInit(mgmt->cfg.maxSchTaskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + if (NULL == newSch.tasksHash) { + qError("taosHashInit %d failed", mgmt->cfg.maxSchTaskNum); + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + + while (true) { + QW_LOCK(QW_WRITE, &mgmt->schLock); + int32_t code = taosHashPut(mgmt->schHash, &schedulerId, sizeof(schedulerId), &newSch, sizeof(newSch)); + if (0 != code) { + if (!HASH_NODE_EXIST(code)) { + QW_UNLOCK(QW_WRITE, &mgmt->schLock); + qError("taosHashPut schedulerId[%"PRIx64"] to scheduleHash failed", schedulerId); + taosHashCleanup(newSch.tasksHash); + return TSDB_CODE_QRY_APP_ERROR; + } + } + + QW_UNLOCK(QW_WRITE, &mgmt->schLock); + if (TSDB_CODE_SUCCESS == qwAcquireScheduler(rwType, mgmt, schedulerId, sch)) { + taosHashCleanup(newSch.tasksHash); + return TSDB_CODE_SUCCESS; + } + } return TSDB_CODE_SUCCESS; } -int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, SSchedulerStatusRsp **rsp) { - SQWorkerSchTaskStatus *schStatus = taosHashGet(mgmt->scheduleHash, &schedulerId, sizeof(schedulerId)); - if (NULL == schStatus) { - qError("no scheduler for schedulerId[%"PRIx64"]", schedulerId); - return TSDB_CODE_QRY_APP_ERROR; + +static FORCE_INLINE void qwReleaseScheduler(int32_t rwType, SQWorkerMgmt *mgmt) { + QW_UNLOCK(rwType, &mgmt->schLock); +} + +static FORCE_INLINE int32_t qwAcquireTask(int32_t rwType, SQWorkerSchStatus *sch, uint64_t queryId, uint64_t taskId, SQWorkerTaskStatus **task) { + char id[sizeof(queryId) + sizeof(taskId)] = {0}; + QW_SET_QTID(id, queryId, taskId); + + QW_LOCK(rwType, &sch->tasksLock); + *task = taosHashGet(sch->tasksHash, id, sizeof(id)); + if (NULL == (*task)) { + QW_UNLOCK(rwType, &sch->tasksLock); + return TSDB_CODE_QRY_TASK_NOT_EXIST; } - schStatus->lastAccessTs = taosGetTimestampSec(); + return TSDB_CODE_SUCCESS; +} - int32_t i = 0; - int32_t taskNum = taosHashGetSize(schStatus->taskStatus); +static FORCE_INLINE int32_t qwInsertAndAcquireTask(int32_t rwType, SQWorkerSchStatus *sch, uint64_t queryId, uint64_t taskId, int8_t status, bool *inserted, SQWorkerTaskStatus **task) { + char id[sizeof(queryId) + sizeof(taskId)] = {0}; + QW_SET_QTID(id, queryId, taskId); + + while (true) { + *inserted = false; + + QW_LOCK(QW_WRITE, &sch->tasksLock); + int32_t code = taosHashPut(sch->tasksHash, id, sizeof(id), &status, sizeof(status)); + if (0 != code) { + QW_UNLOCK(QW_WRITE, &sch->tasksLock); + if (HASH_NODE_EXIST(code)) { + if (qwAcquireTask(rwType, sch, queryId, taskId, task)) { + continue; + } + + break; + } else { + qError("taosHashPut queryId[%"PRIx64"] taskId[%"PRIx64"] to scheduleHash failed", queryId, taskId); + return TSDB_CODE_QRY_APP_ERROR; + } + } + QW_UNLOCK(QW_WRITE, &sch->tasksLock); + + *inserted = true; + + if (TSDB_CODE_SUCCESS == qwAcquireTask(rwType, sch, queryId, taskId, task)) { + return TSDB_CODE_SUCCESS; + } + } + + return TSDB_CODE_SUCCESS; +} + + +static FORCE_INLINE void qwReleaseTask(int32_t rwType, SQWorkerSchStatus *sch) { + QW_UNLOCK(rwType, &sch->tasksLock); +} + +static FORCE_INLINE int32_t qwAcquireTaskResCache(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t queryId, uint64_t taskId, SQWorkerResCache **res) { + char id[sizeof(queryId) + sizeof(taskId)] = {0}; + QW_SET_QTID(id, queryId, taskId); + + QW_LOCK(rwType, &mgmt->resLock); + *res = taosHashGet(mgmt->resHash, id, sizeof(id)); + if (NULL == (*res)) { + QW_UNLOCK(rwType, &mgmt->resLock); + return TSDB_CODE_QRY_RES_CACHE_NOT_EXIST; + } + + return TSDB_CODE_SUCCESS; +} + +static FORCE_INLINE void qwReleaseTaskResCache(int32_t rwType, SQWorkerMgmt *mgmt) { + QW_UNLOCK(rwType, &mgmt->resLock); +} + + +int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, SSchedulerStatusRsp **rsp) { + SQWorkerSchStatus *schStatus = NULL; + int32_t taskNum = 0; + + if (qwAcquireScheduler(QW_READ, mgmt, schedulerId, &schStatus)) { + qWarn("no scheduler for schedulerId[%"PRIx64"]", schedulerId); + } else { + schStatus->lastAccessTs = taosGetTimestampSec(); + + QW_LOCK(QW_READ, &schStatus->tasksLock); + taskNum = taosHashGetSize(schStatus->tasksHash); + } + int32_t size = sizeof(SSchedulerStatusRsp) + sizeof((*rsp)->status[0]) * taskNum; *rsp = calloc(1, size); if (NULL == *rsp) { qError("calloc %d failed", size); + if (schStatus) { + QW_UNLOCK(QW_READ, &schStatus->tasksLock); + qwReleaseScheduler(QW_READ, mgmt); + } + return TSDB_CODE_QRY_OUT_OF_MEMORY; } void *key = NULL; size_t keyLen = 0; - void *pIter = taosHashIterate(schStatus->taskStatus, NULL); - while (pIter) { - SQWorkerTaskStatus *taskStatus = (SQWorkerTaskStatus *)pIter; - taosHashGetKey(pIter, &key, &keyLen); + int32_t i = 0; - QW_GET_QTID(key, (*rsp)->status[i].queryId, (*rsp)->status[i].taskId); - (*rsp)->status[i].status = taskStatus->status; - - pIter = taosHashIterate(schStatus->taskStatus, pIter); - } + if (schStatus) { + void *pIter = taosHashIterate(schStatus->tasksHash, NULL); + while (pIter) { + SQWorkerTaskStatus *taskStatus = (SQWorkerTaskStatus *)pIter; + taosHashGetKey(pIter, &key, &keyLen); + + QW_GET_QTID(key, (*rsp)->status[i].queryId, (*rsp)->status[i].taskId); + (*rsp)->status[i].status = taskStatus->status; + + pIter = taosHashIterate(schStatus->tasksHash, pIter); + } + } + + if (schStatus) { + QW_UNLOCK(QW_READ, &schStatus->tasksLock); + qwReleaseScheduler(QW_READ, mgmt); + } (*rsp)->num = taskNum; return TSDB_CODE_SUCCESS; } -int32_t qwBuildRspMsg(void *data, int32_t msgType); + + +int32_t qwUpdateSchLastAccess(SQWorkerMgmt *mgmt, uint64_t schedulerId) { + SQWorkerSchStatus *schStatus = NULL; + + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &schStatus)); + + schStatus->lastAccessTs = taosGetTimestampSec(); + + qwReleaseScheduler(QW_READ, mgmt); + + return TSDB_CODE_SUCCESS; +} + + +int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, int8_t *taskStatus) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + + QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); + + *taskStatus = task->status; + +_return: + if (task) { + qwReleaseTask(QW_READ, sch); + } + + if (sch) { + qwReleaseScheduler(QW_READ, mgmt); + } + + QW_RET(code); +} + + +int32_t qwSwitchTaskStatus(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, int8_t taskStatus) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + bool inserted = false; + + if (qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)) { + if (qwCheckStatusSwitch(JOB_TASK_STATUS_NULL, taskStatus)) { + qError("switch status error, not start to %d", taskStatus); + QW_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + QW_ERR_RET(qwInsertAndAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + } + + if (qwAcquireTask(QW_READ, sch, queryId, taskId, &task)) { + if (qwCheckStatusSwitch(JOB_TASK_STATUS_NOT_START, taskStatus)) { + qwReleaseScheduler(QW_READ, mgmt); + qError("switch status error, not start to %d", taskStatus); + QW_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + QW_ERR_JRET(qwInsertAndAcquireTask(QW_READ, sch, queryId, taskId, taskStatus, &inserted, &task)); + + if (inserted) { + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + return TSDB_CODE_SUCCESS; + } + + QW_LOCK(QW_WRITE, &task->lock); + code = qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &taskStatus); + QW_UNLOCK(QW_WRITE, &task->lock); + + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + QW_RET(code); + } + + QW_LOCK(QW_WRITE, &task->lock); + code = qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &taskStatus); + QW_UNLOCK(QW_WRITE, &task->lock); + +_return: + + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + QW_RET(code); +} + + +int32_t qwCancelTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + + if (TSDB_CODE_SUCCESS != qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)) { + QW_ERR_RET(qwSwitchTaskStatus(mgmt, schedulerId, queryId, taskId, JOB_TASK_STATUS_NOT_START)); + + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + } + + if (qwAcquireTask(QW_READ, sch, queryId, taskId, &task)) { + code = qwSwitchTaskStatus(mgmt, schedulerId, queryId, taskId, JOB_TASK_STATUS_NOT_START); + if (code) { + qwReleaseScheduler(QW_READ, mgmt); + QW_ERR_RET(code); + } + + QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); + } + + QW_LOCK(QW_WRITE, &task->lock); + + task->cancel = true; + + int8_t oriStatus = task->status; + int8_t newStatus = 0; + + if (task->status == JOB_TASK_STATUS_CANCELLED || task->status == JOB_TASK_STATUS_NOT_START || task->status == JOB_TASK_STATUS_CANCELLING || task->status == JOB_TASK_STATUS_DROPPING) { + QW_UNLOCK(QW_WRITE, &task->lock); + + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + return TSDB_CODE_SUCCESS; + } else if (task->status == JOB_TASK_STATUS_FAILED || task->status == JOB_TASK_STATUS_SUCCEED || task->status == JOB_TASK_STATUS_PARTIAL_SUCCEED) { + newStatus = JOB_TASK_STATUS_CANCELLED; + QW_ERR_JRET(qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &newStatus)); + } else { + newStatus = JOB_TASK_STATUS_CANCELLING; + QW_ERR_JRET(qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &newStatus)); + } + + QW_UNLOCK(QW_WRITE, &task->lock); + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + if (oriStatus == JOB_TASK_STATUS_EXECUTING) { + //TODO call executer to cancel subquery async + } + + return TSDB_CODE_SUCCESS; + +_return: + + if (task) { + QW_UNLOCK(QW_WRITE, &task->lock); + + qwReleaseTask(QW_READ, sch); + } + + if (sch) { + qwReleaseScheduler(QW_READ, mgmt); + } + + QW_RET(code); +} + + + +int32_t qwDropTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + char id[sizeof(queryId) + sizeof(taskId)] = {0}; + QW_SET_QTID(id, queryId, taskId); + + QW_LOCK(QW_WRITE, &mgmt->resLock); + if (mgmt->resHash) { + taosHashRemove(mgmt->resHash, id, sizeof(id)); + } + QW_UNLOCK(QW_WRITE, &mgmt->resLock); + + if (TSDB_CODE_SUCCESS != qwAcquireScheduler(QW_WRITE, mgmt, schedulerId, &sch)) { + qWarn("scheduler %"PRIx64" doesn't exist", schedulerId); + return TSDB_CODE_SUCCESS; + } + + if (qwAcquireTask(QW_WRITE, sch, queryId, taskId, &task)) { + qwReleaseScheduler(QW_WRITE, mgmt); + + qWarn("scheduler %"PRIx64" queryId %"PRIx64" taskId:%"PRIx64" doesn't exist", schedulerId, queryId, taskId); + return TSDB_CODE_SUCCESS; + } + + taosHashRemove(sch->tasksHash, id, sizeof(id)); + + qwReleaseTask(QW_WRITE, sch); + qwReleaseScheduler(QW_WRITE, mgmt); + + return TSDB_CODE_SUCCESS; +} + + +int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + + if (TSDB_CODE_SUCCESS != qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)) { + qWarn("scheduler %"PRIx64" doesn't exist", schedulerId); + return TSDB_CODE_SUCCESS; + } + + if (qwAcquireTask(QW_READ, sch, queryId, taskId, &task)) { + qwReleaseScheduler(QW_READ, mgmt); + + qWarn("scheduler %"PRIx64" queryId %"PRIx64" taskId:%"PRIx64" doesn't exist", schedulerId, queryId, taskId); + return TSDB_CODE_SUCCESS; + } + + QW_LOCK(QW_WRITE, &task->lock); + + task->drop = true; + + int8_t oriStatus = task->status; + int8_t newStatus = 0; + + if (task->status == JOB_TASK_STATUS_EXECUTING) { + newStatus = JOB_TASK_STATUS_CANCELLING; + QW_ERR_JRET(qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &newStatus)); + } else if (task->status == JOB_TASK_STATUS_CANCELLING || task->status == JOB_TASK_STATUS_DROPPING || task->status == JOB_TASK_STATUS_NOT_START) { + QW_UNLOCK(QW_WRITE, &task->lock); + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + return TSDB_CODE_SUCCESS; + } else { + QW_UNLOCK(QW_WRITE, &task->lock); + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + QW_ERR_RET(qwDropTask(mgmt, schedulerId, queryId, taskId)); + return TSDB_CODE_SUCCESS; + } + + QW_UNLOCK(QW_WRITE, &task->lock); + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + if (oriStatus == JOB_TASK_STATUS_EXECUTING) { + //TODO call executer to cancel subquery async + } + + return TSDB_CODE_SUCCESS; + +_return: + + if (task) { + QW_UNLOCK(QW_WRITE, &task->lock); + + qwReleaseTask(QW_READ, sch); + } + + if (sch) { + qwReleaseScheduler(QW_READ, mgmt); + } + + QW_RET(code); +} + + + +int32_t qwBuildAndSendQueryRsp(SRpcMsg *pMsg, int32_t code) { + +} + +int32_t qwBuildAndSendReadyRsp(SRpcMsg *pMsg, int32_t code) { + +} + +int32_t qwBuildAndSendStatusRsp(SRpcMsg *pMsg, SSchedulerStatusRsp *sStatus) { + +} + +int32_t qwBuildAndSendFetchRsp(SRpcMsg *pMsg, void *data) { + +} + + +int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg) { + +} + +int32_t qwBuildAndSendDropRsp(SRpcMsg *pMsg) { + +} + + + +int32_t qwCheckAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg, int32_t rspCode) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + + QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); + + QW_LOCK(QW_WRITE, &task->lock); + + if (QW_READY_NOT_RECEIVED == task->ready) { + QW_UNLOCK(QW_WRITE, &task->lock); + + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + return TSDB_CODE_SUCCESS; + } else if (QW_READY_RECEIVED == task->ready) { + QW_ERR_JRET(qwBuildAndSendReadyRsp(pMsg, rspCode)); + + task->ready = QW_READY_RESPONSED; + } else if (QW_READY_RESPONSED == task->ready) { + qError("query response already send"); + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } else { + assert(0); + } + +_return: + + if (task) { + QW_UNLOCK(QW_WRITE, &task->lock); + } + + if (sch) { + qwReleaseTask(QW_READ, sch); + } + + qwReleaseScheduler(QW_READ, mgmt); + + QW_RET(code); +} + +int32_t qwSetAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + + QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); + + QW_LOCK(QW_WRITE, &task->lock); + if (QW_TASK_READY_RESP(task->status)) { + QW_ERR_JRET(qwBuildAndSendReadyRsp(pMsg, task->code)); + + task->ready = QW_READY_RESPONSED; + } else { + task->ready = QW_READY_RECEIVED; + QW_UNLOCK(QW_WRITE, &task->lock); + + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + return TSDB_CODE_SUCCESS; + } + +_return: + + if (task) { + QW_UNLOCK(QW_WRITE, &task->lock); + } + + if (sch) { + qwReleaseTask(QW_READ, sch); + } + + qwReleaseScheduler(QW_READ, mgmt); + + QW_RET(code); +} + +int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, bool *needStop) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + int8_t status = JOB_TASK_STATUS_CANCELLED; + + *needStop = false; + + if (qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)) { + return TSDB_CODE_SUCCESS; + } + + if (qwAcquireTask(QW_READ, sch, queryId, taskId, &task)) { + qwReleaseScheduler(QW_READ, mgmt); + return TSDB_CODE_SUCCESS; + } + + QW_LOCK(QW_READ, &task->lock); + + if ((!task->cancel) && (!task->drop)) { + QW_UNLOCK(QW_READ, &task->lock); + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + return TSDB_CODE_SUCCESS; + } + + QW_UNLOCK(QW_READ, &task->lock); + + *needStop = true; + + if (task->cancel) { + QW_LOCK(QW_WRITE, &task->lock); + qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &status); + QW_UNLOCK(QW_WRITE, &task->lock); + } else if (task->drop) { + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + qwDropTask(mgmt, schedulerId, queryId, taskId); + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t qwHandleFetch(SQWorkerResCache *res, SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, SRpcMsg *pMsg) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + + QW_ERR_RET(qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch)); + QW_ERR_JRET(qwAcquireTask(QW_READ, sch, queryId, taskId, &task)); + + QW_LOCK(QW_READ, &task->lock); + + if (task->status != JOB_TASK_STATUS_EXECUTING && task->status != JOB_TASK_STATUS_PARTIAL_SUCCEED && task->status != JOB_TASK_STATUS_SUCCEED) { + qError("invalid status %d for fetch", task->status); + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + if (QW_GOT_RES_DATA(res->data)) { + QW_ERR_JRET(qwBuildAndSendFetchRsp(pMsg, res->data)); + if (QW_LOW_RES_DATA(res->data)) { + if (task->status == JOB_TASK_STATUS_PARTIAL_SUCCEED) { + //TODO add query back to queue + } + } + } else { + if (task->status != JOB_TASK_STATUS_EXECUTING) { + qError("invalid status %d for fetch without res", task->status); + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + //TODO SET FLAG FOR QUERY TO SEND RSP WHEN RES READY + } + +_return: + if (task) { + QW_UNLOCK(QW_READ, &task->lock); + } + + if (sch) { + qwReleaseTask(QW_READ, sch); + } + + qwReleaseScheduler(QW_READ, mgmt); + + QW_RET(code); +} + +int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t schedulerId, uint64_t queryId, uint64_t taskId, int8_t status, int32_t errCode) { + SQWorkerSchStatus *sch = NULL; + SQWorkerTaskStatus *task = NULL; + int32_t code = 0; + int8_t newStatus = JOB_TASK_STATUS_CANCELLED; + + code = qwAcquireScheduler(QW_READ, mgmt, schedulerId, &sch); + if (code) { + qError("schedulerId:%"PRIx64" not in cache", schedulerId); + QW_ERR_RET(code); + } + + code = qwAcquireTask(QW_READ, sch, queryId, taskId, &task); + if (code) { + qwReleaseScheduler(QW_READ, mgmt); + qError("schedulerId:%"PRIx64" queryId:%"PRIx64" taskId:%"PRIx64" not in cache", schedulerId, queryId, taskId); + QW_ERR_RET(code); + } + + if (task->cancel) { + QW_LOCK(QW_WRITE, &task->lock); + qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &newStatus); + QW_UNLOCK(QW_WRITE, &task->lock); + } else if (task->drop) { + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + qwDropTask(mgmt, schedulerId, queryId, taskId); + + return TSDB_CODE_SUCCESS; + } else { + QW_LOCK(QW_WRITE, &task->lock); + qwUpdateTaskInfo(task, QW_TASK_INFO_STATUS, &status); + task->code = errCode; + QW_UNLOCK(QW_WRITE, &task->lock); + } + + qwReleaseTask(QW_READ, sch); + qwReleaseScheduler(QW_READ, mgmt); + + return TSDB_CODE_SUCCESS; +} int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt) { SQWorkerMgmt *mgmt = calloc(1, sizeof(SQWorkerMgmt)); if (NULL == mgmt) { qError("calloc %d failed", (int32_t)sizeof(SQWorkerMgmt)); - return TSDB_CODE_QRY_OUT_OF_MEMORY; + QW_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } if (cfg) { @@ -167,16 +812,16 @@ int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt) { mgmt->cfg.maxSchTaskNum = QWORKER_DEFAULT_SCH_TASK_NUMBER; } - mgmt->scheduleHash = taosHashInit(mgmt->cfg.maxSchedulerNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); - if (NULL == mgmt->scheduleHash) { + mgmt->schHash = taosHashInit(mgmt->cfg.maxSchedulerNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_NO_LOCK); + if (NULL == mgmt->schHash) { tfree(mgmt); QW_ERR_LRET(TSDB_CODE_QRY_OUT_OF_MEMORY, "init %d schduler hash failed", mgmt->cfg.maxSchedulerNum); } - mgmt->resHash = taosHashInit(mgmt->cfg.maxResCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); + mgmt->resHash = taosHashInit(mgmt->cfg.maxResCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (NULL == mgmt->resHash) { - taosHashCleanup(mgmt->scheduleHash); - mgmt->scheduleHash = NULL; + taosHashCleanup(mgmt->schHash); + mgmt->schHash = NULL; tfree(mgmt); QW_ERR_LRET(TSDB_CODE_QRY_OUT_OF_MEMORY, "init %d res cache hash failed", mgmt->cfg.maxResCacheNum); @@ -187,99 +832,179 @@ int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt) { return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessQueryMsg(void *qWorkerMgmt, SSchedulerQueryMsg *msg, SRpcMsg *rsp) { - if (NULL == qWorkerMgmt || NULL == msg || NULL == rsp) { - return TSDB_CODE_QRY_INVALID_INPUT; +int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg **rsp) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } + SSubQueryMsg *msg = pMsg->pCont; + if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + bool queryDone = false; + bool queryRsp = false; + bool needStop = false; SSubplan *plan = NULL; - SQWorkerTaskStatus *tStatus = NULL; + int32_t code = 0; - int32_t code = qStringToSubplan(msg->msg, &plan); + QW_ERR_JRET(qwCheckTaskCancelDrop(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, &needStop)); + if (needStop) { + qWarn("task need stop"); + QW_ERR_RET(TSDB_CODE_QRY_TASK_CANCELLED); + } + + code = qStringToSubplan(msg->msg, &plan); if (TSDB_CODE_SUCCESS != code) { qError("schId:%"PRIx64",qId:%"PRIx64",taskId:%"PRIx64" string to subplan failed, code:%d", msg->schedulerId, msg->queryId, msg->taskId, code); - return code; + QW_ERR_JRET(code); } - - //TODO call executer to init subquery - QW_ERR_JRET(qwAddTaskStatus(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, JOB_TASK_STATUS_EXECUTING)); + //TODO call executer to init subquery + code = 0; // return error directly + //TODO call executer to init subquery + + if (code) { + QW_ERR_JRET(code); + } else { + QW_ERR_JRET(qwSwitchTaskStatus(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, JOB_TASK_STATUS_EXECUTING)); + } - QW_ERR_JRET(qwBuildRspMsg(NULL, TSDB_MSG_TYPE_QUERY_RSP)); + QW_ERR_JRET(qwBuildAndSendQueryRsp(pMsg, TSDB_CODE_SUCCESS)); + queryRsp = true; + //TODO call executer to execute subquery - code = 0; + code = 0; void *data = NULL; + queryDone = false; //TODO call executer to execute subquery - QW_ERR_JRET(qwGetTaskStatus(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, &tStatus)); - - tStatus->status = (code) ? JOB_TASK_STATUS_FAILED : JOB_TASK_STATUS_SUCCEED; + if (code) { + QW_ERR_JRET(code); + } else { + QW_ERR_JRET(qwAddTaskResult(qWorkerMgmt, msg->queryId, msg->taskId, data)); - QW_ERR_JRET(qwAddTaskResult(qWorkerMgmt, msg->queryId, msg->taskId, data)); + QW_ERR_JRET(qwSwitchTaskStatus(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, JOB_TASK_STATUS_PARTIAL_SUCCEED)); + } _return: - if (tStatus && QW_TASK_DONE(tStatus->status) && QW_READY_RECEIVED == tStatus->ready) { - QW_ERR_RET(qwBuildRspMsg(NULL, TSDB_MSG_TYPE_RES_READY_RSP)); + if (queryRsp) { + code = qwCheckAndSendReadyRsp(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, pMsg, code); + } else { + code = qwBuildAndSendQueryRsp(pMsg, code); } + + int8_t status = 0; + if (TSDB_CODE_SUCCESS != code || queryDone) { + if (code) { + status = JOB_TASK_STATUS_FAILED; //TODO set CANCELLED from code + } else { + status = JOB_TASK_STATUS_SUCCEED; + } - qDestroySubplan(plan); + qwQueryPostProcess(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, status, code); + } - return code; + QW_RET(code); } -int32_t qWorkerProcessReadyMsg(void *qWorkerMgmt, SSchedulerReadyMsg *msg, SRpcMsg *rsp){ - if (NULL == qWorkerMgmt || NULL == msg || NULL == rsp) { +int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp){ + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { return TSDB_CODE_QRY_INVALID_INPUT; } - SQWorkerTaskStatus *tStatus = NULL; - - QW_ERR_RET(qwGetTaskStatus(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, &tStatus)); - - if (QW_TASK_DONE(tStatus->status)) { - QW_ERR_RET(qwBuildRspMsg(tStatus, TSDB_MSG_TYPE_RES_READY_RSP)); - } else { - tStatus->ready = QW_READY_RECEIVED; - - return TSDB_CODE_SUCCESS; - } + SResReadyMsg *msg = pMsg->pCont; + if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } - tStatus->ready = QW_READY_RESPONSED; + QW_ERR_RET(qwSetAndSendReadyRsp(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, pMsg)); return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessStatusMsg(void *qWorkerMgmt, SSchedulerStatusMsg *msg, SRpcMsg *rsp) { - if (NULL == qWorkerMgmt || NULL == msg || NULL == rsp) { +int32_t qWorkerProcessStatusMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { return TSDB_CODE_QRY_INVALID_INPUT; } + SSchTasksStatusMsg *msg = pMsg->pCont; + if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + SSchedulerStatusRsp *sStatus = NULL; QW_ERR_RET(qwGetSchTasksStatus(qWorkerMgmt, msg->schedulerId, &sStatus)); + QW_ERR_RET(qwBuildAndSendStatusRsp(pMsg, sStatus)); + return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessFetchMsg(void *qWorkerMgmt, SSchedulerFetchMsg *msg, SRpcMsg *rsp) { - if (NULL == qWorkerMgmt || NULL == msg || NULL == rsp) { +int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { return TSDB_CODE_QRY_INVALID_INPUT; } + SResFetchMsg *msg = pMsg->pCont; + if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + QW_ERR_RET(qwUpdateSchLastAccess(qWorkerMgmt, msg->schedulerId)); void *data = NULL; + SQWorkerResCache *res = NULL; + int32_t code = 0; - QW_ERR_RET(qwGetTaskResult(qWorkerMgmt, msg->queryId, msg->taskId, &data)); + QW_ERR_RET(qwAcquireTaskResCache(QW_READ, qWorkerMgmt, msg->queryId, msg->taskId, &res)); + + QW_ERR_JRET(qwHandleFetch(res, qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId, pMsg)); + +_return: + + qwReleaseTaskResCache(QW_READ, qWorkerMgmt); + + QW_RET(code); +} + +int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { + return TSDB_CODE_QRY_INVALID_INPUT; + } + + STaskCancelMsg *msg = pMsg->pCont; + if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + QW_ERR_RET(qwCancelTask(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId)); + + QW_ERR_RET(qwBuildAndSendCancelRsp(pMsg)); + + return TSDB_CODE_SUCCESS; +} + +int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *rsp) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == rsp) { + return TSDB_CODE_QRY_INVALID_INPUT; + } + + STaskDropMsg *msg = pMsg->pCont; + if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + QW_ERR_RET(qwCancelDropTask(qWorkerMgmt, msg->schedulerId, msg->queryId, msg->taskId)); - QW_ERR_RET(qwBuildRspMsg(data, TSDB_MSG_TYPE_FETCH_RSP)); + QW_ERR_RET(qwBuildAndSendDropRsp(pMsg)); return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessCancelMsg(void *qWorkerMgmt, SSchedulerCancelMsg *msg, SRpcMsg *rsp); void qWorkerDestroy(void **qWorkerMgmt) { if (NULL == qWorkerMgmt || NULL == *qWorkerMgmt) { diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 99a9b06fe441832d42fbc5bc86ad24bcc3ebc263..83507c8dd7bf4753c8addf614af1b5bd11e6948d 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -296,44 +296,45 @@ int32_t schAsyncSendMsg(SQueryJob *job, SQueryTask *task, int32_t msgType) { } int32_t len = strlen(task->msg); - msgSize = sizeof(SSchedulerQueryMsg) + len; + msgSize = sizeof(SSubQueryMsg) + len + 1; msg = calloc(1, msgSize); if (NULL == msg) { qError("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SSchedulerQueryMsg *pMsg = msg; + SSubQueryMsg *pMsg = msg; pMsg->schedulerId = htobe64(schMgmt.schedulerId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); pMsg->contentLen = htonl(len); memcpy(pMsg->msg, task->msg, len); + pMsg->msg[len] = 0; break; } case TSDB_MSG_TYPE_RES_READY: { - msgSize = sizeof(SSchedulerReadyMsg); + msgSize = sizeof(SResReadyMsg); msg = calloc(1, msgSize); if (NULL == msg) { qError("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SSchedulerReadyMsg *pMsg = msg; + SResReadyMsg *pMsg = msg; pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); break; } case TSDB_MSG_TYPE_FETCH: { - msgSize = sizeof(SSchedulerFetchMsg); + msgSize = sizeof(SResFetchMsg); msg = calloc(1, msgSize); if (NULL == msg) { qError("calloc %d failed", msgSize); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SSchedulerFetchMsg *pMsg = msg; + SResFetchMsg *pMsg = msg; pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); break; @@ -521,8 +522,8 @@ _return: int32_t schLaunchTask(SQueryJob *job, SQueryTask *task) { SSubplan *plan = task->plan; - - SCH_ERR_RET(qSubPlanToString(plan, &task->msg)); + int32_t len = 0; + SCH_ERR_RET(qSubPlanToString(plan, &task->msg, &len)); if (plan->execEpSet.numOfEps <= 0) { SCH_ERR_RET(schSetTaskExecEpSet(job, &plan->execEpSet)); } diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 48eb84b5360b34a3a686a7c825fcd12c39e87fc7..c80fb4eed83163b29bf26d85879a54d95029696a 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -170,6 +170,7 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) { return 0; } +#if 0 int32_t walRead(SWal *pWal, SWalHead **ppHead, int64_t ver) { int code; code = walSeekVer(pWal, ver); @@ -207,6 +208,7 @@ int32_t walRead(SWal *pWal, SWalHead **ppHead, int64_t ver) { return 0; } -/*int32_t walReadWithFp(SWal *pWal, FWalWrite writeFp, int64_t verStart, int32_t readNum) {*/ -/*return 0;*/ -/*}*/ +int32_t walReadWithFp(SWal *pWal, FWalWrite writeFp, int64_t verStart, int32_t readNum) { +return 0; +} +#endif diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 43ac7606432b6380fbac9b683ef8737e1903c8f3..65057501b9e7c592a81459732be2d0703d7604bf 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -323,7 +323,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INCONSISTAN, "File inconsistance in TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_TIME_CONDITION, "One valid time range condition expected") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_SYS_ERROR, "System error") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_INPUT, "invalid input") - +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_SCH_NOT_EXIST, "Scheduler not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_NOT_EXIST, "Task not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TASK_ALREADY_EXIST, "Task already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_RES_CACHE_NOT_EXIST, "Task result cache not exist") // grant TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, "License expired") diff --git a/source/util/src/thash.c b/source/util/src/thash.c index c4f6f78106e1ee6703e0429e705f62ab83db1881..cfe14f00e14d2f00f09ffbf276c81c9eca14bfe6 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -291,7 +291,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da // enable resize __rd_unlock(&pHashObj->lock, pHashObj->type); - return pHashObj->enableUpdate ? 0 : -1; + return pHashObj->enableUpdate ? 0 : -2; } } diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 800ee034414e2d282bd1aa506b4e440a48f4a6d1..50806fdfd6e9198b318e3a8a4aa3fcd928b527c1 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -32,6 +32,7 @@ #include "ttokendef.h" #include "tutil.h" #include "tvariant.h" +#include "parserInt.h" } %syntax_error { @@ -302,8 +303,8 @@ db_optr(Y) ::= db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = strtol(X.z, %type topic_optr {SCreateDbInfo} -topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; } -topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); } +//topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; } +//topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); } %type alter_db_optr {SCreateDbInfo} alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y); Y.dbType = TSDB_DB_TYPE_DEFAULT;} @@ -325,7 +326,7 @@ alter_db_optr(Y) ::= alter_db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = str alter_topic_optr(Y) ::= alter_db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; } alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); } -%type typename {TAOS_FIELD} +%type typename {SField} typename(A) ::= ids(X). { X.type = 0; tSetColumnType (&A, &X); @@ -425,11 +426,11 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). { setCreatedTableName(pInfo, &V, &U); } -%type column{TAOS_FIELD} +%type column{SField} %type columnlist{SArray*} %destructor columnlist {taosArrayDestroy($$);} columnlist(A) ::= columnlist(X) COMMA column(Y). {taosArrayPush(X, &Y); A = X; } -columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(A, &X);} +columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(SField)); taosArrayPush(A, &X);} // The information used for a column is the name and type of column: // tinyint smallint int bigint float double bool timestamp binary(x) nchar(x) diff --git a/tests/script/general/user/basic1.sim b/tests/script/general/user/basic1.sim index d4a663c096f99cfcde87399bfe57b66f424e2410..33c4dc96d41c76e9ebe2661d806cb1d0ac6b304a 100644 --- a/tests/script/general/user/basic1.sim +++ b/tests/script/general/user/basic1.sim @@ -26,7 +26,7 @@ if $rows != 2 then endi print $data00 $data01 $data02 -print $data10 $data11 $data22 +print $data10 $data11 $data12 print $data20 $data11 $data22 print $data30 $data31 $data32 @@ -38,7 +38,7 @@ if $rows != 3 then endi print $data00 $data01 $data02 -print $data10 $data11 $data22 +print $data10 $data11 $data12 print $data20 $data11 $data22 print $data30 $data31 $data32 print $data40 $data41 $data42 diff --git a/tests/script/general/user/pass_len.sim b/tests/script/general/user/pass_len.sim index 5eb200b51f9ac28b19ea095be6530dbada9be894..649b3efa485b07df486b87195397ae8b4d25ef18 100644 --- a/tests/script/general/user/pass_len.sim +++ b/tests/script/general/user/pass_len.sim @@ -3,8 +3,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c wallevel -v 0 system sh/exec.sh -n dnode1 -s start - -sleep 2000 sql connect $i = 0 @@ -29,7 +27,7 @@ step12: sql create user $user PASS 'taosdata' sql show users -if $rows != 4 then +if $rows != 2 then return -1 endi @@ -40,7 +38,7 @@ sql drop user $user -x step2 step2: sql create user $user PASS '1' sql show users -if $rows != 5 then +if $rows != 3 then return -1 endi @@ -52,7 +50,7 @@ step3: sql create user $user PASS 'abc0123456789' sql show users -if $rows != 6 then +if $rows != 3 then return -1 endi @@ -63,7 +61,7 @@ sql create user $user PASS 'abcd012345678901234567891234567890' -x step4 return -1 step4: sql show users -if $rows != 6 then +if $rows != 4 then return -1 endi @@ -75,7 +73,7 @@ while $i < 3 endw sql show users -if $rows != 3 then +if $rows != 1 then return -1 endi