diff --git a/docs/en/08-develop/01-connect/index.md b/docs/en/08-develop/01-connect/index.md index 916d5e1e09..ab35f6ad63 100644 --- a/docs/en/08-develop/01-connect/index.md +++ b/docs/en/08-develop/01-connect/index.md @@ -90,7 +90,7 @@ If `maven` is used to manage the projects, what needs to be done is only adding com.taosdata.jdbc taos-jdbcdriver - 3.3.0 + 3.3.2 ``` diff --git a/docs/en/14-reference/03-taos-sql/10-function.md b/docs/en/14-reference/03-taos-sql/10-function.md index 72ca878ce8..2ba3c416fd 100644 --- a/docs/en/14-reference/03-taos-sql/10-function.md +++ b/docs/en/14-reference/03-taos-sql/10-function.md @@ -1384,7 +1384,7 @@ SELECT SERVER_VERSION(); SELECT SERVER_STATUS(); ``` -**Description**: The server status. +**Description**: The server status. When checking the status of a cluster, the recommended way is to use `SHOW CLUSTER ALIVE;`. Unlike `SELECT SERVER_STATUS();`, it does not return an error when some nodes in the cluster are unavailable; instead, it returns different status codes. Plese check [SHOW CLUSTER ALIVE](https://docs.tdengine.com/reference/taos-sql/show/#show-cluster-alive) for details. ### CURRENT_USER diff --git a/docs/en/14-reference/05-connectors/14-java.mdx b/docs/en/14-reference/05-connectors/14-java.mdx index aa7e91b7fa..1f4cf9895f 100644 --- a/docs/en/14-reference/05-connectors/14-java.mdx +++ b/docs/en/14-reference/05-connectors/14-java.mdx @@ -42,6 +42,7 @@ REST connection supports all platforms that can run Java. | taos-jdbcdriver version | major changes | TDengine version | | :---------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------: | +| 3.3.2 | 1. Optimized websocket prepareStatement performance; 2. Improved mybatis support| - | | 3.3.0 | 1. Optimized data transmission performance under Websocket connection; 2. SSL validation skipping is supported but disabled by default| 3.3.2.0 or later | | 3.2.11 | Fixed the result set closing bug when using a native connection.| - | | 3.2.10 | 1. Automatic compression/decompression for data transmission, disabled by default; 2.Automatic reconnection for websocket with configurable parameter, disabled by default; 3. A new method for schemaless writing is added in the connection class; 4. Optimized performance for data fetching on native connection; 5. Fixing for some known issues; 6. The list of supported functions can be returned by the API for retrieving metadata| - | @@ -179,7 +180,7 @@ Add following dependency in the `pom.xml` file of your Maven project: com.taosdata.jdbc taos-jdbcdriver - 3.3.0 + 3.3.2 ``` diff --git a/docs/examples/JDBC/JDBCDemo/pom.xml b/docs/examples/JDBC/JDBCDemo/pom.xml index 763be51aff..a9b981a026 100644 --- a/docs/examples/JDBC/JDBCDemo/pom.xml +++ b/docs/examples/JDBC/JDBCDemo/pom.xml @@ -19,7 +19,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.0 + 3.3.2 org.locationtech.jts diff --git a/docs/examples/JDBC/connectionPools/pom.xml b/docs/examples/JDBC/connectionPools/pom.xml index 855d531f4c..a3705e6834 100644 --- a/docs/examples/JDBC/connectionPools/pom.xml +++ b/docs/examples/JDBC/connectionPools/pom.xml @@ -18,7 +18,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.0 + 3.3.2 diff --git a/docs/examples/JDBC/consumer-demo/pom.xml b/docs/examples/JDBC/consumer-demo/pom.xml index ad0f6cd6a1..0db41bc33f 100644 --- a/docs/examples/JDBC/consumer-demo/pom.xml +++ b/docs/examples/JDBC/consumer-demo/pom.xml @@ -17,7 +17,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.0 + 3.3.2 com.google.guava @@ -67,4 +67,4 @@ - \ No newline at end of file + diff --git a/docs/examples/JDBC/taosdemo/pom.xml b/docs/examples/JDBC/taosdemo/pom.xml index c73614948b..8e61cbecdf 100644 --- a/docs/examples/JDBC/taosdemo/pom.xml +++ b/docs/examples/JDBC/taosdemo/pom.xml @@ -67,7 +67,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.0 + 3.3.2 diff --git a/docs/examples/java/pom.xml b/docs/examples/java/pom.xml index 35fe5f280c..c44be4704d 100644 --- a/docs/examples/java/pom.xml +++ b/docs/examples/java/pom.xml @@ -22,7 +22,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.0 + 3.3.2 diff --git a/docs/zh/08-develop/01-connect/index.md b/docs/zh/08-develop/01-connect/index.md index d1aeb0ed8b..5cecd245e5 100644 --- a/docs/zh/08-develop/01-connect/index.md +++ b/docs/zh/08-develop/01-connect/index.md @@ -89,7 +89,7 @@ TDengine 提供了丰富的应用程序开发接口,为了便于用户快速 com.taosdata.jdbc taos-jdbcdriver - 3.3.0 + 3.3.2 ``` diff --git a/docs/zh/14-reference/03-taos-sql/03-table.md b/docs/zh/14-reference/03-taos-sql/03-table.md index 80aad0718a..2f0ae7100a 100644 --- a/docs/zh/14-reference/03-taos-sql/03-table.md +++ b/docs/zh/14-reference/03-taos-sql/03-table.md @@ -41,15 +41,13 @@ table_option: { **使用说明** +1. 表(列)名命名规则参见[名称命名规则](./19-limit.md#名称命名规则)。 +1. 表名最大长度为 192。 1. 表的第一个字段必须是 TIMESTAMP,并且系统自动将其设为主键。 -2. 除时间戳主键列之外,还可以通过 PRIMARY KEY 关键字指定第二列为额外的主键列。被指定为主键列的第二列必须为整型或字符串类型(varchar)。 -3. 表名最大长度为 192。 -4. 表的每行长度不能超过 48KB(从 3.0.5.0 版本开始为 64KB);(注意:每个 BINARY/NCHAR/GEOMETRY 类型的列还会额外占用 2 个字节的存储位置)。 -5. 子表名只能由字母、数字和下划线组成,且不能以数字开头,不区分大小写。 -6. 使用数据类型 BINARY/NCHAR/GEOMETRY,需指定其最长的字节数,如 BINARY(20),表示 20 字节。 -7. 为了兼容支持更多形式的表名,TDengine 引入新的转义符 "\`",可以让表名与关键词不冲突,同时不受限于上述表名称合法性约束检查。但是同样具有长度限制要求。使用转义字符以后,不再对转义字符中的内容进行大小写统一, - 例如:\`aBc\` 和 \`abc\` 是不同的表名,但是 abc 和 aBc 是相同的表名。 -8. 关于 `ENCODE` 和 `COMPRESS` 的使用,请参考[按列压缩](../compress) +1. 除时间戳主键列之外,还可以通过 PRIMARY KEY 关键字指定第二列为额外的主键列。被指定为主键列的第二列必须为整型或字符串类型(varchar)。 +1. 表的每行长度不能超过 48KB(从 3.0.5.0 版本开始为 64KB);(注意:每个 BINARY/NCHAR/GEOMETRY 类型的列还会额外占用 2 个字节的存储位置)。 +1. 使用数据类型 BINARY/NCHAR/GEOMETRY,需指定其最长的字节数,如 BINARY(20),表示 20 字节。 +1. 关于 `ENCODE` 和 `COMPRESS` 的使用,请参考[按列压缩](../compress) **参数说明** diff --git a/docs/zh/14-reference/03-taos-sql/10-function.md b/docs/zh/14-reference/03-taos-sql/10-function.md index ac9311184e..ee71abbdec 100644 --- a/docs/zh/14-reference/03-taos-sql/10-function.md +++ b/docs/zh/14-reference/03-taos-sql/10-function.md @@ -1374,7 +1374,7 @@ SELECT SERVER_VERSION(); SELECT SERVER_STATUS(); ``` -**说明**:检测服务端是否所有 dnode 都在线,如果是则返回成功,否则返回无法建立连接的错误。 +**说明**:检测服务端是否所有 dnode 都在线,如果是则返回成功,否则返回无法建立连接的错误。如果想要查询集群的状态,推荐使用 `SHOW CLUSTER ALIVE;`, 与 `SELECT SERVER_STATUS();` 不同,当集群中的部分节点不可用时,它不会返回错误,而是返回不同的状态码,详见:[SHOW CLUSTER ALIVE](https://docs.taosdata.com/reference/taos-sql/show/#show-cluster-alive) ### CURRENT_USER diff --git a/docs/zh/14-reference/03-taos-sql/19-limit.md b/docs/zh/14-reference/03-taos-sql/19-limit.md index 73107bf3ba..4e2fa69a14 100644 --- a/docs/zh/14-reference/03-taos-sql/19-limit.md +++ b/docs/zh/14-reference/03-taos-sql/19-limit.md @@ -6,13 +6,16 @@ description: 合法字符集和命名中的限制规则 ## 名称命名规则 -1. 合法字符:英文字符、数字和下划线 -2. 允许英文字符或下划线开头,不允许以数字开头 -3. 不区分大小写 -4. 转义后表(列)名规则: - 为了兼容支持更多形式的表(列)名,TDengine 引入新的转义符 "`"。使用转义字符以后,不再对转义字符中的内容进行大小写统一,即可以保留用户指定表名中的大小写属性。 - - 例如:\`aBc\` 和 \`abc\` 是不同的表(列)名,但是 abc 和 aBc 是相同的表(列)名。 +1. 合法字符:英文字符、数字和下划线。 +1. 允许英文字符或下划线开头,不允许以数字开头。 +1. 不区分大小写。 +1. 不能是[保留关键字](./20-keywords.md)。 +1. 转义后表(列)名规则: + 为了兼容支持更多形式的表(列)名,TDengine 引入新的转义符 "`"。使用转义字符以后: + - 不再对转义字符中的内容进行大小写统一,即可以保留用户指定表名中的大小写属性,例如:\`aBc\` 和 \`abc\` 是不同的表(列)名,但是 abc 和 aBc 是相同的表(列)名。 + - 可以创建包含字母、数字和下划线以外字符的表(列)名,例如:\`abc@TD\`,但是转义后名称中仍然不能包含`.`,否则会提示`The table name cannot contain '.'`。 + - 可以创建以数字开头的表(列)名,例如\`1970\`。 + - 可以创建以[保留关键字](./20-keywords.md)命名的表(列)名,例如\`select\`。 ## 密码合法字符集 @@ -37,22 +40,3 @@ description: 合法字符集和命名中的限制规则 - 用户密码的最大长度是 31 字节 - 总数据行数取决于可用资源 - 单个数据库的虚拟结点数上限为 1024 - -## 表(列)名合法性说明 - -### TDengine 中的表(列)名命名规则如下: - -只能由字母、数字、下划线构成,数字不能在首位,长度不能超过 192 字节,不区分大小写。这里表名称不包括数据库名的前缀和分隔符。 - -### 转义后表(列)名规则: - -为了兼容支持更多形式的表(列)名,TDengine 引入新的转义符 "`",可以避免表名与关键词的冲突,转义符不计入表名的长度。 -转义后的表(列)名同样受到长度限制要求,且长度计算的时候不计算转义符。使用转义字符以后,不再对转义字符中的内容进行大小写统一。 - -例如: -\`aBc\` 和 \`abc\` 是不同的表(列)名,但是 abc 和 aBc 是相同的表(列)名。 - -:::note -转义字符中的内容必须符合命名规则中的字符约束。 - -::: diff --git a/docs/zh/14-reference/05-connector/14-java.mdx b/docs/zh/14-reference/05-connector/14-java.mdx index 5f95233163..ec24f1329d 100644 --- a/docs/zh/14-reference/05-connector/14-java.mdx +++ b/docs/zh/14-reference/05-connector/14-java.mdx @@ -33,6 +33,7 @@ REST 连接支持所有能运行 Java 的平台。 | taos-jdbcdriver 版本 | 主要变化 | TDengine 版本 | | :------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------: | +| 3.3.2 | 1. 优化 Websocket 连接下的参数绑定性能;2. 优化了对 mybatis 的支持 | - | | 3.3.0 | 1. 优化 Websocket 连接下的数据传输性能;2. 支持跳过 SSL 验证,默认关闭 | 3.3.2.0 及更高版本 | | 3.2.11 | 解决了 Native 连接关闭结果集 bug | - | | 3.2.10 | 1. REST/WebSocket 连接支持传输中的数据压缩;2. Websocket 自动重连机制,默认关闭;3. Connection 类提供无模式写入的方法;4. 优化了原生连接的数据拉取性能;5. 修复了一些已知问题;6.元数据获取函数可以返回支持的函数列表。 | - | diff --git a/include/client/taos.h b/include/client/taos.h index 1cd0a44315..9ed577166c 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -51,7 +51,7 @@ typedef void TAOS_SUB; #define TSDB_DATA_TYPE_BLOB 18 // binary #define TSDB_DATA_TYPE_MEDIUMBLOB 19 #define TSDB_DATA_TYPE_BINARY TSDB_DATA_TYPE_VARCHAR // string -#define TSDB_DATA_TYPE_GEOMETRY 20 // geometry +#define TSDB_DATA_TYPE_GEOMETRY 20 // geometry #define TSDB_DATA_TYPE_MAX 21 typedef enum { @@ -168,7 +168,7 @@ DLL_EXPORT const char *taos_data_type(int type); DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos); DLL_EXPORT TAOS_STMT *taos_stmt_init_with_reqid(TAOS *taos, int64_t reqid); -DLL_EXPORT TAOS_STMT *taos_stmt_init_with_options(TAOS *taos, TAOS_STMT_OPTIONS* options); +DLL_EXPORT TAOS_STMT *taos_stmt_init_with_options(TAOS *taos, TAOS_STMT_OPTIONS *options); DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags); DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name); @@ -193,6 +193,49 @@ DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt); +typedef void TAOS_STMT2; + +typedef enum { + TAOS_FIELD_COL = 1, + TAOS_FIELD_TAG, + TAOS_FIELD_QUERY, + TAOS_FIELD_TBNAME, +} TAOS_FIELD_T; + +typedef struct { + int64_t reqid; + bool singleStbInsert; + bool singleTableBindOnce; + __taos_async_fn_t asyncExecFn; + void *userdata; +} TAOS_STMT2_OPTION; + +typedef struct { + int buffer_type; + void *buffer; + int32_t *length; + char *is_null; + int num; +} TAOS_STMT2_BIND; + +typedef struct { + int count; + char **tbnames; + TAOS_STMT2_BIND **tags; + TAOS_STMT2_BIND **bind_cols; +} TAOS_STMT2_BINDV; + +DLL_EXPORT TAOS_STMT2 *taos_stmt2_init(TAOS *taos, TAOS_STMT2_OPTION *option); +DLL_EXPORT int taos_stmt2_prepare(TAOS_STMT2 *stmt, const char *sql, unsigned long length); +DLL_EXPORT int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx); +DLL_EXPORT int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows); +DLL_EXPORT int taos_stmt2_close(TAOS_STMT2 *stmt); +DLL_EXPORT int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert); +DLL_EXPORT int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields); +DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields); +DLL_EXPORT TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt); +DLL_EXPORT char *taos_stmt2_error(TAOS_STMT2 *stmt); + DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); DLL_EXPORT TAOS_RES *taos_query_with_reqid(TAOS *taos, const char *sql, int64_t reqId); @@ -246,14 +289,15 @@ DLL_EXPORT void taos_set_hb_quit(int8_t quitByKill); DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type); -typedef void (*__taos_async_whitelist_fn_t)(void *param, int code, TAOS *taos, int numOfWhiteLists, uint64_t* pWhiteLists); +typedef void (*__taos_async_whitelist_fn_t)(void *param, int code, TAOS *taos, int numOfWhiteLists, + uint64_t *pWhiteLists); DLL_EXPORT void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param); typedef enum { TAOS_CONN_MODE_BI = 0, } TAOS_CONN_MODE; -DLL_EXPORT int taos_set_conn_mode(TAOS* taos, int mode, int value); +DLL_EXPORT int taos_set_conn_mode(TAOS *taos, int mode, int value); /* --------------------------schemaless INTERFACE------------------------------- */ DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); @@ -271,10 +315,13 @@ DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int int precision, int32_t ttl); DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, int precision, int32_t ttl, int64_t reqid); -DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows, - int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey); -DLL_EXPORT TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol, - int precision, int32_t ttl, int64_t reqid, char *tbnameKey); +DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, + int32_t *totalRows, int protocol, + int precision, int32_t ttl, int64_t reqid, + char *tbnameKey); +DLL_EXPORT TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, + int protocol, int precision, int32_t ttl, + int64_t reqid, char *tbnameKey); /* --------------------------TMQ INTERFACE------------------------------- */ typedef struct tmq_t tmq_t; @@ -320,14 +367,17 @@ DLL_EXPORT int32_t tmq_unsubscribe(tmq_t *tmq); DLL_EXPORT int32_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics); DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout); DLL_EXPORT int32_t tmq_consumer_close(tmq_t *tmq); -DLL_EXPORT int32_t tmq_commit_sync(tmq_t *tmq, const TAOS_RES *msg); //Commit the msg’s offset + 1 +DLL_EXPORT int32_t tmq_commit_sync(tmq_t *tmq, const TAOS_RES *msg); // Commit the msg’s offset + 1 DLL_EXPORT void tmq_commit_async(tmq_t *tmq, const TAOS_RES *msg, tmq_commit_cb *cb, void *param); DLL_EXPORT int32_t tmq_commit_offset_sync(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset); -DLL_EXPORT void tmq_commit_offset_async(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset, tmq_commit_cb *cb, void *param); -DLL_EXPORT int32_t tmq_get_topic_assignment(tmq_t *tmq, const char *pTopicName, tmq_topic_assignment **assignment,int32_t *numOfAssignment); -DLL_EXPORT void tmq_free_assignment(tmq_topic_assignment* pAssignment); +DLL_EXPORT void tmq_commit_offset_async(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset, + tmq_commit_cb *cb, void *param); +DLL_EXPORT int32_t tmq_get_topic_assignment(tmq_t *tmq, const char *pTopicName, tmq_topic_assignment **assignment, + int32_t *numOfAssignment); +DLL_EXPORT void tmq_free_assignment(tmq_topic_assignment *pAssignment); DLL_EXPORT int32_t tmq_offset_seek(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset); -DLL_EXPORT int64_t tmq_position(tmq_t *tmq, const char *pTopicName, int32_t vgId); // The current offset is the offset of the last consumed message + 1 +DLL_EXPORT int64_t tmq_position(tmq_t *tmq, const char *pTopicName, + int32_t vgId); // The current offset is the offset of the last consumed message + 1 DLL_EXPORT int64_t tmq_committed(tmq_t *tmq, const char *pTopicName, int32_t vgId); DLL_EXPORT TAOS *tmq_get_connect(tmq_t *tmq); @@ -336,7 +386,7 @@ DLL_EXPORT tmq_res_t tmq_get_res_type(TAOS_RES *res); 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 int64_t tmq_get_vgroup_offset(TAOS_RES* res); +DLL_EXPORT int64_t tmq_get_vgroup_offset(TAOS_RES *res); DLL_EXPORT const char *tmq_err2str(int32_t code); /* ------------------------------ TAOSX INTERFACE -----------------------------------*/ @@ -346,15 +396,16 @@ typedef struct tmq_raw_data { uint16_t raw_type; } tmq_raw_data; -DLL_EXPORT int32_t tmq_get_raw(TAOS_RES *res, tmq_raw_data *raw); -DLL_EXPORT int32_t tmq_write_raw(TAOS *taos, tmq_raw_data raw); -DLL_EXPORT int taos_write_raw_block(TAOS *taos, int numOfRows, char *pData, const char *tbname); -DLL_EXPORT int taos_write_raw_block_with_reqid(TAOS *taos, int numOfRows, char *pData, const char *tbname, int64_t reqid); -DLL_EXPORT int taos_write_raw_block_with_fields(TAOS *taos, int rows, char *pData, const char *tbname, - TAOS_FIELD *fields, int numFields); -DLL_EXPORT int taos_write_raw_block_with_fields_with_reqid(TAOS *taos, int rows, char *pData, const char *tbname, - TAOS_FIELD *fields, int numFields, int64_t reqid); -DLL_EXPORT void tmq_free_raw(tmq_raw_data raw); +DLL_EXPORT int32_t tmq_get_raw(TAOS_RES *res, tmq_raw_data *raw); +DLL_EXPORT int32_t tmq_write_raw(TAOS *taos, tmq_raw_data raw); +DLL_EXPORT int taos_write_raw_block(TAOS *taos, int numOfRows, char *pData, const char *tbname); +DLL_EXPORT int taos_write_raw_block_with_reqid(TAOS *taos, int numOfRows, char *pData, const char *tbname, + int64_t reqid); +DLL_EXPORT int taos_write_raw_block_with_fields(TAOS *taos, int rows, char *pData, const char *tbname, + TAOS_FIELD *fields, int numFields); +DLL_EXPORT int taos_write_raw_block_with_fields_with_reqid(TAOS *taos, int rows, char *pData, const char *tbname, + TAOS_FIELD *fields, int numFields, int64_t reqid); +DLL_EXPORT void tmq_free_raw(tmq_raw_data raw); // Returning null means error. Returned result need to be freed by tmq_free_json_meta DLL_EXPORT char *tmq_get_json_meta(TAOS_RES *res); @@ -370,7 +421,7 @@ typedef enum { } TSDB_SERVER_STATUS; DLL_EXPORT TSDB_SERVER_STATUS taos_check_server_status(const char *fqdn, int port, char *details, int maxlen); -DLL_EXPORT char* getBuildInfo(); +DLL_EXPORT char *getBuildInfo(); #ifdef __cplusplus } #endif diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index b4dd6d61e4..22a43012c5 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -41,7 +41,7 @@ typedef struct SBlockOrderInfo { #define BMCharPos(bm_, r_) ((bm_)[(r_) >> NBIT]) #define colDataIsNull_f(bm_, r_) ((BMCharPos(bm_, r_) & (1u << (7u - BitPos(r_)))) == (1u << (7u - BitPos(r_)))) -#define QRY_OPTR_CHECK(_o) \ +#define QRY_PARAM_CHECK(_o) \ do { \ if ((_o) == NULL) { \ return TSDB_CODE_INVALID_PARA; \ diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 4d6d69b178..1179e710cd 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -378,6 +378,19 @@ typedef struct { int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema, SArray *rowArray); +// stmt2 binding +int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen); + +typedef struct { + int32_t columnId; + int32_t type; + int32_t bytes; + TAOS_STMT2_BIND *bind; +} SBindInfo2; + +int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema, + SArray *rowArray); + #endif #ifdef __cplusplus diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 09143dde29..ed56b7e6b2 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -166,6 +166,8 @@ int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bo int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pBlock, uint64_t* useconds); +void qResetTaskCode(qTaskInfo_t tinfo); + void qCleanExecTaskBlockBuf(qTaskInfo_t tinfo); /** diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index a808fccc4a..7271da8ff6 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -20,9 +20,9 @@ extern "C" { #endif +#include "catalog.h" #include "query.h" #include "querynodes.h" -#include "catalog.h" typedef struct SStmtCallback { TAOS_STMT* pStmt; @@ -37,15 +37,15 @@ typedef enum { } SParseResType; typedef struct SParseSchemaRes { - int8_t precision; - int32_t numOfCols; - SSchema* pSchema; + int8_t precision; + int32_t numOfCols; + SSchema* pSchema; } SParseSchemaRes; typedef struct SParseQueryRes { - SNode* pQuery; - SCatalogReq* pCatalogReq; - SMetaData meta; + SNode* pQuery; + SCatalogReq* pCatalogReq; + SMetaData meta; } SParseQueryRes; typedef struct SParseSqlRes { @@ -124,11 +124,13 @@ int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid); int32_t qInitKeywordsTable(); void qCleanupKeywordsTable(); -int32_t qAppendStmtTableOutput(SQuery* pQuery, SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo); -int32_t qBuildStmtFinOutput(SQuery* pQuery, SHashObj* pAllVgHash, SArray* pVgDataBlocks); -//int32_t qBuildStmtOutputFromTbList(SQuery* pQuery, SHashObj* pVgHash, SArray* pBlockList, STableDataCxt* pTbCtx, int32_t tbNum); +int32_t qAppendStmtTableOutput(SQuery* pQuery, SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, + SStbInterlaceInfo* pBuildInfo); +int32_t qBuildStmtFinOutput(SQuery* pQuery, SHashObj* pAllVgHash, SArray* pVgDataBlocks); +// int32_t qBuildStmtOutputFromTbList(SQuery* pQuery, SHashObj* pVgHash, SArray* pBlockList, STableDataCxt* pTbCtx, +// int32_t tbNum); int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash); -int32_t qResetStmtColumns(SArray* pCols, bool deepClear); +int32_t qResetStmtColumns(SArray* pCols, bool deepClear); int32_t qResetStmtDataBlock(STableDataCxt* block, bool keepBuf); int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset); int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, @@ -139,39 +141,51 @@ int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx); int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery); -int32_t qBindStmtStbColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, STSchema** pTSchema, SBindInfo* pBindInfos); +int32_t qBindStmtStbColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, + STSchema** pTSchema, SBindInfo* pBindInfos); int32_t qBindStmtColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen); -int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx, - int32_t rowNum); +int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, + int32_t colIdx, int32_t rowNum); int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD_E** fields); int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields); int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen); + +int32_t qStmtBindParams2(SQuery* pQuery, TAOS_STMT2_BIND* pParams, int32_t colIdx); +int32_t qBindStmtStbColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen, + STSchema** pTSchema, SBindInfo2* pBindInfos); +int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen); +int32_t qBindStmtSingleColValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen, + int32_t colIdx, int32_t rowNum); +int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName, + TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen); + void destroyBoundColumnInfo(void* pBoundInfo); int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf, int32_t msgBufLen); void qDestroyBoundColInfo(void* pInfo); -int32_t smlInitHandle(SQuery** query); -int32_t smlBuildRow(STableDataCxt* pTableCxt); -int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* kv, int32_t index); -int32_t smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta, STableDataCxt** cxt); +int32_t smlInitHandle(SQuery** query); +int32_t smlBuildRow(STableDataCxt* pTableCxt); +int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* kv, int32_t index); +int32_t smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta, STableDataCxt** cxt); void clearColValArraySml(SArray* pCols); int32_t smlBindData(SQuery* handle, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols, STableMeta* pTableMeta, char* tableName, const char* sTableName, int32_t sTableNameLen, int32_t ttl, char* msgBuf, int32_t msgBufLen); int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash); -int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCreateTbReq** pCreateTb, TAOS_FIELD *fields, - int numFields, bool needChangeLength, char* errstr, int32_t errstrLen); +int rawBlockBindData(SQuery* query, STableMeta* pTableMeta, void* data, SVCreateTbReq** pCreateTb, TAOS_FIELD* fields, + int numFields, bool needChangeLength, char* errstr, int32_t errstrLen); int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray); int32_t serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap, SArray** pOut); int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut); -void destoryCatalogReq(SCatalogReq *pCatalogReq); +void destoryCatalogReq(SCatalogReq* pCatalogReq); bool isPrimaryKeyImpl(SNode* pExpr); -int32_t insAppendStmtTableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo); +int32_t insAppendStmtTableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, + SStbInterlaceInfo* pBuildInfo); #ifdef __cplusplus } diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 20f91106a5..31b9f62346 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -705,7 +705,7 @@ int32_t streamTaskSetActiveCheckpointInfo(SStreamTask* pTask, int64_t activeChec void streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId); bool streamTaskAlreadySendTrigger(SStreamTask* pTask, int32_t downstreamNodeId); void streamTaskGetTriggerRecvStatus(SStreamTask* pTask, int32_t* pRecved, int32_t* pTotal); -void streamTaskInitTriggerDispatchInfo(SStreamTask* pTask); +int32_t streamTaskInitTriggerDispatchInfo(SStreamTask* pTask); void streamTaskSetTriggerDispatchConfirmed(SStreamTask* pTask, int32_t vgId); int32_t streamTaskSendCheckpointTriggerMsg(SStreamTask* pTask, int32_t dstTaskId, int32_t downstreamNodeId, SRpcHandleInfo* pInfo, int32_t code); @@ -810,6 +810,7 @@ int32_t streamTaskBuildCheckpointSourceRsp(SStreamCheckpointSourceReq* pReq, SRp int32_t streamSendChkptReportMsg(SStreamTask* pTask, SCheckpointInfo* pCheckpointInfo, int8_t dropRelHTask); int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SVUpdateCheckpointInfoReq* pReq); int32_t streamTaskCreateActiveChkptInfo(SActiveCheckpointInfo** pRes); +void streamTaskSetCheckpointFailed(SStreamTask* pTask); // stream task state machine, and event handling int32_t streamCreateStateMachine(SStreamTask* pTask); diff --git a/source/client/inc/clientStmt2.h b/source/client/inc/clientStmt2.h new file mode 100644 index 0000000000..74eb198930 --- /dev/null +++ b/source/client/inc/clientStmt2.h @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_CLIENTSTMT2_H +#define TDENGINE_CLIENTSTMT2_H + +#ifdef __cplusplus +extern "C" { +#endif +#include "catalog.h" +/* +typedef enum { +STMT_TYPE_INSERT = 1, +STMT_TYPE_MULTI_INSERT, +STMT_TYPE_QUERY, +} STMT_TYPE; + +typedef enum { +STMT_INIT = 1, +STMT_PREPARE, +STMT_SETTBNAME, +STMT_SETTAGS, +STMT_FETCH_FIELDS, +STMT_BIND, +STMT_BIND_COL, +STMT_ADD_BATCH, +STMT_EXECUTE, +STMT_MAX, +} STMT_STATUS; + +#define STMT_TABLE_COLS_NUM 1000 + +typedef struct SStmtTableCache { +STableDataCxt *pDataCtx; +void *boundTags; +} SStmtTableCache; + +typedef struct SStmtQueryResInfo { +TAOS_FIELD *fields; +TAOS_FIELD *userFields; +uint32_t numOfCols; +int32_t precision; +} SStmtQueryResInfo; + +typedef struct SStmtBindInfo { +bool needParse; +bool inExecCache; +uint64_t tbUid; +uint64_t tbSuid; +int32_t tbVgId; +int32_t sBindRowNum; +int32_t sBindLastIdx; +int8_t tbType; +bool tagsCached; +void *boundTags; +char tbName[TSDB_TABLE_FNAME_LEN]; +char tbFName[TSDB_TABLE_FNAME_LEN]; +char stbFName[TSDB_TABLE_FNAME_LEN]; +SName sname; + +char statbName[TSDB_TABLE_FNAME_LEN]; +} SStmtBindInfo; + +typedef struct SStmtAsyncParam { +STableColsData *pTbData; +void* pStmt; +} SStmtAsyncParam; + +typedef struct SStmtExecInfo { +int32_t affectedRows; +SRequestObj *pRequest; +SHashObj *pBlockHash; +STableDataCxt *pCurrBlock; +SSubmitTbData *pCurrTbData; +} SStmtExecInfo; +*/ +typedef struct { + bool stbInterlaceMode; + STMT_TYPE type; + STMT_STATUS status; + uint64_t suid; + uint64_t runTimes; + SHashObj *pTableCache; // SHash + SQuery *pQuery; + char *sqlStr; + int32_t sqlLen; + SArray *nodeList; + SStmtQueryResInfo queryRes; + bool autoCreateTbl; + SHashObj *pVgHash; + SBindInfo2 *pBindInfo; + + SStbInterlaceInfo siInfo; +} SStmtSQLInfo2; +/* +typedef struct SStmtStatInfo { +int64_t ctgGetTbMetaNum; +int64_t getCacheTbInfo; +int64_t parseSqlNum; +int64_t bindDataNum; +int64_t setTbNameUs; +int64_t bindDataUs1; +int64_t bindDataUs2; +int64_t bindDataUs3; +int64_t bindDataUs4; +int64_t addBatchUs; +int64_t execWaitUs; +int64_t execUseUs; +} SStmtStatInfo; + +typedef struct SStmtQNode { +bool restoreTbCols; +STableColsData tblData; +struct SStmtQNode* next; +} SStmtQNode; + +typedef struct SStmtQueue { +bool stopQueue; +SStmtQNode* head; +SStmtQNode* tail; +uint64_t qRemainNum; +} SStmtQueue; +*/ + +typedef struct { + STscObj *taos; + SCatalog *pCatalog; + int32_t affectedRows; + uint32_t seqId; + uint32_t seqIds[STMT_MAX]; + bool bindThreadInUse; + TdThread bindThread; + TAOS_STMT2_OPTION options; + bool stbInterlaceMode; + SStmtQueue queue; + + SStmtSQLInfo2 sql; + SStmtExecInfo exec; + SStmtBindInfo bInfo; + + int64_t reqid; + int32_t errCode; + tsem_t asyncQuerySem; + + SStmtStatInfo stat; +} STscStmt2; +/* +extern char *gStmtStatusStr[]; + +#define STMT_LOG_SEQ(n) \ +do { \ + (pStmt)->seqId++; \ + (pStmt)->seqIds[n]++; \ + STMT_DLOG("the %dth:%d %s", (pStmt)->seqIds[n], (pStmt)->seqId, gStmtStatusStr[n]); \ +} while (0) + +#define STMT_STATUS_NE(S) (pStmt->sql.status != STMT_##S) +#define STMT_STATUS_EQ(S) (pStmt->sql.status == STMT_##S) + +#define STMT_ERR_RET(c) \ +do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + pStmt->errCode = _code; \ + return _code; \ + } \ +} while (0) +#define STMT_RET(c) \ +do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + pStmt->errCode = _code; \ + } \ + return _code; \ +} while (0) +#define STMT_ERR_JRET(c) \ +do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + pStmt->errCode = code; \ + goto _return; \ + } \ +} while (0) +#define STMT_ERRI_JRET(c) \ +do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ +} while (0) + + +#define STMT_FLOG(param, ...) qFatal("stmt:%p " param, pStmt, __VA_ARGS__) +#define STMT_ELOG(param, ...) qError("stmt:%p " param, pStmt, __VA_ARGS__) +#define STMT_DLOG(param, ...) qDebug("stmt:%p " param, pStmt, __VA_ARGS__) + +#define STMT_ELOG_E(param) qError("stmt:%p " param, pStmt) +#define STMT_DLOG_E(param) qDebug("stmt:%p " param, pStmt) +*/ +TAOS_STMT2 *stmtInit2(STscObj *taos, TAOS_STMT2_OPTION *pOptions); +int stmtClose2(TAOS_STMT2 *stmt); +int stmtExec2(TAOS_STMT2 *stmt, int *affected_rows); +int stmtPrepare2(TAOS_STMT2 *stmt, const char *sql, unsigned long length); +int stmtSetTbName2(TAOS_STMT2 *stmt, const char *tbName); +int stmtSetTbTags2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *tags); +int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx); +int stmtGetTagFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields); +int stmtGetColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields); +int stmtGetParamNum2(TAOS_STMT2 *stmt, int *nums); +int stmtGetParamTbName(TAOS_STMT2 *stmt, int *nums); +int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert); +TAOS_RES *stmtUseResult2(TAOS_STMT2 *stmt); +const char *stmtErrstr2(TAOS_STMT2 *stmt); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_CLIENTSTMT2_H diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 3c2729c029..fec1060042 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -687,7 +687,9 @@ void doDestroyRequest(void *p) { taosMemoryFreeClear(pRequest->msgBuf); doFreeReqResultInfo(&pRequest->body.resInfo); - (void)tsem_destroy(&pRequest->body.rspSem); + if (TSDB_CODE_SUCCESS != tsem_destroy(&pRequest->body.rspSem)) { + tscError("failed to destroy semaphore"); + } taosArrayDestroy(pRequest->tableList); taosArrayDestroy(pRequest->targetTableList); @@ -700,7 +702,9 @@ void doDestroyRequest(void *p) { taosMemoryFreeClear(pRequest->pDb); taosArrayDestroy(pRequest->dbList); if (pRequest->body.interParam) { - (void)tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem); + if (TSDB_CODE_SUCCESS != tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem)) { + tscError("failed to destroy semaphore in pRequest"); + } } taosMemoryFree(pRequest->body.interParam); diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 5d3892d5e0..47b80c03d1 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -1636,7 +1636,9 @@ void hbDeregisterConn(STscObj *pTscObj, SClientHbKey connKey) { SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey)); if (pReq) { tFreeClientHbReq(pReq); - (void)taosHashRemove(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey)); + if (TSDB_CODE_SUCCESS != taosHashRemove(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey))) { + tscError("failed to remove connKey from activeInfo"); + } taosHashRelease(pAppHbMgr->activeInfo, pReq); (void)atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1); } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index a208cedd65..34a82d4c42 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -209,7 +209,9 @@ _return: void freeQueryParam(SSyncQueryParam* param) { if (param == NULL) return; - (void)tsem_destroy(¶m->sem); + if (TSDB_CODE_SUCCESS != tsem_destroy(¶m->sem)) { + tscError("failed to destroy semaphore in freeQueryParam"); + } taosMemoryFree(param); } @@ -351,7 +353,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { // int64_t transporterId = 0; TSC_ERR_RET(asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, NULL, pSendMsg)); - (void)tsem_wait(&pRequest->body.rspSem); + TSC_ERR_RET(tsem_wait(&pRequest->body.rspSem)); return TSDB_CODE_SUCCESS; } @@ -1165,14 +1167,18 @@ void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) { if (code != TSDB_CODE_SUCCESS && NEED_CLIENT_HANDLE_ERROR(code) && pRequest->sqlstr != NULL) { tscDebug("0x%" PRIx64 " client retry to handle the error, code:%s, tryCount:%d,QID:0x%" PRIx64, pRequest->self, tstrerror(code), pRequest->retry, pRequest->requestId); - (void)removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); + if (TSDB_CODE_SUCCESS != removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type))) { + tscError("0x%" PRIx64 " remove meta failed,QID:0x%" PRIx64, pRequest->self, pRequest->requestId); + } restartAsyncQuery(pRequest, code); return; } tscDebug("schedulerExecCb request type %s", TMSG_INFO(pRequest->type)); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type) && NULL == pRequest->body.resInfo.execRes.res) { - (void)removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); + if (TSDB_CODE_SUCCESS != removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type))) { + tscError("0x%" PRIx64 " remove meta failed,QID:0x%" PRIx64, pRequest->self, pRequest->requestId); + } } pRequest->metric.execCostUs = taosGetTimestampUs() - pRequest->metric.execStart; @@ -1266,7 +1272,10 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue } if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type) && NULL == pRequest->body.resInfo.execRes.res) { - (void)removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); + code = removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); + if (TSDB_CODE_SUCCESS != code) { + tscError("0x%" PRIx64 " remove meta failed,QID:0x%" PRIx64, pRequest->self, pRequest->requestId); + } } if (TSDB_CODE_SUCCESS == code) { @@ -1479,12 +1488,12 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList, bool isView) { continue; } (void)tNameGetFullDbName(pViewName, dbFName); - (void)catalogRemoveViewMeta(pCatalog, dbFName, 0, pViewName->tname, 0); + TSC_ERR_RET(catalogRemoveViewMeta(pCatalog, dbFName, 0, pViewName->tname, 0)); } } else { for (int32_t i = 0; i < tbNum; ++i) { SName* pTbName = taosArrayGet(tbList, i); - (void)catalogRemoveTableMeta(pCatalog, pTbName); + TSC_ERR_RET(catalogRemoveTableMeta(pCatalog, pTbName)); } } @@ -1584,7 +1593,11 @@ int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __ta tscError("failed to send connect msg to server, code:%s", tstrerror(code)); return code; } - (void)tsem_wait(&pRequest->body.rspSem); + if (TSDB_CODE_SUCCESS != tsem_wait(&pRequest->body.rspSem)) { + destroyTscObj(*pTscObj); + tscError("failed to wait sem, code:%s", terrstr()); + return terrno; + } if (pRequest->code != TSDB_CODE_SUCCESS) { const char* errorMsg = (code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(pRequest->code); tscError("failed to connect to server, reason: %s", errorMsg); @@ -1736,7 +1749,9 @@ int32_t doProcessMsgFromServer(void* param) { tscError("doProcessMsgFromServer pRequest->self:%" PRId64 " != pSendInfo->requestObjRefId:%" PRId64, pRequest->self, pSendInfo->requestObjRefId); - (void)taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); + if (TSDB_CODE_SUCCESS != taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId)) { + tscError("doProcessMsgFromServer taosReleaseRef failed"); + } taosMemoryFree(arg->pEpset); rpcFreeCont(pMsg->pCont); destroySendMsgInfo(pSendInfo); @@ -1769,7 +1784,12 @@ int32_t doProcessMsgFromServer(void* param) { (void)pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); if (pTscObj) { - (void)taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); + int32_t code = taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); + if (TSDB_CODE_SUCCESS != code) { + tscError("doProcessMsgFromServer taosReleaseRef failed"); + terrno = code; + pMsg->code = code; + } } rpcFreeCont(pMsg->pCont); @@ -1946,7 +1966,9 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) static void syncFetchFn(void* param, TAOS_RES* res, int32_t numOfRows) { tsem_t* sem = param; - (void)tsem_post(sem); + if (TSDB_CODE_SUCCESS != tsem_post(sem)) { + tscError("failed to post sem, code:%s", terrstr()); + } } void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) { @@ -1965,10 +1987,16 @@ void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertU // convert ucs4 to native multi-bytes string pResultInfo->convertUcs4 = convertUcs4; tsem_t sem; - (void)tsem_init(&sem, 0, 0); + if (TSDB_CODE_SUCCESS != tsem_init(&sem, 0, 0)) { + tscError("failed to init sem, code:%s", terrstr()); + } taos_fetch_rows_a(pRequest, syncFetchFn, &sem); - (void)tsem_wait(&sem); - (void)tsem_destroy(&sem); + if (TSDB_CODE_SUCCESS != tsem_wait(&sem)) { + tscError("failed to wait sem, code:%s", terrstr()); + } + if (TSDB_CODE_SUCCESS != tsem_destroy(&sem)) { + tscError("failed to destroy sem, code:%s", terrstr()); + } pRequest->inCallback = false; } @@ -2742,7 +2770,9 @@ void syncCatalogFn(SMetaData* pResult, void* param, int32_t code) { SSyncQueryParam* pParam = param; pParam->pRequest->code = code; - (void)tsem_post(&pParam->sem); + if (TSDB_CODE_SUCCESS != tsem_post(&pParam->sem)) { + tscError("failed to post semaphore since %s", tstrerror(terrno)); + } } void syncQueryFn(void* param, void* res, int32_t code) { @@ -2753,7 +2783,9 @@ void syncQueryFn(void* param, void* res, int32_t code) { pParam->pRequest->code = code; } - (void)tsem_post(&pParam->sem); + if (TSDB_CODE_SUCCESS != tsem_post(&pParam->sem)) { + tscError("failed to post semaphore since %s", tstrerror(terrno)); + } } void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly, @@ -2831,10 +2863,20 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly, int8_t s terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - (void)tsem_init(¶m->sem, 0, 0); + int32_t code = tsem_init(¶m->sem, 0, 0); + if (TSDB_CODE_SUCCESS != code) { + terrno = code; + taosMemoryFree(param); + return NULL; + } taosAsyncQueryImpl(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, source); - (void)tsem_wait(¶m->sem); + code = tsem_wait(¶m->sem); + if (TSDB_CODE_SUCCESS != code) { + terrno = code; + taosMemoryFree(param); + return NULL; + } SRequestObj* pRequest = NULL; if (param->pRequest != NULL) { @@ -2860,10 +2902,20 @@ TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly, terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - (void)tsem_init(¶m->sem, 0, 0); + int32_t code = tsem_init(¶m->sem, 0, 0); + if (TSDB_CODE_SUCCESS != code) { + terrno = code; + taosMemoryFree(param); + return NULL; + } taosAsyncQueryImplWithReqid(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, reqid); - (void)tsem_wait(¶m->sem); + code = tsem_wait(¶m->sem); + if (TSDB_CODE_SUCCESS != code) { + terrno = code; + taosMemoryFree(param); + return NULL; + } SRequestObj* pRequest = NULL; if (param->pRequest != NULL) { param->pRequest->syncQuery = true; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 7439aa64d3..78135b245f 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -18,6 +18,7 @@ #include "clientLog.h" #include "clientMonitor.h" #include "clientStmt.h" +#include "clientStmt2.h" #include "functionMgt.h" #include "os.h" #include "query.h" @@ -312,7 +313,9 @@ void taos_close_internal(void *taos) { STscObj *pTscObj = (STscObj *)taos; tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs); - (void)taosRemoveRef(clientConnRefPool, pTscObj->id); + if (TSDB_CODE_SUCCESS != taosRemoveRef(clientConnRefPool, pTscObj->id)) { + tscError("0x%" PRIx64 " failed to remove ref from conn pool", pTscObj->id); + } } void taos_close(TAOS *taos) { @@ -1307,7 +1310,10 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { if (NEED_CLIENT_HANDLE_ERROR(code)) { tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d,QID:0x%" PRIx64, pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId); - (void)refreshMeta(pRequest->pTscObj, pRequest); // ignore return code,try again + if (TSDB_CODE_SUCCESS != refreshMeta(pRequest->pTscObj, pRequest)) { + tscWarn("0x%" PRIx64 " refresh meta failed, code:%d - %s,QID:0x%" PRIx64, pRequest->self, code, + tstrerror(code), pRequest->requestId); + } pRequest->prevCode = code; doAsyncQuery(pRequest, true); return; @@ -1608,8 +1614,11 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { } SSyncQueryParam *pParam = pRequest->body.interParam; - (void)tsem_wait(&pParam->sem); - + code = tsem_wait(&pParam->sem); + if (code) { + tscError("tsem wait failed, code:%d - %s", code, tstrerror(code)); + goto _return; + } _return: destoryCatalogReq(&catalogReq); destroyRequest(pRequest); @@ -1909,6 +1918,160 @@ int taos_stmt_close(TAOS_STMT *stmt) { return stmtClose(stmt); } +TAOS_STMT2 *taos_stmt2_init(TAOS *taos, TAOS_STMT2_OPTION *option) { + STscObj *pObj = acquireTscObj(*(int64_t *)taos); + if (NULL == pObj) { + tscError("invalid parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + + TAOS_STMT2 *pStmt = stmtInit2(pObj, option); + + releaseTscObj(*(int64_t *)taos); + + return pStmt; +} + +int taos_stmt2_prepare(TAOS_STMT2 *stmt, const char *sql, unsigned long length) { + if (stmt == NULL || sql == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtPrepare2(stmt, sql, length); +} + +int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx) { + if (stmt == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + int32_t code = 0; + for (int i = 0; i < bindv->count; ++i) { + if (bindv->tbnames && bindv->tbnames[i]) { + code = stmtSetTbName2(stmt, bindv->tbnames[i]); + if (code) { + return code; + } + } + + if (bindv->tags && bindv->tags[i]) { + code = stmtSetTbTags2(stmt, bindv->tags[i]); + if (code) { + return code; + } + } + + if (bindv->bind_cols && bindv->bind_cols[i]) { + TAOS_STMT2_BIND *bind = bindv->bind_cols[i]; + + if (bind->num <= 0 || bind->num > INT16_MAX) { + tscError("invalid bind num %d", bind->num); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + int32_t insert = 0; + (void)stmtIsInsert2(stmt, &insert); + if (0 == insert && bind->num > 1) { + tscError("only one row data allowed for query"); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + code = stmtBindBatch2(stmt, bind, col_idx); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + } + } + + return TSDB_CODE_SUCCESS; +} + +int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows) { + if (stmt == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtExec2(stmt, affected_rows); +} + +int taos_stmt2_close(TAOS_STMT2 *stmt) { + if (stmt == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtClose2(stmt); +} +/* +int taos_stmt2_param_count(TAOS_STMT2 *stmt, int *nums) { + if (stmt == NULL || nums == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + return stmtGetParamNum2(stmt, nums); +} +*/ +int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) { + if (stmt == NULL || insert == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtIsInsert2(stmt, insert); +} + +int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields) { + if (stmt == NULL || NULL == count) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + if (field_type == TAOS_FIELD_COL) { + return stmtGetColFields2(stmt, count, fields); + } else if (field_type == TAOS_FIELD_TAG) { + return stmtGetTagFields2(stmt, count, fields); + } else if (field_type == TAOS_FIELD_QUERY) { + return stmtGetParamNum2(stmt, count); + } else if (field_type == TAOS_FIELD_TBNAME) { + return stmtGetParamTbName(stmt, count); + } else { + tscError("invalid parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } +} + +void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields) { + (void)stmt; + if (!fields) return; + taosMemoryFree(fields); +} + +TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt) { + if (stmt == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } + + return stmtUseResult2(stmt); +} + +char *taos_stmt2_error(TAOS_STMT2 *stmt) { return (char *)stmtErrstr2(stmt); } + int taos_set_conn_mode(TAOS *taos, int mode, int value) { if (taos == NULL) { terrno = TSDB_CODE_INVALID_PARA; diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c new file mode 100644 index 0000000000..e7e08c0982 --- /dev/null +++ b/source/client/src/clientStmt2.c @@ -0,0 +1,1956 @@ +#include "clientInt.h" +#include "clientLog.h" +#include "tdef.h" + +#include "clientStmt.h" +#include "clientStmt2.h" +/* +char* gStmtStatusStr[] = {"unknown", "init", "prepare", "settbname", "settags", + "fetchFields", "bind", "bindCol", "addBatch", "exec"}; +*/ +static FORCE_INLINE int32_t stmtAllocQNodeFromBuf(STableBufInfo* pTblBuf, void** pBuf) { + if (pTblBuf->buffOffset < pTblBuf->buffSize) { + *pBuf = (char*)pTblBuf->pCurBuff + pTblBuf->buffOffset; + pTblBuf->buffOffset += pTblBuf->buffUnit; + } else if (pTblBuf->buffIdx < taosArrayGetSize(pTblBuf->pBufList)) { + pTblBuf->pCurBuff = taosArrayGetP(pTblBuf->pBufList, pTblBuf->buffIdx++); + if (NULL == pTblBuf->pCurBuff) { + return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); + } + *pBuf = pTblBuf->pCurBuff; + pTblBuf->buffOffset = pTblBuf->buffUnit; + } else { + void* buff = taosMemoryMalloc(pTblBuf->buffSize); + if (NULL == buff) { + return terrno; + } + + if (taosArrayPush(pTblBuf->pBufList, &buff) == NULL) { + return terrno; + } + + pTblBuf->buffIdx++; + pTblBuf->pCurBuff = buff; + *pBuf = buff; + pTblBuf->buffOffset = pTblBuf->buffUnit; + } + + return TSDB_CODE_SUCCESS; +} + +static bool stmtDequeue(STscStmt2* pStmt, SStmtQNode** param) { + while (0 == atomic_load_64(&pStmt->queue.qRemainNum)) { + taosUsleep(1); + return false; + } + + SStmtQNode* orig = pStmt->queue.head; + + SStmtQNode* node = pStmt->queue.head->next; + pStmt->queue.head = pStmt->queue.head->next; + + // taosMemoryFreeClear(orig); + + *param = node; + + (void)atomic_sub_fetch_64(&pStmt->queue.qRemainNum, 1); + + return true; +} + +static void stmtEnqueue(STscStmt2* pStmt, SStmtQNode* param) { + pStmt->queue.tail->next = param; + pStmt->queue.tail = param; + + pStmt->stat.bindDataNum++; + (void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1); +} + +static int32_t stmtCreateRequest(STscStmt2* pStmt) { + int32_t code = 0; + + if (pStmt->exec.pRequest == NULL) { + code = buildRequest(pStmt->taos->id, pStmt->sql.sqlStr, pStmt->sql.sqlLen, NULL, false, &pStmt->exec.pRequest, + pStmt->reqid); + if (pStmt->reqid != 0) { + pStmt->reqid++; + } + if (TSDB_CODE_SUCCESS == code) { + pStmt->exec.pRequest->syncQuery = true; + pStmt->exec.pRequest->isStmtBind = true; + } + } + + return code; +} + +static int32_t stmtSwitchStatus(STscStmt2* pStmt, STMT_STATUS newStatus) { + int32_t code = 0; + + if (newStatus >= STMT_INIT && newStatus < STMT_MAX) { + STMT_LOG_SEQ(newStatus); + } + + if (pStmt->errCode && newStatus != STMT_PREPARE) { + STMT_DLOG("stmt already failed with err: %s", tstrerror(pStmt->errCode)); + return pStmt->errCode; + } + + switch (newStatus) { + case STMT_PREPARE: + pStmt->errCode = 0; + break; + case STMT_SETTBNAME: + if (STMT_STATUS_EQ(INIT)) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + if (!pStmt->sql.stbInterlaceMode && (STMT_STATUS_EQ(BIND) || STMT_STATUS_EQ(BIND_COL))) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + break; + case STMT_SETTAGS: + if (STMT_STATUS_NE(SETTBNAME) && STMT_STATUS_NE(FETCH_FIELDS)) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + break; + case STMT_FETCH_FIELDS: + if (STMT_STATUS_EQ(INIT)) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + break; + case STMT_BIND: + if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND_COL)) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + /* + if ((pStmt->sql.type == STMT_TYPE_MULTI_INSERT) && ()) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + */ + break; + case STMT_BIND_COL: + if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND)) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + break; + case STMT_ADD_BATCH: + if (STMT_STATUS_NE(BIND) && STMT_STATUS_NE(BIND_COL) && STMT_STATUS_NE(FETCH_FIELDS)) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + break; + case STMT_EXECUTE: + if (STMT_TYPE_QUERY == pStmt->sql.type) { + if (STMT_STATUS_NE(ADD_BATCH) && STMT_STATUS_NE(FETCH_FIELDS) && STMT_STATUS_NE(BIND) && + STMT_STATUS_NE(BIND_COL)) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + } else { + if (STMT_STATUS_NE(ADD_BATCH) && STMT_STATUS_NE(FETCH_FIELDS)) { + code = TSDB_CODE_TSC_STMT_API_ERROR; + } + } + break; + default: + code = TSDB_CODE_APP_ERROR; + break; + } + + STMT_ERR_RET(code); + + pStmt->sql.status = newStatus; + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtGetTbName(TAOS_STMT2* stmt, char** tbName) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + pStmt->sql.type = STMT_TYPE_MULTI_INSERT; + + if ('\0' == pStmt->bInfo.tbName[0]) { + tscError("no table name set"); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_TBNAME_ERROR); + } + + *tbName = pStmt->bInfo.tbName; + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtUpdateBindInfo(TAOS_STMT2* stmt, STableMeta* pTableMeta, void* tags, SName* tbName, + const char* sTableName, bool autoCreateTbl) { + STscStmt2* pStmt = (STscStmt2*)stmt; + char tbFName[TSDB_TABLE_FNAME_LEN]; + int32_t code = tNameExtractFullName(tbName, tbFName); + if (code != 0) { + return code; + } + + (void)memcpy(&pStmt->bInfo.sname, tbName, sizeof(*tbName)); + (void)strncpy(pStmt->bInfo.tbFName, tbFName, sizeof(pStmt->bInfo.tbFName) - 1); + pStmt->bInfo.tbFName[sizeof(pStmt->bInfo.tbFName) - 1] = 0; + + pStmt->bInfo.tbUid = autoCreateTbl ? 0 : pTableMeta->uid; + pStmt->bInfo.tbSuid = pTableMeta->suid; + pStmt->bInfo.tbVgId = pTableMeta->vgId; + pStmt->bInfo.tbType = pTableMeta->tableType; + pStmt->bInfo.boundTags = tags; + pStmt->bInfo.tagsCached = false; + tstrncpy(pStmt->bInfo.stbFName, sTableName, sizeof(pStmt->bInfo.stbFName)); + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtUpdateExecInfo(TAOS_STMT2* stmt, SHashObj* pVgHash, SHashObj* pBlockHash) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + pStmt->sql.pVgHash = pVgHash; + pStmt->exec.pBlockHash = pBlockHash; + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtUpdateInfo(TAOS_STMT2* stmt, STableMeta* pTableMeta, void* tags, SName* tbName, bool autoCreateTbl, + SHashObj* pVgHash, SHashObj* pBlockHash, const char* sTableName) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_ERR_RET(stmtUpdateBindInfo(stmt, pTableMeta, tags, tbName, sTableName, autoCreateTbl)); + STMT_ERR_RET(stmtUpdateExecInfo(stmt, pVgHash, pBlockHash)); + + pStmt->sql.autoCreateTbl = autoCreateTbl; + if (pStmt->sql.autoCreateTbl) { + pStmt->sql.stbInterlaceMode = false; + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtGetExecInfo(TAOS_STMT2* stmt, SHashObj** pVgHash, SHashObj** pBlockHash) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + *pVgHash = pStmt->sql.pVgHash; + pStmt->sql.pVgHash = NULL; + + *pBlockHash = pStmt->exec.pBlockHash; + pStmt->exec.pBlockHash = NULL; + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtParseSql(STscStmt2* pStmt) { + pStmt->exec.pCurrBlock = NULL; + + SStmtCallback stmtCb = { + .pStmt = pStmt, + .getTbNameFn = stmtGetTbName, + .setInfoFn = stmtUpdateInfo, + .getExecInfoFn = stmtGetExecInfo, + }; + + STMT_ERR_RET(stmtCreateRequest(pStmt)); + + pStmt->stat.parseSqlNum++; + STMT_ERR_RET(parseSql(pStmt->exec.pRequest, false, &pStmt->sql.pQuery, &stmtCb)); + pStmt->sql.siInfo.pQuery = pStmt->sql.pQuery; + + pStmt->bInfo.needParse = false; + + if (pStmt->sql.pQuery->pRoot && 0 == pStmt->sql.type) { + pStmt->sql.type = STMT_TYPE_INSERT; + pStmt->sql.stbInterlaceMode = false; + } else if (pStmt->sql.pQuery->pPrepareRoot) { + pStmt->sql.type = STMT_TYPE_QUERY; + pStmt->sql.stbInterlaceMode = false; + + return TSDB_CODE_SUCCESS; + } + + STableDataCxt** pSrc = + (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); + if (NULL == pSrc || NULL == *pSrc) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + STableDataCxt* pTableCtx = *pSrc; + if (pStmt->sql.stbInterlaceMode) { + int16_t lastIdx = -1; + + for (int32_t i = 0; i < pTableCtx->boundColsInfo.numOfBound; ++i) { + if (pTableCtx->boundColsInfo.pColIndex[i] < lastIdx) { + pStmt->sql.stbInterlaceMode = false; + break; + } + + lastIdx = pTableCtx->boundColsInfo.pColIndex[i]; + } + } + + if (NULL == pStmt->sql.pBindInfo) { + pStmt->sql.pBindInfo = taosMemoryMalloc(pTableCtx->boundColsInfo.numOfBound * sizeof(*pStmt->sql.pBindInfo)); + if (NULL == pStmt->sql.pBindInfo) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtCleanBindInfo(STscStmt2* pStmt) { + pStmt->bInfo.tbUid = 0; + pStmt->bInfo.tbSuid = 0; + pStmt->bInfo.tbVgId = -1; + pStmt->bInfo.tbType = 0; + pStmt->bInfo.needParse = true; + pStmt->bInfo.inExecCache = false; + + pStmt->bInfo.tbName[0] = 0; + pStmt->bInfo.tbFName[0] = 0; + if (!pStmt->bInfo.tagsCached) { + qDestroyBoundColInfo(pStmt->bInfo.boundTags); + taosMemoryFreeClear(pStmt->bInfo.boundTags); + } + pStmt->bInfo.stbFName[0] = 0; + + return TSDB_CODE_SUCCESS; +} + +static void stmtFreeTableBlkList(STableColsData* pTb) { + (void)qResetStmtColumns(pTb->aCol, true); + taosArrayDestroy(pTb->aCol); +} + +static void stmtResetQueueTableBuf(STableBufInfo* pTblBuf, SStmtQueue* pQueue) { + pTblBuf->pCurBuff = taosArrayGetP(pTblBuf->pBufList, 0); + if (NULL == pTblBuf->pCurBuff) { + tscError("QInfo:%p, failed to get buffer from list", pTblBuf); + return; + } + pTblBuf->buffIdx = 1; + pTblBuf->buffOffset = sizeof(*pQueue->head); + + pQueue->head = pQueue->tail = pTblBuf->pCurBuff; + pQueue->qRemainNum = 0; + pQueue->head->next = NULL; +} + +static int32_t stmtCleanExecInfo(STscStmt2* pStmt, bool keepTable, bool deepClean) { + if (pStmt->sql.stbInterlaceMode) { + if (deepClean) { + taosHashCleanup(pStmt->exec.pBlockHash); + pStmt->exec.pBlockHash = NULL; + + if (NULL != pStmt->exec.pCurrBlock) { + taosMemoryFreeClear(pStmt->exec.pCurrBlock->pData); + qDestroyStmtDataBlock(pStmt->exec.pCurrBlock); + } + } else { + pStmt->sql.siInfo.pTableColsIdx = 0; + stmtResetQueueTableBuf(&pStmt->sql.siInfo.tbBuf, &pStmt->queue); + } + } else { + if (STMT_TYPE_QUERY != pStmt->sql.type || deepClean) { + // if (!pStmt->options.asyncExecFn) { + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + //} + } + + size_t keyLen = 0; + void* pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL); + while (pIter) { + STableDataCxt* pBlocks = *(STableDataCxt**)pIter; + char* key = taosHashGetKey(pIter, &keyLen); + STableMeta* pMeta = qGetTableMetaInDataBlock(pBlocks); + + if (keepTable && pBlocks == pStmt->exec.pCurrBlock) { + TSWAP(pBlocks->pData, pStmt->exec.pCurrTbData); + STMT_ERR_RET(qResetStmtDataBlock(pBlocks, false)); + + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + continue; + } + + qDestroyStmtDataBlock(pBlocks); + STMT_ERR_RET(taosHashRemove(pStmt->exec.pBlockHash, key, keyLen)); + + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + } + + if (keepTable) { + return TSDB_CODE_SUCCESS; + } + + taosHashCleanup(pStmt->exec.pBlockHash); + pStmt->exec.pBlockHash = NULL; + + tDestroySubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE); + taosMemoryFreeClear(pStmt->exec.pCurrTbData); + } + + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + + return TSDB_CODE_SUCCESS; +} + +static void stmtFreeTbBuf(void* buf) { + void* pBuf = *(void**)buf; + taosMemoryFree(pBuf); +} + +static void stmtFreeTbCols(void* buf) { + SArray* pCols = *(SArray**)buf; + taosArrayDestroy(pCols); +} + +static int32_t stmtCleanSQLInfo(STscStmt2* pStmt) { + STMT_DLOG_E("start to free SQL info"); + + taosMemoryFree(pStmt->sql.pBindInfo); + taosMemoryFree(pStmt->sql.queryRes.fields); + taosMemoryFree(pStmt->sql.queryRes.userFields); + taosMemoryFree(pStmt->sql.sqlStr); + qDestroyQuery(pStmt->sql.pQuery); + taosArrayDestroy(pStmt->sql.nodeList); + taosHashCleanup(pStmt->sql.pVgHash); + pStmt->sql.pVgHash = NULL; + + void* pIter = taosHashIterate(pStmt->sql.pTableCache, NULL); + while (pIter) { + SStmtTableCache* pCache = (SStmtTableCache*)pIter; + + qDestroyStmtDataBlock(pCache->pDataCtx); + qDestroyBoundColInfo(pCache->boundTags); + taosMemoryFreeClear(pCache->boundTags); + + pIter = taosHashIterate(pStmt->sql.pTableCache, pIter); + } + taosHashCleanup(pStmt->sql.pTableCache); + pStmt->sql.pTableCache = NULL; + + STMT_ERR_RET(stmtCleanExecInfo(pStmt, false, true)); + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + + taos_free_result(pStmt->sql.siInfo.pRequest); + taosHashCleanup(pStmt->sql.siInfo.pVgroupHash); + tSimpleHashCleanup(pStmt->sql.siInfo.pTableHash); + taosArrayDestroyEx(pStmt->sql.siInfo.tbBuf.pBufList, stmtFreeTbBuf); + taosMemoryFree(pStmt->sql.siInfo.pTSchema); + qDestroyStmtDataBlock(pStmt->sql.siInfo.pDataCtx); + taosArrayDestroyEx(pStmt->sql.siInfo.pTableCols, stmtFreeTbCols); + + (void)memset(&pStmt->sql, 0, sizeof(pStmt->sql)); + pStmt->sql.siInfo.tableColsReady = true; + + STMT_DLOG_E("end to free SQL info"); + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtTryAddTableVgroupInfo(STscStmt2* pStmt, int32_t* vgId) { + if (*vgId >= 0 && taosHashGet(pStmt->sql.pVgHash, (const char*)vgId, sizeof(*vgId))) { + return TSDB_CODE_SUCCESS; + } + + SVgroupInfo vgInfo = {0}; + SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter, + .requestId = pStmt->exec.pRequest->requestId, + .requestObjRefId = pStmt->exec.pRequest->self, + .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)}; + + int32_t code = catalogGetTableHashVgroup(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &vgInfo); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + + code = + taosHashPut(pStmt->sql.pVgHash, (const char*)&vgInfo.vgId, sizeof(vgInfo.vgId), (char*)&vgInfo, sizeof(vgInfo)); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + + *vgId = vgInfo.vgId; + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtRebuildDataBlock(STscStmt2* pStmt, STableDataCxt* pDataBlock, STableDataCxt** newBlock, uint64_t uid, + uint64_t suid, int32_t vgId) { + STMT_ERR_RET(stmtTryAddTableVgroupInfo(pStmt, &vgId)); + STMT_ERR_RET(qRebuildStmtDataBlock(newBlock, pDataBlock, uid, suid, vgId, pStmt->sql.autoCreateTbl)); + + STMT_DLOG("tableDataCxt rebuilt, uid:%" PRId64 ", vgId:%d", uid, vgId); + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtGetFromCache(STscStmt2* pStmt) { + if (pStmt->sql.stbInterlaceMode && pStmt->sql.siInfo.pDataCtx) { + pStmt->bInfo.needParse = false; + pStmt->bInfo.inExecCache = false; + return TSDB_CODE_SUCCESS; + } + + pStmt->bInfo.needParse = true; + pStmt->bInfo.inExecCache = false; + + STableDataCxt** pCxtInExec = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); + if (pCxtInExec) { + pStmt->bInfo.needParse = false; + pStmt->bInfo.inExecCache = true; + + pStmt->exec.pCurrBlock = *pCxtInExec; + + if (pStmt->sql.autoCreateTbl) { + tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; + } + } + + if (NULL == pStmt->pCatalog) { + STMT_ERR_RET(catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &pStmt->pCatalog)); + pStmt->sql.siInfo.pCatalog = pStmt->pCatalog; + } + + if (NULL == pStmt->sql.pTableCache || taosHashGetSize(pStmt->sql.pTableCache) <= 0) { + if (pStmt->bInfo.inExecCache) { + pStmt->bInfo.needParse = false; + tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; + } + + tscDebug("no stmt block cache for tb %s", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; + } + + if (pStmt->sql.autoCreateTbl) { + SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pStmt->bInfo.tbSuid, sizeof(pStmt->bInfo.tbSuid)); + if (pCache) { + pStmt->bInfo.needParse = false; + pStmt->bInfo.tbUid = 0; + + STableDataCxt* pNewBlock = NULL; + STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataCtx, &pNewBlock, 0, pStmt->bInfo.tbSuid, -1)); + + if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock, + POINTER_BYTES)) { + STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + + pStmt->exec.pCurrBlock = pNewBlock; + + tscDebug("reuse stmt block for tb %s in sqlBlock, suid:0x%" PRIx64, pStmt->bInfo.tbFName, pStmt->bInfo.tbSuid); + + return TSDB_CODE_SUCCESS; + } + + STMT_RET(stmtCleanBindInfo(pStmt)); + } + + uint64_t uid, suid; + int32_t vgId; + int8_t tableType; + + STableMeta* pTableMeta = NULL; + SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter, + .requestId = pStmt->exec.pRequest->requestId, + .requestObjRefId = pStmt->exec.pRequest->self, + .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)}; + int32_t code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta); + + pStmt->stat.ctgGetTbMetaNum++; + + if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) { + tscDebug("tb %s not exist", pStmt->bInfo.tbFName); + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + + STMT_ERR_RET(code); + } + + STMT_ERR_RET(code); + + uid = pTableMeta->uid; + suid = pTableMeta->suid; + tableType = pTableMeta->tableType; + pStmt->bInfo.tbVgId = pTableMeta->vgId; + vgId = pTableMeta->vgId; + + taosMemoryFree(pTableMeta); + + uint64_t cacheUid = (TSDB_CHILD_TABLE == tableType) ? suid : uid; + + if (uid == pStmt->bInfo.tbUid) { + pStmt->bInfo.needParse = false; + + tscDebug("tb %s is current table", pStmt->bInfo.tbFName); + + return TSDB_CODE_SUCCESS; + } + + if (pStmt->bInfo.inExecCache) { + SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid)); + if (NULL == pCache) { + tscError("table [%s, %" PRIx64 ", %" PRIx64 "] found in exec blockHash, but not in sql blockHash", + pStmt->bInfo.tbFName, uid, cacheUid); + + STMT_ERR_RET(TSDB_CODE_APP_ERROR); + } + + pStmt->bInfo.needParse = false; + + pStmt->bInfo.tbUid = uid; + pStmt->bInfo.tbSuid = suid; + pStmt->bInfo.tbType = tableType; + pStmt->bInfo.boundTags = pCache->boundTags; + pStmt->bInfo.tagsCached = true; + + tscDebug("tb %s in execBlock list, set to current", pStmt->bInfo.tbFName); + + return TSDB_CODE_SUCCESS; + } + + SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid)); + if (pCache) { + pStmt->bInfo.needParse = false; + + pStmt->bInfo.tbUid = uid; + pStmt->bInfo.tbSuid = suid; + pStmt->bInfo.tbType = tableType; + pStmt->bInfo.boundTags = pCache->boundTags; + pStmt->bInfo.tagsCached = true; + + STableDataCxt* pNewBlock = NULL; + STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataCtx, &pNewBlock, uid, suid, vgId)); + + if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock, + POINTER_BYTES)) { + STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + + pStmt->exec.pCurrBlock = pNewBlock; + + tscDebug("tb %s in sqlBlock list, set to current", pStmt->bInfo.tbFName); + + return TSDB_CODE_SUCCESS; + } + + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtResetStmt(STscStmt2* pStmt) { + STMT_ERR_RET(stmtCleanSQLInfo(pStmt)); + + pStmt->sql.pTableCache = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + if (NULL == pStmt->sql.pTableCache) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + STMT_ERR_RET(terrno); + } + + pStmt->sql.status = STMT_INIT; + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtAsyncOutput(STscStmt2* pStmt, void* param) { + SStmtQNode* pParam = (SStmtQNode*)param; + + if (pParam->restoreTbCols) { + for (int32_t i = 0; i < pStmt->sql.siInfo.pTableColsIdx; ++i) { + SArray** p = (SArray**)TARRAY_GET_ELEM(pStmt->sql.siInfo.pTableCols, i); + *p = taosArrayInit(20, POINTER_BYTES); + if (*p == NULL) { + STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + } + + atomic_store_8((int8_t*)&pStmt->sql.siInfo.tableColsReady, true); + } else { + STMT_ERR_RET(qAppendStmtTableOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, &pParam->tblData, pStmt->exec.pCurrBlock, + &pStmt->sql.siInfo)); + + // taosMemoryFree(pParam->pTbData); + + (void)atomic_sub_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1); + } + return TSDB_CODE_SUCCESS; +} + +static void* stmtBindThreadFunc(void* param) { + setThreadName("stmtBind"); + + qInfo("stmt bind thread started"); + + STscStmt2* pStmt = (STscStmt2*)param; + + while (true) { + if (atomic_load_8((int8_t*)&pStmt->queue.stopQueue)) { + break; + } + + SStmtQNode* asyncParam = NULL; + if (!stmtDequeue(pStmt, &asyncParam)) { + continue; + } + + (void)stmtAsyncOutput(pStmt, asyncParam); + } + + qInfo("stmt bind thread stopped"); + + return NULL; +} + +static int32_t stmtStartBindThread(STscStmt2* pStmt) { + TdThreadAttr thAttr; + if (taosThreadAttrInit(&thAttr) != 0) { + return TSDB_CODE_TSC_INTERNAL_ERROR; + } + if (taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE) != 0) { + return TSDB_CODE_TSC_INTERNAL_ERROR; + } + + if (taosThreadCreate(&pStmt->bindThread, &thAttr, stmtBindThreadFunc, pStmt) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + STMT_ERR_RET(terrno); + } + + pStmt->bindThreadInUse = true; + + (void)taosThreadAttrDestroy(&thAttr); + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtInitQueue(STscStmt2* pStmt) { + STMT_ERR_RET(stmtAllocQNodeFromBuf(&pStmt->sql.siInfo.tbBuf, (void**)&pStmt->queue.head)); + pStmt->queue.tail = pStmt->queue.head; + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtInitTableBuf(STableBufInfo* pTblBuf) { + pTblBuf->buffUnit = sizeof(SStmtQNode); + pTblBuf->buffSize = pTblBuf->buffUnit * 1000; + pTblBuf->pBufList = taosArrayInit(100, POINTER_BYTES); + if (NULL == pTblBuf->pBufList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + void* buff = taosMemoryMalloc(pTblBuf->buffSize); + if (NULL == buff) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + if (taosArrayPush(pTblBuf->pBufList, &buff) == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pTblBuf->pCurBuff = buff; + pTblBuf->buffIdx = 1; + pTblBuf->buffOffset = 0; + + return TSDB_CODE_SUCCESS; +} + +TAOS_STMT2* stmtInit2(STscObj* taos, TAOS_STMT2_OPTION* pOptions) { + STscObj* pObj = (STscObj*)taos; + STscStmt2* pStmt = NULL; + int32_t code = 0; + + pStmt = taosMemoryCalloc(1, sizeof(STscStmt2)); + if (NULL == pStmt) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pStmt->sql.pTableCache = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + if (NULL == pStmt->sql.pTableCache) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pStmt); + return NULL; + } + + pStmt->taos = pObj; + pStmt->bInfo.needParse = true; + pStmt->sql.status = STMT_INIT; + pStmt->errCode = TSDB_CODE_SUCCESS; + + if (NULL != pOptions) { + (void)memcpy(&pStmt->options, pOptions, sizeof(pStmt->options)); + if (pOptions->singleStbInsert && pOptions->singleTableBindOnce) { + pStmt->stbInterlaceMode = true; + } + + pStmt->reqid = pOptions->reqid; + } + + if (pStmt->stbInterlaceMode) { + pStmt->sql.siInfo.transport = taos->pAppInfo->pTransporter; + pStmt->sql.siInfo.acctId = taos->acctId; + pStmt->sql.siInfo.dbname = taos->db; + pStmt->sql.siInfo.mgmtEpSet = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); + pStmt->sql.siInfo.pTableHash = tSimpleHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY)); + if (NULL == pStmt->sql.siInfo.pTableHash) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + (void)stmtClose(pStmt); + return NULL; + } + pStmt->sql.siInfo.pTableCols = taosArrayInit(STMT_TABLE_COLS_NUM, POINTER_BYTES); + if (NULL == pStmt->sql.siInfo.pTableCols) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + (void)stmtClose(pStmt); + return NULL; + } + + code = stmtInitTableBuf(&pStmt->sql.siInfo.tbBuf); + if (TSDB_CODE_SUCCESS == code) { + code = stmtInitQueue(pStmt); + } + if (TSDB_CODE_SUCCESS == code) { + code = stmtStartBindThread(pStmt); + } + if (TSDB_CODE_SUCCESS != code) { + terrno = code; + (void)stmtClose(pStmt); + return NULL; + } + } + + pStmt->sql.siInfo.tableColsReady = true; + if (pStmt->options.asyncExecFn) { + (void)tsem_init(&pStmt->asyncQuerySem, 0, 1); + } + + STMT_LOG_SEQ(STMT_INIT); + + tscDebug("stmt:%p initialized", pStmt); + + return pStmt; +} + +static int stmtSetDbName2(TAOS_STMT2* stmt, const char* dbName) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG("start to set dbName: %s", dbName); + + STMT_ERR_RET(stmtCreateRequest(pStmt)); + + // The SQL statement specifies a database name, overriding the previously specified database + taosMemoryFreeClear(pStmt->exec.pRequest->pDb); + pStmt->exec.pRequest->pDb = taosStrdup(dbName); + if (pStmt->exec.pRequest->pDb == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + return TSDB_CODE_SUCCESS; +} + +int stmtPrepare2(TAOS_STMT2* stmt, const char* sql, unsigned long length) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG_E("start to prepare"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + if (pStmt->sql.status >= STMT_PREPARE) { + STMT_ERR_RET(stmtResetStmt(pStmt)); + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_PREPARE)); + + if (length <= 0) { + length = strlen(sql); + } + + pStmt->sql.sqlStr = strndup(sql, length); + pStmt->sql.sqlLen = length; + pStmt->sql.stbInterlaceMode = pStmt->stbInterlaceMode; + + char* dbName = NULL; + if (qParseDbName(sql, length, &dbName)) { + STMT_ERR_RET(stmtSetDbName2(stmt, dbName)); + taosMemoryFreeClear(dbName); + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtInitStbInterlaceTableInfo(STscStmt2* pStmt) { + STableDataCxt** pSrc = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); + if (!pSrc) { + return TSDB_CODE_OUT_OF_MEMORY; + } + STableDataCxt* pDst = NULL; + + STMT_ERR_RET(qCloneStmtDataBlock(&pDst, *pSrc, true)); + pStmt->sql.siInfo.pDataCtx = pDst; + + SArray* pTblCols = NULL; + for (int32_t i = 0; i < STMT_TABLE_COLS_NUM; i++) { + pTblCols = taosArrayInit(20, POINTER_BYTES); + if (NULL == pTblCols) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + pStmt->sql.siInfo.boundTags = pStmt->bInfo.boundTags; + + return TSDB_CODE_SUCCESS; +} + +int stmtIsInsert2(TAOS_STMT2* stmt, int* insert) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG_E("start is insert"); + + if (pStmt->sql.type) { + *insert = (STMT_TYPE_INSERT == pStmt->sql.type || STMT_TYPE_MULTI_INSERT == pStmt->sql.type); + } else { + *insert = qIsInsertValuesSql(pStmt->sql.sqlStr, pStmt->sql.sqlLen); + } + + return TSDB_CODE_SUCCESS; +} + +int stmtSetTbName2(TAOS_STMT2* stmt, const char* tbName) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + int64_t startUs = taosGetTimestampUs(); + + STMT_DLOG("start to set tbName: %s", tbName); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME)); + + int32_t insert = 0; + STMT_ERR_RET(stmtIsInsert2(stmt, &insert)); + if (0 == insert) { + tscError("set tb name not available for none insert statement"); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + if (!pStmt->sql.stbInterlaceMode || NULL == pStmt->sql.siInfo.pDataCtx) { + 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)); + STMT_ERR_RET(tNameExtractFullName(&pStmt->bInfo.sname, pStmt->bInfo.tbFName)); + + STMT_ERR_RET(stmtGetFromCache(pStmt)); + + if (pStmt->bInfo.needParse) { + (void)strncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName) - 1); + pStmt->bInfo.tbName[sizeof(pStmt->bInfo.tbName) - 1] = 0; + + STMT_ERR_RET(stmtParseSql(pStmt)); + } + } else { + (void)strncpy(pStmt->bInfo.tbName, tbName, sizeof(pStmt->bInfo.tbName) - 1); + pStmt->bInfo.tbName[sizeof(pStmt->bInfo.tbName) - 1] = 0; + pStmt->exec.pRequest->requestId++; + pStmt->bInfo.needParse = false; + } + + if (pStmt->sql.stbInterlaceMode && NULL == pStmt->sql.siInfo.pDataCtx) { + STMT_ERR_RET(stmtInitStbInterlaceTableInfo(pStmt)); + } + + int64_t startUs2 = taosGetTimestampUs(); + pStmt->stat.setTbNameUs += startUs2 - startUs; + + return TSDB_CODE_SUCCESS; +} + +int stmtSetTbTags2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* tags) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG_E("start to set tbTags"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS)); + + SBoundColInfo* tags_info = (SBoundColInfo*)pStmt->bInfo.boundTags; + if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) { + tscWarn("no tags or cols bound in sql, will not bound tags"); + return TSDB_CODE_SUCCESS; + } + + if (pStmt->bInfo.inExecCache) { + return TSDB_CODE_SUCCESS; + } + + STableDataCxt** pDataBlock = + (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); + if (NULL == pDataBlock) { + tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName); + STMT_ERR_RET(TSDB_CODE_APP_ERROR); + } + + tscDebug("start to bind stmt tag values"); + STMT_ERR_RET(qBindStmtTagsValue2(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, pStmt->bInfo.stbFName, + pStmt->bInfo.sname.tname, tags, pStmt->exec.pRequest->msgBuf, + pStmt->exec.pRequest->msgBufLen)); + + return TSDB_CODE_SUCCESS; +} + +static int stmtFetchTagFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields) { + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + tscError("invalid operation to get query tag fileds"); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + STableDataCxt** pDataBlock = + (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); + if (NULL == pDataBlock) { + tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName); + STMT_ERR_RET(TSDB_CODE_APP_ERROR); + } + + STMT_ERR_RET(qBuildStmtTagFields(*pDataBlock, pStmt->bInfo.boundTags, fieldNum, fields)); + + return TSDB_CODE_SUCCESS; +} + +static int stmtFetchColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields) { + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + tscError("invalid operation to get query column fileds"); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + STableDataCxt** pDataBlock = NULL; + + if (pStmt->sql.stbInterlaceMode) { + pDataBlock = &pStmt->sql.siInfo.pDataCtx; + } else { + pDataBlock = + (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); + if (NULL == pDataBlock) { + tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName); + STMT_ERR_RET(TSDB_CODE_APP_ERROR); + } + } + + STMT_ERR_RET(qBuildStmtColFields(*pDataBlock, fieldNum, fields)); + + return TSDB_CODE_SUCCESS; +} +/* +SArray* stmtGetFreeCol(STscStmt2* pStmt, int32_t* idx) { + while (true) { + if (pStmt->exec.smInfo.pColIdx >= STMT_COL_BUF_SIZE) { + pStmt->exec.smInfo.pColIdx = 0; + } + + if ((pStmt->exec.smInfo.pColIdx + 1) == atomic_load_32(&pStmt->exec.smInfo.pColFreeIdx)) { + taosUsleep(1); + continue; + } + + *idx = pStmt->exec.smInfo.pColIdx; + return pStmt->exec.smInfo.pCols[pStmt->exec.smInfo.pColIdx++]; + } +} +*/ +static int32_t stmtAppendTablePostHandle(STscStmt2* pStmt, SStmtQNode* param) { + if (NULL == pStmt->sql.siInfo.pVgroupHash) { + pStmt->sql.siInfo.pVgroupHash = + taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); + } + if (NULL == pStmt->sql.siInfo.pVgroupList) { + pStmt->sql.siInfo.pVgroupList = taosArrayInit(64, POINTER_BYTES); + } + + if (NULL == pStmt->sql.siInfo.pRequest) { + STMT_ERR_RET(buildRequest(pStmt->taos->id, pStmt->sql.sqlStr, pStmt->sql.sqlLen, NULL, false, + (SRequestObj**)&pStmt->sql.siInfo.pRequest, pStmt->reqid)); + + if (pStmt->reqid != 0) { + pStmt->reqid++; + } + pStmt->exec.pRequest->syncQuery = true; + + pStmt->sql.siInfo.requestId = ((SRequestObj*)pStmt->sql.siInfo.pRequest)->requestId; + pStmt->sql.siInfo.requestSelf = ((SRequestObj*)pStmt->sql.siInfo.pRequest)->self; + } + + if (!pStmt->sql.siInfo.tbFromHash && pStmt->sql.siInfo.firstName[0] && + 0 == strcmp(pStmt->sql.siInfo.firstName, pStmt->bInfo.tbName)) { + pStmt->sql.siInfo.tbFromHash = true; + } + + if (0 == pStmt->sql.siInfo.firstName[0]) { + (void)strcpy(pStmt->sql.siInfo.firstName, pStmt->bInfo.tbName); + } + + param->tblData.getFromHash = pStmt->sql.siInfo.tbFromHash; + param->next = NULL; + + (void)atomic_add_fetch_64(&pStmt->sql.siInfo.tbRemainNum, 1); + + stmtEnqueue(pStmt, param); + + return TSDB_CODE_SUCCESS; +} + +static FORCE_INLINE int32_t stmtGetTableColsFromCache(STscStmt2* pStmt, SArray** pTableCols) { + while (true) { + if (pStmt->sql.siInfo.pTableColsIdx < taosArrayGetSize(pStmt->sql.siInfo.pTableCols)) { + *pTableCols = (SArray*)taosArrayGetP(pStmt->sql.siInfo.pTableCols, pStmt->sql.siInfo.pTableColsIdx++); + break; + } else { + SArray* pTblCols = NULL; + for (int32_t i = 0; i < 100; i++) { + pTblCols = taosArrayInit(20, POINTER_BYTES); + if (NULL == pTblCols) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + if (taosArrayPush(pStmt->sql.siInfo.pTableCols, &pTblCols) == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + } + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtCacheBlock(STscStmt2* pStmt) { + if (pStmt->sql.type != STMT_TYPE_MULTI_INSERT) { + return TSDB_CODE_SUCCESS; + } + + uint64_t uid = pStmt->bInfo.tbUid; + uint64_t cacheUid = (TSDB_CHILD_TABLE == pStmt->bInfo.tbType) ? pStmt->bInfo.tbSuid : uid; + + if (taosHashGet(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid))) { + return TSDB_CODE_SUCCESS; + } + + STableDataCxt** pSrc = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); + if (!pSrc) { + return TSDB_CODE_OUT_OF_MEMORY; + } + STableDataCxt* pDst = NULL; + + STMT_ERR_RET(qCloneStmtDataBlock(&pDst, *pSrc, true)); + + SStmtTableCache cache = { + .pDataCtx = pDst, + .boundTags = pStmt->bInfo.boundTags, + }; + + if (taosHashPut(pStmt->sql.pTableCache, &cacheUid, sizeof(cacheUid), &cache, sizeof(cache))) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + if (pStmt->sql.autoCreateTbl) { + pStmt->bInfo.tagsCached = true; + } else { + pStmt->bInfo.boundTags = NULL; + } + + return TSDB_CODE_SUCCESS; +} + +static int stmtAddBatch2(TAOS_STMT2* stmt) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + int64_t startUs = taosGetTimestampUs(); + + STMT_DLOG_E("start to add batch"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_ADD_BATCH)); + + if (pStmt->sql.stbInterlaceMode) { + int64_t startUs2 = taosGetTimestampUs(); + pStmt->stat.addBatchUs += startUs2 - startUs; + + pStmt->sql.siInfo.tableColsReady = false; + + SStmtQNode* param = NULL; + STMT_ERR_RET(stmtAllocQNodeFromBuf(&pStmt->sql.siInfo.tbBuf, (void**)¶m)); + param->restoreTbCols = true; + param->next = NULL; + + stmtEnqueue(pStmt, param); + + return TSDB_CODE_SUCCESS; + } + + STMT_ERR_RET(stmtCacheBlock(pStmt)); + + return TSDB_CODE_SUCCESS; +} +/* +static int32_t stmtBackupQueryFields(STscStmt2* pStmt) { + SStmtQueryResInfo* pRes = &pStmt->sql.queryRes; + pRes->numOfCols = pStmt->exec.pRequest->body.resInfo.numOfCols; + pRes->precision = pStmt->exec.pRequest->body.resInfo.precision; + + int32_t size = pRes->numOfCols * sizeof(TAOS_FIELD); + pRes->fields = taosMemoryMalloc(size); + pRes->userFields = taosMemoryMalloc(size); + if (NULL == pRes->fields || NULL == pRes->userFields) { + STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + (void)memcpy(pRes->fields, pStmt->exec.pRequest->body.resInfo.fields, size); + (void)memcpy(pRes->userFields, pStmt->exec.pRequest->body.resInfo.userFields, size); + + return TSDB_CODE_SUCCESS; +} + +static int32_t stmtRestoreQueryFields(STscStmt2* pStmt) { + SStmtQueryResInfo* pRes = &pStmt->sql.queryRes; + int32_t size = pRes->numOfCols * sizeof(TAOS_FIELD); + + pStmt->exec.pRequest->body.resInfo.numOfCols = pRes->numOfCols; + pStmt->exec.pRequest->body.resInfo.precision = pRes->precision; + + if (NULL == pStmt->exec.pRequest->body.resInfo.fields) { + pStmt->exec.pRequest->body.resInfo.fields = taosMemoryMalloc(size); + if (NULL == pStmt->exec.pRequest->body.resInfo.fields) { + STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + (void)memcpy(pStmt->exec.pRequest->body.resInfo.fields, pRes->fields, size); + } + + if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) { + pStmt->exec.pRequest->body.resInfo.userFields = taosMemoryMalloc(size); + if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) { + STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + (void)memcpy(pStmt->exec.pRequest->body.resInfo.userFields, pRes->userFields, size); + } + + return TSDB_CODE_SUCCESS; +} +*/ +int stmtBindBatch2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* bind, int32_t colIdx) { + STscStmt2* pStmt = (STscStmt2*)stmt; + int32_t code = 0; + + int64_t startUs = taosGetTimestampUs(); + + STMT_DLOG("start to bind stmt data, colIdx: %d", colIdx); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND)); + + if (pStmt->options.asyncExecFn) { + (void)tsem_wait(&pStmt->asyncQuerySem); + } + + if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && + STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { + pStmt->bInfo.needParse = false; + } + + if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + } + + STMT_ERR_RET(stmtCreateRequest(pStmt)); + + if (pStmt->bInfo.needParse) { + STMT_ERR_RET(stmtParseSql(pStmt)); + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + STMT_ERR_RET(qStmtBindParams2(pStmt->sql.pQuery, bind, colIdx)); + + SParseContext ctx = {.requestId = pStmt->exec.pRequest->requestId, + .acctId = pStmt->taos->acctId, + .db = pStmt->exec.pRequest->pDb, + .topicQuery = false, + .pSql = pStmt->sql.sqlStr, + .sqlLen = pStmt->sql.sqlLen, + .pMsg = pStmt->exec.pRequest->msgBuf, + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, + .pTransporter = pStmt->taos->pAppInfo->pTransporter, + .pStmtCb = NULL, + .pUser = pStmt->taos->user}; + ctx.mgmtEpSet = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); + STMT_ERR_RET(catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &ctx.pCatalog)); + + STMT_ERR_RET(qStmtParseQuerySql(&ctx, pStmt->sql.pQuery)); + + if (pStmt->sql.pQuery->haveResultSet) { + STMT_ERR_RET(setResSchemaInfo(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->pResSchema, + pStmt->sql.pQuery->numOfResCols)); + taosMemoryFreeClear(pStmt->sql.pQuery->pResSchema); + setResPrecision(&pStmt->exec.pRequest->body.resInfo, pStmt->sql.pQuery->precision); + } + + TSWAP(pStmt->exec.pRequest->dbList, pStmt->sql.pQuery->pDbList); + TSWAP(pStmt->exec.pRequest->tableList, pStmt->sql.pQuery->pTableList); + TSWAP(pStmt->exec.pRequest->targetTableList, pStmt->sql.pQuery->pTargetTableList); + + // if (STMT_TYPE_QUERY == pStmt->sql.queryRes) { + // STMT_ERR_RET(stmtRestoreQueryFields(pStmt)); + // } + + // STMT_ERR_RET(stmtBackupQueryFields(pStmt)); + + return TSDB_CODE_SUCCESS; + } + + if (pStmt->sql.stbInterlaceMode && NULL == pStmt->sql.siInfo.pDataCtx) { + STMT_ERR_RET(stmtInitStbInterlaceTableInfo(pStmt)); + } + + STableDataCxt** pDataBlock = NULL; + + if (pStmt->exec.pCurrBlock) { + pDataBlock = &pStmt->exec.pCurrBlock; + } else { + pDataBlock = + (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); + if (NULL == pDataBlock) { + tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_CACHE_ERROR); + } + pStmt->exec.pCurrBlock = *pDataBlock; + if (pStmt->sql.stbInterlaceMode) { + taosArrayDestroy(pStmt->exec.pCurrBlock->pData->aCol); + pStmt->exec.pCurrBlock->pData->aCol = NULL; + } + } + + int64_t startUs2 = taosGetTimestampUs(); + pStmt->stat.bindDataUs1 += startUs2 - startUs; + + SStmtQNode* param = NULL; + if (pStmt->sql.stbInterlaceMode) { + STMT_ERR_RET(stmtAllocQNodeFromBuf(&pStmt->sql.siInfo.tbBuf, (void**)¶m)); + STMT_ERR_RET(stmtGetTableColsFromCache(pStmt, ¶m->tblData.aCol)); + taosArrayClear(param->tblData.aCol); + + // param->tblData.aCol = taosArrayInit(20, POINTER_BYTES); + + param->restoreTbCols = false; + (void)strcpy(param->tblData.tbName, pStmt->bInfo.tbName); + } + + int64_t startUs3 = taosGetTimestampUs(); + pStmt->stat.bindDataUs2 += startUs3 - startUs2; + + SArray* pCols = pStmt->sql.stbInterlaceMode ? param->tblData.aCol : (*pDataBlock)->pData->aCol; + + if (colIdx < 0) { + if (pStmt->sql.stbInterlaceMode) { + (*pDataBlock)->pData->flags = 0; + code = qBindStmtStbColsValue2(*pDataBlock, pCols, bind, pStmt->exec.pRequest->msgBuf, + pStmt->exec.pRequest->msgBufLen, &pStmt->sql.siInfo.pTSchema, pStmt->sql.pBindInfo); + } else { + code = + qBindStmtColsValue2(*pDataBlock, pCols, bind, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen); + } + + if (code) { + tscError("qBindStmtColsValue failed, error:%s", tstrerror(code)); + STMT_ERR_RET(code); + } + } else { + if (pStmt->sql.stbInterlaceMode) { + tscError("bind single column not allowed in stb insert mode"); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + if (colIdx != (pStmt->bInfo.sBindLastIdx + 1) && colIdx != 0) { + tscError("bind column index not in sequence"); + STMT_ERR_RET(TSDB_CODE_APP_ERROR); + } + + pStmt->bInfo.sBindLastIdx = colIdx; + + if (0 == colIdx) { + pStmt->bInfo.sBindRowNum = bind->num; + } + + code = qBindStmtSingleColValue2(*pDataBlock, pCols, bind, pStmt->exec.pRequest->msgBuf, + pStmt->exec.pRequest->msgBufLen, colIdx, pStmt->bInfo.sBindRowNum); + if (code) { + tscError("qBindStmtSingleColValue failed, error:%s", tstrerror(code)); + STMT_ERR_RET(code); + } + } + + int64_t startUs4 = taosGetTimestampUs(); + pStmt->stat.bindDataUs3 += startUs4 - startUs3; + + if (pStmt->sql.stbInterlaceMode) { + STMT_ERR_RET(stmtAppendTablePostHandle(pStmt, param)); + } + + STMT_ERR_RET(stmtAddBatch2(pStmt)); + + pStmt->stat.bindDataUs4 += taosGetTimestampUs() - startUs4; + + return TSDB_CODE_SUCCESS; +} +/* +int stmtUpdateTableUid(STscStmt2* pStmt, SSubmitRsp* pRsp) { + tscDebug("stmt start to update tbUid, blockNum: %d", pRsp->nBlocks); + + int32_t code = 0; + int32_t finalCode = 0; + size_t keyLen = 0; + void* pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL); + while (pIter) { + STableDataCxt* pBlock = *(STableDataCxt**)pIter; + char* key = taosHashGetKey(pIter, &keyLen); + + STableMeta* pMeta = qGetTableMetaInDataBlock(pBlock); + if (pMeta->uid) { + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + continue; + } + + SSubmitBlkRsp* blkRsp = NULL; + int32_t i = 0; + for (; i < pRsp->nBlocks; ++i) { + blkRsp = pRsp->pBlocks + i; + if (strlen(blkRsp->tblFName) != keyLen) { + continue; + } + + if (strncmp(blkRsp->tblFName, key, keyLen)) { + continue; + } + + break; + } + + if (i < pRsp->nBlocks) { + tscDebug("auto created table %s uid updated from %" PRIx64 " to %" PRIx64, blkRsp->tblFName, pMeta->uid, + blkRsp->uid); + + pMeta->uid = blkRsp->uid; + pStmt->bInfo.tbUid = blkRsp->uid; + } else { + tscDebug("table %s not found in submit rsp, will update from catalog", pStmt->bInfo.tbFName); + if (NULL == pStmt->pCatalog) { + code = catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &pStmt->pCatalog); + if (code) { + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + finalCode = code; + continue; + } + } + + code = stmtCreateRequest(pStmt); + if (code) { + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + finalCode = code; + continue; + } + + STableMeta* pTableMeta = NULL; + SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter, + .requestId = pStmt->exec.pRequest->requestId, + .requestObjRefId = pStmt->exec.pRequest->self, + .mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)}; + code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta); + + pStmt->stat.ctgGetTbMetaNum++; + + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + + if (code || NULL == pTableMeta) { + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + finalCode = code; + taosMemoryFree(pTableMeta); + continue; + } + + pMeta->uid = pTableMeta->uid; + pStmt->bInfo.tbUid = pTableMeta->uid; + taosMemoryFree(pTableMeta); + } + + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + } + + return finalCode; +} +*/ +/* +int stmtStaticModeExec(TAOS_STMT* stmt) { + STscStmt2* pStmt = (STscStmt2*)stmt; + int32_t code = 0; + SSubmitRsp* pRsp = NULL; + if (pStmt->sql.staticMode) { + return TSDB_CODE_TSC_STMT_API_ERROR; + } + + STMT_DLOG_E("start to exec"); + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE)); + + STMT_ERR_RET(qBuildStmtOutputFromTbList(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->exec.pTbBlkList, +pStmt->exec.pCurrBlock, pStmt->exec.tbBlkNum)); + + launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL); + + if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) { + code = refreshMeta(pStmt->exec.pRequest->pTscObj, pStmt->exec.pRequest); + if (code) { + pStmt->exec.pRequest->code = code; + } else { + tFreeSSubmitRsp(pRsp); + STMT_ERR_RET(stmtResetStmt(pStmt)); + STMT_ERR_RET(TSDB_CODE_NEED_RETRY); + } + } + + STMT_ERR_JRET(pStmt->exec.pRequest->code); + + pStmt->exec.affectedRows = taos_affected_rows(pStmt->exec.pRequest); + pStmt->affectedRows += pStmt->exec.affectedRows; + +_return: + + stmtCleanExecInfo(pStmt, (code ? false : true), false); + + tFreeSSubmitRsp(pRsp); + + ++pStmt->sql.runTimes; + + STMT_RET(code); +} +*/ + +static int32_t createParseContext(const SRequestObj* pRequest, SParseContext** pCxt, SSqlCallbackWrapper* pWrapper) { + const STscObj* pTscObj = pRequest->pTscObj; + + *pCxt = taosMemoryCalloc(1, sizeof(SParseContext)); + if (*pCxt == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + **pCxt = (SParseContext){.requestId = pRequest->requestId, + .requestRid = pRequest->self, + .acctId = pTscObj->acctId, + .db = pRequest->pDb, + .topicQuery = false, + .pSql = pRequest->sqlstr, + .sqlLen = pRequest->sqlLen, + .pMsg = pRequest->msgBuf, + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, + .pTransporter = pTscObj->pAppInfo->pTransporter, + .pStmtCb = NULL, + .pUser = pTscObj->user, + .pEffectiveUser = pRequest->effectiveUser, + .isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)), + .enableSysInfo = pTscObj->sysInfo, + .async = true, + .svrVer = pTscObj->sVer, + .nodeOffline = (pTscObj->pAppInfo->onlineDnodes < pTscObj->pAppInfo->totalDnodes), + .allocatorId = pRequest->allocatorRefId, + .parseSqlFp = clientParseSql, + .parseSqlParam = pWrapper}; + int8_t biMode = atomic_load_8(&((STscObj*)pTscObj)->biMode); + (*pCxt)->biMode = biMode; + return TSDB_CODE_SUCCESS; +} + +static void asyncQueryCb(void* userdata, TAOS_RES* res, int code) { + STscStmt2* pStmt = userdata; + __taos_async_fn_t fp = pStmt->options.asyncExecFn; + + pStmt->exec.affectedRows = taos_affected_rows(pStmt->exec.pRequest); + pStmt->affectedRows += pStmt->exec.affectedRows; + + fp(pStmt->options.userdata, res, code); + + while (0 == atomic_load_8((int8_t*)&pStmt->sql.siInfo.tableColsReady)) { + taosUsleep(1); + } + (void)stmtCleanExecInfo(pStmt, (code ? false : true), false); + ++pStmt->sql.runTimes; + + (void)tsem_post(&pStmt->asyncQuerySem); +} + +int stmtExec2(TAOS_STMT2* stmt, int* affected_rows) { + STscStmt2* pStmt = (STscStmt2*)stmt; + int32_t code = 0; + int64_t startUs = taosGetTimestampUs(); + + STMT_DLOG_E("start to exec"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE)); + + if (STMT_TYPE_QUERY != pStmt->sql.type) { + if (pStmt->sql.stbInterlaceMode) { + int64_t startTs = taosGetTimestampUs(); + while (atomic_load_64(&pStmt->sql.siInfo.tbRemainNum)) { + taosUsleep(1); + } + pStmt->stat.execWaitUs += taosGetTimestampUs() - startTs; + + STMT_ERR_RET(qBuildStmtFinOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->sql.siInfo.pVgroupList)); + taosHashCleanup(pStmt->sql.siInfo.pVgroupHash); + pStmt->sql.siInfo.pVgroupHash = NULL; + pStmt->sql.siInfo.pVgroupList = NULL; + } else { + tDestroySubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE); + taosMemoryFreeClear(pStmt->exec.pCurrTbData); + + STMT_ERR_RET(qCloneCurrentTbData(pStmt->exec.pCurrBlock, &pStmt->exec.pCurrTbData)); + + STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->exec.pBlockHash)); + } + } + + SRequestObj* pRequest = pStmt->exec.pRequest; + __taos_async_fn_t fp = pStmt->options.asyncExecFn; + + if (!fp) { + (void)launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL); + + if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) { + code = refreshMeta(pStmt->exec.pRequest->pTscObj, pStmt->exec.pRequest); + if (code) { + pStmt->exec.pRequest->code = code; + } else { + STMT_ERR_RET(stmtResetStmt(pStmt)); + STMT_ERR_RET(TSDB_CODE_NEED_RETRY); + } + } + + STMT_ERR_JRET(pStmt->exec.pRequest->code); + + pStmt->exec.affectedRows = taos_affected_rows(pStmt->exec.pRequest); + if (affected_rows) { + *affected_rows = pStmt->exec.affectedRows; + } + pStmt->affectedRows += pStmt->exec.affectedRows; + + while (0 == atomic_load_8((int8_t*)&pStmt->sql.siInfo.tableColsReady)) { + taosUsleep(1); + } + + STMT_ERR_RET(stmtCleanExecInfo(pStmt, (code ? false : true), false)); + + ++pStmt->sql.runTimes; + + } else { + SSqlCallbackWrapper* pWrapper = taosMemoryCalloc(1, sizeof(SSqlCallbackWrapper)); + if (pWrapper == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + } else { + pWrapper->pRequest = pRequest; + pRequest->pWrapper = pWrapper; + } + if (TSDB_CODE_SUCCESS == code) { + code = createParseContext(pRequest, &pWrapper->pParseCtx, pWrapper); + } + pRequest->syncQuery = false; + pRequest->body.queryFp = asyncQueryCb; + ((SSyncQueryParam*)(pRequest)->body.interParam)->userParam = pStmt; + + launchAsyncQuery(pRequest, pStmt->sql.pQuery, NULL, pWrapper); + } + +_return: + pStmt->stat.execUseUs += taosGetTimestampUs() - startUs; + + STMT_RET(code); +} + +int stmtClose2(TAOS_STMT2* stmt) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG_E("start to free stmt"); + + pStmt->queue.stopQueue = true; + + if (pStmt->bindThreadInUse) { + (void)taosThreadJoin(pStmt->bindThread, NULL); + pStmt->bindThreadInUse = false; + } + + STMT_DLOG("stmt %p closed, stbInterlaceMode: %d, statInfo: ctgGetTbMetaNum=>%" PRId64 ", getCacheTbInfo=>%" PRId64 + ", parseSqlNum=>%" PRId64 ", pStmt->stat.bindDataNum=>%" PRId64 + ", settbnameAPI:%u, bindAPI:%u, addbatchAPI:%u, execAPI:%u" + ", setTbNameUs:%" PRId64 ", bindDataUs:%" PRId64 ",%" PRId64 ",%" PRId64 ",%" PRId64 " addBatchUs:%" PRId64 + ", execWaitUs:%" PRId64 ", execUseUs:%" PRId64, + pStmt, pStmt->sql.stbInterlaceMode, pStmt->stat.ctgGetTbMetaNum, pStmt->stat.getCacheTbInfo, + pStmt->stat.parseSqlNum, pStmt->stat.bindDataNum, pStmt->seqIds[STMT_SETTBNAME], pStmt->seqIds[STMT_BIND], + pStmt->seqIds[STMT_ADD_BATCH], pStmt->seqIds[STMT_EXECUTE], pStmt->stat.setTbNameUs, + pStmt->stat.bindDataUs1, pStmt->stat.bindDataUs2, pStmt->stat.bindDataUs3, pStmt->stat.bindDataUs4, + pStmt->stat.addBatchUs, pStmt->stat.execWaitUs, pStmt->stat.execUseUs); + + STMT_ERR_RET(stmtCleanSQLInfo(pStmt)); + + if (pStmt->options.asyncExecFn) { + (void)tsem_destroy(&pStmt->asyncQuerySem); + } + taosMemoryFree(stmt); + + return TSDB_CODE_SUCCESS; +} + +const char* stmtErrstr2(TAOS_STMT2* stmt) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + if (stmt == NULL || NULL == pStmt->exec.pRequest) { + return (char*)tstrerror(terrno); + } + + pStmt->exec.pRequest->code = terrno; + + return taos_errstr(pStmt->exec.pRequest); +} +/* +int stmtAffectedRows(TAOS_STMT* stmt) { return ((STscStmt2*)stmt)->affectedRows; } + +int stmtAffectedRowsOnce(TAOS_STMT* stmt) { return ((STscStmt2*)stmt)->exec.affectedRows; } +*/ +int stmtGetTagFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) { + int32_t code = 0; + STscStmt2* pStmt = (STscStmt2*)stmt; + int32_t preCode = pStmt->errCode; + + STMT_DLOG_E("start to get tag fields"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + STMT_ERRI_JRET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); + + if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && + STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { + pStmt->bInfo.needParse = false; + } + + if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + } + + STMT_ERRI_JRET(stmtCreateRequest(pStmt)); + + if (pStmt->bInfo.needParse) { + STMT_ERRI_JRET(stmtParseSql(pStmt)); + } + + STMT_ERRI_JRET(stmtFetchTagFields2(stmt, nums, fields)); + +_return: + + pStmt->errCode = preCode; + + return code; +} + +int stmtGetColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) { + int32_t code = 0; + STscStmt2* pStmt = (STscStmt2*)stmt; + int32_t preCode = pStmt->errCode; + + STMT_DLOG_E("start to get col fields"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + STMT_ERRI_JRET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); + + if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && + STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { + pStmt->bInfo.needParse = false; + } + + if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + STMT_ERR_RET(stmtCreateRequest(pStmt)); + } + + STMT_ERRI_JRET(stmtCreateRequest(pStmt)); + + if (pStmt->bInfo.needParse) { + STMT_ERRI_JRET(stmtParseSql(pStmt)); + } + + STMT_ERRI_JRET(stmtFetchColFields2(stmt, nums, fields)); + +_return: + + pStmt->errCode = preCode; + + return code; +} + +int stmtGetParamNum2(TAOS_STMT2* stmt, int* nums) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG_E("start to get param num"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); + + if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && + STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { + pStmt->bInfo.needParse = false; + } + + if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + } + + STMT_ERR_RET(stmtCreateRequest(pStmt)); + + if (pStmt->bInfo.needParse) { + STMT_ERR_RET(stmtParseSql(pStmt)); + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + *nums = taosArrayGetSize(pStmt->sql.pQuery->pPlaceholderValues); + } else { + STMT_ERR_RET(stmtFetchColFields2(stmt, nums, NULL)); + } + + return TSDB_CODE_SUCCESS; +} + +int stmtGetParamTbName(TAOS_STMT2* stmt, int* nums) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG_E("start to get param num"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); + + if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && + STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { + pStmt->bInfo.needParse = false; + } + + if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + } + + STMT_ERR_RET(stmtCreateRequest(pStmt)); + + if (pStmt->bInfo.needParse) { + STMT_ERR_RET(stmtParseSql(pStmt)); + } + + *nums = STMT_TYPE_MULTI_INSERT == pStmt->sql.type ? 1 : 0; + + return TSDB_CODE_SUCCESS; +} +/* +int stmtGetParam(TAOS_STMT* stmt, int idx, int* type, int* bytes) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG_E("start to get param"); + + if (pStmt->errCode != TSDB_CODE_SUCCESS) { + return pStmt->errCode; + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); + + if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && + STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { + pStmt->bInfo.needParse = false; + } + + if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + } + + STMT_ERR_RET(stmtCreateRequest(pStmt)); + + if (pStmt->bInfo.needParse) { + STMT_ERR_RET(stmtParseSql(pStmt)); + } + + int32_t nums = 0; + TAOS_FIELD_E* pField = NULL; + STMT_ERR_RET(stmtFetchColFields(stmt, &nums, &pField)); + if (idx >= nums) { + tscError("idx %d is too big", idx); + taosMemoryFree(pField); + STMT_ERR_RET(TSDB_CODE_INVALID_PARA); + } + + *type = pField[idx].type; + *bytes = pField[idx].bytes; + + taosMemoryFree(pField); + + return TSDB_CODE_SUCCESS; +} +*/ +TAOS_RES* stmtUseResult2(TAOS_STMT2* stmt) { + STscStmt2* pStmt = (STscStmt2*)stmt; + + STMT_DLOG_E("start to use result"); + + if (STMT_TYPE_QUERY != pStmt->sql.type) { + tscError("useResult only for query statement"); + return NULL; + } + + return pStmt->exec.pRequest; +} diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 8e50c943b9..ea3e88919b 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -849,7 +849,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd int32_t blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int32_t rowCount, SSDataBlock** pResBlock) { int32_t code = 0; - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); if (pBlock == NULL || startIndex < 0 || rowCount > pBlock->info.rows || rowCount + startIndex > pBlock->info.rows) { return TSDB_CODE_INVALID_PARA; @@ -1263,18 +1263,19 @@ static void blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataBloc } static int32_t createHelpColInfoData(const SSDataBlock* pDataBlock, SColumnInfoData** ppCols) { - *ppCols = NULL; - int32_t code = 0; int32_t rows = pDataBlock->info.capacity; size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); + int32_t i = 0; + + *ppCols = NULL; SColumnInfoData* pCols = taosMemoryCalloc(numOfCols, sizeof(SColumnInfoData)); if (pCols == NULL) { return terrno; } - for (int32_t i = 0; i < numOfCols; ++i) { + for (i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, i); if (pColInfoData == NULL) { continue; @@ -1309,6 +1310,10 @@ static int32_t createHelpColInfoData(const SSDataBlock* pDataBlock, SColumnInfoD return code; _error: + for(int32_t j = 0; j < i; ++j) { + colDataDestroy(&pCols[j]); + } + taosMemoryFree(pCols); return code; } @@ -1753,7 +1758,7 @@ int32_t copyDataBlock(SSDataBlock* pDst, const SSDataBlock* pSrc) { } int32_t createSpecialDataBlock(EStreamType type, SSDataBlock** pBlock) { - QRY_OPTR_CHECK(pBlock); + QRY_PARAM_CHECK(pBlock); int32_t code = 0; SSDataBlock* p = taosMemoryCalloc(1, sizeof(SSDataBlock)); @@ -1846,7 +1851,7 @@ _err: } int32_t blockCopyOneRow(const SSDataBlock* pDataBlock, int32_t rowIdx, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); if (pDataBlock == NULL) { return TSDB_CODE_INVALID_PARA; @@ -1946,7 +1951,7 @@ _end: } int32_t createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); if (pDataBlock == NULL) { return TSDB_CODE_INVALID_PARA; } @@ -2029,7 +2034,7 @@ int32_t createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData, SSDataB } int32_t createDataBlock(SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); if (pBlock == NULL) { return terrno; @@ -2080,7 +2085,7 @@ SColumnInfoData createColumnInfoData(int16_t type, int32_t bytes, int16_t colId) int32_t bdGetColumnInfoData(const SSDataBlock* pBlock, int32_t index, SColumnInfoData** pColInfoData) { int32_t code = 0; - QRY_OPTR_CHECK(pColInfoData); + QRY_PARAM_CHECK(pColInfoData); if (index >= taosArrayGetSize(pBlock->pDataBlock)) { return TSDB_CODE_INVALID_PARA; @@ -2402,10 +2407,18 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock) { } else { buf = taosDecodeBinary(buf, (void**)&data.nullbitmap, BitmapLen(pBlock->info.rows)); } + if(buf == NULL) { + uError("failed to decode null bitmap/offset, type:%d", data.info.type); + goto _error; + } int32_t len = 0; buf = taosDecodeFixedI32(buf, &len); buf = taosDecodeBinary(buf, (void**)&data.pData, len); + if (buf == NULL) { + uError("failed to decode data, type:%d", data.info.type); + goto _error; + } if (IS_VAR_DATA_TYPE(data.info.type)) { data.varmeta.length = len; data.varmeta.allocLen = len; @@ -2418,6 +2431,15 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock) { } return (void*)buf; +_error: + for (int32_t i = 0; i < sz; ++i) { + SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i); + if (pColInfoData == NULL) { + break; + } + colDataDestroy(pColInfoData); + } + return NULL; } static char* formatTimestamp(char* buf, int64_t val, int precision) { @@ -2854,7 +2876,7 @@ bool alreadyAddGroupId(char* ctbName, int64_t groupId) { } int32_t buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId, char** pName) { - QRY_OPTR_CHECK(pName); + QRY_PARAM_CHECK(pName); char* pBuf = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1); if (!pBuf) { @@ -3009,6 +3031,12 @@ int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) { data += colSizes[col]; } + if (colSizes[col] <= 0 && !colDataIsNull_s(pColRes, 0) && pColRes->info.type != TSDB_DATA_TYPE_NULL) { + uError("Invalid colSize:%d colIdx:%d colType:%d while encoding block", colSizes[col], col, pColRes->info.type); + terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + return -1; + } + colSizes[col] = htonl(colSizes[col]); // uError("blockEncode col bytes:%d, type:%d, size:%d, htonl size:%d", pColRes->info.bytes, pColRes->info.type, // htonl(colSizes[col]), colSizes[col]); @@ -3036,6 +3064,11 @@ int32_t blockDecode(SSDataBlock* pBlock, const char* pData, const char** pEndPos // total rows sizeof(int32_t) int32_t numOfRows = *(int32_t*)pStart; pStart += sizeof(int32_t); + if (numOfRows <= 0) { + uError("block decode numOfRows:%d error", numOfRows); + terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + return terrno; + } // total columns sizeof(int32_t) int32_t numOfCols = *(int32_t*)pStart; @@ -3115,14 +3148,19 @@ int32_t blockDecode(SSDataBlock* pBlock, const char* pData, const char** pEndPos pStart += BitmapLen(numOfRows); } - if (colLen[i] > 0) { - memcpy(pColInfoData->pData, pStart, colLen[i]); - } - // TODO // setting this flag to true temporarily so aggregate function on stable will // examine NULL value for non-primary key column pColInfoData->hasNull = true; + + if (colLen[i] > 0) { + memcpy(pColInfoData->pData, pStart, colLen[i]); + } else if (!colDataIsNull_s(pColInfoData, 0) && pColInfoData->info.type != TSDB_DATA_TYPE_NULL) { + uError("block decode colLen:%d error, colIdx:%d, type:%d", colLen[i], i, pColInfoData->info.type); + terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + return terrno; + } + pStart += colLen[i]; } diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index b831860512..24e669577a 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -3124,6 +3124,198 @@ _exit: return code; } +int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen) { + int32_t code = 0; + + if (!(pBind->num == 1 && pBind->is_null && *pBind->is_null)) { + if (!(pColData->type == pBind->buffer_type)) { + return TSDB_CODE_INVALID_PARA; + } + } + + if (IS_VAR_DATA_TYPE(pColData->type)) { // var-length data type + uint8_t *buf = pBind->buffer; + for (int32_t i = 0; i < pBind->num; ++i) { + if (pBind->is_null && pBind->is_null[i]) { + if (pColData->cflag & COL_IS_KEY) { + code = TSDB_CODE_PAR_PRIMARY_KEY_IS_NULL; + goto _exit; + } + if (pBind->is_null[i] == 1) { + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NULL](pColData, NULL, 0); + if (code) goto _exit; + } else { + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NONE](pColData, NULL, 0); + if (code) goto _exit; + } + } else if (pBind->length[i] > buffMaxLen) { + uError("var data length too big, len:%d, max:%d", pBind->length[i], buffMaxLen); + return TSDB_CODE_INVALID_PARA; + } else { + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, buf, pBind->length[i]); + buf += pBind->length[i]; + } + } + } else { // fixed-length data type + bool allValue; + bool allNull; + bool allNone; + if (pBind->is_null) { + bool same = (memcmp(pBind->is_null, pBind->is_null + 1, pBind->num - 1) == 0); + allNull = (same && pBind->is_null[0] == 1); + allNone = (same && pBind->is_null[0] > 1); + allValue = (same && pBind->is_null[0] == 0); + } else { + allNull = false; + allNone = false; + allValue = true; + } + + if ((pColData->cflag & COL_IS_KEY) && !allValue) { + code = TSDB_CODE_PAR_PRIMARY_KEY_IS_NULL; + goto _exit; + } + + if (allValue) { + // optimize (todo) + for (int32_t i = 0; i < pBind->num; ++i) { + uint8_t *val = (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i; + if (TSDB_DATA_TYPE_BOOL == pColData->type && *val > 1) { + *val = 1; + } + + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, val, TYPE_BYTES[pColData->type]); + } + } else if (allNull) { + // optimize (todo) + for (int32_t i = 0; i < pBind->num; ++i) { + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NULL](pColData, NULL, 0); + if (code) goto _exit; + } + } else if (allNone) { + // optimize (todo) + for (int32_t i = 0; i < pBind->num; ++i) { + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NONE](pColData, NULL, 0); + if (code) goto _exit; + } + } else { + for (int32_t i = 0; i < pBind->num; ++i) { + if (pBind->is_null[i]) { + if (pBind->is_null[i] == 1) { + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NULL](pColData, NULL, 0); + if (code) goto _exit; + } else { + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NONE](pColData, NULL, 0); + if (code) goto _exit; + } + } else { + uint8_t *val = (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i; + if (TSDB_DATA_TYPE_BOOL == pColData->type && *val > 1) { + *val = 1; + } + + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, val, TYPE_BYTES[pColData->type]); + } + } + } + } + +_exit: + return code; +} + +/* build rows to `rowArray` from bind + * `infos` is the bind information array + * `numOfInfos` is the number of bind information + * `infoSorted` is whether the bind information is sorted by column id + * `pTSchema` is the schema of the table + * `rowArray` is the array to store the rows + */ +int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema, + SArray *rowArray) { + if (infos == NULL || numOfInfos <= 0 || numOfInfos > pTSchema->numOfCols || pTSchema == NULL || rowArray == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + if (!infoSorted) { + taosqsort_r(infos, numOfInfos, sizeof(SBindInfo), NULL, tBindInfoCompare); + } + + int32_t code = 0; + int32_t numOfRows = infos[0].bind->num; + SArray *colValArray, *bufArray; + SColVal colVal; + + if ((colValArray = taosArrayInit(numOfInfos, sizeof(SColVal))) == NULL) { + return terrno; + } + if ((bufArray = taosArrayInit(numOfInfos, sizeof(uint8_t *))) == NULL) { + taosArrayDestroy(colValArray); + return TSDB_CODE_OUT_OF_MEMORY; + } + for (int i = 0; i < numOfInfos; ++i) { + if (!taosArrayPush(bufArray, &infos[i].bind->buffer)) { + taosArrayDestroy(colValArray); + taosArrayDestroy(bufArray); + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + for (int32_t iRow = 0; iRow < numOfRows; iRow++) { + taosArrayClear(colValArray); + + for (int32_t iInfo = 0; iInfo < numOfInfos; iInfo++) { + if (infos[iInfo].bind->is_null && infos[iInfo].bind->is_null[iRow]) { + if (infos[iInfo].bind->is_null[iRow] == 1) { + colVal = COL_VAL_NULL(infos[iInfo].columnId, infos[iInfo].type); + } else { + colVal = COL_VAL_NONE(infos[iInfo].columnId, infos[iInfo].type); + } + } else { + SValue value = { + .type = infos[iInfo].type, + }; + if (IS_VAR_DATA_TYPE(infos[iInfo].type)) { + int32_t length = infos[iInfo].bind->length[iRow]; + uint8_t **data = &((uint8_t **)TARRAY_DATA(bufArray))[iInfo]; + value.nData = length; + value.pData = *data; + *data += length; + // value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow; + } else { + uint8_t *val = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bytes * iRow; + if (TSDB_DATA_TYPE_BOOL == value.type && *val > 1) { + *val = 1; + } + (void)memcpy(&value.val, val, + /*(uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow,*/ + infos[iInfo].bytes /*bind->buffer_length*/); + } + colVal = COL_VAL_VALUE(infos[iInfo].columnId, value); + } + if (taosArrayPush(colValArray, &colVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + } + + SRow *row; + if ((code = tRowBuild(colValArray, pTSchema, &row))) { + goto _exit; + } + + if ((taosArrayPush(rowArray, &row)) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + } + +_exit: + taosArrayDestroy(colValArray); + taosArrayDestroy(bufArray); + return code; +} + static int32_t tColDataCopyRowCell(SColData *pFromColData, int32_t iFromRow, SColData *pToColData, int32_t iToRow) { int32_t code = TSDB_CODE_SUCCESS; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 367eb68865..5b67e1267b 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -615,7 +615,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { tsKeepAliveIdle = TRANGE(tsKeepAliveIdle, 1, 72000); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "keepAliveIdle", tsKeepAliveIdle, 1, 7200000, CFG_SCOPE_BOTH, CFG_DYN_ENT_BOTH)); - tsNumOfTaskQueueThreads = tsNumOfCores; + tsNumOfTaskQueueThreads = tsNumOfCores * 2; tsNumOfTaskQueueThreads = TMAX(tsNumOfTaskQueueThreads, 16); TAOS_CHECK_RETURN( diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 7c2cfd83c9..bf4a91b224 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -43,22 +43,22 @@ #include "tcol.h" #include "tlog.h" -#define DECODESQL() \ - do { \ - if (!tDecodeIsEnd(&decoder)) { \ - if (tDecodeI32(&decoder, &pReq->sqlLen) < 0) return -1; \ - if (pReq->sqlLen > 0) { \ - if (tDecodeBinaryAlloc(&decoder, (void **)&pReq->sql, NULL) < 0) return -1; \ - } \ - } \ +#define DECODESQL() \ + do { \ + if (!tDecodeIsEnd(&decoder)) { \ + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->sqlLen)); \ + if (pReq->sqlLen > 0) { \ + TAOS_CHECK_EXIT(tDecodeBinaryAlloc(&decoder, (void **)&pReq->sql, NULL)); \ + } \ + } \ } while (0) -#define ENCODESQL() \ - do { \ - if (tEncodeI32(&encoder, pReq->sqlLen) < 0) return -1; \ - if (pReq->sqlLen > 0) { \ - if (tEncodeBinary(&encoder, pReq->sql, pReq->sqlLen) < 0) return -1; \ - } \ +#define ENCODESQL() \ + do { \ + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->sqlLen)); \ + if (pReq->sqlLen > 0) { \ + TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)pReq->sql, pReq->sqlLen)); \ + } \ } while (0) #define FREESQL() \ @@ -1243,19 +1243,7 @@ _exit: tDecoderClear(&decoder); return code; } -// int32_t tSerializeSDropTagIdxReq(void *buf, int32_t bufLen, SDropTagIndexReq *pReq) { -// SEncoder encoder = {0}; -// tEncoderInit(&encoder, buf, bufLen); -// if (tStartEncode(&encoder) < 0) return -1; -// tEndEncode(&encoder); -// if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; -// if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1; - -// int32_t tlen = encoder.pos; -// tEncoderClear(&encoder); -// return tlen; -// } int32_t tDeserializeSDropTagIdxReq(void *buf, int32_t bufLen, SDropTagIndexReq *pReq) { SDecoder decoder = {0}; int32_t code = 0; @@ -1307,32 +1295,6 @@ void tFreeSMCreateFullTextReq(SMCreateFullTextReq *pReq) { // impl later return; } -// int32_t tSerializeSMDropFullTextReq(void *buf, int32_t bufLen, SMDropFullTextReq *pReq) { -// SEncoder encoder = {0}; -// tEncoderInit(&encoder, buf, bufLen); - -// if (tStartEncode(&encoder) < 0) return -1; - -// if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; - -// if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1; - -// tEndEncode(&encoder); -// int32_t tlen = encoder.pos; -// tEncoderClear(&encoder); -// return tlen; -// } -// int32_t tDeserializeSMDropFullTextReq(void *buf, int32_t bufLen, SMDropFullTextReq *pReq) { -// SDecoder decoder = {0}; -// tDecoderInit(&decoder, buf, bufLen); -// if (tStartDecode(&decoder) < 0) return -1; -// if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; -// if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1; - -// tEndDecode(&decoder); -// tDecoderClear(&decoder); -// return 0; -// } int32_t tSerializeSNotifyReq(void *buf, int32_t bufLen, SNotifyReq *pReq) { SEncoder encoder = {0}; @@ -2108,7 +2070,7 @@ int32_t tSerializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq) if (len > 0) { TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tabName)); } - TAOS_CHECK_EXIT(tEncodeBinary(&encoder, pReq->tagCond, pReq->tagCondLen)); + TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)pReq->tagCond, pReq->tagCondLen)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->numIpRanges)); for (int32_t i = 0; i < pReq->numIpRanges; ++i) { TAOS_CHECK_EXIT(tEncodeU32(&encoder, pReq->pIpRanges[i].ip)); @@ -3386,6 +3348,8 @@ void tFreeSRetrieveFuncRsp(SRetrieveFuncRsp *pRsp) { } int32_t tSerializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) { + int32_t code = 0; + int32_t lino; int32_t headLen = sizeof(SMsgHead); if (buf != NULL) { buf = (char *)buf + headLen; @@ -3395,26 +3359,34 @@ int32_t tSerializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->tbName) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dbFName)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tbName)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); +_exit: + if (code) { + tEncoderClear(&encoder); + return code; + } else { + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); - if (buf != NULL) { - SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); - pHead->vgId = htonl(pReq->header.vgId); - pHead->contLen = htonl(tlen + headLen); + if (buf != NULL) { + SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); + pHead->vgId = htonl(pReq->header.vgId); + pHead->contLen = htonl(tlen + headLen); + } + + return tlen + headLen; } - - return tlen + headLen; } int32_t tDeserializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) { int32_t headLen = sizeof(SMsgHead); + int32_t code = 0; + int32_t lino; SMsgHead *pHead = buf; pHead->vgId = pReq->header.vgId; pHead->contLen = pReq->header.contLen; @@ -3422,13 +3394,14 @@ int32_t tDeserializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) SDecoder decoder = {0}; tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->tbName) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->tbName)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) { @@ -4683,14 +4656,22 @@ _exit: int32_t tSerializeSTrimDbReq(void *buf, int32_t bufLen, STrimDbReq *pReq) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; - if (tEncodeI32(&encoder, pReq->maxSpeed) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->db)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->maxSpeed)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } @@ -5726,6 +5707,8 @@ void tFreeSSTbHbRsp(SSTbHbRsp *pRsp) { int32_t tSerializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) { int32_t headLen = sizeof(SMsgHead); + int32_t code = 0; + int32_t lino; if (buf != NULL) { buf = (char *)buf + headLen; bufLen -= headLen; @@ -5734,26 +5717,33 @@ int32_t tSerializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->tbName) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dbFName)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tbName)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); +_exit: + if (code) { + tEncoderClear(&encoder); + return code; + } else { + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); - if (buf != NULL) { - SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); - pHead->vgId = htonl(pReq->header.vgId); - pHead->contLen = htonl(tlen + headLen); + if (buf != NULL) { + SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); + pHead->vgId = htonl(pReq->header.vgId); + pHead->contLen = htonl(tlen + headLen); + } + + return tlen + headLen; } - - return tlen + headLen; } int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) { - int32_t headLen = sizeof(SMsgHead); - + int32_t headLen = sizeof(SMsgHead); + int32_t code = 0; + int32_t lino; SMsgHead *pHead = buf; pHead->vgId = pReq->header.vgId; pHead->contLen = pReq->header.contLen; @@ -5761,13 +5751,14 @@ int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq SDecoder decoder = {0}; tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->tbName) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->tbName)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } int32_t tSerializeSMDropTopicReq(void *buf, int32_t bufLen, SMDropTopicReq *pReq) { @@ -6393,7 +6384,7 @@ int32_t tSerializeSQueryCompactProgressReq(void *buf, int32_t bufLen, SQueryComp int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->compactId)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->vgId)); @@ -7768,7 +7759,9 @@ int32_t tDeserializeSMArbUpdateGroupBatchReq(void *buf, int32_t bufLen, SMArbUpd TAOS_CHECK_EXIT(tDecodeI32(&decoder, &sz)); SArray *updateArray = taosArrayInit(sz, sizeof(SMArbUpdateGroup)); - if (!updateArray) return -1; + if (!updateArray) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < sz; i++) { SMArbUpdateGroup group = {0}; @@ -7939,6 +7932,8 @@ void tFreeSExplainRsp(SExplainRsp *pRsp) { } int32_t tSerializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) { + int32_t code = 0; + int32_t lino; int32_t headLen = sizeof(SMsgHead); if (buf != NULL) { buf = (char *)buf + headLen; @@ -7947,35 +7942,42 @@ int32_t tSerializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); int32_t num = taosArrayGetSize(pReq->pMsgs); - if (tEncodeI32(&encoder, num) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(&encoder, num)); for (int32_t i = 0; i < num; ++i) { SBatchMsg *pMsg = taosArrayGet(pReq->pMsgs, i); - if (tEncodeI32(&encoder, pMsg->msgIdx) < 0) return -1; - if (tEncodeI32(&encoder, pMsg->msgType) < 0) return -1; - if (tEncodeI32(&encoder, pMsg->msgLen) < 0) return -1; - if (tEncodeBinary(&encoder, pMsg->msg, pMsg->msgLen) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pMsg->msgIdx)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pMsg->msgType)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pMsg->msgLen)); + TAOS_CHECK_EXIT(tEncodeBinary(&encoder, pMsg->msg, pMsg->msgLen)); } tEndEncode(&encoder); - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); +_exit: + if (code) { + tEncoderClear(&encoder); + return code; + } else { + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); - if (buf != NULL) { - SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); - pHead->vgId = htonl(pReq->header.vgId); - pHead->contLen = htonl(tlen + headLen); + if (buf != NULL) { + SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); + pHead->vgId = htonl(pReq->header.vgId); + pHead->contLen = htonl(tlen + headLen); + } + + return tlen + headLen; } - - return tlen + headLen; } int32_t tDeserializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) { - int32_t headLen = sizeof(SMsgHead); - + int32_t headLen = sizeof(SMsgHead); + int32_t code = 0; + int32_t lino; SMsgHead *pHead = buf; pHead->vgId = pReq->header.vgId; pHead->contLen = pReq->header.contLen; @@ -7983,33 +7985,37 @@ int32_t tDeserializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) { SDecoder decoder = {0}; tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen); - if (tStartDecode(&decoder) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); int32_t num = 0; - if (tDecodeI32(&decoder, &num) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &num)); if (num <= 0) { pReq->pMsgs = NULL; tEndDecode(&decoder); - tDecoderClear(&decoder); return 0; } pReq->pMsgs = taosArrayInit(num, sizeof(SBatchMsg)); - if (NULL == pReq->pMsgs) return -1; + if (NULL == pReq->pMsgs) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < num; ++i) { SBatchMsg msg = {0}; - if (tDecodeI32(&decoder, &msg.msgIdx) < 0) return -1; - if (tDecodeI32(&decoder, &msg.msgType) < 0) return -1; - if (tDecodeI32(&decoder, &msg.msgLen) < 0) return -1; - if (tDecodeBinaryAlloc(&decoder, &msg.msg, NULL) < 0) return -1; - if (NULL == taosArrayPush(pReq->pMsgs, &msg)) return -1; + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &msg.msgIdx)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &msg.msgType)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &msg.msgLen)); + TAOS_CHECK_EXIT(tDecodeBinaryAlloc(&decoder, &msg.msg, NULL)); + if (NULL == taosArrayPush(pReq->pMsgs, &msg)) { + TAOS_CHECK_EXIT(terrno); + } } tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } int32_t tSerializeSBatchRsp(void *buf, int32_t bufLen, SBatchRsp *pRsp) { @@ -8170,7 +8176,9 @@ int32_t tDeserializeSMqHbRsp(void *buf, int32_t bufLen, SMqHbRsp *pRsp) { TAOS_CHECK_EXIT(tDecodeI32(&decoder, &sz)); if (sz > 0) { pRsp->topicPrivileges = taosArrayInit(sz, sizeof(STopicPrivilege)); - if (NULL == pRsp->topicPrivileges) return -1; + if (NULL == pRsp->topicPrivileges) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < sz; ++i) { STopicPrivilege *data = taosArrayReserve(pRsp->topicPrivileges, 1); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, data->topic)); @@ -8534,7 +8542,7 @@ int32_t tSerializeSResFetchReq(void *buf, int32_t bufLen, SResFetchReq *pReq) { TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->execId)); if (pReq->pOpParam) { TAOS_CHECK_EXIT(tEncodeI32(&encoder, 1)); - if (tSerializeSOperatorParam(&encoder, pReq->pOpParam) < 0) return -1; + TAOS_CHECK_EXIT(tSerializeSOperatorParam(&encoder, pReq->pOpParam)); } else { TAOS_CHECK_EXIT(tEncodeI32(&encoder, 0)); } @@ -9026,7 +9034,9 @@ int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp * TAOS_CHECK_EXIT(tDecodeI32(&decoder, &num)); if (num > 0) { pRsp->taskStatus = taosArrayInit(num, sizeof(STaskStatus)); - if (NULL == pRsp->taskStatus) return -1; + if (NULL == pRsp->taskStatus) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < num; ++i) { STaskStatus status = {0}; TAOS_CHECK_EXIT(tDecodeU64(&decoder, &status.queryId)); @@ -9294,8 +9304,12 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->maxDelay)); TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->watermark)); TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->igExpired)); - if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1; - if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1; + if (sqlLen > 0) { + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->sql)); + } + if (astLen > 0) { + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->ast)); + } TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->numOfTags)); for (int32_t i = 0; i < pReq->numOfTags; ++i) { SField *pField = taosArrayGet(pReq->pTags, i); @@ -9740,7 +9754,9 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) { TAOS_CHECK_EXIT(tDecodeI32(pCoder, &pReq->commentLen)); if (pReq->commentLen > 0) { pReq->comment = taosMemoryMalloc(pReq->commentLen + 1); - if (pReq->comment == NULL) return -1; + if (pReq->comment == NULL) { + TAOS_CHECK_EXIT(terrno); + } TAOS_CHECK_EXIT(tDecodeCStrTo(pCoder, pReq->comment)); } @@ -10017,100 +10033,30 @@ int32_t tDecodeSVDropStbReq(SDecoder *pCoder, SVDropStbReq *pReq) { } static int32_t tEncodeSSubmitBlkRsp(SEncoder *pEncoder, const SSubmitBlkRsp *pBlock) { - if (tStartEncode(pEncoder) < 0) return -1; + int32_t code = 0; + int32_t lino; + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); - if (tEncodeI32(pEncoder, pBlock->code) < 0) return -1; - if (tEncodeI64(pEncoder, pBlock->uid) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pBlock->code)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pBlock->uid)); if (pBlock->tblFName) { - if (tEncodeCStr(pEncoder, pBlock->tblFName) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pBlock->tblFName)); } else { - if (tEncodeCStr(pEncoder, "") < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, "")); } - if (tEncodeI32v(pEncoder, pBlock->numOfRows) < 0) return -1; - if (tEncodeI32v(pEncoder, pBlock->affectedRows) < 0) return -1; - if (tEncodeI64v(pEncoder, pBlock->sver) < 0) return -1; - if (tEncodeI32(pEncoder, pBlock->pMeta ? 1 : 0) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pBlock->numOfRows)); + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pBlock->affectedRows)); + TAOS_CHECK_EXIT(tEncodeI64v(pEncoder, pBlock->sver)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pBlock->pMeta ? 1 : 0)); if (pBlock->pMeta) { - if (tEncodeSTableMetaRsp(pEncoder, pBlock->pMeta) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSTableMetaRsp(pEncoder, pBlock->pMeta)); } tEndEncode(pEncoder); - return 0; +_exit: + return code; } -// static int32_t tDecodeSSubmitBlkRsp(SDecoder *pDecoder, SSubmitBlkRsp *pBlock) { -// if (tStartDecode(pDecoder) < 0) return -1; - -// if (tDecodeI32(pDecoder, &pBlock->code) < 0) return -1; -// if (tDecodeI64(pDecoder, &pBlock->uid) < 0) return -1; -// pBlock->tblFName = taosMemoryCalloc(TSDB_TABLE_FNAME_LEN, 1); -// if (NULL == pBlock->tblFName) return -1; -// if (tDecodeCStrTo(pDecoder, pBlock->tblFName) < 0) return -1; -// if (tDecodeI32v(pDecoder, &pBlock->numOfRows) < 0) return -1; -// if (tDecodeI32v(pDecoder, &pBlock->affectedRows) < 0) return -1; -// if (tDecodeI64v(pDecoder, &pBlock->sver) < 0) return -1; - -// int32_t meta = 0; -// if (tDecodeI32(pDecoder, &meta) < 0) return -1; -// if (meta) { -// pBlock->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); -// if (NULL == pBlock->pMeta) return -1; -// if (tDecodeSTableMetaRsp(pDecoder, pBlock->pMeta) < 0) return -1; -// } else { -// pBlock->pMeta = NULL; -// } - -// tEndDecode(pDecoder); -// return 0; -// } - -// int32_t tEncodeSSubmitRsp(SEncoder *pEncoder, const SSubmitRsp *pRsp) { -// int32_t nBlocks = taosArrayGetSize(pRsp->pArray); - -// if (tStartEncode(pEncoder) < 0) return -1; - -// if (tEncodeI32v(pEncoder, pRsp->numOfRows) < 0) return -1; -// if (tEncodeI32v(pEncoder, pRsp->affectedRows) < 0) return -1; -// if (tEncodeI32v(pEncoder, nBlocks) < 0) return -1; -// for (int32_t iBlock = 0; iBlock < nBlocks; iBlock++) { -// if (tEncodeSSubmitBlkRsp(pEncoder, (SSubmitBlkRsp *)taosArrayGet(pRsp->pArray, iBlock)) < 0) return -1; -// } - -// tEndEncode(pEncoder); -// return 0; -// } - -// int32_t tDecodeSSubmitRsp(SDecoder *pDecoder, SSubmitRsp *pRsp) { -// if (tStartDecode(pDecoder) < 0) return -1; - -// if (tDecodeI32v(pDecoder, &pRsp->numOfRows) < 0) return -1; -// if (tDecodeI32v(pDecoder, &pRsp->affectedRows) < 0) return -1; -// if (tDecodeI32v(pDecoder, &pRsp->nBlocks) < 0) return -1; -// pRsp->pBlocks = taosMemoryCalloc(pRsp->nBlocks, sizeof(*pRsp->pBlocks)); -// if (pRsp->pBlocks == NULL) return -1; -// for (int32_t iBlock = 0; iBlock < pRsp->nBlocks; iBlock++) { -// if (tDecodeSSubmitBlkRsp(pDecoder, pRsp->pBlocks + iBlock) < 0) return -1; -// } - -// tEndDecode(pDecoder); -// tDecoderClear(pDecoder); -// return 0; -// } - -// void tFreeSSubmitBlkRsp(void *param) { -// if (NULL == param) { -// return; -// } - -// SSubmitBlkRsp *pRsp = (SSubmitBlkRsp *)param; - -// taosMemoryFree(pRsp->tblFName); -// if (pRsp->pMeta) { -// taosMemoryFree(pRsp->pMeta->pSchemas); -// taosMemoryFree(pRsp->pMeta); -// } -// } - void tFreeSSubmitRsp(SSubmitRsp *pRsp) { if (NULL == pRsp) return; @@ -10129,239 +10075,239 @@ void tFreeSSubmitRsp(SSubmitRsp *pRsp) { } int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { - if (tStartEncode(pEncoder) < 0) return -1; + int32_t code = 0; + int32_t lino; - if (tEncodeCStr(pEncoder, pReq->tbName) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->action) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->colId) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->tbName)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->action)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->colId)); switch (pReq->action) { case TSDB_ALTER_TABLE_ADD_COLUMN: - if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->type) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->flags) < 0) return -1; - if (tEncodeI32v(pEncoder, pReq->bytes) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->colName)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->type)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->flags)); + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pReq->bytes)); break; case TSDB_ALTER_TABLE_DROP_COLUMN: - if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->colName)); break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: - if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->colModType) < 0) return -1; - if (tEncodeI32v(pEncoder, pReq->colModBytes) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->colName)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->colModType)); + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pReq->colModBytes)); break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: - if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1; - if (tEncodeCStr(pEncoder, pReq->colNewName) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->colName)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->colNewName)); break; case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: - if (tEncodeCStr(pEncoder, pReq->tagName) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->isNull) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->tagType) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->tagName)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->isNull)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->tagType)); if (!pReq->isNull) { - if (tEncodeBinary(pEncoder, pReq->pTagVal, pReq->nTagVal) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pReq->pTagVal, pReq->nTagVal)); } break; case TSDB_ALTER_TABLE_UPDATE_OPTIONS: - if (tEncodeI8(pEncoder, pReq->updateTTL) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->updateTTL)); if (pReq->updateTTL) { - if (tEncodeI32v(pEncoder, pReq->newTTL) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pReq->newTTL)); } - if (tEncodeI32v(pEncoder, pReq->newCommentLen) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pReq->newCommentLen)); if (pReq->newCommentLen > 0) { - if (tEncodeCStr(pEncoder, pReq->newComment) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->newComment)); } break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: - if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1; - if (tEncodeU32(pEncoder, pReq->compress) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->colName)); + TAOS_CHECK_EXIT(tEncodeU32(pEncoder, pReq->compress)); break; case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: - if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->type) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->flags) < 0) return -1; - if (tEncodeI32v(pEncoder, pReq->bytes) < 0) return -1; - if (tEncodeU32(pEncoder, pReq->compress) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pReq->colName)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->type)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->flags)); + TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pReq->bytes)); + TAOS_CHECK_EXIT(tEncodeU32(pEncoder, pReq->compress)); break; default: break; } - if (tEncodeI64(pEncoder, pReq->ctimeMs) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->source) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->ctimeMs)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->source)); tEndEncode(pEncoder); - return 0; +_exit: + return code; } static int32_t tDecodeSVAlterTbReqCommon(SDecoder *pDecoder, SVAlterTbReq *pReq) { - if (tDecodeCStr(pDecoder, &pReq->tbName) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->action) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->colId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->tbName)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->action)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->colId)); switch (pReq->action) { case TSDB_ALTER_TABLE_ADD_COLUMN: - if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->type) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->flags) < 0) return -1; - if (tDecodeI32v(pDecoder, &pReq->bytes) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->colName)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->type)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->flags)); + TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &pReq->bytes)); break; case TSDB_ALTER_TABLE_DROP_COLUMN: - if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->colName)); break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: - if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->colModType) < 0) return -1; - if (tDecodeI32v(pDecoder, &pReq->colModBytes) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->colName)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->colModType)); + TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &pReq->colModBytes)); break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: - if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1; - if (tDecodeCStr(pDecoder, &pReq->colNewName) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->colName)); + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->colNewName)); break; case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: - if (tDecodeCStr(pDecoder, &pReq->tagName) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->isNull) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->tagType) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->tagName)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->isNull)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->tagType)); if (!pReq->isNull) { - if (tDecodeBinary(pDecoder, &pReq->pTagVal, &pReq->nTagVal) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeBinary(pDecoder, &pReq->pTagVal, &pReq->nTagVal)); } break; case TSDB_ALTER_TABLE_UPDATE_OPTIONS: - if (tDecodeI8(pDecoder, &pReq->updateTTL) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->updateTTL)); if (pReq->updateTTL) { - if (tDecodeI32v(pDecoder, &pReq->newTTL) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &pReq->newTTL)); } - if (tDecodeI32v(pDecoder, &pReq->newCommentLen) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &pReq->newCommentLen)); if (pReq->newCommentLen > 0) { - if (tDecodeCStr(pDecoder, &pReq->newComment) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->newComment)); } break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: - if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1; - if (tDecodeU32(pDecoder, &pReq->compress) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->colName)); + TAOS_CHECK_EXIT(tDecodeU32(pDecoder, &pReq->compress)); break; case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: - if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->type) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->flags) < 0) return -1; - if (tDecodeI32v(pDecoder, &pReq->bytes) < 0) return -1; - if (tDecodeU32(pDecoder, &pReq->compress) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &pReq->colName)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->type)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->flags)); + TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &pReq->bytes)); + TAOS_CHECK_EXIT(tDecodeU32(pDecoder, &pReq->compress)); default: break; } - return 0; +_exit: + return code; } int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeSVAlterTbReqCommon(pDecoder, pReq) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeSVAlterTbReqCommon(pDecoder, pReq)); pReq->ctimeMs = 0; if (!tDecodeIsEnd(pDecoder)) { - if (tDecodeI64(pDecoder, &pReq->ctimeMs) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->ctimeMs)); } if (!tDecodeIsEnd(pDecoder)) { - if (tDecodeI8(pDecoder, &pReq->source) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->source)); } tEndDecode(pDecoder); - return 0; +_exit: + return code; } int32_t tDecodeSVAlterTbReqSetCtime(SDecoder *pDecoder, SVAlterTbReq *pReq, int64_t ctimeMs) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeSVAlterTbReqCommon(pDecoder, pReq) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeSVAlterTbReqCommon(pDecoder, pReq)); pReq->ctimeMs = 0; if (!tDecodeIsEnd(pDecoder)) { *(int64_t *)(pDecoder->data + pDecoder->pos) = ctimeMs; - if (tDecodeI64(pDecoder, &pReq->ctimeMs) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->ctimeMs)); } tEndDecode(pDecoder); - return 0; +_exit: + return code; } int32_t tEncodeSVAlterTbRsp(SEncoder *pEncoder, const SVAlterTbRsp *pRsp) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->code) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->pMeta ? 1 : 0) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->code)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->pMeta ? 1 : 0)); if (pRsp->pMeta) { - if (tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta)); } tEndEncode(pEncoder); - return 0; +_exit: + return code; } int32_t tDecodeSVAlterTbRsp(SDecoder *pDecoder, SVAlterTbRsp *pRsp) { int32_t meta = 0; - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->code) < 0) return -1; - if (tDecodeI32(pDecoder, &meta) < 0) return -1; + int32_t code = 0; + int32_t lino; + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->code)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &meta)); if (meta) { pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); - if (NULL == pRsp->pMeta) return -1; - if (tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta) < 0) return -1; + if (NULL == pRsp->pMeta) { + TAOS_CHECK_EXIT(terrno); + } + TAOS_CHECK_EXIT(tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta)); } tEndDecode(pDecoder); - return 0; +_exit: + return code; } -// int32_t tDeserializeSVAlterTbRsp(void *buf, int32_t bufLen, SVAlterTbRsp *pRsp) { -// int32_t meta = 0; -// SDecoder decoder = {0}; -// tDecoderInit(&decoder, buf, bufLen); - -// if (tStartDecode(&decoder) < 0) return -1; -// if (tDecodeI32(&decoder, &pRsp->code) < 0) return -1; -// if (tDecodeI32(&decoder, &meta) < 0) return -1; -// if (meta) { -// pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); -// if (NULL == pRsp->pMeta) return -1; -// if (tDecodeSTableMetaRsp(&decoder, pRsp->pMeta) < 0) return -1; -// } -// tEndDecode(&decoder); -// tDecoderClear(&decoder); -// return 0; -// } - int32_t tEncodeSMAlterStbRsp(SEncoder *pEncoder, const SMAlterStbRsp *pRsp) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->pMeta->pSchemas ? 1 : 0) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->pMeta->pSchemas ? 1 : 0)); if (pRsp->pMeta->pSchemas) { - if (tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta)); } tEndEncode(pEncoder); - return 0; +_exit: + return code; } int32_t tDecodeSMAlterStbRsp(SDecoder *pDecoder, SMAlterStbRsp *pRsp) { int32_t meta = 0; - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI32(pDecoder, &meta) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &meta)); if (meta) { pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); - if (NULL == pRsp->pMeta) return -1; - if (tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta) < 0) return -1; + if (NULL == pRsp->pMeta) { + TAOS_CHECK_EXIT(terrno); + } + TAOS_CHECK_EXIT(tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta)); } tEndDecode(pDecoder); - return 0; +_exit: + return code; } -// int32_t tDeserializeSMAlterStbRsp(void *buf, int32_t bufLen, SMAlterStbRsp *pRsp) { -// int32_t meta = 0; -// SDecoder decoder = {0}; -// tDecoderInit(&decoder, buf, bufLen); - -// if (tStartDecode(&decoder) < 0) return -1; -// if (tDecodeI32(&decoder, &meta) < 0) return -1; -// if (meta) { -// pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); -// if (NULL == pRsp->pMeta) return -1; -// if (tDecodeSTableMetaRsp(&decoder, pRsp->pMeta) < 0) return -1; -// } -// tEndDecode(&decoder); -// tDecoderClear(&decoder); -// return 0; -// } - void tFreeSMAlterStbRsp(SMAlterStbRsp *pRsp) { if (NULL == pRsp) { return; @@ -10375,45 +10321,40 @@ void tFreeSMAlterStbRsp(SMAlterStbRsp *pRsp) { } int32_t tEncodeSMCreateStbRsp(SEncoder *pEncoder, const SMCreateStbRsp *pRsp) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->pMeta->pSchemas ? 1 : 0) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->pMeta->pSchemas ? 1 : 0)); if (pRsp->pMeta->pSchemas) { - if (tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta)); } tEndEncode(pEncoder); - return 0; + +_exit: + return code; } int32_t tDecodeSMCreateStbRsp(SDecoder *pDecoder, SMCreateStbRsp *pRsp) { int32_t meta = 0; - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI32(pDecoder, &meta) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &meta)); if (meta) { pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); - if (NULL == pRsp->pMeta) return -1; - if (tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta) < 0) return -1; + if (NULL == pRsp->pMeta) { + TAOS_CHECK_EXIT(terrno); + } + TAOS_CHECK_EXIT(tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta)); } tEndDecode(pDecoder); - return 0; + +_exit: + return code; } -// int32_t tDeserializeSMCreateStbRsp(void *buf, int32_t bufLen, SMCreateStbRsp *pRsp) { -// int32_t meta = 0; -// SDecoder decoder = {0}; -// tDecoderInit(&decoder, buf, bufLen); - -// if (tStartDecode(&decoder) < 0) return -1; -// if (tDecodeI32(&decoder, &meta) < 0) return -1; -// if (meta) { -// pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); -// if (NULL == pRsp->pMeta) return -1; -// if (tDecodeSTableMetaRsp(&decoder, pRsp->pMeta) < 0) return -1; -// } -// tEndDecode(&decoder); -// tDecoderClear(&decoder); -// return 0; -// } - void tFreeSMCreateStbRsp(SMCreateStbRsp *pRsp) { if (NULL == pRsp) { return; @@ -10427,51 +10368,59 @@ void tFreeSMCreateStbRsp(SMCreateStbRsp *pRsp) { } int32_t tEncodeSTqOffsetVal(SEncoder *pEncoder, const STqOffsetVal *pOffsetVal) { + int32_t code = 0; + int32_t lino; + int8_t type = pOffsetVal->type < 0 ? pOffsetVal->type : (TQ_OFFSET_VERSION << 4) | pOffsetVal->type; - if (tEncodeI8(pEncoder, type) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, type)); if (pOffsetVal->type == TMQ_OFFSET__SNAPSHOT_DATA || pOffsetVal->type == TMQ_OFFSET__SNAPSHOT_META) { - if (tEncodeI64(pEncoder, pOffsetVal->uid) < 0) return -1; - if (tEncodeI64(pEncoder, pOffsetVal->ts) < 0) return -1; - if (tEncodeI8(pEncoder, pOffsetVal->primaryKey.type) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pOffsetVal->uid)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pOffsetVal->ts)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pOffsetVal->primaryKey.type)); if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) { - if (tEncodeBinary(pEncoder, pOffsetVal->primaryKey.pData, pOffsetVal->primaryKey.nData) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pOffsetVal->primaryKey.pData, pOffsetVal->primaryKey.nData)); } else { - if (tEncodeI64(pEncoder, pOffsetVal->primaryKey.val) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pOffsetVal->primaryKey.val)); } } else if (pOffsetVal->type == TMQ_OFFSET__LOG) { - if (tEncodeI64(pEncoder, pOffsetVal->version) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pOffsetVal->version)); } else { // do nothing } - return 0; +_exit: + return code; } int32_t tDecodeSTqOffsetVal(SDecoder *pDecoder, STqOffsetVal *pOffsetVal) { - if (tDecodeI8(pDecoder, &pOffsetVal->type) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pOffsetVal->type)); int8_t offsetVersion = 0; if (pOffsetVal->type > 0) { offsetVersion = (pOffsetVal->type >> 4); pOffsetVal->type = pOffsetVal->type & 0x0F; } if (pOffsetVal->type == TMQ_OFFSET__SNAPSHOT_DATA || pOffsetVal->type == TMQ_OFFSET__SNAPSHOT_META) { - if (tDecodeI64(pDecoder, &pOffsetVal->uid) < 0) return -1; - if (tDecodeI64(pDecoder, &pOffsetVal->ts) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pOffsetVal->uid)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pOffsetVal->ts)); if (offsetVersion >= TQ_OFFSET_VERSION) { - if (tDecodeI8(pDecoder, &pOffsetVal->primaryKey.type) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pOffsetVal->primaryKey.type)); if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) { - if (tDecodeBinaryAlloc32(pDecoder, (void **)&pOffsetVal->primaryKey.pData, &pOffsetVal->primaryKey.nData) < 0) - return -1; + TAOS_CHECK_EXIT( + tDecodeBinaryAlloc32(pDecoder, (void **)&pOffsetVal->primaryKey.pData, &pOffsetVal->primaryKey.nData)); } else { - if (tDecodeI64(pDecoder, &pOffsetVal->primaryKey.val) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pOffsetVal->primaryKey.val)); } } } else if (pOffsetVal->type == TMQ_OFFSET__LOG) { - if (tDecodeI64(pDecoder, &pOffsetVal->version) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pOffsetVal->version)); } else { // do nothing } - return 0; +_exit: + return code; } void tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) { @@ -10543,250 +10492,295 @@ void tDeleteSTqOffset(void *param) { } int32_t tEncodeSTqOffset(SEncoder *pEncoder, const STqOffset *pOffset) { - if (tEncodeSTqOffsetVal(pEncoder, &pOffset->val) < 0) return -1; - if (tEncodeCStr(pEncoder, pOffset->subKey) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeSTqOffsetVal(pEncoder, &pOffset->val)); + TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pOffset->subKey)); return 0; } int32_t tDecodeSTqOffset(SDecoder *pDecoder, STqOffset *pOffset) { - if (tDecodeSTqOffsetVal(pDecoder, &pOffset->val) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pOffset->subKey) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeSTqOffsetVal(pDecoder, &pOffset->val)); + TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pOffset->subKey)); return 0; } int32_t tEncodeMqVgOffset(SEncoder *pEncoder, const SMqVgOffset *pOffset) { - if (tEncodeSTqOffset(pEncoder, &pOffset->offset) < 0) return -1; - if (tEncodeI64(pEncoder, pOffset->consumerId) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeSTqOffset(pEncoder, &pOffset->offset)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pOffset->consumerId)); return 0; } int32_t tDecodeMqVgOffset(SDecoder *pDecoder, SMqVgOffset *pOffset) { - if (tDecodeSTqOffset(pDecoder, &pOffset->offset) < 0) return -1; - if (tDecodeI64(pDecoder, &pOffset->consumerId) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeSTqOffset(pDecoder, &pOffset->offset)); + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pOffset->consumerId)); return 0; } int32_t tEncodeSTqCheckInfo(SEncoder *pEncoder, const STqCheckInfo *pInfo) { - if (tEncodeCStr(pEncoder, pInfo->topic) < 0) return -1; - if (tEncodeI64(pEncoder, pInfo->ntbUid) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pInfo->topic)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pInfo->ntbUid)); int32_t sz = taosArrayGetSize(pInfo->colIdList); - if (tEncodeI32(pEncoder, sz) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, sz)); for (int32_t i = 0; i < sz; i++) { int16_t colId = *(int16_t *)taosArrayGet(pInfo->colIdList, i); - if (tEncodeI16(pEncoder, colId) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeI16(pEncoder, colId)); } return pEncoder->pos; } int32_t tDecodeSTqCheckInfo(SDecoder *pDecoder, STqCheckInfo *pInfo) { - if (tDecodeCStrTo(pDecoder, pInfo->topic) < 0) return -1; - if (tDecodeI64(pDecoder, &pInfo->ntbUid) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pInfo->topic)); + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pInfo->ntbUid)); int32_t sz = 0; - if (tDecodeI32(pDecoder, &sz) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &sz)); pInfo->colIdList = taosArrayInit(sz, sizeof(int16_t)); - if (pInfo->colIdList == NULL) return -1; + if (pInfo->colIdList == NULL) { + TAOS_CHECK_RETURN(terrno); + } for (int32_t i = 0; i < sz; i++) { int16_t colId = 0; - if (tDecodeI16(pDecoder, &colId) < 0) return -1; - if (taosArrayPush(pInfo->colIdList, &colId) == NULL) return -1; + TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &colId)); + if (taosArrayPush(pInfo->colIdList, &colId) == NULL) { + TAOS_CHECK_RETURN(terrno); + } } return 0; } void tDeleteSTqCheckInfo(STqCheckInfo *pInfo) { taosArrayDestroy(pInfo->colIdList); } int32_t tEncodeSMqRebVgReq(SEncoder *pCoder, const SMqRebVgReq *pReq) { - if (tStartEncode(pCoder) < 0) return -1; - if (tEncodeI64(pCoder, pReq->leftForVer) < 0) return -1; - if (tEncodeI32(pCoder, pReq->vgId) < 0) return -1; - if (tEncodeI64(pCoder, pReq->oldConsumerId) < 0) return -1; - if (tEncodeI64(pCoder, pReq->newConsumerId) < 0) return -1; - if (tEncodeCStr(pCoder, pReq->subKey) < 0) return -1; - if (tEncodeI8(pCoder, pReq->subType) < 0) return -1; - if (tEncodeI8(pCoder, pReq->withMeta) < 0) return -1; + TAOS_CHECK_RETURN(tStartEncode(pCoder)); + TAOS_CHECK_RETURN(tEncodeI64(pCoder, pReq->leftForVer)); + TAOS_CHECK_RETURN(tEncodeI32(pCoder, pReq->vgId)); + TAOS_CHECK_RETURN(tEncodeI64(pCoder, pReq->oldConsumerId)); + TAOS_CHECK_RETURN(tEncodeI64(pCoder, pReq->newConsumerId)); + TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pReq->subKey)); + TAOS_CHECK_RETURN(tEncodeI8(pCoder, pReq->subType)); + TAOS_CHECK_RETURN(tEncodeI8(pCoder, pReq->withMeta)); if (pReq->subType == TOPIC_SUB_TYPE__COLUMN) { - if (tEncodeCStr(pCoder, pReq->qmsg) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pReq->qmsg)); } else if (pReq->subType == TOPIC_SUB_TYPE__TABLE) { - if (tEncodeI64(pCoder, pReq->suid) < 0) return -1; - if (tEncodeCStr(pCoder, pReq->qmsg) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeI64(pCoder, pReq->suid)); + TAOS_CHECK_RETURN(tEncodeCStr(pCoder, pReq->qmsg)); } tEndEncode(pCoder); return 0; } int32_t tDecodeSMqRebVgReq(SDecoder *pCoder, SMqRebVgReq *pReq) { - if (tStartDecode(pCoder) < 0) return -1; + int32_t code = 0; + int32_t lino; - if (tDecodeI64(pCoder, &pReq->leftForVer) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(pCoder)); - if (tDecodeI32(pCoder, &pReq->vgId) < 0) return -1; - if (tDecodeI64(pCoder, &pReq->oldConsumerId) < 0) return -1; - if (tDecodeI64(pCoder, &pReq->newConsumerId) < 0) return -1; - if (tDecodeCStrTo(pCoder, pReq->subKey) < 0) return -1; - if (tDecodeI8(pCoder, &pReq->subType) < 0) return -1; - if (tDecodeI8(pCoder, &pReq->withMeta) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pReq->leftForVer)); + + TAOS_CHECK_EXIT(tDecodeI32(pCoder, &pReq->vgId)); + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pReq->oldConsumerId)); + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pReq->newConsumerId)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pCoder, pReq->subKey)); + TAOS_CHECK_EXIT(tDecodeI8(pCoder, &pReq->subType)); + TAOS_CHECK_EXIT(tDecodeI8(pCoder, &pReq->withMeta)); if (pReq->subType == TOPIC_SUB_TYPE__COLUMN) { - if (tDecodeCStr(pCoder, &pReq->qmsg) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pCoder, &pReq->qmsg)); } else if (pReq->subType == TOPIC_SUB_TYPE__TABLE) { - if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pReq->suid)); if (!tDecodeIsEnd(pCoder)) { - if (tDecodeCStr(pCoder, &pReq->qmsg) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStr(pCoder, &pReq->qmsg)); } } tEndDecode(pCoder); - return 0; +_exit: + return code; } int32_t tEncodeDeleteRes(SEncoder *pCoder, const SDeleteRes *pRes) { int32_t nUid = taosArrayGetSize(pRes->uidList); + int32_t code = 0; + int32_t lino; - if (tEncodeU64(pCoder, pRes->suid) < 0) return -1; - if (tEncodeI32v(pCoder, nUid) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeU64(pCoder, pRes->suid)); + TAOS_CHECK_EXIT(tEncodeI32v(pCoder, nUid)); for (int32_t iUid = 0; iUid < nUid; iUid++) { - if (tEncodeU64(pCoder, *(uint64_t *)taosArrayGet(pRes->uidList, iUid)) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeU64(pCoder, *(uint64_t *)taosArrayGet(pRes->uidList, iUid))); } - if (tEncodeI64(pCoder, pRes->skey) < 0) return -1; - if (tEncodeI64(pCoder, pRes->ekey) < 0) return -1; - if (tEncodeI64v(pCoder, pRes->affectedRows) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pCoder, pRes->skey)); + TAOS_CHECK_EXIT(tEncodeI64(pCoder, pRes->ekey)); + TAOS_CHECK_EXIT(tEncodeI64v(pCoder, pRes->affectedRows)); - if (tEncodeCStr(pCoder, pRes->tableFName) < 0) return -1; - if (tEncodeCStr(pCoder, pRes->tsColName) < 0) return -1; - if (tEncodeI64(pCoder, pRes->ctimeMs) < 0) return -1; - if (tEncodeI8(pCoder, pRes->source) < 0) return -1; - return 0; + TAOS_CHECK_EXIT(tEncodeCStr(pCoder, pRes->tableFName)); + TAOS_CHECK_EXIT(tEncodeCStr(pCoder, pRes->tsColName)); + TAOS_CHECK_EXIT(tEncodeI64(pCoder, pRes->ctimeMs)); + TAOS_CHECK_EXIT(tEncodeI8(pCoder, pRes->source)); + +_exit: + return code; } int32_t tDecodeDeleteRes(SDecoder *pCoder, SDeleteRes *pRes) { int32_t nUid; uint64_t uid; + int32_t code = 0; + int32_t lino; - if (tDecodeU64(pCoder, &pRes->suid) < 0) return -1; - if (tDecodeI32v(pCoder, &nUid) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeU64(pCoder, &pRes->suid)); + TAOS_CHECK_EXIT(tDecodeI32v(pCoder, &nUid)); for (int32_t iUid = 0; iUid < nUid; iUid++) { - if (tDecodeU64(pCoder, &uid) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeU64(pCoder, &uid)); if (pRes->uidList) { - if (taosArrayPush(pRes->uidList, &uid) == NULL) return -1; + if (taosArrayPush(pRes->uidList, &uid) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } } - if (tDecodeI64(pCoder, &pRes->skey) < 0) return -1; - if (tDecodeI64(pCoder, &pRes->ekey) < 0) return -1; - if (tDecodeI64v(pCoder, &pRes->affectedRows) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pRes->skey)); + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pRes->ekey)); + TAOS_CHECK_EXIT(tDecodeI64v(pCoder, &pRes->affectedRows)); - if (tDecodeCStrTo(pCoder, pRes->tableFName) < 0) return -1; - if (tDecodeCStrTo(pCoder, pRes->tsColName) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStrTo(pCoder, pRes->tableFName)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pCoder, pRes->tsColName)); pRes->ctimeMs = 0; if (!tDecodeIsEnd(pCoder)) { - if (tDecodeI64(pCoder, &pRes->ctimeMs) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pRes->ctimeMs)); } if (!tDecodeIsEnd(pCoder)) { - if (tDecodeI8(pCoder, &pRes->source) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI8(pCoder, &pRes->source)); } - return 0; + +_exit: + return code; } int32_t tEncodeMqMetaRsp(SEncoder *pEncoder, const SMqMetaRsp *pRsp) { - if (tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset) < 0) return -1; - if (tEncodeI16(pEncoder, pRsp->resMsgType)) return -1; - if (tEncodeBinary(pEncoder, pRsp->metaRsp, pRsp->metaRspLen)) return -1; + TAOS_CHECK_RETURN(tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset)); + TAOS_CHECK_RETURN(tEncodeI16(pEncoder, pRsp->resMsgType)); + TAOS_CHECK_RETURN(tEncodeBinary(pEncoder, pRsp->metaRsp, pRsp->metaRspLen)); return 0; } int32_t tDecodeMqMetaRsp(SDecoder *pDecoder, SMqMetaRsp *pRsp) { - if (tDecodeSTqOffsetVal(pDecoder, &pRsp->rspOffset) < 0) return -1; - if (tDecodeI16(pDecoder, &pRsp->resMsgType) < 0) return -1; - if (tDecodeBinaryAlloc(pDecoder, &pRsp->metaRsp, (uint64_t *)&pRsp->metaRspLen) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeSTqOffsetVal(pDecoder, &pRsp->rspOffset)); + TAOS_CHECK_RETURN(tDecodeI16(pDecoder, &pRsp->resMsgType)); + TAOS_CHECK_RETURN(tDecodeBinaryAlloc(pDecoder, &pRsp->metaRsp, (uint64_t *)&pRsp->metaRspLen)); return 0; } void tDeleteMqMetaRsp(SMqMetaRsp *pRsp) { taosMemoryFree(pRsp->metaRsp); } int32_t tEncodeMqDataRspCommon(SEncoder *pEncoder, const SMqDataRsp *pRsp) { - if (tEncodeSTqOffsetVal(pEncoder, &pRsp->reqOffset) < 0) return -1; - if (tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->blockNum) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeSTqOffsetVal(pEncoder, &pRsp->reqOffset)); + TAOS_CHECK_EXIT(tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->blockNum)); if (pRsp->blockNum != 0) { - if (tEncodeI8(pEncoder, pRsp->withTbName) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->withSchema) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pRsp->withTbName)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pRsp->withSchema)); for (int32_t i = 0; i < pRsp->blockNum; i++) { int32_t bLen = *(int32_t *)taosArrayGet(pRsp->blockDataLen, i); void *data = taosArrayGetP(pRsp->blockData, i); - if (tEncodeBinary(pEncoder, (const uint8_t *)data, bLen) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, (const uint8_t *)data, bLen)); if (pRsp->withSchema) { SSchemaWrapper *pSW = (SSchemaWrapper *)taosArrayGetP(pRsp->blockSchema, i); - if (tEncodeSSchemaWrapper(pEncoder, pSW) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSSchemaWrapper(pEncoder, pSW)); } if (pRsp->withTbName) { char *tbName = (char *)taosArrayGetP(pRsp->blockTbName, i); - if (tEncodeCStr(pEncoder, tbName) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, tbName)); } } } - return 0; + +_exit: + return code; } int32_t tEncodeMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pRsp) { - if (tEncodeMqDataRspCommon(pEncoder, pRsp) < 0) return -1; - if (tEncodeI64(pEncoder, ((SMqDataRsp *)pRsp)->sleepTime) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeMqDataRspCommon(pEncoder, pRsp)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pRsp->sleepTime)); return 0; } int32_t tDecodeMqDataRspCommon(SDecoder *pDecoder, SMqDataRsp *pRsp) { - if (tDecodeSTqOffsetVal(pDecoder, &pRsp->reqOffset) < 0) return -1; - if (tDecodeSTqOffsetVal(pDecoder, &pRsp->rspOffset) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->blockNum) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeSTqOffsetVal(pDecoder, &pRsp->reqOffset)); + TAOS_CHECK_EXIT(tDecodeSTqOffsetVal(pDecoder, &pRsp->rspOffset)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->blockNum)); + if (pRsp->blockNum != 0) { - if ((pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void *))) == NULL) return -1; - if ((pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(int32_t))) == NULL) return -1; - if (tDecodeI8(pDecoder, &pRsp->withTbName) < 0) return -1; - if (tDecodeI8(pDecoder, &pRsp->withSchema) < 0) return -1; + if ((pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void *))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } + if ((pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(int32_t))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pRsp->withTbName)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pRsp->withSchema)); if (pRsp->withTbName) { - if ((pRsp->blockTbName = taosArrayInit(pRsp->blockNum, sizeof(void *))) == NULL) return -1; + if ((pRsp->blockTbName = taosArrayInit(pRsp->blockNum, sizeof(void *))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } if (pRsp->withSchema) { - if ((pRsp->blockSchema = taosArrayInit(pRsp->blockNum, sizeof(void *))) == NULL) return -1; + if ((pRsp->blockSchema = taosArrayInit(pRsp->blockNum, sizeof(void *))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } for (int32_t i = 0; i < pRsp->blockNum; i++) { void *data; uint64_t bLen; - if (tDecodeBinaryAlloc(pDecoder, &data, &bLen) < 0) return -1; - if (taosArrayPush(pRsp->blockData, &data) == NULL) return -1; + TAOS_CHECK_EXIT(tDecodeBinaryAlloc(pDecoder, &data, &bLen)); + if (taosArrayPush(pRsp->blockData, &data) == NULL) { + TAOS_CHECK_EXIT(terrno); + } int32_t len = bLen; - if (taosArrayPush(pRsp->blockDataLen, &len) == NULL) return -1; + if (taosArrayPush(pRsp->blockDataLen, &len) == NULL) { + TAOS_CHECK_EXIT(terrno); + } if (pRsp->withSchema) { SSchemaWrapper *pSW = (SSchemaWrapper *)taosMemoryCalloc(1, sizeof(SSchemaWrapper)); - if (pSW == NULL) return -1; - if (tDecodeSSchemaWrapper(pDecoder, pSW) < 0) { + if (pSW == NULL) { + TAOS_CHECK_EXIT(terrno); + } + + if ((code = tDecodeSSchemaWrapper(pDecoder, pSW))) { taosMemoryFree(pSW); - return -1; + goto _exit; } if (taosArrayPush(pRsp->blockSchema, &pSW) == NULL) { taosMemoryFree(pSW); - return -1; + TAOS_CHECK_EXIT(terrno); } } if (pRsp->withTbName) { char *tbName; - if (tDecodeCStrAlloc(pDecoder, &tbName) < 0) return -1; - if (taosArrayPush(pRsp->blockTbName, &tbName) == NULL) return -1; + TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &tbName)); + if (taosArrayPush(pRsp->blockTbName, &tbName) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } } } - return 0; +_exit: + return code; } int32_t tDecodeMqDataRsp(SDecoder *pDecoder, SMqDataRsp *pRsp) { - if (tDecodeMqDataRspCommon(pDecoder, pRsp) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeMqDataRspCommon(pDecoder, pRsp)); if (!tDecodeIsEnd(pDecoder)) { - if (tDecodeI64(pDecoder, &((SMqDataRsp *)pRsp)->sleepTime) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &((SMqDataRsp *)pRsp)->sleepTime)); } return 0; @@ -10808,37 +10802,51 @@ static void tDeleteMqDataRspCommon(SMqDataRsp *pRsp) { void tDeleteMqDataRsp(SMqDataRsp *rsp) { tDeleteMqDataRspCommon(rsp); } int32_t tEncodeSTaosxRsp(SEncoder *pEncoder, const SMqDataRsp *pRsp) { - if (tEncodeMqDataRspCommon(pEncoder, pRsp) < 0) return -1; + int32_t code = 0; + int32_t lino; - if (tEncodeI32(pEncoder, pRsp->createTableNum) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeMqDataRspCommon(pEncoder, pRsp)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->createTableNum)); if (pRsp->createTableNum) { for (int32_t i = 0; i < pRsp->createTableNum; i++) { void *createTableReq = taosArrayGetP(pRsp->createTableReq, i); int32_t createTableLen = *(int32_t *)taosArrayGet(pRsp->createTableLen, i); - if (tEncodeBinary(pEncoder, createTableReq, createTableLen) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, createTableReq, createTableLen)); } } - return 0; +_exit: + return code; } int32_t tDecodeSTaosxRsp(SDecoder *pDecoder, SMqDataRsp *pRsp) { - if (tDecodeMqDataRspCommon(pDecoder, pRsp) < 0) return -1; + int32_t code = 0; + int32_t lino; - if (tDecodeI32(pDecoder, &pRsp->createTableNum) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeMqDataRspCommon(pDecoder, pRsp)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->createTableNum)); if (pRsp->createTableNum) { - if ((pRsp->createTableLen = taosArrayInit(pRsp->createTableNum, sizeof(int32_t))) == NULL) return -1; - if ((pRsp->createTableReq = taosArrayInit(pRsp->createTableNum, sizeof(void *))) == NULL) return -1; + if ((pRsp->createTableLen = taosArrayInit(pRsp->createTableNum, sizeof(int32_t))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } + if ((pRsp->createTableReq = taosArrayInit(pRsp->createTableNum, sizeof(void *))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < pRsp->createTableNum; i++) { void *pCreate = NULL; uint64_t len = 0; - if (tDecodeBinaryAlloc(pDecoder, &pCreate, &len) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeBinaryAlloc(pDecoder, &pCreate, &len)); int32_t l = (int32_t)len; - if (taosArrayPush(pRsp->createTableLen, &l) == NULL) return -1; - if (taosArrayPush(pRsp->createTableReq, &pCreate) == NULL) return -1; + if (taosArrayPush(pRsp->createTableLen, &l) == NULL) { + TAOS_CHECK_EXIT(terrno); + } + if (taosArrayPush(pRsp->createTableReq, &pCreate) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } } - return 0; +_exit: + return code; } void tDeleteSTaosxRsp(SMqDataRsp *pRsp) { @@ -10851,101 +10859,126 @@ void tDeleteSTaosxRsp(SMqDataRsp *pRsp) { } int32_t tEncodeSSingleDeleteReq(SEncoder *pEncoder, const SSingleDeleteReq *pReq) { - if (tEncodeCStr(pEncoder, pReq->tbname) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->startTs) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->endTs) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pReq->tbname)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pReq->startTs)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pReq->endTs)); return 0; } int32_t tDecodeSSingleDeleteReq(SDecoder *pDecoder, SSingleDeleteReq *pReq) { - if (tDecodeCStrTo(pDecoder, pReq->tbname) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->startTs) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->endTs) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pReq->tbname)); + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pReq->startTs)); + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pReq->endTs)); return 0; } int32_t tEncodeSBatchDeleteReq(SEncoder *pEncoder, const SBatchDeleteReq *pReq) { - if (tEncodeI64(pEncoder, pReq->suid) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->suid)); int32_t sz = taosArrayGetSize(pReq->deleteReqs); - if (tEncodeI32(pEncoder, sz) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, sz)); for (int32_t i = 0; i < sz; i++) { SSingleDeleteReq *pOneReq = taosArrayGet(pReq->deleteReqs, i); - if (tEncodeSSingleDeleteReq(pEncoder, pOneReq) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSSingleDeleteReq(pEncoder, pOneReq)); } - if (tEncodeI64(pEncoder, pReq->ctimeMs) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->level) < 0) return -1; - return 0; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->ctimeMs)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->level)); +_exit: + return code; } static int32_t tDecodeSBatchDeleteReqCommon(SDecoder *pDecoder, SBatchDeleteReq *pReq) { - if (tDecodeI64(pDecoder, &pReq->suid) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->suid)); int32_t sz; - if (tDecodeI32(pDecoder, &sz) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &sz)); pReq->deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq)); - if (pReq->deleteReqs == NULL) return -1; + if (pReq->deleteReqs == NULL) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < sz; i++) { SSingleDeleteReq deleteReq; - if (tDecodeSSingleDeleteReq(pDecoder, &deleteReq) < 0) return -1; - if (taosArrayPush(pReq->deleteReqs, &deleteReq) == NULL) return -1; + TAOS_CHECK_EXIT(tDecodeSSingleDeleteReq(pDecoder, &deleteReq)); + if (taosArrayPush(pReq->deleteReqs, &deleteReq) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } - return 0; +_exit: + return code; } int32_t tDecodeSBatchDeleteReq(SDecoder *pDecoder, SBatchDeleteReq *pReq) { - if (tDecodeSBatchDeleteReqCommon(pDecoder, pReq)) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeSBatchDeleteReqCommon(pDecoder, pReq)); pReq->ctimeMs = 0; if (!tDecodeIsEnd(pDecoder)) { - if (tDecodeI64(pDecoder, &pReq->ctimeMs) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->ctimeMs)); } if (!tDecodeIsEnd(pDecoder)) { - if (tDecodeI8(pDecoder, &pReq->level) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->level)); } - return 0; + +_exit: + return code; } int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder *pDecoder, SBatchDeleteReq *pReq, int64_t ctimeMs) { - if (tDecodeSBatchDeleteReqCommon(pDecoder, pReq)) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeSBatchDeleteReqCommon(pDecoder, pReq)); pReq->ctimeMs = 0; if (!tDecodeIsEnd(pDecoder)) { *(int64_t *)(pDecoder->data + pDecoder->pos) = ctimeMs; - if (tDecodeI64(pDecoder, &pReq->ctimeMs) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->ctimeMs)); } - return 0; + +_exit: + return code; } static int32_t tEncodeSSubmitTbData(SEncoder *pCoder, const SSubmitTbData *pSubmitTbData) { - if (tStartEncode(pCoder) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pCoder)); int32_t flags = pSubmitTbData->flags | ((SUBMIT_REQUEST_VERSION) << 8); - if (tEncodeI32v(pCoder, flags) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32v(pCoder, flags)); // auto create table if (pSubmitTbData->flags & SUBMIT_REQ_AUTO_CREATE_TABLE) { if (!(pSubmitTbData->pCreateTbReq)) { return TSDB_CODE_INVALID_MSG; } - if (tEncodeSVCreateTbReq(pCoder, pSubmitTbData->pCreateTbReq) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSVCreateTbReq(pCoder, pSubmitTbData->pCreateTbReq)); } // submit data - if (tEncodeI64(pCoder, pSubmitTbData->suid) < 0) return -1; - if (tEncodeI64(pCoder, pSubmitTbData->uid) < 0) return -1; - if (tEncodeI32v(pCoder, pSubmitTbData->sver) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pCoder, pSubmitTbData->suid)); + TAOS_CHECK_EXIT(tEncodeI64(pCoder, pSubmitTbData->uid)); + TAOS_CHECK_EXIT(tEncodeI32v(pCoder, pSubmitTbData->sver)); if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) { uint64_t nColData = TARRAY_SIZE(pSubmitTbData->aCol); SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol); - if (tEncodeU64v(pCoder, nColData) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeU64v(pCoder, nColData)); for (uint64_t i = 0; i < nColData; i++) { pCoder->pos += tPutColData(SUBMIT_REQUEST_VERSION, pCoder->data ? pCoder->data + pCoder->pos : NULL, &aColData[i]); } } else { - if (tEncodeU64v(pCoder, TARRAY_SIZE(pSubmitTbData->aRowP)) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeU64v(pCoder, TARRAY_SIZE(pSubmitTbData->aRowP))); SRow **rows = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP); for (int32_t iRow = 0; iRow < TARRAY_SIZE(pSubmitTbData->aRowP); ++iRow) { @@ -10953,23 +10986,21 @@ static int32_t tEncodeSSubmitTbData(SEncoder *pCoder, const SSubmitTbData *pSubm pCoder->pos += rows[iRow]->len; } } - if (tEncodeI64(pCoder, pSubmitTbData->ctimeMs) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pCoder, pSubmitTbData->ctimeMs)); tEndEncode(pCoder); - return 0; +_exit: + return code; } static int32_t tDecodeSSubmitTbData(SDecoder *pCoder, SSubmitTbData *pSubmitTbData) { int32_t code = 0; + int32_t lino; int32_t flags; uint8_t version; - if (tStartDecode(pCoder) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto _exit; - } - - if (tDecodeI32v(pCoder, &flags) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(pCoder)); + TAOS_CHECK_EXIT(tDecodeI32v(pCoder, &flags)); pSubmitTbData->flags = flags & 0xff; version = (flags >> 8) & 0xff; @@ -10977,41 +11008,25 @@ static int32_t tDecodeSSubmitTbData(SDecoder *pCoder, SSubmitTbData *pSubmitTbDa if (pSubmitTbData->flags & SUBMIT_REQ_AUTO_CREATE_TABLE) { pSubmitTbData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (pSubmitTbData->pCreateTbReq == NULL) { - goto _exit; + TAOS_CHECK_EXIT(terrno); } - if (tDecodeSVCreateTbReq(pCoder, pSubmitTbData->pCreateTbReq) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto _exit; - } + TAOS_CHECK_EXIT(tDecodeSVCreateTbReq(pCoder, pSubmitTbData->pCreateTbReq)); } // submit data - if (tDecodeI64(pCoder, &pSubmitTbData->suid) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto _exit; - } - if (tDecodeI64(pCoder, &pSubmitTbData->uid) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto _exit; - } - if (tDecodeI32v(pCoder, &pSubmitTbData->sver) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto _exit; - } + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pSubmitTbData->suid)); + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pSubmitTbData->uid)); + TAOS_CHECK_EXIT(tDecodeI32v(pCoder, &pSubmitTbData->sver)); if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) { uint64_t nColData; - if (tDecodeU64v(pCoder, &nColData) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto _exit; - } + TAOS_CHECK_EXIT(tDecodeU64v(pCoder, &nColData)); pSubmitTbData->aCol = taosArrayInit(nColData, sizeof(SColData)); if (pSubmitTbData->aCol == NULL) { - code = terrno; - goto _exit; + TAOS_CHECK_EXIT(terrno); } for (int32_t i = 0; i < nColData; ++i) { @@ -11019,19 +11034,18 @@ static int32_t tDecodeSSubmitTbData(SDecoder *pCoder, SSubmitTbData *pSubmitTbDa } } else { uint64_t nRow; - if (tDecodeU64v(pCoder, &nRow) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto _exit; - } + TAOS_CHECK_EXIT(tDecodeU64v(pCoder, &nRow)); pSubmitTbData->aRowP = taosArrayInit(nRow, sizeof(SRow *)); if (pSubmitTbData->aRowP == NULL) { - code = terrno; - goto _exit; + TAOS_CHECK_EXIT(terrno); } for (int32_t iRow = 0; iRow < nRow; ++iRow) { SRow **ppRow = taosArrayReserve(pSubmitTbData->aRowP, 1); + if (ppRow == NULL) { + TAOS_CHECK_EXIT(terrno); + } *ppRow = (SRow *)(pCoder->data + pCoder->pos); pCoder->pos += (*ppRow)->len; @@ -11040,31 +11054,27 @@ static int32_t tDecodeSSubmitTbData(SDecoder *pCoder, SSubmitTbData *pSubmitTbDa pSubmitTbData->ctimeMs = 0; if (!tDecodeIsEnd(pCoder)) { - if (tDecodeI64(pCoder, &pSubmitTbData->ctimeMs) < 0) { - code = TSDB_CODE_INVALID_MSG; - goto _exit; - } + TAOS_CHECK_EXIT(tDecodeI64(pCoder, &pSubmitTbData->ctimeMs)); } tEndDecode(pCoder); _exit: - if (code) { - // TODO: clear - } - return 0; + return code; } int32_t tEncodeSubmitReq(SEncoder *pCoder, const SSubmitReq2 *pReq) { - if (tStartEncode(pCoder) < 0) return -1; + int32_t code = 0; + int32_t lino; - if (tEncodeU64v(pCoder, taosArrayGetSize(pReq->aSubmitTbData)) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(pCoder)); + TAOS_CHECK_EXIT(tEncodeU64v(pCoder, taosArrayGetSize(pReq->aSubmitTbData))); for (uint64_t i = 0; i < taosArrayGetSize(pReq->aSubmitTbData); i++) { - if (tEncodeSSubmitTbData(pCoder, taosArrayGet(pReq->aSubmitTbData, i)) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSSubmitTbData(pCoder, taosArrayGet(pReq->aSubmitTbData, i))); } - tEndEncode(pCoder); - return 0; +_exit: + return code; } int32_t tDecodeSubmitReq(SDecoder *pCoder, SSubmitReq2 *pReq) { @@ -11173,17 +11183,21 @@ void tDestroySubmitReq(SSubmitReq2 *pReq, int32_t flag) { } int32_t tEncodeSSubmitRsp2(SEncoder *pCoder, const SSubmitRsp2 *pRsp) { - if (tStartEncode(pCoder) < 0) return -1; + int32_t code = 0; + int32_t lino; - if (tEncodeI32v(pCoder, pRsp->affectedRows) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(pCoder)); - if (tEncodeU64v(pCoder, taosArrayGetSize(pRsp->aCreateTbRsp)) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32v(pCoder, pRsp->affectedRows)); + + TAOS_CHECK_EXIT(tEncodeU64v(pCoder, taosArrayGetSize(pRsp->aCreateTbRsp))); for (int32_t i = 0; i < taosArrayGetSize(pRsp->aCreateTbRsp); ++i) { - if (tEncodeSVCreateTbRsp(pCoder, taosArrayGet(pRsp->aCreateTbRsp, i)) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSVCreateTbRsp(pCoder, taosArrayGet(pRsp->aCreateTbRsp, i))); } tEndEncode(pCoder); - return 0; +_exit: + return code; } int32_t tDecodeSSubmitRsp2(SDecoder *pCoder, SSubmitRsp2 *pRsp) { @@ -11266,55 +11280,79 @@ void tDestroySSubmitRsp2(SSubmitRsp2 *pRsp, int32_t flag) { } int32_t tSerializeSMPauseStreamReq(void *buf, int32_t bufLen, const SMPauseStreamReq *pReq) { + int32_t code = 0; + int32_t lino; + int32_t tlen; SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; - if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->name)); + TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->igNotExists)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSMPauseStreamReq(void *buf, int32_t bufLen, SMPauseStreamReq *pReq) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->name)); + TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->igNotExists)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } int32_t tSerializeSMResumeStreamReq(void *buf, int32_t bufLen, const SMResumeStreamReq *pReq) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - 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->igUntreated) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->name)); + TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->igNotExists)); + TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->igUntreated)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSMResumeStreamReq(void *buf, int32_t bufLen, SMResumeStreamReq *pReq) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - 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->igUntreated) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->name)); + TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->igNotExists)); + TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->igUntreated)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } int32_t tEncodeMqSubTopicEp(void **buf, const SMqSubTopicEp *pTopicEp) { @@ -11361,59 +11399,71 @@ void tDeleteMqSubTopicEp(SMqSubTopicEp *pSubTopicEp) { int32_t tSerializeSCMCreateViewReq(void *buf, int32_t bufLen, const SCMCreateViewReq *pReq) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->fullname) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->querySql) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1; - if (tEncodeI8(&encoder, pReq->orReplace) < 0) return -1; - if (tEncodeI8(&encoder, pReq->precision) < 0) return -1; - if (tEncodeI32(&encoder, pReq->numOfCols) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->fullname)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->name)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dbFName)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->querySql)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->sql)); + TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->orReplace)); + TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->precision)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->numOfCols)); for (int32_t i = 0; i < pReq->numOfCols; ++i) { SSchema *pSchema = &pReq->pSchema[i]; - if (tEncodeSSchema(&encoder, pSchema) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSSchema(&encoder, pSchema)); } tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSCMCreateViewReq(void *buf, int32_t bufLen, SCMCreateViewReq *pReq) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->fullname) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1; - if (tDecodeCStrAlloc(&decoder, &pReq->querySql) < 0) return -1; - if (tDecodeCStrAlloc(&decoder, &pReq->sql) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->orReplace) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->numOfCols) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->fullname)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->name)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName)); + TAOS_CHECK_EXIT(tDecodeCStrAlloc(&decoder, &pReq->querySql)); + TAOS_CHECK_EXIT(tDecodeCStrAlloc(&decoder, &pReq->sql)); + TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->orReplace)); + TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->precision)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->numOfCols)); if (pReq->numOfCols > 0) { pReq->pSchema = taosMemoryCalloc(pReq->numOfCols, sizeof(SSchema)); if (pReq->pSchema == NULL) { - return -1; + TAOS_CHECK_EXIT(terrno); } for (int32_t i = 0; i < pReq->numOfCols; ++i) { SSchema *pSchema = pReq->pSchema + i; - if (tDecodeSSchema(&decoder, pSchema) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeSSchema(&decoder, pSchema)); } } tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } void tFreeSCMCreateViewReq(SCMCreateViewReq *pReq) { @@ -11428,37 +11478,49 @@ void tFreeSCMCreateViewReq(SCMCreateViewReq *pReq) { int32_t tSerializeSCMDropViewReq(void *buf, int32_t bufLen, const SCMDropViewReq *pReq) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->fullname) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1; - if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->fullname)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->name)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dbFName)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->sql)); + TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->igNotExists)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSCMDropViewReq(void *buf, int32_t bufLen, SCMDropViewReq *pReq) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->fullname) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1; - if (tDecodeCStrAlloc(&decoder, &pReq->sql) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->fullname)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->name)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName)); + TAOS_CHECK_EXIT(tDecodeCStrAlloc(&decoder, &pReq->sql)); + TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->igNotExists)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } void tFreeSCMDropViewReq(SCMDropViewReq *pReq) { if (NULL == pReq) { @@ -11470,101 +11532,133 @@ void tFreeSCMDropViewReq(SCMDropViewReq *pReq) { int32_t tSerializeSViewMetaReq(void *buf, int32_t bufLen, const SViewMetaReq *pReq) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->fullname) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->fullname)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSViewMetaReq(void *buf, int32_t bufLen, SViewMetaReq *pReq) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->fullname) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->fullname)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } static int32_t tEncodeSViewMetaRsp(SEncoder *pEncoder, const SViewMetaRsp *pRsp) { - if (tEncodeCStr(pEncoder, pRsp->name) < 0) return -1; - if (tEncodeCStr(pEncoder, pRsp->dbFName) < 0) return -1; - if (tEncodeCStr(pEncoder, pRsp->user) < 0) return -1; - if (tEncodeU64(pEncoder, pRsp->dbId) < 0) return -1; - if (tEncodeU64(pEncoder, pRsp->viewId) < 0) return -1; - if (tEncodeCStr(pEncoder, pRsp->querySql) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->precision) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->type) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->version) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->numOfCols) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pRsp->name)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pRsp->dbFName)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pRsp->user)); + TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pRsp->dbId)); + TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pRsp->viewId)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pRsp->querySql)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pRsp->precision)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pRsp->type)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->version)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->numOfCols)); for (int32_t i = 0; i < pRsp->numOfCols; ++i) { SSchema *pSchema = &pRsp->pSchema[i]; - if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSSchema(pEncoder, pSchema)); } - return 0; +_exit: + return code; } int32_t tSerializeSViewMetaRsp(void *buf, int32_t bufLen, const SViewMetaRsp *pRsp) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSViewMetaRsp(&encoder, pRsp) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeSViewMetaRsp(&encoder, pRsp)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } static int32_t tDecodeSViewMetaRsp(SDecoder *pDecoder, SViewMetaRsp *pRsp) { - if (tDecodeCStrTo(pDecoder, pRsp->name) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pRsp->dbFName) < 0) return -1; - if (tDecodeCStrAlloc(pDecoder, &pRsp->user) < 0) return -1; - if (tDecodeU64(pDecoder, &pRsp->dbId) < 0) return -1; - if (tDecodeU64(pDecoder, &pRsp->viewId) < 0) return -1; - if (tDecodeCStrAlloc(pDecoder, &pRsp->querySql) < 0) return -1; - if (tDecodeI8(pDecoder, &pRsp->precision) < 0) return -1; - if (tDecodeI8(pDecoder, &pRsp->type) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->version) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->numOfCols) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pRsp->name)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pRsp->dbFName)); + TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pRsp->user)); + TAOS_CHECK_EXIT(tDecodeU64(pDecoder, &pRsp->dbId)); + TAOS_CHECK_EXIT(tDecodeU64(pDecoder, &pRsp->viewId)); + TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pRsp->querySql)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pRsp->precision)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pRsp->type)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->version)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->numOfCols)); if (pRsp->numOfCols > 0) { pRsp->pSchema = taosMemoryCalloc(pRsp->numOfCols, sizeof(SSchema)); if (pRsp->pSchema == NULL) { - return -1; + TAOS_CHECK_EXIT(terrno); } for (int32_t i = 0; i < pRsp->numOfCols; ++i) { SSchema *pSchema = pRsp->pSchema + i; - if (tDecodeSSchema(pDecoder, pSchema) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeSSchema(pDecoder, pSchema)); } } - return 0; +_exit: + return code; } int32_t tDeserializeSViewMetaRsp(void *buf, int32_t bufLen, SViewMetaRsp *pRsp) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSViewMetaRsp(&decoder, pRsp) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeSViewMetaRsp(&decoder, pRsp)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } void tFreeSViewMetaRsp(SViewMetaRsp *pRsp) { @@ -11579,48 +11673,64 @@ void tFreeSViewMetaRsp(SViewMetaRsp *pRsp) { int32_t tSerializeSViewHbRsp(void *buf, int32_t bufLen, SViewHbRsp *pRsp) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); int32_t numOfMeta = taosArrayGetSize(pRsp->pViewRsp); - if (tEncodeI32(&encoder, numOfMeta) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(&encoder, numOfMeta)); for (int32_t i = 0; i < numOfMeta; ++i) { SViewMetaRsp *pMetaRsp = taosArrayGetP(pRsp->pViewRsp, i); - if (tEncodeSViewMetaRsp(&encoder, pMetaRsp) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSViewMetaRsp(&encoder, pMetaRsp)); } tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSViewHbRsp(void *buf, int32_t bufLen, SViewHbRsp *pRsp) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); int32_t numOfMeta = 0; - if (tDecodeI32(&decoder, &numOfMeta) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &numOfMeta)); pRsp->pViewRsp = taosArrayInit(numOfMeta, POINTER_BYTES); if (pRsp->pViewRsp == NULL) { - return -1; + TAOS_CHECK_EXIT(terrno); } for (int32_t i = 0; i < numOfMeta; ++i) { SViewMetaRsp *metaRsp = taosMemoryCalloc(1, sizeof(SViewMetaRsp)); - if (NULL == metaRsp) return -1; - if (tDecodeSViewMetaRsp(&decoder, metaRsp) < 0) return -1; - if (taosArrayPush(pRsp->pViewRsp, &metaRsp) == NULL) return -1; + if (NULL == metaRsp) { + TAOS_CHECK_EXIT(terrno); + } + TAOS_CHECK_EXIT(tDecodeSViewMetaRsp(&decoder, metaRsp)); + if (taosArrayPush(pRsp->pViewRsp, &metaRsp) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } void tFreeSViewHbRsp(SViewHbRsp *pRsp) { @@ -11648,183 +11758,243 @@ void setFieldWithOptions(SFieldWithOptions *fieldWithOptions, SField *field) { } int32_t tSerializeTableTSMAInfoReq(void *buf, int32_t bufLen, const STableTSMAInfoReq *pReq) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; - if (tEncodeI8(&encoder, pReq->fetchingWithTsmaName) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->name)); + TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->fetchingWithTsmaName)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeTableTSMAInfoReq(void *buf, int32_t bufLen, STableTSMAInfoReq *pReq) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; - if (tDecodeI8(&decoder, (uint8_t *)&pReq->fetchingWithTsmaName) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->name)); + TAOS_CHECK_EXIT(tDecodeI8(&decoder, (uint8_t *)&pReq->fetchingWithTsmaName)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } static int32_t tEncodeTableTSMAInfo(SEncoder *pEncoder, const STableTSMAInfo *pTsmaInfo) { - if (tEncodeCStr(pEncoder, pTsmaInfo->name) < 0) return -1; - if (tEncodeU64(pEncoder, pTsmaInfo->tsmaId) < 0) return -1; - if (tEncodeCStr(pEncoder, pTsmaInfo->tb) < 0) return -1; - if (tEncodeCStr(pEncoder, pTsmaInfo->dbFName) < 0) return -1; - if (tEncodeU64(pEncoder, pTsmaInfo->suid) < 0) return -1; - if (tEncodeU64(pEncoder, pTsmaInfo->destTbUid) < 0) return -1; - if (tEncodeU64(pEncoder, pTsmaInfo->dbId) < 0) return -1; - if (tEncodeI32(pEncoder, pTsmaInfo->version) < 0) return -1; - if (tEncodeCStr(pEncoder, pTsmaInfo->targetTb) < 0) return -1; - if (tEncodeCStr(pEncoder, pTsmaInfo->targetDbFName) < 0) return -1; - if (tEncodeI64(pEncoder, pTsmaInfo->interval) < 0) return -1; - if (tEncodeI8(pEncoder, pTsmaInfo->unit) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTsmaInfo->name)); + TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTsmaInfo->tsmaId)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTsmaInfo->tb)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTsmaInfo->dbFName)); + TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTsmaInfo->suid)); + TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTsmaInfo->destTbUid)); + TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTsmaInfo->dbId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTsmaInfo->version)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTsmaInfo->targetTb)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTsmaInfo->targetDbFName)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTsmaInfo->interval)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTsmaInfo->unit)); int32_t size = pTsmaInfo->pFuncs ? pTsmaInfo->pFuncs->size : 0; - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size)); for (int32_t i = 0; i < size; ++i) { STableTSMAFuncInfo *pFuncInfo = taosArrayGet(pTsmaInfo->pFuncs, i); - if (tEncodeI32(pEncoder, pFuncInfo->funcId) < 0) return -1; - if (tEncodeI16(pEncoder, pFuncInfo->colId) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pFuncInfo->funcId)); + TAOS_CHECK_EXIT(tEncodeI16(pEncoder, pFuncInfo->colId)); } size = pTsmaInfo->pTags ? pTsmaInfo->pTags->size : 0; - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size)); for (int32_t i = 0; i < size; ++i) { const SSchema *pSchema = taosArrayGet(pTsmaInfo->pTags, i); - if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSSchema(pEncoder, pSchema)); } size = pTsmaInfo->pUsedCols ? pTsmaInfo->pUsedCols->size : 0; - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size)); for (int32_t i = 0; i < size; ++i) { const SSchema *pSchema = taosArrayGet(pTsmaInfo->pUsedCols, i); - if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSSchema(pEncoder, pSchema)); } - if (tEncodeCStr(pEncoder, pTsmaInfo->ast) < 0) return -1; - if (tEncodeI64(pEncoder, pTsmaInfo->streamUid) < 0) return -1; - if (tEncodeI64(pEncoder, pTsmaInfo->reqTs) < 0) return -1; - if (tEncodeI64(pEncoder, pTsmaInfo->rspTs) < 0) return -1; - if (tEncodeI64(pEncoder, pTsmaInfo->delayDuration) < 0) return -1; - if (tEncodeI8(pEncoder, pTsmaInfo->fillHistoryFinished) < 0) return -1; - return 0; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTsmaInfo->ast)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTsmaInfo->streamUid)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTsmaInfo->reqTs)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTsmaInfo->rspTs)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTsmaInfo->delayDuration)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTsmaInfo->fillHistoryFinished)); + +_exit: + return code; } static int32_t tDecodeTableTSMAInfo(SDecoder *pDecoder, STableTSMAInfo *pTsmaInfo) { - if (tDecodeCStrTo(pDecoder, pTsmaInfo->name) < 0) return -1; - if (tDecodeU64(pDecoder, &pTsmaInfo->tsmaId) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pTsmaInfo->tb) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pTsmaInfo->dbFName) < 0) return -1; - if (tDecodeU64(pDecoder, &pTsmaInfo->suid) < 0) return -1; - if (tDecodeU64(pDecoder, &pTsmaInfo->destTbUid) < 0) return -1; - if (tDecodeU64(pDecoder, &pTsmaInfo->dbId) < 0) return -1; - if (tDecodeI32(pDecoder, &pTsmaInfo->version) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pTsmaInfo->targetTb) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pTsmaInfo->targetDbFName) < 0) return -1; - if (tDecodeI64(pDecoder, &pTsmaInfo->interval) < 0) return -1; - if (tDecodeI8(pDecoder, &pTsmaInfo->unit) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTsmaInfo->name)); + TAOS_CHECK_EXIT(tDecodeU64(pDecoder, &pTsmaInfo->tsmaId)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTsmaInfo->tb)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTsmaInfo->dbFName)); + TAOS_CHECK_EXIT(tDecodeU64(pDecoder, &pTsmaInfo->suid)); + TAOS_CHECK_EXIT(tDecodeU64(pDecoder, &pTsmaInfo->destTbUid)); + TAOS_CHECK_EXIT(tDecodeU64(pDecoder, &pTsmaInfo->dbId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTsmaInfo->version)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTsmaInfo->targetTb)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTsmaInfo->targetDbFName)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTsmaInfo->interval)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTsmaInfo->unit)); int32_t size = 0; - if (tDecodeI32(pDecoder, &size) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size)); if (size > 0) { pTsmaInfo->pFuncs = taosArrayInit(size, sizeof(STableTSMAFuncInfo)); - if (!pTsmaInfo->pFuncs) return -1; + if (!pTsmaInfo->pFuncs) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < size; ++i) { STableTSMAFuncInfo funcInfo = {0}; - if (tDecodeI32(pDecoder, &funcInfo.funcId) < 0) return -1; - if (tDecodeI16(pDecoder, &funcInfo.colId) < 0) return -1; - if (!taosArrayPush(pTsmaInfo->pFuncs, &funcInfo)) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &funcInfo.funcId)); + TAOS_CHECK_EXIT(tDecodeI16(pDecoder, &funcInfo.colId)); + if (!taosArrayPush(pTsmaInfo->pFuncs, &funcInfo)) { + TAOS_CHECK_EXIT(terrno); + } } } - if (tDecodeI32(pDecoder, &size) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size)); if (size > 0) { pTsmaInfo->pTags = taosArrayInit(size, sizeof(SSchema)); - if (!pTsmaInfo->pTags) return -1; + if (!pTsmaInfo->pTags) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < size; ++i) { SSchema schema = {0}; - if (tDecodeSSchema(pDecoder, &schema) < 0) return -1; - if (taosArrayPush(pTsmaInfo->pTags, &schema) == NULL) return -1; + TAOS_CHECK_EXIT(tDecodeSSchema(pDecoder, &schema)); + if (taosArrayPush(pTsmaInfo->pTags, &schema) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } } - if (tDecodeI32(pDecoder, &size) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size)); if (size > 0) { pTsmaInfo->pUsedCols = taosArrayInit(size, sizeof(SSchema)); - if (!pTsmaInfo->pUsedCols) return -1; + if (!pTsmaInfo->pUsedCols) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < size; ++i) { SSchema schema = {0}; - if (tDecodeSSchema(pDecoder, &schema) < 0) return -1; - if (taosArrayPush(pTsmaInfo->pUsedCols, &schema) == NULL) return -1; + TAOS_CHECK_EXIT(tDecodeSSchema(pDecoder, &schema)); + if (taosArrayPush(pTsmaInfo->pUsedCols, &schema) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } } - if (tDecodeCStrAlloc(pDecoder, &pTsmaInfo->ast) < 0) return -1; - if (tDecodeI64(pDecoder, &pTsmaInfo->streamUid) < 0) return -1; - if (tDecodeI64(pDecoder, &pTsmaInfo->reqTs) < 0) return -1; - if (tDecodeI64(pDecoder, &pTsmaInfo->rspTs) < 0) return -1; - if (tDecodeI64(pDecoder, &pTsmaInfo->delayDuration) < 0) return -1; - if (tDecodeI8(pDecoder, (int8_t *)&pTsmaInfo->fillHistoryFinished) < 0) return -1; - return 0; + TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pTsmaInfo->ast)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTsmaInfo->streamUid)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTsmaInfo->reqTs)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTsmaInfo->rspTs)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTsmaInfo->delayDuration)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, (int8_t *)&pTsmaInfo->fillHistoryFinished)); + +_exit: + return code; } static int32_t tEncodeTableTSMAInfoRsp(SEncoder *pEncoder, const STableTSMAInfoRsp *pRsp) { + int32_t code = 0; + int32_t lino; + int32_t size = pRsp->pTsmas ? pRsp->pTsmas->size : 0; - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size)); for (int32_t i = 0; i < size; ++i) { STableTSMAInfo *pInfo = taosArrayGetP(pRsp->pTsmas, i); - if (tEncodeTableTSMAInfo(pEncoder, pInfo) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeTableTSMAInfo(pEncoder, pInfo)); } - return 0; +_exit: + return code; } static int32_t tDecodeTableTSMAInfoRsp(SDecoder *pDecoder, STableTSMAInfoRsp *pRsp) { int32_t size = 0; - if (tDecodeI32(pDecoder, &size) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size)); if (size <= 0) return 0; pRsp->pTsmas = taosArrayInit(size, POINTER_BYTES); - if (!pRsp->pTsmas) return -1; + if (!pRsp->pTsmas) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < size; ++i) { STableTSMAInfo *pTsma = taosMemoryCalloc(1, sizeof(STableTSMAInfo)); - if (!pTsma) return -1; - if (taosArrayPush(pRsp->pTsmas, &pTsma) == NULL) return -1; - if (tDecodeTableTSMAInfo(pDecoder, pTsma) < 0) return -1; + if (!pTsma) { + TAOS_CHECK_EXIT(terrno); + } + if (taosArrayPush(pRsp->pTsmas, &pTsma) == NULL) { + TAOS_CHECK_EXIT(terrno); + } + TAOS_CHECK_EXIT(tDecodeTableTSMAInfo(pDecoder, pTsma)); } - return 0; +_exit: + return code; } int32_t tSerializeTableTSMAInfoRsp(void *buf, int32_t bufLen, const STableTSMAInfoRsp *pRsp) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeTableTSMAInfoRsp(&encoder, pRsp) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeTableTSMAInfoRsp(&encoder, pRsp)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeTableTSMAInfoRsp(void *buf, int32_t bufLen, STableTSMAInfoRsp *pRsp) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeTableTSMAInfoRsp(&decoder, pRsp) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeTableTSMAInfoRsp(&decoder, pRsp)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } void tFreeTableTSMAInfo(void *p) { @@ -11885,129 +12055,184 @@ void tFreeTableTSMAInfoRsp(STableTSMAInfoRsp *pRsp) { } static int32_t tEncodeStreamProgressReq(SEncoder *pEncoder, const SStreamProgressReq *pReq) { - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->vgId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->fetchIdx) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->subFetchIdx) < 0) return -1; - return 0; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->vgId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->fetchIdx)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->subFetchIdx)); + +_exit: + return code; } int32_t tSerializeStreamProgressReq(void *buf, int32_t bufLen, const SStreamProgressReq *pReq) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeStreamProgressReq(&encoder, pReq) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeStreamProgressReq(&encoder, pReq)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } static int32_t tDecodeStreamProgressReq(SDecoder *pDecoder, SStreamProgressReq *pReq) { - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->vgId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->fetchIdx) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->subFetchIdx) < 0) return -1; - return 0; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->vgId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->fetchIdx)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->subFetchIdx)); + +_exit: + return code; } int32_t tDeserializeStreamProgressReq(void *buf, int32_t bufLen, SStreamProgressReq *pReq) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, (char *)buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeStreamProgressReq(&decoder, pReq) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeStreamProgressReq(&decoder, pReq)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } static int32_t tEncodeStreamProgressRsp(SEncoder *pEncoder, const SStreamProgressRsp *pRsp) { - if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->vgId) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->fillHisFinished) < 0) return -1; - if (tEncodeI64(pEncoder, pRsp->progressDelay) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->fetchIdx) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->subFetchIdx) < 0) return -1; - return 0; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pRsp->streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->vgId)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pRsp->fillHisFinished)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pRsp->progressDelay)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->fetchIdx)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->subFetchIdx)); + +_exit: + return code; } int32_t tSerializeStreamProgressRsp(void *buf, int32_t bufLen, const SStreamProgressRsp *pRsp) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeStreamProgressRsp(&encoder, pRsp) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeStreamProgressRsp(&encoder, pRsp)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } static int32_t tDecodeStreamProgressRsp(SDecoder *pDecoder, SStreamProgressRsp *pRsp) { - if (tDecodeI64(pDecoder, &pRsp->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->vgId) < 0) return -1; - if (tDecodeI8(pDecoder, (int8_t *)&pRsp->fillHisFinished) < 0) return -1; - if (tDecodeI64(pDecoder, &pRsp->progressDelay) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->fetchIdx) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->subFetchIdx) < 0) return -1; - return 0; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pRsp->streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->vgId)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, (int8_t *)&pRsp->fillHisFinished)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pRsp->progressDelay)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->fetchIdx)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->subFetchIdx)); + +_exit: + return code; } int32_t tDeserializeSStreamProgressRsp(void *buf, int32_t bufLen, SStreamProgressRsp *pRsp) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeStreamProgressRsp(&decoder, pRsp) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeStreamProgressRsp(&decoder, pRsp)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } int32_t tEncodeSMDropTbReqOnSingleVg(SEncoder *pEncoder, const SMDropTbReqsOnSingleVg *pReq) { const SVgroupInfo *pVgInfo = &pReq->vgInfo; - if (tEncodeI32(pEncoder, pVgInfo->vgId) < 0) return -1; - if (tEncodeU32(pEncoder, pVgInfo->hashBegin) < 0) return -1; - if (tEncodeU32(pEncoder, pVgInfo->hashEnd) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pVgInfo->epSet) < 0) return -1; - if (tEncodeI32(pEncoder, pVgInfo->numOfTable) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pVgInfo->vgId)); + TAOS_CHECK_EXIT(tEncodeU32(pEncoder, pVgInfo->hashBegin)); + TAOS_CHECK_EXIT(tEncodeU32(pEncoder, pVgInfo->hashEnd)); + TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pVgInfo->epSet)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pVgInfo->numOfTable)); int32_t size = pReq->pTbs ? pReq->pTbs->size : 0; - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size)); for (int32_t i = 0; i < size; ++i) { const SVDropTbReq *pInfo = taosArrayGet(pReq->pTbs, i); - if (tEncodeSVDropTbReq(pEncoder, pInfo) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSVDropTbReq(pEncoder, pInfo)); } - return 0; +_exit: + return code; } int32_t tDecodeSMDropTbReqOnSingleVg(SDecoder *pDecoder, SMDropTbReqsOnSingleVg *pReq) { - if (tDecodeI32(pDecoder, &pReq->vgInfo.vgId) < 0) return -1; - if (tDecodeU32(pDecoder, &pReq->vgInfo.hashBegin) < 0) return -1; - if (tDecodeU32(pDecoder, &pReq->vgInfo.hashEnd) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &pReq->vgInfo.epSet) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->vgInfo.numOfTable) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->vgInfo.vgId)); + TAOS_CHECK_EXIT(tDecodeU32(pDecoder, &pReq->vgInfo.hashBegin)); + TAOS_CHECK_EXIT(tDecodeU32(pDecoder, &pReq->vgInfo.hashEnd)); + TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pReq->vgInfo.epSet)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->vgInfo.numOfTable)); int32_t size = 0; - if (tDecodeI32(pDecoder, &size) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size)); pReq->pTbs = taosArrayInit(size, sizeof(SVDropTbReq)); if (!pReq->pTbs) { - return -1; + TAOS_CHECK_EXIT(terrno); } SVDropTbReq pTbReq = {0}; for (int32_t i = 0; i < size; ++i) { - if (tDecodeSVDropTbReq(pDecoder, &pTbReq) < 0) return -1; - if (taosArrayPush(pReq->pTbs, &pTbReq) == NULL) return -1; + TAOS_CHECK_EXIT(tDecodeSVDropTbReq(pDecoder, &pTbReq)); + if (taosArrayPush(pReq->pTbs, &pTbReq) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } - return 0; + +_exit: + return code; } void tFreeSMDropTbReqOnSingleVg(void *p) { @@ -12017,38 +12242,54 @@ void tFreeSMDropTbReqOnSingleVg(void *p) { int32_t tSerializeSMDropTbsReq(void *buf, int32_t bufLen, const SMDropTbsReq *pReq) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; + tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); int32_t size = pReq->pVgReqs ? pReq->pVgReqs->size : 0; - if (tEncodeI32(&encoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(&encoder, size)); for (int32_t i = 0; i < size; ++i) { SMDropTbReqsOnSingleVg *pVgReq = taosArrayGet(pReq->pVgReqs, i); - if (tEncodeSMDropTbReqOnSingleVg(&encoder, pVgReq) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSMDropTbReqOnSingleVg(&encoder, pVgReq)); } tEndEncode(&encoder); - int32_t tlen = encoder.pos; + +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSMDropTbsReq(void *buf, int32_t bufLen, SMDropTbsReq *pReq) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; + tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); int32_t size = 0; - if (tDecodeI32(&decoder, &size) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &size)); pReq->pVgReqs = taosArrayInit(size, sizeof(SMDropTbReqsOnSingleVg)); if (!pReq->pVgReqs) { - return -1; + TAOS_CHECK_EXIT(terrno); } for (int32_t i = 0; i < size; ++i) { SMDropTbReqsOnSingleVg vgReq = {0}; - if (tDecodeSMDropTbReqOnSingleVg(&decoder, &vgReq) < 0) return -1; - if (taosArrayPush(pReq->pVgReqs, &vgReq) == NULL) return -1; + TAOS_CHECK_EXIT(tDecodeSMDropTbReqOnSingleVg(&decoder, &vgReq)); + if (taosArrayPush(pReq->pVgReqs, &vgReq) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } void tFreeSMDropTbsReq(void *p) { @@ -12057,29 +12298,42 @@ void tFreeSMDropTbsReq(void *p) { } int32_t tEncodeVFetchTtlExpiredTbsRsp(SEncoder *pCoder, const SVFetchTtlExpiredTbsRsp *pRsp) { - if (tEncodeI32(pCoder, pRsp->vgId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeI32(pCoder, pRsp->vgId)); int32_t size = pRsp->pExpiredTbs ? pRsp->pExpiredTbs->size : 0; - if (tEncodeI32(pCoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pCoder, size)); for (int32_t i = 0; i < size; ++i) { - if (tEncodeSVDropTbReq(pCoder, taosArrayGet(pRsp->pExpiredTbs, i)) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeSVDropTbReq(pCoder, taosArrayGet(pRsp->pExpiredTbs, i))); } - return 0; + +_exit: + return code; } int32_t tDecodeVFetchTtlExpiredTbsRsp(SDecoder *pCoder, SVFetchTtlExpiredTbsRsp *pRsp) { - if (tDecodeI32(pCoder, &pRsp->vgId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeI32(pCoder, &pRsp->vgId)); int32_t size = 0; - if (tDecodeI32(pCoder, &size) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pCoder, &size)); if (size > 0) { pRsp->pExpiredTbs = taosArrayInit(size, sizeof(SVDropTbReq)); - if (!pRsp->pExpiredTbs) return terrno; + if (!pRsp->pExpiredTbs) { + TAOS_CHECK_EXIT(terrno); + } SVDropTbReq tb = {0}; for (int32_t i = 0; i < size; ++i) { - if (tDecodeSVDropTbReq(pCoder, &tb) < 0) return -1; - if (taosArrayPush(pRsp->pExpiredTbs, &tb) == NULL) return -1; + TAOS_CHECK_EXIT(tDecodeSVDropTbReq(pCoder, &tb)); + if (taosArrayPush(pRsp->pExpiredTbs, &tb) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } } - return 0; +_exit: + return code; } void tFreeFetchTtlExpiredTbsRsp(void *p) { @@ -12088,52 +12342,73 @@ void tFreeFetchTtlExpiredTbsRsp(void *p) { } int32_t tEncodeMqBatchMetaRsp(SEncoder *pEncoder, const SMqBatchMetaRsp *pRsp) { - if (tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tEncodeSTqOffsetVal(pEncoder, &pRsp->rspOffset)); int32_t size = taosArrayGetSize(pRsp->batchMetaReq); - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size)); if (size > 0) { for (int32_t i = 0; i < size; i++) { void *pMetaReq = taosArrayGetP(pRsp->batchMetaReq, i); int32_t metaLen = *(int32_t *)taosArrayGet(pRsp->batchMetaLen, i); - if (tEncodeBinary(pEncoder, pMetaReq, metaLen) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pMetaReq, metaLen)); } } - return 0; +_exit: + return code; } int32_t tDecodeMqBatchMetaRsp(SDecoder *pDecoder, SMqBatchMetaRsp *pRsp) { int32_t size = 0; - if (tDecodeI32(pDecoder, &size) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size)); if (size > 0) { pRsp->batchMetaReq = taosArrayInit(size, POINTER_BYTES); - if (!pRsp->batchMetaReq) return -1; + if (!pRsp->batchMetaReq) { + TAOS_CHECK_EXIT(terrno); + } pRsp->batchMetaLen = taosArrayInit(size, sizeof(int32_t)); - if (!pRsp->batchMetaLen) return -1; + if (!pRsp->batchMetaLen) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < size; i++) { void *pCreate = NULL; uint64_t len = 0; - if (tDecodeBinaryAlloc(pDecoder, &pCreate, &len) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeBinaryAlloc(pDecoder, &pCreate, &len)); int32_t l = (int32_t)len; - if (taosArrayPush(pRsp->batchMetaReq, &pCreate) == NULL) return -1; - if (taosArrayPush(pRsp->batchMetaLen, &l) == NULL) return -1; + if (taosArrayPush(pRsp->batchMetaReq, &pCreate) == NULL) { + TAOS_CHECK_EXIT(terrno); + } + if (taosArrayPush(pRsp->batchMetaLen, &l) == NULL) { + TAOS_CHECK_EXIT(terrno); + } } } - return 0; +_exit: + return code; } int32_t tSemiDecodeMqBatchMetaRsp(SDecoder *pDecoder, SMqBatchMetaRsp *pRsp) { - if (tDecodeSTqOffsetVal(pDecoder, &pRsp->rspOffset) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tDecodeSTqOffsetVal(pDecoder, &pRsp->rspOffset)); if (pDecoder->size < pDecoder->pos) { - return -1; + return TSDB_CODE_INVALID_PARA; } pRsp->metaBuffLen = TD_CODER_REMAIN_CAPACITY(pDecoder); pRsp->pMetaBuff = taosMemoryCalloc(1, pRsp->metaBuffLen); if (pRsp->pMetaBuff == NULL) { - return -1; + TAOS_CHECK_EXIT(terrno); } memcpy(pRsp->pMetaBuff, TD_CODER_CURRENT(pDecoder), pRsp->metaBuffLen); - return 0; + +_exit: + return code; } void tDeleteMqBatchMetaRsp(SMqBatchMetaRsp *pRsp) { diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 9b0cd7d5a5..9f5db9b0eb 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -147,12 +147,14 @@ static void dmSetSignalHandle() { (void)taosSetSignal(SIGQUIT, dmStopDnode); #endif +#if 0 #ifndef WINDOWS (void)taosSetSignal(SIGBUS, dmLogCrash); #endif (void)taosSetSignal(SIGABRT, dmLogCrash); (void)taosSetSignal(SIGFPE, dmLogCrash); (void)taosSetSignal(SIGSEGV, dmLogCrash); +#endif } static int32_t dmParseArgs(int32_t argc, char const *argv[]) { diff --git a/source/dnode/mnode/impl/src/mndCompact.c b/source/dnode/mnode/impl/src/mndCompact.c index b8073885fd..bce8c5901d 100644 --- a/source/dnode/mnode/impl/src/mndCompact.c +++ b/source/dnode/mnode/impl/src/mndCompact.c @@ -55,36 +55,44 @@ void tFreeCompactObj(SCompactObj *pCompact) {} int32_t tSerializeSCompactObj(void *buf, int32_t bufLen, const SCompactObj *pObj) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - - if (tEncodeI32(&encoder, pObj->compactId) < 0) return -1; - if (tEncodeCStr(&encoder, pObj->dbname) < 0) return -1; - if (tEncodeI64(&encoder, pObj->startTime) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->compactId)); + TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->dbname)); + TAOS_CHECK_EXIT(tEncodeI64(&encoder, pObj->startTime)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSCompactObj(void *buf, int32_t bufLen, SCompactObj *pObj) { - int8_t ex = 0; + int32_t code = 0; + int32_t lino; SDecoder decoder = {0}; tDecoderInit(&decoder, buf, bufLen); - TAOS_CHECK_RETURN(tStartDecode(&decoder)); - - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactId)); - TAOS_CHECK_RETURN(tDecodeCStrTo(&decoder, pObj->dbname)); - TAOS_CHECK_RETURN(tDecodeI64(&decoder, &pObj->startTime)); + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->compactId)); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->dbname)); + TAOS_CHECK_EXIT(tDecodeI64(&decoder, &pObj->startTime)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } SSdbRaw *mndCompactActionEncode(SCompactObj *pCompact) { @@ -633,8 +641,8 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) { static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) { int32_t code = 0; - bool needSave = false; - void *pIter = NULL; + bool needSave = false; + void *pIter = NULL; while (1) { SCompactDetailObj *pDetail = NULL; pIter = sdbFetch(pMnode->pSdb, SDB_COMPACT_DETAIL, pIter, (void **)&pDetail); diff --git a/source/dnode/mnode/impl/src/mndCompactDetail.c b/source/dnode/mnode/impl/src/mndCompactDetail.c index 86d398e7bd..d1bdb4734d 100644 --- a/source/dnode/mnode/impl/src/mndCompactDetail.c +++ b/source/dnode/mnode/impl/src/mndCompactDetail.c @@ -13,9 +13,9 @@ * along with this program. If not, see . */ #include "mndCompactDetail.h" -#include "mndTrans.h" -#include "mndShow.h" #include "mndDb.h" +#include "mndShow.h" +#include "mndTrans.h" #define MND_COMPACT_VER_NUMBER 1 @@ -35,21 +35,20 @@ int32_t mndInitCompactDetail(SMnode *pMnode) { return sdbSetTable(pMnode->pSdb, table); } -void mndCleanupCompactDetail(SMnode *pMnode) { - mDebug("mnd compact detail cleanup"); -} +void mndCleanupCompactDetail(SMnode *pMnode) { mDebug("mnd compact detail cleanup"); } + +int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { + SMnode *pMnode = pReq->info.node; + SSdb *pSdb = pMnode->pSdb; + int32_t numOfRows = 0; + SCompactDetailObj *pCompactDetail = NULL; + char *sep = NULL; + SDbObj *pDb = NULL; -int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows){ - SMnode *pMnode = pReq->info.node; - SSdb *pSdb = pMnode->pSdb; - int32_t numOfRows = 0; - SCompactDetailObj *pCompactDetail = NULL; - char *sep = NULL; - SDbObj *pDb = NULL; - if (strlen(pShow->db) > 0) { sep = strchr(pShow->db, '.'); - if (sep && ((0 == strcmp(sep + 1, TSDB_INFORMATION_SCHEMA_DB) || (0 == strcmp(sep + 1, TSDB_PERFORMANCE_SCHEMA_DB))))) { + if (sep && + ((0 == strcmp(sep + 1, TSDB_INFORMATION_SCHEMA_DB) || (0 == strcmp(sep + 1, TSDB_PERFORMANCE_SCHEMA_DB))))) { sep++; } else { pDb = mndAcquireDb(pMnode, pShow->db); @@ -57,7 +56,7 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB } } - while(numOfRows < rows){ + while (numOfRows < rows) { pShow->pIter = sdbFetch(pSdb, SDB_COMPACT_DETAIL, pShow->pIter, (void **)&pCompactDetail); if (pShow->pIter == NULL) break; @@ -94,53 +93,60 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB return numOfRows; } -void tFreeCompactDetailObj(SCompactDetailObj *pCompact) { -} +void tFreeCompactDetailObj(SCompactDetailObj *pCompact) {} int32_t tSerializeSCompactDetailObj(void *buf, int32_t bufLen, const SCompactDetailObj *pObj) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - - if (tEncodeI32(&encoder, pObj->compactDetailId) < 0) return -1; - if (tEncodeI32(&encoder, pObj->compactId) < 0) return -1; - if (tEncodeI32(&encoder, pObj->vgId) < 0) return -1; - if (tEncodeI32(&encoder, pObj->dnodeId) < 0) return -1; - if (tEncodeI32(&encoder, pObj->numberFileset) < 0) return -1; - if (tEncodeI32(&encoder, pObj->finished) < 0) return -1; - if (tEncodeI64(&encoder, pObj->startTime) < 0) return -1; - if (tEncodeI32(&encoder, pObj->newNumberFileset) < 0) return -1; - if (tEncodeI32(&encoder, pObj->newFinished) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->compactDetailId)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->compactId)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->vgId)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->dnodeId)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->numberFileset)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->finished)); + TAOS_CHECK_EXIT(tEncodeI64(&encoder, pObj->startTime)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->newNumberFileset)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->newFinished)); tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeSCompactDetailObj(void *buf, int32_t bufLen, SCompactDetailObj *pObj) { - int8_t ex = 0; + int32_t code = 0; + int32_t lino; SDecoder decoder = {0}; tDecoderInit(&decoder, buf, bufLen); - TAOS_CHECK_RETURN(tStartDecode(&decoder)); - - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactDetailId)); - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactId)); - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->vgId)); - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->dnodeId)); - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->numberFileset)); - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->finished)); - TAOS_CHECK_RETURN(tDecodeI64(&decoder, &pObj->startTime)); - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->newNumberFileset)); - TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->newFinished)); + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->compactDetailId)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->compactId)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->vgId)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->dnodeId)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->numberFileset)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->finished)); + TAOS_CHECK_EXIT(tDecodeI64(&decoder, &pObj->startTime)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->newNumberFileset)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->newFinished)); tEndDecode(&decoder); +_exit: tDecoderClear(&decoder); - return 0; + return code; } SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) { @@ -148,7 +154,7 @@ SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) { int32_t lino = 0; terrno = TSDB_CODE_SUCCESS; - void *buf = NULL; + void *buf = NULL; SSdbRaw *pRaw = NULL; int32_t tlen = tSerializeSCompactDetailObj(NULL, 0, pCompact); @@ -156,8 +162,8 @@ SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto OVER; } - - int32_t size = sizeof(int32_t) + tlen; + + int32_t size = sizeof(int32_t) + tlen; pRaw = sdbAllocRaw(SDB_COMPACT_DETAIL, MND_COMPACT_VER_NUMBER, size); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -181,7 +187,6 @@ SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) { SDB_SET_BINARY(pRaw, dataPos, buf, tlen, OVER); SDB_SET_DATALEN(pRaw, dataPos, OVER); - OVER: taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { @@ -263,9 +268,8 @@ int32_t mndCompactDetailActionDelete(SSdb *pSdb, SCompactDetailObj *pCompact) { } int32_t mndCompactDetailActionUpdate(SSdb *pSdb, SCompactDetailObj *pOldCompact, SCompactDetailObj *pNewCompact) { - mTrace("compact detail:%" PRId32 ", perform update action, old row:%p new row:%p", - pOldCompact->compactId, pOldCompact, pNewCompact); - + mTrace("compact detail:%" PRId32 ", perform update action, old row:%p new row:%p", pOldCompact->compactId, + pOldCompact, pNewCompact); pOldCompact->numberFileset = pNewCompact->numberFileset; pOldCompact->finished = pNewCompact->finished; @@ -273,8 +277,8 @@ int32_t mndCompactDetailActionUpdate(SSdb *pSdb, SCompactDetailObj *pOldCompact, return 0; } -int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj* pCompact, SVgObj *pVgroup, - SVnodeGid *pVgid, int32_t index){ +int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *pCompact, SVgObj *pVgroup, + SVnodeGid *pVgid, int32_t index) { int32_t code = 0; SCompactDetailObj compactDetail = {0}; compactDetail.compactDetailId = index; @@ -287,8 +291,8 @@ int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj* p compactDetail.newNumberFileset = -1; compactDetail.newFinished = -1; - mInfo("compact:%d, add compact detail to trans, index:%d, vgId:%d, dnodeId:%d", - compactDetail.compactId, compactDetail.compactDetailId, compactDetail.vgId, compactDetail.dnodeId); + mInfo("compact:%d, add compact detail to trans, index:%d, vgId:%d, dnodeId:%d", compactDetail.compactId, + compactDetail.compactDetailId, compactDetail.vgId, compactDetail.dnodeId); SSdbRaw *pVgRaw = mndCompactDetailActionEncode(&compactDetail); if (pVgRaw == NULL) return -1; diff --git a/source/dnode/mnode/impl/src/mndStreamUtil.c b/source/dnode/mnode/impl/src/mndStreamUtil.c index ef91ccef34..abe87fed64 100644 --- a/source/dnode/mnode/impl/src/mndStreamUtil.c +++ b/source/dnode/mnode/impl/src/mndStreamUtil.c @@ -251,7 +251,7 @@ void mndKillTransImpl(SMnode *pMnode, int32_t transId, const char *pDbName) { int32_t code = mndKillTrans(pMnode, pTrans); mndReleaseTrans(pMnode, pTrans); if (code) { - mError("failed to kill trans:%d", pTrans->id); + mError("failed to kill transId:%d, code:%s", pTrans->id, tstrerror(code)); } } else { mError("failed to acquire trans in Db:%s, transId:%d", pDbName, transId); @@ -1858,4 +1858,74 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo mError("error happens during build task attr result blocks, lino:%d, code:%s", lino, tstrerror(code)); } return code; +} + +uint32_t seed = 0; +static SRpcMsg createRpcMsg(STransAction* pAction, int64_t traceId, int64_t signature) { + SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen, .info.ahandle = (void *)signature}; + rpcMsg.pCont = rpcMallocCont(pAction->contLen); + if (rpcMsg.pCont == NULL) { + return rpcMsg; + } + + rpcMsg.info.traceId.rootId = traceId; + rpcMsg.info.notFreeAhandle = 1; + + memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen); + return rpcMsg; +} + +void streamTransRandomErrorGen(STransAction *pAction, STrans *pTrans, int64_t signature) { + if ((pAction->msgType == TDMT_STREAM_TASK_UPDATE_CHKPT && pAction->id > 2) || + (pAction->msgType == TDMT_STREAM_CONSEN_CHKPT) || + (pAction->msgType == TDMT_VND_STREAM_CHECK_POINT_SOURCE && pAction->id > 2)) { + if (seed == 0) { + seed = taosGetTimestampSec(); + } + + uint32_t v = taosRandR(&seed); + int32_t choseItem = v % 5; + + if (choseItem == 0) { + // 1. one of update-checkpoint not send, restart and send it again + taosMsleep(5000); + if (pAction->msgType == TDMT_STREAM_TASK_UPDATE_CHKPT) { + mError( + "***sleep 5s and core dump, following tasks will not recv update-checkpoint info, so the checkpoint will " + "rollback***"); + exit(-1); + } else if (pAction->msgType == TDMT_STREAM_CONSEN_CHKPT) { // pAction->msgType == TDMT_STREAM_CONSEN_CHKPT + mError( + "***sleep 5s and core dump, following tasks will not recv consen-checkpoint info, so the tasks will " + "not started***"); + } else { // pAction->msgType == TDMT_VND_STREAM_CHECK_POINT_SOURCE + mError( + "***sleep 5s and core dump, following tasks will not recv checkpoint-source info, so the tasks will " + "started after restart***"); + exit(-1); + } + } else if (choseItem == 1) { + // 2. repeat send update chkpt msg + mError("***repeat send update-checkpoint/consensus/checkpoint trans msg 3times to vnode***"); + + mError("***repeat 1***"); + SRpcMsg rpcMsg1 = createRpcMsg(pAction, pTrans->mTraceId, signature); + int32_t code = tmsgSendReq(&pAction->epSet, &rpcMsg1); + + mError("***repeat 2***"); + SRpcMsg rpcMsg2 = createRpcMsg(pAction, pTrans->mTraceId, signature); + code = tmsgSendReq(&pAction->epSet, &rpcMsg2); + + mError("***repeat 3***"); + SRpcMsg rpcMsg3 = createRpcMsg(pAction, pTrans->mTraceId, signature); + code = tmsgSendReq(&pAction->epSet, &rpcMsg3); + } else if (choseItem == 2) { + // 3. sleep 40s and then send msg + mError("***idle for 30s, and then send msg***"); + taosMsleep(30000); + } else { + // do nothing + // mInfo("no error triggered"); + } + } } \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 07490989f5..3634720214 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -161,6 +161,8 @@ int metaTtlFindExpired(SMeta* pMeta, int64_t timePointMs, SArray* tb int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp); int metaUpdateChangeTimeWithLock(SMeta* pMeta, tb_uid_t uid, int64_t changeTimeMs); SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock); +int32_t metaGetTbTSchemaNotNull(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock, STSchema** ppTSchema); +int32_t metaGetTbTSchemaMaybeNull(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock, STSchema** ppTSchema); STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock); int32_t metaGetTbTSchemaEx(SMeta* pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema** ppTSchema); int metaGetTableEntryByName(SMetaReader* pReader, const char* name); diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 2625a77ef0..4bb239046f 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -614,6 +614,22 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock) { return pTSchema; } +int32_t metaGetTbTSchemaNotNull(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock, STSchema** ppTSchema) { + *ppTSchema = metaGetTbTSchema(pMeta, uid, sver, lock); + if(*ppTSchema == NULL) { + return terrno; + } + return TSDB_CODE_SUCCESS; +} + +int32_t metaGetTbTSchemaMaybeNull(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock, STSchema** ppTSchema) { + *ppTSchema = metaGetTbTSchema(pMeta, uid, sver, lock); + if(*ppTSchema == NULL && terrno == TSDB_CODE_OUT_OF_MEMORY) { + return terrno; + } + return TSDB_CODE_SUCCESS; +} + int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema **ppTSchema) { int32_t code = 0; int32_t lino; diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 7576a85cdc..19c5b5d481 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -392,10 +392,9 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con return terrno; } - STSchema *pTSchema = metaGetTbTSchema(SMA_META(pSma), suid, -1, 1); - if (!pTSchema) { - TAOS_CHECK_EXIT(TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION); - } + STSchema *pTSchema; + code = metaGetTbTSchemaNotNull(SMA_META(pSma), suid, -1, 1, &pTSchema); + TAOS_CHECK_EXIT(code); pRSmaInfo->pSma = pSma; pRSmaInfo->pTSchema = pTSchema; pRSmaInfo->suid = suid; diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c index 8fd50716f6..f66282ac25 100644 --- a/source/dnode/vnode/src/sma/smaTimeRange.c +++ b/source/dnode/vnode/src/sma/smaTimeRange.c @@ -343,11 +343,8 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char TSDB_CHECK_CODE(code, lino, _exit); } pTsmaStat->pTSma = pTSma; - pTsmaStat->pTSchema = metaGetTbTSchema(SMA_META(pSma), pTSma->dstTbUid, -1, 1); - if (!pTsmaStat->pTSchema) { - code = TSDB_CODE_TSMA_INVALID_PTR; - TSDB_CHECK_CODE(code, lino, _exit); - } + code = metaGetTbTSchemaNotNull(SMA_META(pSma), pTSma->dstTbUid, -1, 1, &pTsmaStat->pTSchema); + TSDB_CHECK_CODE(code, lino, _exit); } if (pTsmaStat->pTSma->indexUid != indexUid) { diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index e319c146c2..ab83764bdc 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -1129,7 +1129,7 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) SStreamTask* pTask = NULL; code = streamMetaAcquireTask(pMeta, req.streamId, req.taskId, &pTask); - if (pTask == NULL) { + if (pTask == NULL || code != 0) { tqError("vgId:%d failed to find s-task:0x%x, ignore checkpoint msg. checkpointId:%" PRId64 " transId:%d it may have been destroyed", vgId, req.taskId, req.checkpointId, req.transId); diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index db7766a7bb..60da4e3799 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -16,64 +16,79 @@ #include "tq.h" int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeCStr(pEncoder, pHandle->subKey) < 0) return -1; - if (tEncodeI8(pEncoder, pHandle->fetchMeta) < 0) return -1; - if (tEncodeI64(pEncoder, pHandle->consumerId) < 0) return -1; - if (tEncodeI64(pEncoder, pHandle->snapshotVer) < 0) return -1; - if (tEncodeI32(pEncoder, pHandle->epoch) < 0) return -1; - if (tEncodeI8(pEncoder, pHandle->execHandle.subType) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pHandle->subKey)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pHandle->fetchMeta)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pHandle->consumerId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pHandle->snapshotVer)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pHandle->epoch)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pHandle->execHandle.subType)); if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { - if (tEncodeCStr(pEncoder, pHandle->execHandle.execCol.qmsg) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pHandle->execHandle.execCol.qmsg)); } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) { int32_t size = taosHashGetSize(pHandle->execHandle.execDb.pFilterOutTbUid); - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size)); void* pIter = NULL; pIter = taosHashIterate(pHandle->execHandle.execDb.pFilterOutTbUid, pIter); while (pIter) { int64_t* tbUid = (int64_t*)taosHashGetKey(pIter, NULL); - if (tEncodeI64(pEncoder, *tbUid) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, *tbUid)); pIter = taosHashIterate(pHandle->execHandle.execDb.pFilterOutTbUid, pIter); } } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { - if (tEncodeI64(pEncoder, pHandle->execHandle.execTb.suid) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pHandle->execHandle.execTb.suid)); if (pHandle->execHandle.execTb.qmsg != NULL) { - if (tEncodeCStr(pEncoder, pHandle->execHandle.execTb.qmsg) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pHandle->execHandle.execTb.qmsg)); } } tEndEncode(pEncoder); - return pEncoder->pos; +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pHandle->subKey) < 0) return -1; - if (tDecodeI8(pDecoder, &pHandle->fetchMeta) < 0) return -1; - if (tDecodeI64(pDecoder, &pHandle->consumerId) < 0) return -1; - if (tDecodeI64(pDecoder, &pHandle->snapshotVer) < 0) return -1; - if (tDecodeI32(pDecoder, &pHandle->epoch) < 0) return -1; - if (tDecodeI8(pDecoder, &pHandle->execHandle.subType) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pHandle->subKey)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pHandle->fetchMeta)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pHandle->consumerId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pHandle->snapshotVer)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pHandle->epoch)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pHandle->execHandle.subType)); if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { - if (tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execCol.qmsg) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execCol.qmsg)); } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) { pHandle->execHandle.execDb.pFilterOutTbUid = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); - if (pHandle->execHandle.execDb.pFilterOutTbUid == NULL) return -1; + if (pHandle->execHandle.execDb.pFilterOutTbUid == NULL) { + TAOS_CHECK_EXIT(terrno); + } int32_t size = 0; - if (tDecodeI32(pDecoder, &size) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size)); for (int32_t i = 0; i < size; i++) { int64_t tbUid = 0; - if (tDecodeI64(pDecoder, &tbUid) < 0) return -1; - if (taosHashPut(pHandle->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0) != 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &tbUid)); + TAOS_CHECK_EXIT(taosHashPut(pHandle->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0)); } } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { - if (tDecodeI64(pDecoder, &pHandle->execHandle.execTb.suid) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pHandle->execHandle.execTb.suid)); if (!tDecodeIsEnd(pDecoder)) { - if (tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execTb.qmsg) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execTb.qmsg)); } } tEndDecode(pDecoder); - return 0; + +_exit: + return code; } int32_t tqMetaDecodeCheckInfo(STqCheckInfo* info, void* pVal, int32_t vLen) { diff --git a/source/dnode/vnode/src/tqCommon/tqCommon.c b/source/dnode/vnode/src/tqCommon/tqCommon.c index 44b3f75289..68f43d637b 100644 --- a/source/dnode/vnode/src/tqCommon/tqCommon.c +++ b/source/dnode/vnode/src/tqCommon/tqCommon.c @@ -410,7 +410,7 @@ int32_t tqStreamTaskProcessRetrieveReq(SStreamMeta* pMeta, SRpcMsg* pMsg) { tDecoderClear(&decoder); if (code) { - tqError("vgId:%d failed to decode retrieve msg, quit handling it", pMeta->vgId); + tqError("vgId:%d failed to decode retrieve msg, discard it", pMeta->vgId); return code; } @@ -420,9 +420,16 @@ int32_t tqStreamTaskProcessRetrieveReq(SStreamMeta* pMeta, SRpcMsg* pMsg) { tqError("vgId:%d process retrieve req, failed to acquire task:0x%x, it may have been dropped already", pMeta->vgId, req.dstTaskId); tCleanupStreamRetrieveReq(&req); - return -1; + return code; } + // enqueue + tqDebug("s-task:%s (vgId:%d level:%d) recv retrieve req from task:0x%x(vgId:%d),QID:0x%" PRIx64, pTask->id.idStr, + pTask->pMeta->vgId, pTask->info.taskLevel, req.srcTaskId, req.srcNodeId, req.reqId); + + // if task is in ck status, set current ck failed + streamTaskSetCheckpointFailed(pTask); + if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) { code = streamProcessRetrieveReq(pTask, &req); } else { @@ -431,14 +438,19 @@ int32_t tqStreamTaskProcessRetrieveReq(SStreamMeta* pMeta, SRpcMsg* pMsg) { code = streamTaskBroadcastRetrieveReq(pTask, &req); } - SRpcMsg rsp = {.info = pMsg->info, .code = 0}; - streamTaskSendRetrieveRsp(&req, &rsp); + if (code != TSDB_CODE_SUCCESS) { // return error not send rsp manually + tqError("s-task:0x%x vgId:%d failed to process retrieve request from 0x%x, code:%s", req.dstTaskId, req.dstNodeId, + req.srcTaskId, tstrerror(code)); + } else { // send rsp manually only on success. + SRpcMsg rsp = {.info = pMsg->info, .code = 0}; + streamTaskSendRetrieveRsp(&req, &rsp); + } streamMetaReleaseTask(pMeta, pTask); tCleanupStreamRetrieveReq(&req); // always return success, to disable the auto rsp - return TSDB_CODE_SUCCESS; + return code; } int32_t tqStreamTaskProcessCheckReq(SStreamMeta* pMeta, SRpcMsg* pMsg) { diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 2a321289d1..2b76e8841d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -2158,6 +2158,11 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea uint64_t uid = uidList[j]; STableLoadInfo *pInfo = getTableLoadInfo(pReader, uid); + if (!pInfo) { + (void)tTombBlockDestroy(&block); + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } + if (pInfo->pTombData == NULL) { pInfo->pTombData = taosArrayInit(4, sizeof(SDelData)); } @@ -2200,8 +2205,18 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea if (newTable) { pInfo = getTableLoadInfo(pReader, uid); + if (!pInfo) { + code = TSDB_CODE_OUT_OF_MEMORY; + finished = true; + break; + } if (pInfo->pTombData == NULL) { pInfo->pTombData = taosArrayInit(4, sizeof(SDelData)); + if (!pInfo->pTombData) { + code = TSDB_CODE_OUT_OF_MEMORY; + finished = true; + break; + } } } @@ -2998,6 +3013,8 @@ static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow, bool *pI uint64_t uid = pIter->idx.uid; STableLoadInfo *pInfo = getTableLoadInfo(pIter->pr, uid); + TSDB_CHECK_NULL(pInfo, code, lino, _err, TSDB_CODE_OUT_OF_MEMORY); + if (pInfo->pTombData == NULL) { pInfo->pTombData = taosArrayInit(4, sizeof(SDelData)); TSDB_CHECK_NULL(pInfo->pTombData, code, lino, _err, TSDB_CODE_OUT_OF_MEMORY); @@ -3204,6 +3221,10 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC break; } // high version's column value + if (slotIds[iCol] > pTSchema->numOfCols - 1) { + continue; + } + SLastCol *lastColVal = (SLastCol *)taosArrayGet(pColArray, iCol); if (lastColVal->colVal.cid != pTSchema->columns[slotIds[iCol]].colId) { continue; diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index 14e4b5a53c..6fcafdefbd 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -237,17 +237,25 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p static int32_t setTableSchema(SCacheRowsReader* p, uint64_t suid, const char* idstr) { int32_t numOfTables = p->numOfTables; + int32_t code = TSDB_CODE_SUCCESS; if (suid != 0) { - p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, suid, -1, 1); - if (p->pSchema == NULL) { + code = metaGetTbTSchemaNotNull(p->pVnode->pMeta, suid, -1, 1, &p->pSchema); + if (TSDB_CODE_SUCCESS != code) { tsdbWarn("stable:%" PRIu64 " has been dropped, failed to retrieve cached rows, %s", suid, idstr); - return TSDB_CODE_PAR_TABLE_NOT_EXIST; + if(code != TSDB_CODE_OUT_OF_MEMORY) { + return TSDB_CODE_PAR_TABLE_NOT_EXIST; + } else { + return code; + } } } else { for (int32_t i = 0; i < numOfTables; ++i) { uint64_t uid = p->pTableList[i].uid; - p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, uid, -1, 1); + code = metaGetTbTSchemaMaybeNull(p->pVnode->pMeta, uid, -1, 1, &p->pSchema); + if(code != TSDB_CODE_SUCCESS) { + return code; + } if (p->pSchema != NULL) { break; } diff --git a/source/dnode/vnode/src/tsdb/tsdbFSet2.c b/source/dnode/vnode/src/tsdb/tsdbFSet2.c index de62ce63a0..f5dd2a3768 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFSet2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFSet2.c @@ -50,7 +50,11 @@ static int32_t tsdbSttLvlInitEx(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lvl } code = TARRAY2_APPEND(lvl[0]->fobjArr, fobj); - if (code) return code; + if (code) { + (void)tsdbSttLvlClear(lvl); + taosMemoryFree(fobj); + return code; + } } return 0; } diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index fc2b873054..ed67bfca3e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -408,9 +408,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl for (int32_t k = startIndex; k < endIndex; ++k) { code = tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[k], &block); - if (code) { - return code; - } + QUERY_CHECK_CODE(code, lino, _end); int32_t i = 0; int32_t rows = block.numOfRecords; @@ -536,12 +534,15 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl } _end: - (void)tStatisBlockDestroy(&block); + (void) tStatisBlockDestroy(&block); + if (code != 0) { + tsdbError("%s error happens at:%s line number: %d, code:%s", id, __func__, lino, tstrerror(code)); + } else { + double el = (taosGetTimestampUs() - st) / 1000.0; + pBlockLoadInfo->cost.statisElapsedTime += el; - double el = (taosGetTimestampUs() - st) / 1000.0; - pBlockLoadInfo->cost.statisElapsedTime += el; - - tsdbDebug("%s load %d statis blocks into buf, elapsed time:%.2fms", id, num, el); + tsdbDebug("%s load %d statis blocks into buf, elapsed time:%.2fms", id, num, el); + } return code; } @@ -953,6 +954,7 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF pMTree->pIter = NULL; pMTree->backward = pConf->backward; pMTree->idStr = pConf->idstr; + int32_t lino = 0; if (!pMTree->backward) { // asc tRBTreeCreate(&pMTree->rbt, tLDataIterCmprFn); @@ -1027,9 +1029,8 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF // let's record the time window for current table of uid in the stt files if (pSttDataInfo != NULL && numOfRows > 0) { void *px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range); - if (px == NULL) { - return terrno; - } + QUERY_CHECK_NULL(px, code, lino, _end, terrno); + pSttDataInfo->numOfRows += numOfRows; } } else { diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index 34280326a0..bcf49a39a7 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -403,7 +403,7 @@ static void initReaderStatus(SReaderStatus* pStatus) { } static int32_t createResBlock(SQueryTableDataCond* pCond, int32_t capacity, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); SSDataBlock* pBlock = NULL; int32_t code = createDataBlock(&pBlock); @@ -1743,8 +1743,6 @@ static int32_t initRowMergeIfNeeded(STsdbReader* pReader, int64_t uid) { if (ps == NULL) { return terrno; } - - code = tsdbRowMergerInit(pMerger, ps); } return code; @@ -4747,13 +4745,15 @@ int32_t tsdbReaderOpen2(void* pVnode, SQueryTableDataCond* pCond, void* pTableLi // no valid error code set in metaGetTbTSchema, so let's set the error code here. // we should proceed in case of tmq processing. if (pCond->suid != 0) { - pReader->info.pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, -1, 1); + code = metaGetTbTSchemaMaybeNull(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, -1, 1, &pReader->info.pSchema); + TSDB_CHECK_CODE(code, lino, _err); if (pReader->info.pSchema == NULL) { tsdbWarn("failed to get table schema, suid:%" PRIu64 ", ver:-1, %s", pReader->info.suid, pReader->idStr); } } else if (numOfTables > 0) { STableKeyInfo* pKey = pTableList; - pReader->info.pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, pKey->uid, -1, 1); + code = metaGetTbTSchemaMaybeNull(pReader->pTsdb->pVnode->pMeta, pKey->uid, -1, 1, &pReader->info.pSchema); + TSDB_CHECK_CODE(code, lino, _err); if (pReader->info.pSchema == NULL) { tsdbWarn("failed to get table schema, uid:%" PRIu64 ", ver:-1, %s", pKey->uid, pReader->idStr); } diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 23bc6b607c..dedb473df6 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -396,15 +396,21 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { switch (req->msgType) { case TDMT_VND_TABLE_META: // error code has been set into reqMsg, no need to handle it here. - (void)vnodeGetTableMeta(pVnode, &reqMsg, false); + if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) { + qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType); + } break; case TDMT_VND_TABLE_CFG: // error code has been set into reqMsg, no need to handle it here. - (void)vnodeGetTableCfg(pVnode, &reqMsg, false); + if (TSDB_CODE_SUCCESS != vnodeGetTableCfg(pVnode, &reqMsg, false)) { + qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType); + } break; case TDMT_VND_GET_STREAM_PROGRESS: // error code has been set into reqMsg, no need to handle it here. - (void)vnodeGetStreamProgress(pVnode, &reqMsg, false); + if (TSDB_CODE_SUCCESS != vnodeGetStreamProgress(pVnode, &reqMsg, false)) { + qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType); + } break; default: qError("invalid req msgType %d", req->msgType); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 8052be46f9..dbd63471c0 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -1477,15 +1477,15 @@ static int32_t vnodeDebugPrintSingleSubmitMsg(SMeta *pMeta, SSubmitBlk *pBlock, tInitSubmitBlkIter(msgIter, pBlock, &blkIter); if (blkIter.row == NULL) return 0; - pSchema = metaGetTbTSchema(pMeta, msgIter->suid, TD_ROW_SVER(blkIter.row), 1); // TODO: use the real schema - if (pSchema) { - suid = msgIter->suid; - rv = TD_ROW_SVER(blkIter.row); - } - if (!pSchema) { + int32_t code = metaGetTbTSchemaNotNull(pMeta, msgIter->suid, TD_ROW_SVER(blkIter.row), 1, &pSchema); // TODO: use the real schema + if (TSDB_CODE_SUCCESS != code) { printf("%s:%d no valid schema\n", tags, __LINE__); - return -1; + return code; } + + suid = msgIter->suid; + rv = TD_ROW_SVER(blkIter.row); + char __tags[128] = {0}; snprintf(__tags, 128, "%s: uid %" PRIi64 " ", tags, msgIter->uid); while ((row = tGetSubmitBlkNext(&blkIter))) { @@ -1510,10 +1510,10 @@ typedef struct SSubmitReqConvertCxt { static int32_t vnodeResetTableCxt(SMeta *pMeta, SSubmitReqConvertCxt *pCxt) { taosMemoryFreeClear(pCxt->pTbSchema); - pCxt->pTbSchema = metaGetTbTSchema(pMeta, pCxt->msgIter.suid > 0 ? pCxt->msgIter.suid : pCxt->msgIter.uid, - pCxt->msgIter.sversion, 1); - if (NULL == pCxt->pTbSchema) { - return TSDB_CODE_INVALID_MSG; + int32_t code = metaGetTbTSchemaNotNull(pMeta, pCxt->msgIter.suid > 0 ? pCxt->msgIter.suid : pCxt->msgIter.uid, + pCxt->msgIter.sversion, 1, &pCxt->pTbSchema); + if (TSDB_CODE_SUCCESS != code) { + return code; } tdSTSRowIterInit(&pCxt->rowIter, pCxt->pTbSchema); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 138782495f..80766855cf 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -78,7 +78,7 @@ static int32_t getSchemaBytes(const SSchema* pSchema) { } static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) { - QRY_OPTR_CHECK(pOutput); + QRY_PARAM_CHECK(pOutput); SSDataBlock* pBlock = NULL; int32_t code = createDataBlock(&pBlock); @@ -236,7 +236,7 @@ static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** static int32_t execResetQueryCache() { return catalogClearCache(); } static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) { - QRY_OPTR_CHECK(pOutput); + QRY_PARAM_CHECK(pOutput); SSDataBlock* pBlock = NULL; int32_t code = createDataBlock(&pBlock); @@ -475,7 +475,7 @@ static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveT } static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) { - QRY_OPTR_CHECK(pOutput); + QRY_PARAM_CHECK(pOutput); SSDataBlock* pBlock = NULL; int32_t code = createDataBlock(&pBlock); @@ -499,7 +499,7 @@ static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) { } static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) { - QRY_OPTR_CHECK(pOutput); + QRY_PARAM_CHECK(pOutput); SSDataBlock* pBlock = NULL; int32_t code = createDataBlock(&pBlock); @@ -929,7 +929,7 @@ static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) { } static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** pOutput) { - QRY_OPTR_CHECK(pOutput); + QRY_PARAM_CHECK(pOutput); SSDataBlock* pBlock = NULL; int32_t code = createDataBlock(&pBlock); diff --git a/source/libs/executor/src/aggregateoperator.c b/source/libs/executor/src/aggregateoperator.c index 61f1339c82..4605d19464 100644 --- a/source/libs/executor/src/aggregateoperator.c +++ b/source/libs/executor/src/aggregateoperator.c @@ -51,7 +51,7 @@ typedef struct SAggOperatorInfo { } SAggOperatorInfo; static void destroyAggOperatorInfo(void* param); -static void setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId); +static int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId); static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock); static void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock); @@ -63,14 +63,14 @@ static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, in static int32_t addNewResultRowBuf(SResultRow* pWindowRes, SDiskbasedBuf* pResultBuf, uint32_t size); -static void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId); +static int32_t doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId); static void functionCtxSave(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus); static void functionCtxRestore(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus); int32_t createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t lino = 0; int32_t code = 0; @@ -184,7 +184,8 @@ static bool nextGroupedResult(SOperatorInfo* pOperator) { if (pBlock) { pAggInfo->pNewGroupBlock = NULL; tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable); - setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId); + code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId); + QUERY_CHECK_CODE(code, lino, _end); code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true); QUERY_CHECK_CODE(code, lino, _end); @@ -225,12 +226,19 @@ static bool nextGroupedResult(SOperatorInfo* pOperator) { break; } // the pDataBlock are always the same one, no need to call this again - setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId); + code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId); + if (code != TSDB_CODE_SUCCESS) { + destroyDataBlockForEmptyInput(blockAllocated, &pBlock); + T_LONG_JMP(pTaskInfo->env, code); + } code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true); - QUERY_CHECK_CODE(code, lino, _end); + if (code != TSDB_CODE_SUCCESS) { + destroyDataBlockForEmptyInput(blockAllocated, &pBlock); + T_LONG_JMP(pTaskInfo->env, code); + } code = doAggregateImpl(pOperator, pSup->pCtx); - if (code != 0) { + if (code != TSDB_CODE_SUCCESS) { destroyDataBlockForEmptyInput(blockAllocated, &pBlock); T_LONG_JMP(pTaskInfo->env, code); } @@ -427,20 +435,24 @@ void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) { *ppBlock = NULL; } -void setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) { +int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) { + int32_t code = TSDB_CODE_SUCCESS; SAggOperatorInfo* pAggInfo = pOperator->info; if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) { - return; + return code; } - doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId); + code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId); // record the current active group id pAggInfo->groupId = groupId; + return code; } -void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) { +int32_t doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) { // for simple group by query without interval, all the tables belong to one group result. + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SAggOperatorInfo* pAggInfo = pOperator->info; @@ -452,23 +464,27 @@ void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uin doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true, groupId, pTaskInfo, false, &pAggInfo->aggSup, true); if (pResultRow == NULL || pTaskInfo->code != 0) { - T_LONG_JMP(pTaskInfo->env, pTaskInfo->code); + code = pTaskInfo->code; + lino = __LINE__; + goto _end; } /* * not assign result buffer yet, add new result buffer * all group belong to one result set, and each group result has different group id so set the id to be one */ if (pResultRow->pageId == -1) { - int32_t ret = addNewResultRowBuf(pResultRow, pAggInfo->aggSup.pResultBuf, pAggInfo->binfo.pRes->info.rowSize); - if (ret != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, terrno); - } + code = addNewResultRowBuf(pResultRow, pAggInfo->aggSup.pResultBuf, pAggInfo->binfo.pRes->info.rowSize); + QUERY_CHECK_CODE(code, lino, _end); } - int32_t ret = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset); - if (ret != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, ret); + code = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset); + QUERY_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); } + return code; } // a new buffer page for each table. Needs to opt this design diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index fdf20b4613..b575613efe 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -97,7 +97,7 @@ _end: int32_t createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandle* readHandle, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; diff --git a/source/libs/executor/src/countwindowoperator.c b/source/libs/executor/src/countwindowoperator.c index 713116d605..2233d58ef8 100644 --- a/source/libs/executor/src/countwindowoperator.c +++ b/source/libs/executor/src/countwindowoperator.c @@ -295,7 +295,7 @@ _end: int32_t createCountwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index fb3ed06224..9bbc5a94eb 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -204,6 +204,7 @@ static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, _return: + taosMemoryFreeClear(pBuf->pData); taosFreeQitem(pBuf); return code; } diff --git a/source/libs/executor/src/dynqueryctrloperator.c b/source/libs/executor/src/dynqueryctrloperator.c index 8058fa9afe..44e8a3cb8a 100644 --- a/source/libs/executor/src/dynqueryctrloperator.c +++ b/source/libs/executor/src/dynqueryctrloperator.c @@ -889,7 +889,7 @@ int32_t seqStableJoin(SOperatorInfo* pOperator, SSDataBlock** pRes) { SDynQueryCtrlOperatorInfo* pInfo = pOperator->info; SStbJoinDynCtrlInfo* pStbJoin = (SStbJoinDynCtrlInfo*)&pInfo->stbJoin; - QRY_OPTR_CHECK(pRes); + QRY_PARAM_CHECK(pRes); if (pOperator->status == OP_EXEC_DONE) { return code; } @@ -958,7 +958,7 @@ int32_t initSeqStbJoinTableHash(SStbJoinPrevJoinCtx* pPrev, bool batchFetch) { int32_t createDynQueryCtrlOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SDynQueryCtrlPhysiNode* pPhyciNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; __optr_fn_t nextFp = NULL; diff --git a/source/libs/executor/src/eventwindowoperator.c b/source/libs/executor/src/eventwindowoperator.c index a4be2ddf7d..0f3a08c14b 100644 --- a/source/libs/executor/src/eventwindowoperator.c +++ b/source/libs/executor/src/eventwindowoperator.c @@ -61,7 +61,7 @@ static void doKeepTuple(SWindowRowsSup* pRowSup, int64_t ts, uint64_t groupId) { int32_t createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index f6f3570804..457aa8ff2b 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -401,7 +401,7 @@ static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo* int32_t createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t lino = 0; @@ -464,7 +464,10 @@ _error: void destroyExchangeOperatorInfo(void* param) { SExchangeInfo* pExInfo = (SExchangeInfo*)param; - (void)taosRemoveRef(exchangeObjRefPool, pExInfo->self); + int32_t code = taosRemoveRef(exchangeObjRefPool, pExInfo->self); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + } } void freeBlock(void* pParam) { @@ -505,7 +508,10 @@ void doDestroyExchangeOperatorInfo(void* param) { blockDataDestroy(pExInfo->pDummyBlock); tSimpleHashCleanup(pExInfo->pHashSources); - (void)tsem_destroy(&pExInfo->ready); + int32_t code = tsem_destroy(&pExInfo->ready); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + } taosMemoryFreeClear(pExInfo->pTaskId); taosMemoryFreeClear(param); @@ -561,9 +567,13 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { if (code != TSDB_CODE_SUCCESS) { code = TAOS_SYSTEM_ERROR(code); qError("failed to invoke post when fetch rsp is ready, code:%s, %p", tstrerror(code), pExchangeInfo); + return code; } - (void)taosReleaseRef(exchangeObjRefPool, pWrapper->exchangeId); + code = taosReleaseRef(exchangeObjRefPool, pWrapper->exchangeId); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + } return code; } @@ -1190,7 +1200,14 @@ static int32_t exchangeWait(SOperatorInfo* pOperator, SExchangeInfo* pExchangeIn return pTask->code; } } - (void)tsem_wait(&pExchangeInfo->ready); + + code = tsem_wait(&pExchangeInfo->ready); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + pTask->code = code; + return pTask->code; + } + if (pTask->pWorkerCb) { code = pTask->pWorkerCb->afterRecoverFromBlocking(pTask->pWorkerCb->pPool); if (code != TSDB_CODE_SUCCESS) { diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index db3017468d..05ed5a9d1e 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -1924,7 +1924,7 @@ SExprInfo* createExpr(SNodeList* pNodeList, int32_t* numOfExprs) { } int32_t createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, SExprInfo** pExprInfo, int32_t* numOfExprs) { - QRY_OPTR_CHECK(pExprInfo); + QRY_PARAM_CHECK(pExprInfo); int32_t code = 0; int32_t numOfFuncs = LIST_LENGTH(pNodeList); diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 117eb8d80a..9e33a3d890 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -601,7 +601,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo; (void)taosThreadOnce(&initPoolOnce, initRefPool); - qDebug("start to create task, TID:0x%" PRIx64 "QID:0x%" PRIx64 ", vgId:%d", taskId, pSubplan->id.queryId, vgId); + qDebug("start to create task, TID:0x%" PRIx64 " QID:0x%" PRIx64 ", vgId:%d", taskId, pSubplan->id.queryId, vgId); int32_t code = createExecTaskInfo(pSubplan, pTask, readHandle, taskId, vgId, sql, model); if (code != TSDB_CODE_SUCCESS || NULL == *pTask) { @@ -904,8 +904,14 @@ void qStopTaskOperators(SExecTaskInfo* pTaskInfo) { } SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pStop->refId); if (pExchangeInfo) { - (void)tsem_post(&pExchangeInfo->ready); - (void)taosReleaseRef(exchangeObjRefPool, pStop->refId); + int32_t code = tsem_post(&pExchangeInfo->ready); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + } + code = taosReleaseRef(exchangeObjRefPool, pStop->refId); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + } } } @@ -1627,3 +1633,11 @@ int32_t qStreamOperatorReloadState(qTaskInfo_t tInfo) { pTaskInfo->pRoot->fpSet.reloadStreamStateFn(pTaskInfo->pRoot); return 0; } + +void qResetTaskCode(qTaskInfo_t tinfo) { + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; + + int32_t code = pTaskInfo->code; + pTaskInfo->code = 0; + qDebug("0x%" PRIx64 " reset task code to be success, prev:%s", pTaskInfo->id.taskId, tstrerror(code)); +} diff --git a/source/libs/executor/src/executorInt.c b/source/libs/executor/src/executorInt.c index a1bf64a10d..00138d6871 100644 --- a/source/libs/executor/src/executorInt.c +++ b/source/libs/executor/src/executorInt.c @@ -1280,7 +1280,7 @@ void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); int32_t code = 0; if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) { diff --git a/source/libs/executor/src/filloperator.c b/source/libs/executor/src/filloperator.c index 21b67c8ffb..76b41ca99a 100644 --- a/source/libs/executor/src/filloperator.c +++ b/source/libs/executor/src/filloperator.c @@ -423,7 +423,7 @@ static int32_t createPrimaryTsExprIfNeeded(SFillOperatorInfo* pInfo, SFillPhysiN int32_t createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t lino = 0; diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 6a9482e31c..1796aa7b64 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -1444,7 +1444,7 @@ static int32_t groupCacheTableCacheEnd(SOperatorInfo* pOperator, SOperatorParam* int32_t createGroupCacheOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SGroupCachePhysiNode* pPhyciNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; SGroupCacheOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupCacheOperatorInfo)); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 47b35fe9f3..e4ace6b83a 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -353,38 +353,6 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { } } -static SSDataBlock* buildGroupResultDataBlock(SOperatorInfo* pOperator) { - int32_t code = TSDB_CODE_SUCCESS; - int32_t lino = 0; - SGroupbyOperatorInfo* pInfo = pOperator->info; - SSDataBlock* pRes = pInfo->binfo.pRes; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - while (1) { - doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - code = doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL); - QUERY_CHECK_CODE(code, lino, _end); - - if (!hasRemainResults(&pInfo->groupResInfo)) { - setOperatorCompleted(pOperator); - break; - } - - if (pRes->info.rows > 0) { - break; - } - } - - pOperator->resultInfo.totalRows += pRes->info.rows; - -_end: - if (code != TSDB_CODE_SUCCESS) { - qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); - T_LONG_JMP(pTaskInfo->env, code); - } - return (pRes->info.rows == 0) ? NULL : pRes; -} - bool hasRemainResultByHash(SOperatorInfo* pOperator) { SGroupbyOperatorInfo* pInfo = pOperator->info; SSHashObj* pHashmap = pInfo->aggSup.pResultRowHashTable; @@ -463,25 +431,23 @@ _end: } static int32_t hashGroupbyAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SGroupbyOperatorInfo* pInfo = pOperator->info; + SGroupResInfo* pGroupResInfo = &pInfo->groupResInfo; + int32_t order = pInfo->binfo.inputTsOrder; + int64_t st = taosGetTimestampUs(); + + QRY_PARAM_CHECK(ppRes); if (pOperator->status == OP_EXEC_DONE) { - (*ppRes) = NULL; return TSDB_CODE_SUCCESS; } - int32_t code = TSDB_CODE_SUCCESS; - int32_t lino = 0; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - SGroupbyOperatorInfo* pInfo = pOperator->info; if (pOperator->status == OP_RES_TO_RETURN) { (*ppRes) = buildGroupResultDataBlockByHash(pOperator); return code; } - SGroupResInfo* pGroupResInfo = &pInfo->groupResInfo; - - int32_t order = pInfo->binfo.inputTsOrder; - int64_t st = taosGetTimestampUs(); - SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { SSDataBlock* pBlock = getNextBlockFromDownstream(pOperator, 0); @@ -511,10 +477,12 @@ static int32_t hashGroupbyAggregateNext(SOperatorInfo* pOperator, SSDataBlock** if (pGroupResInfo->pRows != NULL) { taosArrayDestroy(pGroupResInfo->pRows); } + if (pGroupResInfo->pBuf) { taosMemoryFree(pGroupResInfo->pBuf); pGroupResInfo->pBuf = NULL; } + pGroupResInfo->index = 0; pGroupResInfo->iter = 0; pGroupResInfo->dataPos = NULL; @@ -525,15 +493,16 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); + } else { + (*ppRes) = buildGroupResultDataBlockByHash(pOperator); } - (*ppRes) = buildGroupResultDataBlockByHash(pOperator); + return code; } int32_t createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -1127,7 +1096,7 @@ static void destroyPartitionOperatorInfo(void* param) { int32_t createPartitionOperatorInfo(SOperatorInfo* downstream, SPartitionPhysiNode* pPartNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -1668,7 +1637,7 @@ void freePartItem(void* ptr) { int32_t createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStreamPartitionPhysiNode* pPartNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; diff --git a/source/libs/executor/src/hashjoinoperator.c b/source/libs/executor/src/hashjoinoperator.c index 4e630dbd18..7f13608653 100644 --- a/source/libs/executor/src/hashjoinoperator.c +++ b/source/libs/executor/src/hashjoinoperator.c @@ -996,7 +996,7 @@ static int32_t hJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** p SSDataBlock* pRes = pJoin->finBlk; int64_t st = 0; - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); if (pOperator->cost.openCost == 0) { st = taosGetTimestampUs(); } @@ -1182,7 +1182,7 @@ int32_t hJoinInitResBlocks(SHJoinOperatorInfo* pJoin, SHashJoinPhysiNode* pJoinN int32_t createHashJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SHashJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; SHJoinOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SHJoinOperatorInfo)); diff --git a/source/libs/executor/src/mergejoinoperator.c b/source/libs/executor/src/mergejoinoperator.c index 30cc596a44..90c2248c12 100644 --- a/source/libs/executor/src/mergejoinoperator.c +++ b/source/libs/executor/src/mergejoinoperator.c @@ -1867,7 +1867,7 @@ int32_t mJoinSetImplFp(SMJoinOperatorInfo* pJoin) { int32_t createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SSortMergeJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t oldNum = numOfDownstream; bool newDownstreams = false; diff --git a/source/libs/executor/src/mergeoperator.c b/source/libs/executor/src/mergeoperator.c index 93bddb0787..7357329ca6 100644 --- a/source/libs/executor/src/mergeoperator.c +++ b/source/libs/executor/src/mergeoperator.c @@ -336,7 +336,7 @@ int32_t openNonSortMergeOperator(SOperatorInfo* pOperator) { } int32_t doNonSortMerge(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SMultiwayMergeOperatorInfo* pInfo = pOperator->info; @@ -419,7 +419,7 @@ int32_t copyColumnsValue(SNodeList* pNodeList, uint64_t targetBlkId, SSDataBlock } int32_t doColsMerge(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SMultiwayMergeOperatorInfo* pInfo = pOperator->info; @@ -499,7 +499,7 @@ int32_t openMultiwayMergeOperator(SOperatorInfo* pOperator) { } int32_t doMultiwayMerge(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); if (pOperator->status == OP_EXEC_DONE) { return 0; @@ -556,7 +556,7 @@ int32_t getMultiwayMergeExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplai int32_t createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size_t numStreams, SMergePhysiNode* pMergePhyNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); SPhysiNode* pPhyNode = (SPhysiNode*)pMergePhyNode; int32_t lino = 0; diff --git a/source/libs/executor/src/operator.c b/source/libs/executor/src/operator.c index 983b70c575..6fe270161f 100644 --- a/source/libs/executor/src/operator.c +++ b/source/libs/executor/src/operator.c @@ -180,7 +180,7 @@ ERetType extractOperatorInfo(SOperatorInfo* pOperator, STraverParam* pParam, con // QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN int32_t extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, const char* id, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); if (pOperator == NULL) { qError("invalid operator, failed to find tableScanOperator %s", id); @@ -282,7 +282,7 @@ int32_t stopTableScanOperator(SOperatorInfo* pOperator, const char* pIdStr, SSto int32_t createOperator(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond, SNode* pTagIndexCond, const char* pUser, const char* dbname, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t type = nodeType(pPhyNode); @@ -878,7 +878,7 @@ SSDataBlock* getNextBlockFromDownstreamRemain(struct SOperatorInfo* pOperator, i } int32_t optrDefaultGetNextExtFn(struct SOperatorInfo* pOperator, SOperatorParam* pParam, SSDataBlock** pRes) { - QRY_OPTR_CHECK(pRes); + QRY_PARAM_CHECK(pRes); int32_t code = setOperatorParams(pOperator, pParam, OP_GET_PARAM); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/libs/executor/src/projectoperator.c b/source/libs/executor/src/projectoperator.c index 633eda6bf9..790e97b27c 100644 --- a/source/libs/executor/src/projectoperator.c +++ b/source/libs/executor/src/projectoperator.c @@ -93,7 +93,7 @@ void streamOperatorReloadState(SOperatorInfo* pOperator) { int32_t createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhysiNode* pProjPhyNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; SProjectOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SProjectOperatorInfo)); @@ -262,7 +262,7 @@ static int32_t doIngroupLimitOffset(SLimitInfo* pLimitInfo, uint64_t groupId, SS } int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); SProjectOperatorInfo* pProjectInfo = pOperator->info; SOptrBasicInfo* pInfo = &pProjectInfo->binfo; @@ -441,7 +441,7 @@ int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { int32_t createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t lino = 0; int32_t numOfRows = 4096; @@ -572,7 +572,7 @@ SSDataBlock* doApplyIndefinitFunction1(SOperatorInfo* pOperator) { } int32_t doApplyIndefinitFunction(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); SIndefOperatorInfo* pIndefInfo = pOperator->info; SOptrBasicInfo* pInfo = &pIndefInfo->binfo; @@ -717,7 +717,7 @@ int32_t setFunctionResultOutput(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, } int32_t setRowTsColumnOutputInfo(SqlFunctionCtx* pCtx, int32_t numOfCols, SArray** pResList) { - QRY_OPTR_CHECK(pResList); + QRY_PARAM_CHECK(pResList); SArray* pList = taosArrayInit(4, sizeof(int32_t)); if (pList == NULL) { return terrno; diff --git a/source/libs/executor/src/querytask.c b/source/libs/executor/src/querytask.c index 67b05af120..cb0ebcff70 100644 --- a/source/libs/executor/src/querytask.c +++ b/source/libs/executor/src/querytask.c @@ -288,7 +288,7 @@ void buildTaskId(uint64_t taskId, uint64_t queryId, char* dst) { memcpy(p, "TID:0x", offset); offset += tintToHex(taskId, &p[offset]); - memcpy(&p[offset], "QID:0x", 7); + memcpy(&p[offset], " QID:0x", 7); offset += 7; offset += tintToHex(queryId, &p[offset]); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 3cc1d41924..42e7e4ac3b 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -67,7 +67,7 @@ typedef struct STableCountScanOperatorInfo { SArray* stbUidList; // when group by db_name and/or stable_name } STableCountScanOperatorInfo; -static bool processBlockWithProbability(const SSampleExecInfo* pInfo); +static bool processBlockWithProbability(const SSampleExecInfo* pInfo); static int32_t doTableCountScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes); bool processBlockWithProbability(const SSampleExecInfo* pInfo) { @@ -671,7 +671,8 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int STableCachedVal* pVal = taosLRUCacheValue(pCache->pTableMetaEntryCache, h); val = *pVal; - (void)taosLRUCacheRelease(pCache->pTableMetaEntryCache, h, false); + bool bRes = taosLRUCacheRelease(pCache->pTableMetaEntryCache, h, false); + qTrace("release LRU cache, res %d", bRes); } qDebug("retrieve table meta from cache:%" PRIu64 ", hit:%" PRIu64 " miss:%" PRIu64 ", %s", pCache->metaFetch, @@ -893,7 +894,10 @@ void markGroupProcessed(STableScanInfo* pInfo, uint64_t groupId) { if (pInfo->base.pTableListInfo->groupOffset) { pInfo->countState = TABLE_COUNT_STATE_PROCESSED; } else { - (void)taosHashRemove(pInfo->base.pTableListInfo->remainGroups, &groupId, sizeof(groupId)); + int32_t code = taosHashRemove(pInfo->base.pTableListInfo->remainGroups, &groupId, sizeof(groupId)); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + } } } @@ -933,13 +937,13 @@ static int32_t doTableScanImplNext(SOperatorInfo* pOperator, SSDataBlock** ppRes STableScanInfo* pTableScanInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStorageAPI* pAPI = &pTaskInfo->storageAPI; + SSDataBlock* pBlock = pTableScanInfo->pResBlock; + bool hasNext = false; + int64_t st = taosGetTimestampUs(); - SSDataBlock* pBlock = pTableScanInfo->pResBlock; - bool hasNext = false; + QRY_PARAM_CHECK(ppRes); pBlock->info.dataLoad = false; - int64_t st = taosGetTimestampUs(); - while (true) { code = pAPI->tsdReader.tsdNextDataBlock(pTableScanInfo->base.dataReader, &hasNext); if (code != TSDB_CODE_SUCCESS) { @@ -953,7 +957,7 @@ static int32_t doTableScanImplNext(SOperatorInfo* pOperator, SSDataBlock** ppRes if (isTaskKilled(pTaskInfo)) { pAPI->tsdReader.tsdReaderReleaseDataBlock(pTableScanInfo->base.dataReader); - T_LONG_JMP(pTaskInfo->env, pTaskInfo->code); + return pTaskInfo->code; } if (pOperator->status == OP_EXEC_DONE) { @@ -989,6 +993,7 @@ static int32_t doTableScanImplNext(SOperatorInfo* pOperator, SSDataBlock** ppRes pOperator->cost.totalCost = pTableScanInfo->base.readRecorder.elapsedTime; pBlock->info.scanFlag = pTableScanInfo->base.scanFlag; + (*ppRes) = pBlock; return code; } @@ -997,9 +1002,7 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); } - (*ppRes) = NULL; return code; } @@ -1010,7 +1013,7 @@ static int32_t doGroupedTableScan(SOperatorInfo* pOperator, SSDataBlock** pBlock SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStorageAPI* pAPI = &pTaskInfo->storageAPI; - QRY_OPTR_CHECK(pBlock); + QRY_PARAM_CHECK(pBlock); // The read handle is not initialized yet, since no qualified tables exists if (pTableScanInfo->base.dataReader == NULL || pOperator->status == OP_EXEC_DONE) { @@ -1190,7 +1193,7 @@ static int32_t startNextGroupScan(SOperatorInfo* pOperator, SSDataBlock** pResul SStorageAPI* pAPI = &pTaskInfo->storageAPI; int32_t numOfTables = 0; - QRY_OPTR_CHECK(pResult); + QRY_PARAM_CHECK(pResult); code = tableListGetSize(pInfo->base.pTableListInfo, &numOfTables); QUERY_CHECK_CODE(code, lino, _end); @@ -1238,7 +1241,7 @@ _end: return code; } -static SSDataBlock* groupSeqTableScan(SOperatorInfo* pOperator) { +static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; STableScanInfo* pInfo = pOperator->info; @@ -1246,12 +1249,14 @@ static SSDataBlock* groupSeqTableScan(SOperatorInfo* pOperator) { SStorageAPI* pAPI = &pTaskInfo->storageAPI; int32_t num = 0; STableKeyInfo* pList = NULL; - SSDataBlock* result = NULL; + SSDataBlock* pResult = NULL; + + QRY_PARAM_CHECK(pResBlock); if (pInfo->currentGroupId == -1) { if ((++pInfo->currentGroupId) >= tableListGetOutputGroups(pInfo->base.pTableListInfo)) { setOperatorCompleted(pOperator); - return NULL; + return code; } taosRLockLatch(&pTaskInfo->lock); @@ -1269,28 +1274,32 @@ static SSDataBlock* groupSeqTableScan(SOperatorInfo* pOperator) { if (pInfo->filesetDelimited) { pAPI->tsdReader.tsdSetFilesetDelimited(pInfo->base.dataReader); } + if (pInfo->pResBlock->info.capacity > pOperator->resultInfo.capacity) { pOperator->resultInfo.capacity = pInfo->pResBlock->info.capacity; } } - result = NULL; - code = doGroupedTableScan(pOperator, &result); + pResult = NULL; + code = doGroupedTableScan(pOperator, &pResult); QUERY_CHECK_CODE(code, lino, _end); - if (result != NULL) { + if (pResult != NULL) { if (pOperator->dynamicTask) { - result->info.id.groupId = result->info.id.uid; + pResult->info.id.groupId = pResult->info.id.uid; } - return result; + + *pResBlock = pResult; + return code; } while (true) { - code = startNextGroupScan(pOperator, &result); + code = startNextGroupScan(pOperator, &pResult); QUERY_CHECK_CODE(code, lino, _end); - if (result || pOperator->status == OP_EXEC_DONE) { - return result; + if (pResult || pOperator->status == OP_EXEC_DONE) { + *pResBlock = pResult; + return code; } } @@ -1298,9 +1307,9 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); } - return result; + + return code; } static int32_t doTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { @@ -1309,7 +1318,7 @@ static int32_t doTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { STableScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStorageAPI* pAPI = &pTaskInfo->storageAPI; - QRY_OPTR_CHECK(ppRes); + QRY_PARAM_CHECK(ppRes); if (pOperator->pOperatorGetParam) { pOperator->dynamicTask = true; @@ -1390,8 +1399,7 @@ static int32_t doTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { pInfo->scanTimes = 0; } } else { // scan table group by group sequentially - (*ppRes) = groupSeqTableScan(pOperator); - return code; + code = groupSeqTableScan(pOperator, ppRes); } _end: @@ -1443,7 +1451,7 @@ static void destroyTableScanOperatorInfo(void* param) { int32_t createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -1543,7 +1551,7 @@ _error: } int32_t createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); @@ -3700,7 +3708,7 @@ static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { if (pInfo->dataReader && hasNext) { if (isTaskKilled(pTaskInfo)) { pAPI->tsdReader.tsdReaderReleaseDataBlock(pInfo->dataReader); - T_LONG_JMP(pTaskInfo->env, pTaskInfo->code); + return code; } SSDataBlock* pBlock = NULL; @@ -3802,6 +3810,7 @@ static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { QUERY_CHECK_NULL(tmp, code, lino, _end, terrno); } } + (*ppRes) = NULL; return code; } @@ -3810,8 +3819,8 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); } + (*ppRes) = NULL; return code; } @@ -3833,7 +3842,7 @@ int32_t createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pTaskInfo // create meta reader // create tq reader - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -4025,7 +4034,7 @@ _end: int32_t createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SNode* pTagCond, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -4258,7 +4267,7 @@ _error: return code; } -static void doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pRes, int32_t count, SMetaReader* mr, +static int32_t doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pRes, int32_t count, SMetaReader* mr, SStorageAPI* pAPI) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -4272,7 +4281,7 @@ static void doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pRes, GET_TASKID(pTaskInfo)); tDecoderClear(&(*mr).coder); pAPI->metaReaderFn.clearReader(mr); - T_LONG_JMP(pTaskInfo->env, terrno); + goto _end; } code = pAPI->metaReaderFn.getTableEntryByUid(mr, item->uid); @@ -4281,7 +4290,7 @@ static void doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pRes, qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", item->uid, tstrerror(terrno), GET_TASKID(pTaskInfo)); pAPI->metaReaderFn.clearReader(mr); - T_LONG_JMP(pTaskInfo->env, terrno); + goto _end; } char str[512]; @@ -4310,12 +4319,13 @@ static void doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pRes, } else { data = (char*)p; } + code = colDataSetVal(pDst, (count), data, (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))); QUERY_CHECK_CODE(code, lino, _end); - if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) && - data != NULL) { + if ((pDst->info.type != TSDB_DATA_TYPE_JSON) && (p != NULL) && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) && + (data != NULL)) { taosMemoryFree(data); } } @@ -4325,8 +4335,9 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); } + + return code; } static void tagScanFreeUidTag(void* p) { @@ -4529,6 +4540,7 @@ static int32_t tagScanFillResultBlock(SOperatorInfo* pOperator, SSDataBlock* pRe SColumnInfoData* pDst = taosArrayGet(pRes->pDataBlock, pExprInfo[j].base.resSchema.slotId); QUERY_CHECK_NULL(pDst, code, lino, _end, terrno); code = tagScanFillOneCellWithTag(pOperator, pUidTagInfo, &pExprInfo[j], pDst, i, pAPI, pInfo->readHandle.vnode); + QUERY_CHECK_CODE(code, lino, _end); } } } else { @@ -4540,6 +4552,7 @@ static int32_t tagScanFillResultBlock(SOperatorInfo* pOperator, SSDataBlock* pRe SColumnInfoData* pDst = taosArrayGet(pRes->pDataBlock, pExprInfo[j].base.resSchema.slotId); QUERY_CHECK_NULL(pDst, code, lino, _end, terrno); code = tagScanFillOneCellWithTag(pOperator, pUidTagInfo, &pExprInfo[j], pDst, i, pAPI, pInfo->readHandle.vnode); + QUERY_CHECK_CODE(code, lino, _end); } } } @@ -4552,10 +4565,6 @@ _end: } static int32_t doTagScanFromCtbIdxNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { - if (pOperator->status == OP_EXEC_DONE) { - (*ppRes) = NULL; - return TSDB_CODE_SUCCESS; - } int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; @@ -4563,6 +4572,12 @@ static int32_t doTagScanFromCtbIdxNext(SOperatorInfo* pOperator, SSDataBlock** p STagScanInfo* pInfo = pOperator->info; SSDataBlock* pRes = pInfo->pRes; + + QRY_PARAM_CHECK(ppRes); + + if (pOperator->status == OP_EXEC_DONE) { + return TSDB_CODE_SUCCESS; + } blockDataCleanup(pRes); if (pInfo->pCtbCursor == NULL) { @@ -4629,28 +4644,23 @@ static int32_t doTagScanFromCtbIdxNext(SOperatorInfo* pOperator, SSDataBlock** p pInfo->pCtbCursor = NULL; setOperatorCompleted(pOperator); } - pRes->info.rows = count; + pRes->info.rows = count; bool bLimitReached = applyLimitOffset(&pInfo->limitInfo, pRes, pTaskInfo); if (bLimitReached) { setOperatorCompleted(pOperator); } + pOperator->resultInfo.totalRows += pRes->info.rows; + (*ppRes) = (pRes->info.rows == 0) ? NULL : pInfo->pRes; + _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); } - pOperator->resultInfo.totalRows += pRes->info.rows; - (*ppRes) = (pRes->info.rows == 0) ? NULL : pInfo->pRes; - return code; -} -static SSDataBlock* doTagScanFromCtbIdx(SOperatorInfo* pOperator) { - SSDataBlock* pRes = NULL; - int32_t code = doTagScanFromCtbIdxNext(pOperator, &pRes); - return pRes; + return code; } static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { @@ -4681,18 +4691,18 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock* return code; } - char str[512] = {0}; int32_t count = 0; SMetaReader mr = {0}; pAPI->metaReaderFn.initReader(&mr, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn); while (pInfo->curPos < size && count < pOperator->resultInfo.capacity) { - doTagScanOneTable(pOperator, pRes, count, &mr, &pTaskInfo->storageAPI); + code = doTagScanOneTable(pOperator, pRes, count, &mr, &pTaskInfo->storageAPI); ++count; if (++pInfo->curPos >= size) { setOperatorCompleted(pOperator); } } + pRes->info.rows = count; pAPI->metaReaderFn.clearReader(&mr); @@ -4700,6 +4710,7 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock* if (bLimitReached) { setOperatorCompleted(pOperator); } + // qDebug("QInfo:0x%"PRIx64" create tag values results completed, rows:%d", GET_TASKID(pRuntimeEnv), count); if (pOperator->status == OP_EXEC_DONE) { setTaskStatus(pTaskInfo, TASK_COMPLETED); @@ -4739,7 +4750,7 @@ static void destroyTagScanOperatorInfo(void* param) { int32_t createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pTagScanNode, STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -4907,7 +4918,7 @@ static int32_t fetchNextSubTableBlockFromReader(SOperatorInfo* pOperator, STmsSu code = pAPI->tsdReader.tsdReaderOpen(pHandle->vnode, &pInput->tblCond, pInput->pKeyInfo, 1, pInput->pReaderBlock, (void**)&pInput->pReader, GET_TASKID(pTaskInfo), NULL); if (code != 0) { - T_LONG_JMP(pTaskInfo->env, code); + return code; } } @@ -4915,18 +4926,20 @@ static int32_t fetchNextSubTableBlockFromReader(SOperatorInfo* pOperator, STmsSu while (true) { bool hasNext = false; - int32_t code = pAPI->tsdReader.tsdNextDataBlock(pInfo->base.dataReader, &hasNext); + code = pAPI->tsdReader.tsdNextDataBlock(pInfo->base.dataReader, &hasNext); if (code != 0) { pAPI->tsdReader.tsdReaderReleaseDataBlock(pInfo->base.dataReader); pInfo->base.dataReader = NULL; - T_LONG_JMP(pTaskInfo->env, code); + return code; } + if (!hasNext || isTaskKilled(pTaskInfo)) { if (isTaskKilled(pTaskInfo)) { pAPI->tsdReader.tsdReaderReleaseDataBlock(pInfo->base.dataReader); pInfo->base.dataReader = NULL; - T_LONG_JMP(pTaskInfo->env, pTaskInfo->code); + return code; } + *pSubTableHasBlock = false; break; } @@ -4941,8 +4954,9 @@ static int32_t fetchNextSubTableBlockFromReader(SOperatorInfo* pOperator, STmsSu code = loadDataBlock(pOperator, &pInfo->base, pInput->pReaderBlock, &status); if (code != 0) { pInfo->base.dataReader = NULL; - T_LONG_JMP(pTaskInfo->env, code); + return code; } + if (status == FUNC_DATA_REQUIRED_ALL_FILTEROUT) { *pSubTableHasBlock = false; break; @@ -5209,49 +5223,56 @@ _end: return code; } -static SSDataBlock* getSubTablesSortedBlock(SOperatorInfo* pOperator, SSDataBlock* pResBlock, int32_t capacity) { +static int32_t getSubTablesSortedBlock(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t capacity, SSDataBlock** pResBlock) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; STableMergeScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STmsSubTablesMergeInfo* pSubTblsInfo = pInfo->pSubTablesMergeInfo; + bool finished = false; + + QRY_PARAM_CHECK(pResBlock); + + blockDataCleanup(pBlock); - blockDataCleanup(pResBlock); - bool finished = false; while (true) { - while (1) { + while (true) { if (pSubTblsInfo->numSubTablesCompleted >= pSubTblsInfo->numSubTables) { finished = true; break; } - code = appendChosenRowToDataBlock(pSubTblsInfo, pResBlock); + code = appendChosenRowToDataBlock(pSubTblsInfo, pBlock); QUERY_CHECK_CODE(code, lino, _end); + code = adjustSubTableForNextRow(pOperator, pSubTblsInfo); QUERY_CHECK_CODE(code, lino, _end); - if (pResBlock->info.rows >= capacity) { + if (pBlock->info.rows >= capacity) { break; } } if (isTaskKilled(pTaskInfo)) { - T_LONG_JMP(pOperator->pTaskInfo->env, pTaskInfo->code); + return pTaskInfo->code; } - bool limitReached = applyLimitOffset(&pInfo->limitInfo, pResBlock, pTaskInfo); - if (finished || limitReached || pResBlock->info.rows > 0) { + bool limitReached = applyLimitOffset(&pInfo->limitInfo, pBlock, pTaskInfo); + if (finished || limitReached || pBlock->info.rows > 0) { break; } } + if (pBlock->info.rows > 0) { + *pResBlock = pBlock; + } + _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); } - return (pResBlock->info.rows > 0) ? pResBlock : NULL; + return code; } static int32_t startSubTablesTableMergeScan(SOperatorInfo* pOperator) { @@ -5301,23 +5322,22 @@ static void stopSubTablesTableMergeScan(STableMergeScanInfo* pInfo) { } int32_t doTableMergeScanParaSubTablesNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { - if (pOperator->status == OP_EXEC_DONE) { - (*ppRes) = NULL; - return TSDB_CODE_SUCCESS; - } + QRY_PARAM_CHECK(ppRes); + + int32_t lino = 0; + int32_t tableListSize = 0; + int64_t st = taosGetTimestampUs(); SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STableMergeScanInfo* pInfo = pOperator->info; - int32_t lino = 0; - int32_t code = pOperator->fpSet._openFn(pOperator); - if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); + if (pOperator->status == OP_EXEC_DONE) { + return TSDB_CODE_SUCCESS; } - int64_t st = taosGetTimestampUs(); + int32_t code = pOperator->fpSet._openFn(pOperator); + QUERY_CHECK_CODE(code, lino, _end); - int32_t tableListSize = 0; code = tableListGetSize(pInfo->base.pTableListInfo, &tableListSize); QUERY_CHECK_CODE(code, lino, _end); @@ -5329,6 +5349,7 @@ int32_t doTableMergeScanParaSubTablesNext(SOperatorInfo* pOperator, SSDataBlock* (*ppRes) = NULL; return code; } + pInfo->tableStartIndex = 0; STableKeyInfo* pTmpGpId = (STableKeyInfo*)tableListGetInfo(pInfo->base.pTableListInfo, pInfo->tableStartIndex); QUERY_CHECK_NULL(pTmpGpId, code, lino, _end, terrno); @@ -5340,15 +5361,19 @@ int32_t doTableMergeScanParaSubTablesNext(SOperatorInfo* pOperator, SSDataBlock* SSDataBlock* pBlock = NULL; while (pInfo->tableStartIndex < tableListSize) { if (isTaskKilled(pTaskInfo)) { - T_LONG_JMP(pTaskInfo->env, pTaskInfo->code); + break; } - pBlock = getSubTablesSortedBlock(pOperator, pInfo->pResBlock, pOperator->resultInfo.capacity); + code = getSubTablesSortedBlock(pOperator, pInfo->pResBlock, pOperator->resultInfo.capacity, &pBlock); + QUERY_CHECK_CODE(code, lino, _end); + if (pBlock == NULL && !pInfo->bGroupProcessed && pInfo->needCountEmptyTable) { STableKeyInfo* tbInfo = tableListGetInfo(pInfo->base.pTableListInfo, pInfo->tableStartIndex); QUERY_CHECK_NULL(tbInfo, code, lino, _end, terrno); + pBlock = getOneRowResultBlock(pTaskInfo, &pInfo->base, pInfo->pResBlock, tbInfo); } + if (pBlock != NULL) { pBlock->info.id.groupId = pInfo->groupId; pOperator->resultInfo.totalRows += pBlock->info.rows; @@ -5379,16 +5404,11 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); + } else { + (*ppRes) = pBlock; } - (*ppRes) = pBlock; - return code; -} -static SSDataBlock* doTableMergeScanParaSubTables(SOperatorInfo* pOperator) { - SSDataBlock* pRes = NULL; - int32_t code = doTableMergeScanParaSubTablesNext(pOperator, &pRes); - return pRes; + return code; } static void tableMergeScanDoSkipTable(uint64_t uid, void* pTableMergeOpInfo) { @@ -5420,7 +5440,7 @@ _end: } } -static void doGetBlockForTableMergeScan(SOperatorInfo* pOperator, bool* pFinished, bool* pSkipped) { +static int32_t doGetBlockForTableMergeScan(SOperatorInfo* pOperator, bool* pFinished, bool* pSkipped) { STableMergeScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStorageAPI* pAPI = &pTaskInfo->storageAPI; @@ -5433,7 +5453,8 @@ static void doGetBlockForTableMergeScan(SOperatorInfo* pOperator, bool* pFinishe if (code != 0) { pAPI->tsdReader.tsdReaderReleaseDataBlock(reader); qError("table merge scan fetch next data block error code: %d, %s", code, GET_TASKID(pTaskInfo)); - T_LONG_JMP(pTaskInfo->env, code); + pTaskInfo->code = code; + return code; } if (!hasNext || isTaskKilled(pTaskInfo)) { @@ -5442,7 +5463,7 @@ static void doGetBlockForTableMergeScan(SOperatorInfo* pOperator, bool* pFinishe pAPI->tsdReader.tsdReaderReleaseDataBlock(reader); } *pFinished = true; - return; + return code; } uint32_t status = 0; @@ -5450,21 +5471,22 @@ static void doGetBlockForTableMergeScan(SOperatorInfo* pOperator, bool* pFinishe if (code != TSDB_CODE_SUCCESS) { qInfo("table merge scan load datablock code %d, %s", code, GET_TASKID(pTaskInfo)); - T_LONG_JMP(pTaskInfo->env, code); + pTaskInfo->code = code; + return code; } if (status == FUNC_DATA_REQUIRED_ALL_FILTEROUT) { *pFinished = true; - return; + return code; } // current block is filter out according to filter condition, continue load the next block if (status == FUNC_DATA_REQUIRED_FILTEROUT || pBlock->info.rows == 0) { *pSkipped = true; - return; + return code; } - return; + return code; } static int32_t getBlockForTableMergeScan(void* param, SSDataBlock** ppBlock) { @@ -5475,7 +5497,7 @@ static int32_t getBlockForTableMergeScan(void* param, SSDataBlock** ppBlock) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SSDataBlock* pBlock = NULL; int64_t st = taosGetTimestampUs(); - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; while (true) { if (pInfo->rtnNextDurationBlocks) { @@ -5499,7 +5521,12 @@ static int32_t getBlockForTableMergeScan(void* param, SSDataBlock** ppBlock) { } else { bool bFinished = false; bool bSkipped = false; - doGetBlockForTableMergeScan(pOperator, &bFinished, &bSkipped); + + code = doGetBlockForTableMergeScan(pOperator, &bFinished, &bSkipped); + if (code != 0) { + return code; + } + pBlock = pInfo->pReaderBlock; qDebug("%s table merge scan fetch block. finished %d skipped %d next-duration-block %d new-fileset %d", GET_TASKID(pTaskInfo), bFinished, bSkipped, pInfo->bNextDurationBlockEvent, pInfo->bNewFilesetEvent); @@ -5512,7 +5539,6 @@ static int32_t getBlockForTableMergeScan(void* param, SSDataBlock** ppBlock) { if (!bSkipped) { code = createOneDataBlock(pBlock, true, &pInfo->nextDurationBlocks[pInfo->numNextDurationBlocks]); if (code) { - terrno = code; *ppBlock = NULL; return code; } @@ -5651,7 +5677,11 @@ int32_t startDurationForGroupTableMergeScan(SOperatorInfo* pOperator) { param->pOperator = pOperator; SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); - QUERY_CHECK_NULL(ps, code, lino, _end, terrno); + if (ps == NULL) { + taosMemoryFree(param); + QUERY_CHECK_NULL(ps, code, lino, _end, terrno); + } + ps->param = param; ps->onlyRef = false; code = tsortAddSource(pInfo->pSortHandle, ps); @@ -5846,7 +5876,7 @@ int32_t doTableMergeScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { SSDataBlock* pBlock = NULL; while (pInfo->tableStartIndex < tableListSize) { if (isTaskKilled(pTaskInfo)) { - T_LONG_JMP(pTaskInfo->env, pTaskInfo->code); + goto _end; } pBlock = getSortedTableMergeScanBlockData(pInfo->pSortHandle, pInfo->pResBlock, pOperator->resultInfo.capacity, @@ -5890,9 +5920,10 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); + } else { + (*ppRes) = pBlock; } - (*ppRes) = pBlock; + return code; } @@ -5965,7 +5996,7 @@ int32_t getTableMergeScanExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExpla int32_t createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -6100,11 +6131,11 @@ static int32_t buildVnodeGroupedStbTableCount(STableCountScanOperatorInfo* SSDataBlock* pRes, char* dbName, tb_uid_t stbUid, SStorageAPI* pAPI); static int32_t buildVnodeGroupedNtbTableCount(STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, SSDataBlock* pRes, char* dbName, SStorageAPI* pAPI); -static void buildVnodeFilteredTbCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, +static int32_t buildVnodeFilteredTbCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, SSDataBlock* pRes, char* dbName); -static void buildVnodeGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, +static int32_t buildVnodeGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, SSDataBlock* pRes, int32_t vgId, char* dbName); -static SSDataBlock* buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, +static int32_t buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, SSDataBlock* pRes); static void buildSysDbGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, SSDataBlock* pRes, size_t infodbTableNum, @@ -6207,7 +6238,7 @@ int32_t getTableCountScanSupp(SNodeList* groupTags, SName* tableName, SNodeList* int32_t createTableCountScanOperatorInfo(SReadHandle* readHandle, STableCountScanPhysiNode* pTblCountScanNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -6390,23 +6421,29 @@ static int32_t doTableCountScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRe STableCountScanOperatorInfo* pInfo = pOperator->info; STableCountScanSupp* pSupp = &pInfo->supp; SSDataBlock* pRes = pInfo->pRes; + blockDataCleanup(pRes); + QRY_PARAM_CHECK(ppRes); if (pOperator->status == OP_EXEC_DONE) { - (*ppRes) = NULL; return code; } + if (pInfo->readHandle.mnd != NULL) { (*ppRes) = buildSysDbTableCount(pOperator, pInfo); return code; } - (*ppRes) = buildVnodeDbTableCount(pOperator, pInfo, pSupp, pRes); + code = buildVnodeDbTableCount(pOperator, pInfo, pSupp, pRes); + if ((pRes->info.rows > 0) && (code == 0)) { + *ppRes = pRes; + } + return code; } -static SSDataBlock* buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, - STableCountScanSupp* pSupp, SSDataBlock* pRes) { +static int32_t buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, + STableCountScanSupp* pSupp, SSDataBlock* pRes) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; const char* db = NULL; @@ -6418,27 +6455,29 @@ static SSDataBlock* buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCount // get dbname pAPI->metaFn.getBasicInfo(pInfo->readHandle.vnode, &db, &vgId, NULL, NULL); SName sn = {0}; + code = tNameFromString(&sn, db, T_NAME_ACCT | T_NAME_DB); QUERY_CHECK_CODE(code, lino, _end); + code = tNameGetDbName(&sn, dbName); QUERY_CHECK_CODE(code, lino, _end); if (pSupp->groupByDbName || pSupp->groupByStbName) { - buildVnodeGroupedTableCount(pOperator, pInfo, pSupp, pRes, vgId, dbName); + code = buildVnodeGroupedTableCount(pOperator, pInfo, pSupp, pRes, vgId, dbName); } else { - buildVnodeFilteredTbCount(pOperator, pInfo, pSupp, pRes, dbName); + code = buildVnodeFilteredTbCount(pOperator, pInfo, pSupp, pRes, dbName); } _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); } - return pRes->info.rows > 0 ? pRes : NULL; + + return code; } -static void buildVnodeGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, +static int32_t buildVnodeGroupedTableCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, SSDataBlock* pRes, int32_t vgId, char* dbName) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -6452,6 +6491,7 @@ static void buildVnodeGroupedTableCount(SOperatorInfo* pOperator, STableCountSca code = pAPI->metaFn.storeGetTableList(pInfo->readHandle.vnode, TSDB_SUPER_TABLE, pInfo->stbUidList); QUERY_CHECK_CODE(code, lino, _end); } + if (pInfo->currGrpIdx < taosArrayGetSize(pInfo->stbUidList)) { tb_uid_t stbUid = *(tb_uid_t*)taosArrayGet(pInfo->stbUidList, pInfo->currGrpIdx); code = buildVnodeGroupedStbTableCount(pInfo, pSupp, pRes, dbName, stbUid, pAPI); @@ -6481,11 +6521,11 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; - T_LONG_JMP(pTaskInfo->env, code); } + return code; } -static void buildVnodeFilteredTbCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, +static int32_t buildVnodeFilteredTbCount(SOperatorInfo* pOperator, STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, SSDataBlock* pRes, char* dbName) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -6521,9 +6561,10 @@ _end: if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); - T_LONG_JMP(pTaskInfo->env, code); } + setOperatorCompleted(pOperator); + return code; } static int32_t buildVnodeGroupedNtbTableCount(STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp, diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index bb494cacfa..9b659ac761 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -55,7 +55,7 @@ static void destroySortOpGroupIdCalc(SSortOpGroupIdCalc* pCalc); // todo add limit/offset impl int32_t createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t lino = 0; @@ -252,7 +252,7 @@ static STupleHandle* nextTupleWithGroupId(SSortHandle* pHandle, SSortOperatorInf static int32_t getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo, SSortOperatorInfo* pInfo, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); blockDataCleanup(pDataBlock); int32_t lino = 0; int32_t code = 0; @@ -355,25 +355,26 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) { pInfo->startTs = taosGetTimestampUs(); // pInfo->binfo.pRes is not equalled to the input datablock. pInfo->pSortHandle = NULL; - int32_t code = tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, -1, -1, NULL, pTaskInfo->id.str, - pInfo->maxRows, pInfo->maxTupleLength, tsPQSortMemThreshold * 1024 * 1024, &pInfo->pSortHandle); + int32_t code = + tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, -1, -1, NULL, pTaskInfo->id.str, pInfo->maxRows, + pInfo->maxTupleLength, tsPQSortMemThreshold * 1024 * 1024, &pInfo->pSortHandle); if (code) { return code; } tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, applyScalarFunction, pOperator); - SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); - if (ps == NULL) { + SSortSource* pSource = taosMemoryCalloc(1, sizeof(SSortSource)); + if (pSource == NULL) { return terrno; } - ps->param = pOperator->pDownstream[0]; - ps->onlyRef = true; + pSource->param = pOperator->pDownstream[0]; + pSource->onlyRef = true; - code = tsortAddSource(pInfo->pSortHandle, ps); + code = tsortAddSource(pInfo->pSortHandle, pSource); if (code) { - taosMemoryFree(ps); + taosMemoryFree(pSource); return code; } @@ -390,7 +391,7 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) { } int32_t doSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); if (pOperator->status == OP_EXEC_DONE) { return 0; } @@ -400,7 +401,7 @@ int32_t doSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { int32_t code = pOperator->fpSet._openFn(pOperator); if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); + return code; } // multi-group case not handle here @@ -408,7 +409,7 @@ int32_t doSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { while (1) { if (tsortIsClosed(pInfo->pSortHandle)) { code = TSDB_CODE_TSC_QUERY_CANCELLED; - T_LONG_JMP(pOperator->pTaskInfo->env, code); + T_LONG_JMP(pTaskInfo->env, code); } code = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, @@ -516,7 +517,7 @@ typedef struct SGroupSortOperatorInfo { int32_t getGroupSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo, SGroupSortOperatorInfo* pInfo, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); blockDataCleanup(pDataBlock); int32_t code = blockDataEnsureCapacity(pDataBlock, capacity); @@ -598,7 +599,7 @@ int32_t fetchNextGroupSortDataBlock(void* param, SSDataBlock** ppBlock) { SGroupSortOperatorInfo* grpSortOpInfo = source->grpSortOpInfo; SSDataBlock* block = NULL; - QRY_OPTR_CHECK(ppBlock); + QRY_PARAM_CHECK(ppBlock); if (grpSortOpInfo->prefetchedSortInput) { block = grpSortOpInfo->prefetchedSortInput; @@ -648,23 +649,22 @@ int32_t beginSortGroup(SOperatorInfo* pOperator) { SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); SGroupSortSourceParam* param = taosMemoryCalloc(1, sizeof(SGroupSortSourceParam)); if (ps == NULL || param == NULL) { - T_LONG_JMP(pTaskInfo->env, terrno); + taosMemoryFree(ps); + taosMemoryFree(param); + return terrno; } param->childOpInfo = pOperator->pDownstream[0]; param->grpSortOpInfo = pInfo; + ps->param = param; ps->onlyRef = false; code = tsortAddSource(pInfo->pCurrSortHandle, ps); - if (code) { - T_LONG_JMP(pTaskInfo->env, code); + if (code != 0) { + return code; } code = tsortOpen(pInfo->pCurrSortHandle); - if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); - } - return code; } @@ -686,7 +686,7 @@ int32_t finishSortGroup(SOperatorInfo* pOperator) { } int32_t doGroupSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { - QRY_OPTR_CHECK(pResBlock); + QRY_PARAM_CHECK(pResBlock); SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SGroupSortOperatorInfo* pInfo = pOperator->info; @@ -696,7 +696,7 @@ int32_t doGroupSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { int32_t code = pOperator->fpSet._openFn(pOperator); if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); + return code; } if (!pInfo->hasGroupId) { @@ -720,15 +720,14 @@ int32_t doGroupSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { while (pInfo->pCurrSortHandle != NULL) { if (tsortIsClosed(pInfo->pCurrSortHandle)) { code = TSDB_CODE_TSC_QUERY_CANCELLED; - T_LONG_JMP(pOperator->pTaskInfo->env, code); + T_LONG_JMP(pTaskInfo->env, code); } // beginSortGroup would fetch all child blocks of pInfo->currGroupId; if (pInfo->childOpStatus == CHILD_OP_SAME_GROUP) { - code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; - pOperator->pTaskInfo->code = code; + pTaskInfo->code = code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); - T_LONG_JMP(pOperator->pTaskInfo->env, code); + return code; } code = getGroupSortedBlockData(pInfo->pCurrSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, @@ -777,7 +776,7 @@ void destroyGroupSortOperatorInfo(void* param) { int32_t createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSortPhysiNode* pSortPhyNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t lino = 0; diff --git a/source/libs/executor/src/streamcountwindowoperator.c b/source/libs/executor/src/streamcountwindowoperator.c index b086b41611..524ef6ee2f 100644 --- a/source/libs/executor/src/streamcountwindowoperator.c +++ b/source/libs/executor/src/streamcountwindowoperator.c @@ -807,7 +807,7 @@ _end: int32_t createStreamCountAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); SCountWinodwPhysiNode* pCountNode = (SCountWinodwPhysiNode*)pPhyNode; int32_t numOfCols = 0; diff --git a/source/libs/executor/src/streameventwindowoperator.c b/source/libs/executor/src/streameventwindowoperator.c index 70f88fc37f..735b470325 100644 --- a/source/libs/executor/src/streameventwindowoperator.c +++ b/source/libs/executor/src/streameventwindowoperator.c @@ -858,7 +858,7 @@ _end: int32_t createStreamEventAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); SStreamEventWinodwPhysiNode* pEventNode = (SStreamEventWinodwPhysiNode*)pPhyNode; int32_t tsSlotId = ((SColumnNode*)pEventNode->window.pTspk)->slotId; diff --git a/source/libs/executor/src/streamfilloperator.c b/source/libs/executor/src/streamfilloperator.c index d87e78ede3..58e57eb88b 100644 --- a/source/libs/executor/src/streamfilloperator.c +++ b/source/libs/executor/src/streamfilloperator.c @@ -1349,7 +1349,7 @@ _end: int32_t createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFillPhysiNode* pPhyFillNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; diff --git a/source/libs/executor/src/streamtimewindowoperator.c b/source/libs/executor/src/streamtimewindowoperator.c index 0036618d9f..6196647eff 100644 --- a/source/libs/executor/src/streamtimewindowoperator.c +++ b/source/libs/executor/src/streamtimewindowoperator.c @@ -718,6 +718,11 @@ static void doBuildPullDataBlock(SArray* array, int32_t* pIndex, SSDataBlock* pB SColumnInfoData* pGroupId = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX); SColumnInfoData* pCalStartTs = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, CALCULATE_START_TS_COLUMN_INDEX); SColumnInfoData* pCalEndTs = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX); + SColumnInfoData* pTbName = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, TABLE_NAME_COLUMN_INDEX); + SColumnInfoData* pPrimaryKey = NULL; + if (taosArrayGetSize(pBlock->pDataBlock) > PRIMARY_KEY_COLUMN_INDEX) { + pPrimaryKey = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, PRIMARY_KEY_COLUMN_INDEX); + } for (; (*pIndex) < size; (*pIndex)++) { SPullWindowInfo* pWin = taosArrayGet(array, (*pIndex)); code = colDataSetVal(pStartTs, pBlock->info.rows, (const char*)&pWin->window.skey, false); @@ -735,6 +740,11 @@ static void doBuildPullDataBlock(SArray* array, int32_t* pIndex, SSDataBlock* pB code = colDataSetVal(pCalEndTs, pBlock->info.rows, (const char*)&pWin->calWin.ekey, false); QUERY_CHECK_CODE(code, lino, _end); + colDataSetNULL(pTbName, pBlock->info.rows); + if (pPrimaryKey != NULL) { + colDataSetNULL(pPrimaryKey, pBlock->info.rows); + } + pBlock->info.rows++; } if ((*pIndex) == size) { @@ -1876,7 +1886,7 @@ _end: int32_t createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, int32_t numOfChild, SReadHandle* pHandle, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -3744,7 +3754,7 @@ _end: int32_t createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode; int32_t numOfCols = 0; @@ -4071,7 +4081,7 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) { int32_t createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, int32_t numOfChild, SReadHandle* pHandle, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -4921,7 +4931,7 @@ _end: int32_t createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t lino = 0; @@ -5238,7 +5248,7 @@ _end: int32_t createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 85a8b035da..bf1153f412 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -2177,7 +2177,12 @@ static SSDataBlock* sysTableScanFromMNode(SOperatorInfo* pOperator, SSysTableSca T_LONG_JMP(pTaskInfo->env, code); } - (void)tsem_wait(&pInfo->ready); + code = tsem_wait(&pInfo->ready); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } if (pTaskInfo->code) { qError("%s load meta data from mnode failed, totalRows:%" PRIu64 ", code:%s", GET_TASKID(pTaskInfo), @@ -2228,7 +2233,7 @@ static SSDataBlock* sysTableScanFromMNode(SOperatorInfo* pOperator, SSysTableSca int32_t createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode, const char* pUser, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -2327,7 +2332,10 @@ void extractTbnameSlotId(SSysTableScanInfo* pInfo, const SScanPhysiNode* pScanNo void destroySysScanOperator(void* param) { SSysTableScanInfo* pInfo = (SSysTableScanInfo*)param; - (void)tsem_destroy(&pInfo->ready); + int32_t code = tsem_destroy(&pInfo->ready); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + } blockDataDestroy(pInfo->pRes); if (pInfo->name.type == TSDB_TABLE_NAME_T) { @@ -2383,7 +2391,10 @@ int32_t loadSysTableCallback(void* param, SDataBuf* pMsg, int32_t code) { } } - (void)tsem_post(&pScanResInfo->ready); + int32_t res = tsem_post(&pScanResInfo->ready); + if (res != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(res)); + } return TSDB_CODE_SUCCESS; } @@ -2853,7 +2864,7 @@ static int32_t initTableblockDistQueryCond(uint64_t uid, SQueryTableDataCond* pC int32_t createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanPhysiNode* pBlockScanNode, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t lino = 0; diff --git a/source/libs/executor/src/timesliceoperator.c b/source/libs/executor/src/timesliceoperator.c index 32a769ade3..f9211e5730 100644 --- a/source/libs/executor/src/timesliceoperator.c +++ b/source/libs/executor/src/timesliceoperator.c @@ -1104,7 +1104,7 @@ static int32_t extractPkColumnFromFuncs(SNodeList* pFuncs, bool* pHasPk, SColumn } int32_t createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = 0; int32_t lino = 0; diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index fc91877b66..59883d2b80 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1231,7 +1231,7 @@ void destroyIntervalOperatorInfo(void* param) { cleanupAggSup(&pInfo->aggSup); cleanupExprSupp(&pInfo->scalarSupp); - (void)tdListFree(pInfo->binfo.resultRowInfo.openWindow); + pInfo->binfo.resultRowInfo.openWindow = tdListFree(pInfo->binfo.resultRowInfo.openWindow); taosArrayDestroy(pInfo->pInterpCols); pInfo->pInterpCols = NULL; @@ -1320,7 +1320,7 @@ _end: int32_t createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -1616,7 +1616,7 @@ _end: // todo make this as an non-blocking operator int32_t createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWinodwPhysiNode* pStateNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -1727,7 +1727,7 @@ void destroySWindowOperatorInfo(void* param) { int32_t createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPhysiNode* pSessionNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -2027,7 +2027,7 @@ static int32_t mergeAlignedIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock int32_t createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, SMergeAlignedIntervalPhysiNode* pNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -2132,7 +2132,7 @@ typedef struct SGroupTimeWindow { void destroyMergeIntervalOperatorInfo(void* param) { SMergeIntervalAggOperatorInfo* miaInfo = (SMergeIntervalAggOperatorInfo*)param; - (void)tdListFree(miaInfo->groupIntervals); + miaInfo->groupIntervals = tdListFree(miaInfo->groupIntervals); destroyIntervalOperatorInfo(&miaInfo->intervalAggOperatorInfo); taosMemoryFreeClear(param); @@ -2162,7 +2162,8 @@ static int32_t outputPrevIntervalResult(SOperatorInfo* pOperatorInfo, uint64_t t STimeWindow* prevWin = &prevGrpWin->window; if ((ascScan && newWin->skey > prevWin->ekey) || ((!ascScan) && newWin->skey < prevWin->ekey)) { - (void)tdListPopNode(miaInfo->groupIntervals, listNode); + SListNode* tmp = tdListPopNode(miaInfo->groupIntervals, listNode); + taosMemoryFreeClear(tmp); } } @@ -2365,7 +2366,7 @@ _end: int32_t createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMergeIntervalPhysiNode* pIntervalPhyNode, SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) { - QRY_OPTR_CHECK(pOptrInfo); + QRY_PARAM_CHECK(pOptrInfo); int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 2792e6a197..796ebbeb84 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -79,9 +79,8 @@ struct SSortHandle { bool forceUsePQSort; BoundedQueue* pBoundedQueue; uint32_t tmpRowIdx; - - int64_t mergeLimit; - int64_t currMergeLimitTs; + int64_t mergeLimit; + int64_t currMergeLimitTs; int32_t sourceId; SSDataBlock* pDataBlock; @@ -288,7 +287,7 @@ int32_t tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t pageSize, int32_t code = 0; int32_t lino = 0; - QRY_OPTR_CHECK(pHandle); + QRY_PARAM_CHECK(pHandle); SSortHandle* pSortHandle = taosMemoryCalloc(1, sizeof(SSortHandle)); QUERY_CHECK_NULL(pSortHandle, code, lino, _err, terrno); @@ -367,7 +366,7 @@ static int32_t sortComparCleanup(SMsortComparParam* cmpParam) { return TSDB_CODE_SUCCESS; } -void tsortClearOrderdSource(SArray* pOrderedSource, int64_t *fetchUs, int64_t *fetchNum) { +void tsortClearOrderedSource(SArray* pOrderedSource, int64_t *fetchUs, int64_t *fetchNum) { for (size_t i = 0; i < taosArrayGetSize(pOrderedSource); i++) { SSortSource** pSource = taosArrayGet(pOrderedSource, i); if (NULL == *pSource) { @@ -413,10 +412,11 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { destroyDiskbasedBuf(pSortHandle->pBuf); taosMemoryFreeClear(pSortHandle->idStr); blockDataDestroy(pSortHandle->pDataBlock); + if (pSortHandle->pBoundedQueue) destroyBoundedQueue(pSortHandle->pBoundedQueue); int64_t fetchUs = 0, fetchNum = 0; - tsortClearOrderdSource(pSortHandle->pOrderedSource, &fetchUs, &fetchNum); + tsortClearOrderedSource(pSortHandle->pOrderedSource, &fetchUs, &fetchNum); qDebug("all source fetch time: %" PRId64 "us num:%" PRId64 " %s", fetchUs, fetchNum, pSortHandle->idStr); taosArrayDestroy(pSortHandle->pOrderedSource); @@ -465,7 +465,13 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSource return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; } - return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); + int32_t code = blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); + if (code != 0) { + qError("sort failed at: %s:%d", __func__, __LINE__); + taosArrayDestroy(pPageIdList); + } + + return code; } static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { @@ -935,9 +941,99 @@ int32_t msortComparFn(const void* pLeft, const void* pRight, void* param) { } } } + return 0; } +static int32_t doSortForEachGroup(SSortHandle* pHandle, int32_t sortTimes, int32_t numOfSorted, + int32_t numOfInputSources, SArray* pResList, int32_t sortGroup, int32_t numOfRows) { + int32_t code = 0; + int32_t lino = 0; + SArray* pPageIdList = NULL; + + for (int32_t i = 0; i < sortGroup; ++i) { + qDebug("internal merge sort pass %d group %d. num input sources %d ", sortTimes, i, numOfInputSources); + pHandle->sourceId += 1; + + int32_t end = (i + 1) * numOfInputSources - 1; + if (end > numOfSorted - 1) { + end = numOfSorted - 1; + } + + pHandle->cmpParam.numOfSources = end - i * numOfInputSources + 1; + + code = sortComparInit(&pHandle->cmpParam, pHandle->pOrderedSource, i * numOfInputSources, end, pHandle); + QUERY_CHECK_CODE(code, lino, _err); + + code = + tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn); + QUERY_CHECK_CODE(code, lino, _err); + + int32_t nMergedRows = 0; + pPageIdList = taosArrayInit(4, sizeof(int32_t)); + QUERY_CHECK_NULL(pPageIdList, code, lino, _err, terrno); + + while (1) { + if (tsortIsClosed(pHandle) || (pHandle->abortCheckFn && pHandle->abortCheckFn(pHandle->abortCheckParam))) { + code = TSDB_CODE_TSC_QUERY_CANCELLED; + goto _err; + } + + SSDataBlock* pDataBlock = NULL; + code = getSortedBlockDataInner(pHandle, &pHandle->cmpParam, numOfRows, &pDataBlock); + if (pDataBlock == NULL || code != 0) { + break; + } + + int32_t pageId = -1; + void* pPage = getNewBufPage(pHandle->pBuf, &pageId); + QUERY_CHECK_NULL(pPage, code, lino, _err, terrno); + + void* px = taosArrayPush(pPageIdList, &pageId); + QUERY_CHECK_NULL(px, code, lino, _err, terrno); + + int32_t size = + blockDataGetSize(pDataBlock) + sizeof(int32_t) + taosArrayGetSize(pDataBlock->pDataBlock) * sizeof(int32_t); + if (size > getBufPageSize(pHandle->pBuf)) { + code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + goto _err; + } + + code = blockDataToBuf(pPage, pDataBlock); + QUERY_CHECK_CODE(code, lino, _err); + + setBufPageDirty(pPage, true); + releaseBufPage(pHandle->pBuf, pPage); + nMergedRows += pDataBlock->info.rows; + + blockDataCleanup(pDataBlock); + if ((pHandle->mergeLimit != -1) && (nMergedRows >= pHandle->mergeLimit)) { + break; + } + } + + code = sortComparCleanup(&pHandle->cmpParam); + QUERY_CHECK_CODE(code, lino, _err); + + tMergeTreeDestroy(&pHandle->pMergeTree); + pHandle->numOfCompletedSources = 0; + + SSDataBlock* pBlock = NULL; + code = createOneDataBlock(pHandle->pDataBlock, false, &pBlock); + QUERY_CHECK_CODE(code, lino, _err); + + code = doAddNewExternalMemSource(pHandle->pBuf, pResList, pBlock, &pHandle->sourceId, pPageIdList); + QUERY_CHECK_CODE(code, lino, _err); + } + + return code; + +_err: + taosArrayDestroy(pPageIdList); + qError("%s error happens:%s line:%d, code:%s", pHandle->idStr, __func__, lino, tstrerror(code)); + return code; +} + static int32_t doInternalMergeSort(SSortHandle* pHandle) { size_t numOfSources = taosArrayGetSize(pHandle->pOrderedSource); if (numOfSources == 0) { @@ -959,8 +1055,8 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { pHandle->numOfPages); } - int32_t numOfRows = blockDataGetCapacityInRow(pHandle->pDataBlock, pHandle->pageSize, - blockDataGetSerialMetaSize(taosArrayGetSize(pHandle->pDataBlock->pDataBlock))); + int32_t size = (int32_t) blockDataGetSerialMetaSize(taosArrayGetSize(pHandle->pDataBlock->pDataBlock)); + int32_t numOfRows = blockDataGetCapacityInRow(pHandle->pDataBlock, pHandle->pageSize, size); if (numOfRows < 0) { return terrno; } @@ -985,117 +1081,22 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { int32_t sortGroup = (numOfSorted + numOfInputSources - 1) / numOfInputSources; // Only *numOfInputSources* can be loaded into buffer to perform the external sort. - for (int32_t i = 0; i < sortGroup; ++i) { - qDebug("internal merge sort pass %d group %d. num input sources %d ", t, i, numOfInputSources); - pHandle->sourceId += 1; - - int32_t end = (i + 1) * numOfInputSources - 1; - if (end > numOfSorted - 1) { - end = numOfSorted - 1; - } - - pHandle->cmpParam.numOfSources = end - i * numOfInputSources + 1; - - code = sortComparInit(&pHandle->cmpParam, pHandle->pOrderedSource, i * numOfInputSources, end, pHandle); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(pResList); - return code; - } - - code = - tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(pResList); - return code; - } - - int32_t nMergedRows = 0; - SArray* pPageIdList = taosArrayInit(4, sizeof(int32_t)); - if (pPageIdList == NULL) { - taosArrayDestroy(pResList); - return terrno; - } - - while (1) { - if (tsortIsClosed(pHandle) || (pHandle->abortCheckFn && pHandle->abortCheckFn(pHandle->abortCheckParam))) { - code = terrno = TSDB_CODE_TSC_QUERY_CANCELLED; - return code; - } - - SSDataBlock* pDataBlock = NULL; - code = getSortedBlockDataInner(pHandle, &pHandle->cmpParam, numOfRows, &pDataBlock); - if (pDataBlock == NULL || code != 0) { - break; - } - - int32_t pageId = -1; - void* pPage = getNewBufPage(pHandle->pBuf, &pageId); - if (pPage == NULL) { - taosArrayDestroy(pResList); - taosArrayDestroy(pPageIdList); - return terrno; - } - - void* px = taosArrayPush(pPageIdList, &pageId); - if (px == NULL) { - taosArrayDestroy(pResList); - taosArrayDestroy(pPageIdList); - return terrno; - } - - int32_t size = - blockDataGetSize(pDataBlock) + sizeof(int32_t) + taosArrayGetSize(pDataBlock->pDataBlock) * sizeof(int32_t); - if (size > getBufPageSize(pHandle->pBuf)) { - qError("sort failed at: %s:%d", __func__, __LINE__); - return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; - } - - code= blockDataToBuf(pPage, pDataBlock); - if (code) { - return code; - } - - setBufPageDirty(pPage, true); - releaseBufPage(pHandle->pBuf, pPage); - nMergedRows += pDataBlock->info.rows; - - blockDataCleanup(pDataBlock); - if ((pHandle->mergeLimit != -1) && (nMergedRows >= pHandle->mergeLimit)) { - break; - } - } - - code = sortComparCleanup(&pHandle->cmpParam); - if (code) { - return code; - } - - tMergeTreeDestroy(&pHandle->pMergeTree); - pHandle->numOfCompletedSources = 0; - - SSDataBlock* pBlock = NULL; - - code = createOneDataBlock(pHandle->pDataBlock, false, &pBlock); - if (code) { - taosArrayDestroy(pResList); - return code; - } - - code = doAddNewExternalMemSource(pHandle->pBuf, pResList, pBlock, &pHandle->sourceId, pPageIdList); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(pResList); - return code; - } + code = doSortForEachGroup(pHandle, t, numOfSorted, numOfInputSources, pResList, sortGroup, numOfRows); + if (code != 0) { + tsortClearOrderedSource(pResList, NULL, NULL); + taosArrayDestroy(pResList); + return code; } - tsortClearOrderdSource(pHandle->pOrderedSource, NULL, NULL); + tsortClearOrderedSource(pHandle->pOrderedSource, NULL, NULL); void* px = taosArrayAddAll(pHandle->pOrderedSource, pResList); if (px == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + tsortClearOrderedSource(pResList, NULL, NULL); + taosArrayDestroy(pResList); + return terrno; } taosArrayDestroy(pResList); - numOfSorted = taosArrayGetSize(pHandle->pOrderedSource); int64_t el = taosGetTimestampUs() - st; @@ -2346,7 +2347,7 @@ static int32_t createBlocksMergeSortInitialSources(SSortHandle* pHandle) { } } - tsortClearOrderdSource(pHandle->pOrderedSource, NULL, NULL); + tsortClearOrderedSource(pHandle->pOrderedSource, NULL, NULL); if (!tsortIsClosed(pHandle)) { void* px = taosArrayAddAll(pHandle->pOrderedSource, aExtSrc); QUERY_CHECK_NULL(px, code, lino, _err, terrno); @@ -2378,37 +2379,44 @@ static int32_t createBlocksMergeSortInitialSources(SSortHandle* pHandle) { return code; } -static void freeSSortSource(SSortSource* source) { - if (NULL == source) { +static void freeSortSource(SSortSource* pSource) { + if (NULL == pSource) { return; } - if (source->param && !source->onlyRef) { - taosMemoryFree(source->param); + if (!pSource->onlyRef && pSource->param) { + taosMemoryFree(pSource->param); } - if (!source->onlyRef && source->src.pBlock) { - blockDataDestroy(source->src.pBlock); - source->src.pBlock = NULL; + + if (!pSource->onlyRef && pSource->src.pBlock) { + blockDataDestroy(pSource->src.pBlock); + pSource->src.pBlock = NULL; } - taosMemoryFree(source); + + taosMemoryFree(pSource); } static int32_t createBlocksQuickSortInitialSources(SSortHandle* pHandle) { int32_t code = 0; size_t sortBufSize = pHandle->numOfPages * pHandle->pageSize; - SSortSource** pSource = taosArrayGet(pHandle->pOrderedSource, 0); - if (pSource == NULL) { + SSortSource** p = taosArrayGet(pHandle->pOrderedSource, 0); + if (p == NULL) { return terrno; } - SSortSource* source = *pSource; - *pSource = NULL; + SSortSource* pSource = *p; - tsortClearOrderdSource(pHandle->pOrderedSource, NULL, NULL); + taosArrayRemove(pHandle->pOrderedSource, 0); + tsortClearOrderedSource(pHandle->pOrderedSource, NULL, NULL); while (1) { SSDataBlock* pBlock = NULL; - TAOS_CHECK_RETURN(pHandle->fetchfp(source->param, &pBlock)); + code = pHandle->fetchfp(pSource->param, &pBlock); + if (code != 0) { + freeSortSource(pSource); + return code; + } + if (pBlock == NULL) { break; } @@ -2422,7 +2430,7 @@ static int32_t createBlocksQuickSortInitialSources(SSortHandle* pHandle) { sortBufSize = pHandle->numOfPages * pHandle->pageSize; code = createOneDataBlock(pBlock, false, &pHandle->pDataBlock); if (code) { - freeSSortSource(source); + freeSortSource(pSource); return code; } } @@ -2433,47 +2441,45 @@ static int32_t createBlocksQuickSortInitialSources(SSortHandle* pHandle) { code = blockDataMerge(pHandle->pDataBlock, pBlock); if (code != TSDB_CODE_SUCCESS) { - freeSSortSource(source); + freeSortSource(pSource); return code; } size_t size = blockDataGetSize(pHandle->pDataBlock); if (size > sortBufSize) { // Perform the in-memory sort and then flush data in the buffer into disk. - int64_t p = taosGetTimestampUs(); + int64_t st = taosGetTimestampUs(); code = blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo); if (code != 0) { - freeSSortSource(source); + freeSortSource(pSource); return code; } - int64_t el = taosGetTimestampUs() - p; - pHandle->sortElapsed += el; + pHandle->sortElapsed += (taosGetTimestampUs() - st); + if (pHandle->pqMaxRows > 0) blockDataKeepFirstNRows(pHandle->pDataBlock, pHandle->pqMaxRows); code = doAddToBuf(pHandle->pDataBlock, pHandle); if (code != TSDB_CODE_SUCCESS) { - freeSSortSource(source); + freeSortSource(pSource); return code; } } } - freeSSortSource(source); + freeSortSource(pSource); if (pHandle->pDataBlock != NULL && pHandle->pDataBlock->info.rows > 0) { size_t size = blockDataGetSize(pHandle->pDataBlock); // Perform the in-memory sort and then flush data in the buffer into disk. - int64_t p = taosGetTimestampUs(); - + int64_t st = taosGetTimestampUs(); code = blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo); if (code != 0) { return code; } if (pHandle->pqMaxRows > 0) blockDataKeepFirstNRows(pHandle->pDataBlock, pHandle->pqMaxRows); - int64_t el = taosGetTimestampUs() - p; - pHandle->sortElapsed += el; + pHandle->sortElapsed += (taosGetTimestampUs() - st); // All sorted data can fit in memory, external memory sort is not needed. Return to directly if (size <= sortBufSize && pHandle->pBuf == NULL) { @@ -2488,6 +2494,7 @@ static int32_t createBlocksQuickSortInitialSources(SSortHandle* pHandle) { code = doAddToBuf(pHandle->pDataBlock, pHandle); } } + return code; } @@ -2500,7 +2507,7 @@ static int32_t createInitialSources(SSortHandle* pHandle) { code = createBlocksMergeSortInitialSources(pHandle); } - qDebug("%zu sources created", taosArrayGetSize(pHandle->pOrderedSource)); + qDebug("%s %zu sources created", pHandle->idStr, taosArrayGetSize(pHandle->pOrderedSource)); return code; } diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 17ba430150..f7a6585800 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -678,7 +678,7 @@ static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t // set result type if (numOfParams > 2) { - pFunc->node.resType = (SDataType){.bytes = 512, .type = TSDB_DATA_TYPE_VARCHAR}; + pFunc->node.resType = (SDataType){.bytes = 3200, .type = TSDB_DATA_TYPE_VARCHAR}; } else { pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 84ab103456..665e92fd03 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -2105,7 +2105,8 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { tMemBucket* pMemBucket = ppInfo->pMemBucket; if (pMemBucket != NULL && pMemBucket->total > 0) { // check for null if (pCtx->numOfParams > 2) { - char buf[512] = {0}; + char buf[3200] = {0}; + // max length of double num is 317, e.g. use %.6lf to print -1.0e+308, consider the comma and bracket, 3200 is enough. size_t len = 1; varDataVal(buf)[0] = '['; @@ -2154,6 +2155,8 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { tMemBucketDestroy(pMemBucket); return functionFinalize(pCtx, pBlock); } + } else { + return functionFinalize(pCtx, pBlock); } _fin_error: @@ -3162,7 +3165,7 @@ static int32_t doSaveLastrow(SqlFunctionCtx* pCtx, char* pData, int32_t rowIndex (void)memcpy(pInfo->buf, pData, pInfo->bytes); } - if (pCtx->hasPrimaryKey) { + if (pCtx->hasPrimaryKey && !colDataIsNull_s(pkCol, rowIndex)) { char* pkData = colDataGetData(pkCol, rowIndex); if (IS_VAR_DATA_TYPE(pInfo->pkType)) { pInfo->pkBytes = varDataTLen(pkData); @@ -6008,6 +6011,7 @@ int32_t modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { pInfo->buf = taosMemoryMalloc(pInfo->colBytes); if (NULL == pInfo->buf) { taosHashCleanup(pInfo->pHash); + pInfo->pHash = NULL; return TSDB_CODE_OUT_OF_MEMORY; } @@ -6016,6 +6020,7 @@ int32_t modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { static void modeFunctionCleanup(SModeInfo * pInfo) { taosHashCleanup(pInfo->pHash); + pInfo->pHash = NULL; taosMemoryFreeClear(pInfo->buf); } @@ -6434,63 +6439,74 @@ int32_t blockDistFunction(SqlFunctionCtx* pCtx) { int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDistInfo* pInfo) { SEncoder encoder = {0}; + int32_t code = 0; + int32_t lino; + int32_t tlen; tEncoderInit(&encoder, buf, bufLen); - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeU32(&encoder, pInfo->rowSize) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(&encoder)); + TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->rowSize)); - if (tEncodeU16(&encoder, pInfo->numOfFiles) < 0) return -1; - if (tEncodeU32(&encoder, pInfo->numOfBlocks) < 0) return -1; - if (tEncodeU32(&encoder, pInfo->numOfTables) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeU16(&encoder, pInfo->numOfFiles)); + TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfBlocks)); + TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfTables)); - if (tEncodeU64(&encoder, pInfo->totalSize) < 0) return -1; - if (tEncodeU64(&encoder, pInfo->totalRows) < 0) return -1; - if (tEncodeI32(&encoder, pInfo->maxRows) < 0) return -1; - if (tEncodeI32(&encoder, pInfo->minRows) < 0) return -1; - if (tEncodeI32(&encoder, pInfo->defMaxRows) < 0) return -1; - if (tEncodeI32(&encoder, pInfo->defMinRows) < 0) return -1; - if (tEncodeU32(&encoder, pInfo->numOfInmemRows) < 0) return -1; - if (tEncodeU32(&encoder, pInfo->numOfSttRows) < 0) return -1; - if (tEncodeU32(&encoder, pInfo->numOfVgroups) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->totalSize)); + TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->totalRows)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->maxRows)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->minRows)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->defMaxRows)); + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->defMinRows)); + TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfInmemRows)); + TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfSttRows)); + TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfVgroups)); for (int32_t i = 0; i < tListLen(pInfo->blockRowsHisto); ++i) { - if (tEncodeI32(&encoder, pInfo->blockRowsHisto[i]) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->blockRowsHisto[i])); } tEndEncode(&encoder); - int32_t tlen = encoder.pos; +_exit: + if (code) { + tlen = code; + } else { + tlen = encoder.pos; + } tEncoderClear(&encoder); return tlen; } int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo) { SDecoder decoder = {0}; + int32_t code = 0; + int32_t lino; tDecoderInit(&decoder, buf, bufLen); - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeU32(&decoder, &pInfo->rowSize) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(&decoder)); + TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->rowSize)); - if (tDecodeU16(&decoder, &pInfo->numOfFiles) < 0) return -1; - if (tDecodeU32(&decoder, &pInfo->numOfBlocks) < 0) return -1; - if (tDecodeU32(&decoder, &pInfo->numOfTables) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeU16(&decoder, &pInfo->numOfFiles)); + TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfBlocks)); + TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfTables)); - if (tDecodeU64(&decoder, &pInfo->totalSize) < 0) return -1; - if (tDecodeU64(&decoder, &pInfo->totalRows) < 0) return -1; - if (tDecodeI32(&decoder, &pInfo->maxRows) < 0) return -1; - if (tDecodeI32(&decoder, &pInfo->minRows) < 0) return -1; - if (tDecodeI32(&decoder, &pInfo->defMaxRows) < 0) return -1; - if (tDecodeI32(&decoder, &pInfo->defMinRows) < 0) return -1; - if (tDecodeU32(&decoder, &pInfo->numOfInmemRows) < 0) return -1; - if (tDecodeU32(&decoder, &pInfo->numOfSttRows) < 0) return -1; - if (tDecodeU32(&decoder, &pInfo->numOfVgroups) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->totalSize)); + TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->totalRows)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->maxRows)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->minRows)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->defMaxRows)); + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->defMinRows)); + TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfInmemRows)); + TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfSttRows)); + TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfVgroups)); for (int32_t i = 0; i < tListLen(pInfo->blockRowsHisto); ++i) { - if (tDecodeI32(&decoder, &pInfo->blockRowsHisto[i]) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->blockRowsHisto[i])); } +_exit: tDecoderClear(&decoder); - return 0; + return code; } int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 2f71ab8e24..1a927a1576 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -431,7 +431,9 @@ static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNod (*pPartialFunc)->originalFuncId = pSrcFunc->hasOriginalFunc ? pSrcFunc->originalFuncId : pSrcFunc->funcId; char name[TSDB_FUNC_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_POINTER_PRINT_BYTES + 1] = {0}; int32_t len = snprintf(name, sizeof(name) - 1, "%s.%p", (*pPartialFunc)->functionName, pSrcFunc); - (void)taosHashBinary(name, len); + if (taosHashBinary(name, len) < 0) { + return TSDB_CODE_FAILED; + } (void)strncpy((*pPartialFunc)->node.aliasName, name, TSDB_COL_NAME_LEN - 1); (*pPartialFunc)->hasPk = pSrcFunc->hasPk; (*pPartialFunc)->pkBytes = pSrcFunc->pkBytes; diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index adcce879eb..b17af44260 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -524,7 +524,12 @@ void udfdDeinitScriptPlugins() { void udfdProcessRequest(uv_work_t *req) { SUvUdfWork *uvUdf = (SUvUdfWork *)(req->data); SUdfRequest request = {0}; - if(decodeUdfRequest(uvUdf->input.base, &request) == NULL) return; + if(decodeUdfRequest(uvUdf->input.base, &request) == NULL) + { + taosMemoryFree(uvUdf->input.base); + fnError("udf request decode failed"); + return; + } switch (request.type) { case UDF_TASK_SETUP: { diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index a8db514ee3..9412735ded 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -2254,10 +2254,16 @@ static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifyOpSt static int32_t parseDataFromFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SToken* pFilePath, SRowsDataContext rowsDataCxt) { - char filePathStr[PATH_MAX] = {0}; + char filePathStr[PATH_MAX + 16] = {0}; if (TK_NK_STRING == pFilePath->type) { (void)trimString(pFilePath->z, pFilePath->n, filePathStr, sizeof(filePathStr)); + if (strlen(filePathStr) >= PATH_MAX) { + return buildSyntaxErrMsg(&pCxt->msg, "file path is too long, max length is 4096", pFilePath->z); + } } else { + if (pFilePath->n >= PATH_MAX) { + return buildSyntaxErrMsg(&pCxt->msg, "file path is too long, max length is 4096", pFilePath->z); + } strncpy(filePathStr, pFilePath->z, pFilePath->n); } pStmt->fp = taosOpenFile(filePathStr, TD_FILE_READ | TD_FILE_STREAM); diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 025459a8c9..5b459243a4 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -448,7 +448,407 @@ int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bi pBind = bind; } - code = tColDataAddValueByBind(pCol, pBind, IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1); + code = tColDataAddValueByBind(pCol, pBind, + IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1); + + qDebug("stmt col %d bind %d rows data", colIdx, rowNum); + +_return: + + taosMemoryFree(ncharBind.buffer); + taosMemoryFree(ncharBind.length); + + return code; +} + +int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName, + TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen) { + STableDataCxt* pDataBlock = (STableDataCxt*)pBlock; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; + int32_t code = TSDB_CODE_SUCCESS; + SBoundColInfo* tags = (SBoundColInfo*)boundTags; + if (NULL == tags) { + return TSDB_CODE_APP_ERROR; + } + + SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal)); + if (!pTagArray) { + return buildInvalidOperationMsg(&pBuf, "out of memory"); + } + + SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN); + if (!tagName) { + code = buildInvalidOperationMsg(&pBuf, "out of memory"); + goto end; + } + + SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta); + + bool isJson = false; + STag* pTag = NULL; + + for (int c = 0; c < tags->numOfBound; ++c) { + if (bind[c].is_null && bind[c].is_null[0]) { + continue; + } + + SSchema* pTagSchema = &pSchema[tags->pColIndex[c]]; + int32_t colLen = pTagSchema->bytes; + if (IS_VAR_DATA_TYPE(pTagSchema->type)) { + colLen = bind[c].length[0]; + if ((colLen + VARSTR_HEADER_SIZE) > pTagSchema->bytes) { + code = buildInvalidOperationMsg(&pBuf, "tag length is too big"); + goto end; + } + } + if (NULL == taosArrayPush(tagName, pTagSchema->name)) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + if (pTagSchema->type == TSDB_DATA_TYPE_JSON) { + if (colLen > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { + code = buildSyntaxErrMsg(&pBuf, "json string too long than 4095", bind[c].buffer); + goto end; + } + + isJson = true; + char* tmp = taosMemoryCalloc(1, colLen + 1); + memcpy(tmp, bind[c].buffer, colLen); + code = parseJsontoTagData(tmp, pTagArray, &pTag, &pBuf); + taosMemoryFree(tmp); + if (code != TSDB_CODE_SUCCESS) { + goto end; + } + } else { + STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type}; + // strcpy(val.colName, pTagSchema->name); + if (pTagSchema->type == TSDB_DATA_TYPE_BINARY || pTagSchema->type == TSDB_DATA_TYPE_VARBINARY || + pTagSchema->type == TSDB_DATA_TYPE_GEOMETRY) { + val.pData = (uint8_t*)bind[c].buffer; + val.nData = colLen; + } else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) { + int32_t output = 0; + void* p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE); + if (p == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) { + if (errno == E2BIG) { + taosMemoryFree(p); + code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name); + goto end; + } + char buf[512] = {0}; + snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno)); + taosMemoryFree(p); + code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer); + goto end; + } + val.pData = p; + val.nData = output; + } else { + memcpy(&val.i64, bind[c].buffer, colLen); + } + if (NULL == taosArrayPush(pTagArray, &val)) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + } + } + + if (!isJson && (code = tTagNew(pTagArray, 1, false, &pTag)) != TSDB_CODE_SUCCESS) { + goto end; + } + + if (NULL == pDataBlock->pData->pCreateTbReq) { + pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); + if (NULL == pDataBlock->pData->pCreateTbReq) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + } + + insBuildCreateTbReq(pDataBlock->pData->pCreateTbReq, tName, pTag, suid, sTableName, tagName, + pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL); + pTag = NULL; + +end: + for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) { + STagVal* p = (STagVal*)taosArrayGet(pTagArray, i); + if (p->type == TSDB_DATA_TYPE_NCHAR) { + taosMemoryFreeClear(p->pData); + } + } + taosArrayDestroy(pTagArray); + taosArrayDestroy(tagName); + taosMemoryFree(pTag); + + return code; +} + +static int32_t convertStmtStbNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STMT2_BIND* src, TAOS_STMT2_BIND* dst) { + int32_t output = 0; + const int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE; + + dst->buffer = taosMemoryCalloc(src->num, max_buf_len); + if (NULL == dst->buffer) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + dst->length = taosMemoryCalloc(src->num, sizeof(int32_t)); + if (NULL == dst->length) { + taosMemoryFreeClear(dst->buffer); + return TSDB_CODE_OUT_OF_MEMORY; + } + + char* src_buf = src->buffer; + char* dst_buf = dst->buffer; + for (int32_t i = 0; i < src->num; ++i) { + if (src->is_null && src->is_null[i]) { + continue; + } + + if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) { + if (errno == E2BIG) { + return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); + } + char buf[512] = {0}; + snprintf(buf, tListLen(buf), "%s", strerror(errno)); + return buildSyntaxErrMsg(pMsgBuf, buf, NULL); + } + + dst->length[i] = output; + src_buf += src->length[i]; + dst_buf += output; + } + + dst->buffer_type = src->buffer_type; + dst->is_null = src->is_null; + dst->num = src->num; + + return TSDB_CODE_SUCCESS; +} + +int32_t qBindStmtStbColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen, + STSchema** pTSchema, SBindInfo2* pBindInfos) { + STableDataCxt* pDataBlock = (STableDataCxt*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta); + SBoundColInfo* boundInfo = &pDataBlock->boundColsInfo; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; + int32_t rowNum = bind->num; + SArray* ncharBinds = NULL; + TAOS_STMT2_BIND ncharBind = {0}; + int32_t code = 0; + int16_t lastColId = -1; + bool colInOrder = true; + + if (NULL == *pTSchema) { + *pTSchema = tBuildTSchema(pSchema, pDataBlock->pMeta->tableInfo.numOfColumns, pDataBlock->pMeta->sversion); + } + + for (int c = 0; c < boundInfo->numOfBound; ++c) { + SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]]; + if (pColSchema->colId <= lastColId) { + colInOrder = false; + } else { + lastColId = pColSchema->colId; + } + + if (bind[c].num != rowNum) { + code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); + goto _return; + } + + if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) && + bind[c].buffer_type != pColSchema->type) { // for rowNum ==1 , connector may not set buffer_type + code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); + goto _return; + } + + if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) { + code = convertStmtStbNcharCol2(&pBuf, pColSchema, bind + c, &ncharBind); + if (code) { + goto _return; + } + if (!ncharBinds) { + ncharBinds = taosArrayInit(1, sizeof(ncharBind)); + if (!ncharBinds) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _return; + } + } + if (!taosArrayPush(ncharBinds, &ncharBind)) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _return; + } + pBindInfos[c].bind = taosArrayGetLast(ncharBinds); + } else { + pBindInfos[c].bind = bind + c; + } + + pBindInfos[c].columnId = pColSchema->colId; + pBindInfos[c].type = pColSchema->type; + pBindInfos[c].bytes = pColSchema->bytes; + } + + code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols); + + qDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum); + +_return: + if (ncharBinds) { + for (int i = 0; i < TARRAY_SIZE(ncharBinds); ++i) { + TAOS_STMT2_BIND* ncBind = TARRAY_DATA(ncharBinds); + taosMemoryFree(ncBind[i].buffer); + taosMemoryFree(ncBind[i].length); + } + taosArrayDestroy(ncharBinds); + } + + return code; +} + +static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STMT2_BIND* src, TAOS_STMT2_BIND* dst) { + int32_t output = 0; + const int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE; + + int32_t newBuflen = (pSchema->bytes - VARSTR_HEADER_SIZE) * src->num; + // if (dst->buffer_length < newBuflen) { + dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen); + if (NULL == dst->buffer) { + return TSDB_CODE_OUT_OF_MEMORY; + } + //} + + if (NULL == dst->length) { + dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num); + if (NULL == dst->length) { + taosMemoryFreeClear(dst->buffer); + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + // dst->buffer_length = pSchema->bytes - VARSTR_HEADER_SIZE; + char* src_buf = src->buffer; + char* dst_buf = dst->buffer; + for (int32_t i = 0; i < src->num; ++i) { + if (src->is_null && src->is_null[i]) { + continue; + } + + /*if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i], + (TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {*/ + if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) { + if (errno == E2BIG) { + return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); + } + char buf[512] = {0}; + snprintf(buf, tListLen(buf), "%s", strerror(errno)); + return buildSyntaxErrMsg(pMsgBuf, buf, NULL); + } + + dst->length[i] = output; + src_buf += src->length[i]; + dst_buf += output; + } + + dst->buffer_type = src->buffer_type; + dst->is_null = src->is_null; + dst->num = src->num; + + return TSDB_CODE_SUCCESS; +} + +int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen) { + STableDataCxt* pDataBlock = (STableDataCxt*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta); + SBoundColInfo* boundInfo = &pDataBlock->boundColsInfo; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; + int32_t rowNum = bind->num; + TAOS_STMT2_BIND ncharBind = {0}; + TAOS_STMT2_BIND* pBind = NULL; + int32_t code = 0; + + for (int c = 0; c < boundInfo->numOfBound; ++c) { + SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]]; + SColData* pCol = taosArrayGet(pCols, c); + + if (bind[c].num != rowNum) { + code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); + goto _return; + } + + if ((!(rowNum == 1 && bind[c].is_null && *bind[c].is_null)) && + bind[c].buffer_type != pColSchema->type) { // for rowNum ==1 , connector may not set buffer_type + code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); + goto _return; + } + + if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) { + code = convertStmtNcharCol2(&pBuf, pColSchema, bind + c, &ncharBind); + if (code) { + goto _return; + } + pBind = &ncharBind; + } else { + pBind = bind + c; + } + + code = tColDataAddValueByBind2(pCol, pBind, + IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1); + if (code) { + goto _return; + } + } + + qDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum); + +_return: + + taosMemoryFree(ncharBind.buffer); + taosMemoryFree(ncharBind.length); + + return code; +} + +int32_t qBindStmtSingleColValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen, + int32_t colIdx, int32_t rowNum) { + STableDataCxt* pDataBlock = (STableDataCxt*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta); + SBoundColInfo* boundInfo = &pDataBlock->boundColsInfo; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; + SSchema* pColSchema = &pSchema[boundInfo->pColIndex[colIdx]]; + SColData* pCol = taosArrayGet(pCols, colIdx); + TAOS_STMT2_BIND ncharBind = {0}; + TAOS_STMT2_BIND* pBind = NULL; + int32_t code = 0; + + if (bind->num != rowNum) { + return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); + } + + // Column index exceeds the number of columns + if (colIdx >= pCols->size && pCol == NULL) { + return buildInvalidOperationMsg(&pBuf, "column index exceeds the number of columns"); + } + + if (bind->buffer_type != pColSchema->type) { + return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); + } + + if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) { + code = convertStmtNcharCol2(&pBuf, pColSchema, bind, &ncharBind); + if (code) { + goto _return; + } + pBind = &ncharBind; + } else { + pBind = bind; + } + + code = tColDataAddValueByBind2(pCol, pBind, + IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1); qDebug("stmt col %d bind %d rows data", colIdx, rowNum); @@ -533,7 +933,7 @@ int32_t qResetStmtColumns(SArray* pCols, bool deepClear) { for (int32_t i = 0; i < colNum; ++i) { SColData* pCol = (SColData*)taosArrayGet(pCols, i); - if (pCol == NULL){ + if (pCol == NULL) { qError("qResetStmtColumns column is NULL"); return TSDB_CODE_OUT_OF_MEMORY; } @@ -553,7 +953,7 @@ int32_t qResetStmtDataBlock(STableDataCxt* block, bool deepClear) { for (int32_t i = 0; i < colNum; ++i) { SColData* pCol = (SColData*)taosArrayGet(pBlock->pData->aCol, i); - if (pCol == NULL){ + if (pCol == NULL) { qError("qResetStmtDataBlock column is NULL"); return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index e96aaf52ed..b78cd36f0e 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -76,33 +76,33 @@ bool qIsCreateTbFromFileSql(const char* pStr, size_t length) { } bool qParseDbName(const char* pStr, size_t length, char** pDbName) { - (void) length; + (void)length; int32_t index = 0; - SToken t; + SToken t; if (NULL == pStr) { *pDbName = NULL; return false; } - t = tStrGetToken((char *) pStr, &index, false, NULL); + t = tStrGetToken((char*)pStr, &index, false, NULL); if (TK_INSERT != t.type && TK_IMPORT != t.type) { *pDbName = NULL; return false; } - t = tStrGetToken((char *) pStr, &index, false, NULL); + t = tStrGetToken((char*)pStr, &index, false, NULL); if (TK_INTO != t.type) { *pDbName = NULL; return false; } - t = tStrGetToken((char *) pStr, &index, false, NULL); + t = tStrGetToken((char*)pStr, &index, false, NULL); if (t.n == 0 || t.z == NULL) { *pDbName = NULL; return false; } - char *dotPos = strnchr(t.z, '.', t.n, true); + char* dotPos = strnchr(t.z, '.', t.n, true); if (dotPos != NULL) { int dbNameLen = dotPos - t.z; *pDbName = taosMemoryMalloc(dbNameLen + 1); @@ -331,13 +331,12 @@ int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, SSDataBlock return code; } - -static void destoryTablesReq(void *p) { - STablesReq *pRes = (STablesReq *)p; +static void destoryTablesReq(void* p) { + STablesReq* pRes = (STablesReq*)p; taosArrayDestroy(pRes->pTables); } -void destoryCatalogReq(SCatalogReq *pCatalogReq) { +void destoryCatalogReq(SCatalogReq* pCatalogReq) { if (NULL == pCatalogReq) { return; } @@ -369,7 +368,6 @@ void destoryCatalogReq(SCatalogReq *pCatalogReq) { taosArrayDestroy(pCatalogReq->pTableTag); } - void tfreeSParseQueryRes(void* p) { if (NULL == p) { return; @@ -410,9 +408,7 @@ int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid) { return TSDB_CODE_FAILED; } -int32_t qInitKeywordsTable() { - return taosInitKeywordsTable(); -} +int32_t qInitKeywordsTable() { return taosInitKeywordsTable(); } void qCleanupKeywordsTable() { taosCleanupKeywordsTable(); } @@ -445,6 +441,98 @@ int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx return code; } +static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam) { + if (IS_VAR_DATA_TYPE(pVal->node.resType.type)) { + taosMemoryFreeClear(pVal->datum.p); + } + + if (pParam->is_null && 1 == *(pParam->is_null)) { + pVal->node.resType.type = TSDB_DATA_TYPE_NULL; + pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes; + return TSDB_CODE_SUCCESS; + } + + int32_t inputSize = (NULL != pParam->length ? *(pParam->length) : tDataTypes[pParam->buffer_type].bytes); + pVal->node.resType.type = pParam->buffer_type; + pVal->node.resType.bytes = inputSize; + + switch (pParam->buffer_type) { + case TSDB_DATA_TYPE_VARBINARY: + pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); + if (NULL == pVal->datum.p) { + return TSDB_CODE_OUT_OF_MEMORY; + } + varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); + memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes); + pVal->node.resType.bytes += VARSTR_HEADER_SIZE; + break; + case TSDB_DATA_TYPE_VARCHAR: + case TSDB_DATA_TYPE_GEOMETRY: + pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); + if (NULL == pVal->datum.p) { + return TSDB_CODE_OUT_OF_MEMORY; + } + varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); + strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes); + pVal->node.resType.bytes += VARSTR_HEADER_SIZE; + break; + case TSDB_DATA_TYPE_NCHAR: { + pVal->node.resType.bytes *= TSDB_NCHAR_SIZE; + pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); + if (NULL == pVal->datum.p) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + int32_t output = 0; + if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes, + &output)) { + return errno; + } + varDataSetLen(pVal->datum.p, output); + pVal->node.resType.bytes = output + VARSTR_HEADER_SIZE; + break; + } + default: { + int32_t code = nodesSetValueNodeValue(pVal, pParam->buffer); + if (code) { + return code; + } + break; + } + } + pVal->translate = true; + return TSDB_CODE_SUCCESS; +} + +int32_t qStmtBindParams2(SQuery* pQuery, TAOS_STMT2_BIND* pParams, int32_t colIdx) { + int32_t code = TSDB_CODE_SUCCESS; + + if (colIdx < 0) { + int32_t size = taosArrayGetSize(pQuery->pPlaceholderValues); + for (int32_t i = 0; i < size; ++i) { + code = setValueByBindParam2((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, i), pParams + i); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + } + } else { + code = setValueByBindParam2((SValueNode*)taosArrayGetP(pQuery->pPlaceholderValues, colIdx), pParams); + } + + if (TSDB_CODE_SUCCESS == code && (colIdx < 0 || colIdx + 1 == pQuery->placeholderNum)) { + nodesDestroyNode(pQuery->pRoot); + pQuery->pRoot = NULL; + code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot); + if (NULL == pQuery->pRoot) { + code = code; + } + } + if (TSDB_CODE_SUCCESS == code) { + rewriteExprAlias(pQuery->pRoot); + } + return code; +} + int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery) { int32_t code = translate(pCxt, pQuery, NULL); if (TSDB_CODE_SUCCESS == code) { diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 696222784e..ec48dd50ae 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1274,6 +1274,16 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { return TSDB_CODE_SUCCESS; } +static void filterFreeGroup(void *pItem) { + if (pItem == NULL) { + return; + } + + SFilterGroup *p = (SFilterGroup *)pItem; + taosMemoryFreeClear(p->unitIdxs); + taosMemoryFreeClear(p->unitFlags); +} + int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { SOperatorNode *node = (SOperatorNode *)tree; int32_t ret = TSDB_CODE_SUCCESS; @@ -1336,9 +1346,11 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { SFilterGroup fgroup = {0}; code = filterAddUnitToGroup(&fgroup, uidx); if (TSDB_CODE_SUCCESS != code) { + filterFreeGroup((void*)&fgroup); break; } if (NULL == taosArrayPush(group, &fgroup)) { + filterFreeGroup((void*)&fgroup); code = TSDB_CODE_OUT_OF_MEMORY; break; } @@ -1658,16 +1670,6 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan return TSDB_CODE_SUCCESS; } -static void filterFreeGroup(void *pItem) { - if (pItem == NULL) { - return; - } - - SFilterGroup *p = (SFilterGroup *)pItem; - taosMemoryFreeClear(p->unitIdxs); - taosMemoryFreeClear(p->unitFlags); -} - EDealRes fltTreeToGroup(SNode *pNode, void *pContext) { int32_t code = TSDB_CODE_SUCCESS; SArray *preGroup = NULL; @@ -2247,7 +2249,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { return TSDB_CODE_SCALAR_CONVERT_ERROR; } varDataSetLen(newValData, len); - (void)varDataCopy(fi->data, newValData); + varDataCopy(fi->data, newValData); } } @@ -2944,25 +2946,44 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t gResNum for (int32_t n = 0; n < usize; ++n) { SFilterUnit *u = (SFilterUnit *)taosArrayGetP((SArray *)colInfo->info, n); if (NULL == u) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_RANGE); + code = TSDB_CODE_OUT_OF_RANGE; + break; } - FLT_ERR_JRET(filterAddUnitFromUnit(info, &oinfo, u, &uidx)); - FLT_ERR_JRET(filterAddUnitToGroup(&ng, uidx)); + code = filterAddUnitFromUnit(info, &oinfo, u, &uidx); + if (TSDB_CODE_SUCCESS != code) { + break; + } + code = filterAddUnitToGroup(&ng, uidx); + if (TSDB_CODE_SUCCESS != code) { + break; + } + } + if (TSDB_CODE_SUCCESS != code) { + break; } continue; } + if (TSDB_CODE_SUCCESS != code) { + filterFreeGroup((void*)&ng); + FLT_ERR_JRET(code); + } if (colInfo->type != RANGE_TYPE_MR_CTX) { fltError("filterRewrite get invalid col type : %d", colInfo->type); FLT_ERR_JRET(TSDB_CODE_QRY_FILTER_INVALID_TYPE); } - FLT_ERR_JRET(filterAddGroupUnitFromCtx(info, &oinfo, colInfo->info, res->colIdx[m], &ng, optr, group)); + code = filterAddGroupUnitFromCtx(info, &oinfo, colInfo->info, res->colIdx[m], &ng, optr, group); + if (TSDB_CODE_SUCCESS != code) { + filterFreeGroup((void*)&ng); + FLT_ERR_JRET(code); + } } if (ng.unitNum > 0) { if (NULL == taosArrayPush(group, &ng)) { + filterFreeGroup((void*)&ng); FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } } @@ -4571,7 +4592,7 @@ int32_t filterConverNcharColumns(SFilterInfo *info, int32_t rows, bool *gotNchar if (k == varSrcLen) { /* NULL */ varDataLen(dst) = (VarDataLenT)varSrcLen; - (void)varDataCopy(dst, src); + varDataCopy(dst, src); continue; } bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), (TdUcs4 *)varDataVal(dst), bufSize, &len); diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index ee79c9a66e..f4f4780a01 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -74,7 +74,7 @@ int32_t sclConvertValueToSclParam(SValueNode *pValueNode, SScalarParam *out, int code = colDataSetVal(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); if (code != TSDB_CODE_SUCCESS) { - goto _exit; + goto _exit; } code = colInfoDataEnsureCapacity(out->columnData, 1, true); @@ -91,7 +91,7 @@ _exit: } int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockList) { - SSDataBlock *pb = taosArrayGetP(pBlockList, 0); + SSDataBlock *pb = taosArrayGetP(pBlockList, 0); if (NULL == pb) { SCL_ERR_RET(TSDB_CODE_OUT_OF_RANGE); } @@ -839,8 +839,8 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o } // 1=1 and tag_column = 1 - int32_t ind = (i >= params[m].numOfRows)? (params[m].numOfRows - 1):i; - char* p = colDataGetData(params[m].columnData, ind); + int32_t ind = (i >= params[m].numOfRows) ? (params[m].numOfRows - 1) : i; + char *p = colDataGetData(params[m].columnData, ind); GET_TYPED_DATA(value, bool, params[m].columnData->info.type, p); @@ -1029,7 +1029,7 @@ _return: EDealRes sclRewriteNullInOptr(SNode **pNode, SScalarCtx *ctx, EOperatorType opType) { if (opType <= OP_TYPE_CALC_MAX) { SValueNode *res = NULL; - ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&res); + ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode **)&res); if (NULL == res) { sclError("make value node failed"); return DEAL_RES_ERROR; @@ -1041,7 +1041,7 @@ EDealRes sclRewriteNullInOptr(SNode **pNode, SScalarCtx *ctx, EOperatorType opTy *pNode = (SNode *)res; } else { SValueNode *res = NULL; - ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&res); + ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode **)&res); if (NULL == res) { sclError("make value node failed"); return DEAL_RES_ERROR; @@ -1094,7 +1094,6 @@ static uint8_t sclGetOpValueNodeTsPrecision(SNode *pLeft, SNode *pRight) { return 0; } - int32_t sclConvertOpValueNodeTs(SOperatorNode *node) { if (node->pLeft && SCL_IS_VAR_VALUE_NODE(node->pLeft)) { if (node->pRight && (TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode *)node->pRight)->resType.type)) { @@ -1105,13 +1104,12 @@ int32_t sclConvertOpValueNodeTs(SOperatorNode *node) { if (node->pLeft && (TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode *)node->pLeft)->resType.type)) { if (SCL_IS_VAR_VALUE_NODE(node->pRight)) { SCL_ERR_RET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, node->pRight), - (SValueNode *)node->pRight)); + (SValueNode *)node->pRight)); } else if (QUERY_NODE_NODE_LIST == node->pRight->type) { SNode *pNode; FOREACH(pNode, ((SNodeListNode *)node->pRight)->pNodeList) { if (SCL_IS_VAR_VALUE_NODE(pNode)) { - SCL_ERR_RET( - sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, pNode), (SValueNode *)pNode)); + SCL_ERR_RET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, pNode), (SValueNode *)pNode)); } } } @@ -1120,7 +1118,6 @@ int32_t sclConvertOpValueNodeTs(SOperatorNode *node) { return TSDB_CODE_SUCCESS; } - int32_t sclConvertCaseWhenValueNodeTs(SCaseWhenNode *node) { if (NULL == node->pCase) { return TSDB_CODE_SUCCESS; @@ -1140,7 +1137,7 @@ int32_t sclConvertCaseWhenValueNodeTs(SCaseWhenNode *node) { FOREACH(pNode, node->pWhenThenList) { if (SCL_IS_VAR_VALUE_NODE(((SWhenThenNode *)pNode)->pWhen)) { SCL_ERR_RET(sclConvertToTsValueNode(((SExprNode *)node->pCase)->resType.precision, - (SValueNode *)((SWhenThenNode *)pNode)->pWhen)); + (SValueNode *)((SWhenThenNode *)pNode)->pWhen)); } } } @@ -1201,7 +1198,7 @@ EDealRes sclRewriteFunction(SNode **pNode, SScalarCtx *ctx) { } SValueNode *res = NULL; - ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&res); + ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode **)&res); if (NULL == res) { sclError("make value node failed"); sclFreeParam(&output); @@ -1275,7 +1272,7 @@ EDealRes sclRewriteLogic(SNode **pNode, SScalarCtx *ctx) { } SValueNode *res = NULL; - ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&res); + ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode **)&res); if (NULL == res) { sclError("make value node failed"); sclFreeParam(&output); @@ -1346,7 +1343,7 @@ EDealRes sclRewriteOperator(SNode **pNode, SScalarCtx *ctx) { } SValueNode *res = NULL; - ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&res); + ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode **)&res); if (NULL == res) { sclError("make value node failed"); sclFreeParam(&output); @@ -1409,7 +1406,7 @@ EDealRes sclRewriteCaseWhen(SNode **pNode, SScalarCtx *ctx) { } SValueNode *res = NULL; - ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&res); + ctx->code = nodesMakeNode(QUERY_NODE_VALUE, (SNode **)&res); if (NULL == res) { sclError("make value node failed"); sclFreeParam(&output); @@ -1426,7 +1423,8 @@ EDealRes sclRewriteCaseWhen(SNode **pNode, SScalarCtx *ctx) { } else { int32_t type = output.columnData->info.type; if (IS_VAR_DATA_TYPE(type)) { // todo refactor - res->datum.p = taosMemoryCalloc(varDataTLen(output.columnData->pData) + 1, sizeof(char)); // add \0 to the end for print json value + res->datum.p = taosMemoryCalloc(varDataTLen(output.columnData->pData) + 1, + sizeof(char)); // add \0 to the end for print json value if (NULL == res->datum.p) { sclError("calloc %d failed", (int)(varDataTLen(output.columnData->pData) + 1)); sclFreeParam(&output); @@ -1587,7 +1585,10 @@ EDealRes sclWalkTarget(SNode *pNode, SScalarCtx *ctx) { block->info.rows = res->numOfRows; sclFreeParam(res); - (void)taosHashRemove(ctx->pRes, (void *)&target->pExpr, POINTER_BYTES); + ctx->code = taosHashRemove(ctx->pRes, (void *)&target->pExpr, POINTER_BYTES); + if (TSDB_CODE_SUCCESS != ctx->code) { + return DEAL_RES_ERROR; + } return DEAL_RES_CONTINUE; } @@ -1683,8 +1684,7 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) { SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) || - TSDB_DATA_TYPE_VARBINARY == ldt.type || - TSDB_DATA_TYPE_VARBINARY == rdt.type || + TSDB_DATA_TYPE_VARBINARY == ldt.type || TSDB_DATA_TYPE_VARBINARY == 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; @@ -1720,13 +1720,14 @@ static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) { return TSDB_CODE_TSC_INVALID_OPERATION; } SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; - if (ldt.type == TSDB_DATA_TYPE_VARBINARY || !IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) || + if (ldt.type == TSDB_DATA_TYPE_VARBINARY || !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; } - if (nodesIsMatchRegularOp(pOp)) { - SValueNode* node = (SValueNode*)(pOp->pRight); - if(checkRegexPattern(node->literal) != TSDB_CODE_SUCCESS){ + SValueNode *node = (SValueNode *)(pOp->pRight); + if (!node->placeholderNo && nodesIsMatchRegularOp(pOp)) { + if (checkRegexPattern(node->literal) != TSDB_CODE_SUCCESS) { return TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR; } } @@ -1762,7 +1763,7 @@ static int32_t sclGetBitwiseOperatorResType(SOperatorNode *pOp) { } SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; - if(TSDB_DATA_TYPE_VARBINARY == ldt.type || TSDB_DATA_TYPE_VARBINARY == rdt.type){ + if (TSDB_DATA_TYPE_VARBINARY == ldt.type || TSDB_DATA_TYPE_VARBINARY == rdt.type) { return TSDB_CODE_TSC_INVALID_OPERATION; } pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT; @@ -1813,7 +1814,7 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { } sclFreeParam(res); - (void)taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); + SCL_ERR_JRET(taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES)); } _return: diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index b970bf5297..70d6f7d0ae 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -76,7 +76,7 @@ int32_t flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) { if (NULL == vnode->datum.p) { FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - (void)varDataCopy(vnode->datum.p, value); + varDataCopy(vnode->datum.p, value); vnode->node.resType.bytes = varDataLen(value); } else { vnode->node.resType.bytes = tDataTypes[dataType].bytes; diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index c29f7b8a5b..e14b772ea8 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -120,7 +120,9 @@ int32_t scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t SCL_ERR_RET(TSDB_CODE_APP_ERROR); } - (void)taosArrayPush(pBlockList, &res); + if (NULL == taosArrayPush(pBlockList, &res)) { + SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } *dataBlockId = taosArrayGetSize(pBlockList) - 1; res->info.id.blockId = *dataBlockId; *slotId = 0; @@ -161,7 +163,7 @@ int32_t scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) { if (NULL == vnode->datum.p) { SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - (void)varDataCopy(vnode->datum.p, value); + varDataCopy(vnode->datum.p, value); vnode->node.resType.bytes = varDataTLen(value); } else { vnode->node.resType.bytes = tDataTypes[dataType].bytes; @@ -1382,7 +1384,9 @@ int32_t makeCalculate(void *json, void *key, int32_t rightType, void *rightData, SNode *opNode = NULL; SCL_ERR_RET(makeJsonArrow(&src, &opNode, json, (char *)key)); - (void)taosArrayPush(blockList, &src); + if (NULL == taosArrayPush(blockList, &src)) { + SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } SCL_ERR_RET(makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse)); @@ -1909,7 +1913,7 @@ TEST(columnTest, bigint_column_multi_binary_column) { SArray *blockList = taosArrayInit(1, POINTER_BYTES); ASSERT_NE(blockList, nullptr); - (void)taosArrayPush(blockList, &src); + ASSERT_NE(taosArrayPush(blockList, &src), nullptr); SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); int16_t dataBlockId = 0, slotId = 0; diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 4e34a47902..bf88248259 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -144,7 +144,6 @@ int32_t schProcessExplainRsp(SSchJob *pJob, SSchTask *pTask, SExplainRsp *rsp) { int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDataBuf *pMsg, int32_t rspCode) { int32_t code = 0; - char *msg = pMsg->pData; int32_t msgSize = pMsg->len; int32_t msgType = pMsg->msgType; @@ -158,9 +157,9 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD } case TDMT_VND_CREATE_TABLE_RSP: { SVCreateTbBatchRsp batchRsp = {0}; - if (msg) { + if (pMsg->pData) { SDecoder coder = {0}; - tDecoderInit(&coder, msg, msgSize); + tDecoderInit(&coder, pMsg->pData, msgSize); code = tDecodeSVCreateTbBatchRsp(&coder, &batchRsp); if (TSDB_CODE_SUCCESS == code && batchRsp.nRsps > 0) { SCH_LOCK(SCH_WRITE, &pJob->resLock); @@ -206,16 +205,16 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD } SCH_ERR_JRET(rspCode); - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } case TDMT_VND_DROP_TABLE_RSP: { SVDropTbBatchRsp batchRsp = {0}; - if (msg) { + if (pMsg->pData) { SDecoder coder = {0}; - tDecoderInit(&coder, msg, msgSize); + tDecoderInit(&coder, pMsg->pData, msgSize); code = tDecodeSVDropTbBatchRsp(&coder, &batchRsp); if (TSDB_CODE_SUCCESS == code && batchRsp.nRsps > 0) { for (int32_t i = 0; i < batchRsp.nRsps; ++i) { @@ -232,16 +231,16 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD } SCH_ERR_JRET(rspCode); - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; } case TDMT_VND_ALTER_TABLE_RSP: { SVAlterTbRsp rsp = {0}; - if (msg) { + if (pMsg->pData) { SDecoder coder = {0}; - tDecoderInit(&coder, msg, msgSize); + tDecoderInit(&coder, pMsg->pData, msgSize); code = tDecodeSVAlterTbRsp(&coder, &rsp); tDecoderClear(&coder); SCH_ERR_JRET(code); @@ -253,11 +252,11 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD SCH_ERR_JRET(rspCode); - if (NULL == msg) { + if (NULL == pMsg->pData) { SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); } - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); break; @@ -265,10 +264,10 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD case TDMT_VND_SUBMIT_RSP: { SCH_ERR_JRET(rspCode); - if (msg) { + if (pMsg->pData) { SDecoder coder = {0}; SSubmitRsp2 *rsp = taosMemoryMalloc(sizeof(*rsp)); - tDecoderInit(&coder, msg, msgSize); + tDecoderInit(&coder, pMsg->pData, msgSize); code = tDecodeSSubmitRsp2(&coder, rsp); tDecoderClear(&coder); if (code) { @@ -319,7 +318,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD } } - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); @@ -328,10 +327,10 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD case TDMT_VND_DELETE_RSP: { SCH_ERR_JRET(rspCode); - if (msg) { + if (pMsg->pData) { SDecoder coder = {0}; SVDeleteRsp rsp = {0}; - tDecoderInit(&coder, msg, msgSize); + tDecoderInit(&coder, pMsg->pData, msgSize); if (tDecodeSVDeleteRsp(&coder, &rsp) < 0) { code = terrno; tDecoderClear(&coder); @@ -343,7 +342,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD SCH_TASK_DLOG("delete succeed, affectedRows:%" PRId64, rsp.affectedRows); } - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); @@ -352,7 +351,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD case TDMT_SCH_QUERY_RSP: case TDMT_SCH_MERGE_QUERY_RSP: { SCH_ERR_JRET(rspCode); - if (NULL == msg) { + if (NULL == pMsg->pData) { SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); } @@ -365,7 +364,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD } SQueryTableRsp rsp = {0}; - if (tDeserializeSQueryTableRsp(msg, msgSize, &rsp) < 0) { + if (tDeserializeSQueryTableRsp(pMsg->pData, msgSize, &rsp) < 0) { SCH_TASK_ELOG("tDeserializeSQueryTableRsp failed, msgSize:%d", msgSize); SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_MSG); } @@ -376,7 +375,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD (void)atomic_add_fetch_64(&pJob->resNumOfRows, rsp.affectedRows); - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); SCH_ERR_JRET(schProcessOnTaskSuccess(pJob, pTask)); @@ -384,7 +383,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD } case TDMT_SCH_EXPLAIN_RSP: { SCH_ERR_JRET(rspCode); - if (NULL == msg) { + if (NULL == pMsg->pData) { SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); } @@ -399,20 +398,20 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD } SExplainRsp rsp = {0}; - if (tDeserializeSExplainRsp(msg, msgSize, &rsp)) { + if (tDeserializeSExplainRsp(pMsg->pData, msgSize, &rsp)) { tFreeSExplainRsp(&rsp); SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } SCH_ERR_JRET(schProcessExplainRsp(pJob, pTask, &rsp)); - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); break; } case TDMT_SCH_FETCH_RSP: case TDMT_SCH_MERGE_FETCH_RSP: { - code = schProcessFetchRsp(pJob, pTask, msg, rspCode); - msg = NULL; + code = schProcessFetchRsp(pJob, pTask, pMsg->pData, rspCode); + pMsg->pData = NULL; SCH_ERR_JRET(code); break; } @@ -435,7 +434,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD _return: - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); } @@ -445,7 +444,6 @@ _return: int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDataBuf *pMsg, int32_t rspCode) { int32_t code = 0; int32_t msgType = pMsg->msgType; - char *msg = pMsg->pData; bool dropExecNode = (msgType == TDMT_SCH_LINK_BROKEN || SCH_NETWORK_ERR(rspCode)); if (SCH_IS_QUERY_JOB(pJob)) { @@ -467,7 +465,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa _return: - taosMemoryFreeClear(msg); + taosMemoryFreeClear(pMsg->pData); SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); } diff --git a/source/libs/stream/src/streamCheckStatus.c b/source/libs/stream/src/streamCheckStatus.c index 91196f31e0..41124d8543 100644 --- a/source/libs/stream/src/streamCheckStatus.c +++ b/source/libs/stream/src/streamCheckStatus.c @@ -65,12 +65,7 @@ int32_t streamTaskCheckStatus(SStreamTask* pTask, int32_t upstreamTaskId, int32_ ", prev:%" PRId64, id, upstreamTaskId, vgId, stage, pInfo->stage); // record the checkpoint failure id and sent to mnode - streamMutexLock(&pTask->lock); - ETaskStatus status = streamTaskGetStatus(pTask).state; - if (status == TASK_STATUS__CK) { - streamTaskSetFailedCheckpointId(pTask); - } - streamMutexUnlock(&pTask->lock); + streamTaskSetCheckpointFailed(pTask); } if (pInfo->stage != stage) { diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index d0bf24bd03..916aee4e6e 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -673,6 +673,15 @@ void streamTaskSetFailedCheckpointId(SStreamTask* pTask) { } } +void streamTaskSetCheckpointFailed(SStreamTask* pTask) { + streamMutexLock(&pTask->lock); + ETaskStatus status = streamTaskGetStatus(pTask).state; + if (status == TASK_STATUS__CK) { + streamTaskSetFailedCheckpointId(pTask); + } + streamMutexUnlock(&pTask->lock); +} + static int32_t getCheckpointDataMeta(const char* id, const char* path, SArray* list) { int32_t code = 0; int32_t cap = strlen(path) + 64; @@ -1111,26 +1120,20 @@ void streamTaskGetTriggerRecvStatus(SStreamTask* pTask, int32_t* pRecved, int32_ // record the dispatch checkpoint trigger info in the list // memory insufficient may cause the stream computing stopped -void streamTaskInitTriggerDispatchInfo(SStreamTask* pTask) { +int32_t streamTaskInitTriggerDispatchInfo(SStreamTask* pTask) { SActiveCheckpointInfo* pInfo = pTask->chkInfo.pActiveInfo; + int64_t now = taosGetTimestampMs(); - int64_t now = taosGetTimestampMs(); streamMutexLock(&pInfo->lock); - - // outputQ should be empty here - if (streamQueueGetNumOfUnAccessedItems(pTask->outputq.queue) > 0) { - stFatal("s-task:%s items are still in outputQ, failed to init trigger dispatch info", pTask->id.idStr); - return; - } - pInfo->dispatchTrigger = true; if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) { STaskDispatcherFixed* pDispatch = &pTask->outputInfo.fixedDispatcher; STaskTriggerSendInfo p = {.sendTs = now, .recved = false, .nodeId = pDispatch->nodeId, .taskId = pDispatch->taskId}; void* px = taosArrayPush(pInfo->pDispatchTriggerList, &p); - if (px == NULL) { - // pause the stream task, if memory not enough + if (px == NULL) { // pause the stream task, if memory not enough + streamMutexUnlock(&pInfo->lock); + return terrno; } } else { for (int32_t i = 0; i < streamTaskGetNumOfDownstream(pTask); ++i) { @@ -1141,13 +1144,15 @@ void streamTaskInitTriggerDispatchInfo(SStreamTask* pTask) { STaskTriggerSendInfo p = {.sendTs = now, .recved = false, .nodeId = pVgInfo->vgId, .taskId = pVgInfo->taskId}; void* px = taosArrayPush(pInfo->pDispatchTriggerList, &p); - if (px == NULL) { - // pause the stream task, if memory not enough + if (px == NULL) { // pause the stream task, if memory not enough + streamMutexUnlock(&pInfo->lock); + return terrno; } } } streamMutexUnlock(&pInfo->lock); + return 0; } int32_t streamTaskGetNumOfConfirmed(SActiveCheckpointInfo* pInfo) { diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 0bc090cdfe..ad1866807a 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -726,8 +726,11 @@ int32_t streamSearchAndAddBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, S } int32_t streamDispatchStreamBlock(SStreamTask* pTask) { - const char* id = pTask->id.idStr; - int32_t numOfElems = streamQueueGetNumOfItems(pTask->outputq.queue); + const char* id = pTask->id.idStr; + int32_t code = 0; + SStreamDataBlock* pBlock = NULL; + + int32_t numOfElems = streamQueueGetNumOfItems(pTask->outputq.queue); if (numOfElems > 0) { double size = SIZE_IN_MiB(taosQueueMemorySize(pTask->outputq.queue->pQueue)); int32_t numOfUnAccessed = streamQueueGetNumOfUnAccessedItems(pTask->outputq.queue); @@ -755,35 +758,49 @@ int32_t streamDispatchStreamBlock(SStreamTask* pTask) { stDebug("s-task:%s start to dispatch msg, set output status:%d", id, pTask->outputq.status); } - SStreamDataBlock* pBlock = NULL; - streamQueueNextItem(pTask->outputq.queue, (SStreamQueueItem**)&pBlock); - if (pBlock == NULL) { - atomic_store_8(&pTask->outputq.status, TASK_OUTPUT_STATUS__NORMAL); - stDebug("s-task:%s not dispatch since no elems in outputQ, output status:%d", id, pTask->outputq.status); - return 0; - } + while (1) { + streamQueueNextItem(pTask->outputq.queue, (SStreamQueueItem**)&pBlock); + if (pBlock == NULL) { + atomic_store_8(&pTask->outputq.status, TASK_OUTPUT_STATUS__NORMAL); + stDebug("s-task:%s not dispatch since no elems in outputQ, output status:%d", id, pTask->outputq.status); + return 0; + } - int32_t type = pBlock->type; - if (!(type == STREAM_INPUT__DATA_BLOCK || type == STREAM_INPUT__CHECKPOINT_TRIGGER || - type == STREAM_INPUT__TRANS_STATE)) { - stError("s-task:%s invalid dispatch block type:%d", id, type); - return TSDB_CODE_INTERNAL_ERROR; - } + int32_t type = pBlock->type; + if (!(type == STREAM_INPUT__DATA_BLOCK || type == STREAM_INPUT__CHECKPOINT_TRIGGER || + type == STREAM_INPUT__TRANS_STATE)) { + stError("s-task:%s invalid dispatch block type:%d", id, type); + return TSDB_CODE_INTERNAL_ERROR; + } - pTask->execInfo.dispatch += 1; + pTask->execInfo.dispatch += 1; - streamMutexLock(&pTask->msgInfo.lock); - initDispatchInfo(&pTask->msgInfo, pTask->execInfo.dispatch); - streamMutexUnlock(&pTask->msgInfo.lock); + streamMutexLock(&pTask->msgInfo.lock); + initDispatchInfo(&pTask->msgInfo, pTask->execInfo.dispatch); + streamMutexUnlock(&pTask->msgInfo.lock); - int32_t code = doBuildDispatchMsg(pTask, pBlock); - if (code == 0) { - destroyStreamDataBlock(pBlock); - } else { // todo handle build dispatch msg failed - } + code = doBuildDispatchMsg(pTask, pBlock); + if (code == 0) { + destroyStreamDataBlock(pBlock); + } else { // todo handle build dispatch msg failed + } - if (type == STREAM_INPUT__CHECKPOINT_TRIGGER) { - streamTaskInitTriggerDispatchInfo(pTask); + if (type == STREAM_INPUT__CHECKPOINT_TRIGGER) { + // outputQ should be empty here, otherwise, set the checkpoint failed due to the retrieve req happens + if (streamQueueGetNumOfUnAccessedItems(pTask->outputq.queue) > 0) { + stError("s-task:%s items are still in outputQ due to downstream retrieve, failed to init trigger dispatch", + pTask->id.idStr); + streamTaskSetCheckpointFailed(pTask); + clearBufferedDispatchMsg(pTask); + continue; + } + + code = streamTaskInitTriggerDispatchInfo(pTask); + if (code != TSDB_CODE_SUCCESS) { // todo handle error + } + } + + break; } code = sendDispatchMsg(pTask, pTask->msgInfo.pData); diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c index fca0bf403f..bf4567a273 100644 --- a/source/libs/stream/src/streamExec.c +++ b/source/libs/stream/src/streamExec.c @@ -98,14 +98,13 @@ static int32_t doDumpResult(SStreamTask* pTask, SStreamQueueItem* pItem, SArray* void streamTaskExecImpl(SStreamTask* pTask, SStreamQueueItem* pItem, int64_t* totalSize, int32_t* totalBlocks) { int32_t code = TSDB_CODE_SUCCESS; void* pExecutor = pTask->exec.pExecutor; - - *totalBlocks = 0; - *totalSize = 0; - int32_t size = 0; int32_t numOfBlocks = 0; SArray* pRes = NULL; + *totalBlocks = 0; + *totalSize = 0; + while (1) { if (pRes == NULL) { pRes = taosArrayInit(4, sizeof(SSDataBlock)); @@ -131,7 +130,8 @@ void streamTaskExecImpl(SStreamTask* pTask, SStreamQueueItem* pItem, int64_t* to if (pItem->type == STREAM_INPUT__DATA_RETRIEVE) { SSDataBlock block = {0}; const SStreamDataBlock* pRetrieveBlock = (const SStreamDataBlock*)pItem; - int32_t num = taosArrayGetSize(pRetrieveBlock->blocks); + + int32_t num = taosArrayGetSize(pRetrieveBlock->blocks); if (num != 1) { stError("s-task:%s invalid retrieve block number:%d, ignore", pTask->id.idStr, num); continue; @@ -244,9 +244,10 @@ static void streamScanHistoryDataImpl(SStreamTask* pTask, SArray* pRes, int32_t* SSDataBlock* output = NULL; uint64_t ts = 0; code = qExecTask(exec, &output, &ts); - if (code != TSDB_CODE_TSC_QUERY_KILLED && code != TSDB_CODE_SUCCESS) { + if (code != TSDB_CODE_TSC_QUERY_KILLED && code != TSDB_CODE_SUCCESS) { // if out of memory occurs, quit stError("s-task:%s scan-history data error occurred code:%s, continue scan-history", pTask->id.idStr, tstrerror(code)); + qResetTaskCode(exec); continue; } @@ -596,12 +597,32 @@ void streamProcessTransstateBlock(SStreamTask* pTask, SStreamDataBlock* pBlock) // static void streamTaskSetIdleInfo(SStreamTask* pTask, int32_t idleTime) { pTask->status.schedIdleTime = idleTime; } static void setLastExecTs(SStreamTask* pTask, int64_t ts) { pTask->status.lastExecTs = ts; } +static void doRecordThroughput(STaskExecStatisInfo* pInfo, int64_t totalBlocks, int64_t totalSize, int64_t blockSize, + double st, const char* id) { + double el = (taosGetTimestampMs() - st) / 1000.0; + + stDebug("s-task:%s batch of input blocks exec end, elapsed time:%.2fs, result size:%.2fMiB, numOfBlocks:%" PRId64, id, + el, SIZE_IN_MiB(totalSize), totalBlocks); + + pInfo->outputDataBlocks += totalBlocks; + pInfo->outputDataSize += totalSize; + if (fabs(el - 0.0) <= DBL_EPSILON) { + pInfo->procsThroughput = 0; + pInfo->outputThroughput = 0; + } else { + pInfo->outputThroughput = (totalSize / el); + pInfo->procsThroughput = (blockSize / el); + } +} + static void doStreamTaskExecImpl(SStreamTask* pTask, SStreamQueueItem* pBlock, int32_t num) { const char* id = pTask->id.idStr; int32_t blockSize = 0; int64_t st = taosGetTimestampMs(); SCheckpointInfo* pInfo = &pTask->chkInfo; int64_t ver = pInfo->processedVer; + int64_t totalSize = 0; + int32_t totalBlocks = 0; stDebug("s-task:%s start to process batch blocks, num:%d, type:%s", id, num, streamQueueItemGetTypeStr(pBlock->type)); @@ -611,23 +632,8 @@ static void doStreamTaskExecImpl(SStreamTask* pTask, SStreamQueueItem* pBlock, i return; } - int64_t totalSize = 0; - int32_t totalBlocks = 0; streamTaskExecImpl(pTask, pBlock, &totalSize, &totalBlocks); - - double el = (taosGetTimestampMs() - st) / 1000.0; - stDebug("s-task:%s batch of input blocks exec end, elapsed time:%.2fs, result size:%.2fMiB, numOfBlocks:%d", id, el, - SIZE_IN_MiB(totalSize), totalBlocks); - - pTask->execInfo.outputDataBlocks += totalBlocks; - pTask->execInfo.outputDataSize += totalSize; - if (fabs(el - 0.0) <= DBL_EPSILON) { - pTask->execInfo.procsThroughput = 0; - pTask->execInfo.outputThroughput = 0; - } else { - pTask->execInfo.outputThroughput = (totalSize / el); - pTask->execInfo.procsThroughput = (blockSize / el); - } + doRecordThroughput(&pTask->execInfo, totalBlocks, totalSize, blockSize, st, pTask->id.idStr); // update the currentVer if processing the submit blocks. if (!(pInfo->checkpointVer <= pInfo->nextProcessVer && ver >= pInfo->checkpointVer)) { diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index 084eb7b827..36d0086ac6 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -1224,7 +1224,7 @@ void streamMetaWUnLock(SStreamMeta* pMeta) { } int32_t streamMetaSendMsgBeforeCloseTasks(SStreamMeta* pMeta, SArray** pList) { - QRY_OPTR_CHECK(pList); + QRY_PARAM_CHECK(pList); int32_t code = 0; SArray* pTaskList = taosArrayDup(pMeta->pTaskList, NULL); @@ -1254,16 +1254,7 @@ int32_t streamMetaSendMsgBeforeCloseTasks(SStreamMeta* pMeta, SArray** pList) { continue; } - streamMutexLock(&pTask->lock); - - SStreamTaskState pState = streamTaskGetStatus(pTask); - if (pState.state == TASK_STATUS__CK) { - streamTaskSetFailedCheckpointId(pTask); - } else { - stDebug("s-task:%s status:%s not reset the checkpoint", pTask->id.idStr, pState.name); - } - - streamMutexUnlock(&pTask->lock); + streamTaskSetCheckpointFailed(pTask); streamMetaReleaseTask(pMeta, pTask); } diff --git a/source/libs/stream/src/streamMsg.c b/source/libs/stream/src/streamMsg.c index 8105614d76..1c512888e7 100644 --- a/source/libs/stream/src/streamMsg.c +++ b/source/libs/stream/src/streamMsg.c @@ -19,281 +19,347 @@ #include "streamInt.h" int32_t tEncodeStreamEpInfo(SEncoder* pEncoder, const SStreamUpstreamEpInfo* pInfo) { - if (tEncodeI32(pEncoder, pInfo->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pInfo->nodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pInfo->childId) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pInfo->epSet) < 0) return -1; - if (tEncodeI64(pEncoder, pInfo->stage) < 0) return -1; + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pInfo->taskId)); + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pInfo->nodeId)); + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pInfo->childId)); + TAOS_CHECK_RETURN(tEncodeSEpSet(pEncoder, &pInfo->epSet)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pInfo->stage)); return 0; } int32_t tDecodeStreamEpInfo(SDecoder* pDecoder, SStreamUpstreamEpInfo* pInfo) { - if (tDecodeI32(pDecoder, &pInfo->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pInfo->nodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pInfo->childId) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &pInfo->epSet) < 0) return -1; - if (tDecodeI64(pDecoder, &pInfo->stage) < 0) return -1; + TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pInfo->taskId)); + TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pInfo->nodeId)); + TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pInfo->childId)); + TAOS_CHECK_RETURN(tDecodeSEpSet(pDecoder, &pInfo->epSet)); + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pInfo->stage)); return 0; } int32_t tEncodeStreamCheckpointSourceReq(SEncoder* pEncoder, const SStreamCheckpointSourceReq* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->checkpointId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->nodeId) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pReq->mgmtEps) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->mnodeId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->expireTime) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->transId) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->mndTrigger) < 0) return -1; + TAOS_CHECK_RETURN(tStartEncode(pEncoder)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pReq->checkpointId)); + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->taskId)); + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->nodeId)); + TAOS_CHECK_RETURN(tEncodeSEpSet(pEncoder, &pReq->mgmtEps)); + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->mnodeId)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pReq->expireTime)); + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pReq->transId)); + TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pReq->mndTrigger)); tEndEncode(pEncoder); return pEncoder->pos; } int32_t tDecodeStreamCheckpointSourceReq(SDecoder* pDecoder, SStreamCheckpointSourceReq* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->checkpointId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->nodeId) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &pReq->mgmtEps) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->mnodeId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->expireTime) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->transId) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->mndTrigger) < 0) return -1; + TAOS_CHECK_RETURN(tStartDecode(pDecoder)); + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pReq->streamId)); + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pReq->checkpointId)); + TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->taskId)); + TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->nodeId)); + TAOS_CHECK_RETURN(tDecodeSEpSet(pDecoder, &pReq->mgmtEps)); + TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->mnodeId)); + TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pReq->expireTime)); + TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pReq->transId)); + TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pReq->mndTrigger)); tEndDecode(pDecoder); return 0; } int32_t tEncodeStreamCheckpointSourceRsp(SEncoder* pEncoder, const SStreamCheckpointSourceRsp* pRsp) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1; - if (tEncodeI64(pEncoder, pRsp->checkpointId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->nodeId) < 0) return -1; - if (tEncodeI64(pEncoder, pRsp->expireTime) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->success) < 0) return -1; + TAOS_CHECK_RETURN(tStartEncode(pEncoder)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pRsp->streamId)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pRsp->checkpointId)); + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pRsp->taskId)); + TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pRsp->nodeId)); + TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pRsp->expireTime)); + TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pRsp->success)); tEndEncode(pEncoder); return pEncoder->pos; } int32_t tEncodeStreamTaskUpdateMsg(SEncoder* pEncoder, const SStreamTaskNodeUpdateMsg* pMsg) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pMsg->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pMsg->taskId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pMsg->streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pMsg->taskId)); int32_t size = taosArrayGetSize(pMsg->pNodeList); - if (tEncodeI32(pEncoder, size) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size)); for (int32_t i = 0; i < size; ++i) { SNodeUpdateInfo* pInfo = taosArrayGet(pMsg->pNodeList, i); if (pInfo == NULL) { - return terrno; + TAOS_CHECK_EXIT(terrno); } - if (tEncodeI32(pEncoder, pInfo->nodeId) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pInfo->prevEp) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pInfo->newEp) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pInfo->nodeId)); + TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pInfo->prevEp)); + TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pInfo->newEp)); } // todo this new attribute will be result in being incompatible with previous version - if (tEncodeI32(pEncoder, pMsg->transId) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pMsg->transId)); tEndEncode(pEncoder); - return pEncoder->pos; +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeStreamTaskUpdateMsg(SDecoder* pDecoder, SStreamTaskNodeUpdateMsg* pMsg) { int32_t code = 0; + int32_t lino; - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pMsg->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pMsg->taskId) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pMsg->streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pMsg->taskId)); int32_t size = 0; - if (tDecodeI32(pDecoder, &size) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size)); pMsg->pNodeList = taosArrayInit(size, sizeof(SNodeUpdateInfo)); + if (pMsg->pNodeList == NULL) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < size; ++i) { SNodeUpdateInfo info = {0}; - if (tDecodeI32(pDecoder, &info.nodeId) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &info.prevEp) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &info.newEp) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &info.nodeId)); + TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &info.prevEp)); + TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &info.newEp)); - void* p = taosArrayPush(pMsg->pNodeList, &info); - if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + if (taosArrayPush(pMsg->pNodeList, &info) == NULL) { + TAOS_CHECK_EXIT(terrno); } } - if (tDecodeI32(pDecoder, &pMsg->transId) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pMsg->transId)); tEndDecode(pDecoder); +_exit: return code; } int32_t tEncodeStreamTaskCheckReq(SEncoder* pEncoder, const SStreamTaskCheckReq* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->reqId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->downstreamNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->downstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->childId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->stage) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->reqId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->upstreamNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->upstreamTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->downstreamNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->downstreamTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->childId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->stage)); tEndEncode(pEncoder); - return pEncoder->pos; + +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeStreamTaskCheckReq(SDecoder* pDecoder, SStreamTaskCheckReq* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->reqId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->upstreamNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->upstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->downstreamNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->downstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->childId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->stage) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->reqId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->upstreamNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->upstreamTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->downstreamNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->downstreamTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->childId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->stage)); tEndDecode(pDecoder); - return 0; + +_exit: + return code; } int32_t tEncodeStreamTaskCheckRsp(SEncoder* pEncoder, const SStreamTaskCheckRsp* pRsp) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pRsp->reqId) < 0) return -1; - if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->upstreamNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->upstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->downstreamNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->downstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->childId) < 0) return -1; - if (tEncodeI64(pEncoder, pRsp->oldStage) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->status) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pRsp->reqId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pRsp->streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->upstreamNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->upstreamTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->downstreamNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->downstreamTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pRsp->childId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pRsp->oldStage)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pRsp->status)); tEndEncode(pEncoder); - return pEncoder->pos; + +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeStreamTaskCheckRsp(SDecoder* pDecoder, SStreamTaskCheckRsp* pRsp) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pRsp->reqId) < 0) return -1; - if (tDecodeI64(pDecoder, &pRsp->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->upstreamNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->upstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->downstreamNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->downstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->childId) < 0) return -1; - if (tDecodeI64(pDecoder, &pRsp->oldStage) < 0) return -1; - if (tDecodeI8(pDecoder, &pRsp->status) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pRsp->reqId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pRsp->streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->upstreamNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->upstreamTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->downstreamNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->downstreamTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->childId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pRsp->oldStage)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pRsp->status)); tEndDecode(pDecoder); - return 0; + +_exit: + return code; } int32_t tEncodeStreamCheckpointReadyMsg(SEncoder* pEncoder, const SStreamCheckpointReadyMsg* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->checkpointId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->downstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->downstreamNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->childId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->checkpointId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->downstreamTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->downstreamNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->upstreamTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->upstreamNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->childId)); tEndEncode(pEncoder); - return pEncoder->pos; + +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeStreamCheckpointReadyMsg(SDecoder* pDecoder, SStreamCheckpointReadyMsg* pRsp) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pRsp->streamId) < 0) return -1; - if (tDecodeI64(pDecoder, &pRsp->checkpointId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->downstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->downstreamNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->upstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->upstreamNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->childId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pRsp->streamId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pRsp->checkpointId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->downstreamTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->downstreamNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->upstreamTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->upstreamNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pRsp->childId)); tEndDecode(pDecoder); - return 0; + +_exit: + return code; } int32_t tEncodeStreamDispatchReq(SEncoder* pEncoder, const SStreamDispatchReq* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->stage) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->msgId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->srcVgId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->type) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->type) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamChildId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamRelTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->blockNum) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->totalLen) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->stage)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->msgId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->srcVgId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->type)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->taskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->type)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->upstreamTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->upstreamChildId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->upstreamNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->upstreamRelTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->blockNum)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->totalLen)); if (taosArrayGetSize(pReq->data) != pReq->blockNum || taosArrayGetSize(pReq->dataLen) != pReq->blockNum) { stError("invalid dispatch req msg"); - return TSDB_CODE_INVALID_MSG; + TAOS_CHECK_EXIT(TSDB_CODE_INVALID_MSG); } for (int32_t i = 0; i < pReq->blockNum; i++) { int32_t* pLen = taosArrayGet(pReq->dataLen, i); void* data = taosArrayGetP(pReq->data, i); if (data == NULL || pLen == NULL) { - return terrno; + TAOS_CHECK_EXIT(terrno); } - if (tEncodeI32(pEncoder, *pLen) < 0) return -1; - if (tEncodeBinary(pEncoder, data, *pLen) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, *pLen)); + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, data, *pLen)); } tEndEncode(pEncoder); - return pEncoder->pos; +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->stage) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->msgId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->srcVgId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->type) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->type) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->upstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->upstreamChildId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->upstreamNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->upstreamRelTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->blockNum) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->totalLen) < 0) return -1; + int32_t code = 0; + int32_t lino; - pReq->data = taosArrayInit(pReq->blockNum, sizeof(void*)); - pReq->dataLen = taosArrayInit(pReq->blockNum, sizeof(int32_t)); + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->stage)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->msgId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->srcVgId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->type)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->taskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->type)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->upstreamTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->upstreamChildId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->upstreamNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->upstreamRelTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->blockNum)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->totalLen)); + + if ((pReq->data = taosArrayInit(pReq->blockNum, sizeof(void*))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } + if ((pReq->dataLen = taosArrayInit(pReq->blockNum, sizeof(int32_t))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < pReq->blockNum; i++) { int32_t len1; uint64_t len2; void* data; - if (tDecodeI32(pDecoder, &len1) < 0) return -1; - if (tDecodeBinaryAlloc(pDecoder, &data, &len2) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &len1)); + TAOS_CHECK_EXIT(tDecodeBinaryAlloc(pDecoder, &data, &len2)); if (len1 != len2) { - return TSDB_CODE_INVALID_MSG; + TAOS_CHECK_EXIT(TSDB_CODE_INVALID_MSG); } - void* p = taosArrayPush(pReq->dataLen, &len1); - if (p == NULL) { - tEndDecode(pDecoder); - return TSDB_CODE_OUT_OF_MEMORY; + if (taosArrayPush(pReq->dataLen, &len1) == NULL) { + TAOS_CHECK_EXIT(terrno); } - p = taosArrayPush(pReq->data, &data); - if (p == NULL) { - tEndDecode(pDecoder); - return TSDB_CODE_OUT_OF_MEMORY; + if (taosArrayPush(pReq->data, &data) == NULL) { + TAOS_CHECK_EXIT(terrno); } } tEndDecode(pDecoder); - return 0; +_exit: + return code; } void tCleanupStreamDispatchReq(SStreamDispatchReq* pReq) { @@ -302,188 +368,220 @@ void tCleanupStreamDispatchReq(SStreamDispatchReq* pReq) { } int32_t tEncodeStreamRetrieveReq(SEncoder* pEncoder, const SStreamRetrieveReq* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->reqId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->dstNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->dstTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->srcNodeId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->srcTaskId) < 0) return -1; - if (tEncodeBinary(pEncoder, (const uint8_t*)pReq->pRetrieve, pReq->retrieveLen) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->reqId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->dstNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->dstTaskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->srcNodeId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->srcTaskId)); + TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, (const uint8_t*)pReq->pRetrieve, pReq->retrieveLen)); tEndEncode(pEncoder); - return pEncoder->pos; + +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeStreamRetrieveReq(SDecoder* pDecoder, SStreamRetrieveReq* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->reqId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->dstNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->dstTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->srcNodeId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->srcTaskId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->streamId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->reqId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->dstNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->dstTaskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->srcNodeId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->srcTaskId)); uint64_t len = 0; - if (tDecodeBinaryAlloc(pDecoder, (void**)&pReq->pRetrieve, &len) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeBinaryAlloc(pDecoder, (void**)&pReq->pRetrieve, &len)); pReq->retrieveLen = (int32_t)len; tEndDecode(pDecoder); - return 0; + +_exit: + return code; } void tCleanupStreamRetrieveReq(SStreamRetrieveReq* pReq) { taosMemoryFree(pReq->pRetrieve); } int32_t tEncodeStreamTaskCheckpointReq(SEncoder* pEncoder, const SStreamTaskCheckpointReq* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->nodeId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->taskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->nodeId)); tEndEncode(pEncoder); - return 0; + +_exit: + return code; } int32_t tDecodeStreamTaskCheckpointReq(SDecoder* pDecoder, SStreamTaskCheckpointReq* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->nodeId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->taskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->nodeId)); tEndDecode(pDecoder); - return 0; + +_exit: + return code; } int32_t tEncodeStreamHbMsg(SEncoder* pEncoder, const SStreamHbMsg* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->vgId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->numOfTasks) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->vgId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->numOfTasks)); for (int32_t i = 0; i < pReq->numOfTasks; ++i) { STaskStatusEntry* ps = taosArrayGet(pReq->pTaskStatus, i); if (ps == NULL) { - return terrno; + TAOS_CHECK_EXIT(terrno); } - if (tEncodeI64(pEncoder, ps->id.streamId) < 0) return -1; - if (tEncodeI32(pEncoder, ps->id.taskId) < 0) return -1; - if (tEncodeI32(pEncoder, ps->status) < 0) return -1; - if (tEncodeI64(pEncoder, ps->stage) < 0) return -1; - if (tEncodeI32(pEncoder, ps->nodeId) < 0) return -1; - if (tEncodeDouble(pEncoder, ps->inputQUsed) < 0) return -1; - if (tEncodeDouble(pEncoder, ps->inputRate) < 0) return -1; - if (tEncodeDouble(pEncoder, ps->procsTotal) < 0) return -1; - if (tEncodeDouble(pEncoder, ps->procsThroughput) < 0) return -1; - if (tEncodeDouble(pEncoder, ps->outputTotal) < 0) return -1; - if (tEncodeDouble(pEncoder, ps->outputThroughput) < 0) return -1; - if (tEncodeDouble(pEncoder, ps->sinkQuota) < 0) return -1; - if (tEncodeDouble(pEncoder, ps->sinkDataSize) < 0) return -1; - if (tEncodeI64(pEncoder, ps->processedVer) < 0) return -1; - if (tEncodeI64(pEncoder, ps->verRange.minVer) < 0) return -1; - if (tEncodeI64(pEncoder, ps->verRange.maxVer) < 0) return -1; - if (tEncodeI64(pEncoder, ps->checkpointInfo.activeId) < 0) return -1; - if (tEncodeI8(pEncoder, ps->checkpointInfo.failed) < 0) return -1; - if (tEncodeI32(pEncoder, ps->checkpointInfo.activeTransId) < 0) return -1; - if (tEncodeI64(pEncoder, ps->checkpointInfo.latestId) < 0) return -1; - if (tEncodeI64(pEncoder, ps->checkpointInfo.latestVer) < 0) return -1; - if (tEncodeI64(pEncoder, ps->checkpointInfo.latestTime) < 0) return -1; - if (tEncodeI64(pEncoder, ps->checkpointInfo.latestSize) < 0) return -1; - if (tEncodeI8(pEncoder, ps->checkpointInfo.remoteBackup) < 0) return -1; - if (tEncodeI8(pEncoder, ps->checkpointInfo.consensusChkptId) < 0) return -1; - if (tEncodeI64(pEncoder, ps->checkpointInfo.consensusTs) < 0) return -1; - if (tEncodeI64(pEncoder, ps->startTime) < 0) return -1; - if (tEncodeI64(pEncoder, ps->startCheckpointId) < 0) return -1; - if (tEncodeI64(pEncoder, ps->startCheckpointVer) < 0) return -1; - if (tEncodeI64(pEncoder, ps->hTaskId) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->id.streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, ps->id.taskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, ps->status)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->stage)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, ps->nodeId)); + TAOS_CHECK_EXIT(tEncodeDouble(pEncoder, ps->inputQUsed)); + TAOS_CHECK_EXIT(tEncodeDouble(pEncoder, ps->inputRate)); + TAOS_CHECK_EXIT(tEncodeDouble(pEncoder, ps->procsTotal)); + TAOS_CHECK_EXIT(tEncodeDouble(pEncoder, ps->procsThroughput)); + TAOS_CHECK_EXIT(tEncodeDouble(pEncoder, ps->outputTotal)); + TAOS_CHECK_EXIT(tEncodeDouble(pEncoder, ps->outputThroughput)); + TAOS_CHECK_EXIT(tEncodeDouble(pEncoder, ps->sinkQuota)); + TAOS_CHECK_EXIT(tEncodeDouble(pEncoder, ps->sinkDataSize)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->processedVer)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->verRange.minVer)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->verRange.maxVer)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->checkpointInfo.activeId)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, ps->checkpointInfo.failed)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, ps->checkpointInfo.activeTransId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->checkpointInfo.latestId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->checkpointInfo.latestVer)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->checkpointInfo.latestTime)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->checkpointInfo.latestSize)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, ps->checkpointInfo.remoteBackup)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, ps->checkpointInfo.consensusChkptId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->checkpointInfo.consensusTs)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->startTime)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->startCheckpointId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->startCheckpointVer)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, ps->hTaskId)); } int32_t numOfVgs = taosArrayGetSize(pReq->pUpdateNodes); - if (tEncodeI32(pEncoder, numOfVgs) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, numOfVgs)); for (int j = 0; j < numOfVgs; ++j) { int32_t* pVgId = taosArrayGet(pReq->pUpdateNodes, j); if (pVgId == NULL) { - return terrno; + TAOS_CHECK_EXIT(terrno); } - if (tEncodeI32(pEncoder, *pVgId) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, *pVgId)); } - if (tEncodeI32(pEncoder, pReq->msgId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->ts) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->msgId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->ts)); tEndEncode(pEncoder); - return pEncoder->pos; + +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeStreamHbMsg(SDecoder* pDecoder, SStreamHbMsg* pReq) { int32_t code = 0; + int32_t lino; - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->vgId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->numOfTasks) < 0) return -1; + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->vgId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->numOfTasks)); - pReq->pTaskStatus = taosArrayInit(pReq->numOfTasks, sizeof(STaskStatusEntry)); + if ((pReq->pTaskStatus = taosArrayInit(pReq->numOfTasks, sizeof(STaskStatusEntry))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < pReq->numOfTasks; ++i) { int32_t taskId = 0; STaskStatusEntry entry = {0}; - if (tDecodeI64(pDecoder, &entry.id.streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &entry.status) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.stage) < 0) return -1; - if (tDecodeI32(pDecoder, &entry.nodeId) < 0) return -1; - if (tDecodeDouble(pDecoder, &entry.inputQUsed) < 0) return -1; - if (tDecodeDouble(pDecoder, &entry.inputRate) < 0) return -1; - if (tDecodeDouble(pDecoder, &entry.procsTotal) < 0) return -1; - if (tDecodeDouble(pDecoder, &entry.procsThroughput) < 0) return -1; - if (tDecodeDouble(pDecoder, &entry.outputTotal) < 0) return -1; - if (tDecodeDouble(pDecoder, &entry.outputThroughput) < 0) return -1; - if (tDecodeDouble(pDecoder, &entry.sinkQuota) < 0) return -1; - if (tDecodeDouble(pDecoder, &entry.sinkDataSize) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.processedVer) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.verRange.minVer) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.verRange.maxVer) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.checkpointInfo.activeId) < 0) return -1; - if (tDecodeI8(pDecoder, &entry.checkpointInfo.failed) < 0) return -1; - if (tDecodeI32(pDecoder, &entry.checkpointInfo.activeTransId) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.id.streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &taskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &entry.status)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.stage)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &entry.nodeId)); + TAOS_CHECK_EXIT(tDecodeDouble(pDecoder, &entry.inputQUsed)); + TAOS_CHECK_EXIT(tDecodeDouble(pDecoder, &entry.inputRate)); + TAOS_CHECK_EXIT(tDecodeDouble(pDecoder, &entry.procsTotal)); + TAOS_CHECK_EXIT(tDecodeDouble(pDecoder, &entry.procsThroughput)); + TAOS_CHECK_EXIT(tDecodeDouble(pDecoder, &entry.outputTotal)); + TAOS_CHECK_EXIT(tDecodeDouble(pDecoder, &entry.outputThroughput)); + TAOS_CHECK_EXIT(tDecodeDouble(pDecoder, &entry.sinkQuota)); + TAOS_CHECK_EXIT(tDecodeDouble(pDecoder, &entry.sinkDataSize)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.processedVer)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.verRange.minVer)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.verRange.maxVer)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.checkpointInfo.activeId)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &entry.checkpointInfo.failed)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &entry.checkpointInfo.activeTransId)); - if (tDecodeI64(pDecoder, &entry.checkpointInfo.latestId) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.checkpointInfo.latestVer) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.checkpointInfo.latestTime) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.checkpointInfo.latestSize) < 0) return -1; - if (tDecodeI8(pDecoder, &entry.checkpointInfo.remoteBackup) < 0) return -1; - if (tDecodeI8(pDecoder, &entry.checkpointInfo.consensusChkptId) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.checkpointInfo.consensusTs) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.startTime) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.startCheckpointId) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.startCheckpointVer) < 0) return -1; - if (tDecodeI64(pDecoder, &entry.hTaskId) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.checkpointInfo.latestId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.checkpointInfo.latestVer)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.checkpointInfo.latestTime)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.checkpointInfo.latestSize)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &entry.checkpointInfo.remoteBackup)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &entry.checkpointInfo.consensusChkptId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.checkpointInfo.consensusTs)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.startTime)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.startCheckpointId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.startCheckpointVer)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &entry.hTaskId)); entry.id.taskId = taskId; - void* p = taosArrayPush(pReq->pTaskStatus, &entry); - if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + if (taosArrayPush(pReq->pTaskStatus, &entry) == NULL) { + TAOS_CHECK_EXIT(terrno); } } int32_t numOfVgs = 0; - if (tDecodeI32(pDecoder, &numOfVgs) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &numOfVgs)); - pReq->pUpdateNodes = taosArrayInit(numOfVgs, sizeof(int32_t)); + if ((pReq->pUpdateNodes = taosArrayInit(numOfVgs, sizeof(int32_t))) == NULL) { + TAOS_CHECK_EXIT(terrno); + } for (int j = 0; j < numOfVgs; ++j) { int32_t vgId = 0; - if (tDecodeI32(pDecoder, &vgId) < 0) return -1; - void* p = taosArrayPush(pReq->pUpdateNodes, &vgId); - if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &vgId)); + if (taosArrayPush(pReq->pUpdateNodes, &vgId) == NULL) { + TAOS_CHECK_EXIT(terrno); } } - if (tDecodeI32(pDecoder, &pReq->msgId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->ts) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->msgId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->ts)); tEndDecode(pDecoder); - return 0; - _err: - tEndDecode(pDecoder); +_exit: return code; } @@ -508,212 +606,250 @@ void tCleanupStreamHbMsg(SStreamHbMsg* pMsg) { } int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pTask->ver) < 0) return -1; - if (tEncodeI64(pEncoder, pTask->id.streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->id.taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->info.totalLevel) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->info.taskLevel) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->outputInfo.type) < 0) return -1; - if (tEncodeI16(pEncoder, pTask->msgInfo.msgType) < 0) return -1; + int32_t code = 0; + int32_t lino; - if (tEncodeI8(pEncoder, pTask->status.taskStatus) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->status.schedStatus) < 0) return -1; + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->ver)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->id.streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->id.taskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.totalLevel)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.taskLevel)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->outputInfo.type)); + TAOS_CHECK_EXIT(tEncodeI16(pEncoder, pTask->msgInfo.msgType)); - if (tEncodeI32(pEncoder, pTask->info.selfChildId) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->info.nodeId) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pTask->info.epSet) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pTask->info.mnodeEpset) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->status.taskStatus)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->status.schedStatus)); - if (tEncodeI64(pEncoder, pTask->chkInfo.checkpointId) < 0) return -1; - if (tEncodeI64(pEncoder, pTask->chkInfo.checkpointVer) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->info.fillHistory) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.selfChildId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.nodeId)); + TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->info.epSet)); + TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->info.mnodeEpset)); - if (tEncodeI64(pEncoder, pTask->hTaskInfo.id.streamId)) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->chkInfo.checkpointId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->chkInfo.checkpointVer)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.fillHistory)); + + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->hTaskInfo.id.streamId)); int32_t taskId = pTask->hTaskInfo.id.taskId; - if (tEncodeI32(pEncoder, taskId)) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, taskId)); - if (tEncodeI64(pEncoder, pTask->streamTaskId.streamId)) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->streamTaskId.streamId)); taskId = pTask->streamTaskId.taskId; - if (tEncodeI32(pEncoder, taskId)) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, taskId)); - if (tEncodeU64(pEncoder, pTask->dataRange.range.minVer)) return -1; - if (tEncodeU64(pEncoder, pTask->dataRange.range.maxVer)) return -1; - if (tEncodeI64(pEncoder, pTask->dataRange.window.skey)) return -1; - if (tEncodeI64(pEncoder, pTask->dataRange.window.ekey)) return -1; + TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTask->dataRange.range.minVer)); + TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTask->dataRange.range.maxVer)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->dataRange.window.skey)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->dataRange.window.ekey)); int32_t epSz = taosArrayGetSize(pTask->upstreamInfo.pList); - if (tEncodeI32(pEncoder, epSz) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, epSz)); for (int32_t i = 0; i < epSz; i++) { SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i); - if (tEncodeStreamEpInfo(pEncoder, pInfo) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeStreamEpInfo(pEncoder, pInfo)); } if (pTask->info.taskLevel != TASK_LEVEL__SINK) { - if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->exec.qmsg)); } if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) { - if (tEncodeI64(pEncoder, pTask->outputInfo.tbSink.stbUid) < 0) return -1; - if (tEncodeCStr(pEncoder, pTask->outputInfo.tbSink.stbFullName) < 0) return -1; - if (tEncodeSSchemaWrapper(pEncoder, pTask->outputInfo.tbSink.pSchemaWrapper) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->outputInfo.tbSink.stbUid)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->outputInfo.tbSink.stbFullName)); + TAOS_CHECK_EXIT(tEncodeSSchemaWrapper(pEncoder, pTask->outputInfo.tbSink.pSchemaWrapper)); } else if (pTask->outputInfo.type == TASK_OUTPUT__SMA) { - if (tEncodeI64(pEncoder, pTask->outputInfo.smaSink.smaId) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->outputInfo.smaSink.smaId)); } else if (pTask->outputInfo.type == TASK_OUTPUT__FETCH) { - if (tEncodeI8(pEncoder, pTask->outputInfo.fetchSink.reserved) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->outputInfo.fetchSink.reserved)); } else if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) { - if (tEncodeI32(pEncoder, pTask->outputInfo.fixedDispatcher.taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->outputInfo.fixedDispatcher.nodeId) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pTask->outputInfo.fixedDispatcher.epSet) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->outputInfo.fixedDispatcher.taskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->outputInfo.fixedDispatcher.nodeId)); + TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->outputInfo.fixedDispatcher.epSet)); } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) { - if (tSerializeSUseDbRspImp(pEncoder, &pTask->outputInfo.shuffleDispatcher.dbInfo) < 0) return -1; - if (tEncodeCStr(pEncoder, pTask->outputInfo.shuffleDispatcher.stbFullName) < 0) return -1; + TAOS_CHECK_EXIT(tSerializeSUseDbRspImp(pEncoder, &pTask->outputInfo.shuffleDispatcher.dbInfo)); + TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->outputInfo.shuffleDispatcher.stbFullName)); } - if (tEncodeI64(pEncoder, pTask->info.delaySchedParam) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->subtableWithoutMd5) < 0) return -1; - if (tEncodeCStrWithLen(pEncoder, pTask->reserve, sizeof(pTask->reserve) - 1) < 0) return -1; + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->info.delaySchedParam)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->subtableWithoutMd5)); + TAOS_CHECK_EXIT(tEncodeCStrWithLen(pEncoder, pTask->reserve, sizeof(pTask->reserve) - 1)); tEndEncode(pEncoder); - return 0; +_exit: + return code; } int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { int32_t taskId = 0; + int32_t code = 0; + int32_t lino; - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pTask->ver) < 0) return -1; - if (pTask->ver <= SSTREAM_TASK_INCOMPATIBLE_VER || pTask->ver > SSTREAM_TASK_VER) return -1; + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->ver)); + if (pTask->ver <= SSTREAM_TASK_INCOMPATIBLE_VER || pTask->ver > SSTREAM_TASK_VER) { + TAOS_CHECK_EXIT(TSDB_CODE_INVALID_MSG); + } - if (tDecodeI64(pDecoder, &pTask->id.streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->id.taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->info.totalLevel) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->info.taskLevel) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->outputInfo.type) < 0) return -1; - if (tDecodeI16(pDecoder, &pTask->msgInfo.msgType) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->id.streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->id.taskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.totalLevel)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.taskLevel)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->outputInfo.type)); + TAOS_CHECK_EXIT(tDecodeI16(pDecoder, &pTask->msgInfo.msgType)); - if (tDecodeI8(pDecoder, &pTask->status.taskStatus) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->status.schedStatus) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->status.taskStatus)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->status.schedStatus)); - if (tDecodeI32(pDecoder, &pTask->info.selfChildId) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->info.nodeId) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &pTask->info.epSet) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &pTask->info.mnodeEpset) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.selfChildId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.nodeId)); + TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->info.epSet)); + TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->info.mnodeEpset)); - if (tDecodeI64(pDecoder, &pTask->chkInfo.checkpointId) < 0) return -1; - if (tDecodeI64(pDecoder, &pTask->chkInfo.checkpointVer) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->info.fillHistory) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->chkInfo.checkpointId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->chkInfo.checkpointVer)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.fillHistory)); - if (tDecodeI64(pDecoder, &pTask->hTaskInfo.id.streamId)) return -1; - if (tDecodeI32(pDecoder, &taskId)) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->hTaskInfo.id.streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &taskId)); pTask->hTaskInfo.id.taskId = taskId; - if (tDecodeI64(pDecoder, &pTask->streamTaskId.streamId)) return -1; - if (tDecodeI32(pDecoder, &taskId)) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->streamTaskId.streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &taskId)); pTask->streamTaskId.taskId = taskId; - if (tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.minVer)) return -1; - if (tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.maxVer)) return -1; - if (tDecodeI64(pDecoder, &pTask->dataRange.window.skey)) return -1; - if (tDecodeI64(pDecoder, &pTask->dataRange.window.ekey)) return -1; + TAOS_CHECK_EXIT(tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.minVer)); + TAOS_CHECK_EXIT(tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.maxVer)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->dataRange.window.skey)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->dataRange.window.ekey)); int32_t epSz = -1; - if (tDecodeI32(pDecoder, &epSz) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &epSz) < 0); - pTask->upstreamInfo.pList = taosArrayInit(epSz, POINTER_BYTES); + if ((pTask->upstreamInfo.pList = taosArrayInit(epSz, POINTER_BYTES)) == NULL) { + TAOS_CHECK_EXIT(terrno); + } for (int32_t i = 0; i < epSz; i++) { SStreamUpstreamEpInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamUpstreamEpInfo)); - if (pInfo == NULL) return -1; - if (tDecodeStreamEpInfo(pDecoder, pInfo) < 0) { - taosMemoryFreeClear(pInfo); - return -1; + if (pInfo == NULL) { + TAOS_CHECK_EXIT(terrno); } - void* p = taosArrayPush(pTask->upstreamInfo.pList, &pInfo); - if (p == NULL) { - tEndDecode(pDecoder); - return -1; + if ((code = tDecodeStreamEpInfo(pDecoder, pInfo)) < 0) { + taosMemoryFreeClear(pInfo); + goto _exit; + } + if (taosArrayPush(pTask->upstreamInfo.pList, &pInfo) == NULL) { + TAOS_CHECK_EXIT(terrno); } } if (pTask->info.taskLevel != TASK_LEVEL__SINK) { - if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg)); } if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) { - if (tDecodeI64(pDecoder, &pTask->outputInfo.tbSink.stbUid) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pTask->outputInfo.tbSink.stbFullName) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->outputInfo.tbSink.stbUid)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->outputInfo.tbSink.stbFullName)); pTask->outputInfo.tbSink.pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper)); - if (pTask->outputInfo.tbSink.pSchemaWrapper == NULL) return -1; - if (tDecodeSSchemaWrapper(pDecoder, pTask->outputInfo.tbSink.pSchemaWrapper) < 0) return -1; + if (pTask->outputInfo.tbSink.pSchemaWrapper == NULL) { + TAOS_CHECK_EXIT(terrno); + } + TAOS_CHECK_EXIT(tDecodeSSchemaWrapper(pDecoder, pTask->outputInfo.tbSink.pSchemaWrapper)); } else if (pTask->outputInfo.type == TASK_OUTPUT__SMA) { - if (tDecodeI64(pDecoder, &pTask->outputInfo.smaSink.smaId) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->outputInfo.smaSink.smaId)); } else if (pTask->outputInfo.type == TASK_OUTPUT__FETCH) { - if (tDecodeI8(pDecoder, &pTask->outputInfo.fetchSink.reserved) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->outputInfo.fetchSink.reserved)); } else if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) { - if (tDecodeI32(pDecoder, &pTask->outputInfo.fixedDispatcher.taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->outputInfo.fixedDispatcher.nodeId) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &pTask->outputInfo.fixedDispatcher.epSet) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->outputInfo.fixedDispatcher.taskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->outputInfo.fixedDispatcher.nodeId)); + TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->outputInfo.fixedDispatcher.epSet)); } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) { - if (tDeserializeSUseDbRspImp(pDecoder, &pTask->outputInfo.shuffleDispatcher.dbInfo) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pTask->outputInfo.shuffleDispatcher.stbFullName) < 0) return -1; + TAOS_CHECK_EXIT(tDeserializeSUseDbRspImp(pDecoder, &pTask->outputInfo.shuffleDispatcher.dbInfo)); + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->outputInfo.shuffleDispatcher.stbFullName)); } - if (tDecodeI64(pDecoder, &pTask->info.delaySchedParam) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->info.delaySchedParam)); if (pTask->ver >= SSTREAM_TASK_SUBTABLE_CHANGED_VER) { - if (tDecodeI8(pDecoder, &pTask->subtableWithoutMd5) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->subtableWithoutMd5)); } - if (tDecodeCStrTo(pDecoder, pTask->reserve) < 0) return -1; + TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->reserve)); tEndDecode(pDecoder); - return 0; + +_exit: + return code; } int32_t tEncodeStreamTaskChkptReport(SEncoder* pEncoder, const SCheckpointReport* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->nodeId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->checkpointId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->checkpointVer) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->checkpointTs) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->transId) < 0) return -1; - if (tEncodeI8(pEncoder, pReq->dropHTask) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->taskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->nodeId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->checkpointId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->checkpointVer)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->checkpointTs)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->transId)); + TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->dropHTask)); tEndEncode(pEncoder); - return 0; + +_exit: + return code; } int32_t tDecodeStreamTaskChkptReport(SDecoder* pDecoder, SCheckpointReport* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->nodeId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->checkpointId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->checkpointVer) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->checkpointTs) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->transId) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->dropHTask) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->streamId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->taskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->nodeId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->checkpointId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->checkpointVer)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->checkpointTs)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->transId)); + TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->dropHTask)); tEndDecode(pDecoder); - return 0; + +_exit: + return code; } -int32_t tEncodeRestoreCheckpointInfo (SEncoder* pEncoder, const SRestoreCheckpointInfo* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->startTs) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->checkpointId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->transId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->nodeId) < 0) return -1; +int32_t tEncodeRestoreCheckpointInfo(SEncoder* pEncoder, const SRestoreCheckpointInfo* pReq) { + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartEncode(pEncoder)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->startTs)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->streamId)); + TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pReq->checkpointId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->transId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->taskId)); + TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pReq->nodeId)); tEndEncode(pEncoder); - return pEncoder->pos; + +_exit: + if (code) { + return code; + } else { + return pEncoder->pos; + } } int32_t tDecodeRestoreCheckpointInfo(SDecoder* pDecoder, SRestoreCheckpointInfo* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->startTs) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->checkpointId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->transId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->nodeId) < 0) return -1; + int32_t code = 0; + int32_t lino; + + TAOS_CHECK_EXIT(tStartDecode(pDecoder)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->startTs)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->streamId)); + TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pReq->checkpointId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->transId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->taskId)); + TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pReq->nodeId)); tEndDecode(pDecoder); - return 0; + +_exit: + return code; } diff --git a/source/libs/stream/src/streamQueue.c b/source/libs/stream/src/streamQueue.c index eca728b2d5..3765d0f9d3 100644 --- a/source/libs/stream/src/streamQueue.c +++ b/source/libs/stream/src/streamQueue.c @@ -287,7 +287,7 @@ int32_t streamTaskPutDataIntoInputQ(SStreamTask* pTask, SStreamQueueItem* pItem) "s-task:%s inputQ is full, capacity(size:%d num:%dMiB), current(blocks:%d, size:%.2fMiB) stop to push data", pTask->id.idStr, STREAM_TASK_QUEUE_CAPACITY, STREAM_TASK_QUEUE_CAPACITY_IN_SIZE, total, size); streamDataSubmitDestroy(px); - return -1; + return TSDB_CODE_OUT_OF_MEMORY; } int32_t msgLen = px->submit.msgLen; @@ -312,7 +312,7 @@ int32_t streamTaskPutDataIntoInputQ(SStreamTask* pTask, SStreamQueueItem* pItem) stTrace("s-task:%s input queue is full, capacity:%d size:%d MiB, current(blocks:%d, size:%.2fMiB) abort", pTask->id.idStr, STREAM_TASK_QUEUE_CAPACITY, STREAM_TASK_QUEUE_CAPACITY_IN_SIZE, total, size); streamFreeQitem(pItem); - return -1; + return TSDB_CODE_OUT_OF_MEMORY; } int32_t code = taosWriteQitem(pQueue, pItem); diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index 0791784656..2acfd64b2a 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -1098,15 +1098,12 @@ static int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* return terrno = code; } - // enqueue - stDebug("s-task:%s (vgId:%d level:%d) recv retrieve req from task:0x%x(vgId:%d),QID:0x%" PRIx64, pTask->id.idStr, - pTask->pMeta->vgId, pTask->info.taskLevel, pReq->srcTaskId, pReq->srcNodeId, pReq->reqId); - pData->type = STREAM_INPUT__DATA_RETRIEVE; pData->srcVgId = 0; code = streamRetrieveReqToData(pReq, pData, pTask->id.idStr); if (code != TSDB_CODE_SUCCESS) { + stError("s-task:%s failed to convert retrieve-data to block, code:%s", pTask->id.idStr, tstrerror(code)); taosFreeQitem(pData); return code; } diff --git a/source/libs/stream/src/streamUpdate.c b/source/libs/stream/src/streamUpdate.c index 3f7210d3c9..58ed50da65 100644 --- a/source/libs/stream/src/streamUpdate.c +++ b/source/libs/stream/src/streamUpdate.c @@ -231,7 +231,7 @@ _end: static int32_t getSBf(SUpdateInfo* pInfo, TSKEY ts, SScalableBf** ppSBf) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; - if (ts <= 0) { + if (ts < 0) { code = TSDB_CODE_FAILED; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index a0236c38b8..8e709f8809 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -1421,12 +1421,12 @@ int32_t syncNodeRestore(SSyncNode* pSyncNode) { if (lastVer != -1 && endIndex != lastVer + 1) { code = TSDB_CODE_WAL_LOG_INCOMPLETE; - sError("vgId:%d, failed to restore sync node since %s. expected lastLogIndex:%" PRId64 ", lastVer:%" PRId64 "", - pSyncNode->vgId, terrstr(), endIndex - 1, lastVer); - TAOS_RETURN(code); + sWarn("vgId:%d, failed to restore sync node since %s. expected lastLogIndex:%" PRId64 ", lastVer:%" PRId64 "", + pSyncNode->vgId, terrstr(), endIndex - 1, lastVer); + // TAOS_RETURN(code); } - if (endIndex != lastVer + 1) return TSDB_CODE_SYN_INTERNAL_ERROR; + // if (endIndex != lastVer + 1) return TSDB_CODE_SYN_INTERNAL_ERROR; pSyncNode->commitIndex = TMAX(pSyncNode->commitIndex, commitIndex); sInfo("vgId:%d, restore sync until commitIndex:%" PRId64, pSyncNode->vgId, pSyncNode->commitIndex); diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index 11997d089c..afa048f0ac 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -1227,7 +1227,11 @@ static void checkRegexCache(void* param, void* tmrId) { if(sRegexCache.exit) { goto _exit; } - (void)taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId); + bool ret = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId); + if (!ret) { + uError("failed to reset regex cache timer"); + goto _exit; + } if (taosHashGetSize(sRegexCache.regexHash) < MAX_REGEX_CACHE_SIZE) { goto _exit; } @@ -1238,7 +1242,10 @@ static void checkRegexCache(void* param, void* tmrId) { if (taosGetTimestampSec() - (*ppUsingRegex)->lastUsedTime > REGEX_CACHE_CLEAR_TIME) { size_t len = 0; char* key = (char*)taosHashGetKey(ppUsingRegex, &len); - (void)taosHashRemove(sRegexCache.regexHash, key, len); + if (TSDB_CODE_SUCCESS != taosHashRemove(sRegexCache.regexHash, key, len)) { + uError("failed to remove regex pattern %s from cache", key); + goto _exit; + } } ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex); } @@ -1285,7 +1292,10 @@ void DestroyRegexCache(){ #endif int32_t code = 0; uInfo("[regex cache] destory regex cache"); - (void)taosTmrStopA(&sRegexCache.timer); + bool ret = taosTmrStopA(&sRegexCache.timer); + if (!ret) { + uError("failed to stop regex cache timer"); + } taosWLockLatch(&sRegexCache.mutex); sRegexCache.exit = true; taosHashCleanup(sRegexCache.regexHash); diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 9431774112..3b3217ac75 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -24,7 +24,7 @@ ,,y,army,./pytest.sh python3 ./test.py -f query/fill/fill_desc.py -N 3 -L 3 -D 2 ,,y,army,./pytest.sh python3 ./test.py -f query/fill/fill_null.py ,,y,army,./pytest.sh python3 ./test.py -f cluster/incSnapshot.py -N 3 -,,y,army,./pytest.sh python3 ./test.py -f cluster/clusterBasic.py -N 3 +#,,y,army,./pytest.sh python3 ./test.py -f cluster/clusterBasic.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f query/query_basic.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f query/accuracy/test_query_accuracy.py ,,y,army,./pytest.sh python3 ./test.py -f insert/insert_basic.py -N 3 @@ -351,7 +351,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/splitVGroupWal.py -N 3 -n 3 ,,n,system-test,python3 ./test.py -f 0-others/timeRangeWise.py -N 3 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/delete_check.py -,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_hot_refresh_configurations.py +#,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_hot_refresh_configurations.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/subscribe_stream_privilege.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/empty_identifier.py @@ -1270,7 +1270,7 @@ ,,y,script,./test.sh -f tsim/snode/basic1.sim ,,y,script,./test.sh -f tsim/mnode/basic1.sim ,,y,script,./test.sh -f tsim/mnode/basic2.sim -,,y,script,./test.sh -f tsim/mnode/basic3.sim +#,,y,script,./test.sh -f tsim/mnode/basic3.sim ,,y,script,./test.sh -f tsim/mnode/basic4.sim ,,y,script,./test.sh -f tsim/mnode/basic5.sim ,,y,script,./test.sh -f tsim/show/basic.sim diff --git a/tests/script/api/makefile b/tests/script/api/makefile index d848dca194..d8a4e19218 100644 --- a/tests/script/api/makefile +++ b/tests/script/api/makefile @@ -7,11 +7,13 @@ LFLAGS = '-Wl,-rpath,/usr/local/taos/driver/' -ltaos -lpthread -lm -lrt CFLAGS = -O0 -g -Wno-deprecated -fPIC -Wno-unused-result -Wconversion \ -Wno-char-subscripts -D_REENTRANT -Wno-format -D_REENTRANT -DLINUX \ -Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 -Wno-sign-conversion +#CFLAGS += -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment all: $(TARGET) exe: gcc $(CFLAGS) ./batchprepare.c -o $(ROOT)batchprepare $(LFLAGS) + gcc $(CFLAGS) ./stmt2-test.c -o $(ROOT)stmt2-test $(LFLAGS) gcc $(CFLAGS) ./stopquery.c -o $(ROOT)stopquery $(LFLAGS) gcc $(CFLAGS) ./dbTableRoute.c -o $(ROOT)dbTableRoute $(LFLAGS) gcc $(CFLAGS) ./insertSameTs.c -o $(ROOT)insertSameTs $(LFLAGS) @@ -20,9 +22,15 @@ exe: gcc $(CFLAGS) ./insert_stb.c -o $(ROOT)insert_stb $(LFLAGS) gcc $(CFLAGS) ./tmqViewTest.c -o $(ROOT)tmqViewTest $(LFLAGS) gcc $(CFLAGS) ./stmtQuery.c -o $(ROOT)stmtQuery $(LFLAGS) + gcc $(CFLAGS) ./stmt.c -o $(ROOT)stmt $(LFLAGS) + gcc $(CFLAGS) ./stmt2.c -o $(ROOT)stmt2 $(LFLAGS) + gcc $(CFLAGS) ./stmt2-example.c -o $(ROOT)stmt2-example $(LFLAGS) + gcc $(CFLAGS) ./stmt2-nohole.c -o $(ROOT)stmt2-nohole $(LFLAGS) + gcc $(CFLAGS) ./stmt-crash.c -o $(ROOT)stmt-crash $(LFLAGS) clean: rm $(ROOT)batchprepare + rm $(ROOT)stmt2-test rm $(ROOT)stopquery rm $(ROOT)dbTableRoute rm $(ROOT)insertSameTs @@ -31,3 +39,8 @@ clean: rm $(ROOT)insert_stb rm $(ROOT)tmqViewTest rm $(ROOT)stmtQuery + rm $(ROOT)stmt + rm $(ROOT)stmt2 + rm $(ROOT)stmt2-example + rm $(ROOT)stmt2-nohole + rm $(ROOT)stmt-crash diff --git a/tests/script/api/stmt-crash.c b/tests/script/api/stmt-crash.c new file mode 100644 index 0000000000..310e7c4910 --- /dev/null +++ b/tests/script/api/stmt-crash.c @@ -0,0 +1,289 @@ +// TAOS standard API example. The same syntax as MySQL, but only a subet +// to compile: gcc -o prepare prepare.c -ltaos + +#include +#include +#include +#include "taos.h" + +void taosMsleep(int mseconds); + +int main(int argc, char *argv[]) { + TAOS *taos; + TAOS_RES *result; + int code; + TAOS_STMT *stmt; + + // connect to server + if (argc < 2) { + printf("please input server ip \n"); + return 0; + } + + // taos = taos_connect(argv[1], "root", "Taosdata.1234", NULL, 0); + taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); + if (taos == NULL) { + printf("failed to connect to db, reason:%s\n", taos_errstr(taos)); + exit(1); + } + + result = taos_query(taos, "drop database demo"); + taos_free_result(result); + + result = taos_query(taos, "create database demo"); + code = taos_errno(result); + if (code != 0) { + printf("failed to create database, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + taos_free_result(result); + + result = taos_query(taos, "use demo"); + taos_free_result(result); + + // create table + const char *sql = + "create stable s1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin " + "binary(40), blob nchar(10), varbin varbinary(16)) tags(groupId INT);"; + result = taos_query(taos, sql); + code = taos_errno(result); + if (code != 0) { + printf("failed to create table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + taos_free_result(result); + + // sleep for one second to make sure table is created on data node + // taosMsleep(1000); + + // insert 10 records + struct { + int64_t ts; + int8_t b; + int8_t v1; + int16_t v2; + int32_t v4; + int64_t v8; + float f4; + double f8; + char bin[40]; + char blob[80]; + int8_t varbin[16]; + } v = {0}; + + int32_t boolLen = sizeof(int8_t); + int32_t sintLen = sizeof(int16_t); + int32_t intLen = sizeof(int32_t); + int32_t bintLen = sizeof(int64_t); + int32_t floatLen = sizeof(float); + int32_t doubleLen = sizeof(double); + int32_t binLen = sizeof(v.bin); + int32_t ncharLen = 30; + + stmt = taos_stmt_init(taos); + TAOS_MULTI_BIND params[11]; + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[0].buffer_length = sizeof(v.ts); + params[0].buffer = &v.ts; + params[0].length = &bintLen; + params[0].is_null = NULL; + params[0].num = 1; + + params[1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[1].buffer_length = sizeof(v.b); + params[1].buffer = &v.b; + params[1].length = &boolLen; + params[1].is_null = NULL; + params[1].num = 1; + + params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[2].buffer_length = sizeof(v.v1); + params[2].buffer = &v.v1; + params[2].length = &boolLen; + params[2].is_null = NULL; + params[2].num = 1; + + params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[3].buffer_length = sizeof(v.v2); + params[3].buffer = &v.v2; + params[3].length = &sintLen; + params[3].is_null = NULL; + params[3].num = 1; + + params[4].buffer_type = TSDB_DATA_TYPE_INT; + params[4].buffer_length = sizeof(v.v4); + params[4].buffer = &v.v4; + params[4].length = &intLen; + params[4].is_null = NULL; + params[4].num = 1; + + params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[5].buffer_length = sizeof(v.v8); + params[5].buffer = &v.v8; + params[5].length = &bintLen; + params[5].is_null = NULL; + params[5].num = 1; + + params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[6].buffer_length = sizeof(v.f4); + params[6].buffer = &v.f4; + params[6].length = &floatLen; + params[6].is_null = NULL; + params[6].num = 1; + + params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[7].buffer_length = sizeof(v.f8); + params[7].buffer = &v.f8; + params[7].length = &doubleLen; + params[7].is_null = NULL; + params[7].num = 1; + + params[8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[8].buffer_length = sizeof(v.bin); + params[8].buffer = v.bin; + params[8].length = &binLen; + params[8].is_null = NULL; + params[8].num = 1; + + strcpy(v.blob, "一二三四五六七八九十"); + params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; + params[9].buffer_length = sizeof(v.blob); + params[9].buffer = v.blob; + params[9].length = &ncharLen; + params[9].is_null = NULL; + params[9].num = 1; + + int8_t tmp[16] = {'a', 0, 1, 13, '1'}; + int32_t vbinLen = 5; + memcpy(v.varbin, tmp, sizeof(v.varbin)); + params[10].buffer_type = TSDB_DATA_TYPE_VARBINARY; + params[10].buffer_length = sizeof(v.varbin); + params[10].buffer = v.varbin; + params[10].length = &vbinLen; + params[10].is_null = NULL; + params[10].num = 1; + + TAOS_MULTI_BIND tags[1]; + + int32_t id1 = 0; + + tags[0].buffer_type = TSDB_DATA_TYPE_INT; + tags[0].buffer_length = sizeof(int); + tags[0].buffer = &id1; + tags[0].length = NULL; + tags[0].is_null = NULL; + tags[0].num = 1; + + char is_null = 1; + + sql = "insert into ? using s1 tags(?) values(?,?,?,?,?,?,?,?,?,?,?)"; + code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0) { + printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + } + + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + exit(EXIT_FAILURE); + } + code = taos_stmt_set_tbname_tags(stmt, "m1", tags); + v.ts = 1591060628000; + v.b = (int8_t)0 % 2; + v.v1 = (int8_t)0; + v.v2 = (int16_t)(0 * 2); + v.v4 = (int32_t)(0 * 4); + v.v8 = (int64_t)(0 * 8); + v.f4 = (float)(0 * 40); + v.f8 = (double)(0 * 80); + for (int j = 0; j < sizeof(v.bin); ++j) { + v.bin[j] = (char)(0 + '0'); + } + taos_stmt_bind_param(stmt, params); + taos_stmt_add_batch(stmt); + + code = taos_stmt_set_tbname_tags(stmt, "m2", tags); + v.ts = 1591060628000 + 1; + v.b = (int8_t)1 % 2; + v.v1 = (int8_t)1; + v.v2 = (int16_t)(1 * 2); + v.v4 = (int32_t)(1 * 4); + v.v8 = (int64_t)(1 * 8); + v.f4 = (float)(1 * 40); + v.f8 = (double)(1 * 80); + for (int j = 0; j < sizeof(v.bin); ++j) { + v.bin[j] = (char)(1 + '0'); + } + taos_stmt_bind_param(stmt, params); + taos_stmt_add_batch(stmt); + /* + for (int i = 0; i < 10; ++i) { + if(i % 2 != 0) { + code = taos_stmt_set_tbname(stmt, "m1"); + } else { + code = taos_stmt_set_tbname(stmt, "m2"); + } + v.ts += 1; + for (int j = 1; j < 11; ++j) { + params[j].is_null = ((i == j) ? &is_null : 0); + } + v.b = (int8_t)i % 2; + v.v1 = (int8_t)i; + v.v2 = (int16_t)(i * 2); + v.v4 = (int32_t)(i * 4); + v.v8 = (int64_t)(i * 8); + v.f4 = (float)(i * 40); + v.f8 = (double)(i * 80); + for (int j = 0; j < sizeof(v.bin); ++j) { + v.bin[j] = (char)(i + '0'); + } + + taos_stmt_bind_param(stmt, params); + taos_stmt_add_batch(stmt); + } + */ + // printf("taos multi bind num:%d\n", params[1].num); + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + taos_stmt_close(stmt); + + // query the records + stmt = taos_stmt_init(taos); + taos_stmt_prepare(stmt, "SELECT * FROM m1 WHERE v1 > ? AND v2 < ?", 0); + v.v1 = 5; + v.v2 = 15; + taos_stmt_bind_param(stmt, params + 2); + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute select statement.\n"); + exit(1); + } + + result = taos_stmt_use_result(stmt); + + TAOS_ROW row; + int rows = 0; + int num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; + rows++; + taos_print_row(temp, row, fields, num_fields); + printf("%s\n", temp); + } + if (rows == 2) { + printf("two rows are fetched as expectation\n"); + } else { + printf("expect two rows, but %d rows are fetched\n", rows); + } + + // taos_free_result(result); + taos_stmt_close(stmt); + + return 0; +} diff --git a/tests/script/api/stmt2-example.c b/tests/script/api/stmt2-example.c new file mode 100644 index 0000000000..803e54c156 --- /dev/null +++ b/tests/script/api/stmt2-example.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include "taos.h" + +void do_query(TAOS* taos, const char* sql) { + TAOS_RES* result = taos_query(taos, sql); + int code = taos_errno(result); + if (code) { + printf("failed to query: %s, reason:%s\n", sql, taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); +} + +void do_stmt(TAOS* taos) { + do_query(taos, "drop database if exists db"); + do_query(taos, "create database db"); + do_query(taos, "create table db.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))"); + + struct { + int64_t ts[2]; + char b[16]; + } v; + + int32_t b_len[2], t64_len[2]; + char is_null[2] = {0}; + char is_null2[2] = {0, 2}; + // TAOS_STMT2_OPTION option = {0}; + // TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb, NULL}; + TAOS_STMT2_OPTION option = {0, true, false, NULL, NULL}; + + char* tbs[2] = {"tb", "tb2"}; + int t1_val[2] = {0, 1}; + int t2_len[2] = {3, 3}; + TAOS_STMT2_BIND tags[2][2] = {{{0, &t1_val[0], NULL, NULL, 0}, {0, "a1", &t2_len[0], NULL, 0}}, + {{0, &t1_val[1], NULL, NULL, 0}, {0, "a2", &t2_len[1], NULL, 0}}}; + TAOS_STMT2_BIND params[2][2] = { + {{TSDB_DATA_TYPE_TIMESTAMP, v.ts, NULL, is_null, 2}, {TSDB_DATA_TYPE_BINARY, v.b, b_len, is_null2, 2}}, + {{TSDB_DATA_TYPE_TIMESTAMP, v.ts, NULL, is_null, 2}, {TSDB_DATA_TYPE_BINARY, v.b, b_len, is_null2, 2}}}; + TAOS_STMT2_BIND* tagv[2] = {&tags[0][0], &tags[1][0]}; + TAOS_STMT2_BIND* paramv[2] = {¶ms[0][0], ¶ms[1][0]}; + TAOS_STMT2_BINDV bindv = {2, &tbs[0], &tagv[0], ¶mv[0]}; + + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + const char* sql = "insert into db.? using db.stb tags(?, ?) values(?,?)"; + int code = taos_stmt2_prepare(stmt, sql, 0); + if (code != 0) { + printf("failed to execute taos_stmt2_prepare. error:%s\n", taos_stmt2_error(stmt)); + taos_stmt2_close(stmt); + return; + } + + int64_t ts = 1591060628000; + for (int i = 0; i < 2; ++i) { + // v.ts[i] = ts++; + v.ts[i] = ts; + // t64_len[i] = sizeof(int64_t); + } + strcpy(v.b, "abcdefg"); + b_len[0] = (int)strlen(v.b); + strcpy(v.b + b_len[0], "xyz"); + b_len[1] = 3; + + taos_stmt2_bind_param(stmt, &bindv, -1); + + if (taos_stmt2_exec(stmt, NULL)) { + printf("failed to execute insert statement.error:%s\n", taos_stmt2_error(stmt)); + taos_stmt2_close(stmt); + return; + } + + taos_stmt2_close(stmt); +} + +int main() { + TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); + if (!taos) { + printf("failed to connect to db, reason:%s\n", taos_errstr(taos)); + exit(1); + } + + do_stmt(taos); + taos_close(taos); + taos_cleanup(); +} diff --git a/tests/script/api/stmt2-nohole.c b/tests/script/api/stmt2-nohole.c new file mode 100644 index 0000000000..b29dd3e826 --- /dev/null +++ b/tests/script/api/stmt2-nohole.c @@ -0,0 +1,369 @@ +// sample code to verify all TDengine API +// to compile: gcc -o apitest apitest.c -ltaos + +#include +#include +#include +#include +#include +#include "taos.h" +static int64_t count = 10000; + +int64_t genReqid() { + count += 100; + return count; +} + +sem_t sem; + +void stmtAsyncQueryCb(void* param, TAOS_RES* pRes, int code) { + int affected_rows = taos_affected_rows(pRes); + printf("\033[31maffected rows:%d\033[0m\n", affected_rows); + (void)sem_post(&sem); + return; + /* + SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)param; + if (code == 0 && pRes) { + if (qParam->fetch) { + taos_fetch_rows_a(pRes, sqAsyncFetchCb, param); + } else { + if (qParam->free) { + taos_free_result(pRes); + } + *qParam->end = 1; + } + } else { + sqError("select", taos_errstr(pRes)); + *qParam->end = 1; + taos_free_result(pRes); + } + */ +} + +void veriry_stmt(TAOS* taos) { + TAOS_RES* result = taos_query(taos, "drop database if exists test;"); + taos_free_result(result); + usleep(100000); + result = taos_query(taos, "create database test;"); + + int code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create database, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); + + usleep(100000); + taos_select_db(taos, "test"); + + // create table + /* + const char* sql = + "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin " + "binary(40), blob nchar(10))"; + */ + const char* sql = + "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, blob2 " + "nchar(10), blob nchar(10))"; + result = taos_query(taos, sql); + code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create table, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); + + sql = + "create table m2 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, blob2 " + "nchar(10), blob nchar(10))"; + result = taos_query(taos, sql); + code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create table, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); + + // insert 10 records + struct { + int64_t ts[10]; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + // char blob[10][80]; + // char blob2[10][80]; + char blob[1024]; + char blob2[1024]; + } v; + + int32_t* t8_len = malloc(sizeof(int32_t) * 10); + int32_t* t16_len = malloc(sizeof(int32_t) * 10); + int32_t* t32_len = malloc(sizeof(int32_t) * 10); + int32_t* t64_len = malloc(sizeof(int32_t) * 10); + int32_t* float_len = malloc(sizeof(int32_t) * 10); + int32_t* double_len = malloc(sizeof(int32_t) * 10); + int32_t* bin_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len2 = malloc(sizeof(int32_t) * 10); + +#include "time.h" + clock_t start, end; + TAOS_STMT2_OPTION option = {0, true, false, stmtAsyncQueryCb, NULL}; + + start = clock(); + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + end = clock(); + printf("init time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + // TAOS_MULTI_BIND params[10]; + TAOS_STMT2_BIND params[10]; + char is_null2[10] = {0}; + char is_null[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 2}; + + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + // params[0].buffer_length = sizeof(v.ts[0]); + params[0].buffer = v.ts; + params[0].length = NULL; // t64_len; + params[0].is_null = is_null2; + params[0].num = 10; + + params[1].buffer_type = TSDB_DATA_TYPE_BOOL; + // params[1].buffer_length = sizeof(v.b[0]); + params[1].buffer = v.b; + params[1].length = NULL; // t8_len; + params[1].is_null = is_null; + params[1].num = 10; + + params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; + // params[2].buffer_length = sizeof(v.v1[0]); + params[2].buffer = v.v1; + params[2].length = NULL; // t8_len; + params[2].is_null = is_null; + params[2].num = 10; + + params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + // params[3].buffer_length = sizeof(v.v2[0]); + params[3].buffer = v.v2; + params[3].length = NULL; // t16_len; + params[3].is_null = is_null; + params[3].num = 10; + + params[4].buffer_type = TSDB_DATA_TYPE_INT; + // params[4].buffer_length = sizeof(v.v4[0]); + params[4].buffer = v.v4; + params[4].length = NULL; // t32_len; + params[4].is_null = is_null; + params[4].num = 10; + + params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; + // params[5].buffer_length = sizeof(v.v8[0]); + params[5].buffer = v.v8; + params[5].length = NULL; // t64_len; + params[5].is_null = is_null; + params[5].num = 10; + + params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; + // params[6].buffer_length = sizeof(v.f4[0]); + params[6].buffer = v.f4; + params[6].length = NULL; // float_len; + params[6].is_null = is_null; + params[6].num = 10; + + params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + // params[7].buffer_length = sizeof(v.f8[0]); + params[7].buffer = v.f8; + params[7].length = NULL; // double_len; + params[7].is_null = is_null; + params[7].num = 10; + /* + params[8].buffer_type = TSDB_DATA_TYPE_BINARY; + //params[8].buffer_length = sizeof(v.bin[0]); + params[8].buffer = v.bin; + params[8].length = bin_len; + params[8].is_null = is_null; + params[8].num = 10; + */ + params[8].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[8].buffer_length = sizeof(v.blob2[0]); + params[8].buffer = v.blob2; + params[8].length = blob_len2; + params[8].is_null = is_null; + params[8].num = 10; + + params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[9].buffer_length = sizeof(v.blob[0]); + params[9].buffer = v.blob; + params[9].length = blob_len; + params[9].is_null = is_null; + params[9].num = 10; + + sql = "insert into ? (ts, b, v1, v2, v4, v8, f4, f8, blob2, blob) values(?,?,?,?,?,?,?,?,?,?)"; + start = clock(); + code = taos_stmt2_prepare(stmt, sql, 0); + end = clock(); + printf("prepare time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + /* + code = taos_stmt_set_tbname(stmt, "m1"); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + */ + + int64_t ts = 1591060628000; + char* blob2_buffer = v.blob2; + char* blob_buffer = v.blob; + const char* blob2_str[] = { + "一二三四五六七十九八", "一二三四五六七十九", "一二三四五六七十", "一二三四五六七", "一二三四五六", + "一二三四五", "一二三四", "一二三", "一二", "一", + }; + const char* blob_str[] = { + "一", "一二", "一二三", "一二三四", "一二三四五", + "一二三四五六", "一二三四五六七", "一二三四五六七八", "一二三四五六七八九", "一二三四五六七八九十", + }; + for (int i = 0; i < 10; ++i) { + // is_null[i] = 0; + + v.ts[i] = ts++; + // v.b[i] = (int8_t)i % 2; + v.b[i] = (int8_t)i % 10; + v.v1[i] = (int8_t)i; + v.v2[i] = (int16_t)(i * 2); + v.v4[i] = (int32_t)(i * 4); + v.v8[i] = (int64_t)(i * 8); + v.f4[i] = (float)(i * 40); + v.f8[i] = (double)(i * 80); + for (int j = 0; j < sizeof(v.bin[0]); ++j) { + v.bin[i][j] = (char)(i + '0'); + } + // strcpy(v.blob2[i], "一二三四五六七十九八"); + // strcpy(v.blob[i], "一二三四五六七八九十"); + // const char* blob2_str = "一二三四五六七十九八"; + // const char* blob_str = "一二三四五六七八九十"; + strcpy(blob2_buffer, blob2_str[i]); + strcpy(blob_buffer, blob_str[i]); + + t8_len[i] = sizeof(int8_t); + t16_len[i] = sizeof(int16_t); + t32_len[i] = sizeof(int32_t); + t64_len[i] = sizeof(int64_t); + float_len[i] = sizeof(float); + double_len[i] = sizeof(double); + bin_len[i] = sizeof(v.bin[0]); + // blob_len[i] = (int32_t)strlen(v.blob[i]); + // blob_len2[i] = (int32_t)strlen(v.blob2[i]); + blob_len[i] = (int32_t)strlen(blob_str[i]); + blob_len2[i] = (int32_t)strlen(blob2_str[i]); + blob_buffer += blob_len[i]; + blob2_buffer += blob_len2[i]; + } + int run_time = 0; + char* tbname = "m2"; + TAOS_STMT2_BIND* bind_cols[1] = {¶ms[0]}; + TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, &bind_cols[0]}; +_bind_again: + start = clock(); + // taos_stmt2_bind_param(stmt, "m1", NULL, params, -1); + taos_stmt2_bind_param(stmt, &bindv, -1); + end = clock(); + printf("bind time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + // taos_stmt_bind_param_batch(stmt, params); + // taos_stmt_add_batch(stmt); + /* + int param_count = -1; + code = taos_stmt2_param_count(stmt, ¶m_count); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_param_count. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + printf("param_count: %d\n", param_count); + */ + TAOS_FIELD_E* fields = NULL; + int field_count = -1; + start = clock(); + code = taos_stmt2_get_fields(stmt, TAOS_FIELD_TBNAME, &field_count, NULL); + end = clock(); + printf("get fields time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_param_count. error:%s\033[0m\n", taos_stmt2_error(stmt)); + taos_stmt2_close(stmt); + return; + } + printf("col field_count: %d\n", field_count); + start = clock(); + taos_stmt2_free_fields(stmt, fields); + end = clock(); + printf("free time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + /* + code = taos_stmt2_get_fields(stmt, TAOS_FIELD_TAG, &field_count, &fields); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_param_count. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + printf("tag field_count: %d\n", field_count); + taos_stmt2_free_fields(stmt, fields); + */ + // if (taos_stmt_execute(stmt) != 0) { + (void)sem_init(&sem, 0, 0); + start = clock(); + // if (taos_stmt2_exec(stmt, NULL, stmtAsyncQueryCb, NULL) != 0) { + if (taos_stmt2_exec(stmt, NULL) != 0) { + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt2_close(stmt); + return; + } + end = clock(); + printf("exec time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + + sem_wait(&sem); + (void)sem_destroy(&sem); + if (++run_time < 2) { + goto _bind_again; + } + taos_stmt2_close(stmt); + + free(t8_len); + free(t16_len); + free(t32_len); + free(t64_len); + free(float_len); + free(double_len); + free(bin_len); + free(blob_len); + free(blob_len2); +} + +int main(int argc, char* argv[]) { + const char* host = "127.0.0.1"; + const char* user = "root"; + const char* passwd = "taosdata"; + + taos_options(TSDB_OPTION_TIMEZONE, "GMT-8"); + TAOS* taos = taos_connect(host, user, passwd, "", 0); + if (taos == NULL) { + printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos)); + exit(1); + } + + printf("********* verify stmt query **********\n"); + veriry_stmt(taos); + + printf("done\n"); + taos_close(taos); + taos_cleanup(); +} diff --git a/tests/script/api/stmt2-test.c b/tests/script/api/stmt2-test.c new file mode 100644 index 0000000000..2bbceec92e --- /dev/null +++ b/tests/script/api/stmt2-test.c @@ -0,0 +1,3201 @@ +// TAOS standard API example. The same syntax as MySQL, but only a subet +// to compile: gcc -o prepare prepare.c -ltaos + +#include +#include +#include +#include +#include +#include +#include "../../../include/client/taos.h" + +#define FUNCTION_TEST_IDX 1 +#define TIME_PRECISION_MILLI 0 +#define TIME_PRECISION_MICRO 1 +#define TIME_PRECISION_NANO 2 + +int32_t shortColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT}; +int32_t fullColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_TINYINT, + TSDB_DATA_TYPE_UTINYINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_USMALLINT, + TSDB_DATA_TYPE_INT, TSDB_DATA_TYPE_UINT, TSDB_DATA_TYPE_BIGINT, + TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_FLOAT, TSDB_DATA_TYPE_DOUBLE, + TSDB_DATA_TYPE_BINARY, TSDB_DATA_TYPE_NCHAR}; +int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_NCHAR}; +int32_t optrIdxList[] = {5, 11}; + +typedef struct { + char *oper; + int32_t paramNum; + bool enclose; +} OperInfo; + +typedef struct { + char *funcName; + int32_t paramNum; +} FuncInfo; + +typedef enum { + BP_BIND_TAG = 1, + BP_BIND_COL, +} BP_BIND_TYPE; + +#define BP_BIND_TYPE_STR(t) (((t) == BP_BIND_COL) ? "column" : "tag") + +OperInfo operInfo[] = { + {">", 2, false}, {">=", 2, false}, {"<", 2, false}, {"<=", 2, false}, + {"=", 2, false}, {"<>", 2, false}, {"in", 2, true}, {"not in", 2, true}, + + {"like", 2, false}, {"not like", 2, false}, {"match", 2, false}, {"nmatch", 2, false}, +}; + +int32_t operatorList[] = {0, 1, 2, 3, 4, 5, 6, 7}; +int32_t varoperatorList[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + +FuncInfo funcInfo[] = { + {"count", 1}, + {"sum", 1}, + {"min", 1}, +}; + +#define BP_STARTUP_TS 1591060628000 + +char *bpStbPrefix = "st"; +char *bpTbPrefix = "t"; +int32_t bpDefaultStbId = 1; +int64_t bpTs; + +// char *operatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in"}; +// char *varoperatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in", "like", "not like", "match", "nmatch"}; + +#define tListLen(x) (sizeof(x) / sizeof((x)[0])) +#define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT) +#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT) +#define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE) +#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t))) + +typedef struct { + bool singleTbInsert; + int32_t singleTbIdx; + + int64_t *tsData; + bool *boolData; + int8_t *tinyData; + uint8_t *utinyData; + int16_t *smallData; + uint16_t *usmallData; + int32_t *intData; + uint32_t *uintData; + int64_t *bigData; + uint64_t *ubigData; + float *floatData; + double *doubleData; + char *binaryData; + char *isNull; + int32_t *binaryLen; + TAOS_STMT2_BIND *pBind; + TAOS_STMT2_BIND *pTags; + char *sql; + int32_t *colTypes; + int32_t colNum; +} BindData; + +int32_t gVarCharSize = 10; +int32_t gVarCharLen = 5; + +int32_t gExecLoopTimes = 1; // no change +int32_t gFullColNum = tListLen(fullColList); + +int insertMBSETest1(TAOS_STMT2 *stmt, TAOS *taos); +int insertMBSETest2(TAOS_STMT2 *stmt, TAOS *taos); +int insertMBMETest1(TAOS_STMT2 *stmt, TAOS *taos); +int insertMBMETest2(TAOS_STMT2 *stmt, TAOS *taos); +int insertMBMETest3(TAOS_STMT2 *stmt, TAOS *taos); +int insertMBMETest4(TAOS_STMT2 *stmt, TAOS *taos); +int insertMPMETest1(TAOS_STMT2 *stmt, TAOS *taos); +int insertAUTOTest1(TAOS_STMT2 *stmt, TAOS *taos); +int insertAUTOTest2(TAOS_STMT2 *stmt, TAOS *taos); +int insertAUTOTest3(TAOS_STMT2 *stmt, TAOS *taos); +int queryColumnTest(TAOS_STMT2 *stmt, TAOS *taos); +int queryMiscTest(TAOS_STMT2 *stmt, TAOS *taos); +int insertNonExistsTb(TAOS_STMT2 *stmt, TAOS *taos); +int insertVarLenErr(TAOS_STMT2 *stmt, TAOS *taos); +int insertStbTest(TAOS_STMT2 *stmt, TAOS *taos); + +enum { + TTYPE_INSERT = 1, + TTYPE_INSERT_NG, + TTYPE_QUERY, +}; + +typedef struct { + char caseDesc[128]; + int32_t colNum; + int32_t *colList; // full table column list + int32_t testType; + int32_t autoCreateTbl; + bool duplicateValue; + bool fullCol; + int32_t (*runFn)(TAOS_STMT2 *, TAOS *); + int32_t tblNum; + int32_t rowNum; + int32_t bindRowNum; + int32_t bindColNum; // equal colNum in full column case + int32_t bindTagNum; // equal colNum in full column case + int32_t bindNullNum; + int32_t runTimes; + int32_t preCaseIdx; + bool stbInsert; +} CaseCfg; + +CaseCfg gCase[] = { + {"insert:MBSE0-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, 0, false, true, insertMBSETest1, 1, 10, + 10, 0, 0, 0, 1, -1, false}, + {"insert:MBSE0-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, 0, false, true, insertMBSETest1, 10, 100, + 10, 0, 0, 0, 1, -1, false}, + + {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBSETest1, 10, 10, 2, + 0, 0, 0, 1, -1, false}, + {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBSETest1, 10, 10, 2, + 12, 0, 0, 1, -1, false}, + {"insert:MBSE1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBSETest1, 10, 10, 2, + 2, 0, 0, 1, -1, false}, + + {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBSETest2, 10, 10, 2, + 0, 0, 0, 1, -1, false}, + {"insert:MBSE2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBSETest2, 10, 10, 2, + 12, 0, 0, 1, -1, false}, + {"insert:MBSE2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBSETest2, 10, 10, 2, + 2, 0, 0, 1, -1, false}, + + {"insert:MBME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBMETest1, 10, 10, 2, + 0, 0, 0, 1, -1, false}, + {"insert:MBME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest1, 10, 10, 2, + 12, 0, 0, 1, -1, false}, + {"insert:MBME1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest1, 10, 10, 2, + 2, 0, 0, 1, -1, false}, + + // 11 + {"insert:MBME2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBMETest2, 10, 10, 2, + 0, 0, 0, 1, -1, false}, + {"insert:MBME2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest2, 10, 10, 2, + 12, 0, 0, 1, -1, false}, + {"insert:MBME2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest2, 10, 10, 2, + 2, 0, 0, 1, -1, false}, + + {"insert:MBME3-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBMETest3, 10, 10, 2, + 0, 0, 0, 1, -1, false}, + {"insert:MBME3-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest3, 10, 10, 2, + 12, 0, 0, 1, -1, false}, + {"insert:MBME3-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest3, 10, 10, 2, + 2, 0, 0, 1, -1, false}, + + {"insert:MBME4-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBMETest4, 10, 10, 2, + 0, 0, 0, 1, -1, false}, + {"insert:MBME4-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest4, 10, 10, 2, + 12, 0, 0, 1, -1, false}, + {"insert:MBME4-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest4, 10, 10, 2, + 2, 0, 0, 1, -1, false}, + + {"insert:MPME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMPMETest1, 10, 10, 2, + 0, 0, 0, 1, -1, false}, + {"insert:MPME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMPMETest1, 10, 10, 2, + 12, 0, 0, 1, -1, false}, + + {"insert:STBI-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertStbTest, 10, 10, 2, 0, + 0, 0, 1, -1, true}, + + // 23 + {"insert:AUTO1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 1, false, true, insertAUTOTest1, 10, 10, 2, + 0, 0, 0, 1, -1, false}, + {"insert:AUTO2-TBEXISTS", tListLen(fullColList), fullColList, TTYPE_INSERT, 3, false, true, insertAUTOTest2, 10, 10, + 2, 0, 0, 0, 1, -1, false}, + // {"insert:AUTO3-NTB", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, true, true, insertAUTOTest3, 10, 10, + // 2, 0, 0, 0, 1, -1, false}, + + {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryColumnTest, 10, 10, 1, + 3, 0, 0, 1, 2, false}, + {"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryMiscTest, 10, 10, 1, 3, + 0, 0, 1, 2, false}, + + {"query:NG-TBNEXISTS", tListLen(fullColList), fullColList, TTYPE_INSERT_NG, 0, false, false, insertNonExistsTb, 10, + 10, 1, 3, 0, 0, 1, -1, false}, + {"query:NG-VARLENERR", tListLen(fullColList), fullColList, TTYPE_INSERT_NG, 0, false, true, insertVarLenErr, 10, 10, + 1, 3, 0, 0, 1, -1, false}, + + // {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryColumnTest, 1, 10, + // 1, 1, 0, 0, 1, 2, false}, + // {"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryMiscTest, 2, 10, 1, + // 1, 0, 0, 1, 2, false}, + +}; + +CaseCfg *gCurCase = NULL; + +typedef struct { + char caseCatalog[255]; + int32_t bindNullNum; + bool checkParamNum; + bool printRes; + bool printCreateTblSql; + bool printQuerySql; + bool printStmtSql; + bool printVerbose; + bool autoCreateTbl; + bool numericParam; + uint8_t precision; + int32_t rowNum; // row num for one table + int32_t bindColNum; + int32_t bindTagNum; + int32_t bindRowNum; // row num for once bind + int32_t bindColTypeNum; + int32_t *bindColTypeList; + int32_t bindTagTypeNum; + int32_t *bindTagTypeList; + int32_t optrIdxListNum; + int32_t *optrIdxList; + int32_t funcIdxListNum; + int32_t *funcIdxList; + int32_t runTimes; + int32_t caseIdx; // static case idx + int32_t caseNum; // num in static case list + int32_t caseRunIdx; // runtime case idx + int32_t caseRunNum; // total run case num +} CaseCtrl; + +#if 0 +CaseCtrl gCaseCtrl = { + .precision = TIME_PRECISION_MILLI, + .bindNullNum = 0, + .printCreateTblSql = true, + .printQuerySql = true, + .printStmtSql = true, + .printVerbose = true, + .printRes = true, + .autoCreateTbl = false, + .numericParam = false, + .rowNum = 0, + .bindColNum = 0, + .bindTagNum = 0, + .bindRowNum = 0, + .bindColTypeNum = 0, + .bindColTypeList = NULL, + .bindTagTypeNum = 0, + .bindTagTypeList = NULL, + .optrIdxListNum = 0, + .optrIdxList = NULL, + .funcIdxListNum = 0, + .funcIdxList = NULL, + .checkParamNum = false, + .runTimes = 0, + .caseIdx = 20, + .caseNum = 1, + .caseRunIdx = -1, + .caseRunNum = -1, +}; +#endif + +#if 1 +CaseCtrl gCaseCtrl = { + // default + .precision = TIME_PRECISION_MILLI, + .bindNullNum = 0, + .printCreateTblSql = true, + .printQuerySql = true, + .printStmtSql = true, + .printVerbose = false, + .printRes = true, + .autoCreateTbl = false, + .numericParam = false, + .rowNum = 0, + .bindColNum = 0, + .bindTagNum = 0, + .bindRowNum = 0, + .bindColTypeNum = 0, + .bindColTypeList = NULL, + .bindTagTypeNum = 0, + .bindTagTypeList = NULL, + .optrIdxListNum = 0, + .optrIdxList = NULL, + .funcIdxListNum = 0, + .funcIdxList = NULL, + .checkParamNum = false, + .runTimes = 0, + .caseIdx = -1, + .caseNum = -1, + .caseRunIdx = -1, + .caseRunNum = -1, +}; +#endif + +#if 0 +CaseCtrl gCaseCtrl = { // query case with specified col&oper + .bindNullNum = 1, + .printCreateTblSql = false, + .printQuerySql = true, + .printStmtSql = true, + .rowNum = 0, + .bindColNum = 0, + .bindRowNum = 0, + .optrIdxListNum = tListLen(optrIdxList), + .optrIdxList = optrIdxList, + .bindColTypeNum = tListLen(bindColTypeList), + .bindColTypeList = bindColTypeList, + .checkParamNum = false, + .printRes = true, + .runTimes = 0, + .caseRunIdx = -1, + .caseIdx = 5, + .caseNum = 1, + .caseRunNum = 1, +}; +#endif + +#if 0 +CaseCtrl gCaseCtrl = { // query case with specified col&oper + .bindNullNum = 0, + .printCreateTblSql = true, + .printQuerySql = true, + .printStmtSql = true, + .autoCreateTbl = true, + .rowNum = 0, + .bindColNum = 0, + .bindTagNum = 0, + .bindRowNum = 0, + .bindColTypeNum = 0, + .bindColTypeList = bindColTypeList, + .optrIdxListNum = 0, + .optrIdxList = optrIdxList, + .checkParamNum = false, + .printRes = true, + .runTimes = 0, + .caseRunIdx = -1, + .optrIdxListNum = tListLen(optrIdxList), + .optrIdxList = optrIdxList, + .bindColTypeNum = tListLen(bindColTypeList), + .bindColTypeList = bindColTypeList, + .caseRunIdx = -1, + .caseIdx = 24, + .caseNum = 1, + .caseRunNum = 1, +}; +#endif + +int32_t taosGetTimeOfDay(struct timeval *tv) { return gettimeofday(tv, NULL); } +void *taosMemoryMalloc(uint64_t size) { return malloc(size); } + +void *taosMemoryCalloc(int32_t num, int32_t size) { return calloc(num, size); } +void taosMemoryFree(const void *ptr) { + if (ptr == NULL) return; + + return free((void *)ptr); +} + +static int64_t taosGetTimestampMs() { + struct timeval systemTime; + taosGetTimeOfDay(&systemTime); + return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_usec / 1000; +} + +static int64_t taosGetTimestampUs() { + struct timeval systemTime; + taosGetTimeOfDay(&systemTime); + return (int64_t)systemTime.tv_sec * 1000000LL + (int64_t)systemTime.tv_usec; +} + +bool colExists(TAOS_STMT2_BIND *pBind, int32_t dataType) { + int32_t i = 0; + while (true) { + if (0 == pBind[i].buffer_type) { + return false; + } + + if (pBind[i].buffer_type == dataType) { + return true; + } + + ++i; + } +} + +void generateInsertSQL(BindData *data) { + int32_t len = 0; + if (gCurCase->tblNum > 1) { + if (data->singleTbInsert) { + len = sprintf(data->sql, "insert into %s%d ", bpTbPrefix, data->singleTbIdx); + } else { + len = sprintf(data->sql, "insert into ? "); + } + } else { + len = sprintf(data->sql, "insert into %s0 ", bpTbPrefix); + } + + if (gCurCase->bindTagNum > 0) { + len += sprintf(data->sql + len, "using %s%d ", bpStbPrefix, bpDefaultStbId); + + if (!gCurCase->fullCol) { + len += sprintf(data->sql + len, "("); + for (int c = 0; c < gCurCase->bindTagNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ","); + } + switch (data->pTags[c].buffer_type) { + case TSDB_DATA_TYPE_BOOL: + len += sprintf(data->sql + len, "tbooldata"); + break; + case TSDB_DATA_TYPE_TINYINT: + len += sprintf(data->sql + len, "ttinydata"); + break; + case TSDB_DATA_TYPE_SMALLINT: + len += sprintf(data->sql + len, "tsmalldata"); + break; + case TSDB_DATA_TYPE_INT: + len += sprintf(data->sql + len, "tintdata"); + break; + case TSDB_DATA_TYPE_BIGINT: + len += sprintf(data->sql + len, "tbigdata"); + break; + case TSDB_DATA_TYPE_FLOAT: + len += sprintf(data->sql + len, "tfloatdata"); + break; + case TSDB_DATA_TYPE_DOUBLE: + len += sprintf(data->sql + len, "tdoubledata"); + break; + case TSDB_DATA_TYPE_VARCHAR: + len += sprintf(data->sql + len, "tbinarydata"); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + len += sprintf(data->sql + len, "tts"); + break; + case TSDB_DATA_TYPE_NCHAR: + len += sprintf(data->sql + len, "tnchardata"); + break; + case TSDB_DATA_TYPE_UTINYINT: + len += sprintf(data->sql + len, "tutinydata"); + break; + case TSDB_DATA_TYPE_USMALLINT: + len += sprintf(data->sql + len, "tusmalldata"); + break; + case TSDB_DATA_TYPE_UINT: + len += sprintf(data->sql + len, "tuintdata"); + break; + case TSDB_DATA_TYPE_UBIGINT: + len += sprintf(data->sql + len, "tubigdata"); + break; + default: + printf("!!!invalid tag type:%d", data->pTags[c].buffer_type); + exit(1); + } + } + + len += sprintf(data->sql + len, ") "); + } + + len += sprintf(data->sql + len, "tags ("); + for (int c = 0; c < gCurCase->bindTagNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ","); + } + len += sprintf(data->sql + len, "?"); + } + len += sprintf(data->sql + len, ") "); + } + + if (!gCurCase->fullCol) { + len += sprintf(data->sql + len, "("); + for (int c = 0; c < gCurCase->bindColNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ","); + } + switch (data->pBind[c].buffer_type) { + case TSDB_DATA_TYPE_BOOL: + len += sprintf(data->sql + len, "booldata"); + break; + case TSDB_DATA_TYPE_TINYINT: + len += sprintf(data->sql + len, "tinydata"); + break; + case TSDB_DATA_TYPE_SMALLINT: + len += sprintf(data->sql + len, "smalldata"); + break; + case TSDB_DATA_TYPE_INT: + len += sprintf(data->sql + len, "intdata"); + break; + case TSDB_DATA_TYPE_BIGINT: + len += sprintf(data->sql + len, "bigdata"); + break; + case TSDB_DATA_TYPE_FLOAT: + len += sprintf(data->sql + len, "floatdata"); + break; + case TSDB_DATA_TYPE_DOUBLE: + len += sprintf(data->sql + len, "doubledata"); + break; + case TSDB_DATA_TYPE_VARCHAR: + len += sprintf(data->sql + len, "binarydata"); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + len += sprintf(data->sql + len, "ts"); + break; + case TSDB_DATA_TYPE_NCHAR: + len += sprintf(data->sql + len, "nchardata"); + break; + case TSDB_DATA_TYPE_UTINYINT: + len += sprintf(data->sql + len, "utinydata"); + break; + case TSDB_DATA_TYPE_USMALLINT: + len += sprintf(data->sql + len, "usmalldata"); + break; + case TSDB_DATA_TYPE_UINT: + len += sprintf(data->sql + len, "uintdata"); + break; + case TSDB_DATA_TYPE_UBIGINT: + len += sprintf(data->sql + len, "ubigdata"); + break; + default: + printf("!!!invalid col type:%d", data->pBind[c].buffer_type); + exit(1); + } + } + + len += sprintf(data->sql + len, ") "); + } + + len += sprintf(data->sql + len, "values ("); + for (int c = 0; c < gCurCase->bindColNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ","); + } + len += sprintf(data->sql + len, "?"); + } + len += sprintf(data->sql + len, ")"); + + if (gCaseCtrl.printStmtSql) { + printf("\tSQL: %s\n", data->sql); + } +} + +void bpAppendOperatorParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) { + OperInfo *pInfo = NULL; + + if (gCaseCtrl.optrIdxListNum > 0) { + pInfo = &operInfo[gCaseCtrl.optrIdxList[idx]]; + } else { + if (TSDB_DATA_TYPE_VARCHAR == dataType || TSDB_DATA_TYPE_NCHAR == dataType || TSDB_DATA_TYPE_GEOMETRY == dataType) { +#if 1 + pInfo = &operInfo[varoperatorList[rand() % tListLen(varoperatorList)]]; +#else + pInfo = &operInfo[11]; +#endif + } else { + pInfo = &operInfo[operatorList[rand() % tListLen(operatorList)]]; + } + } + + switch (pInfo->paramNum) { + case 2: + if (pInfo->enclose) { + *len += sprintf(data->sql + *len, " %s (?)", pInfo->oper); + } else { + *len += sprintf(data->sql + *len, " %s ?", pInfo->oper); + } + break; + default: + printf("!!!invalid operator paramNum:%d\n", pInfo->paramNum); + exit(1); + } +} + +void bpAppendFunctionParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) { + FuncInfo *pInfo = NULL; + + if (gCaseCtrl.funcIdxListNum > 0) { + pInfo = &funcInfo[gCaseCtrl.funcIdxList[idx]]; + } else { + pInfo = &funcInfo[rand() % tListLen(funcInfo)]; + } + + switch (pInfo->paramNum) { + case 1: + *len += sprintf(data->sql + *len, " %s(?)", pInfo->funcName); + break; + default: + printf("!!!invalid function paramNum:%d\n", pInfo->paramNum); + exit(1); + } +} + +int32_t bpAppendColumnName(BindData *data, int32_t type, int32_t len) { + switch (type) { + case TSDB_DATA_TYPE_BOOL: + return sprintf(data->sql + len, "booldata"); + break; + case TSDB_DATA_TYPE_TINYINT: + return sprintf(data->sql + len, "tinydata"); + break; + case TSDB_DATA_TYPE_SMALLINT: + return sprintf(data->sql + len, "smalldata"); + break; + case TSDB_DATA_TYPE_INT: + return sprintf(data->sql + len, "intdata"); + break; + case TSDB_DATA_TYPE_BIGINT: + return sprintf(data->sql + len, "bigdata"); + break; + case TSDB_DATA_TYPE_FLOAT: + return sprintf(data->sql + len, "floatdata"); + break; + case TSDB_DATA_TYPE_DOUBLE: + return sprintf(data->sql + len, "doubledata"); + break; + case TSDB_DATA_TYPE_VARCHAR: + return sprintf(data->sql + len, "binarydata"); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + return sprintf(data->sql + len, "ts"); + break; + case TSDB_DATA_TYPE_NCHAR: + return sprintf(data->sql + len, "nchardata"); + break; + case TSDB_DATA_TYPE_UTINYINT: + return sprintf(data->sql + len, "utinydata"); + break; + case TSDB_DATA_TYPE_USMALLINT: + return sprintf(data->sql + len, "usmalldata"); + break; + case TSDB_DATA_TYPE_UINT: + return sprintf(data->sql + len, "uintdata"); + break; + case TSDB_DATA_TYPE_UBIGINT: + return sprintf(data->sql + len, "ubigdata"); + break; + default: + printf("!!!invalid col type:%d", type); + exit(1); + } + + return 0; +} + +void generateQueryCondSQL(BindData *data, int32_t tblIdx) { + int32_t len = sprintf(data->sql, "select * from %s%d where ", bpTbPrefix, tblIdx); + if (!gCurCase->fullCol) { + for (int c = 0; c < gCurCase->bindColNum; ++c) { + if (c) { + len += sprintf(data->sql + len, " and "); + } + len += bpAppendColumnName(data, data->pBind[c].buffer_type, len); + + bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c); + } + } + + if (gCaseCtrl.printStmtSql) { + printf("\tSTMT SQL: %s\n", data->sql); + } +} + +void bpGenerateConstInOpSQL(BindData *data, int32_t tblIdx) { + int32_t len = 0; + len = sprintf(data->sql, "select "); + + for (int c = 0; c < gCurCase->bindColNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ", "); + } + + len += bpAppendColumnName(data, data->pBind[c].buffer_type, len); + + bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c); + } + + len += sprintf(data->sql + len, " from %s%d", bpTbPrefix, tblIdx); +} + +void bpGenerateConstInFuncSQL(BindData *data, int32_t tblIdx) { + int32_t len = 0; + len = sprintf(data->sql, "select "); + + for (int c = 0; c < gCurCase->bindColNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ", "); + } + + bpAppendFunctionParam(data, &len, data->pBind[c].buffer_type, c); + } + + len += sprintf(data->sql + len, " from %s%d", bpTbPrefix, tblIdx); +} + +void generateQueryMiscSQL(BindData *data, int32_t tblIdx) { + if (tblIdx == FUNCTION_TEST_IDX && gCurCase->bindNullNum <= 0) { + bpGenerateConstInFuncSQL(data, tblIdx); + } else { + switch (tblIdx) { + case 0: + // TODO FILL TEST + default: + bpGenerateConstInOpSQL(data, tblIdx); + break; + } + } + + if (gCaseCtrl.printStmtSql) { + printf("\tSTMT SQL: %s\n", data->sql); + } +} + +void generateErrorSQL(BindData *data, int32_t tblIdx) { + int32_t len = 0; + data->sql = taosMemoryCalloc(1, 1024); + + switch (tblIdx) { + case 0: + len = sprintf(data->sql, "insert into %s%d values (?, 1)", bpTbPrefix, tblIdx); + break; + case 1: + len = sprintf(data->sql, "select * from ?"); + break; + case 2: + len = sprintf(data->sql, "select * from %s%d where ? = ?", bpTbPrefix, tblIdx); + break; + default: + len = sprintf(data->sql, "select count(*) from %s%d group by ?", bpTbPrefix, tblIdx); + break; + } + + if (gCaseCtrl.printStmtSql) { + printf("\tSTMT SQL: %s\n", data->sql); + } +} + +void generateColDataType(bool isQuery, BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) { + if (bindIdx < gCurCase->bindColNum) { + if (gCaseCtrl.bindColTypeNum) { + *dataType = gCaseCtrl.bindColTypeList[colIdx]; + return; + } else if (gCurCase->fullCol) { + *dataType = gCurCase->colList[bindIdx]; + return; + } else if (gCaseCtrl.numericParam) { + while (true) { + *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1; + if (!IS_NUMERIC_TYPE(*dataType)) { + continue; + } + + break; + } + return; + } else if (0 == colIdx && !isQuery) { + *dataType = TSDB_DATA_TYPE_TIMESTAMP; + return; + } else { + while (true) { +#if 1 + *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1; +#else + if (!colExists(data->pBind, TSDB_DATA_TYPE_NCHAR)) { + *dataType = TSDB_DATA_TYPE_NCHAR; + } else { + *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1; + } +#endif + if (*dataType == TSDB_DATA_TYPE_JSON || *dataType == TSDB_DATA_TYPE_DECIMAL || + *dataType == TSDB_DATA_TYPE_BLOB || *dataType == TSDB_DATA_TYPE_MEDIUMBLOB || + *dataType == TSDB_DATA_TYPE_VARBINARY || *dataType == TSDB_DATA_TYPE_GEOMETRY) { + continue; + } + + if (colExists(data->pBind, *dataType)) { + continue; + } + + break; + } + } + } else { + *dataType = data->pBind[bindIdx % gCurCase->bindColNum].buffer_type; + } +} + +void generateTagDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) { + if (bindIdx < gCurCase->bindTagNum) { + if (gCaseCtrl.bindTagTypeNum) { + *dataType = gCaseCtrl.bindTagTypeList[colIdx]; + return; + } else if (gCurCase->fullCol) { + *dataType = gCurCase->colList[bindIdx]; + return; + } else { + while (true) { + *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1; + if (*dataType == TSDB_DATA_TYPE_JSON || *dataType == TSDB_DATA_TYPE_DECIMAL || + *dataType == TSDB_DATA_TYPE_BLOB || *dataType == TSDB_DATA_TYPE_MEDIUMBLOB || + *dataType == TSDB_DATA_TYPE_VARBINARY || *dataType == TSDB_DATA_TYPE_GEOMETRY) { + continue; + } + + if (colExists(data->pTags, *dataType)) { + continue; + } + + break; + } + } + } else { + *dataType = data->pTags[bindIdx % gCurCase->bindTagNum].buffer_type; + } +} + +int32_t prepareColData(bool isQuery, BP_BIND_TYPE bType, BindData *data, int32_t bindIdx, int32_t rowIdx, + int32_t colIdx) { + int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP; + TAOS_STMT2_BIND *pBase = NULL; + + if (bType == BP_BIND_TAG) { + pBase = data->pTags; + generateTagDataType(data, bindIdx, colIdx, &dataType); + } else { + pBase = data->pBind; + generateColDataType(isQuery, data, bindIdx, colIdx, &dataType); + } + + switch (dataType) { + case TSDB_DATA_TYPE_BOOL: + // pBase[bindIdx].buffer_length = sizeof(bool); + pBase[bindIdx].buffer = data->boolData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_TINYINT: + // pBase[bindIdx].buffer_length = sizeof(int8_t); + pBase[bindIdx].buffer = data->tinyData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_SMALLINT: + // pBase[bindIdx].buffer_length = sizeof(int16_t); + pBase[bindIdx].buffer = data->smallData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_INT: + // pBase[bindIdx].buffer_length = sizeof(int32_t); + pBase[bindIdx].buffer = data->intData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_BIGINT: + // pBase[bindIdx].buffer_length = sizeof(int64_t); + pBase[bindIdx].buffer = data->bigData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_FLOAT: + // pBase[bindIdx].buffer_length = sizeof(float); + pBase[bindIdx].buffer = data->floatData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_DOUBLE: + // pBase[bindIdx].buffer_length = sizeof(double); + pBase[bindIdx].buffer = data->doubleData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_VARCHAR: + case TSDB_DATA_TYPE_GEOMETRY: + // pBase[bindIdx].buffer_length = gVarCharSize; + // pBase[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize; + pBase[bindIdx].buffer = data->binaryData + rowIdx * gVarCharLen; + pBase[bindIdx].length = data->binaryLen; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_TIMESTAMP: + // pBase[bindIdx].buffer_length = sizeof(int64_t); + pBase[bindIdx].buffer = data->tsData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = NULL; + break; + case TSDB_DATA_TYPE_NCHAR: + // pBase[bindIdx].buffer_length = gVarCharSize; + // pBase[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize; + pBase[bindIdx].buffer = data->binaryData + rowIdx * gVarCharLen; + pBase[bindIdx].length = data->binaryLen; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_UTINYINT: + // pBase[bindIdx].buffer_length = sizeof(uint8_t); + pBase[bindIdx].buffer = data->utinyData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_USMALLINT: + // pBase[bindIdx].buffer_length = sizeof(uint16_t); + pBase[bindIdx].buffer = data->usmallData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_UINT: + // pBase[bindIdx].buffer_length = sizeof(uint32_t); + pBase[bindIdx].buffer = data->uintData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_UBIGINT: + // pBase[bindIdx].buffer_length = sizeof(uint64_t); + pBase[bindIdx].buffer = data->ubigData + rowIdx; + pBase[bindIdx].length = NULL; + pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + default: + printf("!!!invalid col type:%d", dataType); + exit(1); + } + + pBase[bindIdx].buffer_type = dataType; + pBase[bindIdx].num = gCurCase->bindRowNum; + + if (bType == BP_BIND_TAG) { + pBase[bindIdx].num = 1; + } + + return 0; +} + +int32_t prepareInsertData(BindData *data) { + uint64_t allRowNum = gCurCase->rowNum * gCurCase->tblNum; + + data->colNum = 0; + data->colTypes = taosMemoryCalloc(30, sizeof(int32_t)); + data->sql = taosMemoryCalloc(1, 1024); + data->pBind = + taosMemoryCalloc((int32_t)(allRowNum / gCurCase->bindRowNum) * gCurCase->bindColNum, sizeof(TAOS_STMT2_BIND)); + data->pTags = taosMemoryCalloc(gCurCase->tblNum * gCurCase->bindTagNum, sizeof(TAOS_STMT2_BIND)); + data->tsData = taosMemoryMalloc(allRowNum * sizeof(int64_t)); + data->boolData = taosMemoryMalloc(allRowNum * sizeof(bool)); + data->tinyData = taosMemoryMalloc(allRowNum * sizeof(int8_t)); + data->utinyData = taosMemoryMalloc(allRowNum * sizeof(uint8_t)); + data->smallData = taosMemoryMalloc(allRowNum * sizeof(int16_t)); + data->usmallData = taosMemoryMalloc(allRowNum * sizeof(uint16_t)); + data->intData = taosMemoryMalloc(allRowNum * sizeof(int32_t)); + data->uintData = taosMemoryMalloc(allRowNum * sizeof(uint32_t)); + data->bigData = taosMemoryMalloc(allRowNum * sizeof(int64_t)); + data->ubigData = taosMemoryMalloc(allRowNum * sizeof(uint64_t)); + data->floatData = taosMemoryMalloc(allRowNum * sizeof(float)); + data->doubleData = taosMemoryMalloc(allRowNum * sizeof(double)); + data->binaryData = taosMemoryMalloc(allRowNum * gVarCharSize); + data->binaryLen = taosMemoryMalloc(allRowNum * sizeof(int32_t)); + if (gCurCase->bindNullNum) { + data->isNull = taosMemoryCalloc((int32_t)allRowNum, sizeof(char)); + } + + for (int32_t i = 0; i < allRowNum; ++i) { + if (gCurCase->duplicateValue) { + data->tsData[i] = bpTs; + if (i % 2 == 1) { + bpTs++; + } + } else { + data->tsData[i] = bpTs++; + } + data->boolData[i] = (bool)(i % 2); + data->tinyData[i] = (int8_t)i; + data->utinyData[i] = (uint8_t)(i + 1); + data->smallData[i] = (int16_t)i; + data->usmallData[i] = (uint16_t)(i + 1); + data->intData[i] = (int32_t)i; + data->uintData[i] = (uint32_t)(i + 1); + data->bigData[i] = (int64_t)i; + data->ubigData[i] = (uint64_t)(i + 1); + data->floatData[i] = (float)i; + data->doubleData[i] = (double)(i + 1); + // memset(data->binaryData + gVarCharSize * i, 'a' + i % 26, gVarCharLen); + memset(data->binaryData + gVarCharLen * i, 'a' + i % 26, gVarCharLen); + if (gCurCase->bindNullNum) { + data->isNull[i] = (char)(i % 2); + } + data->binaryLen[i] = gVarCharLen; + } + + for (int b = 0; b < (allRowNum / gCurCase->bindRowNum); b++) { + for (int c = 0; c < gCurCase->bindColNum; ++c) { + prepareColData(false, BP_BIND_COL, data, b * gCurCase->bindColNum + c, b * gCurCase->bindRowNum, c); + } + } + + for (int b = 0; b < gCurCase->tblNum; b++) { + for (int c = 0; c < gCurCase->bindTagNum; ++c) { + prepareColData(false, BP_BIND_TAG, data, b * gCurCase->bindTagNum + c, b, c); + } + } + + generateInsertSQL(data); + + return 0; +} + +int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) { + uint64_t bindNum = gCurCase->rowNum / gCurCase->bindRowNum; + + data->colNum = 0; + data->colTypes = taosMemoryCalloc(30, sizeof(int32_t)); + data->sql = taosMemoryCalloc(1, 1024); + data->pBind = taosMemoryCalloc((int32_t)bindNum * gCurCase->bindColNum, sizeof(TAOS_STMT2_BIND)); + data->tsData = taosMemoryMalloc(bindNum * sizeof(int64_t)); + data->boolData = taosMemoryMalloc(bindNum * sizeof(bool)); + data->tinyData = taosMemoryMalloc(bindNum * sizeof(int8_t)); + data->utinyData = taosMemoryMalloc(bindNum * sizeof(uint8_t)); + data->smallData = taosMemoryMalloc(bindNum * sizeof(int16_t)); + data->usmallData = taosMemoryMalloc(bindNum * sizeof(uint16_t)); + data->intData = taosMemoryMalloc(bindNum * sizeof(int32_t)); + data->uintData = taosMemoryMalloc(bindNum * sizeof(uint32_t)); + data->bigData = taosMemoryMalloc(bindNum * sizeof(int64_t)); + data->ubigData = taosMemoryMalloc(bindNum * sizeof(uint64_t)); + data->floatData = taosMemoryMalloc(bindNum * sizeof(float)); + data->doubleData = taosMemoryMalloc(bindNum * sizeof(double)); + data->binaryData = taosMemoryMalloc(bindNum * gVarCharSize); + data->binaryLen = taosMemoryMalloc(bindNum * sizeof(int32_t)); + if (gCurCase->bindNullNum) { + data->isNull = taosMemoryCalloc((int32_t)bindNum, sizeof(char)); + } + + for (int32_t i = 0; i < bindNum; ++i) { + data->tsData[i] = bpTs + tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum; + data->boolData[i] = (bool)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->tinyData[i] = (int8_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->utinyData[i] = (uint8_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->smallData[i] = (int16_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->usmallData[i] = (uint16_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->intData[i] = (int32_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->uintData[i] = (uint32_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->bigData[i] = (int64_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->ubigData[i] = (uint64_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->floatData[i] = (float)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->doubleData[i] = (double)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + // memset(data->binaryData + gVarCharSize * i, 'a' + i % 26, gVarCharLen); + memset(data->binaryData + gVarCharLen * i, 'a' + i % 26, gVarCharLen); + if (gCurCase->bindNullNum) { + data->isNull[i] = (char)(i % 2); + } + data->binaryLen[i] = gVarCharLen; + } + + for (int b = 0; b < bindNum; b++) { + for (int c = 0; c < gCurCase->bindColNum; ++c) { + prepareColData(true, BP_BIND_COL, data, b * gCurCase->bindColNum + c, b * gCurCase->bindRowNum, c); + } + } + + generateQueryCondSQL(data, tblIdx); + + return 0; +} + +int32_t prepareQueryMiscData(BindData *data, int32_t tblIdx) { + uint64_t bindNum = gCurCase->rowNum / gCurCase->bindRowNum; + + data->colNum = 0; + data->colTypes = taosMemoryCalloc(30, sizeof(int32_t)); + data->sql = taosMemoryCalloc(1, 1024); + data->pBind = taosMemoryCalloc((int32_t)bindNum * gCurCase->bindColNum, sizeof(TAOS_STMT2_BIND)); + data->tsData = taosMemoryMalloc(bindNum * sizeof(int64_t)); + data->boolData = taosMemoryMalloc(bindNum * sizeof(bool)); + data->tinyData = taosMemoryMalloc(bindNum * sizeof(int8_t)); + data->utinyData = taosMemoryMalloc(bindNum * sizeof(uint8_t)); + data->smallData = taosMemoryMalloc(bindNum * sizeof(int16_t)); + data->usmallData = taosMemoryMalloc(bindNum * sizeof(uint16_t)); + data->intData = taosMemoryMalloc(bindNum * sizeof(int32_t)); + data->uintData = taosMemoryMalloc(bindNum * sizeof(uint32_t)); + data->bigData = taosMemoryMalloc(bindNum * sizeof(int64_t)); + data->ubigData = taosMemoryMalloc(bindNum * sizeof(uint64_t)); + data->floatData = taosMemoryMalloc(bindNum * sizeof(float)); + data->doubleData = taosMemoryMalloc(bindNum * sizeof(double)); + data->binaryData = taosMemoryMalloc(bindNum * gVarCharSize); + data->binaryLen = taosMemoryMalloc(bindNum * sizeof(int32_t)); + if (gCurCase->bindNullNum) { + data->isNull = taosMemoryCalloc((int32_t)bindNum, sizeof(char)); + } + + for (int32_t i = 0; i < bindNum; ++i) { + data->tsData[i] = bpTs + tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum; + data->boolData[i] = (bool)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->tinyData[i] = (int8_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->utinyData[i] = (uint8_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->smallData[i] = (int16_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->usmallData[i] = (uint16_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->intData[i] = (int32_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->uintData[i] = (uint32_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->bigData[i] = (int64_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->ubigData[i] = (uint64_t)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->floatData[i] = (float)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + data->doubleData[i] = (double)(tblIdx * gCurCase->rowNum + rand() % gCurCase->rowNum); + // memset(data->binaryData + gVarCharSize * i, 'a' + i % 26, gVarCharLen); + memset(data->binaryData + gVarCharLen * i, 'a' + i % 26, gVarCharLen); + if (gCurCase->bindNullNum) { + data->isNull[i] = (char)(i % 2); + } + data->binaryLen[i] = gVarCharLen; + } + + if (tblIdx == FUNCTION_TEST_IDX) { + gCaseCtrl.numericParam = true; + } else { + gCaseCtrl.numericParam = false; + } + + for (int b = 0; b < bindNum; b++) { + for (int c = 0; c < gCurCase->bindColNum; ++c) { + prepareColData(true, BP_BIND_COL, data, b * gCurCase->bindColNum + c, b * gCurCase->bindRowNum, c); + } + } + + gCaseCtrl.numericParam = false; + + generateQueryMiscSQL(data, tblIdx); + + return 0; +} + +void destroyData(BindData *data) { + taosMemoryFree(data->tsData); + taosMemoryFree(data->boolData); + taosMemoryFree(data->tinyData); + taosMemoryFree(data->utinyData); + taosMemoryFree(data->smallData); + taosMemoryFree(data->usmallData); + taosMemoryFree(data->intData); + taosMemoryFree(data->uintData); + taosMemoryFree(data->bigData); + taosMemoryFree(data->ubigData); + taosMemoryFree(data->floatData); + taosMemoryFree(data->doubleData); + taosMemoryFree(data->binaryData); + taosMemoryFree(data->binaryLen); + taosMemoryFree(data->isNull); + taosMemoryFree(data->pBind); + taosMemoryFree(data->pTags); + taosMemoryFree(data->colTypes); + taosMemoryFree(data->sql); +} + +void bpFetchRows(TAOS_RES *result, bool printr, int32_t *rows) { + TAOS_ROW row; + int num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + char temp[256]; + + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + (*rows)++; + if (printr) { + memset(temp, 0, sizeof(temp)); + taos_print_row(temp, row, fields, num_fields); + printf("\t[%s]\n", temp); + } + } +} + +void bpExecQuery(TAOS *taos, char *sql, bool printr, int32_t *rows) { + TAOS_RES *result = taos_query(taos, sql); + int code = taos_errno(result); + if (code != 0) { + printf("!!!failed to query table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + + bpFetchRows(result, printr, rows); + + taos_free_result(result); +} + +int32_t bpAppendValueString(char *buf, int type, void *value, int32_t valueLen, int32_t *len) { + switch (type) { + case TSDB_DATA_TYPE_NULL: + *len += sprintf(buf + *len, "null"); + break; + + case TSDB_DATA_TYPE_BOOL: + *len += sprintf(buf + *len, (*(bool *)value) ? "true" : "false"); + break; + + case TSDB_DATA_TYPE_TINYINT: + *len += sprintf(buf + *len, "%d", *(int8_t *)value); + break; + + case TSDB_DATA_TYPE_SMALLINT: + *len += sprintf(buf + *len, "%d", *(int16_t *)value); + break; + + case TSDB_DATA_TYPE_INT: + *len += sprintf(buf + *len, "%d", *(int32_t *)value); + break; + + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_TIMESTAMP: + *len += sprintf(buf + *len, "%ld", *(int64_t *)value); + break; + + case TSDB_DATA_TYPE_FLOAT: + *len += sprintf(buf + *len, "%e", *(float *)value); + break; + + case TSDB_DATA_TYPE_DOUBLE: + *len += sprintf(buf + *len, "%e", *(double *)value); + break; + + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_VARBINARY: + case TSDB_DATA_TYPE_NCHAR: + case TSDB_DATA_TYPE_GEOMETRY: + buf[*len] = '\''; + ++(*len); + memcpy(buf + *len, value, valueLen); + *len += valueLen; + buf[*len] = '\''; + ++(*len); + break; + + case TSDB_DATA_TYPE_UTINYINT: + *len += sprintf(buf + *len, "%d", *(uint8_t *)value); + break; + + case TSDB_DATA_TYPE_USMALLINT: + *len += sprintf(buf + *len, "%d", *(uint16_t *)value); + break; + + case TSDB_DATA_TYPE_UINT: + *len += sprintf(buf + *len, "%u", *(uint32_t *)value); + break; + + case TSDB_DATA_TYPE_UBIGINT: + *len += sprintf(buf + *len, "%lu", *(uint64_t *)value); + break; + + default: + printf("!!!invalid data type:%d\n", type); + exit(1); + } +} + +static TAOS_STMT2 *st_stmt2_init(TAOS *taos, bool stb_insert) { + TAOS_STMT2_OPTION option = {0}; + if (stb_insert) { + option.singleStbInsert = true; + option.singleTableBindOnce = true; + } + + return taos_stmt2_init(taos, &option); +} + +static int st_stmt2_close(TAOS_STMT2 *stmt) { return taos_stmt2_close(stmt); } + +static char *st_stmt2_error(TAOS_STMT2 *stmt) { return taos_stmt2_error(stmt); } + +static int st_stmt2_prepare(TAOS_STMT2 *stmt, const char *sql, unsigned long length) { + return taos_stmt2_prepare(stmt, sql, length); +} + +static int st_stmt2_bind(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx) { + return taos_stmt2_bind_param(stmt, bindv, col_idx); +} + +static int st_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows) { return taos_stmt2_exec(stmt, affected_rows); } + +static int st_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) { return taos_stmt2_is_insert(stmt, insert); } + +static int st_stmt2_num_params(TAOS_STMT2 *stmt, int *count) { + return taos_stmt2_get_fields(stmt, TAOS_FIELD_QUERY, count, NULL); +} + +static int st_stmt2_get_tag_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_E **fields) { + return taos_stmt2_get_fields(stmt, TAOS_FIELD_TAG, count, fields); +} + +static int st_stmt2_get_col_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_E **fields) { + return taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, count, fields); +} + +static int st_stmt2_get_param(TAOS_STMT2 *stmt, int idx, int *type, int *bytes) { + int32_t code = 0, nums = 0; + TAOS_FIELD_E *fields = NULL; + + code = taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, &nums, &fields); + if (code) { + return code; + } + + if (idx > nums) { + taosMemoryFree(fields); + return -1; + } + + *type = fields[idx].type; + *bytes = fields[idx].bytes; + + taosMemoryFree(fields); + return 0; +} + +static int st_stmt2_set_tbname(TAOS_STMT2 *stmt, char *name) { + TAOS_STMT2_BINDV bindv = {0}; + bindv.count = 1; + bindv.tbnames = &name; + return taos_stmt2_bind_param(stmt, &bindv, -1); +} + +static int st_stmt2_set_tags(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *tags) { + TAOS_STMT2_BINDV bindv = {0}; + bindv.count = 1; + bindv.tags = &tags; + return taos_stmt2_bind_param(stmt, &bindv, -1); +} + +static int st_stmt2_set_tbname_tags(TAOS_STMT2 *stmt, char *name, TAOS_STMT2_BIND *tags) { + TAOS_STMT2_BINDV bindv = {0}; + bindv.count = 1; + bindv.tbnames = &name; + bindv.tags = &tags; + return taos_stmt2_bind_param(stmt, &bindv, -1); +} + +static int st_stmt2_bind_param_batch(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind) { + TAOS_STMT2_BINDV bindv = {0}; + bindv.count = 1; + bindv.bind_cols = &bind; + return taos_stmt2_bind_param(stmt, &bindv, -1); +} + +static int st_stmt2_bind_single_param_batch(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int col_idx) { + TAOS_STMT2_BINDV bindv = {0}; + bindv.count = 1; + bindv.bind_cols = &bind; + return taos_stmt2_bind_param(stmt, &bindv, col_idx); +} + +static int st_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind) { + TAOS_STMT2_BINDV bindv = {0}; + bindv.count = 1; + bindv.bind_cols = &bind; + return taos_stmt2_bind_param(stmt, &bindv, -1); +} + +static int st_stmt2_add_batch(TAOS_STMT2 *stmt) { return 0; } + +static TAOS_RES *st_stmt2_use_result(TAOS_STMT2 *stmt) { return taos_stmt2_result(stmt); } + +void bpCheckIsInsert(TAOS_STMT2 *stmt, int32_t insert) { + int32_t isInsert = 0; + if (st_stmt2_is_insert(stmt, &isInsert)) { + printf("!!!st_stmt2_is_insert error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (insert != isInsert) { + printf("!!!is insert failed\n"); + exit(1); + } +} + +void bpCheckParamNum(TAOS_STMT2 *stmt) { + int32_t num = 0; + if (st_stmt2_num_params(stmt, &num)) { + printf("!!!st_stmt2_num_params error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (gCurCase->bindColNum != num) { + printf("!!!is insert failed\n"); + exit(1); + } +} + +void bpCheckAffectedRows(TAOS_STMT2 *stmt, int32_t times) { + /* TODO: affected rows from exec + int32_t rows = taos_stmt_affected_rows(stmt); + int32_t insertNum = gCurCase->rowNum * gCurCase->tblNum * times; + if (gCurCase->duplicateValue) { + insertNum /= 2; + } + if (insertNum != rows) { + printf("!!!affected rows %d mis-match with insert num %d\n", rows, insertNum); + exit(1); + } + */ +} + +void bpCheckQueryResult(TAOS_STMT2 *stmt, TAOS *taos, char *stmtSql, TAOS_STMT2_BIND *bind) { + // query using sql + char sql[1024]; + int32_t len = 0; + char *p = stmtSql; + char *s = NULL; + int32_t sqlResNum = 0; + + for (int32_t i = 0; true; ++i, p = s + 1) { + s = strchr(p, '?'); + if (NULL == s) { + strcpy(&sql[len], p); + break; + } + + memcpy(&sql[len], p, (int64_t)s - (int64_t)p); + len += (int32_t)((int64_t)s - (int64_t)p); + + if (bind[i].is_null && bind[i].is_null[0]) { + bpAppendValueString(sql, TSDB_DATA_TYPE_NULL, NULL, 0, &len); + continue; + } + + bpAppendValueString(sql, bind[i].buffer_type, bind[i].buffer, (bind[i].length ? bind[i].length[0] : 0), &len); + } + + if (gCaseCtrl.printQuerySql) { + printf("\tQuery SQL: %s\n", sql); + } + + bpExecQuery(taos, sql, gCaseCtrl.printRes, &sqlResNum); + + // query using stmt + TAOS_RES *res = st_stmt2_use_result(stmt); + int32_t stmtResNum = 0; + bpFetchRows(res, gCaseCtrl.printRes, &stmtResNum); + + if (sqlResNum != stmtResNum) { + printf("!!!sql res num %d mis-match stmt res num %d\n", sqlResNum, stmtResNum); + exit(1); + } + + printf("***sql res num match stmt res num %d\n", stmtResNum); +} + +void bpCheckColTagFields(TAOS_STMT2 *stmt, int32_t fieldNum, TAOS_FIELD_E *pFields, int32_t expecteNum, + TAOS_STMT2_BIND *pBind, BP_BIND_TYPE type) { + int32_t code = 0; + + if (fieldNum != expecteNum) { + printf("!!!%s field num %d mis-match expect num %d\n", BP_BIND_TYPE_STR(type), fieldNum, expecteNum); + exit(1); + } + + if (type == BP_BIND_COL) { + if (pFields[0].precision != gCaseCtrl.precision) { + printf("!!!db precision %d mis-match expect %d\n", pFields[0].precision, gCaseCtrl.precision); + exit(1); + } + } + + for (int32_t i = 0; i < fieldNum; ++i) { + if (pFields[i].type != pBind[i].buffer_type) { + printf("!!!%s %dth field type %d mis-match expect type %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].type, + pBind[i].buffer_type); + exit(1); + } + + if (pFields[i].type == TSDB_DATA_TYPE_BINARY || pFields[i].type == TSDB_DATA_TYPE_VARBINARY || + pFields[i].type == TSDB_DATA_TYPE_GEOMETRY) { + /* + if (pFields[i].bytes != (pBind[i].buffer_length + 2)) { + printf("!!!%s %dth field len %d mis-match expect len %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].bytes, + (pBind[i].buffer_length + 2)); + exit(1); + } + */ + } else if (pFields[i].type == TSDB_DATA_TYPE_NCHAR) { + /* + if (pFields[i].bytes != (pBind[i].buffer_length * 4 + 2)) { + printf("!!!%s %dth field len %d mis-match expect len %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].bytes, + (pBind[i].buffer_length + 2)); + exit(1); + } + */ + /*} else if (pFields[i].bytes != pBind[i].buffer_length) { + printf("!!!%s %dth field len %d mis-match expect len %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].bytes, + pBind[i].buffer_length); + exit(1);*/ + } + } + + if (type == BP_BIND_COL) { + int fieldType = 0; + int fieldBytes = 0; + for (int32_t i = 0; i < fieldNum; ++i) { + code = st_stmt2_get_param(stmt, i, &fieldType, &fieldBytes); + if (code) { + printf("!!!st_stmt2_get_param error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (pFields[i].type != fieldType) { + printf("!!!%s %dth field type %d mis-match expect type %d\n", BP_BIND_TYPE_STR(type), i, fieldType, + pFields[i].type); + exit(1); + } + + if (pFields[i].bytes != fieldBytes) { + printf("!!!%s %dth field len %d mis-match expect len %d\n", BP_BIND_TYPE_STR(type), i, fieldBytes, + pFields[i].bytes); + exit(1); + } + } + } + + if (gCaseCtrl.printVerbose) { + printf("%s fields check passed\n", BP_BIND_TYPE_STR(type)); + } +} + +void bpCheckTagFields(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *pBind) { + int32_t code = 0; + int fieldNum = 0; + TAOS_FIELD_E *pFields = NULL; + code = st_stmt2_get_tag_fields(stmt, &fieldNum, &pFields); + if (code != 0) { + printf("!!!st_stmt2_get_tag_fields error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckColTagFields(stmt, fieldNum, pFields, gCurCase->bindTagNum, pBind, BP_BIND_TAG); + taosMemoryFree(pFields); +} + +void bpCheckColFields(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *pBind) { + if (gCurCase->testType == TTYPE_QUERY) { + return; + } + + int32_t code = 0; + int fieldNum = 0; + TAOS_FIELD_E *pFields = NULL; + code = st_stmt2_get_col_fields(stmt, &fieldNum, &pFields); + if (code != 0) { + printf("!!!st_stmt2_get_col_fields error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckColTagFields(stmt, fieldNum, pFields, gCurCase->bindColNum, pBind, BP_BIND_COL); + taosMemoryFree(pFields); +} + +void bpShowBindParam(TAOS_STMT2_BIND *bind, int32_t num) { + for (int32_t i = 0; i < num; ++i) { + TAOS_STMT2_BIND *b = &bind[i]; + printf("Bind %d: type[%d],buf[%p],len[%d],null[%d],num[%d]\n", i, b->buffer_type, b->buffer, + /*b->buffer_length,*/ b->length ? *b->length : 0, b->is_null ? *b->is_null : 0, b->num); + } +} + +int32_t bpBindParam(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, bool expectFail) { + static int32_t n = 0; + + if (!expectFail) { + bpCheckColFields(stmt, bind); + } + + if (gCurCase->bindRowNum > 1) { + if (0 == (n++ % 2) || gCurCase->stbInsert) { + if (st_stmt2_bind_param_batch(stmt, bind)) { + if (expectFail) return 0; + printf("!!!st_stmt2_bind_param_batch error:%s\n", st_stmt2_error(stmt)); + bpShowBindParam(bind, gCurCase->bindColNum); + exit(1); + } + } else { + for (int32_t i = 0; i < gCurCase->bindColNum; ++i) { + if (st_stmt2_bind_single_param_batch(stmt, bind + i, i)) { + if (expectFail) continue; + printf("!!!st_stmt2_bind_single_param_batch %d error:%s\n", i, st_stmt2_error(stmt)); + bpShowBindParam(bind, gCurCase->bindColNum); + exit(1); + } + } + } + } else { + if (0 == (n++ % 2)) { + if (st_stmt2_bind_param_batch(stmt, bind)) { + if (expectFail) return 0; + printf("!!!st_stmt2_bind_param_batch error:%s\n", st_stmt2_error(stmt)); + bpShowBindParam(bind, gCurCase->bindColNum); + exit(1); + } + } else { + if (st_stmt2_bind_param(stmt, bind)) { + if (expectFail) return 0; + printf("!!!st_stmt2_bind_param error:%s\n", st_stmt2_error(stmt)); + bpShowBindParam(bind, gCurCase->bindColNum); + exit(1); + } + } + } + + return 0; +} + +int32_t bpSetTableNameTags(BindData *data, int32_t tblIdx, char *tblName, TAOS_STMT2 *stmt) { + int32_t code = 0; + if (gCurCase->bindTagNum > 0) { + if ((rand() % 2) == 0) { + code = st_stmt2_set_tbname(stmt, tblName); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckTagFields(stmt, data->pTags + tblIdx * gCurCase->bindTagNum); + + return st_stmt2_set_tags(stmt, data->pTags + tblIdx * gCurCase->bindTagNum); + } else { + return st_stmt2_set_tbname_tags(stmt, tblName, data->pTags + tblIdx * gCurCase->bindTagNum); + } + } else { + return st_stmt2_set_tbname(stmt, tblName); + } +} + +/* prepare [settbname [bind add]] exec */ +int insertMBSETest1(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b < bindTimes; ++b) { + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* prepare [settbname bind add] exec */ +int insertMBSETest2(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + + for (int32_t b = 0; b < bindTimes; ++b) { + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* prepare [settbname [bind add] exec] */ +int insertMBMETest1(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b < bindTimes; ++b) { + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + bpCheckIsInsert(stmt, 1); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* prepare [settbname [bind add exec]] */ +int insertMBMETest2(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + for (int32_t b = 0; b < bindTimes; ++b) { + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + } + + bpCheckIsInsert(stmt, 1); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* prepare [settbname [settbname bind add exec]] */ +int insertMBMETest3(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b < bindTimes; ++b) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + } + + bpCheckIsInsert(stmt, 1); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* prepare [settbname bind add exec] */ +int insertMBMETest4(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + + for (int32_t b = 0; b < bindTimes; ++b) { + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + } + + bpCheckIsInsert(stmt, 1); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* [prepare [settbname [bind add] exec]] */ +int insertMPMETest1(TAOS_STMT2 *stmt, TAOS *taos) { + int32_t loop = 0; + + while (gCurCase->bindColNum >= 2) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b < bindTimes; ++b) { + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + bpCheckIsInsert(stmt, 1); + + destroyData(&data); + + gCurCase->bindColNum -= 2; + gCurCase->fullCol = false; + loop++; + } + + bpCheckAffectedRows(stmt, loop); + + gExecLoopTimes = loop; + + return 0; +} + +/* prepare [settbname [bind] exec] */ +int insertStbTest(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b < bindTimes; ++b) { + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + bpCheckIsInsert(stmt, 1); + + destroyData(&data); + + bpCheckAffectedRows(stmt, 1); + + return 0; +} + +/* [prepare [settbnametag [bind add] exec]] */ +int insertAUTOTest1(TAOS_STMT2 *stmt, TAOS *taos) { + int32_t loop = 0; + + while (gCurCase->bindTagNum > 0 && gCurCase->bindColNum > 0) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname_tags error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b < bindTimes; ++b) { + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + bpCheckIsInsert(stmt, 1); + + destroyData(&data); + + gCurCase->bindColNum -= 2; + gCurCase->bindTagNum -= 2; + gCurCase->fullCol = false; + loop++; + } + + bpCheckAffectedRows(stmt, loop); + + gExecLoopTimes = loop; + + return 0; +} + +/* [prepare [settbnametag [bind add exec]]] */ +int insertAUTOTest2(TAOS_STMT2 *stmt, TAOS *taos) { + int32_t loop = 0; + + while (gCurCase->bindTagNum > 0 && gCurCase->bindColNum > 0) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t b = 0; b < bindTimes; ++b) { + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = bpSetTableNameTags(&data, t, buf, stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname_tags error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + } + + bpCheckIsInsert(stmt, 1); + + destroyData(&data); + + gCurCase->bindColNum -= 2; + gCurCase->bindTagNum -= 2; + gCurCase->fullCol = false; + loop++; + } + + bpCheckAffectedRows(stmt, loop); + + gExecLoopTimes = loop; + + return 0; +} + +/* normal table [prepare [bind add exec]] */ +int insertAUTOTest3(TAOS_STMT2 *stmt, TAOS *taos) { + int32_t loop = 0; + + while (gCurCase->bindColNum > 0) { + BindData data = {0}; + data.singleTbInsert = true; + prepareInsertData(&data); + + int32_t bindTimes = gCurCase->rowNum / gCurCase->bindRowNum; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + data.singleTbIdx = t; + generateInsertSQL(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + for (int32_t b = 0; b < bindTimes; ++b) { + bpCheckIsInsert(stmt, 1); + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (bpBindParam(stmt, data.pBind + t * bindTimes * gCurCase->bindColNum + b * gCurCase->bindColNum, false)) { + exit(1); + } + + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + } + + bpCheckIsInsert(stmt, 1); + + destroyData(&data); + + gCurCase->bindColNum -= 2; + gCurCase->fullCol = false; + loop++; + } + + bpCheckAffectedRows(stmt, loop); + + gExecLoopTimes = loop; + + return 0; +} + +/* select * from table */ +int queryColumnTest(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + memset(&data, 0, sizeof(data)); + prepareQueryCondData(&data, t); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + for (int32_t n = 0; n < (gCurCase->rowNum / gCurCase->bindRowNum); ++n) { + bpCheckIsInsert(stmt, 0); + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (bpBindParam(stmt, data.pBind + n * gCurCase->bindColNum, false)) { + exit(1); + } + + if (rand() % 2 == 0) { + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckQueryResult(stmt, taos, data.sql, data.pBind + n * gCurCase->bindColNum); + } + + bpCheckIsInsert(stmt, 0); + + destroyData(&data); + } + + return 0; +} + +/* value in query sql */ +int queryMiscTest(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + memset(&data, 0, sizeof(data)); + prepareQueryMiscData(&data, t); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + for (int32_t n = 0; n < (gCurCase->rowNum / gCurCase->bindRowNum); ++n) { + bpCheckIsInsert(stmt, 0); + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (bpBindParam(stmt, data.pBind + n * gCurCase->bindColNum, false)) { + exit(1); + } + + if (rand() % 2 == 0) { + if (st_stmt2_add_batch(stmt)) { + printf("!!!st_stmt2_add_batch error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + } + + if (st_stmt2_exec(stmt, NULL) != 0) { + printf("!!!st_stmt2_exec error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckQueryResult(stmt, taos, data.sql, data.pBind + n * gCurCase->bindColNum); + } + + bpCheckIsInsert(stmt, 0); + + destroyData(&data); + } + + return 0; +} + +int insertNonExistsTb(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + char *buf = "tbnexist"; + code = bpSetTableNameTags(&data, 0, buf, stmt); + if (code == 0) { + printf("!!!st_stmt2_set_tbname expected error not occurred\n"); + exit(1); + } + + if (0 == st_stmt2_bind_param_batch(stmt, data.pBind)) { + printf("!!!st_stmt2_bind_param_batch expected error not occurred\n"); + exit(1); + } + + if (0 == st_stmt2_exec(stmt, NULL)) { + printf("!!!st_stmt2_execute expected error not occurred\n"); + exit(1); + } + + destroyData(&data); + + return 0; +} + +void bpAddWrongVarBuffLen(TAOS_STMT2_BIND *pBind) { + for (int32_t i = 0; i < gCurCase->bindColNum; ++i) { + if (pBind[i].buffer_type == TSDB_DATA_TYPE_BINARY || pBind[i].buffer_type == TSDB_DATA_TYPE_VARBINARY || + pBind[i].buffer_type == TSDB_DATA_TYPE_NCHAR) { + *pBind[i].length += 100; + } + } +} + +int insertVarLenErr(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + prepareInsertData(&data); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("!!!failed to execute st_stmt2_prepare. error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt, 1); + + code = bpSetTableNameTags(&data, 0, "t0", stmt); + if (code != 0) { + printf("!!!st_stmt2_set_tbname error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + bpAddWrongVarBuffLen(data.pBind); + + if (bpBindParam(stmt, data.pBind, true)) { + exit(1); + } + + destroyData(&data); + + return 0; +} + +int errorSQLTest1(TAOS_STMT2 *stmt, TAOS *taos) { + BindData data = {0}; + + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + memset(&data, 0, sizeof(data)); + generateErrorSQL(&data, t); + + int code = st_stmt2_prepare(stmt, data.sql, 0); + if (code != 0) { + printf("*st_stmt2_prepare error as expected, error:%s\n", st_stmt2_error(stmt)); + } else { + printf("!!!st_stmt2_prepare succeed, which should be error\n"); + exit(1); + } + + destroyData(&data); + } + + return 0; +} + +void prepareCheckResultImpl(TAOS *taos, char *tname, bool printr, int expected, bool silent) { + if (TTYPE_INSERT_NG == gCurCase->testType) { + return; + } + + char sql[255] = "SELECT * FROM "; + int32_t rows = 0; + + strcat(sql, tname); + bpExecQuery(taos, sql, printr, &rows); + + if (rows == expected) { + if (!silent) { + printf("***%d rows are fetched as expected from %s\n", rows, tname); + } + } else { + printf("!!!expect rows %d mis-match rows %d fetched from %s\n", expected, rows, tname); + exit(1); + } +} + +void prepareCheckResult(TAOS *taos, bool silent) { + char buf[32]; + for (int32_t t = 0; t < gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + sprintf(buf, "%s%d", bpTbPrefix, t); + } else { + sprintf(buf, "%s%d", bpTbPrefix, 0); + } + + prepareCheckResultImpl( + taos, buf, gCaseCtrl.printRes, + gCurCase->duplicateValue ? (gCurCase->rowNum * gExecLoopTimes / 2) : (gCurCase->rowNum * gExecLoopTimes), + silent); + } + + gExecLoopTimes = 1; +} + +// 120table 60 record each table +int sql_perf1(TAOS *taos) { + char *sql[3000] = {0}; + TAOS_RES *result; + + for (int i = 0; i < 3000; i++) { + sql[i] = taosMemoryCalloc(1, 1048576); + } + + int len = 0; + int tss = 0; + for (int l = 0; l < 3000; ++l) { + len = sprintf(sql[l], "insert into "); + for (int t = 0; t < 120; ++t) { + len += sprintf(sql[l] + len, "m%d values ", t); + for (int m = 0; m < 60; ++m) { + len += sprintf(sql[l] + len, + "(%d, %d, %d, %d, %d, %d, %f, %f, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", " + "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") ", + tss++, m, m, m, m, m, m + 1.0, m + 1.0); + } + } + } + + int64_t starttime = taosGetTimestampUs(); + for (int i = 0; i < 3000; ++i) { + result = taos_query(taos, sql[i]); + int code = taos_errno(result); + if (code != 0) { + printf("%d failed to query table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + + taos_free_result(result); + } + int64_t endtime = taosGetTimestampUs(); + printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000 * 120 * 60, + (endtime - starttime) / 1000000UL, (endtime - starttime) / (3000 * 120 * 60)); + + for (int i = 0; i < 3000; i++) { + taosMemoryFree(sql[i]); + } + + return 0; +} + +// one table 60 records one time +int sql_perf_s1(TAOS *taos) { + char **sql = calloc(1, sizeof(char *) * 360000); + TAOS_RES *result; + + for (int i = 0; i < 360000; i++) { + sql[i] = taosMemoryCalloc(1, 9000); + } + + int len = 0; + int tss = 0; + int id = 0; + for (int t = 0; t < 120; ++t) { + for (int l = 0; l < 3000; ++l) { + len = sprintf(sql[id], "insert into m%d values ", t); + for (int m = 0; m < 60; ++m) { + len += sprintf(sql[id] + len, + "(%d, %d, %d, %d, %d, %d, %f, %f, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", " + "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") ", + tss++, m, m, m, m, m, m + 1.0, m + 1.0); + } + if (len >= 9000) { + printf("sql:%s,len:%d\n", sql[id], len); + exit(1); + } + ++id; + } + } + + unsigned long long starttime = taosGetTimestampUs(); + for (int i = 0; i < 360000; ++i) { + result = taos_query(taos, sql[i]); + int code = taos_errno(result); + if (code != 0) { + printf("failed to query table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + + taos_free_result(result); + } + unsigned long long endtime = taosGetTimestampUs(); + printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000 * 120 * 60, + (endtime - starttime) / 1000000UL, (endtime - starttime) / (3000 * 120 * 60)); + + for (int i = 0; i < 360000; i++) { + taosMemoryFree(sql[i]); + } + + taosMemoryFree(sql); + + return 0; +} + +// small record size +int sql_s_perf1(TAOS *taos) { + char *sql[3000] = {0}; + TAOS_RES *result; + + for (int i = 0; i < 3000; i++) { + sql[i] = taosMemoryCalloc(1, 1048576); + } + + int len = 0; + int tss = 0; + for (int l = 0; l < 3000; ++l) { + len = sprintf(sql[l], "insert into "); + for (int t = 0; t < 120; ++t) { + len += sprintf(sql[l] + len, "m%d values ", t); + for (int m = 0; m < 60; ++m) { + len += sprintf(sql[l] + len, "(%d, %d) ", tss++, m % 2); + } + } + } + + unsigned long long starttime = taosGetTimestampUs(); + for (int i = 0; i < 3000; ++i) { + result = taos_query(taos, sql[i]); + int code = taos_errno(result); + if (code != 0) { + printf("failed to query table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + + taos_free_result(result); + } + unsigned long long endtime = taosGetTimestampUs(); + printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000 * 120 * 60, + (endtime - starttime) / 1000000UL, (endtime - starttime) / (3000 * 120 * 60)); + + for (int i = 0; i < 3000; i++) { + taosMemoryFree(sql[i]); + } + + return 0; +} + +void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, int32_t tableType) { + int32_t blen = 0; + blen = sprintf(buf, "create table %s%d ", (1 == tableType ? bpStbPrefix : bpTbPrefix), tblIdx); + + if (tableType == 3) { + blen += sprintf(buf + blen, "using %s%d", bpStbPrefix, bpDefaultStbId); + } + + if (tableType == 0 || tableType == 1) { + blen += sprintf(buf + blen, " ("); + + for (int c = 0; c < colNum; ++c) { + if (c > 0) { + blen += sprintf(buf + blen, ","); + } + + switch (colList[c]) { + case TSDB_DATA_TYPE_BOOL: + blen += sprintf(buf + blen, "booldata bool"); + break; + case TSDB_DATA_TYPE_TINYINT: + blen += sprintf(buf + blen, "tinydata tinyint"); + break; + case TSDB_DATA_TYPE_SMALLINT: + blen += sprintf(buf + blen, "smalldata smallint"); + break; + case TSDB_DATA_TYPE_INT: + blen += sprintf(buf + blen, "intdata int"); + break; + case TSDB_DATA_TYPE_BIGINT: + blen += sprintf(buf + blen, "bigdata bigint"); + break; + case TSDB_DATA_TYPE_FLOAT: + blen += sprintf(buf + blen, "floatdata float"); + break; + case TSDB_DATA_TYPE_DOUBLE: + blen += sprintf(buf + blen, "doubledata double"); + break; + case TSDB_DATA_TYPE_VARCHAR: + blen += sprintf(buf + blen, "binarydata binary(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + blen += sprintf(buf + blen, "ts timestamp"); + break; + case TSDB_DATA_TYPE_NCHAR: + blen += sprintf(buf + blen, "nchardata nchar(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_UTINYINT: + blen += sprintf(buf + blen, "utinydata tinyint unsigned"); + break; + case TSDB_DATA_TYPE_USMALLINT: + blen += sprintf(buf + blen, "usmalldata smallint unsigned"); + break; + case TSDB_DATA_TYPE_UINT: + blen += sprintf(buf + blen, "uintdata int unsigned"); + break; + case TSDB_DATA_TYPE_UBIGINT: + blen += sprintf(buf + blen, "ubigdata bigint unsigned"); + break; + default: + printf("invalid col type:%d", colList[c]); + exit(1); + } + } + + blen += sprintf(buf + blen, ")"); + } + + if (1 == tableType) { + blen += sprintf(buf + blen, " tags ("); + for (int c = 0; c < colNum; ++c) { + if (c > 0) { + blen += sprintf(buf + blen, ","); + } + switch (colList[c]) { + case TSDB_DATA_TYPE_BOOL: + blen += sprintf(buf + blen, "tbooldata bool"); + break; + case TSDB_DATA_TYPE_TINYINT: + blen += sprintf(buf + blen, "ttinydata tinyint"); + break; + case TSDB_DATA_TYPE_SMALLINT: + blen += sprintf(buf + blen, "tsmalldata smallint"); + break; + case TSDB_DATA_TYPE_INT: + blen += sprintf(buf + blen, "tintdata int"); + break; + case TSDB_DATA_TYPE_BIGINT: + blen += sprintf(buf + blen, "tbigdata bigint"); + break; + case TSDB_DATA_TYPE_FLOAT: + blen += sprintf(buf + blen, "tfloatdata float"); + break; + case TSDB_DATA_TYPE_DOUBLE: + blen += sprintf(buf + blen, "tdoubledata double"); + break; + case TSDB_DATA_TYPE_VARCHAR: + blen += sprintf(buf + blen, "tbinarydata binary(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + blen += sprintf(buf + blen, "tts timestamp"); + break; + case TSDB_DATA_TYPE_NCHAR: + blen += sprintf(buf + blen, "tnchardata nchar(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_UTINYINT: + blen += sprintf(buf + blen, "tutinydata tinyint unsigned"); + break; + case TSDB_DATA_TYPE_USMALLINT: + blen += sprintf(buf + blen, "tusmalldata smallint unsigned"); + break; + case TSDB_DATA_TYPE_UINT: + blen += sprintf(buf + blen, "tuintdata int unsigned"); + break; + case TSDB_DATA_TYPE_UBIGINT: + blen += sprintf(buf + blen, "tubigdata bigint unsigned"); + break; + default: + printf("invalid col type:%d", colList[c]); + exit(1); + } + } + + blen += sprintf(buf + blen, ")"); + } + + if (3 == tableType) { + blen += sprintf(buf + blen, " tags ("); + for (int c = 0; c < colNum; ++c) { + if (c > 0) { + blen += sprintf(buf + blen, ","); + } + switch (colList[c]) { + case TSDB_DATA_TYPE_BOOL: + blen += sprintf(buf + blen, "%s", rand() % 2 ? "true" : "false"); + break; + case TSDB_DATA_TYPE_TINYINT: + blen += sprintf(buf + blen, "%d", rand() % 128); + break; + case TSDB_DATA_TYPE_SMALLINT: + blen += sprintf(buf + blen, "%d", rand() % 128); + break; + case TSDB_DATA_TYPE_INT: + blen += sprintf(buf + blen, "%d", rand() % 128); + break; + case TSDB_DATA_TYPE_BIGINT: + blen += sprintf(buf + blen, "%d", rand() % 128); + break; + case TSDB_DATA_TYPE_FLOAT: + blen += sprintf(buf + blen, "%f", rand() % 128); + break; + case TSDB_DATA_TYPE_DOUBLE: + blen += sprintf(buf + blen, "%f", rand() % 128); + break; + case TSDB_DATA_TYPE_VARCHAR: + blen += sprintf(buf + blen, "'var%d'", rand() % 128); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + blen += sprintf(buf + blen, "%lld", bpTs); + break; + case TSDB_DATA_TYPE_NCHAR: + blen += sprintf(buf + blen, "'nch%d'", rand() % 128); + break; + case TSDB_DATA_TYPE_UTINYINT: + blen += sprintf(buf + blen, "%d", rand() % 128); + break; + case TSDB_DATA_TYPE_USMALLINT: + blen += sprintf(buf + blen, "%d", rand() % 128); + break; + case TSDB_DATA_TYPE_UINT: + blen += sprintf(buf + blen, "%d", rand() % 128); + break; + case TSDB_DATA_TYPE_UBIGINT: + blen += sprintf(buf + blen, "%d", rand() % 128); + break; + default: + printf("invalid col type:%d", colList[c]); + exit(1); + } + } + + blen += sprintf(buf + blen, ")"); + } + + if (gCaseCtrl.printCreateTblSql) { + printf("\tCreate Table SQL:%s\n", buf); + } +} + +char *bpPrecisionStr(uint8_t precision) { + switch (precision) { + case TIME_PRECISION_MILLI: + return "ms"; + case TIME_PRECISION_MICRO: + return "us"; + case TIME_PRECISION_NANO: + return "ns"; + default: + return "unknwon"; + } +} + +void bpSetStartupTs() { + switch (gCaseCtrl.precision) { + case TIME_PRECISION_MILLI: + bpTs = BP_STARTUP_TS; + break; + case TIME_PRECISION_MICRO: + bpTs = BP_STARTUP_TS * 1000; + break; + case TIME_PRECISION_NANO: + bpTs = BP_STARTUP_TS * 1000000; + break; + default: + bpTs = BP_STARTUP_TS; + break; + } +} + +void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int prepareStb) { + TAOS_RES *result; + int code; + char createDbSql[128] = {0}; + + result = taos_query(taos, "drop database demo"); + taos_free_result(result); + + sprintf(createDbSql, "create database demo keep 36500 precision \"%s\"", bpPrecisionStr(gCaseCtrl.precision)); + printf("\tCreate Database SQL:%s\n", createDbSql); + + result = taos_query(taos, createDbSql); + code = taos_errno(result); + if (code != 0) { + printf("!!!failed to create database, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + taos_free_result(result); + + result = taos_query(taos, "use demo"); + taos_free_result(result); + + if (0 == prepareStb) { + // create table + for (int i = 0; i < 10; i++) { + char buf[1024]; + generateCreateTableSQL(buf, i, colNum, colList, 0); + result = taos_query(taos, buf); + code = taos_errno(result); + if (code != 0) { + printf("!!!failed to create table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + taos_free_result(result); + } + } else { + if (1 == prepareStb || 3 == prepareStb) { + char buf[1024]; + generateCreateTableSQL(buf, bpDefaultStbId, colNum, colList, 1); + + result = taos_query(taos, buf); + code = taos_errno(result); + if (code != 0) { + printf("!!!failed to create table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + taos_free_result(result); + } + + if (3 == prepareStb) { + for (int i = 0; i < 10; i++) { + char buf[1024]; + generateCreateTableSQL(buf, i, colNum, colList, 3); + result = taos_query(taos, buf); + code = taos_errno(result); + if (code != 0) { + printf("!!!failed to create table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + taos_free_result(result); + } + } + } +} + +int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) { + TAOS_STMT2 *stmt = NULL; + int64_t beginUs, endUs, totalUs; + CaseCfg cfg = gCase[caseIdx]; + CaseCfg cfgBk; + gCurCase = &cfg; + + bpSetStartupTs(); + + if ((gCaseCtrl.bindColTypeNum || gCaseCtrl.bindColNum) && (gCurCase->colNum != gFullColNum)) { + return 1; + } + + if (gCurCase->preCaseIdx >= 0) { + bool printRes = gCaseCtrl.printRes; + bool printStmtSql = gCaseCtrl.printStmtSql; + gCaseCtrl.printRes = false; + gCaseCtrl.printStmtSql = false; + runCase(taos, gCurCase->preCaseIdx, caseRunIdx, true); + gCaseCtrl.printRes = printRes; + gCaseCtrl.printStmtSql = printStmtSql; + + gCurCase = &cfg; + } + + if (gCaseCtrl.runTimes) { + gCurCase->runTimes = gCaseCtrl.runTimes; + } + + if (gCaseCtrl.rowNum) { + gCurCase->rowNum = gCaseCtrl.rowNum; + } + + if (gCaseCtrl.autoCreateTbl) { + if (gCurCase->testType == TTYPE_INSERT && gCurCase->tblNum > 1) { + gCurCase->autoCreateTbl = 1; + if (gCurCase->bindTagNum <= 0) { + gCurCase->bindTagNum = gCurCase->colNum; + } + } else { + return 1; + } + } + + if (gCurCase->fullCol) { + gCurCase->bindColNum = gCurCase->colNum; + if (gCurCase->autoCreateTbl) { + gCurCase->bindTagNum = gCurCase->colNum; + } + } + + gCurCase->bindNullNum = gCaseCtrl.bindNullNum; + if (gCaseCtrl.bindColNum) { + gCurCase->bindColNum = gCaseCtrl.bindColNum; + gCurCase->fullCol = false; + } + if (gCaseCtrl.bindTagNum) { + gCurCase->bindTagNum = gCaseCtrl.bindTagNum; + gCurCase->fullCol = false; + } + if (gCaseCtrl.bindRowNum) { + gCurCase->bindRowNum = gCaseCtrl.bindRowNum; + } + if (gCaseCtrl.bindColTypeNum) { + gCurCase->bindColNum = gCaseCtrl.bindColTypeNum; + gCurCase->fullCol = false; + } + if (gCaseCtrl.bindTagTypeNum) { + gCurCase->bindTagNum = gCaseCtrl.bindTagTypeNum; + gCurCase->fullCol = false; + } + + if (!silent) { + printf("* Case %d - [%s]%s Begin *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc); + } + + totalUs = 0; + cfgBk = cfg; + for (int32_t n = 0; n < gCurCase->runTimes; ++n) { + if (gCurCase->preCaseIdx < 0) { + prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->autoCreateTbl); + } + + beginUs = taosGetTimestampUs(); + + stmt = st_stmt2_init(taos, gCurCase->stbInsert); + if (!stmt) { + printf("!!!st_stmt2_init failed, error:%s\n", st_stmt2_error(stmt)); + exit(1); + } + + (*gCurCase->runFn)(stmt, taos); + + (void)st_stmt2_close(stmt); + + endUs = taosGetTimestampUs(); + totalUs += (endUs - beginUs); + + prepareCheckResult(taos, silent); + + cfg = cfgBk; + } + + if (!silent) { + printf("* Case %d - [%s]%s [AvgTime:%.3fms] End *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc, + ((double)totalUs) / 1000 / gCurCase->runTimes); + } + + return 0; +} + +void *runCaseList(TAOS *taos) { + static int32_t caseRunIdx = 0; + static int32_t caseRunNum = 0; + int32_t caseNum = 0; + int32_t caseIdx = (gCaseCtrl.caseIdx >= 0) ? gCaseCtrl.caseIdx : 0; + + for (int32_t i = caseIdx; i < sizeof(gCase) / sizeof(gCase[0]); ++i) { + if (gCaseCtrl.caseNum > 0 && caseNum >= gCaseCtrl.caseNum) { + break; + } + + if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) { + break; + } + + if (gCaseCtrl.caseRunIdx >= 0 && caseRunIdx < gCaseCtrl.caseRunIdx) { + caseRunIdx++; + continue; + } + + if (runCase(taos, i, caseRunIdx, false)) { + continue; + } + + caseRunIdx++; + caseNum++; + caseRunNum++; + } + + return NULL; +} + +void runAll(TAOS *taos) { + strcpy(gCaseCtrl.caseCatalog, "Default Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + runCaseList(taos); + +#if 1 + strcpy(gCaseCtrl.caseCatalog, "Micro DB precision Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.precision = TIME_PRECISION_MICRO; + runCaseList(taos); + gCaseCtrl.precision = TIME_PRECISION_MILLI; + + strcpy(gCaseCtrl.caseCatalog, "Nano DB precision Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.precision = TIME_PRECISION_NANO; + runCaseList(taos); + gCaseCtrl.precision = TIME_PRECISION_MILLI; + + strcpy(gCaseCtrl.caseCatalog, "Auto Create Table Test"); + gCaseCtrl.autoCreateTbl = true; + printf("%s Begin\n", gCaseCtrl.caseCatalog); + runCaseList(taos); + gCaseCtrl.autoCreateTbl = false; + + strcpy(gCaseCtrl.caseCatalog, "Null Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.bindNullNum = 1; + runCaseList(taos); + gCaseCtrl.bindNullNum = 0; + + strcpy(gCaseCtrl.caseCatalog, "Bind Row Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.bindRowNum = 1; + runCaseList(taos); + gCaseCtrl.bindRowNum = 0; + + strcpy(gCaseCtrl.caseCatalog, "Row Num Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.rowNum = 1000; + gCaseCtrl.printRes = false; + runCaseList(taos); + gCaseCtrl.rowNum = 0; + gCaseCtrl.printRes = true; + + strcpy(gCaseCtrl.caseCatalog, "Runtimes Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.runTimes = 2; + runCaseList(taos); + gCaseCtrl.runTimes = 0; + + strcpy(gCaseCtrl.caseCatalog, "Check Param Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.checkParamNum = true; + runCaseList(taos); + gCaseCtrl.checkParamNum = false; + + strcpy(gCaseCtrl.caseCatalog, "Bind Col Num Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.bindColNum = 6; + runCaseList(taos); + gCaseCtrl.bindColNum = 0; + +#endif + + /* + strcpy(gCaseCtrl.caseCatalog, "Bind Col Type Test"); + printf("%s Begin\n", gCaseCtrl.caseCatalog); + gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList); + gCaseCtrl.bindColTypeList = bindColTypeList; + runCaseList(taos); + */ + + printf("All Test End\n"); +} + +int main(int argc, char *argv[]) { + TAOS *taos = NULL; + + srand((unsigned int)time(NULL)); + + // connect to server + if (argc < 2) { + printf("please input server ip \n"); + return 0; + } + + taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); + if (taos == NULL) { + printf("failed to connect to db, reason:%s\n", taos_errstr(taos)); + exit(1); + } + + runAll(taos); + + taos_close(taos); + + return 0; +} diff --git a/tests/script/api/stmt2.c b/tests/script/api/stmt2.c new file mode 100644 index 0000000000..82537905dc --- /dev/null +++ b/tests/script/api/stmt2.c @@ -0,0 +1,323 @@ +// sample code to verify all TDengine API +// to compile: gcc -o apitest apitest.c -ltaos + +#include +#include +#include +#include +#include "taos.h" +static int64_t count = 10000; + +int64_t genReqid() { + count += 100; + return count; +} + +void stmtAsyncQueryCb(void* param, TAOS_RES* pRes, int code) { + int affected_rows = taos_affected_rows(pRes); + return; + /* + SSP_CB_PARAM* qParam = (SSP_CB_PARAM*)param; + if (code == 0 && pRes) { + if (qParam->fetch) { + taos_fetch_rows_a(pRes, sqAsyncFetchCb, param); + } else { + if (qParam->free) { + taos_free_result(pRes); + } + *qParam->end = 1; + } + } else { + sqError("select", taos_errstr(pRes)); + *qParam->end = 1; + taos_free_result(pRes); + } + */ +} + +void veriry_stmt(TAOS* taos) { + TAOS_RES* result = taos_query(taos, "drop database if exists test;"); + taos_free_result(result); + usleep(100000); + result = taos_query(taos, "create database test;"); + + int code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create database, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); + + usleep(100000); + taos_select_db(taos, "test"); + + // create table + /* + const char* sql = + "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin " + "binary(40), blob nchar(10))"; + */ + const char* sql = + "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, blob2 " + "nchar(10), blob nchar(10))"; + result = taos_query(taos, sql); + code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create table, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); + + // insert 10 records + struct { + int64_t ts[10]; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + char blob[10][80]; + char blob2[10][80]; + } v; + + int32_t* t8_len = malloc(sizeof(int32_t) * 10); + int32_t* t16_len = malloc(sizeof(int32_t) * 10); + int32_t* t32_len = malloc(sizeof(int32_t) * 10); + int32_t* t64_len = malloc(sizeof(int32_t) * 10); + int32_t* float_len = malloc(sizeof(int32_t) * 10); + int32_t* double_len = malloc(sizeof(int32_t) * 10); + int32_t* bin_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len2 = malloc(sizeof(int32_t) * 10); + +#include "time.h" + clock_t start, end; + TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb, NULL}; + + start = clock(); + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + end = clock(); + printf("init time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + // TAOS_MULTI_BIND params[10]; + TAOS_STMT2_BIND params[10]; + char is_null[10] = {0}; + + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + // params[0].buffer_length = sizeof(v.ts[0]); + params[0].buffer = v.ts; + params[0].length = t64_len; + params[0].is_null = is_null; + params[0].num = 10; + + params[1].buffer_type = TSDB_DATA_TYPE_BOOL; + // params[1].buffer_length = sizeof(v.b[0]); + params[1].buffer = v.b; + params[1].length = t8_len; + params[1].is_null = is_null; + params[1].num = 10; + + params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; + // params[2].buffer_length = sizeof(v.v1[0]); + params[2].buffer = v.v1; + params[2].length = t8_len; + params[2].is_null = is_null; + params[2].num = 10; + + params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + // params[3].buffer_length = sizeof(v.v2[0]); + params[3].buffer = v.v2; + params[3].length = t16_len; + params[3].is_null = is_null; + params[3].num = 10; + + params[4].buffer_type = TSDB_DATA_TYPE_INT; + // params[4].buffer_length = sizeof(v.v4[0]); + params[4].buffer = v.v4; + params[4].length = t32_len; + params[4].is_null = is_null; + params[4].num = 10; + + params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; + // params[5].buffer_length = sizeof(v.v8[0]); + params[5].buffer = v.v8; + params[5].length = t64_len; + params[5].is_null = is_null; + params[5].num = 10; + + params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; + // params[6].buffer_length = sizeof(v.f4[0]); + params[6].buffer = v.f4; + params[6].length = float_len; + params[6].is_null = is_null; + params[6].num = 10; + + params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + // params[7].buffer_length = sizeof(v.f8[0]); + params[7].buffer = v.f8; + params[7].length = double_len; + params[7].is_null = is_null; + params[7].num = 10; + /* + params[8].buffer_type = TSDB_DATA_TYPE_BINARY; + //params[8].buffer_length = sizeof(v.bin[0]); + params[8].buffer = v.bin; + params[8].length = bin_len; + params[8].is_null = is_null; + params[8].num = 10; + */ + params[8].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[8].buffer_length = sizeof(v.blob2[0]); + params[8].buffer = v.blob2; + params[8].length = blob_len2; + params[8].is_null = is_null; + params[8].num = 10; + + params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[9].buffer_length = sizeof(v.blob[0]); + params[9].buffer = v.blob; + params[9].length = blob_len; + params[9].is_null = is_null; + params[9].num = 10; + + sql = "insert into ? (ts, b, v1, v2, v4, v8, f4, f8, blob2, blob) values(?,?,?,?,?,?,?,?,?,?)"; + start = clock(); + code = taos_stmt2_prepare(stmt, sql, 0); + end = clock(); + printf("prepare time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + /* + code = taos_stmt_set_tbname(stmt, "m1"); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + */ + + int64_t ts = 1591060628000; + for (int i = 0; i < 10; ++i) { + is_null[i] = 0; + + v.ts[i] = ts++; + v.b[i] = (int8_t)i % 2; + v.v1[i] = (int8_t)i; + v.v2[i] = (int16_t)(i * 2); + v.v4[i] = (int32_t)(i * 4); + v.v8[i] = (int64_t)(i * 8); + v.f4[i] = (float)(i * 40); + v.f8[i] = (double)(i * 80); + for (int j = 0; j < sizeof(v.bin[0]); ++j) { + v.bin[i][j] = (char)(i + '0'); + } + strcpy(v.blob2[i], "一二三四五六七十九八"); + strcpy(v.blob[i], "一二三四五六七八九十"); + + t8_len[i] = sizeof(int8_t); + t16_len[i] = sizeof(int16_t); + t32_len[i] = sizeof(int32_t); + t64_len[i] = sizeof(int64_t); + float_len[i] = sizeof(float); + double_len[i] = sizeof(double); + bin_len[i] = sizeof(v.bin[0]); + blob_len[i] = (int32_t)strlen(v.blob[i]); + blob_len2[i] = (int32_t)strlen(v.blob2[i]); + } + + char* tbname = "m1"; + TAOS_STMT2_BIND* bind_cols[1] = {¶ms[0]}; + TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, &bind_cols[0]}; + start = clock(); + // taos_stmt2_bind_param(stmt, "m1", NULL, params, -1); + taos_stmt2_bind_param(stmt, &bindv, -1); + end = clock(); + printf("bind time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + // taos_stmt_bind_param_batch(stmt, params); + // taos_stmt_add_batch(stmt); + /* + int param_count = -1; + code = taos_stmt2_param_count(stmt, ¶m_count); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_param_count. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + printf("param_count: %d\n", param_count); + */ + TAOS_FIELD_E* fields = NULL; + int field_count = -1; + start = clock(); + code = taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, &field_count, NULL); + end = clock(); + printf("get fields time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_param_count. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + printf("col field_count: %d\n", field_count); + start = clock(); + taos_stmt2_free_fields(stmt, fields); + end = clock(); + printf("free time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + /* + code = taos_stmt2_get_fields(stmt, TAOS_FIELD_TAG, &field_count, &fields); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_param_count. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + printf("tag field_count: %d\n", field_count); + taos_stmt2_free_fields(stmt, fields); + */ + // if (taos_stmt_execute(stmt) != 0) { + start = clock(); + // if (taos_stmt2_exec(stmt, NULL, stmtAsyncQueryCb, NULL) != 0) { + if (taos_stmt2_exec(stmt, NULL) != 0) { + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt2_close(stmt); + return; + } + end = clock(); + printf("exec time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); + + taos_stmt2_close(stmt); + + free(t8_len); + free(t16_len); + free(t32_len); + free(t64_len); + free(float_len); + free(double_len); + free(bin_len); + free(blob_len); + free(blob_len2); +} + +int main(int argc, char* argv[]) { + const char* host = "127.0.0.1"; + const char* user = "root"; + const char* passwd = "taosdata"; + + taos_options(TSDB_OPTION_TIMEZONE, "GMT-8"); + TAOS* taos = taos_connect(host, user, passwd, "", 0); + if (taos == NULL) { + printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos)); + exit(1); + } + + printf("********* verify stmt query **********\n"); + veriry_stmt(taos); + + printf("done\n"); + taos_close(taos); + taos_cleanup(); +} diff --git a/tests/system-test/2-query/percentile.py b/tests/system-test/2-query/percentile.py index e01aae97c0..46fff0201e 100644 --- a/tests/system-test/2-query/percentile.py +++ b/tests/system-test/2-query/percentile.py @@ -124,6 +124,9 @@ class TDTestCase: tdSql.query(f'select percentile(col1, 9.9, 19.9, 29.9, 39.9, 49.9, 59.9, 69.9, 79.9, 89.9, 99.9) from {self.ntbname}') tdSql.checkData(0, 0, '[0.891000, 1.791000, 2.691000, 3.591000, 4.491000, 5.391000, 6.291000, 7.191000, 8.091000, 8.991000]') + tdSql.query(f'select percentile(col1 * 1e+200, 9.9, 19.9, 29.9, 39.9, 49.9, 59.9, 69.9, 79.9, 89.9, 99.9) from {self.ntbname}') + tdSql.checkRows(1); + tdSql.error(f'select percentile(col1) from {self.ntbname}') tdSql.error(f'select percentile(col1, -1) from {self.ntbname}') tdSql.error(f'select percentile(col1, 101) from {self.ntbname}') @@ -166,6 +169,9 @@ class TDTestCase: tdSql.query(f'select percentile(col1, 9.9, 19.9, 29.9, 39.9, 49.9, 59.9, 69.9, 79.9, 89.9, 99.9) from {self.stbname}_0') tdSql.checkData(0, 0, '[0.891000, 1.791000, 2.691000, 3.591000, 4.491000, 5.391000, 6.291000, 7.191000, 8.091000, 8.991000]') + tdSql.query(f'select percentile(col1 * 1e+200, 9.9, 19.9, 29.9, 39.9, 49.9, 59.9, 69.9, 79.9, 89.9, 99.9) from {self.stbname}_0') + tdSql.checkRows(1); + tdSql.error(f'select percentile(col1) from {self.stbname}_0') tdSql.error(f'select percentile(col1, -1) from {self.stbname}_0') tdSql.error(f'select percentile(col1, 101) from {self.stbname}_0') diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 7fdfd29542..84da746afd 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -48,15 +48,15 @@ static char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision); static int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres); static void shellPrintNChar(const char *str, int32_t length, int32_t width); static void shellPrintGeometry(const unsigned char *str, int32_t length, int32_t width); -static void shellVerticalPrintResult(TAOS_RES *tres, tsDumpInfo* dump_info); -static void shellHorizontalPrintResult(TAOS_RES *tres, tsDumpInfo* dump_info); +static void shellVerticalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info); +static void shellHorizontalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info); static int64_t shellDumpResult(TAOS_RES *tres, char *fname, int32_t *error_no, bool vertical, const char *sql); static void shellReadHistory(); static void shellWriteHistory(); static void shellPrintError(TAOS_RES *tres, int64_t st); static bool shellIsCommentLine(char *line); static void shellSourceFile(const char *file); -static bool shellGetGrantInfo(char* buf); +static bool shellGetGrantInfo(char *buf); static void shellCleanup(void *arg); static void *shellCancelHandler(void *arg); @@ -165,12 +165,12 @@ int32_t shellRunCommand(char *command, bool recordHistory) { // add help or help; if (strncasecmp(command, "help", 4) == 0) { - if(command[4] == ';' || command[4] == ' ' || command[4] == 0) { - showHelp(); - return 0; + if (command[4] == ';' || command[4] == ' ' || command[4] == 0) { + showHelp(); + return 0; } } - + if (recordHistory) shellRecordCommandToHistory(command); char quote = 0, *cmd = command; @@ -197,19 +197,18 @@ int32_t shellRunCommand(char *command, bool recordHistory) { return shellRunSingleCommand(cmd); } - -char * strendG(const char* pstr) { - if(pstr == NULL) { +char *strendG(const char *pstr) { + if (pstr == NULL) { return NULL; } size_t len = strlen(pstr); - if(len < 4) { + if (len < 4) { return NULL; } - char * p = (char *)pstr + len - 2; - if (strcmp(p, "\\G") == 0 ){ + char *p = (char *)pstr + len - 2; + if (strcmp(p, "\\G") == 0) { return p; } @@ -285,10 +284,11 @@ void shellRunSingleCommandImp(char *command) { et = taosGetTimestampUs(); if (error_no == 0) { - printf("Query OK, %"PRId64 " row(s) in set (%.6fs)\r\n", numOfRows, (et - st) / 1E6); + printf("Query OK, %" PRId64 " row(s) in set (%.6fs)\r\n", numOfRows, (et - st) / 1E6); } else { terrno = error_no; - printf("Query interrupted (%s), %"PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(NULL), numOfRows, (et - st) / 1E6); + printf("Query interrupted (%s), %" PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(NULL), numOfRows, + (et - st) / 1E6); } taos_free_result(pSql); } else { @@ -366,10 +366,10 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i return; } - char quotationStr[2] ={'"', 0}; + char quotationStr[2] = {'"', 0}; int32_t width; - int n = 0; + int n = 0; #define LENGTH 64 char buf[LENGTH] = {0}; switch (field->type) { @@ -431,8 +431,8 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_JSON: { int32_t bufIndex = 0; - char* tmp = (char*)taosMemoryCalloc(length * 2 + 1, 1); - if(tmp == NULL) break; + char *tmp = (char *)taosMemoryCalloc(length * 2 + 1, 1); + if (tmp == NULL) break; for (int32_t i = 0; i < length; i++) { tmp[bufIndex] = val[i]; bufIndex++; @@ -446,19 +446,19 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr); taosMemoryFree(tmp); } break; - case TSDB_DATA_TYPE_VARBINARY:{ - void* tmp = NULL; + case TSDB_DATA_TYPE_VARBINARY: { + void *tmp = NULL; uint32_t size = 0; - if(taosAscii2Hex(val, length, &tmp, &size) < 0){ + if (taosAscii2Hex(val, length, &tmp, &size) < 0) { break; } taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr); taosMemoryFree(tmp); break; } - case TSDB_DATA_TYPE_GEOMETRY:{ - char* tmp = (char*)taosMemoryCalloc(length * 2 + 1, 1); - if(tmp == NULL) break; + case TSDB_DATA_TYPE_GEOMETRY: { + char *tmp = (char *)taosMemoryCalloc(length * 2 + 1, 1); + if (tmp == NULL) break; shellDumpHexValue(tmp, val, length); taosFprintfFile(pFile, "%s", buf); taosMemoryFree(tmp); @@ -635,12 +635,12 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t return; } - int n = 0; -#define LENGTH 64 + int n = 0; +#define LENGTH 64 char buf[LENGTH] = {0}; switch (field->type) { case TSDB_DATA_TYPE_BOOL: - shellPrintString(((((int32_t)(*((char *)val))) == 1) ? "true" : "false"), width); + shellPrintString(((((int32_t)(*((char *)val))) == TSDB_FALSE) ? "false" : "true"), width); break; case TSDB_DATA_TYPE_TINYINT: printf("%*d", width, *((int8_t *)val)); @@ -680,7 +680,7 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t break; case TSDB_DATA_TYPE_DOUBLE: if (tsEnableScience) { - snprintf(buf, LENGTH, "%*.15e", width,GET_DOUBLE_VAL(val)); + snprintf(buf, LENGTH, "%*.15e", width, GET_DOUBLE_VAL(val)); printf("%s", buf); } else { n = snprintf(buf, LENGTH, "%*.15f", width, GET_DOUBLE_VAL(val)); @@ -691,10 +691,10 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t } } break; - case TSDB_DATA_TYPE_VARBINARY:{ - void* data = NULL; + case TSDB_DATA_TYPE_VARBINARY: { + void *data = NULL; uint32_t size = 0; - if(taosAscii2Hex(val, length, &data, &size) < 0){ + if (taosAscii2Hex(val, length, &data, &size) < 0) { break; } shellPrintNChar(data, size, width); @@ -867,7 +867,7 @@ int32_t shellCalcColWidth(TAOS_FIELD *field, int32_t precision) { } else { return TMAX(field->bytes + 2, width); } - case TSDB_DATA_TYPE_VARBINARY:{ + case TSDB_DATA_TYPE_VARBINARY: { int32_t bytes = field->bytes * 2 + 2; if (bytes > shell.args.displayWidth) { return TMAX(shell.args.displayWidth, width); @@ -1121,8 +1121,9 @@ void shellSourceFile(const char *file) { char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1); while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) > 0) { - if ( cmd_len + read_len >= TSDB_MAX_ALLOWED_SQL_LEN) { - printf("read command line too long over 1M, ignore this line. cmd_len = %d read_len=%d \n", (int32_t)cmd_len, read_len); + if (cmd_len + read_len >= TSDB_MAX_ALLOWED_SQL_LEN) { + printf("read command line too long over 1M, ignore this line. cmd_len = %d read_len=%d \n", (int32_t)cmd_len, + read_len); cmd_len = 0; memset(line, 0, TSDB_MAX_ALLOWED_SQL_LEN + 1); continue; @@ -1156,7 +1157,7 @@ void shellSourceFile(const char *file) { taosCloseFile(&pFile); } -bool shellGetGrantInfo(char* buf) { +bool shellGetGrantInfo(char *buf) { bool community = true; char sinfo[256] = {0}; tstrncpy(sinfo, taos_get_server_info(shell.conn), sizeof(sinfo)); @@ -1207,8 +1208,7 @@ bool shellGetGrantInfo(char* buf) { sprintf(buf, "Server is %s, %s and will never expire.\r\n", serverVersion, sinfo); } else { community = false; - sprintf(buf, "Server is %s, %s and will expire at %s.\r\n", serverVersion, sinfo, - expiretime); + sprintf(buf, "Server is %s, %s and will expire at %s.\r\n", serverVersion, sinfo, expiretime); } taos_free_result(tres); @@ -1324,13 +1324,13 @@ int32_t shellExecute() { shellSetConn(shell.conn, runOnce); shellReadHistory(); - if(shell.args.is_bi_mode) { - // need set bi mode - printf("Set BI mode is true.\n"); + if (shell.args.is_bi_mode) { + // need set bi mode + printf("Set BI mode is true.\n"); #ifndef WEBSOCKET taos_set_conn_mode(shell.conn, TAOS_CONN_MODE_BI, 1); #endif - } + } if (runOnce) { if (pArgs->commands != NULL) { @@ -1373,22 +1373,22 @@ int32_t shellExecute() { #ifdef WEBSOCKET if (!shell.args.restful && !shell.args.cloud) { #endif -char* buf = taosMemoryMalloc(512); -bool community = shellGetGrantInfo(buf); + char *buf = taosMemoryMalloc(512); + bool community = shellGetGrantInfo(buf); #ifndef WINDOWS printfIntroduction(community); #else #ifndef WEBSOCKET - if(community) { + if (community) { showAD(false); } -#endif #endif -// printf version -if(!community) { - printf("%s\n", buf); -} -taosMemoryFree(buf); +#endif + // printf version + if (!community) { + printf("%s\n", buf); + } + taosMemoryFree(buf); #ifdef WEBSOCKET } @@ -1407,7 +1407,7 @@ taosMemoryFree(buf); if (community) { showAD(true); } -#endif +#endif taosThreadJoin(spid, NULL); diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c index d3ca60ab87..71acf23e41 100644 --- a/tools/shell/src/shellMain.c +++ b/tools/shell/src/shellMain.c @@ -50,12 +50,14 @@ int main(int argc, char *argv[]) { shell.args.local = false; #endif +#if 0 #if !defined(WINDOWS) taosSetSignal(SIGBUS, shellCrashHandler); #endif taosSetSignal(SIGABRT, shellCrashHandler); taosSetSignal(SIGFPE, shellCrashHandler); taosSetSignal(SIGSEGV, shellCrashHandler); +#endif if (shellCheckIntSize() != 0) { return -1;