diff --git a/docs/en/12-taos-sql/02-database.md b/docs/en/12-taos-sql/02-database.md index 80581b2f1b..c2961d6241 100644 --- a/docs/en/12-taos-sql/02-database.md +++ b/docs/en/12-taos-sql/02-database.md @@ -32,7 +32,6 @@ CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1]; - cacheLast: [Description](/reference/config/#cachelast) - replica: [Description](/reference/config/#replica) - quorum: [Description](/reference/config/#quorum) - - maxVgroupsPerDb: [Description](/reference/config/#maxvgroupsperdb) - comp: [Description](/reference/config/#comp) - precision: [Description](/reference/config/#precision) 6. Please note that all of the parameters mentioned in this section are configured in configuration file `taos.cfg` on the TDengine server. If not specified in the `create database` statement, the values from taos.cfg are used by default. To override default parameters, they must be specified in the `create database` statement. diff --git a/docs/zh/12-taos-sql/02-database.md b/docs/zh/12-taos-sql/02-database.md index 566fec3241..e3a0aa7c87 100644 --- a/docs/zh/12-taos-sql/02-database.md +++ b/docs/zh/12-taos-sql/02-database.md @@ -32,7 +32,6 @@ CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1]; - cacheLast: [详细说明](/reference/config/#cachelast) - replica: [详细说明](/reference/config/#replica) - quorum: [详细说明](/reference/config/#quorum) - - maxVgroupsPerDb: [详细说明](/reference/config/#maxvgroupsperdb) - comp: [详细说明](/reference/config/#comp) - precision: [详细说明](/reference/config/#precision) 6. 请注意上面列出的所有参数都可以配置在配置文件 `taosd.cfg` 中作为创建数据库时使用的默认配置, `create database` 的参数中明确指定的会覆盖配置文件中的设置。 diff --git a/examples/c/tmq.c b/examples/c/tmq.c index 74efb4c026..5d7f1bbe70 100644 --- a/examples/c/tmq.c +++ b/examples/c/tmq.c @@ -28,15 +28,23 @@ static void msg_process(TAOS_RES* msg) { printf("db: %s\n", tmq_get_db_name(msg)); printf("vg: %d\n", tmq_get_vgroup_id(msg)); if (tmq_get_res_type(msg) == TMQ_RES_TABLE_META) { - void* meta; - int32_t metaLen; - tmq_get_raw_meta(msg, &meta, &metaLen); + tmq_raw_data *raw = tmq_get_raw_meta(msg); + if(raw){ + TAOS* pConn = taos_connect("192.168.1.86", "root", "taosdata", "abc1", 0); + if (pConn == NULL) { + return; + } + int32_t ret = taos_write_raw_meta(pConn, raw); + printf("write raw data: %s\n", tmq_err2str(ret)); + free(raw); + taos_close(pConn); + } char* result = tmq_get_json_meta(msg); if(result){ printf("meta result: %s\n", result); free(result); } - printf("meta, len is %d\n", metaLen); + printf("meta:%p\n", raw); return; } while (1) { diff --git a/include/client/taos.h b/include/client/taos.h index 216a5832b0..362782b420 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -260,15 +260,16 @@ enum tmq_res_t { }; typedef enum tmq_res_t tmq_res_t; +typedef struct tmq_raw_data tmq_raw_data; -DLL_EXPORT tmq_res_t tmq_get_res_type(TAOS_RES *res); -DLL_EXPORT int32_t tmq_get_raw_meta(TAOS_RES *res, void **raw_meta, int32_t *raw_meta_len); -DLL_EXPORT int32_t taos_write_raw_meta(TAOS *res, void *raw_meta, int32_t raw_meta_len); -DLL_EXPORT char *tmq_get_json_meta(TAOS_RES *res); // Returning null means error. Returned result need to be freed. -DLL_EXPORT const char *tmq_get_topic_name(TAOS_RES *res); -DLL_EXPORT const char *tmq_get_db_name(TAOS_RES *res); -DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); -DLL_EXPORT const char *tmq_get_table_name(TAOS_RES *res); +DLL_EXPORT tmq_res_t tmq_get_res_type(TAOS_RES *res); +DLL_EXPORT tmq_raw_data *tmq_get_raw_meta(TAOS_RES *res); +DLL_EXPORT int32_t taos_write_raw_meta(TAOS *taos, tmq_raw_data *raw_meta); +DLL_EXPORT char *tmq_get_json_meta(TAOS_RES *res); // Returning null means error. Returned result need to be freed. +DLL_EXPORT const char *tmq_get_topic_name(TAOS_RES *res); +DLL_EXPORT const char *tmq_get_db_name(TAOS_RES *res); +DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); +DLL_EXPORT const char *tmq_get_table_name(TAOS_RES *res); /* ------------------------------ TMQ END -------------------------------- */ diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 779453f714..3d15e8b087 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -55,7 +55,8 @@ enum { enum { STREAM_INPUT__DATA_SUBMIT = 1, STREAM_INPUT__DATA_BLOCK, - STREAM_INPUT__DATA_SCAN, + // STREAM_INPUT__TABLE_SCAN, + STREAM_INPUT__TQ_SCAN, STREAM_INPUT__DATA_RETRIEVE, STREAM_INPUT__TRIGGER, STREAM_INPUT__CHECKPOINT, @@ -122,7 +123,8 @@ enum { }; typedef struct { - int8_t fetchType; + int8_t fetchType; + STqOffsetVal offset; union { SSDataBlock data; void* meta; @@ -153,8 +155,8 @@ typedef struct SQueryTableDataCond { int32_t numOfCols; SColumnInfo* colList; int32_t type; // data block load type: - int32_t numOfTWindows; - STimeWindow* twindows; +// int32_t numOfTWindows; + STimeWindow twindows; int64_t startVersion; int64_t endVersion; } SQueryTableDataCond; diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 8b64287033..af333f72aa 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -231,7 +231,7 @@ SSDataBlock* createDataBlock(); int32_t blockDataAppendColInfo(SSDataBlock* pBlock, SColumnInfoData* pColInfoData); SColumnInfoData createColumnInfoData(int16_t type, int32_t bytes, int16_t colId); -SColumnInfoData* bdGetColumnInfoData(SSDataBlock* pBlock, int32_t index); +SColumnInfoData* bdGetColumnInfoData(const SSDataBlock* pBlock, int32_t index); void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress); const char* blockDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t numOfRows, const char* pData); diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 41674b7a70..944eaa28bc 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -67,7 +67,6 @@ extern int32_t tsNumOfVnodeQueryThreads; extern int32_t tsNumOfVnodeFetchThreads; extern int32_t tsNumOfVnodeWriteThreads; extern int32_t tsNumOfVnodeSyncThreads; -extern int32_t tsNumOfVnodeMergeThreads; extern int32_t tsNumOfQnodeQueryThreads; extern int32_t tsNumOfQnodeFetchThreads; extern int32_t tsNumOfSnodeSharedThreads; diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 20f9503150..f9d3c231ea 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -55,11 +55,11 @@ extern int32_t tMsgDict[]; #define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8) #define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff) -#define TMSG_INFO(TYPE) \ - ((TYPE) >= 0 && \ - ((TYPE) < TDMT_DND_MAX_MSG || (TYPE) < TDMT_MND_MAX_MSG || (TYPE) < TDMT_VND_MAX_MSG || (TYPE) < TDMT_SCH_MAX_MSG || \ - (TYPE) < TDMT_STREAM_MAX_MSG || (TYPE) < TDMT_MON_MAX_MSG || (TYPE) < TDMT_SYNC_MAX_MSG)) \ - ? tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] \ +#define TMSG_INFO(TYPE) \ + ((TYPE) >= 0 && ((TYPE) < TDMT_DND_MAX_MSG || (TYPE) < TDMT_MND_MAX_MSG || (TYPE) < TDMT_VND_MAX_MSG || \ + (TYPE) < TDMT_SCH_MAX_MSG || (TYPE) < TDMT_STREAM_MAX_MSG || (TYPE) < TDMT_MON_MAX_MSG || \ + (TYPE) < TDMT_SYNC_MAX_MSG)) \ + ? tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] \ : 0 #define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)) @@ -169,6 +169,9 @@ typedef enum _mgmt_table { #define TD_CHILD_TABLE TSDB_CHILD_TABLE #define TD_NORMAL_TABLE TSDB_NORMAL_TABLE +#define TD_REQ_FROM_APP 0 +#define TD_REQ_FROM_TAOX 1 + typedef struct { int32_t vgId; char* dbFName; @@ -432,25 +435,30 @@ static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaW STSchema* tdGetSTSChemaFromSSChema(SSchema** pSchema, int32_t nCols); typedef struct { - char name[TSDB_TABLE_FNAME_LEN]; - int8_t igExists; - int64_t delay1; - int64_t delay2; - int64_t watermark1; - int64_t watermark2; - int32_t ttl; - int32_t numOfColumns; - int32_t numOfTags; - int32_t numOfFuncs; - int32_t commentLen; - int32_t ast1Len; - int32_t ast2Len; - SArray* pColumns; // array of SField - SArray* pTags; // array of SField - SArray* pFuncs; - char* pComment; - char* pAst1; - char* pAst2; + char name[TSDB_TABLE_FNAME_LEN]; + int8_t igExists; + int8_t source; // 1-taosX or 0-taosClient + int8_t reserved[6]; + tb_uid_t suid; + int64_t delay1; + int64_t delay2; + int64_t watermark1; + int64_t watermark2; + int32_t ttl; + int32_t colVer; + int32_t tagVer; + int32_t numOfColumns; + int32_t numOfTags; + int32_t numOfFuncs; + int32_t commentLen; + int32_t ast1Len; + int32_t ast2Len; + SArray* pColumns; // array of SField + SArray* pTags; // array of SField + SArray* pFuncs; + char* pComment; + char* pAst1; + char* pAst2; } SMCreateStbReq; int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq); @@ -458,8 +466,11 @@ int32_t tDeserializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pR void tFreeSMCreateStbReq(SMCreateStbReq* pReq); typedef struct { - char name[TSDB_TABLE_FNAME_LEN]; - int8_t igNotExists; + char name[TSDB_TABLE_FNAME_LEN]; + int8_t igNotExists; + int8_t source; // 1-taosX or 0-taosClient + int8_t reserved[6]; + tb_uid_t suid; } SMDropStbReq; int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq); @@ -468,8 +479,6 @@ int32_t tDeserializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq); typedef struct { char name[TSDB_TABLE_FNAME_LEN]; int8_t alterType; - int32_t tagVer; - int32_t colVer; int32_t numOfFields; SArray* pFields; int32_t ttl; @@ -714,7 +723,7 @@ typedef struct { int32_t buffer; // MB int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -727,7 +736,7 @@ typedef struct { int8_t compression; int8_t replications; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int8_t schemaless; int8_t ignoreExist; int32_t numOfRetensions; @@ -743,7 +752,7 @@ typedef struct { int32_t buffer; int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -751,7 +760,7 @@ typedef struct { int32_t fsyncPeriod; int8_t walLevel; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int8_t replications; } SAlterDbReq; @@ -806,6 +815,13 @@ typedef struct { int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq); int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq); +typedef struct { + char db[TSDB_DB_FNAME_LEN]; +} STrimDbReq; + +int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq); +int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq); + typedef struct { int32_t numOfVgroups; int32_t numOfStables; @@ -824,7 +840,7 @@ typedef struct { int8_t compression; int8_t replications; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int32_t numOfRetensions; SArray* pRetensions; int8_t schemaless; @@ -1089,7 +1105,7 @@ typedef struct { int32_t buffer; int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -1104,7 +1120,7 @@ typedef struct { int8_t precision; int8_t compression; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int8_t isTsma; int8_t standby; int8_t replica; @@ -1142,7 +1158,7 @@ typedef struct { int32_t buffer; int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -1150,7 +1166,7 @@ typedef struct { int32_t fsyncPeriod; int8_t walLevel; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int8_t selfIndex; int8_t replica; SReplica replicas[TSDB_MAX_REPLICA]; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 8b39530e84..1dbfbfb2b9 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -116,6 +116,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DB, "alter-db", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SYNC_DB, "sync-db", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_COMPACT_DB, "compact-db", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TRIM_DB, "trim-db", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_GET_DB_CFG, "get-db-cfg", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_VGROUP_LIST, "vgroup-list", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_FUNC, "create-func", NULL, NULL) diff --git a/include/common/tname.h b/include/common/tname.h index 3bf1cee870..77965947ad 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -37,6 +37,8 @@ typedef struct SName { char tname[TSDB_TABLE_NAME_LEN]; } SName; +SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName* pName); + int32_t tNameExtractFullName(const SName* name, char* dst); int32_t tNameLen(const SName* name); diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 5deec2d5f6..29dd4daa25 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -74,201 +74,202 @@ #define TK_DATABASE 56 #define TK_USE 57 #define TK_FLUSH 58 -#define TK_IF 59 -#define TK_NOT 60 -#define TK_EXISTS 61 -#define TK_BUFFER 62 -#define TK_CACHELAST 63 -#define TK_CACHELASTSIZE 64 -#define TK_COMP 65 -#define TK_DURATION 66 -#define TK_NK_VARIABLE 67 -#define TK_FSYNC 68 -#define TK_MAXROWS 69 -#define TK_MINROWS 70 -#define TK_KEEP 71 -#define TK_PAGES 72 -#define TK_PAGESIZE 73 -#define TK_PRECISION 74 -#define TK_REPLICA 75 -#define TK_STRICT 76 -#define TK_WAL 77 -#define TK_VGROUPS 78 -#define TK_SINGLE_STABLE 79 -#define TK_RETENTIONS 80 -#define TK_SCHEMALESS 81 -#define TK_NK_COLON 82 -#define TK_TABLE 83 -#define TK_NK_LP 84 -#define TK_NK_RP 85 -#define TK_STABLE 86 -#define TK_ADD 87 -#define TK_COLUMN 88 -#define TK_MODIFY 89 -#define TK_RENAME 90 -#define TK_TAG 91 -#define TK_SET 92 -#define TK_NK_EQ 93 -#define TK_USING 94 -#define TK_TAGS 95 -#define TK_COMMENT 96 -#define TK_BOOL 97 -#define TK_TINYINT 98 -#define TK_SMALLINT 99 -#define TK_INT 100 -#define TK_INTEGER 101 -#define TK_BIGINT 102 -#define TK_FLOAT 103 -#define TK_DOUBLE 104 -#define TK_BINARY 105 -#define TK_TIMESTAMP 106 -#define TK_NCHAR 107 -#define TK_UNSIGNED 108 -#define TK_JSON 109 -#define TK_VARCHAR 110 -#define TK_MEDIUMBLOB 111 -#define TK_BLOB 112 -#define TK_VARBINARY 113 -#define TK_DECIMAL 114 -#define TK_MAX_DELAY 115 -#define TK_WATERMARK 116 -#define TK_ROLLUP 117 -#define TK_TTL 118 -#define TK_SMA 119 -#define TK_FIRST 120 -#define TK_LAST 121 -#define TK_SHOW 122 -#define TK_DATABASES 123 -#define TK_TABLES 124 -#define TK_STABLES 125 -#define TK_MNODES 126 -#define TK_MODULES 127 -#define TK_QNODES 128 -#define TK_FUNCTIONS 129 -#define TK_INDEXES 130 -#define TK_ACCOUNTS 131 -#define TK_APPS 132 -#define TK_CONNECTIONS 133 -#define TK_LICENCE 134 -#define TK_GRANTS 135 -#define TK_QUERIES 136 -#define TK_SCORES 137 -#define TK_TOPICS 138 -#define TK_VARIABLES 139 -#define TK_BNODES 140 -#define TK_SNODES 141 -#define TK_CLUSTER 142 -#define TK_TRANSACTIONS 143 -#define TK_DISTRIBUTED 144 -#define TK_CONSUMERS 145 -#define TK_SUBSCRIPTIONS 146 -#define TK_LIKE 147 -#define TK_INDEX 148 -#define TK_FUNCTION 149 -#define TK_INTERVAL 150 -#define TK_TOPIC 151 -#define TK_AS 152 -#define TK_WITH 153 -#define TK_META 154 -#define TK_CONSUMER 155 -#define TK_GROUP 156 -#define TK_DESC 157 -#define TK_DESCRIBE 158 -#define TK_RESET 159 -#define TK_QUERY 160 -#define TK_CACHE 161 -#define TK_EXPLAIN 162 -#define TK_ANALYZE 163 -#define TK_VERBOSE 164 -#define TK_NK_BOOL 165 -#define TK_RATIO 166 -#define TK_NK_FLOAT 167 -#define TK_COMPACT 168 -#define TK_VNODES 169 -#define TK_IN 170 -#define TK_OUTPUTTYPE 171 -#define TK_AGGREGATE 172 -#define TK_BUFSIZE 173 -#define TK_STREAM 174 -#define TK_INTO 175 -#define TK_TRIGGER 176 -#define TK_AT_ONCE 177 -#define TK_WINDOW_CLOSE 178 -#define TK_IGNORE 179 -#define TK_EXPIRED 180 -#define TK_KILL 181 -#define TK_CONNECTION 182 -#define TK_TRANSACTION 183 -#define TK_BALANCE 184 -#define TK_VGROUP 185 -#define TK_MERGE 186 -#define TK_REDISTRIBUTE 187 -#define TK_SPLIT 188 -#define TK_SYNCDB 189 -#define TK_DELETE 190 -#define TK_INSERT 191 -#define TK_NULL 192 -#define TK_NK_QUESTION 193 -#define TK_NK_ARROW 194 -#define TK_ROWTS 195 -#define TK_TBNAME 196 -#define TK_QSTARTTS 197 -#define TK_QENDTS 198 -#define TK_WSTARTTS 199 -#define TK_WENDTS 200 -#define TK_WDURATION 201 -#define TK_CAST 202 -#define TK_NOW 203 -#define TK_TODAY 204 -#define TK_TIMEZONE 205 -#define TK_CLIENT_VERSION 206 -#define TK_SERVER_VERSION 207 -#define TK_SERVER_STATUS 208 -#define TK_CURRENT_USER 209 -#define TK_COUNT 210 -#define TK_LAST_ROW 211 -#define TK_BETWEEN 212 -#define TK_IS 213 -#define TK_NK_LT 214 -#define TK_NK_GT 215 -#define TK_NK_LE 216 -#define TK_NK_GE 217 -#define TK_NK_NE 218 -#define TK_MATCH 219 -#define TK_NMATCH 220 -#define TK_CONTAINS 221 -#define TK_JOIN 222 -#define TK_INNER 223 -#define TK_SELECT 224 -#define TK_DISTINCT 225 -#define TK_WHERE 226 -#define TK_PARTITION 227 -#define TK_BY 228 -#define TK_SESSION 229 -#define TK_STATE_WINDOW 230 -#define TK_SLIDING 231 -#define TK_FILL 232 -#define TK_VALUE 233 -#define TK_NONE 234 -#define TK_PREV 235 -#define TK_LINEAR 236 -#define TK_NEXT 237 -#define TK_HAVING 238 -#define TK_RANGE 239 -#define TK_EVERY 240 -#define TK_ORDER 241 -#define TK_SLIMIT 242 -#define TK_SOFFSET 243 -#define TK_LIMIT 244 -#define TK_OFFSET 245 -#define TK_ASC 246 -#define TK_NULLS 247 -#define TK_ID 248 -#define TK_NK_BITNOT 249 -#define TK_VALUES 250 -#define TK_IMPORT 251 -#define TK_NK_SEMI 252 -#define TK_FILE 253 +#define TK_TRIM 59 +#define TK_IF 60 +#define TK_NOT 61 +#define TK_EXISTS 62 +#define TK_BUFFER 63 +#define TK_CACHELAST 64 +#define TK_CACHELASTSIZE 65 +#define TK_COMP 66 +#define TK_DURATION 67 +#define TK_NK_VARIABLE 68 +#define TK_FSYNC 69 +#define TK_MAXROWS 70 +#define TK_MINROWS 71 +#define TK_KEEP 72 +#define TK_PAGES 73 +#define TK_PAGESIZE 74 +#define TK_PRECISION 75 +#define TK_REPLICA 76 +#define TK_STRICT 77 +#define TK_WAL 78 +#define TK_VGROUPS 79 +#define TK_SINGLE_STABLE 80 +#define TK_RETENTIONS 81 +#define TK_SCHEMALESS 82 +#define TK_NK_COLON 83 +#define TK_TABLE 84 +#define TK_NK_LP 85 +#define TK_NK_RP 86 +#define TK_STABLE 87 +#define TK_ADD 88 +#define TK_COLUMN 89 +#define TK_MODIFY 90 +#define TK_RENAME 91 +#define TK_TAG 92 +#define TK_SET 93 +#define TK_NK_EQ 94 +#define TK_USING 95 +#define TK_TAGS 96 +#define TK_COMMENT 97 +#define TK_BOOL 98 +#define TK_TINYINT 99 +#define TK_SMALLINT 100 +#define TK_INT 101 +#define TK_INTEGER 102 +#define TK_BIGINT 103 +#define TK_FLOAT 104 +#define TK_DOUBLE 105 +#define TK_BINARY 106 +#define TK_TIMESTAMP 107 +#define TK_NCHAR 108 +#define TK_UNSIGNED 109 +#define TK_JSON 110 +#define TK_VARCHAR 111 +#define TK_MEDIUMBLOB 112 +#define TK_BLOB 113 +#define TK_VARBINARY 114 +#define TK_DECIMAL 115 +#define TK_MAX_DELAY 116 +#define TK_WATERMARK 117 +#define TK_ROLLUP 118 +#define TK_TTL 119 +#define TK_SMA 120 +#define TK_FIRST 121 +#define TK_LAST 122 +#define TK_SHOW 123 +#define TK_DATABASES 124 +#define TK_TABLES 125 +#define TK_STABLES 126 +#define TK_MNODES 127 +#define TK_MODULES 128 +#define TK_QNODES 129 +#define TK_FUNCTIONS 130 +#define TK_INDEXES 131 +#define TK_ACCOUNTS 132 +#define TK_APPS 133 +#define TK_CONNECTIONS 134 +#define TK_LICENCE 135 +#define TK_GRANTS 136 +#define TK_QUERIES 137 +#define TK_SCORES 138 +#define TK_TOPICS 139 +#define TK_VARIABLES 140 +#define TK_BNODES 141 +#define TK_SNODES 142 +#define TK_CLUSTER 143 +#define TK_TRANSACTIONS 144 +#define TK_DISTRIBUTED 145 +#define TK_CONSUMERS 146 +#define TK_SUBSCRIPTIONS 147 +#define TK_LIKE 148 +#define TK_INDEX 149 +#define TK_FUNCTION 150 +#define TK_INTERVAL 151 +#define TK_TOPIC 152 +#define TK_AS 153 +#define TK_WITH 154 +#define TK_META 155 +#define TK_CONSUMER 156 +#define TK_GROUP 157 +#define TK_DESC 158 +#define TK_DESCRIBE 159 +#define TK_RESET 160 +#define TK_QUERY 161 +#define TK_CACHE 162 +#define TK_EXPLAIN 163 +#define TK_ANALYZE 164 +#define TK_VERBOSE 165 +#define TK_NK_BOOL 166 +#define TK_RATIO 167 +#define TK_NK_FLOAT 168 +#define TK_COMPACT 169 +#define TK_VNODES 170 +#define TK_IN 171 +#define TK_OUTPUTTYPE 172 +#define TK_AGGREGATE 173 +#define TK_BUFSIZE 174 +#define TK_STREAM 175 +#define TK_INTO 176 +#define TK_TRIGGER 177 +#define TK_AT_ONCE 178 +#define TK_WINDOW_CLOSE 179 +#define TK_IGNORE 180 +#define TK_EXPIRED 181 +#define TK_KILL 182 +#define TK_CONNECTION 183 +#define TK_TRANSACTION 184 +#define TK_BALANCE 185 +#define TK_VGROUP 186 +#define TK_MERGE 187 +#define TK_REDISTRIBUTE 188 +#define TK_SPLIT 189 +#define TK_SYNCDB 190 +#define TK_DELETE 191 +#define TK_INSERT 192 +#define TK_NULL 193 +#define TK_NK_QUESTION 194 +#define TK_NK_ARROW 195 +#define TK_ROWTS 196 +#define TK_TBNAME 197 +#define TK_QSTARTTS 198 +#define TK_QENDTS 199 +#define TK_WSTARTTS 200 +#define TK_WENDTS 201 +#define TK_WDURATION 202 +#define TK_CAST 203 +#define TK_NOW 204 +#define TK_TODAY 205 +#define TK_TIMEZONE 206 +#define TK_CLIENT_VERSION 207 +#define TK_SERVER_VERSION 208 +#define TK_SERVER_STATUS 209 +#define TK_CURRENT_USER 210 +#define TK_COUNT 211 +#define TK_LAST_ROW 212 +#define TK_BETWEEN 213 +#define TK_IS 214 +#define TK_NK_LT 215 +#define TK_NK_GT 216 +#define TK_NK_LE 217 +#define TK_NK_GE 218 +#define TK_NK_NE 219 +#define TK_MATCH 220 +#define TK_NMATCH 221 +#define TK_CONTAINS 222 +#define TK_JOIN 223 +#define TK_INNER 224 +#define TK_SELECT 225 +#define TK_DISTINCT 226 +#define TK_WHERE 227 +#define TK_PARTITION 228 +#define TK_BY 229 +#define TK_SESSION 230 +#define TK_STATE_WINDOW 231 +#define TK_SLIDING 232 +#define TK_FILL 233 +#define TK_VALUE 234 +#define TK_NONE 235 +#define TK_PREV 236 +#define TK_LINEAR 237 +#define TK_NEXT 238 +#define TK_HAVING 239 +#define TK_RANGE 240 +#define TK_EVERY 241 +#define TK_ORDER 242 +#define TK_SLIMIT 243 +#define TK_SOFFSET 244 +#define TK_LIMIT 245 +#define TK_OFFSET 246 +#define TK_ASC 247 +#define TK_NULLS 248 +#define TK_ID 249 +#define TK_NK_BITNOT 250 +#define TK_VALUES 251 +#define TK_IMPORT 252 +#define TK_NK_SEMI 253 +#define TK_FILE 254 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index f512587880..783193db49 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -36,6 +36,7 @@ typedef struct SReadHandle { void* vnode; void* mnd; SMsgCb* pMsgCb; + int64_t version; bool initMetaReader; bool initTableReader; bool initTqReader; @@ -109,7 +110,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, * @param tversion * @return */ -int32_t qGetQueriedTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, +int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, int32_t* tversion); /** @@ -174,7 +175,13 @@ int32_t qDeserializeTaskStatus(qTaskInfo_t tinfo, const char* pInput, int32_t le */ int32_t qGetStreamScanStatus(qTaskInfo_t tinfo, uint64_t* uid, int64_t* ts); -int32_t qStreamPrepareScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts); +int32_t qStreamPrepareTsdbScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts); + +int32_t qStreamPrepareScan(qTaskInfo_t tinfo, const STqOffsetVal* pOffset); + +int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset); + +void* qStreamExtractMetaMsg(qTaskInfo_t tinfo); void* qExtractReaderFromStreamScanner(void* scanner); int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner); diff --git a/include/libs/function/function.h b/include/libs/function/function.h index a569c8de54..4d27325d75 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -172,7 +172,13 @@ typedef struct tExprNode { void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)); +typedef enum { + SHOULD_FREE_COLDATA = 0x1, // the newly created column data needs to be destroyed. + DELEGATED_MGMT_COLDATA = 0x2, // input column data should not be released. +} ECOLDATA_MGMT_TYPE_E; + struct SScalarParam { + ECOLDATA_MGMT_TYPE_E type; SColumnInfoData *columnData; SHashObj *pHashFilter; int32_t hashValueType; diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 2187a7b03a..5311915612 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -103,6 +103,11 @@ typedef struct SFlushDatabaseStmt { char dbName[TSDB_DB_NAME_LEN]; } SFlushDatabaseStmt; +typedef struct STrimDatabaseStmt { + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; +} STrimDatabaseStmt; + typedef struct STableOptions { ENodeType type; bool commentNull; diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 30bcf22989..c453ce98f8 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -112,6 +112,7 @@ typedef enum ENodeType { QUERY_NODE_DROP_DATABASE_STMT, QUERY_NODE_ALTER_DATABASE_STMT, QUERY_NODE_FLUSH_DATABASE_STMT, + QUERY_NODE_TRIM_DATABASE_STMT, QUERY_NODE_CREATE_TABLE_STMT, QUERY_NODE_CREATE_SUBTABLE_CLAUSE, QUERY_NODE_CREATE_MULTI_TABLE_STMT, diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index b9a0b90a9a..bbff34c66f 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -250,6 +250,7 @@ typedef struct SSelectStmt { SLimitNode* pSlimit; char stmtName[TSDB_TABLE_NAME_LEN]; uint8_t precision; + int32_t selectFuncNum; bool isEmptyResult; bool isTimeLineResult; bool hasAggFuncs; @@ -257,6 +258,7 @@ typedef struct SSelectStmt { bool hasIndefiniteRowsFunc; bool hasSelectFunc; bool hasSelectValFunc; + bool hasOtherVectorFunc; bool hasUniqueFunc; bool hasTailFunc; bool hasInterpFunc; diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index c3007306ae..a4aec72d4f 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -96,6 +96,9 @@ int32_t smlBindData(void* handle, SArray* tags, SArray* colsSchema, SArray* cols char* tableName, char* msgBuf, int16_t msgBufLen); int32_t smlBuildOutput(void* handle, SHashObj* pVgHash); +int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray); +SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap); +SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap); #ifdef __cplusplus } #endif diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index aaebffa118..c81c474366 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -25,7 +25,7 @@ extern "C" { typedef struct SFilterInfo SFilterInfo; -int32_t scalarGetOperatorResultType(SDataType left, SDataType right, EOperatorType op, SDataType* pRes); +int32_t scalarGetOperatorResultType(SOperatorNode* pOp); /* pNode will be freed in API; @@ -42,7 +42,7 @@ int32_t scalarGetOperatorParamNum(EOperatorType type); int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type); int32_t vectorGetConvertType(int32_t type1, int32_t type2); -int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut); +int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* overflow); /* Math functions */ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index d59a0a64b3..d8dea8a1be 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -27,7 +27,7 @@ extern "C" { #define TAOS_CONN_SERVER 0 #define TAOS_CONN_CLIENT 1 -#define IsReq(pMsg) (pMsg->msgType & 1U) +#define IsReq(pMsg) (pMsg->msgType & 1U) extern int32_t tsRpcHeadSize; diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 43792b5415..7e2d09dd63 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -24,42 +24,14 @@ extern "C" { #endif -#define wFatal(...) \ - { \ - if (wDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("WAL FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ - } \ - } -#define wError(...) \ - { \ - if (wDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("WAL ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ - } \ - } -#define wWarn(...) \ - { \ - if (wDebugFlag & DEBUG_WARN) { \ - taosPrintLog("WAL WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ - } \ - } -#define wInfo(...) \ - { \ - if (wDebugFlag & DEBUG_INFO) { \ - taosPrintLog("WAL ", DEBUG_INFO, 255, __VA_ARGS__); \ - } \ - } -#define wDebug(...) \ - { \ - if (wDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("WAL ", DEBUG_DEBUG, wDebugFlag, __VA_ARGS__); \ - } \ - } -#define wTrace(...) \ - { \ - if (wDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("WAL ", DEBUG_TRACE, wDebugFlag, __VA_ARGS__); \ - } \ - } +// clang-format off +#define wFatal(...) { if (wDebugFlag & DEBUG_FATAL) { taosPrintLog("WAL FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define wError(...) { if (wDebugFlag & DEBUG_ERROR) { taosPrintLog("WAL ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define wWarn(...) { if (wDebugFlag & DEBUG_WARN) { taosPrintLog("WAL WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define wInfo(...) { if (wDebugFlag & DEBUG_INFO) { taosPrintLog("WAL ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL ", DEBUG_DEBUG, wDebugFlag, __VA_ARGS__); }} +#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", DEBUG_TRACE, wDebugFlag, __VA_ARGS__); }} +// clang-format on #define WAL_PROTO_VER 0 #define WAL_NOSUFFIX_LEN 20 @@ -73,7 +45,6 @@ extern "C" { #define WAL_MAGIC 0xFAFBFCFDULL typedef enum { - TAOS_WAL_NOLOG = 0, TAOS_WAL_WRITE = 1, TAOS_WAL_FSYNC = 2, } EWalType; @@ -102,7 +73,7 @@ typedef struct { int8_t isWeek; uint64_t seqNum; uint64_t term; -} SSyncLogMeta; +} SWalSyncInfo; typedef struct { int8_t protoVer; @@ -112,7 +83,7 @@ typedef struct { int64_t ingestTs; // not implemented // sync meta - SSyncLogMeta syncMeta; + SWalSyncInfo syncMeta; char body[]; } SWalCont; @@ -152,6 +123,7 @@ typedef struct SWal { typedef struct { int8_t scanUncommited; int8_t scanMeta; + int8_t enableRef; } SWalFilterCond; typedef struct { @@ -161,6 +133,7 @@ typedef struct { int64_t curFileFirstVer; int64_t curVersion; int64_t capacity; + int8_t curInvalid; TdThreadMutex mutex; SWalFilterCond cond; SWalCkHead *pHead; @@ -175,11 +148,22 @@ SWal *walOpen(const char *path, SWalCfg *pCfg); int32_t walAlter(SWal *, SWalCfg *pCfg); void walClose(SWal *); -// write -int32_t walWriteWithSyncInfo(SWal *, int64_t index, tmsg_t msgType, SSyncLogMeta syncMeta, const void *body, - int32_t bodyLen); +// write interfaces + +// By assigning index by the caller, wal gurantees linearizability int32_t walWrite(SWal *, int64_t index, tmsg_t msgType, const void *body, int32_t bodyLen); -void walFsync(SWal *, bool force); +int32_t walWriteWithSyncInfo(SWal *, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, + int32_t bodyLen); + +// This interface assign version automatically and return to caller. +// When using this interface with concurrent writes, +// wal will write all logs atomically, +// but not sure which one will be actually write first, +// and then the unique index of successful writen is returned. +// -1 will be returned for failed writes +int64_t walAppendLog(SWal *, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen); + +void walFsync(SWal *, bool force); // apis for lifecycle management int32_t walCommit(SWal *, int64_t ver); @@ -194,6 +178,7 @@ int32_t walRestoreFromSnapshot(SWal *, int64_t ver); SWalReader *walOpenReader(SWal *, SWalFilterCond *pCond); void walCloseReader(SWalReader *pRead); int32_t walReadVer(SWalReader *pRead, int64_t ver); +int32_t walReadSeekVer(SWalReader *pRead, int64_t ver); int32_t walNextValidMsg(SWalReader *pRead); // only for tq usage diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 41d5910625..ce434612c3 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -247,9 +247,11 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AE) #define TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03AF) #define TSDB_CODE_MND_SINGLE_STB_MODE_DB TAOS_DEF_ERROR_CODE(0, 0x03B0) +#define TSDB_CODE_MND_INVALID_SCHEMA_VER TAOS_DEF_ERROR_CODE(0, 0x03B1) +#define TSDB_CODE_MND_STABLE_UID_NOT_MATCH TAOS_DEF_ERROR_CODE(0, 0x03B2) // mnode-infoSchema -#define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x03BA) +#define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x03BA) // mnode-func #define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0) @@ -582,6 +584,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INVALID_INTERP_CLAUSE TAOS_DEF_ERROR_CODE(0, 0x265D) #define TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN TAOS_DEF_ERROR_CODE(0, 0x265E) #define TSDB_CODE_PAR_ONLY_SUPPORT_SINGLE_TABLE TAOS_DEF_ERROR_CODE(0, 0x265F) +#define TSDB_CODE_PAR_INVALID_SMA_INDEX TAOS_DEF_ERROR_CODE(0, 0x265C) //planner #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) diff --git a/include/util/tdef.h b/include/util/tdef.h index 84bc30b9e7..55194d8647 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -331,12 +331,12 @@ typedef enum ELogicConditionType { #define TSDB_DB_STRICT_OFF 0 #define TSDB_DB_STRICT_ON 1 #define TSDB_DEFAULT_DB_STRICT 0 -#define TSDB_MIN_DB_CACHE_LAST_ROW 0 -#define TSDB_MAX_DB_CACHE_LAST_ROW 3 -#define TSDB_DEFAULT_CACHE_LAST_ROW 0 -#define TSDB_MIN_DB_LAST_ROW_MEM 1 // MB -#define TSDB_MAX_DB_LAST_ROW_MEM 65536 -#define TSDB_DEFAULT_LAST_ROW_MEM 1 +#define TSDB_MIN_DB_CACHE_LAST 0 +#define TSDB_MAX_DB_CACHE_LAST 3 +#define TSDB_DEFAULT_CACHE_LAST 0 +#define TSDB_MIN_DB_CACHE_LAST_SIZE 1 // MB +#define TSDB_MAX_DB_CACHE_LAST_SIZE 65536 +#define TSDB_DEFAULT_CACHE_LAST_SIZE 1 #define TSDB_DB_STREAM_MODE_OFF 0 #define TSDB_DB_STREAM_MODE_ON 1 #define TSDB_DEFAULT_DB_STREAM_MODE 0 diff --git a/include/util/tlockfree.h b/include/util/tlockfree.h index 44e43f81cf..54a90d7b71 100644 --- a/include/util/tlockfree.h +++ b/include/util/tlockfree.h @@ -69,13 +69,14 @@ typedef void (*_ref_fn_t)(const void *pObj); #define T_REF_VAL_GET(x) (x)->_ref.val // single writer multiple reader lock -typedef volatile int32_t SRWLatch; +typedef volatile int64_t SRWLatch; -void taosInitRWLatch(SRWLatch *pLatch); -void taosWLockLatch(SRWLatch *pLatch); -void taosWUnLockLatch(SRWLatch *pLatch); -void taosRLockLatch(SRWLatch *pLatch); -void taosRUnLockLatch(SRWLatch *pLatch); +void taosInitRWLatch(SRWLatch *pLatch); +void taosInitReentrantRWLatch(SRWLatch *pLatch); +void taosWLockLatch(SRWLatch *pLatch); +void taosWUnLockLatch(SRWLatch *pLatch); +void taosRLockLatch(SRWLatch *pLatch); +void taosRUnLockLatch(SRWLatch *pLatch); int32_t taosWTryLockLatch(SRWLatch *pLatch); // copy on read diff --git a/include/util/tlog.h b/include/util/tlog.h index a519aaa9b7..a8c9eeabde 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -94,7 +94,7 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons #define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); } #define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); } // clang-format on - +#define BUF_PAGE_DEBUG #ifdef __cplusplus } #endif diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index bcc2df4b91..77817e5cf6 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -30,6 +30,7 @@ configDir="/etc/taos" installDir="/usr/local/taos" adapterName="taosadapter" benchmarkName="taosBenchmark" +tmqName="tmq_sim" dumpName="taosdump" demoName="taosdemo" @@ -205,6 +206,7 @@ function install_bin() { [ -x ${install_main_dir}/bin/${adapterName} ] && ${csudo}ln -s ${install_main_dir}/bin/${adapterName} ${bin_link_dir}/${adapterName} || : [ -x ${install_main_dir}/bin/${benchmarkName} ] && ${csudo}ln -s ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${demoName} || : [ -x ${install_main_dir}/bin/${benchmarkName} ] && ${csudo}ln -s ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${benchmarkName} || : + [ -x ${install_main_dir}/bin/${tmqName} ] && ${csudo}ln -s ${install_main_dir}/bin/${tmqName} ${bin_link_dir}/${tmqName} || : [ -x ${install_main_dir}/bin/${dumpName} ] && ${csudo}ln -s ${install_main_dir}/bin/${dumpName} ${bin_link_dir}/${dumpName} || : [ -x ${install_main_dir}/bin/TDinsight.sh ] && ${csudo}ln -s ${install_main_dir}/bin/TDinsight.sh ${bin_link_dir}/TDinsight.sh || : [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript} || : diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 8ad42811d4..680fa6736b 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -305,18 +305,23 @@ function install_lib() { ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/libtaos.so.${verNumber} - ${csudo}cp ${binary_dir}/build/lib/libtaosws.so \ - ${install_main_dir}/driver && - ${csudo}chmod 777 ${install_main_dir}/driver/libtaosws.so - ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 ${csudo}ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so - ${csudo}ln -sf ${install_main_dir}/driver/libtaosws.so ${lib_link_dir}/libtaosws.so || : - if [ -d "${lib64_link_dir}" ]; then - ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 - ${csudo}ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so - ${csudo}ln -sf ${lib64_link_dir}/libtaosws.so ${lib64_link_dir}/libtaosws.so || : + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 + ${csudo}ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so + fi + + if [ -f ${binary_dir}/build/lib/libtaosws.so ]; then + ${csudo}cp ${binary_dir}/build/lib/libtaosws.so \ + ${install_main_dir}/driver && + ${csudo}chmod 777 ${install_main_dir}/driver/libtaosws.so ||: + + ${csudo}ln -sf ${install_main_dir}/driver/libtaosws.so ${lib_link_dir}/libtaosws.so || : + + if [ -d "${lib64_link_dir}" ]; then + ${csudo}ln -sf ${lib64_link_dir}/libtaosws.so ${lib64_link_dir}/libtaosws.so || : + fi fi else ${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \ @@ -357,26 +362,26 @@ function install_header() { if [ "$osType" != "Darwin" ]; then ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || : + ${csudo}rm -f ${inc_link_dir}/taosws.h ||: ${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h ${source_dir}/include/libs/function/taosudf.h \ - ${csudo}rm -f ${inc_link_dir}/taosws.h || : - - ${csudo}cp -f ${source_dir}/src/inc/taos.h ${source_dir}/src/inc/taosdef.h ${source_dir}/src/inc/taoserror.h \ ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* - ${csudo}cp -f ${binary_dir}/build/include/taosws.h ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/taosws.h + if [ -f ${binary_dir}/build/include/taosws.h ]; then + ${csudo}cp -f ${binary_dir}/build/include/taosws.h ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/taosws.h ||: + ${csudo}ln -s ${install_main_dir}/include/taosws.h ${inc_link_dir}/taosws.h ||: + fi ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h ${csudo}ln -s ${install_main_dir}/include/taosudf.h ${inc_link_dir}/taosudf.h - ${csudo}ln -s ${install_main_dir}/include/taosws.h ${inc_link_dir}/taosws.h || : else ${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h ${source_dir}/include/libs/function/taosudf.h \ ${install_main_dir}/include || ${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h ${source_dir}/include/libs/function/taosudf.h \ ${install_main_2_dir}/include && - ${csudo}chmod 644 ${install_main_dir}/include/* || + ${csudo}chmod 644 ${install_main_dir}/include/* ||: ${csudo}chmod 644 ${install_main_2_dir}/include/* fi } diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 2965a02b49..7edab2141b 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -60,7 +60,7 @@ if [ "$pagMode" == "lite" ]; then strip ${build_dir}/bin/${serverName} strip ${build_dir}/bin/${clientName} # lite version doesn't include taosadapter, which will lead to no restful interface - bin_files="${build_dir}/bin/${serverName} ${build_dir}/bin/${clientName} ${script_dir}/remove.sh ${script_dir}/startPre.sh ${build_dir}/bin/taosBenchmark" + bin_files="${build_dir}/bin/${serverName} ${build_dir}/bin/${clientName} ${script_dir}/remove.sh ${script_dir}/startPre.sh ${build_dir}/bin/taosBenchmark ${build_dir}/bin/tmq_sim" taostools_bin_files="" else @@ -78,6 +78,7 @@ else taostools_bin_files=" ${build_dir}/bin/taosdump \ ${build_dir}/bin/taosBenchmark \ + ${build_dir}/bin/tmq_sim \ ${build_dir}/bin/TDinsight.sh \ $tdinsight_caches" diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 9380b73d2d..91f21f6e6a 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -222,8 +222,8 @@ typedef struct SRequestObj { SArray* tableList; SQueryExecMetric metric; SRequestSendRecvBody body; - bool stableQuery; - bool validateOnly; + bool stableQuery; // todo refactor + bool validateOnly; // todo refactor bool killed; uint32_t prevCode; // previous error code: todo refactor, add update flag for catalog @@ -247,9 +247,9 @@ void doFreeReqResultInfo(SReqResultInfo* pResInfo); int32_t transferTableNameList(const char* tbList, int32_t acctId, char* dbName, SArray** pReq); void syncCatalogFn(SMetaData* pResult, void* param, int32_t code); -SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool validateOnly); +SRequestObj* execQuery(uint64_t connId, const char* sql, int sqlLen, bool validateOnly); TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly); -void taosAsyncQueryImpl(TAOS* taos, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly); +void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly); static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) { SMqRspObj* msg = (SMqRspObj*)res; @@ -297,7 +297,7 @@ int32_t releaseTscObj(int64_t rid); uint64_t generateRequestId(); -void* createRequest(STscObj* pObj, int32_t type); +void* createRequest(uint64_t connId, int32_t type); void destroyRequest(SRequestObj* pRequest); SRequestObj* acquireRequest(int64_t rid); int32_t releaseRequest(int64_t rid); @@ -318,13 +318,13 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet); STscObj* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, uint16_t port, int connType); -SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool validateOnly); +SRequestObj* launchQuery(uint64_t connId, const char* sql, int sqlLen, bool validateOnly); int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb); int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); -int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest); +int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, SRequestObj** pRequest); void taos_close_internal(void* taos); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 89ecf16b40..ba92ed238b 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -49,13 +49,8 @@ void cleanupTscQhandle() { // destroy handle taosCleanUpScheduler(tscQhandle); } -static int32_t registerRequest(SRequestObj *pRequest) { - STscObj *pTscObj = acquireTscObj(pRequest->pTscObj->id); - if (NULL == pTscObj) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return terrno; - } +static int32_t registerRequest(SRequestObj *pRequest, STscObj* pTscObj) { // connection has been released already, abort creating request. pRequest->self = taosAddRef(clientReqRefPool, pRequest); @@ -246,29 +241,34 @@ STscObj *acquireTscObj(int64_t rid) { return (STscObj *)taosAcquireRef(clientCon int32_t releaseTscObj(int64_t rid) { return taosReleaseRef(clientConnRefPool, rid); } -void *createRequest(STscObj *pObj, int32_t type) { - assert(pObj != NULL); - +void *createRequest(uint64_t connId, int32_t type) { SRequestObj *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj)); if (NULL == pRequest) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; } + STscObj* pTscObj = acquireTscObj(connId); + if (pTscObj == NULL) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + pRequest->resType = RES_TYPE__QUERY; - pRequest->pDb = getDbOfConnection(pObj); pRequest->requestId = generateRequestId(); pRequest->metric.start = taosGetTimestampUs(); pRequest->body.resInfo.convertUcs4 = true; // convert ucs4 by default - pRequest->type = type; - pRequest->pTscObj = pObj; + + pRequest->pDb = getDbOfConnection(pTscObj); + pRequest->pTscObj = pTscObj; + pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE); pRequest->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE; tsem_init(&pRequest->body.rspSem, 0, 0); - if (registerRequest(pRequest)) { + if (registerRequest(pRequest, pTscObj)) { doDestroyRequest(pRequest); return NULL; } @@ -327,8 +327,8 @@ void doDestroyRequest(void *p) { if (pRequest->self) { deregisterRequest(pRequest); } - taosMemoryFree(pRequest); + taosMemoryFree(pRequest); tscTrace("end to destroy request %" PRIx64 " p:%p", reqId, pRequest); } @@ -338,7 +338,6 @@ void destroyRequest(SRequestObj *pRequest) { } taos_stop_query(pRequest); - removeRequest(pRequest->self); } diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 48fa2d7938..e2d75d39e3 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -264,15 +264,12 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) { static int32_t emptyRspNum = 0; - if (code != 0) { - taosMemoryFreeClear(param); - return -1; - } - char *key = (char *)param; SClientHbBatchRsp pRsp = {0}; - tDeserializeSClientHbBatchRsp(pMsg->pData, pMsg->len, &pRsp); - + if (TSDB_CODE_SUCCESS == code) { + tDeserializeSClientHbBatchRsp(pMsg->pData, pMsg->len, &pRsp); + } + int32_t rspNum = taosArrayGetSize(pRsp.rsps); taosThreadMutexLock(&appInfo.mutex); @@ -288,6 +285,10 @@ static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) { taosMemoryFreeClear(param); + if (code != 0) { + (*pInst)->onlineDnodes = 0; + } + if (rspNum) { tscDebug("hb got %d rsp, %d empty rsp received before", rspNum, atomic_val_compare_exchange_32(&emptyRspNum, emptyRspNum, 0)); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index bff65d3527..25ba63fd34 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -148,29 +148,50 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst, connType); } -int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest) { - *pRequest = createRequest(pTscObj, TSDB_SQL_SELECT); +int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, + SRequestObj** pRequest) { + *pRequest = createRequest(connId, TSDB_SQL_SELECT); if (*pRequest == NULL) { - tscError("failed to malloc sqlObj"); + tscError("failed to malloc sqlObj, %s", sql); return TSDB_CODE_TSC_OUT_OF_MEMORY; } (*pRequest)->sqlstr = taosMemoryMalloc(sqlLen + 1); if ((*pRequest)->sqlstr == NULL) { - tscError("0x%" PRIx64 " failed to prepare sql string buffer", (*pRequest)->self); - (*pRequest)->msgBuf = strdup("failed to prepare sql string buffer"); + tscError("0x%" PRIx64 " failed to prepare sql string buffer, %s", (*pRequest)->self, sql); + destroyRequest(*pRequest); + *pRequest = NULL; return TSDB_CODE_TSC_OUT_OF_MEMORY; } strntolower((*pRequest)->sqlstr, sql, (int32_t)sqlLen); (*pRequest)->sqlstr[sqlLen] = 0; (*pRequest)->sqlLen = sqlLen; + (*pRequest)->validateOnly = validateSql; + if (param == NULL) { + SSyncQueryParam* pParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam)); + if (pParam == NULL) { + destroyRequest(*pRequest); + *pRequest = NULL; + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + tsem_init(&pParam->sem, 0, 0); + pParam->pRequest = (*pRequest); + param = pParam; + } + + (*pRequest)->body.param = param; + + STscObj* pTscObj = (*pRequest)->pTscObj; if (taosHashPut(pTscObj->pRequests, &(*pRequest)->self, sizeof((*pRequest)->self), &(*pRequest)->self, sizeof((*pRequest)->self))) { + tscError("%d failed to add to request container, reqId:0x%" PRIx64 ", conn:%d, %s", (*pRequest)->self, + (*pRequest)->requestId, pTscObj->id, sql); + destroyRequest(*pRequest); *pRequest = NULL; - tscError("put request to request hash failed"); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -325,11 +346,14 @@ int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList) { if (pInfo->pQnodeList) { taosArrayDestroy(pInfo->pQnodeList); pInfo->pQnodeList = NULL; + tscDebug("QnodeList cleared in cluster 0x%" PRIx64, pInfo->clusterId); } if (pNodeList) { pInfo->pQnodeList = taosArrayDup(pNodeList); taosArraySort(pInfo->pQnodeList, compareQueryNodeLoad); + tscDebug("QnodeList updated in cluster 0x%" PRIx64 ", num:%d", pInfo->clusterId, + taosArrayGetSize(pInfo->pQnodeList)); } taosThreadMutexUnlock(&pInfo->qnodeMutex); @@ -627,22 +651,22 @@ _return: int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) { void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter; - SExecResult res = {0}; + SExecResult res = {0}; SRequestConnInfo conn = {.pTrans = pRequest->pTscObj->pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; SSchedulerReq req = { - .syncReq = true, - .pConn = &conn, - .pNodeList = pNodeList, - .pDag = pDag, - .sql = pRequest->sqlstr, - .startTs = pRequest->metric.start, - .execFp = NULL, - .cbParam = NULL, - .chkKillFp = chkRequestKilled, - .chkKillParam = (void*)pRequest->self, - .pExecRes = &res, + .syncReq = true, + .pConn = &conn, + .pNodeList = pNodeList, + .pDag = pDag, + .sql = pRequest->sqlstr, + .startTs = pRequest->metric.start, + .execFp = NULL, + .cbParam = NULL, + .chkKillFp = chkRequestKilled, + .chkKillParam = (void*)pRequest->self, + .pExecRes = &res, }; int32_t code = schedulerExecJob(&req, &pRequest->body.queryJob); @@ -756,7 +780,7 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) { return code; } - SEpSet epset = getEpSet_s(&pAppInfo->mgmtEp); + SEpSet epset = getEpSet_s(&pAppInfo->mgmtEp); SExecResult* pRes = &pRequest->body.resInfo.execRes; switch (pRes->msgType) { @@ -786,11 +810,16 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) { void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) { SRequestObj* pRequest = (SRequestObj*)param; pRequest->code = code; - memcpy(&pRequest->body.resInfo.execRes, pResult, sizeof(*pResult)); + + if (pResult) { + memcpy(&pRequest->body.resInfo.execRes, pResult, sizeof(*pResult)); + } if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_DELETE == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) { - pRequest->body.resInfo.numOfRows = pResult->numOfRows; + if (pResult) { + pRequest->body.resInfo.numOfRows = pResult->numOfRows; + } schedulerFreeJob(&pRequest->body.queryJob, 0); } @@ -880,18 +909,16 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue return pRequest; } -SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool validateOnly) { +SRequestObj* launchQuery(uint64_t connId, const char* sql, int sqlLen, bool validateOnly) { SRequestObj* pRequest = NULL; SQuery* pQuery = NULL; - int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); + int32_t code = buildRequest(connId, sql, sqlLen, NULL, validateOnly, &pRequest); if (code != TSDB_CODE_SUCCESS) { terrno = code; return NULL; } - pRequest->validateOnly = validateOnly; - code = parseSql(pRequest, false, &pQuery, NULL); if (code != TSDB_CODE_SUCCESS) { pRequest->code = code; @@ -944,17 +971,17 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM SRequestConnInfo conn = { .pTrans = pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; SSchedulerReq req = { - .syncReq = false, - .pConn = &conn, - .pNodeList = pNodeList, - .pDag = pDag, - .sql = pRequest->sqlstr, - .startTs = pRequest->metric.start, - .execFp = schedulerExecCb, - .cbParam = pRequest, - .chkKillFp = chkRequestKilled, - .chkKillParam = (void*)pRequest->self, - .pExecRes = NULL, + .syncReq = false, + .pConn = &conn, + .pNodeList = pNodeList, + .pDag = pDag, + .sql = pRequest->sqlstr, + .startTs = pRequest->metric.start, + .execFp = schedulerExecCb, + .cbParam = pRequest, + .chkKillFp = chkRequestKilled, + .chkKillParam = (void*)pRequest->self, + .pExecRes = NULL, }; code = schedulerExecJob(&req, &pRequest->body.queryJob); taosArrayDestroy(pNodeList); @@ -973,6 +1000,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM pRequest->body.queryFp(pRequest->body.param, pRequest, 0); break; default: + pRequest->body.queryFp(pRequest->body.param, pRequest, -1); break; } @@ -1042,19 +1070,20 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList) { return TSDB_CODE_SUCCESS; } -SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool validateOnly) { +// todo remove it soon +SRequestObj* execQuery(uint64_t connId, const char* sql, int sqlLen, bool validateOnly) { SRequestObj* pRequest = NULL; int32_t retryNum = 0; int32_t code = 0; do { destroyRequest(pRequest); - pRequest = launchQuery(pTscObj, sql, sqlLen, validateOnly); + pRequest = launchQuery(connId, sql, sqlLen, validateOnly); if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) { break; } - code = refreshMeta(pTscObj, pRequest); + code = refreshMeta(pRequest->pTscObj, pRequest); if (code) { pRequest->code = code; break; @@ -1062,7 +1091,7 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool valid } while (retryNum++ < REQUEST_TOTAL_EXEC_TIMES); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { - removeMeta(pTscObj, pRequest->tableList); + removeMeta(pRequest->pTscObj, pRequest->tableList); } return pRequest; @@ -1117,7 +1146,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t return pTscObj; } - SRequestObj* pRequest = createRequest(pTscObj, TDMT_MND_CONNECT); + SRequestObj* pRequest = createRequest(pTscObj->id, TDMT_MND_CONNECT); if (pRequest == NULL) { destroyTscObj(pTscObj); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -1395,9 +1424,9 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) } SReqResultInfo* pResInfo = &pRequest->body.resInfo; - SSchedulerReq req = { - .syncReq = true, - .pFetchRes = (void**)&pResInfo->pData, + SSchedulerReq req = { + .syncReq = true, + .pFetchRes = (void**)&pResInfo->pData, }; pRequest->code = schedulerFetchRows(pRequest->body.queryJob, &req); if (pRequest->code != TSDB_CODE_SUCCESS) { @@ -1444,25 +1473,24 @@ void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertU return NULL; } - SSyncQueryParam* pParam = pRequest->body.param; - if (NULL == pParam) { - pParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam)); - tsem_init(&pParam->sem, 0, 0); - } - // convert ucs4 to native multi-bytes string pResultInfo->convertUcs4 = convertUcs4; + SSyncQueryParam* pParam = pRequest->body.param; taos_fetch_rows_a(pRequest, syncFetchFn, pParam); tsem_wait(&pParam->sem); } - if (pRequest->code == TSDB_CODE_SUCCESS && pResultInfo->numOfRows > 0 && setupOneRowPtr) { - doSetOneRowPtr(pResultInfo); - pResultInfo->current += 1; - } + if (pResultInfo->numOfRows == 0 || pRequest->code != TSDB_CODE_SUCCESS) { + return NULL; + } else { + if (setupOneRowPtr) { + doSetOneRowPtr(pResultInfo); + pResultInfo->current += 1; + } - return pResultInfo->row; + return pResultInfo->row; + } } static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { @@ -2024,22 +2052,9 @@ void syncQueryFn(void* param, void* res, int32_t code) { tsem_post(&pParam->sem); } -void taosAsyncQueryImpl(TAOS* taos, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly) { - if (NULL == taos) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - fp(param, NULL, terrno); - return; - } - - int64_t rid = *(int64_t*)taos; - STscObj* pTscObj = acquireTscObj(rid); - if (pTscObj == NULL || sql == NULL || NULL == fp) { +void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly) { + if (sql == NULL || NULL == fp) { terrno = TSDB_CODE_INVALID_PARA; - if (pTscObj) { - releaseTscObj(rid); - } else { - terrno = TSDB_CODE_TSC_DISCONNECTED; - } fp(param, NULL, terrno); return; } @@ -2048,26 +2063,20 @@ void taosAsyncQueryImpl(TAOS* taos, const char* sql, __taos_async_fn_t fp, void* if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) { tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; - releaseTscObj(rid); - fp(param, NULL, terrno); return; } SRequestObj* pRequest = NULL; - int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); + int32_t code = buildRequest(connId, sql, sqlLen, param, validateOnly, &pRequest); if (code != TSDB_CODE_SUCCESS) { terrno = code; - releaseTscObj(rid); fp(param, NULL, terrno); return; } - pRequest->validateOnly = validateOnly; pRequest->body.queryFp = fp; - pRequest->body.param = param; doAsyncQuery(pRequest, false); - releaseTscObj(rid); } TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) { @@ -2076,36 +2085,22 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) { return NULL; } - int64_t rid = *(int64_t*)taos; - STscObj* pTscObj = acquireTscObj(rid); - if (pTscObj == NULL || sql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return NULL; - } - #if SYNC_ON_TOP_OF_ASYNC SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(SSyncQueryParam)); tsem_init(¶m->sem, 0, 0); - taosAsyncQueryImpl((TAOS*)&rid, sql, syncQueryFn, param, validateOnly); + taosAsyncQueryImpl(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly); tsem_wait(¶m->sem); - - releaseTscObj(rid); - return param->pRequest; #else size_t sqlLen = strlen(sql); if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) { - releaseTscObj(rid); tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; return NULL; } - TAOS_RES* pRes = execQuery(pTscObj, sql, sqlLen, validateOnly); - - releaseTscObj(rid); - + TAOS_RES* pRes = execQuery(connId, sql, sqlLen, validateOnly); return pRes; #endif } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index e908046b1e..12de522cbc 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -479,7 +479,6 @@ void taos_stop_query(TAOS_RES *res) { } schedulerFreeJob(&pRequest->body.queryJob, TSDB_CODE_TSC_QUERY_KILLED); - tscDebug("request %" PRIx64 " killed", pRequest->requestId); } @@ -706,7 +705,8 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { } void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) { - taosAsyncQueryImpl(taos, sql, fp, param, false); + int64_t connId = *(int64_t*)taos; + taosAsyncQueryImpl(connId, sql, fp, param, false); } int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) { @@ -915,7 +915,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { return terrno; } - int64_t rid = *(int64_t *)taos; + int64_t connId = *(int64_t *)taos; const int32_t MAX_TABLE_NAME_LENGTH = 12 * 1024 * 1024; // 12MB list int32_t code = 0; SRequestObj * pRequest = NULL; @@ -933,12 +933,14 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { return TSDB_CODE_TSC_INVALID_OPERATION; } - STscObj *pTscObj = acquireTscObj(rid); - if (pTscObj == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return terrno; + char *sql = "taos_load_table_info"; + code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + goto _return; } + STscObj* pTscObj = pRequest->pTscObj; code = transferTableNameList(tableNameList, pTscObj->acctId, pTscObj->db, &catalogReq.pTableMeta); if (code) { goto _return; @@ -950,36 +952,22 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { goto _return; } - char *sql = "taos_load_table_info"; - code = buildRequest(pTscObj, sql, strlen(sql), &pRequest); - if (code != TSDB_CODE_SUCCESS) { - terrno = code; - goto _return; - } - - SSyncQueryParam param = {0}; - tsem_init(¶m.sem, 0, 0); - param.pRequest = pRequest; - SRequestConnInfo conn = { .pTrans = pTscObj->pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); - code = catalogAsyncGetAllMeta(pCtg, &conn, &catalogReq, syncCatalogFn, ¶m, NULL); + code = catalogAsyncGetAllMeta(pCtg, &conn, &catalogReq, syncCatalogFn, NULL, NULL); if (code) { goto _return; } - tsem_wait(¶m.sem); + SSyncQueryParam* pParam = pRequest->body.param; + tsem_wait(&pParam->sem); _return: - taosArrayDestroy(catalogReq.pTableMeta); destroyRequest(pRequest); - - releaseTscObj(rid); - return code; } diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 5039f8bbaf..6e689adf95 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -1570,41 +1570,40 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV return TSDB_CODE_TSC_INVALID_TIME_STAMP; } + *tsVal = timeDouble; size_t typeLen = strlen(type->valuestring); if (typeLen == 1 && (type->valuestring[0] == 's' || type->valuestring[0] == 'S')) { // seconds - timeDouble = timeDouble * 1e9; + *tsVal = *tsVal * NANOSECOND_PER_SEC; + timeDouble = timeDouble * NANOSECOND_PER_SEC; if (smlDoubleToInt64OverFlow(timeDouble)) { smlBuildInvalidDataMsg(&info->msgBuf, "timestamp is too large", NULL); return TSDB_CODE_TSC_INVALID_TIME_STAMP; } - *tsVal = timeDouble; } else if (typeLen == 2 && (type->valuestring[1] == 's' || type->valuestring[1] == 'S')) { switch (type->valuestring[0]) { case 'm': case 'M': // milliseconds - timeDouble = timeDouble * 1e6; + *tsVal = *tsVal * NANOSECOND_PER_MSEC; + timeDouble = timeDouble * NANOSECOND_PER_MSEC; if (smlDoubleToInt64OverFlow(timeDouble)) { smlBuildInvalidDataMsg(&info->msgBuf, "timestamp is too large", NULL); return TSDB_CODE_TSC_INVALID_TIME_STAMP; } - *tsVal = timeDouble; break; case 'u': case 'U': // microseconds - timeDouble = timeDouble * 1e3; + *tsVal = *tsVal * NANOSECOND_PER_USEC; + timeDouble = timeDouble * NANOSECOND_PER_USEC; if (smlDoubleToInt64OverFlow(timeDouble)) { smlBuildInvalidDataMsg(&info->msgBuf, "timestamp is too large", NULL); return TSDB_CODE_TSC_INVALID_TIME_STAMP; } - *tsVal = timeDouble; break; case 'n': case 'N': - // nanoseconds - *tsVal = timeDouble; break; default: return TSDB_CODE_TSC_INVALID_JSON; @@ -1641,21 +1640,23 @@ static int32_t smlParseTSFromJSON(SSmlHandle *info, cJSON *root, SArray *cols) { if (timeDouble < 0) { return TSDB_CODE_TSC_INVALID_TIME_STAMP; } + uint8_t tsLen = smlGetTimestampLen((int64_t)timeDouble); + tsVal = (int64_t)timeDouble; if (tsLen == TSDB_TIME_PRECISION_SEC_DIGITS) { - timeDouble = timeDouble * 1e9; + tsVal = tsVal * NANOSECOND_PER_SEC; + timeDouble = timeDouble * NANOSECOND_PER_SEC; if (smlDoubleToInt64OverFlow(timeDouble)) { smlBuildInvalidDataMsg(&info->msgBuf, "timestamp is too large", NULL); return TSDB_CODE_TSC_INVALID_TIME_STAMP; } - tsVal = timeDouble; } else if (tsLen == TSDB_TIME_PRECISION_MILLI_DIGITS) { - timeDouble = timeDouble * 1e6; + tsVal = tsVal * NANOSECOND_PER_MSEC; + timeDouble = timeDouble * NANOSECOND_PER_MSEC; if (smlDoubleToInt64OverFlow(timeDouble)) { smlBuildInvalidDataMsg(&info->msgBuf, "timestamp is too large", NULL); return TSDB_CODE_TSC_INVALID_TIME_STAMP; } - tsVal = timeDouble; } else if (timeDouble == 0) { tsVal = taosGetTimestampNs(); } else { @@ -2441,22 +2442,15 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr return NULL; } - int64_t rid = *(int64_t*)taos; - STscObj* pTscObj = acquireTscObj(rid); - if (NULL == pTscObj) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - uError("SML:taos_schemaless_insert invalid taos"); - return NULL; - } - - SRequestObj* request = (SRequestObj*)createRequest(pTscObj, TSDB_SQL_INSERT); + SRequestObj* request = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT); if(!request){ - releaseTscObj(rid); uError("SML:taos_schemaless_insert error request is null"); return NULL; } int batchs = 0; + STscObj* pTscObj = request->pTscObj; + pTscObj->schemalessType = 1; SSmlMsgBuf msg = {ERROR_MSG_BUF_DEFAULT_SIZE, request->msgBuf}; @@ -2506,7 +2500,7 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr batchs = ceil(((double)numLines) / LINE_BATCH); for (int i = 0; i < batchs; ++i) { - SRequestObj* req = (SRequestObj*)createRequest(pTscObj, TSDB_SQL_INSERT); + SRequestObj* req = (SRequestObj*)createRequest(pTscObj->id, TSDB_SQL_INSERT); if(!req){ request->code = TSDB_CODE_OUT_OF_MEMORY; uError("SML:taos_schemaless_insert error request is null"); @@ -2548,6 +2542,5 @@ end: // ((STscObj *)taos)->schemalessType = 0; pTscObj->schemalessType = 1; uDebug("resultend:%s", request->msgBuf); - releaseTscObj(rid); return (TAOS_RES*)request; } diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 1e0f30695d..d653b8720f 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -5,6 +5,14 @@ #include "clientStmt.h" +static int32_t stmtCreateRequest(STscStmt* pStmt) { + if (pStmt->exec.pRequest == NULL) { + return buildRequest(pStmt->taos->id, pStmt->sql.sqlStr, pStmt->sql.sqlLen, NULL, false, &pStmt->exec.pRequest); + } else { + return TSDB_CODE_SUCCESS; + } +} + int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) { int32_t code = 0; @@ -217,9 +225,7 @@ int32_t stmtParseSql(STscStmt* pStmt) { .getExecInfoFn = stmtGetExecInfo, }; - if (NULL == pStmt->exec.pRequest) { - STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); - } + STMT_ERR_RET(stmtCreateRequest(pStmt)); STMT_ERR_RET(parseSql(pStmt->exec.pRequest, false, &pStmt->sql.pQuery, &stmtCb)); @@ -532,9 +538,7 @@ int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); } - if (NULL == pStmt->exec.pRequest) { - STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); - } + STMT_ERR_RET(stmtCreateRequest(pStmt)); STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen)); @@ -625,9 +629,7 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { pStmt->exec.pRequest = NULL; } - if (NULL == pStmt->exec.pRequest) { - STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); - } + STMT_ERR_RET(stmtCreateRequest(pStmt)); if (pStmt->bInfo.needParse) { STMT_ERR_RET(stmtParseSql(pStmt)); @@ -873,9 +875,7 @@ int stmtGetTagFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { pStmt->exec.pRequest = NULL; } - if (NULL == pStmt->exec.pRequest) { - STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); - } + STMT_ERR_RET(stmtCreateRequest(pStmt)); if (pStmt->bInfo.needParse) { STMT_ERR_RET(stmtParseSql(pStmt)); @@ -905,9 +905,7 @@ int stmtGetColFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { pStmt->exec.pRequest = NULL; } - if (NULL == pStmt->exec.pRequest) { - STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); - } + STMT_ERR_RET(stmtCreateRequest(pStmt)); if (pStmt->bInfo.needParse) { STMT_ERR_RET(stmtParseSql(pStmt)); @@ -933,10 +931,7 @@ int stmtGetParamNum(TAOS_STMT* stmt, int* nums) { pStmt->exec.pRequest = NULL; } - if (NULL == pStmt->exec.pRequest) { - STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); - } - + STMT_ERR_RET(stmtCreateRequest(pStmt)); if (pStmt->bInfo.needParse) { STMT_ERR_RET(stmtParseSql(pStmt)); } @@ -969,9 +964,7 @@ int stmtGetParam(TAOS_STMT* stmt, int idx, int* type, int* bytes) { pStmt->exec.pRequest = NULL; } - if (NULL == pStmt->exec.pRequest) { - STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); - } + STMT_ERR_RET(stmtCreateRequest(pStmt)); if (pStmt->bInfo.needParse) { STMT_ERR_RET(stmtParseSql(pStmt)); diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 2132f7a2d6..110b839216 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include "cJSON.h" #include "clientInt.h" #include "clientLog.h" #include "parser.h" @@ -23,7 +24,6 @@ #include "tqueue.h" #include "tref.h" #include "ttimer.h" -#include "cJSON.h" int32_t tmqAskEp(tmq_t* tmq, bool async); @@ -106,6 +106,12 @@ struct tmq_t { tsem_t rspSem; }; +struct tmq_raw_data { + void* raw_meta; + int32_t raw_meta_len; + int16_t raw_meta_type; +}; + enum { TMQ_VG_STATUS__IDLE = 0, TMQ_VG_STATUS__WAIT, @@ -396,7 +402,7 @@ int32_t tmqCommitCb2(void* param, SDataBuf* pBuf, int32_t code) { } #endif - /*tscDebug("receive offset commit cb of %s on vg %d, offset is %ld", pParam->pOffset->subKey, pParam->->vgId, + /*tscDebug("receive offset commit cb of %s on vgId:%d, offset is %" PRId64, pParam->pOffset->subKey, pParam->->vgId, * pOffset->version);*/ // count down waiting rsp @@ -471,8 +477,8 @@ static int32_t tmqSendCommitReq(tmq_t* tmq, SMqClientVg* pVg, SMqClientTopic* pT .handle = NULL, }; - tscDebug("consumer %ld commit offset of %s on vg %d, offset is %ld", tmq->consumerId, pOffset->subKey, pVg->vgId, - pOffset->val.version); + tscDebug("consumer:%" PRId64 ", commit offset of %s on vgId:%d, offset is %" PRId64, tmq->consumerId, pOffset->subKey, + pVg->vgId, pOffset->val.version); // TODO: put into cb pVg->committedOffsetNew = pVg->currentOffsetNew; @@ -585,13 +591,14 @@ int32_t tmqCommitInner2(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_ for (int32_t i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) { SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i); - tscDebug("consumer %ld begin commit for topic %s, vgNum %d", tmq->consumerId, pTopic->topicName, + tscDebug("consumer:%" PRId64 ", begin commit for topic %s, vgNum %d", tmq->consumerId, pTopic->topicName, (int32_t)taosArrayGetSize(pTopic->vgs)); for (int32_t j = 0; j < taosArrayGetSize(pTopic->vgs); j++) { SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j); - tscDebug("consumer %ld begin commit for topic %s, vgId %d", tmq->consumerId, pTopic->topicName, pVg->vgId); + tscDebug("consumer:%" PRId64 ", begin commit for topic %s, vgId:%d", tmq->consumerId, pTopic->topicName, + pVg->vgId); if (pVg->currentOffsetNew.type > 0 && !tOffsetEqual(&pVg->currentOffsetNew, &pVg->committedOffsetNew)) { if (tmqSendCommitReq(tmq, pVg, pTopic, pParamSet) < 0) { @@ -894,6 +901,8 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t)); if (pTmq == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + tscError("consumer %ld setup failed since %s, consumer group %s", pTmq->consumerId, terrstr(), pTmq->groupId); return NULL; } @@ -910,6 +919,8 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { pTmq->delayedTask = taosOpenQueue(); if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + tscError("consumer %ld setup failed since %s, consumer group %s", pTmq->consumerId, terrstr(), pTmq->groupId); goto FAIL; } @@ -936,16 +947,20 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { // init semaphore if (tsem_init(&pTmq->rspSem, 0, 0) != 0) { + tscError("consumer %ld setup failed since %s, consumer group %s", pTmq->consumerId, terrstr(), pTmq->groupId); goto FAIL; } // init connection pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, NULL, conf->port, CONN_TYPE__TMQ); if (pTmq->pTscObj == NULL) { + tscError("consumer %ld setup failed since %s, consumer group %s", pTmq->consumerId, terrstr(), pTmq->groupId); tsem_destroy(&pTmq->rspSem); goto FAIL; } + tscInfo("consumer %ld is setup, consumer group %s", pTmq->consumerId, pTmq->groupId); + return pTmq; FAIL: @@ -1082,13 +1097,13 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { int32_t epoch = pParam->epoch; taosMemoryFree(pParam); if (code != 0) { - tscWarn("msg discard from vg %d, epoch %d, code:%x", vgId, epoch, code); + tscWarn("msg discard from vgId:%d, epoch %d, code:%x", vgId, epoch, code); if (pMsg->pData) taosMemoryFree(pMsg->pData); if (code == TSDB_CODE_TQ_NO_COMMITTED_OFFSET) { SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM); if (pRspWrapper == NULL) { taosMemoryFree(pMsg->pData); - tscWarn("msg discard from vg %d, epoch %d since out of memory", vgId, epoch); + tscWarn("msg discard from vgId:%d, epoch %d since out of memory", vgId, epoch); goto CREATE_MSG_FAIL; } pRspWrapper->tmqRspType = TMQ_MSG_TYPE__END_RSP; @@ -1104,7 +1119,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { int32_t tmqEpoch = atomic_load_32(&tmq->epoch); if (msgEpoch < tmqEpoch) { // do not write into queue since updating epoch reset - tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", vgId, msgEpoch, + tscWarn("msg discard from vgId:%d since from earlier epoch, rsp epoch %d, current epoch %d", vgId, msgEpoch, tmqEpoch); tsem_post(&tmq->rspSem); taosMemoryFree(pMsg->pData); @@ -1112,7 +1127,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { } if (msgEpoch != tmqEpoch) { - tscWarn("mismatch rsp from vg %d, epoch %d, current epoch %d", vgId, msgEpoch, tmqEpoch); + tscWarn("mismatch rsp from vgId:%d, epoch %d, current epoch %d", vgId, msgEpoch, tmqEpoch); } // handle meta rsp @@ -1121,7 +1136,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM); if (pRspWrapper == NULL) { taosMemoryFree(pMsg->pData); - tscWarn("msg discard from vg %d, epoch %d since out of memory", vgId, epoch); + tscWarn("msg discard from vgId:%d, epoch %d since out of memory", vgId, epoch); goto CREATE_MSG_FAIL; } @@ -1143,8 +1158,9 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { taosMemoryFree(pMsg->pData); - tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld, type %d", tmq->consumerId, pVg->vgId, - pRspWrapper->dataRsp.reqOffset.version, pRspWrapper->dataRsp.rspOffset.version, rspType); + tscDebug("consumer:%" PRId64 ", recv poll: vgId:%d, req offset %" PRId64 ", rsp offset %" PRId64 " type %d", + tmq->consumerId, pVg->vgId, pRspWrapper->dataRsp.reqOffset.version, pRspWrapper->dataRsp.rspOffset.version, + rspType); taosWriteQitem(tmq->mqueue, pRspWrapper); tsem_post(&tmq->rspSem); @@ -1163,7 +1179,7 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) { int32_t topicNumGet = taosArrayGetSize(pRsp->topics); char vgKey[TSDB_TOPIC_FNAME_LEN + 22]; - tscDebug("consumer %ld update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch, + tscDebug("consumer:%" PRId64 ", update ep epoch %d to epoch %d, topic num:%d", tmq->consumerId, tmq->epoch, epoch, topicNumGet); SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic)); @@ -1182,14 +1198,14 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) { SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, i); if (pTopicCur->vgs) { int32_t vgNumCur = taosArrayGetSize(pTopicCur->vgs); - tscDebug("consumer %ld new vg num: %d", tmq->consumerId, vgNumCur); + tscDebug("consumer:%" PRId64 ", new vg num: %d", tmq->consumerId, vgNumCur); for (int32_t j = 0; j < vgNumCur; j++) { SMqClientVg* pVgCur = taosArrayGet(pTopicCur->vgs, j); sprintf(vgKey, "%s:%d", pTopicCur->topicName, pVgCur->vgId); - char buf[50]; - tFormatOffset(buf, 50, &pVgCur->currentOffsetNew); - tscDebug("consumer %ld epoch %d vg %d vgKey is %s, offset is %s", tmq->consumerId, epoch, pVgCur->vgId, vgKey, - buf); + char buf[80]; + tFormatOffset(buf, 80, &pVgCur->currentOffsetNew); + tscDebug("consumer:%" PRId64 ", epoch %d vgId:%d vgKey is %s, offset is %s", tmq->consumerId, epoch, + pVgCur->vgId, vgKey, buf); taosHashPut(pHash, vgKey, strlen(vgKey), &pVgCur->currentOffsetNew, sizeof(STqOffsetVal)); } } @@ -1202,7 +1218,7 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) { topic.topicName = strdup(pTopicEp->topic); tstrncpy(topic.db, pTopicEp->db, TSDB_DB_FNAME_LEN); - tscDebug("consumer %ld update topic: %s", tmq->consumerId, topic.topicName); + tscDebug("consumer:%" PRId64 ", update topic: %s", tmq->consumerId, topic.topicName); int32_t vgNumGet = taosArrayGetSize(pTopicEp->vgs); topic.vgs = taosArrayInit(vgNumGet, sizeof(SMqClientVg)); @@ -1215,7 +1231,8 @@ bool tmqUpdateEp2(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) { offsetNew = *pOffset; } - /*tscDebug("consumer %ld(epoch %d) offset of vg %d updated to %ld, vgKey is %s", tmq->consumerId, epoch,*/ + /*tscDebug("consumer:%" PRId64 ", (epoch %d) offset of vgId:%d updated to %" PRId64 ", vgKey is %s", + * tmq->consumerId, epoch,*/ /*pVgEp->vgId, offset, vgKey);*/ SMqClientVg clientVg = { .pollCnt = 0, @@ -1249,7 +1266,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) { bool set = false; int32_t topicNumGet = taosArrayGetSize(pRsp->topics); char vgKey[TSDB_TOPIC_FNAME_LEN + 22]; - tscDebug("consumer %ld update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch, + tscDebug("consumer:%" PRId64 ", update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch, topicNumGet); SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic)); if (newTopics == NULL) { @@ -1270,19 +1287,19 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) { topic.topicName = strdup(pTopicEp->topic); tstrncpy(topic.db, pTopicEp->db, TSDB_DB_FNAME_LEN); - tscDebug("consumer %ld update topic: %s", tmq->consumerId, topic.topicName); + tscDebug("consumer:%" PRId64 ", update topic: %s", tmq->consumerId, topic.topicName); int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics); for (int32_t j = 0; j < topicNumCur; j++) { // find old topic SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, j); if (pTopicCur->vgs && strcmp(pTopicCur->topicName, pTopicEp->topic) == 0) { int32_t vgNumCur = taosArrayGetSize(pTopicCur->vgs); - tscDebug("consumer %ld new vg num: %d", tmq->consumerId, vgNumCur); + tscDebug("consumer:%" PRId64 ", new vg num: %d", tmq->consumerId, vgNumCur); if (vgNumCur == 0) break; for (int32_t k = 0; k < vgNumCur; k++) { SMqClientVg* pVgCur = taosArrayGet(pTopicCur->vgs, k); sprintf(vgKey, "%s:%d", topic.topicName, pVgCur->vgId); - tscDebug("consumer %ld epoch %d vg %d build %s", tmq->consumerId, epoch, pVgCur->vgId, vgKey); + tscDebug("consumer:%" PRId64 ", epoch %d vgId:%d build %s", tmq->consumerId, epoch, pVgCur->vgId, vgKey); taosHashPut(pHash, vgKey, strlen(vgKey), &pVgCur->currentOffset, sizeof(int64_t)); } break; @@ -1296,13 +1313,13 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) { sprintf(vgKey, "%s:%d", topic.topicName, pVgEp->vgId); int64_t* pOffset = taosHashGet(pHash, vgKey, strlen(vgKey)); int64_t offset = pVgEp->offset; - tscDebug("consumer %ld(epoch %d) original offset of vg %d is %ld", tmq->consumerId, epoch, pVgEp->vgId, offset); + tscDebug("consumer:%" PRId64 ", (epoch %d) original offset of vgId:%d is %" PRId64, tmq->consumerId, epoch, pVgEp->vgId, offset); if (pOffset != NULL) { offset = *pOffset; - tscDebug("consumer %ld(epoch %d) receive offset of vg %d, full key is %s", tmq->consumerId, epoch, pVgEp->vgId, + tscDebug("consumer:%" PRId64 ", (epoch %d) receive offset of vgId:%d, full key is %s", tmq->consumerId, epoch, pVgEp->vgId, vgKey); } - tscDebug("consumer %ld(epoch %d) offset of vg %d updated to %ld", tmq->consumerId, epoch, pVgEp->vgId, offset); + tscDebug("consumer:%" PRId64 ", (epoch %d) offset of vgId:%d updated to %" PRId64, tmq->consumerId, epoch, pVgEp->vgId, offset); SMqClientVg clientVg = { .pollCnt = 0, .currentOffset = offset, @@ -1336,7 +1353,7 @@ int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) { int8_t async = pParam->async; pParam->code = code; if (code != 0) { - tscError("consumer %ld get topic endpoint error, not ready, wait:%d", tmq->consumerId, pParam->async); + tscError("consumer:%" PRId64 ", get topic endpoint error, not ready, wait:%d", tmq->consumerId, pParam->async); goto END; } @@ -1345,7 +1362,7 @@ int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) { // Epoch will only increase when received newer epoch ep msg SMqRspHead* head = pMsg->pData; int32_t epoch = atomic_load_32(&tmq->epoch); - tscDebug("consumer %ld recv ep, msg epoch %d, current epoch %d", tmq->consumerId, head->epoch, epoch); + tscDebug("consumer:%" PRId64 ", recv ep, msg epoch %d, current epoch %d", tmq->consumerId, head->epoch, epoch); if (head->epoch <= epoch) { goto END; } @@ -1353,8 +1370,8 @@ int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) { if (!async) { SMqAskEpRsp rsp; tDecodeSMqAskEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &rsp); - /*printf("rsp epoch %ld sz %ld\n", rsp.epoch, rsp.topics->size);*/ - /*printf("tmq epoch %ld sz %ld\n", tmq->epoch, tmq->clientTopics->size);*/ + /*printf("rsp epoch %" PRId64 " sz %" PRId64 "\n", rsp.epoch, rsp.topics->size);*/ + /*printf("tmq epoch %" PRId64 " sz %" PRId64 "\n", tmq->epoch, tmq->clientTopics->size);*/ tmqUpdateEp2(tmq, head->epoch, &rsp); tDeleteSMqAskEpRsp(&rsp); } else { @@ -1389,7 +1406,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) { int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1); if (epStatus == 1) { int32_t epSkipCnt = atomic_add_fetch_32(&tmq->epSkipCnt, 1); - tscTrace("consumer %ld skip ask ep cnt %d", tmq->consumerId, epSkipCnt); + tscTrace("consumer:%" PRId64 ", skip ask ep cnt %d", tmq->consumerId, epSkipCnt); if (epSkipCnt < 5000) return 0; } atomic_store_32(&tmq->epSkipCnt, 0); @@ -1439,7 +1456,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) { SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); - tscDebug("consumer %ld ask ep", tmq->consumerId); + tscDebug("consumer:%" PRId64 ", ask ep", tmq->consumerId); int64_t transporterId = 0; asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); @@ -1555,14 +1572,15 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) { int32_t vgStatus = atomic_val_compare_exchange_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE, TMQ_VG_STATUS__WAIT); if (vgStatus != TMQ_VG_STATUS__IDLE) { int32_t vgSkipCnt = atomic_add_fetch_32(&pVg->vgSkipCnt, 1); - tscTrace("consumer %ld epoch %d skip vg %d skip cnt %d", tmq->consumerId, tmq->epoch, pVg->vgId, vgSkipCnt); + tscTrace("consumer:%" PRId64 ", epoch %d skip vgId:%d skip cnt %d", tmq->consumerId, tmq->epoch, pVg->vgId, + vgSkipCnt); continue; /*if (vgSkipCnt < 10000) continue;*/ #if 0 if (skipCnt < 30000) { continue; } else { - tscDebug("consumer %ld skip vg %d skip too much reset", tmq->consumerId, pVg->vgId); + tscDebug("consumer:%" PRId64 ",skip vgId:%d skip too much reset", tmq->consumerId, pVg->vgId); } #endif } @@ -1611,9 +1629,9 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) { char offsetFormatBuf[80]; tFormatOffset(offsetFormatBuf, 80, &pVg->currentOffsetNew); - tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %s, reqId %lu", tmq->consumerId, - pTopic->topicName, pVg->vgId, tmq->epoch, offsetFormatBuf, pReq->reqId); - /*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/ + tscDebug("consumer:%" PRId64 ", send poll to %s vgId:%d, epoch %d, req offset:%s, reqId:%" PRIu64, + tmq->consumerId, pTopic->topicName, pVg->vgId, tmq->epoch, offsetFormatBuf, pReq->reqId); + /*printf("send vgId:%d %" PRId64 "\n", pVg->vgId, pVg->currentOffset);*/ asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo); pVg->pollCnt++; tmq->pollCnt++; @@ -1660,7 +1678,8 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { int32_t consumerEpoch = atomic_load_32(&tmq->epoch); if (pollRspWrapper->dataRsp.head.epoch == consumerEpoch) { SMqClientVg* pVg = pollRspWrapper->vgHandle; - /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ + /*printf("vgId:%d offset %" PRId64 " up to %" PRId64 "\n", pVg->vgId, pVg->currentOffset, + * rspMsg->msg.rspOffset);*/ pVg->currentOffsetNew = pollRspWrapper->dataRsp.rspOffset; atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); if (pollRspWrapper->dataRsp.blockNum == 0) { @@ -1682,7 +1701,8 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { int32_t consumerEpoch = atomic_load_32(&tmq->epoch); if (pollRspWrapper->metaRsp.head.epoch == consumerEpoch) { SMqClientVg* pVg = pollRspWrapper->vgHandle; - /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ + /*printf("vgId:%d offset %" PRId64 " up to %" PRId64 "\n", pVg->vgId, pVg->currentOffset, + * rspMsg->msg.rspOffset);*/ pVg->currentOffsetNew.version = pollRspWrapper->metaRsp.rspOffset; pVg->currentOffsetNew.type = TMQ_OFFSET__LOG; atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); @@ -1701,7 +1721,7 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { tmqHandleNoPollRsp(tmq, rspWrapper, &reset); taosFreeQitem(rspWrapper); if (pollIfReset && reset) { - tscDebug("consumer %ld reset and repoll", tmq->consumerId); + tscDebug("consumer:%" PRId64 ", reset and repoll", tmq->consumerId); tmqPollImpl(tmq, timeout); } } @@ -1741,7 +1761,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) { int64_t endTime = taosGetTimestampMs(); int64_t leftTime = endTime - startTime; if (leftTime > timeout) { - tscDebug("consumer %ld (epoch %d) timeout, no rsp", tmq->consumerId, tmq->epoch); + tscDebug("consumer:%" PRId64 ", (epoch %d) timeout, no rsp", tmq->consumerId, tmq->epoch); return NULL; } tsem_timewait(&tmq->rspSem, leftTime * 1000); @@ -1839,17 +1859,20 @@ const char* tmq_get_table_name(TAOS_RES* res) { return NULL; } -int32_t tmq_get_raw_meta(TAOS_RES* res, void** raw_meta, int32_t* raw_meta_len) { +tmq_raw_data* tmq_get_raw_meta(TAOS_RES* res) { if (TD_RES_TMQ_META(res)) { + tmq_raw_data* raw = taosMemoryCalloc(1, sizeof(tmq_raw_data)); SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res; - *raw_meta = pMetaRspObj->metaRsp.metaRsp; - *raw_meta_len = pMetaRspObj->metaRsp.metaRspLen; - return 0; + raw->raw_meta = pMetaRspObj->metaRsp.metaRsp; + raw->raw_meta_len = pMetaRspObj->metaRsp.metaRspLen; + raw->raw_meta_type = pMetaRspObj->metaRsp.resMsgType; + return raw; } - return -1; + return NULL; } -static char *buildCreateTableJson(SSchemaWrapper *schemaRow, SSchemaWrapper* schemaTag, char* name, int64_t id, int8_t t){ +static char* buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* schemaTag, char* name, int64_t id, + int8_t t) { char* string = NULL; cJSON* json = cJSON_CreateObject(); if (json == NULL) { @@ -1859,31 +1882,31 @@ static char *buildCreateTableJson(SSchemaWrapper *schemaRow, SSchemaWrapper* sch cJSON_AddItemToObject(json, "type", type); char uid[32] = {0}; - sprintf(uid, "%"PRIi64, id); + sprintf(uid, "%" PRIi64, id); cJSON* id_ = cJSON_CreateString(uid); cJSON_AddItemToObject(json, "id", id_); cJSON* tableName = cJSON_CreateString(name); cJSON_AddItemToObject(json, "tableName", tableName); cJSON* tableType = cJSON_CreateString(t == TSDB_NORMAL_TABLE ? "normal" : "super"); cJSON_AddItemToObject(json, "tableType", tableType); -// cJSON* version = cJSON_CreateNumber(1); -// cJSON_AddItemToObject(json, "version", version); + // cJSON* version = cJSON_CreateNumber(1); + // cJSON_AddItemToObject(json, "version", version); cJSON* columns = cJSON_CreateArray(); - for(int i = 0; i < schemaRow->nCols; i++){ - cJSON* column = cJSON_CreateObject(); - SSchema *s = schemaRow->pSchema + i; - cJSON* cname = cJSON_CreateString(s->name); + for (int i = 0; i < schemaRow->nCols; i++) { + cJSON* column = cJSON_CreateObject(); + SSchema* s = schemaRow->pSchema + i; + cJSON* cname = cJSON_CreateString(s->name); cJSON_AddItemToObject(column, "name", cname); cJSON* ctype = cJSON_CreateNumber(s->type); cJSON_AddItemToObject(column, "type", ctype); - if(s->type == TSDB_DATA_TYPE_BINARY){ + if (s->type == TSDB_DATA_TYPE_BINARY) { int32_t length = s->bytes - VARSTR_HEADER_SIZE; - cJSON* cbytes = cJSON_CreateNumber(length); + cJSON* cbytes = cJSON_CreateNumber(length); cJSON_AddItemToObject(column, "length", cbytes); - }else if (s->type == TSDB_DATA_TYPE_NCHAR){ - int32_t length = (s->bytes - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE; - cJSON* cbytes = cJSON_CreateNumber(length); + } else if (s->type == TSDB_DATA_TYPE_NCHAR) { + int32_t length = (s->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; + cJSON* cbytes = cJSON_CreateNumber(length); cJSON_AddItemToObject(column, "length", cbytes); } cJSON_AddItemToArray(columns, column); @@ -1891,20 +1914,20 @@ static char *buildCreateTableJson(SSchemaWrapper *schemaRow, SSchemaWrapper* sch cJSON_AddItemToObject(json, "columns", columns); cJSON* tags = cJSON_CreateArray(); - for(int i = 0; schemaTag && i < schemaTag->nCols; i++){ - cJSON* tag = cJSON_CreateObject(); - SSchema *s = schemaTag->pSchema + i; - cJSON* tname = cJSON_CreateString(s->name); + for (int i = 0; schemaTag && i < schemaTag->nCols; i++) { + cJSON* tag = cJSON_CreateObject(); + SSchema* s = schemaTag->pSchema + i; + cJSON* tname = cJSON_CreateString(s->name); cJSON_AddItemToObject(tag, "name", tname); cJSON* ttype = cJSON_CreateNumber(s->type); cJSON_AddItemToObject(tag, "type", ttype); - if(s->type == TSDB_DATA_TYPE_BINARY){ + if (s->type == TSDB_DATA_TYPE_BINARY) { int32_t length = s->bytes - VARSTR_HEADER_SIZE; - cJSON* cbytes = cJSON_CreateNumber(length); + cJSON* cbytes = cJSON_CreateNumber(length); cJSON_AddItemToObject(tag, "length", cbytes); - }else if (s->type == TSDB_DATA_TYPE_NCHAR){ - int32_t length = (s->bytes - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE; - cJSON* cbytes = cJSON_CreateNumber(length); + } else if (s->type == TSDB_DATA_TYPE_NCHAR) { + int32_t length = (s->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; + cJSON* cbytes = cJSON_CreateNumber(length); cJSON_AddItemToObject(tag, "length", cbytes); } cJSON_AddItemToArray(tags, tag); @@ -1916,13 +1939,13 @@ static char *buildCreateTableJson(SSchemaWrapper *schemaRow, SSchemaWrapper* sch return string; } -static char *processCreateStb(SMqMetaRsp *metaRsp){ +static char* processCreateStb(SMqMetaRsp* metaRsp) { SVCreateStbReq req = {0}; SDecoder coder; - char* string = NULL; + char* string = NULL; // decode and process req - void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); + void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead); tDecoderInit(&coder, data, len); @@ -1938,7 +1961,7 @@ _err: return string; } -static char *buildCreateCTableJson(STag* pTag, int64_t sid, char* name, int64_t id){ +static char* buildCreateCTableJson(STag* pTag, int64_t sid, char* name, int64_t id) { char* string = NULL; cJSON* json = cJSON_CreateObject(); if (json == NULL) { @@ -1947,7 +1970,7 @@ static char *buildCreateCTableJson(STag* pTag, int64_t sid, char* name, int64_t cJSON* type = cJSON_CreateString("create"); cJSON_AddItemToObject(json, "type", type); char cid[32] = {0}; - sprintf(cid, "%"PRIi64, id); + sprintf(cid, "%" PRIi64, id); cJSON* cid_ = cJSON_CreateString(cid); cJSON_AddItemToObject(json, "id", cid_); @@ -1957,19 +1980,19 @@ static char *buildCreateCTableJson(STag* pTag, int64_t sid, char* name, int64_t cJSON_AddItemToObject(json, "tableType", tableType); char sid_[32] = {0}; - sprintf(sid_, "%"PRIi64, sid); + sprintf(sid_, "%" PRIi64, sid); cJSON* using = cJSON_CreateString(sid_); cJSON_AddItemToObject(json, "using", using); -// cJSON* version = cJSON_CreateNumber(1); -// cJSON_AddItemToObject(json, "version", version); + // cJSON* version = cJSON_CreateNumber(1); + // cJSON_AddItemToObject(json, "version", version); cJSON* tags = cJSON_CreateArray(); - if (tTagIsJson(pTag)) { // todo + if (tTagIsJson(pTag)) { // todo char* pJson = parseTagDatatoJson(pTag); cJSON* tag = cJSON_CreateObject(); - cJSON* tname = cJSON_CreateString("unknown"); // todo + cJSON* tname = cJSON_CreateString("unknown"); // todo cJSON_AddItemToObject(tag, "name", tname); cJSON* ttype = cJSON_CreateNumber(TSDB_DATA_TYPE_JSON); cJSON_AddItemToObject(tag, "type", ttype); @@ -1988,12 +2011,12 @@ static char *buildCreateCTableJson(STag* pTag, int64_t sid, char* name, int64_t goto end; } - for(int i = 0; i < taosArrayGetSize(pTagVals); i++){ + for (int i = 0; i < taosArrayGetSize(pTagVals); i++) { STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, i); cJSON* tag = cJSON_CreateObject(); -// cJSON* tname = cJSON_CreateNumber(pTagVal->cid); - cJSON* tname = cJSON_CreateString("unkonwn"); // todo + // cJSON* tname = cJSON_CreateNumber(pTagVal->cid); + cJSON* tname = cJSON_CreateString("unkonwn"); // todo cJSON_AddItemToObject(tag, "name", tname); cJSON* ttype = cJSON_CreateNumber(pTagVal->type); cJSON_AddItemToObject(tag, "type", ttype); @@ -2021,13 +2044,13 @@ end: return string; } -static char *processCreateTable(SMqMetaRsp *metaRsp){ +static char* processCreateTable(SMqMetaRsp* metaRsp) { SDecoder decoder = {0}; SVCreateTbBatchReq req = {0}; - SVCreateTbReq *pCreateReq; - char *string = NULL; + SVCreateTbReq* pCreateReq; + char* string = NULL; // decode - void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); + void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead); tDecoderInit(&decoder, data, len); if (tDecodeSVCreateTbBatchReq(&decoder, &req) < 0) { @@ -2037,27 +2060,29 @@ static char *processCreateTable(SMqMetaRsp *metaRsp){ // loop to create table for (int32_t iReq = 0; iReq < req.nReqs; iReq++) { pCreateReq = req.pReqs + iReq; - if(pCreateReq->type == TSDB_CHILD_TABLE){ - string = buildCreateCTableJson((STag*)pCreateReq->ctb.pTag, pCreateReq->ctb.suid, pCreateReq->name, pCreateReq->uid); - }else if(pCreateReq->type == TSDB_NORMAL_TABLE){ - string = buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE); + if (pCreateReq->type == TSDB_CHILD_TABLE) { + string = + buildCreateCTableJson((STag*)pCreateReq->ctb.pTag, pCreateReq->ctb.suid, pCreateReq->name, pCreateReq->uid); + } else if (pCreateReq->type == TSDB_NORMAL_TABLE) { + string = + buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE); } } tDecoderClear(&decoder); - _exit: +_exit: tDecoderClear(&decoder); return string; } -static char *processAlterTable(SMqMetaRsp *metaRsp){ - SDecoder decoder = {0}; - SVAlterTbReq vAlterTbReq = {0}; - char *string = NULL; +static char* processAlterTable(SMqMetaRsp* metaRsp) { + SDecoder decoder = {0}; + SVAlterTbReq vAlterTbReq = {0}; + char* string = NULL; // decode - void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); + void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead); tDecoderInit(&decoder, data, len); if (tDecodeSVAlterTbReq(&decoder, &vAlterTbReq) < 0) { @@ -2070,8 +2095,8 @@ static char *processAlterTable(SMqMetaRsp *metaRsp){ } cJSON* type = cJSON_CreateString("alter"); cJSON_AddItemToObject(json, "type", type); -// cJSON* uid = cJSON_CreateNumber(id); -// cJSON_AddItemToObject(json, "uid", uid); + // cJSON* uid = cJSON_CreateNumber(id); + // cJSON_AddItemToObject(json, "uid", uid); cJSON* tableName = cJSON_CreateString(vAlterTbReq.tbName); cJSON_AddItemToObject(json, "tableName", tableName); cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL ? "child" : "normal"); @@ -2086,43 +2111,43 @@ static char *processAlterTable(SMqMetaRsp *metaRsp){ cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type); cJSON_AddItemToObject(json, "colType", colType); - if(vAlterTbReq.type == TSDB_DATA_TYPE_BINARY){ + if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY) { int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE; - cJSON* cbytes = cJSON_CreateNumber(length); + cJSON* cbytes = cJSON_CreateNumber(length); cJSON_AddItemToObject(json, "colLength", cbytes); - }else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR){ - int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE; - cJSON* cbytes = cJSON_CreateNumber(length); + } else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) { + int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; + cJSON* cbytes = cJSON_CreateNumber(length); cJSON_AddItemToObject(json, "colLength", cbytes); } break; } - case TSDB_ALTER_TABLE_DROP_COLUMN:{ + case TSDB_ALTER_TABLE_DROP_COLUMN: { cJSON* alterType = cJSON_CreateNumber(TSDB_ALTER_TABLE_DROP_COLUMN); cJSON_AddItemToObject(json, "alterType", alterType); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); cJSON_AddItemToObject(json, "colName", colName); break; } - case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:{ + case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: { cJSON* alterType = cJSON_CreateNumber(TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES); cJSON_AddItemToObject(json, "alterType", alterType); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); cJSON_AddItemToObject(json, "colName", colName); cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type); cJSON_AddItemToObject(json, "colType", colType); - if(vAlterTbReq.type == TSDB_DATA_TYPE_BINARY){ + if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY) { int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE; - cJSON* cbytes = cJSON_CreateNumber(length); + cJSON* cbytes = cJSON_CreateNumber(length); cJSON_AddItemToObject(json, "colLength", cbytes); - }else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR){ - int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE; - cJSON* cbytes = cJSON_CreateNumber(length); + } else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) { + int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; + cJSON* cbytes = cJSON_CreateNumber(length); cJSON_AddItemToObject(json, "colLength", cbytes); } break; } - case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:{ + case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: { cJSON* alterType = cJSON_CreateNumber(TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME); cJSON_AddItemToObject(json, "alterType", alterType); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); @@ -2131,12 +2156,12 @@ static char *processAlterTable(SMqMetaRsp *metaRsp){ cJSON_AddItemToObject(json, "colNewName", colNewName); break; } - case TSDB_ALTER_TABLE_UPDATE_TAG_VAL:{ + case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: { cJSON* alterType = cJSON_CreateNumber(TSDB_ALTER_TABLE_UPDATE_TAG_VAL); cJSON_AddItemToObject(json, "alterType", alterType); cJSON* tagName = cJSON_CreateString(vAlterTbReq.tagName); cJSON_AddItemToObject(json, "colName", tagName); - cJSON* colValue = cJSON_CreateString("invalid, todo"); // todo + cJSON* colValue = cJSON_CreateString("invalid, todo"); // todo cJSON_AddItemToObject(json, "colValue", colValue); cJSON* isNull = cJSON_CreateBool(vAlterTbReq.isNull); cJSON_AddItemToObject(json, "colValueNull", isNull); @@ -2147,18 +2172,18 @@ static char *processAlterTable(SMqMetaRsp *metaRsp){ } string = cJSON_PrintUnformatted(json); - _exit: +_exit: tDecoderClear(&decoder); return string; } -static char *processDropSTable(SMqMetaRsp *metaRsp){ - SDecoder decoder = {0}; - SVDropStbReq req = {0}; - char *string = NULL; +static char* processDropSTable(SMqMetaRsp* metaRsp) { + SDecoder decoder = {0}; + SVDropStbReq req = {0}; + char* string = NULL; // decode - void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); + void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead); tDecoderInit(&decoder, data, len); if (tDecodeSVDropStbReq(&decoder, &req) < 0) { @@ -2172,7 +2197,7 @@ static char *processDropSTable(SMqMetaRsp *metaRsp){ cJSON* type = cJSON_CreateString("drop"); cJSON_AddItemToObject(json, "type", type); char uid[32] = {0}; - sprintf(uid, "%"PRIi64, req.suid); + sprintf(uid, "%" PRIi64, req.suid); cJSON* id = cJSON_CreateString(uid); cJSON_AddItemToObject(json, "id", id); cJSON* tableName = cJSON_CreateString(req.name); @@ -2182,18 +2207,18 @@ static char *processDropSTable(SMqMetaRsp *metaRsp){ string = cJSON_PrintUnformatted(json); - _exit: +_exit: tDecoderClear(&decoder); return string; } -static char *processDropTable(SMqMetaRsp *metaRsp){ - SDecoder decoder = {0}; - SVDropTbBatchReq req = {0}; - char *string = NULL; +static char* processDropTable(SMqMetaRsp* metaRsp) { + SDecoder decoder = {0}; + SVDropTbBatchReq req = {0}; + char* string = NULL; // decode - void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); + void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead); tDecoderInit(&decoder, data, len); if (tDecodeSVDropTbBatchReq(&decoder, &req) < 0) { @@ -2206,49 +2231,539 @@ static char *processDropTable(SMqMetaRsp *metaRsp){ } cJSON* type = cJSON_CreateString("drop"); cJSON_AddItemToObject(json, "type", type); -// cJSON* uid = cJSON_CreateNumber(id); -// cJSON_AddItemToObject(json, "uid", uid); -// cJSON* tableType = cJSON_CreateString("normal"); -// cJSON_AddItemToObject(json, "tableType", tableType); + // cJSON* uid = cJSON_CreateNumber(id); + // cJSON_AddItemToObject(json, "uid", uid); + // cJSON* tableType = cJSON_CreateString("normal"); + // cJSON_AddItemToObject(json, "tableType", tableType); cJSON* tableNameList = cJSON_CreateArray(); for (int32_t iReq = 0; iReq < req.nReqs; iReq++) { SVDropTbReq* pDropTbReq = req.pReqs + iReq; - cJSON* tableName = cJSON_CreateString(pDropTbReq->name); // todo + cJSON* tableName = cJSON_CreateString(pDropTbReq->name); // todo cJSON_AddItemToArray(tableNameList, tableName); } cJSON_AddItemToObject(json, "tableNameList", tableNameList); string = cJSON_PrintUnformatted(json); - _exit: +_exit: tDecoderClear(&decoder); return string; } -char *tmq_get_json_meta(TAOS_RES *res){ +char* tmq_get_json_meta(TAOS_RES* res) { if (!TD_RES_TMQ_META(res)) { return NULL; } SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res; - if(pMetaRspObj->metaRsp.resMsgType == TDMT_VND_CREATE_STB){ + if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_CREATE_STB) { return processCreateStb(&pMetaRspObj->metaRsp); - }else if(pMetaRspObj->metaRsp.resMsgType == TDMT_VND_ALTER_STB){ + } else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_ALTER_STB) { return processCreateStb(&pMetaRspObj->metaRsp); - }else if(pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DROP_STB){ + } else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DROP_STB) { return processDropSTable(&pMetaRspObj->metaRsp); - }else if(pMetaRspObj->metaRsp.resMsgType == TDMT_VND_CREATE_TABLE){ + } else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_CREATE_TABLE) { return processCreateTable(&pMetaRspObj->metaRsp); - }else if(pMetaRspObj->metaRsp.resMsgType == TDMT_VND_ALTER_TABLE){ + } else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_ALTER_TABLE) { return processAlterTable(&pMetaRspObj->metaRsp); - }else if(pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DROP_TABLE){ + } else if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DROP_TABLE) { return processDropTable(&pMetaRspObj->metaRsp); } return NULL; } +static int32_t taosCreateStb(TAOS* taos, void* meta, int32_t metaLen) { + SVCreateStbReq req = {0}; + SDecoder coder; + SMCreateStbReq pReq = {0}; + int32_t code = TSDB_CODE_SUCCESS; + SRequestObj* pRequest = NULL; + + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + if (!pRequest->pDb) { + code = TSDB_CODE_PAR_DB_NOT_SPECIFIED; + goto end; + } + // decode and process req + void* data = POINTER_SHIFT(meta, sizeof(SMsgHead)); + int32_t len = metaLen - sizeof(SMsgHead); + tDecoderInit(&coder, data, len); + if (tDecodeSVCreateStbReq(&coder, &req) < 0) { + code = TSDB_CODE_INVALID_PARA; + goto end; + } + // build create stable + pReq.pColumns = taosArrayInit(req.schemaRow.nCols, sizeof(SField)); + for (int32_t i = 0; i < req.schemaRow.nCols; i++) { + SSchema* pSchema = req.schemaRow.pSchema + i; + SField field = {.type = pSchema->type, .bytes = pSchema->bytes}; + strcpy(field.name, pSchema->name); + taosArrayPush(pReq.pColumns, &field); + } + pReq.pTags = taosArrayInit(req.schemaTag.nCols, sizeof(SField)); + for (int32_t i = 0; i < req.schemaTag.nCols; i++) { + SSchema* pSchema = req.schemaTag.pSchema + i; + SField field = {.type = pSchema->type, .bytes = pSchema->bytes}; + strcpy(field.name, pSchema->name); + taosArrayPush(pReq.pTags, &field); + } + pReq.colVer = req.schemaRow.version; + pReq.tagVer = req.schemaTag.version; + pReq.numOfColumns = req.schemaRow.nCols; + pReq.numOfTags = req.schemaTag.nCols; + pReq.commentLen = -1; + pReq.suid = req.suid; + pReq.source = 1; + + STscObj* pTscObj = pRequest->pTscObj; + + SName tableName; + tNameExtractFullName(toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName), pReq.name); + + SCmdMsgInfo pCmdMsg = {0}; + pCmdMsg.epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); + pCmdMsg.msgType = TDMT_MND_CREATE_STB; + pCmdMsg.msgLen = tSerializeSMCreateStbReq(NULL, 0, &pReq); + pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen); + if (NULL == pCmdMsg.pMsg) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + tSerializeSMCreateStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq); + + SQuery pQuery = {0}; + pQuery.execMode = QUERY_EXEC_MODE_RPC; + pQuery.pCmdMsg = &pCmdMsg; + pQuery.msgType = pQuery.pCmdMsg->msgType; + pQuery.stableQuery = true; + + launchQueryImpl(pRequest, &pQuery, true, NULL); + code = pRequest->code; + taosMemoryFree(pCmdMsg.pMsg); + +end: + destroyRequest(pRequest); + tFreeSMCreateStbReq(&pReq); + tDecoderClear(&coder); + return code; +} + +static int32_t taosDropStb(TAOS* taos, void* meta, int32_t metaLen) { + SVDropStbReq req = {0}; + SDecoder coder; + SMDropStbReq pReq = {0}; + int32_t code = TSDB_CODE_SUCCESS; + SRequestObj* pRequest = NULL; + + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + if (!pRequest->pDb) { + code = TSDB_CODE_PAR_DB_NOT_SPECIFIED; + goto end; + } + // decode and process req + void* data = POINTER_SHIFT(meta, sizeof(SMsgHead)); + int32_t len = metaLen - sizeof(SMsgHead); + tDecoderInit(&coder, data, len); + if (tDecodeSVDropStbReq(&coder, &req) < 0) { + code = TSDB_CODE_INVALID_PARA; + goto end; + } + + // build drop stable + pReq.igNotExists = true; + pReq.source = 1; + pReq.suid = req.suid; + + STscObj* pTscObj = pRequest->pTscObj; + + SName tableName; + tNameExtractFullName(toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName), pReq.name); + + SCmdMsgInfo pCmdMsg = {0}; + pCmdMsg.epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); + pCmdMsg.msgType = TDMT_MND_DROP_STB; + pCmdMsg.msgLen = tSerializeSMDropStbReq(NULL, 0, &pReq); + pCmdMsg.pMsg = taosMemoryMalloc(pCmdMsg.msgLen); + if (NULL == pCmdMsg.pMsg) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + tSerializeSMDropStbReq(pCmdMsg.pMsg, pCmdMsg.msgLen, &pReq); + + SQuery pQuery = {0}; + pQuery.execMode = QUERY_EXEC_MODE_RPC; + pQuery.pCmdMsg = &pCmdMsg; + pQuery.msgType = pQuery.pCmdMsg->msgType; + pQuery.stableQuery = true; + + launchQueryImpl(pRequest, &pQuery, true, NULL); + code = pRequest->code; + taosMemoryFree(pCmdMsg.pMsg); + +end: + destroyRequest(pRequest); + tDecoderClear(&coder); + return code; +} + +typedef struct SVgroupCreateTableBatch { + SVCreateTbBatchReq req; + SVgroupInfo info; + char dbName[TSDB_DB_NAME_LEN]; +} SVgroupCreateTableBatch; + +static void destroyCreateTbReqBatch(void* data) { + SVgroupCreateTableBatch* pTbBatch = (SVgroupCreateTableBatch*)data; + taosArrayDestroy(pTbBatch->req.pArray); +} + +static int32_t taosCreateTable(TAOS *taos, void *meta, int32_t metaLen){ + SVCreateTbBatchReq req = {0}; + SDecoder coder = {0}; + int32_t code = TSDB_CODE_SUCCESS; + SRequestObj *pRequest = NULL; + SQuery *pQuery = NULL; + SHashObj *pVgroupHashmap = NULL; + + code = buildRequest(*(int64_t*) taos, "", 0, NULL, false, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + if (!pRequest->pDb) { + code = TSDB_CODE_PAR_DB_NOT_SPECIFIED; + goto end; + } + // decode and process req + void* data = POINTER_SHIFT(meta, sizeof(SMsgHead)); + int32_t len = metaLen - sizeof(SMsgHead); + tDecoderInit(&coder, data, len); + if (tDecodeSVCreateTbBatchReq(&coder, &req) < 0) { + code = TSDB_CODE_INVALID_PARA; + goto end; + } + + STscObj* pTscObj = pRequest->pTscObj; + + SVCreateTbReq *pCreateReq = NULL; + SCatalog* pCatalog = NULL; + code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (NULL == pVgroupHashmap) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + taosHashSetFreeFp(pVgroupHashmap, destroyCreateTbReqBatch); + + SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter, + .requestId = pRequest->requestId, + .requestObjRefId = pRequest->self, + .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; + // loop to create table + for (int32_t iReq = 0; iReq < req.nReqs; iReq++) { + pCreateReq = req.pReqs + iReq; + + SVgroupInfo pInfo = {0}; + SName pName; + toName(pTscObj->acctId, pRequest->pDb, pCreateReq->name, &pName); + code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + SVgroupCreateTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId)); + if (pTableBatch == NULL) { + SVgroupCreateTableBatch tBatch = {0}; + tBatch.info = pInfo; + strcpy(tBatch.dbName, pRequest->pDb); + + tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq)); + taosArrayPush(tBatch.req.pArray, pCreateReq); + + taosHashPut(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId), &tBatch, sizeof(tBatch)); + } else { // add to the correct vgroup + taosArrayPush(pTableBatch->req.pArray, pCreateReq); + } + } + + SArray* pBufArray = serializeVgroupsCreateTableBatch(pVgroupHashmap); + if (NULL == pBufArray) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + + pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY); + pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; + pQuery->msgType = TDMT_VND_CREATE_TABLE; + pQuery->stableQuery = false; + pQuery->pRoot = nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT); + + code = rewriteToVnodeModifyOpStmt(pQuery, pBufArray); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + launchQueryImpl(pRequest, pQuery, false, NULL); + pQuery = NULL; // no need to free in the end + code = pRequest->code; + +end: + taosHashCleanup(pVgroupHashmap); + destroyRequest(pRequest); + tDecoderClear(&coder); + qDestroyQuery(pQuery); + return code; +} + +typedef struct SVgroupDropTableBatch { + SVDropTbBatchReq req; + SVgroupInfo info; + char dbName[TSDB_DB_NAME_LEN]; +} SVgroupDropTableBatch; + +static void destroyDropTbReqBatch(void* data) { + SVgroupDropTableBatch* pTbBatch = (SVgroupDropTableBatch*)data; + taosArrayDestroy(pTbBatch->req.pArray); +} + +static int32_t taosDropTable(TAOS *taos, void *meta, int32_t metaLen){ + SVDropTbBatchReq req = {0}; + SDecoder coder = {0}; + int32_t code = TSDB_CODE_SUCCESS; + SRequestObj *pRequest = NULL; + SQuery *pQuery = NULL; + SHashObj *pVgroupHashmap = NULL; + + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + if (!pRequest->pDb) { + code = TSDB_CODE_PAR_DB_NOT_SPECIFIED; + goto end; + } + // decode and process req + void* data = POINTER_SHIFT(meta, sizeof(SMsgHead)); + int32_t len = metaLen - sizeof(SMsgHead); + tDecoderInit(&coder, data, len); + if (tDecodeSVDropTbBatchReq(&coder, &req) < 0) { + code = TSDB_CODE_INVALID_PARA; + goto end; + } + + STscObj* pTscObj = pRequest->pTscObj; + + SVDropTbReq *pDropReq = NULL; + SCatalog *pCatalog = NULL; + code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (NULL == pVgroupHashmap) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + taosHashSetFreeFp(pVgroupHashmap, destroyDropTbReqBatch); + + SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter, + .requestId = pRequest->requestId, + .requestObjRefId = pRequest->self, + .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; + // loop to create table + for (int32_t iReq = 0; iReq < req.nReqs; iReq++) { + pDropReq = req.pReqs + iReq; + + SVgroupInfo pInfo = {0}; + SName pName; + toName(pTscObj->acctId, pRequest->pDb, pDropReq->name, &pName); + code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + SVgroupDropTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId)); + if (pTableBatch == NULL) { + SVgroupDropTableBatch tBatch = {0}; + tBatch.info = pInfo; + tBatch.req.pArray = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbReq)); + taosArrayPush(tBatch.req.pArray, pDropReq); + + taosHashPut(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId), &tBatch, sizeof(tBatch)); + } else { // add to the correct vgroup + taosArrayPush(pTableBatch->req.pArray, pDropReq); + } + } + + SArray* pBufArray = serializeVgroupsDropTableBatch(pVgroupHashmap); + if (NULL == pBufArray) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + + pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY); + pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; + pQuery->msgType = TDMT_VND_DROP_TABLE; + pQuery->stableQuery = false; + pQuery->pRoot = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT); + + code = rewriteToVnodeModifyOpStmt(pQuery, pBufArray); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + launchQueryImpl(pRequest, pQuery, false, NULL); + pQuery = NULL; // no need to free in the end + code = pRequest->code; + +end: + taosHashCleanup(pVgroupHashmap); + destroyRequest(pRequest); + tDecoderClear(&coder); + qDestroyQuery(pQuery); + return code; +} + +static int32_t taosAlterTable(TAOS *taos, void *meta, int32_t metaLen){ + SVAlterTbReq req = {0}; + SDecoder coder = {0}; + int32_t code = TSDB_CODE_SUCCESS; + SRequestObj *pRequest = NULL; + SQuery *pQuery = NULL; + SArray *pArray = NULL; + SVgDataBlocks *pVgData = NULL; + + + code = buildRequest(*(int64_t*) taos, "", 0, NULL, false, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + if (!pRequest->pDb) { + code = TSDB_CODE_PAR_DB_NOT_SPECIFIED; + goto end; + } + // decode and process req + void* data = POINTER_SHIFT(meta, sizeof(SMsgHead)); + int32_t len = metaLen - sizeof(SMsgHead); + tDecoderInit(&coder, data, len); + if (tDecodeSVAlterTbReq(&coder, &req) < 0) { + code = TSDB_CODE_INVALID_PARA; + goto end; + } + + // do not deal TSDB_ALTER_TABLE_UPDATE_OPTIONS + if (req.action == TSDB_ALTER_TABLE_UPDATE_OPTIONS) { + goto end; + } + + STscObj* pTscObj = pRequest->pTscObj; + SCatalog* pCatalog = NULL; + code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter, + .requestId = pRequest->requestId, + .requestObjRefId = pRequest->self, + .mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp)}; + + SVgroupInfo pInfo = {0}; + SName pName = {0}; + toName(pTscObj->acctId, pRequest->pDb, req.tbName, &pName); + code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &pInfo); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + pArray = taosArrayInit(1, sizeof(void*)); + if (NULL == pArray) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + + pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); + if (NULL == pVgData) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + pVgData->vg = pInfo; + pVgData->pData = taosMemoryMalloc(metaLen); + if (NULL == pVgData->pData) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + memcpy(pVgData->pData, meta, metaLen); + ((SMsgHead*)pVgData->pData)->vgId = htonl(pInfo.vgId); + pVgData->size = metaLen; + pVgData->numOfTables = 1; + taosArrayPush(pArray, &pVgData); + + pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY); + pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; + pQuery->msgType = TDMT_VND_ALTER_TABLE; + pQuery->stableQuery = false; + pQuery->pRoot = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT); + + code = rewriteToVnodeModifyOpStmt(pQuery, pArray); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + + launchQueryImpl(pRequest, pQuery, false, NULL); + pQuery = NULL; // no need to free in the end + pVgData = NULL; + pArray = NULL; + code = pRequest->code; + +end: + taosArrayDestroy(pArray); + if (pVgData) taosMemoryFreeClear(pVgData->pData); + taosMemoryFreeClear(pVgData); + destroyRequest(pRequest); + tDecoderClear(&coder); + qDestroyQuery(pQuery); + return code; +} + +int32_t taos_write_raw_meta(TAOS* taos, tmq_raw_data* raw_meta) { + if (!taos || !raw_meta) { + return TSDB_CODE_INVALID_PARA; + } + + if (raw_meta->raw_meta_type == TDMT_VND_CREATE_STB) { + return taosCreateStb(taos, raw_meta->raw_meta, raw_meta->raw_meta_len); + } else if (raw_meta->raw_meta_type == TDMT_VND_ALTER_STB) { + return taosCreateStb(taos, raw_meta->raw_meta, raw_meta->raw_meta_len); + } else if (raw_meta->raw_meta_type == TDMT_VND_DROP_STB) { + return taosDropStb(taos, raw_meta->raw_meta, raw_meta->raw_meta_len); + } else if (raw_meta->raw_meta_type == TDMT_VND_CREATE_TABLE) { + return taosCreateTable(taos, raw_meta->raw_meta, raw_meta->raw_meta_len); + } else if (raw_meta->raw_meta_type == TDMT_VND_ALTER_TABLE) { + return taosAlterTable(taos, raw_meta->raw_meta, raw_meta->raw_meta_len); + } else if (raw_meta->raw_meta_type == TDMT_VND_DROP_TABLE) { + return taosDropTable(taos, raw_meta->raw_meta, raw_meta->raw_meta_len); + } + return TSDB_CODE_INVALID_PARA; +} + void tmq_commit_async(tmq_t* tmq, const TAOS_RES* msg, tmq_commit_cb* cb, void* param) { tmqCommitInner2(tmq, msg, 0, 1, cb, param); } diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp index 832564e0db..a6062efb98 100644 --- a/source/client/test/smlTest.cpp +++ b/source/client/test/smlTest.cpp @@ -1284,4 +1284,210 @@ TEST(testCase, sml_dup_time_Test) { ASSERT_EQ(taos_errno(pRes), 0); taos_free_result(pRes); } -*/ + + +TEST(testCase, sml_16960_Test) { +TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); +ASSERT_NE(taos, nullptr); + +TAOS_RES* pRes = taos_query(taos, "create database if not exists d16368 schemaless 1"); +taos_free_result(pRes); + +pRes = taos_query(taos, "use d16368"); +taos_free_result(pRes); + +const char *sql[] = { + "[\n" + "{\n" + "\"timestamp\":\n" + "\n" + "{ \"value\": 1349020800000, \"type\": \"ms\" }\n" + ",\n" + "\"value\":\n" + "\n" + "{ \"value\": 830525384, \"type\": \"int\" }\n" + ",\n" + "\"tags\": {\n" + "\"id\": \"stb00_0\",\n" + "\"t0\":\n" + "\n" + "{ \"value\": 83972721, \"type\": \"int\" }\n" + ",\n" + "\"t1\":\n" + "\n" + "{ \"value\": 539147525, \"type\": \"int\" }\n" + ",\n" + "\"t2\":\n" + "\n" + "{ \"value\": 618258572, \"type\": \"int\" }\n" + ",\n" + "\"t3\":\n" + "\n" + "{ \"value\": -10536201, \"type\": \"int\" }\n" + ",\n" + "\"t4\":\n" + "\n" + "{ \"value\": 349227409, \"type\": \"int\" }\n" + ",\n" + "\"t5\":\n" + "\n" + "{ \"value\": 249347042, \"type\": \"int\" }\n" + "},\n" + "\"metric\": \"stb0\"\n" + "},\n" + "{\n" + "\"timestamp\":\n" + "\n" + "{ \"value\": 1349020800001, \"type\": \"ms\" }\n" + ",\n" + "\"value\":\n" + "\n" + "{ \"value\": -588348364, \"type\": \"int\" }\n" + ",\n" + "\"tags\": {\n" + "\"id\": \"stb00_0\",\n" + "\"t0\":\n" + "\n" + "{ \"value\": 83972721, \"type\": \"int\" }\n" + ",\n" + "\"t1\":\n" + "\n" + "{ \"value\": 539147525, \"type\": \"int\" }\n" + ",\n" + "\"t2\":\n" + "\n" + "{ \"value\": 618258572, \"type\": \"int\" }\n" + ",\n" + "\"t3\":\n" + "\n" + "{ \"value\": -10536201, \"type\": \"int\" }\n" + ",\n" + "\"t4\":\n" + "\n" + "{ \"value\": 349227409, \"type\": \"int\" }\n" + ",\n" + "\"t5\":\n" + "\n" + "{ \"value\": 249347042, \"type\": \"int\" }\n" + "},\n" + "\"metric\": \"stb0\"\n" + "},\n" + "{\n" + "\"timestamp\":\n" + "\n" + "{ \"value\": 1349020800002, \"type\": \"ms\" }\n" + ",\n" + "\"value\":\n" + "\n" + "{ \"value\": -370310823, \"type\": \"int\" }\n" + ",\n" + "\"tags\": {\n" + "\"id\": \"stb00_0\",\n" + "\"t0\":\n" + "\n" + "{ \"value\": 83972721, \"type\": \"int\" }\n" + ",\n" + "\"t1\":\n" + "\n" + "{ \"value\": 539147525, \"type\": \"int\" }\n" + ",\n" + "\"t2\":\n" + "\n" + "{ \"value\": 618258572, \"type\": \"int\" }\n" + ",\n" + "\"t3\":\n" + "\n" + "{ \"value\": -10536201, \"type\": \"int\" }\n" + ",\n" + "\"t4\":\n" + "\n" + "{ \"value\": 349227409, \"type\": \"int\" }\n" + ",\n" + "\"t5\":\n" + "\n" + "{ \"value\": 249347042, \"type\": \"int\" }\n" + "},\n" + "\"metric\": \"stb0\"\n" + "},\n" + "{\n" + "\"timestamp\":\n" + "\n" + "{ \"value\": 1349020800003, \"type\": \"ms\" }\n" + ",\n" + "\"value\":\n" + "\n" + "{ \"value\": -811250191, \"type\": \"int\" }\n" + ",\n" + "\"tags\": {\n" + "\"id\": \"stb00_0\",\n" + "\"t0\":\n" + "\n" + "{ \"value\": 83972721, \"type\": \"int\" }\n" + ",\n" + "\"t1\":\n" + "\n" + "{ \"value\": 539147525, \"type\": \"int\" }\n" + ",\n" + "\"t2\":\n" + "\n" + "{ \"value\": 618258572, \"type\": \"int\" }\n" + ",\n" + "\"t3\":\n" + "\n" + "{ \"value\": -10536201, \"type\": \"int\" }\n" + ",\n" + "\"t4\":\n" + "\n" + "{ \"value\": 349227409, \"type\": \"int\" }\n" + ",\n" + "\"t5\":\n" + "\n" + "{ \"value\": 249347042, \"type\": \"int\" }\n" + "},\n" + "\"metric\": \"stb0\"\n" + "},\n" + "{\n" + "\"timestamp\":\n" + "\n" + "{ \"value\": 1349020800004, \"type\": \"ms\" }\n" + ",\n" + "\"value\":\n" + "\n" + "{ \"value\": -330340558, \"type\": \"int\" }\n" + ",\n" + "\"tags\": {\n" + "\"id\": \"stb00_0\",\n" + "\"t0\":\n" + "\n" + "{ \"value\": 83972721, \"type\": \"int\" }\n" + ",\n" + "\"t1\":\n" + "\n" + "{ \"value\": 539147525, \"type\": \"int\" }\n" + ",\n" + "\"t2\":\n" + "\n" + "{ \"value\": 618258572, \"type\": \"int\" }\n" + ",\n" + "\"t3\":\n" + "\n" + "{ \"value\": -10536201, \"type\": \"int\" }\n" + ",\n" + "\"t4\":\n" + "\n" + "{ \"value\": 349227409, \"type\": \"int\" }\n" + ",\n" + "\"t5\":\n" + "\n" + "{ \"value\": 249347042, \"type\": \"int\" }\n" + "},\n" + "\"metric\": \"stb0\"\n" + "}\n" + "]" +}; + +pRes = taos_schemaless_insert(taos, (char**)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS); +ASSERT_EQ(taos_errno(pRes), 0); +taos_free_result(pRes); +} +*/ \ No newline at end of file diff --git a/source/common/src/systable.c b/source/common/src/systable.c index b8844390d2..ba8a8e1220 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -252,7 +252,7 @@ static const SSysTableMeta infosMeta[] = { {TSDB_INS_TABLE_USER_STABLES, userStbsSchema, tListLen(userStbsSchema)}, {TSDB_PERFS_TABLE_STREAMS, streamSchema, tListLen(streamSchema)}, {TSDB_INS_TABLE_USER_TABLES, userTblsSchema, tListLen(userTblsSchema)}, - {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, + // {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, {TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)}, {TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema)}, {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 8b15f4a101..38f46b9b11 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -463,6 +463,7 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3 pDst->info = pBlock->info; pDst->info.rows = 0; + pDst->info.capacity = 0; size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData colInfo = {0}; @@ -1356,7 +1357,7 @@ SColumnInfoData createColumnInfoData(int16_t type, int32_t bytes, int16_t colId) return col; } -SColumnInfoData* bdGetColumnInfoData(SSDataBlock* pBlock, int32_t index) { +SColumnInfoData* bdGetColumnInfoData(const SSDataBlock* pBlock, int32_t index) { ASSERT(pBlock != NULL); if (index >= taosArrayGetSize(pBlock->pDataBlock)) { return NULL; @@ -1735,9 +1736,9 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf) int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock); int32_t rows = pDataBlock->info.rows; int32_t len = 0; - len += snprintf(dumpBuf + len, size - len, "\n%s |block type %d |child id %d|group id %lu|\n", flag, + len += snprintf(dumpBuf + len, size - len, "\n%s |block type %d |child id %d|group id:%" PRIu64 "|\n", flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.groupId); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; for (int32_t j = 0; j < rows; j++) { len += snprintf(dumpBuf + len, size - len, "%s |", flag); @@ -1746,7 +1747,7 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf) for (int32_t k = 0; k < colNum; k++) { SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k); void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); - if (colDataIsNull(pColInfoData, rows, j, NULL)) { + if (colDataIsNull(pColInfoData, rows, j, NULL) || !pColInfoData->pData) { len += snprintf(dumpBuf + len, size - len, " %15s |", "NULL"); if (len >= size -1) return dumpBuf; continue; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 5b3993dd40..f19d17d034 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -55,12 +55,11 @@ int32_t tsNumOfMnodeQueryThreads = 2; int32_t tsNumOfMnodeFetchThreads = 1; int32_t tsNumOfMnodeReadThreads = 1; int32_t tsNumOfVnodeQueryThreads = 2; -int32_t tsNumOfVnodeFetchThreads = 1; +int32_t tsNumOfVnodeFetchThreads = 4; int32_t tsNumOfVnodeWriteThreads = 2; int32_t tsNumOfVnodeSyncThreads = 2; -int32_t tsNumOfVnodeMergeThreads = 2; int32_t tsNumOfQnodeQueryThreads = 2; -int32_t tsNumOfQnodeFetchThreads = 1; +int32_t tsNumOfQnodeFetchThreads = 4; int32_t tsNumOfSnodeSharedThreads = 2; int32_t tsNumOfSnodeUniqueThreads = 2; @@ -106,11 +105,6 @@ int32_t tsCompressMsgSize = -1; */ int32_t tsCompressColData = -1; -/* - * denote if 3.0 query pattern compatible for 2.0 - */ -int32_t tsCompatibleModel = 1; - // count/hyperloglog function always return values in case of all NULL data or Empty data set. int32_t tsCountAlwaysReturnValue = 1; @@ -190,7 +184,6 @@ int32_t tsMqRebalanceInterval = 2; int32_t tsTtlUnit = 86400; int32_t tsTtlPushInterval = 60; - void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary) { tstrncpy(tsDiskCfg[index].dir, v1, TSDB_FILENAME_LEN); tsDiskCfg[index].level = level; @@ -292,15 +285,14 @@ int32_t taosAddClientLogCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "numOfLogLines", tsNumOfLogLines, 1000, 2000000000, 1) != 0) return -1; if (cfgAddBool(pCfg, "asyncLog", tsAsyncLog, 1) != 0) return -1; if (cfgAddInt32(pCfg, "logKeepDays", 0, -365000, 365000, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "cDebugFlag", cDebugFlag, 0, 255, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "uDebugFlag", uDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "rpcDebugFlag", rpcDebugFlag, 0, 255, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "qDebugFlag", qDebugFlag, 0, 255, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1) != 0) return -1; if (cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "idxDebugFlag", idxDebugFlag, 0, 255, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "qDebugFlag", qDebugFlag, 0, 255, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "cDebugFlag", cDebugFlag, 0, 255, 1) != 0) return -1; return 0; } @@ -308,7 +300,6 @@ static int32_t taosAddServerLogCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, 0) != 0) return -1; if (cfgAddInt32(pCfg, "vDebugFlag", vDebugFlag, 0, 255, 0) != 0) return -1; if (cfgAddInt32(pCfg, "mDebugFlag", mDebugFlag, 0, 255, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "qDebugFlag", qDebugFlag, 0, 255, 0) != 0) return -1; if (cfgAddInt32(pCfg, "wDebugFlag", wDebugFlag, 0, 255, 0) != 0) return -1; if (cfgAddInt32(pCfg, "sDebugFlag", sDebugFlag, 0, 255, 0) != 0) return -1; if (cfgAddInt32(pCfg, "tsdbDebugFlag", tsdbDebugFlag, 0, 255, 0) != 0) return -1; @@ -417,8 +408,8 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { tsNumOfMnodeReadThreads = TRANGE(tsNumOfMnodeReadThreads, 1, 4); if (cfgAddInt32(pCfg, "numOfMnodeReadThreads", tsNumOfMnodeReadThreads, 1, 1024, 0) != 0) return -1; - tsNumOfVnodeQueryThreads = tsNumOfCores / 2; - tsNumOfVnodeQueryThreads = TMAX(tsNumOfVnodeQueryThreads, 1); + tsNumOfVnodeQueryThreads = tsNumOfCores / 4; + tsNumOfVnodeQueryThreads = TMAX(tsNumOfVnodeQueryThreads, 2); if (cfgAddInt32(pCfg, "numOfVnodeQueryThreads", tsNumOfVnodeQueryThreads, 1, 1024, 0) != 0) return -1; tsNumOfVnodeFetchThreads = TRANGE(tsNumOfVnodeFetchThreads, 1, 1); @@ -428,19 +419,16 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { tsNumOfVnodeWriteThreads = TMAX(tsNumOfVnodeWriteThreads, 1); if (cfgAddInt32(pCfg, "numOfVnodeWriteThreads", tsNumOfVnodeWriteThreads, 1, 1024, 0) != 0) return -1; - tsNumOfVnodeSyncThreads = tsNumOfCores / 2; + tsNumOfVnodeSyncThreads = tsNumOfCores; tsNumOfVnodeSyncThreads = TMAX(tsNumOfVnodeSyncThreads, 1); if (cfgAddInt32(pCfg, "numOfVnodeSyncThreads", tsNumOfVnodeSyncThreads, 1, 1024, 0) != 0) return -1; - tsNumOfVnodeMergeThreads = tsNumOfCores / 8; - tsNumOfVnodeMergeThreads = TRANGE(tsNumOfVnodeMergeThreads, 1, 1); - if (cfgAddInt32(pCfg, "numOfVnodeMergeThreads", tsNumOfVnodeMergeThreads, 1, 1024, 0) != 0) return -1; - tsNumOfQnodeQueryThreads = tsNumOfCores / 2; tsNumOfQnodeQueryThreads = TMAX(tsNumOfQnodeQueryThreads, 1); if (cfgAddInt32(pCfg, "numOfQnodeQueryThreads", tsNumOfQnodeQueryThreads, 1, 1024, 0) != 0) return -1; - tsNumOfQnodeFetchThreads = TRANGE(tsNumOfQnodeFetchThreads, 1, 1); + tsNumOfQnodeFetchThreads = tsNumOfCores / 2; + tsNumOfQnodeFetchThreads = TMAX(tsNumOfQnodeFetchThreads, 4); if (cfgAddInt32(pCfg, "numOfQnodeFetchThreads", tsNumOfQnodeFetchThreads, 1, 1024, 0) != 0) return -1; tsNumOfSnodeSharedThreads = tsNumOfCores / 4; @@ -470,7 +458,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "transPullupInterval", tsTransPullupInterval, 1, 10000, 1) != 0) return -1; if (cfgAddInt32(pCfg, "mqRebalanceInterval", tsMqRebalanceInterval, 1, 10000, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "ttlUnit", tsTtlUnit, 1, 86400*365, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "ttlUnit", tsTtlUnit, 1, 86400 * 365, 1) != 0) return -1; if (cfgAddInt32(pCfg, "ttlPushInterval", tsTtlPushInterval, 1, 10000, 1) != 0) return -1; if (cfgAddBool(pCfg, "udf", tsStartUdfd, 0) != 0) return -1; @@ -485,20 +473,18 @@ static void taosSetClientLogCfg(SConfig *pCfg) { tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32; tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval; tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32; - cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32; - uDebugFlag = cfgGetItem(pCfg, "uDebugFlag")->i32; - qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32; - rpcDebugFlag = cfgGetItem(pCfg, "rpcDebugFlag")->i32; tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32; + uDebugFlag = cfgGetItem(pCfg, "uDebugFlag")->i32; jniDebugFlag = cfgGetItem(pCfg, "jniDebugFlag")->i32; - idxDebugFlag = cfgGetItem(pCfg, "idxDebugFlag")->i32; + rpcDebugFlag = cfgGetItem(pCfg, "rpcDebugFlag")->i32; + qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32; + cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32; } static void taosSetServerLogCfg(SConfig *pCfg) { dDebugFlag = cfgGetItem(pCfg, "dDebugFlag")->i32; vDebugFlag = cfgGetItem(pCfg, "vDebugFlag")->i32; mDebugFlag = cfgGetItem(pCfg, "mDebugFlag")->i32; - qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32; wDebugFlag = cfgGetItem(pCfg, "wDebugFlag")->i32; sDebugFlag = cfgGetItem(pCfg, "sDebugFlag")->i32; tsdbDebugFlag = cfgGetItem(pCfg, "tsdbDebugFlag")->i32; @@ -603,7 +589,6 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32; tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32; tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32; - tsNumOfVnodeMergeThreads = cfgGetItem(pCfg, "numOfVnodeMergeThreads")->i32; tsNumOfQnodeQueryThreads = cfgGetItem(pCfg, "numOfQnodeQueryThreads")->i32; tsNumOfQnodeFetchThreads = cfgGetItem(pCfg, "numOfQnodeFetchThreads")->i32; tsNumOfSnodeSharedThreads = cfgGetItem(pCfg, "numOfSnodeSharedThreads")->i32; @@ -636,7 +621,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { return 0; } -int32_t taosSetCfg(SConfig *pCfg, char* name) { +int32_t taosSetCfg(SConfig *pCfg, char *name) { int32_t len = strlen(name); char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0}; strntolower(lowcaseName, name, TMIN(CFG_NAME_MAX_LEN, len)); @@ -666,7 +651,7 @@ int32_t taosSetCfg(SConfig *pCfg, char* name) { tsCompressColData = cfgGetItem(pCfg, "compressColData")->i32; } else if (strcasecmp("countAlwaysReturnValue", name) == 0) { tsCountAlwaysReturnValue = cfgGetItem(pCfg, "countAlwaysReturnValue")->i32; - } else if (strcasecmp("cDebugFlag", name) == 0) { + } else if (strcasecmp("cDebugFlag", name) == 0) { cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32; } break; @@ -691,10 +676,10 @@ int32_t taosSetCfg(SConfig *pCfg, char* name) { tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); - + char defaultFirstEp[TSDB_EP_LEN] = {0}; snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - + SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); SEp firstEp = {0}; taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); @@ -704,10 +689,10 @@ int32_t taosSetCfg(SConfig *pCfg, char* name) { tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); - + char defaultFirstEp[TSDB_EP_LEN] = {0}; snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - + SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); SEp firstEp = {0}; taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); @@ -778,7 +763,7 @@ int32_t taosSetCfg(SConfig *pCfg, char* name) { } else if (strcasecmp("minSlidingTime", name) == 0) { tsMinSlidingTime = cfgGetItem(pCfg, "minSlidingTime")->i32; } else if (strcasecmp("minIntervalTime", name) == 0) { - tsMinIntervalTime = cfgGetItem(pCfg, "minIntervalTime")->i32; + tsMinIntervalTime = cfgGetItem(pCfg, "minIntervalTime")->i32; } else if (strcasecmp("minimalLogDirGB", name) == 0) { tsLogSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval; } @@ -845,8 +830,6 @@ int32_t taosSetCfg(SConfig *pCfg, char* name) { tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32; } else if (strcasecmp("numOfVnodeSyncThreads", name) == 0) { tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32; - } else if (strcasecmp("numOfVnodeMergeThreads", name) == 0) { - tsNumOfVnodeMergeThreads = cfgGetItem(pCfg, "numOfVnodeMergeThreads")->i32; } else if (strcasecmp("numOfQnodeQueryThreads", name) == 0) { tsNumOfQnodeQueryThreads = cfgGetItem(pCfg, "numOfQnodeQueryThreads")->i32; } else if (strcasecmp("numOfQnodeFetchThreads", name) == 0) { @@ -924,10 +907,10 @@ int32_t taosSetCfg(SConfig *pCfg, char* name) { tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); - + char defaultFirstEp[TSDB_EP_LEN] = {0}; snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); - + SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); SEp firstEp = {0}; taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); @@ -999,14 +982,13 @@ int32_t taosSetCfg(SConfig *pCfg, char* name) { break; } default: - terrno = TSDB_CODE_CFG_NOT_FOUND; + terrno = TSDB_CODE_CFG_NOT_FOUND; return -1; } - + return 0; } - int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) { if (tsCfg == NULL) osDefaultInit(); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 192a41a70e..e08aa91459 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -381,9 +381,11 @@ static int32_t tDeserializeSClientHbRsp(SDecoder *pDecoder, SClientHbRsp *pRsp) if (pQnodeNum > 0) { pRsp->query->pQnodeList = taosArrayInit(pQnodeNum, sizeof(SQueryNodeLoad)); if (NULL == pRsp->query->pQnodeList) return -1; - SQueryNodeLoad load = {0}; - if (tDecodeSQueryNodeLoad(pDecoder, &load) < 0) return -1; - taosArrayPush(pRsp->query->pQnodeList, &load); + for (int32_t i = 0; i < pQnodeNum; ++i) { + SQueryNodeLoad load = {0}; + if (tDecodeSQueryNodeLoad(pDecoder, &load) < 0) return -1; + taosArrayPush(pRsp->query->pQnodeList, &load); + } } } @@ -496,11 +498,18 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq if (tStartEncode(&encoder) < 0) return -1; if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; + if (tEncodeI8(&encoder, pReq->source) < 0) return -1; + for (int32_t i = 0; i < sizeof(pReq->reserved) / sizeof(int8_t); ++i) { + if (tEncodeI8(&encoder, pReq->reserved[i]) < 0) return -1; + } + if (tEncodeI64(&encoder, pReq->suid) < 0) return -1; if (tEncodeI64(&encoder, pReq->delay1) < 0) return -1; if (tEncodeI64(&encoder, pReq->delay2) < 0) return -1; if (tEncodeI64(&encoder, pReq->watermark1) < 0) return -1; if (tEncodeI64(&encoder, pReq->watermark2) < 0) return -1; if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1; + if (tEncodeI32(&encoder, pReq->colVer) < 0) return -1; + if (tEncodeI32(&encoder, pReq->tagVer) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfTags) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfFuncs) < 0) return -1; @@ -553,11 +562,18 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->source) < 0) return -1; + for (int32_t i = 0; i < sizeof(pReq->reserved) / sizeof(int8_t); ++i) { + if (tDecodeI8(&decoder, &pReq->reserved[i]) < 0) return -1; + } + if (tDecodeI64(&decoder, &pReq->suid) < 0) return -1; if (tDecodeI64(&decoder, &pReq->delay1) < 0) return -1; if (tDecodeI64(&decoder, &pReq->delay2) < 0) return -1; if (tDecodeI64(&decoder, &pReq->watermark1) < 0) return -1; if (tDecodeI64(&decoder, &pReq->watermark2) < 0) return -1; if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->colVer) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->tagVer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfTags) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfFuncs) < 0) return -1; @@ -645,6 +661,11 @@ int32_t tSerializeSMDropStbReq(void *buf, int32_t bufLen, SMDropStbReq *pReq) { if (tStartEncode(&encoder) < 0) return -1; if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1; + if (tEncodeI8(&encoder, pReq->source) < 0) return -1; + for (int32_t i = 0; i < sizeof(pReq->reserved) / sizeof(int8_t); ++i) { + if (tEncodeI8(&encoder, pReq->reserved[i]) < 0) return -1; + } + if (tEncodeI64(&encoder, pReq->suid) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -659,6 +680,12 @@ int32_t tDeserializeSMDropStbReq(void *buf, int32_t bufLen, SMDropStbReq *pReq) if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->source) < 0) return -1; + for (int32_t i = 0; i < sizeof(pReq->reserved) / sizeof(int8_t); ++i) { + if (tDecodeI8(&decoder, &pReq->reserved[i]) < 0) return -1; + } + if (tDecodeI64(&decoder, &pReq->suid) < 0) return -1; + tEndDecode(&decoder); tDecoderClear(&decoder); @@ -672,8 +699,6 @@ int32_t tSerializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq) if (tStartEncode(&encoder) < 0) return -1; if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeI8(&encoder, pReq->alterType) < 0) return -1; - if (tEncodeI32(&encoder, pReq->tagVer) < 0) return -1; - if (tEncodeI32(&encoder, pReq->colVer) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfFields) < 0) return -1; for (int32_t i = 0; i < pReq->numOfFields; ++i) { SField *pField = taosArrayGet(pReq->pFields, i); @@ -700,8 +725,6 @@ int32_t tDeserializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->alterType) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->tagVer) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->colVer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfFields) < 0) return -1; pReq->pFields = taosArrayInit(pReq->numOfFields, sizeof(SField)); if (pReq->pFields == NULL) { @@ -1978,7 +2001,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1; if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->pages) < 0) return -1; - if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheLastSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; @@ -1991,7 +2014,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { if (tEncodeI8(&encoder, pReq->compression) < 0) return -1; if (tEncodeI8(&encoder, pReq->replications) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; - if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; if (tEncodeI8(&encoder, pReq->schemaless) < 0) return -1; if (tEncodeI8(&encoder, pReq->ignoreExist) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfRetensions) < 0) return -1; @@ -2020,7 +2043,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheLastSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; @@ -2033,7 +2056,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; if (tDecodeI8(&decoder, &pReq->schemaless) < 0) return -1; if (tDecodeI8(&decoder, &pReq->ignoreExist) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1; @@ -2075,7 +2098,7 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1; if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->pages) < 0) return -1; - if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheLastSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; @@ -2083,7 +2106,7 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; - if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; if (tEncodeI8(&encoder, pReq->replications) < 0) return -1; tEndEncode(&encoder); @@ -2101,7 +2124,7 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheLastSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; @@ -2109,7 +2132,7 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1; tEndDecode(&decoder); @@ -2624,6 +2647,31 @@ int32_t tDeserializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) { return 0; } +int32_t tSerializeSTrimDbReq(void *buf, int32_t bufLen, STrimDbReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSTrimDbReq(void *buf, int32_t bufLen, STrimDbReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -2646,7 +2694,7 @@ int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { if (tEncodeI8(&encoder, pRsp->compression) < 0) return -1; if (tEncodeI8(&encoder, pRsp->replications) < 0) return -1; if (tEncodeI8(&encoder, pRsp->strict) < 0) return -1; - if (tEncodeI8(&encoder, pRsp->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->cacheLast) < 0) return -1; if (tEncodeI32(&encoder, pRsp->numOfRetensions) < 0) return -1; for (int32_t i = 0; i < pRsp->numOfRetensions; ++i) { SRetention *pRetension = taosArrayGet(pRsp->pRetensions, i); @@ -2685,7 +2733,7 @@ int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) { if (tDecodeI8(&decoder, &pRsp->compression) < 0) return -1; if (tDecodeI8(&decoder, &pRsp->replications) < 0) return -1; if (tDecodeI8(&decoder, &pRsp->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pRsp->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->cacheLast) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->numOfRetensions) < 0) return -1; if (pRsp->numOfRetensions > 0) { pRsp->pRetensions = taosArrayInit(pRsp->numOfRetensions, sizeof(SRetention)); @@ -3596,7 +3644,7 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1; if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->pages) < 0) return -1; - if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheLastSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; @@ -3611,7 +3659,7 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR if (tEncodeI8(&encoder, pReq->precision) < 0) return -1; if (tEncodeI8(&encoder, pReq->compression) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; - if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; if (tEncodeI8(&encoder, pReq->standby) < 0) return -1; if (tEncodeI8(&encoder, pReq->replica) < 0) return -1; if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1; @@ -3654,7 +3702,7 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheLastSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; @@ -3669,7 +3717,7 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1; if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; if (tDecodeI8(&decoder, &pReq->standby) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1; if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1; @@ -3779,7 +3827,7 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1; if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->pages) < 0) return -1; - if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheLastSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; @@ -3787,7 +3835,7 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; - if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1; if (tEncodeI8(&encoder, pReq->replica) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { @@ -3810,7 +3858,7 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheLastSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; @@ -3818,7 +3866,7 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { @@ -5406,11 +5454,11 @@ int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) { } else if (pVal->type == TMQ_OFFSET__RESET_LATEST) { snprintf(buf, maxLen, "offset(reset to latest)"); } else if (pVal->type == TMQ_OFFSET__LOG) { - snprintf(buf, maxLen, "offset(log) ver:%ld", pVal->version); + snprintf(buf, maxLen, "offset(log) ver:%" PRId64, pVal->version); } else if (pVal->type == TMQ_OFFSET__SNAPSHOT_DATA) { - snprintf(buf, maxLen, "offset(ss data) uid:%ld, ts:%ld", pVal->uid, pVal->ts); + snprintf(buf, maxLen, "offset(ss data) uid:%" PRId64 ", ts:%" PRId64, pVal->uid, pVal->ts); } else if (pVal->type == TMQ_OFFSET__SNAPSHOT_META) { - snprintf(buf, maxLen, "offset(ss meta) uid:%ld, ts:%ld", pVal->uid, pVal->ts); + snprintf(buf, maxLen, "offset(ss meta) uid:%" PRId64 ", ts:%" PRId64, pVal->uid, pVal->ts); } else { ASSERT(0); } diff --git a/source/common/src/tname.c b/source/common/src/tname.c index fb3a2d7464..7183153824 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -115,6 +115,14 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in #endif +SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName* pName) { + pName->type = TSDB_TABLE_NAME_T; + pName->acctId = acctId; + strcpy(pName->dbname, pDbName); + strcpy(pName->tname, pTableName); + return pName; +} + int32_t tNameExtractFullName(const SName* name, char* dst) { assert(name != NULL && dst != NULL); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 59b442881a..5f982ad3a4 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -21,7 +21,7 @@ extern SConfig *tsCfg; static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) { if (pMgmt->pData->dnodeId == 0 || pMgmt->pData->clusterId == 0) { - dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); + dInfo("set local info, dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); taosThreadRwlockWrlock(&pMgmt->pData->lock); pMgmt->pData->dnodeId = pCfg->dnodeId; pMgmt->pData->clusterId = pCfg->clusterId; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index 7f3f76b4b6..a171d2e1e4 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -167,7 +167,7 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { if (pMsg == NULL) return -1; memcpy(pMsg, pRpc, sizeof(SRpcMsg)); - dTrace("msg:%p, is created and will put int %s queue", pMsg, pWorker->name); + dTrace("msg:%p, is created and will put into %s queue, type:%s", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType)); return mmPutMsgToWorker(pMgmt, pWorker, pMsg); } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 5ffddd0127..aac9c8411f 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -210,7 +210,8 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return -1; } - dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d", createReq.vgId, createReq.isTsma, createReq.standby); + dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d cacheLast:%d cacheLastSize:%d", createReq.vgId, + createReq.isTsma, createReq.standby, createReq.cacheLast, createReq.cacheLastSize); vmGenerateVnodeCfg(&createReq, &vnodeCfg); if (vmTsmaAdjustDays(&vnodeCfg, &createReq) < 0) { diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c index ab9d3f67e7..ecbb695e02 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c +++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c @@ -277,7 +277,7 @@ int32_t dmRunDnode(SDnode *pDnode) { while (1) { if (pDnode->stop) { - dInfo("dnode is about to stop"); + dInfo("TDengine is about to stop"); dmSetStatus(pDnode, DND_STAT_STOPPED); dmStopNodes(pDnode); dmCloseNodes(pDnode); diff --git a/source/dnode/mgmt/test/vnode/vnode.cpp b/source/dnode/mgmt/test/vnode/vnode.cpp index 8aba4f81b5..520d844dbd 100644 --- a/source/dnode/mgmt/test/vnode/vnode.cpp +++ b/source/dnode/mgmt/test/vnode/vnode.cpp @@ -45,7 +45,7 @@ TEST_F(DndTestVnode, 01_Create_Vnode) { createReq.compression = 2; createReq.replica = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.selfIndex = 0; for (int r = 0; r < createReq.replica; ++r) { SReplica* pReplica = &createReq.replicas[r]; @@ -80,7 +80,7 @@ TEST_F(DndTestVnode, 02_Alter_Vnode) { alterReq.walLevel = 1; alterReq.replica = 1; alterReq.strict = 1; - alterReq.cacheLastRow = 0; + alterReq.cacheLast = 0; alterReq.selfIndex = 0; for (int r = 0; r < alterReq.replica; ++r) { SReplica* pReplica = &alterReq.replicas[r]; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index f39a848992..7ac991451e 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -246,7 +246,7 @@ typedef struct { int32_t buffer; int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -260,7 +260,7 @@ typedef struct { int8_t replications; int8_t strict; int8_t hashMethod; // default is 1 - int8_t cacheLastRow; + int8_t cacheLast; int32_t numOfRetensions; SArray* pRetensions; int8_t schemaless; diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 14867ff693..b94c60c4ab 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -34,8 +34,6 @@ extern "C" { #endif // clang-format off - - #define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} #define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} #define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} @@ -49,7 +47,6 @@ extern "C" { #define mGInfo(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mInfo (param ", gtid:%s", __VA_ARGS__, buf);} #define mGDebug(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mDebug(param ", gtid:%s", __VA_ARGS__, buf);} #define mGTrace(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mTrace(param ", gtid:%s", __VA_ARGS__, buf);} - // clang-format on #define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE) diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 5b5de10fba..27b785f4d2 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -15,11 +15,11 @@ #define _DEFAULT_SOURCE #include "mndConsumer.h" -#include "mndPrivilege.h" #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" #include "mndOffset.h" +#include "mndPrivilege.h" #include "mndShow.h" #include "mndStb.h" #include "mndSubscribe.h" @@ -92,7 +92,7 @@ static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) { SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pLostMsg->consumerId); ASSERT(pConsumer); - mInfo("receive consumer lost msg, consumer id %ld, status %s", pLostMsg->consumerId, + mInfo("receive consumer lost msg, consumer id %" PRId64 ", status %s", pLostMsg->consumerId, mndConsumerStatusName(pConsumer->status)); if (pConsumer->status != MQ_CONSUMER_STATUS__READY) { @@ -124,7 +124,7 @@ static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) { SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pRecoverMsg->consumerId); ASSERT(pConsumer); - mInfo("receive consumer recover msg, consumer id %ld, status %s", pRecoverMsg->consumerId, + mInfo("receive consumer recover msg, consumer id %" PRId64 ", status %s", pRecoverMsg->consumerId, mndConsumerStatusName(pConsumer->status)); if (pConsumer->status != MQ_CONSUMER_STATUS__READY) { @@ -296,7 +296,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) { // 2. check epoch, only send ep info when epoches do not match if (epoch != serverEpoch) { taosRLockLatch(&pConsumer->lock); - mInfo("process ask ep, consumer %ld(epoch %d), server epoch %d", consumerId, epoch, serverEpoch); + mInfo("process ask ep, consumer:%" PRId64 "(epoch %d), server epoch %d", consumerId, epoch, serverEpoch); int32_t numOfTopics = taosArrayGetSize(pConsumer->currentTopics); rsp.topics = taosArrayInit(numOfTopics, sizeof(SMqSubTopicEp)); @@ -435,23 +435,12 @@ static int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) { goto SUBSCRIBE_OVER; } -#if 0 - // ref topic to prevent drop - // TODO make topic complete - SMqTopicObj topicObj = {0}; - memcpy(&topicObj, pTopic, sizeof(SMqTopicObj)); - topicObj.refConsumerCnt = pTopic->refConsumerCnt + 1; - mInfo("subscribe topic %s by consumer %ld cgroup %s, refcnt %d", pTopic->name, consumerId, cgroup, - topicObj.refConsumerCnt); - if (mndSetTopicCommitLogs(pMnode, pTrans, &topicObj) != 0) goto SUBSCRIBE_OVER; -#endif - mndReleaseTopic(pMnode, pTopic); } pConsumerOld = mndAcquireConsumer(pMnode, consumerId); if (pConsumerOld == NULL) { - mInfo("receive subscribe request from new consumer: %ld", consumerId); + mInfo("receive subscribe request from new consumer:%" PRId64, consumerId); pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup); tstrncpy(pConsumerNew->clientId, subscribe.clientId, 256); @@ -472,8 +461,8 @@ static int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) { int32_t status = atomic_load_32(&pConsumerOld->status); - mInfo("receive subscribe request from old consumer: %ld, current status: %s", consumerId, - mndConsumerStatusName(status)); + mInfo("receive subscribe request from existing consumer:%" PRId64 ", current status: %s, subscribe topic num: %d", + consumerId, mndConsumerStatusName(status), newTopicNum); if (status != MQ_CONSUMER_STATUS__READY) { terrno = TSDB_CODE_MND_CONSUMER_NOT_READY; @@ -849,12 +838,15 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock * pShow->pIter = sdbFetch(pSdb, SDB_CONSUMER, pShow->pIter, (void **)&pConsumer); if (pShow->pIter == NULL) break; if (taosArrayGetSize(pConsumer->assignedTopics) == 0) { + mDebug("showing consumer %ld no assigned topic, skip", pConsumer->consumerId); sdbRelease(pSdb, pConsumer); continue; } taosRLockLatch(&pConsumer->lock); + mDebug("showing consumer %ld", pConsumer->consumerId); + int32_t topicSz = taosArrayGetSize(pConsumer->assignedTopics); bool hasTopic = true; if (topicSz == 0) { diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 156afb09fc..dcae8831ec 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -93,7 +93,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { SDB_SET_INT32(pRaw, dataPos, pDb->cfg.buffer, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.pageSize, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.pages, _OVER) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.lastRowMem, _OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheLastSize, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1, _OVER) @@ -106,7 +106,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compression, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.replications, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.strict, _OVER) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow, _OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLast, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.hashMethod, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfRetensions, _OVER) for (int32_t i = 0; i < pDb->cfg.numOfRetensions; ++i) { @@ -166,7 +166,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.buffer, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.pageSize, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.pages, _OVER) - SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.lastRowMem, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.cacheLastSize, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysPerFile, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep0, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep1, _OVER) @@ -179,7 +179,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.compression, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.replications, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.strict, _OVER) - SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.cacheLastRow, _OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.cacheLast, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.hashMethod, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.numOfRetensions, _OVER) if (pDb->cfg.numOfRetensions > 0) { @@ -234,7 +234,7 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) { pOld->cfg.buffer = pNew->cfg.buffer; pOld->cfg.pageSize = pNew->cfg.pageSize; pOld->cfg.pages = pNew->cfg.pages; - pOld->cfg.lastRowMem = pNew->cfg.lastRowMem; + pOld->cfg.cacheLastSize = pNew->cfg.cacheLastSize; pOld->cfg.daysPerFile = pNew->cfg.daysPerFile; pOld->cfg.daysToKeep0 = pNew->cfg.daysToKeep0; pOld->cfg.daysToKeep1 = pNew->cfg.daysToKeep1; @@ -242,7 +242,7 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) { pOld->cfg.fsyncPeriod = pNew->cfg.fsyncPeriod; pOld->cfg.walLevel = pNew->cfg.walLevel; pOld->cfg.strict = pNew->cfg.strict; - pOld->cfg.cacheLastRow = pNew->cfg.cacheLastRow; + pOld->cfg.cacheLast = pNew->cfg.cacheLast; pOld->cfg.replications = pNew->cfg.replications; taosWUnLockLatch(&pOld->lock); return 0; @@ -291,7 +291,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->buffer < TSDB_MIN_BUFFER_PER_VNODE || pCfg->buffer > TSDB_MAX_BUFFER_PER_VNODE) return -1; if (pCfg->pageSize < TSDB_MIN_PAGESIZE_PER_VNODE || pCfg->pageSize > TSDB_MAX_PAGESIZE_PER_VNODE) return -1; if (pCfg->pages < TSDB_MIN_PAGES_PER_VNODE || pCfg->pages > TSDB_MAX_PAGES_PER_VNODE) return -1; - if (pCfg->lastRowMem < TSDB_MIN_DB_LAST_ROW_MEM || pCfg->lastRowMem > TSDB_MAX_DB_LAST_ROW_MEM) return -1; + if (pCfg->cacheLastSize < TSDB_MIN_DB_CACHE_LAST_SIZE || pCfg->cacheLastSize > TSDB_MAX_DB_CACHE_LAST_SIZE) return -1; if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1; if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1; if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1; @@ -310,7 +310,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->replications != 1 && pCfg->replications != 3) return -1; if (pCfg->strict < TSDB_DB_STRICT_OFF || pCfg->strict > TSDB_DB_STRICT_ON) return -1; if (pCfg->schemaless < TSDB_DB_SCHEMALESS_OFF || pCfg->schemaless > TSDB_DB_SCHEMALESS_ON) return -1; - if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1; + if (pCfg->cacheLast < TSDB_MIN_DB_CACHE_LAST || pCfg->cacheLast > TSDB_MAX_DB_CACHE_LAST) return -1; if (pCfg->hashMethod != 1) return -1; if (pCfg->replications > mndGetDnodeSize(pMnode)) { terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; @@ -339,8 +339,8 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->compression < 0) pCfg->compression = TSDB_DEFAULT_COMP_LEVEL; if (pCfg->replications < 0) pCfg->replications = TSDB_DEFAULT_DB_REPLICA; if (pCfg->strict < 0) pCfg->strict = TSDB_DEFAULT_DB_STRICT; - if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW; - if (pCfg->lastRowMem <= 0) pCfg->lastRowMem = TSDB_DEFAULT_LAST_ROW_MEM; + if (pCfg->cacheLast < 0) pCfg->cacheLast = TSDB_DEFAULT_CACHE_LAST; + if (pCfg->cacheLastSize <= 0) pCfg->cacheLastSize = TSDB_DEFAULT_CACHE_LAST_SIZE; if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0; if (pCfg->schemaless < 0) pCfg->schemaless = TSDB_DB_SCHEMALESS_OFF; } @@ -439,7 +439,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, .buffer = pCreate->buffer, .pageSize = pCreate->pageSize, .pages = pCreate->pages, - .lastRowMem = pCreate->lastRowMem, + .cacheLastSize = pCreate->cacheLastSize, .daysPerFile = pCreate->daysPerFile, .daysToKeep0 = pCreate->daysToKeep0, .daysToKeep1 = pCreate->daysToKeep1, @@ -452,7 +452,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, .compression = pCreate->compression, .replications = pCreate->replications, .strict = pCreate->strict, - .cacheLastRow = pCreate->cacheLastRow, + .cacheLast = pCreate->cacheLast, .hashMethod = 1, .schemaless = pCreate->schemaless, }; @@ -623,13 +623,13 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { #endif } - if (pAlter->cacheLastRow >= 0 && pAlter->cacheLastRow != pDb->cfg.cacheLastRow) { - pDb->cfg.cacheLastRow = pAlter->cacheLastRow; + if (pAlter->cacheLast >= 0 && pAlter->cacheLast != pDb->cfg.cacheLast) { + pDb->cfg.cacheLast = pAlter->cacheLast; terrno = 0; } - if (pAlter->lastRowMem > 0 && pAlter->lastRowMem != pDb->cfg.lastRowMem) { - pDb->cfg.lastRowMem = pAlter->lastRowMem; + if (pAlter->cacheLastSize > 0 && pAlter->cacheLastSize != pDb->cfg.cacheLastSize) { + pDb->cfg.cacheLastSize = pAlter->cacheLastSize; terrno = 0; } @@ -801,7 +801,7 @@ static int32_t mndProcessGetDbCfgReq(SRpcMsg *pReq) { cfgRsp.compression = pDb->cfg.compression; cfgRsp.replications = pDb->cfg.replications; cfgRsp.strict = pDb->cfg.strict; - cfgRsp.cacheLastRow = pDb->cfg.cacheLastRow; + cfgRsp.cacheLast = pDb->cfg.cacheLast; cfgRsp.numOfRetensions = pDb->cfg.numOfRetensions; cfgRsp.pRetensions = pDb->cfg.pRetensions; cfgRsp.schemaless = pDb->cfg.schemaless; @@ -1467,7 +1467,7 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.compression, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.cacheLastRow, false); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.cacheLast, false); const char *precStr = NULL; switch (pDb->cfg.precision) { diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 6ead922d95..9ce108b789 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -406,7 +406,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { } if (statusReq.dnodeId == 0) { - mInfo("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); + mInfo("dnode:%d, %s first access, clusterId:%" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); } else { if (statusReq.clusterId != pMnode->clusterId) { if (pDnode != NULL) { diff --git a/source/dnode/mnode/impl/src/mndOffset.c b/source/dnode/mnode/impl/src/mndOffset.c index e2b20b2163..00753de0ec 100644 --- a/source/dnode/mnode/impl/src/mndOffset.c +++ b/source/dnode/mnode/impl/src/mndOffset.c @@ -185,7 +185,7 @@ static int32_t mndProcessCommitOffsetReq(SRpcMsg *pMsg) { for (int32_t i = 0; i < commitOffsetReq.num; i++) { SMqOffset *pOffset = &commitOffsetReq.offsets[i]; - mInfo("commit offset %ld to vg %d of consumer group %s on topic %s", pOffset->offset, pOffset->vgId, + mInfo("commit offset %" PRId64 " to vgId:%d of consumer group %s on topic %s", pOffset->offset, pOffset->vgId, pOffset->cgroup, pOffset->topicName); if (mndMakePartitionKey(key, pOffset->cgroup, pOffset->topicName, pOffset->vgId) < 0) { mError("submit offset to topic %s failed", pOffset->topicName); diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index da5b8cb48e..c1513cd92f 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -527,10 +527,20 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea streamObj.version = 1; streamObj.sql = pCreate->sql; streamObj.smaId = smaObj.uid; - streamObj.watermark = 0; - streamObj.trigger = STREAM_TRIGGER_AT_ONCE; + streamObj.watermark = pCreate->watermark; + streamObj.trigger = STREAM_TRIGGER_WINDOW_CLOSE; + streamObj.triggerParam = pCreate->maxDelay; streamObj.ast = strdup(smaObj.ast); + // check the maxDelay + if (streamObj.triggerParam < TSDB_MIN_ROLLUP_MAX_DELAY) { + int64_t msInterval = convertTimeFromPrecisionToUnit(pCreate->interval, pDb->cfg.precision, TIME_UNIT_MILLISECOND); + streamObj.triggerParam = msInterval > TSDB_MIN_ROLLUP_MAX_DELAY ? msInterval : TSDB_MIN_ROLLUP_MAX_DELAY; + } + if (streamObj.triggerParam > TSDB_MAX_ROLLUP_MAX_DELAY) { + streamObj.triggerParam = TSDB_MAX_ROLLUP_MAX_DELAY; + } + if (mndAllocSmaVgroup(pMnode, pDb, &streamObj.fixedSinkVg) != 0) { mError("sma:%s, failed to create since %s", smaObj.name, terrstr()); return -1; @@ -1131,14 +1141,17 @@ static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc SSmaObj *pSma = NULL; int32_t cols = 0; - SDbObj *pDb = mndAcquireDb(pMnode, pShow->db); - if (pDb == NULL) return 0; + SDbObj *pDb = NULL; + if (strlen(pShow->db) > 0) { + pDb = mndAcquireDb(pMnode, pShow->db); + if (pDb == NULL) return 0; + } while (numOfRows < rows) { pShow->pIter = sdbFetch(pSdb, SDB_SMA, pShow->pIter, (void **)&pSma); if (pShow->pIter == NULL) break; - if (pSma->dbUid != pDb->uid) { + if (NULL != pDb && pSma->dbUid != pDb->uid) { sdbRelease(pSdb, pSma); continue; } @@ -1151,7 +1164,7 @@ static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc STR_TO_VARSTR(n1, (char *)tNameGetTableName(&smaName)); char n2[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(n2, (char *)mndGetDbStr(pDb->name)); + STR_TO_VARSTR(n2, (char *)mndGetDbStr(pSma->db)); SName stbName = {0}; tNameFromString(&stbName, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index e084710e25..8ce22c2b2e 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -45,6 +45,7 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq); static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextStb(SMnode *pMnode, void *pIter); static int32_t mndProcessTableCfgReq(SRpcMsg *pReq); +static int32_t mndAlterStbImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp); int32_t mndInitStb(SMnode *pMnode) { SSdbTable table = { @@ -705,10 +706,10 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat memcpy(pDst->db, pDb->name, TSDB_DB_FNAME_LEN); pDst->createdTime = taosGetTimestampMs(); pDst->updateTime = pDst->createdTime; - pDst->uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN); + pDst->uid = (pCreate->source == 1) ? pCreate->suid : mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN); pDst->dbUid = pDb->uid; - pDst->tagVer = 1; - pDst->colVer = 1; + pDst->tagVer = (pCreate->source != TD_REQ_FROM_APP) ? pCreate->tagVer : 1; + pDst->colVer = (pCreate->source != TD_REQ_FROM_APP) ? pCreate->colVer : 1; pDst->smaVer = 1; pDst->nextColId = 1; pDst->maxdelay[0] = pCreate->delay1; @@ -854,6 +855,7 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { SStbObj *pStb = NULL; SDbObj *pDb = NULL; SMCreateStbReq createReq = {0}; + bool isAlter = false; if (tDeserializeSMCreateStbReq(pReq->pCont, pReq->contLen, &createReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; @@ -869,9 +871,39 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { pStb = mndAcquireStb(pMnode, createReq.name); if (pStb != NULL) { if (createReq.igExists) { - mDebug("stb:%s, already exist, ignore exist is set", createReq.name); - code = 0; - goto _OVER; + if (createReq.source == TD_REQ_FROM_APP) { + mDebug("stb:%s, already exist, ignore exist is set", createReq.name); + code = 0; + goto _OVER; + } else if (pStb->uid != createReq.suid) { + mError("stb:%s, already exist while create, input suid:%" PRId64 " not match with exist suid:%" PRId64, + createReq.name, createReq.suid, pStb->uid); + terrno = TSDB_CODE_MND_STABLE_UID_NOT_MATCH; + goto _OVER; + } else if (createReq.tagVer > 0 || createReq.colVer > 0) { + int32_t tagDelta = pStb->tagVer - createReq.tagVer; + int32_t colDelta = pStb->colVer - createReq.colVer; + int32_t verDelta = tagDelta + verDelta; + mInfo("stb:%s, already exist while create, input tagVer:%d colVer:%d, exist tagVer:%d colVer:%d", + createReq.name, createReq.tagVer, createReq.colVer, pStb->tagVer, pStb->colVer); + if (tagDelta <= 0 && colDelta <= 0) { + mInfo("stb:%s, schema version is not incremented and nothing needs to be done", createReq.name); + code = 0; + goto _OVER; + } else if ((tagDelta == 1 || colDelta == 1) && (verDelta == 1)) { + isAlter = true; + mInfo("stb:%s, schema version is only increased by 1 number, do alter operation", createReq.name); + } else { + mError("stb:%s, schema version increase more than 1 number, error is returned", createReq.name); + terrno = TSDB_CODE_MND_INVALID_SCHEMA_VER; + goto _OVER; + } + } else { + mError("stb:%s, already exist while create, input tagVer:%d colVer:%d is invalid", createReq.name, + createReq.tagVer, createReq.colVer, pStb->tagVer, pStb->colVer); + terrno = TSDB_CODE_MND_INVALID_SCHEMA_VER; + goto _OVER; + } } else { terrno = TSDB_CODE_MND_STB_ALREADY_EXIST; goto _OVER; @@ -900,7 +932,12 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { goto _OVER; } - code = mndCreateStb(pMnode, pReq, &createReq, pDb); + if (isAlter) { + bool needRsp = false; + code = mndAlterStbImp(pMnode, pReq, pDb, pStb, needRsp); + } else { + code = mndCreateStb(pMnode, pReq, &createReq, pDb); + } if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; _OVER: @@ -1466,14 +1503,13 @@ static int32_t mndBuildStbCfg(SMnode *pMnode, const char *dbFName, const char *t return code; } -static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, const SMAlterStbReq *pAlter, SStbObj *pObj, void **pCont, - int32_t *pLen) { +static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, SStbObj *pObj, void **pCont, int32_t *pLen) { int32_t ret; SEncoder ec = {0}; uint32_t contLen = 0; SMAlterStbRsp alterRsp = {0}; SName name = {0}; - tNameFromString(&name, pAlter->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + tNameFromString(&name, pObj->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); alterRsp.pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); if (NULL == alterRsp.pMeta) { @@ -1506,10 +1542,36 @@ static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, const SMAlterStbReq *pAlter, S return 0; } +static int32_t mndAlterStbImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pStb, bool needRsp) { + int32_t code = -1; + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq); + if (pTrans == NULL) goto _OVER; + + mDebug("trans:%d, used to alter stb:%s", pTrans->id, pStb->name); + mndTransSetDbName(pTrans, pDb->name, NULL); + + if (needRsp) { + void *pCont = NULL; + int32_t contLen = 0; + if (mndBuildSMAlterStbRsp(pDb, pStb, &pCont, &contLen) != 0) goto _OVER; + mndTransSetRpcRsp(pTrans, pCont, contLen); + } + + if (mndSetAlterStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + if (mndSetAlterStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) goto _OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + + code = 0; + +_OVER: + mndTransDrop(pTrans); + return code; +} + static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *pAlter, SDbObj *pDb, SStbObj *pOld) { bool needRsp = true; int32_t code = -1; - STrans *pTrans = NULL; SField *pField0 = NULL; SStbObj stbObj = {0}; @@ -1558,30 +1620,9 @@ static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *p } if (code != 0) goto _OVER; - - code = -1; - pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq); - if (pTrans == NULL) goto _OVER; - - mDebug("trans:%d, used to alter stb:%s", pTrans->id, pAlter->name); - mndTransSetDbName(pTrans, pDb->name, NULL); - - if (needRsp) { - void *pCont = NULL; - int32_t contLen = 0; - if (mndBuildSMAlterStbRsp(pDb, pAlter, &stbObj, &pCont, &contLen) != 0) goto _OVER; - mndTransSetRpcRsp(pTrans, pCont, contLen); - } - - if (mndSetAlterStbRedoLogs(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER; - if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER; - if (mndSetAlterStbRedoActions(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; - - code = 0; + code = mndAlterStbImp(pMnode, pReq, pDb, &stbObj, needRsp); _OVER: - mndTransDrop(pTrans); taosMemoryFreeClear(stbObj.pTags); taosMemoryFreeClear(stbObj.pColumns); return code; @@ -1614,14 +1655,6 @@ static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) { goto _OVER; } - if ((alterReq.tagVer > 0 && alterReq.colVer > 0) && - (alterReq.tagVer <= pStb->tagVer || alterReq.colVer <= pStb->colVer)) { - mDebug("stb:%s, already exist, tagVer:%d colVer:%d smaller than in mnode, tagVer:%d colVer:%d, alter success", - alterReq.name, alterReq.tagVer, alterReq.colVer, pStb->tagVer, pStb->colVer); - code = 0; - goto _OVER; - } - if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) { goto _OVER; } @@ -1752,6 +1785,11 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) { } } + if (dropReq.source != TD_REQ_FROM_APP && pStb->uid != dropReq.suid) { + terrno = TSDB_CODE_MND_STB_NOT_EXIST; + goto _OVER; + } + pDb = mndAcquireDbByStb(pMnode, dropReq.name); if (pDb == NULL) { terrno = TSDB_CODE_MND_DB_NOT_SELECTED; diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index 8dde3e92d8..d67e4e8783 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -235,7 +235,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR .pVgEp = pVgEp, }; taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg)); - mInfo("mq rebalance: remove vg %d from consumer %ld", pVgEp->vgId, consumerId); + mInfo("mq rebalance: remove vgId:%d from consumer:%" PRId64, pVgEp->vgId, consumerId); } taosHashRemove(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t)); // put into removed @@ -255,7 +255,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR .pVgEp = pVgEp, }; taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &rebOutput, sizeof(SMqRebOutputVg)); - mInfo("mq rebalance: remove vg %d from unassigned", pVgEp->vgId); + mInfo("mq rebalance: remove vgId:%d from unassigned", pVgEp->vgId); } } @@ -298,7 +298,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR .pVgEp = pVgEp, }; taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg)); - mInfo("mq rebalance: remove vg %d from consumer %ld (first scan)", pVgEp->vgId, pConsumerEp->consumerId); + mInfo("mq rebalance: remove vgId:%d from consumer:%" PRId64 ",(first scan)", pVgEp->vgId, pConsumerEp->consumerId); } imbCnt++; } @@ -312,7 +312,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR .pVgEp = pVgEp, }; taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg)); - mInfo("mq rebalance: remove vg %d from consumer %ld (first scan)", pVgEp->vgId, pConsumerEp->consumerId); + mInfo("mq rebalance: remove vgId:%d from consumer:%" PRId64 ",(first scan)", pVgEp->vgId, pConsumerEp->consumerId); } } } @@ -329,7 +329,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR newConsumerEp.vgs = taosArrayInit(0, sizeof(void *)); taosHashPut(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t), &newConsumerEp, sizeof(SMqConsumerEp)); taosArrayPush(pOutput->newConsumers, &consumerId); - mInfo("mq rebalance: add new consumer %ld", consumerId); + mInfo("mq rebalance: add new consumer:%" PRId64, consumerId); } } @@ -354,7 +354,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp); pRebVg->newConsumerId = pConsumerEp->consumerId; taosArrayPush(pOutput->rebVgs, pRebVg); - mInfo("mq rebalance: add vg %d to consumer %ld (second scan)", pRebVg->pVgEp->vgId, pConsumerEp->consumerId); + mInfo("mq rebalance: add vgId:%d to consumer:%" PRId64 ",(second scan)", pRebVg->pVgEp->vgId, pConsumerEp->consumerId); } } @@ -372,7 +372,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp); pRebVg->newConsumerId = pConsumerEp->consumerId; taosArrayPush(pOutput->rebVgs, pRebVg); - mInfo("mq rebalance: add vg %d to consumer %ld (second scan)", pRebVg->pVgEp->vgId, pConsumerEp->consumerId); + mInfo("mq rebalance: add vgId:%d to consumer:%" PRId64 ",(second scan)", pRebVg->pVgEp->vgId, pConsumerEp->consumerId); } } else { // if all consumer is removed, put all vg into unassigned @@ -385,7 +385,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR ASSERT(pRebOutput->newConsumerId == -1); taosArrayPush(pOutput->pSub->unassignedVgs, &pRebOutput->pVgEp); taosArrayPush(pOutput->rebVgs, pRebOutput); - mInfo("mq rebalance: unassign vg %d (second scan)", pRebOutput->pVgEp->vgId); + mInfo("mq rebalance: unassign vgId:%d (second scan)", pRebOutput->pVgEp->vgId); } } @@ -393,7 +393,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR mInfo("rebalance calculation completed, rebalanced vg:"); for (int32_t i = 0; i < taosArrayGetSize(pOutput->rebVgs); i++) { SMqRebOutputVg *pOutputRebVg = taosArrayGet(pOutput->rebVgs, i); - mInfo("vgId:%d, moved from consumer %" PRId64 " to consumer %" PRId64, pOutputRebVg->pVgEp->vgId, + mInfo("vgId:%d, moved from consumer:%" PRId64 ", to consumer:%" PRId64, pOutputRebVg->pVgEp->vgId, pOutputRebVg->oldConsumerId, pOutputRebVg->newConsumerId); } @@ -546,7 +546,11 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) { char cgroup[TSDB_CGROUP_LEN]; mndSplitSubscribeKey(pRebInfo->key, topic, cgroup, true); SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic); - ASSERT(pTopic); + /*ASSERT(pTopic);*/ + if (pTopic == NULL) { + mError("rebalance %s failed since topic %s was dropped, abort", pRebInfo->key, topic); + continue; + } taosRLockLatch(&pTopic->lock); rebOutput.pSub = mndCreateSub(pMnode, pTopic, pRebInfo->key); diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 8d1220d596..f2a037ab82 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -558,7 +558,7 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) { mndReleaseConsumer(pMnode, pConsumer); mndReleaseTopic(pMnode, pTopic); terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED; - mError("topic:%s, failed to drop since subscribed by consumer %ld in consumer group %s", dropReq.name, + mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s", dropReq.name, pConsumer->consumerId, pConsumer->cgroup); return -1; } diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 85f1ce6843..beb5502926 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -207,7 +207,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg createReq.buffer = pDb->cfg.buffer; createReq.pageSize = pDb->cfg.pageSize; createReq.pages = pDb->cfg.pages; - createReq.lastRowMem = pDb->cfg.lastRowMem; + createReq.cacheLastSize = pDb->cfg.cacheLastSize; createReq.daysPerFile = pDb->cfg.daysPerFile; createReq.daysToKeep0 = pDb->cfg.daysToKeep0; createReq.daysToKeep1 = pDb->cfg.daysToKeep1; @@ -219,7 +219,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg createReq.precision = pDb->cfg.precision; createReq.compression = pDb->cfg.compression; createReq.strict = pDb->cfg.strict; - createReq.cacheLastRow = pDb->cfg.cacheLastRow; + createReq.cacheLast = pDb->cfg.cacheLast; createReq.replica = pVgroup->replica; createReq.selfIndex = -1; createReq.hashBegin = pVgroup->hashBegin; @@ -277,7 +277,7 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_ alterReq.buffer = pDb->cfg.buffer; alterReq.pageSize = pDb->cfg.pageSize; alterReq.pages = pDb->cfg.pages; - alterReq.lastRowMem = pDb->cfg.lastRowMem; + alterReq.cacheLastSize = pDb->cfg.cacheLastSize; alterReq.daysPerFile = pDb->cfg.daysPerFile; alterReq.daysToKeep0 = pDb->cfg.daysToKeep0; alterReq.daysToKeep1 = pDb->cfg.daysToKeep1; @@ -285,7 +285,7 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_ alterReq.fsyncPeriod = pDb->cfg.fsyncPeriod; alterReq.walLevel = pDb->cfg.walLevel; alterReq.strict = pDb->cfg.strict; - alterReq.cacheLastRow = pDb->cfg.cacheLastRow; + alterReq.cacheLast = pDb->cfg.cacheLast; alterReq.replica = pVgroup->replica; for (int32_t v = 0; v < pVgroup->replica; ++v) { @@ -742,8 +742,8 @@ int64_t mndGetVgroupMemory(SMnode *pMnode, SDbObj *pDbInput, SVgObj *pVgroup) { int64_t vgroupMemroy = 0; if (pDb != NULL) { vgroupMemroy = (int64_t)pDb->cfg.buffer * 1024 * 1024 + (int64_t)pDb->cfg.pages * pDb->cfg.pageSize * 1024; - if (pDb->cfg.cacheLastRow > 0) { - vgroupMemroy += (int64_t)pDb->cfg.lastRowMem * 1024 * 1024; + if (pDb->cfg.cacheLast > 0) { + vgroupMemroy += (int64_t)pDb->cfg.cacheLastSize * 1024 * 1024; } } diff --git a/source/dnode/mnode/impl/test/db/db.cpp b/source/dnode/mnode/impl/test/db/db.cpp index a3d129c7c4..0fb8e9d530 100644 --- a/source/dnode/mnode/impl/test/db/db.cpp +++ b/source/dnode/mnode/impl/test/db/db.cpp @@ -50,7 +50,7 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; createReq.numOfStables = 0; createReq.numOfRetensions = 0; @@ -84,7 +84,7 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { alterdbReq.fsyncPeriod = 4000; alterdbReq.walLevel = 2; alterdbReq.strict = 1; - alterdbReq.cacheLastRow = 1; + alterdbReq.cacheLast = 1; alterdbReq.replications = 1; int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq); @@ -146,7 +146,7 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; createReq.numOfStables = 0; createReq.numOfRetensions = 0; diff --git a/source/dnode/mnode/impl/test/dnode/mdnode.cpp b/source/dnode/mnode/impl/test/dnode/mdnode.cpp index 0b42b28219..8e4e728416 100644 --- a/source/dnode/mnode/impl/test/dnode/mdnode.cpp +++ b/source/dnode/mnode/impl/test/dnode/mdnode.cpp @@ -288,7 +288,7 @@ TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; createReq.numOfStables = 0; createReq.numOfRetensions = 0; @@ -319,7 +319,7 @@ TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) { alterdbReq.fsyncPeriod = 4000; alterdbReq.walLevel = 2; alterdbReq.strict = 1; - alterdbReq.cacheLastRow = 1; + alterdbReq.cacheLast = 1; alterdbReq.replications = 3; int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq); @@ -345,7 +345,7 @@ TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) { alterdbReq.fsyncPeriod = 4000; alterdbReq.walLevel = 2; alterdbReq.strict = 1; - alterdbReq.cacheLastRow = 1; + alterdbReq.cacheLast = 1; alterdbReq.replications = 1; int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq); diff --git a/source/dnode/mnode/impl/test/sma/sma.cpp b/source/dnode/mnode/impl/test/sma/sma.cpp index d795816f57..ce6954279f 100644 --- a/source/dnode/mnode/impl/test/sma/sma.cpp +++ b/source/dnode/mnode/impl/test/sma/sma.cpp @@ -55,7 +55,7 @@ void* MndTestSma::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/mnode/impl/test/stb/stb.cpp b/source/dnode/mnode/impl/test/stb/stb.cpp index 56b8936cf4..dfdd8f3a49 100644 --- a/source/dnode/mnode/impl/test/stb/stb.cpp +++ b/source/dnode/mnode/impl/test/stb/stb.cpp @@ -56,7 +56,7 @@ void* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); @@ -277,8 +277,6 @@ void* MndTestStb::BuildAlterStbUpdateColumnBytesReq(const char* stbname, const c req.numOfFields = 1; req.pFields = taosArrayInit(1, sizeof(SField)); req.alterType = TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES; - req.tagVer = verInBlock; - req.colVer = verInBlock; SField field = {0}; field.bytes = bytes; @@ -818,7 +816,7 @@ TEST_F(MndTestStb, 08_Alter_Stb_AlterTagBytes) { { void* pReq = BuildAlterStbUpdateColumnBytesReq(stbname, "col_not_exist", 20, &contLen, 1); SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_STB, pReq, contLen); - ASSERT_EQ(pRsp->code, 0); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_COLUMN_NOT_EXIST); test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname); EXPECT_EQ(test.GetShowRows(), 1); diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 433a0ab5cc..353cedf636 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -48,7 +48,7 @@ void* MndTestTopic::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 3b1a5fa3c5..d8b6964114 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -315,7 +315,7 @@ TEST_F(MndTestUser, 03_Alter_User) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index b13e654caf..0a5fe1001c 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -111,7 +111,7 @@ static int32_t sndProcessTaskDeployReq(SSnode *pNode, SRpcMsg *pMsg) { streamSetupTrigger(pTask); - qInfo("deploy stream: stream id %ld task id %d child id %d on snode", pTask->streamId, pTask->taskId, + qInfo("deploy stream: stream id %" PRId64 " task id %d child id %d on snode", pTask->streamId, pTask->taskId, pTask->selfChildId); taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void *)); diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 897e4f26e2..e9e20912c5 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -3,6 +3,7 @@ add_library(vnode STATIC "") target_sources( vnode PRIVATE + # vnode "src/vnd/vnodeOpen.c" "src/vnd/vnodeBufPool.c" @@ -13,7 +14,6 @@ target_sources( "src/vnd/vnodeSvr.c" "src/vnd/vnodeSync.c" "src/vnd/vnodeSnapshot.c" - "src/vnd/vnodeUtil.c" # meta "src/meta/metaOpen.c" @@ -26,7 +26,6 @@ target_sources( "src/meta/metaSnapshot.c" # sma - "src/sma/sma.c" "src/sma/smaEnv.c" "src/sma/smaUtil.c" "src/sma/smaOpen.c" @@ -47,6 +46,7 @@ target_sources( "src/tsdb/tsdbUtil.c" "src/tsdb/tsdbSnapshot.c" "src/tsdb/tsdbCacheRead.c" + "src/tsdb/tsdbRetention.c" # tq "src/tq/tq.c" @@ -63,7 +63,6 @@ target_include_directories( PUBLIC "inc" PRIVATE "src/inc" PUBLIC "${TD_SOURCE_DIR}/include/libs/scalar" - ) target_link_libraries( vnode @@ -77,18 +76,19 @@ target_link_libraries( PUBLIC executor PUBLIC scheduler PUBLIC tdb - #PUBLIC bdb - #PUBLIC scalar + + # PUBLIC bdb + # PUBLIC scalar PUBLIC transport PUBLIC stream PUBLIC index ) target_compile_definitions(vnode PUBLIC -DMETA_REFACT) -if (${BUILD_WITH_INVERTEDINDEX}) - add_definitions(-DUSE_INVERTED_INDEX) + +if(${BUILD_WITH_INVERTEDINDEX}) + add_definitions(-DUSE_INVERTED_INDEX) endif(${BUILD_WITH_INVERTEDINDEX}) + if(${BUILD_TEST}) add_subdirectory(test) endif(${BUILD_TEST}) - - diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index b87b9a0512..b42b0f2b44 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -38,10 +38,11 @@ extern "C" { #endif // vnode -typedef struct SVnode SVnode; -typedef struct STsdbCfg STsdbCfg; // todo: remove -typedef struct SVnodeCfg SVnodeCfg; -typedef struct SVSnapshotReader SVSnapshotReader; +typedef struct SVnode SVnode; +typedef struct STsdbCfg STsdbCfg; // todo: remove +typedef struct SVnodeCfg SVnodeCfg; +typedef struct SVSnapReader SVSnapReader; +typedef struct SVSnapWriter SVSnapWriter; extern const SVnodeCfg vnodeCfgDefault; @@ -57,10 +58,6 @@ void vnodeStop(SVnode *pVnode); int64_t vnodeGetSyncHandle(SVnode *pVnode); void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot); void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId); -int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever); -int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader); -int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData); - int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen); int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list); int32_t vnodeGetCtbIdList(SVnode *pVnode, int64_t suid, SArray *list); @@ -133,7 +130,7 @@ bool tsdbNextDataBlock(STsdbReader *pReader); void tsdbRetrieveDataBlockInfo(STsdbReader *pReader, SDataBlockInfo *pDataBlockInfo); int32_t tsdbRetrieveDatablockSMA(STsdbReader *pReader, SColumnDataAgg ***pBlockStatis, bool *allHave); SArray *tsdbRetrieveDataBlock(STsdbReader *pTsdbReadHandle, SArray *pColumnIdList); -int32_t tsdbReaderReset(STsdbReader *pReader, SQueryTableDataCond *pCond, int32_t tWinIdx); +int32_t tsdbReaderReset(STsdbReader *pReader, SQueryTableDataCond *pCond); int32_t tsdbGetFileBlocksDistInfo(STsdbReader *pReader, STableBlockDistInfo *pTableBlockInfo); int64_t tsdbGetNumOfRowsInMemTable(STsdbReader *pHandle); void *tsdbGetIdx(SMeta *pMeta); @@ -174,6 +171,9 @@ int32_t tqReaderSetTbUidList(STqReader *pReader, const SArray *tbUidList); int32_t tqReaderAddTbUidList(STqReader *pReader, const SArray *tbUidList); int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList); +int32_t tqSeekVer(STqReader *pReader, int64_t ver); +int32_t tqNextBlock(STqReader *pReader, SFetchRet *ret); + int32_t tqReaderSetDataMsg(STqReader *pReader, SSubmitReq *pMsg, int64_t ver); bool tqNextDataBlock(STqReader *pReader); bool tqNextDataBlockFilterOut(STqReader *pReader, SHashObj *filterOutUids); @@ -182,7 +182,14 @@ int32_t tqRetrieveDataBlock(SSDataBlock *pBlock, STqReader *pReader); // sma int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days); -// need to reposition +// SVSnapReader +int32_t vnodeSnapReaderOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapReader **ppReader); +int32_t vnodeSnapReaderClose(SVSnapReader *pReader); +int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData); +// SVSnapWriter +int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWriter **ppWriter); +int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback); +int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData); // structs struct STsdbCfg { diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index 66d1689d57..e08925acc3 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -57,6 +57,9 @@ int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid); // metaCommit ================== static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64(); } +// metaTable ================== +int metaHandleEntry(SMeta* pMeta, const SMetaEntry* pME); + struct SMeta { TdThreadRwlock lock; diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h index 2d6edae0e7..d5b719dfb9 100644 --- a/source/dnode/vnode/src/inc/sma.h +++ b/source/dnode/vnode/src/inc/sma.h @@ -47,7 +47,9 @@ struct SSmaEnv { }; typedef struct { - int32_t smaRef; + int8_t inited; + int32_t rsetId; + void *tmrHandle; // shared by all fetch tasks } SSmaMgmt; #define SMA_ENV_LOCK(env) ((env)->lock) @@ -64,7 +66,6 @@ struct SRSmaStat { SSma *pSma; int64_t submitVer; int64_t refId; // shared by fetch tasks - void *tmrHandle; // shared by fetch tasks int8_t triggerStat; // shared by fetch tasks int8_t runningStat; // for persistence task SHashObj *rsmaInfoHash; // key: stbUid, value: SRSmaInfo; @@ -81,7 +82,6 @@ struct SSmaStat { #define SMA_TSMA_STAT(s) (&(s)->tsmaStat) #define SMA_RSMA_STAT(s) (&(s)->rsmaStat) #define RSMA_INFO_HASH(r) ((r)->rsmaInfoHash) -#define RSMA_TMR_HANDLE(r) ((r)->tmrHandle) #define RSMA_TRIGGER_STAT(r) (&(r)->triggerStat) #define RSMA_RUNNING_STAT(r) (&(r)->runningStat) #define RSMA_REF_ID(r) ((r)->refId) @@ -95,6 +95,7 @@ enum { TASK_TRIGGER_STAT_CANCELLED = 4, TASK_TRIGGER_STAT_FINISHED = 5, }; + void tdDestroySmaEnv(SSmaEnv *pSmaEnv); void *tdFreeSmaEnv(SSmaEnv *pSmaEnv); @@ -104,6 +105,10 @@ int32_t tdInsertRSmaData(SSma *pSma, char *msg); int32_t tdRefSmaStat(SSma *pSma, SSmaStat *pStat); int32_t tdUnRefSmaStat(SSma *pSma, SSmaStat *pStat); + +void *tdAcquireSmaRef(int32_t rsetId, int64_t refId, const char *tags, int32_t ln); +int32_t tdReleaseSmaRef(int32_t rsetId, int64_t refId, const char *tags, int32_t ln); + int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType); int32_t tdLockSma(SSma *pSma); @@ -183,7 +188,7 @@ static FORCE_INLINE void tdSmaStatSetDropped(STSmaStat *pTStat) { static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType); void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType); -void *tdFreeRSmaInfo(SRSmaInfo *pInfo); +void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo); int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat); int32_t tdProcessRSmaCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, const char *tbName); diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index 9c3bd85c71..8abaac6dff 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -89,6 +89,8 @@ typedef struct { STqExecTb execTb; STqExecDb execDb; }; + // TODO remove it + int64_t tsdbEndVer; } STqExecHandle; @@ -129,6 +131,7 @@ typedef struct { static STqMgmt tqMgmt = {0}; // tqRead +int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffsetVal* offset); int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum); // tqExec diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index cd2dfd3351..bde9e578a7 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -64,6 +64,7 @@ typedef struct SRowIter SRowIter; typedef struct STsdbFS STsdbFS; typedef struct SRowMerger SRowMerger; typedef struct STsdbFSState STsdbFSState; +typedef struct STsdbSnapHdr STsdbSnapHdr; #define TSDB_MAX_SUBBLOCKS 8 #define TSDB_FHDR_SIZE 512 @@ -237,7 +238,7 @@ int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx, uint8_t **ppBuf); // tsdbCache int32_t tsdbOpenCache(STsdb *pTsdb); void tsdbCloseCache(SLRUCache *pCache); -int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row); +int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb *pTsdb); int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, STSRow *row, bool dup); int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **h); int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **h); diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index ae659dc396..0c386babde 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -49,17 +49,20 @@ extern "C" { #endif -typedef struct SVnodeInfo SVnodeInfo; -typedef struct SMeta SMeta; -typedef struct SSma SSma; -typedef struct STsdb STsdb; -typedef struct STQ STQ; -typedef struct SVState SVState; -typedef struct SVBufPool SVBufPool; -typedef struct SQWorker SQHandle; -typedef struct STsdbKeepCfg STsdbKeepCfg; -typedef struct SMetaSnapshotReader SMetaSnapshotReader; -typedef struct STsdbSnapshotReader STsdbSnapshotReader; +typedef struct SVnodeInfo SVnodeInfo; +typedef struct SMeta SMeta; +typedef struct SSma SSma; +typedef struct STsdb STsdb; +typedef struct STQ STQ; +typedef struct SVState SVState; +typedef struct SVBufPool SVBufPool; +typedef struct SQWorker SQHandle; +typedef struct STsdbKeepCfg STsdbKeepCfg; +typedef struct SMetaSnapReader SMetaSnapReader; +typedef struct SMetaSnapWriter SMetaSnapWriter; +typedef struct STsdbSnapReader STsdbSnapReader; +typedef struct STsdbSnapWriter STsdbSnapWriter; +typedef struct SSnapDataHdr SSnapDataHdr; #define VNODE_META_DIR "meta" #define VNODE_TSDB_DIR "tsdb" @@ -72,10 +75,8 @@ typedef struct STsdbSnapshotReader STsdbSnapshotReader; #define VNODE_RSMA2_DIR "rsma2" // vnd.h -void* vnodeBufPoolMalloc(SVBufPool* pPool, int size); -void vnodeBufPoolFree(SVBufPool* pPool, void* p); -int32_t vnodeRealloc(void** pp, int32_t size); -void vnodeFree(void* p); +void* vnodeBufPoolMalloc(SVBufPool* pPool, int size); +void vnodeBufPoolFree(SVBufPool* pPool, void* p); // meta typedef struct SMCtbCursor SMCtbCursor; @@ -109,9 +110,6 @@ STSma* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid); STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid, bool deepCopy); SArray* metaGetSmaIdsByTable(SMeta* pMeta, tb_uid_t uid); SArray* metaGetSmaTbUids(SMeta* pMeta); -int32_t metaSnapshotReaderOpen(SMeta* pMeta, SMetaSnapshotReader** ppReader, int64_t sver, int64_t ever); -int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader); -int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData); void* metaGetIdx(SMeta* pMeta); void* metaGetIvtIdx(SMeta* pMeta); int metaTtlSmaller(SMeta* pMeta, uint64_t time, SArray* uidList); @@ -131,9 +129,6 @@ int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* p int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); STsdbReader tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, void* pMemRef); -int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever); -int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader); -int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData); // tq int tqInit(); @@ -163,6 +158,8 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool const char* stbFullName, int32_t vgId); // sma +int32_t smaInit(); +void smaCleanUp(); int32_t smaOpen(SVnode* pVnode); int32_t smaClose(SSma* pSma); int32_t smaBegin(SSma* pSma); @@ -181,6 +178,23 @@ int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore); void tdUidStoreDestory(STbUidStore* pStore); void* tdUidStoreFree(STbUidStore* pStore); +// SMetaSnapReader ======================================== +int32_t metaSnapReaderOpen(SMeta* pMeta, int64_t sver, int64_t ever, SMetaSnapReader** ppReader); +int32_t metaSnapReaderClose(SMetaSnapReader** ppReader); +int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData); +// SMetaSnapWriter ======================================== +int32_t metaSnapWriterOpen(SMeta* pMeta, int64_t sver, int64_t ever, SMetaSnapWriter** ppWriter); +int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData); +int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback); +// STsdbSnapReader ======================================== +int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapReader** ppReader); +int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader); +int32_t tsdbSnapRead(STsdbSnapReader* pReader, uint8_t** ppData); +// STsdbSnapWriter ======================================== +int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWriter** ppWriter); +int32_t tsdbSnapWrite(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData); +int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback); + typedef struct { int8_t streamType; // sma or other int8_t dstType; @@ -200,7 +214,9 @@ typedef struct { struct SVState { int64_t committed; int64_t applied; + int64_t applyTerm; int64_t commitID; + int64_t commitTerm; }; struct SVnodeInfo { @@ -289,6 +305,12 @@ struct SSma { // sma void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data); +struct SSnapDataHdr { + int8_t type; + int64_t size; + uint8_t data[]; +}; + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index db959a83b0..e1236c2853 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -147,6 +147,8 @@ int metaTbCursorNext(SMTbCursor *pTbCur) { return -1; } + tDecoderClear(&pTbCur->mr.coder); + metaGetTableEntryByVersion(&pTbCur->mr, *(int64_t *)pTbCur->pVal, *(tb_uid_t *)pTbCur->pKey); if (pTbCur->mr.me.type == TSDB_SUPER_TABLE) { continue; diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c index 5757039d55..ac84842e85 100644 --- a/source/dnode/vnode/src/meta/metaSnapshot.c +++ b/source/dnode/vnode/src/meta/metaSnapshot.c @@ -15,53 +15,57 @@ #include "meta.h" -struct SMetaSnapshotReader { +// SMetaSnapReader ======================================== +struct SMetaSnapReader { SMeta* pMeta; - TBC* pTbc; int64_t sver; int64_t ever; + TBC* pTbc; }; -int32_t metaSnapshotReaderOpen(SMeta* pMeta, SMetaSnapshotReader** ppReader, int64_t sver, int64_t ever) { - int32_t code = 0; - int32_t c = 0; - SMetaSnapshotReader* pMetaReader = NULL; +int32_t metaSnapReaderOpen(SMeta* pMeta, int64_t sver, int64_t ever, SMetaSnapReader** ppReader) { + int32_t code = 0; + int32_t c = 0; + SMetaSnapReader* pMetaSnapReader = NULL; - pMetaReader = (SMetaSnapshotReader*)taosMemoryCalloc(1, sizeof(*pMetaReader)); - if (pMetaReader == NULL) { + // alloc + pMetaSnapReader = (SMetaSnapReader*)taosMemoryCalloc(1, sizeof(*pMetaSnapReader)); + if (pMetaSnapReader == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } - pMetaReader->pMeta = pMeta; - pMetaReader->sver = sver; - pMetaReader->ever = ever; - code = tdbTbcOpen(pMeta->pTbDb, &pMetaReader->pTbc, NULL); + pMetaSnapReader->pMeta = pMeta; + pMetaSnapReader->sver = sver; + pMetaSnapReader->ever = ever; + + // impl + code = tdbTbcOpen(pMeta->pTbDb, &pMetaSnapReader->pTbc, NULL); if (code) { goto _err; } - code = tdbTbcMoveTo(pMetaReader->pTbc, &(STbDbKey){.version = sver, .uid = INT64_MIN}, sizeof(STbDbKey), &c); + code = tdbTbcMoveTo(pMetaSnapReader->pTbc, &(STbDbKey){.version = sver, .uid = INT64_MIN}, sizeof(STbDbKey), &c); if (code) { goto _err; } - *ppReader = pMetaReader; + *ppReader = pMetaSnapReader; return code; _err: + metaError("vgId:%d meta snap reader open failed since %s", TD_VID(pMeta->pVnode), tstrerror(code)); *ppReader = NULL; return code; } -int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader) { - if (pReader) { - tdbTbcClose(pReader->pTbc); - taosMemoryFree(pReader); - } +int32_t metaSnapReaderClose(SMetaSnapReader** ppReader) { + tdbTbcClose((*ppReader)->pTbc); + taosMemoryFree(*ppReader); + *ppReader = NULL; return 0; } -int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nDatap) { +int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) { const void* pKey = NULL; const void* pData = NULL; int32_t nKey = 0; @@ -71,23 +75,110 @@ int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* for (;;) { code = tdbTbcGet(pReader->pTbc, &pKey, &nKey, &pData, &nData); if (code || ((STbDbKey*)pData)->version > pReader->ever) { - return TSDB_CODE_VND_READ_END; + code = TSDB_CODE_VND_READ_END; + goto _exit; } if (((STbDbKey*)pData)->version < pReader->sver) { + tdbTbcMoveToNext(pReader->pTbc); continue; } + tdbTbcMoveToNext(pReader->pTbc); break; } // copy the data - if (vnodeRealloc(ppData, nData) < 0) { + if (tRealloc(ppData, sizeof(SSnapDataHdr) + nData) < 0) { code = TSDB_CODE_OUT_OF_MEMORY; return code; } + ((SSnapDataHdr*)(*ppData))->type = 0; // TODO: use macro + ((SSnapDataHdr*)(*ppData))->size = nData; + memcpy(((SSnapDataHdr*)(*ppData))->data, pData, nData); - memcpy(*ppData, pData, nData); - *nDatap = nData; +_exit: + return code; +} + +// SMetaSnapWriter ======================================== +struct SMetaSnapWriter { + SMeta* pMeta; + int64_t sver; + int64_t ever; +}; + +static int32_t metaSnapRollback(SMetaSnapWriter* pWriter) { + int32_t code = 0; + // TODO + return code; +} + +static int32_t metaSnapCommit(SMetaSnapWriter* pWriter) { + int32_t code = 0; + // TODO + return code; +} + +int32_t metaSnapWriterOpen(SMeta* pMeta, int64_t sver, int64_t ever, SMetaSnapWriter** ppWriter) { + int32_t code = 0; + SMetaSnapWriter* pWriter; + + // alloc + pWriter = (SMetaSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter)); + if (pWriter == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pWriter->pMeta = pMeta; + pWriter->sver = sver; + pWriter->ever = ever; + + *ppWriter = pWriter; + return code; + +_err: + metaError("vgId:%d meta snapshot writer open failed since %s", TD_VID(pMeta->pVnode), tstrerror(code)); + *ppWriter = NULL; + return code; +} + +int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback) { + int32_t code = 0; + SMetaSnapWriter* pWriter = *ppWriter; + + if (rollback) { + code = metaSnapRollback(pWriter); + if (code) goto _err; + } else { + code = metaSnapCommit(pWriter); + if (code) goto _err; + } + taosMemoryFree(pWriter); + *ppWriter = NULL; + + return code; + +_err: + metaError("vgId:%d meta snapshot writer close failed since %s", TD_VID(pWriter->pMeta->pVnode), tstrerror(code)); + return code; +} + +int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { + int32_t code = 0; + SMeta* pMeta = pWriter->pMeta; + SMetaEntry metaEntry = {0}; + SDecoder* pDecoder = &(SDecoder){0}; + + tDecoderInit(pDecoder, pData, nData); + metaDecodeEntry(pDecoder, &metaEntry); + + code = metaHandleEntry(pMeta, &metaEntry); + if (code) goto _err; + + return code; + +_err: + metaError("vgId:%d meta snapshot write failed since %s", TD_VID(pMeta->pVnode), tstrerror(code)); return code; } \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 341173103c..daf7ccb26a 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -17,7 +17,6 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); static int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); -static int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME); static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME); @@ -51,7 +50,7 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const if (pMeta->pTagIvtIdx == NULL || pCtbEntry == NULL) { return -1; } - void * data = pCtbEntry->ctbEntry.pTags; + void *data = pCtbEntry->ctbEntry.pTags; const char *tagName = pSchema->name; tb_uid_t suid = pCtbEntry->ctbEntry.suid; @@ -70,7 +69,7 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i); char type = pTagVal->type; - char * key = pTagVal->pKey; + char *key = pTagVal->pKey; int32_t nKey = strlen(key); SIndexTerm *term = NULL; @@ -78,7 +77,7 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0); } else if (type == TSDB_DATA_TYPE_NCHAR) { if (pTagVal->nData > 0) { - char * val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); + char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE); memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE); type = TSDB_DATA_TYPE_VARCHAR; @@ -109,7 +108,7 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche if (pMeta->pTagIvtIdx == NULL || pCtbEntry == NULL) { return -1; } - void * data = pCtbEntry->ctbEntry.pTags; + void *data = pCtbEntry->ctbEntry.pTags; const char *tagName = pSchema->name; tb_uid_t suid = pCtbEntry->ctbEntry.suid; @@ -128,7 +127,7 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i); char type = pTagVal->type; - char * key = pTagVal->pKey; + char *key = pTagVal->pKey; int32_t nKey = strlen(key); SIndexTerm *term = NULL; @@ -136,7 +135,7 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche term = indexTermCreate(suid, DEL_VALUE, TSDB_DATA_TYPE_VARCHAR, key, nKey, NULL, 0); } else if (type == TSDB_DATA_TYPE_NCHAR) { if (pTagVal->nData > 0) { - char * val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); + char *val = taosMemoryCalloc(1, pTagVal->nData + VARSTR_HEADER_SIZE); int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE); memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE); type = TSDB_DATA_TYPE_VARCHAR; @@ -169,9 +168,9 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { int vLen = 0; const void *pKey = NULL; const void *pVal = NULL; - void * pBuf = NULL; + void *pBuf = NULL; int32_t szBuf = 0; - void * p = NULL; + void *p = NULL; SMetaReader mr = {0}; // validate req @@ -229,7 +228,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) { } // drop all child tables - TBC * pCtbIdxc = NULL; + TBC *pCtbIdxc = NULL; SArray *pArray = taosArrayInit(8, sizeof(tb_uid_t)); tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn); @@ -285,8 +284,8 @@ _exit: int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { SMetaEntry oStbEntry = {0}; SMetaEntry nStbEntry = {0}; - TBC * pUidIdxc = NULL; - TBC * pTbDbc = NULL; + TBC *pUidIdxc = NULL; + TBC *pTbDbc = NULL; const void *pData; int nData; int64_t oversion; @@ -409,7 +408,7 @@ _err: } int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids) { - void * pData = NULL; + void *pData = NULL; int nData = 0; int rc = 0; tb_uid_t uid; @@ -477,7 +476,7 @@ static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { } static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { - void * pData = NULL; + void *pData = NULL; int nData = 0; int rc = 0; SMetaEntry e = {0}; @@ -538,14 +537,14 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { } static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq, STableMetaRsp *pMetaRsp) { - void * pVal = NULL; + void *pVal = NULL; int nVal = 0; - const void * pData = NULL; + const void *pData = NULL; int nData = 0; int ret = 0; tb_uid_t uid; int64_t oversion; - SSchema * pColumn = NULL; + SSchema *pColumn = NULL; SMetaEntry entry = {0}; SSchemaWrapper *pSchema; int c; @@ -699,7 +698,7 @@ _err: static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { SMetaEntry ctbEntry = {0}; SMetaEntry stbEntry = {0}; - void * pVal = NULL; + void *pVal = NULL; int nVal = 0; int ret; int c; @@ -730,7 +729,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA oversion = *(int64_t *)pData; // search table.db - TBC * pTbDbc = NULL; + TBC *pTbDbc = NULL; SDecoder dc1 = {0}; SDecoder dc2 = {0}; @@ -754,7 +753,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA metaDecodeEntry(&dc2, &stbEntry); SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag; - SSchema * pColumn = NULL; + SSchema *pColumn = NULL; int32_t iCol = 0; for (;;) { pColumn = NULL; @@ -784,8 +783,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA memcpy((void *)ctbEntry.ctbEntry.pTags, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal); } else { const STag *pOldTag = (const STag *)ctbEntry.ctbEntry.pTags; - STag * pNewTag = NULL; - SArray * pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal)); + STag *pNewTag = NULL; + SArray *pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal)); if (!pTagArray) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto _err; @@ -844,7 +843,7 @@ _err: } static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { - void * pVal = NULL; + void *pVal = NULL; int nVal = 0; const void *pData = NULL; int nData = 0; @@ -948,8 +947,8 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMeta static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) { STbDbKey tbDbKey; - void * pKey = NULL; - void * pVal = NULL; + void *pKey = NULL; + void *pVal = NULL; int kLen = 0; int vLen = 0; SEncoder coder = {0}; @@ -1055,14 +1054,14 @@ static void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey) { } static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { - void * pData = NULL; + void *pData = NULL; int nData = 0; STbDbKey tbDbKey = {0}; SMetaEntry stbEntry = {0}; - STagIdxKey * pTagIdxKey = NULL; + STagIdxKey *pTagIdxKey = NULL; int32_t nTagIdxKey; const SSchema *pTagColumn; // = &stbEntry.stbEntry.schema.pSchema[0]; - const void * pTagData = NULL; // + const void *pTagData = NULL; // int32_t nTagData = 0; SDecoder dc = {0}; @@ -1109,7 +1108,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) { SEncoder coder = {0}; - void * pVal = NULL; + void *pVal = NULL; int vLen = 0; int rcode = 0; SSkmDbKey skmDbKey = {0}; @@ -1151,7 +1150,7 @@ _exit: return rcode; } -static int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) { +int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) { metaWLock(pMeta); // save to table.db diff --git a/source/dnode/vnode/src/sma/sma.c b/source/dnode/vnode/src/sma/sma.c deleted file mode 100644 index 12f93f9400..0000000000 --- a/source/dnode/vnode/src/sma/sma.c +++ /dev/null @@ -1,257 +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 "sma.h" - -// functions for external invocation - -// TODO: Who is responsible for resource allocate and release? -int32_t tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg) { - int32_t code = TSDB_CODE_SUCCESS; - - if ((code = tdProcessTSmaInsertImpl(pSma, indexUid, msg)) < 0) { - smaWarn("vgId:%d, insert tsma data failed since %s", SMA_VID(pSma), tstrerror(terrno)); - } - // TODO: destroy SSDataBlocks(msg) - return code; -} - -int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg) { - int32_t code = TSDB_CODE_SUCCESS; - - if ((code = tdProcessTSmaCreateImpl(pSma, version, msg)) < 0) { - smaWarn("vgId:%d, create tsma failed since %s", SMA_VID(pSma), tstrerror(terrno)); - } - // TODO: destroy SSDataBlocks(msg) - return code; -} - -int32_t smaGetTSmaDays(SVnodeCfg* pCfg, void* pCont, uint32_t contLen, int32_t* days) { - int32_t code = TSDB_CODE_SUCCESS; - if ((code = tdProcessTSmaGetDaysImpl(pCfg, pCont, contLen, days)) < 0) { - smaWarn("vgId:%d, get tsma days failed since %s", pCfg->vgId, tstrerror(terrno)); - } - smaDebug("vgId:%d, get tsma days %d", pCfg->vgId, *days); - return code; -} - - -// functions for internal invocation - -#if 0 - -/** - * @brief TODO: Assume that the final generated result it less than 3M - * - * @param pReq - * @param pDataBlocks - * @param vgId - * @param suid // TODO: check with Liao whether suid response is reasonable - * - * TODO: colId should be set - */ -int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId, - tb_uid_t suid, const char* stbName, bool isCreateCtb) { - int32_t sz = taosArrayGetSize(pDataBlocks); - int32_t bufSize = sizeof(SSubmitReq); - for (int32_t i = 0; i < sz; ++i) { - SDataBlockInfo* pBlkInfo = &((SSDataBlock*)taosArrayGet(pDataBlocks, i))->info; - bufSize += pBlkInfo->rows * (TD_ROW_HEAD_LEN + pBlkInfo->rowSize + BitmapLen(pBlkInfo->numOfCols)); - bufSize += sizeof(SSubmitBlk); - } - - *pReq = taosMemoryCalloc(1, bufSize); - if (!(*pReq)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_FAILED; - } - void* pDataBuf = *pReq; - - SArray* pTagArray = NULL; - int32_t msgLen = sizeof(SSubmitReq); - int32_t numOfBlks = 0; - int32_t schemaLen = 0; - SRowBuilder rb = {0}; - tdSRowInit(&rb, pTSchema->version); - - for (int32_t i = 0; i < sz; ++i) { - SSDataBlock* pDataBlock = taosArrayGet(pDataBlocks, i); - SDataBlockInfo* pDataBlkInfo = &pDataBlock->info; - int32_t colNum = pDataBlkInfo->numOfCols; - int32_t rows = pDataBlkInfo->rows; - int32_t rowSize = pDataBlkInfo->rowSize; - int64_t groupId = pDataBlkInfo->groupId; - - if (rb.nCols != colNum) { - tdSRowSetTpInfo(&rb, colNum, pTSchema->flen); - } - - if(isCreateCtb) { - SMetaReader mr = {0}; - const char* ctbName = buildCtbNameByGroupId(stbName, pDataBlock->info.groupId); - if (metaGetTableEntryByName(&mr, ctbName) != 0) { - smaDebug("vgId:%d, no tsma ctb %s exists", vgId, ctbName); - } - SVCreateTbReq ctbReq = {0}; - ctbReq.name = ctbName; - ctbReq.type = TSDB_CHILD_TABLE; - ctbReq.ctb.suid = suid; - - STagVal tagVal = {.cid = colNum + PRIMARYKEY_TIMESTAMP_COL_ID, - .type = TSDB_DATA_TYPE_BIGINT, - .i64 = groupId}; - STag* pTag = NULL; - if(!pTagArray) { - pTagArray = taosArrayInit(1, sizeof(STagVal)); - if (!pTagArray) goto _err; - } - taosArrayClear(pTagArray); - taosArrayPush(pTagArray, &tagVal); - tTagNew(pTagArray, 1, false, &pTag); - if (pTag == NULL) { - tdDestroySVCreateTbReq(&ctbReq); - goto _err; - } - ctbReq.ctb.pTag = (uint8_t*)pTag; - - int32_t code; - tEncodeSize(tEncodeSVCreateTbReq, &ctbReq, schemaLen, code); - - tdDestroySVCreateTbReq(&ctbReq); - if (code < 0) { - goto _err; - } - } - - - - SSubmitBlk* pSubmitBlk = POINTER_SHIFT(pDataBuf, msgLen); - pSubmitBlk->suid = suid; - pSubmitBlk->uid = groupId; - pSubmitBlk->numOfRows = rows; - - msgLen += sizeof(SSubmitBlk); - int32_t dataLen = 0; - for (int32_t j = 0; j < rows; ++j) { // iterate by row - tdSRowResetBuf(&rb, POINTER_SHIFT(pDataBuf, msgLen)); // set row buf - bool isStartKey = false; - int32_t offset = 0; - for (int32_t k = 0; k < colNum; ++k) { // iterate by column - SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k); - STColumn* pCol = &pTSchema->columns[k]; - void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); - switch (pColInfoData->info.type) { - case TSDB_DATA_TYPE_TIMESTAMP: - if (!isStartKey) { - isStartKey = true; - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true, - offset, k); - - } else { - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, - true, offset, k); - } - break; - case TSDB_DATA_TYPE_NCHAR: { - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_NCHAR, TD_VTYPE_NORM, var, true, - offset, k); - break; - } - case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_VARCHAR, TD_VTYPE_NORM, var, true, - offset, k); - break; - } - case TSDB_DATA_TYPE_VARBINARY: - case TSDB_DATA_TYPE_DECIMAL: - case TSDB_DATA_TYPE_BLOB: - case TSDB_DATA_TYPE_JSON: - case TSDB_DATA_TYPE_MEDIUMBLOB: - uError("the column type %" PRIi16 " is defined but not implemented yet", pColInfoData->info.type); - TASSERT(0); - break; - default: - if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) { - if (pCol->type == pColInfoData->info.type) { - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, var, true, offset, - k); - } else { - char tv[8] = {0}; - if (pColInfoData->info.type == TSDB_DATA_TYPE_FLOAT) { - float v = 0; - GET_TYPED_DATA(v, float, pColInfoData->info.type, var); - SET_TYPED_DATA(&tv, pCol->type, v); - } else if (pColInfoData->info.type == TSDB_DATA_TYPE_DOUBLE) { - double v = 0; - GET_TYPED_DATA(v, double, pColInfoData->info.type, var); - SET_TYPED_DATA(&tv, pCol->type, v); - } else if (IS_SIGNED_NUMERIC_TYPE(pColInfoData->info.type)) { - int64_t v = 0; - GET_TYPED_DATA(v, int64_t, pColInfoData->info.type, var); - SET_TYPED_DATA(&tv, pCol->type, v); - } else { - uint64_t v = 0; - GET_TYPED_DATA(v, uint64_t, pColInfoData->info.type, var); - SET_TYPED_DATA(&tv, pCol->type, v); - } - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, tv, true, offset, - k); - } - } else { - uError("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type); - TASSERT(0); - } - break; - } - offset += TYPE_BYTES[pCol->type]; // sum/avg would convert to int64_t/uint64_t/double during aggregation - } - dataLen += TD_ROW_LEN(rb.pBuf); -#ifdef TD_DEBUG_PRINT_ROW - tdSRowPrint(rb.pBuf, pTSchema, __func__); -#endif - } - - ++numOfBlks; - - pSubmitBlk->dataLen = dataLen; - msgLen += pSubmitBlk->dataLen; - } - - (*pReq)->length = msgLen; - - (*pReq)->header.vgId = htonl(vgId); - (*pReq)->header.contLen = htonl(msgLen); - (*pReq)->length = (*pReq)->header.contLen; - (*pReq)->numOfBlocks = htonl(numOfBlks); - SSubmitBlk* blk = (SSubmitBlk*)((*pReq) + 1); - while (numOfBlks--) { - int32_t dataLen = blk->dataLen; - blk->uid = htobe64(blk->uid); - blk->suid = htobe64(blk->suid); - blk->padding = htonl(blk->padding); - blk->sversion = htonl(blk->sversion); - blk->dataLen = htonl(blk->dataLen); - blk->schemaLen = htonl(blk->schemaLen); - blk->numOfRows = htons(blk->numOfRows); - blk = (SSubmitBlk*)(blk->data + dataLen); - } - return TSDB_CODE_SUCCESS; -_err: - taosMemoryFreeClear(*pReq); - taosArrayDestroy(pTagArray); - - return TSDB_CODE_FAILED; -} -#endif diff --git a/source/dnode/vnode/src/sma/smaCommit.c b/source/dnode/vnode/src/sma/smaCommit.c index 6e75176136..e241c14fc7 100644 --- a/source/dnode/vnode/src/sma/smaCommit.c +++ b/source/dnode/vnode/src/sma/smaCommit.c @@ -121,7 +121,7 @@ static int32_t tdProcessRSmaPreCommitImpl(SSma *pSma) { // step 3: perform persist task for qTaskInfo tdRSmaPersistExecImpl(pRSmaStat); - smaDebug("vgId:%d, rsma pre commit succeess", SMA_VID(pSma)); + smaDebug("vgId:%d, rsma pre commit success", SMA_VID(pSma)); return TSDB_CODE_SUCCESS; } @@ -173,6 +173,7 @@ static int32_t tdProcessRSmaPostCommitImpl(SSma *pSma) { } if ((pDir = taosOpenDir(dir)) == NULL) { + regfree(®ex); terrno = TAOS_SYSTEM_ERROR(errno); smaWarn("vgId:%d, rsma post commit, open dir %s failed since %s", TD_VID(pVnode), dir, terrstr()); return TSDB_CODE_FAILED; diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c index c7b938f884..5eb9665326 100644 --- a/source/dnode/vnode/src/sma/smaEnv.c +++ b/source/dnode/vnode/src/sma/smaEnv.c @@ -18,7 +18,7 @@ typedef struct SSmaStat SSmaStat; #define RSMA_TASK_INFO_HASH_SLOT 8 -#define SMA_MGMT_REF_NUM 1024 +#define SMA_MGMT_REF_NUM 10240 extern SSmaMgmt smaMgmt; @@ -30,7 +30,73 @@ static int32_t tdInitSmaEnv(SSma *pSma, int8_t smaType, const char *path, SSmaE static void *tdFreeTSmaStat(STSmaStat *pStat); static void tdDestroyRSmaStat(void *pRSmaStat); +/** + * @brief rsma init + * + * @return int32_t + */ // implementation +int32_t smaInit() { + int8_t old; + int32_t nLoops = 0; + while (1) { + old = atomic_val_compare_exchange_8(&smaMgmt.inited, 0, 2); + if (old != 2) break; + if (++nLoops > 1000) { + sched_yield(); + nLoops = 0; + } + } + + if (old == 0) { + // init tref rset + smaMgmt.rsetId = taosOpenRef(SMA_MGMT_REF_NUM, tdDestroyRSmaStat); + + if (smaMgmt.rsetId < 0) { + atomic_store_8(&smaMgmt.inited, 0); + smaError("failed to init sma rset since %s", terrstr()); + return TSDB_CODE_FAILED; + } + + // init fetch timer handle + smaMgmt.tmrHandle = taosTmrInit(10000, 100, 10000, "RSMA"); + if (!smaMgmt.tmrHandle) { + taosCloseRef(smaMgmt.rsetId); + atomic_store_8(&smaMgmt.inited, 0); + smaError("failed to init sma tmr hanle since %s", terrstr()); + return TSDB_CODE_FAILED; + } + + atomic_store_8(&smaMgmt.inited, 1); + smaInfo("sma mgmt env is initialized, rsetId:%d, tmrHandle:%p", smaMgmt.rsetId, smaMgmt.tmrHandle); + } + + return TSDB_CODE_SUCCESS; +} + +/** + * @brief rsma cleanup + * + */ +void smaCleanUp() { + int8_t old; + int32_t nLoops = 0; + while (1) { + old = atomic_val_compare_exchange_8(&smaMgmt.inited, 1, 2); + if (old != 2) break; + if (++nLoops > 1000) { + sched_yield(); + nLoops = 0; + } + } + + if (old == 1) { + taosCloseRef(smaMgmt.rsetId); + taosTmrCleanUp(smaMgmt.tmrHandle); + smaInfo("sma mgmt env is cleaned up, rsetId:%d, tmrHandle:%p", smaMgmt.rsetId, smaMgmt.tmrHandle); + atomic_store_8(&smaMgmt.inited, 0); + } +} static SSmaEnv *tdNewSmaEnv(const SSma *pSma, int8_t smaType, const char *path) { SSmaEnv *pEnv = NULL; @@ -135,34 +201,24 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_INIT); // init smaMgmt - smaMgmt.smaRef = taosOpenRef(SMA_MGMT_REF_NUM, tdDestroyRSmaStat); - if (smaMgmt.smaRef < 0) { - smaError("init smaRef failed, num:%d", SMA_MGMT_REF_NUM); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_FAILED; - } + smaInit(); - int64_t refId = taosAddRef(smaMgmt.smaRef, pRSmaStat); + int64_t refId = taosAddRef(smaMgmt.rsetId, pRSmaStat); if (refId < 0) { - smaError("taosAddRef smaRef failed, since:%s", tstrerror(terrno)); + smaError("vgId:%d, taosAddRef refId:%" PRIi64 " to rsetId rsetId:%d max:%d failed since:%s", SMA_VID(pSma), + refId, smaMgmt.rsetId, SMA_MGMT_REF_NUM, tstrerror(terrno)); return TSDB_CODE_FAILED; + } else { + smaDebug("vgId:%d, taosAddRef refId:%" PRIi64 " to rsetId rsetId:%d max:%d succeed", SMA_VID(pSma), refId, + smaMgmt.rsetId, SMA_MGMT_REF_NUM); } pRSmaStat->refId = refId; - // init timer - RSMA_TMR_HANDLE(pRSmaStat) = taosTmrInit(10000, 100, 10000, "RSMA"); - if (!RSMA_TMR_HANDLE(pRSmaStat)) { - taosMemoryFreeClear(*pSmaStat); - return TSDB_CODE_FAILED; - } // init hash RSMA_INFO_HASH(pRSmaStat) = taosHashInit( RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK); if (!RSMA_INFO_HASH(pRSmaStat)) { - if (RSMA_TMR_HANDLE(pRSmaStat)) { - taosTmrCleanUp(RSMA_TMR_HANDLE(pRSmaStat)); - } taosMemoryFreeClear(*pSmaStat); return TSDB_CODE_FAILED; } @@ -223,7 +279,7 @@ static void tdDestroyRSmaStat(void *pRSmaStat) { void *infoHash = taosHashIterate(RSMA_INFO_HASH(pStat), NULL); while (infoHash) { SRSmaInfo *pSmaInfo = *(SRSmaInfo **)infoHash; - tdFreeRSmaInfo(pSmaInfo); + tdFreeRSmaInfo(pSma, pSmaInfo); infoHash = taosHashIterate(RSMA_INFO_HASH(pStat), infoHash); } } @@ -244,11 +300,6 @@ static void tdDestroyRSmaStat(void *pRSmaStat) { nLoops = 0; } } - - // step 6: cleanup the timer handle - if (RSMA_TMR_HANDLE(pStat)) { - taosTmrCleanUp(RSMA_TMR_HANDLE(pStat)); - } } } @@ -275,8 +326,13 @@ int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) { tdDestroyTSmaStat(SMA_TSMA_STAT(pSmaStat)); } else if (smaType == TSDB_SMA_TYPE_ROLLUP) { SRSmaStat *pRSmaStat = SMA_RSMA_STAT(pSmaStat); - if (taosRemoveRef(smaMgmt.smaRef, RSMA_REF_ID(pRSmaStat)) < 0) { - smaError("remove refId from rsmaRef:0x%" PRIx64 " failed since %s", RSMA_REF_ID(pRSmaStat), terrstr()); + if (taosRemoveRef(smaMgmt.rsetId, RSMA_REF_ID(pRSmaStat)) < 0) { + smaError("vgId:%d, remove refId:%" PRIi64 " from rsmaRef:%" PRIi32 " failed since %s", SMA_VID(pRSmaStat->pSma), + RSMA_REF_ID(pRSmaStat), smaMgmt.rsetId, terrstr()); + ASSERT(0); + } else { + smaDebug("vgId:%d, remove refId:%" PRIi64 " from rsmaRef:%" PRIi32 " succeed", SMA_VID(pRSmaStat->pSma), + RSMA_REF_ID(pRSmaStat), smaMgmt.rsetId); } } else { ASSERT(0); @@ -323,7 +379,7 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) { } break; default: - TASSERT(0); + smaError("vgId:%d undefined smaType:%", SMA_VID(pSma), smaType); return TSDB_CODE_FAILED; } diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 4c2e606e0e..efa2886e48 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -19,23 +19,27 @@ #define RSMA_QTASKINFO_HEAD_LEN (sizeof(int32_t) + sizeof(int8_t) + sizeof(int64_t)) // len + type + suid SSmaMgmt smaMgmt = { - .smaRef = -1, + .inited = 0, + .rsetId = -1, }; #define TD_QTASKINFO_FNAME_PREFIX "qtaskinfo.ver" typedef struct SRSmaQTaskInfoItem SRSmaQTaskInfoItem; typedef struct SRSmaQTaskInfoIter SRSmaQTaskInfoIter; -static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid); -static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids); -static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaInfo *pRSmaInfo, SReadHandle *handle, - int8_t idx); -static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *rsmaItem, - tb_uid_t suid, int8_t level); -static void tdRSmaFetchTrigger(void *param, void *tmrId); -static void tdRSmaPersistTrigger(void *param, void *tmrId); -static void *tdRSmaPersistExec(void *param); -static void tdRSmaQTaskInfoGetFName(int32_t vid, int64_t version, char *outputName); +static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid); +static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids); +static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat *pStat, SRSmaInfo *pRSmaInfo, + SReadHandle *handle, int8_t idx); +static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *rsmaItem, + STSchema *pTSchema, tb_uid_t suid, int8_t level); +static SRSmaInfo *tdGetRSmaInfoBySuid(SSma *pSma, int64_t suid); +static int32_t tdRSmaFetchAndSubmitResult(SRSmaInfoItem *pItem, STSchema *pTSchema, int64_t suid, SRSmaStat *pStat, + int8_t blkType); +static void tdRSmaFetchTrigger(void *param, void *tmrId); +static void tdRSmaPersistTrigger(void *param, void *tmrId); +static void *tdRSmaPersistExec(void *param); +static void tdRSmaQTaskInfoGetFName(int32_t vid, int64_t version, char *outputName); static int32_t tdRSmaQTaskInfoIterInit(SRSmaQTaskInfoIter *pIter, STFile *pTFile); static int32_t tdRSmaQTaskInfoIterNextBlock(SRSmaQTaskInfoIter *pIter, bool *isFinish); @@ -47,25 +51,26 @@ static int32_t tdRSmaRestoreQTaskInfoReload(SSma *pSma, int64_t *committed); static int32_t tdRSmaRestoreTSDataReload(SSma *pSma, int64_t committed); struct SRSmaInfoItem { - SRSmaInfo *pRsmaInfo; - int64_t refId; - void *taskInfo; // qTaskInfo_t - tmr_h tmrId; - int8_t level; - int8_t tmrInitFlag; - int8_t triggerStat; - int32_t maxDelay; + void *taskInfo; // qTaskInfo_t + int64_t refId; + tmr_h tmrId; + int32_t maxDelay; + int8_t level; + int8_t triggerStat; }; struct SRSmaInfo { STSchema *pTSchema; - SRSmaStat *pStat; int64_t suid; SRSmaInfoItem items[TSDB_RETENTION_L2]; }; -#define RSMA_INFO_SMA(r) ((r)->pStat->pSma) -#define RSMA_INFO_STAT(r) ((r)->pStat) +static SRSmaInfo *tdGetRSmaInfoByItem(SRSmaInfoItem *pItem) { + // adapt accordingly if definition of SRSmaInfo update + int32_t rsmaInfoHeadLen = sizeof(int64_t) + sizeof(STSchema *); + ASSERT(pItem->level == 1 || pItem->level == 2); + return (SRSmaInfo *)POINTER_SHIFT(pItem, -sizeof(SRSmaInfoItem) * (pItem->level - 1) - rsmaInfoHeadLen); +} struct SRSmaQTaskInfoItem { int32_t len; @@ -107,9 +112,8 @@ static FORCE_INLINE void tdFreeTaskHandle(qTaskInfo_t *taskHandle, int32_t vgId, } } -void *tdFreeRSmaInfo(SRSmaInfo *pInfo) { +void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo) { if (pInfo) { - SSma *pSma = RSMA_INFO_SMA(pInfo); for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) { SRSmaInfoItem *pItem = &pInfo->items[i]; if (pItem->taskInfo) { @@ -142,8 +146,6 @@ static FORCE_INLINE int32_t tdUidStoreInit(STbUidStore **pStore) { } static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids) { - SSmaEnv *pEnv = SMA_RSMA_ENV(pSma); - SRSmaStat *pStat = (SRSmaStat *)SMA_ENV_STAT(pEnv); SRSmaInfo *pRSmaInfo = NULL; if (!suid || !tbUids) { @@ -152,8 +154,9 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids) return TSDB_CODE_FAILED; } - pRSmaInfo = taosHashGet(RSMA_INFO_HASH(pStat), suid, sizeof(tb_uid_t)); - if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) { + pRSmaInfo = tdGetRSmaInfoBySuid(pSma, *suid); + + if (!pRSmaInfo) { smaError("vgId:%d, failed to get rsma info for uid:%" PRIi64, SMA_VID(pSma), *suid); terrno = TSDB_CODE_RSMA_INVALID_STAT; return TSDB_CODE_FAILED; @@ -251,15 +254,14 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui return TSDB_CODE_SUCCESS; } -static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaInfo *pRSmaInfo, SReadHandle *pReadHandle, - int8_t idx) { +static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat *pStat, SRSmaInfo *pRSmaInfo, + SReadHandle *pReadHandle, int8_t idx) { SRetention *pRetention = SMA_RETENTION(pSma); STsdbCfg *pTsdbCfg = SMA_TSDB_CFG(pSma); if (param->qmsg[idx]) { SRSmaInfoItem *pItem = &(pRSmaInfo->items[idx]); - pItem->refId = RSMA_REF_ID(pRSmaInfo->pStat); - pItem->pRsmaInfo = pRSmaInfo; + pItem->refId = RSMA_REF_ID(pStat); pItem->taskInfo = qCreateStreamExecTaskInfo(param->qmsg[idx], pReadHandle); if (!pItem->taskInfo) { terrno = TSDB_CODE_RSMA_QTASKINFO_CREATE; @@ -347,14 +349,13 @@ int32_t tdProcessRSmaCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con goto _err; } pRSmaInfo->pTSchema = pTSchema; - pRSmaInfo->pStat = pStat; pRSmaInfo->suid = suid; - if (tdSetRSmaInfoItemParams(pSma, param, pRSmaInfo, &handle, 0) < 0) { + if (tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, &handle, 0) < 0) { goto _err; } - if (tdSetRSmaInfoItemParams(pSma, param, pRSmaInfo, &handle, 1) < 0) { + if (tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, &handle, 1) < 0) { goto _err; } @@ -366,7 +367,7 @@ int32_t tdProcessRSmaCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con return TSDB_CODE_SUCCESS; _err: - tdFreeRSmaInfo(pRSmaInfo); + tdFreeRSmaInfo(pSma, pRSmaInfo); taosMemoryFree(pReader); return TSDB_CODE_FAILED; } @@ -537,10 +538,10 @@ int64_t tdRSmaGetMaxSubmitVer(SSma *pSma, int8_t level) { return atomic_load_64(&pRSmaStat->submitVer); } -static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) { - SArray *pResult = NULL; - SRSmaInfo *pRSmaInfo = pItem->pRsmaInfo; - SSma *pSma = RSMA_INFO_SMA(pRSmaInfo); +static int32_t tdRSmaFetchAndSubmitResult(SRSmaInfoItem *pItem, STSchema *pTSchema, int64_t suid, SRSmaStat *pStat, + int8_t blkType) { + SArray *pResult = NULL; + SSma *pSma = pStat->pSma; while (1) { SSDataBlock *output = NULL; @@ -572,16 +573,16 @@ static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb1 : pSma->pRSmaTsdb2); SSubmitReq *pReq = NULL; // TODO: the schema update should be handled - if (buildSubmitReqFromDataBlock(&pReq, pResult, pRSmaInfo->pTSchema, SMA_VID(pSma), pRSmaInfo->suid) < 0) { + if (buildSubmitReqFromDataBlock(&pReq, pResult, pTSchema, SMA_VID(pSma), suid) < 0) { smaError("vgId:%d, build submit req for rsma table %" PRIi64 "l evel %" PRIi8 " failed since %s", SMA_VID(pSma), - pRSmaInfo->suid, pItem->level, terrstr()); + suid, pItem->level, terrstr()); goto _err; } - if (pReq && tdProcessSubmitReq(sinkTsdb, atomic_add_fetch_64(&pRSmaInfo->pStat->submitVer, 1), pReq) < 0) { + if (pReq && tdProcessSubmitReq(sinkTsdb, atomic_add_fetch_64(&pStat->submitVer, 1), pReq) < 0) { taosMemoryFreeClear(pReq); smaError("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " failed since %s", SMA_VID(pSma), - pRSmaInfo->suid, pItem->level, terrstr()); + suid, pItem->level, terrstr()); goto _err; } @@ -599,81 +600,16 @@ _err: return TSDB_CODE_FAILED; } -/** - * @brief trigger to get rsma result - * - * @param param - * @param tmrId - */ -static void tdRSmaFetchTrigger(void *param, void *tmrId) { - SRSmaInfoItem *pItem = param; - SSma *pSma = NULL; - SRSmaStat *pStat = (SRSmaStat *)taosAcquireRef(smaMgmt.smaRef, pItem->refId); - if (!pStat) { - smaDebug("rsma fetch task not start since already destroyed"); - return; - } - - pSma = RSMA_INFO_SMA(pItem->pRsmaInfo); - - // if rsma trigger stat in paused, cancelled or finished, not start fetch task - int8_t rsmaTriggerStat = atomic_load_8(RSMA_TRIGGER_STAT(pStat)); - switch (rsmaTriggerStat) { - case TASK_TRIGGER_STAT_PAUSED: - case TASK_TRIGGER_STAT_CANCELLED: - case TASK_TRIGGER_STAT_FINISHED: { - taosReleaseRef(smaMgmt.smaRef, pItem->refId); - smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is cancelled", - SMA_VID(pSma), pItem->level, pItem->pRsmaInfo->suid); - return; - } - default: - break; - } - - int8_t fetchTriggerStat = - atomic_val_compare_exchange_8(&pItem->triggerStat, TASK_TRIGGER_STAT_ACTIVE, TASK_TRIGGER_STAT_INACTIVE); - switch (fetchTriggerStat) { - case TASK_TRIGGER_STAT_ACTIVE: { - smaDebug("vgId:%d, fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is active", SMA_VID(pSma), - pItem->level, pItem->pRsmaInfo->suid); - - tdRefSmaStat(pSma, (SSmaStat *)pStat); - - SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL}; - qSetStreamInput(pItem->taskInfo, &dataBlock, STREAM_INPUT__DATA_BLOCK, false); - tdFetchAndSubmitRSmaResult(pItem, STREAM_INPUT__DATA_BLOCK); - - tdUnRefSmaStat(pSma, (SSmaStat *)pStat); - } break; - case TASK_TRIGGER_STAT_PAUSED: { - smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is paused", - SMA_VID(pSma), pItem->level, pItem->pRsmaInfo->suid); - } break; - case TASK_TRIGGER_STAT_INACTIVE: { - smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is inactive", - SMA_VID(pSma), pItem->level, pItem->pRsmaInfo->suid); - } break; - case TASK_TRIGGER_STAT_INIT: { - smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is init", SMA_VID(pSma), - pItem->level, pItem->pRsmaInfo->suid); - } break; - default: { - smaWarn("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is unknown", - SMA_VID(pSma), pItem->level, pItem->pRsmaInfo->suid); - } break; - } - -_end: - taosReleaseRef(smaMgmt.smaRef, pItem->refId); -} - -static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *pItem, tb_uid_t suid, - int8_t level) { +static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *pItem, + STSchema *pTSchema, tb_uid_t suid, int8_t level) { if (!pItem || !pItem->taskInfo) { smaDebug("vgId:%d, no qTaskInfo to execute rsma %" PRIi8 " task for suid:%" PRIu64, SMA_VID(pSma), level, suid); return TSDB_CODE_SUCCESS; } + if (!pTSchema) { + smaWarn("vgId:%d, no schema to execute rsma %" PRIi8 " task for suid:%" PRIu64, SMA_VID(pSma), level, suid); + return TSDB_CODE_FAILED; + } smaDebug("vgId:%d, execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, SMA_VID(pSma), level, pItem->taskInfo, suid); @@ -683,14 +619,14 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType return TSDB_CODE_FAILED; } - tdFetchAndSubmitRSmaResult(pItem, STREAM_INPUT__DATA_SUBMIT); - atomic_store_8(&pItem->triggerStat, TASK_TRIGGER_STAT_ACTIVE); - SSmaEnv *pEnv = SMA_RSMA_ENV(pSma); SRSmaStat *pStat = SMA_RSMA_STAT(pEnv->pStat); - if (pStat->tmrHandle) { - taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, pStat->tmrHandle, &pItem->tmrId); + tdRSmaFetchAndSubmitResult(pItem, pTSchema, suid, pStat, STREAM_INPUT__DATA_SUBMIT); + atomic_store_8(&pItem->triggerStat, TASK_TRIGGER_STAT_ACTIVE); + + if (smaMgmt.tmrHandle) { + taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, smaMgmt.tmrHandle, &pItem->tmrId); } else { ASSERT(0); } @@ -698,19 +634,29 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType return TSDB_CODE_SUCCESS; } -static int32_t tdExecuteRSma(SSma *pSma, const void *pMsg, int32_t inputType, tb_uid_t suid) { - SSmaEnv *pEnv = SMA_RSMA_ENV(pSma); +static SRSmaInfo *tdGetRSmaInfoBySuid(SSma *pSma, int64_t suid) { + SSmaEnv *pEnv = SMA_RSMA_ENV(pSma); + SRSmaStat *pStat = NULL; if (!pEnv) { // only applicable when rsma env exists - return TSDB_CODE_SUCCESS; + return NULL; } - SRSmaStat *pStat = (SRSmaStat *)SMA_ENV_STAT(pEnv); - SRSmaInfo *pRSmaInfo = NULL; - - pRSmaInfo = taosHashGet(RSMA_INFO_HASH(pStat), &suid, sizeof(tb_uid_t)); + pStat = (SRSmaStat *)SMA_ENV_STAT(pEnv); + if (!pStat || !RSMA_INFO_HASH(pStat)) { + return NULL; + } + SRSmaInfo *pRSmaInfo = taosHashGet(RSMA_INFO_HASH(pStat), &suid, sizeof(tb_uid_t)); if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) { + return NULL; + } + return pRSmaInfo; +} + +static int32_t tdExecuteRSma(SSma *pSma, const void *pMsg, int32_t inputType, tb_uid_t suid) { + SRSmaInfo *pRSmaInfo = tdGetRSmaInfoBySuid(pSma, suid); + if (!pRSmaInfo) { smaDebug("vgId:%d, return as no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid); return TSDB_CODE_SUCCESS; } @@ -721,8 +667,8 @@ static int32_t tdExecuteRSma(SSma *pSma, const void *pMsg, int32_t inputType, tb } if (inputType == STREAM_INPUT__DATA_SUBMIT) { - tdExecuteRSmaImpl(pSma, pMsg, inputType, &pRSmaInfo->items[0], suid, TSDB_RETENTION_L1); - tdExecuteRSmaImpl(pSma, pMsg, inputType, &pRSmaInfo->items[1], suid, TSDB_RETENTION_L2); + tdExecuteRSmaImpl(pSma, pMsg, inputType, &pRSmaInfo->items[0], pRSmaInfo->pTSchema, suid, TSDB_RETENTION_L1); + tdExecuteRSmaImpl(pSma, pMsg, inputType, &pRSmaInfo->items[1], pRSmaInfo->pTSchema, suid, TSDB_RETENTION_L2); } return TSDB_CODE_SUCCESS; @@ -935,13 +881,11 @@ _err: } static int32_t tdRSmaQTaskInfoItemRestore(SSma *pSma, const SRSmaQTaskInfoItem *pItem) { - SRSmaStat *pStat = (SRSmaStat *)SMA_ENV_STAT((SSmaEnv *)pSma->pRSmaEnv); SRSmaInfo *pRSmaInfo = NULL; void *qTaskInfo = NULL; - pRSmaInfo = taosHashGet(RSMA_INFO_HASH(pStat), &pItem->suid, sizeof(pItem->suid)); - - if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) { + pRSmaInfo = tdGetRSmaInfoBySuid(pSma, pItem->suid); + if (!pRSmaInfo) { smaDebug("vgId:%d, no restore as no rsma info for table:%" PRIu64, SMA_VID(pSma), pItem->suid); return TSDB_CODE_SUCCESS; } @@ -1258,7 +1202,8 @@ _end: } atomic_store_8(RSMA_RUNNING_STAT(pRSmaStat), 0); - taosReleaseRef(smaMgmt.smaRef, pRSmaStat->refId); + smaDebug("vgId:%d, release rsetId rsetId:%" PRIi64 " refId:%d", SMA_VID(pSma), smaMgmt.rsetId, pRSmaStat->refId); + tdReleaseSmaRef(smaMgmt.rsetId, pRSmaStat->refId, __func__, __LINE__); taosThreadExit(NULL); return NULL; } @@ -1283,7 +1228,9 @@ static void tdRSmaPersistTask(SRSmaStat *pRSmaStat) { atomic_load_8(RSMA_TRIGGER_STAT(pRSmaStat))); } atomic_store_8(RSMA_RUNNING_STAT(pRSmaStat), 0); - taosReleaseRef(smaMgmt.smaRef, pRSmaStat->refId); + smaDebug("vgId:%d, release rsetId rsetId:%" PRIi64 " refId:%d)", SMA_VID(pRSmaStat->pSma), smaMgmt.rsetId, + pRSmaStat->refId); + tdReleaseSmaRef(smaMgmt.rsetId, pRSmaStat->refId, __func__, __LINE__); } taosThreadAttrDestroy(&thAttr); @@ -1297,8 +1244,8 @@ static void tdRSmaPersistTask(SRSmaStat *pRSmaStat) { */ static void tdRSmaPersistTrigger(void *param, void *tmrId) { SRSmaStat *rsmaStat = param; - SRSmaStat *pRSmaStat = (SRSmaStat *)taosAcquireRef(smaMgmt.smaRef, rsmaStat->refId); - + SRSmaStat *pRSmaStat = (SRSmaStat *)taosAcquireRef(smaMgmt.rsetId, rsmaStat->refId); + ASSERT(0); if (!pRSmaStat) { smaDebug("rsma persistence task not start since already destroyed"); return; @@ -1341,5 +1288,81 @@ static void tdRSmaPersistTrigger(void *param, void *tmrId) { smaWarn("rsma persistence not start since unknown stat %" PRIi8, tmrStat); } break; } - taosReleaseRef(smaMgmt.smaRef, rsmaStat->refId); + taosReleaseRef(smaMgmt.rsetId, rsmaStat->refId); +} + +/** + * @brief trigger to get rsma result + * + * @param param + * @param tmrId + */ +static void tdRSmaFetchTrigger(void *param, void *tmrId) { + SRSmaInfoItem *pItem = param; + SSma *pSma = NULL; + SRSmaStat *pStat = (SRSmaStat *)tdAcquireSmaRef(smaMgmt.rsetId, pItem->refId, __func__, __LINE__); + + if (!pStat) { + smaDebug("rsma fetch task not start since already destroyed, rsetId rsetId:%" PRIi64 " refId:%d)", smaMgmt.rsetId, + pItem->refId); + return; + } + + pSma = pStat->pSma; + + // if rsma trigger stat in paused, cancelled or finished, not start fetch task + int8_t rsmaTriggerStat = atomic_load_8(RSMA_TRIGGER_STAT(pStat)); + switch (rsmaTriggerStat) { + case TASK_TRIGGER_STAT_PAUSED: + case TASK_TRIGGER_STAT_CANCELLED: + case TASK_TRIGGER_STAT_FINISHED: { + tdReleaseSmaRef(smaMgmt.rsetId, pItem->refId, __func__, __LINE__); + smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data since stat is %" PRIi8 ", rsetId rsetId:%" PRIi64 + " refId:%d", + SMA_VID(pSma), pItem->level, rsmaTriggerStat, smaMgmt.rsetId, pItem->refId); + return; + } + default: + break; + } + + SRSmaInfo *pRSmaInfo = tdGetRSmaInfoByItem(pItem); + + ASSERT(pRSmaInfo->suid > 0); + + int8_t fetchTriggerStat = + atomic_val_compare_exchange_8(&pItem->triggerStat, TASK_TRIGGER_STAT_ACTIVE, TASK_TRIGGER_STAT_INACTIVE); + switch (fetchTriggerStat) { + case TASK_TRIGGER_STAT_ACTIVE: { + smaDebug("vgId:%d, fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is active", SMA_VID(pSma), + pItem->level, pRSmaInfo->suid); + + tdRefSmaStat(pSma, (SSmaStat *)pStat); + + SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL}; + qSetStreamInput(pItem->taskInfo, &dataBlock, STREAM_INPUT__DATA_BLOCK, false); + tdRSmaFetchAndSubmitResult(pItem, pRSmaInfo->pTSchema, pRSmaInfo->suid, pStat, STREAM_INPUT__DATA_BLOCK); + + tdUnRefSmaStat(pSma, (SSmaStat *)pStat); + } break; + case TASK_TRIGGER_STAT_PAUSED: { + smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is paused", + SMA_VID(pSma), pItem->level, pRSmaInfo->suid); + } break; + case TASK_TRIGGER_STAT_INACTIVE: { + smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is inactive", + SMA_VID(pSma), pItem->level, pRSmaInfo->suid); + } break; + case TASK_TRIGGER_STAT_INIT: { + smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is init", SMA_VID(pSma), + pItem->level, pRSmaInfo->suid); + } break; + default: { + smaWarn("vgId:%d, not fetch rsma level %" PRIi8 " data for table:%" PRIi64 " since stat is unknown", + SMA_VID(pSma), pItem->level, pRSmaInfo->suid); + } break; + } + +_end: + tdReleaseSmaRef(smaMgmt.rsetId, pItem->refId, __func__, __LINE__); } diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c index ecd8db8ea9..6d71f3a250 100644 --- a/source/dnode/vnode/src/sma/smaTimeRange.c +++ b/source/dnode/vnode/src/sma/smaTimeRange.c @@ -20,6 +20,36 @@ #define SMA_STORAGE_MINUTES_DAY 1440 #define SMA_STORAGE_SPLIT_FACTOR 14400 // least records in tsma file +// TODO: Who is responsible for resource allocate and release? +int32_t tdProcessTSmaInsert(SSma *pSma, int64_t indexUid, const char *msg) { + int32_t code = TSDB_CODE_SUCCESS; + + if ((code = tdProcessTSmaInsertImpl(pSma, indexUid, msg)) < 0) { + smaWarn("vgId:%d, insert tsma data failed since %s", SMA_VID(pSma), tstrerror(terrno)); + } + // TODO: destroy SSDataBlocks(msg) + return code; +} + +int32_t tdProcessTSmaCreate(SSma *pSma, int64_t version, const char *msg) { + int32_t code = TSDB_CODE_SUCCESS; + + if ((code = tdProcessTSmaCreateImpl(pSma, version, msg)) < 0) { + smaWarn("vgId:%d, create tsma failed since %s", SMA_VID(pSma), tstrerror(terrno)); + } + // TODO: destroy SSDataBlocks(msg) + return code; +} + +int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days) { + int32_t code = TSDB_CODE_SUCCESS; + if ((code = tdProcessTSmaGetDaysImpl(pCfg, pCont, contLen, days)) < 0) { + smaWarn("vgId:%d, get tsma days failed since %s", pCfg->vgId, tstrerror(terrno)); + } + smaDebug("vgId:%d, get tsma days %d", pCfg->vgId, *days); + return code; +} + /** * @brief Judge the tsma file split days * diff --git a/source/dnode/vnode/src/sma/smaUtil.c b/source/dnode/vnode/src/sma/smaUtil.c index 2ce6d23648..22d82e8df0 100644 --- a/source/dnode/vnode/src/sma/smaUtil.c +++ b/source/dnode/vnode/src/sma/smaUtil.c @@ -294,4 +294,23 @@ int32_t tdRemoveTFile(STFile *pTFile) { } // smaXXXUtil ================ +void *tdAcquireSmaRef(int32_t rsetId, int64_t refId, const char *tags, int32_t ln) { + void *pResult = taosAcquireRef(rsetId, refId); + if (!pResult) { + smaWarn("%s:%d taosAcquireRef for rsetId:%" PRIi64 " refId:%d failed since %s", tags, ln, rsetId, refId, terrstr()); + } else { + smaDebug("%s:%d taosAcquireRef for rsetId:%" PRIi64 " refId:%d success", tags, ln, rsetId, refId); + } + return pResult; +} + +int32_t tdReleaseSmaRef(int32_t rsetId, int64_t refId, const char *tags, int32_t ln) { + if (taosReleaseRef(rsetId, refId) < 0) { + smaWarn("%s:%d taosReleaseRef for rsetId:%" PRIi64 " refId:%d failed since %s", tags, ln, rsetId, refId, terrstr()); + return TSDB_CODE_FAILED; + } + smaDebug("%s:%d taosReleaseRef for rsetId:%" PRIi64 " refId:%d success", tags, ln, rsetId, refId); + + return TSDB_CODE_SUCCESS; +} // ... \ No newline at end of file diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index e21b0fe9e8..fbb972fafe 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -112,7 +112,8 @@ int32_t tqSendMetaPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, }; tmsgSendRsp(&resp); - tqDebug("vg %d from consumer %ld (epoch %d) send rsp, res msg type %d, reqOffset: %ld, rspOffset: %ld", + tqDebug("vgId:%d from consumer:%" PRId64 ", (epoch %d) send rsp, res msg type %d, reqOffset:%" PRId64 + ", rspOffset:%" PRId64, TD_VID(pTq->pVnode), pReq->consumerId, pReq->epoch, pRsp->resMsgType, pRsp->reqOffset, pRsp->rspOffset); return 0; @@ -162,7 +163,7 @@ int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, con char buf2[80]; tFormatOffset(buf1, 80, &pRsp->reqOffset); tFormatOffset(buf2, 80, &pRsp->rspOffset); - tqDebug("vg %d from consumer %ld (epoch %d) send rsp, block num: %d, reqOffset: %s, rspOffset: %s", + tqDebug("vgId:%d from consumer:%" PRId64 ", (epoch %d) send rsp, block num: %d, reqOffset:%s, rspOffset:%s", TD_VID(pTq->pVnode), pReq->consumerId, pReq->epoch, pRsp->blockNum, buf1, buf2); return 0; @@ -179,10 +180,10 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen) { tDecoderClear(&decoder); if (offset.val.type == TMQ_OFFSET__SNAPSHOT_DATA) { - tqDebug("receive offset commit msg to %s on vg %d, offset(type:snapshot) uid: %ld, ts: %ld", offset.subKey, - TD_VID(pTq->pVnode), offset.val.uid, offset.val.ts); + tqDebug("receive offset commit msg to %s on vgId:%d, offset(type:snapshot) uid:%" PRId64 ", ts:%" PRId64, + offset.subKey, TD_VID(pTq->pVnode), offset.val.uid, offset.val.ts); } else if (offset.val.type == TMQ_OFFSET__LOG) { - tqDebug("receive offset commit msg to %s on vg %d, offset(type:log) version: %ld", offset.subKey, + tqDebug("receive offset commit msg to %s on vgId:%d, offset(type:log) version:%" PRId64, offset.subKey, TD_VID(pTq->pVnode), offset.val.version); } else { ASSERT(0); @@ -244,22 +245,18 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { STqOffsetVal fetchOffsetNew; // 1.find handle - char buf[80]; - tFormatOffset(buf, 80, &reqOffset); - tqDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req offset %s", consumerId, pReq->epoch, - TD_VID(pTq->pVnode), buf); - STqHandle* pHandle = taosHashGet(pTq->handles, pReq->subKey, strlen(pReq->subKey)); /*ASSERT(pHandle);*/ if (pHandle == NULL) { - tqError("tmq poll: no consumer handle for consumer %ld in vg %d, subkey %s", consumerId, TD_VID(pTq->pVnode), - pReq->subKey); + tqError("tmq poll: no consumer handle for consumer:%" PRId64 ", in vgId:%d, subkey %s", consumerId, + TD_VID(pTq->pVnode), pReq->subKey); return -1; } // check rebalance if (pHandle->consumerId != consumerId) { - tqError("tmq poll: consumer handle mismatch for consumer %ld in vg %d, subkey %s, handle consumer id %ld", + tqError("tmq poll: consumer handle mismatch for consumer:%" PRId64 + ", in vgId:%d, subkey %s, handle consumer id %" PRId64, consumerId, TD_VID(pTq->pVnode), pReq->subKey, pHandle->consumerId); return -1; } @@ -270,6 +267,14 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { consumerEpoch = atomic_val_compare_exchange_32(&pHandle->epoch, consumerEpoch, reqEpoch); } + char buf[80]; + tFormatOffset(buf, 80, &reqOffset); + tqDebug("tmq poll: consumer %ld (epoch %d), subkey %s, recv poll req in vg %d, req offset %s", consumerId, + pReq->epoch, pHandle->subKey, TD_VID(pTq->pVnode), buf); + + SMqDataRsp dataRsp = {0}; + tqInitDataRsp(&dataRsp, pReq, pHandle->execHandle.subType); + // 2.reset offset if needed if (reqOffset.type > 0) { fetchOffsetNew = reqOffset; @@ -279,7 +284,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { fetchOffsetNew = pOffset->val; char formatBuf[80]; tFormatOffset(formatBuf, 80, &fetchOffsetNew); - tqDebug("tmq poll: consumer %ld, offset reset to %s", consumerId, formatBuf); + tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, offset reset to %s", consumerId, pHandle->subKey, formatBuf); } else { if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) { if (pReq->useSnapshot && pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { @@ -293,25 +298,50 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { tqOffsetResetToLog(&fetchOffsetNew, walGetFirstVer(pTq->pVnode->pWal)); } } else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) { - tqOffsetResetToLog(&fetchOffsetNew, walGetLastVer(pTq->pVnode->pWal)); + tqOffsetResetToLog(&dataRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal)); + tqDebug("tmq poll: consumer %ld, subkey %s, offset reset to %ld", consumerId, pHandle->subKey, + dataRsp.rspOffset.version); + if (tqSendDataRsp(pTq, pMsg, pReq, &dataRsp) < 0) { + code = -1; + } + goto OVER; } else if (reqOffset.type == TMQ_OFFSET__RESET_NONE) { - tqError("tmq poll: no offset committed for consumer %ld in vg %d, subkey %s, reset none failed", consumerId, - TD_VID(pTq->pVnode), pReq->subKey); + tqError("tmq poll: subkey %s, no offset committed for consumer %" PRId64 + " in vg %d, subkey %s, reset none failed", + pHandle->subKey, consumerId, TD_VID(pTq->pVnode), pReq->subKey); terrno = TSDB_CODE_TQ_NO_COMMITTED_OFFSET; - return -1; + code = -1; + goto OVER; } } } // 3.query - SMqDataRsp dataRsp = {0}; - tqInitDataRsp(&dataRsp, pReq, pHandle->execHandle.subType); + if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { + if (fetchOffsetNew.type == TMQ_OFFSET__LOG) { + fetchOffsetNew.version++; + } + if (tqScan(pTq, &pHandle->execHandle, &dataRsp, &fetchOffsetNew) < 0) { + ASSERT(0); + code = -1; + goto OVER; + } + if (dataRsp.blockNum == 0) { + // TODO add to async task pool + /*dataRsp.rspOffset.version--;*/ + } + if (tqSendDataRsp(pTq, pMsg, pReq, &dataRsp) < 0) { + code = -1; + } + goto OVER; + } - if (fetchOffsetNew.type == TMQ_OFFSET__LOG) { + if (pHandle->execHandle.subType != TOPIC_SUB_TYPE__COLUMN) { int64_t fetchVer = fetchOffsetNew.version + 1; SWalCkHead* pCkHead = taosMemoryMalloc(sizeof(SWalCkHead) + 2048); if (pCkHead == NULL) { - return -1; + code = -1; + goto OVER; } walSetReaderCapacity(pHandle->pWalReader, 2048); @@ -319,8 +349,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { while (1) { consumerEpoch = atomic_load_32(&pHandle->epoch); if (consumerEpoch > reqEpoch) { - tqWarn("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d, discard req epoch %d", - consumerId, pReq->epoch, TD_VID(pTq->pVnode), fetchVer, consumerEpoch, reqEpoch); + tqWarn("tmq poll: consumer %ld (epoch %d), subkey %s, vg %d offset %" PRId64 + ", found new consumer epoch %d, discard req epoch %d", + consumerId, pReq->epoch, pHandle->subKey, TD_VID(pTq->pVnode), fetchVer, consumerEpoch, reqEpoch); break; } @@ -337,8 +368,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { SWalCont* pHead = &pCkHead->head; - tqDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch, - TD_VID(pTq->pVnode), fetchVer, pHead->msgType); + tqDebug("tmq poll: consumer:%" PRId64 ", (epoch %d) iter log, vgId:%d offset %" PRId64 " msgType %d", consumerId, + pReq->epoch, TD_VID(pTq->pVnode), fetchVer, pHead->msgType); if (pHead->msgType == TDMT_VND_SUBMIT) { SSubmitReq* pCont = (SSubmitReq*)&pHead->body; @@ -363,7 +394,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } else { ASSERT(pHandle->fetchMeta); ASSERT(IS_META_MSG(pHead->msgType)); - tqInfo("fetch meta msg, ver: %ld, type: %d", pHead->version, pHead->msgType); + tqDebug("fetch meta msg, ver:%" PRId64 ", type:%d", pHead->version, pHead->msgType); SMqMetaRsp metaRsp = {0}; /*metaRsp.reqOffset = pReq->reqOffset.version;*/ /*metaRsp.rspOffset = fetchVer;*/ @@ -383,8 +414,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } taosMemoryFree(pCkHead); +#if 0 } else if (fetchOffsetNew.type == TMQ_OFFSET__SNAPSHOT_DATA) { - tqInfo("retrieve using snapshot actual offset: uid %ld ts %ld", fetchOffsetNew.uid, fetchOffsetNew.ts); + tqInfo("retrieve using snapshot actual offset: uid %" PRId64 " ts %" PRId64, fetchOffsetNew.uid, fetchOffsetNew.ts); if (tqScanSnapshot(pTq, &pHandle->execHandle, &dataRsp, fetchOffsetNew, workerId) < 0) { ASSERT(0); } @@ -393,6 +425,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { if (tqSendDataRsp(pTq, pMsg, pReq, &dataRsp) < 0) { code = -1; } +#endif } else if (fetchOffsetNew.type == TMQ_OFFSET__SNAPSHOT_META) { ASSERT(0); } @@ -450,6 +483,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { /*for (int32_t i = 0; i < 5; i++) {*/ /*pHandle->execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode);*/ /*}*/ + int64_t ver = walGetCommittedVer(pTq->pVnode->pWal); if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { pHandle->execHandle.execCol.qmsg = req.qmsg; req.qmsg = NULL; @@ -460,6 +494,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { .vnode = pTq->pVnode, .initTableReader = true, .initTqReader = true, + .version = ver, }; pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle); ASSERT(pHandle->execHandle.execCol.task[i]); @@ -468,6 +503,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { ASSERT(scanner); pHandle->execHandle.pExecReader[i] = qExtractReaderFromStreamScanner(scanner); ASSERT(pHandle->execHandle.pExecReader[i]); + pHandle->execHandle.tsdbEndVer = ver; } } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) { for (int32_t i = 0; i < 5; i++) { @@ -476,18 +512,16 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { pHandle->execHandle.execDb.pFilterOutTbUid = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { - for (int32_t i = 0; i < 5; i++) { - pHandle->execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode); - } pHandle->execHandle.execTb.suid = req.suid; SArray* tbUidList = taosArrayInit(0, sizeof(int64_t)); vnodeGetCtbIdList(pTq->pVnode, req.suid, tbUidList); - tqDebug("vg %d, tq try get suid: %ld", pTq->pVnode->config.vgId, req.suid); + tqDebug("vgId:%d, tq try get suid:%" PRId64, pTq->pVnode->config.vgId, req.suid); for (int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) { int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i); - tqDebug("vg %d, idx %d, uid: %ld", TD_VID(pTq->pVnode), i, tbUid); + tqDebug("vgId:%d, idx %d, uid:%" PRId64, TD_VID(pTq->pVnode), i, tbUid); } for (int32_t i = 0; i < 5; i++) { + pHandle->execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode); tqReaderSetTbUidList(pHandle->execHandle.pExecReader[i], tbUidList); } taosArrayDestroy(tbUidList); @@ -572,7 +606,7 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen) { streamSetupTrigger(pTask); - tqInfo("deploy stream task id %d child id %d on vg %d", pTask->taskId, pTask->selfChildId, TD_VID(pTq->pVnode)); + tqInfo("deploy stream task id %d child id %d on vgId:%d", pTask->taskId, pTask->selfChildId, TD_VID(pTq->pVnode)); taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void*)); diff --git a/source/dnode/vnode/src/tq/tqExec.c b/source/dnode/vnode/src/tq/tqExec.c index 16822e6003..54e46e7b9a 100644 --- a/source/dnode/vnode/src/tq/tqExec.c +++ b/source/dnode/vnode/src/tq/tqExec.c @@ -46,7 +46,7 @@ static int32_t tqAddBlockSchemaToRsp(const STqExecHandle* pExec, int32_t workerI return 0; } -static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, SMqDataRsp* pRsp, int32_t workerId) { +static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, SMqDataRsp* pRsp) { SMetaReader mr = {0}; metaReaderInit(&mr, pTq->pVnode->pMeta, 0); if (metaGetTableEntryByUid(&mr, uid) < 0) { @@ -59,15 +59,76 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, SMqDataRsp* pRsp, i return 0; } +int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffsetVal* pOffset) { + qTaskInfo_t task = pExec->execCol.task[0]; + + if (qStreamPrepareScan(task, pOffset) < 0) { + ASSERT(pOffset->type == TMQ_OFFSET__LOG); + pRsp->rspOffset = *pOffset; + pRsp->rspOffset.version--; + return 0; + } + + int32_t rowCnt = 0; + while (1) { + SSDataBlock* pDataBlock = NULL; + uint64_t ts = 0; + if (qExecTask(task, &pDataBlock, &ts) < 0) { + ASSERT(0); + } + + if (pDataBlock != NULL) { + tqAddBlockDataToRsp(pDataBlock, pRsp); + pRsp->blockNum++; + if (pRsp->withTbName) { + if (pOffset->type == TMQ_OFFSET__LOG) { + int64_t uid = pExec->pExecReader[0]->msgIter.uid; + tqAddTbNameToRsp(pTq, uid, pRsp); + } else { + pRsp->withTbName = 0; + } + } + if (pOffset->type == TMQ_OFFSET__LOG) { + continue; + } else { + rowCnt += pDataBlock->info.rows; + if (rowCnt <= 4096) continue; + } + } + + if (pRsp->blockNum == 0 && pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) { + tqOffsetResetToLog(pOffset, pExec->tsdbEndVer + 1); + qStreamPrepareScan(task, pOffset); + continue; + } + + void* meta = qStreamExtractMetaMsg(task); + if (meta != NULL) { + // tq add meta to rsp + } + + if (qStreamExtractOffset(task, &pRsp->rspOffset) < 0) { + ASSERT(0); + } + + ASSERT(pRsp->rspOffset.type != 0); + + if (pRsp->reqOffset.type == TMQ_OFFSET__LOG) { + ASSERT(pRsp->rspOffset.version + 1 >= pRsp->reqOffset.version); + } + + break; + } + + return 0; +} + +#if 0 int32_t tqScanSnapshot(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffsetVal offset, int32_t workerId) { ASSERT(pExec->subType == TOPIC_SUB_TYPE__COLUMN); qTaskInfo_t task = pExec->execCol.task[workerId]; - /*if (qStreamScanSnapshot(task) < 0) {*/ - /*ASSERT(0);*/ - /*}*/ - - if (qStreamPrepareScan(task, offset.uid, offset.ts) < 0) { + if (qStreamPrepareTsdbScan(task, offset.uid, offset.ts) < 0) { ASSERT(0); } @@ -93,7 +154,7 @@ int32_t tqScanSnapshot(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, S if (qGetStreamScanStatus(task, &uid, &ts) < 0) { ASSERT(0); } - tqAddTbNameToRsp(pTq, uid, pRsp, workerId); + tqAddTbNameToRsp(pTq, uid, pRsp); #endif } pRsp->blockNum++; @@ -110,30 +171,12 @@ int32_t tqScanSnapshot(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, S return 0; } +#endif int32_t tqLogScanExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataRsp* pRsp, int32_t workerId) { - if (pExec->subType == TOPIC_SUB_TYPE__COLUMN) { - qTaskInfo_t task = pExec->execCol.task[workerId]; - ASSERT(task); - qSetStreamInput(task, pReq, STREAM_INPUT__DATA_SUBMIT, false); - while (1) { - SSDataBlock* pDataBlock = NULL; - uint64_t ts = 0; - if (qExecTask(task, &pDataBlock, &ts) < 0) { - ASSERT(0); - } - if (pDataBlock == NULL) break; + ASSERT(pExec->subType != TOPIC_SUB_TYPE__COLUMN); - ASSERT(pDataBlock->info.rows != 0); - - tqAddBlockDataToRsp(pDataBlock, pRsp); - if (pRsp->withTbName) { - int64_t uid = pExec->pExecReader[workerId]->msgIter.uid; - tqAddTbNameToRsp(pTq, uid, pRsp, workerId); - } - pRsp->blockNum++; - } - } else if (pExec->subType == TOPIC_SUB_TYPE__TABLE) { + if (pExec->subType == TOPIC_SUB_TYPE__TABLE) { pRsp->withSchema = 1; STqReader* pReader = pExec->pExecReader[workerId]; tqReaderSetDataMsg(pReader, pReq, 0); @@ -146,7 +189,7 @@ int32_t tqLogScanExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataR tqAddBlockDataToRsp(&block, pRsp); if (pRsp->withTbName) { int64_t uid = pExec->pExecReader[workerId]->msgIter.uid; - tqAddTbNameToRsp(pTq, uid, pRsp, workerId); + tqAddTbNameToRsp(pTq, uid, pRsp); } tqAddBlockSchemaToRsp(pExec, workerId, pRsp); pRsp->blockNum++; @@ -164,15 +207,17 @@ int32_t tqLogScanExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataR tqAddBlockDataToRsp(&block, pRsp); if (pRsp->withTbName) { int64_t uid = pExec->pExecReader[workerId]->msgIter.uid; - tqAddTbNameToRsp(pTq, uid, pRsp, workerId); + tqAddTbNameToRsp(pTq, uid, pRsp); } tqAddBlockSchemaToRsp(pExec, workerId, pRsp); pRsp->blockNum++; } } + if (pRsp->blockNum == 0) { pRsp->skipLogNum++; return -1; } + return 0; } diff --git a/source/dnode/vnode/src/tq/tqOffset.c b/source/dnode/vnode/src/tq/tqOffset.c index 8561314431..ec9674d637 100644 --- a/source/dnode/vnode/src/tq/tqOffset.c +++ b/source/dnode/vnode/src/tq/tqOffset.c @@ -139,7 +139,7 @@ int32_t tqOffsetSnapshot(STqOffsetStore* pStore) { int64_t writeLen; if ((writeLen = taosWriteFile(pFile, buf, totLen)) != totLen) { ASSERT(0); - tqError("write offset incomplete, len %d, write len %ld", bodyLen, writeLen); + tqError("write offset incomplete, len %d, write len %" PRId64, bodyLen, writeLen); taosHashCancelIterate(pStore->pHash, pIter); return -1; } diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c index bd7cda4de3..e9e5f6cd8b 100644 --- a/source/dnode/vnode/src/tq/tqPush.c +++ b/source/dnode/vnode/src/tq/tqPush.c @@ -223,7 +223,7 @@ int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_ memset(&pHandle->pushHandle.rpcInfo, 0, sizeof(SRpcHandleInfo)); taosWUnLockLatch(&pHandle->pushHandle.lock); - tqDebug("vg %d offset %ld from consumer %ld (epoch %d) send rsp, block num: %d, reqOffset: %ld, rspOffset: %ld", + tqDebug("vgId:%d offset %" PRId64 " from consumer:%" PRId64 ", (epoch %d) send rsp, block num: %d, reqOffset:%" PRId64 ", rspOffset:%" PRId64, TD_VID(pTq->pVnode), fetchOffset, pHandle->pushHandle.consumerId, pHandle->pushHandle.epoch, rsp.blockNum, rsp.reqOffset, rsp.rspOffset); diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 53ef17a6ba..8753ecc47c 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -15,11 +15,6 @@ #include "tq.h" -int64_t tqScanLog(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffsetVal offset) { - /*if ()*/ - return 0; -} - int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** ppCkHead) { int32_t code = 0; taosThreadMutexLock(&pHandle->pWalReader->mutex); @@ -27,8 +22,8 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHea while (1) { if (walFetchHead(pHandle->pWalReader, offset, *ppCkHead) < 0) { - tqDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", pHandle->consumerId, - pHandle->epoch, TD_VID(pTq->pVnode), offset); + tqDebug("tmq poll: consumer:%" PRId64 ", (epoch %d) vgId:%d offset %" PRId64 ", no more log to return", + pHandle->consumerId, pHandle->epoch, TD_VID(pTq->pVnode), offset); *fetchOffset = offset - 1; code = -1; goto END; @@ -84,8 +79,10 @@ STqReader* tqOpenReader(SVnode* pVnode) { return NULL; } - // TODO open - /*pReader->pWalReader = walOpenReader(pVnode->pWal, NULL);*/ + pReader->pWalReader = walOpenReader(pVnode->pWal, NULL); + if (pReader->pWalReader == NULL) { + return NULL; + } pReader->pVnodeMeta = pVnode->pMeta; pReader->pMsg = NULL; @@ -106,13 +103,27 @@ void tqCloseReader(STqReader* pReader) { taosMemoryFree(pReader); } +int32_t tqSeekVer(STqReader* pReader, int64_t ver) { + if (walReadSeekVer(pReader->pWalReader, ver) < 0) { + ASSERT(pReader->pWalReader->curInvalid); + ASSERT(pReader->pWalReader->curVersion == ver); + return -1; + } + ASSERT(pReader->pWalReader->curVersion == ver); + return 0; +} + int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) { bool fromProcessedMsg = pReader->pMsg != NULL; while (1) { if (!fromProcessedMsg) { if (walNextValidMsg(pReader->pWalReader) < 0) { + pReader->ver = pReader->pWalReader->curVersion - pReader->pWalReader->curInvalid; + ret->offset.type = TMQ_OFFSET__LOG; + ret->offset.version = pReader->ver; ret->fetchType = FETCH_TYPE__NONE; + ASSERT(ret->offset.version >= 0); return -1; } void* body = pReader->pWalReader->pHead->head.body; @@ -127,22 +138,21 @@ int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) { } while (tqNextDataBlock(pReader)) { + // TODO mem free memset(&ret->data, 0, sizeof(SSDataBlock)); int32_t code = tqRetrieveDataBlock(&ret->data, pReader); if (code != 0 || ret->data.info.rows == 0) { - if (fromProcessedMsg) { - ret->fetchType = FETCH_TYPE__NONE; - return 0; - } else { - break; - } + ASSERT(0); + continue; } - ret->fetchType = FETCH_TYPE__DATA; return 0; } if (fromProcessedMsg) { + ret->offset.type = TMQ_OFFSET__LOG; + ret->offset.version = pReader->ver; + ASSERT(pReader->ver >= 0); ret->fetchType = FETCH_TYPE__NONE; return 0; } @@ -179,9 +189,9 @@ bool tqNextDataBlock(STqReader* pReader) { return true; } void* ret = taosHashGet(pReader->tbIdHash, &pReader->msgIter.uid, sizeof(int64_t)); - /*tqDebug("search uid %ld", pHandle->msgIter.uid);*/ + /*tqDebug("search uid %" PRId64, pHandle->msgIter.uid);*/ if (ret != NULL) { - /*tqDebug("find uid %ld", pHandle->msgIter.uid);*/ + /*tqDebug("find uid %" PRId64, pHandle->msgIter.uid);*/ return true; } } @@ -212,7 +222,7 @@ int32_t tqRetrieveDataBlock(SSDataBlock* pBlock, STqReader* pReader) { if (pReader->pSchema) taosMemoryFree(pReader->pSchema); pReader->pSchema = metaGetTbTSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion); if (pReader->pSchema == NULL) { - tqWarn("cannot found tsschema for table: uid: %ld (suid: %ld), version %d, possibly dropped table", + tqWarn("cannot found tsschema for table: uid:%" PRId64 " (suid:%" PRId64 "), version %d, possibly dropped table", pReader->msgIter.uid, pReader->msgIter.suid, pReader->cachedSchemaVer); /*ASSERT(0);*/ terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND; @@ -222,7 +232,7 @@ int32_t tqRetrieveDataBlock(SSDataBlock* pBlock, STqReader* pReader) { if (pReader->pSchemaWrapper) tDeleteSSchemaWrapper(pReader->pSchemaWrapper); pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, true); if (pReader->pSchemaWrapper == NULL) { - tqWarn("cannot found schema wrapper for table: suid: %ld, version %d, possibly dropped table", + tqWarn("cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table", pReader->msgIter.uid, pReader->cachedSchemaVer); /*ASSERT(0);*/ terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND; diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 946984d9c2..e4b322d0b8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -173,20 +173,64 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST return code; } -int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row) { +typedef struct { + TSKEY ts; + SColVal colVal; +} SLastCol; + +int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb *pTsdb) { int32_t code = 0; STSRow *cacheRow = NULL; char key[32] = {0}; int keyLen = 0; - ((void)(row)); + // ((void)(row)); // getTableCacheKey(uid, "l", key, &keyLen); getTableCacheKey(uid, 1, key, &keyLen); LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); if (h) { + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + TSKEY keyTs = row->ts; + bool invalidate = false; + + SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h); + int16_t nCol = taosArrayGetSize(pLast); + int16_t iCol = 0; + + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (keyTs > tTsVal->ts) { + STColumn *pTColumn = &pTSchema->columns[0]; + SColVal tColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = keyTs}); + + taosArraySet(pLast, iCol, &(SLastCol){.ts = keyTs, .colVal = tColVal}); + } + + for (++iCol; iCol < nCol; ++iCol) { + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (keyTs >= tTsVal->ts) { + SColVal *tColVal = &tTsVal->colVal; + + SColVal colVal = {0}; + tTSRowGetVal(row, pTSchema, iCol, &colVal); + if (colVal.isNone || colVal.isNull) { + if (keyTs == tTsVal->ts && !tColVal->isNone && !tColVal->isNull) { + invalidate = true; + + break; + } + } else { + taosArraySet(pLast, iCol, &(SLastCol){.ts = keyTs, .colVal = colVal}); + } + } + } + + taosMemoryFreeClear(pTSchema); + + taosLRUCacheRelease(pCache, h, invalidate); + // clear last cache anyway, lazy load when get last lookup - taosLRUCacheRelease(pCache, h, true); + // taosLRUCacheRelease(pCache, h, true); } return code; @@ -516,12 +560,46 @@ typedef struct SMemNextRowIter { SMEMNEXTROWSTATES state; STbData *pMem; // [input] STbDataIter iter; // mem buffer skip list iterator + // bool iterOpened; + // TSDBROW *curRow; } SMemNextRowIter; static int32_t getNextRowFromMem(void *iter, TSDBROW **ppRow) { + // static int32_t getNextRowFromMem(void *iter, SArray *pRowArray) { SMemNextRowIter *state = (SMemNextRowIter *)iter; int32_t code = 0; + /* + if (!state->iterOpened) { + if (state->pMem != NULL) { + tsdbTbDataIterOpen(state->pMem, NULL, 1, &state->iter); + state->iterOpened = true; + + TSDBROW *pMemRow = tsdbTbDataIterGet(&state->iter); + if (pMemRow) { + state->curRow = pMemRow; + } else { + return code; + } + } else { + return code; + } + } + + taosArrayPush(pRowArray, state->curRow); + while (tsdbTbDataIterNext(&state->iter)) { + TSDBROW *row = tsdbTbDataIterGet(&state->iter); + + if (TSDBROW_TS(row) < TSDBROW_TS(state->curRow)) { + state->curRow = row; + break; + } else { + taosArrayPush(pRowArray, row); + } + } + + return code; + */ switch (state->state) { case SMEMNEXTROW_ENTER: { if (state->pMem != NULL) { @@ -599,7 +677,7 @@ _exit: return code; } -static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int *iSkyline) { +static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int64_t *iSkyline) { bool deleted = false; while (*iSkyline > 0) { TSDBKEY *pItemBack = (TSDBKEY *)taosArrayGet(pSkyline, *iSkyline); @@ -626,9 +704,11 @@ static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int *iSkyline) { } typedef int32_t (*_next_row_fn_t)(void *iter, TSDBROW **ppRow); +// typedef int32_t (*_next_row_fn_t)(void *iter, SArray *pRowArray); typedef int32_t (*_next_row_clear_fn_t)(void *iter); -typedef struct TsdbNextRowState { +// typedef struct TsdbNextRowState { +typedef struct { TSDBROW *pRow; bool stop; bool next; @@ -637,6 +717,388 @@ typedef struct TsdbNextRowState { _next_row_clear_fn_t nextRowClearFn; } TsdbNextRowState; +typedef struct { + // STsdb *pTsdb; + SArray *pSkyline; + int64_t iSkyline; + + SBlockIdx idx; + SMemNextRowIter memState; + SMemNextRowIter imemState; + SFSNextRowIter fsState; + TSDBROW memRow, imemRow, fsRow; + + TsdbNextRowState input[3]; +} CacheNextRowIter; + +static int32_t nextRowIterOpen(CacheNextRowIter *pIter, tb_uid_t uid, STsdb *pTsdb) { + int code = 0; + + tb_uid_t suid = getTableSuidByUid(uid, pTsdb); + + STbData *pMem = NULL; + if (pTsdb->mem) { + tsdbGetTbDataFromMemTable(pTsdb->mem, suid, uid, &pMem); + } + + STbData *pIMem = NULL; + if (pTsdb->imem) { + tsdbGetTbDataFromMemTable(pTsdb->imem, suid, uid, &pIMem); + } + + pIter->pSkyline = taosArrayInit(32, sizeof(TSDBKEY)); + + SDelIdx delIdx; + + SDelFile *pDelFile = tsdbFSStateGetDelFile(pTsdb->fs->cState); + if (pDelFile) { + SDelFReader *pDelFReader; + + code = tsdbDelFReaderOpen(&pDelFReader, pDelFile, pTsdb, NULL); + if (code) goto _err; + + code = getTableDelIdx(pDelFReader, suid, uid, &delIdx); + if (code) goto _err; + + code = getTableDelSkyline(pMem, pIMem, pDelFReader, &delIdx, pIter->pSkyline); + if (code) goto _err; + + tsdbDelFReaderClose(&pDelFReader); + } else { + code = getTableDelSkyline(pMem, pIMem, NULL, NULL, pIter->pSkyline); + if (code) goto _err; + } + + pIter->iSkyline = taosArrayGetSize(pIter->pSkyline) - 1; + + pIter->idx = (SBlockIdx){.suid = suid, .uid = uid}; + + pIter->fsState.state = SFSNEXTROW_FS; + pIter->fsState.pTsdb = pTsdb; + pIter->fsState.pBlockIdxExp = &pIter->idx; + + pIter->input[0] = (TsdbNextRowState){&pIter->memRow, true, false, &pIter->memState, getNextRowFromMem, NULL}; + pIter->input[1] = (TsdbNextRowState){&pIter->imemRow, true, false, &pIter->imemState, getNextRowFromMem, NULL}; + pIter->input[2] = + (TsdbNextRowState){&pIter->fsRow, false, true, &pIter->fsState, getNextRowFromFS, clearNextRowFromFS}; + + if (pMem) { + pIter->memState.pMem = pMem; + pIter->memState.state = SMEMNEXTROW_ENTER; + pIter->input[0].stop = false; + pIter->input[0].next = true; + } + + if (pIMem) { + pIter->imemState.pMem = pIMem; + pIter->imemState.state = SMEMNEXTROW_ENTER; + pIter->input[1].stop = false; + pIter->input[1].next = true; + } + + return code; +_err: + return code; +} + +static int32_t nextRowIterClose(CacheNextRowIter *pIter) { + int code = 0; + + for (int i = 0; i < 3; ++i) { + if (pIter->input[i].nextRowClearFn) { + pIter->input[i].nextRowClearFn(pIter->input[i].iter); + } + } + + if (pIter->pSkyline) { + taosArrayDestroy(pIter->pSkyline); + } + + return code; +_err: + return code; +} + +// iterate next row non deleted backward ts, version (from high to low) +static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow) { + int code = 0; + + for (int i = 0; i < 3; ++i) { + if (pIter->input[i].next && !pIter->input[i].stop) { + code = pIter->input[i].nextRowFn(pIter->input[i].iter, &pIter->input[i].pRow); + if (code) goto _err; + + if (pIter->input[i].pRow == NULL) { + pIter->input[i].stop = true; + pIter->input[i].next = false; + } + } + } + + if (pIter->input[0].stop && pIter->input[1].stop && pIter->input[2].stop) { + *ppRow = NULL; + return code; + } + + // select maxpoint(s) from mem, imem, fs + TSDBROW *max[3] = {0}; + int iMax[3] = {-1, -1, -1}; + int nMax = 0; + TSKEY maxKey = TSKEY_MIN; + + for (int i = 0; i < 3; ++i) { + if (!pIter->input[i].stop && pIter->input[i].pRow != NULL) { + TSDBKEY key = TSDBROW_KEY(pIter->input[i].pRow); + + // merging & deduplicating on client side + if (maxKey <= key.ts) { + if (maxKey < key.ts) { + nMax = 0; + maxKey = key.ts; + } + + iMax[nMax] = i; + max[nMax++] = pIter->input[i].pRow; + } + } + } + + // delete detection + TSDBROW *merge[3] = {0}; + int iMerge[3] = {-1, -1, -1}; + int nMerge = 0; + for (int i = 0; i < nMax; ++i) { + TSDBKEY maxKey = TSDBROW_KEY(max[i]); + + bool deleted = tsdbKeyDeleted(&maxKey, pIter->pSkyline, &pIter->iSkyline); + if (!deleted) { + iMerge[nMerge] = iMax[i]; + merge[nMerge++] = max[i]; + } + + pIter->input[iMax[i]].next = deleted; + } + + if (nMerge > 0) { + pIter->input[iMerge[0]].next = true; + + *ppRow = merge[0]; + } else { + *ppRow = NULL; + } + + return code; +_err: + return code; +} + +static int32_t mergeLastRow2(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRow) { + int32_t code = 0; + + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + int16_t nCol = pTSchema->numOfCols; + int16_t iCol = 0; + int16_t noneCol = 0; + bool setNoneCol = false; + SArray *pColArray = taosArrayInit(nCol, sizeof(SColVal)); + SColVal *pColVal = &(SColVal){0}; + + // tb_uid_t suid = getTableSuidByUid(uid, pTsdb); + + TSKEY lastRowTs = TSKEY_MAX; + + CacheNextRowIter iter = {0}; + nextRowIterOpen(&iter, uid, pTsdb); + + do { + TSDBROW *pRow = NULL; + nextRowIterGet(&iter, &pRow); + + if (!pRow) { + break; + } + + if (lastRowTs == TSKEY_MAX) { + lastRowTs = TSDBROW_TS(pRow); + STColumn *pTColumn = &pTSchema->columns[0]; + + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = lastRowTs}); + if (taosArrayPush(pColArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + for (iCol = 1; iCol < nCol; ++iCol) { + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + + if (taosArrayPush(pColArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + if (pColVal->isNone && !setNoneCol) { + noneCol = iCol; + setNoneCol = true; + } + } + if (!setNoneCol) { + // goto build the result ts row + break; + } else { + continue; + } + } + + if ((TSDBROW_TS(pRow) < lastRowTs)) { + // goto build the result ts row + break; + } + + // merge into pColArray + setNoneCol = false; + for (iCol = noneCol; iCol < nCol; ++iCol) { + // high version's column value + SColVal *tColVal = (SColVal *)taosArrayGet(pColArray, iCol); + + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + if (tColVal->isNone && !pColVal->isNone) { + taosArraySet(pColArray, iCol, pColVal); + } else if (tColVal->isNone && pColVal->isNone && !setNoneCol) { + noneCol = iCol; + setNoneCol = true; + } + } + } while (setNoneCol); + + // build the result ts row here + *dup = false; + if (taosArrayGetSize(pColArray) == nCol) { + code = tdSTSRowNew(pColArray, pTSchema, ppRow); + if (code) goto _err; + } else { + *ppRow = NULL; + } + + nextRowIterClose(&iter); + taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + return code; + +_err: + nextRowIterClose(&iter); + taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + return code; +} + +static int32_t mergeLast2(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { + int32_t code = 0; + + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + int16_t nCol = pTSchema->numOfCols; + int16_t iCol = 0; + int16_t noneCol = 0; + bool setNoneCol = false; + SArray *pColArray = taosArrayInit(nCol, sizeof(SLastCol)); + SColVal *pColVal = &(SColVal){0}; + + // tb_uid_t suid = getTableSuidByUid(uid, pTsdb); + + TSKEY lastRowTs = TSKEY_MAX; + + CacheNextRowIter iter = {0}; + nextRowIterOpen(&iter, uid, pTsdb); + + do { + TSDBROW *pRow = NULL; + nextRowIterGet(&iter, &pRow); + + if (!pRow) { + break; + } + + TSKEY rowTs = TSDBROW_TS(pRow); + + if (lastRowTs == TSKEY_MAX) { + lastRowTs = rowTs; + STColumn *pTColumn = &pTSchema->columns[0]; + + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = lastRowTs}); + if (taosArrayPush(pColArray, &(SLastCol){.ts = lastRowTs, .colVal = *pColVal}) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + for (iCol = 1; iCol < nCol; ++iCol) { + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + + if (taosArrayPush(pColArray, &(SLastCol){.ts = lastRowTs, .colVal = *pColVal}) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + if ((pColVal->isNone || pColVal->isNull) && !setNoneCol) { + noneCol = iCol; + setNoneCol = true; + } + } + if (!setNoneCol) { + // goto build the result ts row + break; + } else { + continue; + } + } + /* + if ((TSDBROW_TS(pRow) < lastRowTs)) { + // goto build the result ts row + break; + } + */ + // merge into pColArray + setNoneCol = false; + for (iCol = noneCol; iCol < nCol; ++iCol) { + // high version's column value + SColVal *tColVal = (SColVal *)taosArrayGet(pColArray, iCol); + + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + if ((tColVal->isNone || tColVal->isNull) && (!pColVal->isNone && !pColVal->isNull)) { + taosArraySet(pColArray, iCol, &(SLastCol){.ts = rowTs, .colVal = *pColVal}); + //} else if (tColVal->isNone && pColVal->isNone && !setNoneCol) { + } else if ((tColVal->isNone || tColVal->isNull) && (pColVal->isNone || pColVal->isNull) && !setNoneCol) { + noneCol = iCol; + setNoneCol = true; + } + } + } while (setNoneCol); + + // build the result ts row here + //*dup = false; + if (taosArrayGetSize(pColArray) <= 0) { + *ppLastArray = NULL; + taosArrayDestroy(pColArray); + } else { + *ppLastArray = pColArray; + } + /* if (taosArrayGetSize(pColArray) == nCol) { + code = tdSTSRowNew(pColArray, pTSchema, ppRow); + if (code) goto _err; + } else { + *ppRow = NULL; + }*/ + + nextRowIterClose(&iter); + // taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + return code; + +_err: + nextRowIterClose(&iter); + // taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + return code; +} + static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRow) { int32_t code = 0; SArray *pSkyline = NULL; @@ -682,7 +1144,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo if (code) goto _err; } - int iSkyline = taosArrayGetSize(pSkyline) - 1; + int64_t iSkyline = taosArrayGetSize(pSkyline) - 1; SBlockIdx idx = {.suid = suid, .uid = uid}; @@ -719,12 +1181,14 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo do { for (int i = 0; i < 3; ++i) { if (input[i].next && !input[i].stop) { - code = input[i].nextRowFn(input[i].iter, &input[i].pRow); - if (code) goto _err; - if (input[i].pRow == NULL) { - input[i].stop = true; - input[i].next = false; + code = input[i].nextRowFn(input[i].iter, &input[i].pRow); + if (code) goto _err; + + if (input[i].pRow == NULL) { + input[i].stop = true; + input[i].next = false; + } } } } @@ -758,14 +1222,14 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo // delete detection TSDBROW *merge[3] = {0}; - // int iMerge[3] = {-1, -1, -1}; - int nMerge = 0; + int iMerge[3] = {-1, -1, -1}; + int nMerge = 0; for (int i = 0; i < nMax; ++i) { TSDBKEY maxKey = TSDBROW_KEY(max[i]); bool deleted = tsdbKeyDeleted(&maxKey, pSkyline, &iSkyline); if (!deleted) { - // iMerge[nMerge] = i; + iMerge[nMerge] = i; merge[nMerge++] = max[i]; } @@ -792,7 +1256,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo } } - } while (*ppRow == NULL); + } while (1); for (int i = 0; i < 3; ++i) { if (input[i].nextRowClearFn) { @@ -819,11 +1283,6 @@ _err: return code; } -typedef struct { - TSKEY ts; - SColVal colVal; -} SLastCol; - // static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, STSRow **ppRow) { static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { int32_t code = 0; @@ -873,7 +1332,7 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { if (code) goto _err; } - int iSkyline = taosArrayGetSize(pSkyline) - 1; + int64_t iSkyline = taosArrayGetSize(pSkyline) - 1; SBlockIdx idx = {.suid = suid, .uid = uid}; @@ -1128,7 +1587,7 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUH } else { STSRow *pRow = NULL; bool dup = false; // which is always false for now - code = mergeLastRow(uid, pTsdb, &dup, &pRow); + code = mergeLastRow2(uid, pTsdb, &dup, &pRow); // if table's empty or error, return code of -1 if (code < 0 || pRow == NULL) { if (!dup && pRow) { @@ -1195,7 +1654,8 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHand // STSRow *pRow = NULL; // code = mergeLast(uid, pTsdb, &pRow); SArray *pLastArray = NULL; - code = mergeLast(uid, pTsdb, &pLastArray); + // code = mergeLast(uid, pTsdb, &pLastArray); + code = mergeLast2(uid, pTsdb, &pLastArray); // if table's empty or error, return code of -1 // if (code < 0 || pRow == NULL) { if (code < 0 || pLastArray == NULL) { @@ -1256,6 +1716,8 @@ int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { if (invalidate) { taosLRUCacheRelease(pCache, h, true); + } else { + taosLRUCacheRelease(pCache, h, false); } // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); } diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index 9381f673d8..5186f8288f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -561,7 +561,7 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i } } - tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, pLastRow); + tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, pLastRow, pMemTable->pTsdb); pTbData->minVersion = TMIN(pTbData->minVersion, version); pTbData->maxVersion = TMAX(pTbData->maxVersion, version); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 838c61109e..5f796bbab9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -59,7 +59,6 @@ typedef struct SBlockLoadSuppInfo { SColumnDataAgg tsColAgg; SColumnDataAgg** plist; int16_t* colIds; // column ids for loading file block data - int32_t* slotIds; // colId to slotId char** buildBuf; // build string tmp buffer, todo remove it later after all string format being updated. } SBlockLoadSuppInfo; @@ -183,7 +182,6 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableK return NULL; } - // todo apply the lastkey of table check to avoid to load header file for (int32_t j = 0; j < numOfTables; ++j) { STableBlockScanInfo info = {.lastKey = 0, .uid = idList[j].uid}; if (ASCENDING_TRAVERSE(pTsdbReader->order)) { @@ -218,6 +216,30 @@ static void resetDataBlockScanInfo(SHashObj* pTableMap) { } } +static void destroyBlockScanInfo(SHashObj* pTableMap) { + STableBlockScanInfo* p = NULL; + + while ((p = taosHashIterate(pTableMap, p)) != NULL) { + p->iterInit = false; + p->iiter.hasVal = false; + + if (p->iter.iter != NULL) { + tsdbTbDataIterDestroy(p->iter.iter); + p->iter.iter = NULL; + } + + if (p->iiter.iter != NULL) { + tsdbTbDataIterDestroy(p->iiter.iter); + p->iiter.iter = NULL; + } + + taosArrayDestroy(p->delSkyline); + p->delSkyline = NULL; + } + + taosHashCleanup(pTableMap); +} + static bool isEmptyQueryTimeWindow(STimeWindow* pWindow) { ASSERT(pWindow != NULL); return pWindow->skey > pWindow->ekey; @@ -265,6 +287,10 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, const STsdbFSState* pFSt return TSDB_CODE_SUCCESS; } +static void cleanupFilesetIterator(SFilesetIter* pIter) { + taosArrayDestroy(pIter->pFileList); +} + static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) { bool asc = ASCENDING_TRAVERSE(pIter->order); int32_t step = asc ? 1 : -1; @@ -297,6 +323,9 @@ static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) { if ((asc && (win.ekey < pReader->window.skey)) || ((!asc) && (win.skey > pReader->window.ekey))) { pIter->index += step; + if ((asc && pIter->index >= pIter->numOfFiles) || ((!asc) && pIter->index < 0)) { + return false; + } continue; } @@ -313,7 +342,15 @@ static void resetDataBlockIterator(SDataBlockIter* pIter, int32_t order) { pIter->order = order; pIter->index = -1; pIter->numOfBlocks = -1; - pIter->blockList = taosArrayInit(4, sizeof(SFileDataBlockInfo)); + if (pIter->blockList == NULL) { + pIter->blockList = taosArrayInit(4, sizeof(SFileDataBlockInfo)); + } else { + taosArrayClear(pIter->blockList); + } +} + +static void cleanupDataBlockIterator(SDataBlockIter* pIter) { + taosArrayDestroy(pIter->blockList); } static void initReaderStatus(SReaderStatus* pStatus) { @@ -356,14 +393,14 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd initReaderStatus(&pReader->status); pReader->pTsdb = - getTsdbByRetentions(pVnode, pCond->twindows[0].skey, pVnode->config.tsdbCfg.retentions, idstr, &level); + getTsdbByRetentions(pVnode, pCond->twindows.skey, pVnode->config.tsdbCfg.retentions, idstr, &level); pReader->suid = pCond->suid; pReader->order = pCond->order; pReader->capacity = 4096; pReader->idStr = (idstr != NULL) ? strdup(idstr) : NULL; pReader->verRange = getQueryVerRange(pVnode, pCond, level); pReader->type = pCond->type; - pReader->window = updateQueryTimeWindow(pVnode->pTsdb, pCond->twindows); + pReader->window = updateQueryTimeWindow(pVnode->pTsdb, &pCond->twindows); ASSERT(pCond->numOfCols > 0); @@ -2182,12 +2219,21 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* ret return VND_TSDB(pVnode); } -static SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_t level) { +SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_t level) { + int64_t startVer = (pCond->startVersion == -1)? 0:pCond->startVersion; + if (VND_IS_RSMA(pVnode)) { - return (SVersionRange){.minVer = pCond->startVersion, .maxVer = tdRSmaGetMaxSubmitVer(pVnode->pSma, level)}; + return (SVersionRange){.minVer = startVer, .maxVer = tdRSmaGetMaxSubmitVer(pVnode->pSma, level)}; } - return (SVersionRange){.minVer = pCond->startVersion, .maxVer = pVnode->state.applied}; + int64_t endVer = 0; + if (pCond->endVersion == -1) { // user not specified end version, set current maximum version of vnode as the endVersion + endVer = pVnode->state.applied; + } else { + endVer = (pCond->endVersion > pVnode->state.applied)? pVnode->state.applied:pCond->endVersion; + } + + return (SVersionRange){.minVer = startVer, .maxVer = endVer}; } // // todo not unref yet, since it is not support multi-group interpolation query @@ -2506,6 +2552,7 @@ void doMergeMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDe tRowMergerInit(&merge, pRow, pReader->pSchema); doMergeRowsInBuf(pIter, k.ts, pDelList, &merge, pReader); tRowMergerGetRow(&merge, pTSRow); + tRowMergerClear(&merge); } void doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, @@ -2642,6 +2689,7 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e } doAppendOneRow(pBlock, pReader, pTSRow); + taosMemoryFree(pTSRow); // no data in buffer, return immediately if (!(pBlockScanInfo->iter.hasVal || pBlockScanInfo->iiter.hasVal)) { @@ -2769,11 +2817,24 @@ void tsdbReaderClose(STsdbReader* pReader) { return; } - blockDataDestroy(pReader->pResBlock); - taosMemoryFreeClear(pReader->suppInfo.plist); + SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; + + taosMemoryFreeClear(pSupInfo->plist); + taosMemoryFree(pSupInfo->colIds); + + taosArrayDestroy(pSupInfo->pColAgg); + for(int32_t i = 0; i < blockDataGetNumOfCols(pReader->pResBlock); ++i) { + if (pSupInfo->buildBuf[i] != NULL) { + taosMemoryFreeClear(pSupInfo->buildBuf[i]); + } + } + taosMemoryFree(pSupInfo->buildBuf); + + cleanupFilesetIterator(&pReader->status.fileIter); + cleanupDataBlockIterator(&pReader->status.blockIter); + destroyBlockScanInfo(pReader->status.pTableMap); + blockDataDestroy(pReader->pResBlock); - taosArrayDestroy(pReader->suppInfo.pColAgg); - taosMemoryFree(pReader->suppInfo.slotIds); #if 0 // if (pReader->status.pTableScanInfo != NULL) { @@ -2945,7 +3006,7 @@ SArray* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) { return pReader->pResBlock->pDataBlock; } -int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond, int32_t tWinIdx) { +int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { if (isEmptyQueryTimeWindow(&pReader->window)) { return TSDB_CODE_SUCCESS; } @@ -2955,7 +3016,7 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond, int32_ pReader->status.loadFromFile = true; pReader->status.pTableIter = NULL; - pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows[tWinIdx]); + pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows); // allocate buffer in order to load data blocks from file memset(&pReader->suppInfo.tsColAgg, 0, sizeof(SColumnDataAgg)); diff --git a/source/dnode/vnode/src/vnd/vnodeUtil.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c similarity index 52% rename from source/dnode/vnode/src/vnd/vnodeUtil.c rename to source/dnode/vnode/src/tsdb/tsdbRetention.c index cd942099bc..e73f3f947c 100644 --- a/source/dnode/vnode/src/vnd/vnodeUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -13,33 +13,30 @@ * along with this program. If not, see . */ -#include "vnd.h" +#include "tsdb.h" -int32_t vnodeRealloc(void** pp, int32_t size) { - uint8_t* p = NULL; - int32_t csize = 0; +int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) { + int32_t code = 0; - if (*pp) { - p = (uint8_t*)(*pp) - sizeof(int32_t); - csize = *(int32_t*)p; + // begin + code = tsdbFSBegin(pTsdb->fs); + if (code) goto _err; + + // do retention + for (int32_t iSet = 0; iSet < taosArrayGetSize(pTsdb->fs->nState->aDFileSet); iSet++) { + SDFileSet *pDFileSet = (SDFileSet *)taosArrayGet(pTsdb->fs->nState->aDFileSet, iSet); + + // TODO } - if (csize >= size) { - return 0; - } + // commit + code = tsdbFSCommit(pTsdb->fs); + if (code) goto _err; - p = (uint8_t*)taosMemoryRealloc(p, size); - if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - *(int32_t*)p = size; - *pp = p + sizeof(int32_t); +_exit: + return code; - return 0; -} - -void vnodeFree(void* p) { - if (p) { - taosMemoryFree(((uint8_t*)p) - sizeof(int32_t)); - } +_err: + tsdbError("vgId:%d tsdb do retention failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; } \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index 79989a5560..54087a7871 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -15,22 +15,686 @@ #include "tsdb.h" -struct STsdbSnapshotReader { - STsdb* pTsdb; - // TODO +// STsdbSnapReader ======================================== +struct STsdbSnapReader { + STsdb* pTsdb; + int64_t sver; + int64_t ever; + // for data file + int8_t dataDone; + int32_t fid; + SDataFReader* pDataFReader; + SArray* aBlockIdx; // SArray + int32_t iBlockIdx; + SBlockIdx* pBlockIdx; + SMapData mBlock; // SMapData + int32_t iBlock; + SBlockData blkData; + // for del file + int8_t delDone; + SDelFReader* pDelFReader; + int32_t iDelIdx; + SArray* aDelIdx; // SArray + SArray* aDelData; // SArray }; -int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever) { - // TODO - return 0; +static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) { + int32_t code = 0; + + while (true) { + if (pReader->pDataFReader == NULL) { + SDFileSet* pSet = NULL; + + // search the next data file set to read (todo) + if (0 /* TODO */) { + code = TSDB_CODE_VND_READ_END; + goto _exit; + } + + // open + code = tsdbDataFReaderOpen(&pReader->pDataFReader, pReader->pTsdb, pSet); + if (code) goto _err; + + // SBlockIdx + code = tsdbReadBlockIdx(pReader->pDataFReader, pReader->aBlockIdx, NULL); + if (code) goto _err; + + pReader->iBlockIdx = 0; + pReader->pBlockIdx = NULL; + } + + while (true) { + if (pReader->pBlockIdx == NULL) { + if (pReader->iBlockIdx >= taosArrayGetSize(pReader->aBlockIdx)) { + tsdbDataFReaderClose(&pReader->pDataFReader); + break; + } + + pReader->pBlockIdx = (SBlockIdx*)taosArrayGet(pReader->aBlockIdx, pReader->iBlockIdx); + pReader->iBlockIdx++; + + // SBlock + code = tsdbReadBlock(pReader->pDataFReader, pReader->pBlockIdx, &pReader->mBlock, NULL); + if (code) goto _err; + + pReader->iBlock = 0; + } + + while (true) { + SBlock block; + SBlock* pBlock = █ + + if (pReader->iBlock >= pReader->mBlock.nItem) { + pReader->pBlockIdx = NULL; + break; + } + + tMapDataGetItemByIdx(&pReader->mBlock, pReader->iBlock, pBlock, tGetBlock); + pReader->iBlock++; + + if ((pBlock->minVersion >= pReader->sver && pBlock->minVersion <= pReader->ever) || + (pBlock->maxVersion >= pReader->sver && pBlock->maxVersion <= pReader->ever)) { + // overlap (todo) + + code = tsdbReadBlockData(pReader->pDataFReader, pReader->pBlockIdx, pBlock, &pReader->blkData, NULL, NULL); + if (code) goto _err; + + goto _exit; + } + } + } + } + +_exit: + return code; + +_err: + tsdbError("vgId:%d snap read data failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + return code; } -int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader) { - // TODO - return 0; +static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) { + int32_t code = 0; + STsdb* pTsdb = pReader->pTsdb; + SDelFile* pDelFile = pTsdb->fs->cState->pDelFile; + + if (pReader->pDelFReader == NULL) { + if (pDelFile == NULL) { + code = TSDB_CODE_VND_READ_END; + goto _exit; + } + + // open + code = tsdbDelFReaderOpen(&pReader->pDelFReader, pDelFile, pTsdb, NULL); + if (code) goto _err; + + // read index + code = tsdbReadDelIdx(pReader->pDelFReader, pReader->aDelIdx, NULL); + if (code) goto _err; + + pReader->iDelIdx = 0; + } + + while (pReader->iDelIdx < taosArrayGetSize(pReader->aDelIdx)) { + SDelIdx* pDelIdx = (SDelIdx*)taosArrayGet(pReader->aDelIdx, pReader->iDelIdx); + int32_t size = 0; + + pReader->iDelIdx++; + + code = tsdbReadDelData(pReader->pDelFReader, pDelIdx, pReader->aDelData, NULL); + if (code) goto _err; + + for (int32_t iDelData = 0; iDelData < taosArrayGetSize(pReader->aDelData); iDelData++) { + SDelData* pDelData = (SDelData*)taosArrayGet(pReader->aDelData, iDelData); + + if (pDelData->version >= pReader->sver && pDelData->version <= pReader->ever) { + size += tPutDelData(NULL, pDelData); + } + } + + if (size > 0) { + int64_t n = 0; + + size = size + sizeof(SSnapDataHdr) + sizeof(TABLEID); + code = tRealloc(ppData, size); + if (code) goto _err; + + // SSnapDataHdr + SSnapDataHdr* pSnapDataHdr = (SSnapDataHdr*)(*ppData + n); + pSnapDataHdr->type = 1; + pSnapDataHdr->size = size; // TODO: size here may incorrect + n += sizeof(SSnapDataHdr); + + // TABLEID + TABLEID* pId = (TABLEID*)(*ppData + n); + pId->suid = pDelIdx->suid; + pId->uid = pDelIdx->uid; + n += sizeof(*pId); + + // DATA + for (int32_t iDelData = 0; iDelData < taosArrayGetSize(pReader->aDelData); iDelData++) { + SDelData* pDelData = (SDelData*)taosArrayGet(pReader->aDelData, iDelData); + + if (pDelData->version >= pReader->sver && pDelData->version <= pReader->ever) { + n += tPutDelData(*ppData + n, pDelData); + } + } + + goto _exit; + } + } + + code = TSDB_CODE_VND_READ_END; + tsdbDelFReaderClose(&pReader->pDelFReader); + +_exit: + return code; + +_err: + tsdbError("vgId:%d snap read del failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; } -int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData) { - // TODO - return 0; +int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapReader** ppReader) { + int32_t code = 0; + STsdbSnapReader* pReader = NULL; + + // alloc + pReader = (STsdbSnapReader*)taosMemoryCalloc(1, sizeof(*pReader)); + if (pReader == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pReader->pTsdb = pTsdb; + pReader->sver = sver; + pReader->ever = ever; + + pReader->aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); + if (pReader->aBlockIdx == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + pReader->mBlock = tMapDataInit(); + + code = tBlockDataInit(&pReader->blkData); + if (code) goto _err; + + pReader->aDelIdx = taosArrayInit(0, sizeof(SDelIdx)); + if (pReader->aDelIdx == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + pReader->aDelData = taosArrayInit(0, sizeof(SDelData)); + if (pReader->aDelData == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + *ppReader = pReader; + return code; + +_err: + tsdbError("vgId:%d snapshot reader open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + *ppReader = NULL; + return code; +} + +int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader) { + int32_t code = 0; + STsdbSnapReader* pReader = *ppReader; + + taosArrayDestroy(pReader->aDelData); + taosArrayDestroy(pReader->aDelIdx); + if (pReader->pDelFReader) { + tsdbDelFReaderClose(&pReader->pDelFReader); + } + tBlockDataClear(&pReader->blkData); + tMapDataClear(&pReader->mBlock); + taosArrayDestroy(pReader->aBlockIdx); + if (pReader->pDataFReader) { + tsdbDataFReaderClose(&pReader->pDataFReader); + } + taosMemoryFree(pReader); + *ppReader = NULL; + + return code; +} + +int32_t tsdbSnapRead(STsdbSnapReader* pReader, uint8_t** ppData) { + int32_t code = 0; + + // read data file + if (!pReader->dataDone) { + code = tsdbSnapReadData(pReader, ppData); + if (code) { + if (code == TSDB_CODE_VND_READ_END) { + pReader->dataDone = 1; + } else { + goto _err; + } + } else { + goto _exit; + } + } + + // read del file + if (!pReader->delDone) { + code = tsdbSnapReadDel(pReader, ppData); + if (code) { + if (code == TSDB_CODE_VND_READ_END) { + pReader->delDone = 1; + } else { + goto _err; + } + } else { + goto _exit; + } + } + + code = TSDB_CODE_VND_READ_END; + +_exit: + return code; + +_err: + tsdbError("vgId:%d snapshot read failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + return code; +} + +// STsdbSnapWriter ======================================== +struct STsdbSnapWriter { + STsdb* pTsdb; + int64_t sver; + int64_t ever; + + // config + int32_t minutes; + int8_t precision; + + // for data file + int32_t fid; + SDataFReader* pDataFReader; + SArray* aBlockIdx; + int32_t iBlockIdx; + SBlockIdx* pBlockIdx; + SMapData mBlock; + int32_t iBlock; + SBlockData blockData; + int32_t iRow; + + SDataFWriter* pDataFWriter; + SArray* aBlockIdxN; + SBlockIdx blockIdx; + SMapData mBlockN; + SBlock block; + SBlockData nBlockData; + + // for del file + SDelFReader* pDelFReader; + SDelFWriter* pDelFWriter; + int32_t iDelIdx; + SArray* aDelIdx; + SArray* aDelData; + SArray* aDelIdxN; +}; + +static int32_t tsdbSnapRollback(STsdbSnapWriter* pWriter) { + int32_t code = 0; + // TODO + return code; +} + +static int32_t tsdbSnapCommit(STsdbSnapWriter* pWriter) { + int32_t code = 0; + // TODO + return code; +} + +static int32_t tsdbSnapWriteDataEnd(STsdbSnapWriter* pWriter) { + int32_t code = 0; + STsdb* pTsdb = pWriter->pTsdb; + + if (pWriter->pDataFWriter == NULL) goto _exit; + + // TODO + + code = tsdbDataFWriterClose(&pWriter->pDataFWriter, 0); + if (code) goto _err; + + if (pWriter->pDataFReader) { + code = tsdbDataFReaderClose(&pWriter->pDataFReader); + if (code) goto _err; + } + +_exit: + return code; + +_err: + tsdbError("vgId:%d tsdb snapshot writer data end failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} + +static int32_t tsdbSnapWriteAppendData(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { + int32_t code = 0; + int32_t iRow = 0; // todo + int32_t nRow = 0; // todo + SBlockData* pBlockData = NULL; // todo + + while (iRow < nRow) { + code = tBlockDataAppendRow(&pWriter->nBlockData, &tsdbRowFromBlockData(pBlockData, iRow), NULL); + if (code) goto _err; + } + + return code; + +_err: + tsdbError("vgId:%d tsdb snapshot write append data failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + return code; +} + +static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { + int32_t code = 0; + STsdb* pTsdb = pWriter->pTsdb; + int64_t suid = 0; // todo + int64_t uid = 0; // todo + int64_t skey; // todo + int64_t ekey; // todo + + int32_t fid = tsdbKeyFid(skey, pWriter->minutes, pWriter->precision); + ASSERT(fid == tsdbKeyFid(ekey, pWriter->minutes, pWriter->precision)); + + // begin + if (pWriter->pDataFWriter == NULL || pWriter->fid != fid) { + code = tsdbSnapWriteDataEnd(pWriter); + if (code) goto _err; + + pWriter->fid = fid; + SDFileSet* pSet = tsdbFSStateGetDFileSet(pTsdb->fs->nState, fid); + // reader + if (pSet) { + // open + code = tsdbDataFReaderOpen(&pWriter->pDataFReader, pTsdb, pSet); + if (code) goto _err; + + // SBlockIdx + code = tsdbReadBlockIdx(pWriter->pDataFReader, pWriter->aBlockIdx, NULL); + if (code) goto _err; + } else { + taosArrayClear(pWriter->aBlockIdx); + } + pWriter->iBlockIdx = 0; + + // writer + SDFileSet wSet = {0}; + if (pSet == NULL) { + wSet = (SDFileSet){0}; // todo + } else { + wSet = (SDFileSet){0}; // todo + } + + code = tsdbDataFWriterOpen(&pWriter->pDataFWriter, pTsdb, &wSet); + if (code) goto _err; + + taosArrayClear(pWriter->aBlockIdxN); + } + + // process + TABLEID id = {0}; // TODO + TSKEY minKey = 0; // TODO + TSKEY maxKey = 0; // TODO + + while (true) { + if (pWriter->pBlockIdx) { + int32_t c = tTABLEIDCmprFn(&id, pWriter->pBlockIdx); + + if (c == 0) { + } else if (c < 0) { + // keep merge + } else { + // code = tsdbSnapWriteTableDataEnd(pWriter); + if (code) goto _err; + + pWriter->iBlockIdx++; + if (pWriter->iBlockIdx < taosArrayGetSize(pWriter->aBlockIdx)) { + pWriter->pBlockIdx = (SBlockIdx*)taosArrayGet(pWriter->aBlockIdx, pWriter->iBlockIdx); + } else { + pWriter->pBlockIdx = NULL; + } + + if (pWriter->pBlockIdx) { + code = tsdbReadBlock(pWriter->pDataFReader, pWriter->pBlockIdx, &pWriter->mBlock, NULL); + if (code) goto _err; + } + } + } else { + int32_t c = tTABLEIDCmprFn(&id, &pWriter->blockIdx); + + if (c == 0) { + // merge commit the block data + } else if (c > 0) { + // code = tsdbSnapWriteTableDataEnd(pWriter); + if (code) goto _err; + } else { + ASSERT(0); + } + } + } + + return code; + +_err: + tsdbError("vgId:%d tsdb snapshot write data failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} + +static int32_t tsdbSnapWriteDel(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { + int32_t code = 0; + STsdb* pTsdb = pWriter->pTsdb; + + if (pWriter->pDelFWriter == NULL) { + SDelFile* pDelFile = tsdbFSStateGetDelFile(pTsdb->fs->nState); + + // reader + if (pDelFile) { + code = tsdbDelFReaderOpen(&pWriter->pDelFReader, pDelFile, pTsdb, NULL); + if (code) goto _err; + + code = tsdbReadDelIdx(pWriter->pDelFReader, pWriter->aDelIdx, NULL); + if (code) goto _err; + } + + // writer + SDelFile delFile = {.commitID = pTsdb->pVnode->state.commitID, .offset = 0, .size = 0}; + code = tsdbDelFWriterOpen(&pWriter->pDelFWriter, &delFile, pTsdb); + if (code) goto _err; + } + + // process the del data + TABLEID id = {0}; // todo + + while (true) { + SDelIdx* pDelIdx = NULL; + int64_t n = 0; + SDelData delData; + SDelIdx delIdx; + int8_t toBreak = 0; + + if (pWriter->iDelIdx < taosArrayGetSize(pWriter->aDelIdx)) { + pDelIdx = taosArrayGet(pWriter->aDelIdx, pWriter->iDelIdx); + } + + if (pDelIdx) { + int32_t c = tTABLEIDCmprFn(&id, pDelIdx); + if (c < 0) { + goto _new_del; + } else { + code = tsdbReadDelData(pWriter->pDelFReader, pDelIdx, pWriter->aDelData, NULL); + if (code) goto _err; + + pWriter->iDelIdx++; + if (c == 0) { + toBreak = 1; + delIdx = (SDelIdx){.suid = id.suid, .uid = id.uid}; + goto _merge_del; + } else { + delIdx = (SDelIdx){.suid = pDelIdx->suid, .uid = pDelIdx->uid}; + goto _write_del; + } + } + } + + _new_del: + toBreak = 1; + delIdx = (SDelIdx){.suid = id.suid, .uid = id.uid}; + taosArrayClear(pWriter->aDelData); + + _merge_del: + while (n < nData) { + n += tGetDelData(pData + n, &delData); + if (taosArrayPush(pWriter->aDelData, &delData) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + + _write_del: + code = tsdbWriteDelData(pWriter->pDelFWriter, pWriter->aDelData, NULL, &delIdx); + if (code) goto _err; + + if (taosArrayPush(pWriter->aDelIdxN, &delIdx) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + if (toBreak) break; + } + +_exit: + return code; + +_err: + tsdbError("vgId:%d tsdb snapshot write del failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} + +static int32_t tsdbSnapWriteDelEnd(STsdbSnapWriter* pWriter) { + int32_t code = 0; + STsdb* pTsdb = pWriter->pTsdb; + + if (pWriter->pDelFWriter == NULL) goto _exit; + for (; pWriter->iDelIdx < taosArrayGetSize(pWriter->aDelIdx); pWriter->iDelIdx++) { + SDelIdx* pDelIdx = (SDelIdx*)taosArrayGet(pWriter->aDelIdx, pWriter->iDelIdx); + + code = tsdbReadDelData(pWriter->pDelFReader, pDelIdx, pWriter->aDelData, NULL); + if (code) goto _err; + + SDelIdx delIdx = (SDelIdx){.suid = pDelIdx->suid, .uid = pDelIdx->uid}; + code = tsdbWriteDelData(pWriter->pDelFWriter, pWriter->aDelData, NULL, &delIdx); + if (code) goto _err; + + if (taosArrayPush(pWriter->aDelIdx, &delIdx) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + } + + code = tsdbUpdateDelFileHdr(pWriter->pDelFWriter); + if (code) goto _err; + + code = tsdbFSStateUpsertDelFile(pTsdb->fs->nState, &pWriter->pDelFWriter->fDel); + if (code) goto _err; + + code = tsdbDelFWriterClose(&pWriter->pDelFWriter, 1); + if (code) goto _err; + + if (pWriter->pDelFReader) { + code = tsdbDelFReaderClose(&pWriter->pDelFReader); + if (code) goto _err; + } + +_exit: + return code; + +_err: + tsdbError("vgId:%d tsdb snapshow write del end failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} + +int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWriter** ppWriter) { + int32_t code = 0; + STsdbSnapWriter* pWriter = NULL; + + // alloc + pWriter = (STsdbSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter)); + if (pWriter == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pWriter->pTsdb = pTsdb; + pWriter->sver = sver; + pWriter->ever = ever; + + *ppWriter = pWriter; + return code; + +_err: + tsdbError("vgId:%d tsdb snapshot writer open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + *ppWriter = NULL; + return code; +} + +int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback) { + int32_t code = 0; + STsdbSnapWriter* pWriter = *ppWriter; + + if (rollback) { + code = tsdbSnapRollback(pWriter); + if (code) goto _err; + } else { + code = tsdbSnapWriteDataEnd(pWriter); + if (code) goto _err; + + code = tsdbSnapWriteDelEnd(pWriter); + if (code) goto _err; + + code = tsdbSnapCommit(pWriter); + if (code) goto _err; + } + + taosMemoryFree(pWriter); + *ppWriter = NULL; + + return code; + +_err: + tsdbError("vgId:%d tsdb snapshot writer close failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + return code; +} + +int32_t tsdbSnapWrite(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { + int32_t code = 0; + int8_t type = pData[0]; + + // ts data + if (type == 0) { + code = tsdbSnapWriteData(pWriter, pData + 1, nData - 1); + if (code) goto _err; + } else { + code = tsdbSnapWriteDataEnd(pWriter); + if (code) goto _err; + } + + // del data + if (type == 1) { + code = tsdbSnapWriteDel(pWriter, pData + 1, nData - 1); + if (code) goto _err; + } + + return code; + +_err: + tsdbError("vgId:%d tsdb snapshow write failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 2e628edb7a..415a674737 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -87,8 +87,10 @@ int32_t tPutMapData(uint8_t *p, SMapData *pMapData) { n += tPutI32v(p ? p + n : p, pMapData->nItem); if (pMapData->nItem) { + int32_t lOffset = 0; for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) { - n += tPutI32v(p ? p + n : p, pMapData->aOffset[iItem]); + n += tPutI32v(p ? p + n : p, pMapData->aOffset[iItem] - lOffset); + lOffset = pMapData->aOffset[iItem]; } n += tPutI32v(p ? p + n : p, pMapData->nData); @@ -111,8 +113,11 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData) { if (pMapData->nItem) { if (tRealloc((uint8_t **)&pMapData->aOffset, sizeof(int32_t) * pMapData->nItem)) return -1; + int32_t lOffset = 0; for (int32_t iItem = 0; iItem < pMapData->nItem; iItem++) { n += tGetI32v(p + n, &pMapData->aOffset[iItem]); + pMapData->aOffset[iItem] += lOffset; + lOffset = pMapData->aOffset[iItem]; } n += tGetI32v(p + n, &pMapData->nData); diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index c74baa6d7b..20ac56617f 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -15,30 +15,37 @@ #include "vnd.h" -const SVnodeCfg vnodeCfgDefault = { - .vgId = -1, - .dbname = "", - .dbId = 0, - .szPage = 4096, - .szCache = 256, - .szBuf = 96 * 1024 * 1024, - .isHeap = false, - .isWeak = 0, - .tsdbCfg = {.precision = TSDB_TIME_PRECISION_MILLI, - .update = 1, - .compression = 2, - .slLevel = 5, - .days = 14400, - .minRows = 100, - .maxRows = 4096, - .keep2 = 5256000, - .keep0 = 5256000, - .keep1 = 5256000}, - .walCfg = - {.vgId = -1, .fsyncPeriod = 0, .retentionPeriod = 0, .rollPeriod = 0, .segSize = 0, .level = TAOS_WAL_WRITE}, - .hashBegin = 0, - .hashEnd = 0, - .hashMethod = 0}; +const SVnodeCfg vnodeCfgDefault = {.vgId = -1, + .dbname = "", + .dbId = 0, + .szPage = 4096, + .szCache = 256, + .szBuf = 96 * 1024 * 1024, + .isHeap = false, + .isWeak = 0, + .tsdbCfg = {.precision = TSDB_TIME_PRECISION_MILLI, + .update = 1, + .compression = 2, + .slLevel = 5, + .days = 14400, + .minRows = 100, + .maxRows = 4096, + .keep2 = 5256000, + .keep0 = 5256000, + .keep1 = 5256000}, + .walCfg = + { + .vgId = -1, + .fsyncPeriod = 0, + .retentionPeriod = -1, + .rollPeriod = -1, + .segSize = -1, + .retentionSize = -1, + .level = TAOS_WAL_WRITE, + }, + .hashBegin = 0, + .hashEnd = 0, + .hashMethod = 0}; int vnodeCheckCfg(const SVnodeCfg *pCfg) { // TODO @@ -79,7 +86,7 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { SJson *pNodeRetentions = tjsonCreateArray(); tjsonAddItemToObject(pJson, "retentions", pNodeRetentions); for (int32_t i = 0; i < nRetention; ++i) { - SJson * pNodeRetention = tjsonCreateObject(); + SJson *pNodeRetention = tjsonCreateObject(); const SRetention *pRetention = pCfg->tsdbCfg.retentions + i; tjsonAddIntegerToObject(pNodeRetention, "freq", pRetention->freq); tjsonAddIntegerToObject(pNodeRetention, "freqUnit", pRetention->freqUnit); @@ -156,7 +163,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (code < 0) return -1; tjsonGetNumberValue(pJson, "keep2", pCfg->tsdbCfg.keep2, code); if (code < 0) return -1; - SJson * pNodeRetentions = tjsonGetObjectItem(pJson, "retentions"); + SJson *pNodeRetentions = tjsonGetObjectItem(pJson, "retentions"); int32_t nRetention = tjsonGetArraySize(pNodeRetentions); if (nRetention > TSDB_RETENTION_MAX) { nRetention = TSDB_RETENTION_MAX; diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 21db14f0df..ebbb691e28 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -15,7 +15,7 @@ #include "vnd.h" -#define VND_INFO_FNAME "vnode.json" +#define VND_INFO_FNAME "vnode.json" #define VND_INFO_FNAME_TMP "vnode_tmp.json" static int vnodeEncodeInfo(const SVnodeInfo *pInfo, char **ppData); @@ -223,12 +223,14 @@ int vnodeCommit(SVnode *pVnode) { // save info info.config = pVnode->config; info.state.committed = pVnode->state.applied; + info.state.commitTerm = pVnode->state.applyTerm; info.state.commitID = pVnode->state.commitID; snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path); if (vnodeSaveInfo(dir, &info) < 0) { ASSERT(0); return -1; } + walBeginSnapshot(pVnode->pWal, pVnode->state.applied); // preCommit smaPreCommit(pVnode->pSma); @@ -270,13 +272,14 @@ int vnodeCommit(SVnode *pVnode) { ASSERT(0); return -1; } - + pVnode->state.committed = info.state.committed; // postCommit smaPostCommit(pVnode->pSma); // apply the commit (TODO) + walEndSnapshot(pVnode->pWal); vnodeBufPoolReset(pVnode->onCommit); pVnode->onCommit->next = pVnode->pPool; pVnode->pPool = pVnode->onCommit; @@ -316,6 +319,7 @@ static int vnodeEncodeState(const void *pObj, SJson *pJson) { if (tjsonAddIntegerToObject(pJson, "commit version", pState->committed) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "commit ID", pState->commitID) < 0) return -1; + if (tjsonAddIntegerToObject(pJson, "commit term", pState->commitTerm) < 0) return -1; return 0; } @@ -328,6 +332,8 @@ static int vnodeDecodeState(const SJson *pJson, void *pObj) { if (code < 0) return -1; tjsonGetNumberValue(pJson, "commit ID", pState->commitID, code); if (code < 0) return -1; + tjsonGetNumberValue(pJson, "commit term", pState->commitTerm, code); + if (code < 0) return -1; return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeModule.c b/source/dnode/vnode/src/vnd/vnodeModule.c index d0aede145e..69f87a2c1a 100644 --- a/source/dnode/vnode/src/vnd/vnodeModule.c +++ b/source/dnode/vnode/src/vnd/vnodeModule.c @@ -100,6 +100,7 @@ void vnodeCleanup() { walCleanUp(); tqCleanUp(); + smaCleanUp(); } int vnodeScheduleTask(int (*execute)(void*), void* arg) { diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 4267dd9b1f..fe26bd1090 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -79,8 +79,10 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { strcpy(pVnode->path, path); pVnode->config = info.config; pVnode->state.committed = info.state.committed; + pVnode->state.commitTerm = info.state.commitTerm; pVnode->state.applied = info.state.committed; pVnode->state.commitID = info.state.commitID; + pVnode->state.commitTerm = info.state.commitTerm; pVnode->pTfs = pTfs; pVnode->msgCb = msgCb; pVnode->blockCount = 0; @@ -115,6 +117,13 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { // open wal sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_WAL_DIR); taosRealPath(tdir, NULL, sizeof(tdir)); + +// for test tsdb snapshot +#if 0 + pVnode->config.walCfg.segSize = 200; + pVnode->config.walCfg.retentionSize = 2000; +#endif + pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg)); if (pVnode->pWal == NULL) { vError("vgId:%d, failed to open vnode wal since %s", TD_VID(pVnode), tstrerror(terrno)); @@ -194,4 +203,9 @@ void vnodeStop(SVnode *pVnode) {} int64_t vnodeGetSyncHandle(SVnode *pVnode) { return pVnode->sync; } -void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot) { pSnapshot->lastApplyIndex = pVnode->state.committed; } +void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot) { + pSnapshot->data = NULL; + pSnapshot->lastApplyIndex = pVnode->state.committed; + pSnapshot->lastApplyTerm = pVnode->state.commitTerm; + pSnapshot->lastConfigIndex = -1; +} diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index baa8422307..27f30ec787 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -13,24 +13,27 @@ * along with this program. If not, see . */ -#include "vnodeInt.h" +#include "vnd.h" -struct SVSnapshotReader { - SVnode *pVnode; - int64_t sver; - int64_t ever; - int8_t isMetaEnd; - int8_t isTsdbEnd; - SMetaSnapshotReader *pMetaReader; - STsdbSnapshotReader *pTsdbReader; - void *pData; - int32_t nData; +// SVSnapReader ======================================================== +struct SVSnapReader { + SVnode *pVnode; + int64_t sver; + int64_t ever; + // meta + int8_t metaDone; + SMetaSnapReader *pMetaReader; + // tsdb + int8_t tsdbDone; + STsdbSnapReader *pTsdbReader; + uint8_t *pData; }; -int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever) { - SVSnapshotReader *pReader = NULL; +int32_t vnodeSnapReaderOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapReader **ppReader) { + int32_t code = 0; + SVSnapReader *pReader = NULL; - pReader = (SVSnapshotReader *)taosMemoryCalloc(1, sizeof(*pReader)); + pReader = (SVSnapReader *)taosMemoryCalloc(1, sizeof(*pReader)); if (pReader == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto _err; @@ -38,72 +41,169 @@ int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int pReader->pVnode = pVnode; pReader->sver = sver; pReader->ever = ever; - pReader->isMetaEnd = 0; - pReader->isTsdbEnd = 0; - if (metaSnapshotReaderOpen(pVnode->pMeta, &pReader->pMetaReader, sver, ever) < 0) { - taosMemoryFree(pReader); - goto _err; - } + code = metaSnapReaderOpen(pVnode->pMeta, sver, ever, &pReader->pMetaReader); + if (code) goto _err; - if (tsdbSnapshotReaderOpen(pVnode->pTsdb, &pReader->pTsdbReader, sver, ever) < 0) { - metaSnapshotReaderClose(pReader->pMetaReader); - taosMemoryFree(pReader); - goto _err; - } + code = tsdbSnapReaderOpen(pVnode->pTsdb, sver, ever, &pReader->pTsdbReader); + if (code) goto _err; -_exit: *ppReader = pReader; - return 0; + return code; _err: + vError("vgId:%d vnode snapshot reader open failed since %s", TD_VID(pVnode), tstrerror(code)); *ppReader = NULL; - return -1; + return code; } -int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader) { - if (pReader) { - vnodeFree(pReader->pData); - tsdbSnapshotReaderClose(pReader->pTsdbReader); - metaSnapshotReaderClose(pReader->pMetaReader); - taosMemoryFree(pReader); - } - return 0; -} - -int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData) { +int32_t vnodeSnapReaderClose(SVSnapReader *pReader) { int32_t code = 0; - if (!pReader->isMetaEnd) { - code = metaSnapshotRead(pReader->pMetaReader, &pReader->pData, &pReader->nData); + tFree(pReader->pData); + if (pReader->pTsdbReader) tsdbSnapReaderClose(&pReader->pTsdbReader); + if (pReader->pMetaReader) metaSnapReaderClose(&pReader->pMetaReader); + taosMemoryFree(pReader); + + return code; +} + +int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) { + int32_t code = 0; + + if (!pReader->metaDone) { + code = metaSnapRead(pReader->pMetaReader, &pReader->pData); if (code) { if (code == TSDB_CODE_VND_READ_END) { - pReader->isMetaEnd = 1; + pReader->metaDone = 1; } else { - return code; + goto _err; } } else { *ppData = pReader->pData; - *nData = pReader->nData; - return code; + *nData = sizeof(SSnapDataHdr) + ((SSnapDataHdr *)pReader->pData)->size; + goto _exit; } } - if (!pReader->isTsdbEnd) { - code = tsdbSnapshotRead(pReader->pTsdbReader, &pReader->pData, &pReader->nData); + if (!pReader->tsdbDone) { + code = tsdbSnapRead(pReader->pTsdbReader, &pReader->pData); if (code) { if (code == TSDB_CODE_VND_READ_END) { - pReader->isTsdbEnd = 1; + pReader->tsdbDone = 1; } else { - return code; + goto _err; } } else { *ppData = pReader->pData; - *nData = pReader->nData; - return code; + *nData = sizeof(SSnapDataHdr) + ((SSnapDataHdr *)pReader->pData)->size; + goto _exit; } } code = TSDB_CODE_VND_READ_END; + +_exit: + return code; + +_err: + vError("vgId:% snapshot read failed since %s", TD_VID(pReader->pVnode), tstrerror(code)); + return code; +} + +// SVSnapWriter ======================================================== +struct SVSnapWriter { + SVnode *pVnode; + int64_t sver; + int64_t ever; + // meta + SMetaSnapWriter *pMetaSnapWriter; + // tsdb + STsdbSnapWriter *pTsdbSnapWriter; +}; + +static int32_t vnodeSnapRollback(SVSnapWriter *pWriter) { + int32_t code = 0; + // TODO + return code; +} + +static int32_t vnodeSnapCommit(SVSnapWriter *pWriter) { + int32_t code = 0; + // TODO + return code; +} + +int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWriter **ppWriter) { + int32_t code = 0; + SVSnapWriter *pWriter = NULL; + + // alloc + pWriter = (SVSnapWriter *)taosMemoryCalloc(1, sizeof(*pWriter)); + if (pWriter == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pWriter->pVnode = pVnode; + pWriter->sver = sver; + pWriter->ever = ever; + + return code; + +_err: + vError("vgId:%d vnode snapshot writer open failed since %s", TD_VID(pVnode), tstrerror(code)); + return code; +} + +int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback) { + int32_t code = 0; + + if (rollback) { + code = vnodeSnapRollback(pWriter); + if (code) goto _err; + } else { + code = vnodeSnapCommit(pWriter); + if (code) goto _err; + } + + taosMemoryFree(pWriter); + return code; + +_err: + vError("vgId:%d vnode snapshow writer close failed since %s", TD_VID(pWriter->pVnode), tstrerror(code)); + return code; +} + +int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) { + int32_t code = 0; + SSnapDataHdr *pSnapDataHdr = (SSnapDataHdr *)pData; + SVnode *pVnode = pWriter->pVnode; + + ASSERT(pSnapDataHdr->size + sizeof(SSnapDataHdr) == nData); + + if (pSnapDataHdr->type == 0) { + // meta + if (pWriter->pMetaSnapWriter == NULL) { + code = metaSnapWriterOpen(pVnode->pMeta, pWriter->sver, pWriter->ever, &pWriter->pMetaSnapWriter); + if (code) goto _err; + } + + code = metaSnapWrite(pWriter->pMetaSnapWriter, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr)); + if (code) goto _err; + } else { + // tsdb + if (pWriter->pTsdbSnapWriter == NULL) { + code = tsdbSnapWriterOpen(pVnode->pTsdb, pWriter->sver, pWriter->ever, &pWriter->pTsdbSnapWriter); + if (code) goto _err; + } + + code = tsdbSnapWrite(pWriter->pTsdbSnapWriter, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr)); + if (code) goto _err; + } + + return code; + +_err: + vError("vgId:%d vnode snapshot write failed since %s", TD_VID(pVnode), tstrerror(code)); return code; } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index cd25707fce..3140d6ad59 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -24,7 +24,8 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); -static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); +static int32_t vnodeProcessAlterHashRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); +static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); @@ -143,6 +144,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp version); pVnode->state.applied = version; + pVnode->state.applyTerm = pMsg->info.conn.applyTerm; // skip header pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); @@ -214,9 +216,10 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp vnodeProcessAlterConfirmReq(pVnode, version, pReq, len, pRsp); break; case TDMT_VND_ALTER_HASHRANGE: - vnodeProcessAlterHasnRangeReq(pVnode, version, pReq, len, pRsp); + vnodeProcessAlterHashRangeReq(pVnode, version, pReq, len, pRsp); break; case TDMT_VND_ALTER_CONFIG: + vnodeProcessAlterConfigReq(pVnode, version, pReq, len, pRsp); break; case TDMT_VND_COMMIT: goto _do_commit; @@ -885,7 +888,7 @@ static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void return 0; } -static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { +static int32_t vnodeProcessAlterHashRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { vInfo("vgId:%d, alter hashrange msg will be processed", TD_VID(pVnode)); // todo @@ -895,6 +898,18 @@ static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, vo return 0; } +static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { + SAlterVnodeReq alterReq = {0}; + if (tDeserializeSAlterVnodeReq(pReq, len, &alterReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return TSDB_CODE_INVALID_MSG; + } + + vInfo("vgId:%d, start to alter vnode config, cacheLast:%d cacheLastSize:%d", TD_VID(pVnode), alterReq.cacheLast, + alterReq.cacheLastSize); + return 0; +} + static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { int32_t code = 0; SDecoder *pCoder = &(SDecoder){0}; diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index 0ca083d551..97ce8eaab7 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -423,7 +423,7 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { SVnode *pVnode = pFsm->data; - vTrace("vgId:%d, commit-cb is excuted, fsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", + vTrace("vgId:%d, commit-cb is excuted, fsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), pMsg->msgType, TMSG_INFO(pMsg->msgType)); @@ -438,43 +438,94 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c static void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { SVnode *pVnode = pFsm->data; - vTrace("vgId:%d, pre-commit-cb is excuted, fsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", + vTrace("vgId:%d, pre-commit-cb is excuted, fsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), pMsg->msgType, TMSG_INFO(pMsg->msgType)); } static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { SVnode *pVnode = pFsm->data; - vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", + vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, msgtype:%d %s", syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), pMsg->msgType, TMSG_INFO(pMsg->msgType)); } +#define USE_TSDB_SNAPSHOT + static int32_t vnodeSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) { +#ifdef USE_TSDB_SNAPSHOT SVnode *pVnode = pFsm->data; SSnapshotParam *pSnapshotParam = pParam; - int32_t code = - vnodeSnapshotReaderOpen(pVnode, (SVSnapshotReader **)ppReader, pSnapshotParam->start, pSnapshotParam->end); + int32_t code = vnodeSnapReaderOpen(pVnode, pSnapshotParam->start, pSnapshotParam->end, (SVSnapReader **)ppReader); return code; +#else + *ppReader = taosMemoryMalloc(32); + return 0; +#endif } static int32_t vnodeSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { +#ifdef USE_TSDB_SNAPSHOT SVnode *pVnode = pFsm->data; - int32_t code = vnodeSnapshotReaderClose(pReader); + int32_t code = vnodeSnapReaderClose(pReader); return code; +#else + taosMemoryFree(pReader); + return 0; +#endif } static int32_t vnodeSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) { +#ifdef USE_TSDB_SNAPSHOT SVnode *pVnode = pFsm->data; - int32_t code = vnodeSnapshotRead(pReader, (const void **)ppBuf, len); + int32_t code = vnodeSnapRead(pReader, (uint8_t **)ppBuf, len); return code; +#else + static int32_t times = 0; + if (times++ < 5) { + *len = 64; + *ppBuf = taosMemoryMalloc(*len); + snprintf(*ppBuf, *len, "snapshot block %d", times); + } else { + *len = 0; + *ppBuf = NULL; + } + return 0; +#endif } -static int32_t vnodeSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void **ppWriter) { return 0; } +static int32_t vnodeSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void **ppWriter) { +#ifdef USE_TSDB_SNAPSHOT + SVnode *pVnode = pFsm->data; + SSnapshotParam *pSnapshotParam = pParam; + int32_t code = vnodeSnapWriterOpen(pVnode, pSnapshotParam->start, pSnapshotParam->end, (SVSnapWriter **)ppWriter); + return code; +#else + *ppWriter = taosMemoryMalloc(32); + return 0; +#endif +} -static int32_t vnodeSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool isApply) { return 0; } +static int32_t vnodeSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool isApply) { +#ifdef USE_TSDB_SNAPSHOT + SVnode *pVnode = pFsm->data; + int32_t code = vnodeSnapWriterClose(pWriter, !isApply); + return code; +#else + taosMemoryFree(pWriter); + return 0; +#endif +} -static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) { return 0; } +static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) { +#ifdef USE_TSDB_SNAPSHOT + SVnode *pVnode = pFsm->data; + int32_t code = vnodeSnapWrite(pWriter, pBuf, len); + return code; +#else + return 0; +#endif +} static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM)); @@ -497,7 +548,8 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { SSyncInfo syncInfo = { - .snapshotStrategy = SYNC_STRATEGY_NO_SNAPSHOT, + .snapshotStrategy = SYNC_STRATEGY_WAL_FIRST, + //.snapshotStrategy = SYNC_STRATEGY_NO_SNAPSHOT, .batchSize = 10, .vgId = pVnode->config.vgId, .isStandBy = pVnode->config.standby, diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 9d0e3871cc..598a754c50 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -166,7 +166,7 @@ typedef struct SCtgDBCache { int8_t deleted; SCtgVgCache vgCache; SHashObj *tbCache; // key:tbname, value:SCtgTbCache - SHashObj *stbCache; // key:suid, value:STableMeta* + SHashObj *stbCache; // key:suid, value:char* } SCtgDBCache; typedef struct SCtgRentSlot { @@ -480,37 +480,35 @@ typedef struct SCtgOperation { #define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000 -#define CTG_IS_LOCKED(_lock) atomic_load_32((_lock)) - #define CTG_LOCK(type, _lock) do { \ if (CTG_READ == (type)) { \ - assert(atomic_load_32((_lock)) >= 0); \ - CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ + CTG_LOCK_DEBUG("CTG RLOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ taosRLockLatch(_lock); \ - CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) > 0); \ + CTG_LOCK_DEBUG("CTG RLOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) > 0); \ } else { \ - assert(atomic_load_32((_lock)) >= 0); \ - CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ + CTG_LOCK_DEBUG("CTG WLOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ taosWLockLatch(_lock); \ - CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ + CTG_LOCK_DEBUG("CTG WLOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ } \ } while (0) #define CTG_UNLOCK(type, _lock) do { \ if (CTG_READ == (type)) { \ - assert(atomic_load_32((_lock)) > 0); \ - CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) > 0); \ + CTG_LOCK_DEBUG("CTG RULOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ taosRUnLockLatch(_lock); \ - CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) >= 0); \ + CTG_LOCK_DEBUG("CTG RULOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ } else { \ - assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ - CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ + CTG_LOCK_DEBUG("CTG WULOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ taosWUnLockLatch(_lock); \ - CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) >= 0); \ + CTG_LOCK_DEBUG("CTG WULOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ } \ } while (0) diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 455f2bd6a7..e77df8f7f2 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -789,9 +789,13 @@ _return: int32_t ctgCallUserCb(void* param) { SCtgJob* pJob = (SCtgJob*)param; + + qDebug("QID:0x%" PRIx64 " ctg start to call user cb with rsp %s", pJob->queryId, tstrerror(pJob->jobResCode)); (*pJob->userFp)(&pJob->jobRes, pJob->userParam, pJob->jobResCode); + qDebug("QID:0x%" PRIx64 " ctg end to call user cb", pJob->queryId); + taosRemoveRef(gCtgMgmt.jobPool, pJob->refId); return TSDB_CODE_SUCCESS; @@ -822,8 +826,6 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) { _return: - qDebug("QID:0x%" PRIx64 " ctg call user callback with rsp %s", pJob->queryId, tstrerror(code)); - pJob->jobResCode = code; //taosSsleep(2); diff --git a/source/libs/catalog/src/ctgDbg.c b/source/libs/catalog/src/ctgDbg.c index 9195747bee..bd3402dc39 100644 --- a/source/libs/catalog/src/ctgDbg.c +++ b/source/libs/catalog/src/ctgDbg.c @@ -64,7 +64,7 @@ void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) { qDebug("db %d vgInfo:", i); for (int32_t j = 0; j < vgNum; ++j) { SVgroupInfo* pInfo = taosArrayGet(pDb, j); - qDebug("vg %d info: vgId:%d", j, pInfo->vgId); + qDebug("vg :%d info: vgId:%d", j, pInfo->vgId); } } } else { diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 21e78d4925..ad73fe40d2 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -731,7 +731,7 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName *pVgroup = *vgInfo; - ctgDebug("Got tb %s hash vgroup, vgId %d, epNum %d, current %s port %d", tbFullName, vgInfo->vgId, vgInfo->epSet.numOfEps, + ctgDebug("Got tb %s hash vgroup, vgId:%d, epNum %d, current %s port %d", tbFullName, vgInfo->vgId, vgInfo->epSet.numOfEps, vgInfo->epSet.eps[vgInfo->epSet.inUse].fqdn, vgInfo->epSet.eps[vgInfo->epSet.inUse].port); CTG_RET(code); diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 3245fcd16a..51b721f818 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -109,7 +109,7 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 7f70a78b12..a2816209a9 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -223,7 +223,7 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbFName, S "CREATE DATABASE `%s` BUFFER %d CACHELAST %d COMP %d DURATION %dm " "FSYNC %d MAXROWS %d MINROWS %d KEEP %dm,%dm,%dm PAGES %d PAGESIZE %d PRECISION '%s' REPLICA %d " "STRICT %d WAL %d VGROUPS %d SINGLE_STABLE %d", - dbFName, pCfg->buffer, pCfg->cacheLastRow, pCfg->compression, pCfg->daysPerFile, pCfg->fsyncPeriod, + dbFName, pCfg->buffer, pCfg->cacheLast, pCfg->compression, pCfg->daysPerFile, pCfg->fsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2, pCfg->pages, pCfg->pageSize, prec, pCfg->replications, pCfg->strict, pCfg->walLevel, pCfg->numOfVgroups, 1 == pCfg->numOfStables); diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index 2c8fbe9206..f9aba30a46 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -126,4 +126,6 @@ void cleanupQueryTableDataCond(SQueryTableDataCond* pCond); int32_t convertFillType(int32_t mode); +int32_t resultrowComparAsc(const void* p1, const void* p2); + #endif // TDENGINE_QUERYUTIL_H diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 5df653324d..69ba88916a 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -51,13 +51,12 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int #define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData ? 1 : 0) -#define START_TS_COLUMN_INDEX 0 -#define END_TS_COLUMN_INDEX 1 -#define UID_COLUMN_INDEX 2 -#define GROUPID_COLUMN_INDEX UID_COLUMN_INDEX +#define START_TS_COLUMN_INDEX 0 +#define END_TS_COLUMN_INDEX 1 +#define UID_COLUMN_INDEX 2 +#define GROUPID_COLUMN_INDEX UID_COLUMN_INDEX #define DELETE_GROUPID_COLUMN_INDEX 2 - enum { // when this task starts to execute, this status will set TASK_NOT_COMPLETED = 0x1u, @@ -81,8 +80,8 @@ typedef struct SResultInfo { // TODO refactor } SResultInfo; typedef struct STableQueryInfo { - TSKEY lastKey; // last check ts, todo remove it later - SResultRowPosition pos; // current active time window + TSKEY lastKey; // last check ts, todo remove it later + SResultRowPosition pos; // current active time window } STableQueryInfo; typedef struct SLimit { @@ -105,7 +104,7 @@ typedef struct STaskCostInfo { uint64_t loadDataTime; SFileBlockLoadRecorder* pRecoder; - uint64_t elapsedTime; + uint64_t elapsedTime; uint64_t firstStageMergeTime; uint64_t winInfoSize; @@ -118,8 +117,8 @@ typedef struct STaskCostInfo { } STaskCostInfo; typedef struct SOperatorCostInfo { - double openCost; - double totalCost; + double openCost; + double totalCost; } SOperatorCostInfo; struct SOperatorInfo; @@ -139,24 +138,36 @@ typedef struct STaskIdInfo { char* str; } STaskIdInfo; +typedef struct { + STqOffsetVal prepareStatus; // for tmq + STqOffsetVal lastStatus; // for tmq + void* metaBlk; // for tmq fetching meta + SSDataBlock* pullOverBlk; // for streaming + SWalFilterCond cond; + int64_t lastScanUid; +} SStreamTaskInfo; + typedef struct SExecTaskInfo { - STaskIdInfo id; - uint32_t status; - STimeWindow window; - STaskCostInfo cost; - int64_t owner; // if it is in execution - int32_t code; + STaskIdInfo id; + uint32_t status; + STimeWindow window; + STaskCostInfo cost; + int64_t owner; // if it is in execution + int32_t code; + + SStreamTaskInfo streamInfo; + struct { - char *tablename; - char *dbname; - int32_t tversion; - SSchemaWrapper*sw; + char* tablename; + char* dbname; + int32_t tversion; + SSchemaWrapper* sw; } schemaVer; - STableListInfo tableqinfoList; // this is a table list - const char* sql; // query sql string - jmp_buf env; // jump to this position when error happens. - EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] + STableListInfo tableqinfoList; // this is a table list + const char* sql; // query sql string + jmp_buf env; // jump to this position when error happens. + EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] struct SOperatorInfo* pRoot; } SExecTaskInfo; @@ -168,36 +179,36 @@ enum { }; typedef struct SOperatorFpSet { - __optr_open_fn_t _openFn; // DO NOT invoke this function directly - __optr_fn_t getNextFn; - __optr_fn_t getStreamResFn; // execute the aggregate in the stream model, todo remove it - __optr_fn_t cleanupFn; // call this function to release the allocated resources ASAP - __optr_close_fn_t closeFn; - __optr_encode_fn_t encodeResultRow; - __optr_decode_fn_t decodeResultRow; - __optr_explain_fn_t getExplainFn; + __optr_open_fn_t _openFn; // DO NOT invoke this function directly + __optr_fn_t getNextFn; + __optr_fn_t getStreamResFn; // execute the aggregate in the stream model, todo remove it + __optr_fn_t cleanupFn; // call this function to release the allocated resources ASAP + __optr_close_fn_t closeFn; + __optr_encode_fn_t encodeResultRow; + __optr_decode_fn_t decodeResultRow; + __optr_explain_fn_t getExplainFn; } SOperatorFpSet; typedef struct SExprSupp { SExprInfo* pExprInfo; - int32_t numOfExprs; // the number of scalar expression in group operator + int32_t numOfExprs; // the number of scalar expression in group operator SqlFunctionCtx* pCtx; int32_t* rowEntryInfoOffset; // offset value for each row result cell info } SExprSupp; typedef struct SOperatorInfo { - uint8_t operatorType; - bool blocking; // block operator or not - uint8_t status; // denote if current operator is completed - char* name; // name, for debug purpose - void* info; // extension attribution - SExprSupp exprSupp; - SExecTaskInfo* pTaskInfo; - SOperatorCostInfo cost; - SResultInfo resultInfo; - struct SOperatorInfo** pDownstream; // downstram pointer list - int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator - SOperatorFpSet fpSet; + uint8_t operatorType; + bool blocking; // block operator or not + uint8_t status; // denote if current operator is completed + char* name; // name, for debug purpose + void* info; // extension attribution + SExprSupp exprSupp; + SExecTaskInfo* pTaskInfo; + SOperatorCostInfo cost; + SResultInfo resultInfo; + struct SOperatorInfo** pDownstream; // downstram pointer list + int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator + SOperatorFpSet fpSet; } SOperatorInfo; typedef enum { @@ -210,12 +221,12 @@ typedef enum { #define COL_MATCH_FROM_SLOT_ID 0x2 typedef struct SSourceDataInfo { - int32_t index; - SRetrieveTableRsp* pRsp; - uint64_t totalRows; - int32_t code; - EX_SOURCE_STATUS status; - const char* taskId; + int32_t index; + SRetrieveTableRsp* pRsp; + uint64_t totalRows; + int32_t code; + EX_SOURCE_STATUS status; + const char* taskId; } SSourceDataInfo; typedef struct SLoadRemoteDataInfo { @@ -268,9 +279,6 @@ typedef struct STableScanInfo { SScanInfo scanInfo; int32_t scanTimes; SNode* pFilterNode; // filter info, which is push down by optimizer - SqlFunctionCtx* pCtx; // which belongs to the direct upstream operator operator query context,todo: remove this by using SExprSup - int32_t* rowEntryInfoOffset; // todo: remove this by using SExprSup - SExprInfo* pExpr;// todo: remove this by using SExprSup SSDataBlock* pResBlock; SArray* pColMatchInfo; @@ -279,19 +287,17 @@ typedef struct STableScanInfo { int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan int32_t dataBlockLoadFlag; SInterval interval; // if the upstream is an interval operator, the interval info is also kept here to get the time window to check if current data block needs to be loaded. - SSampleExecInfo sample; // sample execution info - int32_t curTWinIdx; int32_t currentGroupId; int32_t currentTable; - uint64_t queryId; // todo remove it - uint64_t taskId; // todo remove it +#if 0 struct { uint64_t uid; int64_t ts; } lastStatus; +#endif int8_t scanMode; int8_t noTable; @@ -325,10 +331,10 @@ typedef enum EStreamScanMode { } EStreamScanMode; typedef struct SCatchSupporter { - SHashObj* pWindowHashTable; // quick locate the window object for each window - SDiskbasedBuf* pDataBuf; // buffer based on blocked-wised disk file - int32_t keySize; - int64_t* pKeyBuf; + SHashObj* pWindowHashTable; // quick locate the window object for each window + SDiskbasedBuf* pDataBuf; // buffer based on blocked-wised disk file + int32_t keySize; + int64_t* pKeyBuf; } SCatchSupporter; typedef struct SStreamAggSupporter { @@ -344,48 +350,48 @@ typedef struct SStreamAggSupporter { typedef struct SessionWindowSupporter { SStreamAggSupporter* pStreamAggSup; - int64_t gap; - uint8_t parentType; + int64_t gap; + uint8_t parentType; } SessionWindowSupporter; typedef struct SStreamScanInfo { - uint64_t tableUid; // queried super table uid - SExprInfo* pPseudoExpr; - int32_t numOfPseudoExpr; - int32_t primaryTsIndex; // primary time stamp slot id - SReadHandle readHandle; - SInterval interval; // if the upstream is an interval operator, the interval info is also kept here. - SArray* pColMatchInfo; // - SNode* pCondition; + uint64_t tableUid; // queried super table uid + SExprInfo* pPseudoExpr; + int32_t numOfPseudoExpr; + int32_t primaryTsIndex; // primary time stamp slot id + SReadHandle readHandle; + SInterval interval; // if the upstream is an interval operator, the interval info is also kept here. + SArray* pColMatchInfo; // + SNode* pCondition; - SArray* pBlockLists; // multiple SSDatablock. - SSDataBlock* pRes; // result SSDataBlock - SSDataBlock* pUpdateRes; // update SSDataBlock - int32_t updateResIndex; - int32_t blockType; // current block type - int32_t validBlockIndex; // Is current data has returned? - uint64_t numOfExec; // execution times - STqReader* tqReader; + SArray* pBlockLists; // multiple SSDatablock. + SSDataBlock* pRes; // result SSDataBlock + SSDataBlock* pUpdateRes; // update SSDataBlock + int32_t updateResIndex; + int32_t blockType; // current block type + int32_t validBlockIndex; // Is current data has returned? + uint64_t numOfExec; // execution times + STqReader* tqReader; - int32_t tsArrayIndex; - SArray* tsArray; - uint64_t groupId; - SUpdateInfo* pUpdateInfo; + int32_t tsArrayIndex; + SArray* tsArray; + uint64_t groupId; + SUpdateInfo* pUpdateInfo; - EStreamScanMode scanMode; - SOperatorInfo* pStreamScanOp; - SOperatorInfo* pTableScanOp; - SArray* childIds; + EStreamScanMode scanMode; + SOperatorInfo* pStreamScanOp; + SOperatorInfo* pTableScanOp; + SArray* childIds; SessionWindowSupporter sessionSup; - bool assignBlockUid; // assign block uid to groupId, temporarily used for generating rollup SMA. - int32_t scanWinIndex; // for state operator - int32_t pullDataResIndex; - SSDataBlock* pPullDataRes; // pull data SSDataBlock - SSDataBlock* pDeleteDataRes; // delete data SSDataBlock - int32_t deleteDataIndex; + bool assignBlockUid; // assign block uid to groupId, temporarily used for generating rollup SMA. + int32_t scanWinIndex; // for state operator + int32_t pullDataResIndex; + SSDataBlock* pPullDataRes; // pull data SSDataBlock + SSDataBlock* pDeleteDataRes; // delete data SSDataBlock + int32_t deleteDataIndex; // status for tmq - //SSchemaWrapper schema; + // SSchemaWrapper schema; STqOffset offset; } SStreamScanInfo; @@ -445,7 +451,6 @@ typedef struct SIntervalAggOperatorInfo { int32_t primaryTsIndex; // primary time stamp slot id from result of downstream operator. STimeWindow win; // query time range bool timeWindowInterpo; // interpolation needed or not - char** pRow; // previous row/tuple of already processed datablock SArray* pInterpCols; // interpolation columns int32_t order; // current SSDataBlock scan order EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] @@ -461,11 +466,22 @@ typedef struct SIntervalAggOperatorInfo { SNode *pCondition; } SIntervalAggOperatorInfo; +typedef struct SMergeAlignedIntervalAggOperatorInfo { + SIntervalAggOperatorInfo *intervalAggOperatorInfo; + + bool hasGroupId; + uint64_t groupId; + SSDataBlock* prefetchedBlock; + bool inputBlocksFinished; + + SNode* pCondition; +} SMergeAlignedIntervalAggOperatorInfo; + typedef struct SStreamFinalIntervalOperatorInfo { // SOptrBasicInfo should be first, SAggSupporter should be second for stream encode SOptrBasicInfo binfo; // basic info SAggSupporter aggSup; // aggregate supporter - + SExprSupp scalarSupp; // supporter for perform scalar function SGroupResInfo groupResInfo; // multiple results build supporter SInterval interval; // interval info int32_t primaryTsIndex; // primary time stamp slot id from result of downstream operator. @@ -524,6 +540,9 @@ typedef struct SIndefOperatorInfo { SArray* pPseudoColInfo; SExprSupp scalarSup; SNode* pCondition; + uint64_t groupId; + + SSDataBlock* pNextGroupRes; } SIndefOperatorInfo; typedef struct SFillOperatorInfo { @@ -535,6 +554,8 @@ typedef struct SFillOperatorInfo { bool multigroupResult; STimeWindow win; SNode* pCondition; + SArray* pColMatchColInfo; + int32_t primaryTsCol; } SFillOperatorInfo; typedef struct SGroupbyOperatorInfo { @@ -595,7 +616,7 @@ typedef struct SSessionAggOperatorInfo { int64_t gap; // session window gap int32_t tsSlotId; // primary timestamp slot id STimeWindowAggSupp twAggSup; - SNode *pCondition; + const SNode* pCondition; } SSessionAggOperatorInfo; typedef struct SResultWindowInfo { @@ -613,6 +634,7 @@ typedef struct SStateWindowInfo { typedef struct SStreamSessionAggOperatorInfo { SOptrBasicInfo binfo; SStreamAggSupporter streamAggSup; + SExprSupp scalarSupp; // supporter for perform scalar function SGroupResInfo groupResInfo; int64_t gap; // session window gap int32_t primaryTsIndex; // primary timestamp slot id @@ -657,17 +679,18 @@ typedef struct SStateWindowOperatorInfo { int32_t tsSlotId; // primary timestamp column slot id STimeWindowAggSupp twAggSup; // bool reptScan; - const SNode *pCondition; + const SNode* pCondition; } SStateWindowOperatorInfo; typedef struct SStreamStateAggOperatorInfo { SOptrBasicInfo binfo; SStreamAggSupporter streamAggSup; + SExprSupp scalarSupp; // supporter for perform scalar function SGroupResInfo groupResInfo; int32_t primaryTsIndex; // primary timestamp slot id int32_t order; // current SSDataBlock scan order STimeWindowAggSupp twAggSup; - SColumn stateCol; // start row index + SColumn stateCol; SqlFunctionCtx* pDummyCtx; // for combine SSDataBlock* pDelRes; SHashObj* pSeDeleted; @@ -756,6 +779,8 @@ int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLo int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList); void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win); +STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order); + int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t *order, int32_t* scanFlag); int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz); @@ -893,7 +918,7 @@ int32_t aggDecodeResultRow(SOperatorInfo* pOperator, char* result); int32_t aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* length); STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval, - int32_t precision, STimeWindow* win); + int32_t order); int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimaryColumn, int32_t startPos, TSKEY ekey, __block_search_fn_t searchFn, STableQueryInfo* item, int32_t order); int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); @@ -909,7 +934,6 @@ int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pStartTs, TSKEY* pEndTs, int32_t rows, int32_t start, int64_t gap, SHashObj* pStDeleted); bool functionNeedToExecute(SqlFunctionCtx* pCtx); -int32_t compareTimeWindow(const void* p1, const void* p2, const void* param); int32_t finalizeResultRowIntoResultDataBlock(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, int32_t numOfExprs, const int32_t* rowCellOffset, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 4e5458e620..2da8811e5e 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include #include "function.h" #include "functionMgt.h" #include "index.h" @@ -76,7 +77,7 @@ void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo) { pGroupResInfo->index = 0; } -static int32_t resultrowComparAsc(const void* p1, const void* p2) { +int32_t resultrowComparAsc(const void* p1, const void* p2) { SResKeyPos* pp1 = *(SResKeyPos**)p1; SResKeyPos* pp2 = *(SResKeyPos**)p2; @@ -323,12 +324,12 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, if (code == TSDB_CODE_INDEX_REBUILDING) { code = vnodeGetAllTableList(pVnode, tableUid, pListInfo->pTableList); } else if (code != TSDB_CODE_SUCCESS) { - qError("failed to get tableIds, reason: %s, suid: %" PRIu64 "", tstrerror(code), tableUid); + qError("failed to get tableIds, reason:%s, suid:%" PRIu64, tstrerror(code), tableUid); taosArrayDestroy(res); terrno = code; return code; } else { - qDebug("sucess to get tableIds, size: %d, suid: %" PRIu64 "", (int)taosArrayGetSize(res), tableUid); + qDebug("success to get tableIds, size:%d, suid:%" PRIu64, (int)taosArrayGetSize(res), tableUid); } for (int i = 0; i < taosArrayGetSize(res); i++) { @@ -341,7 +342,7 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, } if (code != TSDB_CODE_SUCCESS) { - qError("failed to get tableIds, reason: %s, suid: %" PRIu64 "", tstrerror(code), tableUid); + qError("failed to get tableIds, reason:%s, suid:%" PRIu64, tstrerror(code), tableUid); terrno = code; return code; } @@ -748,11 +749,12 @@ SInterval extractIntervalInfo(const STableScanPhysiNode* pTableScanNode) { SColumn extractColumnFromColumnNode(SColumnNode* pColNode) { SColumn c = {0}; - c.slotId = pColNode->slotId; - c.colId = pColNode->colId; - c.type = pColNode->node.resType.type; - c.bytes = pColNode->node.resType.bytes; - c.scale = pColNode->node.resType.scale; + + c.slotId = pColNode->slotId; + c.colId = pColNode->colId; + c.type = pColNode->node.resType.type; + c.bytes = pColNode->node.resType.bytes; + c.scale = pColNode->node.resType.scale; c.precision = pColNode->node.resType.precision; return c; } @@ -768,12 +770,11 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi // pCond->twindow = pTableScanNode->scanRange; // TODO: get it from stable scan node - pCond->numOfTWindows = 1; - pCond->twindows = taosMemoryCalloc(pCond->numOfTWindows, sizeof(STimeWindow)); - pCond->twindows[0] = pTableScanNode->scanRange; - pCond->suid = pTableScanNode->scan.suid; - - pCond->type = BLOCK_LOAD_OFFSET_ORDER; + pCond->twindows = pTableScanNode->scanRange; + pCond->suid = pTableScanNode->scan.suid; + pCond->type = BLOCK_LOAD_OFFSET_ORDER; + pCond->startVersion = -1; + pCond->endVersion = -1; // pCond->type = pTableScanNode->scanFlag; int32_t j = 0; @@ -823,3 +824,87 @@ int32_t convertFillType(int32_t mode) { return type; } + +static void getInitialStartTimeWindow(SInterval* pInterval, TSKEY ts, STimeWindow* w, bool ascQuery) { + if (ascQuery) { + getAlignQueryTimeWindow(pInterval, pInterval->precision, ts, w); + } else { + // the start position of the first time window in the endpoint that spreads beyond the queried last timestamp + getAlignQueryTimeWindow(pInterval, pInterval->precision, ts, w); + + int64_t key = w->skey; + while (key < ts) { // moving towards end + key = taosTimeAdd(key, pInterval->sliding, pInterval->slidingUnit, pInterval->precision); + if (key >= ts) { + break; + } + + w->skey = key; + } + } +} + +static STimeWindow doCalculateTimeWindow(int64_t ts, SInterval* pInterval) { + STimeWindow w = {0}; + + if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') { + w.skey = taosTimeTruncate(ts, pInterval, pInterval->precision); + w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; + } else { + int64_t st = w.skey; + + if (st > ts) { + st -= ((st - ts + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; + } + + int64_t et = st + pInterval->interval - 1; + if (et < ts) { + st += ((ts - et + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; + } + + w.skey = st; + w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; + } + + return w; +} + +STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order) { + int32_t factor = (order == TSDB_ORDER_ASC)? -1:1; + + STimeWindow win = *pWindow; + STimeWindow save = win; + while(win.skey <= ts && win.ekey >= ts) { + save = win; + win.skey = taosTimeAdd(win.skey, factor * pInterval->sliding, pInterval->slidingUnit, pInterval->precision); + win.ekey = taosTimeAdd(win.ekey, factor * pInterval->sliding, pInterval->slidingUnit, pInterval->precision); + } + + return save; +} + +// get the correct time window according to the handled timestamp +STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval, + int32_t order) { + STimeWindow w = {0}; + if (pResultRowInfo->cur.pageId == -1) { // the first window, from the previous stored value + getInitialStartTimeWindow(pInterval, ts, &w, (order == TSDB_ORDER_ASC)); + w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; + return w; + } + + w = getResultRowByPos(pBuf, &pResultRowInfo->cur)->win; + + // in case of typical time window, we can calculate time window directly. + if (w.skey > ts || w.ekey < ts) { + w = doCalculateTimeWindow(ts, pInterval); + } + + if (pInterval->interval != pInterval->sliding) { + // it is an sliding window query, in which sliding value is not equalled to + // interval value, and we need to find the first qualified time window. + w = getFirstQualifiedTimeWindow(ts, &w, pInterval, order); + } + + return w; +} \ No newline at end of file diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index a83565cbe0..9f6b12c13a 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -60,9 +60,8 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu taosArrayAddAll(p->pDataBlock, pDataBlock->pDataBlock); taosArrayPush(pInfo->pBlockLists, &p); } - } else if (type == STREAM_INPUT__DATA_SCAN) { - // do nothing - ASSERT(pInfo->blockType == STREAM_INPUT__DATA_SCAN); + /*} else if (type == STREAM_INPUT__TABLE_SCAN) {*/ + /*ASSERT(pInfo->blockType == STREAM_INPUT__TABLE_SCAN);*/ } else { ASSERT(0); } @@ -71,13 +70,15 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu } } +#if 0 int32_t qStreamScanSnapshot(qTaskInfo_t tinfo) { if (tinfo == NULL) { return TSDB_CODE_QRY_APP_ERROR; } SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; - return doSetStreamBlock(pTaskInfo->pRoot, NULL, 0, STREAM_INPUT__DATA_SCAN, 0, NULL); + return doSetStreamBlock(pTaskInfo->pRoot, NULL, 0, STREAM_INPUT__TABLE_SCAN, 0, NULL); } +#endif int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type, bool assignUid) { return qSetMultiStreamInput(tinfo, input, 1, type, assignUid); @@ -184,7 +185,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo return code; } -int32_t qGetQueriedTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, +int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, int32_t* tversion) { ASSERT(tinfo != NULL && dbName != NULL && tableName != NULL); SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; diff --git a/source/libs/executor/src/executorMain.c b/source/libs/executor/src/executorMain.c index baf667d618..b30800680b 100644 --- a/source/libs/executor/src/executorMain.c +++ b/source/libs/executor/src/executorMain.c @@ -267,7 +267,91 @@ const STqOffset* qExtractStatusFromStreamScanner(void* scanner) { return &pInfo->offset; } -int32_t qStreamPrepareScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts) { +void* qStreamExtractMetaMsg(qTaskInfo_t tinfo) { + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; + ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM); + return pTaskInfo->streamInfo.metaBlk; +} + +int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) { + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; + ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM); + memcpy(pOffset, &pTaskInfo->streamInfo.lastStatus, sizeof(STqOffsetVal)); + return 0; +} + +int32_t qStreamPrepareScan(qTaskInfo_t tinfo, const STqOffsetVal* pOffset) { + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; + SOperatorInfo* pOperator = pTaskInfo->pRoot; + ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM); + pTaskInfo->streamInfo.prepareStatus = *pOffset; + // TODO: optimize + /*if (pTaskInfo->streamInfo.lastStatus.type != pOffset->type ||*/ + /*pTaskInfo->streamInfo.prepareStatus.version != pTaskInfo->streamInfo.lastStatus.version) {*/ + while (1) { + uint8_t type = pOperator->operatorType; + pOperator->status = OP_OPENED; + if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { + SStreamScanInfo* pInfo = pOperator->info; + if (pOffset->type == TMQ_OFFSET__LOG) { + if (tqSeekVer(pInfo->tqReader, pOffset->version) < 0) { + return -1; + } + ASSERT(pInfo->tqReader->pWalReader->curVersion == pOffset->version); + } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) { + /*pInfo->blockType = STREAM_INPUT__TABLE_SCAN;*/ + int64_t uid = pOffset->uid; + int64_t ts = pOffset->ts; + + if (uid == 0) { + if (taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList) != 0) { + STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, 0); + uid = pTableInfo->uid; + ts = INT64_MIN; + } + } + if (pTaskInfo->streamInfo.lastStatus.type != TMQ_OFFSET__SNAPSHOT_DATA || + pTaskInfo->streamInfo.lastStatus.uid != uid || pTaskInfo->streamInfo.lastStatus.ts != ts) { + STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info; + int32_t tableSz = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList); + bool found = false; + for (int32_t i = 0; i < tableSz; i++) { + STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, i); + if (pTableInfo->uid == uid) { + found = true; + pTableScanInfo->currentTable = i; + } + } + + // TODO after dropping table, table may be not found + ASSERT(found); + + tsdbSetTableId(pTableScanInfo->dataReader, uid); + int64_t oldSkey = pTableScanInfo->cond.twindows.skey; + pTableScanInfo->cond.twindows.skey = ts + 1; + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); + pTableScanInfo->cond.twindows.skey = oldSkey; + pTableScanInfo->scanTimes = 0; + + qDebug("tsdb reader offset seek to uid %ld ts %ld, table cur set to %d , all table num %d", uid, ts, + pTableScanInfo->currentTable, tableSz); + } + + } else { + ASSERT(0); + } + return 0; + } else { + ASSERT(pOperator->numOfDownstream == 1); + pOperator = pOperator->pDownstream[0]; + } + } + /*}*/ + return 0; +} + +#if 0 +int32_t qStreamPrepareTsdbScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; if (uid == 0) { @@ -286,3 +370,4 @@ int32_t qGetStreamScanStatus(qTaskInfo_t tinfo, uint64_t* uid, int64_t* ts) { return doGetScanStatus(pTaskInfo->pRoot, uid, ts); } +#endif diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index b638fb82e1..c4cbaf0987 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include #include "filter.h" #include "function.h" #include "functionMgt.h" @@ -544,9 +545,7 @@ static int32_t doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunct if (pCtx[k].fpSet.process == NULL) { continue; } -#ifdef BUF_PAGE_DEBUG - qDebug("page_process"); -#endif + int32_t code = pCtx[k].fpSet.process(&pCtx[k]); if (code != TSDB_CODE_SUCCESS) { qError("%s aggregate function error happens, code: %s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code)); @@ -570,26 +569,27 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc setPseudoOutputColInfo(pResult, pCtx, pPseudoList); pResult->info.groupId = pSrcBlock->info.groupId; - // if the source equals to the destination, it is to create a new column as the result of scalar function or some - // operators. + // if the source equals to the destination, it is to create a new column as the result of scalar + // function or some operators. bool createNewColModel = (pResult == pSrcBlock); int32_t numOfRows = 0; for (int32_t k = 0; k < numOfOutput; ++k) { - int32_t outputSlotId = pExpr[k].base.resSchema.slotId; - SqlFunctionCtx* pfCtx = &pCtx[k]; + int32_t outputSlotId = pExpr[k].base.resSchema.slotId; + SqlFunctionCtx* pfCtx = &pCtx[k]; + SInputColumnInfoData* pInputData = &pfCtx->input; if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId); if (pResult->info.rows > 0 && !createNewColModel) { - colDataMergeCol(pColInfoData, pResult->info.rows, &pResult->info.capacity, pfCtx->input.pData[0], - pfCtx->input.numOfRows); + colDataMergeCol(pColInfoData, pResult->info.rows, &pResult->info.capacity, pInputData->pData[0], + pInputData->numOfRows); } else { - colDataAssign(pColInfoData, pfCtx->input.pData[0], pfCtx->input.numOfRows, &pResult->info); + colDataAssign(pColInfoData, pInputData->pData[0], pInputData->numOfRows, &pResult->info); } - numOfRows = pfCtx->input.numOfRows; + numOfRows = pInputData->numOfRows; } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_VALUE) { SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId); @@ -622,14 +622,12 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc numOfRows = dest.numOfRows; taosArrayDestroy(pBlockList); } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_FUNCTION) { - ASSERT(!fmIsAggFunc(pfCtx->functionId)); - // _rowts/_c0, not tbname column if (fmIsPseudoColumnFunc(pfCtx->functionId) && (!fmIsScanPseudoColumnFunc(pfCtx->functionId))) { // do nothing } else if (fmIsIndefiniteRowsFunc(pfCtx->functionId)) { - SResultRowEntryInfo* pResInfo = GET_RES_INFO(&pCtx[k]); - pfCtx->fpSet.init(&pCtx[k], pResInfo); + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pfCtx); + pfCtx->fpSet.init(pfCtx, pResInfo); pfCtx->pOutput = taosArrayGet(pResult->pDataBlock, outputSlotId); pfCtx->offset = createNewColModel ? 0 : pResult->info.rows; // set the start offset @@ -641,6 +639,23 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc } numOfRows = pfCtx->fpSet.process(pfCtx); + } else if (fmIsAggFunc(pfCtx->functionId)) { + // _group_key function for "partition by tbname" + csum(col_name) query + SColumnInfoData* pOutput = taosArrayGet(pResult->pDataBlock, outputSlotId); + int32_t slotId = pfCtx->param[0].pCol->slotId; + + // todo handle the json tag + SColumnInfoData* pInput = taosArrayGet(pSrcBlock->pDataBlock, slotId); + for (int32_t f = 0; f < pSrcBlock->info.rows; ++f) { + bool isNull = colDataIsNull_s(pInput, f); + if (isNull) { + colDataAppendNULL(pOutput, pResult->info.rows + f); + } else { + char* data = colDataGetData(pInput, f); + colDataAppend(pOutput, pResult->info.rows + f, data, isNull); + } + } + } else { SArray* pBlockList = taosArrayInit(4, POINTER_BYTES); taosArrayPush(pBlockList, &pSrcBlock); @@ -674,25 +689,6 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc return TSDB_CODE_SUCCESS; } -static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { - if (IS_VAR_DATA_TYPE(type)) { - // todo disable this - - // if (pResultRow->key == NULL) { - // pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); - // varDataCopy(pResultRow->key, pData); - // } else { - // ASSERT(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); - // } - } else { - int64_t v = -1; - GET_TYPED_DATA(v, int64_t, type, pData); - - pResultRow->win.skey = v; - pResultRow->win.ekey = v; - } -} - bool functionNeedToExecute(SqlFunctionCtx* pCtx) { struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); @@ -1038,6 +1034,7 @@ static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockI #endif static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock) { +#if 0 SqlFunctionCtx* pCtx = pTableScanInfo->pCtx; uint32_t status = BLK_DATA_NOT_LOAD; @@ -1059,6 +1056,8 @@ static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSData } return status; +#endif + return 0; } int32_t loadDataBlockOnDemand(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, @@ -2443,7 +2442,6 @@ _error: doDestroyExchangeOperatorInfo(pInfo); } - taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; @@ -2463,7 +2461,7 @@ static void destroySortedMergeOperatorInfo(void* param, int32_t numOfOutput) { blockDataDestroy(pInfo->binfo.pRes); cleanupAggSup(&pInfo->aggSup); - + taosMemoryFreeClear(param); } @@ -2844,7 +2842,7 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan } } } - +#if 0 int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) { uint8_t type = pOperator->operatorType; @@ -2852,7 +2850,7 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) { if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { SStreamScanInfo* pScanInfo = pOperator->info; - pScanInfo->blockType = STREAM_INPUT__DATA_SCAN; + pScanInfo->blockType = STREAM_INPUT__TABLE_SCAN; pScanInfo->pTableScanOp->status = OP_OPENED; @@ -2887,14 +2885,13 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) { ASSERT(found); tsdbSetTableId(pInfo->dataReader, uid); - int64_t oldSkey = pInfo->cond.twindows[0].skey; - pInfo->cond.twindows[0].skey = ts + 1; - tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); - pInfo->cond.twindows[0].skey = oldSkey; + int64_t oldSkey = pInfo->cond.twindows.skey; + pInfo->cond.twindows.skey = ts + 1; + tsdbReaderReset(pInfo->dataReader, &pInfo->cond); + pInfo->cond.twindows.skey = oldSkey; pInfo->scanTimes = 0; - pInfo->curTWinIdx = 0; - qDebug("tsdb reader offset seek to uid %ld ts %ld, table cur set to %d , all table num %d", uid, ts, + qDebug("tsdb reader offset seek to uid %" PRId64 " ts %" PRId64 ", table cur set to %d , all table num %d", uid, ts, pInfo->currentTable, tableSz); } @@ -2930,6 +2927,7 @@ int32_t doGetScanStatus(SOperatorInfo* pOperator, uint64_t* uid, int64_t* ts) { return TSDB_CODE_SUCCESS; } +#endif // this is a blocking operator static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { @@ -3287,7 +3285,10 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { // The downstream exec may change the value of the newgroup, so use a local variable instead. SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); if (pBlock == NULL) { + // TODO optimize + /*if (pTaskInfo->execModel != OPTR_EXEC_MODEL_STREAM) {*/ doSetOperatorCompleted(pOperator); + /*}*/ break; } if (pBlock->info.type == STREAM_RETRIEVE) { @@ -3338,8 +3339,8 @@ static void doHandleRemainBlockForNewGroupImpl(SFillOperatorInfo* pInfo, SResult SExecTaskInfo* pTaskInfo) { pInfo->totalInputRows = pInfo->existNewGroupBlock->info.rows; - int64_t ekey = Q_STATUS_EQUAL(pTaskInfo->status, TASK_COMPLETED) ? pInfo->win.ekey - : pInfo->existNewGroupBlock->info.window.ekey; + int64_t ekey = + Q_STATUS_EQUAL(pTaskInfo->status, TASK_COMPLETED) ? pInfo->win.ekey : pInfo->existNewGroupBlock->info.window.ekey; taosResetFillInfo(pInfo->pFillInfo, getFillInfoStart(pInfo->pFillInfo)); taosFillSetStartInfo(pInfo->pFillInfo, pInfo->existNewGroupBlock->info.rows, ekey); @@ -3390,6 +3391,8 @@ static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) { assert(pBlock != NULL); } + blockDataUpdateTsWindow(pBlock, pInfo->primaryTsCol); + if (*newgroup && pInfo->totalInputRows > 0) { // there are already processed current group data block pInfo->existNewGroupBlock = pBlock; *newgroup = false; @@ -3675,14 +3678,14 @@ void cleanupBasicInfo(SOptrBasicInfo* pInfo) { void destroyBasicOperatorInfo(void* param, int32_t numOfOutput) { SOptrBasicInfo* pInfo = (SOptrBasicInfo*)param; cleanupBasicInfo(pInfo); - + taosMemoryFreeClear(param); } void destroyAggOperatorInfo(void* param, int32_t numOfOutput) { SAggOperatorInfo* pInfo = (SAggOperatorInfo*)param; - cleanupBasicInfo(&pInfo->binfo); - + cleanupBasicInfo(&pInfo->binfo); + taosMemoryFreeClear(param); } @@ -3691,7 +3694,7 @@ void destroySFillOperatorInfo(void* param, int32_t numOfOutput) { pInfo->pFillInfo = taosDestroyFillInfo(pInfo->pFillInfo); pInfo->pRes = blockDataDestroy(pInfo->pRes); taosMemoryFreeClear(pInfo->p); - + taosMemoryFreeClear(param); } @@ -3703,7 +3706,7 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) { cleanupBasicInfo(&pInfo->binfo); cleanupAggSup(&pInfo->aggSup); taosArrayDestroy(pInfo->pPseudoColInfo); - + taosMemoryFreeClear(param); } @@ -3721,7 +3724,7 @@ static void destroyIndefinitOperatorInfo(void* param, int32_t numOfOutput) { taosArrayDestroy(pInfo->pPseudoColInfo); cleanupAggSup(&pInfo->aggSup); cleanupExprSupp(&pInfo->scalarSup); - + taosMemoryFreeClear(param); } @@ -3740,7 +3743,7 @@ void doDestroyExchangeOperatorInfo(void* param) { } tsem_destroy(&pExInfo->ready); - + taosMemoryFreeClear(param); } @@ -3818,6 +3821,41 @@ _error: return NULL; } +static void doHandleDataBlock(SOperatorInfo* pOperator, SSDataBlock* pBlock, SOperatorInfo* downstream, + SExecTaskInfo* pTaskInfo) { + int32_t order = 0; + int32_t scanFlag = 0; + + SIndefOperatorInfo* pIndefInfo = pOperator->info; + SOptrBasicInfo* pInfo = &pIndefInfo->binfo; + SExprSupp* pSup = &pOperator->exprSupp; + + // the pDataBlock are always the same one, no need to call this again + int32_t code = getTableScanInfo(downstream, &order, &scanFlag); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + + // there is an scalar expression that needs to be calculated before apply the group aggregation. + SExprSupp* pScalarSup = &pIndefInfo->scalarSup; + if (pScalarSup->pExprInfo != NULL) { + code = projectApplyFunctions(pScalarSup->pExprInfo, pBlock, pBlock, pScalarSup->pCtx, pScalarSup->numOfExprs, + pIndefInfo->pPseudoColInfo); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + } + + setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, false); + blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); + + code = projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, + pIndefInfo->pPseudoColInfo); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } +} + static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { SIndefOperatorInfo* pIndefInfo = pOperator->info; SOptrBasicInfo* pInfo = &pIndefInfo->binfo; @@ -3832,8 +3870,6 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { } int64_t st = 0; - int32_t order = 0; - int32_t scanFlag = 0; if (pOperator->cost.openCost == 0) { st = taosGetTimestampUs(); @@ -3842,41 +3878,53 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { - // The downstream exec may change the value of the newgroup, so use a local variable instead. - SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); - if (pBlock == NULL) { - doSetOperatorCompleted(pOperator); - break; + // here we need to handle the existsed group results + if (pIndefInfo->pNextGroupRes != NULL) { // todo extract method + for (int32_t k = 0; k < pSup->numOfExprs; ++k) { + SqlFunctionCtx* pCtx = &pSup->pCtx[k]; + + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + pResInfo->initialized = false; + pCtx->pOutput = NULL; + } + + doHandleDataBlock(pOperator, pIndefInfo->pNextGroupRes, downstream, pTaskInfo); + pIndefInfo->pNextGroupRes = NULL; } - // the pDataBlock are always the same one, no need to call this again - int32_t code = getTableScanInfo(pOperator->pDownstream[0], &order, &scanFlag); - if (code != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, code); - } + if (pInfo->pRes->info.rows < pOperator->resultInfo.threshold) { + while (1) { + // The downstream exec may change the value of the newgroup, so use a local variable instead. + SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); + if (pBlock == NULL) { + doSetOperatorCompleted(pOperator); + break; + } - // there is an scalar expression that needs to be calculated before apply the group aggregation. - SExprSupp* pScalarSup = &pIndefInfo->scalarSup; - if (pScalarSup->pExprInfo != NULL) { - code = projectApplyFunctions(pScalarSup->pExprInfo, pBlock, pBlock, pScalarSup->pCtx, pScalarSup->numOfExprs, - pIndefInfo->pPseudoColInfo); - if (code != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, code); + if (pIndefInfo->groupId == 0 && pBlock->info.groupId != 0) { + pIndefInfo->groupId = pBlock->info.groupId; // this is the initial group result + } else { + if (pIndefInfo->groupId != pBlock->info.groupId) { // reset output buffer and computing status + pIndefInfo->groupId = pBlock->info.groupId; + pIndefInfo->pNextGroupRes = pBlock; + break; + } + } + + doHandleDataBlock(pOperator, pBlock, downstream, pTaskInfo); + if (pInfo->pRes->info.rows >= pOperator->resultInfo.threshold) { + break; + } } } - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, false); - blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); - - code = projectApplyFunctions(pOperator->exprSupp.pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, - pOperator->exprSupp.numOfExprs, pIndefInfo->pPseudoColInfo); - if (code != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, code); + doFilter(pIndefInfo->pCondition, pInfo->pRes); + size_t rows = pInfo->pRes->info.rows; + if (rows >= 0) { + break; } } - doFilter(pIndefInfo->pCondition, pInfo->pRes); - size_t rows = pInfo->pRes->info.rows; pOperator->resultInfo.totalRows += rows; @@ -3921,24 +3969,23 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy if (numOfRows * pResBlock->info.rowSize > TWOMB) { numOfRows = TWOMB / pResBlock->info.rowSize; } + initResultSizeInfo(pOperator, numOfRows); - initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfExpr, keyBufSize, pTaskInfo->id.str); + initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfExpr, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); setFunctionResultOutput(pOperator, &pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfExpr); pInfo->binfo.pRes = pResBlock; - pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pSup->pCtx, numOfExpr); pInfo->pCondition = pPhyNode->node.pConditions; + pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pSup->pCtx, numOfExpr); pOperator->name = "IndefinitOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC; pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->exprSupp.numOfExprs = numOfExpr; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, NULL, @@ -3964,12 +4011,13 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t STimeWindow w = TSWINDOW_INITIALIZER; getAlignQueryTimeWindow(pInterval, pInterval->precision, win.skey, &w); + w = getFirstQualifiedTimeWindow(win.skey, &w, pInterval, TSDB_ORDER_ASC); int32_t order = TSDB_ORDER_ASC; pInfo->pFillInfo = taosCreateFillInfo(order, w.skey, 0, capacity, numOfCols, pInterval, fillType, pColInfo, id); pInfo->win = win; - pInfo->p = taosMemoryCalloc(numOfCols, POINTER_BYTES); + pInfo->p = taosMemoryCalloc(numOfCols, POINTER_BYTES); if (pInfo->pFillInfo == NULL || pInfo->p == NULL) { taosMemoryFree(pInfo->pFillInfo); taosMemoryFree(pInfo->p); @@ -3990,11 +4038,20 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* int32_t num = 0; SSDataBlock* pResBlock = createResDataBlock(pPhyFillNode->node.pOutputDataBlockDesc); SExprInfo* pExprInfo = createExprInfo(pPhyFillNode->pTargets, NULL, &num); - SInterval* pInterval = &((SIntervalAggOperatorInfo*)downstream->info)->interval; - int32_t type = convertFillType(pPhyFillNode->mode); + SInterval* pInterval = + QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == downstream->operatorType + ? &((SMergeAlignedIntervalAggOperatorInfo*)downstream->info)->intervalAggOperatorInfo->interval + : &((SIntervalAggOperatorInfo*)downstream->info)->interval; + + int32_t type = convertFillType(pPhyFillNode->mode); SResultInfo* pResultInfo = &pOperator->resultInfo; initResultSizeInfo(pOperator, 4096); + pInfo->primaryTsCol = ((SColumnNode*)pPhyFillNode->pWStartTs)->slotId; + + int32_t numOfOutputCols = 0; + SArray* pColMatchColInfo = extractColMatchInfo(pPhyFillNode->pTargets, pPhyFillNode->node.pOutputDataBlockDesc, + &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); int32_t code = initFillInfo(pInfo, pExprInfo, num, (SNodeListNode*)pPhyFillNode->pValues, pPhyFillNode->timeRange, pResultInfo->capacity, pTaskInfo->id.str, pInterval, type); @@ -4005,6 +4062,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pInfo->pRes = pResBlock; pInfo->multigroupResult = multigroupResult; pInfo->pCondition = pPhyFillNode->node.pConditions; + pInfo->pColMatchColInfo = pColMatchColInfo; pOperator->name = "FillOperator"; pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; @@ -4047,7 +4105,7 @@ static STsdbReader* doCreateDataReader(STableScanPhysiNode* pTableScanNode, SRea static SArray* extractColumnInfo(SNodeList* pNodeList); -int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskInfo* pTaskInfo) { +int32_t extractTableSchemaInfo(SReadHandle* pHandle, uint64_t uid, SExecTaskInfo* pTaskInfo) { SMetaReader mr = {0}; metaReaderInit(&mr, pHandle->meta, 0); int32_t code = metaGetTableEntryByUid(&mr, uid); @@ -4062,6 +4120,8 @@ int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskI pTaskInfo->schemaVer.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow); pTaskInfo->schemaVer.tversion = mr.me.stbEntry.schemaTag.version; } else if (mr.me.type == TSDB_CHILD_TABLE) { + tDecoderClear(&mr.coder); + tb_uid_t suid = mr.me.ctbEntry.suid; metaGetTableEntryByUid(&mr, suid); pTaskInfo->schemaVer.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow); @@ -4071,10 +4131,20 @@ int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskI } metaReaderClear(&mr); - return TSDB_CODE_SUCCESS; } +static void cleanupTableSchemaInfo(SExecTaskInfo* pTaskInfo) { + taosMemoryFreeClear(pTaskInfo->schemaVer.dbname); + if (pTaskInfo->schemaVer.sw == NULL) { + return; + } + + taosMemoryFree(pTaskInfo->schemaVer.sw->pSchema); + taosMemoryFree(pTaskInfo->schemaVer.sw); + taosMemoryFree(pTaskInfo->schemaVer.tablename); +} + static int32_t sortTableGroup(STableListInfo* pTableListInfo, int32_t groupNum) { taosArrayClear(pTableListInfo->pGroupList); SArray* sortSupport = taosArrayInit(groupNum, sizeof(uint64_t)); @@ -4248,7 +4318,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo return NULL; } - code = extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo); + code = extractTableSchemaInfo(pHandle, pTableScanNode->scan.uid, pTaskInfo); if (code) { pTaskInfo->code = terrno; return NULL; @@ -4266,7 +4336,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pTaskInfo->code = code; return NULL; } - code = extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo); + code = extractTableSchemaInfo(pHandle, pTableScanNode->scan.uid, pTaskInfo); if (code) { pTaskInfo->code = terrno; return NULL; @@ -4344,9 +4414,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo cond.colList->type = TSDB_DATA_TYPE_TIMESTAMP; cond.colList->bytes = sizeof(TSKEY); - cond.numOfTWindows = 1; - cond.twindows = taosMemoryCalloc(1, sizeof(STimeWindow)); - cond.twindows[0] = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; + cond.twindows = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; cond.suid = pBlockNode->suid; cond.type = BLOCK_LOAD_OFFSET_ORDER; } @@ -4365,7 +4433,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo // return NULL; // } - int32_t code = extractTableSchemaVersion(pHandle, pScanNode->uid, pTaskInfo); + int32_t code = extractTableSchemaInfo(pHandle, pScanNode->uid, pTaskInfo); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; return NULL; @@ -4462,7 +4530,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo .precision = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->node.resType.precision}; int32_t tsSlotId = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; - pOptr = createMergeAlignedIntervalOperatorInfo(ops[0], pExprInfo, num, pResBlock, &interval, tsSlotId, pPhyNode->pConditions, pTaskInfo); + pOptr = createMergeAlignedIntervalOperatorInfo(ops[0], pExprInfo, num, pResBlock, &interval, tsSlotId, + pPhyNode->pConditions, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL == type) { SMergeIntervalPhysiNode* pIntervalPhyNode = (SMergeIntervalPhysiNode*)pPhyNode; @@ -4501,8 +4570,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); int32_t tsSlotId = ((SColumnNode*)pSessionNode->window.pTspk)->slotId; - pOptr = - createSessionAggOperatorInfo(ops[0], pExprInfo, num, pResBlock, pSessionNode->gap, tsSlotId, &as, pPhyNode->pConditions, pTaskInfo); + pOptr = createSessionAggOperatorInfo(ops[0], pExprInfo, num, pResBlock, pSessionNode->gap, tsSlotId, &as, + pPhyNode->pConditions, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION == type) { pOptr = createStreamSessionAggOperatorInfo(ops[0], pPhyNode, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION == type) { @@ -4524,7 +4593,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SColumnNode* pColNode = (SColumnNode*)((STargetNode*)pStateNode->pStateKey)->pExpr; SColumn col = extractColumnFromColumnNode(pColNode); - pOptr = createStatewindowOperatorInfo(ops[0], pExprInfo, num, pResBlock, &as, tsSlotId, &col, pPhyNode->pConditions, pTaskInfo); + pOptr = createStatewindowOperatorInfo(ops[0], pExprInfo, num, pResBlock, &as, tsSlotId, &col, pPhyNode->pConditions, + pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE == type) { pOptr = createStreamStateAggOperatorInfo(ops[0], pPhyNode, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN == type) { @@ -4543,18 +4613,6 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo return pOptr; } -int32_t compareTimeWindow(const void* p1, const void* p2, const void* param) { - const SQueryTableDataCond* pCond = param; - const STimeWindow* pWin1 = p1; - const STimeWindow* pWin2 = p2; - if (pCond->order == TSDB_ORDER_ASC) { - return pWin1->skey - pWin2->skey; - } else if (pCond->order == TSDB_ORDER_DESC) { - return pWin2->skey - pWin1->skey; - } - return 0; -} - SArray* extractColumnInfo(SNodeList* pNodeList) { size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn)); @@ -4795,7 +4853,7 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, qTaskInfo_t* pT return TSDB_CODE_OUT_OF_MEMORY; } pInserterParam->readHandle = readHandle; - + *pParam = pInserterParam; break; } @@ -4876,11 +4934,8 @@ void doDestroyTask(SExecTaskInfo* pTaskInfo) { doDestroyTableList(&pTaskInfo->tableqinfoList); destroyOperatorInfo(pTaskInfo->pRoot); - // taosArrayDestroy(pTaskInfo->summary.queryProfEvents); - // taosHashCleanup(pTaskInfo->summary.operatorProfResults); + cleanupTableSchemaInfo(pTaskInfo); - taosMemoryFree(pTaskInfo->schemaVer.dbname); - taosMemoryFree(pTaskInfo->schemaVer.tablename); taosMemoryFreeClear(pTaskInfo->sql); taosMemoryFreeClear(pTaskInfo->id.str); taosMemoryFreeClear(pTaskInfo); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 311d7f0d5a..ee20bc7ba6 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -637,6 +637,7 @@ static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) { int32_t* pageId = taosArrayGet(pGroupInfo->pPageList, pInfo->pageIndex); void* page = getBufPage(pInfo->pBuf, *pageId); + blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->rowCapacity); blockDataFromBuf1(pInfo->binfo.pRes, page, pInfo->rowCapacity); pInfo->pageIndex += 1; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 5aafaa0b45..0194cd78dc 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -39,9 +39,9 @@ static int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capac static int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName); -static void addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, - SSDataBlock* pBlock); -static bool processBlockWithProbability(const SSampleExecInfo* pInfo); +static int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, + SSDataBlock* pBlock, const char* idStr); +static bool processBlockWithProbability(const SSampleExecInfo* pInfo); bool processBlockWithProbability(const SSampleExecInfo* pInfo) { #if 0 @@ -210,6 +210,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca bool allColumnsHaveAgg = true; SColumnDataAgg** pColAgg = NULL; + int32_t code = tsdbRetrieveDatablockSMA(pTableScanInfo->dataReader, &pColAgg, &allColumnsHaveAgg); if (code != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, code); @@ -263,7 +264,12 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca // currently only the tbname pseudo column if (pTableScanInfo->pseudoSup.numOfExprs > 0) { SExprSupp* pSup = &pTableScanInfo->pseudoSup; - addTagPseudoColumnData(&pTableScanInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pBlock); + + int32_t code = addTagPseudoColumnData(&pTableScanInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pBlock, + GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } } int64_t st = taosGetTimestampMs(); @@ -288,25 +294,25 @@ static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunction // setupQueryRangeForReverseScan(pTableScanInfo); pTableScanInfo->cond.order = TSDB_ORDER_DESC; - for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { - STimeWindow* pTWindow = &pTableScanInfo->cond.twindows[i]; - TSWAP(pTWindow->skey, pTWindow->ekey); - } - - SQueryTableDataCond* pCond = &pTableScanInfo->cond; - taosqsort(pCond->twindows, pCond->numOfTWindows, sizeof(STimeWindow), pCond, compareTimeWindow); + STimeWindow* pTWindow = &pTableScanInfo->cond.twindows; + TSWAP(pTWindow->skey, pTWindow->ekey); } -void addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, - SSDataBlock* pBlock) { +int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, + SSDataBlock* pBlock, const char* idStr) { // currently only the tbname pseudo column if (numOfPseudoExpr == 0) { - return; + return TSDB_CODE_SUCCESS; } SMetaReader mr = {0}; metaReaderInit(&mr, pHandle->meta, 0); - metaGetTableEntryByUid(&mr, pBlock->info.uid); + int32_t code = metaGetTableEntryByUid(&mr, pBlock->info.uid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", pBlock->info.uid, tstrerror(terrno), idStr); + metaReaderClear(&mr); + return terrno; + } for (int32_t j = 0; j < numOfPseudoExpr; ++j) { SExprInfo* pExpr = &pPseudoExpr[j]; @@ -348,6 +354,7 @@ void addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_ } metaReaderClear(&mr); + return TSDB_CODE_SUCCESS; } void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId) { @@ -415,8 +422,11 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { pOperator->cost.totalCost = pTableScanInfo->readRecorder.elapsedTime; // todo refactor - pTableScanInfo->lastStatus.uid = pBlock->info.uid; - pTableScanInfo->lastStatus.ts = pBlock->info.window.ekey; + /*pTableScanInfo->lastStatus.uid = pBlock->info.uid;*/ + /*pTableScanInfo->lastStatus.ts = pBlock->info.window.ekey;*/ + pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_DATA; + pTaskInfo->streamInfo.lastStatus.uid = pBlock->info.uid; + pTaskInfo->streamInfo.lastStatus.ts = pBlock->info.window.ekey; ASSERT(pBlock->info.uid != 0); return pBlock; @@ -435,16 +445,10 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { // do the ascending order traverse in the first place. while (pTableScanInfo->scanTimes < pTableScanInfo->scanInfo.numOfAsc) { - while (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - SSDataBlock* p = doTableScanImpl(pOperator); - if (p != NULL) { - ASSERT(p->info.uid != 0); - return p; - } - pTableScanInfo->curTWinIdx += 1; - if (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, pTableScanInfo->curTWinIdx); - } + SSDataBlock* p = doTableScanImpl(pOperator); + if (p != NULL) { + ASSERT(p->info.uid != 0); + return p; } pTableScanInfo->scanTimes += 1; @@ -453,40 +457,25 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTableScanInfo->scanFlag = REPEAT_SCAN; qDebug("%s start to repeat ascending order scan data blocks due to query func required", GET_TASKID(pTaskInfo)); - for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { - STimeWindow* pWin = &pTableScanInfo->cond.twindows[i]; - qDebug("%s qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); - } + // do prepare for the next round table scan operation - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); - pTableScanInfo->curTWinIdx = 0; + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); } } int32_t total = pTableScanInfo->scanInfo.numOfAsc + pTableScanInfo->scanInfo.numOfDesc; if (pTableScanInfo->scanTimes < total) { if (pTableScanInfo->cond.order == TSDB_ORDER_ASC) { - prepareForDescendingScan(pTableScanInfo, pTableScanInfo->pCtx, 0); - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); - pTableScanInfo->curTWinIdx = 0; + prepareForDescendingScan(pTableScanInfo, pOperator->exprSupp.pCtx, 0); + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); } qDebug("%s start to descending order scan data blocks due to query func required", GET_TASKID(pTaskInfo)); - for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { - STimeWindow* pWin = &pTableScanInfo->cond.twindows[i]; - qDebug("%s qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); - } while (pTableScanInfo->scanTimes < total) { - while (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - SSDataBlock* p = doTableScanImpl(pOperator); - if (p != NULL) { - return p; - } - pTableScanInfo->curTWinIdx += 1; - if (pTableScanInfo->curTWinIdx < pTableScanInfo->cond.numOfTWindows) { - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, pTableScanInfo->curTWinIdx); - } + SSDataBlock* p = doTableScanImpl(pOperator); + if (p != NULL) { + return p; } pTableScanInfo->scanTimes += 1; @@ -497,12 +486,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { qDebug("%s start to repeat descending order scan data blocks due to query func required", GET_TASKID(pTaskInfo)); - for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { - STimeWindow* pWin = &pTableScanInfo->cond.twindows[i]; - qDebug("%s qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); - } - tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); - pTableScanInfo->curTWinIdx = 0; + tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); } } } @@ -529,9 +513,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { } STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, pInfo->currentTable); tsdbSetTableId(pInfo->dataReader, pTableInfo->uid); - tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); + tsdbReaderReset(pInfo->dataReader, &pInfo->cond); pInfo->scanTimes = 0; - pInfo->curTWinIdx = 0; } } @@ -563,8 +546,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId); // tsdbSetTableList(pInfo->dataReader, tableList); - tsdbReaderReset(pInfo->dataReader, &pInfo->cond, 0); - pInfo->curTWinIdx = 0; + tsdbReaderReset(pInfo->dataReader, &pInfo->cond); pInfo->scanTimes = 0; result = doTableScanGroup(pOperator); @@ -595,7 +577,7 @@ static void destroyTableScanOperatorInfo(void* param, int32_t numOfOutput) { if (pTableScanInfo->pColMatchInfo != NULL) { taosArrayDestroy(pTableScanInfo->pColMatchInfo); } - + taosMemoryFreeClear(param); } @@ -635,7 +617,6 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; pInfo->scanFlag = MAIN_SCAN; pInfo->pColMatchInfo = pColList; - pInfo->curTWinIdx = 0; pInfo->currentGroupId = -1; pOperator->name = "TableScanOperator"; // for debug purpose @@ -679,34 +660,46 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* return pOperator; } -static int32_t doGetTableRowSize(void* pMeta, uint64_t uid) { - int32_t rowLen = 0; +static int32_t doGetTableRowSize(void* pMeta, uint64_t uid, int32_t* rowLen, const char* idstr) { + *rowLen = 0; SMetaReader mr = {0}; metaReaderInit(&mr, pMeta, 0); - metaGetTableEntryByUid(&mr, uid); + int32_t code = metaGetTableEntryByUid(&mr, uid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", uid, tstrerror(terrno), idstr); + metaReaderClear(&mr); + return terrno; + } + if (mr.me.type == TSDB_SUPER_TABLE) { int32_t numOfCols = mr.me.stbEntry.schemaRow.nCols; for (int32_t i = 0; i < numOfCols; ++i) { - rowLen += mr.me.stbEntry.schemaRow.pSchema[i].bytes; + (*rowLen) += mr.me.stbEntry.schemaRow.pSchema[i].bytes; } } else if (mr.me.type == TSDB_CHILD_TABLE) { uint64_t suid = mr.me.ctbEntry.suid; - metaGetTableEntryByUid(&mr, suid); + code = metaGetTableEntryByUid(&mr, suid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", suid, tstrerror(terrno), idstr); + metaReaderClear(&mr); + return terrno; + } + int32_t numOfCols = mr.me.stbEntry.schemaRow.nCols; for (int32_t i = 0; i < numOfCols; ++i) { - rowLen += mr.me.stbEntry.schemaRow.pSchema[i].bytes; + (*rowLen) += mr.me.stbEntry.schemaRow.pSchema[i].bytes; } } else if (mr.me.type == TSDB_NORMAL_TABLE) { int32_t numOfCols = mr.me.ntbEntry.schemaRow.nCols; for (int32_t i = 0; i < numOfCols; ++i) { - rowLen += mr.me.ntbEntry.schemaRow.pSchema[i].bytes; + (*rowLen) += mr.me.ntbEntry.schemaRow.pSchema[i].bytes; } } metaReaderClear(&mr); - return rowLen; + return TSDB_CODE_SUCCESS; } static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) { @@ -715,9 +708,14 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) { } SBlockDistInfo* pBlockScanInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STableBlockDistInfo blockDistInfo = {.minRows = INT_MAX, .maxRows = INT_MIN}; - blockDistInfo.rowSize = doGetTableRowSize(pBlockScanInfo->readHandle.meta, pBlockScanInfo->uid); + int32_t code = doGetTableRowSize(pBlockScanInfo->readHandle.meta, pBlockScanInfo->uid, &blockDistInfo.rowSize, + GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } tsdbGetFileBlocksDistInfo(pBlockScanInfo->pHandle, &blockDistInfo); blockDistInfo.numOfInmemRows = (int32_t)tsdbGetNumOfRowsInMemTable(pBlockScanInfo->pHandle); @@ -745,7 +743,7 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) { static void destroyBlockDistScanOperatorInfo(void* param, int32_t numOfOutput) { SBlockDistInfo* pDistInfo = (SBlockDistInfo*)param; blockDataDestroy(pDistInfo->pResBlock); - + taosMemoryFreeClear(param); } @@ -848,12 +846,7 @@ static void setGroupId(SStreamScanInfo* pInfo, SSDataBlock* pBlock, int32_t grou } void resetTableScanInfo(STableScanInfo* pTableScanInfo, STimeWindow* pWin) { - pTableScanInfo->cond.twindows[0] = *pWin; - pTableScanInfo->curTWinIdx = 0; - // tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); - // if (!pTableScanInfo->dataReader) { - // return false; - // } + pTableScanInfo->cond.twindows = *pWin; pTableScanInfo->scanTimes = 0; pTableScanInfo->currentGroupId = -1; } @@ -911,7 +904,7 @@ static bool prepareDataScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32_t t setGroupId(pInfo, pSDB, GROUPID_COLUMN_INDEX, *pRowIndex); (*pRowIndex) += updateSessionWindowInfo(pCurWin, tsCols, NULL, pSDB->info.rows, *pRowIndex, gap, NULL); } else { - win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[*pRowIndex], &pInfo->interval, pInfo->interval.precision, NULL); + win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[*pRowIndex], &pInfo->interval, TSDB_ORDER_ASC); setGroupId(pInfo, pSDB, GROUPID_COLUMN_INDEX, *pRowIndex); (*pRowIndex) += getNumOfRowsInTimeWindow(&pSDB->info, tsCols, *pRowIndex, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); @@ -1131,13 +1124,122 @@ static void setBlockGroupId(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32 } } +static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock) { + SDataBlockInfo* pBlockInfo = &pInfo->pRes->info; + SOperatorInfo* pOperator = pInfo->pStreamScanOp; + SExecTaskInfo* pTaskInfo = pInfo->pStreamScanOp->pTaskInfo; + + pInfo->pRes->info.rows = pBlock->info.rows; + pInfo->pRes->info.uid = pBlock->info.uid; + pInfo->pRes->info.type = STREAM_NORMAL; + pInfo->pRes->info.capacity = pBlock->info.rows; + + uint64_t* groupIdPre = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t)); + if (groupIdPre) { + pInfo->pRes->info.groupId = *groupIdPre; + } else { + pInfo->pRes->info.groupId = 0; + } + + // for generating rollup SMA result, each time is an independent time serie. + // TODO temporarily used, when the statement of "partition by tbname" is ready, remove this + if (pInfo->assignBlockUid) { + pInfo->pRes->info.groupId = pBlock->info.uid; + } + + // todo extract method + for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) { + SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i); + if (!pColMatchInfo->output) { + continue; + } + + bool colExists = false; + for (int32_t j = 0; j < blockDataGetNumOfCols(pBlock); ++j) { + SColumnInfoData* pResCol = bdGetColumnInfoData(pBlock, j); + if (pResCol->info.colId == pColMatchInfo->colId) { + taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, pResCol); + colExists = true; + break; + } + } + + // the required column does not exists in submit block, let's set it to be all null value + if (!colExists) { + SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId); + colDataAppendNNULL(pDst, 0, pBlockInfo->rows); + } + } + + taosArrayDestroy(pBlock->pDataBlock); + + ASSERT(pInfo->pRes->pDataBlock != NULL); +#if 0 + if (pInfo->pRes->pDataBlock == NULL) { + // TODO add log + updateInfoDestoryColseWinSBF(pInfo->pUpdateInfo); + pOperator->status = OP_EXEC_DONE; + pTaskInfo->code = terrno; + return -1; + } +#endif + + // currently only the tbname pseudo column + if (pInfo->numOfPseudoExpr > 0) { + int32_t code = addTagPseudoColumnData(&pInfo->readHandle, pInfo->pPseudoExpr, pInfo->numOfPseudoExpr, pInfo->pRes, + GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + } + + doFilter(pInfo->pCondition, pInfo->pRes); + blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex); + return 0; +} + static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { // NOTE: this operator does never check if current status is done or not SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStreamScanInfo* pInfo = pOperator->info; - pTaskInfo->code = pOperator->fpSet._openFn(pOperator); - if (pTaskInfo->code != TSDB_CODE_SUCCESS || pOperator->status == OP_EXEC_DONE) { + /*pTaskInfo->code = pOperator->fpSet._openFn(pOperator);*/ + /*if (pTaskInfo->code != TSDB_CODE_SUCCESS || pOperator->status == OP_EXEC_DONE) {*/ + /*return NULL;*/ + /*}*/ + + if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__LOG) { + while (1) { + SFetchRet ret = {0}; + tqNextBlock(pInfo->tqReader, &ret); + if (ret.fetchType == FETCH_TYPE__DATA) { + blockDataCleanup(pInfo->pRes); + if (setBlockIntoRes(pInfo, &ret.data) < 0) { + ASSERT(0); + } + // TODO clean data block + if (pInfo->pRes->info.rows > 0) { + return pInfo->pRes; + } + } else if (ret.fetchType == FETCH_TYPE__META) { + ASSERT(0); + pTaskInfo->streamInfo.lastStatus = ret.offset; + pTaskInfo->streamInfo.metaBlk = ret.meta; + return NULL; + } else if (ret.fetchType == FETCH_TYPE__NONE) { + pTaskInfo->streamInfo.lastStatus = ret.offset; + ASSERT(pTaskInfo->streamInfo.lastStatus.version + 1 >= pTaskInfo->streamInfo.prepareStatus.version); + return NULL; + } else { + ASSERT(0); + } + } + } else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) { + SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp); + return pResult && pResult->info.rows > 0 ? pResult : NULL; + } else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_META) { + // TODO scan meta + ASSERT(0); return NULL; } @@ -1146,7 +1248,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { if (pInfo->blockType == STREAM_INPUT__DATA_BLOCK) { if (pInfo->validBlockIndex >= total) { /*doClearBufferedBlocks(pInfo);*/ - pOperator->status = OP_EXEC_DONE; + /*pOperator->status = OP_EXEC_DONE;*/ return NULL; } @@ -1250,66 +1352,8 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { return NULL; } - pInfo->pRes->info.rows = block.info.rows; - pInfo->pRes->info.uid = block.info.uid; - pInfo->pRes->info.type = STREAM_NORMAL; - pInfo->pRes->info.capacity = block.info.rows; + setBlockIntoRes(pInfo, &block); - - - uint64_t* groupIdPre = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &block.info.uid, sizeof(int64_t)); - if (groupIdPre) { - pInfo->pRes->info.groupId = *groupIdPre; - } else { - pInfo->pRes->info.groupId = 0; - } - - // for generating rollup SMA result, each time is an independent time serie. - // TODO temporarily used, when the statement of "partition by tbname" is ready, remove this - if (pInfo->assignBlockUid) { - pInfo->pRes->info.groupId = block.info.uid; - } - - // todo extract method - for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) { - SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i); - if (!pColMatchInfo->output) { - continue; - } - - bool colExists = false; - for (int32_t j = 0; j < blockDataGetNumOfCols(&block); ++j) { - SColumnInfoData* pResCol = bdGetColumnInfoData(&block, j); - if (pResCol->info.colId == pColMatchInfo->colId) { - taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, pResCol); - colExists = true; - break; - } - } - - // the required column does not exists in submit block, let's set it to be all null value - if (!colExists) { - SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId); - colDataAppendNNULL(pDst, 0, pBlockInfo->rows); - } - } - - taosArrayDestroy(block.pDataBlock); - if (pInfo->pRes->pDataBlock == NULL) { - // TODO add log - updateInfoDestoryColseWinSBF(pInfo->pUpdateInfo); - pOperator->status = OP_EXEC_DONE; - pTaskInfo->code = terrno; - return NULL; - } - - // currently only the tbname pseudo column - if (pInfo->numOfPseudoExpr > 0) { - addTagPseudoColumnData(&pInfo->readHandle, pInfo->pPseudoExpr, pInfo->numOfPseudoExpr, pInfo->pRes); - } - - doFilter(pInfo->pCondition, pInfo->pRes); - blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex); if (pBlockInfo->rows > 0) { break; } @@ -1321,7 +1365,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { if (pBlockInfo->rows == 0) { updateInfoDestoryColseWinSBF(pInfo->pUpdateInfo); - pOperator->status = OP_EXEC_DONE; + /*pOperator->status = OP_EXEC_DONE;*/ } else if (pInfo->pUpdateInfo) { pInfo->tsArrayIndex = 0; checkUpdateData(pInfo, true, pInfo->pRes, true); @@ -1339,11 +1383,14 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { return (pBlockInfo->rows == 0) ? NULL : pInfo->pRes; - } else if (pInfo->blockType == STREAM_INPUT__DATA_SCAN) { +#if 0 + } else if (pInfo->blockType == STREAM_INPUT__TABLE_SCAN) { + ASSERT(0); // check reader last status // if not match, reset status SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp); return pResult && pResult->info.rows > 0 ? pResult : NULL; +#endif } else { ASSERT(0); @@ -1351,6 +1398,11 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } } +static SSDataBlock* doRawScan(SOperatorInfo* pInfo) { + // + return NULL; +} + static SArray* extractTableIdList(const STableListInfo* pTableGroupInfo) { SArray* tableIdList = taosArrayInit(4, sizeof(uint64_t)); @@ -1363,6 +1415,19 @@ static SArray* extractTableIdList(const STableListInfo* pTableGroupInfo) { return tableIdList; } +// for subscribing db or stb (not including column), +// if this scan is used, meta data can be return +// and schemas are decided when scanning +SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, + SExecTaskInfo* pTaskInfo, STimeWindowAggSupp* pTwSup) { + // create operator + // create tb reader + // create meta reader + // create tq reader + + return NULL; +} + SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo, STimeWindowAggSupp* pTwSup, uint64_t queryId, uint64_t taskId) { @@ -1406,13 +1471,16 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys if (pHandle) { SOperatorInfo* pTableScanOp = createTableScanOperatorInfo(pTableScanNode, pHandle, pTaskInfo); - STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanOp->info; + STableScanInfo* pTSInfo = (STableScanInfo*)pTableScanOp->info; + if (pHandle->version > 0) { + pTSInfo->cond.endVersion = pHandle->version; + } SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, 0); if (pHandle->initTableReader) { - pSTInfo->scanMode = TABLE_SCAN__TABLE_ORDER; - pSTInfo->dataReader = NULL; - if (tsdbReaderOpen(pHandle->vnode, &pSTInfo->cond, tableList, &pSTInfo->dataReader, NULL) < 0) { + pTSInfo->scanMode = TABLE_SCAN__TABLE_ORDER; + pTSInfo->dataReader = NULL; + if (tsdbReaderOpen(pHandle->vnode, &pTSInfo->cond, tableList, &pTSInfo->dataReader, NULL) < 0) { ASSERT(0); } } @@ -1426,14 +1494,14 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys pInfo->tqReader = pHandle->tqReader; } - if (pSTInfo->interval.interval > 0) { - pInfo->pUpdateInfo = updateInfoInitP(&pSTInfo->interval, pTwSup->waterMark); + if (pTSInfo->interval.interval > 0) { + pInfo->pUpdateInfo = updateInfoInitP(&pTSInfo->interval, pTwSup->waterMark); } else { pInfo->pUpdateInfo = NULL; } pInfo->pTableScanOp = pTableScanOp; - pInfo->interval = pSTInfo->interval; + pInfo->interval = pTSInfo->interval; pInfo->readHandle = *pHandle; pInfo->tableUid = pScanPhyNode->uid; @@ -1730,7 +1798,17 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { SMetaReader mr = {0}; metaReaderInit(&mr, pInfo->readHandle.meta, 0); - metaGetTableEntryByUid(&mr, pInfo->pCur->mr.me.ctbEntry.suid); + + uint64_t suid = pInfo->pCur->mr.me.ctbEntry.suid; + int32_t code = metaGetTableEntryByUid(&mr, suid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get super table meta, uid:0x%" PRIx64 ", code:%s, %s", suid, tstrerror(terrno), + GET_TASKID(pTaskInfo)); + metaReaderClear(&mr); + metaCloseTbCursor(pInfo->pCur); + pInfo->pCur = NULL; + longjmp(pTaskInfo->env, terrno); + } // number of columns pColInfoData = taosArrayGet(p->pDataBlock, 3); @@ -2125,7 +2203,13 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { while (pInfo->curPos < size && count < pOperator->resultInfo.capacity) { STableKeyInfo* item = taosArrayGet(pInfo->pTableList->pTableList, pInfo->curPos); - metaGetTableEntryByUid(&mr, item->uid); + int32_t code = metaGetTableEntryByUid(&mr, item->uid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", item->uid, tstrerror(terrno), + GET_TASKID(pTaskInfo)); + metaReaderClear(&mr); + longjmp(pTaskInfo->env, terrno); + } for (int32_t j = 0; j < pOperator->exprSupp.numOfExprs; ++j) { SColumnInfoData* pDst = taosArrayGet(pRes->pDataBlock, pExprInfo[j].base.resSchema.slotId); @@ -2177,7 +2261,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) { STagScanInfo* pInfo = (STagScanInfo*)param; pInfo->pRes = blockDataDestroy(pInfo->pRes); - + taosMemoryFreeClear(param); } @@ -2410,8 +2494,11 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc // currently only the tbname pseudo column if (pTableScanInfo->numOfPseudoExpr > 0) { - addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pPseudoExpr, pTableScanInfo->numOfPseudoExpr, - pBlock); + int32_t code = addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pPseudoExpr, + pTableScanInfo->numOfPseudoExpr, pBlock, GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } } int64_t st = taosGetTimestampMs(); @@ -2669,7 +2756,7 @@ void destroyTableMergeScanOperatorInfo(void* param, int32_t numOfOutput) { pTableScanInfo->pSortInputBlock = blockDataDestroy(pTableScanInfo->pSortInputBlock); taosArrayDestroy(pTableScanInfo->pSortInfo); - + taosMemoryFreeClear(param); } diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index d106d3e749..8d9cac3614 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -217,6 +217,7 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { doSetOperatorCompleted(pOperator); break; } + if (blockDataGetNumOfRows(pBlock) > 0) { break; } @@ -601,8 +602,7 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData break; } - if (pInfo->groupSort) - { + if (pInfo->groupSort) { uint64_t tupleGroupId = tsortGetGroupId(pTupleHandle); if (!pInfo->hasGroupId) { pInfo->groupId = tupleGroupId; diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index 1d82d6a644..b0e2166baf 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -50,8 +50,11 @@ static void setTagsValue(SFillInfo* pFillInfo, void** data, int32_t genRows) { static void setNullRow(SSDataBlock* pBlock, int32_t numOfCol, int32_t rowIndex) { // the first are always the timestamp column, so start from the second column. - for (int32_t i = 1; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData* p = taosArrayGet(pBlock->pDataBlock, i); + if (p->info.type == TSDB_DATA_TYPE_TIMESTAMP && i == 0) { + continue; + } colDataAppendNULL(p, rowIndex); } } diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 0847b0267b..78775073a4 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -59,61 +59,6 @@ static void doCloseWindow(SResultRowInfo* pResultRowInfo, const SIntervalAggOper static TSKEY getStartTsKey(STimeWindow* win, const TSKEY* tsCols) { return tsCols == NULL ? win->skey : tsCols[0]; } -static void getInitialStartTimeWindow(SInterval* pInterval, int32_t precision, TSKEY ts, STimeWindow* w, - bool ascQuery) { - if (ascQuery) { - getAlignQueryTimeWindow(pInterval, precision, ts, w); - } else { - // the start position of the first time window in the endpoint that spreads beyond the queried last timestamp - getAlignQueryTimeWindow(pInterval, precision, ts, w); - - int64_t key = w->skey; - while (key < ts) { // moving towards end - key = taosTimeAdd(key, pInterval->sliding, pInterval->slidingUnit, precision); - if (key >= ts) { - break; - } - - w->skey = key; - } - } -} - -// get the correct time window according to the handled timestamp -STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval, - int32_t precision, STimeWindow* win) { - STimeWindow w = {0}; - - if (pResultRowInfo->cur.pageId == -1) { // the first window, from the previous stored value - getInitialStartTimeWindow(pInterval, precision, ts, &w, true); - w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; - } else { - w = getResultRowByPos(pBuf, &pResultRowInfo->cur)->win; - } - - if (w.skey > ts || w.ekey < ts) { - if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') { - w.skey = taosTimeTruncate(ts, pInterval, precision); - w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; - } else { - int64_t st = w.skey; - - if (st > ts) { - st -= ((st - ts + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; - } - - int64_t et = st + pInterval->interval - 1; - if (et < ts) { - st += ((ts - et + pInterval->sliding - 1) / pInterval->sliding) * pInterval->sliding; - } - - w.skey = st; - w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; - } - } - return w; -} - static int32_t setTimeWindowOutputBuf(SResultRowInfo* pResultRowInfo, STimeWindow* win, bool masterscan, SResultRow** pResult, int64_t tableGroupId, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup, @@ -814,7 +759,7 @@ static void removeResults(SArray* pWins, SArray* pUpdated) { } int64_t getWinReskey(void* data, int32_t index) { - SArray* res = (SArray*)data; + SArray* res = (SArray*)data; SWinRes* pos = taosArrayGet(res, index); return pos->ts; } @@ -824,15 +769,14 @@ static void removeDeleteResults(SArray* pUpdated, SArray* pDelWins) { int32_t delSize = taosArrayGetSize(pDelWins); for (int32_t i = 0; i < upSize; i++) { SResKeyPos* pResKey = taosArrayGetP(pUpdated, i); - int64_t key = *(int64_t*)pResKey->key; - int32_t index = binarySearch(pDelWins, delSize, key, TSDB_ORDER_DESC, getWinReskey); + int64_t key = *(int64_t*)pResKey->key; + int32_t index = binarySearch(pDelWins, delSize, key, TSDB_ORDER_DESC, getWinReskey); if (index >= 0 && key == getWinReskey(pDelWins, index)) { taosArrayRemove(pDelWins, index); } } } - bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup) { ASSERT(pSup->maxTs == INT64_MIN || pSup->maxTs > 0); return pSup->maxTs != INT64_MIN && ts < pSup->maxTs - pSup->waterMark; @@ -855,8 +799,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul TSKEY ts = getStartTsKey(&pBlock->info.window, tsCols); SResultRow* pResult = NULL; - STimeWindow win = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, - pInfo->interval.precision, &pInfo->win); + STimeWindow win = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->order); int32_t ret = TSDB_CODE_SUCCESS; if (!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) { ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pSup->pCtx, @@ -1010,21 +953,6 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->order, scanFlag, true); hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, scanFlag, NULL); - -#if 0 // test for encode/decode result info - if(pOperator->fpSet.encodeResultRow){ - char *result = NULL; - int32_t length = 0; - SAggSupporter *pSup = &pInfo->aggSup; - pOperator->fpSet.encodeResultRow(pOperator, &result, &length); - taosHashClear(pSup->pResultRowHashTable); - pInfo->binfo.resultRowInfo.size = 0; - pOperator->fpSet.decodeResultRow(pOperator, result); - if(result){ - taosMemoryFree(result); - } - } -#endif } closeAllResultRows(&pInfo->binfo.resultRowInfo); @@ -1146,7 +1074,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) { SOptrBasicInfo* pBInfo = &pInfo->binfo; if (pOperator->status == OP_RES_TO_RETURN) { - while(1) { + while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); doFilter(pInfo->pCondition, pBInfo->pRes); @@ -1161,7 +1089,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) { } } pOperator->resultInfo.totalRows += pBInfo->pRes->info.rows; - return (pBInfo->pRes->info.rows == 0)? NULL:pBInfo->pRes; + return (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes; } int32_t order = TSDB_ORDER_ASC; @@ -1187,7 +1115,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) { initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, TSDB_ORDER_ASC); blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity); - while(1) { + while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); doFilter(pInfo->pCondition, pBInfo->pRes); @@ -1202,7 +1130,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) { } } pOperator->resultInfo.totalRows += pBInfo->pRes->info.rows; - return (pBInfo->pRes->info.rows == 0)? NULL:pBInfo->pRes; + return (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes; } static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) { @@ -1227,11 +1155,13 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) { while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); doFilter(pInfo->pCondition, pBlock); + bool hasRemain = hasDataInGroupInfo(&pInfo->groupResInfo); if (!hasRemain) { doSetOperatorCompleted(pOperator); break; } + if (pBlock->info.rows > 0) { break; } @@ -1324,13 +1254,13 @@ bool doDeleteIntervalWindow(SAggSupporter* pAggSup, TSKEY ts, uint64_t groupId) void doDeleteSpecifyIntervalWindow(SAggSupporter* pAggSup, SSDataBlock* pBlock, SArray* pUpWins, SInterval* pInterval) { SColumnInfoData* pStartCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX); - TSKEY* tsStarts = (TSKEY*)pStartCol->pData; + TSKEY* tsStarts = (TSKEY*)pStartCol->pData; SColumnInfoData* pGroupCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX); - uint64_t* groupIds = (uint64_t*)pGroupCol->pData; + uint64_t* groupIds = (uint64_t*)pGroupCol->pData; for (int32_t i = 0; i < pBlock->info.rows; i++) { SResultRowInfo dumyInfo; dumyInfo.cur.pageId = -1; - STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsStarts[i], pInterval, pInterval->precision, NULL); + STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsStarts[i], pInterval, TSDB_ORDER_ASC); doDeleteIntervalWindow(pAggSup, win.skey, groupIds[i]); if (pUpWins) { SWinRes winRes = {.ts = win.skey, .groupId = groupIds[i]}; @@ -1339,8 +1269,8 @@ void doDeleteSpecifyIntervalWindow(SAggSupporter* pAggSup, SSDataBlock* pBlock, } } -static void doClearWindows(SAggSupporter* pAggSup, SExprSupp* pSup1, SInterval* pInterval, - int32_t numOfOutput, SSDataBlock* pBlock, SArray* pUpWins) { +static void doClearWindows(SAggSupporter* pAggSup, SExprSupp* pSup1, SInterval* pInterval, int32_t numOfOutput, + SSDataBlock* pBlock, SArray* pUpWins) { SColumnInfoData* pTsCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX); TSKEY* tsCols = (TSKEY*)pTsCol->pData; uint64_t* pGpDatas = NULL; @@ -1352,10 +1282,10 @@ static void doClearWindows(SAggSupporter* pAggSup, SExprSupp* pSup1, SInterval* for (int32_t i = 0; i < pBlock->info.rows; i += step) { SResultRowInfo dumyInfo; dumyInfo.cur.pageId = -1; - STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[i], pInterval, pInterval->precision, NULL); + STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[i], pInterval, TSDB_ORDER_ASC); step = getNumOfRowsInTimeWindow(&pBlock->info, tsCols, i, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); uint64_t winGpId = pGpDatas ? pGpDatas[i] : pBlock->info.groupId; - bool res = doClearWindow(pAggSup, pSup1, (char*)&win.skey, sizeof(TKEY), winGpId, numOfOutput); + bool res = doClearWindow(pAggSup, pSup1, (char*)&win.skey, sizeof(TKEY), winGpId, numOfOutput); if (pUpWins && res) { SWinRes winRes = {.ts = win.skey, .groupId = winGpId}; taosArrayPush(pUpWins, &winRes); @@ -1380,9 +1310,9 @@ static int32_t getAllIntervalWindow(SHashObj* pHashMap, SArray* resWins) { return TSDB_CODE_SUCCESS; } -static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup, - SInterval* pInterval, SHashObj* pPullDataMap, SArray* closeWins, - SArray* pRecyPages, SDiskbasedBuf* pDiscBuf) { +static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup, SInterval* pInterval, + SHashObj* pPullDataMap, SArray* closeWins, SArray* pRecyPages, + SDiskbasedBuf* pDiscBuf) { void* pIte = NULL; size_t keyLen = 0; while ((pIte = taosHashIterate(pHashMap, pIte)) != NULL) { @@ -1392,7 +1322,7 @@ static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup, TSKEY ts = *(int64_t*)((char*)key + sizeof(uint64_t)); SResultRowInfo dumyInfo; dumyInfo.cur.pageId = -1; - STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, ts, pInterval, pInterval->precision, NULL); + STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, ts, pInterval, TSDB_ORDER_ASC); SWinRes winRe = { .ts = win.skey, .groupId = groupId, @@ -1402,13 +1332,13 @@ static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup, if (chIds && pPullDataMap) { SArray* chAy = *(SArray**)chIds; int32_t size = taosArrayGetSize(chAy); - qInfo("======window %ld wait child size:%d", win.skey, size); + qInfo("window %" PRId64 " wait child size:%d", win.skey, size); for (int32_t i = 0; i < size; i++) { - qInfo("======window %ld wait chid id:%d", win.skey, *(int32_t*)taosArrayGet(chAy, i)); + qInfo("window %" PRId64 " wait chid id:%d", win.skey, *(int32_t*)taosArrayGet(chAy, i)); } continue; } else if (pPullDataMap) { - qInfo("======close window %ld", win.skey); + qInfo("close window %" PRId64, win.skey); } SResultRowPosition* pPos = (SResultRowPosition*)pIte; if (pSup->calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) { @@ -1437,8 +1367,8 @@ static void closeChildIntervalWindow(SArray* pChildren, TSKEY maxTs) { SStreamFinalIntervalOperatorInfo* pChInfo = pChildOp->info; ASSERT(pChInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE); pChInfo->twAggSup.maxTs = TMAX(pChInfo->twAggSup.maxTs, maxTs); - closeIntervalWindow(pChInfo->aggSup.pResultRowHashTable, &pChInfo->twAggSup, - &pChInfo->interval, NULL, NULL, NULL, pChInfo->aggSup.pResultBuf); + closeIntervalWindow(pChInfo->aggSup.pResultRowHashTable, &pChInfo->twAggSup, &pChInfo->interval, NULL, NULL, NULL, + pChInfo->aggSup.pResultBuf); } } @@ -1484,7 +1414,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { } if (pOperator->status == OP_RES_TO_RETURN) { - doBuildDeleteResult(pInfo->pDelWins, &pInfo->delIndex ,pInfo->pDelRes); + doBuildDeleteResult(pInfo->pDelWins, &pInfo->delIndex, pInfo->pDelRes); if (pInfo->pDelRes->info.rows > 0) { return pInfo->pDelRes; } @@ -1499,7 +1429,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { SOperatorInfo* downstream = pOperator->pDownstream[0]; - SArray* pUpdated = taosArrayInit(4, POINTER_BYTES); // SResKeyPos + SArray* pUpdated = taosArrayInit(4, POINTER_BYTES); // SResKeyPos while (1) { SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); if (pBlock == NULL) { @@ -1508,11 +1438,12 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { printDataBlock(pBlock, "single interval recv"); if (pBlock->info.type == STREAM_CLEAR) { - doClearWindows(&pInfo->aggSup, &pOperator->exprSupp, &pInfo->interval, - pOperator->exprSupp.numOfExprs, pBlock, NULL); + doClearWindows(&pInfo->aggSup, &pOperator->exprSupp, &pInfo->interval, pOperator->exprSupp.numOfExprs, pBlock, + NULL); qDebug("%s clear existed time window results for updates checked", GET_TASKID(pTaskInfo)); continue; - } if (pBlock->info.type == STREAM_DELETE_DATA) { + } + if (pBlock->info.type == STREAM_DELETE_DATA) { doDeleteSpecifyIntervalWindow(&pInfo->aggSup, pBlock, pInfo->pDelWins, &pInfo->interval); continue; } else if (pBlock->info.type == STREAM_GET_ALL) { @@ -1537,8 +1468,8 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, MAIN_SCAN, pUpdated); } pOperator->status = OP_RES_TO_RETURN; - closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, - &pInfo->interval, NULL, pUpdated, pInfo->pRecycledPages, pInfo->aggSup.pResultBuf); + closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, NULL, pUpdated, + pInfo->pRecycledPages, pInfo->aggSup.pResultBuf); finalizeUpdatedResult(pOperator->exprSupp.numOfExprs, pInfo->aggSup.pResultBuf, pUpdated, pSup->rowEntryInfoOffset); initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated); @@ -1557,7 +1488,7 @@ static void destroyStateWindowOperatorInfo(void* param, int32_t numOfOutput) { SStateWindowOperatorInfo* pInfo = (SStateWindowOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); taosMemoryFreeClear(pInfo->stateKey.pData); - + taosMemoryFreeClear(param); } @@ -1566,7 +1497,7 @@ void destroyIntervalOperatorInfo(void* param, int32_t numOfOutput) { cleanupBasicInfo(&pInfo->binfo); cleanupAggSup(&pInfo->aggSup); taosArrayDestroy(pInfo->pRecycledPages); - + taosMemoryFreeClear(param); } @@ -1590,7 +1521,7 @@ void destroyStreamFinalIntervalOperatorInfo(void* param, int32_t numOfOutput) { } } nodesDestroyNode((SNode*)pInfo->pPhyNode); - + taosMemoryFreeClear(param); } @@ -1733,8 +1664,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pInfo->pDelWins = taosArrayInit(4, sizeof(SWinRes)); pInfo->delIndex = 0; // pInfo->pDelRes = createPullDataBlock(); todo(liuyao) for delete - pInfo->pDelRes = createOneDataBlock(pInfo->binfo.pRes, false);// todo(liuyao) for delete - pInfo->pDelRes->info.type = STREAM_DELETE_RESULT;// todo(liuyao) for delete + pInfo->pDelRes = createOneDataBlock(pInfo->binfo.pRes, false); // todo(liuyao) for delete + pInfo->pDelRes->info.type = STREAM_DELETE_RESULT; // todo(liuyao) for delete initResultRowInfo(&pInfo->binfo.resultRowInfo); @@ -1902,7 +1833,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { SExprSupp* pSup = &pOperator->exprSupp; if (pOperator->status == OP_RES_TO_RETURN) { - while(1) { + while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); doFilter(pInfo->pCondition, pBInfo->pRes); @@ -1917,7 +1848,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { } } pOperator->resultInfo.totalRows += pBInfo->pRes->info.rows; - return (pBInfo->pRes->info.rows == 0)? NULL:pBInfo->pRes; + return (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes; } int64_t st = taosGetTimestampUs(); @@ -1946,7 +1877,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, TSDB_ORDER_ASC); blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity); - while(1) { + while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); doFilter(pInfo->pCondition, pBInfo->pRes); @@ -1961,7 +1892,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { } } pOperator->resultInfo.totalRows += pBInfo->pRes->info.rows; - return (pBInfo->pRes->info.rows == 0)? NULL:pBInfo->pRes; + return (pBInfo->pRes->info.rows == 0) ? NULL : pBInfo->pRes; } static void doKeepPrevRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock* pBlock, int32_t rowIndex) { @@ -2325,13 +2256,14 @@ _error: void destroySWindowOperatorInfo(void* param, int32_t numOfOutput) { SSessionAggOperatorInfo* pInfo = (SSessionAggOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); - + taosMemoryFreeClear(param); } SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, int64_t gap, int32_t tsSlotId, - STimeWindowAggSupp* pTwAggSupp, SNode* pCondition, SExecTaskInfo* pTaskInfo) { + STimeWindowAggSupp* pTwAggSupp, SNode* pCondition, + SExecTaskInfo* pTaskInfo) { SSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSessionAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -2410,20 +2342,20 @@ bool hasIntervalWindow(SAggSupporter* pSup, TSKEY ts, uint64_t groupId) { return p1 != NULL; } -static void rebuildIntervalWindow(SStreamFinalIntervalOperatorInfo* pInfo, SExprSupp* pSup, - SArray* pWinArray, int32_t groupId, int32_t numOfOutput, SExecTaskInfo* pTaskInfo, SArray* pUpdated) { +static void rebuildIntervalWindow(SStreamFinalIntervalOperatorInfo* pInfo, SExprSupp* pSup, SArray* pWinArray, + int32_t groupId, int32_t numOfOutput, SExecTaskInfo* pTaskInfo, SArray* pUpdated) { int32_t size = taosArrayGetSize(pWinArray); if (!pInfo->pChildren) { return; } for (int32_t i = 0; i < size; i++) { - SWinRes* pWinRes = taosArrayGet(pWinArray, i); - SResultRow* pCurResult = NULL; - STimeWindow ParentWin = {.skey = pWinRes->ts, .ekey = pWinRes->ts+1}; - setTimeWindowOutputBuf(&pInfo->binfo.resultRowInfo, &ParentWin, true, &pCurResult, pWinRes->groupId, pSup->pCtx, numOfOutput, - pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo); + SWinRes* pWinRes = taosArrayGet(pWinArray, i); + SResultRow* pCurResult = NULL; + STimeWindow ParentWin = {.skey = pWinRes->ts, .ekey = pWinRes->ts + 1}; + setTimeWindowOutputBuf(&pInfo->binfo.resultRowInfo, &ParentWin, true, &pCurResult, pWinRes->groupId, pSup->pCtx, + numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo); int32_t numOfChildren = taosArrayGetSize(pInfo->pChildren); - bool find = true; + bool find = true; for (int32_t j = 0; j < numOfChildren; j++) { SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, j); SIntervalAggOperatorInfo* pChInfo = pChildOp->info; @@ -2433,8 +2365,9 @@ static void rebuildIntervalWindow(SStreamFinalIntervalOperatorInfo* pInfo, SExpr } find = true; SResultRow* pChResult = NULL; - setTimeWindowOutputBuf(&pChInfo->binfo.resultRowInfo, &ParentWin, true, &pChResult, pWinRes->groupId, pChildSup->pCtx, - pChildSup->numOfExprs, pChildSup->rowEntryInfoOffset, &pChInfo->aggSup, pTaskInfo); + setTimeWindowOutputBuf(&pChInfo->binfo.resultRowInfo, &ParentWin, true, &pChResult, pWinRes->groupId, + pChildSup->pCtx, pChildSup->numOfExprs, pChildSup->rowEntryInfoOffset, &pChInfo->aggSup, + pTaskInfo); compactFunctions(pSup->pCtx, pChildSup->pCtx, numOfOutput, pTaskInfo); } if (find && pUpdated) { @@ -2468,6 +2401,12 @@ void addPullWindow(SHashObj* pMap, SWinRes* pWinRes, int32_t size) { static int32_t getChildIndex(SSDataBlock* pBlock) { return pBlock->info.childId; } +STimeWindow getFinalTimeWindow(int64_t ts, SInterval* pInterval) { + STimeWindow w = {.skey = ts, .ekey = INT64_MAX}; + w.ekey = taosTimeAdd(w.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1; + return w; +} + static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBlock, uint64_t tableGroupId, SArray* pUpdated) { SStreamFinalIntervalOperatorInfo* pInfo = (SStreamFinalIntervalOperatorInfo*)pOperatorInfo->info; @@ -2487,8 +2426,12 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc int32_t startPos = ascScan ? 0 : (pSDataBlock->info.rows - 1); TSKEY ts = getStartTsKey(&pSDataBlock->info.window, tsCols); - STimeWindow nextWin = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, - pInfo->interval.precision, NULL); + STimeWindow nextWin = {0}; + if (IS_FINAL_OP(pInfo)) { + nextWin = getFinalTimeWindow(ts, &pInfo->interval); + } else { + nextWin = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->order); + } while (1) { bool isClosed = isCloseWindow(&nextWin, &pInfo->twAggSup); if (pInfo->ignoreExpiredData && isClosed) { @@ -2545,8 +2488,12 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey, NULL, + if (IS_FINAL_OP(pInfo)) { + forwardRows = 1; + } else { + forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); + } if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdated) { saveResultRow(pResult, tableGroupId, pUpdated); } @@ -2712,7 +2659,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { clearSpecialDataBlock(pInfo->pUpdateRes); removeDeleteResults(pUpdated, pInfo->pDelWins); pOperator->status = OP_RES_TO_RETURN; - qInfo("Stream Final Interval return data"); + qInfo("%s return data", IS_FINAL_OP(pInfo) ? "interval Final" : "interval Semi"); break; } printDataBlock(pBlock, IS_FINAL_OP(pInfo) ? "interval Final recv" : "interval Semi recv"); @@ -2723,18 +2670,16 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { pInfo->binfo.pRes->info.type = pBlock->info.type; } else if (pBlock->info.type == STREAM_CLEAR) { SArray* pUpWins = taosArrayInit(8, sizeof(SWinRes)); - doClearWindows(&pInfo->aggSup, pSup, &pInfo->interval, pOperator->exprSupp.numOfExprs, - pBlock, pUpWins); + doClearWindows(&pInfo->aggSup, pSup, &pInfo->interval, pOperator->exprSupp.numOfExprs, pBlock, pUpWins); if (IS_FINAL_OP(pInfo)) { int32_t childIndex = getChildIndex(pBlock); SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex); SStreamFinalIntervalOperatorInfo* pChildInfo = pChildOp->info; SExprSupp* pChildSup = &pChildOp->exprSupp; - doClearWindows(&pChildInfo->aggSup, pChildSup, &pChildInfo->interval, - pChildSup->numOfExprs, pBlock, NULL); - rebuildIntervalWindow(pInfo, pSup, pUpWins, pInfo->binfo.pRes->info.groupId, - pOperator->exprSupp.numOfExprs, pOperator->pTaskInfo, NULL); + doClearWindows(&pChildInfo->aggSup, pChildSup, &pChildInfo->interval, pChildSup->numOfExprs, pBlock, NULL); + rebuildIntervalWindow(pInfo, pSup, pUpWins, pInfo->binfo.pRes->info.groupId, pOperator->exprSupp.numOfExprs, + pOperator->pTaskInfo, NULL); taosArrayDestroy(pUpWins); continue; } @@ -2752,7 +2697,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { SExprSupp* pChildSup = &pChildOp->exprSupp; doDeleteSpecifyIntervalWindow(&pChildInfo->aggSup, pBlock, NULL, &pChildInfo->interval); rebuildIntervalWindow(pInfo, pSup, pInfo->pDelWins, pInfo->binfo.pRes->info.groupId, - pOperator->exprSupp.numOfExprs, pOperator->pTaskInfo, pUpdated); + pOperator->exprSupp.numOfExprs, pOperator->pTaskInfo, pUpdated); continue; } removeResults(pInfo->pDelWins, pUpdated); @@ -2774,6 +2719,10 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { continue; } + if (pInfo->scalarSupp.pExprInfo != NULL) { + SExprSupp* pExprSup = &pInfo->scalarSupp; + projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL); + } setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->order, MAIN_SCAN, true); doHashInterval(pOperator, pBlock, pBlock->info.groupId, pUpdated); if (IS_FINAL_OP(pInfo)) { @@ -2802,8 +2751,8 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs); if (IS_FINAL_OP(pInfo)) { - closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, - &pInfo->interval, pInfo->pPullDataMap, pUpdated, pInfo->pRecycledPages, pInfo->aggSup.pResultBuf); + closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, pInfo->pPullDataMap, + pUpdated, pInfo->pRecycledPages, pInfo->aggSup.pResultBuf); closeChildIntervalWindow(pInfo->pChildren, pInfo->twAggSup.maxTs); } @@ -2891,6 +2840,15 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; initResultSizeInfo(pOperator, 4096); + if (pIntervalPhyNode->window.pExprs != NULL) { + int32_t numOfScalar = 0; + SExprInfo* pScalarExprInfo = createExprInfo(pIntervalPhyNode->window.pExprs, NULL, &numOfScalar); + int32_t code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + } + int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &numOfCols); SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); @@ -2945,8 +2903,8 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, pInfo->pPullDataRes = createPullDataBlock(); pInfo->ignoreExpiredData = pIntervalPhyNode->window.igExpired; // pInfo->pDelRes = createPullDataBlock(); // todo(liuyao) for delete - pInfo->pDelRes = createOneDataBlock(pInfo->binfo.pRes, false);// todo(liuyao) for delete - pInfo->pDelRes->info.type = STREAM_DELETE_RESULT;// todo(liuyao) for delete + pInfo->pDelRes = createOneDataBlock(pInfo->binfo.pRes, false); // todo(liuyao) for delete + pInfo->pDelRes->info.type = STREAM_DELETE_RESULT; // todo(liuyao) for delete pInfo->delIndex = 0; pInfo->pDelWins = taosArrayInit(4, sizeof(SWinRes)); @@ -3003,7 +2961,7 @@ void destroyStreamSessionAggOperatorInfo(void* param, int32_t numOfOutput) { taosMemoryFreeClear(pChInfo); } } - + taosMemoryFreeClear(param); } @@ -3057,6 +3015,14 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh } initResultSizeInfo(pOperator, 4096); + if (pSessionNode->window.pExprs != NULL) { + int32_t numOfScalar = 0; + SExprInfo* pScalarExprInfo = createExprInfo(pSessionNode->window.pExprs, NULL, &numOfScalar); + int32_t code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + } SExprSupp* pSup = &pOperator->exprSupp; code = initBasicInfoEx(&pInfo->binfo, pSup, pExprInfo, numOfCols, pResBlock); @@ -3092,8 +3058,8 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh pInfo->pStDeleted = taosHashInit(64, hashFn, true, HASH_NO_LOCK); pInfo->pDelIterator = NULL; // pInfo->pDelRes = createPullDataBlock(); - pInfo->pDelRes = createOneDataBlock(pInfo->binfo.pRes, false);// todo(liuyao) for delete - pInfo->pDelRes->info.type = STREAM_DELETE_RESULT;// todo(liuyao) for delete + pInfo->pDelRes = createOneDataBlock(pInfo->binfo.pRes, false); // todo(liuyao) for delete + pInfo->pDelRes->info.type = STREAM_DELETE_RESULT; // todo(liuyao) for delete pInfo->pChildren = NULL; pInfo->isFinal = false; pInfo->pPhyNode = pPhyNode; @@ -3146,9 +3112,7 @@ bool isInTimeWindow(STimeWindow* pWin, TSKEY ts, int64_t gap) { return false; } -bool isInWindow(SResultWindowInfo* pWinInfo, TSKEY ts, int64_t gap) { - return isInTimeWindow(&pWinInfo->win, ts, gap); -} +bool isInWindow(SResultWindowInfo* pWinInfo, TSKEY ts, int64_t gap) { return isInTimeWindow(&pWinInfo->win, ts, gap); } static SResultWindowInfo* insertNewSessionWindow(SArray* pWinInfos, TSKEY ts, int32_t index) { SResultWindowInfo win = {.pos.offset = -1, .pos.pageId = -1, .win.skey = ts, .win.ekey = ts, .isOutput = false}; @@ -3174,7 +3138,7 @@ SArray* getWinInfos(SStreamAggSupporter* pAggSup, uint64_t groupId) { // don't add new window SResultWindowInfo* getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId, - int64_t gap, int32_t* pIndex) { + int64_t gap, int32_t* pIndex) { SArray* pWinInfos = getWinInfos(pAggSup, groupId); pAggSup->pCurWins = pWinInfos; @@ -3183,7 +3147,7 @@ SResultWindowInfo* getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY start return NULL; } // find the first position which is smaller than the key - int32_t index = binarySearch(pWinInfos, size, startTs, TSDB_ORDER_DESC, getSessionWindowEndkey); + int32_t index = binarySearch(pWinInfos, size, startTs, TSDB_ORDER_DESC, getSessionWindowEndkey); SResultWindowInfo* pWin = NULL; if (index >= 0) { pWin = taosArrayGet(pWinInfos, index); @@ -3454,16 +3418,15 @@ void deleteWindow(SArray* pWinInfos, int32_t index) { static void doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, int64_t gap, SArray* result) { SColumnInfoData* pStartTsCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX); - TSKEY* startDatas = (TSKEY*)pStartTsCol->pData; + TSKEY* startDatas = (TSKEY*)pStartTsCol->pData; SColumnInfoData* pEndTsCol = taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX); - TSKEY* endDatas = (TSKEY*)pEndTsCol->pData; + TSKEY* endDatas = (TSKEY*)pEndTsCol->pData; SColumnInfoData* pGroupCol = taosArrayGet(pBlock->pDataBlock, UID_COLUMN_INDEX); - uint64_t* gpDatas = (uint64_t*)pGroupCol->pData; + uint64_t* gpDatas = (uint64_t*)pGroupCol->pData; for (int32_t i = 0; i < pBlock->info.rows; i++) { int32_t winIndex = 0; - while(1) { - SResultWindowInfo* pCurWin = - getCurSessionWindow(pAggSup, startDatas[i], endDatas[i], gpDatas[i], gap, &winIndex); + while (1) { + SResultWindowInfo* pCurWin = getCurSessionWindow(pAggSup, startDatas[i], endDatas[i], gpDatas[i], gap, &winIndex); if (!pCurWin) { break; } @@ -3513,6 +3476,7 @@ static int32_t copyUpdateResult(SHashObj* pStUpdated, SArray* pUpdated) { *(int64_t*)pos->key = ((SWinRes*)pData)->ts; taosArrayPush(pUpdated, &pos); } + taosArraySort(pUpdated, resultrowComparAsc); return TSDB_CODE_SUCCESS; } @@ -3695,8 +3659,8 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { if (pBlock->info.type == STREAM_CLEAR) { SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo)); - doClearSessionWindows(&pInfo->streamAggSup, &pOperator->exprSupp, pBlock, 0, pOperator->exprSupp.numOfExprs, - 0, pWins); + doClearSessionWindows(&pInfo->streamAggSup, &pOperator->exprSupp, pBlock, 0, pOperator->exprSupp.numOfExprs, 0, + pWins); if (IS_FINAL_OP(pInfo)) { int32_t childIndex = getChildIndex(pBlock); SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex); @@ -3727,6 +3691,10 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { continue; } + if (pInfo->scalarSupp.pExprInfo != NULL) { + SExprSupp* pExprSup = &pInfo->scalarSupp; + projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL); + } // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted, IS_FINAL_OP(pInfo)); @@ -3850,7 +3818,7 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) { break; } else if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT) { // gap must be 0 - doDeleteTimeWindows(&pInfo->streamAggSup, pBlock, 0, NULL); + doDeleteTimeWindows(&pInfo->streamAggSup, pBlock, 0, NULL); copyDataBlock(pInfo->pDelRes, pBlock); pInfo->pDelRes->info.type = STREAM_DELETE_RESULT; break; @@ -3859,6 +3827,10 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) { continue; } + if (pInfo->scalarSupp.pExprInfo != NULL) { + SExprSupp* pExprSup = &pInfo->scalarSupp; + projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL); + } // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted, false); @@ -4255,6 +4227,10 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) { continue; } + if (pInfo->scalarSupp.pExprInfo != NULL) { + SExprSupp* pExprSup = &pInfo->scalarSupp; + projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL); + } // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamStateAggImpl(pOperator, pBlock, pSeUpdated, pInfo->pSeDeleted); @@ -4308,6 +4284,15 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys pInfo->stateCol = extractColumnFromColumnNode(pColNode); initResultSizeInfo(pOperator, 4096); + if (pStateNode->window.pExprs != NULL) { + int32_t numOfScalar = 0; + SExprInfo* pScalarExprInfo = createExprInfo(pStateNode->window.pExprs, NULL, &numOfScalar); + int32_t code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + } + initResultRowInfo(&pInfo->binfo.resultRowInfo); pInfo->twAggSup = (STimeWindowAggSupp){ .waterMark = pStateNode->window.watermark, @@ -4338,8 +4323,8 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys pInfo->pSeDeleted = taosHashInit(64, hashFn, true, HASH_NO_LOCK); pInfo->pDelIterator = NULL; // pInfo->pDelRes = createPullDataBlock(); // todo(liuyao) for delete - pInfo->pDelRes = createOneDataBlock(pInfo->binfo.pRes, false);// todo(liuyao) for delete - pInfo->pDelRes->info.type = STREAM_DELETE_RESULT;// todo(liuyao) for delete + pInfo->pDelRes = createOneDataBlock(pInfo->binfo.pRes, false); // todo(liuyao) for delete + pInfo->pDelRes->info.type = STREAM_DELETE_RESULT; // todo(liuyao) for delete pInfo->pChildren = NULL; pInfo->ignoreExpiredData = pStateNode->window.igExpired; @@ -4368,17 +4353,6 @@ _error: return NULL; } -typedef struct SMergeAlignedIntervalAggOperatorInfo { - SIntervalAggOperatorInfo *intervalAggOperatorInfo; - - bool hasGroupId; - uint64_t groupId; - SSDataBlock* prefetchedBlock; - bool inputBlocksFinished; - - SNode* pCondition; -} SMergeAlignedIntervalAggOperatorInfo; - void destroyMergeAlignedIntervalOperatorInfo(void* param, int32_t numOfOutput) { SMergeAlignedIntervalAggOperatorInfo* miaInfo = (SMergeAlignedIntervalAggOperatorInfo*)param; destroyIntervalOperatorInfo(miaInfo->intervalAggOperatorInfo, numOfOutput); @@ -4534,7 +4508,8 @@ static SSDataBlock* doMergeAlignedIntervalAgg(SOperatorInfo* pOperator) { SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, - int32_t primaryTsSlotId, SNode* pCondition, SExecTaskInfo* pTaskInfo) { + int32_t primaryTsSlotId, SNode* pCondition, + SExecTaskInfo* pTaskInfo) { SMergeAlignedIntervalAggOperatorInfo* miaInfo = taosMemoryCalloc(1, sizeof(SMergeAlignedIntervalAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (miaInfo == NULL || pOperator == NULL) { @@ -4624,7 +4599,7 @@ void destroyMergeIntervalOperatorInfo(void* param, int32_t numOfOutput) { SMergeIntervalAggOperatorInfo* miaInfo = (SMergeIntervalAggOperatorInfo*)param; tdListFree(miaInfo->groupIntervals); destroyIntervalOperatorInfo(&miaInfo->intervalAggOperatorInfo, numOfOutput); - + taosMemoryFreeClear(param); } @@ -4666,7 +4641,7 @@ static int32_t outputPrevIntervalResult(SOperatorInfo* pOperatorInfo, uint64_t t continue; } STimeWindow* prevWin = &prevGrpWin->window; - if ((ascScan && newWin->skey > prevWin->ekey || (!ascScan) && newWin->skey < prevWin->ekey)) { + if ((ascScan && newWin->skey > prevWin->ekey) || ((!ascScan) && newWin->skey < prevWin->ekey)) { finalizeWindowResult(pOperatorInfo, tableGroupId, prevWin, pResultBlock); tdListPopNode(miaInfo->groupIntervals, listNode); } @@ -4691,8 +4666,8 @@ static void doMergeIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultRowInfo* TSKEY blockStartTs = getStartTsKey(&pBlock->info.window, tsCols); SResultRow* pResult = NULL; - STimeWindow win = getActiveTimeWindow(iaInfo->aggSup.pResultBuf, pResultRowInfo, blockStartTs, &iaInfo->interval, - iaInfo->interval.precision, &iaInfo->win); + STimeWindow win = + getActiveTimeWindow(iaInfo->aggSup.pResultBuf, pResultRowInfo, blockStartTs, &iaInfo->interval, iaInfo->order); int32_t ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pExprSup->pCtx, diff --git a/source/libs/executor/test/executorTests.cpp b/source/libs/executor/test/executorTests.cpp index 3c12889aca..bba4b254c5 100644 --- a/source/libs/executor/test/executorTests.cpp +++ b/source/libs/executor/test/executorTests.cpp @@ -1029,7 +1029,7 @@ TEST(testCase, external_sort_Test) { int64_t e = taosGetTimestampUs(); if (t++ == 1) { - printf("---------------elapsed:%ld\n", e - s); + printf("---------------elapsed:%" PRId64 "\n", e - s); } if (pRes == NULL) { @@ -1046,7 +1046,7 @@ TEST(testCase, external_sort_Test) { } int64_t s2 = taosGetTimestampUs(); - printf("total:%ld\n", s2 - s1); + printf("total:%" PRId64 "\n", s2 - s1); pOperator->closeFn(pOperator->info, 2); taosMemoryFreeClear(exp); @@ -1101,7 +1101,7 @@ TEST(testCase, sorted_merge_Test) { int64_t e = taosGetTimestampUs(); if (t++ == 1) { - printf("---------------elapsed:%ld\n", e - s); + printf("---------------elapsed:%" PRId64 "\n", e - s); } if (pRes == NULL) { @@ -1112,13 +1112,13 @@ TEST(testCase, sorted_merge_Test) { // SColumnInfoData* pCol2 = static_cast(taosArrayGet(pRes->pDataBlock, 1)); for (int32_t i = 0; i < pRes->info.rows; ++i) { // char* p = colDataGetData(pCol2, i); - printf("%d: %ld\n", total++, ((int64_t*)pCol1->pData)[i]); + printf("%d: %" PRId64 "\n", total++, ((int64_t*)pCol1->pData)[i]); // printf("%d: %d, %s\n", total++, ((int32_t*)pCol1->pData)[i], (char*)varDataVal(p)); } } int64_t s2 = taosGetTimestampUs(); - printf("total:%ld\n", s2 - s1); + printf("total:%" PRId64 "\n", s2 - s1); pOperator->closeFn(pOperator->info, 2); taosMemoryFreeClear(exp); @@ -1179,7 +1179,7 @@ TEST(testCase, time_interval_Operator_Test) { int64_t e = taosGetTimestampUs(); if (t++ == 1) { - printf("---------------elapsed:%ld\n", e - s); + printf("---------------elapsed:%" PRId64 "\n", e - s); } if (pRes == NULL) { @@ -1190,13 +1190,13 @@ TEST(testCase, time_interval_Operator_Test) { // SColumnInfoData* pCol2 = static_cast(taosArrayGet(pRes->pDataBlock, 1)); for (int32_t i = 0; i < pRes->info.rows; ++i) { // char* p = colDataGetData(pCol2, i); - printf("%d: %ld\n", total++, ((int64_t*)pCol1->pData)[i]); + printf("%d: %" PRId64 "\n", total++, ((int64_t*)pCol1->pData)[i]); // printf("%d: %d, %s\n", total++, ((int32_t*)pCol1->pData)[i], (char*)varDataVal(p)); } } int64_t s2 = taosGetTimestampUs(); - printf("total:%ld\n", s2 - s1); + printf("total:%" PRId64 "\n", s2 - s1); pOperator->closeFn(pOperator->info, 2); taosMemoryFreeClear(exp); diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 70def78263..6e244152f2 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -118,7 +118,7 @@ SSDataBlock* getSingleColDummyBlock(void* param) { } colDataAppend(pColInfo, i, result, false); - printf("int: %ld\n", v); + printf("int: %" PRId64 "\n", v); taosMemoryFree(result); } } @@ -333,7 +333,7 @@ TEST(testCase, external_mem_sort_Test) { }else{ memcpy((char*)(&result) + sizeof(int64_t) - tDataTypes[pInfo[i].type].bytes, v, tDataTypes[pInfo[i].type].bytes); } - printf("%d: %ld\n", row++, result); + printf("%d: %" PRId64 "\n", row++, result); } } taosArrayDestroy(orderInfo); diff --git a/source/libs/function/inc/fnLog.h b/source/libs/function/inc/fnLog.h index d8dd1d1e67..9658b6b782 100644 --- a/source/libs/function/inc/fnLog.h +++ b/source/libs/function/inc/fnLog.h @@ -14,7 +14,7 @@ extern "C" { #define fnFatal(...) { if (udfDebugFlag & DEBUG_FATAL) { taosPrintLog("UDF FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} #define fnError(...) { if (udfDebugFlag & DEBUG_ERROR) { taosPrintLog("UDF ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} #define fnWarn(...) { if (udfDebugFlag & DEBUG_WARN) { taosPrintLog("UDF WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} -#define fnInfo(...) { if (udfDebugFlag & DEBUG_INFO) { taosPrintLog("UDF ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define fnInfo(...) { if (udfDebugFlag & DEBUG_INFO) { taosPrintLog("UDF ", DEBUG_INFO, 255, __VA_ARGS__); }} #define fnDebug(...) { if (udfDebugFlag & DEBUG_DEBUG) { taosPrintLog("UDF ", DEBUG_DEBUG, udfDebugFlag, __VA_ARGS__); }} #define fnTrace(...) { if (udfDebugFlag & DEBUG_TRACE) { taosPrintLog("UDF ", DEBUG_TRACE, udfDebugFlag, __VA_ARGS__); }} // clang-format on diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 1e7e7e57c3..fc87ba964a 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -48,8 +48,8 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) { return TIME_UNIT_INVALID; } - if (TSDB_TIME_PRECISION_MILLI == dbPrec && (0 == strcasecmp(pVal->literal, "1u") || - 0 == strcasecmp(pVal->literal, "1b"))) { + if (TSDB_TIME_PRECISION_MILLI == dbPrec && + (0 == strcasecmp(pVal->literal, "1u") || 0 == strcasecmp(pVal->literal, "1b"))) { return TIME_UNIT_TOO_SMALL; } @@ -57,10 +57,9 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) { return TIME_UNIT_TOO_SMALL; } - if (pVal->literal[0] != '1' || (pVal->literal[1] != 'u' && pVal->literal[1] != 'a' && - pVal->literal[1] != 's' && pVal->literal[1] != 'm' && - pVal->literal[1] != 'h' && pVal->literal[1] != 'd' && - pVal->literal[1] != 'w' && pVal->literal[1] != 'b')) { + if (pVal->literal[0] != '1' || + (pVal->literal[1] != 'u' && pVal->literal[1] != 'a' && pVal->literal[1] != 's' && pVal->literal[1] != 'm' && + pVal->literal[1] != 'h' && pVal->literal[1] != 'd' && pVal->literal[1] != 'w' && pVal->literal[1] != 'b')) { return TIME_UNIT_INVALID; } @@ -678,9 +677,10 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (TSDB_DATA_TYPE_TIMESTAMP != paraType) { - return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + SNode* pPara1 = nodesListGetNode(pFunc->pParameterList, 0); + if (QUERY_NODE_COLUMN != nodeType(pPara1) || PRIMARYKEY_TIMESTAMP_COL_ID != ((SColumnNode*)pPara1)->colId) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "The first parameter of the ELAPSED function can only be the timestamp primary key"); } // param1 @@ -694,8 +694,7 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len pValue->notReserved = true; - paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if (!IS_INTEGER_TYPE(paraType)) { + if (!IS_INTEGER_TYPE(pValue->node.resType.type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -706,8 +705,9 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "ELAPSED function time unit parameter should be greater than db precision"); } else if (ret == TIME_UNIT_INVALID) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "ELAPSED function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); + return buildFuncErrMsg( + pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "ELAPSED function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); } } @@ -1229,7 +1229,8 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32 "STATEDURATION function time unit parameter should be greater than db precision"); } else if (ret == TIME_UNIT_INVALID) { return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "STATEDURATION function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); + "STATEDURATION function time unit parameter should be one of the following: [1b, 1u, 1a, " + "1s, 1m, 1h, 1d, 1w]"); } } @@ -1740,8 +1741,9 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_ return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "TIMETRUNCATE function time unit parameter should be greater than db precision"); } else if (ret == TIME_UNIT_INVALID) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); + return buildFuncErrMsg( + pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); } addDbPrecisonParam(&pFunc->pParameterList, dbPrec); @@ -1779,8 +1781,9 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "TIMEDIFF function time unit parameter should be greater than db precision"); } else if (ret == TIME_UNIT_INVALID) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "TIMEDIFF function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); + return buildFuncErrMsg( + pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "TIMEDIFF function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); } } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index d8fcca30c0..932bfb8793 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1863,8 +1863,6 @@ static void stddevTransferInfo(SStddevRes* pInput, SStddevRes* pOutput) { } pOutput->count += pInput->count; - - return; } int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx) { @@ -1874,14 +1872,13 @@ int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx) { SStddevRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SStddevRes* pInputInfo = (SStddevRes*)varDataVal(data); - - stddevTransferInfo(pInputInfo, pInfo); + for(int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) { + char* data = colDataGetData(pCol, i); + SStddevRes* pInputInfo = (SStddevRes*)varDataVal(data); + stddevTransferInfo(pInputInfo, pInfo); + } SET_VAL(GET_RES_INFO(pCtx), 1, 1); - return TSDB_CODE_SUCCESS; } @@ -3467,6 +3464,10 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS setBufPageDirty(pPage, true); releaseBufPage(pCtx->pBuf, pPage); +#ifdef BUF_PAGE_DEBUG + qDebug("page_saveTuple pos:%p,pageId:%d, offset:%d\n", pPos, pPos->pageId, + pPos->offset); +#endif } void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos) { @@ -3501,6 +3502,9 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS setBufPageDirty(pPage, true); releaseBufPage(pCtx->pBuf, pPage); +#ifdef BUF_PAGE_DEBUG + qDebug("page_copyTuple pos:%p, pageId:%d, offset:%d", pPos, pPos->pageId, pPos->offset); +#endif } int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 262adc5d6f..ed82654f77 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -139,7 +139,7 @@ bool fmIsAggFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MG bool fmIsScalarFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCALAR_FUNC); } -bool fmIsVectorFunc(int32_t funcId) { return !fmIsScalarFunc(funcId); } +bool fmIsVectorFunc(int32_t funcId) { return !fmIsScalarFunc(funcId) && !fmIsPseudoColumnFunc(funcId); } bool fmIsSelectFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SELECT_FUNC); } diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index dcf6676f9f..c16c3e3937 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -203,7 +203,7 @@ int32_t udfStartUdfd(int32_t startDnodeId) { uv_async_send(&pData->stopAsync); uv_thread_join(&pData->thread); pData->needCleanUp = false; - fnInfo("dnode udfd cleaned up after spawn err"); + fnInfo("udfd is cleaned up after spawn err"); } else { pData->needCleanUp = true; } @@ -212,7 +212,7 @@ int32_t udfStartUdfd(int32_t startDnodeId) { int32_t udfStopUdfd() { SUdfdData *pData = &udfdGlobal; - fnInfo("dnode to stop udfd. need cleanup: %d, spawn err: %d", + fnInfo("udfd start to stop, need cleanup:%d, spawn err:%d", pData->needCleanUp, pData->spawnErr); if (!pData->needCleanUp || atomic_load_32(&pData->stopCalled)) { return 0; @@ -225,7 +225,7 @@ int32_t udfStopUdfd() { #ifdef WINDOWS if (pData->jobHandle != NULL) CloseHandle(pData->jobHandle); #endif - fnInfo("dnode udfd cleaned up"); + fnInfo("udfd is cleaned up"); return 0; } @@ -467,7 +467,7 @@ int32_t getUdfdPipeName(char* pipeName, int32_t size) { size_t dnodeIdSize = sizeof(dnodeId); int32_t err = uv_os_getenv(UDF_DNODE_ID_ENV_NAME, dnodeId, &dnodeIdSize); if (err != 0) { - fnError("get dnode id from env. error: %s.", uv_err_name(err)); + fnError("failed to get dnodeId from env since %s", uv_err_name(err)); dnodeId[0] = '1'; } #ifdef _WIN32 @@ -475,7 +475,7 @@ int32_t getUdfdPipeName(char* pipeName, int32_t size) { #else snprintf(pipeName, size, "%s/%s%s", tsDataDir, UDF_LISTEN_PIPE_NAME_PREFIX, dnodeId); #endif - fnInfo("get dnode id from env. dnode id: %s. pipe path: %s", dnodeId, pipeName); + fnInfo("get dnodeId:%s from env, pipe path:%s", dnodeId, pipeName); return 0; } @@ -1609,7 +1609,7 @@ int32_t udfcClose() { taosArrayDestroy(udfc->udfStubs); uv_mutex_destroy(&udfc->udfStubsMutex); udfc->udfcState = UDFC_STATE_INITAL; - fnInfo("udfc cleaned up"); + fnInfo("udfc is cleaned up"); return 0; } diff --git a/source/libs/index/inc/indexFstCommon.h b/source/libs/index/inc/indexFstCommon.h index 8335e437fb..e15df5dc34 100644 --- a/source/libs/index/inc/indexFstCommon.h +++ b/source/libs/index/inc/indexFstCommon.h @@ -4,6 +4,7 @@ #include "tutil.h" extern const uint8_t COMMON_INPUTS[]; extern const char COMMON_INPUTS_INV[]; +extern const int32_t COMMON_INPUTS_LEN; #ifdef __cplusplus extern "C" { diff --git a/source/libs/index/inc/indexFstDfa.h b/source/libs/index/inc/indexFstDfa.h index f6c220bcb7..5a5622e280 100644 --- a/source/libs/index/inc/indexFstDfa.h +++ b/source/libs/index/inc/indexFstDfa.h @@ -29,16 +29,16 @@ extern "C" { typedef struct FstDfa FstDfa; typedef struct { - SArray * insts; + SArray *insts; uint32_t next[256]; bool isMatch; -} State; +} DfaState; /* * dfa builder related func **/ typedef struct FstDfaBuilder { - FstDfa * dfa; + FstDfa *dfa; SHashObj *cache; } FstDfaBuilder; @@ -51,7 +51,7 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder); bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t bytes, uint32_t *result); -bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result); +bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result); /* * dfa related func diff --git a/source/libs/index/inc/indexFstRegex.h b/source/libs/index/inc/indexFstRegex.h index 2bf9c9b791..2814b5dc16 100644 --- a/source/libs/index/inc/indexFstRegex.h +++ b/source/libs/index/inc/indexFstRegex.h @@ -65,6 +65,7 @@ typedef struct { } FstRegex; FstRegex *regexCreate(const char *str); +void regexDestroy(FstRegex *regex); uint32_t regexAutomStart(FstRegex *regex); bool regexAutomIsMatch(FstRegex *regex, uint32_t state); diff --git a/source/libs/index/inc/indexFstSparse.h b/source/libs/index/inc/indexFstSparse.h index 665fb2ba5c..bd704fb427 100644 --- a/source/libs/index/inc/indexFstSparse.h +++ b/source/libs/index/inc/indexFstSparse.h @@ -23,17 +23,18 @@ extern "C" { #endif typedef struct FstSparseSet { - uint32_t *dense; - uint32_t *sparse; - int32_t size; + int32_t *dense; + int32_t *sparse; + int32_t size; + int32_t cap; } FstSparseSet; FstSparseSet *sparSetCreate(int32_t sz); void sparSetDestroy(FstSparseSet *s); uint32_t sparSetLen(FstSparseSet *ss); -uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip); -uint32_t sparSetGet(FstSparseSet *ss, uint32_t i); -bool sparSetContains(FstSparseSet *ss, uint32_t ip); +bool sparSetAdd(FstSparseSet *ss, int32_t ip, int32_t *val); +bool sparSetGet(FstSparseSet *ss, int32_t i, int32_t *val); +bool sparSetContains(FstSparseSet *ss, int32_t ip); void sparSetClear(FstSparseSet *ss); #ifdef __cplusplus diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index 040e8ed830..05ce418037 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -22,7 +22,7 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later #define MEM_TERM_LIMIT 10 * 10000 -#define MEM_THRESHOLD 64 * 1024 +#define MEM_THRESHOLD 512 * 1024 #define MEM_SIGNAL_QUIT MEM_THRESHOLD * 20 #define MEM_ESTIMATE_RADIO 1.5 @@ -204,7 +204,6 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr if (0 == strcmp(c->colVal, pCt->colVal)) { if (c->operaType == ADD_VALUE) { INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid) - // taosArrayPush(result, &c->uid); *s = kTypeValue; } else if (c->operaType == DEL_VALUE) { INDEX_MERGE_ADD_DEL(tr->add, tr->del, c->uid) @@ -309,7 +308,6 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR if (cond == MATCH) { if (c->operaType == ADD_VALUE) { INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid) - // taosArrayPush(result, &c->uid); *s = kTypeValue; } else if (c->operaType == DEL_VALUE) { INDEX_MERGE_ADD_DEL(tr->add, tr->del, c->uid) diff --git a/source/libs/index/src/indexFst.c b/source/libs/index/src/indexFst.c index 81ac4c9d40..c4b83f8a07 100644 --- a/source/libs/index/src/indexFst.c +++ b/source/libs/index/src/indexFst.c @@ -1307,7 +1307,6 @@ FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) { taosArrayPush(sws->inp, &(trn.inp)); if (FST_NODE_IS_FINAL(nextNode)) { - // void *eofState = sws->aut->acceptEof(nextState); void* eofState = automFuncs[aut->type].acceptEof(aut, nextState); if (eofState != NULL) { isMatch = automFuncs[aut->type].isMatch(aut, eofState); diff --git a/source/libs/index/src/indexFstCommon.c b/source/libs/index/src/indexFstCommon.c index 902e68ce09..0b20157009 100644 --- a/source/libs/index/src/indexFstCommon.c +++ b/source/libs/index/src/indexFstCommon.c @@ -294,3 +294,4 @@ const char COMMON_INPUTS_INV[] = { '\xee', '\xef', '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff', }; +const int32_t COMMON_INPUTS_LEN = sizeof(COMMON_INPUTS) / sizeof(COMMON_INPUTS[0]); diff --git a/source/libs/index/src/indexFstDfa.c b/source/libs/index/src/indexFstDfa.c index 3011f124c9..046ed0f4f4 100644 --- a/source/libs/index/src/indexFstDfa.c +++ b/source/libs/index/src/indexFstDfa.c @@ -41,7 +41,7 @@ FstDfaBuilder *dfaBuilderCreate(SArray *insts) { return NULL; } - SArray *states = taosArrayInit(4, sizeof(State)); + SArray *states = taosArrayInit(4, sizeof(DfaState)); builder->dfa = dfaCreate(insts, states); builder->cache = taosHashInit( @@ -64,16 +64,16 @@ void dfaBuilderDestroy(FstDfaBuilder *builder) { taosMemoryFree(builder); } -FstDfa *dfaBuilder(FstDfaBuilder *builder) { +FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) { uint32_t sz = taosArrayGetSize(builder->dfa->insts); FstSparseSet *cur = sparSetCreate(sz); FstSparseSet *nxt = sparSetCreate(sz); dfaAdd(builder->dfa, cur, 0); - SArray * states = taosArrayInit(0, sizeof(uint32_t)); + SArray *states = taosArrayInit(0, sizeof(uint32_t)); uint32_t result; - if (dfaBuilderCachedState(builder, cur, &result)) { + if (dfaBuilderCacheState(builder, cur, &result)) { taosArrayPush(states, &result); } SHashObj *seen = taosHashInit(12, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); @@ -101,17 +101,18 @@ FstDfa *dfaBuilder(FstDfaBuilder *builder) { bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t byte, uint32_t *result) { sparSetClear(cur); - State *t = taosArrayGet(builder->dfa->states, state); + DfaState *t = taosArrayGet(builder->dfa->states, state); for (int i = 0; i < taosArrayGetSize(t->insts); i++) { - uint32_t ip = *(int32_t *)taosArrayGet(t->insts, i); - sparSetAdd(cur, ip); + int32_t ip = *(int32_t *)taosArrayGet(t->insts, i); + bool succ = sparSetAdd(cur, ip, NULL); + assert(succ == true); } dfaRun(builder->dfa, cur, next, byte); t = taosArrayGet(builder->dfa->states, state); uint32_t nxtState; - if (dfaBuilderCachedState(builder, next, &nxtState)) { + if (dfaBuilderCacheState(builder, next, &nxtState)) { t->next[byte] = nxtState; *result = nxtState; return true; @@ -119,12 +120,13 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet return false; } -bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) { +bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) { SArray *tinsts = taosArrayInit(4, sizeof(uint32_t)); bool isMatch = false; for (int i = 0; i < sparSetLen(set); i++) { - uint32_t ip = sparSetGet(set, i); + int32_t ip; + if (false == sparSetGet(set, i, &ip)) continue; Inst *inst = taosArrayGet(builder->dfa->insts, ip); if (inst->ty == JUMP || inst->ty == SPLIT) { @@ -144,7 +146,7 @@ bool dfaBuilderCachedState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t * *result = *v; taosArrayDestroy(tinsts); } else { - State st; + DfaState st; st.insts = tinsts; st.isMatch = isMatch; taosArrayPush(builder->dfa->states, &st); @@ -169,14 +171,14 @@ bool dfaIsMatch(FstDfa *dfa, uint32_t si) { if (dfa->states == NULL || si < taosArrayGetSize(dfa->states)) { return false; } - State *st = taosArrayGet(dfa->states, si); + DfaState *st = taosArrayGet(dfa->states, si); return st != NULL ? st->isMatch : false; } bool dfaAccept(FstDfa *dfa, uint32_t si, uint8_t byte, uint32_t *result) { if (dfa->states == NULL || si < taosArrayGetSize(dfa->states)) { return false; } - State *st = taosArrayGet(dfa->states, si); + DfaState *st = taosArrayGet(dfa->states, si); *result = st->next[byte]; return true; } @@ -184,7 +186,8 @@ void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) { if (sparSetContains(set, ip)) { return; } - sparSetAdd(set, ip); + bool succ = sparSetAdd(set, ip, NULL); + // assert(succ == true); Inst *inst = taosArrayGet(dfa->insts, ip); if (inst->ty == MATCH || inst->ty == RANGE) { // do nothing @@ -201,7 +204,8 @@ bool dfaRun(FstDfa *dfa, FstSparseSet *from, FstSparseSet *to, uint8_t byte) { bool isMatch = false; sparSetClear(to); for (int i = 0; i < sparSetLen(from); i++) { - uint32_t ip = sparSetGet(from, i); + int32_t ip; + if (false == sparSetGet(from, i, &ip)) continue; Inst *inst = taosArrayGet(dfa->insts, ip); if (inst->ty == JUMP || inst->ty == SPLIT) { diff --git a/source/libs/index/src/indexFstRegex.c b/source/libs/index/src/indexFstRegex.c index 33eeae802e..e148f211f2 100644 --- a/source/libs/index/src/indexFstRegex.c +++ b/source/libs/index/src/indexFstRegex.c @@ -22,20 +22,26 @@ FstRegex *regexCreate(const char *str) { if (regex == NULL) { return NULL; } - int32_t sz = (int32_t)strlen(str); - char * orig = taosMemoryCalloc(1, sz); - memcpy(orig, str, sz); - regex->orig = orig; + regex->orig = tstrdup(str); // construct insts based on str - SArray *insts = NULL; - + SArray *insts = taosArrayInit(256, sizeof(uint8_t)); + for (int i = 0; i < strlen(str); i++) { + uint8_t v = str[i]; + taosArrayPush(insts, &v); + } FstDfaBuilder *builder = dfaBuilderCreate(insts); regex->dfa = dfaBuilderBuild(builder); return regex; } +void regexDestroy(FstRegex *regex) { + if (regex == NULL) return; + taosMemoryFree(regex->orig); + taosMemoryFree(regex); +} + uint32_t regexAutomStart(FstRegex *regex) { ///// no nothing return 0; diff --git a/source/libs/index/src/indexFstSparse.c b/source/libs/index/src/indexFstSparse.c index 71d8854dcc..60eb7afd90 100644 --- a/source/libs/index/src/indexFstSparse.c +++ b/source/libs/index/src/indexFstSparse.c @@ -15,14 +15,24 @@ #include "indexFstSparse.h" +static void sparSetUtil(int32_t *buf, int32_t cap) { + for (int32_t i = 0; i < cap; i++) { + buf[i] = -1; + } +} FstSparseSet *sparSetCreate(int32_t sz) { FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet)); if (ss == NULL) { return NULL; } - ss->dense = (uint32_t *)taosMemoryCalloc(sz, sizeof(uint32_t)); - ss->sparse = (uint32_t *)taosMemoryCalloc(sz, sizeof(uint32_t)); + ss->dense = (int32_t *)taosMemoryMalloc(sz * sizeof(int32_t)); + ss->sparse = (int32_t *)taosMemoryMalloc(sz * sizeof(int32_t)); + sparSetUtil(ss->dense, sz); + sparSetUtil(ss->sparse, sz); + + ss->cap = sz; + ss->size = 0; return ss; } @@ -38,23 +48,39 @@ uint32_t sparSetLen(FstSparseSet *ss) { // Get occupied size return ss == NULL ? 0 : ss->size; } -uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip) { +bool sparSetAdd(FstSparseSet *ss, int32_t ip, int32_t *idx) { if (ss == NULL) { - return 0; + return false; + } + if (ip >= ss->cap || ip < 0) { + return false; } uint32_t i = ss->size; ss->dense[i] = ip; ss->sparse[ip] = i; ss->size += 1; - return i; + + if (idx != NULL) *idx = i; + + return true; } -uint32_t sparSetGet(FstSparseSet *ss, uint32_t i) { - // check later - return ss->dense[i]; +bool sparSetGet(FstSparseSet *ss, int32_t idx, int32_t *ip) { + if (idx >= ss->cap || idx >= ss->size || idx < 0) { + return false; + } + int32_t val = ss->dense[idx]; + if (ip != NULL) { + *ip = val; + } + return val == -1 ? false : true; } -bool sparSetContains(FstSparseSet *ss, uint32_t ip) { - uint32_t i = ss->sparse[ip]; - if (i < ss->size && ss->dense[i] == ip) { +bool sparSetContains(FstSparseSet *ss, int32_t ip) { + if (ip >= ss->cap || ip < 0) { + return false; + } + int32_t i = ss->sparse[ip]; + + if (i >= 0 && i < ss->cap && i < ss->size && ss->dense[i] == ip) { return true; } else { return false; @@ -64,5 +90,7 @@ void sparSetClear(FstSparseSet *ss) { if (ss == NULL) { return; } + sparSetUtil(ss->dense, ss->cap); + sparSetUtil(ss->sparse, ss->cap); ss->size = 0; } diff --git a/source/libs/index/test/CMakeLists.txt b/source/libs/index/test/CMakeLists.txt index 9a4b7bbad8..b3eca28003 100644 --- a/source/libs/index/test/CMakeLists.txt +++ b/source/libs/index/test/CMakeLists.txt @@ -4,6 +4,7 @@ IF(NOT TD_DARWIN) add_executable(idxFstUT "") add_executable(idxUtilUT "") add_executable(idxJsonUT "") + add_executable(idxFstUtilUT "") target_sources(idxTest PRIVATE @@ -23,6 +24,25 @@ IF(NOT TD_DARWIN) "utilUT.cc" ) + target_sources(idxJsonUT + PRIVATE + "jsonUT.cc" + ) + target_sources(idxFstUtilUT + PRIVATE + "fstUtilUT.cc" + ) + + target_include_directories (idxTest + PUBLIC + "${TD_SOURCE_DIR}/include/libs/index" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" + ) + target_include_directories (idxFstTest + PUBLIC + "${TD_SOURCE_DIR}/include/libs/index" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" + ) target_sources(idxJsonUT PRIVATE "jsonUT.cc" @@ -50,6 +70,38 @@ IF(NOT TD_DARWIN) "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) + target_include_directories (idxJsonUT + PUBLIC + "${TD_SOURCE_DIR}/include/libs/index" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" + ) + target_include_directories (idxFstUtilUT + PUBLIC + "${TD_SOURCE_DIR}/include/libs/index" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" + ) + + target_link_libraries (idxTest + os + util + common + gtest_main + index + ) + target_link_libraries (idxFstTest + os + util + common + gtest_main + index + ) + target_link_libraries (idxFstUT + os + util + common + gtest_main + index + ) target_include_directories (idxJsonUT PUBLIC "${TD_SOURCE_DIR}/include/libs/index" @@ -92,15 +144,28 @@ IF(NOT TD_DARWIN) gtest_main index ) + target_link_libraries (idxFstUtilUT + os + util + common + gtest_main + index + ) + + add_test( + NAME idxJsonUT + COMMAND idxJsonUT + ) + add_test( + NAME idxFstUtilUT + COMMAND idxFstUtilUT + + ) add_test( NAME idxtest COMMAND idxTest ) - add_test( - NAME idxJsonUT - COMMAND idxJsonUT - ) add_test( NAME idxUtilUT COMMAND idxUtilUT @@ -109,4 +174,4 @@ IF(NOT TD_DARWIN) NAME idxFstUT COMMAND idxFstUT ) -ENDIF () \ No newline at end of file +ENDIF () diff --git a/source/libs/index/test/fstUtilUT.cc b/source/libs/index/test/fstUtilUT.cc new file mode 100644 index 0000000000..593a312c9e --- /dev/null +++ b/source/libs/index/test/fstUtilUT.cc @@ -0,0 +1,112 @@ + +#include +#include +#include +#include +#include +#include +#include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstDfa.h" +#include "indexFstRegex.h" +#include "indexFstSparse.h" +#include "indexFstUtil.h" +#include "indexInt.h" +#include "indexTfile.h" +#include "tglobal.h" +#include "tlog.h" +#include "tskiplist.h" +#include "tutil.h" +class FstUtilEnv : public ::testing::Test { + protected: + virtual void SetUp() { + SArray *inst = taosArrayInit(4, sizeof(char)); + builder = dfaBuilderCreate(inst); + } + virtual void TearDown() { dfaBuilderDestroy(builder); } + + FstDfaBuilder *builder; +}; + +class FstRegexEnv : public ::testing::Test { + protected: + virtual void SetUp() { regex = regexCreate("test"); } + virtual void TearDown() { regexDestroy(regex); } + FstRegex *regex; +}; + +class FstSparseSetEnv : public ::testing::Test { + protected: + virtual void SetUp() { set = sparSetCreate(256); } + virtual void TearDown() { + // tear down + sparSetDestroy(set); + } + void ReBuild(int32_t sz) { + sparSetDestroy(set); + set = sparSetCreate(sz); + } + FstSparseSet *set; +}; + +// test FstDfaBuilder +TEST_F(FstUtilEnv, test1) { + // test +} +TEST_F(FstUtilEnv, test2) { + // test +} +TEST_F(FstUtilEnv, test3) { + // test +} +TEST_F(FstUtilEnv, test4) { + // test +} + +// test FstRegex + +TEST_F(FstRegexEnv, test1) { + // + EXPECT_EQ(regex != NULL, true); +} +TEST_F(FstRegexEnv, test2) {} +TEST_F(FstRegexEnv, test3) {} +TEST_F(FstRegexEnv, test4) {} + +// test FstSparseSet +TEST_F(FstSparseSetEnv, test1) { + for (int8_t i = 0; i < 20; i++) { + int32_t val = -1; + bool succ = sparSetAdd(set, 'a' + i, &val); + } + EXPECT_EQ(sparSetLen(set), 20); + for (int8_t i = 0; i < 20; i++) { + int val = -1; + bool find = sparSetGet(set, i, &val); + EXPECT_EQ(find, true); + EXPECT_EQ(val, i + 'a'); + } + for (int8_t i = 'a'; i < 'a' + 20; i++) { + EXPECT_EQ(sparSetContains(set, i), true); + } + + for (int8_t i = 'A'; i < 20; i++) { + EXPECT_EQ(sparSetContains(set, 'A'), false); + } + + for (int i = 512; i < 1000; i++) { + EXPECT_EQ(sparSetAdd(set, i, NULL), false); + + EXPECT_EQ(sparSetGet(set, i, NULL), false); + EXPECT_EQ(sparSetContains(set, i), false); + } + sparSetClear(set); + + for (int i = 'a'; i < 'a' + 20; i++) { + EXPECT_EQ(sparSetGet(set, i, NULL), false); + } + for (int i = 1000; i < 2000; i++) { + EXPECT_EQ(sparSetGet(set, i, NULL), false); + } +} diff --git a/source/libs/index/test/utilUT.cc b/source/libs/index/test/utilUT.cc index ab5128cd3e..323a6b4afa 100644 --- a/source/libs/index/test/utilUT.cc +++ b/source/libs/index/test/utilUT.cc @@ -8,6 +8,7 @@ #include "indexCache.h" #include "indexComm.h" #include "indexFst.h" +#include "indexFstCommon.h" #include "indexFstUtil.h" #include "indexInt.h" #include "indexTfile.h" @@ -356,3 +357,11 @@ TEST_F(UtilEnv, TempResultExcept) { idxTRsltMergeTo(relt, f); EXPECT_EQ(taosArrayGetSize(f), 1); } + +TEST_F(UtilEnv, testDictComm) { + int32_t count = COMMON_INPUTS_LEN; + for (int i = 0; i < 256; i++) { + uint8_t v = COMMON_INPUTS_INV[i]; + EXPECT_EQ(COMMON_INPUTS[v], i); + } +} diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 5d5e95cd2b..294488a38d 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -543,11 +543,40 @@ static int32_t jsonToLogicPlanNode(const SJson* pJson, void* pObj) { static const char* jkScanLogicPlanScanCols = "ScanCols"; static const char* jkScanLogicPlanScanPseudoCols = "ScanPseudoCols"; -static const char* jkScanLogicPlanTableId = "TableId"; static const char* jkScanLogicPlanTableType = "TableType"; +static const char* jkScanLogicPlanTableId = "TableId"; +static const char* jkScanLogicPlanStableId = "StableId"; +static const char* jkScanLogicPlanScanCount = "ScanCount"; +static const char* jkScanLogicPlanReverseScanCount = "ReverseScanCount"; static const char* jkScanLogicPlanTagCond = "TagCond"; static const char* jkScanLogicPlanGroupTags = "GroupTags"; +// typedef struct SScanLogicNode { +// uint64_t stableId; +// SVgroupsInfo* pVgroupList; +// EScanType scanType; +// uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count +// STimeWindow scanRange; +// SName tableName; +// bool showRewrite; +// double ratio; +// SNodeList* pDynamicScanFuncs; +// int32_t dataRequired; +// int64_t interval; +// int64_t offset; +// int64_t sliding; +// int8_t intervalUnit; +// int8_t slidingUnit; +// SNode* pTagCond; +// SNode* pTagIndexCond; +// int8_t triggerType; +// int64_t watermark; +// int8_t igExpired; +// SArray* pSmaIndexes; +// SNodeList* pGroupTags; +// bool groupSort; +// } SScanLogicNode; + static int32_t logicScanNodeToJson(const void* pObj, SJson* pJson) { const SScanLogicNode* pNode = (const SScanLogicNode*)pObj; @@ -558,11 +587,20 @@ static int32_t logicScanNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkScanLogicPlanScanPseudoCols, pNode->pScanPseudoCols); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanTableType, pNode->tableType); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanTableId, pNode->tableId); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanTableType, pNode->tableType); + code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanStableId, pNode->stableId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanScanCount, pNode->scanSeq[0]); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkScanLogicPlanReverseScanCount, pNode->scanSeq[1]); } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkScanLogicPlanTagCond, nodeToJson, pNode->pTagCond); @@ -585,11 +623,20 @@ static int32_t jsonToLogicScanNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkScanLogicPlanScanPseudoCols, &pNode->pScanPseudoCols); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetTinyIntValue(pJson, jkScanLogicPlanTableType, &pNode->tableType); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetUBigIntValue(pJson, jkScanLogicPlanTableId, &pNode->tableId); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetTinyIntValue(pJson, jkScanLogicPlanTableType, &pNode->tableType); + code = tjsonGetUBigIntValue(pJson, jkScanLogicPlanStableId, &pNode->stableId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUTinyIntValue(pJson, jkScanLogicPlanScanCount, &pNode->scanSeq[0]); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUTinyIntValue(pJson, jkScanLogicPlanReverseScanCount, &pNode->scanSeq[1]); } if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkScanLogicPlanTagCond, &pNode->pTagCond); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index e15375e6ef..897b575e10 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -105,6 +105,8 @@ SNode* nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SAlterDatabaseStmt)); case QUERY_NODE_FLUSH_DATABASE_STMT: return makeNode(type, sizeof(SFlushDatabaseStmt)); + case QUERY_NODE_TRIM_DATABASE_STMT: + return makeNode(type, sizeof(STrimDatabaseStmt)); case QUERY_NODE_CREATE_TABLE_STMT: return makeNode(type, sizeof(SCreateTableStmt)); case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: @@ -548,6 +550,7 @@ void nodesDestroyNode(SNode* pNode) { nodesDestroyNode((SNode*)((SAlterDatabaseStmt*)pNode)->pOptions); break; case QUERY_NODE_FLUSH_DATABASE_STMT: // no pointer field + case QUERY_NODE_TRIM_DATABASE_STMT: // no pointer field break; case QUERY_NODE_CREATE_TABLE_STMT: { SCreateTableStmt* pStmt = (SCreateTableStmt*)pNode; @@ -1790,7 +1793,7 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) { } else if (pCol->hasIndex) { pCxt->hasTagIndexCol = true; pCxt->hasTagCol = true; - } else if (COLUMN_TYPE_TAG == pCol->colType) { + } else if (COLUMN_TYPE_TAG == pCol->colType || COLUMN_TYPE_TBNAME == pCol->colType) { pCxt->hasTagCol = true; } else { pCxt->hasOtherCol = true; diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index ee60a14da9..59fc69f768 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -137,6 +137,7 @@ SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, STok SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); SNode* createFlushDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); +SNode* createTrimDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createDefaultTableOptions(SAstCreateContext* pCxt); SNode* createAlterTableOptions(SAstCreateContext* pCxt); SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index fd79eaa9b7..cd0b5c1d6c 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -158,6 +158,7 @@ cmd ::= DROP DATABASE exists_opt(A) db_name(B). cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); } cmd ::= ALTER DATABASE db_name(A) alter_db_options(B). { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); } cmd ::= FLUSH DATABASE db_name(A). { pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &A); } +cmd ::= TRIM DATABASE db_name(A). { pCxt->pRootNode = createTrimDatabaseStmt(pCxt, &A); } %type not_exists_opt { bool } %destructor not_exists_opt { } @@ -769,7 +770,7 @@ compare_op(A) ::= CONTAINS. in_op(A) ::= IN. { A = OP_TYPE_IN; } in_op(A) ::= NOT IN. { A = OP_TYPE_NOT_IN; } -in_predicate_value(A) ::= NK_LP(C) expression_list(B) NK_RP(D). { A = createRawExprNodeExt(pCxt, &C, &D, createNodeListNode(pCxt, B)); } +in_predicate_value(A) ::= NK_LP(C) literal_list(B) NK_RP(D). { A = createRawExprNodeExt(pCxt, &C, &D, createNodeListNode(pCxt, B)); } /************************************************ boolean_value_expression ********************************************/ boolean_value_expression(A) ::= boolean_primary(B). { A = B; } @@ -934,7 +935,11 @@ query_expression_body(A) ::= query_primary(A) ::= query_specification(B). { A = B; } query_primary(A) ::= NK_LP query_expression_body(B) - order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { A = B; } + order_by_clause_opt(C) slimit_clause_opt(D) limit_clause_opt(E) NK_RP. { + A = addOrderByClause(pCxt, B, C); + A = addSlimitClause(pCxt, A, D); + A = addLimitClause(pCxt, A, E); + } %type order_by_clause_opt { SNodeList* } %destructor order_by_clause_opt { nodesDestroyList($$); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index ab73204fb7..c60e5541e0 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -339,6 +339,10 @@ SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) { SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) { CHECK_PARSER_STATUS(pCxt); + if (NULL == pCxt->pQueryCxt->pStmtCb) { + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z); + return NULL; + } SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); CHECK_OUT_OF_MEM(val); val->literal = strndup(pLiteral->z, pLiteral->n); @@ -665,6 +669,9 @@ SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving) { SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList) { CHECK_PARSER_STATUS(pCxt); + if (NULL == pOrderByList) { + return pStmt; + } if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { ((SSelectStmt*)pStmt)->pOrderByList = pOrderByList; } else { @@ -675,6 +682,9 @@ SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrder SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) { CHECK_PARSER_STATUS(pCxt); + if (NULL == pSlimit) { + return pStmt; + } if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { ((SSelectStmt*)pStmt)->pSlimit = (SLimitNode*)pSlimit; } @@ -683,6 +693,9 @@ SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) { SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit) { CHECK_PARSER_STATUS(pCxt); + if (NULL == pLimit) { + return pStmt; + } if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { ((SSelectStmt*)pStmt)->pLimit = (SLimitNode*)pLimit; } else { @@ -746,8 +759,8 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) { SDatabaseOptions* pOptions = (SDatabaseOptions*)nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS); CHECK_OUT_OF_MEM(pOptions); pOptions->buffer = TSDB_DEFAULT_BUFFER_PER_VNODE; - pOptions->cacheLast = TSDB_DEFAULT_CACHE_LAST_ROW; - pOptions->cacheLastSize = TSDB_DEFAULT_LAST_ROW_MEM; + pOptions->cacheLast = TSDB_DEFAULT_CACHE_LAST; + pOptions->cacheLastSize = TSDB_DEFAULT_CACHE_LAST_SIZE; pOptions->compressionLevel = TSDB_DEFAULT_COMP_LEVEL; pOptions->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; pOptions->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; @@ -922,7 +935,18 @@ SNode* createFlushDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) { if (!checkDbName(pCxt, pDbName, false)) { return NULL; } - SAlterDatabaseStmt* pStmt = (SAlterDatabaseStmt*)nodesMakeNode(QUERY_NODE_FLUSH_DATABASE_STMT); + SFlushDatabaseStmt* pStmt = (SFlushDatabaseStmt*)nodesMakeNode(QUERY_NODE_FLUSH_DATABASE_STMT); + CHECK_OUT_OF_MEM(pStmt); + COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName); + return (SNode*)pStmt; +} + +SNode* createTrimDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) { + CHECK_PARSER_STATUS(pCxt); + if (!checkDbName(pCxt, pDbName, false)) { + return NULL; + } + STrimDatabaseStmt* pStmt = (STrimDatabaseStmt*)nodesMakeNode(QUERY_NODE_TRIM_DATABASE_STMT); CHECK_OUT_OF_MEM(pStmt); COPY_STRING_FORM_ID_TOKEN(pStmt->dbName, pDbName); return (SNode*)pStmt; diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index f38def0b1d..2060c3da4c 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -270,6 +270,9 @@ static int32_t collectMetaKeyFromCreateIndex(SCollectMetaKeyCxt* pCxt, SCreateIn if (TSDB_CODE_SUCCESS == code) { code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, pCxt->pMetaCache); } + if (TSDB_CODE_SUCCESS == code) { + code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, pCxt->pMetaCache); + } } return code; } diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 6c670b3f01..4dff42592a 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -195,8 +195,8 @@ static int32_t calcConstProject(SNode* pProject, SNode** pNew) { return code; } -static bool isUselessCol(bool hasSelectValFunc, SExprNode* pProj) { - if (hasSelectValFunc && QUERY_NODE_FUNCTION == nodeType(pProj) && fmIsSelectFunc(((SFunctionNode*)pProj)->funcId)) { +static bool isUselessCol(SExprNode* pProj) { + if (QUERY_NODE_FUNCTION == nodeType(pProj) && !fmIsScalarFunc(((SFunctionNode*)pProj)->funcId)) { return false; } return NULL == ((SExprNode*)pProj)->pAssociation; @@ -218,7 +218,7 @@ static SNode* createConstantValue() { static int32_t calcConstProjections(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { SNode* pProj = NULL; WHERE_EACH(pProj, pSelect->pProjectionList) { - if (subquery && isUselessCol(pSelect->hasSelectValFunc, (SExprNode*)pProj)) { + if (subquery && isUselessCol((SExprNode*)pProj)) { ERASE_NODE(pSelect->pProjectionList); continue; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index a5cf755a74..2494c5a8a7 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -120,86 +120,6 @@ static int32_t skipInsertInto(char** pSql, SMsgBuf* pMsg) { return TSDB_CODE_SUCCESS; } -static int32_t parserValidateIdToken(SToken* pToken) { - if (pToken == NULL || pToken->z == NULL || pToken->type != TK_NK_ID) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - // it is a token quoted with escape char '`' - if (pToken->z[0] == TS_ESCAPE_CHAR && pToken->z[pToken->n - 1] == TS_ESCAPE_CHAR) { - return TSDB_CODE_SUCCESS; - } - - char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); - if (sep == NULL) { // It is a single part token, not a complex type - if (isNumber(pToken)) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - strntolower(pToken->z, pToken->z, pToken->n); - } else { // two part - int32_t oldLen = pToken->n; - char* pStr = pToken->z; - - if (pToken->type == TK_NK_SPACE) { - pToken->n = (uint32_t)strtrim(pToken->z); - } - - pToken->n = tGetToken(pToken->z, &pToken->type); - if (pToken->z[pToken->n] != TS_PATH_DELIMITER[0]) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - if (pToken->type != TK_NK_ID) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - int32_t firstPartLen = pToken->n; - - pToken->z = sep + 1; - pToken->n = (uint32_t)(oldLen - (sep - pStr) - 1); - int32_t len = tGetToken(pToken->z, &pToken->type); - if (len != pToken->n || pToken->type != TK_NK_ID) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - // re-build the whole name string - if (pStr[firstPartLen] == TS_PATH_DELIMITER[0]) { - // first part do not have quote do nothing - } else { - pStr[firstPartLen] = TS_PATH_DELIMITER[0]; - memmove(&pStr[firstPartLen + 1], pToken->z, pToken->n); - uint32_t offset = (uint32_t)(pToken->z - (pStr + firstPartLen + 1)); - memset(pToken->z + pToken->n - offset, ' ', offset); - } - - pToken->n += (firstPartLen + sizeof(TS_PATH_DELIMITER[0])); - pToken->z = pStr; - - strntolower(pToken->z, pToken->z, pToken->n); - } - - return TSDB_CODE_SUCCESS; -} - -static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullDbName, char* tableName) { - if (parserValidateIdToken(pStname) != TSDB_CODE_SUCCESS) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid table name", pStname->z); - } - - char* p = strnchr(pStname->z, TS_PATH_DELIMITER[0], pStname->n, false); - if (NULL != p) { // db.table - int32_t n = sprintf(fullDbName, "%d.", pCxt->pComCxt->acctId); - strncpy(fullDbName + n, pStname->z, p - pStname->z); - strncpy(tableName, p + 1, pStname->n - (p - pStname->z) - 1); - } else { - snprintf(fullDbName, TSDB_DB_FNAME_LEN, "%d.%s", pCxt->pComCxt->acctId, pCxt->pComCxt->db); - strncpy(tableName, pStname->z, pStname->n); - } - - return TSDB_CODE_SUCCESS; -} - static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, const char* dbName, SMsgBuf* pMsgBuf) { const char* msg1 = "name too long"; const char* msg2 = "invalid database name"; @@ -978,11 +898,11 @@ static int32_t parseTagToken(char** end, SToken* pToken, SSchema* pSchema, int16 case TSDB_DATA_TYPE_NCHAR: { int32_t output = 0; - void* p = taosMemoryCalloc(1, pToken->n * TSDB_NCHAR_SIZE); + void* p = taosMemoryCalloc(1, pSchema->bytes - VARSTR_HEADER_SIZE); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), pToken->n * TSDB_NCHAR_SIZE, &output)) { + if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), pSchema->bytes - VARSTR_HEADER_SIZE, &output)) { if (errno == E2BIG) { taosMemoryFree(p); return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 920921a3b3..58f6354402 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -216,6 +216,7 @@ static SKeyword keywordTable[] = { {"TRANSACTION", TK_TRANSACTION}, {"TRANSACTIONS", TK_TRANSACTIONS}, {"TRIGGER", TK_TRIGGER}, + {"TRIM", TK_TRIM}, {"TSERIES", TK_TSERIES}, {"TTL", TK_TTL}, {"UNION", TK_UNION}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 0fbeac47e6..f417f0e084 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -77,14 +77,6 @@ static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { return TSDB_CODE_SUCCESS; } -static SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName* pName) { - pName->type = TSDB_TABLE_NAME_T; - pName->acctId = acctId; - strcpy(pName->dbname, pDbName); - strcpy(pName->tname, pTableName); - return pName; -} - static int32_t collectUseDatabaseImpl(const char* pFullDbName, SHashObj* pDbs) { SFullDatabaseName name = {0}; strcpy(name.fullDbName, pFullDbName); @@ -469,12 +461,10 @@ static bool isDistinctOrderBy(STranslateContext* pCxt) { ((SSelectStmt*)pCxt->pCurrStmt)->isDistinct); } -static bool belongTable(const char* currentDb, const SColumnNode* pCol, const STableNode* pTable) { +static bool belongTable(const SColumnNode* pCol, const STableNode* pTable) { int cmp = 0; if ('\0' != pCol->dbName[0]) { cmp = strcmp(pCol->dbName, pTable->dbName); - } else { - cmp = (QUERY_NODE_REAL_TABLE == nodeType(pTable) ? strcmp(currentDb, pTable->dbName) : 0); } if (0 == cmp) { cmp = strcmp(pCol->tableAlias, pTable->tableAlias); @@ -638,7 +628,7 @@ static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode** bool foundTable = false; for (size_t i = 0; i < nums; ++i) { STableNode* pTable = taosArrayGetP(pTables, i); - if (belongTable(pCxt->pParseCxt->db, (*pCol), pTable)) { + if (belongTable((*pCol), pTable)) { foundTable = true; bool foundCol = false; pCxt->errCode = findAndSetColumn(pCxt, pCol, pTable, &foundCol); @@ -962,6 +952,10 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { return translateValueImpl(pCxt, pVal, dt, false); } +static int32_t doTranslateValue(STranslateContext* pCxt, SValueNode* pVal) { + return DEAL_RES_ERROR == translateValue(pCxt, pVal) ? pCxt->errCode : TSDB_CODE_SUCCESS; +} + static bool isMultiResFunc(SNode* pNode) { if (NULL == pNode) { return false; @@ -977,131 +971,11 @@ static bool isMultiResFunc(SNode* pNode) { return (QUERY_NODE_COLUMN == nodeType(pParam) ? 0 == strcmp(((SColumnNode*)pParam)->colName, "*") : false); } -static int32_t rewriteNegativeOperator(SNode** pOp) { - SNode* pRes = NULL; - int32_t code = scalarCalculateConstants(*pOp, &pRes); - if (TSDB_CODE_SUCCESS == code) { - *pOp = pRes; - } - return code; -} - -static EDealRes translateUnaryOperator(STranslateContext* pCxt, SOperatorNode** pOpRef) { - SOperatorNode* pOp = *pOpRef; - if (OP_TYPE_MINUS == pOp->opType) { - if (!IS_MATHABLE_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pLeft))->aliasName); - } - pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; - pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - - pCxt->errCode = rewriteNegativeOperator((SNode**)pOpRef); - } else { - pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; - pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; - } - return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR; -} - -static EDealRes translateArithmeticOperator(STranslateContext* pCxt, SOperatorNode* pOp) { - SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; - SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; - if (TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_BLOB == rdt.type) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); - } - if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) || - (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) || - (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); - } - - if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && IS_INTEGER_TYPE(rdt.type)) || - (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && IS_INTEGER_TYPE(ldt.type)) || - (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_BOOL == rdt.type) || - (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && TSDB_DATA_TYPE_BOOL == ldt.type)) { - pOp->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP; - pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; - } else { - pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; - pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - } - return DEAL_RES_CONTINUE; -} - static bool dataTypeEqual(const SDataType* l, const SDataType* r) { return (l->type == r->type && l->bytes == r->bytes && l->precision == r->precision && l->scale == r->scale); } -static EDealRes translateComparisonOperator(STranslateContext* pCxt, SOperatorNode* pOp) { - SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; - SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; - if (TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_BLOB == rdt.type) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); - } - if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) { - SNodeListNode* pRight = (SNodeListNode*)pOp->pRight; - bool first = true; - SDataType targetDt = {0}; - SNode* pNode = NULL; - FOREACH(pNode, pRight->pNodeList) { - SDataType dt = ((SExprNode*)pNode)->resType; - if (first) { - targetDt = dt; - if (targetDt.type != TSDB_DATA_TYPE_NULL) { - first = false; - } - } else if (dt.type != targetDt.type && dt.type != TSDB_DATA_TYPE_NULL) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)pNode)->aliasName); - } else if (dt.bytes > targetDt.bytes) { - targetDt.bytes = dt.bytes; - } - } - pRight->dataType = targetDt; - } - if (nodesIsRegularOp(pOp)) { - if (!IS_VAR_DATA_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pLeft))->aliasName); - } - if (QUERY_NODE_VALUE != nodeType(pOp->pRight) || - ((!IS_STR_DATA_TYPE(((SExprNode*)(pOp->pRight))->resType.type)) && - (((SExprNode*)(pOp->pRight))->resType.type != TSDB_DATA_TYPE_NULL))) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); - } - } - pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; - pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; - return DEAL_RES_CONTINUE; -} - -static EDealRes translateJsonOperator(STranslateContext* pCxt, SOperatorNode* pOp) { - SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; - SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; - if (TSDB_DATA_TYPE_JSON != ldt.type || TSDB_DATA_TYPE_BINARY != rdt.type) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); - } - if (pOp->opType == OP_TYPE_JSON_GET_VALUE) { - pOp->node.resType.type = TSDB_DATA_TYPE_JSON; - } else if (pOp->opType == OP_TYPE_JSON_CONTAINS) { - pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; - } - pOp->node.resType.bytes = tDataTypes[pOp->node.resType.type].bytes; - return DEAL_RES_CONTINUE; -} - -static EDealRes translateBitwiseOperator(STranslateContext* pCxt, SOperatorNode* pOp) { - SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; - SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; - if (TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_BLOB == rdt.type) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); - } - pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT; - pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; - return DEAL_RES_CONTINUE; -} - -static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode** pOpRef) { - SOperatorNode* pOp = *pOpRef; - +static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { if (isMultiResFunc(pOp->pLeft)) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pLeft))->aliasName); } @@ -1109,17 +983,10 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode** pOpRe return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); } - if (nodesIsUnaryOp(pOp)) { - return translateUnaryOperator(pCxt, pOpRef); - } else if (nodesIsArithmeticOp(pOp)) { - return translateArithmeticOperator(pCxt, pOp); - } else if (nodesIsComparisonOp(pOp)) { - return translateComparisonOperator(pCxt, pOp); - } else if (nodesIsJsonOp(pOp)) { - return translateJsonOperator(pCxt, pOp); - } else if (nodesIsBitwiseOp(pOp)) { - return translateBitwiseOperator(pCxt, pOp); + if (TSDB_CODE_SUCCESS != scalarGetOperatorResultType(pOp)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pOp->node.aliasName); } + return DEAL_RES_CONTINUE; } @@ -1317,6 +1184,12 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) { pSelect->hasAggFuncs = pSelect->hasAggFuncs ? true : fmIsAggFunc(pFunc->funcId); pSelect->hasRepeatScanFuncs = pSelect->hasRepeatScanFuncs ? true : fmIsRepeatScanFunc(pFunc->funcId); pSelect->hasIndefiniteRowsFunc = pSelect->hasIndefiniteRowsFunc ? true : fmIsIndefiniteRowsFunc(pFunc->funcId); + if (fmIsSelectFunc(pFunc->funcId)) { + pSelect->hasSelectFunc = true; + ++(pSelect->selectFuncNum); + } else if (fmIsVectorFunc(pFunc->funcId)) { + pSelect->hasOtherVectorFunc = true; + } pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType); pSelect->hasTailFunc = pSelect->hasTailFunc ? true : (FUNCTION_TYPE_TAIL == pFunc->funcType); pSelect->hasInterpFunc = pSelect->hasInterpFunc ? true : (FUNCTION_TYPE_INTERP == pFunc->funcType); @@ -1485,7 +1358,7 @@ static EDealRes doTranslateExpr(SNode** pNode, void* pContext) { case QUERY_NODE_VALUE: return translateValue(pCxt, (SValueNode*)*pNode); case QUERY_NODE_OPERATOR: - return translateOperator(pCxt, (SOperatorNode**)pNode); + return translateOperator(pCxt, (SOperatorNode*)*pNode); case QUERY_NODE_FUNCTION: return translateFunction(pCxt, (SFunctionNode**)pNode); case QUERY_NODE_LOGIC_CONDITION: @@ -1526,16 +1399,12 @@ static int32_t getGroupByErrorCode(STranslateContext* pCxt) { if (isDistinctOrderBy(pCxt)) { return TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION; } - return TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION; + if (isSelectStmt(pCxt->pCurrStmt) && NULL != ((SSelectStmt*)pCxt->pCurrStmt)->pGroupByList) { + return TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION; + } + return TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN; } -typedef struct SCheckExprForGroupByCxt { - STranslateContext* pTranslateCxt; - int32_t selectFuncNum; - bool hasSelectValFunc; - bool hasOtherAggFunc; -} SCheckExprForGroupByCxt; - static EDealRes rewriteColToSelectValFunc(STranslateContext* pCxt, SNode** pNode) { SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); if (NULL == pFunc) { @@ -1557,68 +1426,68 @@ static EDealRes rewriteColToSelectValFunc(STranslateContext* pCxt, SNode** pNode return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR; } +static EDealRes rewriteExprToGroupKeyFunc(STranslateContext* pCxt, SNode** pNode) { + SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pFunc) { + pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; + return DEAL_RES_ERROR; + } + + strcpy(pFunc->functionName, "_group_key"); + strcpy(pFunc->node.aliasName, ((SExprNode*)*pNode)->aliasName); + pCxt->errCode = nodesListMakeAppend(&pFunc->pParameterList, *pNode); + if (TSDB_CODE_SUCCESS == pCxt->errCode) { + *pNode = (SNode*)pFunc; + pCxt->errCode = fmGetFuncInfo(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len); + } + + return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR); +} + static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) { - SCheckExprForGroupByCxt* pCxt = (SCheckExprForGroupByCxt*)pContext; + STranslateContext* pCxt = (STranslateContext*)pContext; + SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt; if (!nodesIsExprNode(*pNode) || isAliasColumn(*pNode)) { return DEAL_RES_CONTINUE; } - if (isSelectFunc(*pNode)) { - ++(pCxt->selectFuncNum); - } else if (isAggFunc(*pNode)) { - pCxt->hasOtherAggFunc = true; - } - if ((pCxt->selectFuncNum > 1 && pCxt->hasSelectValFunc) || (pCxt->hasOtherAggFunc && pCxt->hasSelectValFunc)) { - return generateDealNodeErrMsg(pCxt->pTranslateCxt, getGroupByErrorCode(pCxt->pTranslateCxt)); - } - if (isAggFunc(*pNode) && !isDistinctOrderBy(pCxt->pTranslateCxt)) { + if (isVectorFunc(*pNode) && !isDistinctOrderBy(pCxt)) { return DEAL_RES_IGNORE_CHILD; } SNode* pGroupNode = NULL; - FOREACH(pGroupNode, getGroupByList(pCxt->pTranslateCxt)) { + FOREACH(pGroupNode, getGroupByList(pCxt)) { if (nodesEqualNode(getGroupByNode(pGroupNode), *pNode)) { return DEAL_RES_IGNORE_CHILD; } } SNode* pPartKey = NULL; - FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) { + FOREACH(pPartKey, pSelect->pPartitionByList) { if (nodesEqualNode(pPartKey, *pNode)) { - return DEAL_RES_IGNORE_CHILD; + return rewriteExprToGroupKeyFunc(pCxt, pNode); } } if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) { - if (pCxt->selectFuncNum > 1 || pCxt->hasOtherAggFunc) { - return generateDealNodeErrMsg(pCxt->pTranslateCxt, getGroupByErrorCode(pCxt->pTranslateCxt)); + if (pSelect->selectFuncNum > 1 || pSelect->hasOtherVectorFunc || !pSelect->hasSelectFunc) { + return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt)); } else { - pCxt->hasSelectValFunc = true; - return rewriteColToSelectValFunc(pCxt->pTranslateCxt, pNode); + return rewriteColToSelectValFunc(pCxt, pNode); } } - if (isAggFunc(*pNode) && isDistinctOrderBy(pCxt->pTranslateCxt)) { - return generateDealNodeErrMsg(pCxt->pTranslateCxt, getGroupByErrorCode(pCxt->pTranslateCxt)); + if (isVectorFunc(*pNode) && isDistinctOrderBy(pCxt)) { + return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt)); } return DEAL_RES_CONTINUE; } static int32_t checkExprForGroupBy(STranslateContext* pCxt, SNode** pNode) { - SCheckExprForGroupByCxt cxt = { - .pTranslateCxt = pCxt, .selectFuncNum = 0, .hasSelectValFunc = false, .hasOtherAggFunc = false}; - nodesRewriteExpr(pNode, doCheckExprForGroupBy, &cxt); - if (cxt.selectFuncNum != 1 && cxt.hasSelectValFunc) { - return generateSyntaxErrMsg(&pCxt->msgBuf, getGroupByErrorCode(pCxt)); - } + nodesRewriteExpr(pNode, doCheckExprForGroupBy, pCxt); return pCxt->errCode; } -static int32_t checkExprListForGroupBy(STranslateContext* pCxt, SNodeList* pList) { - if (NULL == getGroupByList(pCxt)) { +static int32_t checkExprListForGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect, SNodeList* pList) { + if (NULL == getGroupByList(pCxt) && NULL == pSelect->pWindow) { return TSDB_CODE_SUCCESS; } - SCheckExprForGroupByCxt cxt = { - .pTranslateCxt = pCxt, .selectFuncNum = 0, .hasSelectValFunc = false, .hasOtherAggFunc = false}; - nodesRewriteExprs(pList, doCheckExprForGroupBy, &cxt); - if (cxt.selectFuncNum != 1 && cxt.hasSelectValFunc) { - return generateSyntaxErrMsg(&pCxt->msgBuf, getGroupByErrorCode(pCxt)); - } + nodesRewriteExprs(pList, doCheckExprForGroupBy, pCxt); return pCxt->errCode; } @@ -1642,63 +1511,42 @@ static int32_t rewriteColsToSelectValFunc(STranslateContext* pCxt, SSelectStmt* typedef struct CheckAggColCoexistCxt { STranslateContext* pTranslateCxt; - bool existAggFunc; bool existCol; - bool existIndefiniteRowsFunc; - int32_t selectFuncNum; - bool existOtherAggFunc; } CheckAggColCoexistCxt; -static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) { +static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) { CheckAggColCoexistCxt* pCxt = (CheckAggColCoexistCxt*)pContext; - if (isSelectFunc(pNode)) { - ++(pCxt->selectFuncNum); - } else if (isAggFunc(pNode)) { - pCxt->existOtherAggFunc = true; - } - if (isAggFunc(pNode)) { - pCxt->existAggFunc = true; - return DEAL_RES_IGNORE_CHILD; - } - if (isIndefiniteRowsFunc(pNode)) { - pCxt->existIndefiniteRowsFunc = true; + if (isVectorFunc(*pNode)) { return DEAL_RES_IGNORE_CHILD; } SNode* pPartKey = NULL; FOREACH(pPartKey, ((SSelectStmt*)pCxt->pTranslateCxt->pCurrStmt)->pPartitionByList) { - if (nodesEqualNode(pPartKey, pNode)) { - return DEAL_RES_IGNORE_CHILD; + if (nodesEqualNode(pPartKey, *pNode)) { + return rewriteExprToGroupKeyFunc(pCxt->pTranslateCxt, pNode); } } - if (isScanPseudoColumnFunc(pNode) || QUERY_NODE_COLUMN == nodeType(pNode)) { + if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) { pCxt->existCol = true; } return DEAL_RES_CONTINUE; } static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect) { - if (NULL != pSelect->pGroupByList) { + if (NULL != pSelect->pGroupByList || NULL != pSelect->pWindow || + (!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc && !pSelect->hasInterpFunc)) { return TSDB_CODE_SUCCESS; } - CheckAggColCoexistCxt cxt = {.pTranslateCxt = pCxt, - .existAggFunc = false, - .existCol = false, - .existIndefiniteRowsFunc = false, - .selectFuncNum = 0, - .existOtherAggFunc = false}; - nodesWalkExprs(pSelect->pProjectionList, doCheckAggColCoexist, &cxt); + CheckAggColCoexistCxt cxt = {.pTranslateCxt = pCxt, .existCol = false}; + nodesRewriteExprs(pSelect->pProjectionList, doCheckAggColCoexist, &cxt); if (!pSelect->isDistinct) { - nodesWalkExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt); + nodesRewriteExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt); } - if (1 == cxt.selectFuncNum && !cxt.existOtherAggFunc) { + if (1 == pSelect->selectFuncNum && !pSelect->hasOtherVectorFunc) { return rewriteColsToSelectValFunc(pCxt, pSelect); } - if ((cxt.selectFuncNum > 1 || cxt.existAggFunc || NULL != pSelect->pWindow) && cxt.existCol) { + if (cxt.existCol) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SINGLE_GROUP); } - if (cxt.existIndefiniteRowsFunc && cxt.existCol) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC); - } return TSDB_CODE_SUCCESS; } @@ -2178,7 +2026,7 @@ static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) { pCxt->currClause = SQL_CLAUSE_ORDER_BY; code = translateExprList(pCxt, pSelect->pOrderByList); if (TSDB_CODE_SUCCESS == code) { - code = checkExprListForGroupBy(pCxt, pSelect->pOrderByList); + code = checkExprListForGroupBy(pCxt, pSelect, pSelect->pOrderByList); } } return code; @@ -2191,7 +2039,7 @@ static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect code = translateStar(pCxt, pSelect); } if (TSDB_CODE_SUCCESS == code) { - code = checkExprListForGroupBy(pCxt, pSelect->pProjectionList); + code = checkExprListForGroupBy(pCxt, pSelect, pSelect->pProjectionList); } return code; } @@ -2988,8 +2836,8 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS pReq->compression = pStmt->pOptions->compressionLevel; pReq->replications = pStmt->pOptions->replica; pReq->strict = pStmt->pOptions->strict; - pReq->cacheLastRow = pStmt->pOptions->cacheLast; - pReq->lastRowMem = pStmt->pOptions->cacheLastSize; + pReq->cacheLast = pStmt->pOptions->cacheLast; + pReq->cacheLastSize = pStmt->pOptions->cacheLastSize; pReq->schemaless = pStmt->pOptions->schemaless; pReq->ignoreExist = pStmt->ignoreExists; return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq); @@ -3150,12 +2998,12 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName int32_t code = checkRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE); if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "cacheLast", pOptions->cacheLast, TSDB_MIN_DB_CACHE_LAST_ROW, - TSDB_MAX_DB_CACHE_LAST_ROW); + code = checkRangeOption(pCxt, "cacheLast", pOptions->cacheLast, TSDB_MIN_DB_CACHE_LAST, + TSDB_MAX_DB_CACHE_LAST); } if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "cacheLastSize", pOptions->cacheLastSize, TSDB_MIN_DB_LAST_ROW_MEM, - TSDB_MAX_DB_LAST_ROW_MEM); + code = checkRangeOption(pCxt, "cacheLastSize", pOptions->cacheLastSize, TSDB_MIN_DB_CACHE_LAST_SIZE, + TSDB_MAX_DB_CACHE_LAST_SIZE); } if (TSDB_CODE_SUCCESS == code) { code = checkRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); @@ -3268,7 +3116,7 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, pReq->buffer = pStmt->pOptions->buffer; pReq->pageSize = -1; pReq->pages = pStmt->pOptions->pages; - pReq->lastRowMem = -1; + pReq->cacheLastSize = -1; pReq->daysPerFile = -1; pReq->daysToKeep0 = pStmt->pOptions->keep[0]; pReq->daysToKeep1 = pStmt->pOptions->keep[1]; @@ -3276,8 +3124,8 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod; pReq->walLevel = pStmt->pOptions->walLevel; pReq->strict = pStmt->pOptions->strict; - pReq->cacheLastRow = pStmt->pOptions->cacheLast; - pReq->lastRowMem = pStmt->pOptions->cacheLastSize; + pReq->cacheLast = pStmt->pOptions->cacheLast; + pReq->cacheLastSize = pStmt->pOptions->cacheLastSize; pReq->replications = pStmt->pOptions->replica; return; } @@ -3294,6 +3142,14 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm return buildCmdMsg(pCxt, TDMT_MND_ALTER_DB, (FSerializeFunc)tSerializeSAlterDbReq, &alterReq); } +static int32_t translateTrimDatabase(STranslateContext* pCxt, STrimDatabaseStmt* pStmt) { + STrimDbReq req = {0}; + SName name = {0}; + tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); + tNameGetFullDbName(&name, req.db); + return buildCmdMsg(pCxt, TDMT_MND_TRIM_DB, (FSerializeFunc)tSerializeSTrimDbReq, &req); +} + static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray) { *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); SNode* pNode; @@ -3352,7 +3208,7 @@ static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs if (NULL == pFuncs) { if (NULL != pDbCfg->pRetensions) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TABLE_OPTION, - "To create a super table in a database with the retensions parameter configured, " + "To create a super table in databases configured with the 'RETENTIONS' option, " "the 'ROLLUP' option must be present"); } return TSDB_CODE_SUCCESS; @@ -3563,10 +3419,12 @@ static int32_t checkTableWatermarkOption(STranslateContext* pCxt, STableOptions* } static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt, bool createStable) { - int32_t code = TSDB_CODE_SUCCESS; SDbCfgInfo dbCfg = {0}; - if (createStable) { - code = getDBCfg(pCxt, pStmt->dbName, &dbCfg); + int32_t code = getDBCfg(pCxt, pStmt->dbName, &dbCfg); + if (TSDB_CODE_SUCCESS == code && !createStable && NULL != dbCfg.pRetensions) { + code = generateSyntaxErrMsgExt( + &pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TABLE_OPTION, + "Only super table creation is supported in databases configured with the 'RETENTIONS' option"); } if (TSDB_CODE_SUCCESS == code) { code = checkTableMaxDelayOption(pCxt, pStmt->pOptions, createStable, &dbCfg); @@ -4157,8 +4015,15 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pReq->intervalUnit); if (NULL != pStmt->pOptions->pStreamOptions) { SStreamOptions* pStreamOpt = (SStreamOptions*)pStmt->pOptions->pStreamOptions; - pReq->maxDelay = (NULL != pStreamOpt->pDelay ? ((SValueNode*)pStreamOpt->pDelay)->datum.i : 0); - pReq->watermark = (NULL != pStreamOpt->pWatermark ? ((SValueNode*)pStreamOpt->pWatermark)->datum.i : 0); + pReq->maxDelay = (NULL != pStreamOpt->pDelay ? ((SValueNode*)pStreamOpt->pDelay)->datum.i : -1); + pReq->watermark = (NULL != pStreamOpt->pWatermark ? ((SValueNode*)pStreamOpt->pWatermark)->datum.i + : TSDB_DEFAULT_ROLLUP_WATERMARK); + if (pReq->watermark < TSDB_MIN_ROLLUP_WATERMARK) { + pReq->watermark = TSDB_MIN_ROLLUP_WATERMARK; + } + if (pReq->watermark > TSDB_MAX_ROLLUP_WATERMARK) { + pReq->watermark = TSDB_MAX_ROLLUP_WATERMARK; + } } int32_t code = getSmaIndexDstVgId(pCxt, pStmt->tableName, &pReq->dstVgId); @@ -4172,29 +4037,42 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm return code; } -static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { - if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pInterval) || - (NULL != pStmt->pOptions->pOffset && - DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pOffset)) || - (NULL != pStmt->pOptions->pSliding && - DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pSliding))) { - return pCxt->errCode; +static int32_t checkCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { + SDbCfgInfo dbCfg = {0}; + int32_t code = getDBCfg(pCxt, pCxt->pParseCxt->db, &dbCfg); + if (TSDB_CODE_SUCCESS == code && NULL != dbCfg.pRetensions) { + code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_SMA_INDEX, + "Tables configured with the 'ROLLUP' option do not support creating sma index"); + } + if (TSDB_CODE_SUCCESS == code) { + code = doTranslateValue(pCxt, (SValueNode*)pStmt->pOptions->pInterval); + } + if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pOptions->pOffset) { + code = doTranslateValue(pCxt, (SValueNode*)pStmt->pOptions->pOffset); + } + if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pOptions->pSliding) { + code = doTranslateValue(pCxt, (SValueNode*)pStmt->pOptions->pSliding); } - if (NULL != pStmt->pOptions->pStreamOptions) { + if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pOptions->pStreamOptions) { SStreamOptions* pStreamOpt = (SStreamOptions*)pStmt->pOptions->pStreamOptions; - if (NULL != pStreamOpt->pWatermark && - (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStreamOpt->pWatermark))) { - return pCxt->errCode; + if (NULL != pStreamOpt->pWatermark) { + code = doTranslateValue(pCxt, (SValueNode*)pStreamOpt->pWatermark); } - - if (NULL != pStreamOpt->pDelay && (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStreamOpt->pDelay))) { - return pCxt->errCode; + if (TSDB_CODE_SUCCESS == code && NULL != pStreamOpt->pDelay) { + code = doTranslateValue(pCxt, (SValueNode*)pStreamOpt->pDelay); } } + return code; +} + +static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { SMCreateSmaReq createSmaReq = {0}; - int32_t code = buildCreateSmaReq(pCxt, pStmt, &createSmaReq); + int32_t code = checkCreateSmaIndex(pCxt, pStmt); + if (TSDB_CODE_SUCCESS == code) { + code = buildCreateSmaReq(pCxt, pStmt, &createSmaReq); + } if (TSDB_CODE_SUCCESS == code) { code = buildCmdMsg(pCxt, TDMT_MND_CREATE_SMA, (FSerializeFunc)tSerializeSMCreateSmaReq, &createSmaReq); } @@ -4711,6 +4589,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_ALTER_DATABASE_STMT: code = translateAlterDatabase(pCxt, (SAlterDatabaseStmt*)pNode); break; + case QUERY_NODE_TRIM_DATABASE_STMT: + code = translateTrimDatabase(pCxt, (STrimDatabaseStmt*)pNode); + break; case QUERY_NODE_CREATE_TABLE_STMT: code = translateCreateSuperTable(pCxt, (SCreateTableStmt*)pNode); break; @@ -5370,8 +5251,9 @@ static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch return TSDB_CODE_SUCCESS; } -static void destroyCreateTbReqBatch(SVgroupCreateTableBatch* pTbBatch) { - size_t size = taosArrayGetSize(pTbBatch->req.pArray); +static void destroyCreateTbReqBatch(void* data) { + SVgroupCreateTableBatch* pTbBatch = (SVgroupCreateTableBatch*)data; + size_t size = taosArrayGetSize(pTbBatch->req.pArray); for (int32_t i = 0; i < size; ++i) { SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i); taosMemoryFreeClear(pTableReq->name); @@ -5387,7 +5269,7 @@ static void destroyCreateTbReqBatch(SVgroupCreateTableBatch* pTbBatch) { taosArrayDestroy(pTbBatch->req.pArray); } -static int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray) { +int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray) { SVnodeModifOpStmt* pNewStmt = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT); if (pNewStmt == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -5453,10 +5335,10 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) { static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, SCreateSubTableClause* pStmt, const STag* pTag, uint64_t suid, SVgroupInfo* pVgInfo) { - char dbFName[TSDB_DB_FNAME_LEN] = {0}; - SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId}; - strcpy(name.dbname, pStmt->dbName); - tNameGetFullDbName(&name, dbFName); + // char dbFName[TSDB_DB_FNAME_LEN] = {0}; + // SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId}; + // strcpy(name.dbname, pStmt->dbName); + // tNameGetFullDbName(&name, dbFName); struct SVCreateTbReq req = {0}; req.type = TD_CHILD_TABLE; @@ -5717,7 +5599,7 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla return code; } -static SArray* serializeVgroupsCreateTableBatch(int32_t acctId, SHashObj* pVgroupHashmap) { +SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap) { SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); if (NULL == pBufArray) { return NULL; @@ -5732,7 +5614,6 @@ static SArray* serializeVgroupsCreateTableBatch(int32_t acctId, SHashObj* pVgrou } serializeVgroupCreateTableBatch(pTbBatch, pBufArray); - destroyCreateTbReqBatch(pTbBatch); } while (true); return pBufArray; @@ -5746,6 +5627,7 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) return TSDB_CODE_OUT_OF_MEMORY; } + taosHashSetFreeFp(pVgroupHashmap, destroyCreateTbReqBatch); int32_t code = TSDB_CODE_SUCCESS; SNode* pNode; FOREACH(pNode, pStmt->pSubTables) { @@ -5757,7 +5639,7 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) } } - SArray* pBufArray = serializeVgroupsCreateTableBatch(pCxt->pParseCxt->acctId, pVgroupHashmap); + SArray* pBufArray = serializeVgroupsCreateTableBatch(pVgroupHashmap); taosHashCleanup(pVgroupHashmap); if (NULL == pBufArray) { return TSDB_CODE_OUT_OF_MEMORY; @@ -5817,7 +5699,10 @@ over: return code; } -static void destroyDropTbReqBatch(SVgroupDropTableBatch* pTbBatch) { taosArrayDestroy(pTbBatch->req.pArray); } +static void destroyDropTbReqBatch(void* data) { + SVgroupDropTableBatch* pTbBatch = (SVgroupDropTableBatch*)data; + taosArrayDestroy(pTbBatch->req.pArray); +} static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SArray* pBufArray) { int tlen; @@ -5851,7 +5736,7 @@ static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SA return TSDB_CODE_SUCCESS; } -static SArray* serializeVgroupsDropTableBatch(int32_t acctId, SHashObj* pVgroupHashmap) { +SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap) { SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); if (NULL == pBufArray) { return NULL; @@ -5866,7 +5751,6 @@ static SArray* serializeVgroupsDropTableBatch(int32_t acctId, SHashObj* pVgroupH } serializeVgroupDropTableBatch(pTbBatch, pBufArray); - destroyDropTbReqBatch(pTbBatch); } while (true); return pBufArray; @@ -5880,6 +5764,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { return TSDB_CODE_OUT_OF_MEMORY; } + taosHashSetFreeFp(pVgroupHashmap, destroyDropTbReqBatch); bool isSuperTable = false; SNode* pNode; FOREACH(pNode, pStmt->pTables) { @@ -5898,7 +5783,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { return TSDB_CODE_SUCCESS; } - SArray* pBufArray = serializeVgroupsDropTableBatch(pCxt->pParseCxt->acctId, pVgroupHashmap); + SArray* pBufArray = serializeVgroupsDropTableBatch(pVgroupHashmap); taosHashCleanup(pVgroupHashmap); if (NULL == pBufArray) { return TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index b36adbe5d4..fdba0e2fcc 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -38,8 +38,10 @@ bool qIsInsertValuesSql(const char* pStr, size_t length) { t = tStrGetToken((char*)pStr, &index, false); if (TK_USING == t.type || TK_VALUES == t.type) { return true; + } else if (TK_SELECT == t.type) { + return false; } - if (0 == t.type) { + if (0 == t.type || 0 == t.n) { break; } } while (pStr - pSql < length); diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 124d1b2270..cb09860758 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -104,26 +104,26 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 377 +#define YYNOCODE 378 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SToken yy5; - EJoinType yy74; - SNodeList* yy210; - EFillMode yy270; - int64_t yy311; - SAlterOption yy351; - bool yy403; - EOperatorType yy428; - int32_t yy462; - ENullOrder yy477; - int8_t yy535; - SDataType yy552; - EOrder yy553; - SNode* yy652; + EFillMode yy18; + EJoinType yy36; + ENullOrder yy109; + EOperatorType yy128; + bool yy173; + SDataType yy196; + EOrder yy218; + SAlterOption yy389; + int32_t yy424; + SToken yy533; + SNode* yy560; + int64_t yy585; + SNodeList* yy712; + int8_t yy719; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -139,17 +139,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 663 -#define YYNRULE 487 -#define YYNTOKEN 254 -#define YY_MAX_SHIFT 662 -#define YY_MIN_SHIFTREDUCE 966 -#define YY_MAX_SHIFTREDUCE 1452 -#define YY_ERROR_ACTION 1453 -#define YY_ACCEPT_ACTION 1454 -#define YY_NO_ACTION 1455 -#define YY_MIN_REDUCE 1456 -#define YY_MAX_REDUCE 1942 +#define YYNSTATE 666 +#define YYNRULE 488 +#define YYNTOKEN 255 +#define YY_MAX_SHIFT 665 +#define YY_MIN_SHIFTREDUCE 969 +#define YY_MAX_SHIFTREDUCE 1456 +#define YY_ERROR_ACTION 1457 +#define YY_ACCEPT_ACTION 1458 +#define YY_NO_ACTION 1459 +#define YY_MIN_REDUCE 1460 +#define YY_MAX_REDUCE 1947 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -216,656 +216,688 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2360) +#define YY_ACTTAB_COUNT (2520) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 430, 1920, 431, 1491, 438, 71, 431, 1491, 514, 62, - /* 10 */ 1645, 1693, 40, 38, 1919, 550, 323, 325, 1917, 1690, - /* 20 */ 337, 86, 1254, 1457, 34, 33, 1643, 1589, 41, 39, - /* 30 */ 37, 36, 35, 1329, 119, 1252, 1777, 41, 39, 37, - /* 40 */ 36, 35, 1585, 122, 103, 1734, 550, 102, 101, 100, - /* 50 */ 99, 98, 97, 96, 95, 94, 1324, 526, 550, 23, - /* 60 */ 14, 1016, 342, 1015, 1795, 1638, 1640, 1260, 113, 142, - /* 70 */ 1795, 1468, 578, 79, 122, 468, 466, 1747, 543, 577, - /* 80 */ 40, 38, 1392, 120, 1, 1593, 122, 61, 337, 61, - /* 90 */ 1254, 1017, 358, 555, 1586, 555, 379, 552, 155, 1862, - /* 100 */ 1863, 1329, 1867, 1252, 1808, 1479, 659, 1521, 89, 1778, - /* 110 */ 580, 1780, 1781, 576, 120, 571, 542, 553, 1854, 553, - /* 120 */ 1331, 1332, 304, 1850, 1324, 1478, 120, 526, 14, 249, - /* 130 */ 1862, 549, 1456, 548, 1920, 1260, 1920, 1920, 164, 31, - /* 140 */ 259, 156, 1862, 1863, 1777, 1867, 1747, 161, 447, 161, - /* 150 */ 159, 1917, 2, 1917, 1917, 1593, 112, 111, 110, 109, - /* 160 */ 108, 107, 106, 105, 104, 1255, 1747, 1253, 1279, 483, - /* 170 */ 482, 481, 1795, 1920, 659, 480, 220, 221, 118, 477, - /* 180 */ 578, 44, 476, 475, 474, 1747, 160, 577, 1331, 1332, - /* 190 */ 1917, 429, 1258, 1259, 433, 1307, 1308, 1310, 1311, 1312, - /* 200 */ 1313, 1314, 573, 569, 1322, 1323, 1325, 1326, 1327, 1328, - /* 210 */ 1330, 1333, 1808, 1413, 1278, 539, 90, 1778, 580, 1780, - /* 220 */ 1781, 576, 1279, 571, 162, 1454, 1854, 162, 553, 162, - /* 230 */ 330, 1850, 1933, 1255, 314, 1253, 61, 303, 140, 143, - /* 240 */ 516, 1888, 999, 1549, 34, 33, 1645, 1596, 41, 39, - /* 250 */ 37, 36, 35, 341, 536, 1411, 1412, 1414, 1415, 1477, - /* 260 */ 1258, 1259, 1643, 1307, 1308, 1310, 1311, 1312, 1313, 1314, - /* 270 */ 573, 569, 1322, 1323, 1325, 1326, 1327, 1328, 1330, 1333, - /* 280 */ 40, 38, 1003, 1004, 315, 349, 313, 312, 337, 470, - /* 290 */ 1254, 1777, 43, 472, 545, 540, 305, 1353, 11, 10, - /* 300 */ 1747, 1329, 103, 1252, 153, 102, 101, 100, 99, 98, - /* 310 */ 97, 96, 95, 94, 385, 471, 378, 1632, 377, 1795, - /* 320 */ 1358, 1292, 1151, 1152, 1324, 1278, 1920, 554, 14, 1351, - /* 330 */ 1639, 1640, 1747, 437, 577, 1260, 433, 40, 38, 159, - /* 340 */ 483, 482, 481, 1917, 1920, 337, 480, 1254, 1518, 118, - /* 350 */ 477, 301, 2, 476, 475, 474, 605, 1918, 1329, 1808, - /* 360 */ 1252, 1917, 28, 90, 1778, 580, 1780, 1781, 576, 435, - /* 370 */ 571, 71, 370, 1854, 659, 1276, 162, 330, 1850, 154, - /* 380 */ 1396, 1324, 1365, 1352, 117, 1016, 1278, 1015, 1331, 1332, - /* 390 */ 1309, 158, 1260, 1588, 372, 368, 544, 34, 33, 1880, - /* 400 */ 1571, 41, 39, 37, 36, 35, 1357, 479, 478, 8, - /* 410 */ 636, 635, 634, 633, 345, 1017, 632, 631, 630, 123, - /* 420 */ 625, 624, 623, 622, 621, 620, 619, 618, 133, 614, - /* 430 */ 324, 659, 162, 1255, 562, 1253, 34, 33, 140, 613, - /* 440 */ 41, 39, 37, 36, 35, 1331, 1332, 1595, 30, 335, - /* 450 */ 1346, 1347, 1348, 1349, 1350, 1354, 1355, 1356, 1280, 447, - /* 460 */ 1258, 1259, 1476, 1307, 1308, 1310, 1311, 1312, 1313, 1314, - /* 470 */ 573, 569, 1322, 1323, 1325, 1326, 1327, 1328, 1330, 1333, - /* 480 */ 34, 33, 214, 526, 41, 39, 37, 36, 35, 170, - /* 490 */ 1255, 207, 1253, 219, 165, 1281, 340, 37, 36, 35, - /* 500 */ 59, 34, 33, 1747, 140, 41, 39, 37, 36, 35, - /* 510 */ 61, 1593, 75, 1595, 629, 627, 69, 1258, 1259, 68, - /* 520 */ 1307, 1308, 1310, 1311, 1312, 1313, 1314, 573, 569, 1322, - /* 530 */ 1323, 1325, 1326, 1327, 1328, 1330, 1333, 40, 38, 1334, - /* 540 */ 1689, 139, 298, 1475, 343, 337, 1777, 1254, 1277, 162, - /* 550 */ 73, 303, 140, 305, 516, 1234, 1235, 1423, 1329, 418, - /* 560 */ 1252, 1595, 1309, 1109, 602, 601, 600, 1113, 599, 1115, - /* 570 */ 1116, 598, 1118, 595, 1795, 1124, 592, 1126, 1127, 589, - /* 580 */ 586, 1324, 578, 488, 1747, 1449, 1351, 1747, 526, 577, - /* 590 */ 251, 472, 1260, 1474, 40, 38, 1683, 1254, 498, 383, - /* 600 */ 45, 4, 337, 555, 1254, 174, 173, 172, 1260, 9, - /* 610 */ 1252, 1071, 206, 471, 1808, 1329, 1593, 1252, 89, 1778, - /* 620 */ 580, 1780, 1781, 576, 497, 571, 491, 231, 1854, 1473, - /* 630 */ 485, 659, 304, 1850, 1747, 205, 563, 495, 1324, 493, - /* 640 */ 1352, 27, 1260, 1073, 1920, 1331, 1332, 34, 33, 1260, - /* 650 */ 162, 41, 39, 37, 36, 35, 1569, 159, 1869, 1472, - /* 660 */ 1471, 1917, 56, 1357, 611, 55, 9, 1869, 559, 526, - /* 670 */ 1747, 34, 33, 1645, 1448, 41, 39, 37, 36, 35, - /* 680 */ 384, 659, 1866, 131, 130, 608, 607, 606, 659, 1644, - /* 690 */ 1255, 1865, 1253, 1003, 1004, 1869, 513, 1593, 1470, 7, - /* 700 */ 1747, 1747, 1331, 1332, 1570, 30, 335, 1346, 1347, 1348, - /* 710 */ 1349, 1350, 1354, 1355, 1356, 613, 1582, 1258, 1259, 1864, - /* 720 */ 1307, 1308, 1310, 1311, 1312, 1313, 1314, 573, 569, 1322, - /* 730 */ 1323, 1325, 1326, 1327, 1328, 1330, 1333, 1920, 557, 1747, - /* 740 */ 1255, 1688, 1253, 298, 617, 29, 1565, 1255, 1403, 1253, - /* 750 */ 159, 34, 33, 514, 1917, 41, 39, 37, 36, 35, - /* 760 */ 347, 1874, 1385, 1263, 1691, 34, 33, 1258, 1259, 41, - /* 770 */ 39, 37, 36, 35, 1258, 1259, 213, 1307, 1308, 1310, - /* 780 */ 1311, 1312, 1313, 1314, 573, 569, 1322, 1323, 1325, 1326, - /* 790 */ 1327, 1328, 1330, 1333, 40, 38, 300, 1578, 1276, 1467, - /* 800 */ 611, 1920, 337, 1777, 1254, 411, 74, 609, 423, 1466, - /* 810 */ 1636, 1508, 1389, 526, 159, 1329, 499, 1252, 1917, 131, - /* 820 */ 130, 608, 607, 606, 388, 396, 1465, 424, 1464, 398, - /* 830 */ 1339, 1795, 610, 484, 271, 1636, 1278, 1623, 1324, 578, - /* 840 */ 1747, 1593, 1292, 1568, 1747, 526, 577, 34, 33, 1260, - /* 850 */ 1747, 41, 39, 37, 36, 35, 113, 1920, 550, 52, - /* 860 */ 510, 389, 198, 473, 1262, 196, 2, 1747, 560, 1747, - /* 870 */ 159, 1808, 616, 1593, 1917, 90, 1778, 580, 1780, 1781, - /* 880 */ 576, 1463, 571, 1385, 1462, 1854, 122, 1461, 659, 330, - /* 890 */ 1850, 1933, 1460, 1459, 200, 1266, 1497, 199, 567, 1580, - /* 900 */ 1911, 422, 1331, 1332, 417, 416, 415, 414, 413, 410, - /* 910 */ 409, 408, 407, 406, 402, 401, 400, 399, 393, 392, - /* 920 */ 391, 390, 1747, 387, 386, 1747, 120, 526, 1747, 526, - /* 930 */ 628, 141, 1576, 1747, 1747, 526, 277, 526, 403, 611, - /* 940 */ 404, 157, 1862, 1863, 654, 1867, 446, 1255, 1590, 1253, - /* 950 */ 275, 58, 11, 10, 57, 1593, 506, 1593, 131, 130, - /* 960 */ 608, 607, 606, 1593, 210, 1593, 1777, 1451, 1452, 572, - /* 970 */ 176, 426, 373, 42, 1258, 1259, 550, 1307, 1308, 1310, - /* 980 */ 1311, 1312, 1313, 1314, 573, 569, 1322, 1323, 1325, 1326, - /* 990 */ 1327, 1328, 1330, 1333, 1795, 526, 1265, 61, 202, 526, - /* 1000 */ 526, 201, 554, 526, 122, 204, 1722, 1747, 203, 577, - /* 1010 */ 507, 511, 1309, 1584, 524, 1202, 218, 1469, 1764, 604, - /* 1020 */ 1550, 526, 254, 1593, 1761, 555, 465, 1593, 1593, 1761, - /* 1030 */ 1343, 1593, 525, 1388, 1808, 88, 526, 1777, 90, 1778, - /* 1040 */ 580, 1780, 1781, 576, 120, 571, 1503, 260, 1854, 1593, - /* 1050 */ 1757, 1763, 330, 1850, 154, 1757, 1763, 326, 222, 249, - /* 1060 */ 1862, 549, 571, 548, 1593, 1795, 1920, 571, 486, 1501, - /* 1070 */ 66, 65, 382, 578, 1881, 169, 537, 243, 1747, 159, - /* 1080 */ 577, 376, 1767, 1917, 125, 328, 327, 526, 128, 1042, - /* 1090 */ 129, 489, 1796, 50, 299, 1268, 235, 366, 344, 364, - /* 1100 */ 360, 356, 166, 351, 348, 1808, 1329, 1765, 1261, 90, - /* 1110 */ 1778, 580, 1780, 1781, 576, 1593, 571, 42, 1761, 1854, - /* 1120 */ 1769, 1043, 42, 330, 1850, 1933, 519, 346, 42, 1324, - /* 1130 */ 228, 584, 1102, 1777, 1873, 1410, 85, 162, 238, 128, - /* 1140 */ 1260, 129, 114, 128, 1757, 1763, 82, 500, 1492, 1633, - /* 1150 */ 551, 1884, 253, 256, 258, 248, 571, 3, 53, 1359, - /* 1160 */ 80, 1795, 5, 350, 1315, 1276, 353, 357, 310, 578, - /* 1170 */ 270, 1071, 1218, 1130, 1747, 311, 577, 405, 267, 535, - /* 1180 */ 1685, 1134, 171, 1141, 1139, 132, 412, 420, 419, 421, - /* 1190 */ 555, 425, 427, 1282, 1777, 1285, 1284, 428, 436, 439, - /* 1200 */ 179, 1808, 440, 181, 441, 284, 1778, 580, 1780, 1781, - /* 1210 */ 576, 1286, 571, 442, 184, 186, 444, 1283, 188, 70, - /* 1220 */ 445, 448, 1795, 191, 467, 469, 1583, 195, 1579, 197, - /* 1230 */ 578, 1920, 134, 135, 93, 1747, 302, 577, 1269, 268, - /* 1240 */ 1264, 208, 1581, 1577, 161, 136, 137, 1777, 1917, 211, - /* 1250 */ 1727, 555, 502, 501, 508, 505, 512, 534, 1281, 215, - /* 1260 */ 515, 1726, 1808, 520, 1695, 1272, 284, 1778, 580, 1780, - /* 1270 */ 1781, 576, 320, 571, 517, 1795, 569, 1322, 1323, 1325, - /* 1280 */ 1326, 1327, 1328, 578, 126, 322, 521, 127, 1747, 224, - /* 1290 */ 577, 522, 1920, 269, 226, 78, 1594, 530, 1885, 1777, - /* 1300 */ 538, 6, 233, 532, 533, 159, 237, 547, 329, 1917, - /* 1310 */ 531, 541, 1385, 528, 1895, 1808, 529, 247, 121, 91, - /* 1320 */ 1778, 580, 1780, 1781, 576, 1894, 571, 1795, 244, 1854, - /* 1330 */ 246, 1876, 148, 1853, 1850, 578, 1280, 564, 1870, 561, - /* 1340 */ 1747, 331, 577, 242, 19, 245, 1835, 582, 272, 1637, - /* 1350 */ 1566, 252, 1777, 655, 1916, 51, 147, 263, 1741, 558, - /* 1360 */ 1936, 656, 658, 285, 63, 255, 1777, 1808, 276, 565, - /* 1370 */ 257, 91, 1778, 580, 1780, 1781, 576, 1740, 571, 274, - /* 1380 */ 1795, 1854, 1739, 295, 294, 566, 1850, 64, 575, 1738, - /* 1390 */ 352, 1735, 354, 1747, 1795, 577, 355, 1246, 1247, 167, - /* 1400 */ 359, 1733, 578, 361, 362, 363, 1732, 1747, 365, 577, - /* 1410 */ 1731, 1730, 369, 367, 1729, 371, 1712, 168, 374, 1777, - /* 1420 */ 1808, 375, 1221, 1220, 292, 1778, 580, 1780, 1781, 576, - /* 1430 */ 574, 571, 568, 1826, 1808, 1706, 1705, 1777, 144, 1778, - /* 1440 */ 580, 1780, 1781, 576, 380, 571, 381, 1795, 1704, 1703, - /* 1450 */ 1190, 1678, 1677, 1676, 67, 578, 1675, 1674, 1673, 1672, - /* 1460 */ 1747, 1671, 577, 394, 395, 1795, 1670, 397, 1669, 1668, - /* 1470 */ 321, 1667, 1666, 578, 1665, 1664, 1663, 1662, 1747, 1661, - /* 1480 */ 577, 1660, 556, 1934, 1659, 1658, 1657, 1808, 1656, 1777, - /* 1490 */ 1655, 91, 1778, 580, 1780, 1781, 576, 124, 571, 1654, - /* 1500 */ 1653, 1854, 1652, 1651, 1650, 1808, 1851, 1649, 1648, 293, - /* 1510 */ 1778, 580, 1780, 1781, 576, 1192, 571, 1795, 1647, 1646, - /* 1520 */ 1522, 175, 527, 1520, 1488, 578, 152, 1006, 115, 177, - /* 1530 */ 1747, 1777, 577, 1487, 178, 1005, 116, 432, 434, 1720, - /* 1540 */ 1714, 1777, 1702, 185, 183, 1701, 1687, 1572, 1519, 1517, - /* 1550 */ 449, 451, 1515, 455, 1513, 459, 1035, 1808, 450, 1795, - /* 1560 */ 453, 293, 1778, 580, 1780, 1781, 576, 578, 571, 1795, - /* 1570 */ 457, 1511, 1747, 454, 577, 458, 461, 578, 462, 1500, - /* 1580 */ 1499, 1484, 1747, 463, 577, 1574, 1145, 1144, 1573, 194, - /* 1590 */ 1070, 1777, 1069, 1068, 49, 1067, 626, 1509, 1064, 1808, - /* 1600 */ 316, 1063, 628, 288, 1778, 580, 1780, 1781, 576, 1808, - /* 1610 */ 571, 662, 1062, 144, 1778, 580, 1780, 1781, 576, 1795, - /* 1620 */ 571, 1061, 1504, 317, 334, 266, 490, 578, 1502, 318, - /* 1630 */ 1483, 487, 1747, 1777, 577, 492, 1482, 494, 1481, 151, - /* 1640 */ 496, 546, 1719, 92, 652, 648, 644, 640, 264, 1713, - /* 1650 */ 1228, 1777, 1700, 138, 503, 1698, 1699, 1697, 1935, 1808, - /* 1660 */ 1696, 1795, 54, 293, 1778, 580, 1780, 1781, 576, 575, - /* 1670 */ 571, 212, 217, 15, 1747, 87, 577, 1694, 229, 1795, - /* 1680 */ 223, 504, 319, 76, 336, 225, 509, 578, 518, 1238, - /* 1690 */ 1686, 227, 1747, 77, 577, 16, 230, 82, 1425, 1437, - /* 1700 */ 24, 1808, 42, 1777, 232, 292, 1778, 580, 1780, 1781, - /* 1710 */ 576, 523, 571, 236, 1827, 1270, 234, 48, 1407, 1808, - /* 1720 */ 1409, 145, 240, 293, 1778, 580, 1780, 1781, 576, 239, - /* 1730 */ 571, 1795, 25, 241, 1767, 193, 338, 26, 1402, 578, - /* 1740 */ 47, 250, 81, 216, 1747, 17, 577, 1382, 1381, 146, - /* 1750 */ 1766, 149, 1442, 1777, 464, 460, 456, 452, 192, 46, - /* 1760 */ 18, 1431, 13, 1777, 1226, 1436, 209, 332, 1441, 1440, - /* 1770 */ 333, 1808, 10, 1811, 20, 293, 1778, 580, 1780, 1781, - /* 1780 */ 576, 1795, 571, 1319, 570, 72, 1344, 32, 190, 578, - /* 1790 */ 150, 1795, 1317, 1316, 1747, 12, 577, 21, 163, 578, - /* 1800 */ 1300, 581, 579, 22, 1747, 1131, 577, 583, 339, 585, - /* 1810 */ 587, 1128, 588, 1108, 1125, 590, 593, 596, 1123, 1777, - /* 1820 */ 591, 1808, 1122, 1119, 594, 278, 1778, 580, 1780, 1781, - /* 1830 */ 576, 1808, 571, 1117, 597, 279, 1778, 580, 1780, 1781, - /* 1840 */ 576, 603, 571, 83, 84, 1140, 60, 1795, 261, 1121, - /* 1850 */ 189, 182, 1136, 187, 1120, 578, 1033, 443, 612, 1058, - /* 1860 */ 1747, 1777, 577, 1077, 262, 615, 1051, 1056, 1055, 1054, - /* 1870 */ 1053, 1777, 1052, 1050, 1049, 1074, 180, 1072, 1046, 1516, - /* 1880 */ 1045, 1044, 1041, 1777, 1040, 1039, 1038, 1808, 637, 1795, - /* 1890 */ 1514, 280, 1778, 580, 1780, 1781, 576, 578, 571, 1795, - /* 1900 */ 639, 638, 1747, 641, 577, 642, 643, 578, 1512, 645, - /* 1910 */ 646, 1795, 1747, 1510, 577, 647, 649, 650, 1498, 578, - /* 1920 */ 653, 651, 996, 1480, 1747, 1777, 577, 265, 657, 1808, - /* 1930 */ 1455, 1256, 273, 287, 1778, 580, 1780, 1781, 576, 1808, - /* 1940 */ 571, 660, 1777, 289, 1778, 580, 1780, 1781, 576, 661, - /* 1950 */ 571, 1808, 1455, 1795, 1455, 281, 1778, 580, 1780, 1781, - /* 1960 */ 576, 578, 571, 1455, 1455, 1455, 1747, 1455, 577, 1455, - /* 1970 */ 1795, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 578, 1455, - /* 1980 */ 1455, 1455, 1455, 1747, 1777, 577, 1455, 1455, 1455, 1455, - /* 1990 */ 1455, 1455, 1455, 1808, 1777, 1455, 1455, 290, 1778, 580, - /* 2000 */ 1780, 1781, 576, 1455, 571, 1455, 1455, 1455, 1455, 1455, - /* 2010 */ 1808, 1455, 1795, 1455, 282, 1778, 580, 1780, 1781, 576, - /* 2020 */ 578, 571, 1795, 1455, 1455, 1747, 1455, 577, 1455, 1455, - /* 2030 */ 578, 1455, 1455, 1455, 1455, 1747, 1777, 577, 1455, 1455, - /* 2040 */ 1455, 1455, 1455, 1455, 1455, 1455, 1777, 1455, 1455, 1455, - /* 2050 */ 1455, 1455, 1808, 1455, 1455, 1455, 291, 1778, 580, 1780, - /* 2060 */ 1781, 576, 1808, 571, 1795, 1455, 283, 1778, 580, 1780, - /* 2070 */ 1781, 576, 578, 571, 1795, 1455, 1455, 1747, 1455, 577, - /* 2080 */ 1455, 1455, 578, 1455, 1455, 1455, 1455, 1747, 1777, 577, - /* 2090 */ 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1777, 1455, - /* 2100 */ 1455, 1455, 1455, 1455, 1808, 1455, 1455, 1455, 296, 1778, - /* 2110 */ 580, 1780, 1781, 576, 1808, 571, 1795, 1455, 297, 1778, - /* 2120 */ 580, 1780, 1781, 576, 578, 571, 1795, 1455, 1455, 1747, - /* 2130 */ 1455, 577, 1455, 1455, 578, 1455, 1455, 1455, 1455, 1747, - /* 2140 */ 1455, 577, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, - /* 2150 */ 1777, 1455, 1455, 1455, 1455, 1455, 1808, 1455, 1455, 1455, - /* 2160 */ 1789, 1778, 580, 1780, 1781, 576, 1808, 571, 1455, 1777, - /* 2170 */ 1788, 1778, 580, 1780, 1781, 576, 1455, 571, 1795, 1455, - /* 2180 */ 1455, 1455, 1455, 1455, 1455, 1455, 578, 1455, 1455, 1455, - /* 2190 */ 1455, 1747, 1777, 577, 1455, 1455, 1455, 1795, 1455, 1455, - /* 2200 */ 1455, 1455, 1455, 1455, 1455, 578, 1455, 1455, 1455, 1455, - /* 2210 */ 1747, 1777, 577, 1455, 1455, 1455, 1455, 1455, 1808, 1455, - /* 2220 */ 1795, 1455, 1787, 1778, 580, 1780, 1781, 576, 578, 571, - /* 2230 */ 1455, 1455, 1455, 1747, 1455, 577, 1455, 1808, 1455, 1795, - /* 2240 */ 1455, 308, 1778, 580, 1780, 1781, 576, 578, 571, 1455, - /* 2250 */ 1455, 1455, 1747, 1455, 577, 1455, 1455, 1455, 1455, 1455, - /* 2260 */ 1808, 1455, 1455, 1455, 307, 1778, 580, 1780, 1781, 576, - /* 2270 */ 1777, 571, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1808, - /* 2280 */ 1777, 1455, 1455, 309, 1778, 580, 1780, 1781, 576, 1455, - /* 2290 */ 571, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1795, 1455, - /* 2300 */ 1455, 1455, 1455, 1455, 1455, 1455, 578, 1455, 1795, 1455, - /* 2310 */ 1455, 1747, 1455, 577, 1455, 1455, 578, 1455, 1455, 1455, - /* 2320 */ 1455, 1747, 1455, 577, 1455, 1455, 1455, 1455, 1455, 1455, - /* 2330 */ 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1455, 1808, 1455, - /* 2340 */ 1455, 1455, 306, 1778, 580, 1780, 1781, 576, 1808, 571, - /* 2350 */ 1455, 1455, 286, 1778, 580, 1780, 1781, 576, 1455, 571, + /* 0 */ 529, 1698, 433, 552, 434, 1495, 441, 1587, 434, 1495, + /* 10 */ 1769, 113, 39, 37, 386, 62, 517, 1583, 471, 380, + /* 20 */ 338, 1766, 1258, 1002, 324, 79, 1782, 1695, 1598, 30, + /* 30 */ 260, 122, 143, 1333, 103, 1256, 1554, 102, 101, 100, + /* 40 */ 99, 98, 97, 96, 95, 94, 1591, 1762, 1768, 327, + /* 50 */ 71, 302, 557, 1925, 1800, 555, 1328, 1512, 1283, 574, + /* 60 */ 1925, 14, 581, 1006, 1007, 500, 1924, 1752, 1264, 580, + /* 70 */ 1922, 120, 1594, 159, 39, 37, 1396, 1922, 498, 487, + /* 80 */ 496, 529, 338, 557, 1258, 1, 250, 1867, 551, 1019, + /* 90 */ 550, 1018, 164, 1925, 1813, 1333, 61, 1256, 89, 1783, + /* 100 */ 583, 1785, 1786, 579, 469, 574, 161, 662, 1859, 1598, + /* 110 */ 1922, 343, 305, 1855, 1643, 1645, 71, 61, 1328, 1020, + /* 120 */ 43, 1335, 1336, 14, 1925, 1461, 1925, 33, 32, 117, + /* 130 */ 1264, 40, 38, 36, 35, 34, 475, 161, 1593, 160, + /* 140 */ 142, 1922, 1472, 1922, 1483, 1782, 103, 2, 214, 102, + /* 150 */ 101, 100, 99, 98, 97, 96, 95, 94, 474, 1155, + /* 160 */ 1156, 486, 485, 484, 170, 1925, 1259, 483, 1257, 662, + /* 170 */ 118, 480, 325, 1800, 479, 478, 477, 1458, 1923, 74, + /* 180 */ 140, 556, 1922, 1335, 1336, 1752, 1752, 555, 580, 1600, + /* 190 */ 1644, 1645, 69, 1262, 1263, 68, 1311, 1312, 1314, 1315, + /* 200 */ 1316, 1317, 1318, 576, 572, 1326, 1327, 1329, 1330, 1331, + /* 210 */ 1332, 1334, 1337, 1813, 36, 35, 34, 90, 1783, 583, + /* 220 */ 1785, 1786, 579, 529, 574, 162, 371, 1859, 1259, 555, + /* 230 */ 1257, 329, 1855, 154, 113, 419, 162, 350, 1482, 33, + /* 240 */ 32, 476, 450, 40, 38, 36, 35, 34, 373, 369, + /* 250 */ 1283, 1598, 552, 1886, 1393, 1262, 1263, 162, 1311, 1312, + /* 260 */ 1314, 1315, 1316, 1317, 1318, 576, 572, 1326, 1327, 1329, + /* 270 */ 1330, 1331, 1332, 1334, 1337, 39, 37, 1453, 1925, 1752, + /* 280 */ 122, 174, 173, 338, 220, 1258, 40, 38, 36, 35, + /* 290 */ 34, 159, 306, 61, 42, 1922, 1333, 1739, 1256, 1113, + /* 300 */ 605, 604, 603, 1117, 602, 1119, 1120, 601, 1122, 598, + /* 310 */ 1800, 1128, 595, 1130, 1131, 592, 589, 1296, 545, 1328, + /* 320 */ 120, 1782, 33, 32, 14, 1355, 40, 38, 36, 35, + /* 330 */ 34, 1264, 39, 37, 554, 155, 1867, 1868, 86, 1872, + /* 340 */ 338, 552, 1258, 1769, 359, 1650, 1238, 1239, 2, 1800, + /* 350 */ 341, 119, 326, 1333, 1766, 1256, 544, 581, 140, 1590, + /* 360 */ 344, 1648, 1752, 529, 580, 1400, 1452, 1600, 140, 122, + /* 370 */ 662, 1282, 1282, 379, 165, 378, 1328, 1600, 557, 1356, + /* 380 */ 1762, 1768, 333, 1576, 1335, 1336, 1460, 432, 1264, 1813, + /* 390 */ 436, 1598, 574, 89, 1783, 583, 1785, 1786, 579, 1481, + /* 400 */ 574, 440, 1361, 1859, 436, 8, 215, 305, 1855, 120, + /* 410 */ 112, 111, 110, 109, 108, 107, 106, 105, 104, 1925, + /* 420 */ 482, 481, 632, 630, 156, 1867, 1868, 662, 1872, 1259, + /* 430 */ 208, 1257, 159, 162, 162, 61, 1922, 75, 516, 1480, + /* 440 */ 1752, 1335, 1336, 450, 29, 336, 1350, 1351, 1352, 1353, + /* 450 */ 1354, 1358, 1359, 1360, 1479, 315, 1262, 1263, 546, 1311, + /* 460 */ 1312, 1314, 1315, 1316, 1317, 1318, 576, 572, 1326, 1327, + /* 470 */ 1329, 1330, 1331, 1332, 1334, 1337, 1392, 33, 32, 1925, + /* 480 */ 1752, 40, 38, 36, 35, 34, 1259, 1357, 1257, 73, + /* 490 */ 304, 1650, 159, 519, 541, 1752, 1922, 33, 32, 348, + /* 500 */ 1284, 40, 38, 36, 35, 34, 316, 1649, 314, 313, + /* 510 */ 1362, 473, 616, 1262, 1263, 475, 1311, 1312, 1314, 1315, + /* 520 */ 1316, 1317, 1318, 576, 572, 1326, 1327, 1329, 1330, 1331, + /* 530 */ 1332, 1334, 1337, 39, 37, 1338, 438, 474, 1006, 1007, + /* 540 */ 1925, 338, 1280, 1258, 1782, 162, 1874, 1478, 1313, 1019, + /* 550 */ 306, 1018, 27, 159, 1333, 1427, 1256, 1922, 1589, 33, + /* 560 */ 32, 221, 222, 40, 38, 36, 35, 34, 1285, 1766, + /* 570 */ 1871, 552, 1800, 547, 542, 162, 1574, 1328, 1281, 1020, + /* 580 */ 556, 529, 529, 1355, 153, 1752, 1477, 580, 1752, 1264, + /* 590 */ 39, 37, 384, 385, 22, 1762, 1768, 1637, 338, 122, + /* 600 */ 1258, 1522, 1075, 11, 10, 140, 9, 574, 1650, 1598, + /* 610 */ 1598, 1333, 1813, 1256, 1601, 342, 90, 1783, 583, 1785, + /* 620 */ 1786, 579, 304, 574, 1648, 519, 1859, 1752, 662, 529, + /* 630 */ 329, 1855, 154, 252, 1328, 1077, 616, 1356, 1874, 120, + /* 640 */ 389, 1473, 1335, 1336, 158, 1343, 1264, 1694, 1688, 299, + /* 650 */ 517, 1282, 1885, 1264, 157, 1867, 1868, 1598, 1872, 172, + /* 660 */ 1361, 1696, 1870, 9, 639, 638, 637, 636, 346, 561, + /* 670 */ 635, 634, 633, 123, 628, 627, 626, 625, 624, 623, + /* 680 */ 622, 621, 133, 617, 1525, 662, 1282, 1259, 1369, 1257, + /* 690 */ 33, 32, 1874, 1476, 40, 38, 36, 35, 34, 1335, + /* 700 */ 1336, 232, 29, 336, 1350, 1351, 1352, 1353, 1354, 1358, + /* 710 */ 1359, 1360, 7, 1475, 1262, 1263, 1869, 1311, 1312, 1314, + /* 720 */ 1315, 1316, 1317, 1318, 576, 572, 1326, 1327, 1329, 1330, + /* 730 */ 1331, 1332, 1334, 1337, 1752, 33, 32, 1879, 1389, 40, + /* 740 */ 38, 36, 35, 34, 1259, 608, 1257, 486, 485, 484, + /* 750 */ 44, 4, 1258, 483, 1752, 272, 118, 480, 1628, 619, + /* 760 */ 479, 478, 477, 1474, 1585, 1256, 1417, 1693, 1407, 299, + /* 770 */ 612, 1262, 1263, 1641, 1311, 1312, 1314, 1315, 1316, 1317, + /* 780 */ 1318, 576, 572, 1326, 1327, 1329, 1330, 1331, 1332, 1334, + /* 790 */ 1337, 39, 37, 301, 613, 1280, 614, 1641, 1264, 338, + /* 800 */ 1581, 1258, 412, 1782, 1752, 424, 211, 538, 1415, 1416, + /* 810 */ 1418, 1419, 1333, 1296, 1256, 131, 130, 611, 610, 609, + /* 820 */ 11, 10, 397, 1575, 425, 575, 399, 59, 1313, 529, + /* 830 */ 529, 1800, 529, 1471, 620, 1328, 1570, 662, 1573, 581, + /* 840 */ 404, 405, 26, 449, 1752, 509, 580, 1264, 33, 32, + /* 850 */ 1507, 1505, 40, 38, 36, 35, 34, 1598, 1598, 390, + /* 860 */ 1598, 33, 32, 1313, 2, 40, 38, 36, 35, 34, + /* 870 */ 562, 1813, 489, 492, 1752, 91, 1783, 583, 1785, 1786, + /* 880 */ 579, 28, 574, 607, 631, 1859, 662, 33, 32, 1858, + /* 890 */ 1855, 40, 38, 36, 35, 34, 1259, 1389, 1257, 423, + /* 900 */ 1335, 1336, 418, 417, 416, 415, 414, 411, 410, 409, + /* 910 */ 408, 407, 403, 402, 401, 400, 394, 393, 392, 391, + /* 920 */ 614, 388, 387, 1262, 1263, 529, 1470, 374, 199, 141, + /* 930 */ 1555, 197, 564, 529, 278, 614, 1595, 52, 513, 131, + /* 940 */ 130, 611, 610, 609, 1727, 1259, 255, 1257, 276, 58, + /* 950 */ 41, 219, 57, 1598, 131, 130, 611, 610, 609, 1267, + /* 960 */ 1770, 1598, 502, 1469, 1782, 1455, 1456, 1752, 177, 429, + /* 970 */ 427, 1766, 1262, 1263, 1468, 1311, 1312, 1314, 1315, 1316, + /* 980 */ 1317, 1318, 576, 572, 1326, 1327, 1329, 1330, 1331, 1332, + /* 990 */ 1334, 1337, 1800, 1206, 223, 539, 61, 1762, 1768, 529, + /* 1000 */ 581, 468, 529, 1925, 1752, 1752, 139, 580, 1467, 574, + /* 1010 */ 510, 1266, 1466, 514, 529, 1752, 159, 1772, 201, 1465, + /* 1020 */ 1922, 200, 1464, 203, 1463, 527, 202, 1598, 570, 503, + /* 1030 */ 1598, 1801, 1813, 244, 88, 125, 90, 1783, 583, 1785, + /* 1040 */ 1786, 579, 1598, 574, 529, 1782, 1859, 529, 529, 1752, + /* 1050 */ 329, 1855, 1938, 1752, 205, 528, 1774, 204, 261, 345, + /* 1060 */ 1752, 1893, 552, 1752, 1046, 1752, 559, 128, 1501, 66, + /* 1070 */ 65, 383, 1598, 1800, 169, 1598, 1598, 347, 522, 85, + /* 1080 */ 377, 581, 129, 50, 335, 334, 1752, 1496, 580, 82, + /* 1090 */ 122, 236, 1270, 300, 1272, 1638, 367, 1047, 365, 361, + /* 1100 */ 357, 166, 352, 349, 249, 1333, 1889, 1265, 254, 553, + /* 1110 */ 229, 557, 257, 1813, 50, 3, 657, 90, 1783, 583, + /* 1120 */ 1785, 1786, 579, 1782, 574, 1106, 1414, 1859, 1328, 41, + /* 1130 */ 120, 329, 1855, 1938, 239, 565, 162, 41, 491, 259, + /* 1140 */ 1264, 80, 1916, 587, 1269, 250, 1867, 551, 53, 550, + /* 1150 */ 5, 1800, 1925, 501, 351, 1280, 354, 1363, 128, 581, + /* 1160 */ 1347, 358, 1222, 129, 1752, 159, 580, 207, 311, 1922, + /* 1170 */ 114, 128, 1319, 1075, 312, 406, 1782, 268, 1690, 569, + /* 1180 */ 271, 494, 171, 413, 421, 488, 1134, 420, 422, 1286, + /* 1190 */ 206, 1813, 426, 428, 430, 90, 1783, 583, 1785, 1786, + /* 1200 */ 579, 1138, 574, 431, 1800, 1859, 1145, 439, 1289, 329, + /* 1210 */ 1855, 1938, 581, 1143, 132, 442, 180, 1752, 56, 580, + /* 1220 */ 1878, 55, 443, 182, 1288, 1290, 445, 444, 1782, 185, + /* 1230 */ 447, 187, 1287, 557, 189, 451, 70, 448, 1273, 470, + /* 1240 */ 1268, 472, 192, 1588, 1813, 303, 196, 1732, 285, 1783, + /* 1250 */ 583, 1785, 1786, 579, 1584, 574, 1800, 93, 269, 198, + /* 1260 */ 134, 135, 504, 1586, 581, 1276, 1582, 136, 137, 1752, + /* 1270 */ 209, 580, 505, 212, 1925, 511, 572, 1326, 1327, 1329, + /* 1280 */ 1330, 1331, 1332, 515, 508, 557, 216, 161, 518, 537, + /* 1290 */ 227, 1922, 321, 1782, 126, 1731, 1813, 127, 1700, 520, + /* 1300 */ 285, 1783, 583, 1785, 1786, 579, 323, 574, 523, 1782, + /* 1310 */ 225, 524, 270, 525, 78, 1599, 1285, 1890, 533, 535, + /* 1320 */ 540, 1800, 234, 238, 1900, 536, 1925, 328, 6, 581, + /* 1330 */ 543, 549, 534, 532, 1752, 531, 580, 1800, 248, 159, + /* 1340 */ 1389, 121, 1284, 1922, 566, 578, 563, 48, 1899, 330, + /* 1350 */ 1752, 1875, 580, 1840, 585, 1881, 245, 243, 1642, 148, + /* 1360 */ 247, 1813, 273, 264, 1782, 91, 1783, 583, 1785, 1786, + /* 1370 */ 579, 246, 574, 1571, 658, 1859, 1782, 1813, 659, 568, + /* 1380 */ 1855, 293, 1783, 583, 1785, 1786, 579, 577, 574, 571, + /* 1390 */ 1831, 661, 1800, 51, 147, 275, 1746, 1921, 253, 286, + /* 1400 */ 581, 296, 295, 277, 1800, 1752, 560, 580, 256, 1941, + /* 1410 */ 567, 63, 581, 258, 1745, 1744, 64, 1752, 1743, 580, + /* 1420 */ 353, 1740, 355, 356, 1250, 1251, 167, 360, 1738, 362, + /* 1430 */ 363, 364, 1813, 1737, 366, 1736, 144, 1783, 583, 1785, + /* 1440 */ 1786, 579, 368, 574, 1813, 1735, 370, 1734, 91, 1783, + /* 1450 */ 583, 1785, 1786, 579, 1782, 574, 1717, 372, 1859, 375, + /* 1460 */ 168, 376, 1225, 1856, 1224, 1711, 1710, 381, 1782, 382, + /* 1470 */ 1709, 1708, 1194, 1683, 1682, 1681, 67, 1680, 1782, 1679, + /* 1480 */ 558, 1939, 1800, 1678, 1677, 1676, 395, 322, 396, 1675, + /* 1490 */ 581, 398, 1674, 1673, 1672, 1752, 1800, 580, 1671, 1670, + /* 1500 */ 1669, 530, 1668, 1667, 581, 1666, 1800, 1665, 1664, 1752, + /* 1510 */ 1663, 580, 1662, 1661, 581, 1660, 1659, 1658, 124, 1752, + /* 1520 */ 1657, 580, 1813, 1656, 1655, 1654, 294, 1783, 583, 1785, + /* 1530 */ 1786, 579, 1653, 574, 1652, 1782, 1813, 1651, 1527, 1526, + /* 1540 */ 294, 1783, 583, 1785, 1786, 579, 1813, 574, 1524, 1196, + /* 1550 */ 289, 1783, 583, 1785, 1786, 579, 1492, 574, 1491, 1782, + /* 1560 */ 175, 178, 176, 1800, 152, 115, 1009, 1008, 435, 179, + /* 1570 */ 116, 581, 1725, 1719, 437, 1707, 1752, 186, 580, 184, + /* 1580 */ 1706, 1692, 1577, 1523, 1521, 1782, 452, 1800, 548, 453, + /* 1590 */ 1519, 1517, 1039, 454, 456, 578, 457, 460, 1515, 458, + /* 1600 */ 1752, 1504, 580, 1813, 461, 462, 464, 144, 1783, 583, + /* 1610 */ 1785, 1786, 579, 1800, 574, 465, 466, 1503, 337, 1488, + /* 1620 */ 1579, 581, 1149, 1578, 1148, 195, 1752, 1813, 580, 49, + /* 1630 */ 1074, 293, 1783, 583, 1785, 1786, 579, 629, 574, 1782, + /* 1640 */ 1832, 1073, 1072, 631, 1071, 1068, 1067, 1066, 1065, 1513, + /* 1650 */ 317, 1508, 1940, 1813, 318, 665, 1506, 294, 1783, 583, + /* 1660 */ 1785, 1786, 579, 490, 574, 319, 493, 1800, 1487, 267, + /* 1670 */ 495, 1486, 339, 497, 1485, 581, 499, 92, 1724, 1232, + /* 1680 */ 1752, 1718, 580, 151, 506, 1705, 138, 1703, 655, 651, + /* 1690 */ 647, 643, 265, 1704, 54, 213, 507, 1702, 1701, 320, + /* 1700 */ 15, 1699, 512, 1691, 218, 226, 224, 1813, 41, 76, + /* 1710 */ 77, 294, 1783, 583, 1785, 1786, 579, 194, 574, 231, + /* 1720 */ 87, 521, 1782, 230, 82, 228, 16, 23, 242, 47, + /* 1730 */ 233, 146, 1429, 235, 1411, 237, 467, 463, 459, 455, + /* 1740 */ 193, 1413, 1242, 145, 240, 24, 1782, 1406, 241, 81, + /* 1750 */ 1800, 10, 1772, 25, 1441, 1386, 526, 251, 581, 45, + /* 1760 */ 46, 1385, 1771, 1752, 149, 580, 1446, 18, 72, 1435, + /* 1770 */ 1440, 191, 331, 1445, 1800, 1444, 332, 1274, 1348, 17, + /* 1780 */ 1816, 573, 581, 1304, 13, 19, 1323, 1752, 217, 580, + /* 1790 */ 1813, 150, 163, 1321, 279, 1783, 583, 1785, 1786, 579, + /* 1800 */ 31, 574, 1782, 586, 1112, 584, 1320, 12, 20, 1230, + /* 1810 */ 21, 210, 1135, 340, 1813, 588, 590, 582, 280, 1783, + /* 1820 */ 583, 1785, 1786, 579, 591, 574, 593, 596, 599, 1132, + /* 1830 */ 1800, 606, 594, 190, 183, 597, 188, 1129, 581, 1123, + /* 1840 */ 446, 1127, 1121, 1752, 1782, 580, 1144, 600, 83, 84, + /* 1850 */ 60, 262, 1140, 1126, 1782, 1062, 1037, 1125, 615, 181, + /* 1860 */ 618, 1124, 263, 1081, 1060, 1055, 1782, 1059, 1058, 1057, + /* 1870 */ 1813, 1056, 1800, 1054, 281, 1783, 583, 1785, 1786, 579, + /* 1880 */ 581, 574, 1800, 1053, 1078, 1752, 1076, 580, 1050, 1049, + /* 1890 */ 581, 1048, 1045, 1044, 1800, 1752, 1043, 580, 1042, 1520, + /* 1900 */ 640, 642, 581, 1518, 644, 646, 641, 1752, 1516, 580, + /* 1910 */ 648, 645, 1813, 650, 649, 1514, 288, 1783, 583, 1785, + /* 1920 */ 1786, 579, 1813, 574, 652, 653, 290, 1783, 583, 1785, + /* 1930 */ 1786, 579, 654, 574, 1813, 656, 999, 1484, 282, 1783, + /* 1940 */ 583, 1785, 1786, 579, 1502, 574, 266, 1782, 660, 1459, + /* 1950 */ 1260, 274, 663, 664, 1459, 1459, 1459, 1459, 1459, 1459, + /* 1960 */ 1459, 1459, 1459, 1459, 1459, 1459, 1782, 1459, 1459, 1459, + /* 1970 */ 1459, 1459, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, + /* 1980 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, + /* 1990 */ 580, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, 1459, + /* 2000 */ 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, 580, + /* 2010 */ 1459, 1459, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 291, + /* 2020 */ 1783, 583, 1785, 1786, 579, 1459, 574, 1782, 1459, 1459, + /* 2030 */ 1459, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 283, 1783, + /* 2040 */ 583, 1785, 1786, 579, 1459, 574, 1782, 1459, 1459, 1459, + /* 2050 */ 1459, 1459, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, + /* 2060 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, + /* 2070 */ 580, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, 1459, + /* 2080 */ 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, 580, + /* 2090 */ 1459, 1459, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 292, + /* 2100 */ 1783, 583, 1785, 1786, 579, 1459, 574, 1459, 1459, 1459, + /* 2110 */ 1459, 1459, 1459, 1782, 1813, 1459, 1459, 1459, 284, 1783, + /* 2120 */ 583, 1785, 1786, 579, 1459, 574, 1459, 1459, 1459, 1782, + /* 2130 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1782, + /* 2140 */ 1459, 1800, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 581, + /* 2150 */ 1459, 1459, 1459, 1459, 1752, 1459, 580, 1800, 1459, 1459, + /* 2160 */ 1459, 1459, 1459, 1459, 1459, 581, 1459, 1800, 1459, 1459, + /* 2170 */ 1752, 1459, 580, 1459, 1459, 581, 1459, 1459, 1459, 1459, + /* 2180 */ 1752, 1813, 580, 1459, 1459, 297, 1783, 583, 1785, 1786, + /* 2190 */ 579, 1459, 574, 1782, 1459, 1459, 1459, 1813, 1459, 1459, + /* 2200 */ 1459, 298, 1783, 583, 1785, 1786, 579, 1813, 574, 1459, + /* 2210 */ 1459, 1794, 1783, 583, 1785, 1786, 579, 1459, 574, 1459, + /* 2220 */ 1459, 1800, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 581, + /* 2230 */ 1459, 1459, 1459, 1459, 1752, 1459, 580, 1459, 1459, 1459, + /* 2240 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1782, 1459, 1459, + /* 2250 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 2260 */ 1459, 1813, 1459, 1459, 1459, 1793, 1783, 583, 1785, 1786, + /* 2270 */ 579, 1459, 574, 1459, 1459, 1800, 1459, 1459, 1459, 1459, + /* 2280 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, + /* 2290 */ 580, 1459, 1459, 1459, 1459, 1459, 1459, 1782, 1459, 1459, + /* 2300 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 2310 */ 1459, 1459, 1459, 1459, 1782, 1813, 1459, 1459, 1459, 1792, + /* 2320 */ 1783, 583, 1785, 1786, 579, 1800, 574, 1459, 1459, 1459, + /* 2330 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, + /* 2340 */ 580, 1459, 1800, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 2350 */ 581, 1459, 1459, 1459, 1459, 1752, 1459, 580, 1459, 1459, + /* 2360 */ 1459, 1459, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 309, + /* 2370 */ 1783, 583, 1785, 1786, 579, 1459, 574, 1782, 1459, 1459, + /* 2380 */ 1459, 1459, 1813, 1459, 1459, 1459, 308, 1783, 583, 1785, + /* 2390 */ 1786, 579, 1459, 574, 1459, 1459, 1459, 1459, 1782, 1459, + /* 2400 */ 1459, 1459, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, + /* 2410 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, + /* 2420 */ 580, 1459, 1459, 1459, 1459, 1459, 1800, 1459, 1459, 1459, + /* 2430 */ 1459, 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, + /* 2440 */ 1782, 580, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 310, + /* 2450 */ 1783, 583, 1785, 1786, 579, 1459, 574, 1459, 1459, 1459, + /* 2460 */ 1459, 1459, 1459, 1459, 1459, 1459, 1813, 1459, 1800, 1459, + /* 2470 */ 307, 1783, 583, 1785, 1786, 579, 581, 574, 1459, 1459, + /* 2480 */ 1459, 1752, 1459, 580, 1459, 1459, 1459, 1459, 1459, 1459, + /* 2490 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 2500 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1813, 1459, + /* 2510 */ 1459, 1459, 287, 1783, 583, 1785, 1786, 579, 1459, 574, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 261, 355, 263, 264, 261, 269, 263, 264, 300, 4, - /* 10 */ 285, 0, 12, 13, 368, 265, 308, 292, 372, 311, - /* 20 */ 20, 267, 22, 0, 8, 9, 301, 291, 12, 13, - /* 30 */ 14, 15, 16, 33, 280, 35, 257, 12, 13, 14, - /* 40 */ 15, 16, 288, 293, 21, 0, 265, 24, 25, 26, - /* 50 */ 27, 28, 29, 30, 31, 32, 56, 265, 265, 43, - /* 60 */ 60, 20, 296, 22, 285, 299, 300, 67, 276, 256, - /* 70 */ 285, 258, 293, 267, 293, 283, 35, 298, 293, 300, - /* 80 */ 12, 13, 14, 333, 84, 293, 293, 84, 20, 84, - /* 90 */ 22, 50, 47, 314, 288, 314, 314, 347, 348, 349, - /* 100 */ 350, 33, 352, 35, 325, 257, 106, 0, 329, 330, - /* 110 */ 331, 332, 333, 334, 333, 336, 331, 20, 339, 20, - /* 120 */ 120, 121, 343, 344, 56, 257, 333, 265, 60, 348, - /* 130 */ 349, 350, 0, 352, 355, 67, 355, 355, 276, 340, - /* 140 */ 341, 348, 349, 350, 257, 352, 298, 368, 59, 368, - /* 150 */ 368, 372, 84, 372, 372, 293, 24, 25, 26, 27, - /* 160 */ 28, 29, 30, 31, 32, 165, 298, 167, 20, 62, - /* 170 */ 63, 64, 285, 355, 106, 68, 115, 116, 71, 72, - /* 180 */ 293, 84, 75, 76, 77, 298, 368, 300, 120, 121, - /* 190 */ 372, 262, 192, 193, 265, 195, 196, 197, 198, 199, + /* 0 */ 266, 0, 262, 266, 264, 265, 262, 287, 264, 265, + /* 10 */ 288, 277, 12, 13, 266, 4, 301, 287, 284, 315, + /* 20 */ 20, 299, 22, 4, 309, 268, 258, 312, 294, 341, + /* 30 */ 342, 294, 271, 33, 21, 35, 275, 24, 25, 26, + /* 40 */ 27, 28, 29, 30, 31, 32, 289, 325, 326, 327, + /* 50 */ 270, 303, 315, 356, 286, 20, 56, 0, 20, 337, + /* 60 */ 356, 61, 294, 44, 45, 21, 369, 299, 68, 301, + /* 70 */ 373, 334, 292, 369, 12, 13, 14, 373, 34, 22, + /* 80 */ 36, 266, 20, 315, 22, 85, 349, 350, 351, 20, + /* 90 */ 353, 22, 277, 356, 326, 33, 85, 35, 330, 331, + /* 100 */ 332, 333, 334, 335, 35, 337, 369, 107, 340, 294, + /* 110 */ 373, 297, 344, 345, 300, 301, 270, 85, 56, 50, + /* 120 */ 85, 121, 122, 61, 356, 0, 356, 8, 9, 283, + /* 130 */ 68, 12, 13, 14, 15, 16, 97, 369, 292, 369, + /* 140 */ 257, 373, 259, 373, 258, 258, 21, 85, 56, 24, + /* 150 */ 25, 26, 27, 28, 29, 30, 31, 32, 119, 121, + /* 160 */ 122, 63, 64, 65, 56, 356, 166, 69, 168, 107, + /* 170 */ 72, 73, 278, 286, 76, 77, 78, 255, 369, 87, + /* 180 */ 286, 294, 373, 121, 122, 299, 299, 20, 301, 295, + /* 190 */ 300, 301, 84, 193, 194, 87, 196, 197, 198, 199, /* 200 */ 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, - /* 210 */ 210, 211, 325, 192, 20, 150, 329, 330, 331, 332, - /* 220 */ 333, 334, 20, 336, 224, 254, 339, 224, 20, 224, - /* 230 */ 343, 344, 345, 165, 37, 167, 84, 176, 285, 270, - /* 240 */ 179, 354, 4, 274, 8, 9, 285, 294, 12, 13, - /* 250 */ 14, 15, 16, 292, 233, 234, 235, 236, 237, 257, - /* 260 */ 192, 193, 301, 195, 196, 197, 198, 199, 200, 201, - /* 270 */ 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, - /* 280 */ 12, 13, 44, 45, 87, 314, 89, 90, 20, 92, - /* 290 */ 22, 257, 84, 96, 229, 230, 60, 147, 1, 2, - /* 300 */ 298, 33, 21, 35, 284, 24, 25, 26, 27, 28, - /* 310 */ 29, 30, 31, 32, 265, 118, 164, 297, 166, 285, - /* 320 */ 170, 85, 120, 121, 56, 20, 355, 293, 60, 93, - /* 330 */ 299, 300, 298, 262, 300, 67, 265, 12, 13, 368, - /* 340 */ 62, 63, 64, 372, 355, 20, 68, 22, 0, 71, - /* 350 */ 72, 302, 84, 75, 76, 77, 95, 368, 33, 325, - /* 360 */ 35, 372, 212, 329, 330, 331, 332, 333, 334, 14, - /* 370 */ 336, 269, 160, 339, 106, 20, 224, 343, 344, 345, - /* 380 */ 14, 56, 85, 147, 282, 20, 20, 22, 120, 121, - /* 390 */ 196, 357, 67, 291, 182, 183, 20, 8, 9, 365, - /* 400 */ 0, 12, 13, 14, 15, 16, 170, 271, 272, 84, - /* 410 */ 62, 63, 64, 65, 66, 50, 68, 69, 70, 71, - /* 420 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, - /* 430 */ 277, 106, 224, 165, 43, 167, 8, 9, 285, 59, - /* 440 */ 12, 13, 14, 15, 16, 120, 121, 294, 212, 213, - /* 450 */ 214, 215, 216, 217, 218, 219, 220, 221, 20, 59, - /* 460 */ 192, 193, 257, 195, 196, 197, 198, 199, 200, 201, - /* 470 */ 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, - /* 480 */ 8, 9, 56, 265, 12, 13, 14, 15, 16, 56, - /* 490 */ 165, 116, 167, 115, 276, 20, 277, 14, 15, 16, - /* 500 */ 3, 8, 9, 298, 285, 12, 13, 14, 15, 16, - /* 510 */ 84, 293, 86, 294, 271, 272, 83, 192, 193, 86, - /* 520 */ 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, - /* 530 */ 205, 206, 207, 208, 209, 210, 211, 12, 13, 14, - /* 540 */ 310, 152, 312, 257, 277, 20, 257, 22, 20, 224, - /* 550 */ 175, 176, 285, 60, 179, 177, 178, 85, 33, 78, - /* 560 */ 35, 294, 196, 97, 98, 99, 100, 101, 102, 103, - /* 570 */ 104, 105, 106, 107, 285, 109, 110, 111, 112, 113, - /* 580 */ 114, 56, 293, 4, 298, 157, 93, 298, 265, 300, - /* 590 */ 152, 96, 67, 257, 12, 13, 293, 22, 19, 276, - /* 600 */ 42, 43, 20, 314, 22, 124, 125, 304, 67, 84, - /* 610 */ 35, 35, 33, 118, 325, 33, 293, 35, 329, 330, - /* 620 */ 331, 332, 333, 334, 21, 336, 47, 152, 339, 257, - /* 630 */ 51, 106, 343, 344, 298, 56, 245, 34, 56, 36, - /* 640 */ 147, 2, 67, 67, 355, 120, 121, 8, 9, 67, - /* 650 */ 224, 12, 13, 14, 15, 16, 0, 368, 327, 257, - /* 660 */ 257, 372, 83, 170, 96, 86, 84, 327, 43, 265, - /* 670 */ 298, 8, 9, 285, 246, 12, 13, 14, 15, 16, - /* 680 */ 276, 106, 351, 115, 116, 117, 118, 119, 106, 301, - /* 690 */ 165, 351, 167, 44, 45, 327, 314, 293, 257, 39, - /* 700 */ 298, 298, 120, 121, 0, 212, 213, 214, 215, 216, - /* 710 */ 217, 218, 219, 220, 221, 59, 286, 192, 193, 351, - /* 720 */ 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, - /* 730 */ 205, 206, 207, 208, 209, 210, 211, 355, 241, 298, - /* 740 */ 165, 310, 167, 312, 273, 2, 275, 165, 85, 167, - /* 750 */ 368, 8, 9, 300, 372, 12, 13, 14, 15, 16, - /* 760 */ 314, 222, 223, 35, 311, 8, 9, 192, 193, 12, - /* 770 */ 13, 14, 15, 16, 192, 193, 56, 195, 196, 197, - /* 780 */ 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, - /* 790 */ 208, 209, 210, 211, 12, 13, 18, 286, 20, 257, - /* 800 */ 96, 355, 20, 257, 22, 27, 86, 295, 30, 257, - /* 810 */ 298, 0, 4, 265, 368, 33, 314, 35, 372, 115, - /* 820 */ 116, 117, 118, 119, 276, 47, 257, 49, 257, 51, - /* 830 */ 14, 285, 295, 22, 278, 298, 20, 281, 56, 293, - /* 840 */ 298, 293, 85, 0, 298, 265, 300, 8, 9, 67, - /* 850 */ 298, 12, 13, 14, 15, 16, 276, 355, 265, 152, - /* 860 */ 153, 83, 88, 283, 35, 91, 84, 298, 243, 298, - /* 870 */ 368, 325, 67, 293, 372, 329, 330, 331, 332, 333, - /* 880 */ 334, 257, 336, 223, 257, 339, 293, 257, 106, 343, - /* 890 */ 344, 345, 257, 257, 88, 167, 0, 91, 60, 286, - /* 900 */ 354, 123, 120, 121, 126, 127, 128, 129, 130, 131, - /* 910 */ 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, - /* 920 */ 142, 143, 298, 145, 146, 298, 333, 265, 298, 265, - /* 930 */ 43, 18, 286, 298, 298, 265, 23, 265, 276, 96, - /* 940 */ 276, 348, 349, 350, 48, 352, 276, 165, 276, 167, - /* 950 */ 37, 38, 1, 2, 41, 293, 318, 293, 115, 116, - /* 960 */ 117, 118, 119, 293, 286, 293, 257, 120, 121, 286, - /* 970 */ 57, 58, 85, 43, 192, 193, 265, 195, 196, 197, - /* 980 */ 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, - /* 990 */ 208, 209, 210, 211, 285, 265, 167, 84, 88, 265, - /* 1000 */ 265, 91, 293, 265, 293, 88, 276, 298, 91, 300, - /* 1010 */ 276, 276, 196, 287, 276, 85, 43, 258, 287, 286, - /* 1020 */ 274, 265, 375, 293, 298, 314, 266, 293, 293, 298, - /* 1030 */ 192, 293, 276, 225, 325, 122, 265, 257, 329, 330, - /* 1040 */ 331, 332, 333, 334, 333, 336, 0, 276, 339, 293, - /* 1050 */ 324, 325, 343, 344, 345, 324, 325, 326, 85, 348, - /* 1060 */ 349, 350, 336, 352, 293, 285, 355, 336, 22, 0, - /* 1070 */ 157, 158, 159, 293, 365, 162, 366, 362, 298, 368, - /* 1080 */ 300, 168, 46, 372, 43, 12, 13, 265, 43, 35, - /* 1090 */ 43, 22, 285, 43, 181, 22, 43, 184, 276, 186, - /* 1100 */ 187, 188, 189, 190, 191, 325, 33, 287, 35, 329, - /* 1110 */ 330, 331, 332, 333, 334, 293, 336, 43, 298, 339, - /* 1120 */ 84, 67, 43, 343, 344, 345, 85, 266, 43, 56, - /* 1130 */ 85, 43, 85, 257, 354, 85, 84, 224, 85, 43, - /* 1140 */ 67, 43, 43, 43, 324, 325, 94, 321, 264, 297, - /* 1150 */ 353, 328, 369, 369, 369, 346, 336, 356, 289, 85, - /* 1160 */ 84, 285, 226, 323, 85, 20, 265, 47, 322, 293, - /* 1170 */ 85, 35, 163, 85, 298, 271, 300, 265, 316, 106, - /* 1180 */ 265, 85, 42, 85, 85, 85, 305, 147, 303, 303, - /* 1190 */ 314, 265, 265, 20, 257, 20, 20, 259, 259, 320, - /* 1200 */ 269, 325, 300, 269, 313, 329, 330, 331, 332, 333, - /* 1210 */ 334, 20, 336, 315, 269, 269, 313, 20, 269, 269, - /* 1220 */ 306, 265, 285, 269, 259, 285, 285, 285, 285, 285, - /* 1230 */ 293, 355, 285, 285, 265, 298, 259, 300, 165, 320, - /* 1240 */ 167, 267, 285, 285, 368, 285, 285, 257, 372, 267, - /* 1250 */ 298, 314, 319, 173, 265, 300, 265, 231, 20, 267, - /* 1260 */ 298, 298, 325, 149, 298, 192, 329, 330, 331, 332, - /* 1270 */ 333, 334, 313, 336, 298, 285, 203, 204, 205, 206, - /* 1280 */ 207, 208, 209, 293, 309, 298, 307, 309, 298, 293, - /* 1290 */ 300, 306, 355, 281, 267, 267, 293, 298, 328, 257, - /* 1300 */ 232, 238, 309, 298, 298, 368, 309, 156, 298, 372, - /* 1310 */ 240, 298, 223, 227, 361, 325, 239, 323, 293, 329, - /* 1320 */ 330, 331, 332, 333, 334, 361, 336, 285, 360, 339, - /* 1330 */ 358, 364, 361, 343, 344, 293, 20, 244, 327, 242, - /* 1340 */ 298, 247, 300, 363, 84, 359, 342, 289, 265, 298, - /* 1350 */ 275, 370, 257, 36, 371, 317, 312, 267, 0, 371, - /* 1360 */ 376, 260, 259, 279, 175, 370, 257, 325, 255, 371, - /* 1370 */ 370, 329, 330, 331, 332, 333, 334, 0, 336, 268, - /* 1380 */ 285, 339, 0, 279, 279, 343, 344, 42, 293, 0, - /* 1390 */ 75, 0, 35, 298, 285, 300, 185, 35, 35, 35, - /* 1400 */ 185, 0, 293, 35, 35, 185, 0, 298, 185, 300, - /* 1410 */ 0, 0, 22, 35, 0, 35, 0, 84, 170, 257, - /* 1420 */ 325, 169, 167, 165, 329, 330, 331, 332, 333, 334, - /* 1430 */ 335, 336, 337, 338, 325, 0, 0, 257, 329, 330, - /* 1440 */ 331, 332, 333, 334, 161, 336, 160, 285, 0, 0, - /* 1450 */ 46, 0, 0, 0, 144, 293, 0, 0, 0, 0, - /* 1460 */ 298, 0, 300, 139, 35, 285, 0, 139, 0, 0, - /* 1470 */ 290, 0, 0, 293, 0, 0, 0, 0, 298, 0, - /* 1480 */ 300, 0, 373, 374, 0, 0, 0, 325, 0, 257, - /* 1490 */ 0, 329, 330, 331, 332, 333, 334, 42, 336, 0, - /* 1500 */ 0, 339, 0, 0, 0, 325, 344, 0, 0, 329, - /* 1510 */ 330, 331, 332, 333, 334, 22, 336, 285, 0, 0, - /* 1520 */ 0, 56, 290, 0, 0, 293, 43, 14, 39, 42, - /* 1530 */ 298, 257, 300, 0, 40, 14, 39, 46, 46, 0, - /* 1540 */ 0, 257, 0, 156, 39, 0, 0, 0, 0, 0, - /* 1550 */ 35, 39, 0, 39, 0, 39, 61, 325, 47, 285, - /* 1560 */ 35, 329, 330, 331, 332, 333, 334, 293, 336, 285, - /* 1570 */ 35, 0, 298, 47, 300, 47, 35, 293, 47, 0, - /* 1580 */ 0, 0, 298, 39, 300, 0, 35, 22, 0, 91, - /* 1590 */ 35, 257, 35, 35, 93, 35, 43, 0, 35, 325, - /* 1600 */ 22, 35, 43, 329, 330, 331, 332, 333, 334, 325, - /* 1610 */ 336, 19, 35, 329, 330, 331, 332, 333, 334, 285, - /* 1620 */ 336, 35, 0, 22, 290, 33, 35, 293, 0, 22, - /* 1630 */ 0, 49, 298, 257, 300, 35, 0, 35, 0, 47, - /* 1640 */ 22, 367, 0, 20, 52, 53, 54, 55, 56, 0, - /* 1650 */ 35, 257, 0, 171, 22, 0, 0, 0, 374, 325, - /* 1660 */ 0, 285, 152, 329, 330, 331, 332, 333, 334, 293, - /* 1670 */ 336, 149, 85, 84, 298, 83, 300, 0, 86, 285, - /* 1680 */ 84, 152, 152, 84, 290, 39, 154, 293, 150, 180, - /* 1690 */ 0, 148, 298, 84, 300, 228, 46, 94, 85, 35, - /* 1700 */ 84, 325, 43, 257, 84, 329, 330, 331, 332, 333, - /* 1710 */ 334, 119, 336, 84, 338, 22, 85, 43, 85, 325, - /* 1720 */ 85, 84, 43, 329, 330, 331, 332, 333, 334, 84, - /* 1730 */ 336, 285, 84, 46, 46, 33, 290, 43, 85, 293, - /* 1740 */ 43, 46, 84, 151, 298, 228, 300, 85, 85, 47, - /* 1750 */ 46, 46, 85, 257, 52, 53, 54, 55, 56, 222, - /* 1760 */ 43, 85, 228, 257, 172, 35, 174, 35, 35, 35, - /* 1770 */ 35, 325, 2, 84, 43, 329, 330, 331, 332, 333, - /* 1780 */ 334, 285, 336, 85, 84, 83, 192, 84, 86, 293, - /* 1790 */ 46, 285, 85, 85, 298, 84, 300, 84, 46, 293, - /* 1800 */ 22, 95, 194, 84, 298, 85, 300, 35, 35, 84, - /* 1810 */ 35, 85, 84, 22, 85, 35, 35, 35, 108, 257, - /* 1820 */ 84, 325, 108, 85, 84, 329, 330, 331, 332, 333, - /* 1830 */ 334, 325, 336, 85, 84, 329, 330, 331, 332, 333, - /* 1840 */ 334, 96, 336, 84, 84, 35, 84, 285, 43, 108, - /* 1850 */ 148, 149, 22, 151, 108, 293, 61, 155, 60, 35, - /* 1860 */ 298, 257, 300, 67, 43, 82, 22, 35, 35, 35, - /* 1870 */ 35, 257, 35, 35, 35, 67, 174, 35, 35, 0, - /* 1880 */ 35, 35, 35, 257, 35, 35, 35, 325, 35, 285, - /* 1890 */ 0, 329, 330, 331, 332, 333, 334, 293, 336, 285, - /* 1900 */ 39, 47, 298, 35, 300, 47, 39, 293, 0, 35, - /* 1910 */ 47, 285, 298, 0, 300, 39, 35, 47, 0, 293, - /* 1920 */ 35, 39, 35, 0, 298, 257, 300, 22, 21, 325, - /* 1930 */ 377, 22, 22, 329, 330, 331, 332, 333, 334, 325, - /* 1940 */ 336, 21, 257, 329, 330, 331, 332, 333, 334, 20, - /* 1950 */ 336, 325, 377, 285, 377, 329, 330, 331, 332, 333, - /* 1960 */ 334, 293, 336, 377, 377, 377, 298, 377, 300, 377, - /* 1970 */ 285, 377, 377, 377, 377, 377, 377, 377, 293, 377, - /* 1980 */ 377, 377, 377, 298, 257, 300, 377, 377, 377, 377, - /* 1990 */ 377, 377, 377, 325, 257, 377, 377, 329, 330, 331, - /* 2000 */ 332, 333, 334, 377, 336, 377, 377, 377, 377, 377, - /* 2010 */ 325, 377, 285, 377, 329, 330, 331, 332, 333, 334, - /* 2020 */ 293, 336, 285, 377, 377, 298, 377, 300, 377, 377, - /* 2030 */ 293, 377, 377, 377, 377, 298, 257, 300, 377, 377, - /* 2040 */ 377, 377, 377, 377, 377, 377, 257, 377, 377, 377, - /* 2050 */ 377, 377, 325, 377, 377, 377, 329, 330, 331, 332, - /* 2060 */ 333, 334, 325, 336, 285, 377, 329, 330, 331, 332, - /* 2070 */ 333, 334, 293, 336, 285, 377, 377, 298, 377, 300, - /* 2080 */ 377, 377, 293, 377, 377, 377, 377, 298, 257, 300, - /* 2090 */ 377, 377, 377, 377, 377, 377, 377, 377, 257, 377, - /* 2100 */ 377, 377, 377, 377, 325, 377, 377, 377, 329, 330, - /* 2110 */ 331, 332, 333, 334, 325, 336, 285, 377, 329, 330, - /* 2120 */ 331, 332, 333, 334, 293, 336, 285, 377, 377, 298, - /* 2130 */ 377, 300, 377, 377, 293, 377, 377, 377, 377, 298, - /* 2140 */ 377, 300, 377, 377, 377, 377, 377, 377, 377, 377, - /* 2150 */ 257, 377, 377, 377, 377, 377, 325, 377, 377, 377, - /* 2160 */ 329, 330, 331, 332, 333, 334, 325, 336, 377, 257, - /* 2170 */ 329, 330, 331, 332, 333, 334, 377, 336, 285, 377, - /* 2180 */ 377, 377, 377, 377, 377, 377, 293, 377, 377, 377, - /* 2190 */ 377, 298, 257, 300, 377, 377, 377, 285, 377, 377, - /* 2200 */ 377, 377, 377, 377, 377, 293, 377, 377, 377, 377, - /* 2210 */ 298, 257, 300, 377, 377, 377, 377, 377, 325, 377, - /* 2220 */ 285, 377, 329, 330, 331, 332, 333, 334, 293, 336, - /* 2230 */ 377, 377, 377, 298, 377, 300, 377, 325, 377, 285, - /* 2240 */ 377, 329, 330, 331, 332, 333, 334, 293, 336, 377, - /* 2250 */ 377, 377, 298, 377, 300, 377, 377, 377, 377, 377, - /* 2260 */ 325, 377, 377, 377, 329, 330, 331, 332, 333, 334, - /* 2270 */ 257, 336, 377, 377, 377, 377, 377, 377, 377, 325, - /* 2280 */ 257, 377, 377, 329, 330, 331, 332, 333, 334, 377, - /* 2290 */ 336, 377, 377, 377, 377, 377, 377, 377, 285, 377, - /* 2300 */ 377, 377, 377, 377, 377, 377, 293, 377, 285, 377, - /* 2310 */ 377, 298, 377, 300, 377, 377, 293, 377, 377, 377, - /* 2320 */ 377, 298, 377, 300, 377, 377, 377, 377, 377, 377, - /* 2330 */ 377, 377, 377, 377, 377, 377, 377, 377, 325, 377, - /* 2340 */ 377, 377, 329, 330, 331, 332, 333, 334, 325, 336, - /* 2350 */ 377, 377, 329, 330, 331, 332, 333, 334, 377, 336, + /* 210 */ 210, 211, 212, 326, 14, 15, 16, 330, 331, 332, + /* 220 */ 333, 334, 335, 266, 337, 225, 161, 340, 166, 20, + /* 230 */ 168, 344, 345, 346, 277, 79, 225, 315, 258, 8, + /* 240 */ 9, 284, 60, 12, 13, 14, 15, 16, 183, 184, + /* 250 */ 20, 294, 266, 366, 4, 193, 194, 225, 196, 197, + /* 260 */ 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, + /* 270 */ 208, 209, 210, 211, 212, 12, 13, 158, 356, 299, + /* 280 */ 294, 125, 126, 20, 116, 22, 12, 13, 14, 15, + /* 290 */ 16, 369, 61, 85, 85, 373, 33, 0, 35, 98, + /* 300 */ 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, + /* 310 */ 286, 110, 111, 112, 113, 114, 115, 86, 294, 56, + /* 320 */ 334, 258, 8, 9, 61, 94, 12, 13, 14, 15, + /* 330 */ 16, 68, 12, 13, 348, 349, 350, 351, 268, 353, + /* 340 */ 20, 266, 22, 288, 47, 286, 178, 179, 85, 286, + /* 350 */ 278, 281, 293, 33, 299, 35, 332, 294, 286, 289, + /* 360 */ 278, 302, 299, 266, 301, 14, 247, 295, 286, 294, + /* 370 */ 107, 20, 20, 165, 277, 167, 56, 295, 315, 148, + /* 380 */ 325, 326, 327, 0, 121, 122, 0, 263, 68, 326, + /* 390 */ 266, 294, 337, 330, 331, 332, 333, 334, 335, 258, + /* 400 */ 337, 263, 171, 340, 266, 85, 56, 344, 345, 334, + /* 410 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 356, + /* 420 */ 272, 273, 272, 273, 349, 350, 351, 107, 353, 166, + /* 430 */ 117, 168, 369, 225, 225, 85, 373, 87, 315, 258, + /* 440 */ 299, 121, 122, 60, 213, 214, 215, 216, 217, 218, + /* 450 */ 219, 220, 221, 222, 258, 37, 193, 194, 20, 196, + /* 460 */ 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, + /* 470 */ 207, 208, 209, 210, 211, 212, 226, 8, 9, 356, + /* 480 */ 299, 12, 13, 14, 15, 16, 166, 148, 168, 176, + /* 490 */ 177, 286, 369, 180, 151, 299, 373, 8, 9, 315, + /* 500 */ 20, 12, 13, 14, 15, 16, 88, 302, 90, 91, + /* 510 */ 171, 93, 60, 193, 194, 97, 196, 197, 198, 199, + /* 520 */ 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, + /* 530 */ 210, 211, 212, 12, 13, 14, 14, 119, 44, 45, + /* 540 */ 356, 20, 20, 22, 258, 225, 328, 258, 197, 20, + /* 550 */ 61, 22, 213, 369, 33, 86, 35, 373, 288, 8, + /* 560 */ 9, 116, 117, 12, 13, 14, 15, 16, 20, 299, + /* 570 */ 352, 266, 286, 230, 231, 225, 0, 56, 20, 50, + /* 580 */ 294, 266, 266, 94, 285, 299, 258, 301, 299, 68, + /* 590 */ 12, 13, 277, 277, 43, 325, 326, 298, 20, 294, + /* 600 */ 22, 0, 35, 1, 2, 286, 85, 337, 286, 294, + /* 610 */ 294, 33, 326, 35, 295, 293, 330, 331, 332, 333, + /* 620 */ 334, 335, 177, 337, 302, 180, 340, 299, 107, 266, + /* 630 */ 344, 345, 346, 153, 56, 68, 60, 148, 328, 334, + /* 640 */ 277, 259, 121, 122, 358, 14, 68, 311, 294, 313, + /* 650 */ 301, 20, 366, 68, 349, 350, 351, 294, 353, 305, + /* 660 */ 171, 312, 352, 85, 63, 64, 65, 66, 67, 43, + /* 670 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, + /* 680 */ 79, 80, 81, 82, 0, 107, 20, 166, 86, 168, + /* 690 */ 8, 9, 328, 258, 12, 13, 14, 15, 16, 121, + /* 700 */ 122, 153, 213, 214, 215, 216, 217, 218, 219, 220, + /* 710 */ 221, 222, 39, 258, 193, 194, 352, 196, 197, 198, + /* 720 */ 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, + /* 730 */ 209, 210, 211, 212, 299, 8, 9, 223, 224, 12, + /* 740 */ 13, 14, 15, 16, 166, 96, 168, 63, 64, 65, + /* 750 */ 42, 43, 22, 69, 299, 279, 72, 73, 282, 68, + /* 760 */ 76, 77, 78, 258, 287, 35, 193, 311, 86, 313, + /* 770 */ 296, 193, 194, 299, 196, 197, 198, 199, 200, 201, + /* 780 */ 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, + /* 790 */ 212, 12, 13, 18, 296, 20, 97, 299, 68, 20, + /* 800 */ 287, 22, 27, 258, 299, 30, 287, 234, 235, 236, + /* 810 */ 237, 238, 33, 86, 35, 116, 117, 118, 119, 120, + /* 820 */ 1, 2, 47, 0, 49, 287, 51, 3, 197, 266, + /* 830 */ 266, 286, 266, 258, 274, 56, 276, 107, 0, 294, + /* 840 */ 277, 277, 2, 277, 299, 319, 301, 68, 8, 9, + /* 850 */ 0, 0, 12, 13, 14, 15, 16, 294, 294, 84, + /* 860 */ 294, 8, 9, 197, 85, 12, 13, 14, 15, 16, + /* 870 */ 244, 326, 22, 22, 299, 330, 331, 332, 333, 334, + /* 880 */ 335, 2, 337, 287, 43, 340, 107, 8, 9, 344, + /* 890 */ 345, 12, 13, 14, 15, 16, 166, 224, 168, 124, + /* 900 */ 121, 122, 127, 128, 129, 130, 131, 132, 133, 134, + /* 910 */ 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, + /* 920 */ 97, 146, 147, 193, 194, 266, 258, 86, 89, 18, + /* 930 */ 275, 92, 43, 266, 23, 97, 277, 153, 154, 116, + /* 940 */ 117, 118, 119, 120, 277, 166, 376, 168, 37, 38, + /* 950 */ 43, 43, 41, 294, 116, 117, 118, 119, 120, 35, + /* 960 */ 288, 294, 315, 258, 258, 121, 122, 299, 57, 58, + /* 970 */ 59, 299, 193, 194, 258, 196, 197, 198, 199, 200, + /* 980 */ 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, + /* 990 */ 211, 212, 286, 86, 86, 367, 85, 325, 326, 266, + /* 1000 */ 294, 267, 266, 356, 299, 299, 153, 301, 258, 337, + /* 1010 */ 277, 35, 258, 277, 266, 299, 369, 46, 89, 258, + /* 1020 */ 373, 92, 258, 89, 258, 277, 92, 294, 61, 322, + /* 1030 */ 294, 286, 326, 363, 123, 43, 330, 331, 332, 333, + /* 1040 */ 334, 335, 294, 337, 266, 258, 340, 266, 266, 299, + /* 1050 */ 344, 345, 346, 299, 89, 277, 85, 92, 277, 277, + /* 1060 */ 299, 355, 266, 299, 35, 299, 242, 43, 0, 158, + /* 1070 */ 159, 160, 294, 286, 163, 294, 294, 267, 86, 85, + /* 1080 */ 169, 294, 43, 43, 12, 13, 299, 265, 301, 95, + /* 1090 */ 294, 43, 168, 182, 22, 298, 185, 68, 187, 188, + /* 1100 */ 189, 190, 191, 192, 347, 33, 329, 35, 370, 354, + /* 1110 */ 86, 315, 370, 326, 43, 357, 48, 330, 331, 332, + /* 1120 */ 333, 334, 335, 258, 337, 86, 86, 340, 56, 43, + /* 1130 */ 334, 344, 345, 346, 86, 246, 225, 43, 4, 370, + /* 1140 */ 68, 85, 355, 43, 168, 349, 350, 351, 290, 353, + /* 1150 */ 227, 286, 356, 19, 324, 20, 266, 86, 43, 294, + /* 1160 */ 193, 47, 164, 43, 299, 369, 301, 33, 323, 373, + /* 1170 */ 43, 43, 86, 35, 272, 266, 258, 317, 266, 107, + /* 1180 */ 86, 47, 42, 306, 148, 51, 86, 304, 304, 20, + /* 1190 */ 56, 326, 266, 266, 266, 330, 331, 332, 333, 334, + /* 1200 */ 335, 86, 337, 260, 286, 340, 86, 260, 20, 344, + /* 1210 */ 345, 346, 294, 86, 86, 321, 270, 299, 84, 301, + /* 1220 */ 355, 87, 301, 270, 20, 20, 316, 314, 258, 270, + /* 1230 */ 314, 270, 20, 315, 270, 266, 270, 307, 166, 260, + /* 1240 */ 168, 286, 270, 286, 326, 260, 286, 299, 330, 331, + /* 1250 */ 332, 333, 334, 335, 286, 337, 286, 266, 321, 286, + /* 1260 */ 286, 286, 174, 286, 294, 193, 286, 286, 286, 299, + /* 1270 */ 268, 301, 320, 268, 356, 266, 204, 205, 206, 207, + /* 1280 */ 208, 209, 210, 266, 301, 315, 268, 369, 299, 232, + /* 1290 */ 268, 373, 314, 258, 310, 299, 326, 310, 299, 299, + /* 1300 */ 330, 331, 332, 333, 334, 335, 299, 337, 150, 258, + /* 1310 */ 294, 308, 282, 307, 268, 294, 20, 329, 299, 299, + /* 1320 */ 233, 286, 310, 310, 362, 299, 356, 299, 239, 294, + /* 1330 */ 299, 157, 241, 240, 299, 228, 301, 286, 324, 369, + /* 1340 */ 224, 294, 20, 373, 245, 294, 243, 85, 362, 248, + /* 1350 */ 299, 328, 301, 343, 290, 365, 361, 364, 299, 362, + /* 1360 */ 359, 326, 266, 268, 258, 330, 331, 332, 333, 334, + /* 1370 */ 335, 360, 337, 276, 36, 340, 258, 326, 261, 344, + /* 1380 */ 345, 330, 331, 332, 333, 334, 335, 336, 337, 338, + /* 1390 */ 339, 260, 286, 318, 313, 269, 0, 372, 371, 280, + /* 1400 */ 294, 280, 280, 256, 286, 299, 372, 301, 371, 377, + /* 1410 */ 372, 176, 294, 371, 0, 0, 42, 299, 0, 301, + /* 1420 */ 76, 0, 35, 186, 35, 35, 35, 186, 0, 35, + /* 1430 */ 35, 186, 326, 0, 186, 0, 330, 331, 332, 333, + /* 1440 */ 334, 335, 35, 337, 326, 0, 22, 0, 330, 331, + /* 1450 */ 332, 333, 334, 335, 258, 337, 0, 35, 340, 171, + /* 1460 */ 85, 170, 168, 345, 166, 0, 0, 162, 258, 161, + /* 1470 */ 0, 0, 46, 0, 0, 0, 145, 0, 258, 0, + /* 1480 */ 374, 375, 286, 0, 0, 0, 140, 291, 35, 0, + /* 1490 */ 294, 140, 0, 0, 0, 299, 286, 301, 0, 0, + /* 1500 */ 0, 291, 0, 0, 294, 0, 286, 0, 0, 299, + /* 1510 */ 0, 301, 0, 0, 294, 0, 0, 0, 42, 299, + /* 1520 */ 0, 301, 326, 0, 0, 0, 330, 331, 332, 333, + /* 1530 */ 334, 335, 0, 337, 0, 258, 326, 0, 0, 0, + /* 1540 */ 330, 331, 332, 333, 334, 335, 326, 337, 0, 22, + /* 1550 */ 330, 331, 332, 333, 334, 335, 0, 337, 0, 258, + /* 1560 */ 56, 42, 56, 286, 43, 39, 14, 14, 46, 40, + /* 1570 */ 39, 294, 0, 0, 46, 0, 299, 157, 301, 39, + /* 1580 */ 0, 0, 0, 0, 0, 258, 35, 286, 368, 47, + /* 1590 */ 0, 0, 62, 39, 35, 294, 47, 35, 0, 39, + /* 1600 */ 299, 0, 301, 326, 47, 39, 35, 330, 331, 332, + /* 1610 */ 333, 334, 335, 286, 337, 47, 39, 0, 291, 0, + /* 1620 */ 0, 294, 35, 0, 22, 92, 299, 326, 301, 94, + /* 1630 */ 35, 330, 331, 332, 333, 334, 335, 43, 337, 258, + /* 1640 */ 339, 35, 35, 43, 35, 35, 35, 35, 35, 0, + /* 1650 */ 22, 0, 375, 326, 22, 19, 0, 330, 331, 332, + /* 1660 */ 333, 334, 335, 49, 337, 22, 35, 286, 0, 33, + /* 1670 */ 35, 0, 291, 35, 0, 294, 22, 20, 0, 35, + /* 1680 */ 299, 0, 301, 47, 22, 0, 172, 0, 52, 53, + /* 1690 */ 54, 55, 56, 0, 153, 150, 153, 0, 0, 153, + /* 1700 */ 85, 0, 155, 0, 86, 39, 85, 326, 43, 85, + /* 1710 */ 85, 330, 331, 332, 333, 334, 335, 33, 337, 46, + /* 1720 */ 84, 151, 258, 87, 95, 149, 229, 85, 46, 43, + /* 1730 */ 85, 47, 86, 86, 86, 85, 52, 53, 54, 55, + /* 1740 */ 56, 86, 181, 85, 85, 85, 258, 86, 43, 85, + /* 1750 */ 286, 2, 46, 43, 35, 86, 120, 46, 294, 223, + /* 1760 */ 43, 86, 46, 299, 46, 301, 86, 43, 84, 86, + /* 1770 */ 35, 87, 35, 35, 286, 35, 35, 22, 193, 229, + /* 1780 */ 85, 85, 294, 22, 229, 43, 86, 299, 152, 301, + /* 1790 */ 326, 46, 46, 86, 330, 331, 332, 333, 334, 335, + /* 1800 */ 85, 337, 258, 35, 22, 96, 86, 85, 85, 173, + /* 1810 */ 85, 175, 86, 35, 326, 85, 35, 195, 330, 331, + /* 1820 */ 332, 333, 334, 335, 85, 337, 35, 35, 35, 86, + /* 1830 */ 286, 97, 85, 149, 150, 85, 152, 86, 294, 86, + /* 1840 */ 156, 109, 86, 299, 258, 301, 35, 85, 85, 85, + /* 1850 */ 85, 43, 22, 109, 258, 35, 62, 109, 61, 175, + /* 1860 */ 83, 109, 43, 68, 35, 22, 258, 35, 35, 35, + /* 1870 */ 326, 35, 286, 35, 330, 331, 332, 333, 334, 335, + /* 1880 */ 294, 337, 286, 35, 68, 299, 35, 301, 35, 35, + /* 1890 */ 294, 35, 35, 35, 286, 299, 35, 301, 35, 0, + /* 1900 */ 35, 39, 294, 0, 35, 39, 47, 299, 0, 301, + /* 1910 */ 35, 47, 326, 39, 47, 0, 330, 331, 332, 333, + /* 1920 */ 334, 335, 326, 337, 35, 47, 330, 331, 332, 333, + /* 1930 */ 334, 335, 39, 337, 326, 35, 35, 0, 330, 331, + /* 1940 */ 332, 333, 334, 335, 0, 337, 22, 258, 21, 378, + /* 1950 */ 22, 22, 21, 20, 378, 378, 378, 378, 378, 378, + /* 1960 */ 378, 378, 378, 378, 378, 378, 258, 378, 378, 378, + /* 1970 */ 378, 378, 378, 378, 378, 286, 378, 378, 378, 378, + /* 1980 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, + /* 1990 */ 301, 378, 378, 378, 286, 378, 378, 378, 378, 378, + /* 2000 */ 378, 378, 294, 378, 378, 378, 378, 299, 378, 301, + /* 2010 */ 378, 378, 378, 378, 378, 326, 378, 378, 378, 330, + /* 2020 */ 331, 332, 333, 334, 335, 378, 337, 258, 378, 378, + /* 2030 */ 378, 378, 378, 378, 326, 378, 378, 378, 330, 331, + /* 2040 */ 332, 333, 334, 335, 378, 337, 258, 378, 378, 378, + /* 2050 */ 378, 378, 378, 378, 378, 286, 378, 378, 378, 378, + /* 2060 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, + /* 2070 */ 301, 378, 378, 378, 286, 378, 378, 378, 378, 378, + /* 2080 */ 378, 378, 294, 378, 378, 378, 378, 299, 378, 301, + /* 2090 */ 378, 378, 378, 378, 378, 326, 378, 378, 378, 330, + /* 2100 */ 331, 332, 333, 334, 335, 378, 337, 378, 378, 378, + /* 2110 */ 378, 378, 378, 258, 326, 378, 378, 378, 330, 331, + /* 2120 */ 332, 333, 334, 335, 378, 337, 378, 378, 378, 258, + /* 2130 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 258, + /* 2140 */ 378, 286, 378, 378, 378, 378, 378, 378, 378, 294, + /* 2150 */ 378, 378, 378, 378, 299, 378, 301, 286, 378, 378, + /* 2160 */ 378, 378, 378, 378, 378, 294, 378, 286, 378, 378, + /* 2170 */ 299, 378, 301, 378, 378, 294, 378, 378, 378, 378, + /* 2180 */ 299, 326, 301, 378, 378, 330, 331, 332, 333, 334, + /* 2190 */ 335, 378, 337, 258, 378, 378, 378, 326, 378, 378, + /* 2200 */ 378, 330, 331, 332, 333, 334, 335, 326, 337, 378, + /* 2210 */ 378, 330, 331, 332, 333, 334, 335, 378, 337, 378, + /* 2220 */ 378, 286, 378, 378, 378, 378, 378, 378, 378, 294, + /* 2230 */ 378, 378, 378, 378, 299, 378, 301, 378, 378, 378, + /* 2240 */ 378, 378, 378, 378, 378, 378, 378, 258, 378, 378, + /* 2250 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, + /* 2260 */ 378, 326, 378, 378, 378, 330, 331, 332, 333, 334, + /* 2270 */ 335, 378, 337, 378, 378, 286, 378, 378, 378, 378, + /* 2280 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, + /* 2290 */ 301, 378, 378, 378, 378, 378, 378, 258, 378, 378, + /* 2300 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, + /* 2310 */ 378, 378, 378, 378, 258, 326, 378, 378, 378, 330, + /* 2320 */ 331, 332, 333, 334, 335, 286, 337, 378, 378, 378, + /* 2330 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, + /* 2340 */ 301, 378, 286, 378, 378, 378, 378, 378, 378, 378, + /* 2350 */ 294, 378, 378, 378, 378, 299, 378, 301, 378, 378, + /* 2360 */ 378, 378, 378, 378, 378, 326, 378, 378, 378, 330, + /* 2370 */ 331, 332, 333, 334, 335, 378, 337, 258, 378, 378, + /* 2380 */ 378, 378, 326, 378, 378, 378, 330, 331, 332, 333, + /* 2390 */ 334, 335, 378, 337, 378, 378, 378, 378, 258, 378, + /* 2400 */ 378, 378, 378, 378, 378, 286, 378, 378, 378, 378, + /* 2410 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, + /* 2420 */ 301, 378, 378, 378, 378, 378, 286, 378, 378, 378, + /* 2430 */ 378, 378, 378, 378, 294, 378, 378, 378, 378, 299, + /* 2440 */ 258, 301, 378, 378, 378, 326, 378, 378, 378, 330, + /* 2450 */ 331, 332, 333, 334, 335, 378, 337, 378, 378, 378, + /* 2460 */ 378, 378, 378, 378, 378, 378, 326, 378, 286, 378, + /* 2470 */ 330, 331, 332, 333, 334, 335, 294, 337, 378, 378, + /* 2480 */ 378, 299, 378, 301, 378, 378, 378, 378, 378, 378, + /* 2490 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, + /* 2500 */ 378, 378, 378, 378, 378, 378, 378, 378, 326, 378, + /* 2510 */ 378, 378, 330, 331, 332, 333, 334, 335, 378, 337, }; -#define YY_SHIFT_COUNT (662) +#define YY_SHIFT_COUNT (665) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1929) +#define YY_SHIFT_MAX (1944) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 913, 0, 0, 68, 68, 268, 268, 268, 325, 325, - /* 10 */ 268, 268, 525, 582, 782, 582, 582, 582, 582, 582, - /* 20 */ 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, - /* 30 */ 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, - /* 40 */ 582, 582, 582, 208, 208, 97, 97, 97, 1073, 1073, - /* 50 */ 1073, 152, 426, 3, 3, 99, 99, 238, 238, 5, - /* 60 */ 202, 3, 3, 99, 99, 99, 99, 99, 99, 99, - /* 70 */ 99, 99, 89, 99, 99, 99, 148, 305, 99, 99, - /* 80 */ 305, 376, 99, 305, 305, 305, 99, 380, 778, 236, - /* 90 */ 493, 493, 281, 278, 575, 575, 575, 575, 575, 575, - /* 100 */ 575, 575, 575, 575, 575, 575, 575, 575, 575, 575, - /* 110 */ 575, 575, 575, 197, 202, 355, 355, 400, 576, 656, - /* 120 */ 438, 438, 438, 576, 528, 148, 11, 11, 305, 305, - /* 130 */ 541, 541, 261, 805, 466, 466, 466, 466, 466, 466, - /* 140 */ 466, 1592, 23, 107, 428, 21, 41, 375, 65, 366, - /* 150 */ 816, 365, 649, 495, 475, 539, 660, 539, 558, 497, - /* 160 */ 497, 497, 808, 194, 1076, 936, 1145, 1120, 1136, 1009, - /* 170 */ 1145, 1145, 1140, 1040, 1040, 1145, 1145, 1173, 1173, 1175, - /* 180 */ 89, 148, 89, 1176, 1191, 89, 1176, 89, 1197, 89, - /* 190 */ 89, 1145, 89, 1173, 305, 305, 305, 305, 305, 305, - /* 200 */ 305, 305, 305, 305, 305, 1145, 1173, 541, 1175, 380, - /* 210 */ 1080, 148, 380, 1145, 1145, 1176, 380, 1026, 541, 541, - /* 220 */ 541, 541, 1026, 541, 1114, 528, 1197, 380, 261, 380, - /* 230 */ 528, 1238, 541, 1068, 1026, 541, 541, 1068, 1026, 541, - /* 240 */ 541, 305, 1063, 1151, 1068, 1070, 1077, 1086, 936, 1089, - /* 250 */ 528, 1316, 1093, 1097, 1094, 1093, 1097, 1093, 1097, 1260, - /* 260 */ 1076, 541, 805, 1145, 380, 1317, 1173, 2360, 2360, 2360, - /* 270 */ 2360, 2360, 2360, 2360, 348, 1702, 132, 579, 472, 16, - /* 280 */ 663, 639, 743, 389, 757, 704, 839, 839, 839, 839, - /* 290 */ 839, 839, 839, 839, 843, 568, 25, 25, 61, 212, - /* 300 */ 433, 481, 603, 378, 297, 150, 483, 483, 483, 483, - /* 310 */ 45, 887, 774, 806, 910, 917, 811, 1046, 1069, 720, - /* 320 */ 707, 930, 973, 1041, 1045, 1047, 1050, 728, 829, 1053, - /* 330 */ 951, 847, 625, 391, 1074, 838, 1079, 1036, 1085, 1088, - /* 340 */ 1096, 1098, 1099, 1100, 1052, 1054, 896, 1358, 1189, 1377, - /* 350 */ 1382, 1345, 1389, 1315, 1391, 1357, 1211, 1362, 1363, 1364, - /* 360 */ 1215, 1401, 1368, 1369, 1220, 1406, 1223, 1410, 1378, 1411, - /* 370 */ 1390, 1414, 1380, 1416, 1333, 1248, 1252, 1255, 1258, 1435, - /* 380 */ 1436, 1283, 1286, 1448, 1449, 1404, 1451, 1452, 1453, 1310, - /* 390 */ 1456, 1457, 1458, 1459, 1461, 1324, 1429, 1466, 1328, 1468, - /* 400 */ 1469, 1471, 1472, 1474, 1475, 1476, 1477, 1479, 1481, 1484, - /* 410 */ 1485, 1486, 1488, 1455, 1490, 1499, 1500, 1502, 1503, 1504, - /* 420 */ 1493, 1507, 1508, 1518, 1519, 1520, 1465, 1523, 1524, 1487, - /* 430 */ 1489, 1483, 1513, 1491, 1521, 1492, 1533, 1494, 1497, 1539, - /* 440 */ 1540, 1542, 1505, 1387, 1545, 1546, 1547, 1495, 1548, 1549, - /* 450 */ 1515, 1511, 1512, 1552, 1525, 1526, 1514, 1554, 1535, 1528, - /* 460 */ 1516, 1571, 1541, 1531, 1544, 1579, 1580, 1581, 1585, 1501, - /* 470 */ 1498, 1551, 1565, 1588, 1555, 1557, 1558, 1560, 1553, 1559, - /* 480 */ 1563, 1566, 1577, 1586, 1597, 1578, 1622, 1601, 1582, 1628, - /* 490 */ 1607, 1591, 1630, 1600, 1636, 1602, 1638, 1618, 1623, 1642, - /* 500 */ 1510, 1615, 1649, 1482, 1632, 1529, 1522, 1652, 1655, 1530, - /* 510 */ 1532, 1656, 1657, 1660, 1589, 1587, 1509, 1677, 1596, 1538, - /* 520 */ 1599, 1690, 1646, 1543, 1609, 1603, 1650, 1659, 1467, 1616, - /* 530 */ 1613, 1620, 1631, 1633, 1629, 1693, 1674, 1635, 1637, 1645, - /* 540 */ 1648, 1653, 1679, 1687, 1688, 1658, 1694, 1517, 1662, 1663, - /* 550 */ 1695, 1537, 1697, 1704, 1705, 1667, 1717, 1534, 1676, 1664, - /* 560 */ 1730, 1732, 1733, 1734, 1735, 1676, 1770, 1594, 1731, 1689, - /* 570 */ 1698, 1700, 1707, 1703, 1708, 1744, 1711, 1713, 1752, 1778, - /* 580 */ 1608, 1719, 1706, 1720, 1772, 1773, 1725, 1726, 1775, 1728, - /* 590 */ 1729, 1780, 1736, 1738, 1781, 1740, 1748, 1782, 1750, 1710, - /* 600 */ 1714, 1741, 1746, 1791, 1745, 1759, 1760, 1810, 1762, 1805, - /* 610 */ 1805, 1830, 1795, 1798, 1824, 1796, 1783, 1821, 1832, 1833, - /* 620 */ 1834, 1835, 1837, 1844, 1838, 1839, 1808, 1553, 1842, 1559, - /* 630 */ 1843, 1845, 1846, 1847, 1849, 1850, 1851, 1879, 1853, 1854, - /* 640 */ 1861, 1890, 1868, 1858, 1867, 1908, 1874, 1863, 1876, 1913, - /* 650 */ 1881, 1870, 1882, 1918, 1885, 1887, 1923, 1905, 1907, 1909, - /* 660 */ 1910, 1920, 1929, + /* 0 */ 911, 0, 0, 62, 62, 263, 263, 263, 320, 320, + /* 10 */ 263, 263, 521, 578, 779, 578, 578, 578, 578, 578, + /* 20 */ 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, + /* 30 */ 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, + /* 40 */ 578, 578, 209, 209, 35, 35, 35, 1072, 1072, 1072, + /* 50 */ 1072, 208, 350, 32, 32, 167, 167, 19, 19, 11, + /* 60 */ 38, 32, 32, 167, 167, 167, 167, 167, 167, 167, + /* 70 */ 167, 167, 182, 167, 167, 167, 230, 352, 167, 167, + /* 80 */ 352, 438, 167, 352, 352, 352, 167, 452, 775, 231, + /* 90 */ 489, 489, 13, 98, 730, 730, 730, 730, 730, 730, + /* 100 */ 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, + /* 110 */ 730, 730, 730, 418, 38, 522, 522, 383, 567, 576, + /* 120 */ 480, 480, 480, 567, 558, 230, 1, 1, 352, 352, + /* 130 */ 585, 585, 649, 691, 201, 201, 201, 201, 201, 201, + /* 140 */ 201, 1636, 125, 684, 119, 573, 69, 313, 343, 351, + /* 150 */ 631, 529, 494, 39, 548, 514, 673, 514, 708, 824, + /* 160 */ 824, 824, 250, 666, 1056, 923, 1135, 1114, 1138, 998, + /* 170 */ 1135, 1135, 1140, 1036, 1036, 1135, 1135, 1135, 1169, 1169, + /* 180 */ 1188, 182, 230, 182, 1204, 1205, 182, 1204, 182, 1212, + /* 190 */ 182, 182, 1135, 182, 1169, 352, 352, 352, 352, 352, + /* 200 */ 352, 352, 352, 352, 352, 352, 1135, 1169, 585, 1188, + /* 210 */ 452, 1088, 230, 452, 1135, 1135, 1204, 452, 1057, 585, + /* 220 */ 585, 585, 585, 1057, 585, 1158, 558, 1212, 452, 649, + /* 230 */ 452, 558, 1296, 585, 1087, 1057, 585, 585, 1087, 1057, + /* 240 */ 585, 585, 352, 1089, 1174, 1087, 1091, 1093, 1107, 923, + /* 250 */ 1116, 558, 1322, 1099, 1103, 1101, 1099, 1103, 1099, 1103, + /* 260 */ 1262, 1056, 585, 691, 1135, 452, 1338, 1169, 2520, 2520, + /* 270 */ 2520, 2520, 2520, 2520, 2520, 601, 1684, 386, 1134, 469, + /* 280 */ 551, 682, 840, 879, 853, 727, 823, 314, 314, 314, + /* 290 */ 314, 314, 314, 314, 314, 838, 699, 274, 274, 445, + /* 300 */ 65, 108, 156, 44, 168, 602, 339, 200, 200, 200, + /* 310 */ 200, 297, 841, 839, 929, 934, 965, 57, 850, 851, + /* 320 */ 92, 784, 907, 908, 992, 1024, 1039, 1040, 1048, 819, + /* 330 */ 844, 626, 889, 1071, 924, 976, 967, 1086, 971, 1094, + /* 340 */ 1100, 1115, 1120, 1127, 1128, 994, 1029, 1068, 1396, 1235, + /* 350 */ 1414, 1415, 1374, 1418, 1344, 1421, 1387, 1237, 1389, 1390, + /* 360 */ 1391, 1241, 1428, 1394, 1395, 1245, 1433, 1248, 1435, 1407, + /* 370 */ 1445, 1424, 1447, 1422, 1456, 1375, 1288, 1291, 1294, 1298, + /* 380 */ 1465, 1466, 1305, 1308, 1470, 1471, 1426, 1473, 1474, 1475, + /* 390 */ 1331, 1477, 1479, 1483, 1484, 1485, 1346, 1453, 1489, 1351, + /* 400 */ 1492, 1493, 1494, 1498, 1499, 1500, 1502, 1503, 1505, 1507, + /* 410 */ 1508, 1510, 1512, 1513, 1476, 1515, 1516, 1517, 1520, 1523, + /* 420 */ 1524, 1527, 1525, 1532, 1534, 1537, 1538, 1504, 1539, 1506, + /* 430 */ 1548, 1556, 1519, 1526, 1521, 1552, 1522, 1553, 1528, 1558, + /* 440 */ 1529, 1531, 1572, 1573, 1575, 1540, 1420, 1580, 1581, 1582, + /* 450 */ 1530, 1583, 1584, 1551, 1542, 1554, 1590, 1559, 1549, 1560, + /* 460 */ 1591, 1562, 1557, 1566, 1598, 1571, 1568, 1577, 1601, 1617, + /* 470 */ 1619, 1620, 1535, 1533, 1587, 1602, 1623, 1595, 1606, 1607, + /* 480 */ 1609, 1594, 1600, 1610, 1611, 1612, 1613, 1649, 1628, 1651, + /* 490 */ 1632, 1614, 1656, 1643, 1631, 1668, 1635, 1671, 1638, 1674, + /* 500 */ 1654, 1657, 1678, 1541, 1644, 1681, 1514, 1662, 1543, 1545, + /* 510 */ 1685, 1687, 1546, 1547, 1693, 1697, 1698, 1615, 1618, 1561, + /* 520 */ 1701, 1621, 1570, 1624, 1703, 1666, 1576, 1625, 1629, 1673, + /* 530 */ 1665, 1497, 1642, 1646, 1645, 1647, 1648, 1650, 1686, 1655, + /* 540 */ 1658, 1659, 1660, 1661, 1705, 1682, 1706, 1664, 1710, 1550, + /* 550 */ 1669, 1675, 1711, 1536, 1717, 1716, 1718, 1680, 1724, 1555, + /* 560 */ 1683, 1719, 1735, 1737, 1738, 1740, 1741, 1683, 1749, 1755, + /* 570 */ 1585, 1742, 1695, 1700, 1696, 1707, 1715, 1720, 1745, 1722, + /* 580 */ 1723, 1746, 1761, 1622, 1725, 1709, 1726, 1768, 1778, 1730, + /* 590 */ 1743, 1781, 1739, 1751, 1791, 1747, 1753, 1792, 1750, 1756, + /* 600 */ 1793, 1762, 1732, 1744, 1748, 1752, 1782, 1734, 1763, 1764, + /* 610 */ 1811, 1765, 1808, 1808, 1830, 1794, 1797, 1820, 1795, 1777, + /* 620 */ 1819, 1829, 1832, 1833, 1834, 1836, 1843, 1838, 1848, 1816, + /* 630 */ 1594, 1851, 1600, 1853, 1854, 1856, 1857, 1858, 1861, 1863, + /* 640 */ 1899, 1865, 1859, 1862, 1903, 1869, 1864, 1866, 1908, 1875, + /* 650 */ 1867, 1874, 1915, 1889, 1878, 1893, 1944, 1900, 1901, 1937, + /* 660 */ 1924, 1927, 1928, 1929, 1931, 1933, }; -#define YY_REDUCE_COUNT (273) -#define YY_REDUCE_MIN (-354) -#define YY_REDUCE_MAX (2023) +#define YY_REDUCE_COUNT (274) +#define YY_REDUCE_MIN (-312) +#define YY_REDUCE_MAX (2182) static const short yy_reduce_ofst[] = { - /* 0 */ -29, -221, 289, 34, 709, -113, 546, 780, 876, 937, - /* 10 */ 990, 1042, 1095, 1109, 1162, 1180, 1232, 1274, 1284, 1334, - /* 20 */ 1376, 1394, 1446, 1496, 1506, 1562, 1604, 1614, 1626, 1668, - /* 30 */ 1685, 1727, 1737, 1779, 1789, 1831, 1841, 1893, 1912, 1935, - /* 40 */ 1954, 2013, 2023, -219, 711, -250, -207, 593, 731, 726, - /* 50 */ 820, -218, 382, 446, 502, -208, 580, -261, -257, -354, - /* 60 */ -234, -182, -11, -138, 218, 323, 404, 548, 662, 664, - /* 70 */ 670, 672, 102, 730, 734, 735, -292, 153, 738, 756, - /* 80 */ -275, -215, 771, 219, -39, 267, 822, -246, 49, -201, - /* 90 */ -201, -201, -187, -31, -152, -132, 2, 205, 286, 336, - /* 100 */ 372, 402, 403, 441, 542, 552, 569, 571, 624, 627, - /* 110 */ 630, 635, 636, 20, 31, -71, 71, -264, 136, -194, - /* 120 */ 331, 340, 368, 243, 303, 453, 230, 431, -47, 388, - /* 130 */ 512, 537, 556, 471, 430, 511, 613, 646, 678, 683, - /* 140 */ 733, 638, 759, 746, 647, 710, 760, 826, 715, 807, - /* 150 */ 807, 861, 884, 852, 823, 797, 797, 797, 809, 783, - /* 160 */ 784, 785, 801, 807, 869, 840, 901, 846, 904, 862, - /* 170 */ 912, 915, 881, 885, 886, 926, 927, 938, 939, 879, - /* 180 */ 931, 902, 934, 891, 898, 945, 903, 946, 914, 949, - /* 190 */ 950, 956, 954, 965, 940, 941, 942, 943, 944, 947, - /* 200 */ 948, 957, 958, 960, 961, 969, 977, 952, 919, 974, - /* 210 */ 933, 955, 982, 989, 991, 959, 992, 975, 962, 963, - /* 220 */ 966, 976, 978, 987, 979, 996, 985, 1027, 1012, 1028, - /* 230 */ 1003, 970, 999, 953, 993, 1005, 1006, 964, 997, 1010, - /* 240 */ 1013, 807, 967, 980, 971, 968, 986, 972, 994, 797, - /* 250 */ 1025, 1011, 983, 981, 984, 988, 995, 998, 1000, 1004, - /* 260 */ 1058, 1051, 1075, 1083, 1090, 1101, 1103, 1038, 1044, 1084, - /* 270 */ 1104, 1105, 1111, 1113, + /* 0 */ -78, -232, 63, 286, -113, 706, 787, 865, 918, 970, + /* 10 */ 545, 1035, 1051, 1106, 1118, 1196, 1210, 1220, 1277, 1301, + /* 20 */ 1327, 1381, 1464, 1488, 1544, 1586, 1596, 1608, 1689, 1708, + /* 30 */ 1769, 1788, 1855, 1871, 1881, 1935, 1989, 2039, 2056, 2119, + /* 40 */ 2140, 2182, -263, 796, -14, 75, 305, -278, 55, 270, + /* 50 */ 672, -296, 123, 184, 647, -266, -43, -260, -256, -303, + /* 60 */ -186, -230, -191, -185, 97, 315, 316, 363, 563, 564, + /* 70 */ 566, 659, -154, 667, 733, 736, -285, -106, 748, 778, + /* 80 */ 59, 24, 781, 72, 322, 82, 782, 70, -252, -312, + /* 90 */ -312, -312, -117, -239, -114, -20, 141, 181, 196, 289, + /* 100 */ 328, 435, 455, 505, 575, 668, 705, 716, 750, 754, + /* 110 */ 761, 764, 766, 299, -110, 124, 138, -220, 148, -243, + /* 120 */ 218, 310, 364, 150, 354, 349, 336, 456, 319, 205, + /* 130 */ 474, 498, 476, 560, -280, -270, 477, 513, 519, 538, + /* 140 */ 596, 526, 382, 655, 570, 628, 734, 707, 670, 745, + /* 150 */ 745, 810, 822, 797, 777, 755, 755, 755, 757, 738, + /* 160 */ 742, 769, 758, 745, 858, 830, 890, 845, 902, 860, + /* 170 */ 909, 912, 877, 883, 884, 926, 927, 928, 943, 947, + /* 180 */ 894, 946, 921, 953, 913, 910, 959, 916, 961, 930, + /* 190 */ 964, 966, 969, 972, 979, 955, 957, 960, 968, 973, + /* 200 */ 974, 975, 977, 980, 981, 982, 991, 985, 948, 937, + /* 210 */ 1002, 952, 983, 1005, 1009, 1017, 978, 1018, 984, 989, + /* 220 */ 996, 999, 1000, 987, 1007, 1003, 1016, 1006, 1022, 1030, + /* 230 */ 1046, 1021, 988, 1019, 962, 1012, 1020, 1026, 986, 1013, + /* 240 */ 1028, 1031, 745, 990, 993, 997, 995, 1011, 1001, 1014, + /* 250 */ 755, 1047, 1023, 1025, 1027, 1032, 1034, 1037, 1038, 1042, + /* 260 */ 1010, 1064, 1059, 1097, 1096, 1095, 1117, 1131, 1075, 1081, + /* 270 */ 1119, 1121, 1122, 1126, 1147, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 10 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 20 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 30 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 40 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 50 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 60 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 70 */ 1453, 1453, 1526, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 80 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1524, 1679, 1453, - /* 90 */ 1856, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 100 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 110 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1526, 1453, 1524, - /* 120 */ 1868, 1868, 1868, 1453, 1453, 1453, 1723, 1723, 1453, 1453, - /* 130 */ 1453, 1453, 1622, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 140 */ 1453, 1715, 1453, 1453, 1937, 1453, 1453, 1721, 1891, 1453, - /* 150 */ 1453, 1453, 1453, 1575, 1883, 1860, 1874, 1861, 1858, 1922, - /* 160 */ 1922, 1922, 1877, 1453, 1591, 1887, 1453, 1453, 1453, 1707, - /* 170 */ 1453, 1453, 1684, 1681, 1681, 1453, 1453, 1453, 1453, 1453, - /* 180 */ 1526, 1453, 1526, 1453, 1453, 1526, 1453, 1526, 1453, 1526, - /* 190 */ 1526, 1453, 1526, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 200 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1524, - /* 210 */ 1717, 1453, 1524, 1453, 1453, 1453, 1524, 1896, 1453, 1453, - /* 220 */ 1453, 1453, 1896, 1453, 1453, 1453, 1453, 1524, 1453, 1524, - /* 230 */ 1453, 1453, 1453, 1898, 1896, 1453, 1453, 1898, 1896, 1453, - /* 240 */ 1453, 1453, 1910, 1906, 1898, 1914, 1912, 1889, 1887, 1874, - /* 250 */ 1453, 1453, 1928, 1924, 1940, 1928, 1924, 1928, 1924, 1453, - /* 260 */ 1591, 1453, 1453, 1453, 1524, 1485, 1453, 1709, 1723, 1625, - /* 270 */ 1625, 1625, 1527, 1458, 1453, 1453, 1453, 1453, 1453, 1453, - /* 280 */ 1453, 1453, 1453, 1453, 1453, 1453, 1794, 1909, 1908, 1832, - /* 290 */ 1831, 1830, 1828, 1793, 1453, 1587, 1792, 1791, 1453, 1453, - /* 300 */ 1453, 1453, 1453, 1453, 1453, 1453, 1785, 1786, 1784, 1783, - /* 310 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 320 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 330 */ 1857, 1453, 1925, 1929, 1453, 1453, 1453, 1768, 1453, 1453, - /* 340 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 350 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 360 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 370 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 380 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 390 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 400 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 410 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 420 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 430 */ 1453, 1490, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 440 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 450 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 460 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 470 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1556, 1555, - /* 480 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 490 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 500 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 510 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1727, 1453, 1453, - /* 520 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1890, 1453, 1453, - /* 530 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 540 */ 1453, 1453, 1453, 1453, 1768, 1453, 1907, 1453, 1867, 1863, - /* 550 */ 1453, 1453, 1859, 1767, 1453, 1453, 1923, 1453, 1453, 1453, - /* 560 */ 1453, 1453, 1453, 1453, 1453, 1453, 1852, 1453, 1825, 1810, - /* 570 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 580 */ 1779, 1453, 1453, 1453, 1453, 1453, 1619, 1453, 1453, 1453, - /* 590 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1604, - /* 600 */ 1602, 1601, 1600, 1453, 1597, 1453, 1453, 1453, 1453, 1628, - /* 610 */ 1627, 1453, 1453, 1453, 1453, 1453, 1453, 1547, 1453, 1453, - /* 620 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1538, 1453, 1537, - /* 630 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 640 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 650 */ 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, 1453, - /* 660 */ 1453, 1453, 1453, + /* 0 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 10 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 20 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 30 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 40 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 50 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 60 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 70 */ 1457, 1457, 1531, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 80 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1529, 1684, 1457, + /* 90 */ 1861, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 100 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 110 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1531, 1457, 1529, + /* 120 */ 1873, 1873, 1873, 1457, 1457, 1457, 1728, 1728, 1457, 1457, + /* 130 */ 1457, 1457, 1627, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 140 */ 1457, 1720, 1457, 1457, 1942, 1457, 1457, 1726, 1896, 1457, + /* 150 */ 1457, 1457, 1457, 1580, 1888, 1865, 1879, 1866, 1863, 1927, + /* 160 */ 1927, 1927, 1882, 1457, 1596, 1892, 1457, 1457, 1457, 1712, + /* 170 */ 1457, 1457, 1689, 1686, 1686, 1457, 1457, 1457, 1457, 1457, + /* 180 */ 1457, 1531, 1457, 1531, 1457, 1457, 1531, 1457, 1531, 1457, + /* 190 */ 1531, 1531, 1457, 1531, 1457, 1457, 1457, 1457, 1457, 1457, + /* 200 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 210 */ 1529, 1722, 1457, 1529, 1457, 1457, 1457, 1529, 1901, 1457, + /* 220 */ 1457, 1457, 1457, 1901, 1457, 1457, 1457, 1457, 1529, 1457, + /* 230 */ 1529, 1457, 1457, 1457, 1903, 1901, 1457, 1457, 1903, 1901, + /* 240 */ 1457, 1457, 1457, 1915, 1911, 1903, 1919, 1917, 1894, 1892, + /* 250 */ 1879, 1457, 1457, 1933, 1929, 1945, 1933, 1929, 1933, 1929, + /* 260 */ 1457, 1596, 1457, 1457, 1457, 1529, 1489, 1457, 1714, 1728, + /* 270 */ 1630, 1630, 1630, 1532, 1462, 1457, 1457, 1457, 1457, 1457, + /* 280 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1799, 1914, 1913, + /* 290 */ 1837, 1836, 1835, 1833, 1798, 1457, 1592, 1797, 1796, 1457, + /* 300 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1790, 1791, 1789, + /* 310 */ 1788, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 320 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1862, + /* 330 */ 1457, 1930, 1934, 1457, 1457, 1457, 1457, 1457, 1773, 1457, + /* 340 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 350 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 360 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 370 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 380 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 390 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 400 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 410 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 420 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 430 */ 1457, 1457, 1457, 1457, 1494, 1457, 1457, 1457, 1457, 1457, + /* 440 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 450 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 460 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 470 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 480 */ 1457, 1561, 1560, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 490 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 500 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 510 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 520 */ 1732, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 530 */ 1895, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 540 */ 1457, 1457, 1457, 1457, 1457, 1457, 1773, 1457, 1912, 1457, + /* 550 */ 1872, 1868, 1457, 1457, 1864, 1772, 1457, 1457, 1928, 1457, + /* 560 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1857, 1457, + /* 570 */ 1457, 1830, 1815, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 580 */ 1457, 1457, 1457, 1784, 1457, 1457, 1457, 1457, 1457, 1624, + /* 590 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 600 */ 1457, 1457, 1609, 1607, 1606, 1605, 1457, 1602, 1457, 1457, + /* 610 */ 1457, 1457, 1633, 1632, 1457, 1457, 1457, 1457, 1457, 1457, + /* 620 */ 1552, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 630 */ 1543, 1457, 1542, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 640 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 650 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, + /* 660 */ 1457, 1457, 1457, 1457, 1457, 1457, }; /********** End of lemon-generated parsing tables *****************************/ @@ -944,6 +976,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* DATABASE => nothing */ 0, /* USE => nothing */ 0, /* FLUSH => nothing */ + 0, /* TRIM => nothing */ 0, /* IF => nothing */ 0, /* NOT => nothing */ 0, /* EXISTS => nothing */ @@ -1134,11 +1167,11 @@ static const YYCODETYPE yyFallback[] = { 0, /* ASC => nothing */ 0, /* NULLS => nothing */ 0, /* ID => nothing */ - 248, /* NK_BITNOT => ID */ - 248, /* VALUES => ID */ - 248, /* IMPORT => ID */ - 248, /* NK_SEMI => ID */ - 248, /* FILE => ID */ + 249, /* NK_BITNOT => ID */ + 249, /* VALUES => ID */ + 249, /* IMPORT => ID */ + 249, /* NK_SEMI => ID */ + 249, /* FILE => ID */ }; #endif /* YYFALLBACK */ @@ -1285,324 +1318,325 @@ static const char *const yyTokenName[] = { /* 56 */ "DATABASE", /* 57 */ "USE", /* 58 */ "FLUSH", - /* 59 */ "IF", - /* 60 */ "NOT", - /* 61 */ "EXISTS", - /* 62 */ "BUFFER", - /* 63 */ "CACHELAST", - /* 64 */ "CACHELASTSIZE", - /* 65 */ "COMP", - /* 66 */ "DURATION", - /* 67 */ "NK_VARIABLE", - /* 68 */ "FSYNC", - /* 69 */ "MAXROWS", - /* 70 */ "MINROWS", - /* 71 */ "KEEP", - /* 72 */ "PAGES", - /* 73 */ "PAGESIZE", - /* 74 */ "PRECISION", - /* 75 */ "REPLICA", - /* 76 */ "STRICT", - /* 77 */ "WAL", - /* 78 */ "VGROUPS", - /* 79 */ "SINGLE_STABLE", - /* 80 */ "RETENTIONS", - /* 81 */ "SCHEMALESS", - /* 82 */ "NK_COLON", - /* 83 */ "TABLE", - /* 84 */ "NK_LP", - /* 85 */ "NK_RP", - /* 86 */ "STABLE", - /* 87 */ "ADD", - /* 88 */ "COLUMN", - /* 89 */ "MODIFY", - /* 90 */ "RENAME", - /* 91 */ "TAG", - /* 92 */ "SET", - /* 93 */ "NK_EQ", - /* 94 */ "USING", - /* 95 */ "TAGS", - /* 96 */ "COMMENT", - /* 97 */ "BOOL", - /* 98 */ "TINYINT", - /* 99 */ "SMALLINT", - /* 100 */ "INT", - /* 101 */ "INTEGER", - /* 102 */ "BIGINT", - /* 103 */ "FLOAT", - /* 104 */ "DOUBLE", - /* 105 */ "BINARY", - /* 106 */ "TIMESTAMP", - /* 107 */ "NCHAR", - /* 108 */ "UNSIGNED", - /* 109 */ "JSON", - /* 110 */ "VARCHAR", - /* 111 */ "MEDIUMBLOB", - /* 112 */ "BLOB", - /* 113 */ "VARBINARY", - /* 114 */ "DECIMAL", - /* 115 */ "MAX_DELAY", - /* 116 */ "WATERMARK", - /* 117 */ "ROLLUP", - /* 118 */ "TTL", - /* 119 */ "SMA", - /* 120 */ "FIRST", - /* 121 */ "LAST", - /* 122 */ "SHOW", - /* 123 */ "DATABASES", - /* 124 */ "TABLES", - /* 125 */ "STABLES", - /* 126 */ "MNODES", - /* 127 */ "MODULES", - /* 128 */ "QNODES", - /* 129 */ "FUNCTIONS", - /* 130 */ "INDEXES", - /* 131 */ "ACCOUNTS", - /* 132 */ "APPS", - /* 133 */ "CONNECTIONS", - /* 134 */ "LICENCE", - /* 135 */ "GRANTS", - /* 136 */ "QUERIES", - /* 137 */ "SCORES", - /* 138 */ "TOPICS", - /* 139 */ "VARIABLES", - /* 140 */ "BNODES", - /* 141 */ "SNODES", - /* 142 */ "CLUSTER", - /* 143 */ "TRANSACTIONS", - /* 144 */ "DISTRIBUTED", - /* 145 */ "CONSUMERS", - /* 146 */ "SUBSCRIPTIONS", - /* 147 */ "LIKE", - /* 148 */ "INDEX", - /* 149 */ "FUNCTION", - /* 150 */ "INTERVAL", - /* 151 */ "TOPIC", - /* 152 */ "AS", - /* 153 */ "WITH", - /* 154 */ "META", - /* 155 */ "CONSUMER", - /* 156 */ "GROUP", - /* 157 */ "DESC", - /* 158 */ "DESCRIBE", - /* 159 */ "RESET", - /* 160 */ "QUERY", - /* 161 */ "CACHE", - /* 162 */ "EXPLAIN", - /* 163 */ "ANALYZE", - /* 164 */ "VERBOSE", - /* 165 */ "NK_BOOL", - /* 166 */ "RATIO", - /* 167 */ "NK_FLOAT", - /* 168 */ "COMPACT", - /* 169 */ "VNODES", - /* 170 */ "IN", - /* 171 */ "OUTPUTTYPE", - /* 172 */ "AGGREGATE", - /* 173 */ "BUFSIZE", - /* 174 */ "STREAM", - /* 175 */ "INTO", - /* 176 */ "TRIGGER", - /* 177 */ "AT_ONCE", - /* 178 */ "WINDOW_CLOSE", - /* 179 */ "IGNORE", - /* 180 */ "EXPIRED", - /* 181 */ "KILL", - /* 182 */ "CONNECTION", - /* 183 */ "TRANSACTION", - /* 184 */ "BALANCE", - /* 185 */ "VGROUP", - /* 186 */ "MERGE", - /* 187 */ "REDISTRIBUTE", - /* 188 */ "SPLIT", - /* 189 */ "SYNCDB", - /* 190 */ "DELETE", - /* 191 */ "INSERT", - /* 192 */ "NULL", - /* 193 */ "NK_QUESTION", - /* 194 */ "NK_ARROW", - /* 195 */ "ROWTS", - /* 196 */ "TBNAME", - /* 197 */ "QSTARTTS", - /* 198 */ "QENDTS", - /* 199 */ "WSTARTTS", - /* 200 */ "WENDTS", - /* 201 */ "WDURATION", - /* 202 */ "CAST", - /* 203 */ "NOW", - /* 204 */ "TODAY", - /* 205 */ "TIMEZONE", - /* 206 */ "CLIENT_VERSION", - /* 207 */ "SERVER_VERSION", - /* 208 */ "SERVER_STATUS", - /* 209 */ "CURRENT_USER", - /* 210 */ "COUNT", - /* 211 */ "LAST_ROW", - /* 212 */ "BETWEEN", - /* 213 */ "IS", - /* 214 */ "NK_LT", - /* 215 */ "NK_GT", - /* 216 */ "NK_LE", - /* 217 */ "NK_GE", - /* 218 */ "NK_NE", - /* 219 */ "MATCH", - /* 220 */ "NMATCH", - /* 221 */ "CONTAINS", - /* 222 */ "JOIN", - /* 223 */ "INNER", - /* 224 */ "SELECT", - /* 225 */ "DISTINCT", - /* 226 */ "WHERE", - /* 227 */ "PARTITION", - /* 228 */ "BY", - /* 229 */ "SESSION", - /* 230 */ "STATE_WINDOW", - /* 231 */ "SLIDING", - /* 232 */ "FILL", - /* 233 */ "VALUE", - /* 234 */ "NONE", - /* 235 */ "PREV", - /* 236 */ "LINEAR", - /* 237 */ "NEXT", - /* 238 */ "HAVING", - /* 239 */ "RANGE", - /* 240 */ "EVERY", - /* 241 */ "ORDER", - /* 242 */ "SLIMIT", - /* 243 */ "SOFFSET", - /* 244 */ "LIMIT", - /* 245 */ "OFFSET", - /* 246 */ "ASC", - /* 247 */ "NULLS", - /* 248 */ "ID", - /* 249 */ "NK_BITNOT", - /* 250 */ "VALUES", - /* 251 */ "IMPORT", - /* 252 */ "NK_SEMI", - /* 253 */ "FILE", - /* 254 */ "cmd", - /* 255 */ "account_options", - /* 256 */ "alter_account_options", - /* 257 */ "literal", - /* 258 */ "alter_account_option", - /* 259 */ "user_name", - /* 260 */ "sysinfo_opt", - /* 261 */ "privileges", - /* 262 */ "priv_level", - /* 263 */ "priv_type_list", - /* 264 */ "priv_type", - /* 265 */ "db_name", - /* 266 */ "dnode_endpoint", - /* 267 */ "not_exists_opt", - /* 268 */ "db_options", - /* 269 */ "exists_opt", - /* 270 */ "alter_db_options", - /* 271 */ "integer_list", - /* 272 */ "variable_list", - /* 273 */ "retention_list", - /* 274 */ "alter_db_option", - /* 275 */ "retention", - /* 276 */ "full_table_name", - /* 277 */ "column_def_list", - /* 278 */ "tags_def_opt", - /* 279 */ "table_options", - /* 280 */ "multi_create_clause", - /* 281 */ "tags_def", - /* 282 */ "multi_drop_clause", - /* 283 */ "alter_table_clause", - /* 284 */ "alter_table_options", - /* 285 */ "column_name", - /* 286 */ "type_name", - /* 287 */ "signed_literal", - /* 288 */ "create_subtable_clause", - /* 289 */ "specific_cols_opt", - /* 290 */ "expression_list", - /* 291 */ "drop_table_clause", - /* 292 */ "col_name_list", - /* 293 */ "table_name", - /* 294 */ "column_def", - /* 295 */ "duration_list", - /* 296 */ "rollup_func_list", - /* 297 */ "alter_table_option", - /* 298 */ "duration_literal", - /* 299 */ "rollup_func_name", - /* 300 */ "function_name", - /* 301 */ "col_name", - /* 302 */ "db_name_cond_opt", - /* 303 */ "like_pattern_opt", - /* 304 */ "table_name_cond", - /* 305 */ "from_db_opt", - /* 306 */ "index_name", - /* 307 */ "index_options", - /* 308 */ "func_list", - /* 309 */ "sliding_opt", - /* 310 */ "sma_stream_opt", - /* 311 */ "func", - /* 312 */ "stream_options", - /* 313 */ "topic_name", - /* 314 */ "query_expression", - /* 315 */ "cgroup_name", - /* 316 */ "analyze_opt", - /* 317 */ "explain_options", - /* 318 */ "agg_func_opt", - /* 319 */ "bufsize_opt", - /* 320 */ "stream_name", - /* 321 */ "into_opt", - /* 322 */ "dnode_list", - /* 323 */ "where_clause_opt", - /* 324 */ "signed", - /* 325 */ "literal_func", - /* 326 */ "literal_list", - /* 327 */ "table_alias", - /* 328 */ "column_alias", - /* 329 */ "expression", - /* 330 */ "pseudo_column", - /* 331 */ "column_reference", - /* 332 */ "function_expression", - /* 333 */ "subquery", - /* 334 */ "star_func", - /* 335 */ "star_func_para_list", - /* 336 */ "noarg_func", - /* 337 */ "other_para_list", - /* 338 */ "star_func_para", - /* 339 */ "predicate", - /* 340 */ "compare_op", - /* 341 */ "in_op", - /* 342 */ "in_predicate_value", - /* 343 */ "boolean_value_expression", - /* 344 */ "boolean_primary", - /* 345 */ "common_expression", - /* 346 */ "from_clause_opt", - /* 347 */ "table_reference_list", - /* 348 */ "table_reference", - /* 349 */ "table_primary", - /* 350 */ "joined_table", - /* 351 */ "alias_opt", - /* 352 */ "parenthesized_joined_table", - /* 353 */ "join_type", - /* 354 */ "search_condition", - /* 355 */ "query_specification", - /* 356 */ "set_quantifier_opt", - /* 357 */ "select_list", - /* 358 */ "partition_by_clause_opt", - /* 359 */ "range_opt", - /* 360 */ "every_opt", - /* 361 */ "fill_opt", - /* 362 */ "twindow_clause_opt", - /* 363 */ "group_by_clause_opt", - /* 364 */ "having_clause_opt", - /* 365 */ "select_item", - /* 366 */ "fill_mode", - /* 367 */ "group_by_list", - /* 368 */ "query_expression_body", - /* 369 */ "order_by_clause_opt", - /* 370 */ "slimit_clause_opt", - /* 371 */ "limit_clause_opt", - /* 372 */ "query_primary", - /* 373 */ "sort_specification_list", - /* 374 */ "sort_specification", - /* 375 */ "ordering_specification_opt", - /* 376 */ "null_ordering_opt", + /* 59 */ "TRIM", + /* 60 */ "IF", + /* 61 */ "NOT", + /* 62 */ "EXISTS", + /* 63 */ "BUFFER", + /* 64 */ "CACHELAST", + /* 65 */ "CACHELASTSIZE", + /* 66 */ "COMP", + /* 67 */ "DURATION", + /* 68 */ "NK_VARIABLE", + /* 69 */ "FSYNC", + /* 70 */ "MAXROWS", + /* 71 */ "MINROWS", + /* 72 */ "KEEP", + /* 73 */ "PAGES", + /* 74 */ "PAGESIZE", + /* 75 */ "PRECISION", + /* 76 */ "REPLICA", + /* 77 */ "STRICT", + /* 78 */ "WAL", + /* 79 */ "VGROUPS", + /* 80 */ "SINGLE_STABLE", + /* 81 */ "RETENTIONS", + /* 82 */ "SCHEMALESS", + /* 83 */ "NK_COLON", + /* 84 */ "TABLE", + /* 85 */ "NK_LP", + /* 86 */ "NK_RP", + /* 87 */ "STABLE", + /* 88 */ "ADD", + /* 89 */ "COLUMN", + /* 90 */ "MODIFY", + /* 91 */ "RENAME", + /* 92 */ "TAG", + /* 93 */ "SET", + /* 94 */ "NK_EQ", + /* 95 */ "USING", + /* 96 */ "TAGS", + /* 97 */ "COMMENT", + /* 98 */ "BOOL", + /* 99 */ "TINYINT", + /* 100 */ "SMALLINT", + /* 101 */ "INT", + /* 102 */ "INTEGER", + /* 103 */ "BIGINT", + /* 104 */ "FLOAT", + /* 105 */ "DOUBLE", + /* 106 */ "BINARY", + /* 107 */ "TIMESTAMP", + /* 108 */ "NCHAR", + /* 109 */ "UNSIGNED", + /* 110 */ "JSON", + /* 111 */ "VARCHAR", + /* 112 */ "MEDIUMBLOB", + /* 113 */ "BLOB", + /* 114 */ "VARBINARY", + /* 115 */ "DECIMAL", + /* 116 */ "MAX_DELAY", + /* 117 */ "WATERMARK", + /* 118 */ "ROLLUP", + /* 119 */ "TTL", + /* 120 */ "SMA", + /* 121 */ "FIRST", + /* 122 */ "LAST", + /* 123 */ "SHOW", + /* 124 */ "DATABASES", + /* 125 */ "TABLES", + /* 126 */ "STABLES", + /* 127 */ "MNODES", + /* 128 */ "MODULES", + /* 129 */ "QNODES", + /* 130 */ "FUNCTIONS", + /* 131 */ "INDEXES", + /* 132 */ "ACCOUNTS", + /* 133 */ "APPS", + /* 134 */ "CONNECTIONS", + /* 135 */ "LICENCE", + /* 136 */ "GRANTS", + /* 137 */ "QUERIES", + /* 138 */ "SCORES", + /* 139 */ "TOPICS", + /* 140 */ "VARIABLES", + /* 141 */ "BNODES", + /* 142 */ "SNODES", + /* 143 */ "CLUSTER", + /* 144 */ "TRANSACTIONS", + /* 145 */ "DISTRIBUTED", + /* 146 */ "CONSUMERS", + /* 147 */ "SUBSCRIPTIONS", + /* 148 */ "LIKE", + /* 149 */ "INDEX", + /* 150 */ "FUNCTION", + /* 151 */ "INTERVAL", + /* 152 */ "TOPIC", + /* 153 */ "AS", + /* 154 */ "WITH", + /* 155 */ "META", + /* 156 */ "CONSUMER", + /* 157 */ "GROUP", + /* 158 */ "DESC", + /* 159 */ "DESCRIBE", + /* 160 */ "RESET", + /* 161 */ "QUERY", + /* 162 */ "CACHE", + /* 163 */ "EXPLAIN", + /* 164 */ "ANALYZE", + /* 165 */ "VERBOSE", + /* 166 */ "NK_BOOL", + /* 167 */ "RATIO", + /* 168 */ "NK_FLOAT", + /* 169 */ "COMPACT", + /* 170 */ "VNODES", + /* 171 */ "IN", + /* 172 */ "OUTPUTTYPE", + /* 173 */ "AGGREGATE", + /* 174 */ "BUFSIZE", + /* 175 */ "STREAM", + /* 176 */ "INTO", + /* 177 */ "TRIGGER", + /* 178 */ "AT_ONCE", + /* 179 */ "WINDOW_CLOSE", + /* 180 */ "IGNORE", + /* 181 */ "EXPIRED", + /* 182 */ "KILL", + /* 183 */ "CONNECTION", + /* 184 */ "TRANSACTION", + /* 185 */ "BALANCE", + /* 186 */ "VGROUP", + /* 187 */ "MERGE", + /* 188 */ "REDISTRIBUTE", + /* 189 */ "SPLIT", + /* 190 */ "SYNCDB", + /* 191 */ "DELETE", + /* 192 */ "INSERT", + /* 193 */ "NULL", + /* 194 */ "NK_QUESTION", + /* 195 */ "NK_ARROW", + /* 196 */ "ROWTS", + /* 197 */ "TBNAME", + /* 198 */ "QSTARTTS", + /* 199 */ "QENDTS", + /* 200 */ "WSTARTTS", + /* 201 */ "WENDTS", + /* 202 */ "WDURATION", + /* 203 */ "CAST", + /* 204 */ "NOW", + /* 205 */ "TODAY", + /* 206 */ "TIMEZONE", + /* 207 */ "CLIENT_VERSION", + /* 208 */ "SERVER_VERSION", + /* 209 */ "SERVER_STATUS", + /* 210 */ "CURRENT_USER", + /* 211 */ "COUNT", + /* 212 */ "LAST_ROW", + /* 213 */ "BETWEEN", + /* 214 */ "IS", + /* 215 */ "NK_LT", + /* 216 */ "NK_GT", + /* 217 */ "NK_LE", + /* 218 */ "NK_GE", + /* 219 */ "NK_NE", + /* 220 */ "MATCH", + /* 221 */ "NMATCH", + /* 222 */ "CONTAINS", + /* 223 */ "JOIN", + /* 224 */ "INNER", + /* 225 */ "SELECT", + /* 226 */ "DISTINCT", + /* 227 */ "WHERE", + /* 228 */ "PARTITION", + /* 229 */ "BY", + /* 230 */ "SESSION", + /* 231 */ "STATE_WINDOW", + /* 232 */ "SLIDING", + /* 233 */ "FILL", + /* 234 */ "VALUE", + /* 235 */ "NONE", + /* 236 */ "PREV", + /* 237 */ "LINEAR", + /* 238 */ "NEXT", + /* 239 */ "HAVING", + /* 240 */ "RANGE", + /* 241 */ "EVERY", + /* 242 */ "ORDER", + /* 243 */ "SLIMIT", + /* 244 */ "SOFFSET", + /* 245 */ "LIMIT", + /* 246 */ "OFFSET", + /* 247 */ "ASC", + /* 248 */ "NULLS", + /* 249 */ "ID", + /* 250 */ "NK_BITNOT", + /* 251 */ "VALUES", + /* 252 */ "IMPORT", + /* 253 */ "NK_SEMI", + /* 254 */ "FILE", + /* 255 */ "cmd", + /* 256 */ "account_options", + /* 257 */ "alter_account_options", + /* 258 */ "literal", + /* 259 */ "alter_account_option", + /* 260 */ "user_name", + /* 261 */ "sysinfo_opt", + /* 262 */ "privileges", + /* 263 */ "priv_level", + /* 264 */ "priv_type_list", + /* 265 */ "priv_type", + /* 266 */ "db_name", + /* 267 */ "dnode_endpoint", + /* 268 */ "not_exists_opt", + /* 269 */ "db_options", + /* 270 */ "exists_opt", + /* 271 */ "alter_db_options", + /* 272 */ "integer_list", + /* 273 */ "variable_list", + /* 274 */ "retention_list", + /* 275 */ "alter_db_option", + /* 276 */ "retention", + /* 277 */ "full_table_name", + /* 278 */ "column_def_list", + /* 279 */ "tags_def_opt", + /* 280 */ "table_options", + /* 281 */ "multi_create_clause", + /* 282 */ "tags_def", + /* 283 */ "multi_drop_clause", + /* 284 */ "alter_table_clause", + /* 285 */ "alter_table_options", + /* 286 */ "column_name", + /* 287 */ "type_name", + /* 288 */ "signed_literal", + /* 289 */ "create_subtable_clause", + /* 290 */ "specific_cols_opt", + /* 291 */ "expression_list", + /* 292 */ "drop_table_clause", + /* 293 */ "col_name_list", + /* 294 */ "table_name", + /* 295 */ "column_def", + /* 296 */ "duration_list", + /* 297 */ "rollup_func_list", + /* 298 */ "alter_table_option", + /* 299 */ "duration_literal", + /* 300 */ "rollup_func_name", + /* 301 */ "function_name", + /* 302 */ "col_name", + /* 303 */ "db_name_cond_opt", + /* 304 */ "like_pattern_opt", + /* 305 */ "table_name_cond", + /* 306 */ "from_db_opt", + /* 307 */ "index_name", + /* 308 */ "index_options", + /* 309 */ "func_list", + /* 310 */ "sliding_opt", + /* 311 */ "sma_stream_opt", + /* 312 */ "func", + /* 313 */ "stream_options", + /* 314 */ "topic_name", + /* 315 */ "query_expression", + /* 316 */ "cgroup_name", + /* 317 */ "analyze_opt", + /* 318 */ "explain_options", + /* 319 */ "agg_func_opt", + /* 320 */ "bufsize_opt", + /* 321 */ "stream_name", + /* 322 */ "into_opt", + /* 323 */ "dnode_list", + /* 324 */ "where_clause_opt", + /* 325 */ "signed", + /* 326 */ "literal_func", + /* 327 */ "literal_list", + /* 328 */ "table_alias", + /* 329 */ "column_alias", + /* 330 */ "expression", + /* 331 */ "pseudo_column", + /* 332 */ "column_reference", + /* 333 */ "function_expression", + /* 334 */ "subquery", + /* 335 */ "star_func", + /* 336 */ "star_func_para_list", + /* 337 */ "noarg_func", + /* 338 */ "other_para_list", + /* 339 */ "star_func_para", + /* 340 */ "predicate", + /* 341 */ "compare_op", + /* 342 */ "in_op", + /* 343 */ "in_predicate_value", + /* 344 */ "boolean_value_expression", + /* 345 */ "boolean_primary", + /* 346 */ "common_expression", + /* 347 */ "from_clause_opt", + /* 348 */ "table_reference_list", + /* 349 */ "table_reference", + /* 350 */ "table_primary", + /* 351 */ "joined_table", + /* 352 */ "alias_opt", + /* 353 */ "parenthesized_joined_table", + /* 354 */ "join_type", + /* 355 */ "search_condition", + /* 356 */ "query_specification", + /* 357 */ "set_quantifier_opt", + /* 358 */ "select_list", + /* 359 */ "partition_by_clause_opt", + /* 360 */ "range_opt", + /* 361 */ "every_opt", + /* 362 */ "fill_opt", + /* 363 */ "twindow_clause_opt", + /* 364 */ "group_by_clause_opt", + /* 365 */ "having_clause_opt", + /* 366 */ "select_item", + /* 367 */ "fill_mode", + /* 368 */ "group_by_list", + /* 369 */ "query_expression_body", + /* 370 */ "order_by_clause_opt", + /* 371 */ "slimit_clause_opt", + /* 372 */ "limit_clause_opt", + /* 373 */ "query_primary", + /* 374 */ "sort_specification_list", + /* 375 */ "sort_specification", + /* 376 */ "ordering_specification_opt", + /* 377 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1677,426 +1711,427 @@ static const char *const yyRuleName[] = { /* 64 */ "cmd ::= USE db_name", /* 65 */ "cmd ::= ALTER DATABASE db_name alter_db_options", /* 66 */ "cmd ::= FLUSH DATABASE db_name", - /* 67 */ "not_exists_opt ::= IF NOT EXISTS", - /* 68 */ "not_exists_opt ::=", - /* 69 */ "exists_opt ::= IF EXISTS", - /* 70 */ "exists_opt ::=", - /* 71 */ "db_options ::=", - /* 72 */ "db_options ::= db_options BUFFER NK_INTEGER", - /* 73 */ "db_options ::= db_options CACHELAST NK_INTEGER", - /* 74 */ "db_options ::= db_options CACHELASTSIZE NK_INTEGER", - /* 75 */ "db_options ::= db_options COMP NK_INTEGER", - /* 76 */ "db_options ::= db_options DURATION NK_INTEGER", - /* 77 */ "db_options ::= db_options DURATION NK_VARIABLE", - /* 78 */ "db_options ::= db_options FSYNC NK_INTEGER", - /* 79 */ "db_options ::= db_options MAXROWS NK_INTEGER", - /* 80 */ "db_options ::= db_options MINROWS NK_INTEGER", - /* 81 */ "db_options ::= db_options KEEP integer_list", - /* 82 */ "db_options ::= db_options KEEP variable_list", - /* 83 */ "db_options ::= db_options PAGES NK_INTEGER", - /* 84 */ "db_options ::= db_options PAGESIZE NK_INTEGER", - /* 85 */ "db_options ::= db_options PRECISION NK_STRING", - /* 86 */ "db_options ::= db_options REPLICA NK_INTEGER", - /* 87 */ "db_options ::= db_options STRICT NK_INTEGER", - /* 88 */ "db_options ::= db_options WAL NK_INTEGER", - /* 89 */ "db_options ::= db_options VGROUPS NK_INTEGER", - /* 90 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", - /* 91 */ "db_options ::= db_options RETENTIONS retention_list", - /* 92 */ "db_options ::= db_options SCHEMALESS NK_INTEGER", - /* 93 */ "alter_db_options ::= alter_db_option", - /* 94 */ "alter_db_options ::= alter_db_options alter_db_option", - /* 95 */ "alter_db_option ::= BUFFER NK_INTEGER", - /* 96 */ "alter_db_option ::= CACHELAST NK_INTEGER", - /* 97 */ "alter_db_option ::= CACHELASTSIZE NK_INTEGER", - /* 98 */ "alter_db_option ::= FSYNC NK_INTEGER", - /* 99 */ "alter_db_option ::= KEEP integer_list", - /* 100 */ "alter_db_option ::= KEEP variable_list", - /* 101 */ "alter_db_option ::= PAGES NK_INTEGER", - /* 102 */ "alter_db_option ::= REPLICA NK_INTEGER", - /* 103 */ "alter_db_option ::= STRICT NK_INTEGER", - /* 104 */ "alter_db_option ::= WAL NK_INTEGER", - /* 105 */ "integer_list ::= NK_INTEGER", - /* 106 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", - /* 107 */ "variable_list ::= NK_VARIABLE", - /* 108 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", - /* 109 */ "retention_list ::= retention", - /* 110 */ "retention_list ::= retention_list NK_COMMA retention", - /* 111 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", - /* 112 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 113 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 114 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 115 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 116 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 117 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 118 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 119 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 120 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 121 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 122 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 123 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 124 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 125 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 126 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 127 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 128 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", - /* 129 */ "multi_create_clause ::= create_subtable_clause", - /* 130 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 131 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options", - /* 132 */ "multi_drop_clause ::= drop_table_clause", - /* 133 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 134 */ "drop_table_clause ::= exists_opt full_table_name", - /* 135 */ "specific_cols_opt ::=", - /* 136 */ "specific_cols_opt ::= NK_LP col_name_list NK_RP", - /* 137 */ "full_table_name ::= table_name", - /* 138 */ "full_table_name ::= db_name NK_DOT table_name", - /* 139 */ "column_def_list ::= column_def", - /* 140 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 141 */ "column_def ::= column_name type_name", - /* 142 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 143 */ "type_name ::= BOOL", - /* 144 */ "type_name ::= TINYINT", - /* 145 */ "type_name ::= SMALLINT", - /* 146 */ "type_name ::= INT", - /* 147 */ "type_name ::= INTEGER", - /* 148 */ "type_name ::= BIGINT", - /* 149 */ "type_name ::= FLOAT", - /* 150 */ "type_name ::= DOUBLE", - /* 151 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 152 */ "type_name ::= TIMESTAMP", - /* 153 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 154 */ "type_name ::= TINYINT UNSIGNED", - /* 155 */ "type_name ::= SMALLINT UNSIGNED", - /* 156 */ "type_name ::= INT UNSIGNED", - /* 157 */ "type_name ::= BIGINT UNSIGNED", - /* 158 */ "type_name ::= JSON", - /* 159 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 160 */ "type_name ::= MEDIUMBLOB", - /* 161 */ "type_name ::= BLOB", - /* 162 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 163 */ "type_name ::= DECIMAL", - /* 164 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 165 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 166 */ "tags_def_opt ::=", - /* 167 */ "tags_def_opt ::= tags_def", - /* 168 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 169 */ "table_options ::=", - /* 170 */ "table_options ::= table_options COMMENT NK_STRING", - /* 171 */ "table_options ::= table_options MAX_DELAY duration_list", - /* 172 */ "table_options ::= table_options WATERMARK duration_list", - /* 173 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", - /* 174 */ "table_options ::= table_options TTL NK_INTEGER", - /* 175 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 176 */ "alter_table_options ::= alter_table_option", - /* 177 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 178 */ "alter_table_option ::= COMMENT NK_STRING", - /* 179 */ "alter_table_option ::= TTL NK_INTEGER", - /* 180 */ "duration_list ::= duration_literal", - /* 181 */ "duration_list ::= duration_list NK_COMMA duration_literal", - /* 182 */ "rollup_func_list ::= rollup_func_name", - /* 183 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", - /* 184 */ "rollup_func_name ::= function_name", - /* 185 */ "rollup_func_name ::= FIRST", - /* 186 */ "rollup_func_name ::= LAST", - /* 187 */ "col_name_list ::= col_name", - /* 188 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 189 */ "col_name ::= column_name", - /* 190 */ "cmd ::= SHOW DNODES", - /* 191 */ "cmd ::= SHOW USERS", - /* 192 */ "cmd ::= SHOW DATABASES", - /* 193 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 194 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 195 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 196 */ "cmd ::= SHOW MNODES", - /* 197 */ "cmd ::= SHOW MODULES", - /* 198 */ "cmd ::= SHOW QNODES", - /* 199 */ "cmd ::= SHOW FUNCTIONS", - /* 200 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 201 */ "cmd ::= SHOW STREAMS", - /* 202 */ "cmd ::= SHOW ACCOUNTS", - /* 203 */ "cmd ::= SHOW APPS", - /* 204 */ "cmd ::= SHOW CONNECTIONS", - /* 205 */ "cmd ::= SHOW LICENCE", - /* 206 */ "cmd ::= SHOW GRANTS", - /* 207 */ "cmd ::= SHOW CREATE DATABASE db_name", - /* 208 */ "cmd ::= SHOW CREATE TABLE full_table_name", - /* 209 */ "cmd ::= SHOW CREATE STABLE full_table_name", - /* 210 */ "cmd ::= SHOW QUERIES", - /* 211 */ "cmd ::= SHOW SCORES", - /* 212 */ "cmd ::= SHOW TOPICS", - /* 213 */ "cmd ::= SHOW VARIABLES", - /* 214 */ "cmd ::= SHOW LOCAL VARIABLES", - /* 215 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", - /* 216 */ "cmd ::= SHOW BNODES", - /* 217 */ "cmd ::= SHOW SNODES", - /* 218 */ "cmd ::= SHOW CLUSTER", - /* 219 */ "cmd ::= SHOW TRANSACTIONS", - /* 220 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", - /* 221 */ "cmd ::= SHOW CONSUMERS", - /* 222 */ "cmd ::= SHOW SUBSCRIPTIONS", - /* 223 */ "db_name_cond_opt ::=", - /* 224 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 225 */ "like_pattern_opt ::=", - /* 226 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 227 */ "table_name_cond ::= table_name", - /* 228 */ "from_db_opt ::=", - /* 229 */ "from_db_opt ::= FROM db_name", - /* 230 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 231 */ "cmd ::= DROP INDEX exists_opt index_name", - /* 232 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", - /* 233 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", - /* 234 */ "func_list ::= func", - /* 235 */ "func_list ::= func_list NK_COMMA func", - /* 236 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 237 */ "sma_stream_opt ::=", - /* 238 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", - /* 239 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", - /* 240 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 241 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", - /* 242 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", - /* 243 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", - /* 244 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", - /* 245 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 246 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", - /* 247 */ "cmd ::= DESC full_table_name", - /* 248 */ "cmd ::= DESCRIBE full_table_name", - /* 249 */ "cmd ::= RESET QUERY CACHE", - /* 250 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 251 */ "analyze_opt ::=", - /* 252 */ "analyze_opt ::= ANALYZE", - /* 253 */ "explain_options ::=", - /* 254 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 255 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 256 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", - /* 257 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 258 */ "cmd ::= DROP FUNCTION exists_opt function_name", - /* 259 */ "agg_func_opt ::=", - /* 260 */ "agg_func_opt ::= AGGREGATE", - /* 261 */ "bufsize_opt ::=", - /* 262 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 263 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", - /* 264 */ "cmd ::= DROP STREAM exists_opt stream_name", - /* 265 */ "into_opt ::=", - /* 266 */ "into_opt ::= INTO full_table_name", - /* 267 */ "stream_options ::=", - /* 268 */ "stream_options ::= stream_options TRIGGER AT_ONCE", - /* 269 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", - /* 270 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", - /* 271 */ "stream_options ::= stream_options WATERMARK duration_literal", - /* 272 */ "stream_options ::= stream_options IGNORE EXPIRED", - /* 273 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 274 */ "cmd ::= KILL QUERY NK_STRING", - /* 275 */ "cmd ::= KILL TRANSACTION NK_INTEGER", - /* 276 */ "cmd ::= BALANCE VGROUP", - /* 277 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 278 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 279 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 280 */ "dnode_list ::= DNODE NK_INTEGER", - /* 281 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 282 */ "cmd ::= SYNCDB db_name REPLICA", - /* 283 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", - /* 284 */ "cmd ::= query_expression", - /* 285 */ "cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression", - /* 286 */ "literal ::= NK_INTEGER", - /* 287 */ "literal ::= NK_FLOAT", - /* 288 */ "literal ::= NK_STRING", - /* 289 */ "literal ::= NK_BOOL", - /* 290 */ "literal ::= TIMESTAMP NK_STRING", - /* 291 */ "literal ::= duration_literal", - /* 292 */ "literal ::= NULL", - /* 293 */ "literal ::= NK_QUESTION", - /* 294 */ "duration_literal ::= NK_VARIABLE", - /* 295 */ "signed ::= NK_INTEGER", - /* 296 */ "signed ::= NK_PLUS NK_INTEGER", - /* 297 */ "signed ::= NK_MINUS NK_INTEGER", - /* 298 */ "signed ::= NK_FLOAT", - /* 299 */ "signed ::= NK_PLUS NK_FLOAT", - /* 300 */ "signed ::= NK_MINUS NK_FLOAT", - /* 301 */ "signed_literal ::= signed", - /* 302 */ "signed_literal ::= NK_STRING", - /* 303 */ "signed_literal ::= NK_BOOL", - /* 304 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 305 */ "signed_literal ::= duration_literal", - /* 306 */ "signed_literal ::= NULL", - /* 307 */ "signed_literal ::= literal_func", - /* 308 */ "literal_list ::= signed_literal", - /* 309 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 310 */ "db_name ::= NK_ID", - /* 311 */ "table_name ::= NK_ID", - /* 312 */ "column_name ::= NK_ID", - /* 313 */ "function_name ::= NK_ID", - /* 314 */ "table_alias ::= NK_ID", - /* 315 */ "column_alias ::= NK_ID", - /* 316 */ "user_name ::= NK_ID", - /* 317 */ "index_name ::= NK_ID", - /* 318 */ "topic_name ::= NK_ID", - /* 319 */ "stream_name ::= NK_ID", - /* 320 */ "cgroup_name ::= NK_ID", - /* 321 */ "expression ::= literal", - /* 322 */ "expression ::= pseudo_column", - /* 323 */ "expression ::= column_reference", - /* 324 */ "expression ::= function_expression", - /* 325 */ "expression ::= subquery", - /* 326 */ "expression ::= NK_LP expression NK_RP", - /* 327 */ "expression ::= NK_PLUS expression", - /* 328 */ "expression ::= NK_MINUS expression", - /* 329 */ "expression ::= expression NK_PLUS expression", - /* 330 */ "expression ::= expression NK_MINUS expression", - /* 331 */ "expression ::= expression NK_STAR expression", - /* 332 */ "expression ::= expression NK_SLASH expression", - /* 333 */ "expression ::= expression NK_REM expression", - /* 334 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 335 */ "expression ::= expression NK_BITAND expression", - /* 336 */ "expression ::= expression NK_BITOR expression", - /* 337 */ "expression_list ::= expression", - /* 338 */ "expression_list ::= expression_list NK_COMMA expression", - /* 339 */ "column_reference ::= column_name", - /* 340 */ "column_reference ::= table_name NK_DOT column_name", - /* 341 */ "pseudo_column ::= ROWTS", - /* 342 */ "pseudo_column ::= TBNAME", - /* 343 */ "pseudo_column ::= table_name NK_DOT TBNAME", - /* 344 */ "pseudo_column ::= QSTARTTS", - /* 345 */ "pseudo_column ::= QENDTS", - /* 346 */ "pseudo_column ::= WSTARTTS", - /* 347 */ "pseudo_column ::= WENDTS", - /* 348 */ "pseudo_column ::= WDURATION", - /* 349 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 350 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 351 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 352 */ "function_expression ::= literal_func", - /* 353 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 354 */ "literal_func ::= NOW", - /* 355 */ "noarg_func ::= NOW", - /* 356 */ "noarg_func ::= TODAY", - /* 357 */ "noarg_func ::= TIMEZONE", - /* 358 */ "noarg_func ::= DATABASE", - /* 359 */ "noarg_func ::= CLIENT_VERSION", - /* 360 */ "noarg_func ::= SERVER_VERSION", - /* 361 */ "noarg_func ::= SERVER_STATUS", - /* 362 */ "noarg_func ::= CURRENT_USER", - /* 363 */ "noarg_func ::= USER", - /* 364 */ "star_func ::= COUNT", - /* 365 */ "star_func ::= FIRST", - /* 366 */ "star_func ::= LAST", - /* 367 */ "star_func ::= LAST_ROW", - /* 368 */ "star_func_para_list ::= NK_STAR", - /* 369 */ "star_func_para_list ::= other_para_list", - /* 370 */ "other_para_list ::= star_func_para", - /* 371 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 372 */ "star_func_para ::= expression", - /* 373 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 374 */ "predicate ::= expression compare_op expression", - /* 375 */ "predicate ::= expression BETWEEN expression AND expression", - /* 376 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 377 */ "predicate ::= expression IS NULL", - /* 378 */ "predicate ::= expression IS NOT NULL", - /* 379 */ "predicate ::= expression in_op in_predicate_value", - /* 380 */ "compare_op ::= NK_LT", - /* 381 */ "compare_op ::= NK_GT", - /* 382 */ "compare_op ::= NK_LE", - /* 383 */ "compare_op ::= NK_GE", - /* 384 */ "compare_op ::= NK_NE", - /* 385 */ "compare_op ::= NK_EQ", - /* 386 */ "compare_op ::= LIKE", - /* 387 */ "compare_op ::= NOT LIKE", - /* 388 */ "compare_op ::= MATCH", - /* 389 */ "compare_op ::= NMATCH", - /* 390 */ "compare_op ::= CONTAINS", - /* 391 */ "in_op ::= IN", - /* 392 */ "in_op ::= NOT IN", - /* 393 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 394 */ "boolean_value_expression ::= boolean_primary", - /* 395 */ "boolean_value_expression ::= NOT boolean_primary", - /* 396 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 397 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 398 */ "boolean_primary ::= predicate", - /* 399 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 400 */ "common_expression ::= expression", - /* 401 */ "common_expression ::= boolean_value_expression", - /* 402 */ "from_clause_opt ::=", - /* 403 */ "from_clause_opt ::= FROM table_reference_list", - /* 404 */ "table_reference_list ::= table_reference", - /* 405 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 406 */ "table_reference ::= table_primary", - /* 407 */ "table_reference ::= joined_table", - /* 408 */ "table_primary ::= table_name alias_opt", - /* 409 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 410 */ "table_primary ::= subquery alias_opt", - /* 411 */ "table_primary ::= parenthesized_joined_table", - /* 412 */ "alias_opt ::=", - /* 413 */ "alias_opt ::= table_alias", - /* 414 */ "alias_opt ::= AS table_alias", - /* 415 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 416 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 417 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 418 */ "join_type ::=", - /* 419 */ "join_type ::= INNER", - /* 420 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 421 */ "set_quantifier_opt ::=", - /* 422 */ "set_quantifier_opt ::= DISTINCT", - /* 423 */ "set_quantifier_opt ::= ALL", - /* 424 */ "select_list ::= select_item", - /* 425 */ "select_list ::= select_list NK_COMMA select_item", - /* 426 */ "select_item ::= NK_STAR", - /* 427 */ "select_item ::= common_expression", - /* 428 */ "select_item ::= common_expression column_alias", - /* 429 */ "select_item ::= common_expression AS column_alias", - /* 430 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 431 */ "where_clause_opt ::=", - /* 432 */ "where_clause_opt ::= WHERE search_condition", - /* 433 */ "partition_by_clause_opt ::=", - /* 434 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 435 */ "twindow_clause_opt ::=", - /* 436 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 437 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 438 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 439 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 440 */ "sliding_opt ::=", - /* 441 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 442 */ "fill_opt ::=", - /* 443 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 444 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 445 */ "fill_mode ::= NONE", - /* 446 */ "fill_mode ::= PREV", - /* 447 */ "fill_mode ::= NULL", - /* 448 */ "fill_mode ::= LINEAR", - /* 449 */ "fill_mode ::= NEXT", - /* 450 */ "group_by_clause_opt ::=", - /* 451 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 452 */ "group_by_list ::= expression", - /* 453 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 454 */ "having_clause_opt ::=", - /* 455 */ "having_clause_opt ::= HAVING search_condition", - /* 456 */ "range_opt ::=", - /* 457 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", - /* 458 */ "every_opt ::=", - /* 459 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", - /* 460 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 461 */ "query_expression_body ::= query_primary", - /* 462 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 463 */ "query_expression_body ::= query_expression_body UNION query_expression_body", - /* 464 */ "query_primary ::= query_specification", - /* 465 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", - /* 466 */ "order_by_clause_opt ::=", - /* 467 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 468 */ "slimit_clause_opt ::=", - /* 469 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 470 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 471 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 472 */ "limit_clause_opt ::=", - /* 473 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 474 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 475 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 476 */ "subquery ::= NK_LP query_expression NK_RP", - /* 477 */ "search_condition ::= common_expression", - /* 478 */ "sort_specification_list ::= sort_specification", - /* 479 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 480 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 481 */ "ordering_specification_opt ::=", - /* 482 */ "ordering_specification_opt ::= ASC", - /* 483 */ "ordering_specification_opt ::= DESC", - /* 484 */ "null_ordering_opt ::=", - /* 485 */ "null_ordering_opt ::= NULLS FIRST", - /* 486 */ "null_ordering_opt ::= NULLS LAST", + /* 67 */ "cmd ::= TRIM DATABASE db_name", + /* 68 */ "not_exists_opt ::= IF NOT EXISTS", + /* 69 */ "not_exists_opt ::=", + /* 70 */ "exists_opt ::= IF EXISTS", + /* 71 */ "exists_opt ::=", + /* 72 */ "db_options ::=", + /* 73 */ "db_options ::= db_options BUFFER NK_INTEGER", + /* 74 */ "db_options ::= db_options CACHELAST NK_INTEGER", + /* 75 */ "db_options ::= db_options CACHELASTSIZE NK_INTEGER", + /* 76 */ "db_options ::= db_options COMP NK_INTEGER", + /* 77 */ "db_options ::= db_options DURATION NK_INTEGER", + /* 78 */ "db_options ::= db_options DURATION NK_VARIABLE", + /* 79 */ "db_options ::= db_options FSYNC NK_INTEGER", + /* 80 */ "db_options ::= db_options MAXROWS NK_INTEGER", + /* 81 */ "db_options ::= db_options MINROWS NK_INTEGER", + /* 82 */ "db_options ::= db_options KEEP integer_list", + /* 83 */ "db_options ::= db_options KEEP variable_list", + /* 84 */ "db_options ::= db_options PAGES NK_INTEGER", + /* 85 */ "db_options ::= db_options PAGESIZE NK_INTEGER", + /* 86 */ "db_options ::= db_options PRECISION NK_STRING", + /* 87 */ "db_options ::= db_options REPLICA NK_INTEGER", + /* 88 */ "db_options ::= db_options STRICT NK_INTEGER", + /* 89 */ "db_options ::= db_options WAL NK_INTEGER", + /* 90 */ "db_options ::= db_options VGROUPS NK_INTEGER", + /* 91 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", + /* 92 */ "db_options ::= db_options RETENTIONS retention_list", + /* 93 */ "db_options ::= db_options SCHEMALESS NK_INTEGER", + /* 94 */ "alter_db_options ::= alter_db_option", + /* 95 */ "alter_db_options ::= alter_db_options alter_db_option", + /* 96 */ "alter_db_option ::= BUFFER NK_INTEGER", + /* 97 */ "alter_db_option ::= CACHELAST NK_INTEGER", + /* 98 */ "alter_db_option ::= CACHELASTSIZE NK_INTEGER", + /* 99 */ "alter_db_option ::= FSYNC NK_INTEGER", + /* 100 */ "alter_db_option ::= KEEP integer_list", + /* 101 */ "alter_db_option ::= KEEP variable_list", + /* 102 */ "alter_db_option ::= PAGES NK_INTEGER", + /* 103 */ "alter_db_option ::= REPLICA NK_INTEGER", + /* 104 */ "alter_db_option ::= STRICT NK_INTEGER", + /* 105 */ "alter_db_option ::= WAL NK_INTEGER", + /* 106 */ "integer_list ::= NK_INTEGER", + /* 107 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", + /* 108 */ "variable_list ::= NK_VARIABLE", + /* 109 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", + /* 110 */ "retention_list ::= retention", + /* 111 */ "retention_list ::= retention_list NK_COMMA retention", + /* 112 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", + /* 113 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 114 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 115 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 116 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 117 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 118 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 119 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 120 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 121 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 122 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 123 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 124 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 125 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 126 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 127 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 128 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 129 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", + /* 130 */ "multi_create_clause ::= create_subtable_clause", + /* 131 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 132 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options", + /* 133 */ "multi_drop_clause ::= drop_table_clause", + /* 134 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 135 */ "drop_table_clause ::= exists_opt full_table_name", + /* 136 */ "specific_cols_opt ::=", + /* 137 */ "specific_cols_opt ::= NK_LP col_name_list NK_RP", + /* 138 */ "full_table_name ::= table_name", + /* 139 */ "full_table_name ::= db_name NK_DOT table_name", + /* 140 */ "column_def_list ::= column_def", + /* 141 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 142 */ "column_def ::= column_name type_name", + /* 143 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 144 */ "type_name ::= BOOL", + /* 145 */ "type_name ::= TINYINT", + /* 146 */ "type_name ::= SMALLINT", + /* 147 */ "type_name ::= INT", + /* 148 */ "type_name ::= INTEGER", + /* 149 */ "type_name ::= BIGINT", + /* 150 */ "type_name ::= FLOAT", + /* 151 */ "type_name ::= DOUBLE", + /* 152 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 153 */ "type_name ::= TIMESTAMP", + /* 154 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 155 */ "type_name ::= TINYINT UNSIGNED", + /* 156 */ "type_name ::= SMALLINT UNSIGNED", + /* 157 */ "type_name ::= INT UNSIGNED", + /* 158 */ "type_name ::= BIGINT UNSIGNED", + /* 159 */ "type_name ::= JSON", + /* 160 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 161 */ "type_name ::= MEDIUMBLOB", + /* 162 */ "type_name ::= BLOB", + /* 163 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 164 */ "type_name ::= DECIMAL", + /* 165 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 166 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 167 */ "tags_def_opt ::=", + /* 168 */ "tags_def_opt ::= tags_def", + /* 169 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 170 */ "table_options ::=", + /* 171 */ "table_options ::= table_options COMMENT NK_STRING", + /* 172 */ "table_options ::= table_options MAX_DELAY duration_list", + /* 173 */ "table_options ::= table_options WATERMARK duration_list", + /* 174 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", + /* 175 */ "table_options ::= table_options TTL NK_INTEGER", + /* 176 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 177 */ "alter_table_options ::= alter_table_option", + /* 178 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 179 */ "alter_table_option ::= COMMENT NK_STRING", + /* 180 */ "alter_table_option ::= TTL NK_INTEGER", + /* 181 */ "duration_list ::= duration_literal", + /* 182 */ "duration_list ::= duration_list NK_COMMA duration_literal", + /* 183 */ "rollup_func_list ::= rollup_func_name", + /* 184 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", + /* 185 */ "rollup_func_name ::= function_name", + /* 186 */ "rollup_func_name ::= FIRST", + /* 187 */ "rollup_func_name ::= LAST", + /* 188 */ "col_name_list ::= col_name", + /* 189 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 190 */ "col_name ::= column_name", + /* 191 */ "cmd ::= SHOW DNODES", + /* 192 */ "cmd ::= SHOW USERS", + /* 193 */ "cmd ::= SHOW DATABASES", + /* 194 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 195 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 196 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 197 */ "cmd ::= SHOW MNODES", + /* 198 */ "cmd ::= SHOW MODULES", + /* 199 */ "cmd ::= SHOW QNODES", + /* 200 */ "cmd ::= SHOW FUNCTIONS", + /* 201 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 202 */ "cmd ::= SHOW STREAMS", + /* 203 */ "cmd ::= SHOW ACCOUNTS", + /* 204 */ "cmd ::= SHOW APPS", + /* 205 */ "cmd ::= SHOW CONNECTIONS", + /* 206 */ "cmd ::= SHOW LICENCE", + /* 207 */ "cmd ::= SHOW GRANTS", + /* 208 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 209 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 210 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 211 */ "cmd ::= SHOW QUERIES", + /* 212 */ "cmd ::= SHOW SCORES", + /* 213 */ "cmd ::= SHOW TOPICS", + /* 214 */ "cmd ::= SHOW VARIABLES", + /* 215 */ "cmd ::= SHOW LOCAL VARIABLES", + /* 216 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", + /* 217 */ "cmd ::= SHOW BNODES", + /* 218 */ "cmd ::= SHOW SNODES", + /* 219 */ "cmd ::= SHOW CLUSTER", + /* 220 */ "cmd ::= SHOW TRANSACTIONS", + /* 221 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", + /* 222 */ "cmd ::= SHOW CONSUMERS", + /* 223 */ "cmd ::= SHOW SUBSCRIPTIONS", + /* 224 */ "db_name_cond_opt ::=", + /* 225 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 226 */ "like_pattern_opt ::=", + /* 227 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 228 */ "table_name_cond ::= table_name", + /* 229 */ "from_db_opt ::=", + /* 230 */ "from_db_opt ::= FROM db_name", + /* 231 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 232 */ "cmd ::= DROP INDEX exists_opt index_name", + /* 233 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", + /* 234 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", + /* 235 */ "func_list ::= func", + /* 236 */ "func_list ::= func_list NK_COMMA func", + /* 237 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 238 */ "sma_stream_opt ::=", + /* 239 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", + /* 240 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", + /* 241 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 242 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", + /* 243 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", + /* 244 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", + /* 245 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", + /* 246 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 247 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", + /* 248 */ "cmd ::= DESC full_table_name", + /* 249 */ "cmd ::= DESCRIBE full_table_name", + /* 250 */ "cmd ::= RESET QUERY CACHE", + /* 251 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 252 */ "analyze_opt ::=", + /* 253 */ "analyze_opt ::= ANALYZE", + /* 254 */ "explain_options ::=", + /* 255 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 256 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 257 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 258 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 259 */ "cmd ::= DROP FUNCTION exists_opt function_name", + /* 260 */ "agg_func_opt ::=", + /* 261 */ "agg_func_opt ::= AGGREGATE", + /* 262 */ "bufsize_opt ::=", + /* 263 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 264 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", + /* 265 */ "cmd ::= DROP STREAM exists_opt stream_name", + /* 266 */ "into_opt ::=", + /* 267 */ "into_opt ::= INTO full_table_name", + /* 268 */ "stream_options ::=", + /* 269 */ "stream_options ::= stream_options TRIGGER AT_ONCE", + /* 270 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", + /* 271 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", + /* 272 */ "stream_options ::= stream_options WATERMARK duration_literal", + /* 273 */ "stream_options ::= stream_options IGNORE EXPIRED", + /* 274 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 275 */ "cmd ::= KILL QUERY NK_STRING", + /* 276 */ "cmd ::= KILL TRANSACTION NK_INTEGER", + /* 277 */ "cmd ::= BALANCE VGROUP", + /* 278 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 279 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 280 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 281 */ "dnode_list ::= DNODE NK_INTEGER", + /* 282 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 283 */ "cmd ::= SYNCDB db_name REPLICA", + /* 284 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", + /* 285 */ "cmd ::= query_expression", + /* 286 */ "cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression", + /* 287 */ "literal ::= NK_INTEGER", + /* 288 */ "literal ::= NK_FLOAT", + /* 289 */ "literal ::= NK_STRING", + /* 290 */ "literal ::= NK_BOOL", + /* 291 */ "literal ::= TIMESTAMP NK_STRING", + /* 292 */ "literal ::= duration_literal", + /* 293 */ "literal ::= NULL", + /* 294 */ "literal ::= NK_QUESTION", + /* 295 */ "duration_literal ::= NK_VARIABLE", + /* 296 */ "signed ::= NK_INTEGER", + /* 297 */ "signed ::= NK_PLUS NK_INTEGER", + /* 298 */ "signed ::= NK_MINUS NK_INTEGER", + /* 299 */ "signed ::= NK_FLOAT", + /* 300 */ "signed ::= NK_PLUS NK_FLOAT", + /* 301 */ "signed ::= NK_MINUS NK_FLOAT", + /* 302 */ "signed_literal ::= signed", + /* 303 */ "signed_literal ::= NK_STRING", + /* 304 */ "signed_literal ::= NK_BOOL", + /* 305 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 306 */ "signed_literal ::= duration_literal", + /* 307 */ "signed_literal ::= NULL", + /* 308 */ "signed_literal ::= literal_func", + /* 309 */ "literal_list ::= signed_literal", + /* 310 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 311 */ "db_name ::= NK_ID", + /* 312 */ "table_name ::= NK_ID", + /* 313 */ "column_name ::= NK_ID", + /* 314 */ "function_name ::= NK_ID", + /* 315 */ "table_alias ::= NK_ID", + /* 316 */ "column_alias ::= NK_ID", + /* 317 */ "user_name ::= NK_ID", + /* 318 */ "index_name ::= NK_ID", + /* 319 */ "topic_name ::= NK_ID", + /* 320 */ "stream_name ::= NK_ID", + /* 321 */ "cgroup_name ::= NK_ID", + /* 322 */ "expression ::= literal", + /* 323 */ "expression ::= pseudo_column", + /* 324 */ "expression ::= column_reference", + /* 325 */ "expression ::= function_expression", + /* 326 */ "expression ::= subquery", + /* 327 */ "expression ::= NK_LP expression NK_RP", + /* 328 */ "expression ::= NK_PLUS expression", + /* 329 */ "expression ::= NK_MINUS expression", + /* 330 */ "expression ::= expression NK_PLUS expression", + /* 331 */ "expression ::= expression NK_MINUS expression", + /* 332 */ "expression ::= expression NK_STAR expression", + /* 333 */ "expression ::= expression NK_SLASH expression", + /* 334 */ "expression ::= expression NK_REM expression", + /* 335 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 336 */ "expression ::= expression NK_BITAND expression", + /* 337 */ "expression ::= expression NK_BITOR expression", + /* 338 */ "expression_list ::= expression", + /* 339 */ "expression_list ::= expression_list NK_COMMA expression", + /* 340 */ "column_reference ::= column_name", + /* 341 */ "column_reference ::= table_name NK_DOT column_name", + /* 342 */ "pseudo_column ::= ROWTS", + /* 343 */ "pseudo_column ::= TBNAME", + /* 344 */ "pseudo_column ::= table_name NK_DOT TBNAME", + /* 345 */ "pseudo_column ::= QSTARTTS", + /* 346 */ "pseudo_column ::= QENDTS", + /* 347 */ "pseudo_column ::= WSTARTTS", + /* 348 */ "pseudo_column ::= WENDTS", + /* 349 */ "pseudo_column ::= WDURATION", + /* 350 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 351 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 352 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", + /* 353 */ "function_expression ::= literal_func", + /* 354 */ "literal_func ::= noarg_func NK_LP NK_RP", + /* 355 */ "literal_func ::= NOW", + /* 356 */ "noarg_func ::= NOW", + /* 357 */ "noarg_func ::= TODAY", + /* 358 */ "noarg_func ::= TIMEZONE", + /* 359 */ "noarg_func ::= DATABASE", + /* 360 */ "noarg_func ::= CLIENT_VERSION", + /* 361 */ "noarg_func ::= SERVER_VERSION", + /* 362 */ "noarg_func ::= SERVER_STATUS", + /* 363 */ "noarg_func ::= CURRENT_USER", + /* 364 */ "noarg_func ::= USER", + /* 365 */ "star_func ::= COUNT", + /* 366 */ "star_func ::= FIRST", + /* 367 */ "star_func ::= LAST", + /* 368 */ "star_func ::= LAST_ROW", + /* 369 */ "star_func_para_list ::= NK_STAR", + /* 370 */ "star_func_para_list ::= other_para_list", + /* 371 */ "other_para_list ::= star_func_para", + /* 372 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 373 */ "star_func_para ::= expression", + /* 374 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 375 */ "predicate ::= expression compare_op expression", + /* 376 */ "predicate ::= expression BETWEEN expression AND expression", + /* 377 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 378 */ "predicate ::= expression IS NULL", + /* 379 */ "predicate ::= expression IS NOT NULL", + /* 380 */ "predicate ::= expression in_op in_predicate_value", + /* 381 */ "compare_op ::= NK_LT", + /* 382 */ "compare_op ::= NK_GT", + /* 383 */ "compare_op ::= NK_LE", + /* 384 */ "compare_op ::= NK_GE", + /* 385 */ "compare_op ::= NK_NE", + /* 386 */ "compare_op ::= NK_EQ", + /* 387 */ "compare_op ::= LIKE", + /* 388 */ "compare_op ::= NOT LIKE", + /* 389 */ "compare_op ::= MATCH", + /* 390 */ "compare_op ::= NMATCH", + /* 391 */ "compare_op ::= CONTAINS", + /* 392 */ "in_op ::= IN", + /* 393 */ "in_op ::= NOT IN", + /* 394 */ "in_predicate_value ::= NK_LP literal_list NK_RP", + /* 395 */ "boolean_value_expression ::= boolean_primary", + /* 396 */ "boolean_value_expression ::= NOT boolean_primary", + /* 397 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 398 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 399 */ "boolean_primary ::= predicate", + /* 400 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 401 */ "common_expression ::= expression", + /* 402 */ "common_expression ::= boolean_value_expression", + /* 403 */ "from_clause_opt ::=", + /* 404 */ "from_clause_opt ::= FROM table_reference_list", + /* 405 */ "table_reference_list ::= table_reference", + /* 406 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 407 */ "table_reference ::= table_primary", + /* 408 */ "table_reference ::= joined_table", + /* 409 */ "table_primary ::= table_name alias_opt", + /* 410 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 411 */ "table_primary ::= subquery alias_opt", + /* 412 */ "table_primary ::= parenthesized_joined_table", + /* 413 */ "alias_opt ::=", + /* 414 */ "alias_opt ::= table_alias", + /* 415 */ "alias_opt ::= AS table_alias", + /* 416 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 417 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 418 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 419 */ "join_type ::=", + /* 420 */ "join_type ::= INNER", + /* 421 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 422 */ "set_quantifier_opt ::=", + /* 423 */ "set_quantifier_opt ::= DISTINCT", + /* 424 */ "set_quantifier_opt ::= ALL", + /* 425 */ "select_list ::= select_item", + /* 426 */ "select_list ::= select_list NK_COMMA select_item", + /* 427 */ "select_item ::= NK_STAR", + /* 428 */ "select_item ::= common_expression", + /* 429 */ "select_item ::= common_expression column_alias", + /* 430 */ "select_item ::= common_expression AS column_alias", + /* 431 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 432 */ "where_clause_opt ::=", + /* 433 */ "where_clause_opt ::= WHERE search_condition", + /* 434 */ "partition_by_clause_opt ::=", + /* 435 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 436 */ "twindow_clause_opt ::=", + /* 437 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 438 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 439 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 440 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 441 */ "sliding_opt ::=", + /* 442 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 443 */ "fill_opt ::=", + /* 444 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 445 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 446 */ "fill_mode ::= NONE", + /* 447 */ "fill_mode ::= PREV", + /* 448 */ "fill_mode ::= NULL", + /* 449 */ "fill_mode ::= LINEAR", + /* 450 */ "fill_mode ::= NEXT", + /* 451 */ "group_by_clause_opt ::=", + /* 452 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 453 */ "group_by_list ::= expression", + /* 454 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 455 */ "having_clause_opt ::=", + /* 456 */ "having_clause_opt ::= HAVING search_condition", + /* 457 */ "range_opt ::=", + /* 458 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", + /* 459 */ "every_opt ::=", + /* 460 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", + /* 461 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 462 */ "query_expression_body ::= query_primary", + /* 463 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 464 */ "query_expression_body ::= query_expression_body UNION query_expression_body", + /* 465 */ "query_primary ::= query_specification", + /* 466 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", + /* 467 */ "order_by_clause_opt ::=", + /* 468 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 469 */ "slimit_clause_opt ::=", + /* 470 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 471 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 472 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 473 */ "limit_clause_opt ::=", + /* 474 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 475 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 476 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 477 */ "subquery ::= NK_LP query_expression NK_RP", + /* 478 */ "search_condition ::= common_expression", + /* 479 */ "sort_specification_list ::= sort_specification", + /* 480 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 481 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 482 */ "ordering_specification_opt ::=", + /* 483 */ "ordering_specification_opt ::= ASC", + /* 484 */ "ordering_specification_opt ::= DESC", + /* 485 */ "null_ordering_opt ::=", + /* 486 */ "null_ordering_opt ::= NULLS FIRST", + /* 487 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -2223,181 +2258,181 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 254: /* cmd */ - case 257: /* literal */ - case 268: /* db_options */ - case 270: /* alter_db_options */ - case 275: /* retention */ - case 276: /* full_table_name */ - case 279: /* table_options */ - case 283: /* alter_table_clause */ - case 284: /* alter_table_options */ - case 287: /* signed_literal */ - case 288: /* create_subtable_clause */ - case 291: /* drop_table_clause */ - case 294: /* column_def */ - case 298: /* duration_literal */ - case 299: /* rollup_func_name */ - case 301: /* col_name */ - case 302: /* db_name_cond_opt */ - case 303: /* like_pattern_opt */ - case 304: /* table_name_cond */ - case 305: /* from_db_opt */ - case 307: /* index_options */ - case 309: /* sliding_opt */ - case 310: /* sma_stream_opt */ - case 311: /* func */ - case 312: /* stream_options */ - case 314: /* query_expression */ - case 317: /* explain_options */ - case 321: /* into_opt */ - case 323: /* where_clause_opt */ - case 324: /* signed */ - case 325: /* literal_func */ - case 329: /* expression */ - case 330: /* pseudo_column */ - case 331: /* column_reference */ - case 332: /* function_expression */ - case 333: /* subquery */ - case 338: /* star_func_para */ - case 339: /* predicate */ - case 342: /* in_predicate_value */ - case 343: /* boolean_value_expression */ - case 344: /* boolean_primary */ - case 345: /* common_expression */ - case 346: /* from_clause_opt */ - case 347: /* table_reference_list */ - case 348: /* table_reference */ - case 349: /* table_primary */ - case 350: /* joined_table */ - case 352: /* parenthesized_joined_table */ - case 354: /* search_condition */ - case 355: /* query_specification */ - case 359: /* range_opt */ - case 360: /* every_opt */ - case 361: /* fill_opt */ - case 362: /* twindow_clause_opt */ - case 364: /* having_clause_opt */ - case 365: /* select_item */ - case 368: /* query_expression_body */ - case 370: /* slimit_clause_opt */ - case 371: /* limit_clause_opt */ - case 372: /* query_primary */ - case 374: /* sort_specification */ + case 255: /* cmd */ + case 258: /* literal */ + case 269: /* db_options */ + case 271: /* alter_db_options */ + case 276: /* retention */ + case 277: /* full_table_name */ + case 280: /* table_options */ + case 284: /* alter_table_clause */ + case 285: /* alter_table_options */ + case 288: /* signed_literal */ + case 289: /* create_subtable_clause */ + case 292: /* drop_table_clause */ + case 295: /* column_def */ + case 299: /* duration_literal */ + case 300: /* rollup_func_name */ + case 302: /* col_name */ + case 303: /* db_name_cond_opt */ + case 304: /* like_pattern_opt */ + case 305: /* table_name_cond */ + case 306: /* from_db_opt */ + case 308: /* index_options */ + case 310: /* sliding_opt */ + case 311: /* sma_stream_opt */ + case 312: /* func */ + case 313: /* stream_options */ + case 315: /* query_expression */ + case 318: /* explain_options */ + case 322: /* into_opt */ + case 324: /* where_clause_opt */ + case 325: /* signed */ + case 326: /* literal_func */ + case 330: /* expression */ + case 331: /* pseudo_column */ + case 332: /* column_reference */ + case 333: /* function_expression */ + case 334: /* subquery */ + case 339: /* star_func_para */ + case 340: /* predicate */ + case 343: /* in_predicate_value */ + case 344: /* boolean_value_expression */ + case 345: /* boolean_primary */ + case 346: /* common_expression */ + case 347: /* from_clause_opt */ + case 348: /* table_reference_list */ + case 349: /* table_reference */ + case 350: /* table_primary */ + case 351: /* joined_table */ + case 353: /* parenthesized_joined_table */ + case 355: /* search_condition */ + case 356: /* query_specification */ + case 360: /* range_opt */ + case 361: /* every_opt */ + case 362: /* fill_opt */ + case 363: /* twindow_clause_opt */ + case 365: /* having_clause_opt */ + case 366: /* select_item */ + case 369: /* query_expression_body */ + case 371: /* slimit_clause_opt */ + case 372: /* limit_clause_opt */ + case 373: /* query_primary */ + case 375: /* sort_specification */ { - nodesDestroyNode((yypminor->yy652)); + nodesDestroyNode((yypminor->yy560)); } break; - case 255: /* account_options */ - case 256: /* alter_account_options */ - case 258: /* alter_account_option */ - case 319: /* bufsize_opt */ + case 256: /* account_options */ + case 257: /* alter_account_options */ + case 259: /* alter_account_option */ + case 320: /* bufsize_opt */ { } break; - case 259: /* user_name */ - case 262: /* priv_level */ - case 265: /* db_name */ - case 266: /* dnode_endpoint */ - case 285: /* column_name */ - case 293: /* table_name */ - case 300: /* function_name */ - case 306: /* index_name */ - case 313: /* topic_name */ - case 315: /* cgroup_name */ - case 320: /* stream_name */ - case 327: /* table_alias */ - case 328: /* column_alias */ - case 334: /* star_func */ - case 336: /* noarg_func */ - case 351: /* alias_opt */ + case 260: /* user_name */ + case 263: /* priv_level */ + case 266: /* db_name */ + case 267: /* dnode_endpoint */ + case 286: /* column_name */ + case 294: /* table_name */ + case 301: /* function_name */ + case 307: /* index_name */ + case 314: /* topic_name */ + case 316: /* cgroup_name */ + case 321: /* stream_name */ + case 328: /* table_alias */ + case 329: /* column_alias */ + case 335: /* star_func */ + case 337: /* noarg_func */ + case 352: /* alias_opt */ { } break; - case 260: /* sysinfo_opt */ + case 261: /* sysinfo_opt */ { } break; - case 261: /* privileges */ - case 263: /* priv_type_list */ - case 264: /* priv_type */ + case 262: /* privileges */ + case 264: /* priv_type_list */ + case 265: /* priv_type */ { } break; - case 267: /* not_exists_opt */ - case 269: /* exists_opt */ - case 316: /* analyze_opt */ - case 318: /* agg_func_opt */ - case 356: /* set_quantifier_opt */ + case 268: /* not_exists_opt */ + case 270: /* exists_opt */ + case 317: /* analyze_opt */ + case 319: /* agg_func_opt */ + case 357: /* set_quantifier_opt */ { } break; - case 271: /* integer_list */ - case 272: /* variable_list */ - case 273: /* retention_list */ - case 277: /* column_def_list */ - case 278: /* tags_def_opt */ - case 280: /* multi_create_clause */ - case 281: /* tags_def */ - case 282: /* multi_drop_clause */ - case 289: /* specific_cols_opt */ - case 290: /* expression_list */ - case 292: /* col_name_list */ - case 295: /* duration_list */ - case 296: /* rollup_func_list */ - case 308: /* func_list */ - case 322: /* dnode_list */ - case 326: /* literal_list */ - case 335: /* star_func_para_list */ - case 337: /* other_para_list */ - case 357: /* select_list */ - case 358: /* partition_by_clause_opt */ - case 363: /* group_by_clause_opt */ - case 367: /* group_by_list */ - case 369: /* order_by_clause_opt */ - case 373: /* sort_specification_list */ + case 272: /* integer_list */ + case 273: /* variable_list */ + case 274: /* retention_list */ + case 278: /* column_def_list */ + case 279: /* tags_def_opt */ + case 281: /* multi_create_clause */ + case 282: /* tags_def */ + case 283: /* multi_drop_clause */ + case 290: /* specific_cols_opt */ + case 291: /* expression_list */ + case 293: /* col_name_list */ + case 296: /* duration_list */ + case 297: /* rollup_func_list */ + case 309: /* func_list */ + case 323: /* dnode_list */ + case 327: /* literal_list */ + case 336: /* star_func_para_list */ + case 338: /* other_para_list */ + case 358: /* select_list */ + case 359: /* partition_by_clause_opt */ + case 364: /* group_by_clause_opt */ + case 368: /* group_by_list */ + case 370: /* order_by_clause_opt */ + case 374: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy210)); + nodesDestroyList((yypminor->yy712)); } break; - case 274: /* alter_db_option */ - case 297: /* alter_table_option */ + case 275: /* alter_db_option */ + case 298: /* alter_table_option */ { } break; - case 286: /* type_name */ + case 287: /* type_name */ { } break; - case 340: /* compare_op */ - case 341: /* in_op */ + case 341: /* compare_op */ + case 342: /* in_op */ { } break; - case 353: /* join_type */ + case 354: /* join_type */ { } break; - case 366: /* fill_mode */ + case 367: /* fill_mode */ { } break; - case 375: /* ordering_specification_opt */ + case 376: /* ordering_specification_opt */ { } break; - case 376: /* null_ordering_opt */ + case 377: /* null_ordering_opt */ { } @@ -2696,493 +2731,494 @@ 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[] = { - { 254, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 254, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 255, 0 }, /* (2) account_options ::= */ - { 255, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 255, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 255, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 255, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 255, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 255, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 255, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 255, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 255, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 256, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 256, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 258, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 258, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 258, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 258, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 258, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 258, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 258, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 258, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 258, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 258, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 254, -6 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ - { 254, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 254, -5 }, /* (26) cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ - { 254, -5 }, /* (27) cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ - { 254, -3 }, /* (28) cmd ::= DROP USER user_name */ - { 260, 0 }, /* (29) sysinfo_opt ::= */ - { 260, -2 }, /* (30) sysinfo_opt ::= SYSINFO NK_INTEGER */ - { 254, -6 }, /* (31) cmd ::= GRANT privileges ON priv_level TO user_name */ - { 254, -6 }, /* (32) cmd ::= REVOKE privileges ON priv_level FROM user_name */ - { 261, -1 }, /* (33) privileges ::= ALL */ - { 261, -1 }, /* (34) privileges ::= priv_type_list */ - { 263, -1 }, /* (35) priv_type_list ::= priv_type */ - { 263, -3 }, /* (36) priv_type_list ::= priv_type_list NK_COMMA priv_type */ - { 264, -1 }, /* (37) priv_type ::= READ */ - { 264, -1 }, /* (38) priv_type ::= WRITE */ - { 262, -3 }, /* (39) priv_level ::= NK_STAR NK_DOT NK_STAR */ - { 262, -3 }, /* (40) priv_level ::= db_name NK_DOT NK_STAR */ - { 254, -3 }, /* (41) cmd ::= CREATE DNODE dnode_endpoint */ - { 254, -5 }, /* (42) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ - { 254, -3 }, /* (43) cmd ::= DROP DNODE NK_INTEGER */ - { 254, -3 }, /* (44) cmd ::= DROP DNODE dnode_endpoint */ - { 254, -4 }, /* (45) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 254, -5 }, /* (46) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 254, -4 }, /* (47) cmd ::= ALTER ALL DNODES NK_STRING */ - { 254, -5 }, /* (48) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 266, -1 }, /* (49) dnode_endpoint ::= NK_STRING */ - { 266, -1 }, /* (50) dnode_endpoint ::= NK_ID */ - { 266, -1 }, /* (51) dnode_endpoint ::= NK_IPTOKEN */ - { 254, -3 }, /* (52) cmd ::= ALTER LOCAL NK_STRING */ - { 254, -4 }, /* (53) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 254, -5 }, /* (54) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 254, -5 }, /* (55) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 254, -5 }, /* (56) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ - { 254, -5 }, /* (57) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ - { 254, -5 }, /* (58) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ - { 254, -5 }, /* (59) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ - { 254, -5 }, /* (60) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ - { 254, -5 }, /* (61) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ - { 254, -5 }, /* (62) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 254, -4 }, /* (63) cmd ::= DROP DATABASE exists_opt db_name */ - { 254, -2 }, /* (64) cmd ::= USE db_name */ - { 254, -4 }, /* (65) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 254, -3 }, /* (66) cmd ::= FLUSH DATABASE db_name */ - { 267, -3 }, /* (67) not_exists_opt ::= IF NOT EXISTS */ - { 267, 0 }, /* (68) not_exists_opt ::= */ - { 269, -2 }, /* (69) exists_opt ::= IF EXISTS */ - { 269, 0 }, /* (70) exists_opt ::= */ - { 268, 0 }, /* (71) db_options ::= */ - { 268, -3 }, /* (72) db_options ::= db_options BUFFER NK_INTEGER */ - { 268, -3 }, /* (73) db_options ::= db_options CACHELAST NK_INTEGER */ - { 268, -3 }, /* (74) db_options ::= db_options CACHELASTSIZE NK_INTEGER */ - { 268, -3 }, /* (75) db_options ::= db_options COMP NK_INTEGER */ - { 268, -3 }, /* (76) db_options ::= db_options DURATION NK_INTEGER */ - { 268, -3 }, /* (77) db_options ::= db_options DURATION NK_VARIABLE */ - { 268, -3 }, /* (78) db_options ::= db_options FSYNC NK_INTEGER */ - { 268, -3 }, /* (79) db_options ::= db_options MAXROWS NK_INTEGER */ - { 268, -3 }, /* (80) db_options ::= db_options MINROWS NK_INTEGER */ - { 268, -3 }, /* (81) db_options ::= db_options KEEP integer_list */ - { 268, -3 }, /* (82) db_options ::= db_options KEEP variable_list */ - { 268, -3 }, /* (83) db_options ::= db_options PAGES NK_INTEGER */ - { 268, -3 }, /* (84) db_options ::= db_options PAGESIZE NK_INTEGER */ - { 268, -3 }, /* (85) db_options ::= db_options PRECISION NK_STRING */ - { 268, -3 }, /* (86) db_options ::= db_options REPLICA NK_INTEGER */ - { 268, -3 }, /* (87) db_options ::= db_options STRICT NK_INTEGER */ - { 268, -3 }, /* (88) db_options ::= db_options WAL NK_INTEGER */ - { 268, -3 }, /* (89) db_options ::= db_options VGROUPS NK_INTEGER */ - { 268, -3 }, /* (90) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 268, -3 }, /* (91) db_options ::= db_options RETENTIONS retention_list */ - { 268, -3 }, /* (92) db_options ::= db_options SCHEMALESS NK_INTEGER */ - { 270, -1 }, /* (93) alter_db_options ::= alter_db_option */ - { 270, -2 }, /* (94) alter_db_options ::= alter_db_options alter_db_option */ - { 274, -2 }, /* (95) alter_db_option ::= BUFFER NK_INTEGER */ - { 274, -2 }, /* (96) alter_db_option ::= CACHELAST NK_INTEGER */ - { 274, -2 }, /* (97) alter_db_option ::= CACHELASTSIZE NK_INTEGER */ - { 274, -2 }, /* (98) alter_db_option ::= FSYNC NK_INTEGER */ - { 274, -2 }, /* (99) alter_db_option ::= KEEP integer_list */ - { 274, -2 }, /* (100) alter_db_option ::= KEEP variable_list */ - { 274, -2 }, /* (101) alter_db_option ::= PAGES NK_INTEGER */ - { 274, -2 }, /* (102) alter_db_option ::= REPLICA NK_INTEGER */ - { 274, -2 }, /* (103) alter_db_option ::= STRICT NK_INTEGER */ - { 274, -2 }, /* (104) alter_db_option ::= WAL NK_INTEGER */ - { 271, -1 }, /* (105) integer_list ::= NK_INTEGER */ - { 271, -3 }, /* (106) integer_list ::= integer_list NK_COMMA NK_INTEGER */ - { 272, -1 }, /* (107) variable_list ::= NK_VARIABLE */ - { 272, -3 }, /* (108) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ - { 273, -1 }, /* (109) retention_list ::= retention */ - { 273, -3 }, /* (110) retention_list ::= retention_list NK_COMMA retention */ - { 275, -3 }, /* (111) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ - { 254, -9 }, /* (112) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 254, -3 }, /* (113) cmd ::= CREATE TABLE multi_create_clause */ - { 254, -9 }, /* (114) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 254, -3 }, /* (115) cmd ::= DROP TABLE multi_drop_clause */ - { 254, -4 }, /* (116) cmd ::= DROP STABLE exists_opt full_table_name */ - { 254, -3 }, /* (117) cmd ::= ALTER TABLE alter_table_clause */ - { 254, -3 }, /* (118) cmd ::= ALTER STABLE alter_table_clause */ - { 283, -2 }, /* (119) alter_table_clause ::= full_table_name alter_table_options */ - { 283, -5 }, /* (120) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 283, -4 }, /* (121) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 283, -5 }, /* (122) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 283, -5 }, /* (123) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 283, -5 }, /* (124) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 283, -4 }, /* (125) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 283, -5 }, /* (126) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 283, -5 }, /* (127) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 283, -6 }, /* (128) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ - { 280, -1 }, /* (129) multi_create_clause ::= create_subtable_clause */ - { 280, -2 }, /* (130) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 288, -10 }, /* (131) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ - { 282, -1 }, /* (132) multi_drop_clause ::= drop_table_clause */ - { 282, -2 }, /* (133) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 291, -2 }, /* (134) drop_table_clause ::= exists_opt full_table_name */ - { 289, 0 }, /* (135) specific_cols_opt ::= */ - { 289, -3 }, /* (136) specific_cols_opt ::= NK_LP col_name_list NK_RP */ - { 276, -1 }, /* (137) full_table_name ::= table_name */ - { 276, -3 }, /* (138) full_table_name ::= db_name NK_DOT table_name */ - { 277, -1 }, /* (139) column_def_list ::= column_def */ - { 277, -3 }, /* (140) column_def_list ::= column_def_list NK_COMMA column_def */ - { 294, -2 }, /* (141) column_def ::= column_name type_name */ - { 294, -4 }, /* (142) column_def ::= column_name type_name COMMENT NK_STRING */ - { 286, -1 }, /* (143) type_name ::= BOOL */ - { 286, -1 }, /* (144) type_name ::= TINYINT */ - { 286, -1 }, /* (145) type_name ::= SMALLINT */ - { 286, -1 }, /* (146) type_name ::= INT */ - { 286, -1 }, /* (147) type_name ::= INTEGER */ - { 286, -1 }, /* (148) type_name ::= BIGINT */ - { 286, -1 }, /* (149) type_name ::= FLOAT */ - { 286, -1 }, /* (150) type_name ::= DOUBLE */ - { 286, -4 }, /* (151) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 286, -1 }, /* (152) type_name ::= TIMESTAMP */ - { 286, -4 }, /* (153) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 286, -2 }, /* (154) type_name ::= TINYINT UNSIGNED */ - { 286, -2 }, /* (155) type_name ::= SMALLINT UNSIGNED */ - { 286, -2 }, /* (156) type_name ::= INT UNSIGNED */ - { 286, -2 }, /* (157) type_name ::= BIGINT UNSIGNED */ - { 286, -1 }, /* (158) type_name ::= JSON */ - { 286, -4 }, /* (159) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 286, -1 }, /* (160) type_name ::= MEDIUMBLOB */ - { 286, -1 }, /* (161) type_name ::= BLOB */ - { 286, -4 }, /* (162) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 286, -1 }, /* (163) type_name ::= DECIMAL */ - { 286, -4 }, /* (164) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 286, -6 }, /* (165) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 278, 0 }, /* (166) tags_def_opt ::= */ - { 278, -1 }, /* (167) tags_def_opt ::= tags_def */ - { 281, -4 }, /* (168) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 279, 0 }, /* (169) table_options ::= */ - { 279, -3 }, /* (170) table_options ::= table_options COMMENT NK_STRING */ - { 279, -3 }, /* (171) table_options ::= table_options MAX_DELAY duration_list */ - { 279, -3 }, /* (172) table_options ::= table_options WATERMARK duration_list */ - { 279, -5 }, /* (173) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ - { 279, -3 }, /* (174) table_options ::= table_options TTL NK_INTEGER */ - { 279, -5 }, /* (175) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 284, -1 }, /* (176) alter_table_options ::= alter_table_option */ - { 284, -2 }, /* (177) alter_table_options ::= alter_table_options alter_table_option */ - { 297, -2 }, /* (178) alter_table_option ::= COMMENT NK_STRING */ - { 297, -2 }, /* (179) alter_table_option ::= TTL NK_INTEGER */ - { 295, -1 }, /* (180) duration_list ::= duration_literal */ - { 295, -3 }, /* (181) duration_list ::= duration_list NK_COMMA duration_literal */ - { 296, -1 }, /* (182) rollup_func_list ::= rollup_func_name */ - { 296, -3 }, /* (183) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ - { 299, -1 }, /* (184) rollup_func_name ::= function_name */ - { 299, -1 }, /* (185) rollup_func_name ::= FIRST */ - { 299, -1 }, /* (186) rollup_func_name ::= LAST */ - { 292, -1 }, /* (187) col_name_list ::= col_name */ - { 292, -3 }, /* (188) col_name_list ::= col_name_list NK_COMMA col_name */ - { 301, -1 }, /* (189) col_name ::= column_name */ - { 254, -2 }, /* (190) cmd ::= SHOW DNODES */ - { 254, -2 }, /* (191) cmd ::= SHOW USERS */ - { 254, -2 }, /* (192) cmd ::= SHOW DATABASES */ - { 254, -4 }, /* (193) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 254, -4 }, /* (194) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 254, -3 }, /* (195) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 254, -2 }, /* (196) cmd ::= SHOW MNODES */ - { 254, -2 }, /* (197) cmd ::= SHOW MODULES */ - { 254, -2 }, /* (198) cmd ::= SHOW QNODES */ - { 254, -2 }, /* (199) cmd ::= SHOW FUNCTIONS */ - { 254, -5 }, /* (200) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 254, -2 }, /* (201) cmd ::= SHOW STREAMS */ - { 254, -2 }, /* (202) cmd ::= SHOW ACCOUNTS */ - { 254, -2 }, /* (203) cmd ::= SHOW APPS */ - { 254, -2 }, /* (204) cmd ::= SHOW CONNECTIONS */ - { 254, -2 }, /* (205) cmd ::= SHOW LICENCE */ - { 254, -2 }, /* (206) cmd ::= SHOW GRANTS */ - { 254, -4 }, /* (207) cmd ::= SHOW CREATE DATABASE db_name */ - { 254, -4 }, /* (208) cmd ::= SHOW CREATE TABLE full_table_name */ - { 254, -4 }, /* (209) cmd ::= SHOW CREATE STABLE full_table_name */ - { 254, -2 }, /* (210) cmd ::= SHOW QUERIES */ - { 254, -2 }, /* (211) cmd ::= SHOW SCORES */ - { 254, -2 }, /* (212) cmd ::= SHOW TOPICS */ - { 254, -2 }, /* (213) cmd ::= SHOW VARIABLES */ - { 254, -3 }, /* (214) cmd ::= SHOW LOCAL VARIABLES */ - { 254, -4 }, /* (215) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ - { 254, -2 }, /* (216) cmd ::= SHOW BNODES */ - { 254, -2 }, /* (217) cmd ::= SHOW SNODES */ - { 254, -2 }, /* (218) cmd ::= SHOW CLUSTER */ - { 254, -2 }, /* (219) cmd ::= SHOW TRANSACTIONS */ - { 254, -4 }, /* (220) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ - { 254, -2 }, /* (221) cmd ::= SHOW CONSUMERS */ - { 254, -2 }, /* (222) cmd ::= SHOW SUBSCRIPTIONS */ - { 302, 0 }, /* (223) db_name_cond_opt ::= */ - { 302, -2 }, /* (224) db_name_cond_opt ::= db_name NK_DOT */ - { 303, 0 }, /* (225) like_pattern_opt ::= */ - { 303, -2 }, /* (226) like_pattern_opt ::= LIKE NK_STRING */ - { 304, -1 }, /* (227) table_name_cond ::= table_name */ - { 305, 0 }, /* (228) from_db_opt ::= */ - { 305, -2 }, /* (229) from_db_opt ::= FROM db_name */ - { 254, -8 }, /* (230) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 254, -4 }, /* (231) cmd ::= DROP INDEX exists_opt index_name */ - { 307, -10 }, /* (232) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ - { 307, -12 }, /* (233) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ - { 308, -1 }, /* (234) func_list ::= func */ - { 308, -3 }, /* (235) func_list ::= func_list NK_COMMA func */ - { 311, -4 }, /* (236) func ::= function_name NK_LP expression_list NK_RP */ - { 310, 0 }, /* (237) sma_stream_opt ::= */ - { 310, -3 }, /* (238) sma_stream_opt ::= stream_options WATERMARK duration_literal */ - { 310, -3 }, /* (239) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ - { 254, -6 }, /* (240) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 254, -7 }, /* (241) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ - { 254, -9 }, /* (242) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ - { 254, -7 }, /* (243) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ - { 254, -9 }, /* (244) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ - { 254, -4 }, /* (245) cmd ::= DROP TOPIC exists_opt topic_name */ - { 254, -7 }, /* (246) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ - { 254, -2 }, /* (247) cmd ::= DESC full_table_name */ - { 254, -2 }, /* (248) cmd ::= DESCRIBE full_table_name */ - { 254, -3 }, /* (249) cmd ::= RESET QUERY CACHE */ - { 254, -4 }, /* (250) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ - { 316, 0 }, /* (251) analyze_opt ::= */ - { 316, -1 }, /* (252) analyze_opt ::= ANALYZE */ - { 317, 0 }, /* (253) explain_options ::= */ - { 317, -3 }, /* (254) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 317, -3 }, /* (255) explain_options ::= explain_options RATIO NK_FLOAT */ - { 254, -6 }, /* (256) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ - { 254, -10 }, /* (257) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ - { 254, -4 }, /* (258) cmd ::= DROP FUNCTION exists_opt function_name */ - { 318, 0 }, /* (259) agg_func_opt ::= */ - { 318, -1 }, /* (260) agg_func_opt ::= AGGREGATE */ - { 319, 0 }, /* (261) bufsize_opt ::= */ - { 319, -2 }, /* (262) bufsize_opt ::= BUFSIZE NK_INTEGER */ - { 254, -8 }, /* (263) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ - { 254, -4 }, /* (264) cmd ::= DROP STREAM exists_opt stream_name */ - { 321, 0 }, /* (265) into_opt ::= */ - { 321, -2 }, /* (266) into_opt ::= INTO full_table_name */ - { 312, 0 }, /* (267) stream_options ::= */ - { 312, -3 }, /* (268) stream_options ::= stream_options TRIGGER AT_ONCE */ - { 312, -3 }, /* (269) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ - { 312, -4 }, /* (270) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ - { 312, -3 }, /* (271) stream_options ::= stream_options WATERMARK duration_literal */ - { 312, -3 }, /* (272) stream_options ::= stream_options IGNORE EXPIRED */ - { 254, -3 }, /* (273) cmd ::= KILL CONNECTION NK_INTEGER */ - { 254, -3 }, /* (274) cmd ::= KILL QUERY NK_STRING */ - { 254, -3 }, /* (275) cmd ::= KILL TRANSACTION NK_INTEGER */ - { 254, -2 }, /* (276) cmd ::= BALANCE VGROUP */ - { 254, -4 }, /* (277) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 254, -4 }, /* (278) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 254, -3 }, /* (279) cmd ::= SPLIT VGROUP NK_INTEGER */ - { 322, -2 }, /* (280) dnode_list ::= DNODE NK_INTEGER */ - { 322, -3 }, /* (281) dnode_list ::= dnode_list DNODE NK_INTEGER */ - { 254, -3 }, /* (282) cmd ::= SYNCDB db_name REPLICA */ - { 254, -4 }, /* (283) cmd ::= DELETE FROM full_table_name where_clause_opt */ - { 254, -1 }, /* (284) cmd ::= query_expression */ - { 254, -5 }, /* (285) cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression */ - { 257, -1 }, /* (286) literal ::= NK_INTEGER */ - { 257, -1 }, /* (287) literal ::= NK_FLOAT */ - { 257, -1 }, /* (288) literal ::= NK_STRING */ - { 257, -1 }, /* (289) literal ::= NK_BOOL */ - { 257, -2 }, /* (290) literal ::= TIMESTAMP NK_STRING */ - { 257, -1 }, /* (291) literal ::= duration_literal */ - { 257, -1 }, /* (292) literal ::= NULL */ - { 257, -1 }, /* (293) literal ::= NK_QUESTION */ - { 298, -1 }, /* (294) duration_literal ::= NK_VARIABLE */ - { 324, -1 }, /* (295) signed ::= NK_INTEGER */ - { 324, -2 }, /* (296) signed ::= NK_PLUS NK_INTEGER */ - { 324, -2 }, /* (297) signed ::= NK_MINUS NK_INTEGER */ - { 324, -1 }, /* (298) signed ::= NK_FLOAT */ - { 324, -2 }, /* (299) signed ::= NK_PLUS NK_FLOAT */ - { 324, -2 }, /* (300) signed ::= NK_MINUS NK_FLOAT */ - { 287, -1 }, /* (301) signed_literal ::= signed */ - { 287, -1 }, /* (302) signed_literal ::= NK_STRING */ - { 287, -1 }, /* (303) signed_literal ::= NK_BOOL */ - { 287, -2 }, /* (304) signed_literal ::= TIMESTAMP NK_STRING */ - { 287, -1 }, /* (305) signed_literal ::= duration_literal */ - { 287, -1 }, /* (306) signed_literal ::= NULL */ - { 287, -1 }, /* (307) signed_literal ::= literal_func */ - { 326, -1 }, /* (308) literal_list ::= signed_literal */ - { 326, -3 }, /* (309) literal_list ::= literal_list NK_COMMA signed_literal */ - { 265, -1 }, /* (310) db_name ::= NK_ID */ - { 293, -1 }, /* (311) table_name ::= NK_ID */ - { 285, -1 }, /* (312) column_name ::= NK_ID */ - { 300, -1 }, /* (313) function_name ::= NK_ID */ - { 327, -1 }, /* (314) table_alias ::= NK_ID */ - { 328, -1 }, /* (315) column_alias ::= NK_ID */ - { 259, -1 }, /* (316) user_name ::= NK_ID */ - { 306, -1 }, /* (317) index_name ::= NK_ID */ - { 313, -1 }, /* (318) topic_name ::= NK_ID */ - { 320, -1 }, /* (319) stream_name ::= NK_ID */ - { 315, -1 }, /* (320) cgroup_name ::= NK_ID */ - { 329, -1 }, /* (321) expression ::= literal */ - { 329, -1 }, /* (322) expression ::= pseudo_column */ - { 329, -1 }, /* (323) expression ::= column_reference */ - { 329, -1 }, /* (324) expression ::= function_expression */ - { 329, -1 }, /* (325) expression ::= subquery */ - { 329, -3 }, /* (326) expression ::= NK_LP expression NK_RP */ - { 329, -2 }, /* (327) expression ::= NK_PLUS expression */ - { 329, -2 }, /* (328) expression ::= NK_MINUS expression */ - { 329, -3 }, /* (329) expression ::= expression NK_PLUS expression */ - { 329, -3 }, /* (330) expression ::= expression NK_MINUS expression */ - { 329, -3 }, /* (331) expression ::= expression NK_STAR expression */ - { 329, -3 }, /* (332) expression ::= expression NK_SLASH expression */ - { 329, -3 }, /* (333) expression ::= expression NK_REM expression */ - { 329, -3 }, /* (334) expression ::= column_reference NK_ARROW NK_STRING */ - { 329, -3 }, /* (335) expression ::= expression NK_BITAND expression */ - { 329, -3 }, /* (336) expression ::= expression NK_BITOR expression */ - { 290, -1 }, /* (337) expression_list ::= expression */ - { 290, -3 }, /* (338) expression_list ::= expression_list NK_COMMA expression */ - { 331, -1 }, /* (339) column_reference ::= column_name */ - { 331, -3 }, /* (340) column_reference ::= table_name NK_DOT column_name */ - { 330, -1 }, /* (341) pseudo_column ::= ROWTS */ - { 330, -1 }, /* (342) pseudo_column ::= TBNAME */ - { 330, -3 }, /* (343) pseudo_column ::= table_name NK_DOT TBNAME */ - { 330, -1 }, /* (344) pseudo_column ::= QSTARTTS */ - { 330, -1 }, /* (345) pseudo_column ::= QENDTS */ - { 330, -1 }, /* (346) pseudo_column ::= WSTARTTS */ - { 330, -1 }, /* (347) pseudo_column ::= WENDTS */ - { 330, -1 }, /* (348) pseudo_column ::= WDURATION */ - { 332, -4 }, /* (349) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 332, -4 }, /* (350) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 332, -6 }, /* (351) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 332, -1 }, /* (352) function_expression ::= literal_func */ - { 325, -3 }, /* (353) literal_func ::= noarg_func NK_LP NK_RP */ - { 325, -1 }, /* (354) literal_func ::= NOW */ - { 336, -1 }, /* (355) noarg_func ::= NOW */ - { 336, -1 }, /* (356) noarg_func ::= TODAY */ - { 336, -1 }, /* (357) noarg_func ::= TIMEZONE */ - { 336, -1 }, /* (358) noarg_func ::= DATABASE */ - { 336, -1 }, /* (359) noarg_func ::= CLIENT_VERSION */ - { 336, -1 }, /* (360) noarg_func ::= SERVER_VERSION */ - { 336, -1 }, /* (361) noarg_func ::= SERVER_STATUS */ - { 336, -1 }, /* (362) noarg_func ::= CURRENT_USER */ - { 336, -1 }, /* (363) noarg_func ::= USER */ - { 334, -1 }, /* (364) star_func ::= COUNT */ - { 334, -1 }, /* (365) star_func ::= FIRST */ - { 334, -1 }, /* (366) star_func ::= LAST */ - { 334, -1 }, /* (367) star_func ::= LAST_ROW */ - { 335, -1 }, /* (368) star_func_para_list ::= NK_STAR */ - { 335, -1 }, /* (369) star_func_para_list ::= other_para_list */ - { 337, -1 }, /* (370) other_para_list ::= star_func_para */ - { 337, -3 }, /* (371) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 338, -1 }, /* (372) star_func_para ::= expression */ - { 338, -3 }, /* (373) star_func_para ::= table_name NK_DOT NK_STAR */ - { 339, -3 }, /* (374) predicate ::= expression compare_op expression */ - { 339, -5 }, /* (375) predicate ::= expression BETWEEN expression AND expression */ - { 339, -6 }, /* (376) predicate ::= expression NOT BETWEEN expression AND expression */ - { 339, -3 }, /* (377) predicate ::= expression IS NULL */ - { 339, -4 }, /* (378) predicate ::= expression IS NOT NULL */ - { 339, -3 }, /* (379) predicate ::= expression in_op in_predicate_value */ - { 340, -1 }, /* (380) compare_op ::= NK_LT */ - { 340, -1 }, /* (381) compare_op ::= NK_GT */ - { 340, -1 }, /* (382) compare_op ::= NK_LE */ - { 340, -1 }, /* (383) compare_op ::= NK_GE */ - { 340, -1 }, /* (384) compare_op ::= NK_NE */ - { 340, -1 }, /* (385) compare_op ::= NK_EQ */ - { 340, -1 }, /* (386) compare_op ::= LIKE */ - { 340, -2 }, /* (387) compare_op ::= NOT LIKE */ - { 340, -1 }, /* (388) compare_op ::= MATCH */ - { 340, -1 }, /* (389) compare_op ::= NMATCH */ - { 340, -1 }, /* (390) compare_op ::= CONTAINS */ - { 341, -1 }, /* (391) in_op ::= IN */ - { 341, -2 }, /* (392) in_op ::= NOT IN */ - { 342, -3 }, /* (393) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 343, -1 }, /* (394) boolean_value_expression ::= boolean_primary */ - { 343, -2 }, /* (395) boolean_value_expression ::= NOT boolean_primary */ - { 343, -3 }, /* (396) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 343, -3 }, /* (397) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 344, -1 }, /* (398) boolean_primary ::= predicate */ - { 344, -3 }, /* (399) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 345, -1 }, /* (400) common_expression ::= expression */ - { 345, -1 }, /* (401) common_expression ::= boolean_value_expression */ - { 346, 0 }, /* (402) from_clause_opt ::= */ - { 346, -2 }, /* (403) from_clause_opt ::= FROM table_reference_list */ - { 347, -1 }, /* (404) table_reference_list ::= table_reference */ - { 347, -3 }, /* (405) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 348, -1 }, /* (406) table_reference ::= table_primary */ - { 348, -1 }, /* (407) table_reference ::= joined_table */ - { 349, -2 }, /* (408) table_primary ::= table_name alias_opt */ - { 349, -4 }, /* (409) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 349, -2 }, /* (410) table_primary ::= subquery alias_opt */ - { 349, -1 }, /* (411) table_primary ::= parenthesized_joined_table */ - { 351, 0 }, /* (412) alias_opt ::= */ - { 351, -1 }, /* (413) alias_opt ::= table_alias */ - { 351, -2 }, /* (414) alias_opt ::= AS table_alias */ - { 352, -3 }, /* (415) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 352, -3 }, /* (416) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 350, -6 }, /* (417) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 353, 0 }, /* (418) join_type ::= */ - { 353, -1 }, /* (419) join_type ::= INNER */ - { 355, -12 }, /* (420) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 356, 0 }, /* (421) set_quantifier_opt ::= */ - { 356, -1 }, /* (422) set_quantifier_opt ::= DISTINCT */ - { 356, -1 }, /* (423) set_quantifier_opt ::= ALL */ - { 357, -1 }, /* (424) select_list ::= select_item */ - { 357, -3 }, /* (425) select_list ::= select_list NK_COMMA select_item */ - { 365, -1 }, /* (426) select_item ::= NK_STAR */ - { 365, -1 }, /* (427) select_item ::= common_expression */ - { 365, -2 }, /* (428) select_item ::= common_expression column_alias */ - { 365, -3 }, /* (429) select_item ::= common_expression AS column_alias */ - { 365, -3 }, /* (430) select_item ::= table_name NK_DOT NK_STAR */ - { 323, 0 }, /* (431) where_clause_opt ::= */ - { 323, -2 }, /* (432) where_clause_opt ::= WHERE search_condition */ - { 358, 0 }, /* (433) partition_by_clause_opt ::= */ - { 358, -3 }, /* (434) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 362, 0 }, /* (435) twindow_clause_opt ::= */ - { 362, -6 }, /* (436) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 362, -4 }, /* (437) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 362, -6 }, /* (438) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 362, -8 }, /* (439) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 309, 0 }, /* (440) sliding_opt ::= */ - { 309, -4 }, /* (441) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 361, 0 }, /* (442) fill_opt ::= */ - { 361, -4 }, /* (443) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 361, -6 }, /* (444) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 366, -1 }, /* (445) fill_mode ::= NONE */ - { 366, -1 }, /* (446) fill_mode ::= PREV */ - { 366, -1 }, /* (447) fill_mode ::= NULL */ - { 366, -1 }, /* (448) fill_mode ::= LINEAR */ - { 366, -1 }, /* (449) fill_mode ::= NEXT */ - { 363, 0 }, /* (450) group_by_clause_opt ::= */ - { 363, -3 }, /* (451) group_by_clause_opt ::= GROUP BY group_by_list */ - { 367, -1 }, /* (452) group_by_list ::= expression */ - { 367, -3 }, /* (453) group_by_list ::= group_by_list NK_COMMA expression */ - { 364, 0 }, /* (454) having_clause_opt ::= */ - { 364, -2 }, /* (455) having_clause_opt ::= HAVING search_condition */ - { 359, 0 }, /* (456) range_opt ::= */ - { 359, -6 }, /* (457) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ - { 360, 0 }, /* (458) every_opt ::= */ - { 360, -4 }, /* (459) every_opt ::= EVERY NK_LP duration_literal NK_RP */ - { 314, -4 }, /* (460) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 368, -1 }, /* (461) query_expression_body ::= query_primary */ - { 368, -4 }, /* (462) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 368, -3 }, /* (463) query_expression_body ::= query_expression_body UNION query_expression_body */ - { 372, -1 }, /* (464) query_primary ::= query_specification */ - { 372, -6 }, /* (465) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ - { 369, 0 }, /* (466) order_by_clause_opt ::= */ - { 369, -3 }, /* (467) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 370, 0 }, /* (468) slimit_clause_opt ::= */ - { 370, -2 }, /* (469) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 370, -4 }, /* (470) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 370, -4 }, /* (471) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 371, 0 }, /* (472) limit_clause_opt ::= */ - { 371, -2 }, /* (473) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 371, -4 }, /* (474) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 371, -4 }, /* (475) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 333, -3 }, /* (476) subquery ::= NK_LP query_expression NK_RP */ - { 354, -1 }, /* (477) search_condition ::= common_expression */ - { 373, -1 }, /* (478) sort_specification_list ::= sort_specification */ - { 373, -3 }, /* (479) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 374, -3 }, /* (480) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 375, 0 }, /* (481) ordering_specification_opt ::= */ - { 375, -1 }, /* (482) ordering_specification_opt ::= ASC */ - { 375, -1 }, /* (483) ordering_specification_opt ::= DESC */ - { 376, 0 }, /* (484) null_ordering_opt ::= */ - { 376, -2 }, /* (485) null_ordering_opt ::= NULLS FIRST */ - { 376, -2 }, /* (486) null_ordering_opt ::= NULLS LAST */ + { 255, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 255, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 256, 0 }, /* (2) account_options ::= */ + { 256, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 256, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 256, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 256, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 256, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 256, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 256, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 256, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 256, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 257, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 257, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 259, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 259, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 259, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 259, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 259, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 259, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 259, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 259, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 259, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 259, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 255, -6 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ + { 255, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 255, -5 }, /* (26) cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ + { 255, -5 }, /* (27) cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ + { 255, -3 }, /* (28) cmd ::= DROP USER user_name */ + { 261, 0 }, /* (29) sysinfo_opt ::= */ + { 261, -2 }, /* (30) sysinfo_opt ::= SYSINFO NK_INTEGER */ + { 255, -6 }, /* (31) cmd ::= GRANT privileges ON priv_level TO user_name */ + { 255, -6 }, /* (32) cmd ::= REVOKE privileges ON priv_level FROM user_name */ + { 262, -1 }, /* (33) privileges ::= ALL */ + { 262, -1 }, /* (34) privileges ::= priv_type_list */ + { 264, -1 }, /* (35) priv_type_list ::= priv_type */ + { 264, -3 }, /* (36) priv_type_list ::= priv_type_list NK_COMMA priv_type */ + { 265, -1 }, /* (37) priv_type ::= READ */ + { 265, -1 }, /* (38) priv_type ::= WRITE */ + { 263, -3 }, /* (39) priv_level ::= NK_STAR NK_DOT NK_STAR */ + { 263, -3 }, /* (40) priv_level ::= db_name NK_DOT NK_STAR */ + { 255, -3 }, /* (41) cmd ::= CREATE DNODE dnode_endpoint */ + { 255, -5 }, /* (42) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ + { 255, -3 }, /* (43) cmd ::= DROP DNODE NK_INTEGER */ + { 255, -3 }, /* (44) cmd ::= DROP DNODE dnode_endpoint */ + { 255, -4 }, /* (45) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 255, -5 }, /* (46) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 255, -4 }, /* (47) cmd ::= ALTER ALL DNODES NK_STRING */ + { 255, -5 }, /* (48) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 267, -1 }, /* (49) dnode_endpoint ::= NK_STRING */ + { 267, -1 }, /* (50) dnode_endpoint ::= NK_ID */ + { 267, -1 }, /* (51) dnode_endpoint ::= NK_IPTOKEN */ + { 255, -3 }, /* (52) cmd ::= ALTER LOCAL NK_STRING */ + { 255, -4 }, /* (53) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 255, -5 }, /* (54) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 255, -5 }, /* (55) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 255, -5 }, /* (56) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ + { 255, -5 }, /* (57) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ + { 255, -5 }, /* (58) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ + { 255, -5 }, /* (59) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ + { 255, -5 }, /* (60) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ + { 255, -5 }, /* (61) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ + { 255, -5 }, /* (62) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 255, -4 }, /* (63) cmd ::= DROP DATABASE exists_opt db_name */ + { 255, -2 }, /* (64) cmd ::= USE db_name */ + { 255, -4 }, /* (65) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 255, -3 }, /* (66) cmd ::= FLUSH DATABASE db_name */ + { 255, -3 }, /* (67) cmd ::= TRIM DATABASE db_name */ + { 268, -3 }, /* (68) not_exists_opt ::= IF NOT EXISTS */ + { 268, 0 }, /* (69) not_exists_opt ::= */ + { 270, -2 }, /* (70) exists_opt ::= IF EXISTS */ + { 270, 0 }, /* (71) exists_opt ::= */ + { 269, 0 }, /* (72) db_options ::= */ + { 269, -3 }, /* (73) db_options ::= db_options BUFFER NK_INTEGER */ + { 269, -3 }, /* (74) db_options ::= db_options CACHELAST NK_INTEGER */ + { 269, -3 }, /* (75) db_options ::= db_options CACHELASTSIZE NK_INTEGER */ + { 269, -3 }, /* (76) db_options ::= db_options COMP NK_INTEGER */ + { 269, -3 }, /* (77) db_options ::= db_options DURATION NK_INTEGER */ + { 269, -3 }, /* (78) db_options ::= db_options DURATION NK_VARIABLE */ + { 269, -3 }, /* (79) db_options ::= db_options FSYNC NK_INTEGER */ + { 269, -3 }, /* (80) db_options ::= db_options MAXROWS NK_INTEGER */ + { 269, -3 }, /* (81) db_options ::= db_options MINROWS NK_INTEGER */ + { 269, -3 }, /* (82) db_options ::= db_options KEEP integer_list */ + { 269, -3 }, /* (83) db_options ::= db_options KEEP variable_list */ + { 269, -3 }, /* (84) db_options ::= db_options PAGES NK_INTEGER */ + { 269, -3 }, /* (85) db_options ::= db_options PAGESIZE NK_INTEGER */ + { 269, -3 }, /* (86) db_options ::= db_options PRECISION NK_STRING */ + { 269, -3 }, /* (87) db_options ::= db_options REPLICA NK_INTEGER */ + { 269, -3 }, /* (88) db_options ::= db_options STRICT NK_INTEGER */ + { 269, -3 }, /* (89) db_options ::= db_options WAL NK_INTEGER */ + { 269, -3 }, /* (90) db_options ::= db_options VGROUPS NK_INTEGER */ + { 269, -3 }, /* (91) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 269, -3 }, /* (92) db_options ::= db_options RETENTIONS retention_list */ + { 269, -3 }, /* (93) db_options ::= db_options SCHEMALESS NK_INTEGER */ + { 271, -1 }, /* (94) alter_db_options ::= alter_db_option */ + { 271, -2 }, /* (95) alter_db_options ::= alter_db_options alter_db_option */ + { 275, -2 }, /* (96) alter_db_option ::= BUFFER NK_INTEGER */ + { 275, -2 }, /* (97) alter_db_option ::= CACHELAST NK_INTEGER */ + { 275, -2 }, /* (98) alter_db_option ::= CACHELASTSIZE NK_INTEGER */ + { 275, -2 }, /* (99) alter_db_option ::= FSYNC NK_INTEGER */ + { 275, -2 }, /* (100) alter_db_option ::= KEEP integer_list */ + { 275, -2 }, /* (101) alter_db_option ::= KEEP variable_list */ + { 275, -2 }, /* (102) alter_db_option ::= PAGES NK_INTEGER */ + { 275, -2 }, /* (103) alter_db_option ::= REPLICA NK_INTEGER */ + { 275, -2 }, /* (104) alter_db_option ::= STRICT NK_INTEGER */ + { 275, -2 }, /* (105) alter_db_option ::= WAL NK_INTEGER */ + { 272, -1 }, /* (106) integer_list ::= NK_INTEGER */ + { 272, -3 }, /* (107) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 273, -1 }, /* (108) variable_list ::= NK_VARIABLE */ + { 273, -3 }, /* (109) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + { 274, -1 }, /* (110) retention_list ::= retention */ + { 274, -3 }, /* (111) retention_list ::= retention_list NK_COMMA retention */ + { 276, -3 }, /* (112) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + { 255, -9 }, /* (113) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 255, -3 }, /* (114) cmd ::= CREATE TABLE multi_create_clause */ + { 255, -9 }, /* (115) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 255, -3 }, /* (116) cmd ::= DROP TABLE multi_drop_clause */ + { 255, -4 }, /* (117) cmd ::= DROP STABLE exists_opt full_table_name */ + { 255, -3 }, /* (118) cmd ::= ALTER TABLE alter_table_clause */ + { 255, -3 }, /* (119) cmd ::= ALTER STABLE alter_table_clause */ + { 284, -2 }, /* (120) alter_table_clause ::= full_table_name alter_table_options */ + { 284, -5 }, /* (121) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 284, -4 }, /* (122) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 284, -5 }, /* (123) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 284, -5 }, /* (124) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 284, -5 }, /* (125) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 284, -4 }, /* (126) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 284, -5 }, /* (127) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 284, -5 }, /* (128) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 284, -6 }, /* (129) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ + { 281, -1 }, /* (130) multi_create_clause ::= create_subtable_clause */ + { 281, -2 }, /* (131) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 289, -10 }, /* (132) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ + { 283, -1 }, /* (133) multi_drop_clause ::= drop_table_clause */ + { 283, -2 }, /* (134) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 292, -2 }, /* (135) drop_table_clause ::= exists_opt full_table_name */ + { 290, 0 }, /* (136) specific_cols_opt ::= */ + { 290, -3 }, /* (137) specific_cols_opt ::= NK_LP col_name_list NK_RP */ + { 277, -1 }, /* (138) full_table_name ::= table_name */ + { 277, -3 }, /* (139) full_table_name ::= db_name NK_DOT table_name */ + { 278, -1 }, /* (140) column_def_list ::= column_def */ + { 278, -3 }, /* (141) column_def_list ::= column_def_list NK_COMMA column_def */ + { 295, -2 }, /* (142) column_def ::= column_name type_name */ + { 295, -4 }, /* (143) column_def ::= column_name type_name COMMENT NK_STRING */ + { 287, -1 }, /* (144) type_name ::= BOOL */ + { 287, -1 }, /* (145) type_name ::= TINYINT */ + { 287, -1 }, /* (146) type_name ::= SMALLINT */ + { 287, -1 }, /* (147) type_name ::= INT */ + { 287, -1 }, /* (148) type_name ::= INTEGER */ + { 287, -1 }, /* (149) type_name ::= BIGINT */ + { 287, -1 }, /* (150) type_name ::= FLOAT */ + { 287, -1 }, /* (151) type_name ::= DOUBLE */ + { 287, -4 }, /* (152) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 287, -1 }, /* (153) type_name ::= TIMESTAMP */ + { 287, -4 }, /* (154) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 287, -2 }, /* (155) type_name ::= TINYINT UNSIGNED */ + { 287, -2 }, /* (156) type_name ::= SMALLINT UNSIGNED */ + { 287, -2 }, /* (157) type_name ::= INT UNSIGNED */ + { 287, -2 }, /* (158) type_name ::= BIGINT UNSIGNED */ + { 287, -1 }, /* (159) type_name ::= JSON */ + { 287, -4 }, /* (160) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 287, -1 }, /* (161) type_name ::= MEDIUMBLOB */ + { 287, -1 }, /* (162) type_name ::= BLOB */ + { 287, -4 }, /* (163) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 287, -1 }, /* (164) type_name ::= DECIMAL */ + { 287, -4 }, /* (165) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 287, -6 }, /* (166) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 279, 0 }, /* (167) tags_def_opt ::= */ + { 279, -1 }, /* (168) tags_def_opt ::= tags_def */ + { 282, -4 }, /* (169) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 280, 0 }, /* (170) table_options ::= */ + { 280, -3 }, /* (171) table_options ::= table_options COMMENT NK_STRING */ + { 280, -3 }, /* (172) table_options ::= table_options MAX_DELAY duration_list */ + { 280, -3 }, /* (173) table_options ::= table_options WATERMARK duration_list */ + { 280, -5 }, /* (174) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ + { 280, -3 }, /* (175) table_options ::= table_options TTL NK_INTEGER */ + { 280, -5 }, /* (176) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 285, -1 }, /* (177) alter_table_options ::= alter_table_option */ + { 285, -2 }, /* (178) alter_table_options ::= alter_table_options alter_table_option */ + { 298, -2 }, /* (179) alter_table_option ::= COMMENT NK_STRING */ + { 298, -2 }, /* (180) alter_table_option ::= TTL NK_INTEGER */ + { 296, -1 }, /* (181) duration_list ::= duration_literal */ + { 296, -3 }, /* (182) duration_list ::= duration_list NK_COMMA duration_literal */ + { 297, -1 }, /* (183) rollup_func_list ::= rollup_func_name */ + { 297, -3 }, /* (184) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ + { 300, -1 }, /* (185) rollup_func_name ::= function_name */ + { 300, -1 }, /* (186) rollup_func_name ::= FIRST */ + { 300, -1 }, /* (187) rollup_func_name ::= LAST */ + { 293, -1 }, /* (188) col_name_list ::= col_name */ + { 293, -3 }, /* (189) col_name_list ::= col_name_list NK_COMMA col_name */ + { 302, -1 }, /* (190) col_name ::= column_name */ + { 255, -2 }, /* (191) cmd ::= SHOW DNODES */ + { 255, -2 }, /* (192) cmd ::= SHOW USERS */ + { 255, -2 }, /* (193) cmd ::= SHOW DATABASES */ + { 255, -4 }, /* (194) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 255, -4 }, /* (195) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 255, -3 }, /* (196) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 255, -2 }, /* (197) cmd ::= SHOW MNODES */ + { 255, -2 }, /* (198) cmd ::= SHOW MODULES */ + { 255, -2 }, /* (199) cmd ::= SHOW QNODES */ + { 255, -2 }, /* (200) cmd ::= SHOW FUNCTIONS */ + { 255, -5 }, /* (201) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 255, -2 }, /* (202) cmd ::= SHOW STREAMS */ + { 255, -2 }, /* (203) cmd ::= SHOW ACCOUNTS */ + { 255, -2 }, /* (204) cmd ::= SHOW APPS */ + { 255, -2 }, /* (205) cmd ::= SHOW CONNECTIONS */ + { 255, -2 }, /* (206) cmd ::= SHOW LICENCE */ + { 255, -2 }, /* (207) cmd ::= SHOW GRANTS */ + { 255, -4 }, /* (208) cmd ::= SHOW CREATE DATABASE db_name */ + { 255, -4 }, /* (209) cmd ::= SHOW CREATE TABLE full_table_name */ + { 255, -4 }, /* (210) cmd ::= SHOW CREATE STABLE full_table_name */ + { 255, -2 }, /* (211) cmd ::= SHOW QUERIES */ + { 255, -2 }, /* (212) cmd ::= SHOW SCORES */ + { 255, -2 }, /* (213) cmd ::= SHOW TOPICS */ + { 255, -2 }, /* (214) cmd ::= SHOW VARIABLES */ + { 255, -3 }, /* (215) cmd ::= SHOW LOCAL VARIABLES */ + { 255, -4 }, /* (216) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + { 255, -2 }, /* (217) cmd ::= SHOW BNODES */ + { 255, -2 }, /* (218) cmd ::= SHOW SNODES */ + { 255, -2 }, /* (219) cmd ::= SHOW CLUSTER */ + { 255, -2 }, /* (220) cmd ::= SHOW TRANSACTIONS */ + { 255, -4 }, /* (221) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ + { 255, -2 }, /* (222) cmd ::= SHOW CONSUMERS */ + { 255, -2 }, /* (223) cmd ::= SHOW SUBSCRIPTIONS */ + { 303, 0 }, /* (224) db_name_cond_opt ::= */ + { 303, -2 }, /* (225) db_name_cond_opt ::= db_name NK_DOT */ + { 304, 0 }, /* (226) like_pattern_opt ::= */ + { 304, -2 }, /* (227) like_pattern_opt ::= LIKE NK_STRING */ + { 305, -1 }, /* (228) table_name_cond ::= table_name */ + { 306, 0 }, /* (229) from_db_opt ::= */ + { 306, -2 }, /* (230) from_db_opt ::= FROM db_name */ + { 255, -8 }, /* (231) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 255, -4 }, /* (232) cmd ::= DROP INDEX exists_opt index_name */ + { 308, -10 }, /* (233) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ + { 308, -12 }, /* (234) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ + { 309, -1 }, /* (235) func_list ::= func */ + { 309, -3 }, /* (236) func_list ::= func_list NK_COMMA func */ + { 312, -4 }, /* (237) func ::= function_name NK_LP expression_list NK_RP */ + { 311, 0 }, /* (238) sma_stream_opt ::= */ + { 311, -3 }, /* (239) sma_stream_opt ::= stream_options WATERMARK duration_literal */ + { 311, -3 }, /* (240) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ + { 255, -6 }, /* (241) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 255, -7 }, /* (242) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ + { 255, -9 }, /* (243) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ + { 255, -7 }, /* (244) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ + { 255, -9 }, /* (245) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ + { 255, -4 }, /* (246) cmd ::= DROP TOPIC exists_opt topic_name */ + { 255, -7 }, /* (247) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ + { 255, -2 }, /* (248) cmd ::= DESC full_table_name */ + { 255, -2 }, /* (249) cmd ::= DESCRIBE full_table_name */ + { 255, -3 }, /* (250) cmd ::= RESET QUERY CACHE */ + { 255, -4 }, /* (251) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + { 317, 0 }, /* (252) analyze_opt ::= */ + { 317, -1 }, /* (253) analyze_opt ::= ANALYZE */ + { 318, 0 }, /* (254) explain_options ::= */ + { 318, -3 }, /* (255) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 318, -3 }, /* (256) explain_options ::= explain_options RATIO NK_FLOAT */ + { 255, -6 }, /* (257) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ + { 255, -10 }, /* (258) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 255, -4 }, /* (259) cmd ::= DROP FUNCTION exists_opt function_name */ + { 319, 0 }, /* (260) agg_func_opt ::= */ + { 319, -1 }, /* (261) agg_func_opt ::= AGGREGATE */ + { 320, 0 }, /* (262) bufsize_opt ::= */ + { 320, -2 }, /* (263) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 255, -8 }, /* (264) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ + { 255, -4 }, /* (265) cmd ::= DROP STREAM exists_opt stream_name */ + { 322, 0 }, /* (266) into_opt ::= */ + { 322, -2 }, /* (267) into_opt ::= INTO full_table_name */ + { 313, 0 }, /* (268) stream_options ::= */ + { 313, -3 }, /* (269) stream_options ::= stream_options TRIGGER AT_ONCE */ + { 313, -3 }, /* (270) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + { 313, -4 }, /* (271) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ + { 313, -3 }, /* (272) stream_options ::= stream_options WATERMARK duration_literal */ + { 313, -3 }, /* (273) stream_options ::= stream_options IGNORE EXPIRED */ + { 255, -3 }, /* (274) cmd ::= KILL CONNECTION NK_INTEGER */ + { 255, -3 }, /* (275) cmd ::= KILL QUERY NK_STRING */ + { 255, -3 }, /* (276) cmd ::= KILL TRANSACTION NK_INTEGER */ + { 255, -2 }, /* (277) cmd ::= BALANCE VGROUP */ + { 255, -4 }, /* (278) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 255, -4 }, /* (279) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 255, -3 }, /* (280) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 323, -2 }, /* (281) dnode_list ::= DNODE NK_INTEGER */ + { 323, -3 }, /* (282) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 255, -3 }, /* (283) cmd ::= SYNCDB db_name REPLICA */ + { 255, -4 }, /* (284) cmd ::= DELETE FROM full_table_name where_clause_opt */ + { 255, -1 }, /* (285) cmd ::= query_expression */ + { 255, -5 }, /* (286) cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression */ + { 258, -1 }, /* (287) literal ::= NK_INTEGER */ + { 258, -1 }, /* (288) literal ::= NK_FLOAT */ + { 258, -1 }, /* (289) literal ::= NK_STRING */ + { 258, -1 }, /* (290) literal ::= NK_BOOL */ + { 258, -2 }, /* (291) literal ::= TIMESTAMP NK_STRING */ + { 258, -1 }, /* (292) literal ::= duration_literal */ + { 258, -1 }, /* (293) literal ::= NULL */ + { 258, -1 }, /* (294) literal ::= NK_QUESTION */ + { 299, -1 }, /* (295) duration_literal ::= NK_VARIABLE */ + { 325, -1 }, /* (296) signed ::= NK_INTEGER */ + { 325, -2 }, /* (297) signed ::= NK_PLUS NK_INTEGER */ + { 325, -2 }, /* (298) signed ::= NK_MINUS NK_INTEGER */ + { 325, -1 }, /* (299) signed ::= NK_FLOAT */ + { 325, -2 }, /* (300) signed ::= NK_PLUS NK_FLOAT */ + { 325, -2 }, /* (301) signed ::= NK_MINUS NK_FLOAT */ + { 288, -1 }, /* (302) signed_literal ::= signed */ + { 288, -1 }, /* (303) signed_literal ::= NK_STRING */ + { 288, -1 }, /* (304) signed_literal ::= NK_BOOL */ + { 288, -2 }, /* (305) signed_literal ::= TIMESTAMP NK_STRING */ + { 288, -1 }, /* (306) signed_literal ::= duration_literal */ + { 288, -1 }, /* (307) signed_literal ::= NULL */ + { 288, -1 }, /* (308) signed_literal ::= literal_func */ + { 327, -1 }, /* (309) literal_list ::= signed_literal */ + { 327, -3 }, /* (310) literal_list ::= literal_list NK_COMMA signed_literal */ + { 266, -1 }, /* (311) db_name ::= NK_ID */ + { 294, -1 }, /* (312) table_name ::= NK_ID */ + { 286, -1 }, /* (313) column_name ::= NK_ID */ + { 301, -1 }, /* (314) function_name ::= NK_ID */ + { 328, -1 }, /* (315) table_alias ::= NK_ID */ + { 329, -1 }, /* (316) column_alias ::= NK_ID */ + { 260, -1 }, /* (317) user_name ::= NK_ID */ + { 307, -1 }, /* (318) index_name ::= NK_ID */ + { 314, -1 }, /* (319) topic_name ::= NK_ID */ + { 321, -1 }, /* (320) stream_name ::= NK_ID */ + { 316, -1 }, /* (321) cgroup_name ::= NK_ID */ + { 330, -1 }, /* (322) expression ::= literal */ + { 330, -1 }, /* (323) expression ::= pseudo_column */ + { 330, -1 }, /* (324) expression ::= column_reference */ + { 330, -1 }, /* (325) expression ::= function_expression */ + { 330, -1 }, /* (326) expression ::= subquery */ + { 330, -3 }, /* (327) expression ::= NK_LP expression NK_RP */ + { 330, -2 }, /* (328) expression ::= NK_PLUS expression */ + { 330, -2 }, /* (329) expression ::= NK_MINUS expression */ + { 330, -3 }, /* (330) expression ::= expression NK_PLUS expression */ + { 330, -3 }, /* (331) expression ::= expression NK_MINUS expression */ + { 330, -3 }, /* (332) expression ::= expression NK_STAR expression */ + { 330, -3 }, /* (333) expression ::= expression NK_SLASH expression */ + { 330, -3 }, /* (334) expression ::= expression NK_REM expression */ + { 330, -3 }, /* (335) expression ::= column_reference NK_ARROW NK_STRING */ + { 330, -3 }, /* (336) expression ::= expression NK_BITAND expression */ + { 330, -3 }, /* (337) expression ::= expression NK_BITOR expression */ + { 291, -1 }, /* (338) expression_list ::= expression */ + { 291, -3 }, /* (339) expression_list ::= expression_list NK_COMMA expression */ + { 332, -1 }, /* (340) column_reference ::= column_name */ + { 332, -3 }, /* (341) column_reference ::= table_name NK_DOT column_name */ + { 331, -1 }, /* (342) pseudo_column ::= ROWTS */ + { 331, -1 }, /* (343) pseudo_column ::= TBNAME */ + { 331, -3 }, /* (344) pseudo_column ::= table_name NK_DOT TBNAME */ + { 331, -1 }, /* (345) pseudo_column ::= QSTARTTS */ + { 331, -1 }, /* (346) pseudo_column ::= QENDTS */ + { 331, -1 }, /* (347) pseudo_column ::= WSTARTTS */ + { 331, -1 }, /* (348) pseudo_column ::= WENDTS */ + { 331, -1 }, /* (349) pseudo_column ::= WDURATION */ + { 333, -4 }, /* (350) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 333, -4 }, /* (351) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 333, -6 }, /* (352) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + { 333, -1 }, /* (353) function_expression ::= literal_func */ + { 326, -3 }, /* (354) literal_func ::= noarg_func NK_LP NK_RP */ + { 326, -1 }, /* (355) literal_func ::= NOW */ + { 337, -1 }, /* (356) noarg_func ::= NOW */ + { 337, -1 }, /* (357) noarg_func ::= TODAY */ + { 337, -1 }, /* (358) noarg_func ::= TIMEZONE */ + { 337, -1 }, /* (359) noarg_func ::= DATABASE */ + { 337, -1 }, /* (360) noarg_func ::= CLIENT_VERSION */ + { 337, -1 }, /* (361) noarg_func ::= SERVER_VERSION */ + { 337, -1 }, /* (362) noarg_func ::= SERVER_STATUS */ + { 337, -1 }, /* (363) noarg_func ::= CURRENT_USER */ + { 337, -1 }, /* (364) noarg_func ::= USER */ + { 335, -1 }, /* (365) star_func ::= COUNT */ + { 335, -1 }, /* (366) star_func ::= FIRST */ + { 335, -1 }, /* (367) star_func ::= LAST */ + { 335, -1 }, /* (368) star_func ::= LAST_ROW */ + { 336, -1 }, /* (369) star_func_para_list ::= NK_STAR */ + { 336, -1 }, /* (370) star_func_para_list ::= other_para_list */ + { 338, -1 }, /* (371) other_para_list ::= star_func_para */ + { 338, -3 }, /* (372) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 339, -1 }, /* (373) star_func_para ::= expression */ + { 339, -3 }, /* (374) star_func_para ::= table_name NK_DOT NK_STAR */ + { 340, -3 }, /* (375) predicate ::= expression compare_op expression */ + { 340, -5 }, /* (376) predicate ::= expression BETWEEN expression AND expression */ + { 340, -6 }, /* (377) predicate ::= expression NOT BETWEEN expression AND expression */ + { 340, -3 }, /* (378) predicate ::= expression IS NULL */ + { 340, -4 }, /* (379) predicate ::= expression IS NOT NULL */ + { 340, -3 }, /* (380) predicate ::= expression in_op in_predicate_value */ + { 341, -1 }, /* (381) compare_op ::= NK_LT */ + { 341, -1 }, /* (382) compare_op ::= NK_GT */ + { 341, -1 }, /* (383) compare_op ::= NK_LE */ + { 341, -1 }, /* (384) compare_op ::= NK_GE */ + { 341, -1 }, /* (385) compare_op ::= NK_NE */ + { 341, -1 }, /* (386) compare_op ::= NK_EQ */ + { 341, -1 }, /* (387) compare_op ::= LIKE */ + { 341, -2 }, /* (388) compare_op ::= NOT LIKE */ + { 341, -1 }, /* (389) compare_op ::= MATCH */ + { 341, -1 }, /* (390) compare_op ::= NMATCH */ + { 341, -1 }, /* (391) compare_op ::= CONTAINS */ + { 342, -1 }, /* (392) in_op ::= IN */ + { 342, -2 }, /* (393) in_op ::= NOT IN */ + { 343, -3 }, /* (394) in_predicate_value ::= NK_LP literal_list NK_RP */ + { 344, -1 }, /* (395) boolean_value_expression ::= boolean_primary */ + { 344, -2 }, /* (396) boolean_value_expression ::= NOT boolean_primary */ + { 344, -3 }, /* (397) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 344, -3 }, /* (398) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 345, -1 }, /* (399) boolean_primary ::= predicate */ + { 345, -3 }, /* (400) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 346, -1 }, /* (401) common_expression ::= expression */ + { 346, -1 }, /* (402) common_expression ::= boolean_value_expression */ + { 347, 0 }, /* (403) from_clause_opt ::= */ + { 347, -2 }, /* (404) from_clause_opt ::= FROM table_reference_list */ + { 348, -1 }, /* (405) table_reference_list ::= table_reference */ + { 348, -3 }, /* (406) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 349, -1 }, /* (407) table_reference ::= table_primary */ + { 349, -1 }, /* (408) table_reference ::= joined_table */ + { 350, -2 }, /* (409) table_primary ::= table_name alias_opt */ + { 350, -4 }, /* (410) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 350, -2 }, /* (411) table_primary ::= subquery alias_opt */ + { 350, -1 }, /* (412) table_primary ::= parenthesized_joined_table */ + { 352, 0 }, /* (413) alias_opt ::= */ + { 352, -1 }, /* (414) alias_opt ::= table_alias */ + { 352, -2 }, /* (415) alias_opt ::= AS table_alias */ + { 353, -3 }, /* (416) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 353, -3 }, /* (417) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 351, -6 }, /* (418) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 354, 0 }, /* (419) join_type ::= */ + { 354, -1 }, /* (420) join_type ::= INNER */ + { 356, -12 }, /* (421) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 357, 0 }, /* (422) set_quantifier_opt ::= */ + { 357, -1 }, /* (423) set_quantifier_opt ::= DISTINCT */ + { 357, -1 }, /* (424) set_quantifier_opt ::= ALL */ + { 358, -1 }, /* (425) select_list ::= select_item */ + { 358, -3 }, /* (426) select_list ::= select_list NK_COMMA select_item */ + { 366, -1 }, /* (427) select_item ::= NK_STAR */ + { 366, -1 }, /* (428) select_item ::= common_expression */ + { 366, -2 }, /* (429) select_item ::= common_expression column_alias */ + { 366, -3 }, /* (430) select_item ::= common_expression AS column_alias */ + { 366, -3 }, /* (431) select_item ::= table_name NK_DOT NK_STAR */ + { 324, 0 }, /* (432) where_clause_opt ::= */ + { 324, -2 }, /* (433) where_clause_opt ::= WHERE search_condition */ + { 359, 0 }, /* (434) partition_by_clause_opt ::= */ + { 359, -3 }, /* (435) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 363, 0 }, /* (436) twindow_clause_opt ::= */ + { 363, -6 }, /* (437) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 363, -4 }, /* (438) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + { 363, -6 }, /* (439) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 363, -8 }, /* (440) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 310, 0 }, /* (441) sliding_opt ::= */ + { 310, -4 }, /* (442) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 362, 0 }, /* (443) fill_opt ::= */ + { 362, -4 }, /* (444) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 362, -6 }, /* (445) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 367, -1 }, /* (446) fill_mode ::= NONE */ + { 367, -1 }, /* (447) fill_mode ::= PREV */ + { 367, -1 }, /* (448) fill_mode ::= NULL */ + { 367, -1 }, /* (449) fill_mode ::= LINEAR */ + { 367, -1 }, /* (450) fill_mode ::= NEXT */ + { 364, 0 }, /* (451) group_by_clause_opt ::= */ + { 364, -3 }, /* (452) group_by_clause_opt ::= GROUP BY group_by_list */ + { 368, -1 }, /* (453) group_by_list ::= expression */ + { 368, -3 }, /* (454) group_by_list ::= group_by_list NK_COMMA expression */ + { 365, 0 }, /* (455) having_clause_opt ::= */ + { 365, -2 }, /* (456) having_clause_opt ::= HAVING search_condition */ + { 360, 0 }, /* (457) range_opt ::= */ + { 360, -6 }, /* (458) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ + { 361, 0 }, /* (459) every_opt ::= */ + { 361, -4 }, /* (460) every_opt ::= EVERY NK_LP duration_literal NK_RP */ + { 315, -4 }, /* (461) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 369, -1 }, /* (462) query_expression_body ::= query_primary */ + { 369, -4 }, /* (463) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 369, -3 }, /* (464) query_expression_body ::= query_expression_body UNION query_expression_body */ + { 373, -1 }, /* (465) query_primary ::= query_specification */ + { 373, -6 }, /* (466) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ + { 370, 0 }, /* (467) order_by_clause_opt ::= */ + { 370, -3 }, /* (468) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 371, 0 }, /* (469) slimit_clause_opt ::= */ + { 371, -2 }, /* (470) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 371, -4 }, /* (471) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 371, -4 }, /* (472) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 372, 0 }, /* (473) limit_clause_opt ::= */ + { 372, -2 }, /* (474) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 372, -4 }, /* (475) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 372, -4 }, /* (476) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 334, -3 }, /* (477) subquery ::= NK_LP query_expression NK_RP */ + { 355, -1 }, /* (478) search_condition ::= common_expression */ + { 374, -1 }, /* (479) sort_specification_list ::= sort_specification */ + { 374, -3 }, /* (480) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 375, -3 }, /* (481) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 376, 0 }, /* (482) ordering_specification_opt ::= */ + { 376, -1 }, /* (483) ordering_specification_opt ::= ASC */ + { 376, -1 }, /* (484) ordering_specification_opt ::= DESC */ + { 377, 0 }, /* (485) null_ordering_opt ::= */ + { 377, -2 }, /* (486) null_ordering_opt ::= NULLS FIRST */ + { 377, -2 }, /* (487) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3271,11 +3307,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,255,&yymsp[0].minor); + yy_destructor(yypParser,256,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,256,&yymsp[0].minor); + yy_destructor(yypParser,257,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -3289,20 +3325,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,255,&yymsp[-2].minor); +{ yy_destructor(yypParser,256,&yymsp[-2].minor); { } - yy_destructor(yypParser,257,&yymsp[0].minor); + yy_destructor(yypParser,258,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,258,&yymsp[0].minor); +{ yy_destructor(yypParser,259,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,256,&yymsp[-1].minor); +{ yy_destructor(yypParser,257,&yymsp[-1].minor); { } - yy_destructor(yypParser,258,&yymsp[0].minor); + yy_destructor(yypParser,259,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -3316,72 +3352,72 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,257,&yymsp[0].minor); + yy_destructor(yypParser,258,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy5, &yymsp[-1].minor.yy0, yymsp[0].minor.yy535); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy533, &yymsp[-1].minor.yy0, yymsp[0].minor.yy719); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy5, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy533, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy5, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy533, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy5, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy533, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); } break; case 28: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy5); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy533); } break; case 29: /* sysinfo_opt ::= */ -{ yymsp[1].minor.yy535 = 1; } +{ yymsp[1].minor.yy719 = 1; } break; case 30: /* sysinfo_opt ::= SYSINFO NK_INTEGER */ -{ yymsp[-1].minor.yy535 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy719 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); } break; case 31: /* cmd ::= GRANT privileges ON priv_level TO user_name */ -{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy311, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5); } +{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy585, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy533); } break; case 32: /* cmd ::= REVOKE privileges ON priv_level FROM user_name */ -{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy311, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5); } +{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy585, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy533); } break; case 33: /* privileges ::= ALL */ -{ yymsp[0].minor.yy311 = PRIVILEGE_TYPE_ALL; } +{ yymsp[0].minor.yy585 = PRIVILEGE_TYPE_ALL; } break; case 34: /* privileges ::= priv_type_list */ case 35: /* priv_type_list ::= priv_type */ yytestcase(yyruleno==35); -{ yylhsminor.yy311 = yymsp[0].minor.yy311; } - yymsp[0].minor.yy311 = yylhsminor.yy311; +{ yylhsminor.yy585 = yymsp[0].minor.yy585; } + yymsp[0].minor.yy585 = yylhsminor.yy585; break; case 36: /* priv_type_list ::= priv_type_list NK_COMMA priv_type */ -{ yylhsminor.yy311 = yymsp[-2].minor.yy311 | yymsp[0].minor.yy311; } - yymsp[-2].minor.yy311 = yylhsminor.yy311; +{ yylhsminor.yy585 = yymsp[-2].minor.yy585 | yymsp[0].minor.yy585; } + yymsp[-2].minor.yy585 = yylhsminor.yy585; break; case 37: /* priv_type ::= READ */ -{ yymsp[0].minor.yy311 = PRIVILEGE_TYPE_READ; } +{ yymsp[0].minor.yy585 = PRIVILEGE_TYPE_READ; } break; case 38: /* priv_type ::= WRITE */ -{ yymsp[0].minor.yy311 = PRIVILEGE_TYPE_WRITE; } +{ yymsp[0].minor.yy585 = PRIVILEGE_TYPE_WRITE; } break; case 39: /* priv_level ::= NK_STAR NK_DOT NK_STAR */ -{ yylhsminor.yy5 = yymsp[-2].minor.yy0; } - yymsp[-2].minor.yy5 = yylhsminor.yy5; +{ yylhsminor.yy533 = yymsp[-2].minor.yy0; } + yymsp[-2].minor.yy533 = yylhsminor.yy533; break; case 40: /* priv_level ::= db_name NK_DOT NK_STAR */ -{ yylhsminor.yy5 = yymsp[-2].minor.yy5; } - yymsp[-2].minor.yy5 = yylhsminor.yy5; +{ yylhsminor.yy533 = yymsp[-2].minor.yy533; } + yymsp[-2].minor.yy533 = yylhsminor.yy533; break; case 41: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy5, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy533, NULL); } break; case 42: /* cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy0); } break; case 43: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 44: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy5); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy533); } break; case 45: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -3398,32 +3434,32 @@ static YYACTIONTYPE yy_reduce( case 49: /* dnode_endpoint ::= NK_STRING */ case 50: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==50); case 51: /* dnode_endpoint ::= NK_IPTOKEN */ yytestcase(yyruleno==51); - case 310: /* db_name ::= NK_ID */ yytestcase(yyruleno==310); - case 311: /* table_name ::= NK_ID */ yytestcase(yyruleno==311); - case 312: /* column_name ::= NK_ID */ yytestcase(yyruleno==312); - case 313: /* function_name ::= NK_ID */ yytestcase(yyruleno==313); - case 314: /* table_alias ::= NK_ID */ yytestcase(yyruleno==314); - case 315: /* column_alias ::= NK_ID */ yytestcase(yyruleno==315); - case 316: /* user_name ::= NK_ID */ yytestcase(yyruleno==316); - case 317: /* index_name ::= NK_ID */ yytestcase(yyruleno==317); - case 318: /* topic_name ::= NK_ID */ yytestcase(yyruleno==318); - case 319: /* stream_name ::= NK_ID */ yytestcase(yyruleno==319); - case 320: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==320); - case 355: /* noarg_func ::= NOW */ yytestcase(yyruleno==355); - case 356: /* noarg_func ::= TODAY */ yytestcase(yyruleno==356); - case 357: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==357); - case 358: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==358); - case 359: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==359); - case 360: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==360); - case 361: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==361); - case 362: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==362); - case 363: /* noarg_func ::= USER */ yytestcase(yyruleno==363); - case 364: /* star_func ::= COUNT */ yytestcase(yyruleno==364); - case 365: /* star_func ::= FIRST */ yytestcase(yyruleno==365); - case 366: /* star_func ::= LAST */ yytestcase(yyruleno==366); - case 367: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==367); -{ yylhsminor.yy5 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy5 = yylhsminor.yy5; + case 311: /* db_name ::= NK_ID */ yytestcase(yyruleno==311); + case 312: /* table_name ::= NK_ID */ yytestcase(yyruleno==312); + case 313: /* column_name ::= NK_ID */ yytestcase(yyruleno==313); + case 314: /* function_name ::= NK_ID */ yytestcase(yyruleno==314); + case 315: /* table_alias ::= NK_ID */ yytestcase(yyruleno==315); + case 316: /* column_alias ::= NK_ID */ yytestcase(yyruleno==316); + case 317: /* user_name ::= NK_ID */ yytestcase(yyruleno==317); + case 318: /* index_name ::= NK_ID */ yytestcase(yyruleno==318); + case 319: /* topic_name ::= NK_ID */ yytestcase(yyruleno==319); + case 320: /* stream_name ::= NK_ID */ yytestcase(yyruleno==320); + case 321: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==321); + case 356: /* noarg_func ::= NOW */ yytestcase(yyruleno==356); + case 357: /* noarg_func ::= TODAY */ yytestcase(yyruleno==357); + case 358: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==358); + case 359: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==359); + case 360: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==360); + case 361: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==361); + case 362: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==362); + case 363: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==363); + case 364: /* noarg_func ::= USER */ yytestcase(yyruleno==364); + case 365: /* star_func ::= COUNT */ yytestcase(yyruleno==365); + case 366: /* star_func ::= FIRST */ yytestcase(yyruleno==366); + case 367: /* star_func ::= LAST */ yytestcase(yyruleno==367); + case 368: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==368); +{ yylhsminor.yy533 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy533 = yylhsminor.yy533; break; case 52: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -3456,1234 +3492,1238 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } break; case 62: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy403, &yymsp[-1].minor.yy5, yymsp[0].minor.yy652); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy173, &yymsp[-1].minor.yy533, yymsp[0].minor.yy560); } break; case 63: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy403, &yymsp[0].minor.yy5); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy533); } break; case 64: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy5); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy533); } break; case 65: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy5, yymsp[0].minor.yy652); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy533, yymsp[0].minor.yy560); } break; case 66: /* cmd ::= FLUSH DATABASE db_name */ -{ pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &yymsp[0].minor.yy5); } +{ pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &yymsp[0].minor.yy533); } break; - case 67: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy403 = true; } + case 67: /* cmd ::= TRIM DATABASE db_name */ +{ pCxt->pRootNode = createTrimDatabaseStmt(pCxt, &yymsp[0].minor.yy533); } break; - case 68: /* not_exists_opt ::= */ - case 70: /* exists_opt ::= */ yytestcase(yyruleno==70); - case 251: /* analyze_opt ::= */ yytestcase(yyruleno==251); - case 259: /* agg_func_opt ::= */ yytestcase(yyruleno==259); - case 421: /* set_quantifier_opt ::= */ yytestcase(yyruleno==421); -{ yymsp[1].minor.yy403 = false; } + case 68: /* not_exists_opt ::= IF NOT EXISTS */ +{ yymsp[-2].minor.yy173 = true; } break; - case 69: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy403 = true; } + case 69: /* not_exists_opt ::= */ + case 71: /* exists_opt ::= */ yytestcase(yyruleno==71); + case 252: /* analyze_opt ::= */ yytestcase(yyruleno==252); + case 260: /* agg_func_opt ::= */ yytestcase(yyruleno==260); + case 422: /* set_quantifier_opt ::= */ yytestcase(yyruleno==422); +{ yymsp[1].minor.yy173 = false; } break; - case 71: /* db_options ::= */ -{ yymsp[1].minor.yy652 = createDefaultDatabaseOptions(pCxt); } + case 70: /* exists_opt ::= IF EXISTS */ +{ yymsp[-1].minor.yy173 = true; } break; - case 72: /* db_options ::= db_options BUFFER NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 72: /* db_options ::= */ +{ yymsp[1].minor.yy560 = createDefaultDatabaseOptions(pCxt); } break; - case 73: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 73: /* db_options ::= db_options BUFFER NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 74: /* db_options ::= db_options CACHELASTSIZE NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_CACHELASTSIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 74: /* db_options ::= db_options CACHELAST NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 75: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 75: /* db_options ::= db_options CACHELASTSIZE NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_CACHELASTSIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 76: /* db_options ::= db_options DURATION NK_INTEGER */ - case 77: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==77); -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 76: /* db_options ::= db_options COMP NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 78: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 77: /* db_options ::= db_options DURATION NK_INTEGER */ + case 78: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==78); +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 79: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 79: /* db_options ::= db_options FSYNC NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 80: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 80: /* db_options ::= db_options MAXROWS NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 81: /* db_options ::= db_options KEEP integer_list */ - case 82: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==82); -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_KEEP, yymsp[0].minor.yy210); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 81: /* db_options ::= db_options MINROWS NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 83: /* db_options ::= db_options PAGES NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 84: /* db_options ::= db_options PAGESIZE NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 85: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 86: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 87: /* db_options ::= db_options STRICT NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 88: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 89: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 90: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 91: /* db_options ::= db_options RETENTIONS retention_list */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_RETENTIONS, yymsp[0].minor.yy210); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 92: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ -{ yylhsminor.yy652 = setDatabaseOption(pCxt, yymsp[-2].minor.yy652, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 93: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy652 = createAlterDatabaseOptions(pCxt); yylhsminor.yy652 = setAlterDatabaseOption(pCxt, yylhsminor.yy652, &yymsp[0].minor.yy351); } - yymsp[0].minor.yy652 = yylhsminor.yy652; - break; - case 94: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy652 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy652, &yymsp[0].minor.yy351); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; - break; - case 95: /* alter_db_option ::= BUFFER NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } - break; - case 96: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } - break; - case 97: /* alter_db_option ::= CACHELASTSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = DB_OPTION_CACHELASTSIZE; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } - break; - case 98: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } - break; - case 99: /* alter_db_option ::= KEEP integer_list */ - case 100: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==100); -{ yymsp[-1].minor.yy351.type = DB_OPTION_KEEP; yymsp[-1].minor.yy351.pList = yymsp[0].minor.yy210; } - break; - case 101: /* alter_db_option ::= PAGES NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = DB_OPTION_PAGES; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } - break; - case 102: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } - break; - case 103: /* alter_db_option ::= STRICT NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = DB_OPTION_STRICT; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } - break; - case 104: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = DB_OPTION_WAL; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } - break; - case 105: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy210 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy210 = yylhsminor.yy210; - break; - case 106: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 281: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==281); -{ yylhsminor.yy210 = addNodeToList(pCxt, yymsp[-2].minor.yy210, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy210 = yylhsminor.yy210; - break; - case 107: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy210 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy210 = yylhsminor.yy210; - break; - case 108: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy210 = addNodeToList(pCxt, yymsp[-2].minor.yy210, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy210 = yylhsminor.yy210; - break; - case 109: /* retention_list ::= retention */ - case 129: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==129); - case 132: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==132); - case 139: /* column_def_list ::= column_def */ yytestcase(yyruleno==139); - case 182: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==182); - case 187: /* col_name_list ::= col_name */ yytestcase(yyruleno==187); - case 234: /* func_list ::= func */ yytestcase(yyruleno==234); - case 308: /* literal_list ::= signed_literal */ yytestcase(yyruleno==308); - case 370: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==370); - case 424: /* select_list ::= select_item */ yytestcase(yyruleno==424); - case 478: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==478); -{ yylhsminor.yy210 = createNodeList(pCxt, yymsp[0].minor.yy652); } - yymsp[0].minor.yy210 = yylhsminor.yy210; - break; - case 110: /* retention_list ::= retention_list NK_COMMA retention */ - case 140: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==140); - case 183: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==183); - case 188: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==188); - case 235: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==235); - case 309: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==309); - case 371: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==371); - case 425: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==425); - case 479: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==479); -{ yylhsminor.yy210 = addNodeToList(pCxt, yymsp[-2].minor.yy210, yymsp[0].minor.yy652); } - yymsp[-2].minor.yy210 = yylhsminor.yy210; - break; - case 111: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy652 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 112: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 114: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==114); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy403, yymsp[-5].minor.yy652, yymsp[-3].minor.yy210, yymsp[-1].minor.yy210, yymsp[0].minor.yy652); } - break; - case 113: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy210); } - break; - case 115: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy210); } - break; - case 116: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy403, yymsp[0].minor.yy652); } - break; - case 117: /* cmd ::= ALTER TABLE alter_table_clause */ - case 284: /* cmd ::= query_expression */ yytestcase(yyruleno==284); -{ pCxt->pRootNode = yymsp[0].minor.yy652; } - break; - case 118: /* cmd ::= ALTER STABLE alter_table_clause */ -{ pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy652); } - break; - case 119: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy652 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy652, yymsp[0].minor.yy652); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 82: /* db_options ::= db_options KEEP integer_list */ + case 83: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==83); +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_KEEP, yymsp[0].minor.yy712); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 120: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy652 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy652, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy5, yymsp[0].minor.yy552); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + case 84: /* db_options ::= db_options PAGES NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 121: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy652 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy652, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy5); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; - break; - case 122: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy652 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy652, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy5, yymsp[0].minor.yy552); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + case 85: /* db_options ::= db_options PAGESIZE NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 123: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy652 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy652, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy5, &yymsp[0].minor.yy5); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + case 86: /* db_options ::= db_options PRECISION NK_STRING */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 87: /* db_options ::= db_options REPLICA NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 88: /* db_options ::= db_options STRICT NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 89: /* db_options ::= db_options WAL NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 90: /* db_options ::= db_options VGROUPS NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 91: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 92: /* db_options ::= db_options RETENTIONS retention_list */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_RETENTIONS, yymsp[0].minor.yy712); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 93: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ +{ yylhsminor.yy560 = setDatabaseOption(pCxt, yymsp[-2].minor.yy560, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 94: /* alter_db_options ::= alter_db_option */ +{ yylhsminor.yy560 = createAlterDatabaseOptions(pCxt); yylhsminor.yy560 = setAlterDatabaseOption(pCxt, yylhsminor.yy560, &yymsp[0].minor.yy389); } + yymsp[0].minor.yy560 = yylhsminor.yy560; + break; + case 95: /* alter_db_options ::= alter_db_options alter_db_option */ +{ yylhsminor.yy560 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy560, &yymsp[0].minor.yy389); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; + break; + case 96: /* alter_db_option ::= BUFFER NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } + break; + case 97: /* alter_db_option ::= CACHELAST NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } + break; + case 98: /* alter_db_option ::= CACHELASTSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = DB_OPTION_CACHELASTSIZE; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } + break; + case 99: /* alter_db_option ::= FSYNC NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } + break; + case 100: /* alter_db_option ::= KEEP integer_list */ + case 101: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==101); +{ yymsp[-1].minor.yy389.type = DB_OPTION_KEEP; yymsp[-1].minor.yy389.pList = yymsp[0].minor.yy712; } + break; + case 102: /* alter_db_option ::= PAGES NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = DB_OPTION_PAGES; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } + break; + case 103: /* alter_db_option ::= REPLICA NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } + break; + case 104: /* alter_db_option ::= STRICT NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = DB_OPTION_STRICT; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } + break; + case 105: /* alter_db_option ::= WAL NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = DB_OPTION_WAL; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } + break; + case 106: /* integer_list ::= NK_INTEGER */ +{ yylhsminor.yy712 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy712 = yylhsminor.yy712; + break; + case 107: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ + case 282: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==282); +{ yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-2].minor.yy712, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy712 = yylhsminor.yy712; + break; + case 108: /* variable_list ::= NK_VARIABLE */ +{ yylhsminor.yy712 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy712 = yylhsminor.yy712; + break; + case 109: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ +{ yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-2].minor.yy712, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy712 = yylhsminor.yy712; + break; + case 110: /* retention_list ::= retention */ + case 130: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==130); + case 133: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==133); + case 140: /* column_def_list ::= column_def */ yytestcase(yyruleno==140); + case 183: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==183); + case 188: /* col_name_list ::= col_name */ yytestcase(yyruleno==188); + case 235: /* func_list ::= func */ yytestcase(yyruleno==235); + case 309: /* literal_list ::= signed_literal */ yytestcase(yyruleno==309); + case 371: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==371); + case 425: /* select_list ::= select_item */ yytestcase(yyruleno==425); + case 479: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==479); +{ yylhsminor.yy712 = createNodeList(pCxt, yymsp[0].minor.yy560); } + yymsp[0].minor.yy712 = yylhsminor.yy712; + break; + case 111: /* retention_list ::= retention_list NK_COMMA retention */ + case 141: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==141); + case 184: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==184); + case 189: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==189); + case 236: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==236); + case 310: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==310); + case 372: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==372); + case 426: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==426); + case 480: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==480); +{ yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-2].minor.yy712, yymsp[0].minor.yy560); } + yymsp[-2].minor.yy712 = yylhsminor.yy712; + break; + case 112: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ +{ yylhsminor.yy560 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; + break; + case 113: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 115: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==115); +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy173, yymsp[-5].minor.yy560, yymsp[-3].minor.yy712, yymsp[-1].minor.yy712, yymsp[0].minor.yy560); } + break; + case 114: /* cmd ::= CREATE TABLE multi_create_clause */ +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy712); } + break; + case 116: /* cmd ::= DROP TABLE multi_drop_clause */ +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy712); } + break; + case 117: /* cmd ::= DROP STABLE exists_opt full_table_name */ +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy173, yymsp[0].minor.yy560); } + break; + case 118: /* cmd ::= ALTER TABLE alter_table_clause */ + case 285: /* cmd ::= query_expression */ yytestcase(yyruleno==285); +{ pCxt->pRootNode = yymsp[0].minor.yy560; } + break; + case 119: /* cmd ::= ALTER STABLE alter_table_clause */ +{ pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy560); } + break; + case 120: /* alter_table_clause ::= full_table_name alter_table_options */ +{ yylhsminor.yy560 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 124: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy652 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy652, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy5, yymsp[0].minor.yy552); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + case 121: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ +{ yylhsminor.yy560 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy560, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy533, yymsp[0].minor.yy196); } + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 125: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy652 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy652, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy5); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + case 122: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ +{ yylhsminor.yy560 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy560, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy533); } + yymsp[-3].minor.yy560 = yylhsminor.yy560; + break; + case 123: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ +{ yylhsminor.yy560 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy560, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy533, yymsp[0].minor.yy196); } + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 126: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy652 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy652, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy5, yymsp[0].minor.yy552); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + case 124: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ +{ yylhsminor.yy560 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy560, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy533, &yymsp[0].minor.yy533); } + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 127: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy652 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy652, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy5, &yymsp[0].minor.yy5); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + case 125: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ +{ yylhsminor.yy560 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy560, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy533, yymsp[0].minor.yy196); } + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 128: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ -{ yylhsminor.yy652 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy652, &yymsp[-2].minor.yy5, yymsp[0].minor.yy652); } - yymsp[-5].minor.yy652 = yylhsminor.yy652; + case 126: /* alter_table_clause ::= full_table_name DROP TAG column_name */ +{ yylhsminor.yy560 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy560, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy533); } + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 130: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 133: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==133); -{ yylhsminor.yy210 = addNodeToList(pCxt, yymsp[-1].minor.yy210, yymsp[0].minor.yy652); } - yymsp[-1].minor.yy210 = yylhsminor.yy210; + case 127: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ +{ yylhsminor.yy560 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy560, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy533, yymsp[0].minor.yy196); } + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 131: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ -{ yylhsminor.yy652 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy403, yymsp[-8].minor.yy652, yymsp[-6].minor.yy652, yymsp[-5].minor.yy210, yymsp[-2].minor.yy210, yymsp[0].minor.yy652); } - yymsp[-9].minor.yy652 = yylhsminor.yy652; + case 128: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ +{ yylhsminor.yy560 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy560, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy533, &yymsp[0].minor.yy533); } + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 134: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy652 = createDropTableClause(pCxt, yymsp[-1].minor.yy403, yymsp[0].minor.yy652); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 129: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ +{ yylhsminor.yy560 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy560, &yymsp[-2].minor.yy533, yymsp[0].minor.yy560); } + yymsp[-5].minor.yy560 = yylhsminor.yy560; break; - case 135: /* specific_cols_opt ::= */ - case 166: /* tags_def_opt ::= */ yytestcase(yyruleno==166); - case 433: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==433); - case 450: /* group_by_clause_opt ::= */ yytestcase(yyruleno==450); - case 466: /* order_by_clause_opt ::= */ yytestcase(yyruleno==466); -{ yymsp[1].minor.yy210 = NULL; } + case 131: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 134: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==134); +{ yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-1].minor.yy712, yymsp[0].minor.yy560); } + yymsp[-1].minor.yy712 = yylhsminor.yy712; break; - case 136: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy210 = yymsp[-1].minor.yy210; } + case 132: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ +{ yylhsminor.yy560 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy173, yymsp[-8].minor.yy560, yymsp[-6].minor.yy560, yymsp[-5].minor.yy712, yymsp[-2].minor.yy712, yymsp[0].minor.yy560); } + yymsp[-9].minor.yy560 = yylhsminor.yy560; break; - case 137: /* full_table_name ::= table_name */ -{ yylhsminor.yy652 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy5, NULL); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 135: /* drop_table_clause ::= exists_opt full_table_name */ +{ yylhsminor.yy560 = createDropTableClause(pCxt, yymsp[-1].minor.yy173, yymsp[0].minor.yy560); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 138: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy652 = createRealTableNode(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5, NULL); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 136: /* specific_cols_opt ::= */ + case 167: /* tags_def_opt ::= */ yytestcase(yyruleno==167); + case 434: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==434); + case 451: /* group_by_clause_opt ::= */ yytestcase(yyruleno==451); + case 467: /* order_by_clause_opt ::= */ yytestcase(yyruleno==467); +{ yymsp[1].minor.yy712 = NULL; } break; - case 141: /* column_def ::= column_name type_name */ -{ yylhsminor.yy652 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy5, yymsp[0].minor.yy552, NULL); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 137: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ +{ yymsp[-2].minor.yy712 = yymsp[-1].minor.yy712; } break; - case 142: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy652 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy5, yymsp[-2].minor.yy552, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + case 138: /* full_table_name ::= table_name */ +{ yylhsminor.yy560 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy533, NULL); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 143: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_BOOL); } + case 139: /* full_table_name ::= db_name NK_DOT table_name */ +{ yylhsminor.yy560 = createRealTableNode(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy533, NULL); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 144: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_TINYINT); } + case 142: /* column_def ::= column_name type_name */ +{ yylhsminor.yy560 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy533, yymsp[0].minor.yy196, NULL); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 145: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_SMALLINT); } + case 143: /* column_def ::= column_name type_name COMMENT NK_STRING */ +{ yylhsminor.yy560 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy533, yymsp[-2].minor.yy196, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 146: /* type_name ::= INT */ - case 147: /* type_name ::= INTEGER */ yytestcase(yyruleno==147); -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_INT); } + case 144: /* type_name ::= BOOL */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 148: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_BIGINT); } + case 145: /* type_name ::= TINYINT */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 149: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_FLOAT); } + case 146: /* type_name ::= SMALLINT */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 150: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_DOUBLE); } + case 147: /* type_name ::= INT */ + case 148: /* type_name ::= INTEGER */ yytestcase(yyruleno==148); +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 151: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy552 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } + case 149: /* type_name ::= BIGINT */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 152: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } + case 150: /* type_name ::= FLOAT */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 153: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy552 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } + case 151: /* type_name ::= DOUBLE */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 154: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy552 = createDataType(TSDB_DATA_TYPE_UTINYINT); } + case 152: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy196 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 155: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy552 = createDataType(TSDB_DATA_TYPE_USMALLINT); } + case 153: /* type_name ::= TIMESTAMP */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 156: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy552 = createDataType(TSDB_DATA_TYPE_UINT); } + case 154: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy196 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 157: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy552 = createDataType(TSDB_DATA_TYPE_UBIGINT); } + case 155: /* type_name ::= TINYINT UNSIGNED */ +{ yymsp[-1].minor.yy196 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 158: /* type_name ::= JSON */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_JSON); } + case 156: /* type_name ::= SMALLINT UNSIGNED */ +{ yymsp[-1].minor.yy196 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 159: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy552 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } + case 157: /* type_name ::= INT UNSIGNED */ +{ yymsp[-1].minor.yy196 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 160: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } + case 158: /* type_name ::= BIGINT UNSIGNED */ +{ yymsp[-1].minor.yy196 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 161: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_BLOB); } + case 159: /* type_name ::= JSON */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 162: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy552 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } + case 160: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy196 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 163: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy552 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 161: /* type_name ::= MEDIUMBLOB */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 164: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy552 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 162: /* type_name ::= BLOB */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 165: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy552 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 163: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy196 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 167: /* tags_def_opt ::= tags_def */ - case 369: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==369); -{ yylhsminor.yy210 = yymsp[0].minor.yy210; } - yymsp[0].minor.yy210 = yylhsminor.yy210; + case 164: /* type_name ::= DECIMAL */ +{ yymsp[0].minor.yy196 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 168: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy210 = yymsp[-1].minor.yy210; } + case 165: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy196 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 169: /* table_options ::= */ -{ yymsp[1].minor.yy652 = createDefaultTableOptions(pCxt); } + case 166: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy196 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 170: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy652 = setTableOption(pCxt, yymsp[-2].minor.yy652, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 168: /* tags_def_opt ::= tags_def */ + case 370: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==370); +{ yylhsminor.yy712 = yymsp[0].minor.yy712; } + yymsp[0].minor.yy712 = yylhsminor.yy712; break; - case 171: /* table_options ::= table_options MAX_DELAY duration_list */ -{ yylhsminor.yy652 = setTableOption(pCxt, yymsp[-2].minor.yy652, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy210); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 169: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ +{ yymsp[-3].minor.yy712 = yymsp[-1].minor.yy712; } break; - case 172: /* table_options ::= table_options WATERMARK duration_list */ -{ yylhsminor.yy652 = setTableOption(pCxt, yymsp[-2].minor.yy652, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy210); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 170: /* table_options ::= */ +{ yymsp[1].minor.yy560 = createDefaultTableOptions(pCxt); } break; - case 173: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ -{ yylhsminor.yy652 = setTableOption(pCxt, yymsp[-4].minor.yy652, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy210); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + case 171: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy560 = setTableOption(pCxt, yymsp[-2].minor.yy560, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 174: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy652 = setTableOption(pCxt, yymsp[-2].minor.yy652, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 172: /* table_options ::= table_options MAX_DELAY duration_list */ +{ yylhsminor.yy560 = setTableOption(pCxt, yymsp[-2].minor.yy560, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy712); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 175: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy652 = setTableOption(pCxt, yymsp[-4].minor.yy652, TABLE_OPTION_SMA, yymsp[-1].minor.yy210); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + case 173: /* table_options ::= table_options WATERMARK duration_list */ +{ yylhsminor.yy560 = setTableOption(pCxt, yymsp[-2].minor.yy560, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy712); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 176: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy652 = createAlterTableOptions(pCxt); yylhsminor.yy652 = setTableOption(pCxt, yylhsminor.yy652, yymsp[0].minor.yy351.type, &yymsp[0].minor.yy351.val); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 174: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ +{ yylhsminor.yy560 = setTableOption(pCxt, yymsp[-4].minor.yy560, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy712); } + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 177: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy652 = setTableOption(pCxt, yymsp[-1].minor.yy652, yymsp[0].minor.yy351.type, &yymsp[0].minor.yy351.val); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 175: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy560 = setTableOption(pCxt, yymsp[-2].minor.yy560, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 178: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy351.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } + case 176: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy560 = setTableOption(pCxt, yymsp[-4].minor.yy560, TABLE_OPTION_SMA, yymsp[-1].minor.yy712); } + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 179: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy351.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy351.val = yymsp[0].minor.yy0; } + case 177: /* alter_table_options ::= alter_table_option */ +{ yylhsminor.yy560 = createAlterTableOptions(pCxt); yylhsminor.yy560 = setTableOption(pCxt, yylhsminor.yy560, yymsp[0].minor.yy389.type, &yymsp[0].minor.yy389.val); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 180: /* duration_list ::= duration_literal */ - case 337: /* expression_list ::= expression */ yytestcase(yyruleno==337); -{ yylhsminor.yy210 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy652)); } - yymsp[0].minor.yy210 = yylhsminor.yy210; + case 178: /* alter_table_options ::= alter_table_options alter_table_option */ +{ yylhsminor.yy560 = setTableOption(pCxt, yymsp[-1].minor.yy560, yymsp[0].minor.yy389.type, &yymsp[0].minor.yy389.val); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 181: /* duration_list ::= duration_list NK_COMMA duration_literal */ - case 338: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==338); -{ yylhsminor.yy210 = addNodeToList(pCxt, yymsp[-2].minor.yy210, releaseRawExprNode(pCxt, yymsp[0].minor.yy652)); } - yymsp[-2].minor.yy210 = yylhsminor.yy210; + case 179: /* alter_table_option ::= COMMENT NK_STRING */ +{ yymsp[-1].minor.yy389.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } break; - case 184: /* rollup_func_name ::= function_name */ -{ yylhsminor.yy652 = createFunctionNode(pCxt, &yymsp[0].minor.yy5, NULL); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 180: /* alter_table_option ::= TTL NK_INTEGER */ +{ yymsp[-1].minor.yy389.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } break; - case 185: /* rollup_func_name ::= FIRST */ - case 186: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==186); -{ yylhsminor.yy652 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 181: /* duration_list ::= duration_literal */ + case 338: /* expression_list ::= expression */ yytestcase(yyruleno==338); +{ yylhsminor.yy712 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy560)); } + yymsp[0].minor.yy712 = yylhsminor.yy712; break; - case 189: /* col_name ::= column_name */ -{ yylhsminor.yy652 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy5); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 182: /* duration_list ::= duration_list NK_COMMA duration_literal */ + case 339: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==339); +{ yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-2].minor.yy712, releaseRawExprNode(pCxt, yymsp[0].minor.yy560)); } + yymsp[-2].minor.yy712 = yylhsminor.yy712; break; - case 190: /* cmd ::= SHOW DNODES */ + case 185: /* rollup_func_name ::= function_name */ +{ yylhsminor.yy560 = createFunctionNode(pCxt, &yymsp[0].minor.yy533, NULL); } + yymsp[0].minor.yy560 = yylhsminor.yy560; + break; + case 186: /* rollup_func_name ::= FIRST */ + case 187: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==187); +{ yylhsminor.yy560 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } + yymsp[0].minor.yy560 = yylhsminor.yy560; + break; + case 190: /* col_name ::= column_name */ +{ yylhsminor.yy560 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy533); } + yymsp[0].minor.yy560 = yylhsminor.yy560; + break; + case 191: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } break; - case 191: /* cmd ::= SHOW USERS */ + case 192: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } break; - case 192: /* cmd ::= SHOW DATABASES */ + case 193: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } break; - case 193: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy652, yymsp[0].minor.yy652, OP_TYPE_LIKE); } + case 194: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy560, yymsp[0].minor.yy560, OP_TYPE_LIKE); } break; - case 194: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy652, yymsp[0].minor.yy652, OP_TYPE_LIKE); } + case 195: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy560, yymsp[0].minor.yy560, OP_TYPE_LIKE); } break; - case 195: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy652, NULL, OP_TYPE_LIKE); } + case 196: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy560, NULL, OP_TYPE_LIKE); } break; - case 196: /* cmd ::= SHOW MNODES */ + case 197: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } break; - case 197: /* cmd ::= SHOW MODULES */ + case 198: /* cmd ::= SHOW MODULES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT); } break; - case 198: /* cmd ::= SHOW QNODES */ + case 199: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); } break; - case 199: /* cmd ::= SHOW FUNCTIONS */ + case 200: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); } break; - case 200: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy652, yymsp[-1].minor.yy652, OP_TYPE_EQUAL); } + case 201: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy560, yymsp[-1].minor.yy560, OP_TYPE_EQUAL); } break; - case 201: /* cmd ::= SHOW STREAMS */ + case 202: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); } break; - case 202: /* cmd ::= SHOW ACCOUNTS */ + case 203: /* cmd ::= SHOW ACCOUNTS */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; - case 203: /* cmd ::= SHOW APPS */ + case 204: /* cmd ::= SHOW APPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); } break; - case 204: /* cmd ::= SHOW CONNECTIONS */ + case 205: /* cmd ::= SHOW CONNECTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); } break; - case 205: /* cmd ::= SHOW LICENCE */ - case 206: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==206); + case 206: /* cmd ::= SHOW LICENCE */ + case 207: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==207); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT); } break; - case 207: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy5); } + case 208: /* cmd ::= SHOW CREATE DATABASE db_name */ +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy533); } break; - case 208: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy652); } + case 209: /* cmd ::= SHOW CREATE TABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy560); } break; - case 209: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy652); } + case 210: /* cmd ::= SHOW CREATE STABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy560); } break; - case 210: /* cmd ::= SHOW QUERIES */ + case 211: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } break; - case 211: /* cmd ::= SHOW SCORES */ + case 212: /* cmd ::= SHOW SCORES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } break; - case 212: /* cmd ::= SHOW TOPICS */ + case 213: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } break; - case 213: /* cmd ::= SHOW VARIABLES */ + case 214: /* cmd ::= SHOW VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } break; - case 214: /* cmd ::= SHOW LOCAL VARIABLES */ + case 215: /* cmd ::= SHOW LOCAL VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } break; - case 215: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + case 216: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-1].minor.yy0)); } break; - case 216: /* cmd ::= SHOW BNODES */ + case 217: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } break; - case 217: /* cmd ::= SHOW SNODES */ + case 218: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } break; - case 218: /* cmd ::= SHOW CLUSTER */ + case 219: /* cmd ::= SHOW CLUSTER */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } break; - case 219: /* cmd ::= SHOW TRANSACTIONS */ + case 220: /* cmd ::= SHOW TRANSACTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } break; - case 220: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ -{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy652); } + case 221: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ +{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy560); } break; - case 221: /* cmd ::= SHOW CONSUMERS */ + case 222: /* cmd ::= SHOW CONSUMERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); } break; - case 222: /* cmd ::= SHOW SUBSCRIPTIONS */ + case 223: /* cmd ::= SHOW SUBSCRIPTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); } break; - case 223: /* db_name_cond_opt ::= */ - case 228: /* from_db_opt ::= */ yytestcase(yyruleno==228); -{ yymsp[1].minor.yy652 = createDefaultDatabaseCondValue(pCxt); } + case 224: /* db_name_cond_opt ::= */ + case 229: /* from_db_opt ::= */ yytestcase(yyruleno==229); +{ yymsp[1].minor.yy560 = createDefaultDatabaseCondValue(pCxt); } break; - case 224: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy5); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 225: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy533); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 225: /* like_pattern_opt ::= */ - case 265: /* into_opt ::= */ yytestcase(yyruleno==265); - case 402: /* from_clause_opt ::= */ yytestcase(yyruleno==402); - case 431: /* where_clause_opt ::= */ yytestcase(yyruleno==431); - case 435: /* twindow_clause_opt ::= */ yytestcase(yyruleno==435); - case 440: /* sliding_opt ::= */ yytestcase(yyruleno==440); - case 442: /* fill_opt ::= */ yytestcase(yyruleno==442); - case 454: /* having_clause_opt ::= */ yytestcase(yyruleno==454); - case 456: /* range_opt ::= */ yytestcase(yyruleno==456); - case 458: /* every_opt ::= */ yytestcase(yyruleno==458); - case 468: /* slimit_clause_opt ::= */ yytestcase(yyruleno==468); - case 472: /* limit_clause_opt ::= */ yytestcase(yyruleno==472); -{ yymsp[1].minor.yy652 = NULL; } + case 226: /* like_pattern_opt ::= */ + case 266: /* into_opt ::= */ yytestcase(yyruleno==266); + case 403: /* from_clause_opt ::= */ yytestcase(yyruleno==403); + case 432: /* where_clause_opt ::= */ yytestcase(yyruleno==432); + case 436: /* twindow_clause_opt ::= */ yytestcase(yyruleno==436); + case 441: /* sliding_opt ::= */ yytestcase(yyruleno==441); + case 443: /* fill_opt ::= */ yytestcase(yyruleno==443); + case 455: /* having_clause_opt ::= */ yytestcase(yyruleno==455); + case 457: /* range_opt ::= */ yytestcase(yyruleno==457); + case 459: /* every_opt ::= */ yytestcase(yyruleno==459); + case 469: /* slimit_clause_opt ::= */ yytestcase(yyruleno==469); + case 473: /* limit_clause_opt ::= */ yytestcase(yyruleno==473); +{ yymsp[1].minor.yy560 = NULL; } break; - case 226: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 227: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 227: /* table_name_cond ::= table_name */ -{ yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy5); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 228: /* table_name_cond ::= table_name */ +{ yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy533); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 229: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy5); } + case 230: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy533); } break; - case 230: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy403, &yymsp[-3].minor.yy5, &yymsp[-1].minor.yy5, NULL, yymsp[0].minor.yy652); } + case 231: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy173, &yymsp[-3].minor.yy533, &yymsp[-1].minor.yy533, NULL, yymsp[0].minor.yy560); } break; - case 231: /* cmd ::= DROP INDEX exists_opt index_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy403, &yymsp[0].minor.yy5); } + case 232: /* cmd ::= DROP INDEX exists_opt index_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy533); } break; - case 232: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ -{ yymsp[-9].minor.yy652 = createIndexOption(pCxt, yymsp[-7].minor.yy210, releaseRawExprNode(pCxt, yymsp[-3].minor.yy652), NULL, yymsp[-1].minor.yy652, yymsp[0].minor.yy652); } + case 233: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ +{ yymsp[-9].minor.yy560 = createIndexOption(pCxt, yymsp[-7].minor.yy712, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), NULL, yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } break; - case 233: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ -{ yymsp[-11].minor.yy652 = createIndexOption(pCxt, yymsp[-9].minor.yy210, releaseRawExprNode(pCxt, yymsp[-5].minor.yy652), releaseRawExprNode(pCxt, yymsp[-3].minor.yy652), yymsp[-1].minor.yy652, yymsp[0].minor.yy652); } + case 234: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ +{ yymsp[-11].minor.yy560 = createIndexOption(pCxt, yymsp[-9].minor.yy712, releaseRawExprNode(pCxt, yymsp[-5].minor.yy560), releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } break; - case 236: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy652 = createFunctionNode(pCxt, &yymsp[-3].minor.yy5, yymsp[-1].minor.yy210); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + case 237: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy560 = createFunctionNode(pCxt, &yymsp[-3].minor.yy533, yymsp[-1].minor.yy712); } + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 237: /* sma_stream_opt ::= */ - case 267: /* stream_options ::= */ yytestcase(yyruleno==267); -{ yymsp[1].minor.yy652 = createStreamOptions(pCxt); } + case 238: /* sma_stream_opt ::= */ + case 268: /* stream_options ::= */ yytestcase(yyruleno==268); +{ yymsp[1].minor.yy560 = createStreamOptions(pCxt); } break; - case 238: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ - case 271: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==271); -{ ((SStreamOptions*)yymsp[-2].minor.yy652)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy652); yylhsminor.yy652 = yymsp[-2].minor.yy652; } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 239: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ + case 272: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==272); +{ ((SStreamOptions*)yymsp[-2].minor.yy560)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy560); yylhsminor.yy560 = yymsp[-2].minor.yy560; } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 239: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ -{ ((SStreamOptions*)yymsp[-2].minor.yy652)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy652); yylhsminor.yy652 = yymsp[-2].minor.yy652; } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 240: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-2].minor.yy560)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy560); yylhsminor.yy560 = yymsp[-2].minor.yy560; } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 240: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy403, &yymsp[-2].minor.yy5, yymsp[0].minor.yy652); } + case 241: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy173, &yymsp[-2].minor.yy533, yymsp[0].minor.yy560); } break; - case 241: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy403, &yymsp[-3].minor.yy5, &yymsp[0].minor.yy5, false); } + case 242: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy173, &yymsp[-3].minor.yy533, &yymsp[0].minor.yy533, false); } break; - case 242: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy403, &yymsp[-5].minor.yy5, &yymsp[0].minor.yy5, true); } + case 243: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy173, &yymsp[-5].minor.yy533, &yymsp[0].minor.yy533, true); } break; - case 243: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy403, &yymsp[-3].minor.yy5, yymsp[0].minor.yy652, false); } + case 244: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy173, &yymsp[-3].minor.yy533, yymsp[0].minor.yy560, false); } break; - case 244: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy403, &yymsp[-5].minor.yy5, yymsp[0].minor.yy652, true); } + case 245: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy173, &yymsp[-5].minor.yy533, yymsp[0].minor.yy560, true); } break; - case 245: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy403, &yymsp[0].minor.yy5); } + case 246: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy533); } break; - case 246: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ -{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy403, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5); } + case 247: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ +{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy173, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy533); } break; - case 247: /* cmd ::= DESC full_table_name */ - case 248: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==248); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy652); } + case 248: /* cmd ::= DESC full_table_name */ + case 249: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==249); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy560); } break; - case 249: /* cmd ::= RESET QUERY CACHE */ + case 250: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 250: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy403, yymsp[-1].minor.yy652, yymsp[0].minor.yy652); } + case 251: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy173, yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } break; - case 252: /* analyze_opt ::= ANALYZE */ - case 260: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==260); - case 422: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==422); -{ yymsp[0].minor.yy403 = true; } + case 253: /* analyze_opt ::= ANALYZE */ + case 261: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==261); + case 423: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==423); +{ yymsp[0].minor.yy173 = true; } break; - case 253: /* explain_options ::= */ -{ yymsp[1].minor.yy652 = createDefaultExplainOptions(pCxt); } + case 254: /* explain_options ::= */ +{ yymsp[1].minor.yy560 = createDefaultExplainOptions(pCxt); } break; - case 254: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy652 = setExplainVerbose(pCxt, yymsp[-2].minor.yy652, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 255: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy560 = setExplainVerbose(pCxt, yymsp[-2].minor.yy560, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 255: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy652 = setExplainRatio(pCxt, yymsp[-2].minor.yy652, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 256: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy560 = setExplainRatio(pCxt, yymsp[-2].minor.yy560, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 256: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy210); } + case 257: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy712); } break; - case 257: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy403, yymsp[-8].minor.yy403, &yymsp[-5].minor.yy5, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy552, yymsp[0].minor.yy462); } + case 258: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy173, yymsp[-8].minor.yy173, &yymsp[-5].minor.yy533, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy196, yymsp[0].minor.yy424); } break; - case 258: /* cmd ::= DROP FUNCTION exists_opt function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy403, &yymsp[0].minor.yy5); } + case 259: /* cmd ::= DROP FUNCTION exists_opt function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy533); } break; - case 261: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy462 = 0; } + case 262: /* bufsize_opt ::= */ +{ yymsp[1].minor.yy424 = 0; } break; - case 262: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy462 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } + case 263: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy424 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 263: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy403, &yymsp[-4].minor.yy5, yymsp[-2].minor.yy652, yymsp[-3].minor.yy652, yymsp[0].minor.yy652); } + case 264: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy173, &yymsp[-4].minor.yy533, yymsp[-2].minor.yy560, yymsp[-3].minor.yy560, yymsp[0].minor.yy560); } break; - case 264: /* cmd ::= DROP STREAM exists_opt stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy403, &yymsp[0].minor.yy5); } + case 265: /* cmd ::= DROP STREAM exists_opt stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy533); } break; - case 266: /* into_opt ::= INTO full_table_name */ - case 403: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==403); - case 432: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==432); - case 455: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==455); -{ yymsp[-1].minor.yy652 = yymsp[0].minor.yy652; } + case 267: /* into_opt ::= INTO full_table_name */ + case 404: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==404); + case 433: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==433); + case 456: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==456); +{ yymsp[-1].minor.yy560 = yymsp[0].minor.yy560; } break; - case 268: /* stream_options ::= stream_options TRIGGER AT_ONCE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy652)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy652 = yymsp[-2].minor.yy652; } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 269: /* stream_options ::= stream_options TRIGGER AT_ONCE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy560)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy560 = yymsp[-2].minor.yy560; } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 269: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy652)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy652 = yymsp[-2].minor.yy652; } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 270: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy560)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy560 = yymsp[-2].minor.yy560; } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 270: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ -{ ((SStreamOptions*)yymsp[-3].minor.yy652)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy652)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy652); yylhsminor.yy652 = yymsp[-3].minor.yy652; } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + case 271: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-3].minor.yy560)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy560)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy560); yylhsminor.yy560 = yymsp[-3].minor.yy560; } + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 272: /* stream_options ::= stream_options IGNORE EXPIRED */ -{ ((SStreamOptions*)yymsp[-2].minor.yy652)->ignoreExpired = true; yylhsminor.yy652 = yymsp[-2].minor.yy652; } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 273: /* stream_options ::= stream_options IGNORE EXPIRED */ +{ ((SStreamOptions*)yymsp[-2].minor.yy560)->ignoreExpired = true; yylhsminor.yy560 = yymsp[-2].minor.yy560; } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 273: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 274: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 274: /* cmd ::= KILL QUERY NK_STRING */ + case 275: /* cmd ::= KILL QUERY NK_STRING */ { pCxt->pRootNode = createKillQueryStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 275: /* cmd ::= KILL TRANSACTION NK_INTEGER */ + case 276: /* cmd ::= KILL TRANSACTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); } break; - case 276: /* cmd ::= BALANCE VGROUP */ + case 277: /* cmd ::= BALANCE VGROUP */ { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } break; - case 277: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 278: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 278: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy210); } + case 279: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy712); } break; - case 279: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 280: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 280: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy210 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + case 281: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy712 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; - case 282: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy5); } + case 283: /* cmd ::= SYNCDB db_name REPLICA */ +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy533); } break; - case 283: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ -{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy652, yymsp[0].minor.yy652); } + case 284: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ +{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } break; - case 285: /* cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression */ -{ pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-2].minor.yy652, yymsp[-1].minor.yy210, yymsp[0].minor.yy652); } + case 286: /* cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression */ +{ pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-2].minor.yy560, yymsp[-1].minor.yy712, yymsp[0].minor.yy560); } break; - case 286: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 287: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 287: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 288: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 288: /* literal ::= NK_STRING */ -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 289: /* literal ::= NK_STRING */ +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 289: /* literal ::= NK_BOOL */ -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 290: /* literal ::= NK_BOOL */ +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 290: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 291: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 291: /* literal ::= duration_literal */ - case 301: /* signed_literal ::= signed */ yytestcase(yyruleno==301); - case 321: /* expression ::= literal */ yytestcase(yyruleno==321); - case 322: /* expression ::= pseudo_column */ yytestcase(yyruleno==322); - case 323: /* expression ::= column_reference */ yytestcase(yyruleno==323); - case 324: /* expression ::= function_expression */ yytestcase(yyruleno==324); - case 325: /* expression ::= subquery */ yytestcase(yyruleno==325); - case 352: /* function_expression ::= literal_func */ yytestcase(yyruleno==352); - case 394: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==394); - case 398: /* boolean_primary ::= predicate */ yytestcase(yyruleno==398); - case 400: /* common_expression ::= expression */ yytestcase(yyruleno==400); - case 401: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==401); - case 404: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==404); - case 406: /* table_reference ::= table_primary */ yytestcase(yyruleno==406); - case 407: /* table_reference ::= joined_table */ yytestcase(yyruleno==407); - case 411: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==411); - case 461: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==461); - case 464: /* query_primary ::= query_specification */ yytestcase(yyruleno==464); -{ yylhsminor.yy652 = yymsp[0].minor.yy652; } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 292: /* literal ::= duration_literal */ + case 302: /* signed_literal ::= signed */ yytestcase(yyruleno==302); + case 322: /* expression ::= literal */ yytestcase(yyruleno==322); + case 323: /* expression ::= pseudo_column */ yytestcase(yyruleno==323); + case 324: /* expression ::= column_reference */ yytestcase(yyruleno==324); + case 325: /* expression ::= function_expression */ yytestcase(yyruleno==325); + case 326: /* expression ::= subquery */ yytestcase(yyruleno==326); + case 353: /* function_expression ::= literal_func */ yytestcase(yyruleno==353); + case 395: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==395); + case 399: /* boolean_primary ::= predicate */ yytestcase(yyruleno==399); + case 401: /* common_expression ::= expression */ yytestcase(yyruleno==401); + case 402: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==402); + case 405: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==405); + case 407: /* table_reference ::= table_primary */ yytestcase(yyruleno==407); + case 408: /* table_reference ::= joined_table */ yytestcase(yyruleno==408); + case 412: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==412); + case 462: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==462); + case 465: /* query_primary ::= query_specification */ yytestcase(yyruleno==465); +{ yylhsminor.yy560 = yymsp[0].minor.yy560; } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 292: /* literal ::= NULL */ -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 293: /* literal ::= NULL */ +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 293: /* literal ::= NK_QUESTION */ -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 294: /* literal ::= NK_QUESTION */ +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 294: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 295: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 295: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 296: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 296: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 297: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; - case 297: /* signed ::= NK_MINUS NK_INTEGER */ + case 298: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 298: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 299: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 299: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 300: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 300: /* signed ::= NK_MINUS NK_FLOAT */ + case 301: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 302: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 303: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 303: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 304: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 304: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 305: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 305: /* signed_literal ::= duration_literal */ - case 307: /* signed_literal ::= literal_func */ yytestcase(yyruleno==307); - case 372: /* star_func_para ::= expression */ yytestcase(yyruleno==372); - case 427: /* select_item ::= common_expression */ yytestcase(yyruleno==427); - case 477: /* search_condition ::= common_expression */ yytestcase(yyruleno==477); -{ yylhsminor.yy652 = releaseRawExprNode(pCxt, yymsp[0].minor.yy652); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 306: /* signed_literal ::= duration_literal */ + case 308: /* signed_literal ::= literal_func */ yytestcase(yyruleno==308); + case 373: /* star_func_para ::= expression */ yytestcase(yyruleno==373); + case 428: /* select_item ::= common_expression */ yytestcase(yyruleno==428); + case 478: /* search_condition ::= common_expression */ yytestcase(yyruleno==478); +{ yylhsminor.yy560 = releaseRawExprNode(pCxt, yymsp[0].minor.yy560); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 306: /* signed_literal ::= NULL */ -{ yylhsminor.yy652 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 307: /* signed_literal ::= NULL */ +{ yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 326: /* expression ::= NK_LP expression NK_RP */ - case 399: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==399); -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy652)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 327: /* expression ::= NK_LP expression NK_RP */ + case 400: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==400); +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy560)); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 327: /* expression ::= NK_PLUS expression */ + case 328: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy652)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy560)); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 328: /* expression ::= NK_MINUS expression */ + case 329: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy652), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy560), NULL)); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 329: /* expression ::= expression NK_PLUS expression */ + case 330: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 330: /* expression ::= expression NK_MINUS expression */ + case 331: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 331: /* expression ::= expression NK_STAR expression */ + case 332: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 332: /* expression ::= expression NK_SLASH expression */ + case 333: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 333: /* expression ::= expression NK_REM expression */ + case 334: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 334: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 335: /* expression ::= column_reference NK_ARROW NK_STRING */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 335: /* expression ::= expression NK_BITAND expression */ + case 336: /* expression ::= expression NK_BITAND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 336: /* expression ::= expression NK_BITOR expression */ + case 337: /* expression ::= expression NK_BITOR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 339: /* column_reference ::= column_name */ -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy5, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy5)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 340: /* column_reference ::= column_name */ +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy533, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy533)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 340: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5, createColumnNode(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy5)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 341: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy533, createColumnNode(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy533)); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 341: /* pseudo_column ::= ROWTS */ - case 342: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==342); - case 344: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==344); - case 345: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==345); - case 346: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==346); - case 347: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==347); - case 348: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==348); - case 354: /* literal_func ::= NOW */ yytestcase(yyruleno==354); -{ yylhsminor.yy652 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 342: /* pseudo_column ::= ROWTS */ + case 343: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==343); + case 345: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==345); + case 346: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==346); + case 347: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==347); + case 348: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==348); + case 349: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==349); + case 355: /* literal_func ::= NOW */ yytestcase(yyruleno==355); +{ yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 343: /* pseudo_column ::= table_name NK_DOT TBNAME */ -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy5)))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 344: /* pseudo_column ::= table_name NK_DOT TBNAME */ +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy533)))); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 349: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 350: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==350); -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy5, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy5, yymsp[-1].minor.yy210)); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + case 350: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 351: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==351); +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy533, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy533, yymsp[-1].minor.yy712)); } + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 351: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy652), yymsp[-1].minor.yy552)); } - yymsp[-5].minor.yy652 = yylhsminor.yy652; + case 352: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), yymsp[-1].minor.yy196)); } + yymsp[-5].minor.yy560 = yylhsminor.yy560; break; - case 353: /* literal_func ::= noarg_func NK_LP NK_RP */ -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy5, NULL)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 354: /* literal_func ::= noarg_func NK_LP NK_RP */ +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy533, NULL)); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 368: /* star_func_para_list ::= NK_STAR */ -{ yylhsminor.yy210 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy210 = yylhsminor.yy210; + case 369: /* star_func_para_list ::= NK_STAR */ +{ yylhsminor.yy712 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy712 = yylhsminor.yy712; break; - case 373: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 430: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==430); -{ yylhsminor.yy652 = createColumnNode(pCxt, &yymsp[-2].minor.yy5, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 374: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 431: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==431); +{ yylhsminor.yy560 = createColumnNode(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 374: /* predicate ::= expression compare_op expression */ - case 379: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==379); + case 375: /* predicate ::= expression compare_op expression */ + case 380: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==380); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy428, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy128, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 375: /* predicate ::= expression BETWEEN expression AND expression */ + case 376: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy652), releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy560), releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-4].minor.yy652 = yylhsminor.yy652; + yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 376: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 377: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy652), releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy560), releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-5].minor.yy652 = yylhsminor.yy652; + yymsp[-5].minor.yy560 = yylhsminor.yy560; break; - case 377: /* predicate ::= expression IS NULL */ + case 378: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), NULL)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 378: /* predicate ::= expression IS NOT NULL */ + case 379: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy652), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), NULL)); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 380: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy428 = OP_TYPE_LOWER_THAN; } + case 381: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy128 = OP_TYPE_LOWER_THAN; } break; - case 381: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy428 = OP_TYPE_GREATER_THAN; } + case 382: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy128 = OP_TYPE_GREATER_THAN; } break; - case 382: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy428 = OP_TYPE_LOWER_EQUAL; } + case 383: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy128 = OP_TYPE_LOWER_EQUAL; } break; - case 383: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy428 = OP_TYPE_GREATER_EQUAL; } + case 384: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy128 = OP_TYPE_GREATER_EQUAL; } break; - case 384: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy428 = OP_TYPE_NOT_EQUAL; } + case 385: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy128 = OP_TYPE_NOT_EQUAL; } break; - case 385: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy428 = OP_TYPE_EQUAL; } + case 386: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy128 = OP_TYPE_EQUAL; } break; - case 386: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy428 = OP_TYPE_LIKE; } + case 387: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy128 = OP_TYPE_LIKE; } break; - case 387: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy428 = OP_TYPE_NOT_LIKE; } + case 388: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy128 = OP_TYPE_NOT_LIKE; } break; - case 388: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy428 = OP_TYPE_MATCH; } + case 389: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy128 = OP_TYPE_MATCH; } break; - case 389: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy428 = OP_TYPE_NMATCH; } + case 390: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy128 = OP_TYPE_NMATCH; } break; - case 390: /* compare_op ::= CONTAINS */ -{ yymsp[0].minor.yy428 = OP_TYPE_JSON_CONTAINS; } + case 391: /* compare_op ::= CONTAINS */ +{ yymsp[0].minor.yy128 = OP_TYPE_JSON_CONTAINS; } break; - case 391: /* in_op ::= IN */ -{ yymsp[0].minor.yy428 = OP_TYPE_IN; } + case 392: /* in_op ::= IN */ +{ yymsp[0].minor.yy128 = OP_TYPE_IN; } break; - case 392: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy428 = OP_TYPE_NOT_IN; } + case 393: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy128 = OP_TYPE_NOT_IN; } break; - case 393: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy210)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 394: /* in_predicate_value ::= NK_LP literal_list NK_RP */ +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy712)); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 395: /* boolean_value_expression ::= NOT boolean_primary */ + case 396: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy652), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy560), NULL)); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 396: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 397: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 397: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 398: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy652); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy652); - yylhsminor.yy652 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); + yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 405: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy652 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy652, yymsp[0].minor.yy652, NULL); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 406: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy560 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy560, yymsp[0].minor.yy560, NULL); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 408: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy652 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy5, &yymsp[0].minor.yy5); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 409: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy560 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy533, &yymsp[0].minor.yy533); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 409: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy652 = createRealTableNode(pCxt, &yymsp[-3].minor.yy5, &yymsp[-1].minor.yy5, &yymsp[0].minor.yy5); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + case 410: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy560 = createRealTableNode(pCxt, &yymsp[-3].minor.yy533, &yymsp[-1].minor.yy533, &yymsp[0].minor.yy533); } + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 410: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy652 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy652), &yymsp[0].minor.yy5); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 411: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy560 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy560), &yymsp[0].minor.yy533); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 412: /* alias_opt ::= */ -{ yymsp[1].minor.yy5 = nil_token; } + case 413: /* alias_opt ::= */ +{ yymsp[1].minor.yy533 = nil_token; } break; - case 413: /* alias_opt ::= table_alias */ -{ yylhsminor.yy5 = yymsp[0].minor.yy5; } - yymsp[0].minor.yy5 = yylhsminor.yy5; + case 414: /* alias_opt ::= table_alias */ +{ yylhsminor.yy533 = yymsp[0].minor.yy533; } + yymsp[0].minor.yy533 = yylhsminor.yy533; break; - case 414: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy5 = yymsp[0].minor.yy5; } + case 415: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy533 = yymsp[0].minor.yy533; } break; - case 415: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 416: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==416); -{ yymsp[-2].minor.yy652 = yymsp[-1].minor.yy652; } + case 416: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 417: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==417); +{ yymsp[-2].minor.yy560 = yymsp[-1].minor.yy560; } break; - case 417: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy652 = createJoinTableNode(pCxt, yymsp[-4].minor.yy74, yymsp[-5].minor.yy652, yymsp[-2].minor.yy652, yymsp[0].minor.yy652); } - yymsp[-5].minor.yy652 = yylhsminor.yy652; + case 418: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy560 = createJoinTableNode(pCxt, yymsp[-4].minor.yy36, yymsp[-5].minor.yy560, yymsp[-2].minor.yy560, yymsp[0].minor.yy560); } + yymsp[-5].minor.yy560 = yylhsminor.yy560; break; - case 418: /* join_type ::= */ -{ yymsp[1].minor.yy74 = JOIN_TYPE_INNER; } + case 419: /* join_type ::= */ +{ yymsp[1].minor.yy36 = JOIN_TYPE_INNER; } break; - case 419: /* join_type ::= INNER */ -{ yymsp[0].minor.yy74 = JOIN_TYPE_INNER; } + case 420: /* join_type ::= INNER */ +{ yymsp[0].minor.yy36 = JOIN_TYPE_INNER; } break; - case 420: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 421: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-11].minor.yy652 = createSelectStmt(pCxt, yymsp[-10].minor.yy403, yymsp[-9].minor.yy210, yymsp[-8].minor.yy652); - yymsp[-11].minor.yy652 = addWhereClause(pCxt, yymsp[-11].minor.yy652, yymsp[-7].minor.yy652); - yymsp[-11].minor.yy652 = addPartitionByClause(pCxt, yymsp[-11].minor.yy652, yymsp[-6].minor.yy210); - yymsp[-11].minor.yy652 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy652, yymsp[-2].minor.yy652); - yymsp[-11].minor.yy652 = addGroupByClause(pCxt, yymsp[-11].minor.yy652, yymsp[-1].minor.yy210); - yymsp[-11].minor.yy652 = addHavingClause(pCxt, yymsp[-11].minor.yy652, yymsp[0].minor.yy652); - yymsp[-11].minor.yy652 = addRangeClause(pCxt, yymsp[-11].minor.yy652, yymsp[-5].minor.yy652); - yymsp[-11].minor.yy652 = addEveryClause(pCxt, yymsp[-11].minor.yy652, yymsp[-4].minor.yy652); - yymsp[-11].minor.yy652 = addFillClause(pCxt, yymsp[-11].minor.yy652, yymsp[-3].minor.yy652); + yymsp[-11].minor.yy560 = createSelectStmt(pCxt, yymsp[-10].minor.yy173, yymsp[-9].minor.yy712, yymsp[-8].minor.yy560); + yymsp[-11].minor.yy560 = addWhereClause(pCxt, yymsp[-11].minor.yy560, yymsp[-7].minor.yy560); + yymsp[-11].minor.yy560 = addPartitionByClause(pCxt, yymsp[-11].minor.yy560, yymsp[-6].minor.yy712); + yymsp[-11].minor.yy560 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy560, yymsp[-2].minor.yy560); + yymsp[-11].minor.yy560 = addGroupByClause(pCxt, yymsp[-11].minor.yy560, yymsp[-1].minor.yy712); + yymsp[-11].minor.yy560 = addHavingClause(pCxt, yymsp[-11].minor.yy560, yymsp[0].minor.yy560); + yymsp[-11].minor.yy560 = addRangeClause(pCxt, yymsp[-11].minor.yy560, yymsp[-5].minor.yy560); + yymsp[-11].minor.yy560 = addEveryClause(pCxt, yymsp[-11].minor.yy560, yymsp[-4].minor.yy560); + yymsp[-11].minor.yy560 = addFillClause(pCxt, yymsp[-11].minor.yy560, yymsp[-3].minor.yy560); } break; - case 423: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy403 = false; } + case 424: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy173 = false; } break; - case 426: /* select_item ::= NK_STAR */ -{ yylhsminor.yy652 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 427: /* select_item ::= NK_STAR */ +{ yylhsminor.yy560 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 428: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy652 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy652), &yymsp[0].minor.yy5); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; + case 429: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy560 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy560), &yymsp[0].minor.yy533); } + yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 429: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy652 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), &yymsp[0].minor.yy5); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 430: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy560 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), &yymsp[0].minor.yy533); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 434: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 451: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==451); - case 467: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==467); -{ yymsp[-2].minor.yy210 = yymsp[0].minor.yy210; } + case 435: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 452: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==452); + case 468: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==468); +{ yymsp[-2].minor.yy712 = yymsp[0].minor.yy712; } break; - case 436: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy652 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy652), releaseRawExprNode(pCxt, yymsp[-1].minor.yy652)); } + case 437: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy560 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), releaseRawExprNode(pCxt, yymsp[-1].minor.yy560)); } break; - case 437: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy652 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy652)); } + case 438: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy560 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy560)); } break; - case 438: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy652 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy652), NULL, yymsp[-1].minor.yy652, yymsp[0].minor.yy652); } + case 439: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy560 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), NULL, yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } break; - case 439: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy652 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy652), releaseRawExprNode(pCxt, yymsp[-3].minor.yy652), yymsp[-1].minor.yy652, yymsp[0].minor.yy652); } + case 440: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy560 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy560), releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } break; - case 441: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - case 459: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==459); -{ yymsp[-3].minor.yy652 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy652); } + case 442: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + case 460: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==460); +{ yymsp[-3].minor.yy560 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy560); } break; - case 443: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy652 = createFillNode(pCxt, yymsp[-1].minor.yy270, NULL); } + case 444: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy560 = createFillNode(pCxt, yymsp[-1].minor.yy18, NULL); } break; - case 444: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy652 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy210)); } + case 445: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy560 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy712)); } break; - case 445: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy270 = FILL_MODE_NONE; } + case 446: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy18 = FILL_MODE_NONE; } break; - case 446: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy270 = FILL_MODE_PREV; } + case 447: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy18 = FILL_MODE_PREV; } break; - case 447: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy270 = FILL_MODE_NULL; } + case 448: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy18 = FILL_MODE_NULL; } break; - case 448: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy270 = FILL_MODE_LINEAR; } + case 449: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy18 = FILL_MODE_LINEAR; } break; - case 449: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy270 = FILL_MODE_NEXT; } + case 450: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy18 = FILL_MODE_NEXT; } break; - case 452: /* group_by_list ::= expression */ -{ yylhsminor.yy210 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); } - yymsp[0].minor.yy210 = yylhsminor.yy210; + case 453: /* group_by_list ::= expression */ +{ yylhsminor.yy712 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } + yymsp[0].minor.yy712 = yylhsminor.yy712; break; - case 453: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy210 = addNodeToList(pCxt, yymsp[-2].minor.yy210, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy652))); } - yymsp[-2].minor.yy210 = yylhsminor.yy210; + case 454: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-2].minor.yy712, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } + yymsp[-2].minor.yy712 = yylhsminor.yy712; break; - case 457: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ -{ yymsp[-5].minor.yy652 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy652), releaseRawExprNode(pCxt, yymsp[-1].minor.yy652)); } + case 458: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ +{ yymsp[-5].minor.yy560 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), releaseRawExprNode(pCxt, yymsp[-1].minor.yy560)); } break; - case 460: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 461: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy652 = addOrderByClause(pCxt, yymsp[-3].minor.yy652, yymsp[-2].minor.yy210); - yylhsminor.yy652 = addSlimitClause(pCxt, yylhsminor.yy652, yymsp[-1].minor.yy652); - yylhsminor.yy652 = addLimitClause(pCxt, yylhsminor.yy652, yymsp[0].minor.yy652); + yylhsminor.yy560 = addOrderByClause(pCxt, yymsp[-3].minor.yy560, yymsp[-2].minor.yy712); + yylhsminor.yy560 = addSlimitClause(pCxt, yylhsminor.yy560, yymsp[-1].minor.yy560); + yylhsminor.yy560 = addLimitClause(pCxt, yylhsminor.yy560, yymsp[0].minor.yy560); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 462: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy652 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy652, yymsp[0].minor.yy652); } - yymsp[-3].minor.yy652 = yylhsminor.yy652; + case 463: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy560 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy560, yymsp[0].minor.yy560); } + yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 463: /* query_expression_body ::= query_expression_body UNION query_expression_body */ -{ yylhsminor.yy652 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy652, yymsp[0].minor.yy652); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 464: /* query_expression_body ::= query_expression_body UNION query_expression_body */ +{ yylhsminor.yy560 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy560, yymsp[0].minor.yy560); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 465: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ -{ yymsp[-5].minor.yy652 = yymsp[-4].minor.yy652; } - yy_destructor(yypParser,369,&yymsp[-3].minor); - yy_destructor(yypParser,370,&yymsp[-2].minor); - yy_destructor(yypParser,371,&yymsp[-1].minor); + case 466: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ +{ + yymsp[-5].minor.yy560 = addOrderByClause(pCxt, yymsp[-4].minor.yy560, yymsp[-3].minor.yy712); + yymsp[-5].minor.yy560 = addSlimitClause(pCxt, yymsp[-5].minor.yy560, yymsp[-2].minor.yy560); + yymsp[-5].minor.yy560 = addLimitClause(pCxt, yymsp[-5].minor.yy560, yymsp[-1].minor.yy560); + } break; - case 469: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 473: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==473); -{ yymsp[-1].minor.yy652 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 470: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 474: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==474); +{ yymsp[-1].minor.yy560 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 470: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 474: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==474); -{ yymsp[-3].minor.yy652 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 471: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 475: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==475); +{ yymsp[-3].minor.yy560 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 471: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 475: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==475); -{ yymsp[-3].minor.yy652 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 472: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 476: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==476); +{ yymsp[-3].minor.yy560 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 476: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy652 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy652); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 477: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy560); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 480: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy652 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy652), yymsp[-1].minor.yy553, yymsp[0].minor.yy477); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 481: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy560 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), yymsp[-1].minor.yy218, yymsp[0].minor.yy109); } + yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 481: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy553 = ORDER_ASC; } + case 482: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy218 = ORDER_ASC; } break; - case 482: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy553 = ORDER_ASC; } + case 483: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy218 = ORDER_ASC; } break; - case 483: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy553 = ORDER_DESC; } + case 484: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy218 = ORDER_DESC; } break; - case 484: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy477 = NULL_ORDER_DEFAULT; } + case 485: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy109 = NULL_ORDER_DEFAULT; } break; - case 485: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy477 = NULL_ORDER_FIRST; } + case 486: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy109 = NULL_ORDER_FIRST; } break; - case 486: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy477 = NULL_ORDER_LAST; } + case 487: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy109 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp index b39a066ba1..e9c8fb5326 100644 --- a/source/libs/parser/test/parInitialCTest.cpp +++ b/source/libs/parser/test/parInitialCTest.cpp @@ -76,8 +76,8 @@ TEST_F(ParserInitialCTest, createDatabase) { expect.db[len] = '\0'; expect.ignoreExist = igExists; expect.buffer = TSDB_DEFAULT_BUFFER_PER_VNODE; - expect.cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW; - expect.lastRowMem = TSDB_DEFAULT_LAST_ROW_MEM; + expect.cacheLast = TSDB_DEFAULT_CACHE_LAST; + expect.cacheLastSize = TSDB_DEFAULT_CACHE_LAST_SIZE; expect.compression = TSDB_DEFAULT_COMP_LEVEL; expect.daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; expect.fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; @@ -98,8 +98,8 @@ TEST_F(ParserInitialCTest, createDatabase) { }; auto setDbBufferFunc = [&](int32_t buffer) { expect.buffer = buffer; }; - auto setDbCachelastFunc = [&](int8_t cachelast) { expect.cacheLastRow = cachelast; }; - auto setDbCachelastSize = [&](int8_t cachelastSize) { expect.lastRowMem = cachelastSize; }; + auto setDbCachelastFunc = [&](int8_t cachelast) { expect.cacheLast = cachelast; }; + auto setDbCachelastSize = [&](int8_t cachelastSize) { expect.cacheLastSize = cachelastSize; }; auto setDbCompressionFunc = [&](int8_t compressionLevel) { expect.compression = compressionLevel; }; auto setDbDaysFunc = [&](int32_t daysPerFile) { expect.daysPerFile = daysPerFile; }; auto setDbFsyncFunc = [&](int32_t fsyncPeriod) { expect.fsyncPeriod = fsyncPeriod; }; @@ -155,8 +155,8 @@ TEST_F(ParserInitialCTest, createDatabase) { ASSERT_EQ(req.compression, expect.compression); ASSERT_EQ(req.replications, expect.replications); ASSERT_EQ(req.strict, expect.strict); - ASSERT_EQ(req.cacheLastRow, expect.cacheLastRow); - ASSERT_EQ(req.lastRowMem, expect.lastRowMem); + ASSERT_EQ(req.cacheLast, expect.cacheLast); + ASSERT_EQ(req.cacheLastSize, expect.cacheLastSize); // ASSERT_EQ(req.schemaless, expect.schemaless); ASSERT_EQ(req.ignoreExist, expect.ignoreExist); ASSERT_EQ(req.numOfRetensions, expect.numOfRetensions); diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp index 4ca2dec299..0aa1773c28 100644 --- a/source/libs/parser/test/parSelectTest.cpp +++ b/source/libs/parser/test/parSelectTest.cpp @@ -144,9 +144,9 @@ TEST_F(ParserSelectTest, IndefiniteRowsFunc) { TEST_F(ParserSelectTest, IndefiniteRowsFuncSemanticCheck) { useDb("root", "test"); - run("SELECT DIFF(c1), c2 FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC); + run("SELECT DIFF(c1), c2 FROM t1", TSDB_CODE_PAR_NOT_SINGLE_GROUP); - run("SELECT DIFF(c1), tbname FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC); + run("SELECT DIFF(c1), tbname FROM t1", TSDB_CODE_PAR_NOT_SINGLE_GROUP); run("SELECT DIFF(c1), count(*) FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC); @@ -245,13 +245,21 @@ TEST_F(ParserSelectTest, orderBy) { TEST_F(ParserSelectTest, distinct) { useDb("root", "test"); - // run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by c1"); + run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by c1"); - // run("SELECT distinct c1 + 10, c2 FROM t1 WHERE c1 > 0 order by c1 + 10, c2"); + run("SELECT distinct c1 + 10, c2 FROM t1 WHERE c1 > 0 order by c1 + 10, c2"); - // run("SELECT distinct c1 + 10 cc1, c2 cc2 FROM t1 WHERE c1 > 0 order by cc1, c2"); + run("SELECT distinct c1 + 10 cc1, c2 cc2 FROM t1 WHERE c1 > 0 order by cc1, c2"); - // run("SELECT distinct COUNT(c2) FROM t1 WHERE c1 > 0 GROUP BY c1 order by COUNT(c2)"); + run("SELECT distinct COUNT(c2) FROM t1 WHERE c1 > 0 GROUP BY c1 order by COUNT(c2)"); +} + +TEST_F(ParserSelectTest, limit) { + useDb("root", "test"); + + run("SELECT c1, c2 FROM t1 LIMIT 10"); + + run("(SELECT c1, c2 FROM t1 LIMIT 10)"); } // INTERVAL(interval_val [, interval_offset]) [SLIDING (sliding_val)] [FILL(fill_mod_and_val)] @@ -273,7 +281,7 @@ TEST_F(ParserSelectTest, interval) { TEST_F(ParserSelectTest, intervalSemanticCheck) { useDb("root", "test"); - run("SELECT c1 FROM t1 INTERVAL(10s)", TSDB_CODE_PAR_NOT_SINGLE_GROUP); + run("SELECT c1 FROM t1 INTERVAL(10s)", TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN); run("SELECT DISTINCT c1, c2 FROM t1 WHERE c1 > 3 INTERVAL(1d) FILL(NEXT)", TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE); run("SELECT HISTOGRAM(c1, 'log_bin', '{\"start\": -33,\"factor\": 55,\"count\": 5,\"infinity\": false}', 1) FROM t1 " "WHERE ts > TIMESTAMP '2022-04-01 00:00:00' and ts < TIMESTAMP '2022-04-30 23:59:59' INTERVAL(10s) FILL(NULL)", @@ -329,70 +337,69 @@ TEST_F(ParserSelectTest, semanticCheck) { useDb("root", "test"); // TSDB_CODE_PAR_INVALID_COLUMN - run("SELECT c1, cc1 FROM t1", TSDB_CODE_PAR_INVALID_COLUMN, PARSER_STAGE_TRANSLATE); + run("SELECT c1, cc1 FROM t1", TSDB_CODE_PAR_INVALID_COLUMN); - run("SELECT t1.c1, t1.cc1 FROM t1", TSDB_CODE_PAR_INVALID_COLUMN, PARSER_STAGE_TRANSLATE); + run("SELECT t1.c1, t1.cc1 FROM t1", TSDB_CODE_PAR_INVALID_COLUMN); // TSDB_CODE_PAR_TABLE_NOT_EXIST - run("SELECT * FROM t10", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + run("SELECT * FROM t10", TSDB_CODE_PAR_TABLE_NOT_EXIST); - run("SELECT * FROM test.t10", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + run("SELECT * FROM test.t10", TSDB_CODE_PAR_TABLE_NOT_EXIST); - run("SELECT t2.c1 FROM t1", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + run("SELECT t2.c1 FROM t1", TSDB_CODE_PAR_TABLE_NOT_EXIST); // TSDB_CODE_PAR_AMBIGUOUS_COLUMN - run("SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1", TSDB_CODE_PAR_AMBIGUOUS_COLUMN, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1", TSDB_CODE_PAR_AMBIGUOUS_COLUMN); - run("SELECT c2 FROM (SELECT c1 c2, c2 FROM t1)", TSDB_CODE_PAR_AMBIGUOUS_COLUMN, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM (SELECT c1 c2, c2 FROM t1)", TSDB_CODE_PAR_AMBIGUOUS_COLUMN); // TSDB_CODE_PAR_WRONG_VALUE_TYPE - run("SELECT timestamp '2010a' FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE); + run("SELECT timestamp '2010a' FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE); - run("SELECT LAST(*) + SUM(c1) FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE); + run("SELECT LAST(*) + SUM(c1) FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE); - run("SELECT CEIL(LAST(ts, c1)) FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE); + run("SELECT CEIL(LAST(ts, c1)) FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE); // TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION - run("SELECT c2 FROM t1 tt1 join t1 tt2 on COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, - PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 tt1 join t1 tt2 on COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); - run("SELECT c2 FROM t1 WHERE COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 WHERE COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); - run("SELECT c2 FROM t1 GROUP BY COUNT(*)", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 GROUP BY COUNT(*)", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); // TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT - run("SELECT c2 FROM t1 order by 0", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 order by 0", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT); - run("SELECT c2 FROM t1 order by 2", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 order by 2", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT); // TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION - run("SELECT COUNT(*) cnt FROM t1 having c1 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*) cnt FROM t1 having c1 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION); - run("SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c1 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c1 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION); - run("SELECT COUNT(*), c1 cnt FROM t1 GROUP BY c2 having c2 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*), c1 cnt FROM t1 GROUP BY c2 having c2 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION); - run("SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c2 > 0 order by c1", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c2 > 0 order by c1", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION); // TSDB_CODE_PAR_NOT_SINGLE_GROUP - run("SELECT COUNT(*), c1 FROM t1", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*), c1 FROM t1", TSDB_CODE_PAR_NOT_SINGLE_GROUP); - run("SELECT COUNT(*) FROM t1 order by c1", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*) FROM t1 order by c1", TSDB_CODE_PAR_NOT_SINGLE_GROUP); - run("SELECT c1 FROM t1 order by COUNT(*)", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + run("SELECT c1 FROM t1 order by COUNT(*)", TSDB_CODE_PAR_NOT_SINGLE_GROUP); // TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION - run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by ts", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by ts", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION); - run("SELECT distinct c1 FROM t1 WHERE c1 > 0 order by COUNT(c2)", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT distinct c1 FROM t1 WHERE c1 > 0 order by COUNT(c2)", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION); - run("SELECT distinct c2 FROM t1 WHERE c1 > 0 order by COUNT(c2)", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT distinct c2 FROM t1 WHERE c1 > 0 order by COUNT(c2)", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION); +} + +TEST_F(ParserSelectTest, syntaxError) { + useDb("root", "test"); + + run("SELECT CAST(? AS BINARY(10)) FROM t1", TSDB_CODE_PAR_SYNTAX_ERROR, PARSER_STAGE_PARSE); } TEST_F(ParserSelectTest, setOperator) { diff --git a/source/libs/parser/test/parShowToUse.cpp b/source/libs/parser/test/parShowToUse.cpp index e109781169..eecb291554 100644 --- a/source/libs/parser/test/parShowToUse.cpp +++ b/source/libs/parser/test/parShowToUse.cpp @@ -222,6 +222,25 @@ TEST_F(ParserShowToUseTest, splitVgroup) { run("SPLIT VGROUP 15"); } +TEST_F(ParserShowToUseTest, trimDatabase) { + useDb("root", "test"); + + STrimDbReq expect = {0}; + + auto setTrimDbReq = [&](const char* pDb) { snprintf(expect.db, sizeof(expect.db), "0.%s", pDb); }; + + setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { + ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_TRIM_DATABASE_STMT); + ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_TRIM_DB); + STrimDbReq req = {0}; + ASSERT_EQ(tDeserializeSTrimDbReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS); + ASSERT_EQ(std::string(req.db), std::string(expect.db)); + }); + + setTrimDbReq("wxy_db"); + run("TRIM DATABASE wxy_db"); +} + TEST_F(ParserShowToUseTest, useDatabase) { useDb("root", "test"); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 703395b0d5..cb38e1fc18 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -485,10 +485,6 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, code = rewriteExprsForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY); } - if (NULL != pSelect->pPartitionByList) { - code = createGroupKeysFromPartKeys(pSelect->pPartitionByList, &pAgg->pGroupKeys); - } - if (NULL != pSelect->pGroupByList) { if (NULL != pAgg->pGroupKeys) { code = nodesListStrictAppendList(pAgg->pGroupKeys, nodesCloneList(pSelect->pGroupByList)); @@ -845,8 +841,7 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel } static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { - if (NULL == pSelect->pPartitionByList || (pSelect->hasAggFuncs && NULL == pSelect->pWindow) || - NULL != pSelect->pGroupByList) { + if (NULL == pSelect->pPartitionByList) { return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 67b79d5b1c..dee7bd49db 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -80,6 +80,23 @@ static void optResetParent(SLogicNode* pNode) { FOREACH(pChild, pNode->pChildren) { ((SLogicNode*)pChild)->pParent = pNode; } } +static EDealRes optRebuildTbanme(SNode** pNode, void* pContext) { + if (QUERY_NODE_COLUMN == nodeType(*pNode) && COLUMN_TYPE_TBNAME == ((SColumnNode*)*pNode)->colType) { + SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pFunc) { + *(int32_t*)pContext = TSDB_CODE_OUT_OF_MEMORY; + return DEAL_RES_ERROR; + } + strcpy(pFunc->functionName, "tbname"); + pFunc->funcType = FUNCTION_TYPE_TBNAME; + pFunc->node.resType = ((SColumnNode*)*pNode)->node.resType; + nodesDestroyNode(*pNode); + *pNode = (SNode*)pFunc; + return DEAL_RES_IGNORE_CHILD; + } + return DEAL_RES_CONTINUE; +} + EDealRes scanPathOptHaveNormalColImpl(SNode* pNode, void* pContext) { if (QUERY_NODE_COLUMN == nodeType(pNode)) { // *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType); @@ -312,6 +329,12 @@ static int32_t pushDownCondOptCalcTimeRange(SOptimizeContext* pCxt, SScanLogicNo return code; } +static int32_t pushDownCondOptRebuildTbanme(SNode** pTagCond) { + int32_t code = TSDB_CODE_SUCCESS; + nodesRewriteExpr(pTagCond, optRebuildTbanme, &code); + return code; +} + static int32_t pushDownCondOptDealScan(SOptimizeContext* pCxt, SScanLogicNode* pScan) { if (NULL == pScan->node.pConditions || OPTIMIZE_FLAG_TEST_MASK(pScan->node.optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE) || @@ -323,6 +346,9 @@ static int32_t pushDownCondOptDealScan(SOptimizeContext* pCxt, SScanLogicNode* p SNode* pOtherCond = NULL; int32_t code = nodesPartitionCond(&pScan->node.pConditions, &pPrimaryKeyCond, &pScan->pTagIndexCond, &pScan->pTagCond, &pOtherCond); + if (TSDB_CODE_SUCCESS == code && NULL != pScan->pTagCond) { + code = pushDownCondOptRebuildTbanme(&pScan->pTagCond); + } if (TSDB_CODE_SUCCESS == code && NULL != pPrimaryKeyCond) { code = pushDownCondOptCalcTimeRange(pCxt, pScan, &pPrimaryKeyCond, &pOtherCond); } @@ -896,7 +922,7 @@ static int32_t pushDownCondOptTrivialPushDown(SOptimizeContext* pCxt, SLogicNode return TSDB_CODE_SUCCESS; } SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pLogicNode->pChildren, 0); - int32_t code = pushDownCondOptPushCondToChild(pCxt, pChild, &pLogicNode->pConditions); + int32_t code = pushDownCondOptPushCondToChild(pCxt, pChild, &pLogicNode->pConditions); if (TSDB_CODE_SUCCESS == code) { OPTIMIZE_FLAG_SET_MASK(pLogicNode->optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE); pCxt->optimized = true; @@ -1010,8 +1036,13 @@ static int32_t sortPriKeyOptApply(SOptimizeContext* pCxt, SLogicSubplan* pLogicS SNodeList* pScanNodes) { EOrder order = sortPriKeyOptGetPriKeyOrder(pSort); if (ORDER_DESC == order) { - SNode* pScan = NULL; - FOREACH(pScan, pScanNodes) { TSWAP(((SScanLogicNode*)pScan)->scanSeq[0], ((SScanLogicNode*)pScan)->scanSeq[1]); } + SNode* pScanNode = NULL; + FOREACH(pScanNode, pScanNodes) { + SScanLogicNode* pScan = (SScanLogicNode*)pScanNode; + if (pScan->scanSeq[0] > 0) { + TSWAP(pScan->scanSeq[0], pScan->scanSeq[1]); + } + } } int32_t code = @@ -1020,6 +1051,7 @@ static int32_t sortPriKeyOptApply(SOptimizeContext* pCxt, SLogicSubplan* pLogicS NODES_CLEAR_LIST(pSort->node.pChildren); nodesDestroyNode((SNode*)pSort); } + pCxt->optimized = true; return code; } @@ -1183,7 +1215,7 @@ static int32_t smaIndexOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNo if (smaFuncIndex < 0) { break; } else { - code = nodesListMakeStrictAppend(&pCols, smaIndexOptCreateSmaCol(pFunc, tableId, smaFuncIndex + 2)); + code = nodesListMakeStrictAppend(&pCols, smaIndexOptCreateSmaCol(pFunc, tableId, smaFuncIndex + 1)); if (TSDB_CODE_SUCCESS != code) { break; } @@ -1380,26 +1412,9 @@ static bool partTagsOptMayBeOptimized(SLogicNode* pNode) { return !partTagsOptHasCol(partTagsGetPartKeys(pNode)) && partTagsOptAreSupportedFuncs(partTagsGetFuncs(pNode)); } -static EDealRes partTagsOptRebuildTbanmeImpl(SNode** pNode, void* pContext) { - if (QUERY_NODE_COLUMN == nodeType(*pNode) && COLUMN_TYPE_TBNAME == ((SColumnNode*)*pNode)->colType) { - SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); - if (NULL == pFunc) { - *(int32_t*)pContext = TSDB_CODE_OUT_OF_MEMORY; - return DEAL_RES_ERROR; - } - strcpy(pFunc->functionName, "tbname"); - pFunc->funcType = FUNCTION_TYPE_TBNAME; - pFunc->node.resType = ((SColumnNode*)*pNode)->node.resType; - nodesDestroyNode(*pNode); - *pNode = (SNode*)pFunc; - return DEAL_RES_IGNORE_CHILD; - } - return DEAL_RES_CONTINUE; -} - static int32_t partTagsOptRebuildTbanme(SNodeList* pPartKeys) { int32_t code = TSDB_CODE_SUCCESS; - nodesRewriteExprs(pPartKeys, partTagsOptRebuildTbanmeImpl, &code); + nodesRewriteExprs(pPartKeys, optRebuildTbanme, &code); return code; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 18d69d21d8..d10fe1ce0c 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -1317,10 +1317,7 @@ static int32_t createFillPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren } if (TSDB_CODE_SUCCESS == code) { - pFill->pWStartTs = nodesCloneNode(pFillNode->pWStartTs); - if (NULL == pFill->pWStartTs) { - code = TSDB_CODE_OUT_OF_MEMORY; - } + code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pFillNode->pWStartTs, &pFill->pWStartTs); } if (TSDB_CODE_SUCCESS == code && NULL != pFillNode->pValues) { diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 2137108386..d7eccf4b8e 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -945,6 +945,7 @@ static int32_t stbSplSplitPartitionNode(SSplitContext* pCxt, SStableSplitInfo* p code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren, (SNode*)splCreateScanSubplan(pCxt, pInfo->pSplitNode, SPLIT_FLAG_STABLE_SPLIT)); } + pInfo->pSubplan->subplanType = SUBPLAN_TYPE_MERGE; ++(pCxt->groupId); return code; } diff --git a/source/libs/planner/test/planIntervalTest.cpp b/source/libs/planner/test/planIntervalTest.cpp index 10ef09adb9..73fa898bf8 100644 --- a/source/libs/planner/test/planIntervalTest.cpp +++ b/source/libs/planner/test/planIntervalTest.cpp @@ -62,4 +62,6 @@ TEST_F(PlanIntervalTest, stable) { run("SELECT _WSTARTTS, COUNT(*) FROM st1 INTERVAL(10s)"); run("SELECT _WSTARTTS, COUNT(*) FROM st1 PARTITION BY TBNAME INTERVAL(10s)"); + + run("SELECT TBNAME, COUNT(*) FROM st1 PARTITION BY TBNAME INTERVAL(10s)"); } diff --git a/source/libs/planner/test/planOptimizeTest.cpp b/source/libs/planner/test/planOptimizeTest.cpp index e4019292d8..ef056c5ec8 100644 --- a/source/libs/planner/test/planOptimizeTest.cpp +++ b/source/libs/planner/test/planOptimizeTest.cpp @@ -37,6 +37,8 @@ TEST_F(PlanOptimizeTest, pushDownCondition) { run("SELECT ts, c1 FROM st1 WHERE tag1 > 4"); + run("SELECT ts, c1 FROM st1 WHERE TBNAME = 'st1s1'"); + run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 or tag1 < 2"); run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 AND tag2 = 'hello'"); diff --git a/source/libs/planner/test/planOrderByTest.cpp b/source/libs/planner/test/planOrderByTest.cpp index e542f4772f..13dfbad78c 100644 --- a/source/libs/planner/test/planOrderByTest.cpp +++ b/source/libs/planner/test/planOrderByTest.cpp @@ -53,6 +53,12 @@ TEST_F(PlanOrderByTest, withGroupBy) { run("SELECT SUM(c1) AS a FROM t1 GROUP BY c2 ORDER BY a"); } +TEST_F(PlanOrderByTest, withSubquery) { + useDb("root", "test"); + + run("SELECT ts FROM (SELECT * FROM t1 ORDER BY ts DESC) ORDER BY ts DESC"); +} + TEST_F(PlanOrderByTest, stable) { useDb("root", "test"); diff --git a/source/libs/planner/test/planPartByTest.cpp b/source/libs/planner/test/planPartByTest.cpp index 2abcb44dfd..48a4c12577 100644 --- a/source/libs/planner/test/planPartByTest.cpp +++ b/source/libs/planner/test/planPartByTest.cpp @@ -35,6 +35,10 @@ TEST_F(PlanPartitionByTest, withAggFunc) { run("select count(*) from t1 partition by c1"); + run("select count(*) from st1 partition by c1"); + + run("select sample(c1, 2) from st1 partition by c1"); + run("select count(*), c1 from t1 partition by c1"); } diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index 4780249ec9..0f90b54adb 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -330,6 +330,10 @@ class PlannerTestBaseImpl { cxt.pMsg = stmtEnv_.msgBuf_.data(); cxt.msgLen = stmtEnv_.msgBuf_.max_size(); cxt.svrVer = "3.0.0.0"; + if (prepare) { + SStmtCallback stmtCb = {0}; + cxt.pStmtCb = &stmtCb; + } DO_WITH_THROW(qParseSql, &cxt, pQuery); if (prepare) { diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 908149c3ea..ed8786170d 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -381,11 +381,11 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes; } - qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId %d db %s stb %s suid %" PRIx64 " sver %d tver %d" PRIx64 - " tagNum %d colNum %d precision %d rowSize %d", - msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName, pTableMeta->suid, - pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags, pTableMeta->tableInfo.numOfColumns, - pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize); + qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s stb %s suid %" PRIx64 " sver %d tver %d" PRIx64 + " tagNum %d colNum %d precision %d rowSize %d", + msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName, + pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags, + pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize); *pMeta = pTableMeta; return TSDB_CODE_SUCCESS; diff --git a/source/libs/qworker/inc/qwInt.h b/source/libs/qworker/inc/qwInt.h index 539643c390..b35e0e2fc4 100644 --- a/source/libs/qworker/inc/qwInt.h +++ b/source/libs/qworker/inc/qwInt.h @@ -316,34 +316,34 @@ typedef struct SQWorkerMgmt { #define QW_LOCK(type, _lock) \ do { \ if (QW_READ == (type)) { \ - assert(atomic_load_32((_lock)) >= 0); \ - QW_LOCK_DEBUG("QW RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ + QW_LOCK_DEBUG("QW RLOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ taosRLockLatch(_lock); \ - QW_LOCK_DEBUG("QW RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) > 0); \ + QW_LOCK_DEBUG("QW RLOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) > 0); \ } else { \ - assert(atomic_load_32((_lock)) >= 0); \ - QW_LOCK_DEBUG("QW WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ + QW_LOCK_DEBUG("QW WLOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ taosWLockLatch(_lock); \ - QW_LOCK_DEBUG("QW WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ + QW_LOCK_DEBUG("QW WLOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ } \ } while (0) #define QW_UNLOCK(type, _lock) \ do { \ if (QW_READ == (type)) { \ - assert(atomic_load_32((_lock)) > 0); \ - QW_LOCK_DEBUG("QW RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) > 0); \ + QW_LOCK_DEBUG("QW RULOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ taosRUnLockLatch(_lock); \ - QW_LOCK_DEBUG("QW RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) >= 0); \ + QW_LOCK_DEBUG("QW RULOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ } else { \ - assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ - QW_LOCK_DEBUG("QW WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ + QW_LOCK_DEBUG("QW WULOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ taosWUnLockLatch(_lock); \ - QW_LOCK_DEBUG("QW WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) >= 0); \ + QW_LOCK_DEBUG("QW WULOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ } \ } while (0) diff --git a/source/libs/qworker/src/qwDbg.c b/source/libs/qworker/src/qwDbg.c index dfe5a04d19..869eedf8f6 100644 --- a/source/libs/qworker/src/qwDbg.c +++ b/source/libs/qworker/src/qwDbg.c @@ -9,7 +9,7 @@ #include "tmsg.h" #include "tname.h" -SQWDebug gQWDebug = {.statusEnable = true, .dumpEnable = false, .tmp = false}; +SQWDebug gQWDebug = {.statusEnable = true, .dumpEnable = false, .tmp = true}; int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, bool *ignore) { if (!gQWDebug.statusEnable) { diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c index 5aaf2b8038..9c49cbcb1f 100644 --- a/source/libs/qworker/src/qwUtil.c +++ b/source/libs/qworker/src/qwUtil.c @@ -436,7 +436,7 @@ void qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx) { char dbFName[TSDB_DB_FNAME_LEN] = {0}; char tbName[TSDB_TABLE_NAME_LEN] = {0}; - qGetQueriedTableSchemaVersion(pTaskInfo, dbFName, tbName, &ctx->tbInfo.sversion, &ctx->tbInfo.tversion); + qGetQueryTableSchemaVersion(pTaskInfo, dbFName, tbName, &ctx->tbInfo.sversion, &ctx->tbInfo.tversion); if (dbFName[0] && tbName[0]) { sprintf(ctx->tbInfo.tbFName, "%s.%s", dbFName, tbName); diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index cf8116fee7..3e8ced318c 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -517,7 +517,7 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, const char* sql) { ctx->needFetch = qwMsg->msgInfo.needFetch; ctx->queryType = qwMsg->msgType; - QW_TASK_DLOGL("subplan json string, len:%d, %s", qwMsg->msgLen, qwMsg->msg); + //QW_TASK_DLOGL("subplan json string, len:%d, %s", qwMsg->msgLen, qwMsg->msg); code = qStringToSubplan(qwMsg->msg, &plan); if (TSDB_CODE_SUCCESS != code) { @@ -1041,7 +1041,7 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qW *qWorkerMgmt = mgmt; - qDebug("qworker initialized for node, type:%d, id:%d, handle:%p", mgmt->nodeType, mgmt->nodeId, mgmt); + qDebug("qworker initialized, type:%d, id:%d, handle:%p", mgmt->nodeType, mgmt->nodeId, mgmt); return TSDB_CODE_SUCCESS; diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index c2d984c7dd..4422da1b81 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -56,8 +56,8 @@ typedef struct SScalarCtx { #define SCL_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) #define SCL_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) -int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out); -SColumnInfoData* sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows); +int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow); +int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam); int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode); #define GET_PARAM_TYPE(_c) ((_c)->columnData ? (_c)->columnData->info.type : (_c)->hashValueType) diff --git a/source/libs/scalar/inc/sclvector.h b/source/libs/scalar/inc/sclvector.h index f80ffc70a2..a1bf1ce1ef 100644 --- a/source/libs/scalar/inc/sclvector.h +++ b/source/libs/scalar/inc/sclvector.h @@ -94,7 +94,7 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) return p; } -typedef void (*_bufConverteFunc)(char *buf, SScalarParam* pOut, int32_t outType); +typedef void (*_bufConverteFunc)(char *buf, SScalarParam* pOut, int32_t outType, int32_t* overflow); typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *output, int32_t order); _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator); diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index a7f66ebb7d..0348f13191 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1042,12 +1042,18 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { for (int32_t i = 0; i < listNode->pNodeList->length; ++i) { SValueNode *valueNode = (SValueNode *)cell->pNode; - if (valueNode->node.resType.type != type) { - code = doConvertDataType(valueNode, &out); + if (valueNode->node.resType.type != type) { + int32_t overflow = 0; + code = doConvertDataType(valueNode, &out, &overflow); if (code) { // fltError("convert from %d to %d failed", in.type, out.type); FLT_ERR_RET(code); } + + if (overflow) { + cell = cell->pNext; + continue; + } len = tDataTypes[type].bytes; @@ -1835,7 +1841,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } // todo refactor the convert - int32_t code = doConvertDataType(var, &out); + int32_t code = doConvertDataType(var, &out, NULL); if (code != TSDB_CODE_SUCCESS) { qError("convert value to type[%d] failed", type); return TSDB_CODE_TSC_INVALID_OPERATION; @@ -3617,7 +3623,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } - if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && node->opType >= OP_TYPE_NOT_EQUAL) { + if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && + (node->opType >= OP_TYPE_NOT_EQUAL) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } @@ -3827,13 +3834,20 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnData SScalarParam output = {0}; SDataType type = {.type = TSDB_DATA_TYPE_BOOL, .bytes = sizeof(bool)}; - output.columnData = sclCreateColumnInfoData(&type, pSrc->info.rows); + int32_t code = sclCreateColumnInfoData(&type, pSrc->info.rows, &output); + if (code != TSDB_CODE_SUCCESS) { + return code; + } SArray *pList = taosArrayInit(1, POINTER_BYTES); taosArrayPush(pList, &pSrc); FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pList, &output)); - *p = (int8_t *)output.columnData->pData; + *p = taosMemoryMalloc(output.numOfRows * sizeof(bool)); + + memcpy(*p, output.columnData->pData, output.numOfRows); + colDataDestroy(output.columnData); + taosMemoryFree(output.columnData); taosArrayDestroy(pList); return false; diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index cbb1089d61..dd55894266 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -35,12 +35,11 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) { return TSDB_CODE_SUCCESS; } - -SColumnInfoData* sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows) { +int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam) { SColumnInfoData* pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); if (pColumnData == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; + return terrno; } pColumnData->info.type = pType->type; @@ -52,19 +51,25 @@ SColumnInfoData* sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows) { if (code != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(pColumnData); - return NULL; - } else { - return pColumnData; + return terrno; } + + pParam->columnData = pColumnData; + pParam->type = SHOULD_FREE_COLDATA; + return TSDB_CODE_SUCCESS; } -int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out) { +int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow) { SScalarParam in = {.numOfRows = 1}; - in.columnData = sclCreateColumnInfoData(&pValueNode->node.resType, 1); + int32_t code = sclCreateColumnInfoData(&pValueNode->node.resType, 1, &in); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); colInfoDataEnsureCapacity(out->columnData, 1); - int32_t code = vectorConvertImpl(&in, out); + code = vectorConvertImpl(&in, out, overflow); sclFreeParam(&in); return code; @@ -102,15 +107,21 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { out.columnData->info.bytes = tDataTypes[type].bytes; } - code = doConvertDataType(valueNode, &out); + int32_t overflow = 0; + code = doConvertDataType(valueNode, &out, &overflow); if (code != TSDB_CODE_SUCCESS) { // sclError("convert data from %d to %d failed", in.type, out.type); SCL_ERR_JRET(code); } + if (overflow) { + cell = cell->pNext; + continue; + } + if (IS_VAR_DATA_TYPE(type)) { buf = colDataGetVarData(out.columnData, 0); - len = varDataTLen(data); + len = varDataTLen(buf); } else { len = tDataTypes[type].bytes; buf = out.columnData->pData; @@ -157,7 +168,7 @@ void sclFreeRes(SHashObj *res) { void sclFreeParam(SScalarParam *param) { if (param->columnData != NULL) { colDataDestroy(param->columnData); - taosMemoryFree(param->columnData); + taosMemoryFreeClear(param->columnData); } if (param->pHashFilter != NULL) { @@ -190,8 +201,9 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t case QUERY_NODE_VALUE: { SValueNode *valueNode = (SValueNode *)node; + ASSERT(param->columnData == NULL); param->numOfRows = 1; - param->columnData = sclCreateColumnInfoData(&valueNode->node.resType, 1); + /*int32_t code = */sclCreateColumnInfoData(&valueNode->node.resType, 1, param); if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) { colDataAppendNULL(param->columnData, 0); } else { @@ -429,10 +441,9 @@ int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outp SCL_ERR_JRET(code); } - output->columnData = sclCreateColumnInfoData(&node->node.resType, rowNum); - if (output->columnData == NULL) { - sclError("calloc %d failed", (int32_t)(rowNum * output->columnData->info.bytes)); - SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + code = sclCreateColumnInfoData(&node->node.resType, rowNum, output); + if (code != TSDB_CODE_SUCCESS) { + SCL_ERR_JRET(code); } code = (*ffpSet.process)(params, paramNum, output); @@ -482,10 +493,9 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o output->numOfRows = rowNum; SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; - output->columnData = sclCreateColumnInfoData(&t, rowNum); - if (output->columnData == NULL) { - sclError("calloc %d failed", (int32_t)(rowNum * sizeof(bool))); - SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + code = sclCreateColumnInfoData(&t, rowNum, output); + if (code != TSDB_CODE_SUCCESS) { + SCL_ERR_JRET(code); } bool value = false; @@ -537,18 +547,19 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp int32_t code = 0; // json not support in in operator - if(nodeType(node->pLeft) == QUERY_NODE_VALUE){ + if (nodeType(node->pLeft) == QUERY_NODE_VALUE) { SValueNode *valueNode = (SValueNode *)node->pLeft; - if(valueNode->node.resType.type == TSDB_DATA_TYPE_JSON && (node->opType == OP_TYPE_IN || node->opType == OP_TYPE_NOT_IN)){ + if (valueNode->node.resType.type == TSDB_DATA_TYPE_JSON && (node->opType == OP_TYPE_IN || node->opType == OP_TYPE_NOT_IN)) { SCL_RET(TSDB_CODE_QRY_JSON_IN_ERROR); } } SCL_ERR_RET(sclInitOperatorParams(¶ms, node, ctx, &rowNum)); - output->columnData = sclCreateColumnInfoData(&node->node.resType, rowNum); if (output->columnData == NULL) { - sclError("calloc failed, size:%d", (int32_t)rowNum * node->node.resType.bytes); - SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + code = sclCreateColumnInfoData(&node->node.resType, rowNum, output); + if (code != TSDB_CODE_SUCCESS) { + SCL_ERR_JRET(code); + } } _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType); @@ -563,14 +574,17 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp _return: for (int32_t i = 0; i < paramNum; ++i) { -// sclFreeParam(¶ms[i]); + if (params[i].type == SHOULD_FREE_COLDATA) { + colDataDestroy(params[i].columnData); + taosMemoryFreeClear(params[i].columnData); + } } taosMemoryFreeClear(params); SCL_RET(code); } -EDealRes sclRewriteBasedOnOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opType) { +EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opType) { if (opType <= OP_TYPE_CALC_MAX) { SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); if (NULL == res) { @@ -602,6 +616,24 @@ EDealRes sclRewriteBasedOnOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opT return DEAL_RES_CONTINUE; } +EDealRes sclAggFuncWalker(SNode* pNode, void* pContext) { + if (QUERY_NODE_FUNCTION == nodeType(pNode)) { + SFunctionNode* pFunc = (SFunctionNode*)pNode; + *(bool*)pContext = fmIsAggFunc(pFunc->funcId); + if (*(bool*)pContext) { + return DEAL_RES_END; + } + } + + return DEAL_RES_CONTINUE; +} + + +bool sclContainsAggFuncNode(SNode* pNode) { + bool aggFunc = false; + nodesWalkExpr(pNode, sclAggFuncWalker, (void *)&aggFunc); + return aggFunc; +} EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)*pNode; @@ -609,8 +641,9 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { if (node->pLeft && (QUERY_NODE_VALUE == nodeType(node->pLeft))) { SValueNode *valueNode = (SValueNode *)node->pLeft; - if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { - return sclRewriteBasedOnOptr(pNode, ctx, node->opType); + if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) + && (!sclContainsAggFuncNode(node->pRight))) { + return sclRewriteNullInOptr(pNode, ctx, node->opType); } if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pRight && nodesIsExprNode(node->pRight) @@ -625,8 +658,9 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { if (node->pRight && (QUERY_NODE_VALUE == nodeType(node->pRight))) { SValueNode *valueNode = (SValueNode *)node->pRight; - if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { - return sclRewriteBasedOnOptr(pNode, ctx, node->opType); + if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) + && (!sclContainsAggFuncNode(node->pLeft))) { + return sclRewriteNullInOptr(pNode, ctx, node->opType); } if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pLeft && nodesIsExprNode(node->pLeft) @@ -648,7 +682,7 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { ERASE_NODE(listNode->pNodeList); continue; } else { //OP_TYPE_NOT_IN - return sclRewriteBasedOnOptr(pNode, ctx, node->opType); + return sclRewriteNullInOptr(pNode, ctx, node->opType); } } @@ -656,7 +690,7 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { } if (listNode->pNodeList->length <= 0) { - return sclRewriteBasedOnOptr(pNode, ctx, node->opType); + return sclRewriteNullInOptr(pNode, ctx, node->opType); } } @@ -766,7 +800,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { return sclRewriteNonConstOperator(pNode, ctx); } - SScalarParam output = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; + SScalarParam output = {0}; ctx->code = sclExecOperator(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; @@ -834,6 +868,7 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_ERROR; } + output.type = DELEGATED_MGMT_COLDATA; if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) { ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return DEAL_RES_ERROR; @@ -868,6 +903,7 @@ EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_ERROR; } + output.type = DELEGATED_MGMT_COLDATA; if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) { ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return DEAL_RES_ERROR; @@ -1026,7 +1062,8 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { colDataAssign(pDst->columnData, res->columnData, res->numOfRows, NULL); pDst->numOfRows = res->numOfRows; } - + + sclFreeParam(res); taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); } @@ -1036,71 +1073,122 @@ _return: return code; } -int32_t scalarGetOperatorResultType(SDataType left, SDataType right, EOperatorType op, SDataType* pRes) { - switch (op) { +static int32_t getMinusOperatorResultType(SOperatorNode* pOp) { + if (!IS_MATHABLE_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; + return TSDB_CODE_SUCCESS; +} + +static int32_t getArithmeticOperatorResultType(SOperatorNode* pOp) { + SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; + SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; + if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) || + (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) || + (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && IS_INTEGER_TYPE(rdt.type)) || + (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && IS_INTEGER_TYPE(ldt.type)) || + (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_BOOL == rdt.type) || + (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && TSDB_DATA_TYPE_BOOL == ldt.type)) { + pOp->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; + } else { + pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; + } + return TSDB_CODE_SUCCESS; +} + +static int32_t getComparisonOperatorResultType(SOperatorNode* pOp) { + SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; + if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) { + ((SExprNode*)(pOp->pRight))->resType = ldt; + } else if (nodesIsRegularOp(pOp)) { + SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; + if (!IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) || + (!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + } + pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; + return TSDB_CODE_SUCCESS; +} + +static int32_t getJsonOperatorResultType(SOperatorNode* pOp) { + SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; + SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; + if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + if (pOp->opType == OP_TYPE_JSON_GET_VALUE) { + pOp->node.resType.type = TSDB_DATA_TYPE_JSON; + } else if (pOp->opType == OP_TYPE_JSON_CONTAINS) { + pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; + } + pOp->node.resType.bytes = tDataTypes[pOp->node.resType.type].bytes; + return TSDB_CODE_SUCCESS; +} + +static int32_t getBitwiseOperatorResultType(SOperatorNode* pOp) { + pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; + return TSDB_CODE_SUCCESS; +} + +int32_t scalarGetOperatorResultType(SOperatorNode* pOp) { + if (TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pLeft))->resType.type || + (NULL != pOp->pRight && TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pRight))->resType.type)) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + switch (pOp->opType) { case OP_TYPE_ADD: - if (left.type == TSDB_DATA_TYPE_TIMESTAMP && right.type == TSDB_DATA_TYPE_TIMESTAMP) { - qError("invalid op %d, left type:%d, right type:%d", op, left.type, right.type); - return TSDB_CODE_TSC_INVALID_OPERATION; - } - if ((left.type == TSDB_DATA_TYPE_TIMESTAMP && (IS_INTEGER_TYPE(right.type) || right.type == TSDB_DATA_TYPE_BOOL)) || - (right.type == TSDB_DATA_TYPE_TIMESTAMP && (IS_INTEGER_TYPE(left.type) || left.type == TSDB_DATA_TYPE_BOOL))) { - pRes->type = TSDB_DATA_TYPE_TIMESTAMP; - return TSDB_CODE_SUCCESS; - } - pRes->type = TSDB_DATA_TYPE_DOUBLE; - return TSDB_CODE_SUCCESS; case OP_TYPE_SUB: - if ((left.type == TSDB_DATA_TYPE_TIMESTAMP && right.type == TSDB_DATA_TYPE_BIGINT) || - (right.type == TSDB_DATA_TYPE_TIMESTAMP && left.type == TSDB_DATA_TYPE_BIGINT)) { - pRes->type = TSDB_DATA_TYPE_TIMESTAMP; - return TSDB_CODE_SUCCESS; - } - pRes->type = TSDB_DATA_TYPE_DOUBLE; - return TSDB_CODE_SUCCESS; case OP_TYPE_MULTI: - if (left.type == TSDB_DATA_TYPE_TIMESTAMP && right.type == TSDB_DATA_TYPE_TIMESTAMP) { - qError("invalid op %d, left type:%d, right type:%d", op, left.type, right.type); - return TSDB_CODE_TSC_INVALID_OPERATION; - } case OP_TYPE_DIV: - if (left.type == TSDB_DATA_TYPE_TIMESTAMP && right.type == TSDB_DATA_TYPE_TIMESTAMP) { - qError("invalid op %d, left type:%d, right type:%d", op, left.type, right.type); - return TSDB_CODE_TSC_INVALID_OPERATION; - } case OP_TYPE_REM: + return getArithmeticOperatorResultType(pOp); case OP_TYPE_MINUS: - pRes->type = TSDB_DATA_TYPE_DOUBLE; - return TSDB_CODE_SUCCESS; + return getMinusOperatorResultType(pOp); + case OP_TYPE_ASSIGN: + pOp->node.resType = ((SExprNode*)(pOp->pLeft))->resType; + break; + case OP_TYPE_BIT_AND: + case OP_TYPE_BIT_OR: + return getBitwiseOperatorResultType(pOp); case OP_TYPE_GREATER_THAN: case OP_TYPE_GREATER_EQUAL: case OP_TYPE_LOWER_THAN: case OP_TYPE_LOWER_EQUAL: case OP_TYPE_EQUAL: case OP_TYPE_NOT_EQUAL: - case OP_TYPE_IN: - case OP_TYPE_NOT_IN: + case OP_TYPE_IS_NULL: + case OP_TYPE_IS_NOT_NULL: + case OP_TYPE_IS_TRUE: + case OP_TYPE_IS_FALSE: + case OP_TYPE_IS_UNKNOWN: + case OP_TYPE_IS_NOT_TRUE: + case OP_TYPE_IS_NOT_FALSE: + case OP_TYPE_IS_NOT_UNKNOWN: case OP_TYPE_LIKE: case OP_TYPE_NOT_LIKE: case OP_TYPE_MATCH: case OP_TYPE_NMATCH: - case OP_TYPE_IS_NULL: - case OP_TYPE_IS_NOT_NULL: - case OP_TYPE_IS_TRUE: - case OP_TYPE_JSON_CONTAINS: - pRes->type = TSDB_DATA_TYPE_BOOL; - return TSDB_CODE_SUCCESS; - case OP_TYPE_BIT_AND: - case OP_TYPE_BIT_OR: - pRes->type = TSDB_DATA_TYPE_BIGINT; - return TSDB_CODE_SUCCESS; + case OP_TYPE_IN: + case OP_TYPE_NOT_IN: + return getComparisonOperatorResultType(pOp); case OP_TYPE_JSON_GET_VALUE: - pRes->type = TSDB_DATA_TYPE_JSON; - return TSDB_CODE_SUCCESS; + case OP_TYPE_JSON_CONTAINS: + return getJsonOperatorResultType(pOp); default: - ASSERT(0); - return TSDB_CODE_APP_ERROR; + break; } + + return TSDB_CODE_SUCCESS; } - - diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 18bbacd5b7..bf457d07eb 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -276,7 +276,7 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { return p; } -static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t rowIndex) { +static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { int64_t value = 0; if (taosParseTime(buf, &value, strlen(buf), pOut->columnData->info.precision, tsDaylight) != TSDB_CODE_SUCCESS) { value = 0; @@ -285,10 +285,26 @@ static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t r colDataAppendInt64(pOut->columnData, rowIndex, &value); } -static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { +static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { + if (overflow) { + int64_t minValue = tDataTypes[pOut->columnData->info.type].minValue; + int64_t maxValue = tDataTypes[pOut->columnData->info.type].maxValue; + int64_t value = (int64_t)taosStr2Int64(buf, NULL, 10); + if (value > maxValue) { + *overflow = 1; + return; + } else if (value < minValue) { + *overflow = -1; + return; + } else { + *overflow = 0; + } + } + switch (pOut->columnData->info.type) { case TSDB_DATA_TYPE_TINYINT: { int8_t value = (int8_t)taosStr2Int8(buf, NULL, 10); + colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); break; } @@ -310,7 +326,22 @@ static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowI } } -static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex) { +static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { + if (overflow) { + uint64_t minValue = (uint64_t)tDataTypes[pOut->columnData->info.type].minValue; + uint64_t maxValue = (uint64_t)tDataTypes[pOut->columnData->info.type].maxValue; + uint64_t value = (uint64_t)taosStr2UInt64(buf, NULL, 10); + if (value > maxValue) { + *overflow = 1; + return; + } else if (value < minValue) { + *overflow = -1; + return; + } else { + *overflow = 0; + } + } + switch (pOut->columnData->info.type) { case TSDB_DATA_TYPE_UTINYINT: { uint8_t value = (uint8_t)taosStr2UInt8(buf, NULL, 10); @@ -335,18 +366,24 @@ static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t ro } } -static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex) { +static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { + if (TSDB_DATA_TYPE_FLOAT == pOut->columnData->info.type) { + float value = taosStr2Float(buf, NULL); + colDataAppendFloat(pOut->columnData, rowIndex, &value); + return; + } + double value = taosStr2Double(buf, NULL); colDataAppendDouble(pOut->columnData, rowIndex, &value); } -static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex) { +static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { int64_t value = taosStr2Int64(buf, NULL, 10); bool v = (value != 0)? true:false; colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v); } -static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIndex) { +static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { int32_t len = 0; int32_t inputLen = varDataLen(buf); int32_t outputMaxLen = (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; @@ -359,7 +396,7 @@ static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIn taosMemoryFree(t); } -static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIndex) { +static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { int32_t inputLen = varDataLen(buf); char* t = taosMemoryCalloc(1, inputLen + VARSTR_HEADER_SIZE); @@ -376,7 +413,7 @@ static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIn //TODO opt performance, tmp is not needed. -int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { +int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType, int32_t* overflow) { bool vton = false; _bufConverteFunc func = NULL; @@ -415,8 +452,7 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in if(inType == TSDB_DATA_TYPE_JSON){ if(*data == TSDB_DATA_TYPE_NULL) { ASSERT(0); - } - else if(*data == TSDB_DATA_TYPE_NCHAR) { + } else if(*data == TSDB_DATA_TYPE_NCHAR) { data += CHAR_BYTES; convertType = TSDB_DATA_TYPE_NCHAR; } else if(tTagIsJson(data)){ @@ -453,7 +489,7 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in } } - (*func)(tmp, pOut, i); + (*func)(tmp, pOut, i, overflow); taosMemoryFreeClear(tmp); } @@ -606,7 +642,7 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1 int32_t len = sprintf(varDataVal(tmp), "%" PRId64, value); varDataLen(tmp) = len; if (outType == TSDB_DATA_TYPE_NCHAR) { - varToNchar(tmp, pOut, i); + varToNchar(tmp, pOut, i, NULL); } else { colDataAppend(pOutputCol, i, (char *)tmp, false); } @@ -623,7 +659,7 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1 int32_t len = sprintf(varDataVal(tmp), "%" PRIu64, value); varDataLen(tmp) = len; if (outType == TSDB_DATA_TYPE_NCHAR) { - varToNchar(tmp, pOut, i); + varToNchar(tmp, pOut, i, NULL); } else { colDataAppend(pOutputCol, i, (char *)tmp, false); } @@ -640,7 +676,7 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1 int32_t len = sprintf(varDataVal(tmp), "%lf", value); varDataLen(tmp) = len; if (outType == TSDB_DATA_TYPE_NCHAR) { - varToNchar(tmp, pOut, i); + varToNchar(tmp, pOut, i, NULL); } else { colDataAppend(pOutputCol, i, (char *)tmp, false); } @@ -653,9 +689,8 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1 return TSDB_CODE_SUCCESS; } - // TODO opt performance -int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { +int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* overflow) { SColumnInfoData* pInputCol = pIn->columnData; SColumnInfoData* pOutputCol = pOut->columnData; @@ -668,7 +703,47 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { int16_t outType = pOutputCol->info.type; if (IS_VAR_DATA_TYPE(inType)) { - return vectorConvertFromVarData(pIn, pOut, inType, outType); + return vectorConvertFromVarData(pIn, pOut, inType, outType, overflow); + } + + if (overflow) { + ASSERT(1 == pIn->numOfRows); + + pOut->numOfRows = 0; + + if (IS_SIGNED_NUMERIC_TYPE(outType)) { + int64_t minValue = tDataTypes[outType].minValue; + int64_t maxValue = tDataTypes[outType].maxValue; + + double value = 0; + GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, 0)); + + if (value > maxValue) { + *overflow = 1; + return TSDB_CODE_SUCCESS; + } else if (value < minValue) { + *overflow = -1; + return TSDB_CODE_SUCCESS; + } else { + *overflow = 0; + } + } else if (IS_UNSIGNED_NUMERIC_TYPE(outType)) { + uint64_t minValue = (uint64_t)tDataTypes[outType].minValue; + uint64_t maxValue = (uint64_t)tDataTypes[outType].maxValue; + + double value = 0; + GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, 0)); + + if (value > maxValue) { + *overflow = 1; + return TSDB_CODE_SUCCESS; + } else if (value < minValue) { + *overflow = -1; + return TSDB_CODE_SUCCESS; + } else { + *overflow = 0; + } + } } pOut->numOfRows = pIn->numOfRows; @@ -829,6 +904,8 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { return TSDB_CODE_SUCCESS; } + + int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = { /* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */ /*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -865,16 +942,15 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) { } int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int32_t type) { - int32_t code = 0; SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; output->numOfRows = input->numOfRows; - output->columnData = sclCreateColumnInfoData(&t, input->numOfRows); - if (output->columnData == NULL) { + int32_t code = sclCreateColumnInfoData(&t, input->numOfRows, output); + if (code != TSDB_CODE_SUCCESS) { return TSDB_CODE_OUT_OF_MEMORY; } - code = vectorConvertImpl(input, output); + code = vectorConvertImpl(input, output, NULL); if (code) { // taosMemoryFreeClear(paramOut1->data); return code; @@ -940,13 +1016,12 @@ static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SSca pDest->numOfRows = pParam->numOfRows; SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; - pDest->columnData = sclCreateColumnInfoData(&t, pParam->numOfRows); - if (pDest->columnData == NULL) { - sclError("malloc %d failed", (int32_t)(pParam->numOfRows * sizeof(double))); - return TSDB_CODE_OUT_OF_MEMORY; + int32_t code = sclCreateColumnInfoData(&t, pParam->numOfRows, pDest); + if (code != TSDB_CODE_SUCCESS) { + return code; } - int32_t code = vectorConvertImpl(pParam, pDest); + code = vectorConvertImpl(pParam, pDest, NULL); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -1716,7 +1791,7 @@ void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut } void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - vectorConvertImpl(pLeft, pOut); + vectorConvertImpl(pLeft, pOut, NULL); for(int32_t i = 0; i < pOut->numOfRows; ++i) { if(colDataIsNull_s(pOut->columnData, i)) { int8_t v = 0; diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index 8f9332cef8..d8c64eef55 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -205,13 +205,19 @@ void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { *pNode = (SNode *)lnode; } +void initScalarParam(SScalarParam* pParam) { + memset(pParam, 0, sizeof(SScalarParam)); + pParam->type = SHOULD_FREE_COLDATA; +} } TEST(timerangeTest, greater) { SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL; bool eRes[5] = {false, false, true, true, true}; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); + int64_t tsmall = 222, tbig = 333; flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); @@ -234,7 +240,8 @@ TEST(timerangeTest, greater) { TEST(timerangeTest, greater_and_lower) { SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; bool eRes[5] = {false, false, true, true, true}; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int64_t tsmall = 222, tbig = 333; flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); @@ -265,7 +272,8 @@ TEST(timerangeTest, greater_and_lower) { TEST(timerangeTest, greater_equal_and_lower_equal) { SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; bool eRes[5] = {false, false, true, true, true}; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int64_t tsmall = 222, tbig = 333; flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); @@ -297,7 +305,8 @@ TEST(timerangeTest, greater_equal_and_lower_equal) { TEST(timerangeTest, greater_and_lower_not_strict) { SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL; bool eRes[5] = {false, false, true, true, true}; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int64_t tsmall1 = 222, tbig1 = 333; int64_t tsmall2 = 444, tbig2 = 555; SNode *list[2] = {0}; @@ -350,7 +359,8 @@ TEST(columnTest, smallint_column_greater_double_value) { double rightv= 2.5; int8_t eRes[5] = {0, 0, 1, 1, 1}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); @@ -405,7 +415,8 @@ TEST(columnTest, int_column_greater_smallint_value) { int16_t rightv= 4; int8_t eRes[5] = {0, 0, 1, 1, 1}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); @@ -460,7 +471,8 @@ TEST(columnTest, int_column_in_double_list) { double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3; bool eRes[5] = {true, true, true, false, false}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); SNodeList* list = nodesMakeList(); @@ -503,7 +515,8 @@ TEST(columnTest, binary_column_in_binary_list) { SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; bool eRes[5] = {true, true, false, false, false}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); char leftv[5][5]= {0}; char rightv[3][5]= {0}; for (int32_t i = 0; i < 5; ++i) { @@ -567,7 +580,8 @@ TEST(columnTest, binary_column_like_binary) { char rightv[64] = {0}; char leftv[5][5]= {0}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); bool eRes[5] = {true, false, true, false, true}; for (int32_t i = 0; i < 5; ++i) { @@ -614,7 +628,8 @@ TEST(columnTest, binary_column_is_null) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); bool eRes[5] = {false, false, true, false, true}; for (int32_t i = 0; i < 5; ++i) { @@ -661,7 +676,8 @@ TEST(columnTest, binary_column_is_not_null) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); bool eRes[5] = {true, true, true, true, false}; for (int32_t i = 0; i < 5; ++i) { @@ -710,7 +726,8 @@ TEST(opTest, smallint_column_greater_int_column) { int32_t rightv[5]= {0, -5, -4, 23, 100}; bool eRes[5] = {true, false, true, false, true}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv); @@ -747,7 +764,8 @@ TEST(opTest, smallint_value_add_int_column) { int16_t rightv[5]= {0, -1, -4, -1, 100}; bool eRes[5] = {true, false, true, false, true}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); flttMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv); @@ -790,7 +808,8 @@ TEST(opTest, bigint_column_multi_binary_column) { } bool eRes[5] = {false, true, true, true, true}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); @@ -833,7 +852,8 @@ TEST(opTest, smallint_column_and_binary_column) { } bool eRes[5] = {false, false, true, false, true}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); @@ -871,7 +891,8 @@ TEST(opTest, smallint_column_or_float_column) { float rightv[5]= {2.0, 3.0, 0, 5.2, 6.0}; bool eRes[5] = {true, true, false, true, true}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv); @@ -909,7 +930,8 @@ TEST(opTest, smallint_column_or_double_value) { double rightv= 10.2; bool eRes[5] = {true, true, true, true, true}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); @@ -945,7 +967,8 @@ TEST(opTest, binary_column_is_true) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; SSDataBlock *src = NULL; - SScalarParam res = {0}; + SScalarParam res; + initScalarParam(&res); bool eRes[5] = {false, true, false, true, false}; for (int32_t i = 0; i < 5; ++i) { diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index 07440e7435..9b40f0a465 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -1092,7 +1092,7 @@ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, do printf("op:%s,1result:%f,except:%f\n", gOptrStr[opType].str, *((double *)colDataGetData(column, 0)), exceptValue); ASSERT_TRUE(fabs(*((double *)colDataGetData(column, 0)) - exceptValue) < 0.0001); }else if(opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR){ - printf("op:%s,2result:%ld,except:%f\n", gOptrStr[opType].str, *((int64_t *)colDataGetData(column, 0)), exceptValue); + printf("op:%s,2result:%" PRId64 ",except:%f\n", gOptrStr[opType].str, *((int64_t *)colDataGetData(column, 0)), exceptValue); ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue); }else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN || opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL || diff --git a/source/libs/scheduler/inc/schInt.h b/source/libs/scheduler/inc/schInt.h index 9018deaf13..e5c7e37479 100644 --- a/source/libs/scheduler/inc/schInt.h +++ b/source/libs/scheduler/inc/schInt.h @@ -35,7 +35,6 @@ extern "C" { #define SCH_DEFAULT_TASK_TIMEOUT_USEC 10000000 #define SCH_MAX_TASK_TIMEOUT_USEC 60000000 -#define SCH_TASK_MAX_EXEC_TIMES 8 #define SCH_MAX_CANDIDATE_EP_NUM TSDB_MAX_REPLICA enum { @@ -55,6 +54,11 @@ typedef enum { SCH_OP_GET_STATUS, } SCH_OP_TYPE; +typedef struct SSchDebug { + bool lockEnable; + bool apiEnable; +} SSchDebug; + typedef struct SSchTrans { void *pTrans; void *pHandle; @@ -179,15 +183,15 @@ typedef struct SSchLevel { } SSchLevel; typedef struct SSchTaskProfile { - int64_t startTs; - int64_t execUseTime[SCH_TASK_MAX_EXEC_TIMES]; - int64_t waitTime; - int64_t endTs; + int64_t startTs; + int64_t* execTime; + int64_t waitTime; + int64_t endTs; } SSchTaskProfile; typedef struct SSchTask { uint64_t taskId; // task id - SRWLatch lock; // task lock + SRWLatch lock; // task reentrant lock int32_t maxExecTimes; // task may exec times int32_t execId; // task current execute try index SSchLevel *level; // level @@ -260,33 +264,7 @@ typedef struct SSchJob { extern SSchedulerMgmt schMgmt; -#define SCH_LOG_TASK_START_TS(_task) \ - do { \ - int64_t us = taosGetTimestampUs(); \ - int32_t idx = (_task)->execId % SCH_TASK_MAX_EXEC_TIMES; \ - (_task)->profile.execUseTime[idx] = us; \ - if (0 == (_task)->execId) { \ - (_task)->profile.startTs = us; \ - } \ - } while (0) - -#define SCH_LOG_TASK_WAIT_TS(_task) \ - do { \ - int64_t us = taosGetTimestampUs(); \ - int32_t idx = (_task)->execId % SCH_TASK_MAX_EXEC_TIMES; \ - (_task)->profile.waitTime += us - (_task)->profile.execUseTime[idx]; \ - } while (0) - - -#define SCH_LOG_TASK_END_TS(_task) \ - do { \ - int64_t us = taosGetTimestampUs(); \ - int32_t idx = (_task)->execId % SCH_TASK_MAX_EXEC_TIMES; \ - (_task)->profile.execUseTime[idx] = us - (_task)->profile.execUseTime[idx]; \ - (_task)->profile.endTs = us; \ - } while (0) - -#define SCH_TASK_TIMEOUT(_task) ((taosGetTimestampUs() - (_task)->profile.execUseTime[(_task)->execId % SCH_TASK_MAX_EXEC_TIMES]) > (_task)->timeoutUsec) +#define SCH_TASK_TIMEOUT(_task) ((taosGetTimestampUs() - (_task)->profile.execTime[(_task)->execId % (_task)->maxExecTimes]) > (_task)->timeoutUsec) #define SCH_TASK_READY_FOR_LAUNCH(readyNum, task) ((readyNum) >= taosArrayGetSize((task)->children)) @@ -320,6 +298,7 @@ extern SSchedulerMgmt schMgmt; #define SCH_TASK_NEED_FLOW_CTRL(_job, _task) (SCH_IS_DATA_BIND_QRY_TASK(_task) && SCH_JOB_NEED_FLOW_CTRL(_job) && SCH_IS_LEVEL_UNFINISHED((_task)->level)) #define SCH_FETCH_TYPE(_pSrcTask) (SCH_IS_DATA_BIND_QRY_TASK(_pSrcTask) ? TDMT_SCH_FETCH : TDMT_SCH_MERGE_FETCH) #define SCH_TASK_NEED_FETCH(_task) ((_task)->plan->subplanType != SUBPLAN_TYPE_MODIFY) +#define SCH_TASK_MAX_EXEC_TIMES(_levelIdx, _levelNum) (SCH_MAX_CANDIDATE_EP_NUM * ((_levelNum) - (_levelIdx))) #define SCH_SET_JOB_TYPE(_job, type) do { if ((type) != SUBPLAN_TYPE_MODIFY) { (_job)->attr.queryJob = true; } } while (0) #define SCH_IS_QUERY_JOB(_job) ((_job)->attr.queryJob) @@ -328,16 +307,43 @@ extern SSchedulerMgmt schMgmt; #define SCH_JOB_NEED_DROP(_job) (SCH_IS_QUERY_JOB(_job)) #define SCH_IS_EXPLAIN_JOB(_job) (EXPLAIN_MODE_ANALYZE == (_job)->attr.explainMode) #define SCH_NETWORK_ERR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL) -#define SCH_SUB_TASK_NETWORK_ERR(_code, _len) (SCH_NETWORK_ERR(_code) && ((_len) > 0)) -#define SCH_NEED_REDIRECT_MSGTYPE(_msgType) ((_msgType) == TDMT_SCH_QUERY || (_msgType) == TDMT_SCH_MERGE_QUERY || (_msgType) == TDMT_SCH_FETCH || (_msgType) == TDMT_SCH_MERGE_FETCH) -#define SCH_NEED_REDIRECT(_msgType, _code, _rspLen) (SCH_NEED_REDIRECT_MSGTYPE(_msgType) && (NEED_SCHEDULER_REDIRECT_ERROR(_code) || SCH_SUB_TASK_NETWORK_ERR(_code, _rspLen))) -#define SCH_NEED_RETRY(_msgType, _code) ((SCH_NETWORK_ERR(_code) && SCH_NEED_REDIRECT_MSGTYPE(_msgType)) || (_code) == TSDB_CODE_SCH_TIMEOUT_ERROR) +#define SCH_MERGE_TASK_NETWORK_ERR(_task, _code, _len) (SCH_NETWORK_ERR(_code) && (((_len) > 0) || (!SCH_IS_DATA_BIND_TASK(_task)))) +#define SCH_REDIRECT_MSGTYPE(_msgType) ((_msgType) == TDMT_SCH_QUERY || (_msgType) == TDMT_SCH_MERGE_QUERY || (_msgType) == TDMT_SCH_FETCH || (_msgType) == TDMT_SCH_MERGE_FETCH) +#define SCH_TASK_NEED_REDIRECT(_task, _msgType, _code, _rspLen) (SCH_REDIRECT_MSGTYPE(_msgType) && (NEED_SCHEDULER_REDIRECT_ERROR(_code) || SCH_MERGE_TASK_NETWORK_ERR((_task), (_code), (_rspLen)))) +#define SCH_NEED_RETRY(_msgType, _code) ((SCH_NETWORK_ERR(_code) && SCH_REDIRECT_MSGTYPE(_msgType)) || (_code) == TSDB_CODE_SCH_TIMEOUT_ERROR) #define SCH_IS_LEVEL_UNFINISHED(_level) ((_level)->taskLaunchedNum < (_level)->taskNum) #define SCH_GET_CUR_EP(_addr) (&(_addr)->epSet.eps[(_addr)->epSet.inUse]) #define SCH_SWITCH_EPSET(_addr) ((_addr)->epSet.inUse = ((_addr)->epSet.inUse + 1) % (_addr)->epSet.numOfEps) #define SCH_TASK_NUM_OF_EPS(_addr) ((_addr)->epSet.numOfEps) +#define SCH_LOG_TASK_START_TS(_task) \ + do { \ + int64_t us = taosGetTimestampUs(); \ + int32_t idx = (_task)->execId % (_task)->maxExecTimes; \ + (_task)->profile.execTime[idx] = us; \ + if (0 == (_task)->execId) { \ + (_task)->profile.startTs = us; \ + } \ + } while (0) + +#define SCH_LOG_TASK_WAIT_TS(_task) \ + do { \ + int64_t us = taosGetTimestampUs(); \ + int32_t idx = (_task)->execId % (_task)->maxExecTimes; \ + (_task)->profile.waitTime += us - (_task)->profile.execTime[idx]; \ + } while (0) + + +#define SCH_LOG_TASK_END_TS(_task) \ + do { \ + int64_t us = taosGetTimestampUs(); \ + int32_t idx = (_task)->execId % (_task)->maxExecTimes; \ + (_task)->profile.execTime[idx] = us - (_task)->profile.execTime[idx]; \ + (_task)->profile.endTs = us; \ + } while (0) + + #define SCH_JOB_ELOG(param, ...) qError("QID:0x%" PRIx64 " " param, pJob->queryId, __VA_ARGS__) #define SCH_JOB_DLOG(param, ...) qDebug("QID:0x%" PRIx64 " " param, pJob->queryId, __VA_ARGS__) @@ -355,8 +361,41 @@ extern SSchedulerMgmt schMgmt; #define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(_code); } return _code; } while (0) #define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(code); goto _return; } } while (0) -#define SCH_LOCK(type, _lock) (SCH_READ == (type) ? taosRLockLatch(_lock) : taosWLockLatch(_lock)) -#define SCH_UNLOCK(type, _lock) (SCH_READ == (type) ? taosRUnLockLatch(_lock) : taosWUnLockLatch(_lock)) +#define SCH_LOCK_DEBUG(...) do { if (gSCHDebug.lockEnable) { qDebug(__VA_ARGS__); } } while (0) + +#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000 + +#define SCH_LOCK(type, _lock) do { \ + if (SCH_READ == (type)) { \ + assert(atomic_load_64(_lock) >= 0); \ + SCH_LOCK_DEBUG("SCH RLOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + taosRLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH RLOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64(_lock) > 0); \ + } else { \ + assert(atomic_load_64(_lock) >= 0); \ + SCH_LOCK_DEBUG("SCH WLOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + taosWLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH WLOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64(_lock) & TD_RWLATCH_WRITE_FLAG_COPY); \ + } \ +} while (0) + +#define SCH_UNLOCK(type, _lock) do { \ + if (SCH_READ == (type)) { \ + assert(atomic_load_64((_lock)) > 0); \ + SCH_LOCK_DEBUG("SCH RULOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + taosRUnLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH RULOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ + } else { \ + assert(atomic_load_64((_lock)) & TD_RWLATCH_WRITE_FLAG_COPY); \ + SCH_LOCK_DEBUG("SCH WULOCK%p:%" PRIx64 ", %s:%d B", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + taosWUnLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH WULOCK%p:%" PRIx64 ", %s:%d E", (_lock), atomic_load_64(_lock), __FILE__, __LINE__); \ + assert(atomic_load_64((_lock)) >= 0); \ + } \ +} while (0) void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask); @@ -431,7 +470,11 @@ void schFreeTask(SSchJob *pJob, SSchTask *pTask); void schDropTaskInHashList(SSchJob *pJob, SHashObj *list); int32_t schLaunchLevelTasks(SSchJob *pJob, SSchLevel *level); int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask); -int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel); +int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel, int32_t levelNum); +int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask); +void schDirectPostJobRes(SSchedulerReq* pReq, int32_t errCode); + +extern SSchDebug gSCHDebug; #ifdef __cplusplus diff --git a/source/libs/scheduler/src/schDbg.c b/source/libs/scheduler/src/schDbg.c index 7f013b8f32..a6398522d3 100644 --- a/source/libs/scheduler/src/schDbg.c +++ b/source/libs/scheduler/src/schDbg.c @@ -17,6 +17,7 @@ #include "schInt.h" tsem_t schdRspSem; +SSchDebug gSCHDebug = {0}; void schdExecCallback(SExecResult* pResult, void* param, int32_t code) { if (code) { diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 13100afb8b..e482814ee7 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -337,14 +337,14 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { SCH_SET_JOB_TYPE(pJob, plan->subplanType); SSchTask task = {0}; - SCH_ERR_JRET(schInitTask(pJob, &task, plan, pLevel)); - SSchTask *pTask = taosArrayPush(pLevel->subTasks, &task); if (NULL == pTask) { SCH_TASK_ELOG("taosArrayPush task to level failed, level:%d, taskIdx:%d", pLevel->level, n); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + SCH_ERR_JRET(schInitTask(pJob, pTask, plan, pLevel, levelNum)); + SCH_ERR_JRET(schAppendJobDataSrc(pJob, pTask)); if (0 != taosHashPut(planToTask, &plan, POINTER_BYTES, &pTask, POINTER_BYTES)) { @@ -543,9 +543,12 @@ int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask) { int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp) { if (rsp->tbFName[0]) { + SCH_LOCK(SCH_WRITE, &pJob->resLock); + if (NULL == pJob->execRes.res) { pJob->execRes.res = taosArrayInit(pJob->taskNum, sizeof(STbVerInfo)); if (NULL == pJob->execRes.res) { + SCH_UNLOCK(SCH_WRITE, &pJob->resLock); SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } @@ -557,6 +560,8 @@ int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp) { taosArrayPush((SArray *)pJob->execRes.res, &tbInfo); pJob->execRes.msgType = TDMT_SCH_QUERY; + + SCH_UNLOCK(SCH_WRITE, &pJob->resLock); } return TSDB_CODE_SUCCESS; @@ -758,6 +763,17 @@ int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq) { return TSDB_CODE_SUCCESS; } +void schDirectPostJobRes(SSchedulerReq* pReq, int32_t errCode) { + if (NULL == pReq || pReq->syncReq) { + return; + } + + if (pReq->execFp) { + (*pReq->execFp)(NULL, pReq->cbParam, errCode); + } else if (pReq->fetchFp) { + (*pReq->fetchFp)(NULL, pReq->cbParam, errCode); + } +} void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode) { int32_t op = 0; @@ -796,17 +812,13 @@ void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq) { int32_t code = 0; - int8_t status = 0; - - if (schJobNeedToStop(pJob, &status)) { - SCH_JOB_ELOG("abort op %s cause of job need to stop, status:%s", schGetOpStr(type), jobTaskStatusStr(status)); - SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); - } + int8_t status = SCH_GET_JOB_STATUS(pJob); switch (type) { case SCH_OP_EXEC: if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) { SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op)); + schDirectPostJobRes(pReq, TSDB_CODE_TSC_APP_ERROR); SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } @@ -817,11 +829,16 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq case SCH_OP_FETCH: if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) { SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op)); + schDirectPostJobRes(pReq, TSDB_CODE_TSC_APP_ERROR); SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } SCH_JOB_DLOG("job start %s operation", schGetOpStr(pJob->opStatus.op)); - + + pJob->userRes.fetchRes = pReq->pFetchRes; + pJob->userRes.fetchFp = pReq->fetchFp; + pJob->userRes.cbParam = pReq->cbParam; + pJob->opStatus.syncReq = pReq->syncReq; if (!SCH_JOB_NEED_FETCH(pJob)) { @@ -834,10 +851,6 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - pJob->userRes.fetchRes = pReq->pFetchRes; - pJob->userRes.fetchFp = pReq->fetchFp; - pJob->userRes.cbParam = pReq->cbParam; - break; case SCH_OP_GET_STATUS: if (pJob->status < JOB_TASK_STATUS_INIT || pJob->levelNum <= 0 || NULL == pJob->levels) { @@ -850,6 +863,11 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } + if (schJobNeedToStop(pJob, &status)) { + SCH_JOB_ELOG("abort op %s cause of job need to stop, status:%s", schGetOpStr(type), jobTaskStatusStr(status)); + SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); + } + return TSDB_CODE_SUCCESS; } diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index f9c3d80e46..2257ba8328 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -85,7 +85,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_JRET(schValidateRspMsgType(pJob, pTask, msgType)); int32_t reqType = IsReq(pMsg) ? pMsg->msgType : (pMsg->msgType - 1); - if (SCH_NEED_REDIRECT(reqType, rspCode, pMsg->len)) { + if (SCH_TASK_NEED_REDIRECT(pTask, reqType, rspCode, pMsg->len)) { SCH_RET(schHandleRedirect(pJob, pTask, (SDataBuf *)pMsg, rspCode)); } diff --git a/source/libs/scheduler/src/schStatus.c b/source/libs/scheduler/src/schStatus.c index 091b1359e0..a4fa4f2839 100644 --- a/source/libs/scheduler/src/schStatus.c +++ b/source/libs/scheduler/src/schStatus.c @@ -77,6 +77,7 @@ int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq int32_t code = errCode; if (NULL == pJob) { + schDirectPostJobRes(pReq, errCode); SCH_RET(code); } diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index d56397283c..a6621d279d 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -46,21 +46,32 @@ void schFreeTask(SSchJob *pJob, SSchTask *pTask) { } -int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel) { +int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel, int32_t levelNum) { + int32_t code = 0; + pTask->plan = pPlan; pTask->level = pLevel; pTask->execId = -1; - pTask->maxExecTimes = SCH_TASK_MAX_EXEC_TIMES; + pTask->maxExecTimes = SCH_TASK_MAX_EXEC_TIMES(pLevel->level, levelNum); pTask->timeoutUsec = SCH_DEFAULT_TASK_TIMEOUT_USEC; - SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); pTask->taskId = schGenTaskId(); pTask->execNodes = taosHashInit(SCH_MAX_CANDIDATE_EP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - if (NULL == pTask->execNodes) { - SCH_TASK_ELOG("taosHashInit %d execNodes failed", SCH_MAX_CANDIDATE_EP_NUM); - SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + pTask->profile.execTime = taosMemoryCalloc(pTask->maxExecTimes, sizeof(int64_t)); + if (NULL == pTask->execNodes || NULL == pTask->profile.execTime) { + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + taosInitReentrantRWLatch(&pTask->lock); + + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); return TSDB_CODE_SUCCESS; + +_return: + + taosMemoryFreeClear(pTask->profile.execTime); + taosHashCleanup(pTask->execNodes); + + SCH_RET(code); } int32_t schRecordTaskSucceedNode(SSchJob *pJob, SSchTask *pTask) { @@ -253,7 +264,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) { SSchTask *parent = *(SSchTask **)taosArrayGet(pTask->parents, i); int32_t readyNum = atomic_add_fetch_32(&parent->childReady, 1); - SCH_LOCK(SCH_WRITE, &parent->lock); + SCH_LOCK_TASK(parent); SDownstreamSourceNode source = {.type = QUERY_NODE_DOWNSTREAM_SOURCE, .taskId = pTask->taskId, .schedId = schMgmt.sId, @@ -262,7 +273,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) { .fetchMsgType = SCH_FETCH_TYPE(pTask), }; qSetSubplanExecutionNode(parent->plan, pTask->plan->id.groupId, &source); - SCH_UNLOCK(SCH_WRITE, &parent->lock); + SCH_UNLOCK_TASK(parent); if (SCH_TASK_READY_FOR_LAUNCH(readyNum, parent)) { SCH_TASK_DLOG("all %d children task done, start to launch parent task 0x%" PRIx64, readyNum, parent->taskId); @@ -338,6 +349,11 @@ int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32 qClearSubplanExecutionNode(pTask->plan); + // Note: current error task and upper level merge task + if ((pData && 0 == pData->len) || NULL == pData) { + SCH_ERR_JRET(schSwitchTaskCandidateAddr(pJob, pTask)); + } + SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); int32_t childrenNum = taosArrayGetSize(pTask->children); @@ -531,10 +547,7 @@ int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) { if (SCH_IS_DATA_BIND_TASK(pTask)) { SCH_SWITCH_EPSET(&pTask->plan->execNode); } else { - int32_t candidateNum = taosArrayGetSize(pTask->candidateAddrs); - if (++pTask->candidateIdx >= candidateNum) { - pTask->candidateIdx = 0; - } + SCH_ERR_RET(schSwitchTaskCandidateAddr(pJob, pTask)); } SCH_ERR_RET(schLaunchTask(pJob, pTask)); @@ -633,6 +646,16 @@ int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet* pEpSe return TSDB_CODE_SUCCESS; } +int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask) { + int32_t candidateNum = taosArrayGetSize(pTask->candidateAddrs); + if (++pTask->candidateIdx >= candidateNum) { + pTask->candidateIdx = 0; + } + SCH_TASK_DLOG("switch task candiateIdx to %d", pTask->candidateIdx); + return TSDB_CODE_SUCCESS; +} + + int32_t schRemoveTaskFromExecList(SSchJob *pJob, SSchTask *pTask) { int32_t code = taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId)); diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c index 8b8badd67a..29e0f7ded0 100644 --- a/source/libs/stream/src/stream.c +++ b/source/libs/stream/src/stream.c @@ -208,7 +208,7 @@ int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, S int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp) { ASSERT(pRsp->inputStatus == TASK_OUTPUT_STATUS__NORMAL || pRsp->inputStatus == TASK_OUTPUT_STATUS__BLOCKED); - qInfo("task %d receive dispatch rsp", pTask->taskId); + qDebug("task %d receive dispatch rsp", pTask->taskId); int8_t old = atomic_exchange_8(&pTask->outputStatus, pRsp->inputStatus); ASSERT(old == TASK_OUTPUT_STATUS__WAIT); @@ -242,7 +242,7 @@ int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp) } int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq, SRpcMsg* pRsp) { - qInfo("task %d receive retrieve req from node %d task %d", pTask->taskId, pReq->srcNodeId, pReq->srcTaskId); + qDebug("task %d receive retrieve req from node %d task %d", pTask->taskId, pReq->srcNodeId, pReq->srcTaskId); streamTaskEnqueueRetrieve(pTask, pReq, pRsp); diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 8034840fce..98b0874b00 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -303,7 +303,7 @@ int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb) { } ASSERT(pBlock->type == STREAM_INPUT__DATA_BLOCK); - qInfo("stream continue dispatching: task %d", pTask->taskId); + qDebug("stream continue dispatching: task %d", pTask->taskId); SRpcMsg dispatchMsg = {0}; SEpSet* pEpSet = NULL; diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index e43c1e4b33..8409e1c711 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -131,7 +131,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { SSyncRaftEntry* pEntry = ths->pLogStore->getEntry(ths->pLogStore, pMsg->prevLogIndex); if (pEntry == NULL) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "getEntry error, index:%ld, since %s", pMsg->prevLogIndex, terrstr()); + snprintf(logBuf, sizeof(logBuf), "getEntry error, index:%" PRId64 ", since %s", pMsg->prevLogIndex, terrstr()); syncNodeErrorLog(ths, logBuf); return -1; } @@ -150,7 +150,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { ((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, reject, pre-index:%ld, pre-term:%lu, datalen:%d", + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries, reject, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); syncNodeEventLog(ths, logBuf); } while (0); @@ -167,10 +168,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { char host[128]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-reply to %s:%d, {term:%lu, pterm:%lu, success:%d, " - "match-index:%ld}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); } while (0); SRpcMsg rpcMsg; @@ -194,7 +194,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, accept, pre-index:%ld, pre-term:%lu, datalen:%d", + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries, accept, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); syncNodeEventLog(ths, logBuf); } while (0); @@ -207,7 +208,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { SSyncRaftEntry* pExtraEntry = ths->pLogStore->getEntry(ths->pLogStore, extraIndex); if (pExtraEntry == NULL) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "getEntry error2, index:%ld, since %s", extraIndex, terrstr()); + snprintf(logBuf, sizeof(logBuf), "getEntry error2, index:%" PRId64 ", since %s", extraIndex, terrstr()); syncNodeErrorLog(ths, logBuf); return -1; } @@ -229,7 +230,8 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { SyncIndex delBegin = ths->pLogStore->getLastIndex(ths->pLogStore); SyncIndex delEnd = extraIndex; - sTrace("syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%ld, delEnd:%ld", conflict, delBegin, delEnd); + sTrace("syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%" PRId64 ", delEnd:%" PRId64, conflict, delBegin, + delEnd); // notice! reverse roll back! for (SyncIndex index = delEnd; index >= delBegin; --index) { @@ -237,7 +239,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { SSyncRaftEntry* pRollBackEntry = ths->pLogStore->getEntry(ths->pLogStore, index); if (pRollBackEntry == NULL) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "getEntry error3, index:%ld, since %s", index, terrstr()); + snprintf(logBuf, sizeof(logBuf), "getEntry error3, index:%" PRId64 ", since %s", index, terrstr()); syncNodeErrorLog(ths, logBuf); return -1; } @@ -350,10 +352,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { char host[128]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-reply to %s:%d, {term:%lu, pterm:%lu, success:%d, " - "match-index:%ld}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); } while (0); SRpcMsg rpcMsg; @@ -421,7 +422,7 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) { ASSERT(code == 0); char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "log truncate, from %ld to %ld", delBegin, delEnd); + snprintf(eventLog, sizeof(eventLog), "log truncate, from %" PRId64 " to %" PRId64, delBegin, delEnd); syncNodeEventLog(ths, eventLog); logStoreSimpleLog2("after syncNodeMakeLogSame", ths->pLogStore); @@ -466,7 +467,7 @@ static int32_t syncNodeDoMakeLogSame(SSyncNode* ths, SyncIndex FromIndex) { ASSERT(code == 0); char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "log truncate, from %ld to %ld", delBegin, delEnd); + snprintf(eventLog, sizeof(eventLog), "log truncate, from %" PRId64 " to %" PRId64, delBegin, delEnd); syncNodeEventLog(ths, eventLog); logStoreSimpleLog2("after syncNodeMakeLogSame", ths->pLogStore); @@ -499,13 +500,13 @@ static bool syncNodeOnAppendEntriesBatchLogOK(SSyncNode* pSyncNode, SyncAppendEn SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); if (pMsg->prevLogIndex > myLastIndex) { - sDebug("vgId:%d sync log not ok, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d sync log not ok, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); if (myPreLogTerm == SYNC_TERM_INVALID) { - sDebug("vgId:%d sync log not ok2, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d sync log not ok2, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } @@ -513,7 +514,7 @@ static bool syncNodeOnAppendEntriesBatchLogOK(SSyncNode* pSyncNode, SyncAppendEn return true; } - sDebug("vgId:%d sync log not ok3, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d sync log not ok3, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } @@ -526,13 +527,13 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); if (pMsg->prevLogIndex > myLastIndex) { - sDebug("vgId:%d sync log not ok, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d sync log not ok, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); if (myPreLogTerm == SYNC_TERM_INVALID) { - sDebug("vgId:%d sync log not ok2, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d sync log not ok2, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } @@ -540,7 +541,7 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries return true; } - sDebug("vgId:%d sync log not ok3, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); + sDebug("vgId:%d sync log not ok3, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); return false; } @@ -597,7 +598,8 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc do { char logBuf[128]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch, fake match2, {pre-index:%ld, pre-term:%lu, datalen:%d, datacount:%d}", + "recv sync-append-entries-batch, fake match2, {pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", datalen:%d, datacount:%d}", pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen, pMsg->dataCount); syncNodeEventLog(ths, logBuf); } while (0); @@ -657,10 +659,9 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc char host[128]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-reply to %s:%d, {term:%lu, pterm:%lu, success:%d, " - "match-index:%ld}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); } while (0); // send response @@ -697,7 +698,8 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc do { char logBuf[128]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch, not match, {pre-index:%ld, pre-term:%lu, datalen:%d, datacount:%d}", + "recv sync-append-entries-batch, not match, {pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", datalen:%d, datacount:%d}", pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen, pMsg->dataCount); syncNodeEventLog(ths, logBuf); } while (0); @@ -716,10 +718,9 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc char host[128]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-reply to %s:%d, {term:%lu, pterm:%lu, success:%d, " - "match-index:%ld}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); } while (0); // send response @@ -754,7 +755,8 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc do { char logBuf[128]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch, match, {pre-index:%ld, pre-term:%lu, datalen:%d, datacount:%d}", + "recv sync-append-entries-batch, match, {pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", datalen:%d, datacount:%d}", pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen, pMsg->dataCount); syncNodeEventLog(ths, logBuf); } while (0); @@ -800,10 +802,9 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc char host[128]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-reply to %s:%d, {term:%lu, pterm:%lu, success:%d, " - "match-index:%ld}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); } while (0); // send response @@ -825,8 +826,8 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc ths->commitIndex = snapshot.lastApplyIndex; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%ld to index:%ld", commitBegin, - commitEnd); + snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, + commitBegin, commitEnd); syncNodeEventLog(ths, eventLog); } @@ -927,7 +928,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs if (condition) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, fake match, pre-index:%ld, pre-term:%lu", + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, fake match, pre-index:%" PRId64 ", pre-term:%" PRIu64, pMsg->prevLogIndex, pMsg->prevLogTerm); syncNodeEventLog(ths, logBuf); @@ -967,8 +968,8 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs do { char logBuf[128]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries, fake match2, pre-index:%ld, pre-term:%lu, datalen:%d", pMsg->prevLogIndex, - pMsg->prevLogTerm, pMsg->dataLen); + "recv sync-append-entries, fake match2, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", + pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); syncNodeEventLog(ths, logBuf); } while (0); @@ -1020,10 +1021,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs char host[128]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-reply to %s:%d, {term:%lu, pterm:%lu, success:%d, " - "match-index:%ld}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); } while (0); // send response @@ -1058,7 +1058,8 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs if (condition) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, not match, pre-index:%ld, pre-term:%lu, datalen:%d", + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries, not match, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); syncNodeEventLog(ths, logBuf); @@ -1076,10 +1077,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs char host[128]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-reply to %s:%d, {term:%lu, pterm:%lu, success:%d, " - "match-index:%ld}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); } while (0); // send response @@ -1111,7 +1111,8 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs bool hasAppendEntries = pMsg->dataLen > 0; char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, match, pre-index:%ld, pre-term:%lu, datalen:%d", + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries, match, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); syncNodeEventLog(ths, logBuf); @@ -1152,10 +1153,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs char host[128]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-reply to %s:%d, {term:%lu, pterm:%lu, success:%d, " - "match-index:%ld}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); } while (0); // send response @@ -1177,8 +1177,8 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs ths->commitIndex = snapshot.lastApplyIndex; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%ld to index:%ld", commitBegin, - commitEnd); + snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, + commitBegin, commitEnd); syncNodeEventLog(ths, eventLog); } diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index afea32d672..c18c2b4d38 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -52,7 +52,8 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%lu, drop stale response", pMsg->term); + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%" PRIu64 ", drop stale response", + pMsg->term); syncNodeEventLog(ths, logBuf); return 0; } @@ -70,7 +71,7 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p if (pMsg->term > ths->pRaftStore->currentTerm) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%lu", pMsg->term); + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%" PRIu64, pMsg->term); syncNodeErrorLog(ths, logBuf); return -1; } @@ -155,7 +156,8 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%lu, drop stale response", pMsg->term); + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%" PRIu64 ", drop stale response", + pMsg->term); syncNodeEventLog(ths, logBuf); return -1; } @@ -163,7 +165,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie // error term if (pMsg->term > ths->pRaftStore->currentTerm) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%lu", pMsg->term); + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%" PRIu64, pMsg->term); syncNodeErrorLog(ths, logBuf); return -1; } @@ -209,8 +211,8 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "reset next-index:%ld, match-index:%ld for %s:%d", newNextIndex, newMatchIndex, - host, port); + snprintf(logBuf, sizeof(logBuf), "reset next-index:%" PRId64 ", match-index:%" PRId64 " for %s:%d", newNextIndex, + newMatchIndex, host, port); syncNodeEventLog(ths, logBuf); } while (0); @@ -233,10 +235,10 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie // do nothing } else { - SSyncRaftEntry* pEntry; - int32_t code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, nextIndex, &pEntry); - ASSERT(code == 0); - syncNodeStartSnapshotOnce(ths, SYNC_INDEX_BEGIN, nextIndex, pEntry->term, pMsg); + SSnapshot oldSnapshot; + ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &oldSnapshot); + SyncTerm newSnapshotTerm = oldSnapshot.lastApplyTerm; + syncNodeStartSnapshotOnce(ths, SYNC_INDEX_BEGIN, nextIndex, newSnapshotTerm, pMsg); // get sender SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId)); @@ -263,8 +265,8 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie SyncIndex newNextIndex = nextIndex; SyncIndex newMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "reset2 next-index:%ld, match-index:%ld for %s:%d", newNextIndex, newMatchIndex, - host, port); + snprintf(logBuf, sizeof(logBuf), "reset2 next-index:%" PRId64 ", match-index:%" PRId64 " for %s:%d", newNextIndex, + newMatchIndex, host, port); syncNodeEventLog(ths, logBuf); } while (0); @@ -288,7 +290,8 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%lu, drop stale response", pMsg->term); + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%" PRIu64 ", drop stale response", + pMsg->term); syncNodeEventLog(ths, logBuf); return 0; } @@ -306,7 +309,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries if (pMsg->term > ths->pRaftStore->currentTerm) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%lu", pMsg->term); + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%" PRIu64, pMsg->term); syncNodeErrorLog(ths, logBuf); return -1; } @@ -318,7 +321,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1); if (gRaftDetailLog) { - sTrace("update next match, index:%ld, success:%d", pMsg->matchIndex + 1, pMsg->success); + sTrace("update next match, index:%" PRId64 ", success:%d", pMsg->matchIndex + 1, pMsg->success); } // matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex] @@ -332,7 +335,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries } else { SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); if (gRaftDetailLog) { - sTrace("update next index not match, begin, index:%ld, success:%d", nextIndex, pMsg->success); + sTrace("update next index not match, begin, index:%" PRId64 ", success:%d", nextIndex, pMsg->success); } // notice! int64, uint64 @@ -376,7 +379,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex); if (gRaftDetailLog) { - sTrace("update next index not match, end, index:%ld, success:%d", nextIndex, pMsg->success); + sTrace("update next index not match, end, index:%" PRId64 ", success:%d", nextIndex, pMsg->success); } } diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 3e8b020230..b3cdd079a4 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -57,7 +57,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { pSyncNode->commitIndex = snapshot.lastApplyIndex; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%ld to index:%ld", commitBegin, commitEnd); + snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, + commitEnd); syncNodeEventLog(pSyncNode, eventLog); } @@ -67,8 +68,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { bool agree = syncAgree(pSyncNode, index); if (gRaftDetailLog) { - sTrace("syncMaybeAdvanceCommitIndex syncAgree:%d, index:%ld, pSyncNode->commitIndex:%ld", agree, index, - pSyncNode->commitIndex); + sTrace("syncMaybeAdvanceCommitIndex syncAgree:%d, index:%" PRId64 ", pSyncNode->commitIndex:%" PRId64, agree, + index, pSyncNode->commitIndex); } if (agree) { @@ -82,7 +83,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { newCommitIndex = index; if (gRaftDetailLog) { - sTrace("syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%ld commit, pSyncNode->commitIndex:%ld", + sTrace("syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%" PRId64 + " commit, pSyncNode->commitIndex:%" PRId64, newCommitIndex, pSyncNode->commitIndex); } @@ -90,10 +92,9 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { break; } else { if (gRaftDetailLog) { - sTrace( - "syncMaybeAdvanceCommitIndex can not commit due to term not equal, pEntry->term:%lu, " - "pSyncNode->pRaftStore->currentTerm:%lu", - pEntry->term, pSyncNode->pRaftStore->currentTerm); + sTrace("syncMaybeAdvanceCommitIndex can not commit due to term not equal, pEntry->term:%" PRIu64 + ", pSyncNode->pRaftStore->currentTerm:%" PRIu64, + pEntry->term, pSyncNode->pRaftStore->currentTerm); } } @@ -107,7 +108,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { SyncIndex endIndex = newCommitIndex; if (gRaftDetailLog) { - sTrace("syncMaybeAdvanceCommitIndex sync commit %ld", newCommitIndex); + sTrace("syncMaybeAdvanceCommitIndex sync commit %" PRId64, newCommitIndex); } // update commit index diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c index 2712b4edc6..6dcbb598ae 100644 --- a/source/libs/sync/src/syncElection.c +++ b/source/libs/sync/src/syncElection.c @@ -123,8 +123,9 @@ int32_t syncNodeRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, con char host[128]; uint16_t port; syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-request-vote to %s:%d, {term:%lu, last-index:%ld, last-term:%lu}", pSyncNode->vgId, host, - port, pMsg->term, pMsg->lastLogTerm, pMsg->lastLogIndex); + sDebug("vgId:%d, send sync-request-vote to %s:%d, {term:%" PRIu64 ", last-index:%" PRId64 ", last-term:%" PRIu64 + "}", + pSyncNode->vgId, host, port, pMsg->term, pMsg->lastLogTerm, pMsg->lastLogIndex); } while (0); SRpcMsg rpcMsg; diff --git a/source/libs/sync/src/syncIndexMgr.c b/source/libs/sync/src/syncIndexMgr.c index 10f0e0e335..a9c1147fc1 100644 --- a/source/libs/sync/src/syncIndexMgr.c +++ b/source/libs/sync/src/syncIndexMgr.c @@ -134,28 +134,28 @@ char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) { // for debug ------------------- void syncIndexMgrPrint(SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); - printf("syncIndexMgrPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncIndexMgrPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); - printf("syncIndexMgrPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncIndexMgrPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncIndexMgrLog(SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); - sTrace("syncIndexMgrLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncIndexMgrLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj) { if (gRaftDetailLog) { char *serialized = syncIndexMgr2Str(pObj); - sTrace("syncIndexMgrLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncIndexMgrLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -173,7 +173,7 @@ void syncIndexMgrSetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, S char host[128]; uint16_t port; syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port); - sError("vgId:%d index mgr set for %s:%d, term:%lu error", pSyncIndexMgr->pSyncNode->vgId, host, port, term); + sError("vgId:%d index mgr set for %s:%d, term:%" PRIu64 " error", pSyncIndexMgr->pSyncNode->vgId, host, port, term); } SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId) { diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 7fa13c9dc8..50e2588e19 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -477,8 +477,8 @@ SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapsho lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[i]; } } - sTrace("vgId:%d, sync get snapshot last config index, index:%ld lcindex:%ld", pSyncNode->vgId, snapshotLastApplyIndex, - lastIndex); + sTrace("vgId:%d, sync get snapshot last config index, index:%" PRId64 " lcindex:%" PRId64, pSyncNode->vgId, + snapshotLastApplyIndex, lastIndex); return lastIndex; } @@ -590,7 +590,7 @@ int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo) void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb) { SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { - sTrace("syncSetQ get pSyncNode is NULL, rid:%ld", rid); + sTrace("syncSetQ get pSyncNode is NULL, rid:%" PRId64, rid); return; } ASSERT(rid == pSyncNode->rid); @@ -602,7 +602,7 @@ void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb) { char* sync2SimpleStr(int64_t rid) { SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { - sTrace("syncSetRpc get pSyncNode is NULL, rid:%ld", rid); + sTrace("syncSetRpc get pSyncNode is NULL, rid:%" PRId64, rid); return NULL; } ASSERT(rid == pSyncNode->rid); @@ -819,13 +819,13 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { rpcFreeCont(rpcMsg.pCont); syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum); ret = 1; - sDebug("vgId:%d optimized index:%ld success, msgtype:%s,%d", pSyncNode->vgId, retIndex, + sDebug("vgId:%d optimized index:%" PRId64 " success, msgtype:%s,%d", pSyncNode->vgId, retIndex, TMSG_INFO(pMsg->msgType), pMsg->msgType); } else { ret = -1; terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - sError("vgId:%d optimized index:%ld error, msgtype:%s,%d", pSyncNode->vgId, retIndex, TMSG_INFO(pMsg->msgType), - pMsg->msgType); + sError("vgId:%d optimized index:%" PRId64 " error, msgtype:%s,%d", pSyncNode->vgId, retIndex, + TMSG_INFO(pMsg->msgType), pMsg->msgType); } } else { @@ -1391,7 +1391,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) { cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache); // life cycle - snprintf(u64buf, sizeof(u64buf), "%ld", pSyncNode->rid); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->rid); cJSON_AddStringToObject(pRoot, "rid", u64buf); // tla+ server vars @@ -1409,7 +1409,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) { // tla+ log vars cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore)); - snprintf(u64buf, sizeof(u64buf), "%" PRId64 "", pSyncNode->commitIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->commitIndex); cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); // timer ms init @@ -1421,39 +1421,39 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) { snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer); cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf); cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->pingTimerLogicClock); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerLogicClock); cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->pingTimerLogicClockUser); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerLogicClockUser); cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf); snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB); cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->pingTimerCounter); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerCounter); cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf); // elect timer snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer); cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf); cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->electTimerLogicClock); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->electTimerLogicClock); cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->electTimerLogicClockUser); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->electTimerLogicClockUser); cJSON_AddStringToObject(pRoot, "electTimerLogicClockUser", u64buf); snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB); cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->electTimerCounter); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->electTimerCounter); cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf); // heartbeat timer snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer); cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf); cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->heartbeatTimerLogicClock); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerLogicClock); cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->heartbeatTimerLogicClockUser); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerLogicClockUser); cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf); snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB); cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->heartbeatTimerCounter); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerCounter); cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf); // callback @@ -1527,10 +1527,12 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " + "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 + ", lastsnapshot:%" PRId64 + ", standby:%d, " "strategy:%d, batch:%d, " "replica-num:%d, " - "lconfig:%ld, changing:%d, restore:%d, %s", + "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, @@ -1546,10 +1548,12 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, - "vgId:%d, sync %s %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " + "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 + ", lastsnapshot:%" PRId64 + ", standby:%d, " "strategy:%d, batch:%d, " "replica-num:%d, " - "lconfig:%ld, changing:%d, restore:%d, %s", + "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, @@ -1590,9 +1594,11 @@ void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " + "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 + ", lastsnapshot:%" PRId64 + ", standby:%d, " "replica-num:%d, " - "lconfig:%ld, changing:%d, restore:%d, %s", + "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, @@ -1607,9 +1613,11 @@ void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, - "vgId:%d, sync %s %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " + "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 + ", lastsnapshot:%" PRId64 + ", standby:%d, " "replica-num:%d, " - "lconfig:%ld, changing:%d, restore:%d, %s", + "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, @@ -1636,9 +1644,11 @@ char* syncNode2SimpleStr(const SSyncNode* pSyncNode) { SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); snprintf(s, len, - "vgId:%d, sync %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " + "vgId:%d, sync %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 + ", lastsnapshot:%" PRId64 + ", standby:%d, " "replica-num:%d, " - "lconfig:%ld, changing:%d, restore:%d", + "lconfig:%" PRId64 ", changing:%d, restore:%d", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish); @@ -1783,7 +1793,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde do { char eventLog[256]; - snprintf(eventLog, sizeof(eventLog), "snapshot sender reset for %lu, newIndex:%d, %s:%d, %p", + snprintf(eventLog, sizeof(eventLog), "snapshot sender reset for: %" PRIu64 ", newIndex:%d, %s:%d, %p", (pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]); syncNodeEventLog(pSyncNode, eventLog); } while (0); @@ -1839,8 +1849,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde char tmpbuf[512]; char* oldStr = syncCfg2SimpleStr(&oldConfig); char* newStr = syncCfg2SimpleStr(pNewConfig); - snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%ld, %s --> %s", oldConfig.replicaNum, - pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); + snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%" PRId64 ", %s --> %s", + oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); taosMemoryFree(oldStr); taosMemoryFree(newStr); @@ -1863,8 +1873,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde char tmpbuf[512]; char* oldStr = syncCfg2SimpleStr(&oldConfig); char* newStr = syncCfg2SimpleStr(pNewConfig); - snprintf(tmpbuf, sizeof(tmpbuf), "do not config change from %d to %d, index:%ld, %s --> %s", oldConfig.replicaNum, - pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); + snprintf(tmpbuf, sizeof(tmpbuf), "do not config change from %d to %d, index:%" PRId64 ", %s --> %s", + oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); taosMemoryFree(oldStr); taosMemoryFree(newStr); syncNodeEventLog(pSyncNode, tmpbuf); @@ -1901,7 +1911,7 @@ void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) { if (term > pSyncNode->pRaftStore->currentTerm) { raftStoreSetTerm(pSyncNode->pRaftStore, term); char tmpBuf[64]; - snprintf(tmpBuf, sizeof(tmpBuf), "update term to %lu", term); + snprintf(tmpBuf, sizeof(tmpBuf), "update term to %" PRIu64, term); syncNodeBecomeFollower(pSyncNode, tmpBuf); raftStoreClearVote(pSyncNode->pRaftStore); } @@ -2189,7 +2199,7 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "sync node get pre term error, index:%ld", index); + snprintf(logBuf, sizeof(logBuf), "sync node get pre term error, index:%" PRId64, index); syncNodeErrorLog(pSyncNode, logBuf); } while (0); @@ -2206,35 +2216,35 @@ int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex // for debug -------------- void syncNodePrint(SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); - printf("syncNodePrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncNodePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncNodePrint2(char* s, SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); - printf("syncNodePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncNodePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncNodeLog(SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog | len:%lu | %s", strlen(serialized), serialized); + sTraceLong("syncNodeLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncNodeLog2(char* s, SSyncNode* pObj) { if (gRaftDetailLog) { char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTraceLong("syncNodeLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } void syncNodeLog3(char* s, SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog3 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTraceLong("syncNodeLog3 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } @@ -2269,7 +2279,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) { } } else { - sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%" PRIu64 ", pingTimerLogicClockUser:%" PRIu64 "", + sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%" PRIu64 ", pingTimerLogicClockUser:%" PRIu64, pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser); } } @@ -2304,7 +2314,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { sError("sync env is stop, syncNodeEqElectTimer"); } } else { - sTrace("==syncNodeEqElectTimer== electTimerLogicClock:%" PRIu64 ", electTimerLogicClockUser:%" PRIu64 "", + sTrace("==syncNodeEqElectTimer== electTimerLogicClock:%" PRIu64 ", electTimerLogicClockUser:%" PRIu64, pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser); } } @@ -2399,8 +2409,9 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) { // log state char logBuf[1024] = {0}; snprintf(logBuf, sizeof(logBuf), - "==syncNodeOnPingCb== vgId:%d, state: %d, %s, term:%lu electTimerLogicClock:%lu, " - "electTimerLogicClockUser:%lu, electTimerMS:%d", + "==syncNodeOnPingCb== vgId:%d, state: %d, %s, term:%" PRIu64 " electTimerLogicClock:%" PRIu64 + ", " + "electTimerLogicClockUser:%" PRIu64 ", electTimerMS:%d", ths->vgId, ths->state, syncUtilState2String(ths->state), ths->pRaftStore->currentTerm, ths->electTimerLogicClock, ths->electTimerLogicClockUser, ths->electTimerMS); @@ -2610,7 +2621,7 @@ static int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftE ASSERT(ret == 0); char eventLog[256]; - snprintf(eventLog, sizeof(eventLog), "maybe leader transfer to %s:%d %lu", + snprintf(eventLog, sizeof(eventLog), "maybe leader transfer to %s:%d %" PRIu64, pSyncLeaderTransfer->newNodeInfo.nodeFqdn, pSyncLeaderTransfer->newNodeInfo.nodePort, pSyncLeaderTransfer->newLeaderId.addr); syncNodeEventLog(ths, eventLog); @@ -2680,7 +2691,7 @@ static int32_t syncNodeConfigChangeFinish(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyn char tmpbuf[512]; char* oldStr = syncCfg2SimpleStr(&(pFinish->oldCfg)); char* newStr = syncCfg2SimpleStr(&(pFinish->newCfg)); - snprintf(tmpbuf, sizeof(tmpbuf), "config change finish from %d to %d, index:%ld, %s --> %s", + snprintf(tmpbuf, sizeof(tmpbuf), "config change finish from %d to %d, index:%" PRId64 ", %s --> %s", pFinish->oldCfg.replicaNum, pFinish->newCfg.replicaNum, pFinish->newCfgIndex, oldStr, newStr); taosMemoryFree(oldStr); taosMemoryFree(newStr); @@ -2741,7 +2752,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, ESyncState state = flag; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by wal from index:%ld to index:%ld", beginIndex, endIndex); + snprintf(eventLog, sizeof(eventLog), "commit by wal from index:%" PRId64 " to index:%" PRId64, beginIndex, endIndex); syncNodeEventLog(ths, eventLog); // execute fsm @@ -2765,7 +2776,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "index:%ld, internalExecute:%d", i, internalExecute); + snprintf(logBuf, sizeof(logBuf), "index:%" PRId64 ", internalExecute:%d", i, internalExecute); syncNodeEventLog(ths, logBuf); } while (0); @@ -2822,7 +2833,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, ths->restoreFinish = true; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "restore finish, index:%ld", pEntry->index); + snprintf(eventLog, sizeof(eventLog), "restore finish, index:%" PRId64, pEntry->index); syncNodeEventLog(ths, eventLog); } } diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 697c25f304..42a3290d5b 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -133,28 +133,28 @@ char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) { // for debug ---------------------- void syncRpcMsgPrint(SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); - printf("syncRpcMsgPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncRpcMsgPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); - printf("syncRpcMsgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncRpcMsgPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRpcMsgLog(SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); - sTrace("syncRpcMsgLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncRpcMsgLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) { if (gRaftDetailLog) { char* serialized = syncRpcMsg2Str(pMsg); - sTrace("syncRpcMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncRpcMsgLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -242,7 +242,7 @@ cJSON* syncTimeout2Json(const SyncTimeout* pMsg) { cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON_AddNumberToObject(pRoot, "timeoutType", pMsg->timeoutType); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->logicClock); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->logicClock); cJSON_AddStringToObject(pRoot, "logicClock", u64buf); cJSON_AddNumberToObject(pRoot, "timerMS", pMsg->timerMS); snprintf(u64buf, sizeof(u64buf), "%p", pMsg->data); @@ -271,21 +271,21 @@ void syncTimeoutPrint(const SyncTimeout* pMsg) { void syncTimeoutPrint2(char* s, const SyncTimeout* pMsg) { char* serialized = syncTimeout2Str(pMsg); - printf("syncTimeoutPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncTimeoutPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncTimeoutLog(const SyncTimeout* pMsg) { char* serialized = syncTimeout2Str(pMsg); - sTrace("syncTimeoutLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncTimeoutLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) { if (gRaftDetailLog) { char* serialized = syncTimeout2Str(pMsg); - sTrace("syncTimeoutLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncTimeoutLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -472,7 +472,7 @@ cJSON* syncPing2Json(const SyncPing* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -487,7 +487,7 @@ cJSON* syncPing2Json(const SyncPing* pMsg) { cJSON_AddItemToObject(pRoot, "srcId", pSrcId); cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); cJSON_AddStringToObject(pDestId, "addr", u64buf); { uint64_t u64 = pMsg->destId.addr; @@ -526,28 +526,28 @@ char* syncPing2Str(const SyncPing* pMsg) { // for debug ---------------------- void syncPingPrint(const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); - printf("syncPingPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncPingPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncPingPrint2(char* s, const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); - printf("syncPingPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncPingPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncPingLog(const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); - sTrace("syncPingLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncPingLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncPingLog2(char* s, const SyncPing* pMsg) { if (gRaftDetailLog) { char* serialized = syncPing2Str(pMsg); - sTrace("syncPingLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncPingLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -734,7 +734,7 @@ cJSON* syncPingReply2Json(const SyncPingReply* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -749,7 +749,7 @@ cJSON* syncPingReply2Json(const SyncPingReply* pMsg) { cJSON_AddItemToObject(pRoot, "srcId", pSrcId); cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); cJSON_AddStringToObject(pDestId, "addr", u64buf); { uint64_t u64 = pMsg->destId.addr; @@ -902,7 +902,7 @@ cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) { cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->seqNum); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->seqNum); cJSON_AddStringToObject(pRoot, "seqNum", u64buf); cJSON_AddNumberToObject(pRoot, "isWeak", pMsg->isWeak); cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); @@ -931,28 +931,28 @@ char* syncClientRequest2Str(const SyncClientRequest* pMsg) { // for debug ---------------------- void syncClientRequestPrint(const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); - printf("syncClientRequestPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncClientRequestPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); - printf("syncClientRequestPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncClientRequestPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncClientRequestLog(const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); - sTrace("syncClientRequestLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncClientRequestLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) { if (gRaftDetailLog) { char* serialized = syncClientRequest2Str(pMsg); - sTrace("syncClientRequestLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncClientRequestLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1101,28 +1101,28 @@ char* syncClientRequestBatch2Str(const SyncClientRequestBatch* pMsg) { // for debug ---------------------- void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg) { char* serialized = syncClientRequestBatch2Str(pMsg); - printf("syncClientRequestBatchPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncClientRequestBatchPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg) { char* serialized = syncClientRequestBatch2Str(pMsg); - printf("syncClientRequestBatchPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncClientRequestBatchPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) { char* serialized = syncClientRequestBatch2Str(pMsg); - sTrace("syncClientRequestBatchLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncClientRequestBatchLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) { if (gRaftDetailLog) { char* serialized = syncClientRequestBatch2Str(pMsg); - sTraceLong("syncClientRequestBatchLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTraceLong("syncClientRequestBatchLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1201,7 +1201,7 @@ cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -1229,11 +1229,11 @@ cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) { cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); cJSON_AddItemToObject(pRoot, "destId", pDestId); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->lastLogIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastLogIndex); cJSON_AddStringToObject(pRoot, "lastLogIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastLogTerm); cJSON_AddStringToObject(pRoot, "lastLogTerm", u64buf); } @@ -1252,28 +1252,28 @@ char* syncRequestVote2Str(const SyncRequestVote* pMsg) { // for debug ---------------------- void syncRequestVotePrint(const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); - printf("syncRequestVotePrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncRequestVotePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVotePrint2(char* s, const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); - printf("syncRequestVotePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncRequestVotePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVoteLog(const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); - sTrace("syncRequestVoteLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncRequestVoteLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg) { if (gRaftDetailLog) { char* serialized = syncRequestVote2Str(pMsg); - sTrace("syncRequestVoteLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncRequestVoteLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1352,7 +1352,7 @@ cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -1380,7 +1380,7 @@ cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg) { cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); cJSON_AddItemToObject(pRoot, "destId", pDestId); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); cJSON_AddNumberToObject(pRoot, "vote_granted", pMsg->voteGranted); } @@ -1400,28 +1400,28 @@ char* syncRequestVoteReply2Str(const SyncRequestVoteReply* pMsg) { // for debug ---------------------- void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - printf("syncRequestVoteReplyPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncRequestVoteReplyPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - printf("syncRequestVoteReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncRequestVoteReplyPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - sTrace("syncRequestVoteReplyLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncRequestVoteReplyLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) { if (gRaftDetailLog) { char* serialized = syncRequestVoteReply2Str(pMsg); - sTrace("syncRequestVoteReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncRequestVoteReplyLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1502,7 +1502,7 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -1517,7 +1517,7 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) { cJSON_AddItemToObject(pRoot, "srcId", pSrcId); cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); cJSON_AddStringToObject(pDestId, "addr", u64buf); { uint64_t u64 = pMsg->destId.addr; @@ -1531,19 +1531,19 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) { cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); cJSON_AddItemToObject(pRoot, "destId", pDestId); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->privateTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->prevLogIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->prevLogIndex); cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->prevLogTerm); cJSON_AddStringToObject(pRoot, "pre_log_term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->commitIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex); cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); @@ -1571,28 +1571,28 @@ char* syncAppendEntries2Str(const SyncAppendEntries* pMsg) { // for debug ---------------------- void syncAppendEntriesPrint(const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); - printf("syncAppendEntriesPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncAppendEntriesPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); - printf("syncAppendEntriesPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncAppendEntriesPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesLog(const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); - sTrace("syncAppendEntriesLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncAppendEntriesLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) { if (gRaftDetailLog) { char* serialized = syncAppendEntries2Str(pMsg); - sTrace("syncAppendEntriesLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncAppendEntriesLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1714,7 +1714,7 @@ cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -1729,7 +1729,7 @@ cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) { cJSON_AddItemToObject(pRoot, "srcId", pSrcId); cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); cJSON_AddStringToObject(pDestId, "addr", u64buf); { uint64_t u64 = pMsg->destId.addr; @@ -1743,19 +1743,19 @@ cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) { cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); cJSON_AddItemToObject(pRoot, "destId", pDestId); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->prevLogIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->prevLogIndex); cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->prevLogTerm); cJSON_AddStringToObject(pRoot, "prevLogTerm", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->commitIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex); cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->privateTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount); @@ -1810,28 +1810,28 @@ char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg) { // for debug ---------------------- void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg) { char* serialized = syncAppendEntriesBatch2Str(pMsg); - printf("syncAppendEntriesBatchPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncAppendEntriesBatchPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg) { char* serialized = syncAppendEntriesBatch2Str(pMsg); - printf("syncAppendEntriesBatchPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncAppendEntriesBatchPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) { char* serialized = syncAppendEntriesBatch2Str(pMsg); - sTrace("syncAppendEntriesBatchLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncAppendEntriesBatchLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) { if (gRaftDetailLog) { char* serialized = syncAppendEntriesBatch2Str(pMsg); - sTraceLong("syncAppendEntriesBatchLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTraceLong("syncAppendEntriesBatchLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1910,7 +1910,7 @@ cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -1925,7 +1925,7 @@ cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) { cJSON_AddItemToObject(pRoot, "srcId", pSrcId); cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); cJSON_AddStringToObject(pDestId, "addr", u64buf); { uint64_t u64 = pMsg->destId.addr; @@ -1939,13 +1939,13 @@ cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) { cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); cJSON_AddItemToObject(pRoot, "destId", pDestId); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->privateTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); cJSON_AddNumberToObject(pRoot, "success", pMsg->success); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->matchIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->matchIndex); cJSON_AddStringToObject(pRoot, "matchIndex", u64buf); } @@ -1964,28 +1964,28 @@ char* syncAppendEntriesReply2Str(const SyncAppendEntriesReply* pMsg) { // for debug ---------------------- void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); - printf("syncAppendEntriesReplyPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncAppendEntriesReplyPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); - printf("syncAppendEntriesReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncAppendEntriesReplyPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); - sTrace("syncAppendEntriesReplyLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncAppendEntriesReplyLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) { if (gRaftDetailLog) { char* serialized = syncAppendEntriesReply2Str(pMsg); - sTrace("syncAppendEntriesReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncAppendEntriesReplyLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2083,13 +2083,13 @@ cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->fsmMeta.index); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fsmMeta.index); cJSON_AddStringToObject(pRoot, "fsmMeta.index", u64buf); cJSON_AddNumberToObject(pRoot, "fsmMeta.isWeak", pMsg->fsmMeta.isWeak); cJSON_AddNumberToObject(pRoot, "fsmMeta.code", pMsg->fsmMeta.code); cJSON_AddNumberToObject(pRoot, "fsmMeta.state", pMsg->fsmMeta.state); cJSON_AddStringToObject(pRoot, "fsmMeta.state.str", syncUtilState2String(pMsg->fsmMeta.state)); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->fsmMeta.seqNum); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->fsmMeta.seqNum); cJSON_AddStringToObject(pRoot, "fsmMeta.seqNum", u64buf); cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); @@ -2117,28 +2117,28 @@ char* syncApplyMsg2Str(const SyncApplyMsg* pMsg) { // for debug ---------------------- void syncApplyMsgPrint(const SyncApplyMsg* pMsg) { char* serialized = syncApplyMsg2Str(pMsg); - printf("syncApplyMsgPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncApplyMsgPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg) { char* serialized = syncApplyMsg2Str(pMsg); - printf("syncApplyMsgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncApplyMsgPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncApplyMsgLog(const SyncApplyMsg* pMsg) { char* serialized = syncApplyMsg2Str(pMsg); - sTrace("ssyncApplyMsgLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("ssyncApplyMsgLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) { if (gRaftDetailLog) { char* serialized = syncApplyMsg2Str(pMsg); - sTrace("syncApplyMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncApplyMsgLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2219,7 +2219,7 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -2234,7 +2234,7 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) { cJSON_AddItemToObject(pRoot, "srcId", pSrcId); cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); cJSON_AddStringToObject(pDestId, "addr", u64buf); { uint64_t u64 = pMsg->destId.addr; @@ -2248,23 +2248,23 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) { cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); cJSON_AddItemToObject(pRoot, "destId", pDestId); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->privateTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->beginIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->beginIndex); cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->lastIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex); cJSON_AddStringToObject(pRoot, "lastIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->lastConfigIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastConfigIndex); cJSON_AddStringToObject(pRoot, "lastConfigIndex", u64buf); cJSON_AddItemToObject(pRoot, "lastConfig", syncCfg2Json((SSyncCfg*)&(pMsg->lastConfig))); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastTerm); cJSON_AddStringToObject(pRoot, "lastTerm", u64buf); cJSON_AddNumberToObject(pRoot, "seq", pMsg->seq); @@ -2294,28 +2294,28 @@ char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg) { // for debug ---------------------- void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg) { char* serialized = syncSnapshotSend2Str(pMsg); - printf("syncSnapshotSendPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncSnapshotSendPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg) { char* serialized = syncSnapshotSend2Str(pMsg); - printf("syncSnapshotSendPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncSnapshotSendPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) { char* serialized = syncSnapshotSend2Str(pMsg); - sTrace("syncSnapshotSendLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncSnapshotSendLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) { if (gRaftDetailLog) { char* serialized = syncSnapshotSend2Str(pMsg); - sTrace("syncSnapshotSendLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncSnapshotSendLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2394,7 +2394,7 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) { cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -2409,7 +2409,7 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) { cJSON_AddItemToObject(pRoot, "srcId", pSrcId); cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); cJSON_AddStringToObject(pDestId, "addr", u64buf); { uint64_t u64 = pMsg->destId.addr; @@ -2423,16 +2423,16 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) { cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); cJSON_AddItemToObject(pRoot, "destId", pDestId); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->privateTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->lastIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex); cJSON_AddStringToObject(pRoot, "lastIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastTerm); cJSON_AddStringToObject(pRoot, "lastTerm", u64buf); cJSON_AddNumberToObject(pRoot, "ack", pMsg->ack); @@ -2454,28 +2454,28 @@ char* syncSnapshotRsp2Str(const SyncSnapshotRsp* pMsg) { // for debug ---------------------- void syncSnapshotRspPrint(const SyncSnapshotRsp* pMsg) { char* serialized = syncSnapshotRsp2Str(pMsg); - printf("syncSnapshotRspPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncSnapshotRspPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg) { char* serialized = syncSnapshotRsp2Str(pMsg); - printf("syncSnapshotRspPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncSnapshotRspPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg) { char* serialized = syncSnapshotRsp2Str(pMsg); - sTrace("syncSnapshotRspLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncSnapshotRspLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) { if (gRaftDetailLog) { char* serialized = syncSnapshotRsp2Str(pMsg); - sTrace("syncSnapshotRspLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncSnapshotRspLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2555,7 +2555,7 @@ cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg) { /* cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); cJSON_AddStringToObject(pSrcId, "addr", u64buf); { uint64_t u64 = pMsg->srcId.addr; @@ -2570,7 +2570,7 @@ cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg) { cJSON_AddItemToObject(pRoot, "srcId", pSrcId); cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); cJSON_AddStringToObject(pDestId, "addr", u64buf); { uint64_t u64 = pMsg->destId.addr; @@ -2586,7 +2586,7 @@ cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg) { */ cJSON* pNewerId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->newLeaderId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newLeaderId.addr); cJSON_AddStringToObject(pNewerId, "addr", u64buf); { uint64_t u64 = pMsg->newLeaderId.addr; @@ -2616,28 +2616,28 @@ char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) { // for debug ---------------------- void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg) { char* serialized = syncLeaderTransfer2Str(pMsg); - printf("syncLeaderTransferPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncLeaderTransferPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg) { char* serialized = syncLeaderTransfer2Str(pMsg); - printf("syncLeaderTransferPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncLeaderTransferPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg) { char* serialized = syncLeaderTransfer2Str(pMsg); - sTrace("syncLeaderTransferLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncLeaderTransferLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg) { if (gRaftDetailLog) { char* serialized = syncLeaderTransfer2Str(pMsg); - sTrace("syncLeaderTransferLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncLeaderTransferLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2720,13 +2720,13 @@ cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg) { cJSON_AddItemToObject(pRoot, "oldCfg", pOldCfg); cJSON_AddItemToObject(pRoot, "newCfg", pNewCfg); - snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->newCfgIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->newCfgIndex); cJSON_AddStringToObject(pRoot, "newCfgIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->newCfgTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newCfgTerm); cJSON_AddStringToObject(pRoot, "newCfgTerm", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->newCfgSeqNum); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newCfgSeqNum); cJSON_AddStringToObject(pRoot, "newCfgSeqNum", u64buf); } @@ -2745,28 +2745,28 @@ char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg) { // for debug ---------------------- void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg) { char* serialized = syncReconfigFinish2Str(pMsg); - printf("syncReconfigFinishPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncReconfigFinishPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg) { char* serialized = syncReconfigFinish2Str(pMsg); - printf("syncReconfigFinishPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncReconfigFinishPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncReconfigFinishLog(const SyncReconfigFinish* pMsg) { char* serialized = syncReconfigFinish2Str(pMsg); - sTrace("syncReconfigFinishLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncReconfigFinishLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) { if (gRaftDetailLog) { char* serialized = syncReconfigFinish2Str(pMsg); - sTrace("syncReconfigFinishLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncReconfigFinishLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index 6c381f6e7d..0bbeaaf5b0 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -101,7 +101,7 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) { char *syncCfg2Str(SSyncCfg *pSyncCfg) { cJSON *pJson = syncCfg2Json(pSyncCfg); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -109,7 +109,7 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) { char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) { if (pSyncCfg != NULL) { int32_t len = 512; - char *s = taosMemoryMalloc(len); + char * s = taosMemoryMalloc(len); memset(s, 0, len); snprintf(s, len, "{replica-num:%d, my-index:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex); @@ -186,14 +186,14 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) { cJSON_AddNumberToObject(pRoot, "batchSize", pRaftCfg->batchSize); char buf64[128]; - snprintf(buf64, sizeof(buf64), "%ld", pRaftCfg->lastConfigIndex); + snprintf(buf64, sizeof(buf64), "%" PRId64, pRaftCfg->lastConfigIndex); cJSON_AddStringToObject(pRoot, "lastConfigIndex", buf64); cJSON_AddNumberToObject(pRoot, "configIndexCount", pRaftCfg->configIndexCount); cJSON *pIndexArr = cJSON_CreateArray(); cJSON_AddItemToObject(pRoot, "configIndexArr", pIndexArr); for (int i = 0; i < pRaftCfg->configIndexCount; ++i) { - snprintf(buf64, sizeof(buf64), "%ld", (pRaftCfg->configIndexArr)[i]); + snprintf(buf64, sizeof(buf64), "%" PRId64, (pRaftCfg->configIndexArr)[i]); cJSON *pIndexObj = cJSON_CreateObject(); cJSON_AddStringToObject(pIndexObj, "index", buf64); cJSON_AddItemToArray(pIndexArr, pIndexObj); @@ -206,7 +206,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) { char *raftCfg2Str(SRaftCfg *pRaftCfg) { cJSON *pJson = raftCfg2Json(pRaftCfg); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -285,7 +285,7 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) { (pRaftCfg->configIndexArr)[i] = atoll(pIndex->valuestring); } - cJSON *pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg"); + cJSON * pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg"); int32_t code = syncCfgFromJson(pJsonSyncCfg, &(pRaftCfg->cfg)); ASSERT(code == 0); @@ -306,58 +306,58 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg) { // for debug ---------------------- void syncCfgPrint(SSyncCfg *pCfg) { char *serialized = syncCfg2Str(pCfg); - printf("syncCfgPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("syncCfgPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncCfgPrint2(char *s, SSyncCfg *pCfg) { char *serialized = syncCfg2Str(pCfg); - printf("syncCfgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("syncCfgPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncCfgLog(SSyncCfg *pCfg) { char *serialized = syncCfg2Str(pCfg); - sTrace("syncCfgLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("syncCfgLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void syncCfgLog2(char *s, SSyncCfg *pCfg) { char *serialized = syncCfg2Str(pCfg); - sTrace("syncCfgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncCfgLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } void syncCfgLog3(char *s, SSyncCfg *pCfg) { char *serialized = syncCfg2SimpleStr(pCfg); - sTrace("syncCfgLog3 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("syncCfgLog3 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } void raftCfgPrint(SRaftCfg *pCfg) { char *serialized = raftCfg2Str(pCfg); - printf("raftCfgPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("raftCfgPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCfgPrint2(char *s, SRaftCfg *pCfg) { char *serialized = raftCfg2Str(pCfg); - printf("raftCfgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("raftCfgPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCfgLog(SRaftCfg *pCfg) { char *serialized = raftCfg2Str(pCfg); - sTrace("raftCfgLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("raftCfgLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void raftCfgLog2(char *s, SRaftCfg *pCfg) { char *serialized = raftCfg2Str(pCfg); - sTrace("raftCfgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("raftCfgLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index 0ee4684ea8..465584a40f 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -130,12 +130,12 @@ cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes); cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType); cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType); - snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->seqNum); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->seqNum); cJSON_AddStringToObject(pRoot, "seqNum", u64buf); cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak); - snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->index); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->index); cJSON_AddStringToObject(pRoot, "index", u64buf); cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen); @@ -246,7 +246,7 @@ int32_t raftCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry do { char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%ld, bytes:%d", + snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d", TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType, pEntry->index, pEntry->bytes); syncNodeEventLog(pCache->pSyncNode, eventLog); @@ -274,7 +274,7 @@ int32_t raftCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index, SSync do { char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%ld", + snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64, TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), (*ppEntry)->originalRpcType, (*ppEntry)->index); syncNodeEventLog(pCache->pSyncNode, eventLog); @@ -306,7 +306,7 @@ int32_t raftCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyn do { char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%ld", + snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64, TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), (*ppEntry)->originalRpcType, (*ppEntry)->index); syncNodeEventLog(pCache->pSyncNode, eventLog); @@ -344,7 +344,7 @@ int32_t raftCacheGetAndDel(struct SRaftEntryCache* pCache, SyncIndex index, SSyn do { char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache get-and-del, type:%s,%d, type2:%s,%d, index:%ld", + snprintf(eventLog, sizeof(eventLog), "raft cache get-and-del, type:%s,%d, type2:%s,%d, index:%" PRId64, TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), (*ppEntry)->originalRpcType, (*ppEntry)->index); syncNodeEventLog(pCache->pSyncNode, eventLog); @@ -415,28 +415,28 @@ char* raftCache2Str(SRaftEntryCache* pCache) { void raftCachePrint(SRaftEntryCache* pCache) { char* serialized = raftCache2Str(pCache); - printf("raftCachePrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("raftCachePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCachePrint2(char* s, SRaftEntryCache* pCache) { char* serialized = raftCache2Str(pCache); - printf("raftCachePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("raftCachePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCacheLog(SRaftEntryCache* pCache) { char* serialized = raftCache2Str(pCache); - sTrace("raftCacheLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("raftCacheLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void raftCacheLog2(char* s, SRaftEntryCache* pCache) { if (gRaftDetailLog) { char* serialized = raftCache2Str(pCache); - sTraceLong("raftCacheLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTraceLong("raftCacheLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index 3a44933eea..edc01c9a05 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -122,8 +122,8 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI char logBuf[128]; snprintf(logBuf, sizeof(logBuf), - "wal restore from snapshot error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", snapshotIndex, err, - err, errStr, sysErr, sysErrStr); + "wal restore from snapshot error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + snapshotIndex, err, err, errStr, sysErr, sysErrStr); syncNodeErrorLog(pData->pSyncNode, logBuf); return -1; @@ -201,19 +201,56 @@ static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) { return SYNC_TERM_INVALID; } +static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + + SyncIndex index = 0; + SWalSyncInfo syncMeta; + syncMeta.isWeek = pEntry->isWeak; + syncMeta.seqNum = pEntry->seqNum; + syncMeta.term = pEntry->term; + index = walAppendLog(pWal, pEntry->originalRpcType, syncMeta, pEntry->data, pEntry->dataLen); + if (index < 0) { + int32_t err = terrno; + const char* errStr = tstrerror(err); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pEntry->index, err, err, errStr, sysErr, sysErrStr); + syncNodeErrorLog(pData->pSyncNode, logBuf); + + ASSERT(0); + return -1; + } + pEntry->index = index; + + do { + char eventLog[128]; + snprintf(eventLog, sizeof(eventLog), "write index:%" PRId64 ", type:%s,%d, type2:%s,%d", pEntry->index, + TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType); + syncNodeEventLog(pData->pSyncNode, eventLog); + } while (0); + + return 0; +} + +#if 0 static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; SyncIndex writeIndex = raftLogWriteIndex(pLogStore); if (pEntry->index != writeIndex) { - sError("vgId:%d wal write index error, entry-index:%ld update to %ld", pData->pSyncNode->vgId, pEntry->index, - writeIndex); + sError("vgId:%d wal write index error, entry-index:%" PRId64 " update to %" PRId64, pData->pSyncNode->vgId, + pEntry->index, writeIndex); pEntry->index = writeIndex; } int code = 0; - SSyncLogMeta syncMeta; + SWalSyncInfo syncMeta; syncMeta.isWeek = pEntry->isWeak; syncMeta.seqNum = pEntry->seqNum; syncMeta.term = pEntry->term; @@ -225,7 +262,7 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr const char* sysErrStr = strerror(errno); char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal write error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", pEntry->index, err, err, errStr, sysErr, sysErrStr); syncNodeErrorLog(pData->pSyncNode, logBuf); @@ -236,13 +273,14 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr do { char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "write index:%ld, type:%s,%d, type2:%s,%d", pEntry->index, + snprintf(eventLog, sizeof(eventLog), "write index:%" PRId64 ", type:%s,%d, type2:%s,%d", pEntry->index, TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType); syncNodeEventLog(pData->pSyncNode, eventLog); } while (0); return code; } +#endif // entry found, return 0 // entry not found, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST @@ -272,8 +310,8 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal read error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, err, - err, errStr, sysErr, sysErrStr); + snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + index, err, err, errStr, sysErr, sysErrStr); if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { syncNodeEventLog(pData->pSyncNode, logBuf); } else { @@ -321,7 +359,7 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn const char* errStr = tstrerror(err); int32_t sysErr = errno; const char* sysErrStr = strerror(errno); - sError("vgId:%d wal truncate error, from-index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + sError("vgId:%d wal truncate error, from-index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", pData->pSyncNode->vgId, fromIndex, err, err, errStr, sysErr, sysErrStr); ASSERT(0); @@ -330,7 +368,7 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn // event log do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal truncate, from-index:%ld", fromIndex); + snprintf(logBuf, sizeof(logBuf), "wal truncate, from-index:%" PRId64, fromIndex); syncNodeEventLog(pData->pSyncNode, logBuf); } while (0); @@ -361,6 +399,8 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp //------------------------------- // log[0 .. n] + +#if 0 int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; @@ -369,7 +409,7 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { ASSERT(pEntry->index == lastIndex + 1); int code = 0; - SSyncLogMeta syncMeta; + SWalSyncInfo syncMeta; syncMeta.isWeek = pEntry->isWeak; syncMeta.seqNum = pEntry->seqNum; syncMeta.term = pEntry->term; @@ -381,7 +421,7 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { const char* sysErrStr = strerror(errno); char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal write error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", pEntry->index, err, err, errStr, sysErr, sysErrStr); syncNodeErrorLog(pData->pSyncNode, logBuf); @@ -391,12 +431,50 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { // walFsync(pWal, true); char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "old write index:%ld, type:%s,%d, type2:%s,%d", pEntry->index, + snprintf(eventLog, sizeof(eventLog), "old write index:%" PRId64 ", type:%s,%d, type2:%s,%d", pEntry->index, TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType); syncNodeEventLog(pData->pSyncNode, eventLog); return code; } +#endif + +int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + + SyncIndex index = 0; + SWalSyncInfo syncMeta; + syncMeta.isWeek = pEntry->isWeak; + syncMeta.seqNum = pEntry->seqNum; + syncMeta.term = pEntry->term; + + index = walAppendLog(pWal, pEntry->originalRpcType, syncMeta, pEntry->data, pEntry->dataLen); + if (index < 0) { + int32_t err = terrno; + const char* errStr = tstrerror(err); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pEntry->index, err, err, errStr, sysErr, sysErrStr); + syncNodeErrorLog(pData->pSyncNode, logBuf); + + ASSERT(0); + return -1; + } + pEntry->index = index; + + do { + char eventLog[128]; + snprintf(eventLog, sizeof(eventLog), "write2 index:%" PRId64 ", type:%s,%d, type2:%s,%d", pEntry->index, + TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType); + syncNodeEventLog(pData->pSyncNode, eventLog); + } while (0); + + return 0; +} SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { SSyncLogStoreData* pData = pLogStore->data; @@ -418,8 +496,8 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal read error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, - err, err, errStr, sysErr, sysErrStr); + snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + index, err, err, errStr, sysErr, sysErrStr); if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { syncNodeEventLog(pData->pSyncNode, logBuf); } else { @@ -466,7 +544,7 @@ int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) { const char* errStr = tstrerror(err); int32_t sysErr = errno; const char* sysErrStr = strerror(errno); - sError("vgId:%d wal truncate error, from-index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + sError("vgId:%d wal truncate error, from-index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", pData->pSyncNode->vgId, fromIndex, err, err, errStr, sysErr, sysErrStr); ASSERT(0); @@ -475,7 +553,7 @@ int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) { // event log do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal truncate, from-index:%ld", fromIndex); + snprintf(logBuf, sizeof(logBuf), "wal truncate, from-index:%" PRId64, fromIndex); syncNodeEventLog(pData->pSyncNode, logBuf); } while (0); @@ -509,7 +587,7 @@ int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) { const char* errStr = tstrerror(err); int32_t sysErr = errno; const char* sysErrStr = strerror(errno); - sError("vgId:%d wal update commit index error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + sError("vgId:%d wal update commit index error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", pData->pSyncNode->vgId, index, err, err, errStr, sysErr, sysErrStr); ASSERT(0); @@ -546,25 +624,25 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore) { cJSON_AddStringToObject(pRoot, "pWal", u64buf); SyncIndex beginIndex = raftLogBeginIndex(pLogStore); - snprintf(u64buf, sizeof(u64buf), "%ld", beginIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex); cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); SyncIndex endIndex = raftLogEndIndex(pLogStore); - snprintf(u64buf, sizeof(u64buf), "%ld", endIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex); cJSON_AddStringToObject(pRoot, "endIndex", u64buf); int32_t count = raftLogEntryCount(pLogStore); cJSON_AddNumberToObject(pRoot, "entryCount", count); - snprintf(u64buf, sizeof(u64buf), "%ld", raftLogWriteIndex(pLogStore)); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore)); cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf); snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore)); cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", raftLogLastIndex(pLogStore)); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore)); cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", raftLogLastTerm(pLogStore)); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore)); cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); cJSON* pEntries = cJSON_CreateArray(); @@ -603,25 +681,25 @@ cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore) { cJSON_AddStringToObject(pRoot, "pWal", u64buf); SyncIndex beginIndex = raftLogBeginIndex(pLogStore); - snprintf(u64buf, sizeof(u64buf), "%ld", beginIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex); cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); SyncIndex endIndex = raftLogEndIndex(pLogStore); - snprintf(u64buf, sizeof(u64buf), "%ld", endIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex); cJSON_AddStringToObject(pRoot, "endIndex", u64buf); int32_t count = raftLogEntryCount(pLogStore); cJSON_AddNumberToObject(pRoot, "entryCount", count); - snprintf(u64buf, sizeof(u64buf), "%ld", raftLogWriteIndex(pLogStore)); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore)); cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf); snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore)); cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", raftLogLastIndex(pLogStore)); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore)); cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", raftLogLastTerm(pLogStore)); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore)); cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); } @@ -646,14 +724,14 @@ SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore) { // for debug ----------------- void logStorePrint(SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); - printf("logStorePrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("logStorePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void logStorePrint2(char* s, SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); - printf("logStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("logStorePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } @@ -661,7 +739,7 @@ void logStorePrint2(char* s, SSyncLogStore* pLogStore) { void logStoreLog(SSyncLogStore* pLogStore) { if (gRaftDetailLog) { char* serialized = logStore2Str(pLogStore); - sTraceLong("logStoreLog | len:%lu | %s", strlen(serialized), serialized); + sTraceLong("logStoreLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } } @@ -669,7 +747,7 @@ void logStoreLog(SSyncLogStore* pLogStore) { void logStoreLog2(char* s, SSyncLogStore* pLogStore) { if (gRaftDetailLog) { char* serialized = logStore2Str(pLogStore); - sTraceLong("logStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTraceLong("logStoreLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -677,28 +755,28 @@ void logStoreLog2(char* s, SSyncLogStore* pLogStore) { // for debug ----------------- void logStoreSimplePrint(SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); - printf("logStoreSimplePrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("logStoreSimplePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); - printf("logStoreSimplePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("logStoreSimplePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void logStoreSimpleLog(SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); - sTrace("logStoreSimpleLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("logStoreSimpleLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) { if (gRaftDetailLog) { char* serialized = logStoreSimple2Str(pLogStore); - sTrace("logStoreSimpleLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("logStoreSimpleLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } } diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index c52a96a514..b6bc4bc816 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -135,7 +135,8 @@ int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode) { SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); - sError("vgId:%d sync get pre term error, nextIndex:%ld, update next-index:%ld, match-index:%d, raftid:%ld", + sError("vgId:%d sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 + ", match-index:%d, raftid:%" PRId64, pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr); return -1; @@ -224,7 +225,8 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) { SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); - sError("vgId:%d sync get pre term error, nextIndex:%ld, update next-index:%ld, match-index:%d, raftid:%ld", + sError("vgId:%d sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 + ", match-index:%d, raftid:%" PRId64, pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr); return -1; @@ -314,11 +316,12 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c char host[128]; uint16_t port; syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries to %s:%d, {term:%lu, pre-index:%ld, pre-term:%lu, pterm:%lu, commit:%ld, " - "datalen:%d}", - pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, - pMsg->commitIndex, pMsg->dataLen); + sDebug("vgId:%d, send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", pterm:%" PRIu64 ", commit:%" PRId64 + ", " + "datalen:%d}", + pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, + pMsg->commitIndex, pMsg->dataLen); } while (0); SRpcMsg rpcMsg; @@ -333,12 +336,10 @@ int32_t syncNodeAppendEntriesBatch(SSyncNode* pSyncNode, const SRaftId* destRaft char host[128]; uint16_t port; syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries-batch to %s:%d, {term:%lu, pre-index:%ld, pre-term:%lu, pterm:%lu, " - "commit:%ld, " - "datalen:%d, datacount:%d}", - pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, - pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount); + sDebug("vgId:%d, send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 + ", pre-term:%" PRIu64 ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, datacount:%d}", + pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, + pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount); } while (0); SRpcMsg rpcMsg; diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index d272e0175f..a6ca0e6d78 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -55,7 +55,8 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, term:%lu, lindex:%ld, lterm:%lu, maybe replica already dropped", + "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 + ", maybe replica already dropped", host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm); syncNodeEventLog(ths, logBuf); } while (0); @@ -97,8 +98,9 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, term:%lu, lindex:%ld, lterm:%lu, reply-grant:%d", host, port, - pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); + "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 + ", reply-grant:%d", + host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); syncNodeEventLog(ths, logBuf); } while (0); @@ -115,7 +117,7 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { int32_t ret = 0; char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteCb== term:%lu", ths->pRaftStore->currentTerm); + snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteCb== term:%" PRIu64, ths->pRaftStore->currentTerm); syncRequestVoteLog2(logBuf, pMsg); if (pMsg->term > ths->pRaftStore->currentTerm) { @@ -181,7 +183,8 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, term:%lu, lindex:%ld, lterm:%lu, maybe replica already dropped", + "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 + ", maybe replica already dropped", host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm); syncNodeEventLog(ths, logBuf); } while (0); @@ -221,8 +224,9 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, term:%lu, lindex:%ld, lterm:%lu, reply-grant:%d", host, port, - pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); + "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 + ", reply-grant:%d", + host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); syncNodeEventLog(ths, logBuf); } while (0); diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index 4c205d16ec..8ab4f75c5c 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -42,7 +42,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) // print log char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteReplyCb== term:%lu", ths->pRaftStore->currentTerm); + snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteReplyCb== term:%" PRIu64, ths->pRaftStore->currentTerm); syncRequestVoteReplyLog2(logBuf, pMsg); // if already drop replica, do not process @@ -53,7 +53,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - sTrace("recv SyncRequestVoteReply, drop stale response, receive_term:%lu current_term:%lu", pMsg->term, + sTrace("recv SyncRequestVoteReply, drop stale response, receive_term:%" PRIu64 " current_term:%" PRIu64, pMsg->term, ths->pRaftStore->currentTerm); return ret; } @@ -66,8 +66,8 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) if (pMsg->term > ths->pRaftStore->currentTerm) { char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "syncNodeOnRequestVoteReplyCb error term, receive:%lu current:%lu", pMsg->term, - ths->pRaftStore->currentTerm); + snprintf(logBuf, sizeof(logBuf), "syncNodeOnRequestVoteReplyCb error term, receive:%" PRIu64 " current:%" PRIu64, + pMsg->term, ths->pRaftStore->currentTerm); syncNodePrint2(logBuf, ths); sError("%s", logBuf); return ret; @@ -107,7 +107,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) int32_t ret = 0; char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteReplyCb== term:%lu", ths->pRaftStore->currentTerm); + snprintf(logBuf, sizeof(logBuf), "==syncNodeOnRequestVoteReplyCb== term:%" PRIu64, ths->pRaftStore->currentTerm); syncRequestVoteReplyLog2(logBuf, pMsg); if (pMsg->term < ths->pRaftStore->currentTerm) { @@ -124,7 +124,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) if (pMsg->term > ths->pRaftStore->currentTerm) { char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "syncNodeOnRequestVoteReplyCb error term, receive:%lu current:%lu", pMsg->term, + snprintf(logBuf, sizeof(logBuf), "syncNodeOnRequestVoteReplyCb error term, receive:%" PRIu64 " current:%" PRIu64, pMsg->term, ths->pRaftStore->currentTerm); syncNodePrint2(logBuf, ths); sError("%s", logBuf); @@ -166,7 +166,7 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl // print log char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "recv SyncRequestVoteReply, term:%lu", ths->pRaftStore->currentTerm); + snprintf(logBuf, sizeof(logBuf), "recv SyncRequestVoteReply, term:%" PRIu64, ths->pRaftStore->currentTerm); syncRequestVoteReplyLog2(logBuf, pMsg); // if already drop replica, do not process @@ -177,7 +177,7 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - sTrace("recv SyncRequestVoteReply, drop stale response, receive_term:%lu current_term:%lu", pMsg->term, + sTrace("recv SyncRequestVoteReply, drop stale response, receive_term:%" PRIu64 " current_term:%" PRIu64, pMsg->term, ths->pRaftStore->currentTerm); return ret; } @@ -190,8 +190,9 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl if (pMsg->term > ths->pRaftStore->currentTerm) { char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "recv SyncRequestVoteReply, error term, receive_term:%lu current_term:%lu", - pMsg->term, ths->pRaftStore->currentTerm); + snprintf(logBuf, sizeof(logBuf), + "recv SyncRequestVoteReply, error term, receive_term:%" PRIu64 " current_term:%" PRIu64, pMsg->term, + ths->pRaftStore->currentTerm); syncNodePrint2(logBuf, ths); sError("%s", logBuf); return ret; diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index 8dd1349edb..eaeadd3991 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -50,7 +50,7 @@ int64_t syncRespMgrAdd(SSyncRespMgr *pObj, SRespStub *pStub) { SSyncNode *pSyncNode = pObj->data; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "resp mgr add, type:%s,%d, seq:%lu, handle:%p, ahandle:%p", + snprintf(eventLog, sizeof(eventLog), "resp mgr add, type:%s,%d, seq:%" PRIu64 ", handle:%p, ahandle:%p", TMSG_INFO(pStub->rpcMsg.msgType), pStub->rpcMsg.msgType, keyCode, pStub->rpcMsg.info.handle, pStub->rpcMsg.info.ahandle); syncNodeEventLog(pSyncNode, eventLog); @@ -77,7 +77,7 @@ int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub) { SSyncNode *pSyncNode = pObj->data; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "resp mgr get, type:%s,%d, seq:%lu, handle:%p, ahandle:%p", + snprintf(eventLog, sizeof(eventLog), "resp mgr get, type:%s,%d, seq:%" PRIu64 ", handle:%p, ahandle:%p", TMSG_INFO(pStub->rpcMsg.msgType), pStub->rpcMsg.msgType, index, pStub->rpcMsg.info.handle, pStub->rpcMsg.info.ahandle); syncNodeEventLog(pSyncNode, eventLog); @@ -98,7 +98,7 @@ int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStu SSyncNode *pSyncNode = pObj->data; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "resp mgr get-and-del, type:%s,%d, seq:%lu, handle:%p, ahandle:%p", + snprintf(eventLog, sizeof(eventLog), "resp mgr get-and-del, type:%s,%d, seq:%" PRIu64 ", handle:%p, ahandle:%p", TMSG_INFO(pStub->rpcMsg.msgType), pStub->rpcMsg.msgType, index, pStub->rpcMsg.info.handle, pStub->rpcMsg.info.ahandle); syncNodeEventLog(pSyncNode, eventLog); diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index a33f66733b..87cc5685f3 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -153,8 +153,8 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho // event log do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "snapshot sender update lcindex from %ld to %ld", oldLastConfigIndex, - newLastConfigIndex); + snprintf(logBuf, sizeof(logBuf), "snapshot sender update lcindex from %" PRId64 " to %" PRId64, + oldLastConfigIndex, newLastConfigIndex); char *eventLog = snapshotSender2SimpleStr(pSender, logBuf); syncNodeEventLog(pSender->pSyncNode, eventLog); taosMemoryFree(eventLog); @@ -350,19 +350,19 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) { } cJSON *pSnapshot = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pSender->snapshot.lastApplyIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->snapshot.lastApplyIndex); cJSON_AddStringToObject(pSnapshot, "lastApplyIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pSender->snapshot.lastApplyTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->snapshot.lastApplyTerm); cJSON_AddStringToObject(pSnapshot, "lastApplyTerm", u64buf); cJSON_AddItemToObject(pRoot, "snapshot", pSnapshot); - snprintf(u64buf, sizeof(u64buf), "%lu", pSender->sendingMS); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->sendingMS); cJSON_AddStringToObject(pRoot, "sendingMS", u64buf); snprintf(u64buf, sizeof(u64buf), "%p", pSender->pSyncNode); cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); cJSON_AddNumberToObject(pRoot, "replicaIndex", pSender->replicaIndex); - snprintf(u64buf, sizeof(u64buf), "%lu", pSender->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pSender->privateTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->privateTerm); cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); cJSON_AddNumberToObject(pRoot, "finish", pSender->finish); } @@ -389,7 +389,9 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) { syncUtilU642Addr(destId.addr, host, sizeof(host), &port); snprintf(s, len, - "%s {%p s-param:%ld e-param:%ld laindex:%ld laterm:%lu lcindex:%ld seq:%d ack:%d finish:%d pterm:%lu " + "%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64 + " seq:%d ack:%d finish:%d pterm:%" PRIu64 + " " "replica-index:%d %s:%d}", event, pSender, pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, @@ -640,7 +642,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) { cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); cJSON *pFromId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->fromId.addr); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->fromId.addr); cJSON_AddStringToObject(pFromId, "addr", u64buf); { uint64_t u64 = pReceiver->fromId.addr; @@ -654,19 +656,19 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) { cJSON_AddNumberToObject(pFromId, "vgId", pReceiver->fromId.vgId); cJSON_AddItemToObject(pRoot, "fromId", pFromId); - snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->snapshot.lastApplyIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->snapshot.lastApplyIndex); cJSON_AddStringToObject(pRoot, "snapshot.lastApplyIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->snapshot.lastApplyTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->snapshot.lastApplyTerm); cJSON_AddStringToObject(pRoot, "snapshot.lastApplyTerm", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->snapshot.lastConfigIndex); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->snapshot.lastConfigIndex); cJSON_AddStringToObject(pRoot, "snapshot.lastConfigIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->privateTerm); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->privateTerm); cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); } @@ -692,8 +694,10 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event) syncUtilU642Addr(fromId.addr, host, sizeof(host), &port); snprintf(s, len, - "%s {%p start:%d ack:%d term:%lu pterm:%lu from:%s:%d s-param:%ld e-param:%ld laindex:%ld laterm:%lu " - "lcindex:%ld}", + "%s {%p start:%d ack:%d term:%" PRIu64 " pterm:%" PRIu64 " from:%s:%d s-param:%" PRId64 " e-param:%" PRId64 + " laindex:%" PRId64 " laterm:%" PRIu64 + " " + "lcindex:%" PRId64 "}", event, pReceiver, pReceiver->start, pReceiver->ack, pReceiver->term, pReceiver->privateTerm, host, port, pReceiver->snapshotParam.start, pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex); diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index 2c43312064..1d46d71a05 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -109,7 +109,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) { cJSON_AddItemToObject(pRoot, "isGranted", pIsGranted); cJSON_AddNumberToObject(pRoot, "votes", pVotesGranted->votes); - snprintf(u64buf, sizeof(u64buf), "%lu", pVotesGranted->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pVotesGranted->term); cJSON_AddStringToObject(pRoot, "term", u64buf); cJSON_AddNumberToObject(pRoot, "quorum", pVotesGranted->quorum); cJSON_AddNumberToObject(pRoot, "toLeader", pVotesGranted->toLeader); @@ -135,27 +135,27 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) { // for debug ------------------- void voteGrantedPrint(SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); - printf("voteGrantedPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("voteGrantedPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void voteGrantedPrint2(char *s, SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); - printf("voteGrantedPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("voteGrantedPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void voteGrantedLog(SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); - sTrace("voteGrantedLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("voteGrantedLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void voteGrantedLog2(char *s, SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); - sTrace("voteGrantedLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("voteGrantedLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } @@ -243,7 +243,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) { cJSON_AddItemToObject(pRoot, "isRespond", pIsRespond); cJSON_AddNumberToObject(pRoot, "respondNum", respondNum); - snprintf(u64buf, sizeof(u64buf), "%lu", pVotesRespond->term); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pVotesRespond->term); cJSON_AddStringToObject(pRoot, "term", u64buf); snprintf(u64buf, sizeof(u64buf), "%p", pVotesRespond->pSyncNode); cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); @@ -264,26 +264,26 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) { // for debug ------------------- void votesRespondPrint(SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); - printf("votesRespondPrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("votesRespondPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void votesRespondPrint2(char *s, SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); - printf("votesRespondPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("votesRespondPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void votesRespondLog(SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); - sTrace("votesRespondLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("votesRespondLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void votesRespondLog2(char *s, SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); - sTrace("votesRespondLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("votesRespondLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } diff --git a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp index 7cd97695f9..339ebe90e7 100644 --- a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp +++ b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp @@ -45,28 +45,31 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { if (cbMeta.index > beginIndex) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, flag:%lu, term:%lu \n", + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 + ", term:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } else { - sTrace("==callback== ==CommitCb== do not apply again %ld", cbMeta.index); + sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); } } void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s flag:%lu\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + snprintf( + logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s flag:%lu\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), + cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -147,8 +150,8 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%ld, code:%d, currentTerm:%lu, term:%lu", cbMeta.flag, - cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, + cbMeta.flag, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); } SSyncFSM* createFsm() { @@ -267,7 +270,8 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%ld", myIndex, i, count, taosGetTimestampMs()); + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncConfigChangeTest.cpp b/source/libs/sync/test/syncConfigChangeTest.cpp index c96e337378..ba3fc77650 100644 --- a/source/libs/sync/test/syncConfigChangeTest.cpp +++ b/source/libs/sync/test/syncConfigChangeTest.cpp @@ -44,27 +44,30 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { if (cbMeta.index > beginIndex) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s flag:%lu\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), + cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } else { - sTrace("==callback== ==CommitCb== do not apply again %ld", cbMeta.index); + sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); } } void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s flag:%lu\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + snprintf( + logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s flag:%lu\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), + cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -78,8 +81,8 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%ld, code:%d, currentTerm:%lu, term:%lu", cbMeta.flag, - cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, + cbMeta.flag, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); } SSyncFSM* createFsm() { @@ -188,7 +191,8 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%ld", myIndex, i, count, taosGetTimestampMs()); + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncEntryCacheTest.cpp b/source/libs/sync/test/syncEntryCacheTest.cpp index 787c08e507..6250181b25 100644 --- a/source/libs/sync/test/syncEntryCacheTest.cpp +++ b/source/libs/sync/test/syncEntryCacheTest.cpp @@ -5,6 +5,7 @@ #include "syncRaftLog.h" #include "syncRaftStore.h" #include "syncUtil.h" +#include "tskiplist.h" void logTest() { sTrace("--- sync log test: trace"); @@ -148,15 +149,131 @@ void test4() { raftCacheLog2((char*)"==test4 after get-and-del entry 3==", pCache); } +static char* keyFn(const void* pData) { + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pData; + return (char*)(&(pEntry->index)); +} + +static int cmpFn(const void* p1, const void* p2) { return memcmp(p1, p2, sizeof(SyncIndex)); } + +void printSkipList(SSkipList* pSkipList) { + ASSERT(pSkipList != NULL); + + SSkipListIterator* pIter = tSkipListCreateIter(pSkipList); + while (tSkipListIterNext(pIter)) { + SSkipListNode* pNode = tSkipListIterGet(pIter); + ASSERT(pNode != NULL); + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode); + syncEntryPrint2((char*)"", pEntry); + } +} + +void delSkipListFirst(SSkipList* pSkipList, int n) { + ASSERT(pSkipList != NULL); + + sTrace("delete first %d -------------", n); + SSkipListIterator* pIter = tSkipListCreateIter(pSkipList); + for (int i = 0; i < n; ++i) { + tSkipListIterNext(pIter); + SSkipListNode* pNode = tSkipListIterGet(pIter); + tSkipListRemoveNode(pSkipList, pNode); + } +} + + +SSyncRaftEntry* getLogEntry2(SSkipList* pSkipList, SyncIndex index) { + SyncIndex index2 = index; + SSyncRaftEntry *pEntry = NULL; + int arraySize = 0; + + SArray* entryPArray = tSkipListGet(pSkipList, (char*)(&index2)); + arraySize = taosArrayGetSize(entryPArray); + if (arraySize > 0) { + SSkipListNode** ppNode = (SSkipListNode**)taosArrayGet(entryPArray, 0); + ASSERT(*ppNode != NULL); + pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(*ppNode); + } + taosArrayDestroy(entryPArray); + + sTrace("get index2: %ld, arraySize:%d -------------", index, arraySize); + syncEntryLog2((char*)"getLogEntry2", pEntry); + return pEntry; +} + + +SSyncRaftEntry* getLogEntry(SSkipList* pSkipList, SyncIndex index) { + sTrace("get index: %ld -------------", index); + SyncIndex index2 = index; + SSyncRaftEntry *pEntry = NULL; + SSkipListIterator* pIter = tSkipListCreateIterFromVal(pSkipList, (const char *)&index2, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + if (tSkipListIterNext(pIter)) { + SSkipListNode* pNode = tSkipListIterGet(pIter); + ASSERT(pNode != NULL); + pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode); + } + + syncEntryLog2((char*)"getLogEntry", pEntry); + return pEntry; +} + +void test5() { + SSkipList* pSkipList = + tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, sizeof(SyncIndex), cmpFn, SL_ALLOW_DUP_KEY, keyFn); + ASSERT(pSkipList != NULL); + + sTrace("insert 9 - 5"); + for (int i = 9; i >= 5; --i) { + SSyncRaftEntry* pEntry = createEntry(i); + SSkipListNode* pSkipListNode = tSkipListPut(pSkipList, pEntry); + } + + sTrace("insert 0 - 4"); + for (int i = 0; i <= 4; ++i) { + SSyncRaftEntry* pEntry = createEntry(i); + SSkipListNode* pSkipListNode = tSkipListPut(pSkipList, pEntry); + } + + sTrace("insert 7 7 7 7 7"); + for (int i = 0; i <= 4; ++i) { + SSyncRaftEntry* pEntry = createEntry(7); + SSkipListNode* pSkipListNode = tSkipListPut(pSkipList, pEntry); + } + + sTrace("print: -------------"); + printSkipList(pSkipList); + + delSkipListFirst(pSkipList, 3); + + sTrace("print: -------------"); + printSkipList(pSkipList); + + getLogEntry(pSkipList, 2); + getLogEntry(pSkipList, 5); + getLogEntry(pSkipList, 7); + getLogEntry(pSkipList, 7); + + getLogEntry2(pSkipList, 2); + getLogEntry2(pSkipList, 5); + getLogEntry2(pSkipList, 7); + getLogEntry2(pSkipList, 7); + + + tSkipListDestroy(pSkipList); +} + int main(int argc, char** argv) { gRaftDetailLog = true; tsAsyncLog = 0; sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE + DEBUG_DEBUG; - test1(); - test2(); - test3(); - test4(); + /* + test1(); + test2(); + test3(); + test4(); + */ + + test5(); return 0; } diff --git a/source/libs/sync/test/syncIndexMgrTest.cpp b/source/libs/sync/test/syncIndexMgrTest.cpp index 0ad69f0f51..23b8693a0b 100644 --- a/source/libs/sync/test/syncIndexMgrTest.cpp +++ b/source/libs/sync/test/syncIndexMgrTest.cpp @@ -81,7 +81,7 @@ int main(int argc, char** argv) { for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) { SyncIndex idx = syncIndexMgrGetIndex(pSyncIndexMgr, &ids[i]); // SyncTerm term = syncIndexMgrGetTerm(pSyncIndexMgr, &ids[i]); - // printf("%d: index:%ld term:%lu \n", i, idx, term); + // printf("%d: index:%" PRId64 " term:%" PRIu64 " \n", i, idx, term); } printf("---------------------------------------\n"); diff --git a/source/libs/sync/test/syncIndexTest.cpp b/source/libs/sync/test/syncIndexTest.cpp index 07a05d437e..91c7800756 100644 --- a/source/libs/sync/test/syncIndexTest.cpp +++ b/source/libs/sync/test/syncIndexTest.cpp @@ -13,7 +13,7 @@ void print(SHashObj *pNextIndex) { SRaftId *pRaftId = (SRaftId *)key; - printf("key:<%lu, %d>, value:%lu \n", pRaftId->addr, pRaftId->vgId, *p); + printf("key:<" PRIu64 ", %d>, value:%" PRIu64 " \n", pRaftId->addr, pRaftId->vgId, *p); p = (uint64_t *)taosHashIterate(pNextIndex, p); } } diff --git a/source/libs/sync/test/syncRaftIdCheck.cpp b/source/libs/sync/test/syncRaftIdCheck.cpp index 90560e91e7..65da0f6631 100644 --- a/source/libs/sync/test/syncRaftIdCheck.cpp +++ b/source/libs/sync/test/syncRaftIdCheck.cpp @@ -15,14 +15,14 @@ int main(int argc, char** argv) { char host[128]; uint16_t port; syncUtilU642Addr(u64, host, sizeof(host), &port); - printf("%lu -> %s:%d \n", u64, host, port); + printf("" PRIu64 " -> %s:%d \n", u64, host, port); } else if (argc == 3) { uint64_t u64; char* host = argv[1]; uint16_t port = atoi(argv[2]); u64 = syncUtilAddr2U64(host, port); - printf("%s:%d -> %lu \n", host, port, u64); + printf("%s:%d ->: %" PRIu64 " \n", host, port, u64); } else { usage(argv[0]); exit(-1); diff --git a/source/libs/sync/test/syncRaftLogTest.cpp b/source/libs/sync/test/syncRaftLogTest.cpp index 7903e86749..278113919a 100644 --- a/source/libs/sync/test/syncRaftLogTest.cpp +++ b/source/libs/sync/test/syncRaftLogTest.cpp @@ -38,7 +38,7 @@ void test1() { int64_t firstVer = walGetFirstVer(pWal); int64_t lastVer = walGetLastVer(pWal); - printf("firstVer:%ld lastVer:%ld \n", firstVer, lastVer); + printf("firstVer:%" PRId64 " lastVer:%" PRId64 " \n", firstVer, lastVer); walClose(pWal); } @@ -68,7 +68,7 @@ void test2() { int64_t firstVer = walGetFirstVer(pWal); int64_t lastVer = walGetLastVer(pWal); - printf("firstVer:%ld lastVer:%ld \n", firstVer, lastVer); + printf("firstVer:%" PRId64 " lastVer:%" PRId64 " \n", firstVer, lastVer); walClose(pWal); } @@ -92,7 +92,7 @@ void test3() { int64_t firstVer = walGetFirstVer(pWal); int64_t lastVer = walGetLastVer(pWal); - printf("firstVer:%ld lastVer:%ld \n", firstVer, lastVer); + printf("firstVer:%" PRId64 " lastVer:%" PRId64 " \n", firstVer, lastVer); walClose(pWal); } @@ -124,7 +124,7 @@ void test4() { int64_t firstVer = walGetFirstVer(pWal); int64_t lastVer = walGetLastVer(pWal); - printf("firstVer:%ld lastVer:%ld \n", firstVer, lastVer); + printf("firstVer:%" PRId64 " lastVer:%" PRId64 " \n", firstVer, lastVer); walClose(pWal); } @@ -149,7 +149,7 @@ void test5() { int64_t firstVer = walGetFirstVer(pWal); int64_t lastVer = walGetLastVer(pWal); - printf("firstVer:%ld lastVer:%ld \n", firstVer, lastVer); + printf("firstVer:%" PRId64 " lastVer:%" PRId64 " \n", firstVer, lastVer); walClose(pWal); } diff --git a/source/libs/sync/test/syncRaftLogTest2.cpp b/source/libs/sync/test/syncRaftLogTest2.cpp index 9e0c2ecc29..0cb9b51fba 100644 --- a/source/libs/sync/test/syncRaftLogTest2.cpp +++ b/source/libs/sync/test/syncRaftLogTest2.cpp @@ -413,7 +413,7 @@ void test6() { SyncIndex firstVer = walGetFirstVer(pWal); SyncIndex lastVer = walGetLastVer(pWal); bool isEmpty = walIsEmpty(pWal); - printf("before -------- firstVer:%ld lastVer:%ld isEmpty:%d \n", firstVer, lastVer, isEmpty); + printf("before -------- firstVer:%" PRId64 " lastVer:%" PRId64 " isEmpty:%d \n", firstVer, lastVer, isEmpty); } while (0); logStoreDestory(pLogStore); @@ -429,7 +429,7 @@ void test6() { SyncIndex firstVer = walGetFirstVer(pWal); SyncIndex lastVer = walGetLastVer(pWal); bool isEmpty = walIsEmpty(pWal); - printf("after -------- firstVer:%ld lastVer:%ld isEmpty:%d \n", firstVer, lastVer, isEmpty); + printf("after -------- firstVer:%" PRId64 " lastVer:%" PRId64 " isEmpty:%d \n", firstVer, lastVer, isEmpty); } while (0); logStoreLog2((char*)"\n\n\ntest6 restart ----- ", pLogStore); diff --git a/source/libs/sync/test/syncRaftLogTest3.cpp b/source/libs/sync/test/syncRaftLogTest3.cpp index ea1788c545..fd4cade31c 100644 --- a/source/libs/sync/test/syncRaftLogTest3.cpp +++ b/source/libs/sync/test/syncRaftLogTest3.cpp @@ -92,13 +92,13 @@ void test1() { SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode); sTrace("test1"); - sTrace("hasSnapshot:%d, lastApplyIndex:%ld, lastApplyTerm:%lu", hasSnapshot, snapshot.lastApplyIndex, + sTrace("hasSnapshot:%d, lastApplyIndex:%" PRId64 ", lastApplyTerm:%" PRIu64, hasSnapshot, snapshot.lastApplyIndex, snapshot.lastApplyTerm); - sTrace("lastIndex: %ld", lastIndex); - sTrace("lastTerm: %lu", lastTerm); - sTrace("syncStartIndex: %ld", syncStartIndex); - sTrace("%ld's preIndex: %ld", testIndex, preIndex); - sTrace("%ld's preTerm: %lu", testIndex, preTerm); + sTrace("lastIndex: %" PRId64, lastIndex); + sTrace("lastTerm: %" PRIu64, lastTerm); + sTrace("syncStartIndex: %" PRId64, syncStartIndex); + sTrace("" PRId64 "'s preIndex: %" PRId64, testIndex, preIndex); + sTrace("" PRId64 "'s preTerm: %" PRIu64, testIndex, preTerm); if (gAssert) { assert(lastIndex == -1); @@ -154,11 +154,11 @@ void test2() { SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode); sTrace("test2"); - sTrace("hasSnapshot:%d, lastApplyIndex:%ld, lastApplyTerm:%lu", hasSnapshot, snapshot.lastApplyIndex, + sTrace("hasSnapshot:%d, lastApplyIndex:%" PRId64 ", lastApplyTerm:%" PRIu64, hasSnapshot, snapshot.lastApplyIndex, snapshot.lastApplyTerm); - sTrace("lastIndex: %ld", lastIndex); - sTrace("lastTerm: %lu", lastTerm); - sTrace("syncStartIndex: %ld", syncStartIndex); + sTrace("lastIndex: %" PRId64, lastIndex); + sTrace("lastTerm: %" PRIu64, lastTerm); + sTrace("syncStartIndex: %" PRId64, syncStartIndex); if (gAssert) { assert(lastIndex == 10); @@ -170,8 +170,8 @@ void test2() { SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i); SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i); - sTrace("%ld's preIndex: %ld", i, preIndex); - sTrace("%ld's preTerm: %lu", i, preTerm); + sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex); + sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm); if (gAssert) { SyncIndex preIndexArr[12] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; @@ -214,13 +214,13 @@ void test3() { SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode); sTrace("test3"); - sTrace("hasSnapshot:%d, lastApplyIndex:%ld, lastApplyTerm:%lu", hasSnapshot, snapshot.lastApplyIndex, + sTrace("hasSnapshot:%d, lastApplyIndex:%" PRId64 ", lastApplyTerm:%" PRIu64, hasSnapshot, snapshot.lastApplyIndex, snapshot.lastApplyTerm); - sTrace("lastIndex: %ld", lastIndex); - sTrace("lastTerm: %lu", lastTerm); - sTrace("syncStartIndex: %ld", syncStartIndex); - sTrace("%d's preIndex: %ld", 6, preIndex); - sTrace("%d's preTerm: %lu", 6, preTerm); + sTrace("lastIndex: %" PRId64, lastIndex); + sTrace("lastTerm: %" PRIu64, lastTerm); + sTrace("syncStartIndex: %" PRId64, syncStartIndex); + sTrace("%d's preIndex: %" PRId64, 6, preIndex); + sTrace("%d's preTerm: %" PRIu64, 6, preTerm); if (gAssert) { assert(lastIndex == 5); @@ -276,11 +276,11 @@ void test4() { SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode); sTrace("test4"); - sTrace("hasSnapshot:%d, lastApplyIndex:%ld, lastApplyTerm:%lu", hasSnapshot, snapshot.lastApplyIndex, + sTrace("hasSnapshot:%d, lastApplyIndex:%" PRId64 ", lastApplyTerm:%" PRIu64, hasSnapshot, snapshot.lastApplyIndex, snapshot.lastApplyTerm); - sTrace("lastIndex: %ld", lastIndex); - sTrace("lastTerm: %lu", lastTerm); - sTrace("syncStartIndex: %ld", syncStartIndex); + sTrace("lastIndex: %" PRId64, lastIndex); + sTrace("lastTerm: %" PRIu64, lastTerm); + sTrace("syncStartIndex: %" PRId64, syncStartIndex); if (gAssert) { assert(lastIndex == 10); @@ -292,8 +292,8 @@ void test4() { SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i); SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i); - sTrace("%ld's preIndex: %ld", i, preIndex); - sTrace("%ld's preTerm: %lu", i, preTerm); + sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex); + sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm); } logStoreDestory(pLogStore); @@ -344,18 +344,18 @@ void test5() { SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode); sTrace("test5"); - sTrace("hasSnapshot:%d, lastApplyIndex:%ld, lastApplyTerm:%lu", hasSnapshot, snapshot.lastApplyIndex, + sTrace("hasSnapshot:%d, lastApplyIndex:%" PRId64 ", lastApplyTerm:%" PRIu64, hasSnapshot, snapshot.lastApplyIndex, snapshot.lastApplyTerm); - sTrace("lastIndex: %ld", lastIndex); - sTrace("lastTerm: %lu", lastTerm); - sTrace("syncStartIndex: %ld", syncStartIndex); + sTrace("lastIndex: %" PRId64, lastIndex); + sTrace("lastTerm: %" PRIu64, lastTerm); + sTrace("syncStartIndex: %" PRId64, syncStartIndex); for (SyncIndex i = 11; i >= 6; --i) { SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i); SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i); - sTrace("%ld's preIndex: %ld", i, preIndex); - sTrace("%ld's preTerm: %lu", i, preTerm); + sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex); + sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm); if (gAssert) { SyncIndex preIndexArr[12] = {9999, 9999, 9999, 9999, 9999, 9999, 5, 6, 7, 8, 9, 10}; diff --git a/source/libs/sync/test/syncRefTest.cpp b/source/libs/sync/test/syncRefTest.cpp index 96062b1a91..90923a87ee 100644 --- a/source/libs/sync/test/syncRefTest.cpp +++ b/source/libs/sync/test/syncRefTest.cpp @@ -32,7 +32,7 @@ typedef struct SyncObj { static void syncFreeObj(void *param) { SyncObj *pObj = (SyncObj *)param; - printf("syncFreeObj name:%s rid:%ld \n", pObj->name, pObj->rid); + printf("syncFreeObj name:%s rid:%" PRId64 " \n", pObj->name, pObj->rid); taosMemoryFree(pObj); } @@ -66,7 +66,7 @@ int64_t start() { return -1; } - printf("start name:%s rid:%ld \n", pObj->name, pObj->rid); + printf("start name:%s rid:%" PRId64 " \n", pObj->name, pObj->rid); return pObj->rid; } @@ -74,7 +74,7 @@ void stop(int64_t rid) { SyncObj *pObj = (SyncObj *)taosAcquireRef(tsNodeRefId, rid); if (pObj == NULL) return; - printf("stop name:%s rid:%ld \n", pObj->name, pObj->rid); + printf("stop name:%s rid:%" PRId64 " \n", pObj->name, pObj->rid); pObj->data = NULL; taosReleaseRef(tsNodeRefId, pObj->rid); @@ -89,7 +89,7 @@ void *func(void *param) { SyncObj *pObj = (SyncObj *)taosAcquireRef(tsNodeRefId, rid); if (pObj != NULL) { - printf("taosAcquireRef sleep:%d, name:%s, rid:%ld \n", ms, pObj->name, pObj->rid); + printf("taosAcquireRef sleep:%d, name:%s, rid:%" PRId64 " \n", ms, pObj->name, pObj->rid); } else { printf("taosAcquireRef sleep:%d, NULL! \n", ms); } diff --git a/source/libs/sync/test/syncReplicateTest.cpp b/source/libs/sync/test/syncReplicateTest.cpp index 66f347b620..d3ba4bc136 100644 --- a/source/libs/sync/test/syncReplicateTest.cpp +++ b/source/libs/sync/test/syncReplicateTest.cpp @@ -40,26 +40,28 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { if (cbMeta.index > beginIndex) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } else { - sTrace("==callback== ==CommitCb== do not apply again %ld", cbMeta.index); + sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); } } void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, - cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -143,7 +145,8 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%ld", myIndex, i, count, taosGetTimestampMs()); + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncRespMgrTest.cpp b/source/libs/sync/test/syncRespMgrTest.cpp index 93a7ce430f..35daff796f 100644 --- a/source/libs/sync/test/syncRespMgrTest.cpp +++ b/source/libs/sync/test/syncRespMgrTest.cpp @@ -23,7 +23,7 @@ void syncRespMgrInsert(uint64_t count) { stub.rpcMsg.info.ahandle = (void *)(200 + i); stub.rpcMsg.info.handle = (void *)(300 + i); uint64_t ret = syncRespMgrAdd(pMgr, &stub); - printf("insert %lu \n", ret); + printf("insert: %" PRIu64 " \n", ret); } } @@ -35,8 +35,8 @@ void syncRespMgrDelTest(uint64_t begin, uint64_t end) { } void printStub(SRespStub *p) { - printf("createTime:%ld, rpcMsg.code:%d rpcMsg.ahandle:%ld rpcMsg.handle:%ld \n", p->createTime, p->rpcMsg.code, - (int64_t)(p->rpcMsg.info.ahandle), (int64_t)(p->rpcMsg.info.handle)); + printf("createTime:%" PRId64 ", rpcMsg.code:%d rpcMsg.ahandle:%" PRId64 " rpcMsg.handle:%" PRId64 " \n", + p->createTime, p->rpcMsg.code, (int64_t)(p->rpcMsg.info.ahandle), (int64_t)(p->rpcMsg.info.handle)); } void syncRespMgrPrint() { printf("\n----------------syncRespMgrPrint--------------\n"); @@ -52,24 +52,24 @@ void syncRespMgrPrint() { } void syncRespMgrGetTest(uint64_t i) { - printf("------syncRespMgrGetTest------- %lu -- \n", i); + printf("------syncRespMgrGetTest-------: %" PRIu64 " -- \n", i); SRespStub stub; int32_t ret = syncRespMgrGet(pMgr, i, &stub); if (ret == 1) { printStub(&stub); } else if (ret == 0) { - printf("%ld notFound \n", i); + printf("" PRId64 " notFound \n", i); } } void syncRespMgrGetAndDelTest(uint64_t i) { - printf("------syncRespMgrGetAndDelTest-------%lu-- \n", i); + printf("------syncRespMgrGetAndDelTest-------" PRIu64 "-- \n", i); SRespStub stub; int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub); if (ret == 1) { printStub(&stub); } else if (ret == 0) { - printf("%ld notFound \n", i); + printf("" PRId64 " notFound \n", i); } } diff --git a/source/libs/sync/test/syncSnapshotTest.cpp b/source/libs/sync/test/syncSnapshotTest.cpp index 954bdd8ea5..e0d33598b0 100644 --- a/source/libs/sync/test/syncSnapshotTest.cpp +++ b/source/libs/sync/test/syncSnapshotTest.cpp @@ -43,26 +43,28 @@ void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { if (cbMeta.index > beginIndex) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } else { - sTrace("==callback== ==CommitCb== do not apply again %ld", cbMeta.index); + sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); } } void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, - cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } @@ -172,7 +174,7 @@ int main(int argc, char **argv) { if (argc >= 2) { snapshotLastApplyIndex = atoi(argv[1]); } - sTrace("--snapshotLastApplyIndex : %ld \n", snapshotLastApplyIndex); + sTrace("--snapshotLastApplyIndex : %" PRId64 " \n", snapshotLastApplyIndex); int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]); assert(ret == 0); diff --git a/source/libs/sync/test/syncTestTool.cpp b/source/libs/sync/test/syncTestTool.cpp index 2c08910aa8..f35c6f8a2f 100644 --- a/source/libs/sync/test/syncTestTool.cpp +++ b/source/libs/sync/test/syncTestTool.cpp @@ -40,8 +40,10 @@ void cleanup() { walCleanUp(); } void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, flag:%lu, term:%lu " - "currentTerm:%lu \n", + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 + ", term:%" PRIu64 + " " + "currentTerm:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term, cbMeta.currentTerm); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); @@ -50,8 +52,10 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, flag:%lu, term:%lu " - "currentTerm:%lu \n", + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 + ", term:%" PRIu64 + " " + "currentTerm:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term, cbMeta.currentTerm); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); @@ -60,8 +64,10 @@ void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, flag:%lu, term:%lu " - "currentTerm:%lu \n", + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 + ", term:%" PRIu64 + " " + "currentTerm:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term, cbMeta.currentTerm); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); @@ -128,8 +134,9 @@ int32_t SnapshotStopWrite(struct SSyncFSM* pFsm, void* pWriter, bool isApply) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==SnapshotStopWrite== pFsm:%p, pWriter:%p, isApply:%d, gSnapshotLastApplyIndex:%ld, " - "gSnapshotLastApplyTerm:%ld", + "==callback== ==SnapshotStopWrite== pFsm:%p, pWriter:%p, isApply:%d, gSnapshotLastApplyIndex:%" PRId64 + ", " + "gSnapshotLastApplyTerm:%" PRId64, pFsm, pWriter, isApply, gSnapshotLastApplyIndex, gSnapshotLastApplyTerm); sTrace("%s", logBuf); @@ -148,7 +155,8 @@ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFini void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { char* s = syncCfg2Str(&(cbMeta.newCfg)); - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%ld, code:%d, currentTerm:%lu, term:%lu, newCfg:%s", + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64 + ", newCfg:%s", cbMeta.flag, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term, s); taosMemoryFree(s); } @@ -156,8 +164,10 @@ void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMe void LeaderTransferCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==LeaderTransferCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, flag:%lu, term:%lu " - "currentTerm:%lu \n", + "==callback== ==LeaderTransferCb== pFsm:%p, index:%" PRId64 + ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 + " " + "currentTerm:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term, cbMeta.currentTerm); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); @@ -300,7 +310,8 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = TDMT_VND_SUBMIT; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%ld", myIndex, i, count, taosGetTimestampMs()); + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncWriteTest.cpp b/source/libs/sync/test/syncWriteTest.cpp index 34c8eb0f56..3bf068e3c7 100644 --- a/source/libs/sync/test/syncWriteTest.cpp +++ b/source/libs/sync/test/syncWriteTest.cpp @@ -33,23 +33,25 @@ const char *pDir = "./syncWriteTest"; void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, - cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index dad4511491..60eaf467ae 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -370,7 +370,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage init = 1; nRead = tdbOsPRead(pPager->fd, pPage->pData, pPage->pageSize, ((i64)pPage->pageSize) * (pgno - 1)); - tdbTrace("tdbttl pager:%p, pgno:%d, nRead:%ld", pPager, pgno, nRead); + tdbTrace("tdbttl pager:%p, pgno:%d, nRead:%" PRId64, pPager, pgno, nRead); if (nRead < pPage->pageSize) { ASSERT(0); return -1; diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index f699df6883..e73ddedd73 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -249,30 +249,30 @@ int transAsyncSend(SAsyncPool* pool, queue* mq); } \ } while (0) -#define ASYNC_CHECK_HANDLE(exh1, id) \ - do { \ - if (id > 0) { \ - tTrace("handle step1"); \ - SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), id); \ - if (exh2 == NULL || id != exh2->refId) { \ - tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, \ - exh2 ? exh2->refId : 0, id); \ - goto _return1; \ - } \ - } else if (id == 0) { \ - tTrace("handle step2"); \ - SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), id); \ - if (exh2 == NULL || id == exh2->refId) { \ - tTrace("handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, id, \ - exh2 ? exh2->refId : 0); \ - goto _return1; \ - } else { \ - id = exh1->refId; \ - } \ - } else if (id < 0) { \ - tTrace("handle step3"); \ - goto _return2; \ - } \ +#define ASYNC_CHECK_HANDLE(exh1, id) \ + do { \ + if (id > 0) { \ + tTrace("handle step1"); \ + SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), id); \ + if (exh2 == NULL || id != exh2->refId) { \ + tTrace("handle %p except, may already freed, ignore msg, ref1:%" PRIu64 ", ref2:%" PRIu64, exh1, \ + exh2 ? exh2->refId : 0, id); \ + goto _return1; \ + } \ + } else if (id == 0) { \ + tTrace("handle step2"); \ + SExHandle* exh2 = transAcquireExHandle(transGetRefMgt(), id); \ + if (exh2 == NULL || id == exh2->refId) { \ + tTrace("handle %p except, may already freed, ignore msg, ref1:%" PRIu64 ", ref2:%" PRIu64, exh1, id, \ + exh2 ? exh2->refId : 0); \ + goto _return1; \ + } else { \ + id = exh1->refId; \ + } \ + } else if (id < 0) { \ + tTrace("handle step3"); \ + goto _return2; \ + } \ } while (0) int transInitBuffer(SConnBuffer* buf); diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 48e7d7c91d..e9e439971c 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -58,7 +58,7 @@ void* rpcOpen(const SRpcInit* pInit) { uint32_t ip = 0; if (pInit->connType == TAOS_CONN_SERVER) { if (transValidLocalFqdn(pInit->localFqdn, &ip) != 0) { - tError("invalid fqdn: %s, errmsg: %s", pInit->localFqdn, terrstr()); + tError("invalid fqdn:%s, errmsg:%s", pInit->localFqdn, terrstr()); taosMemoryFree(pRpc); return NULL; } @@ -86,7 +86,7 @@ void rpcClose(void* arg) { tInfo("start to close rpc"); transRemoveExHandle(transGetInstMgt(), (int64_t)arg); transReleaseExHandle(transGetInstMgt(), (int64_t)arg); - tInfo("finish to close rpc"); + tInfo("rpc is closed"); return; } void rpcCloseImpl(void* arg) { @@ -112,7 +112,7 @@ void* rpcMallocCont(int32_t contLen) { void rpcFreeCont(void* cont) { if (cont == NULL) return; taosMemoryFree((char*)cont - TRANS_MSG_OVERHEAD); - tTrace("free mem: %p", (char*)cont - TRANS_MSG_OVERHEAD); + tTrace("free mem:%p", (char*)cont - TRANS_MSG_OVERHEAD); } void* rpcReallocCont(void* ptr, int32_t contLen) { diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 4b6ff43ba8..f5110f2471 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -184,22 +184,22 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { #define CONN_PERSIST_TIME(para) (para * 1000 * 10) #define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL) #define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pTransInst))->label) -#define CONN_SHOULD_RELEASE(conn, head) \ - do { \ - if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \ - uint64_t ahandle = head->ahandle; \ - CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); \ - transClearBuffer(&conn->readBuf); \ - transFreeMsg(transContFromHead((char*)head)); \ - tDebug("%s conn %p receive release request, ref: %d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); \ - if (T_REF_VAL_GET(conn) > 1) { \ - transUnrefCliHandle(conn); \ - } \ - destroyCmsg(pMsg); \ - cliReleaseUnfinishedMsg(conn); \ - addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); \ - return; \ - } \ +#define CONN_SHOULD_RELEASE(conn, head) \ + do { \ + if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \ + uint64_t ahandle = head->ahandle; \ + CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); \ + transClearBuffer(&conn->readBuf); \ + transFreeMsg(transContFromHead((char*)head)); \ + tDebug("%s conn %p receive release request, ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); \ + if (T_REF_VAL_GET(conn) > 1) { \ + transUnrefCliHandle(conn); \ + } \ + destroyCmsg(pMsg); \ + cliReleaseUnfinishedMsg(conn); \ + addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); \ + return; \ + } \ } while (0) #define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ @@ -353,7 +353,7 @@ void cliHandleResp(SCliConn* conn) { } STraceId* trace = &transMsg.info.traceId; - tGTrace("%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, code: %d", CONN_GET_INST_LABEL(conn), + tGTrace("%s conn %p %s received from %s:%d, local info:%s:%d, msg size:%d, code:0x%x", CONN_GET_INST_LABEL(conn), conn, TMSG_INFO(pHead->msgType), taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), taosInetNtoa(conn->localAddr.sin_addr), ntohs(conn->localAddr.sin_port), transMsg.contLen, transMsg.code); @@ -573,8 +573,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { return; } if (nread < 0) { - tWarn("%s conn %p read error: %s, ref: %d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), - T_REF_VAL_GET(conn)); + tWarn("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), T_REF_VAL_GET(conn)); conn->broken = true; cliHandleExcept(conn); } @@ -650,12 +649,16 @@ static bool cliHandleNoResp(SCliConn* conn) { return res; } static void cliSendCb(uv_write_t* req, int status) { - SCliConn* pConn = req->data; + SCliConn* pConn = req && req->handle ? req->handle->data : NULL; + taosMemoryFree(req); + if (pConn == NULL) { + return; + } if (status == 0) { tTrace("%s conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); } else { - tError("%s conn %p failed to write: %s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); + tError("%s conn %p failed to write:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); cliHandleExcept(pConn); return; } @@ -708,8 +711,8 @@ void cliSend(SCliConn* pConn) { CONN_SET_PERSIST_BY_APP(pConn); } - pConn->writeReq.data = pConn; - uv_write(&pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); + uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); + uv_write(req, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); return; _RETURN: return; @@ -719,7 +722,7 @@ void cliConnCb(uv_connect_t* req, int status) { // impl later SCliConn* pConn = req->data; if (status != 0) { - tError("%s conn %p failed to connect server: %s", CONN_GET_INST_LABEL(pConn), pConn, uv_strerror(status)); + tError("%s conn %p failed to connect server:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_strerror(status)); cliHandleExcept(pConn); return; } @@ -852,7 +855,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { tTrace("%s conn %p try to connect to %s:%d", pTransInst->label, conn, conn->ip, conn->port); ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); if (ret != 0) { - tTrace("%s conn %p failed to connect to %s:%d, reason: %s", pTransInst->label, conn, conn->ip, conn->port, + tTrace("%s conn %p failed to connect to %s:%d, reason:%s", pTransInst->label, conn, conn->ip, conn->port, uv_err_name(ret)); cliHandleExcept(conn); return; @@ -883,7 +886,7 @@ static void cliAsyncCb(uv_async_t* handle) { count++; } if (count >= 2) { - tTrace("cli process batch size: %d", count); + tTrace("cli process batch size:%d", count); } } @@ -910,7 +913,7 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, int err = taosThreadCreate(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd)); if (err == 0) { - tDebug("success to create tranport-cli thread %d", i); + tDebug("success to create tranport-cli thread:%d", i); } cli->pThreadObj[i] = pThrd; } @@ -1222,7 +1225,7 @@ void transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra cliMsg->refId = (int64_t)shandle; STraceId* trace = &pReq->info.traceId; - tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", transLabel(pTransInst), pThrd->pid, + tGTrace("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); ASSERT(transAsyncSend(pThrd->asyncPool, &(cliMsg->q)) == 0); transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); @@ -1260,7 +1263,7 @@ void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransM cliMsg->refId = (int64_t)shandle; STraceId* trace = &pReq->info.traceId; - tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", transLabel(pTransInst), pThrd->pid, + tGTrace("%s send request at thread:%08" PRId64 ", dst:%s:%d, app:%p", transLabel(pTransInst), pThrd->pid, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); transAsyncSend(pThrd->asyncPool, &(cliMsg->q)); @@ -1294,7 +1297,7 @@ void transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { cliMsg->refId = (int64_t)shandle; SCliThrd* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[i]; - tDebug("%s update epset at thread:%08" PRId64 "", pTransInst->label, thrd->pid); + tDebug("%s update epset at thread:%08" PRId64, pTransInst->label, thrd->pid); transAsyncSend(thrd->asyncPool, &(cliMsg->q)); } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 5f6e3db615..812123441c 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -136,7 +136,7 @@ int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) { } else { p->cap = p->total; p->buf = taosMemoryRealloc(p->buf, p->cap); - tTrace("internal malloc mem: %p, size: %d", p->buf, p->cap); + tTrace("internal malloc mem:%p, size:%d", p->buf, p->cap); uvBuf->base = p->buf + p->len; uvBuf->len = p->cap - p->len; @@ -221,7 +221,7 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { taosThreadMutexUnlock(&item->mtx); int64_t el = taosGetTimestampUs() - st; if (el > 50) { - // tInfo("lock and unlock cost: %d", (int)el); + // tInfo("lock and unlock cost:%d", (int)el); } return uv_async_send(async); } @@ -446,7 +446,7 @@ int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_ } } - tTrace("timer %p put task into delay queue, timeoutMs: %" PRIu64 "", queue->timer, timeoutMs); + tTrace("timer %p put task into delay queue, timeoutMs:%" PRIu64, queue->timer, timeoutMs); heapInsert(queue->heap, &task->node); uv_timer_start(queue->timer, transDQTimeout, timeoutMs, 0); return 0; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 9e4abf09cf..a6e3c57e75 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -245,11 +245,11 @@ static void uvHandleReq(SSvrConn* pConn) { if (pConn->status == ConnNormal && pHead->noResp == 0) { transRefSrvHandle(pConn); - tGTrace("%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", transLabel(pTransInst), pConn, + tGTrace("%s conn %p %s received from %s:%d, local info:%s:%d, msg size:%d", transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->localAddr.sin_addr), ntohs(pConn->localAddr.sin_port), transMsg.contLen); } else { - tGTrace("%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, resp:%d, code: %d", + tGTrace("%s conn %p %s received from %s:%d, local info:%s:%d, msg size:%d, resp:%d, code:%d", transLabel(pTransInst), pConn, TMSG_INFO(transMsg.msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->localAddr.sin_addr), ntohs(pConn->localAddr.sin_port), transMsg.contLen, pHead->noResp, transMsg.code); @@ -265,8 +265,8 @@ static void uvHandleReq(SSvrConn* pConn) { transMsg.info.refId = pConn->refId; transMsg.info.traceId = pHead->traceId; - tGTrace("%s handle %p conn: %p translated to app, refId: %" PRIu64 "", transLabel(pTransInst), transMsg.info.handle, - pConn, pConn->refId); + tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn, + pConn->refId); assert(transMsg.info.handle != NULL); if (pHead->noResp == 1) { @@ -292,7 +292,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { STrans* pTransInst = conn->pTransInst; if (nread > 0) { pBuf->len += nread; - tTrace("%s conn %p total read: %d, current read: %d", transLabel(pTransInst), conn, pBuf->len, (int)nread); + tTrace("%s conn %p total read:%d, current read:%d", transLabel(pTransInst), conn, pBuf->len, (int)nread); if (transReadComplete(pBuf)) { tTrace("%s conn %p alread read complete packet", transLabel(pTransInst), conn); uvHandleReq(conn); @@ -305,7 +305,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { return; } - tWarn("%s conn %p read error: %s", transLabel(pTransInst), conn, uv_err_name(nread)); + tWarn("%s conn %p read error:%s", transLabel(pTransInst), conn, uv_err_name(nread)); if (nread < 0) { conn->broken = true; if (conn->status == ConnAcquire) { @@ -331,7 +331,10 @@ void uvOnTimeoutCb(uv_timer_t* handle) { } void uvOnSendCb(uv_write_t* req, int status) { - SSvrConn* conn = req->data; + SSvrConn* conn = req && req->handle ? req->handle->data : NULL; + taosMemoryFree(req); + if (conn == NULL) return; + if (status == 0) { tTrace("conn %p data already was written on stream", conn); if (!transQueueEmpty(&conn->srvMsgs)) { @@ -390,7 +393,6 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { pHead->traceId = pMsg->info.traceId; pHead->hasEpSet = pMsg->info.hasEpSet; - if (pConn->status == ConnNormal) { pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); } else { @@ -414,7 +416,7 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { STrans* pTransInst = pConn->pTransInst; STraceId* trace = &pMsg->info.traceId; - tGTrace("%s conn %p %s is sent to %s:%d, local info: %s:%d, msglen:%d", transLabel(pTransInst), pConn, + tGTrace("%s conn %p %s is sent to %s:%d, local info:%s:%d, msglen:%d", transLabel(pTransInst), pConn, TMSG_INFO(pHead->msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->localAddr.sin_addr), ntohs(pConn->localAddr.sin_port), len); pHead->msgLen = htonl(len); @@ -433,7 +435,9 @@ static void uvStartSendRespInternal(SSvrMsg* smsg) { uvPrepareSendData(smsg, &wb); transRefSrvHandle(pConn); - uv_write(&pConn->pWriter, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); + + uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); + uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); } static void uvStartSendResp(SSvrMsg* smsg) { // impl @@ -538,7 +542,7 @@ static void uvAcceptAsyncCb(uv_async_t* async) { static void uvShutDownCb(uv_shutdown_t* req, int status) { if (status != 0) { - tDebug("conn failed to shut down: %s", uv_err_name(status)); + tDebug("conn failed to shut down:%s", uv_err_name(status)); } uv_close((uv_handle_t*)req->handle, uvDestroyConn); taosMemoryFree(req); @@ -599,7 +603,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { tError("read error %s", uv_err_name(nread)); } // TODO(log other failure reason) - tError("failed to create connect: %p", q); + tWarn("failed to create connect:%p", q); taosMemoryFree(buf->base); uv_close((uv_handle_t*)q, NULL); // taosMemoryFree(q); @@ -642,7 +646,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { if (uv_accept(q, (uv_stream_t*)(pConn->pTcp)) == 0) { uv_os_fd_t fd; uv_fileno((const uv_handle_t*)pConn->pTcp, &fd); - tTrace("conn %p created, fd: %d", pConn, fd); + tTrace("conn %p created, fd:%d", pConn, fd); int addrlen = sizeof(pConn->addr); if (0 != uv_tcp_getpeername(pConn->pTcp, (struct sockaddr*)&pConn->addr, &addrlen)) { @@ -710,7 +714,7 @@ static bool addHandleToAcceptloop(void* arg) { int err = 0; if ((err = uv_tcp_init(srv->loop, &srv->server)) != 0) { - tError("failed to init accept server: %s", uv_err_name(err)); + tError("failed to init accept server:%s", uv_err_name(err)); return false; } @@ -722,11 +726,11 @@ static bool addHandleToAcceptloop(void* arg) { struct sockaddr_in bind_addr; uv_ip4_addr("0.0.0.0", srv->port, &bind_addr); if ((err = uv_tcp_bind(&srv->server, (const struct sockaddr*)&bind_addr, 0)) != 0) { - tError("failed to bind: %s", uv_err_name(err)); + tError("failed to bind:%s", uv_err_name(err)); return false; } if ((err = uv_listen((uv_stream_t*)&srv->server, 512, uvOnAcceptCb)) != 0) { - tError("failed to listen: %s", uv_err_name(err)); + tError("failed to listen:%s", uv_err_name(err)); terrno = TSDB_CODE_RPC_PORT_EADDRINUSE; return false; } @@ -763,7 +767,7 @@ static SSvrConn* createConn(void* hThrd) { STrans* pTransInst = pThrd->pTransInst; pConn->refId = exh->refId; transRefSrvHandle(pConn); - tTrace("%s handle %p, conn %p created, refId: %" PRId64 "", transLabel(pTransInst), exh, pConn, pConn->refId); + tTrace("%s handle %p, conn %p created, refId:%" PRId64, transLabel(pTransInst), exh, pConn, pConn->refId); return pConn; } @@ -866,10 +870,10 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, assert(0 == uv_pipe_init(srv->loop, &srv->pipeListen, 0)); #ifdef WINDOWS char pipeName[64]; - snprintf(pipeName, sizeof(pipeName), "\\\\?\\pipe\\trans.rpc.%p-%lu", taosSafeRand(), GetCurrentProcessId()); + snprintf(pipeName, sizeof(pipeName), "\\\\?\\pipe\\trans.rpc.%p-" PRIu64, taosSafeRand(), GetCurrentProcessId()); #else char pipeName[PATH_MAX] = {0}; - snprintf(pipeName, sizeof(pipeName), "%s%spipe.trans.rpc.%08X-%lu", tsTempDir, TD_DIRSEP, taosSafeRand(), + snprintf(pipeName, sizeof(pipeName), "%s%spipe.trans.rpc.%08X-" PRIu64, tsTempDir, TD_DIRSEP, taosSafeRand(), taosGetSelfPthreadId()); #endif assert(0 == uv_pipe_bind(&srv->pipeListen, pipeName)); @@ -890,17 +894,16 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, } int err = taosThreadCreate(&(thrd->thread), NULL, transWorkerThread, (void*)(thrd)); if (err == 0) { - tDebug("sucess to create worker-thread %d", i); - // printf("thread %d create\n", i); + tDebug("success to create worker-thread:%d", i); } else { // TODO: clear all other resource later - tError("failed to create worker-thread %d", i); + tError("failed to create worker-thread:%d", i); goto End; } } if (false == taosValidIpAndPort(srv->ip, srv->port)) { terrno = TAOS_SYSTEM_ERROR(errno); - tError("invalid ip/port, %d:%d, reason: %s", srv->ip, srv->port, terrstr()); + tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); goto End; } if (false == addHandleToAcceptloop(srv)) { @@ -1021,7 +1024,7 @@ void transRefSrvHandle(void* handle) { return; } int ref = T_REF_INC((SSvrConn*)handle); - tDebug("conn %p ref count: %d", handle, ref); + tDebug("conn %p ref count:%d", handle, ref); } void transUnrefSrvHandle(void* handle) { @@ -1029,7 +1032,7 @@ void transUnrefSrvHandle(void* handle) { return; } int ref = T_REF_DEC((SSvrConn*)handle); - tDebug("conn %p ref count: %d", handle, ref); + tDebug("conn %p ref count:%d", handle, ref); if (ref == 0) { destroyConn((SSvrConn*)handle, true); } diff --git a/source/libs/transport/test/pushServer.c b/source/libs/transport/test/pushServer.c index 8b1dcd46cf..6a4ff213d0 100644 --- a/source/libs/transport/test/pushServer.c +++ b/source/libs/transport/test/pushServer.c @@ -153,7 +153,7 @@ int main(int argc, char *argv[]) { dDebugFlag = rpcDebugFlag; uDebugFlag = rpcDebugFlag; } else { - printf("\nusage: %s [options] \n", argv[0]); + printf("\nusage:% [options] \n", argv[0]); printf(" [-p port]: server port number, default is:%d\n", rpcInit.localPort); printf(" [-t threads]: number of rpc threads, default is:%d\n", rpcInit.numOfThreads); printf(" [-s sessions]: number of sessions, default is:%d\n", rpcInit.sessions); diff --git a/source/libs/wal/inc/walInt.h b/source/libs/wal/inc/walInt.h index 2767780ff3..20667fc918 100644 --- a/source/libs/wal/inc/walInt.h +++ b/source/libs/wal/inc/walInt.h @@ -146,12 +146,12 @@ int walMetaDeserialize(SWal* pWal, const char* bytes); // seek section int walChangeWrite(SWal* pWal, int64_t ver); -int walSetWrite(SWal* pWal); +int walInitWriteFile(SWal* pWal); // seek section end int64_t walGetSeq(); int walSeekWriteVer(SWal* pWal, int64_t ver); -int walRoll(SWal* pWal); +int32_t walRollImpl(SWal* pWal); #ifdef __cplusplus } diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 313fd06c8e..991b50f7c0 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -51,10 +51,10 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { char fnameStr[WAL_FILE_LEN]; walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); - int64_t file_size = 0; - taosStatFile(fnameStr, &file_size, NULL); - int readSize = TMIN(WAL_MAX_SIZE + 2, file_size); - pLastFileInfo->fileSize = file_size; + int64_t fileSize = 0; + taosStatFile(fnameStr, &fileSize, NULL); + int readSize = TMIN(WAL_MAX_SIZE + 2, fileSize); + pLastFileInfo->fileSize = fileSize; TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); if (pFile == NULL) { @@ -141,34 +141,53 @@ int walCheckAndRepairMeta(SWal* pWal) { regfree(&idxRegPattern); taosArraySort(pLogInfoArray, compareWalFileInfo); - int oldSz = 0; - if (pWal->fileInfoSet) { - oldSz = taosArrayGetSize(pWal->fileInfoSet); - } - int newSz = taosArrayGetSize(pLogInfoArray); - if (oldSz > newSz) { - taosArrayPopFrontBatch(pWal->fileInfoSet, oldSz - newSz); - } else if (oldSz < newSz) { - for (int i = oldSz; i < newSz; i++) { + int metaFileNum = taosArrayGetSize(pWal->fileInfoSet); + int actualFileNum = taosArrayGetSize(pLogInfoArray); + +#if 0 + for (int32_t fileNo = actualFileNum - 1; fileNo >= 0; fileNo--) { + SWalFileInfo* pFileInfo = taosArrayGet(pLogInfoArray, fileNo); + char fnameStr[WAL_FILE_LEN]; + walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); + int64_t fileSize = 0; + taosStatFile(fnameStr, &fileSize, NULL); + if (fileSize == 0) { + taosRemoveFile(fnameStr); + walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); + taosRemoveFile(fnameStr); + taosArrayPop(pLogInfoArray); + } else { + break; + } + } + + actualFileNum = taosArrayGetSize(pLogInfoArray); +#endif + + if (metaFileNum > actualFileNum) { + taosArrayPopFrontBatch(pWal->fileInfoSet, metaFileNum - actualFileNum); + } else if (metaFileNum < actualFileNum) { + for (int i = metaFileNum; i < actualFileNum; i++) { SWalFileInfo* pFileInfo = taosArrayGet(pLogInfoArray, i); taosArrayPush(pWal->fileInfoSet, pFileInfo); } } taosArrayDestroy(pLogInfoArray); - pWal->writeCur = newSz - 1; - if (newSz > 0) { + pWal->writeCur = actualFileNum - 1; + if (actualFileNum > 0) { pWal->vers.firstVer = ((SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, 0))->firstVer; - SWalFileInfo* pLastFileInfo = taosArrayGet(pWal->fileInfoSet, newSz - 1); + SWalFileInfo* pLastFileInfo = taosArrayGet(pWal->fileInfoSet, actualFileNum - 1); char fnameStr[WAL_FILE_LEN]; walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); - int64_t file_size = 0; - taosStatFile(fnameStr, &file_size, NULL); + int64_t fileSize = 0; + taosStatFile(fnameStr, &fileSize, NULL); + /*ASSERT(fileSize != 0);*/ - if (oldSz != newSz || pLastFileInfo->fileSize != file_size) { - pLastFileInfo->fileSize = file_size; + if (metaFileNum != actualFileNum || pLastFileInfo->fileSize != fileSize) { + pLastFileInfo->fileSize = fileSize; pWal->vers.lastVer = walScanLogGetLastVer(pWal); ((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->lastVer = pWal->vers.lastVer; ASSERT(pWal->vers.lastVer != -1); @@ -382,9 +401,9 @@ int walLoadMeta(SWal* pWal) { char fnameStr[WAL_FILE_LEN]; walBuildMetaName(pWal, metaVer, fnameStr); // read metafile - int64_t file_size = 0; - taosStatFile(fnameStr, &file_size, NULL); - int size = (int)file_size; + int64_t fileSize = 0; + taosStatFile(fnameStr, &fileSize, NULL); + int size = (int)fileSize; char* buf = taosMemoryMalloc(size + 5); if (buf == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index b5c75ce3c4..eb0c7f56bd 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -32,16 +32,22 @@ SWalReader *walOpenReader(SWal *pWal, SWalFilterCond *cond) { pRead->pLogFile = NULL; pRead->curVersion = -1; pRead->curFileFirstVer = -1; + pRead->curInvalid = 1; pRead->capacity = 0; - if (cond) + if (cond) { pRead->cond = *cond; - else { + } else { pRead->cond.scanMeta = 0; pRead->cond.scanUncommited = 0; + pRead->cond.enableRef = 0; } taosThreadMutexInit(&pRead->mutex, NULL); + /*if (pRead->cond.enableRef) {*/ + /*walOpenRef(pWal);*/ + /*}*/ + pRead->pHead = taosMemoryMalloc(sizeof(SWalCkHead)); if (pRead->pHead == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; @@ -94,17 +100,19 @@ static int64_t walReadSeekFilePos(SWalReader *pRead, int64_t fileFirstVer, int64 ret = taosLSeekFile(pIdxTFile, offset, SEEK_SET); if (ret < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("failed to seek idx file, ver %ld, pos: %ld, since %s", ver, offset, terrstr()); + wError("vgId:%d, failed to seek idx file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pRead->pWal->cfg.vgId, ver, + offset, terrstr()); return -1; } SWalIdxEntry entry = {0}; if ((ret = taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry))) != sizeof(SWalIdxEntry)) { if (ret < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("failed to read idx file, since %s", terrstr()); + wError("vgId:%d, failed to read idx file, since %s", pRead->pWal->cfg.vgId, terrstr()); } else { terrno = TSDB_CODE_WAL_FILE_CORRUPTED; - wError("read idx file incompletely, read bytes %ld, bytes should be %lu", ret, sizeof(SWalIdxEntry)); + wError("vgId:%d, read idx file incompletely, read bytes %" PRId64 ", bytes should be %" PRIu64, + pRead->pWal->cfg.vgId, ret, sizeof(SWalIdxEntry)); } return -1; } @@ -113,7 +121,8 @@ static int64_t walReadSeekFilePos(SWalReader *pRead, int64_t fileFirstVer, int64 ret = taosLSeekFile(pLogTFile, entry.offset, SEEK_SET); if (ret < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("failed to seek log file, ver %ld, pos: %ld, since %s", ver, entry.offset, terrstr()); + wError("vgId:%d, failed to seek log file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pRead->pWal->cfg.vgId, ver, + entry.offset, terrstr()); return -1; } return ret; @@ -129,7 +138,7 @@ static int32_t walReadChangeFile(SWalReader *pRead, int64_t fileFirstVer) { TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_READ); if (pLogTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("cannot open file %s, since %s", fnameStr, terrstr()); + wError("vgId:%d, cannot open file %s, since %s", pRead->pWal->cfg.vgId, fnameStr, terrstr()); return -1; } @@ -139,7 +148,7 @@ static int32_t walReadChangeFile(SWalReader *pRead, int64_t fileFirstVer) { TdFilePtr pIdxTFile = taosOpenFile(fnameStr, TD_FILE_READ); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("cannot open file %s, since %s", fnameStr, terrstr()); + wError("vgId:%d, cannot open file %s, since %s", pRead->pWal->cfg.vgId, fnameStr, terrstr()); return -1; } @@ -147,18 +156,8 @@ static int32_t walReadChangeFile(SWalReader *pRead, int64_t fileFirstVer) { return 0; } -static int32_t walReadSeekVer(SWalReader *pRead, int64_t ver) { +int32_t walReadSeekVerImpl(SWalReader *pRead, int64_t ver) { SWal *pWal = pRead->pWal; - if (ver == pRead->curVersion) { - return 0; - } - if (ver > pWal->vers.lastVer || ver < pWal->vers.firstVer) { - wError("invalid version: % " PRId64 ", first ver %ld, last ver %ld", ver, pWal->vers.firstVer, pWal->vers.lastVer); - terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; - return -1; - } - if (ver < pWal->vers.snapshotVer) { - } SWalFileInfo tmpInfo; tmpInfo.firstVer = ver; @@ -166,18 +165,45 @@ static int32_t walReadSeekVer(SWalReader *pRead, int64_t ver) { SWalFileInfo *pRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE); ASSERT(pRet != NULL); if (pRead->curFileFirstVer != pRet->firstVer) { - // error code set inner + // error code was set inner if (walReadChangeFile(pRead, pRet->firstVer) < 0) { return -1; } } - // error code set inner + // error code was set inner if (walReadSeekFilePos(pRead, pRet->firstVer, ver) < 0) { return -1; } + wDebug("wal version reset from %ld to %ld", pRead->curVersion, ver); + pRead->curVersion = ver; + return 0; +} + +int32_t walReadSeekVer(SWalReader *pRead, int64_t ver) { + SWal *pWal = pRead->pWal; + if (!pRead->curInvalid && ver == pRead->curVersion) { + wDebug("wal version %ld match, no need to reset", ver); + return 0; + } + + pRead->curInvalid = 1; + pRead->curVersion = ver; + + if (ver > pWal->vers.lastVer || ver < pWal->vers.firstVer) { + wDebug("vgId:%d, invalid index:%" PRId64 ", first index:%" PRId64 ", last index:%" PRId64, pRead->pWal->cfg.vgId, + ver, pWal->vers.firstVer, pWal->vers.lastVer); + terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; + return -1; + } + if (ver < pWal->vers.snapshotVer) { + } + + if (walReadSeekVerImpl(pRead, ver) < 0) { + return -1; + } return 0; } @@ -186,18 +212,35 @@ void walSetReaderCapacity(SWalReader *pRead, int32_t capacity) { pRead->capacity static int32_t walFetchHeadNew(SWalReader *pRead, int64_t fetchVer) { int64_t contLen; - if (pRead->curVersion != fetchVer) { - if (walReadSeekVer(pRead, fetchVer) < 0) return -1; - } - contLen = taosReadFile(pRead->pLogFile, pRead->pHead, sizeof(SWalCkHead)); - if (contLen != sizeof(SWalCkHead)) { - if (contLen < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - } else { - terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + bool seeked = false; + + if (pRead->curInvalid || pRead->curVersion != fetchVer) { + if (walReadSeekVer(pRead, fetchVer) < 0) { + ASSERT(0); + pRead->curVersion = fetchVer; + pRead->curInvalid = 1; + return -1; + } + seeked = true; + } + while (1) { + contLen = taosReadFile(pRead->pLogFile, pRead->pHead, sizeof(SWalCkHead)); + if (contLen == sizeof(SWalCkHead)) { + break; + } else if (contLen == 0 && !seeked) { + walReadSeekVerImpl(pRead, fetchVer); + seeked = true; + continue; + } else { + if (contLen < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + } else { + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + } + ASSERT(0); + pRead->curInvalid = 1; + return -1; } - pRead->curVersion = -1; - return -1; } return 0; } @@ -220,35 +263,37 @@ static int32_t walFetchBodyNew(SWalReader *pRead) { if (pReadHead->bodyLen != taosReadFile(pRead->pLogFile, pReadHead->body, pReadHead->bodyLen)) { if (pReadHead->bodyLen < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("wal fetch body error: %" PRId64 ", read request version:%" PRId64 ", since %s", - pRead->pHead->head.version, ver, tstrerror(terrno)); + wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since %s", + pRead->pWal->cfg.vgId, pRead->pHead->head.version, ver, tstrerror(terrno)); } else { - wError("wal fetch body error: %" PRId64 ", read request version:%" PRId64 ", since file corrupted", - pRead->pHead->head.version, ver); + wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since file corrupted", + pRead->pWal->cfg.vgId, pRead->pHead->head.version, ver); terrno = TSDB_CODE_WAL_FILE_CORRUPTED; } - pRead->curVersion = -1; + pRead->curInvalid = 1; ASSERT(0); return -1; } if (pReadHead->version != ver) { - wError("wal fetch body error: %" PRId64 ", read request version:%" PRId64 "", pRead->pHead->head.version, ver); - pRead->curVersion = -1; + wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64, pRead->pWal->cfg.vgId, + pRead->pHead->head.version, ver); + pRead->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; ASSERT(0); return -1; } if (walValidBodyCksum(pRead->pHead) != 0) { - wError("wal fetch body error: % " PRId64 ", since body checksum not passed", ver); - pRead->curVersion = -1; + wError("vgId:%d, wal fetch body error:%" PRId64 ", since body checksum not passed", pRead->pWal->cfg.vgId, ver); + pRead->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; ASSERT(0); return -1; } pRead->curVersion = ver + 1; + wDebug("version advance to %ld, fetch body", pRead->curVersion); return 0; } @@ -260,11 +305,13 @@ static int32_t walSkipFetchBodyNew(SWalReader *pRead) { code = taosLSeekFile(pRead->pLogFile, pRead->pHead->head.bodyLen, SEEK_CUR); if (code < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - pRead->curVersion = -1; + pRead->curInvalid = 1; + ASSERT(0); return -1; } pRead->curVersion++; + wDebug("version advance to %ld, skip fetch", pRead->curVersion); return 0; } @@ -277,7 +324,7 @@ int32_t walFetchHead(SWalReader *pRead, int64_t ver, SWalCkHead *pHead) { return -1; } - if (pRead->curVersion != ver) { + if (pRead->curInvalid || pRead->curVersion != ver) { code = walReadSeekVer(pRead, ver); if (code < 0) return -1; } @@ -292,7 +339,7 @@ int32_t walFetchHead(SWalReader *pRead, int64_t ver, SWalCkHead *pHead) { code = walValidHeadCksum(pHead); if (code != 0) { - wError("unexpected wal log version: % " PRId64 ", since head checksum not passed", ver); + wError("vgId:%d, unexpected wal log index:%" PRId64 ", since head checksum not passed", pRead->pWal->cfg.vgId, ver); terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; } @@ -308,7 +355,7 @@ int32_t walSkipFetchBody(SWalReader *pRead, const SWalCkHead *pHead) { code = taosLSeekFile(pRead->pLogFile, pHead->head.bodyLen, SEEK_CUR); if (code < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - pRead->curVersion = -1; + pRead->curInvalid = 1; return -1; } @@ -338,15 +385,16 @@ int32_t walFetchBody(SWalReader *pRead, SWalCkHead **ppHead) { } if (pReadHead->version != ver) { - wError("wal fetch body error: %" PRId64 ", read request version:%" PRId64 "", pRead->pHead->head.version, ver); - pRead->curVersion = -1; + wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64, pRead->pWal->cfg.vgId, + pRead->pHead->head.version, ver); + pRead->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; } if (walValidBodyCksum(*ppHead) != 0) { - wError("wal fetch body error: % " PRId64 ", since body checksum not passed", ver); - pRead->curVersion = -1; + wError("vgId:%d, wal fetch body error:%" PRId64 ", since body checksum not passed", pRead->pWal->cfg.vgId, ver); + pRead->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; } @@ -355,61 +403,52 @@ int32_t walFetchBody(SWalReader *pRead, SWalCkHead **ppHead) { return 0; } -int32_t walReadWithHandle_s(SWalReader *pRead, int64_t ver, SWalCont **ppHead) { - taosThreadMutexLock(&pRead->mutex); - if (walReadVer(pRead, ver) < 0) { - taosThreadMutexUnlock(&pRead->mutex); - return -1; - } - *ppHead = taosMemoryMalloc(sizeof(SWalCont) + pRead->pHead->head.bodyLen); - if (*ppHead == NULL) { - taosThreadMutexUnlock(&pRead->mutex); - return -1; - } - memcpy(*ppHead, &pRead->pHead->head, sizeof(SWalCont) + pRead->pHead->head.bodyLen); - taosThreadMutexUnlock(&pRead->mutex); - return 0; -} - int32_t walReadVer(SWalReader *pRead, int64_t ver) { - int64_t code; + int64_t contLen; + bool seeked = false; if (pRead->pWal->vers.firstVer == -1) { terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; return -1; } - // TODO: check wal life - if (pRead->curVersion != ver) { - if (walReadSeekVer(pRead, ver) < 0) { - wError("unexpected wal log version: % " PRId64 ", since %s", ver, terrstr()); - return -1; - } - } - if (ver > pRead->pWal->vers.lastVer || ver < pRead->pWal->vers.firstVer) { - wError("invalid version: % " PRId64 ", first ver %ld, last ver %ld", ver, pRead->pWal->vers.firstVer, - pRead->pWal->vers.lastVer); + wError("vgId:%d, invalid index:%" PRId64 ", first index:%" PRId64 ", last index:%" PRId64, pRead->pWal->cfg.vgId, + ver, pRead->pWal->vers.firstVer, pRead->pWal->vers.lastVer); terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; return -1; } - ASSERT(taosValidFile(pRead->pLogFile) == true); - - code = taosReadFile(pRead->pLogFile, pRead->pHead, sizeof(SWalCkHead)); - if (code != sizeof(SWalCkHead)) { - if (code < 0) - terrno = TAOS_SYSTEM_ERROR(errno); - else { - terrno = TSDB_CODE_WAL_FILE_CORRUPTED; - ASSERT(0); + if (pRead->curInvalid || pRead->curVersion != ver) { + if (walReadSeekVer(pRead, ver) < 0) { + wError("vgId:%d, unexpected wal log index:%" PRId64 ", since %s", pRead->pWal->cfg.vgId, ver, terrstr()); + return -1; } - return -1; + seeked = true; } - code = walValidHeadCksum(pRead->pHead); - if (code != 0) { - wError("unexpected wal log version: % " PRId64 ", since head checksum not passed", ver); + while (1) { + contLen = taosReadFile(pRead->pLogFile, pRead->pHead, sizeof(SWalCkHead)); + if (contLen == sizeof(SWalCkHead)) { + break; + } else if (contLen == 0 && !seeked) { + walReadSeekVerImpl(pRead, ver); + seeked = true; + continue; + } else { + if (contLen < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + } else { + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + } + ASSERT(0); + return -1; + } + } + + contLen = walValidHeadCksum(pRead->pHead); + if (contLen != 0) { + wError("vgId:%d, unexpected wal log index:%" PRId64 ", since head checksum not passed", pRead->pWal->cfg.vgId, ver); terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; } @@ -424,9 +463,9 @@ int32_t walReadVer(SWalReader *pRead, int64_t ver) { pRead->capacity = pRead->pHead->head.bodyLen; } - if ((code = taosReadFile(pRead->pLogFile, pRead->pHead->head.body, pRead->pHead->head.bodyLen)) != + if ((contLen = taosReadFile(pRead->pLogFile, pRead->pHead->head.body, pRead->pHead->head.bodyLen)) != pRead->pHead->head.bodyLen) { - if (code < 0) + if (contLen < 0) terrno = TAOS_SYSTEM_ERROR(errno); else { terrno = TSDB_CODE_WAL_FILE_CORRUPTED; @@ -436,17 +475,17 @@ int32_t walReadVer(SWalReader *pRead, int64_t ver) { } if (pRead->pHead->head.version != ver) { - wError("unexpected wal log version: %" PRId64 ", read request version:%" PRId64 "", pRead->pHead->head.version, - ver); - pRead->curVersion = -1; + wError("vgId:%d, unexpected wal log index:%" PRId64 ", read request index:%" PRId64, pRead->pWal->cfg.vgId, + pRead->pHead->head.version, ver); + pRead->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; } - code = walValidBodyCksum(pRead->pHead); - if (code != 0) { - wError("unexpected wal log version: % " PRId64 ", since body checksum not passed", ver); - pRead->curVersion = -1; + contLen = walValidBodyCksum(pRead->pHead); + if (contLen != 0) { + wError("vgId:%d, unexpected wal log index:%" PRId64 ", since body checksum not passed", pRead->pWal->cfg.vgId, ver); + pRead->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; } diff --git a/source/libs/wal/src/walSeek.c b/source/libs/wal/src/walSeek.c index b99206fe98..78d45c84e2 100644 --- a/source/libs/wal/src/walSeek.c +++ b/source/libs/wal/src/walSeek.c @@ -48,7 +48,7 @@ static int64_t walSeekWritePos(SWal* pWal, int64_t ver) { return 0; } -int walSetWrite(SWal* pWal) { +int walInitWriteFile(SWal* pWal) { TdFilePtr pIdxTFile, pLogTFile; SWalFileInfo* pRet = taosArrayGetLast(pWal->fileInfoSet); ASSERT(pRet != NULL); @@ -70,6 +70,7 @@ int walSetWrite(SWal* pWal) { // switch file pWal->pWriteIdxTFile = pIdxTFile; pWal->pWriteLogTFile = pLogTFile; + pWal->writeCur = taosArrayGetSize(pWal->fileInfoSet) - 1; return 0; } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 445cdea45b..26dc3cdffb 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -99,7 +99,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { // delete files int fileSetSize = taosArrayGetSize(pWal->fileInfoSet); - for (int i = pWal->writeCur; i < fileSetSize; i++) { + for (int i = pWal->writeCur + 1; i < fileSetSize; i++) { walBuildLogName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr); taosRemoveFile(fnameStr); walBuildIdxName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr); @@ -113,18 +113,21 @@ int32_t walRollback(SWal *pWal, int64_t ver) { TdFilePtr pIdxTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND); if (pIdxTFile == NULL) { + ASSERT(0); taosThreadMutexUnlock(&pWal->mutex); return -1; } int64_t idxOff = walGetVerIdxOffset(pWal, ver); code = taosLSeekFile(pIdxTFile, idxOff, SEEK_SET); if (code < 0) { + ASSERT(0); taosThreadMutexUnlock(&pWal->mutex); return -1; } // read idx file and get log file pos SWalIdxEntry entry; if (taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) { + ASSERT(0); taosThreadMutexUnlock(&pWal->mutex); return -1; } @@ -133,12 +136,14 @@ int32_t walRollback(SWal *pWal, int64_t ver) { walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr); TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND); if (pLogTFile == NULL) { + ASSERT(0); // TODO taosThreadMutexUnlock(&pWal->mutex); return -1; } code = taosLSeekFile(pLogTFile, entry.offset, SEEK_SET); if (code < 0) { + ASSERT(0); // TODO taosThreadMutexUnlock(&pWal->mutex); return -1; @@ -148,6 +153,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { ASSERT(taosValidFile(pLogTFile)); int64_t size = taosReadFile(pLogTFile, &head, sizeof(SWalCkHead)); if (size != sizeof(SWalCkHead)) { + ASSERT(0); taosThreadMutexUnlock(&pWal->mutex); return -1; } @@ -201,19 +207,49 @@ int32_t walRollback(SWal *pWal, int64_t ver) { return 0; } +static FORCE_INLINE int32_t walCheckAndRoll(SWal *pWal) { + if (taosArrayGetSize(pWal->fileInfoSet) == 0) { + /*pWal->vers.firstVer = index;*/ + if (walRollImpl(pWal) < 0) { + return -1; + } + } else { + int64_t passed = walGetSeq() - pWal->lastRollSeq; + if (pWal->cfg.rollPeriod != -1 && pWal->cfg.rollPeriod != 0 && passed > pWal->cfg.rollPeriod) { + if (walRollImpl(pWal) < 0) { + return -1; + } + } else if (pWal->cfg.segSize != -1 && pWal->cfg.segSize != 0 && walGetLastFileSize(pWal) > pWal->cfg.segSize) { + if (walRollImpl(pWal) < 0) { + return -1; + } + } + } + return 0; +} + int32_t walBeginSnapshot(SWal *pWal, int64_t ver) { pWal->vers.verInSnapshotting = ver; // check file rolling if (pWal->cfg.retentionPeriod == 0) { - walRoll(pWal); + taosThreadMutexLock(&pWal->mutex); + if (walGetLastFileSize(pWal) != 0) { + walRollImpl(pWal); + } + taosThreadMutexUnlock(&pWal->mutex); } return 0; } int32_t walEndSnapshot(SWal *pWal) { + int32_t code = 0; + taosThreadMutexLock(&pWal->mutex); int64_t ver = pWal->vers.verInSnapshotting; - if (ver == -1) return 0; + if (ver == -1) { + code = -1; + goto END; + }; pWal->vers.snapshotVer = ver; int ts = taosGetTimestampSec(); @@ -229,7 +265,7 @@ int32_t walEndSnapshot(SWal *pWal) { } // iterate files, until the searched result for (SWalFileInfo *iter = pWal->fileInfoSet->pData; iter < pInfo; iter++) { - if ((pWal->cfg.retentionSize != -1 && pWal->totSize > pWal->cfg.retentionSize) || + if ((pWal->cfg.retentionSize != -1 && newTotSize > pWal->cfg.retentionSize) || (pWal->cfg.retentionPeriod != -1 && iter->closeTs + pWal->cfg.retentionPeriod > ts)) { // delete according to file size or close time deleteCnt++; @@ -259,28 +295,30 @@ int32_t walEndSnapshot(SWal *pWal) { pWal->vers.verInSnapshotting = -1; // save snapshot ver, commit ver - int code = walSaveMeta(pWal); + code = walSaveMeta(pWal); if (code < 0) { - return -1; + goto END; } - return 0; +END: + taosThreadMutexUnlock(&pWal->mutex); + return code; } -int walRoll(SWal *pWal) { +int32_t walRollImpl(SWal *pWal) { int32_t code = 0; if (pWal->pWriteIdxTFile != NULL) { code = taosCloseFile(&pWal->pWriteIdxTFile); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + goto END; } } if (pWal->pWriteLogTFile != NULL) { code = taosCloseFile(&pWal->pWriteLogTFile); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + goto END; } } TdFilePtr pIdxTFile, pLogTFile; @@ -291,18 +329,20 @@ int walRoll(SWal *pWal) { pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + code = -1; + goto END; } walBuildLogName(pWal, newFileFirstVersion, fnameStr); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + code = -1; + goto END; } - // terrno set inner + // error code was set inner code = walRollFileInfo(pWal); if (code != 0) { - return -1; + goto END; } // switch file @@ -312,13 +352,18 @@ int walRoll(SWal *pWal) { ASSERT(pWal->writeCur >= 0); pWal->lastRollSeq = walGetSeq(); - return 0; + + walSaveMeta(pWal); + +END: + return code; } -static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { +static int32_t walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { SWalIdxEntry entry = {.ver = ver, .offset = offset}; int64_t idxOffset = taosLSeekFile(pWal->pWriteIdxTFile, 0, SEEK_END); - wDebug("write index: ver: %ld, offset: %ld, at %ld", ver, offset, idxOffset); + wDebug("vgId:%d, write index, index:%" PRId64 ", offset:%" PRId64 ", at %" PRId64, pWal->cfg.vgId, ver, offset, + idxOffset); int64_t size = taosWriteFile(pWal->pWriteIdxTFile, &entry, sizeof(SWalIdxEntry)); if (size != sizeof(SWalIdxEntry)) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -328,61 +373,14 @@ static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { return 0; } -int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLogMeta syncMeta, const void *body, - int32_t bodyLen) { - int32_t code = 0; - - // no wal - if (pWal->cfg.level == TAOS_WAL_NOLOG) return 0; - - if (bodyLen > TSDB_MAX_WAL_SIZE) { - terrno = TSDB_CODE_WAL_SIZE_LIMIT; - return -1; - } - taosThreadMutexLock(&pWal->mutex); - - if (index == pWal->vers.lastVer + 1) { - if (taosArrayGetSize(pWal->fileInfoSet) == 0) { - pWal->vers.firstVer = index; - if (walRoll(pWal) < 0) { - taosThreadMutexUnlock(&pWal->mutex); - return -1; - } - } else { - int64_t passed = walGetSeq() - pWal->lastRollSeq; - if (pWal->cfg.rollPeriod != -1 && pWal->cfg.rollPeriod != 0 && passed > pWal->cfg.rollPeriod) { - if (walRoll(pWal) < 0) { - taosThreadMutexUnlock(&pWal->mutex); - return -1; - } - } else if (pWal->cfg.segSize != -1 && pWal->cfg.segSize != 0 && walGetLastFileSize(pWal) > pWal->cfg.segSize) { - if (walRoll(pWal) < 0) { - taosThreadMutexUnlock(&pWal->mutex); - return -1; - } - } - } - } else { - // reject skip log or rewrite log - // must truncate explicitly first - terrno = TSDB_CODE_WAL_INVALID_VER; - taosThreadMutexUnlock(&pWal->mutex); - return -1; - } - - /*if (!tfValid(pWal->pWriteLogTFile)) return -1;*/ - - ASSERT(pWal->writeCur >= 0); - - if (pWal->pWriteIdxTFile == NULL || pWal->pWriteLogTFile == NULL) { - walSetWrite(pWal); - taosLSeekFile(pWal->pWriteLogTFile, 0, SEEK_END); - taosLSeekFile(pWal->pWriteIdxTFile, 0, SEEK_END); - } - - pWal->writeHead.head.version = index; +// TODO gurantee atomicity by truncate failed writing +static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, + const void *body, int32_t bodyLen) { + int64_t code = 0; int64_t offset = walGetCurFileOffset(pWal); + + pWal->writeHead.head.version = index; pWal->writeHead.head.bodyLen = bodyLen; pWal->writeHead.head.msgType = msgType; @@ -397,7 +395,8 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog terrno = TAOS_SYSTEM_ERROR(errno); wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); - return -1; + code = -1; + goto END; } if (taosWriteFile(pWal->pWriteLogTFile, (char *)body, bodyLen) != bodyLen) { @@ -405,13 +404,14 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog terrno = TAOS_SYSTEM_ERROR(errno); wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); - return -1; + code = -1; + goto END; } code = walWriteIndex(pWal, index, offset); - if (code != 0) { - // TODO - return -1; + if (code < 0) { + // TODO ftruncate + goto END; } // set status @@ -424,13 +424,88 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog walGetCurFileInfo(pWal)->lastVer = index; walGetCurFileInfo(pWal)->fileSize += sizeof(SWalCkHead) + bodyLen; - taosThreadMutexUnlock(&pWal->mutex); - return 0; +END: + return -1; +} + +int64_t walAppendLog(SWal *pWal, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen) { + if (bodyLen > TSDB_MAX_WAL_SIZE) { + terrno = TSDB_CODE_WAL_SIZE_LIMIT; + return -1; + } + + taosThreadMutexLock(&pWal->mutex); + + int64_t index = pWal->vers.lastVer + 1; + + if (walCheckAndRoll(pWal) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + if (pWal->pWriteIdxTFile == NULL || pWal->pWriteIdxTFile == NULL || pWal->writeCur < 0) { + if (walInitWriteFile(pWal) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + } + + ASSERT(pWal->pWriteIdxTFile != NULL && pWal->pWriteLogTFile != NULL && pWal->writeCur >= 0); + + if (walWriteImpl(pWal, index, msgType, syncMeta, body, bodyLen) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + taosThreadMutexUnlock(&pWal->mutex); + return index; +} + +int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, + int32_t bodyLen) { + int32_t code = 0; + + if (bodyLen > TSDB_MAX_WAL_SIZE) { + terrno = TSDB_CODE_WAL_SIZE_LIMIT; + return -1; + } + taosThreadMutexLock(&pWal->mutex); + + // concurrency control: + // if logs are write with assigned index, + // smaller index must be write before larger one + if (index != pWal->vers.lastVer + 1) { + terrno = TSDB_CODE_WAL_INVALID_VER; + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + if (walCheckAndRoll(pWal) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + if (pWal->pWriteIdxTFile == NULL || pWal->pWriteIdxTFile == NULL || pWal->writeCur < 0) { + if (walInitWriteFile(pWal) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + } + + ASSERT(pWal->pWriteIdxTFile != NULL && pWal->pWriteLogTFile != NULL && pWal->writeCur >= 0); + + if (walWriteImpl(pWal, index, msgType, syncMeta, body, bodyLen) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + taosThreadMutexUnlock(&pWal->mutex); + return code; } int32_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, int32_t bodyLen) { - SSyncLogMeta syncMeta = { + SWalSyncInfo syncMeta = { .isWeek = -1, .seqNum = UINT64_MAX, .term = UINT64_MAX, diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 243a234abe..b755a35815 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -106,8 +106,8 @@ int32_t taosMkDir(const char *dirname) { int32_t taosMulMkDir(const char *dirname) { if (dirname == NULL) return -1; - char temp[1024]; - char * pos = temp; + char temp[1024]; + char *pos = temp; int32_t code = 0; #ifdef WINDOWS taosRealPath(dirname, temp, sizeof(temp)); @@ -127,11 +127,11 @@ int32_t taosMulMkDir(const char *dirname) { for (; *pos != '\0'; pos++) { if (*pos == TD_DIRSEP[0]) { *pos = '\0'; - #ifdef WINDOWS +#ifdef WINDOWS code = _mkdir(temp, 0755); - #else +#else code = mkdir(temp, 0755); - #endif +#endif if (code < 0 && errno != EEXIST) { return code; } @@ -140,11 +140,11 @@ int32_t taosMulMkDir(const char *dirname) { } if (*(pos - 1) != TD_DIRSEP[0]) { - #ifdef WINDOWS +#ifdef WINDOWS code = _mkdir(temp, 0755); - #else +#else code = mkdir(temp, 0755); - #endif +#endif if (code < 0 && errno != EEXIST) { return code; } @@ -267,7 +267,7 @@ char *taosDirName(char *name) { } else { name[0] = 0; } - return name; + return name; #else return dirname(name); #endif @@ -334,9 +334,9 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) { } char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) { - if (pDirEntry == NULL) { - return NULL; - } + /*if (pDirEntry == NULL) {*/ + /*return NULL;*/ + /*}*/ #ifdef WINDOWS return pDirEntry->findFileData.cFileName; #else diff --git a/source/os/src/osSemaphore.c b/source/os/src/osSemaphore.c index 7ee73d8e2f..3275774cce 100644 --- a/source/os/src/osSemaphore.c +++ b/source/os/src/osSemaphore.c @@ -210,7 +210,7 @@ int32_t tsem_timewait(tsem_t* sem, int64_t nanosecs) { // id = 0; // } // char name[NAME_MAX - 4]; -// snprintf(name, sizeof(name), "/t%ld", id); +// snprintf(name, sizeof(name), "/t" PRId64, id); // p->sem = sem_open(name, O_CREAT | O_EXCL, pshared, value); // p->id = id; // if (p->sem != SEM_FAILED) break; @@ -366,7 +366,7 @@ int32_t tsem_timewait(tsem_t* sem, int64_t nanosecs) { // } // #elif defined(SEM_USE_POSIX) // char name[NAME_MAX - 4]; -// snprintf(name, sizeof(name), "/t%ld", p->id); +// snprintf(name, sizeof(name), "/t" PRId64, p->id); // int r = sem_unlink(name); // if (r) { // int e = errno; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 0301b842c4..ef6697b3b5 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -251,6 +251,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_ALREADY_EXIST, "Column already exists TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_NOT_EXIST, "Column does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC,"Field used by topic") TAOS_DEFINE_ERROR(TSDB_CODE_MND_SINGLE_STB_MODE_DB, "Database is single stable mode") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SCHEMA_VER, "Invalid schema version while alter stb") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_STABLE_UID_NOT_MATCH, "Invalid stable uid while alter stb") // mnode-infoSchema TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SYS_TABLENAME, "Invalid system table name") diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 45a2ffec77..cc823decf4 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -202,9 +202,8 @@ int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal return TSDB_CODE_FAILED; } #ifdef WINDOWS - sscanf(p, "%lld", pVal); + sscanf(p, "%" PRId64, pVal); #else - // sscanf(p,"%ld",pVal); *pVal = taosStr2Int64(p, NULL, 10); #endif return TSDB_CODE_SUCCESS; @@ -237,9 +236,8 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV return TSDB_CODE_FAILED; } #ifdef WINDOWS - sscanf(p, "%llu", pVal); + sscanf(p, "%" PRIu64, pVal); #else - // sscanf(p,"%ld",pVal); *pVal = taosStr2UInt64(p, NULL, 10); #endif return TSDB_CODE_SUCCESS; diff --git a/source/util/src/tlockfree.c b/source/util/src/tlockfree.c index a755a67cc8..3cab16ee83 100644 --- a/source/util/src/tlockfree.c +++ b/source/util/src/tlockfree.c @@ -17,8 +17,10 @@ #include "tlockfree.h" #define TD_RWLATCH_WRITE_FLAG 0x40000000 +#define TD_RWLATCH_REENTRANT_FLAG 0x4000000000000000 void taosInitRWLatch(SRWLatch *pLatch) { *pLatch = 0; } +void taosInitReentrantRWLatch(SRWLatch *pLatch) { *pLatch = TD_RWLATCH_REENTRANT_FLAG; } void taosWLockLatch(SRWLatch *pLatch) { SRWLatch oLatch, nLatch; @@ -26,8 +28,14 @@ void taosWLockLatch(SRWLatch *pLatch) { // Set write flag while (1) { - oLatch = atomic_load_32(pLatch); + oLatch = atomic_load_64(pLatch); if (oLatch & TD_RWLATCH_WRITE_FLAG) { + if (oLatch & TD_RWLATCH_REENTRANT_FLAG) { + nLatch = (((oLatch >> 32) + 1) << 32) | (oLatch & 0xFFFFFFFF); + if (atomic_val_compare_exchange_64(pLatch, oLatch, nLatch) == oLatch) break; + + continue; + } nLoops++; if (nLoops > 1000) { sched_yield(); @@ -37,14 +45,14 @@ void taosWLockLatch(SRWLatch *pLatch) { } nLatch = oLatch | TD_RWLATCH_WRITE_FLAG; - if (atomic_val_compare_exchange_32(pLatch, oLatch, nLatch) == oLatch) break; + if (atomic_val_compare_exchange_64(pLatch, oLatch, nLatch) == oLatch) break; } // wait for all reads end nLoops = 0; while (1) { - oLatch = atomic_load_32(pLatch); - if (oLatch == TD_RWLATCH_WRITE_FLAG) break; + oLatch = atomic_load_64(pLatch); + if (0 == (oLatch & 0xFFFFFFF)) break; nLoops++; if (nLoops > 1000) { sched_yield(); @@ -53,29 +61,50 @@ void taosWLockLatch(SRWLatch *pLatch) { } } +// no reentrant int32_t taosWTryLockLatch(SRWLatch *pLatch) { SRWLatch oLatch, nLatch; - oLatch = atomic_load_32(pLatch); - if (oLatch) { + oLatch = atomic_load_64(pLatch); + if (oLatch << 2) { return -1; } nLatch = oLatch | TD_RWLATCH_WRITE_FLAG; - if (atomic_val_compare_exchange_32(pLatch, oLatch, nLatch) == oLatch) { + if (atomic_val_compare_exchange_64(pLatch, oLatch, nLatch) == oLatch) { return 0; } return -1; } -void taosWUnLockLatch(SRWLatch *pLatch) { atomic_store_32(pLatch, 0); } +void taosWUnLockLatch(SRWLatch *pLatch) { + SRWLatch oLatch, nLatch, wLatch; + + while (1) { + oLatch = atomic_load_64(pLatch); + + if (0 == (oLatch & TD_RWLATCH_REENTRANT_FLAG)) { + atomic_store_64(pLatch, 0); + break; + } + + wLatch = ((oLatch << 2) >> 34); + if (wLatch) { + nLatch = ((--wLatch) << 32) | TD_RWLATCH_REENTRANT_FLAG | TD_RWLATCH_WRITE_FLAG; + } else { + nLatch = TD_RWLATCH_REENTRANT_FLAG; + } + + if (atomic_val_compare_exchange_64(pLatch, oLatch, nLatch) == oLatch) break; + } +} void taosRLockLatch(SRWLatch *pLatch) { SRWLatch oLatch, nLatch; int32_t nLoops = 0; while (1) { - oLatch = atomic_load_32(pLatch); + oLatch = atomic_load_64(pLatch); if (oLatch & TD_RWLATCH_WRITE_FLAG) { nLoops++; if (nLoops > 1000) { @@ -86,8 +115,8 @@ void taosRLockLatch(SRWLatch *pLatch) { } nLatch = oLatch + 1; - if (atomic_val_compare_exchange_32(pLatch, oLatch, nLatch) == oLatch) break; + if (atomic_val_compare_exchange_64(pLatch, oLatch, nLatch) == oLatch) break; } } -void taosRUnLockLatch(SRWLatch *pLatch) { atomic_fetch_sub_32(pLatch, 1); } \ No newline at end of file +void taosRUnLockLatch(SRWLatch *pLatch) { atomic_fetch_sub_64(pLatch, 1); } diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 9d7656de35..490c6f29bf 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -745,14 +745,14 @@ cmp_end: void taosSetAllDebugFlag(int32_t flag) { if (flag <= 0) return; + uDebugFlag = flag; + rpcDebugFlag = flag; + jniDebugFlag = flag; + qDebugFlag = flag; + cDebugFlag = flag; dDebugFlag = flag; vDebugFlag = flag; mDebugFlag = flag; - cDebugFlag = flag; - jniDebugFlag = flag; - uDebugFlag = flag; - rpcDebugFlag = flag; - qDebugFlag = flag; wDebugFlag = flag; sDebugFlag = flag; tsdbDebugFlag = flag; @@ -761,6 +761,5 @@ void taosSetAllDebugFlag(int32_t flag) { udfDebugFlag = flag; smaDebugFlag = flag; idxDebugFlag = flag; - uInfo("all debug flag are set to %d", flag); } diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 68f96c0385..88bd36f0cb 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -39,7 +39,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) { worker->pool = pool; } - uDebug("worker:%s is initialized, min:%d max:%d", pool->name, pool->min, pool->max); + uInfo("worker:%s is initialized, min:%d max:%d", pool->name, pool->min, pool->max); return 0; } diff --git a/tests/pytest/util/cluster.py b/tests/pytest/util/cluster.py index efa83323a4..e892e1cc02 100644 --- a/tests/pytest/util/cluster.py +++ b/tests/pytest/util/cluster.py @@ -58,9 +58,10 @@ class ConfigureyCluster: self.dnodes.append(dnode) return self.dnodes - def create_dnode(self,conn): + def create_dnode(self,conn,dnodeNum): tdSql.init(conn.cursor()) - for dnode in self.dnodes[1:]: + dnodeNum=int(dnodeNum) + for dnode in self.dnodes[1:dnodeNum]: # print(dnode.cfgDict) dnode_id = dnode.cfgDict["fqdn"] + ":" +dnode.cfgDict["serverPort"] tdSql.execute(" create dnode '%s';"%dnode_id) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 4e009e702d..6826258151 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -52,6 +52,7 @@ ./test.sh -f tsim/insert/null.sim ./test.sh -f tsim/insert/update0.sim ./test.sh -f tsim/insert/commit-merge0.sim +./test.sh -f tsim/insert/insert_select.sim # ---- parser ./test.sh -f tsim/parser/groupby-basic.sim @@ -80,7 +81,7 @@ ./test.sh -f tsim/mnode/basic1.sim ./test.sh -f tsim/mnode/basic2.sim ./test.sh -f tsim/mnode/basic3.sim -./test.sh -f tsim/mnode/basic4.sim +#./test.sh -f tsim/mnode/basic4.sim ./test.sh -f tsim/mnode/basic5.sim # ---- show @@ -97,7 +98,7 @@ ./test.sh -f tsim/stream/distributeInterval0.sim # ./test.sh -f tsim/stream/distributeIntervalRetrive0.sim # ./test.sh -f tsim/stream/distributesession0.sim -# ./test.sh -f tsim/stream/session0.sim +./test.sh -f tsim/stream/session0.sim ./test.sh -f tsim/stream/session1.sim # ./test.sh -f tsim/stream/state0.sim ./test.sh -f tsim/stream/triggerInterval0.sim @@ -163,8 +164,8 @@ # --- sma ./test.sh -f tsim/sma/drop_sma.sim ./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim -#./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim -#./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim +./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim +./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim # --- valgrind ./test.sh -f tsim/valgrind/checkError1.sim @@ -193,4 +194,7 @@ # --- catalog ./test.sh -f tsim/catalog/alterInCurrent.sim +# --- scalar +./test.sh -f tsim/scalar/in.sim + #======================b1-end=============== diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 4d93878a98..de7b8ecfbf 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -122,28 +122,29 @@ echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG echo "fqdn ${HOSTNAME}" >> $TAOS_CFG echo "serverPort ${NODE}" >> $TAOS_CFG echo "supportVnodes 1024" >> $TAOS_CFG +echo "statusInterval 1" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG echo "debugFlag 0" >> $TAOS_CFG -echo "mDebugFlag 143" >> $TAOS_CFG -echo "dDebugFlag 143" >> $TAOS_CFG -echo "vDebugFlag 143" >> $TAOS_CFG -echo "tqDebugFlag 143" >> $TAOS_CFG -echo "tsdbDebugFlag 143" >> $TAOS_CFG -echo "cDebugFlag 143" >> $TAOS_CFG -echo "jniDebugFlag 143" >> $TAOS_CFG -echo "qDebugFlag 143" >> $TAOS_CFG -echo "rpcDebugFlag 143" >> $TAOS_CFG -echo "sDebugFlag 143" >> $TAOS_CFG -echo "wDebugFlag 143" >> $TAOS_CFG -echo "idxDebugFlag 143" >> $TAOS_CFG -echo "fsDebugFlag 143" >> $TAOS_CFG -echo "udfDebugFlag 143" >> $TAOS_CFG -echo "smaDebugFlag 143" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG echo "uDebugFlag 131" >> $TAOS_CFG +echo "rpcDebugFlag 131" >> $TAOS_CFG +echo "jniDebugFlag 143" >> $TAOS_CFG +echo "qDebugFlag 143" >> $TAOS_CFG +echo "cDebugFlag 143" >> $TAOS_CFG +echo "dDebugFlag 143" >> $TAOS_CFG +echo "vDebugFlag 143" >> $TAOS_CFG +echo "mDebugFlag 143" >> $TAOS_CFG +echo "wDebugFlag 143" >> $TAOS_CFG +echo "sDebugFlag 143" >> $TAOS_CFG +echo "tsdbDebugFlag 143" >> $TAOS_CFG +echo "tqDebugFlag 143" >> $TAOS_CFG +echo "fsDebugFlag 143" >> $TAOS_CFG +echo "idxDebugFlag 143" >> $TAOS_CFG +echo "udfDebugFlag 143" >> $TAOS_CFG +echo "smaDebugFlag 143" >> $TAOS_CFG +echo "idxDebugFlag 143" >> $TAOS_CFG echo "numOfLogLines 20000000" >> $TAOS_CFG -echo "statusInterval 1" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG echo "telemetryReporting 0" >> $TAOS_CFG diff --git a/tests/script/general/insert/insert_select.sim b/tests/script/tsim/insert/insert_select.sim similarity index 100% rename from tests/script/general/insert/insert_select.sim rename to tests/script/tsim/insert/insert_select.sim diff --git a/tests/script/tsim/scalar/in.sim b/tests/script/tsim/scalar/in.sim new file mode 100644 index 0000000000..60c12a00c2 --- /dev/null +++ b/tests/script/tsim/scalar/in.sim @@ -0,0 +1,83 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print ======== step1 +sql drop database if exists db1; +sql create database db1 vgroups 3; +sql use db1; +sql create stable st1 (fts timestamp, fbool bool, ftiny tinyint, fsmall smallint, fint int, fbig bigint, futiny tinyint unsigned, fusmall smallint unsigned, fuint int unsigned, fubig bigint unsigned, ffloat float, fdouble double, fbin binary(10), fnchar nchar(10)) tags(tts timestamp, tbool bool, ttiny tinyint, tsmall smallint, tint int, tbig bigint, tutiny tinyint unsigned, tusmall smallint unsigned, tuint int unsigned, tubig bigint unsigned, tfloat float, tdouble double, tbin binary(10), tnchar nchar(10)); +sql create table tb1 using st1 tags('2022-07-10 16:31:00', true, 1, 1, 1, 1, 1, 1, 1, 1, 1.0, 1.0, 'a', 'a'); +sql create table tb2 using st1 tags('2022-07-10 16:32:00', false, 2, 2, 2, 2, 2, 2, 2, 2, 2.0, 2.0, 'b', 'b'); +sql create table tb3 using st1 tags('2022-07-10 16:33:00', true, 3, 3, 3, 3, 3, 3, 3, 3, 3.0, 3.0, 'c', 'c'); + +sql insert into tb1 values ('2022-07-10 16:31:01', false, 1, 1, 1, 1, 1, 1, 1, 1, 1.0, 1.0, 'a', 'a'); +sql insert into tb1 values ('2022-07-10 16:31:02', true, 2, 2, 2, 2, 2, 2, 2, 2, 2.0, 2.0, 'b', 'b'); +sql insert into tb1 values ('2022-07-10 16:31:03', false, 3, 3, 3, 3, 3, 3, 3, 3, 3.0, 3.0, 'c', 'c'); +sql insert into tb1 values ('2022-07-10 16:31:04', true, 4, 4, 4, 4, 4, 4, 4, 4, 4.0, 4.0, 'd', 'd'); +sql insert into tb1 values ('2022-07-10 16:31:05', false, 5, 5, 5, 5, 5, 5, 5, 5, 5.0, 5.0, 'e', 'e'); + +sql insert into tb2 values ('2022-07-10 16:32:01', false, 1, 1, 1, 1, 1, 1, 1, 1, 1.0, 1.0, 'a', 'a'); +sql insert into tb2 values ('2022-07-10 16:32:02', true, 2, 2, 2, 2, 2, 2, 2, 2, 2.0, 2.0, 'b', 'b'); +sql insert into tb2 values ('2022-07-10 16:32:03', false, 3, 3, 3, 3, 3, 3, 3, 3, 3.0, 3.0, 'c', 'c'); +sql insert into tb2 values ('2022-07-10 16:32:04', true, 4, 4, 4, 4, 4, 4, 4, 4, 4.0, 4.0, 'd', 'd'); +sql insert into tb2 values ('2022-07-10 16:32:05', false, 5, 5, 5, 5, 5, 5, 5, 5, 5.0, 5.0, 'e', 'e'); + +sql insert into tb3 values ('2022-07-10 16:33:01', false, 1, 1, 1, 1, 1, 1, 1, 1, 1.0, 1.0, 'a', 'a'); +sql insert into tb3 values ('2022-07-10 16:33:02', true, 2, 2, 2, 2, 2, 2, 2, 2, 2.0, 2.0, 'b', 'b'); +sql insert into tb3 values ('2022-07-10 16:33:03', false, 3, 3, 3, 3, 3, 3, 3, 3, 3.0, 3.0, 'c', 'c'); +sql insert into tb3 values ('2022-07-10 16:33:04', true, 4, 4, 4, 4, 4, 4, 4, 4, 4.0, 4.0, 'd', 'd'); +sql insert into tb3 values ('2022-07-10 16:33:05', false, 5, 5, 5, 5, 5, 5, 5, 5, 5.0, 5.0, 'e', 'e'); + +sql select * from tb1 where fts in ('2022-07-10 16:31:01', '2022-07-10 16:31:03', 1657441865000); +if $rows != 3 then + return -1 +endi + +sql select * from tb1 where fbool in (0, 3); +if $rows != 5 then + return -1 +endi + +sql select * from tb1 where ftiny in (257); +if $rows != 0 then + return -1 +endi + +sql select * from tb1 where ftiny in (2, 257); +if $rows != 1 then + return -1 +endi + +sql select * from tb1 where futiny in (0, 257); +if $rows != 0 then + return -1 +endi + +sql select * from st1 where tts in ('2022-07-10 16:31:00', '2022-07-10 16:33:00', 1657441865000); +if $rows != 10 then + return -1 +endi + +sql select * from st1 where tbool in (0, 3); +if $rows != 15 then + return -1 +endi + +sql select * from st1 where ttiny in (257); +if $rows != 0 then + return -1 +endi + +sql select * from st1 where ttiny in (2, 257); +if $rows != 5 then + return -1 +endi + +sql select * from st1 where tutiny in (0, 257); +if $rows != 0 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/show/basic.sim b/tests/script/tsim/show/basic.sim index 4d646f39e3..d0643bc7f2 100644 --- a/tests/script/tsim/show/basic.sim +++ b/tests/script/tsim/show/basic.sim @@ -99,7 +99,7 @@ if $rows != 1 then endi #sql select * from information_schema.`streams` sql select * from information_schema.user_tables -if $rows != 31 then +if $rows != 30 then return -1 endi #sql select * from information_schema.user_table_distributed @@ -197,7 +197,7 @@ if $rows != 1 then endi #sql select * from performance_schema.`streams` sql select * from information_schema.user_tables -if $rows != 31 then +if $rows != 30 then return -1 endi #sql select * from information_schema.user_table_distributed diff --git a/tests/script/tsim/sync/vnodesnapshot-restart.sim b/tests/script/tsim/sync/vnodesnapshot-restart.sim index 3ed82fdfe7..b44191071d 100644 --- a/tests/script/tsim/sync/vnodesnapshot-restart.sim +++ b/tests/script/tsim/sync/vnodesnapshot-restart.sim @@ -1,6 +1,6 @@ system sh/stop_dnodes.sh -system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +#system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode2 -s start diff --git a/tests/script/tsim/sync/vnodesnapshot-test.sim b/tests/script/tsim/sync/vnodesnapshot-test.sim new file mode 100644 index 0000000000..e4ef6739dd --- /dev/null +++ b/tests/script/tsim/sync/vnodesnapshot-test.sim @@ -0,0 +1,178 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 + +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 + +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] +print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] +print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] +if $data[0][0] != 1 then + return -1 +endi +if $data[0][4] != ready then + goto check_dnode_ready +endi + +sql connect +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 +sql create dnode $hostname port 7400 + +$loop_cnt = 0 +check_dnode_ready_1: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 10 then + print ====> dnodes not ready! + return -1 +endi +sql show dnodes +print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] +print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] +print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] +if $data[0][4] != ready then + goto check_dnode_ready_1 +endi +if $data[1][4] != ready then + goto check_dnode_ready_1 +endi +if $data[2][4] != ready then + goto check_dnode_ready_1 +endi +if $data[3][4] != ready then + goto check_dnode_ready_1 +endi + +$replica = 3 +$vgroups = 1 + +print ============= create database +sql create database db replica $replica vgroups $vgroups + +$loop_cnt = 0 +check_db_ready: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 100 then + print ====> db not ready! + return -1 +endi +sql show databases +print ===> rows: $rows +print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][6] $data[2][11] $data[2][12] $data[2][13] $data[2][14] $data[2][15] $data[2][16] $data[2][17] $data[2][18] $data[2][19] +if $rows != 3 then + return -1 +endi +if $data[2][19] != ready then + goto check_db_ready +endi + +sql use db + +$loop_cnt = 0 +check_vg_ready: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 300 then + print ====> vgroups not ready! + return -1 +endi + +sql show vgroups +print ===> rows: $rows +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11] + +if $rows != $vgroups then + return -1 +endi + +if $data[0][4] == leader then + if $data[0][6] == follower then + if $data[0][8] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][3] + endi + endi +elif $data[0][6] == leader then + if $data[0][4] == follower then + if $data[0][8] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][5] + endi + endi +elif $data[0][8] == leader then + if $data[0][4] == follower then + if $data[0][6] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][7] + endi + endi +else + goto check_vg_ready +endi + + +vg_ready: +print ====> create stable/child table +sql create table stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb tags(1000) + + +print ===> stop dnode4 +system sh/exec.sh -n dnode4 -s stop -x SIGINT +sleep 3000 + + +print ===> write 100 records +$N = 100 +$count = 0 +while $count < $N + $ms = 1591200000000 + $count + sql insert into ct1 values( $ms , $count , 2.1, 3.1) + $count = $count + 1 +endw + + +#sql flush database db; + + +sleep 3000 + + +print ===> stop dnode1 dnode2 dnode3 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT + + + + +print ===> start dnode1 dnode2 dnode3 dnode4 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + + diff --git a/tests/script/tsim/valgrind/basic1.sim b/tests/script/tsim/valgrind/basic1.sim index 7d8991c095..e9dfc0eb4e 100644 --- a/tests/script/tsim/valgrind/basic1.sim +++ b/tests/script/tsim/valgrind/basic1.sim @@ -10,16 +10,19 @@ step1: $x = $x + 1 sleep 1000 if $x == 10 then - print ----> dnode not ready! + print ---> dnode not ready! return -1 endi sql show dnodes -print ----> $data00 $data01 $data02 $data03 $data04 $data05 +print ---> $data00 $data01 $data02 $data03 $data04 $data05 if $rows != 1 then return -1 endi +if $data(1)[4] != ready then + goto step1 +endi -print =============== step2: create show database +print =============== step2: create db sql create database d1 vgroups 1 buffer 3 sql show databases sql use d1 @@ -32,7 +35,7 @@ if $rows != 1 then return -1 endi -print =============== step4: create show table +print =============== step3: create show table sql create table ct1 using stb tags(1000) sql show tables if $rows != 1 then @@ -40,8 +43,28 @@ if $rows != 1 then endi print =============== step5: insert data +sql insert into ct1 values(now+0s, 10, 2.0, 3.0) +sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) print =============== step6: select data +sql select * from ct1 +#sql select * from stb _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT + +print =============== check +print ----> start to check if there are ERRORS in vagrind log file for each dnode +system_content sh/checkValgrind.sh -n dnode1 + +print cmd return result ----> [ $system_content ] +if $system_content <= 0 then + return 0 +endi + +$null= +if $system_content == $null then + return 0 +endi + +return -1 diff --git a/tests/script/tsim/valgrind/basic2.sim b/tests/script/tsim/valgrind/basic2.sim index 1a76d8ce5c..154617bc18 100644 --- a/tests/script/tsim/valgrind/basic2.sim +++ b/tests/script/tsim/valgrind/basic2.sim @@ -4,7 +4,7 @@ system sh/cfg.sh -n dnode1 -c debugflag -v 131 system sh/exec.sh -n dnode1 -s start -v sql connect -print =============== step1: show dnodes +print =============== step1: create drop show dnodes $x = 0 step1: $x = $x + 1 @@ -22,75 +22,35 @@ if $data(1)[4] != ready then goto step1 endi -print =============== step2: create alter drop show user -sql create user u1 pass 'taosdata' -sql show users -sql alter user u1 sysinfo 1 -sql alter user u1 enable 1 -sql alter user u1 pass 'taosdata' -sql drop user u1 -sql_error alter user u2 sysinfo 0 - -print =============== step3: create drop dnode -sql create dnode $hostname port 7200 -sql drop dnode 2 -sql alter dnode 1 'debugflag 131' - -print =============== step4: - -print =============== run show xxxx -sql show dnodes -if $rows != 1 then - return -1 -endi - -sql show mnodes -if $rows != 1 then - return -1 -endi - +print =============== step2: create db +sql create database d1 vgroups 1 buffer 3 sql show databases -if $rows != 2 then - return -1 -endi +sql use d1 +sql show vgroups -sql show users +print =============== step3: create show stable +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned) +sql show stables if $rows != 1 then return -1 endi -print =============== run select * from information_schema.xxxx -sql select * from information_schema.`dnodes` -if $rows != 1 then - return -1 -endi +print =============== step3: create show table +sql create table ct1 using stb tags(1000) +#sql show tables +#if $rows != 1 then +# return -1 +#endi -sql select * from information_schema.`mnodes` -if $rows != 1 then - return -1 -endi +print =============== step5: insert data +sql insert into ct1 values(now+0s, 10, 2.0, 3.0) +sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) -sql select * from information_schema.user_users -if $rows != 1 then - return -1 -endi +print =============== step6: select data +sql select * from ct1 +sql select * from stb -sql show variables; -if $rows != 4 then - return -1 -endi - -sql show dnode 1 variables; -if $rows <= 0 then - return -1 -endi - -sql show local variables; -if $rows <= 0 then - return -1 -endi - -print =============== stop +_OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT print =============== check diff --git a/tests/script/tsim/valgrind/basic3.sim b/tests/script/tsim/valgrind/basic3.sim new file mode 100644 index 0000000000..7fba66c468 --- /dev/null +++ b/tests/script/tsim/valgrind/basic3.sim @@ -0,0 +1,152 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/exec.sh -n dnode1 -s start -v +system sh/exec.sh -n dnode2 -s start -v +sql connect + +print =============== add dnode2 into cluster +sql create dnode $hostname port 7200 + +$x = 0 +step1: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ---> dnode not ready! + return -1 + endi +sql show dnodes +print ---> $data00 $data01 $data02 $data03 $data04 $data05 +print ---> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi + +print =============== create database, stable, table +sql create database db vgroups 3 +sql use db +sql create table stb (ts timestamp, c int) tags (t int) +sql create table t0 using stb tags (0) +sql create table tba (ts timestamp, c1 binary(10), c2 nchar(10)); + +print =============== run show xxxx +sql show dnodes +if $rows != 2 then + return -1 +endi + +sql show mnodes +if $rows != 1 then + return -1 +endi + +sql show databases +if $rows != 3 then + return -1 +endi + +sql show stables +if $rows != 1 then + return -1 +endi + +sql show tables +if $rows != 2 then + return -1 +endi + +sql show users +if $rows != 1 then + return -1 +endi + +sql show vgroups +if $rows != 3 then + return -1 +endi + +print =============== run select * from information_schema.xxxx +sql select * from information_schema.`dnodes` +if $rows != 2 then + return -1 +endi + +sql select * from information_schema.`mnodes` +if $rows != 1 then + return -1 +endi + +sql select * from information_schema.user_databases +if $rows != 3 then + return -1 +endi + +sql select * from information_schema.user_stables +if $rows != 1 then + return -1 +endi + +sql select * from information_schema.user_tables +if $rows != 31 then + return -1 +endi + +sql select * from information_schema.user_users +if $rows != 1 then + return -1 +endi + +sql select * from information_schema.`vgroups` +if $rows != 3 then + return -1 +endi + +sql show variables; +if $rows != 4 then + return -1 +endi + +sql show dnode 1 variables; +if $rows <= 0 then + return -1 +endi + +sql show local variables; +if $rows <= 0 then + return -1 +endi + +print ==== stop dnode1 and dnode2, and restart dnodes +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT + +print =============== check dnode1 +system_content sh/checkValgrind.sh -n dnode1 +print cmd return result ----> [ $system_content ] +if $system_content <= 0 then + return 0 +endi + +$null= +if $system_content == $null then + return 0 +endi + +print =============== check dnode2 +system_content sh/checkValgrind.sh -n dnode2 +print cmd return result ----> [ $system_content ] +if $system_content <= 0 then + return 0 +endi + +$null= +if $system_content == $null then + return 0 +endi diff --git a/tests/script/tsim/valgrind/checkError1.sim b/tests/script/tsim/valgrind/checkError1.sim index 62653bbdd3..1a76d8ce5c 100644 --- a/tests/script/tsim/valgrind/checkError1.sim +++ b/tests/script/tsim/valgrind/checkError1.sim @@ -36,6 +36,60 @@ sql create dnode $hostname port 7200 sql drop dnode 2 sql alter dnode 1 'debugflag 131' +print =============== step4: + +print =============== run show xxxx +sql show dnodes +if $rows != 1 then + return -1 +endi + +sql show mnodes +if $rows != 1 then + return -1 +endi + +sql show databases +if $rows != 2 then + return -1 +endi + +sql show users +if $rows != 1 then + return -1 +endi + +print =============== run select * from information_schema.xxxx +sql select * from information_schema.`dnodes` +if $rows != 1 then + return -1 +endi + +sql select * from information_schema.`mnodes` +if $rows != 1 then + return -1 +endi + +sql select * from information_schema.user_users +if $rows != 1 then + return -1 +endi + +sql show variables; +if $rows != 4 then + return -1 +endi + +sql show dnode 1 variables; +if $rows <= 0 then + return -1 +endi + +sql show local variables; +if $rows <= 0 then + return -1 +endi + print =============== stop system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/valgrind/checkError2.sim b/tests/script/tsim/valgrind/checkError2.sim index f98cd0df1d..e2ac9577e0 100644 --- a/tests/script/tsim/valgrind/checkError2.sim +++ b/tests/script/tsim/valgrind/checkError2.sim @@ -37,17 +37,17 @@ endi print =============== step3: create show table sql create table ct1 using stb tags(1000) -#sql show tables -#if $rows != 1 then -# return -1 -#endi +sql show tables +if $rows != 1 then + return -1 +endi print =============== step5: insert data sql insert into ct1 values(now+0s, 10, 2.0, 3.0) sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) print =============== step6: select data -#sql select * from ct1 +sql select * from ct1 #sql select * from stb _OVER: @@ -58,7 +58,7 @@ print ----> start to check if there are ERRORS in vagrind log file for each dnod system_content sh/checkValgrind.sh -n dnode1 print cmd return result ----> [ $system_content ] -if $system_content <= 0 then +if $system_content <= 2 then return 0 endi diff --git a/tests/script/tsim/valgrind/checkError3.sim b/tests/script/tsim/valgrind/checkError3.sim index 6bf82b4ef4..3713f372ae 100644 --- a/tests/script/tsim/valgrind/checkError3.sim +++ b/tests/script/tsim/valgrind/checkError3.sim @@ -1,13 +1,10 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/deploy.sh -n dnode2 -i 2 +system sh/cfg.sh -n dnode1 -c debugflag -v 131 system sh/exec.sh -n dnode1 -s start -v -system sh/exec.sh -n dnode2 -s start -v sql connect -print =============== add dnode2 into cluster -sql create dnode $hostname port 7200 - +print =============== step1: show dnodes $x = 0 step1: $x = $x + 1 @@ -18,16 +15,26 @@ step1: endi sql show dnodes print ---> $data00 $data01 $data02 $data03 $data04 $data05 -print ---> $data10 $data11 $data12 $data13 $data14 $data15 -if $rows != 2 then +if $rows != 1 then return -1 endi if $data(1)[4] != ready then goto step1 endi -if $data(2)[4] != ready then - goto step1 -endi + +print =============== step2: create alter drop show user +sql create user u1 pass 'taosdata' +sql show users +sql alter user u1 sysinfo 1 +sql alter user u1 enable 1 +sql alter user u1 pass 'taosdata' +sql drop user u1 +sql_error alter user u2 sysinfo 0 + +print =============== step3: create drop dnode +sql create dnode $hostname port 7200 +sql drop dnode 2 +sql alter dnode 1 'debugflag 131' print =============== create database, stable, table sql create database db vgroups 3 @@ -38,7 +45,7 @@ sql create table tba (ts timestamp, c1 binary(10), c2 nchar(10)); print =============== run show xxxx sql show dnodes -if $rows != 2 then +if $rows != 1 then return -1 endi @@ -67,14 +74,9 @@ if $rows != 1 then return -1 endi -sql show vgroups -if $rows != 3 then - return -1 -endi - print =============== run select * from information_schema.xxxx sql select * from information_schema.`dnodes` -if $rows != 2 then +if $rows != 1 then return -1 endi @@ -94,7 +96,7 @@ if $rows != 1 then endi sql select * from information_schema.user_tables -if $rows != 31 then +if $rows != 30 then return -1 endi @@ -123,12 +125,13 @@ if $rows <= 0 then return -1 endi -print ==== stop dnode1 and dnode2, and restart dnodes +print =============== stop system sh/exec.sh -n dnode1 -s stop -x SIGINT -system sh/exec.sh -n dnode2 -s stop -x SIGINT -print =============== check dnode1 +print =============== check +print ----> start to check if there are ERRORS in vagrind log file for each dnode system_content sh/checkValgrind.sh -n dnode1 + print cmd return result ----> [ $system_content ] if $system_content <= 0 then return 0 @@ -140,17 +143,3 @@ if $system_content == $null then endi return -1 - -print =============== check dnode2 -system_content sh/checkValgrind.sh -n dnode2 -print cmd return result ----> [ $system_content ] -if $system_content <= 0 then - return 0 -endi - -$null= -if $system_content == $null then - return 0 -endi - -return -1 \ No newline at end of file diff --git a/tests/system-test/0-others/taosShellError.py b/tests/system-test/0-others/taosShellError.py index 825ac015fb..5735e55c03 100644 --- a/tests/system-test/0-others/taosShellError.py +++ b/tests/system-test/0-others/taosShellError.py @@ -162,28 +162,28 @@ class TDTestCase: keyDict['h'] = 'abc' retCode, retVal = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): - tdLog.info("taos -h %s test suceess"%keyDict['h']) + tdLog.info("taos -h %s test success"%keyDict['h']) else: tdLog.exit("taos -h %s fail"%keyDict['h']) keyDict['h'] = '\'abc\'' retCode, retVal = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): - tdLog.info("taos -h %s test suceess"%keyDict['h']) + tdLog.info("taos -h %s test success"%keyDict['h']) else: tdLog.exit("taos -h %s fail"%keyDict['h']) keyDict['h'] = '3' retCode, retVal = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): - tdLog.info("taos -h %s test suceess"%keyDict['h']) + tdLog.info("taos -h %s test success"%keyDict['h']) else: tdLog.exit("taos -h %s fail"%keyDict['h']) keyDict['h'] = '\'3\'' retCode, retVal = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): - tdLog.info("taos -h %s test suceess"%keyDict['h']) + tdLog.info("taos -h %s test success"%keyDict['h']) else: tdLog.exit("taos -h %s fail"%keyDict['h']) @@ -193,42 +193,42 @@ class TDTestCase: keyDict['P'] = 'abc' retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Invalid port" in retVal): - tdLog.info("taos -P %s test suceess"%keyDict['P']) + tdLog.info("taos -P %s test success"%keyDict['P']) else: tdLog.exit("taos -P %s fail"%keyDict['P']) keyDict['P'] = '\'abc\'' retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Invalid port" in retVal): - tdLog.info("taos -P %s test suceess"%keyDict['P']) + tdLog.info("taos -P %s test success"%keyDict['P']) else: tdLog.exit("taos -P %s fail"%keyDict['P']) keyDict['P'] = '3' retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): - tdLog.info("taos -P %s test suceess"%keyDict['P']) + tdLog.info("taos -P %s test success"%keyDict['P']) else: tdLog.exit("taos -P %s fail"%keyDict['P']) keyDict['P'] = '\'3\'' retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): - tdLog.info("taos -P %s test suceess"%keyDict['P']) + tdLog.info("taos -P %s test success"%keyDict['P']) else: tdLog.exit("taos -P %s fail"%keyDict['P']) keyDict['P'] = '12ab' retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): - tdLog.info("taos -P %s test suceess"%keyDict['P']) + tdLog.info("taos -P %s test success"%keyDict['P']) else: tdLog.exit("taos -P %s fail"%keyDict['P']) keyDict['P'] = '\'12ab\'' retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): - tdLog.info("taos -P %s test suceess"%keyDict['P']) + tdLog.info("taos -P %s test success"%keyDict['P']) else: tdLog.exit("taos -P %s fail"%keyDict['P']) @@ -293,7 +293,7 @@ class TDTestCase: keyDict['p'] = 'errorPassword' retCode, retVal = taos_command(buildPath, "u", keyDict['u'], "taos>", keyDict['c'], sqlString, 'p', keyDict['p']) if retCode == "TAOS_FAIL" and "Authentication failure" in retVal: - tdLog.info("taos -p %s test suceess"%keyDict['p']) + tdLog.info("taos -p %s test success"%keyDict['p']) else: tdLog.exit("taos -u %s -p %s"%(keyDict['u'], keyDict['p'])) diff --git a/tests/system-test/1-insert/test_stmt_insert_query_ex.py b/tests/system-test/1-insert/test_stmt_insert_query_ex.py deleted file mode 100644 index 2a64c09ff4..0000000000 --- a/tests/system-test/1-insert/test_stmt_insert_query_ex.py +++ /dev/null @@ -1,262 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import os -import threading as thd -import multiprocessing as mp -from numpy.lib.function_base import insert -import taos -from taos import * -from util.log import * -from util.cases import * -from util.sql import * -import numpy as np -import datetime as dt -from datetime import datetime -from ctypes import * -import time -# constant define -WAITS = 5 # wait seconds - -class TDTestCase: - # - # --------------- main frame ------------------- - def caseDescription(self): - ''' - limit and offset keyword function test cases; - case1: limit offset base function test - case2: offset return valid - ''' - return - - def getBuildPath(self): - selfPath = os.path.dirname(os.path.realpath(__file__)) - - if ("community" in selfPath): - projPath = selfPath[:selfPath.find("community")] - else: - projPath = selfPath[:selfPath.find("tests")] - - for root, dirs, files in os.walk(projPath): - if ("taosd" in files or "taosd.exe" in files): - rootRealPath = os.path.dirname(os.path.realpath(root)) - if ("packaging" not in rootRealPath): - buildPath = root[:len(root)-len("/build/bin")] - break - return buildPath - - # init - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) - # tdSql.prepare() - # self.create_tables(); - self.ts = 1500000000000 - - # stop - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - - # --------------- case ------------------- - - - def newcon(self,host,cfg): - user = "root" - password = "taosdata" - port =6030 - con=taos.connect(host=host, user=user, password=password, config=cfg ,port=port) - print(con) - return con - - def test_stmt_set_tbname_tag(self,conn): - dbname = "stmt_tag" - - try: - conn.execute("drop database if exists %s" % dbname) - conn.execute("create database if not exists %s PRECISION 'us' " % dbname) - conn.select_db(dbname) - conn.execute("create table if not exists log(ts timestamp, bo bool, nil tinyint, ti tinyint, si smallint, ii int,\ - bi bigint, tu tinyint unsigned, su smallint unsigned, iu int unsigned, bu bigint unsigned, \ - ff float, dd double, bb binary(100), nn nchar(100), tt timestamp , vc varchar(100)) tags (t1 timestamp, t2 bool,\ - t3 tinyint, t4 tinyint, t5 smallint, t6 int, t7 bigint, t8 tinyint unsigned, t9 smallint unsigned, \ - t10 int unsigned, t11 bigint unsigned, t12 float, t13 double, t14 binary(100), t15 nchar(100), t16 timestamp)") - - stmt = conn.statement("insert into ? using log tags (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) \ - values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)") - tags = new_bind_params(16) - tags[0].timestamp(1626861392589123, PrecisionEnum.Microseconds) - tags[1].bool(True) - tags[2].bool(False) - tags[3].tinyint(2) - tags[4].smallint(3) - tags[5].int(4) - tags[6].bigint(5) - tags[7].tinyint_unsigned(6) - tags[8].smallint_unsigned(7) - tags[9].int_unsigned(8) - tags[10].bigint_unsigned(9) - tags[11].float(10.1) - tags[12].double(10.11) - tags[13].binary("hello") - tags[14].nchar("stmt") - tags[15].timestamp(1626861392589, PrecisionEnum.Milliseconds) - stmt.set_tbname_tags("tb1", tags) - params = new_multi_binds(17) - params[0].timestamp((1626861392589111, 1626861392590111, 1626861392591111)) - params[1].bool((True, None, False)) - params[2].tinyint([-128, -128, None]) # -128 is tinyint null - params[3].tinyint([0, 127, None]) - params[4].smallint([3, None, 2]) - params[5].int([3, 4, None]) - params[6].bigint([3, 4, None]) - params[7].tinyint_unsigned([3, 4, None]) - params[8].smallint_unsigned([3, 4, None]) - params[9].int_unsigned([3, 4, None]) - params[10].bigint_unsigned([3, 4, 5]) - params[11].float([3, None, 1]) - params[12].double([3, None, 1.2]) - params[13].binary(["abc", "dddafadfadfadfadfa", None]) - params[14].nchar(["涛思数据", None, "a long string with 中文字符"]) - params[15].timestamp([None, None, 1626861392591]) - params[16].binary(["涛思数据16", None, "a long string with 中文-字符"]) - - stmt.bind_param_batch(params) - stmt.execute() - - assert stmt.affected_rows == 3 - - #query all - querystmt1=conn.statement("select * from log where bu < ?") - queryparam1=new_bind_params(1) - print(type(queryparam1)) - queryparam1[0].int(10) - querystmt1.bind_param(queryparam1) - querystmt1.execute() - result1=querystmt1.use_result() - rows1=result1.fetch_all() - print(rows1[0]) - print(rows1[1]) - print(rows1[2]) - assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111" - assert rows1[0][10] == 3 - assert rows1[1][10] == 4 - - #query: Numeric Functions - querystmt2=conn.statement("select abs(?) from log where bu < ?") - queryparam2=new_bind_params(2) - print(type(queryparam2)) - queryparam2[0].int(5) - queryparam2[1].int(5) - querystmt2.bind_param(queryparam2) - querystmt2.execute() - result2=querystmt2.use_result() - rows2=result2.fetch_all() - print("2",rows2) - assert rows2[0][0] == 5 - assert rows2[1][0] == 5 - - - #query: Numeric Functions and escapes - - querystmt3=conn.statement("select abs(?) from log where nn= 'a? long string with 中文字符' ") - queryparam3=new_bind_params(1) - print(type(queryparam3)) - queryparam3[0].int(5) - querystmt3.bind_param(queryparam3) - querystmt3.execute() - result3=querystmt3.use_result() - rows3=result3.fetch_all() - print("3",rows3) - assert rows3 == [] - - #query: string Functions - - querystmt9=conn.statement("select CHAR_LENGTH(?) from log ") - queryparam9=new_bind_params(1) - print(type(queryparam9)) - queryparam9[0].binary('中文字符') - querystmt9.bind_param(queryparam9) - querystmt9.execute() - result9=querystmt9.use_result() - rows9=result9.fetch_all() - print("9",rows9) - assert rows9[0][0] == 12, 'fourth case is failed' - assert rows9[1][0] == 12, 'fourth case is failed' - - #query: conversion Functions - - querystmt4=conn.statement("select cast( ? as bigint) from log ") - queryparam4=new_bind_params(1) - print(type(queryparam4)) - queryparam4[0].binary('1232a') - querystmt4.bind_param(queryparam4) - querystmt4.execute() - result4=querystmt4.use_result() - rows4=result4.fetch_all() - print("5",rows4) - assert rows4[0][0] == 1232 - assert rows4[1][0] == 1232 - - querystmt4=conn.statement("select cast( ? as binary(10)) from log ") - queryparam4=new_bind_params(1) - print(type(queryparam4)) - queryparam4[0].int(123) - querystmt4.bind_param(queryparam4) - querystmt4.execute() - result4=querystmt4.use_result() - rows4=result4.fetch_all() - print("6",rows4) - assert rows4[0][0] == '123' - assert rows4[1][0] == '123' - - # #query: datatime Functions - - # querystmt4=conn.statement(" select timediff('2021-07-21 17:56:32.590111',?,1s) from log ") - # queryparam4=new_bind_params(1) - # print(type(queryparam4)) - # queryparam4[0].timestamp(1626861392591111) - # querystmt4.bind_param(queryparam4) - # querystmt4.execute() - # result4=querystmt4.use_result() - # rows4=result4.fetch_all() - # print("7",rows4) - # assert rows4[0][0] == 1, 'seventh case is failed' - # assert rows4[1][0] == 1, 'seventh case is failed' - - - - # conn.execute("drop database if exists %s" % dbname) - conn.close() - - except Exception as err: - # conn.execute("drop database if exists %s" % dbname) - conn.close() - raise err - - def run(self): - buildPath = self.getBuildPath() - config = buildPath+ "../sim/dnode1/cfg/" - host="localhost" - connectstmt=self.newcon(host,config) - self.test_stmt_set_tbname_tag(connectstmt) - - return - - -# add case with filename -# -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/1-insert/time_range_wise.py b/tests/system-test/1-insert/time_range_wise.py index a620a4b51a..2596f82476 100644 --- a/tests/system-test/1-insert/time_range_wise.py +++ b/tests/system-test/1-insert/time_range_wise.py @@ -614,12 +614,12 @@ class TDTestCase: self.__insert_data() self.all_test() - tdLog.printNoPrefix("==========step2:create table in rollup database") - tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m") - tdSql.execute("use db3") + #tdLog.printNoPrefix("==========step2:create table in rollup database") + #tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m") + #tdSql.execute("use db3") # self.__create_tb() - tdSql.execute(f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL}) ") - self.all_test() + #tdSql.execute(f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL}) ") + #self.all_test() # self.__insert_data() diff --git a/tests/system-test/2-query/function_diff.py b/tests/system-test/2-query/function_diff.py index 2bcacd5ae3..7d49f875d1 100644 --- a/tests/system-test/2-query/function_diff.py +++ b/tests/system-test/2-query/function_diff.py @@ -360,15 +360,15 @@ class TDTestCase: tdSql.checkRows(229) tdSql.checkData(0,0,0) tdSql.query("select diff(c1) from stb1 partition by tbname ") - tdSql.checkRows(199) + tdSql.checkRows(190) # tdSql.query("select diff(st1) from stb1 partition by tbname") # tdSql.checkRows(229) tdSql.query("select diff(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(199) + tdSql.checkRows(190) tdSql.query("select diff(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(199) + tdSql.checkRows(190) tdSql.query("select diff(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(199) + tdSql.checkRows(190) # # bug need fix # tdSql.query("select diff(st1+c1) from stb1 partition by tbname slimit 1 ") @@ -378,7 +378,7 @@ class TDTestCase: # bug need fix tdSql.query("select diff(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(199) + tdSql.checkRows(190) # bug need fix # tdSql.query("select tbname , diff(c1) from stb1 partition by tbname") diff --git a/tests/system-test/2-query/mavg.py b/tests/system-test/2-query/mavg.py index 346d9e1df3..de379e39ce 100644 --- a/tests/system-test/2-query/mavg.py +++ b/tests/system-test/2-query/mavg.py @@ -678,15 +678,15 @@ class TDTestCase: tdSql.checkRows(68) tdSql.checkData(0,0,1.000000000) tdSql.query("select mavg(c1,3) from stb1 partition by tbname ") - tdSql.checkRows(38) + tdSql.checkRows(20) # tdSql.query("select mavg(st1,3) from stb1 partition by tbname") # tdSql.checkRows(38) tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") - tdSql.checkRows(38) + tdSql.checkRows(20) tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") - tdSql.checkRows(38) + tdSql.checkRows(20) tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") - tdSql.checkRows(38) + tdSql.checkRows(20) # # bug need fix # tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname slimit 1 ") @@ -696,7 +696,7 @@ class TDTestCase: # bug need fix tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") - tdSql.checkRows(38) + tdSql.checkRows(20) # bug need fix # tdSql.query("select tbname , mavg(c1,3) from stb1 partition by tbname") diff --git a/tests/system-test/2-query/queryQnode.py b/tests/system-test/2-query/queryQnode.py index d9976d8f3e..3fdc09478d 100644 --- a/tests/system-test/2-query/queryQnode.py +++ b/tests/system-test/2-query/queryQnode.py @@ -32,9 +32,9 @@ class TDTestCase: # # --------------- main frame ------------------- # - clientCfgDict = {'queryPolicy': '1','debugFlag': 135} + clientCfgDict = {'queryPolicy': '1','debugFlag': 143} clientCfgDict["queryPolicy"] = '1' - clientCfgDict["debugFlag"] = 131 + clientCfgDict["debugFlag"] = 143 updatecfgDict = {'clientCfg': {}} updatecfgDict = {'debugFlag': 143} @@ -278,22 +278,7 @@ class TDTestCase: tdSql.checkData(0,0,rowsPerSTable) return - # test case1 base - def test_case1(self): - #stableCount=threadNumbersCtb - parameterDict = {'vgroups': 1, \ - 'threadNumbersCtb': 5, \ - 'threadNumbersIda': 5, \ - 'stableCount': 5, \ - 'tablesPerStb': 50, \ - 'rowsPerTable': 10, \ - 'dbname': 'db', \ - 'stbname': 'stb', \ - 'host': 'localhost', \ - 'startTs': 1640966400000} # 2022-01-01 00:00:00.000 - - tdLog.debug("-----create database and muti-thread create tables test------- ") - + # test case : Switch back and forth among the three queryPolicy(1\2\3) def test_case1(self): self.taosBenchCreate("127.0.0.1","no","db1", "stb1", 1, 2, 1*10) tdSql.execute("use db1;") @@ -407,6 +392,7 @@ class TDTestCase: tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union all select c0,c1 from stb11_1 where c0>2000;") assert unionallQnode==tdSql.queryResult + # test case : queryPolicy = 2 def test_case2(self): self.taosBenchCreate("127.0.0.1","no","db1", "stb1", 10, 2, 1*10) tdSql.query("show qnodes") @@ -438,8 +424,9 @@ class TDTestCase: tdSql.query("select max(c1) from stb10_0;") tdSql.query("select min(c1) from stb11_0;") - def test_case3(self): + # test case : queryPolicy = 3 + def test_case3(self): tdSql.execute('alter local "queryPolicy" "3"') tdLog.debug("create qnode on dnode 1") tdSql.execute("create qnode on dnode 1") @@ -472,10 +459,16 @@ class TDTestCase: # run case def run(self): # test qnode + tdLog.debug(" test_case1 ............ [start]") self.test_case1() + tdLog.debug(" test_case1 ............ [OK]") + tdLog.debug(" test_case2 ............ [start]") self.test_case2() - + tdLog.debug(" test_case2 ............ [OK]") + tdLog.debug(" test_case3 ............ [start]") self.test_case3() + tdLog.debug(" test_case3 ............ [OK]") + # tdLog.debug(" LIMIT test_case3 ............ [OK]") def stop(self): @@ -487,4 +480,4 @@ class TDTestCase: # add case with filename # tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/query_cols_tags_and_or.py b/tests/system-test/2-query/query_cols_tags_and_or.py index f8a44f735f..c9df6f61bb 100644 --- a/tests/system-test/2-query/query_cols_tags_and_or.py +++ b/tests/system-test/2-query/query_cols_tags_and_or.py @@ -1066,7 +1066,7 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in query_sql = f'select {select_elm} from {tb_name} where c5 in (1, 6.6)' - tdSql.error(query_sql) + tdSql.query(query_sql) # not in query_sql = f'select {select_elm} from {tb_name} where c5 not in (2, 3)' tdSql.query(query_sql) @@ -1074,10 +1074,10 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and query_sql = f'select {select_elm} from {tb_name} where c5 > 0 and c5 >= 1 and c5 < 7 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 6.6 and c5 is not null and c5 between 2 and 6.6 and c5 not between 1 and 2 and c5 in (2,6.6) and c5 not in (1,2)' - tdSql.error(query_sql) + tdSql.query(query_sql) # or query_sql = f'select {select_elm} from {tb_name} where c5 > 6 or c5 >= 6.6 or c5 < 1 or c5 <= 0 or c5 != 1.1 or c5 <> 1.1 or c5 = 5 or c5 is null or c5 between 4 and 5 or c5 not between 1 and 3 or c5 in (4,5) or c5 not in (1.1,3)' - tdSql.error(query_sql) + tdSql.query(query_sql) # and or query_sql = f'select {select_elm} from {tb_name} where c5 > 0 and c5 >= 1 or c5 < 5 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 4 or c5 is not null and c5 between 2 and 4 and c5 not between 1 and 2 and c5 in (2,4) and c5 not in (1,2)' tdSql.query(query_sql) @@ -1145,7 +1145,7 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in query_sql = f'select {select_elm} from {tb_name} where c6 in (1, 7.7)' - tdSql.error(query_sql) + tdSql.query(query_sql) # not in query_sql = f'select {select_elm} from {tb_name} where c6 not in (2, 3)' tdSql.query(query_sql) @@ -1153,10 +1153,10 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and query_sql = f'select {select_elm} from {tb_name} where c6 > 0 and c6 >= 1 and c6 < 8 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 7.7 and c6 is not null and c6 between 2 and 7.7 and c6 not between 1 and 2 and c6 in (2,7.7) and c6 not in (1,2)' - tdSql.error(query_sql) + tdSql.query(query_sql) # or query_sql = f'select {select_elm} from {tb_name} where c6 > 7 or c6 >= 7.7 or c6 < 1 or c6 <= 0 or c6 != 1.1 or c6 <> 1.1 or c6 = 5 or c6 is null or c6 between 4 and 5 or c6 not between 1 and 3 or c6 in (4,5) or c6 not in (1.1,3)' - tdSql.error(query_sql) + tdSql.query(query_sql) # and or query_sql = f'select {select_elm} from {tb_name} where c6 > 0 and c6 >= 1 or c6 < 5 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 4 or c6 is not null and c6 between 2 and 4 and c6 not between 1 and 2 and c6 in (2,4) and c6 not in (1,2)' tdSql.query(query_sql) @@ -1398,7 +1398,7 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in query_sql = f'select {select_elm} from {tb_name} where c9 in ("binar", false)' - tdSql.error(query_sql) + tdSql.query(query_sql) # # not in query_sql = f'select {select_elm} from {tb_name} where c9 not in (true)' tdSql.query(query_sql) @@ -1407,13 +1407,13 @@ class TDTestCase: # # and query_sql = f'select {select_elm} from {tb_name} where c9 = true and c9 != "false" and c9 <> "binary" and c9 is not null and c9 in ("binary", true) and c9 not in ("binary")' - tdSql.error(query_sql) + tdSql.query(query_sql) # # or query_sql = f'select {select_elm} from {tb_name} where c9 = true or c9 != "false" or c9 <> "binary" or c9 = "true" or c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' - tdSql.error(query_sql) + tdSql.query(query_sql) # # and or query_sql = f'select {select_elm} from {tb_name} where c9 = true and c9 != "false" or c9 <> "binary" or c9 = "true" and c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' - tdSql.error(query_sql) + tdSql.query(query_sql) query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(9) diff --git a/tests/system-test/2-query/tsbsQuery.py b/tests/system-test/2-query/tsbsQuery.py new file mode 100644 index 0000000000..d24e5ea283 --- /dev/null +++ b/tests/system-test/2-query/tsbsQuery.py @@ -0,0 +1,74 @@ +import taos +import sys +import datetime +import inspect + +from util.log import * +from util.sql import * +from util.cases import * + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), True) + + def prepareData(self): + database="db_tsbs" + ts=1451606400000 + tdSql.execute(f"create database {database};") + tdSql.execute(f"use {database} ") + tdSql.execute(''' + create table readings (ts timestamp,latitude double,longitude double,elevation double,velocity double,heading double,grade double,fuel_consumption double,load_capacity double,fuel_capacity double,nominal_fuel_consumption double) tags (name binary(30),fleet binary(30),driver binary(30),model binary(30),device_version binary(30)); + ''') + tdSql.execute(''' + create table diagnostics (ts timestamp,fuel_state double,current_load double,status bigint,load_capacity double,fuel_capacity double,nominal_fuel_consumption double) tags (name binary(30),fleet binary(30),driver binary(30),model binary(30),device_version binary(30)) ; + ''') + + for i in range(10): + tdSql.execute(f"create table rct{i} using readings (name,fleet,driver,model,device_version) tags ('truck_{i}','South{i}','Trish{i}','H-{i}','v2.3')") + tdSql.execute(f"create table dct{i} using diagnostics (name,fleet,driver,model,device_version) tags ('truck_{i}','South{i}','Trish{i}','H-{i}','v2.3')") + for j in range(10): + for i in range(10): + tdSql.execute( + f"insert into rct{j} values ( {ts+i*10000}, {80+i}, {90+i}, {85+i}, {30+i*10}, {1.2*i}, {221+i*2}, {20+i*0.2}, {1500+i*20}, {150+i*2},{5+i} )" + ) + tdSql.execute( + f"insert into dct{j} values ( {ts+i*10000}, {1+i*0.1},{1400+i*15}, {1+i},{1500+i*20}, {150+i*2},{5+i} )" + ) + + # def check_avg(self ,origin_query , check_query): + # avg_result = tdSql.getResult(origin_query) + # origin_result = tdSql.getResult(check_query) + + # check_status = True + # for row_index , row in enumerate(avg_result): + # for col_index , elem in enumerate(row): + # if avg_result[row_index][col_index] != origin_result[row_index][col_index]: + # check_status = False + # if not check_status: + # tdLog.notice("avg function value has not as expected , sql is \"%s\" "%origin_query ) + # sys.exit(1) + # else: + # tdLog.info("avg value check pass , it work as expected ,sql is \"%s\" "%check_query ) + + + def tsbsIotQuery(self): + tdSql.execute("use db_tsbs") + tdSql.query(" SELECT avg(velocity) as mean_velocity ,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet interval(10m); ") + tdSql.checkRows(1) + + + + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring + tdLog.printNoPrefix("==========step1:create database and table,insert data ==============") + self.tsbsIotQuery() + self.tsbsIotQuery() + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/6-cluster/5dnode1mnode.py b/tests/system-test/6-cluster/5dnode1mnode.py index 5f4ab7357b..4611726c14 100644 --- a/tests/system-test/6-cluster/5dnode1mnode.py +++ b/tests/system-test/6-cluster/5dnode1mnode.py @@ -124,9 +124,9 @@ class TDTestCase: tdSql.query('show databases;') tdSql.checkData(2,5,'no_strict') tdSql.error('alter database db strict 0') - tdSql.execute('alter database db strict 1') - tdSql.query('show databases;') - tdSql.checkData(2,5,'strict') + # tdSql.execute('alter database db strict 1') + # tdSql.query('show databases;') + # tdSql.checkData(2,5,'strict') def getConnection(self, dnode): host = dnode.cfgDict["fqdn"] diff --git a/tests/system-test/6-cluster/5dnode3mnodeAdd1Ddnoe.py b/tests/system-test/6-cluster/5dnode3mnodeAdd1Ddnoe.py new file mode 100644 index 0000000000..d3de31eb04 --- /dev/null +++ b/tests/system-test/6-cluster/5dnode3mnodeAdd1Ddnoe.py @@ -0,0 +1,229 @@ +from ssl import ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE +from numpy import row_stack +import taos +import sys +import time +import os + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import TDDnodes +from util.dnodes import TDDnode +from util.cluster import * +sys.path.append("./6-cluster") +from clusterCommonCreate import * +from clusterCommonCheck import clusterComCheck + +import time +import socket +import subprocess +from multiprocessing import Process +import threading +import time +import inspect +import ctypes + +class TDTestCase: + + def init(self,conn ,logSql): + tdLog.debug(f"start to excute {__file__}") + self.TDDnodes = None + tdSql.init(conn.cursor()) + self.host = socket.gethostname() + + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def _async_raise(self, tid, exctype): + """raises the exception, performs cleanup if needed""" + if not inspect.isclass(exctype): + exctype = type(exctype) + res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) + if res == 0: + raise ValueError("invalid thread id") + elif res != 1: + # """if it returns a number greater than one, you're in trouble, + # and you should call it again with exc=NULL to revert the effect""" + ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) + raise SystemError("PyThreadState_SetAsyncExc failed") + + def stopThread(self,thread): + self._async_raise(thread.ident, SystemExit) + + + def insertData(self,countstart,countstop): + # fisrt add data : db\stable\childtable\general table + + for couti in range(countstart,countstop): + tdLog.debug("drop database if exists db%d" %couti) + tdSql.execute("drop database if exists db%d" %couti) + print("create database if not exists db%d replica 1 duration 300" %couti) + tdSql.execute("create database if not exists db%d replica 1 duration 300" %couti) + tdSql.execute("use db%d" %couti) + tdSql.execute( + '''create table stb1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + + def fiveDnodeThreeMnode(self,dnodeNumbers,mnodeNums,restartNumbers,stopRole): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'db0_0', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'replica': 1, + 'stbName': 'stb', + 'stbNumbers': 2, + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbNum': 200, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + "rowsPerTbl": 1000, + "batchNum": 5000 + } + hostname = socket.gethostname() + dnodeNumbers=int(dnodeNumbers) + mnodeNums=int(mnodeNums) + vnodeNumbers = int(dnodeNumbers-mnodeNums) + allctbNumbers=(paraDict['stbNumbers']*paraDict["ctbNum"]) + rowsPerStb=paraDict["ctbNum"]*paraDict["rowsPerTbl"] + rowsall=rowsPerStb*paraDict['stbNumbers'] + dbNumbers = 1 + + tdLog.info("first check dnode and mnode") + tdSql.query("show dnodes;") + tdSql.checkData(0,1,'%s:6030'%self.host) + tdSql.checkData(4,1,'%s:6430'%self.host) + clusterComCheck.checkDnodes(dnodeNumbers) + clusterComCheck.checkMnodeStatus(1) + + # fisr add three mnodes; + tdLog.info("fisr add three mnodes and check mnode status") + tdSql.execute("create mnode on dnode 2") + clusterComCheck.checkMnodeStatus(2) + tdSql.execute("create mnode on dnode 3") + clusterComCheck.checkMnodeStatus(3) + + # add some error operations and + tdLog.info("Confirm the status of the dnode again") + tdSql.error("create mnode on dnode 2") + tdSql.query("show dnodes;") + print(tdSql.queryResult) + clusterComCheck.checkDnodes(dnodeNumbers) + + # create database and stable + clusterComCreate.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']) + tdLog.info("Take turns stopping Mnodes ") + + tdDnodes=cluster.dnodes + # dnode6=cluster.addDnode(6) + # tdDnodes.append(dnode6) + # tdDnodes = ClusterDnodes(tdDnodes) + stopcount =0 + threads=[] + + # create stable:stb_0 + stableName= paraDict['stbName'] + newTdSql=tdCom.newTdSql() + clusterComCreate.create_stables(newTdSql, paraDict["dbName"],stableName,paraDict['stbNumbers']) + #create child table:ctb_0 + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + newTdSql=tdCom.newTdSql() + clusterComCreate.create_ctable(newTdSql, paraDict["dbName"],stableName,stableName, paraDict['ctbNum']) + #insert date + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + newTdSql=tdCom.newTdSql() + threads.append(threading.Thread(target=clusterComCreate.insert_data, args=(newTdSql, paraDict["dbName"],stableName,paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]))) + for tr in threads: + tr.start() + dnode6Port=int(6030+5*100) + tdSql.execute("create dnode '%s:%d'"%(hostname,dnode6Port)) + clusterComCheck.checkDnodes(dnodeNumbers) + + while stopcount < restartNumbers: + tdLog.info(" restart loop: %d"%stopcount ) + if stopRole == "mnode": + for i in range(mnodeNums): + tdDnodes[i].stoptaosd() + # sleep(10) + tdDnodes[i].starttaosd() + # sleep(10) + elif stopRole == "vnode": + for i in range(vnodeNumbers): + tdDnodes[i+mnodeNums].stoptaosd() + # sleep(10) + tdDnodes[i+mnodeNums].starttaosd() + # sleep(10) + elif stopRole == "dnode": + for i in range(dnodeNumbers): + tdDnodes[i].stoptaosd() + # sleep(10) + tdDnodes[i].starttaosd() + # sleep(10) + + # dnodeNumbers don't include database of schema + if clusterComCheck.checkDnodes(dnodeNumbers): + tdLog.info("123") + else: + print("456") + + self.stopThread(threads) + tdLog.exit("one or more of dnodes failed to start ") + # self.check3mnode() + stopcount+=1 + for tr in threads: + tr.join() + + + clusterComCheck.checkDnodes(dnodeNumbers) + clusterComCheck.checkDbRows(dbNumbers) + # clusterComCheck.checkDb(dbNumbers,1,paraDict["dbName"]) + + tdSql.execute("use %s" %(paraDict["dbName"])) + tdSql.query("show stables") + tdSql.checkRows(paraDict["stbNumbers"]) + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + tdSql.query("select * from %s"%stableName) + tdSql.checkRows(rowsPerStb) + def run(self): + # print(self.master_dnode.cfgDict) + self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=2,stopRole='dnode') + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertData.py b/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertData.py new file mode 100644 index 0000000000..e5946342d2 --- /dev/null +++ b/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertData.py @@ -0,0 +1,223 @@ +from ssl import ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE +from numpy import row_stack +import taos +import sys +import time +import os + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import TDDnodes +from util.dnodes import TDDnode +from util.cluster import * +sys.path.append("./6-cluster") +from clusterCommonCreate import * +from clusterCommonCheck import clusterComCheck + +import time +import socket +import subprocess +from multiprocessing import Process +import threading +import time +import inspect +import ctypes + +class TDTestCase: + + def init(self,conn ,logSql): + tdLog.debug(f"start to excute {__file__}") + self.TDDnodes = None + tdSql.init(conn.cursor()) + self.host = socket.gethostname() + + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def _async_raise(self, tid, exctype): + """raises the exception, performs cleanup if needed""" + if not inspect.isclass(exctype): + exctype = type(exctype) + res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) + if res == 0: + raise ValueError("invalid thread id") + elif res != 1: + # """if it returns a number greater than one, you're in trouble, + # and you should call it again with exc=NULL to revert the effect""" + ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) + raise SystemError("PyThreadState_SetAsyncExc failed") + + def stopThread(self,thread): + self._async_raise(thread.ident, SystemExit) + + + def insertData(self,countstart,countstop): + # fisrt add data : db\stable\childtable\general table + + for couti in range(countstart,countstop): + tdLog.debug("drop database if exists db%d" %couti) + tdSql.execute("drop database if exists db%d" %couti) + print("create database if not exists db%d replica 1 duration 300" %couti) + tdSql.execute("create database if not exists db%d replica 1 duration 300" %couti) + tdSql.execute("use db%d" %couti) + tdSql.execute( + '''create table stb1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + + def fiveDnodeThreeMnode(self,dnodeNumbers,mnodeNums,restartNumbers,stopRole): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'db0_0', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'replica': 1, + 'stbName': 'stb', + 'stbNumbers': 2, + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbNum': 200, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + "rowsPerTbl": 1000, + "batchNum": 5000 + } + + dnodeNumbers=int(dnodeNumbers) + mnodeNums=int(mnodeNums) + vnodeNumbers = int(dnodeNumbers-mnodeNums) + allctbNumbers=(paraDict['stbNumbers']*paraDict["ctbNum"]) + rowsPerStb=paraDict["ctbNum"]*paraDict["rowsPerTbl"] + rowsall=rowsPerStb*paraDict['stbNumbers'] + dbNumbers = 1 + + tdLog.info("first check dnode and mnode") + tdSql.query("show dnodes;") + tdSql.checkData(0,1,'%s:6030'%self.host) + tdSql.checkData(4,1,'%s:6430'%self.host) + clusterComCheck.checkDnodes(dnodeNumbers) + clusterComCheck.checkMnodeStatus(1) + + # fisr add three mnodes; + tdLog.info("fisr add three mnodes and check mnode status") + tdSql.execute("create mnode on dnode 2") + clusterComCheck.checkMnodeStatus(2) + tdSql.execute("create mnode on dnode 3") + clusterComCheck.checkMnodeStatus(3) + + # add some error operations and + tdLog.info("Confirm the status of the dnode again") + tdSql.error("create mnode on dnode 2") + tdSql.query("show dnodes;") + print(tdSql.queryResult) + clusterComCheck.checkDnodes(dnodeNumbers) + + # create database and stable + clusterComCreate.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']) + tdLog.info("Take turns stopping Mnodes ") + + tdDnodes=cluster.dnodes + stopcount =0 + threads=[] + + # create stable:stb_0 + stableName= paraDict['stbName'] + newTdSql=tdCom.newTdSql() + clusterComCreate.create_stables(newTdSql, paraDict["dbName"],stableName,paraDict['stbNumbers']) + #create child table:ctb_0 + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + newTdSql=tdCom.newTdSql() + clusterComCreate.create_ctable(newTdSql, paraDict["dbName"],stableName,stableName, paraDict['ctbNum']) + #insert date + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + newTdSql=tdCom.newTdSql() + threads.append(threading.Thread(target=clusterComCreate.insert_data, args=(newTdSql, paraDict["dbName"],stableName,paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]))) + for tr in threads: + tr.start() + for tr in threads: + tr.join() + + while stopcount < restartNumbers: + tdLog.info(" restart loop: %d"%stopcount ) + if stopRole == "mnode": + for i in range(mnodeNums): + tdDnodes[i].stoptaosd() + # sleep(10) + tdDnodes[i].starttaosd() + # sleep(10) + elif stopRole == "vnode": + for i in range(vnodeNumbers): + tdDnodes[i+mnodeNums].stoptaosd() + # sleep(10) + tdDnodes[i+mnodeNums].starttaosd() + # sleep(10) + elif stopRole == "dnode": + for i in range(dnodeNumbers): + tdDnodes[i].stoptaosd() + # sleep(10) + tdDnodes[i].starttaosd() + # sleep(10) + + # dnodeNumbers don't include database of schema + if clusterComCheck.checkDnodes(dnodeNumbers): + tdLog.info("123") + else: + print("456") + + self.stopThread(threads) + tdLog.exit("one or more of dnodes failed to start ") + # self.check3mnode() + stopcount+=1 + + + clusterComCheck.checkDnodes(dnodeNumbers) + clusterComCheck.checkDbRows(dbNumbers) + # clusterComCheck.checkDb(dbNumbers,1,paraDict["dbName"]) + + tdSql.execute("use %s" %(paraDict["dbName"])) + tdSql.query("show stables") + tdSql.checkRows(paraDict["stbNumbers"]) + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + tdSql.query("select * from %s"%stableName) + tdSql.checkRows(rowsPerStb) + def run(self): + # print(self.master_dnode.cfgDict) + self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=2,stopRole='dnode') + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py index 96fad487d1..8971a51ef3 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py @@ -143,42 +143,43 @@ class TDTestCase: threads=[] for i in range(restartNumbers): dbNameIndex = '%s%d'%(paraDict["dbName"],i) - threads.append(threading.Thread(target=clusterComCreate.create_databases, args=(tdSql, dbNameIndex,paraDict["dbNumbers"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) + newTdSql=tdCom.newTdSql() + threads.append(threading.Thread(target=clusterComCreate.create_databases, args=(newTdSql, dbNameIndex,paraDict["dbNumbers"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) for tr in threads: tr.start() tdLog.info("Take turns stopping Mnodes ") - # while stopcount < restartNumbers: - # tdLog.info(" restart loop: %d"%stopcount ) - # if stopRole == "mnode": - # for i in range(mnodeNums): - # tdDnodes[i].stoptaosd() - # # sleep(10) - # tdDnodes[i].starttaosd() - # # sleep(10) - # elif stopRole == "vnode": - # for i in range(vnodeNumbers): - # tdDnodes[i+mnodeNums].stoptaosd() - # # sleep(10) - # tdDnodes[i+mnodeNums].starttaosd() - # # sleep(10) - # elif stopRole == "dnode": - # for i in range(dnodeNumbers): - # tdDnodes[i].stoptaosd() - # # sleep(10) - # tdDnodes[i].starttaosd() - # # sleep(10) + while stopcount < restartNumbers: + tdLog.info(" restart loop: %d"%stopcount ) + if stopRole == "mnode": + for i in range(mnodeNums): + tdDnodes[i].stoptaosd() + # sleep(10) + tdDnodes[i].starttaosd() + # sleep(10) + elif stopRole == "vnode": + for i in range(vnodeNumbers): + tdDnodes[i+mnodeNums].stoptaosd() + # sleep(10) + tdDnodes[i+mnodeNums].starttaosd() + # sleep(10) + elif stopRole == "dnode": + for i in range(dnodeNumbers): + tdDnodes[i].stoptaosd() + # sleep(10) + tdDnodes[i].starttaosd() + # sleep(10) - # # dnodeNumbers don't include database of schema - # if clusterComCheck.checkDnodes(dnodeNumbers): - # tdLog.info("check dnodes status is ready") - # else: - # tdLog.info("check dnodes status is not ready") - # self.stopThread(threads) - # tdLog.exit("one or more of dnodes failed to start ") - # # self.check3mnode() - # stopcount+=1 + # dnodeNumbers don't include database of schema + if clusterComCheck.checkDnodes(dnodeNumbers): + tdLog.info("check dnodes status is ready") + else: + tdLog.info("check dnodes status is not ready") + self.stopThread(threads) + tdLog.exit("one or more of dnodes failed to start ") + # self.check3mnode() + stopcount+=1 for tr in threads: tr.join() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py index 4ab9aa64e1..6db1a9fddd 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py @@ -92,7 +92,7 @@ class TDTestCase: def fiveDnodeThreeMnode(self,dnodeNumbers,mnodeNums,restartNumbers,stopRole): tdLog.printNoPrefix("======== test case 1: ") - paraDict = {'dbName': 'db0_0', + paraDict = {'dbName': 'db', 'dropFlag': 1, 'event': '', 'vgroups': 4, @@ -143,7 +143,8 @@ class TDTestCase: threads=[] for i in range(restartNumbers): stableName= '%s%d'%(paraDict['stbName'],i) - threads.append(threading.Thread(target=clusterComCreate.create_stables, args=(tdSql, paraDict["dbName"],stableName,paraDict['stbNumbers']))) + newTdSql=tdCom.newTdSql() + threads.append(threading.Thread(target=clusterComCreate.create_stables, args=(newTdSql, paraDict["dbName"],stableName,paraDict['stbNumbers']))) for tr in threads: tr.start() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeInsertData.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeInsertData.py new file mode 100644 index 0000000000..8f99ef0b5c --- /dev/null +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeInsertData.py @@ -0,0 +1,221 @@ +from ssl import ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE +from numpy import row_stack +import taos +import sys +import time +import os + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import TDDnodes +from util.dnodes import TDDnode +from util.cluster import * +sys.path.append("./6-cluster") +from clusterCommonCreate import * +from clusterCommonCheck import clusterComCheck + +import time +import socket +import subprocess +from multiprocessing import Process +import threading +import time +import inspect +import ctypes + +class TDTestCase: + + def init(self,conn ,logSql): + tdLog.debug(f"start to excute {__file__}") + self.TDDnodes = None + tdSql.init(conn.cursor()) + self.host = socket.gethostname() + + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def _async_raise(self, tid, exctype): + """raises the exception, performs cleanup if needed""" + if not inspect.isclass(exctype): + exctype = type(exctype) + res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) + if res == 0: + raise ValueError("invalid thread id") + elif res != 1: + # """if it returns a number greater than one, you're in trouble, + # and you should call it again with exc=NULL to revert the effect""" + ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) + raise SystemError("PyThreadState_SetAsyncExc failed") + + def stopThread(self,thread): + self._async_raise(thread.ident, SystemExit) + + + def insertData(self,countstart,countstop): + # fisrt add data : db\stable\childtable\general table + + for couti in range(countstart,countstop): + tdLog.debug("drop database if exists db%d" %couti) + tdSql.execute("drop database if exists db%d" %couti) + print("create database if not exists db%d replica 1 duration 300" %couti) + tdSql.execute("create database if not exists db%d replica 1 duration 300" %couti) + tdSql.execute("use db%d" %couti) + tdSql.execute( + '''create table stb1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + + def fiveDnodeThreeMnode(self,dnodeNumbers,mnodeNums,restartNumbers,stopRole): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'db0_0', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'replica': 1, + 'stbName': 'stb', + 'stbNumbers': 2, + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbNum': 200, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + "rowsPerTbl": 10000, + "batchNum": 5000 + } + + dnodeNumbers=int(dnodeNumbers) + mnodeNums=int(mnodeNums) + vnodeNumbers = int(dnodeNumbers-mnodeNums) + allctbNumbers=(paraDict['stbNumbers']*paraDict["ctbNum"]) + rowsPerStb=paraDict["ctbNum"]*paraDict["rowsPerTbl"] + rowsall=rowsPerStb*paraDict['stbNumbers'] + dbNumbers = 1 + + tdLog.info("first check dnode and mnode") + tdSql.query("show dnodes;") + tdSql.checkData(0,1,'%s:6030'%self.host) + tdSql.checkData(4,1,'%s:6430'%self.host) + clusterComCheck.checkDnodes(dnodeNumbers) + clusterComCheck.checkMnodeStatus(1) + + # fisr add three mnodes; + tdLog.info("fisr add three mnodes and check mnode status") + tdSql.execute("create mnode on dnode 2") + clusterComCheck.checkMnodeStatus(2) + tdSql.execute("create mnode on dnode 3") + clusterComCheck.checkMnodeStatus(3) + + # add some error operations and + tdLog.info("Confirm the status of the dnode again") + tdSql.error("create mnode on dnode 2") + tdSql.query("show dnodes;") + print(tdSql.queryResult) + clusterComCheck.checkDnodes(dnodeNumbers) + + # create database and stable + clusterComCreate.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']) + tdLog.info("Take turns stopping Mnodes ") + + tdDnodes=cluster.dnodes + stopcount =0 + threads=[] + + # create stable:stb_0 + stableName= paraDict['stbName'] + newTdSql=tdCom.newTdSql() + clusterComCreate.create_stables(newTdSql, paraDict["dbName"],stableName,paraDict['stbNumbers']) + #create child table:ctb_0 + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + newTdSql=tdCom.newTdSql() + clusterComCreate.create_ctable(newTdSql, paraDict["dbName"],stableName,stableName, paraDict['ctbNum']) + #insert date + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + newTdSql=tdCom.newTdSql() + threads.append(threading.Thread(target=clusterComCreate.insert_data, args=(newTdSql, paraDict["dbName"],stableName,paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]))) + for tr in threads: + tr.start() + while stopcount < restartNumbers: + tdLog.info(" restart loop: %d"%stopcount ) + if stopRole == "mnode": + for i in range(mnodeNums): + tdDnodes[i].stoptaosd() + # sleep(10) + tdDnodes[i].starttaosd() + # sleep(10) + elif stopRole == "vnode": + for i in range(vnodeNumbers): + tdDnodes[i+mnodeNums].stoptaosd() + # sleep(10) + tdDnodes[i+mnodeNums].starttaosd() + # sleep(10) + elif stopRole == "dnode": + for i in range(dnodeNumbers): + tdDnodes[i].stoptaosd() + # sleep(10) + tdDnodes[i].starttaosd() + # sleep(10) + + # dnodeNumbers don't include database of schema + if clusterComCheck.checkDnodes(dnodeNumbers): + tdLog.info("123") + else: + print("456") + + self.stopThread(threads) + tdLog.exit("one or more of dnodes failed to start ") + # self.check3mnode() + stopcount+=1 + + for tr in threads: + tr.join() + clusterComCheck.checkDnodes(dnodeNumbers) + clusterComCheck.checkDbRows(dbNumbers) + # clusterComCheck.checkDb(dbNumbers,1,paraDict["dbName"]) + + tdSql.execute("use %s" %(paraDict["dbName"])) + tdSql.query("show stables") + tdSql.checkRows(paraDict["stbNumbers"]) + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + tdSql.query("select * from %s"%stableName) + tdSql.checkRows(rowsPerStb) + def run(self): + # print(self.master_dnode.cfgDict) + self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=2,stopRole='dnode') + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py index 17c344e341..f820d812ec 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py @@ -116,7 +116,8 @@ class TDTestCase: threads=[] for i in range(restartNumbers): dbNameIndex = '%s%d'%(paraDict["dbName"],i) - threads.append(threading.Thread(target=clusterComCreate.create_databases, args=(tdSql, dbNameIndex,paraDict["dbNumbers"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) + newTdSql=tdCom.newTdSql() + threads.append(threading.Thread(target=clusterComCreate.create_databases, args=(newTdSql, dbNameIndex,paraDict["dbNumbers"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) for tr in threads: tr.start() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py index 2f1c1368d1..128dc10b37 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py @@ -30,8 +30,8 @@ class TDTestCase: self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() - - + print(tdSql) + def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) @@ -113,6 +113,7 @@ class TDTestCase: allStbNumbers=(paraDict['stbNumbers']*restartNumbers) dbNumbers = 1 + print(tdSql) tdLog.info("first check dnode and mnode") tdSql.query("show dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) @@ -141,9 +142,11 @@ class TDTestCase: tdDnodes=cluster.dnodes stopcount =0 threads=[] + for i in range(restartNumbers): stableName= '%s%d'%(paraDict['stbName'],i) - threads.append(threading.Thread(target=clusterComCreate.create_stables, args=(tdSql, paraDict["dbName"],stableName,paraDict['stbNumbers']))) + newTdSql=tdCom.newTdSql() + threads.append(threading.Thread(target=clusterComCreate.create_stables, args=(newTdSql, paraDict["dbName"],stableName,paraDict['stbNumbers']))) for tr in threads: tr.start() diff --git a/tests/system-test/6-cluster/clusterCommonCreate.py b/tests/system-test/6-cluster/clusterCommonCreate.py index 9d3f74a2e3..851fe3b51c 100644 --- a/tests/system-test/6-cluster/clusterCommonCreate.py +++ b/tests/system-test/6-cluster/clusterCommonCreate.py @@ -152,7 +152,7 @@ class ClusterComCreate: if (i % 2 == 0): tagValue = 'shanghai' - sql += " %s%d using %s tags(%d, '%s')"%(ctbPrefix,i,stbName,i+1, tagValue) + sql += " %s_%d using %s tags(%d, '%s')"%(ctbPrefix,i,stbName,i+1, tagValue) if (i > 0) and (i%100 == 0): tsql.execute(sql) sql = pre_create @@ -173,13 +173,13 @@ class ClusterComCreate: startTs = int(round(t * 1000)) #tdLog.debug("doing insert data into stable:%s rows:%d ..."%(stbName, allRows)) for i in range(ctbNum): - sql += " %s%d values "%(stbName,i) + sql += " %s_%d values "%(stbName,i) for j in range(rowsPerTbl): - sql += "(%d, %d, 'tmqrow_%d') "%(startTs + j, j, j) + sql += "(%d, %d, %d, 'mnode_%d') "%(startTs + j, j, j,j) if (j > 0) and ((j%batchNum == 0) or (j == rowsPerTbl - 1)): tsql.execute(sql) if j < rowsPerTbl - 1: - sql = "insert into %s%d values " %(stbName,i) + sql = "insert into %s_%d values " %(stbName,i) else: sql = "insert into " #end sql diff --git a/tests/system-test/failed.txt b/tests/system-test/failed.txt index d0b66b1769..59c4d625d9 100644 --- a/tests/system-test/failed.txt +++ b/tests/system-test/failed.txt @@ -1 +1,2 @@ #python3 ./test.py -f 2-query/last.py -Q 3 +#./test.sh -f tsim/mnode/basic4.sim diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 15e6ecd61c..2d1ca64914 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -123,10 +123,11 @@ python3 ./test.py -f 2-query/function_null.py python3 ./test.py -f 2-query/queryQnode.py python3 ./test.py -f 2-query/max_partition.py -#python3 ./test.py -f 6-cluster/5dnode1mnode.py -#python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3 + +python3 ./test.py -f 6-cluster/5dnode1mnode.py +#BUG python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3 #python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -N 5 -M 3 -#python3 ./test.py -f 6-cluster/5dnode3mnodeStopLoop.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeStopLoop.py -N 5 -M 3 # BUG python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py -N 5 -M 3 # BUG python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py -N 5 -M 3 @@ -136,7 +137,8 @@ python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py -N 5 - # BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py # python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 # python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3 - +# BUG Redict python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 +# python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertData.py -N 5 -M 3 python3 ./test.py -f 7-tmq/basic5.py python3 ./test.py -f 7-tmq/subscribeDb.py diff --git a/tests/system-test/test.py b/tests/system-test/test.py index 9596efdfc8..0a891759d0 100644 --- a/tests/system-test/test.py +++ b/tests/system-test/test.py @@ -64,8 +64,9 @@ if __name__ == "__main__": updateCfgDict = {} execCmd = "" queryPolicy = 1 - opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:', [ - 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy']) + createDnodeNums = 1 + opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:C:', [ + 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy','createDnodeNums']) for key, value in opts: if key in ['-h', '--help']: tdLog.printNoPrefix( @@ -81,9 +82,11 @@ if __name__ == "__main__": tdLog.printNoPrefix('-d update cfg dict, base64 json str') tdLog.printNoPrefix('-k not kill valgrind processer') tdLog.printNoPrefix('-e eval str to run') - tdLog.printNoPrefix('-N create dnodes numbers in clusters') + tdLog.printNoPrefix('-N start dnodes numbers in clusters') tdLog.printNoPrefix('-M create mnode numbers in clusters') tdLog.printNoPrefix('-Q set queryPolicy in one dnode') + tdLog.printNoPrefix('-C create Dnode Numbers in one cluster') + sys.exit(0) @@ -143,6 +146,9 @@ if __name__ == "__main__": if key in ['-Q', '--queryPolicy']: queryPolicy = value + if key in ['-C', '--createDnodeNums']: + createDnodeNums = value + if not execCmd == "": tdDnodes.init(deployPath) print(execCmd) @@ -239,7 +245,11 @@ if __name__ == "__main__": host, config=tdDnodes.getSimCfgPath()) print(tdDnodes.getSimCfgPath(),host) - cluster.create_dnode(conn) + if createDnodeNums == 1: + createDnodeNums=dnodeNums + else: + createDnodeNums=createDnodeNums + cluster.create_dnode(conn,createDnodeNums) try: if cluster.check_dnode(conn) : print("check dnode ready") @@ -314,7 +324,11 @@ if __name__ == "__main__": host, config=tdDnodes.getSimCfgPath()) print(tdDnodes.getSimCfgPath(),host) - cluster.create_dnode(conn) + if createDnodeNums == 1: + createDnodeNums=dnodeNums + else: + createDnodeNums=createDnodeNums + cluster.create_dnode(conn,createDnodeNums) try: if cluster.check_dnode(conn) : print("check dnode ready") diff --git a/tests/test/c/sdbDump.c b/tests/test/c/sdbDump.c index a62c30660d..4d0f582dc6 100644 --- a/tests/test/c/sdbDump.c +++ b/tests/test/c/sdbDump.c @@ -24,6 +24,7 @@ #define TMP_MNODE_DIR TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" #define TMP_SDB_DATA_DIR TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "data" #define TMP_SDB_SYNC_DIR TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "sync" +#define TMP_SDB_MNODE_JSON TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "mnode.json" #define TMP_SDB_DATA_FILE TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "data" TD_DIRSEP "sdb.data" #define TMP_SDB_RAFT_CFG_FILE TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "sync" TD_DIRSEP "raft_config.json" #define TMP_SDB_RAFT_STORE_FILE TD_TMP_DIR_PATH "dumpsdb" TD_DIRSEP "mnode" TD_DIRSEP "sync" TD_DIRSEP "raft_store.json" @@ -71,6 +72,7 @@ void dumpDb(SSdb *pSdb, SJson *json) { tjsonAddIntegerToObject(item, "buffer", pObj->cfg.buffer); tjsonAddIntegerToObject(item, "pageSize", pObj->cfg.pageSize); tjsonAddIntegerToObject(item, "pages", pObj->cfg.pages); + tjsonAddIntegerToObject(item, "cacheLastSize", pObj->cfg.cacheLastSize); tjsonAddIntegerToObject(item, "daysPerFile", pObj->cfg.daysPerFile); tjsonAddIntegerToObject(item, "daysToKeep0", pObj->cfg.daysToKeep0); tjsonAddIntegerToObject(item, "daysToKeep1", pObj->cfg.daysToKeep1); @@ -83,7 +85,7 @@ void dumpDb(SSdb *pSdb, SJson *json) { tjsonAddIntegerToObject(item, "compression", pObj->cfg.compression); tjsonAddIntegerToObject(item, "replications", pObj->cfg.replications); tjsonAddIntegerToObject(item, "strict", pObj->cfg.strict); - tjsonAddIntegerToObject(item, "cacheLastRow", pObj->cfg.cacheLastRow); + tjsonAddIntegerToObject(item, "cacheLast", pObj->cfg.cacheLast); tjsonAddIntegerToObject(item, "hashMethod", pObj->cfg.hashMethod); tjsonAddIntegerToObject(item, "numOfRetensions", pObj->cfg.numOfRetensions); tjsonAddIntegerToObject(item, "schemaless", pObj->cfg.schemaless); @@ -412,9 +414,11 @@ int32_t parseArgs(int32_t argc, char *argv[]) { return -1; } + char mnodeJson[PATH_MAX] = {0}; char dataFile[PATH_MAX] = {0}; char raftCfgFile[PATH_MAX] = {0}; char raftStoreFile[PATH_MAX] = {0}; + snprintf(mnodeJson, PATH_MAX, "%s" TD_DIRSEP "mnode" TD_DIRSEP "mnode.json", tsDataDir); snprintf(dataFile, PATH_MAX, "%s" TD_DIRSEP "mnode" TD_DIRSEP "data" TD_DIRSEP "sdb.data", tsDataDir); snprintf(raftCfgFile, PATH_MAX, "%s" TD_DIRSEP "mnode" TD_DIRSEP "sync" TD_DIRSEP "raft_config.json", tsDataDir); snprintf(raftStoreFile, PATH_MAX, "%s" TD_DIRSEP "mnode" TD_DIRSEP "sync" TD_DIRSEP "raft_store.json", tsDataDir); @@ -425,6 +429,8 @@ int32_t parseArgs(int32_t argc, char *argv[]) { #ifdef WINDOWS taosMulMkDir(TMP_SDB_DATA_DIR); taosMulMkDir(TMP_SDB_SYNC_DIR); + snprintf(cmd, sizeof(cmd), "cp %s %s 2>nul", mnodeJson, TMP_SDB_MNODE_JSON); + system(cmd); snprintf(cmd, sizeof(cmd), "cp %s %s 2>nul", dataFile, TMP_SDB_DATA_FILE); system(cmd); snprintf(cmd, sizeof(cmd), "cp %s %s 2>nul", raftCfgFile, TMP_SDB_RAFT_CFG_FILE); @@ -436,6 +442,8 @@ int32_t parseArgs(int32_t argc, char *argv[]) { system(cmd); snprintf(cmd, sizeof(cmd), "mkdir -p %s", TMP_SDB_SYNC_DIR); system(cmd); + snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", mnodeJson, TMP_SDB_MNODE_JSON); + system(cmd); snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", dataFile, TMP_SDB_DATA_FILE); system(cmd); snprintf(cmd, sizeof(cmd), "cp %s %s 2>/dev/null", raftCfgFile, TMP_SDB_RAFT_CFG_FILE); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 59908cca8a..5d463e1de9 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,25 +1,46 @@ IF (TD_WEBSOCKET) - MESSAGE("${Green} use libtaos-ws${ColourReset}") - IF (TD_LINUX) - include(ExternalProject) - ExternalProject_Add(taosws-rs - PREFIX "taosws-rs" - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosws-rs - BUILD_ALWAYS off - DEPENDS taos - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND cmake -E echo "taosws-rs no need cmake to config" - PATCH_COMMAND - COMMAND git clean -f -d - BUILD_COMMAND - COMMAND cargo build --release -p taos-ws-sys - COMMAND ./taos-ws-sys/ci/package.sh - INSTALL_COMMAND - COMMAND cmake -E copy target/libtaosws/libtaosws.so ${CMAKE_BINARY_DIR}/build/lib - COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/build/include - COMMAND cmake -E copy target/libtaosws/taosws.h ${CMAKE_BINARY_DIR}/build/include - ) - ENDIF() + MESSAGE("${Green} use libtaos-ws${ColourReset}") + IF (TD_LINUX) + IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/taosws-rs/target/release/libtaosws.so" OR "${CMAKE_CURRENT_SOURCE_DIR}/taosws-rs/target/release/libtaosws.so" IS_NEWER_THAN "${CMAKE_SOURCE_DIR}/.git/modules/tools/taosws-rs/FETCH_HEAD") + include(ExternalProject) + ExternalProject_Add(taosws-rs + PREFIX "taosws-rs" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosws-rs + BUILD_ALWAYS off + DEPENDS taos + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND cmake -E echo "taosws-rs no need cmake to config" + PATCH_COMMAND + COMMAND git clean -f -d + BUILD_COMMAND + COMMAND cargo build --release -p taos-ws-sys + COMMAND ./taos-ws-sys/ci/package.sh + INSTALL_COMMAND + COMMAND cmake -E copy target/libtaosws/libtaosws.so ${CMAKE_BINARY_DIR}/build/lib + COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/build/include + COMMAND cmake -E copy target/libtaosws/taosws.h ${CMAKE_BINARY_DIR}/build/include + ) + ELSE() + include(ExternalProject) + ExternalProject_Add(taosws-rs + PREFIX "taosws-rs" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosws-rs + BUILD_ALWAYS on + DEPENDS taos + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND cmake -E echo "taosws-rs no need cmake to config" + PATCH_COMMAND + COMMAND git clean -f -d + BUILD_COMMAND + COMMAND cargo build --release -p taos-ws-sys + COMMAND ./taos-ws-sys/ci/package.sh + INSTALL_COMMAND + COMMAND cmake -E copy target/libtaosws/libtaosws.so ${CMAKE_BINARY_DIR}/build/lib + COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/build/include + COMMAND cmake -E copy target/libtaosws/taosws.h ${CMAKE_BINARY_DIR}/build/include + ) + ENDIF () + ENDIF() ENDIF () IF (TD_TAOS_TOOLS) diff --git a/tools/taos-tools b/tools/taos-tools index 9cb71e3c4c..3f42d428eb 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit 9cb71e3c4c0474553aa961cbe19795541c29b5c7 +Subproject commit 3f42d428eb6b90dea2651f4ccea66e44705c831b diff --git a/tools/taosws-rs b/tools/taosws-rs index 430982a0c2..7a94ffab45 160000 --- a/tools/taosws-rs +++ b/tools/taosws-rs @@ -1 +1 @@ -Subproject commit 430982a0c2c29a819ffc414d11f49f2d424ca3fe +Subproject commit 7a94ffab45f08e16f09b3f430fe75d717054adb6