Merge branch '3.0' into feat/TD-32642

This commit is contained in:
WANG MINGMING 2024-12-10 14:11:47 +08:00 committed by GitHub
commit 4a3eda51e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
72 changed files with 2228 additions and 1035 deletions

1
.gitignore vendored
View File

@ -162,3 +162,4 @@ geos_c.h
source/libs/parser/src/sql.c source/libs/parser/src/sql.c
include/common/ttokenauto.h include/common/ttokenauto.h
!packaging/smokeTest/pytest_require.txt !packaging/smokeTest/pytest_require.txt
tdengine-test-dir

View File

@ -164,9 +164,6 @@ If you are using Maven to manage your project, simply add the following dependen
pip3 install taospy[ws] pip3 install taospy[ws]
``` ```
</TabItem>
</Tabs>
- **Installation Verification** - **Installation Verification**
<Tabs defaultValue="rest"> <Tabs defaultValue="rest">
@ -199,8 +196,8 @@ import taosws
</TabItem> </TabItem>
</Tabs> </Tabs>
</TabItem>
<Tabs>
<TabItem label="Go" value="go"> <TabItem label="Go" value="go">
Edit `go.mod` to add the `driver-go` dependency. Edit `go.mod` to add the `driver-go` dependency.

View File

@ -194,7 +194,7 @@ alter_table_option: {
### Modify Subtable Tag Value ### Modify Subtable Tag Value
```sql ```sql
ALTER TABLE tb_name SET tag tag_name=new_tag_value; ALTER TABLE tb_name SET TAG tag_name1=new_tag_value1,tag_name2=new_tag_value2...;
``` ```
### Modify Table Lifespan ### Modify Table Lifespan

View File

@ -28,13 +28,14 @@ In this document, it specifically refers to the internal levels of the second-le
- Default compression algorithms list and applicable range for each data type - Default compression algorithms list and applicable range for each data type
| Data Type | Available Encoding Algorithms | Default Encoding Algorithm | Available Compression Algorithms|Default Compression Algorithm| Default Compression Level| | Data Type |Available Encoding Algorithms | Default Encoding Algorithm | Available Compression Algorithms | Default Compression Algorithm | Default Compression Level |
| :-----------:|:----------:|:-------:|:-------:|:----------:|:----:| |:------------------------------------:|:----------------:|:-----------:|:--------------------:|:----:|:------:|
| tinyint/untinyint/smallint/usmallint/int/uint | simple8b| simple8b | lz4/zlib/zstd/xz| lz4 | medium| | int/uint | simple8b | simple8b | lz4/zlib/zstd/xz | lz4 | medium |
| bigint/ubigint/timestamp | simple8b/delta-i | delta-i |lz4/zlib/zstd/xz | lz4| medium| | tinyint/untinyint/smallint/usmallint | simple8b | simple8b | lz4/zlib/zstd/xz | zlib | medium |
|float/double | delta-d|delta-d |lz4/zlib/zstd/xz/tsz|lz4| medium| | bigint/ubigint/timestamp | simple8b/delta-i | delta-i | lz4/zlib/zstd/xz | lz4 | medium |
|binary/nchar| disabled| disabled|lz4/zlib/zstd/xz| lz4| medium| | float/double | delta-d | delta-d | lz4/zlib/zstd/xz/tsz | lz4 | medium |
|bool| bit-packing| bit-packing| lz4/zlib/zstd/xz| lz4| medium| | binary/nchar | disabled | disabled | lz4/zlib/zstd/xz | zstd | medium |
| bool | bit-packing | bit-packing | lz4/zlib/zstd/xz | zstd | medium |
## SQL Syntax ## SQL Syntax

View File

@ -37,7 +37,7 @@ TDengine 提供了丰富的应用程序开发接口,为了便于用户快速
关键不同点在于: 关键不同点在于:
1. 使用 原生连接,需要保证客户端的驱动程序 taosc 和服务端的 TDengine 版本配套 1. 使用 原生连接,需要保证客户端的驱动程序 taosc 和服务端的 TDengine 版本保持一致
2. 使用 REST 连接,用户无需安装客户端驱动程序 taosc具有跨平台易用的优势但是无法体验数据订阅和二进制数据类型等功能。另外与 原生连接 和 WebSocket 连接相比REST连接的性能最低。REST 接口是无状态的。在使用 REST 连接时,需要在 SQL 中指定表、超级表的数据库名称。 2. 使用 REST 连接,用户无需安装客户端驱动程序 taosc具有跨平台易用的优势但是无法体验数据订阅和二进制数据类型等功能。另外与 原生连接 和 WebSocket 连接相比REST连接的性能最低。REST 接口是无状态的。在使用 REST 连接时,需要在 SQL 中指定表、超级表的数据库名称。
3. 使用 WebSocket 连接,用户也无需安装客户端驱动程序 taosc。 3. 使用 WebSocket 连接,用户也无需安装客户端驱动程序 taosc。
4. 连接云服务实例,必须使用 REST 连接 或 WebSocket 连接。 4. 连接云服务实例,必须使用 REST 连接 或 WebSocket 连接。

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

View File

@ -145,6 +145,44 @@ TDinsight 仪表盘旨在提供 TDengine 相关资源的使用情况和状态,
还有上述分类的细分维度折线图。 还有上述分类的细分维度折线图。
### 预配置告警规则自动导入
涛思总结用户使用经验,整理出 14 个常用的告警规则alert rule能够对集群关键指标进行监测并及时上报指标异常、超限等告警信息。
从 TDengine-server 3.3.4.3 版本tdengine-datasource 3.6.3开始TDengine Datasource 支持预配置告警规则自动导入功能,用户可将 14 个告警规则一键导入 Grafana11 及以上版本),直接使用。
预配置告警规则导入方法如下图所示,在 tdengine-datasource setting 界面,打开 “Load Tengine Alert” 开关,点击 “Save & test” 按钮后,插件会自动加载上述告警规则, 规则会放入以数据源名称 + “-alert” 的 grafana 告警目录中。如不需要,关闭 “Load TDengine Alert” 开关,点击 “Clear TDengine Alert” 旁边的按钮则会清除此数据源已导入的所有告警规则。
![TDengine Alert](./assets/TDengine-Alert.webp)
导入后,点击 Grafana 左侧 “Alert rules” ,可查看当前所有告警规则。
用户只需配置联络点Contact points即可获取告警通知。联络点配置方法见[告警配置](https://docs.taosdata.com/third-party/visual/grafana/#%E5%91%8A%E8%AD%A6%E9%85%8D%E7%BD%AE)。
![Alert-rules](./assets/Alert-rules.webp)
14 个告警规则具体配置如下:
| 规则名称| 规则阈值| 无监控数据时的行为 | 数据扫描间隔 |持续时间 | 执行SQL |
| ------ | --------- | ---------------- | ----------- |------- |----------------------|
|dnode 节点的CPU负载|均值 > 80%|触发告警|5分钟|5分钟 |`select now(), dnode_id, last(cpu_system) as cup_use from log.taosd_dnodes_info where _ts >= (now- 5m) and _ts < now partition by dnode_id having first(_ts) > 0 `|
|dnode 节点的的内存 |均值 > 60%|触发告警|5分钟|5分钟|`select now(), dnode_id, last(mem_engine) / last(mem_total) * 100 as taosd from log.taosd_dnodes_info where _ts >= (now- 5m) and _ts <now partition by dnode_id`|
|dnode 节点的磁盘容量占用 | > 80%|触发告警|5分钟|5分钟|`select now(), dnode_id, data_dir_level, data_dir_name, last(used) / last(total) * 100 as used from log.taosd_dnodes_data_dirs where _ts >= (now - 5m) and _ts < now partition by dnode_id, data_dir_level, data_dir_name`|
|集群授权到期 |< 60天|触发告警|1天|0秒|`select now(), cluster_id, last(grants_expire_time) / 86400 as expire_time from log.taosd_cluster_info where _ts >= (now - 24h) and _ts < now partition by cluster_id having first(_ts) > 0 `|
|测点数达到授权测点数|>= 90%|触发告警|1天|0秒|`select now(), cluster_id, CASE WHEN max(grants_timeseries_total) > 0.0 THEN max(grants_timeseries_used) /max(grants_timeseries_total) * 100.0 ELSE 0.0 END AS result from log.taosd_cluster_info where _ts >= (now - 30s) and _ts < now partition by cluster_id having timetruncate(first(_ts), 1m) > 0`|
|查询并发请求数 | > 100|不触发报警|1分钟|0秒|`select now() as ts, count(*) as slow_count from performance_schema.perf_queries`|
|慢查询执行最长时间 (无时间窗口) |> 300秒|不触发报警|1分钟|0秒|`select now() as ts, count(*) as slow_count from performance_schema.perf_queries where exec_usec>300000000`|
|dnode下线 |total != alive|触发告警|30秒|0秒|`select now(), cluster_id, last(dnodes_total) - last(dnodes_alive) as dnode_offline from log.taosd_cluster_info where _ts >= (now -30s) and _ts < now partition by cluster_id having first(_ts) > 0`|
|vnode下线 |total != alive|触发告警|30秒|0秒|`select now(), cluster_id, last(vnodes_total) - last(vnodes_alive) as vnode_offline from log.taosd_cluster_info where _ts >= (now - 30s) and _ts < now partition by cluster_id having first(_ts) > 0 `|
|数据删除请求数 |> 0|不触发报警|30秒|0秒|``select now(), count(`count`) as `delete_count` from log.taos_sql_req where sql_type = 'delete' and _ts >= (now -30s) and _ts < now``|
|Adapter RESTful 请求失败 |> 5|不触发报警|30秒|0秒|``select now(), sum(`fail`) as `Failed` from log.adapter_requests where req_type=0 and ts >= (now -30s) and ts < now``|
|Adapter WebSocket 请求失败 |> 5|不触发报警|30秒|0秒|``select now(), sum(`fail`) as `Failed` from log.adapter_requests where req_type=1 and ts >= (now -30s) and ts < now``|
|dnode 数据上报缺少 |< 3|触发告警|180秒|0秒|`select now(), cluster_id, count(*) as dnode_report from log.taosd_cluster_info where _ts >= (now -180s) and _ts < now partition by cluster_id having timetruncate(first(_ts), 1h) > 0`|
|dnode 重启 |max(update_time) > last(update_time)|触发告警|90秒|0秒|`select now(), dnode_id, max(uptime) - last(uptime) as dnode_restart from log.taosd_dnodes_info where _ts >= (now - 90s) and _ts < now partition by dnode_id`|
用户可参考上述告警规则,根据自己业务需求进行修改与完善。
Grafana7.5 及以下版本Dashboards 与 Alert rules 功能合在一起,而之后的新版本两个功能是分开的。为兼容 Grafana7.5 及以下版本TDinsight 面板中增加了 Alert Used Only 面板,仅 Grafana7.5 及以下版本需要使用。
![Alert Used Only](./assets/Alert-Used-Only.webp)
## 升级 ## 升级
下面三种方式都可以进行升级: 下面三种方式都可以进行升级:
- 用图形界面,若有新版本,可以在 ”TDengine Datasource“ 插件页面点击 update 升级。 - 用图形界面,若有新版本,可以在 ”TDengine Datasource“ 插件页面点击 update 升级。
@ -155,10 +193,11 @@ TDinsight 仪表盘旨在提供 TDengine 相关资源的使用情况和状态,
针对不同的安装方式,卸载时: 针对不同的安装方式,卸载时:
- 用图形界面,在 ”TDengine Datasource“ 插件页面点击 ”Uninstall“ 卸载。 - 用图形界面,在 ”TDengine Datasource“ 插件页面点击 ”Uninstall“ 卸载。
- 通过 `TDinsight.sh` 脚本安装的 TDinsight可以使用命令行 `TDinsight.sh -R` 清理相关资源。 - 通过 `TDinsight.sh` 脚本安装的 TDinsight可以使用命令行 `TDinsight.sh -R` 清理相关资源。
- 手动安装的 TDinsight要完全卸载需要清理以下内容 - 手动安装的 TDinsight要完全卸载需要按照顺序清理以下内容:
1. Grafana 中的 TDinsight Dashboard。 1. Grafana 中的 TDinsight Dashboard。
2. Grafana 中的 Data Source 数据源。 2. Grafana 中的 Alert rules 告警规则。
3. 从插件安装目录删除 `tdengine-datasource` 插件。 3. Grafana 中的 Data Source 数据源。
4. 从插件安装目录删除 `tdengine-datasource` 插件。
## 附录 ## 附录

View File

@ -195,7 +195,7 @@ alter_table_option: {
### 修改子表标签值 ### 修改子表标签值
``` ```
ALTER TABLE tb_name SET TAG tag_name=new_tag_value; ALTER TABLE tb_name SET TAG tag_name1=new_tag_value1,tag_name2=new_tag_value2...;
``` ```
### 修改表生命周期 ### 修改表生命周期

View File

@ -29,14 +29,15 @@ description: 可配置压缩算法
- 各个数据类型的默认压缩算法列表和适用范围 - 各个数据类型的默认压缩算法列表和适用范围
| 数据类型 | 可选编码算法 | 编码算法默认值 | 可选压缩算法|压缩算法默认值| 压缩等级默认值| | 数据类型 | 可选编码算法 | 编码算法默认值 | 可选压缩算法 | 压缩算法默认值 |压缩等级默认值|
| :-----------:|:----------:|:-------:|:-------:|:----------:|:----:| |:------------------------------------:|:----------------:|:-----------:|:--------------------:|:----:|:------:|
| int/uint | simple8b| simple8b | lz4/zlib/zstd/xz| lz4 | medium| | int/uint | simple8b | simple8b | lz4/zlib/zstd/xz | lz4 | medium |
| tinyint/untinyint/smallint/usmallint | simple8b| simple8b | lz4/zlib/zstd/xz| zlib | medium| | tinyint/untinyint/smallint/usmallint | simple8b | simple8b | lz4/zlib/zstd/xz | zlib | medium |
| bigint/ubigint/timestamp | simple8b/delta-i | delta-i |lz4/zlib/zstd/xz | lz4| medium| | bigint/ubigint/timestamp | simple8b/delta-i | delta-i | lz4/zlib/zstd/xz | lz4 | medium |
|float/double | delta-d|delta-d |lz4/zlib/zstd/xz/tsz|lz4| medium| | float/double | delta-d | delta-d | lz4/zlib/zstd/xz/tsz | lz4 | medium |
|binary/nchar| disabled| disabled|lz4/zlib/zstd/xz| zstd| medium| | binary/nchar | disabled | disabled | lz4/zlib/zstd/xz | zstd | medium |
|bool| bit-packing| bit-packing| lz4/zlib/zstd/xz| zstd| medium| | bool | bit-packing | bit-packing | lz4/zlib/zstd/xz | zstd | medium |
## SQL 语法 ## SQL 语法

View File

@ -48,13 +48,13 @@ void atomic_store_8(int8_t volatile *ptr, int8_t val);
void atomic_store_16(int16_t volatile *ptr, int16_t val); void atomic_store_16(int16_t volatile *ptr, int16_t val);
void atomic_store_32(int32_t volatile *ptr, int32_t val); void atomic_store_32(int32_t volatile *ptr, int32_t val);
void atomic_store_64(int64_t volatile *ptr, int64_t val); void atomic_store_64(int64_t volatile *ptr, int64_t val);
double atomic_store_double(double volatile *ptr, double val); void atomic_store_double(double volatile *ptr, double val);
void atomic_store_ptr(void *ptr, void *val); void atomic_store_ptr(void *ptr, void *val);
int8_t atomic_exchange_8(int8_t volatile *ptr, int8_t val); int8_t atomic_exchange_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_exchange_16(int16_t volatile *ptr, int16_t val); int16_t atomic_exchange_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_exchange_32(int32_t volatile *ptr, int32_t val); int32_t atomic_exchange_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_exchange_64(int64_t volatile *ptr, int64_t val); int64_t atomic_exchange_64(int64_t volatile *ptr, int64_t val);
double atomic_exchange_double(double volatile *ptr, int64_t val); double atomic_exchange_double(double volatile *ptr, double val);
void *atomic_exchange_ptr(void *ptr, void *val); void *atomic_exchange_ptr(void *ptr, void *val);
int8_t atomic_val_compare_exchange_8(int8_t volatile *ptr, int8_t oldval, int8_t newval); int8_t atomic_val_compare_exchange_8(int8_t volatile *ptr, int8_t oldval, int8_t newval);
int16_t atomic_val_compare_exchange_16(int16_t volatile *ptr, int16_t oldval, int16_t newval); int16_t atomic_val_compare_exchange_16(int16_t volatile *ptr, int16_t oldval, int16_t newval);
@ -71,7 +71,7 @@ int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val); int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val); int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val);
double atomic_fetch_add_double(double volatile *ptr, double val); double atomic_fetch_add_double(double volatile *ptr, double val);
void *atomic_fetch_add_ptr(void *ptr, void *val); void *atomic_fetch_add_ptr(void *ptr, int64_t val);
int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val); int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val); int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val); int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val);
@ -82,37 +82,37 @@ int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val); int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val); int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val);
double atomic_fetch_sub_double(double volatile *ptr, double val); double atomic_fetch_sub_double(double volatile *ptr, double val);
void *atomic_fetch_sub_ptr(void *ptr, void *val); void *atomic_fetch_sub_ptr(void *ptr, int64_t val);
int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val); int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val); int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val); int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_and_fetch_64(int64_t volatile *ptr, int64_t val); int64_t atomic_and_fetch_64(int64_t volatile *ptr, int64_t val);
void *atomic_and_fetch_ptr(void *ptr, void *val); void *atomic_and_fetch_ptr(void *ptr, int64_t val);
int8_t atomic_fetch_and_8(int8_t volatile *ptr, int8_t val); int8_t atomic_fetch_and_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_fetch_and_16(int16_t volatile *ptr, int16_t val); int16_t atomic_fetch_and_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_and_32(int32_t volatile *ptr, int32_t val); int32_t atomic_fetch_and_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_and_64(int64_t volatile *ptr, int64_t val); int64_t atomic_fetch_and_64(int64_t volatile *ptr, int64_t val);
void *atomic_fetch_and_ptr(void *ptr, void *val); void *atomic_fetch_and_ptr(void *ptr, int64_t val);
int8_t atomic_or_fetch_8(int8_t volatile *ptr, int8_t val); int8_t atomic_or_fetch_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_or_fetch_16(int16_t volatile *ptr, int16_t val); int16_t atomic_or_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_or_fetch_32(int32_t volatile *ptr, int32_t val); int32_t atomic_or_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_or_fetch_64(int64_t volatile *ptr, int64_t val); int64_t atomic_or_fetch_64(int64_t volatile *ptr, int64_t val);
void *atomic_or_fetch_ptr(void *ptr, void *val); void *atomic_or_fetch_ptr(void *ptr, int64_t val);
int8_t atomic_fetch_or_8(int8_t volatile *ptr, int8_t val); int8_t atomic_fetch_or_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_fetch_or_16(int16_t volatile *ptr, int16_t val); int16_t atomic_fetch_or_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_or_32(int32_t volatile *ptr, int32_t val); int32_t atomic_fetch_or_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_or_64(int64_t volatile *ptr, int64_t val); int64_t atomic_fetch_or_64(int64_t volatile *ptr, int64_t val);
void *atomic_fetch_or_ptr(void *ptr, void *val); void *atomic_fetch_or_ptr(void *ptr, int64_t val);
int8_t atomic_xor_fetch_8(int8_t volatile *ptr, int8_t val); int8_t atomic_xor_fetch_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_xor_fetch_16(int16_t volatile *ptr, int16_t val); int16_t atomic_xor_fetch_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_xor_fetch_32(int32_t volatile *ptr, int32_t val); int32_t atomic_xor_fetch_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_xor_fetch_64(int64_t volatile *ptr, int64_t val); int64_t atomic_xor_fetch_64(int64_t volatile *ptr, int64_t val);
void *atomic_xor_fetch_ptr(void *ptr, void *val); void *atomic_xor_fetch_ptr(void *ptr, int64_t val);
int8_t atomic_fetch_xor_8(int8_t volatile *ptr, int8_t val); int8_t atomic_fetch_xor_8(int8_t volatile *ptr, int8_t val);
int16_t atomic_fetch_xor_16(int16_t volatile *ptr, int16_t val); int16_t atomic_fetch_xor_16(int16_t volatile *ptr, int16_t val);
int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val); int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val);
int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val); int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val);
void *atomic_fetch_xor_ptr(void *ptr, void *val); void *atomic_fetch_xor_ptr(void *ptr, int64_t val);
#ifdef _MSC_VER #ifdef _MSC_VER
#define tmemory_barrier(order) MemoryBarrier() #define tmemory_barrier(order) MemoryBarrier()

View File

@ -1,59 +1,80 @@
import subprocess import subprocess
import re import re
# 执行 git fetch 命令并捕获输出
def git_fetch(): def git_fetch():
result = subprocess.run(['git', 'fetch'], capture_output=True, text=True) result = subprocess.run(['git', 'fetch'], capture_output=True, text=True)
return result return result
# 解析分支名称 def git_prune():
# git remote prune origin
print("git remote prune origin")
result = subprocess.run(['git', 'remote', 'prune', 'origin'], capture_output=True, text=True)
return result
def parse_branch_name_type1(error_output): def parse_branch_name_type1(error_output):
# 使用正则表达式匹配 'is at' 前的分支名称 # error: cannot lock ref 'refs/remotes/origin/fix/3.0/TD-32817': is at 7af5 but expected eaba
# match the branch name before is at with a regular expression
match = re.search(r"error: cannot lock ref '(refs/remotes/origin/[^']+)': is at", error_output) match = re.search(r"error: cannot lock ref '(refs/remotes/origin/[^']+)': is at", error_output)
if match: if match:
return match.group(1) return match.group(1)
return None return None
# 解析第二种错误中的分支名称
def parse_branch_name_type2(error_output): def parse_branch_name_type2(error_output):
# 使用正则表达式匹配 'exists' 前的第一个引号内的分支名称 # match the branch name before exists; cannot create with a regular expression
match = re.search(r"'(refs/remotes/origin/[^']+)' exists;", error_output) match = re.search(r"'(refs/remotes/origin/[^']+)' exists;", error_output)
if match: if match:
return match.group(1) return match.group(1)
return None return None
# 执行 git update-ref -d 命令 # parse branch name from error output of git remote prune origin
def parse_branch_name_type3(error_output):
# match the branch name before the first single quote before 'Unable to' with a regular expression
# git error: could not delete references: cannot lock ref 'refs/remotes/origin/test/3.0/TS-4893': Unable to create 'D:/workspace/main/TDinternal/community/.git/refs/remotes/origin/test/3.0/TS-4893.lock': File exists
match = re.search(r"references: cannot lock ref '(refs/remotes/origin/[^']+)': Unable to", error_output)
if match:
return match.group(1)
return None
# execute git update-ref -d <branch_name> to delete the ref
def git_update_ref(branch_name): def git_update_ref(branch_name):
if branch_name: if branch_name:
subprocess.run(['git', 'update-ref', '-d', f'{branch_name}'], check=True) subprocess.run(['git', 'update-ref', '-d', f'{branch_name}'], check=True)
# 解析错误类型并执行相应的修复操作 # parse error type and execute corresponding repair operation
def handle_error(error_output): def handle_error(error_output):
# 错误类型1本地引用的提交ID与远程不一致 error_types = [
if "is at" in error_output and "but expected" in error_output: ("is at", "but expected", parse_branch_name_type1, "type 1"),
branch_name = parse_branch_name_type1(error_output) ("exists; cannot create", None, parse_branch_name_type2, "type 2"),
if branch_name: ("Unable to create", "File exists", parse_branch_name_type3, "type 3")
print(f"Detected error type 1, attempting to delete ref for branch: {branch_name}") ]
git_update_ref(branch_name)
else: for error_type in error_types:
print("Error parsing branch name for type 1.") if error_type[0] in error_output and (error_type[1] is None or error_type[1] in error_output):
# 错误类型2尝试创建新的远程引用时本地已经存在同名的引用 branch_name = error_type[2](error_output)
elif "exists; cannot create" in error_output: if branch_name:
branch_name = parse_branch_name_type2(error_output) print(f"Detected error {error_type[3]}, attempting to delete ref for branch: {branch_name}")
if branch_name: git_update_ref(branch_name)
print(f"Detected error type 2, attempting to delete ref for branch: {branch_name}") else:
git_update_ref(branch_name) print(f"Error parsing branch name for {error_type[3]}.")
else: break
print("Error parsing branch name for type 2.")
# 主函数
def main(): def main():
fetch_result = git_fetch() fetch_result = git_fetch()
if fetch_result.returncode != 0: # 如果 git fetch 命令失败 if fetch_result.returncode != 0:
error_output = fetch_result.stderr error_output = fetch_result.stderr
handle_error(error_output) handle_error(error_output)
else: else:
print("Git fetch successful.") print("Git fetch successful.")
prune_result = git_prune()
print(prune_result.returncode)
if prune_result.returncode != 0:
error_output = prune_result.stderr
print(error_output)
handle_error(error_output)
else:
print("Git prune successful.")
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -52,6 +52,22 @@
#define TMQ_META_VERSION "1.0" #define TMQ_META_VERSION "1.0"
static bool tmqAddJsonObjectItem(cJSON *object, const char *string, cJSON *item){
bool ret = cJSON_AddItemToObject(object, string, item);
if (!ret){
cJSON_Delete(item);
}
return ret;
}
static bool tmqAddJsonArrayItem(cJSON *array, cJSON *item){
bool ret = cJSON_AddItemToArray(array, item);
if (!ret){
cJSON_Delete(item);
}
return ret;
}
static int32_t tmqWriteBatchMetaDataImpl(TAOS* taos, void* meta, int32_t metaLen); static int32_t tmqWriteBatchMetaDataImpl(TAOS* taos, void* meta, int32_t metaLen);
static tb_uid_t processSuid(tb_uid_t suid, char* db) { return suid + MurmurHash3_32(db, strlen(db)); } static tb_uid_t processSuid(tb_uid_t suid, char* db) { return suid + MurmurHash3_32(db, strlen(db)); }
static void buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* schemaTag, char* name, int64_t id, int8_t t, static void buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* schemaTag, char* name, int64_t id, int8_t t,
@ -68,41 +84,43 @@ static void buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* sche
cJSON* type = cJSON_CreateString("create"); cJSON* type = cJSON_CreateString("create");
RAW_NULL_CHECK(type); RAW_NULL_CHECK(type);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
cJSON* tableType = cJSON_CreateString(t == TSDB_NORMAL_TABLE ? "normal" : "super"); cJSON* tableType = cJSON_CreateString(t == TSDB_NORMAL_TABLE ? "normal" : "super");
RAW_NULL_CHECK(tableType); RAW_NULL_CHECK(tableType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableType", tableType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
cJSON* tableName = cJSON_CreateString(name); cJSON* tableName = cJSON_CreateString(name);
RAW_NULL_CHECK(tableName); RAW_NULL_CHECK(tableName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableName", tableName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
cJSON* columns = cJSON_CreateArray(); cJSON* columns = cJSON_CreateArray();
RAW_NULL_CHECK(columns); RAW_NULL_CHECK(columns);
RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "columns", columns));
for (int i = 0; i < schemaRow->nCols; i++) { for (int i = 0; i < schemaRow->nCols; i++) {
cJSON* column = cJSON_CreateObject(); cJSON* column = cJSON_CreateObject();
RAW_NULL_CHECK(column); RAW_NULL_CHECK(column);
RAW_FALSE_CHECK(tmqAddJsonArrayItem(columns, column));
SSchema* s = schemaRow->pSchema + i; SSchema* s = schemaRow->pSchema + i;
cJSON* cname = cJSON_CreateString(s->name); cJSON* cname = cJSON_CreateString(s->name);
RAW_NULL_CHECK(cname); RAW_NULL_CHECK(cname);
RAW_FALSE_CHECK(cJSON_AddItemToObject(column, "name", cname)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "name", cname));
cJSON* ctype = cJSON_CreateNumber(s->type); cJSON* ctype = cJSON_CreateNumber(s->type);
RAW_NULL_CHECK(ctype); RAW_NULL_CHECK(ctype);
RAW_FALSE_CHECK(cJSON_AddItemToObject(column, "type", ctype)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "type", ctype));
if (s->type == TSDB_DATA_TYPE_BINARY || s->type == TSDB_DATA_TYPE_VARBINARY || s->type == TSDB_DATA_TYPE_GEOMETRY) { if (s->type == TSDB_DATA_TYPE_BINARY || s->type == TSDB_DATA_TYPE_VARBINARY || s->type == TSDB_DATA_TYPE_GEOMETRY) {
int32_t length = s->bytes - VARSTR_HEADER_SIZE; int32_t length = s->bytes - VARSTR_HEADER_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(column, "length", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "length", cbytes));
} else if (s->type == TSDB_DATA_TYPE_NCHAR) { } else if (s->type == TSDB_DATA_TYPE_NCHAR) {
int32_t length = (s->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t length = (s->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(column, "length", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "length", cbytes));
} }
cJSON* isPk = cJSON_CreateBool(s->flags & COL_IS_KEY); cJSON* isPk = cJSON_CreateBool(s->flags & COL_IS_KEY);
RAW_NULL_CHECK(isPk); RAW_NULL_CHECK(isPk);
RAW_FALSE_CHECK(cJSON_AddItemToObject(column, "isPrimarykey", isPk)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "isPrimarykey", isPk));
RAW_FALSE_CHECK(cJSON_AddItemToArray(columns, column));
if (pColCmprRow == NULL) { if (pColCmprRow == NULL) {
continue; continue;
@ -124,44 +142,44 @@ static void buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* sche
cJSON* encodeJson = cJSON_CreateString(encode); cJSON* encodeJson = cJSON_CreateString(encode);
RAW_NULL_CHECK(encodeJson); RAW_NULL_CHECK(encodeJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(column, "encode", encodeJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "encode", encodeJson));
cJSON* compressJson = cJSON_CreateString(compress); cJSON* compressJson = cJSON_CreateString(compress);
RAW_NULL_CHECK(compressJson); RAW_NULL_CHECK(compressJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(column, "compress", compressJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "compress", compressJson));
cJSON* levelJson = cJSON_CreateString(level); cJSON* levelJson = cJSON_CreateString(level);
RAW_NULL_CHECK(levelJson); RAW_NULL_CHECK(levelJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(column, "level", levelJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(column, "level", levelJson));
} }
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "columns", columns));
cJSON* tags = cJSON_CreateArray(); cJSON* tags = cJSON_CreateArray();
RAW_NULL_CHECK(tags); RAW_NULL_CHECK(tags);
RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tags", tags));
for (int i = 0; schemaTag && i < schemaTag->nCols; i++) { for (int i = 0; schemaTag && i < schemaTag->nCols; i++) {
cJSON* tag = cJSON_CreateObject(); cJSON* tag = cJSON_CreateObject();
RAW_NULL_CHECK(tag); RAW_NULL_CHECK(tag);
RAW_FALSE_CHECK(tmqAddJsonArrayItem(tags, tag));
SSchema* s = schemaTag->pSchema + i; SSchema* s = schemaTag->pSchema + i;
cJSON* tname = cJSON_CreateString(s->name); cJSON* tname = cJSON_CreateString(s->name);
RAW_NULL_CHECK(tname); RAW_NULL_CHECK(tname);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "name", tname)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "name", tname));
cJSON* ttype = cJSON_CreateNumber(s->type); cJSON* ttype = cJSON_CreateNumber(s->type);
RAW_NULL_CHECK(ttype); RAW_NULL_CHECK(ttype);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "type", ttype)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "type", ttype));
if (s->type == TSDB_DATA_TYPE_BINARY || s->type == TSDB_DATA_TYPE_VARBINARY || s->type == TSDB_DATA_TYPE_GEOMETRY) { if (s->type == TSDB_DATA_TYPE_BINARY || s->type == TSDB_DATA_TYPE_VARBINARY || s->type == TSDB_DATA_TYPE_GEOMETRY) {
int32_t length = s->bytes - VARSTR_HEADER_SIZE; int32_t length = s->bytes - VARSTR_HEADER_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "length", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "length", cbytes));
} else if (s->type == TSDB_DATA_TYPE_NCHAR) { } else if (s->type == TSDB_DATA_TYPE_NCHAR) {
int32_t length = (s->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t length = (s->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "length", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "length", cbytes));
} }
RAW_FALSE_CHECK(cJSON_AddItemToArray(tags, tag));
} }
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tags", tags));
end: end:
*pJson = json; *pJson = json;
@ -175,7 +193,7 @@ static int32_t setCompressOption(cJSON* json, uint32_t para) {
RAW_NULL_CHECK(encodeStr); RAW_NULL_CHECK(encodeStr);
cJSON* encodeJson = cJSON_CreateString(encodeStr); cJSON* encodeJson = cJSON_CreateString(encodeStr);
RAW_NULL_CHECK(encodeJson); RAW_NULL_CHECK(encodeJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "encode", encodeJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "encode", encodeJson));
return code; return code;
} }
uint8_t compress = COMPRESS_L2_TYPE_U32(para); uint8_t compress = COMPRESS_L2_TYPE_U32(para);
@ -184,7 +202,7 @@ static int32_t setCompressOption(cJSON* json, uint32_t para) {
RAW_NULL_CHECK(compressStr); RAW_NULL_CHECK(compressStr);
cJSON* compressJson = cJSON_CreateString(compressStr); cJSON* compressJson = cJSON_CreateString(compressStr);
RAW_NULL_CHECK(compressJson); RAW_NULL_CHECK(compressJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "compress", compressJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "compress", compressJson));
return code; return code;
} }
uint8_t level = COMPRESS_L2_TYPE_LEVEL_U32(para); uint8_t level = COMPRESS_L2_TYPE_LEVEL_U32(para);
@ -193,7 +211,7 @@ static int32_t setCompressOption(cJSON* json, uint32_t para) {
RAW_NULL_CHECK(levelStr); RAW_NULL_CHECK(levelStr);
cJSON* levelJson = cJSON_CreateString(levelStr); cJSON* levelJson = cJSON_CreateString(levelStr);
RAW_NULL_CHECK(levelJson); RAW_NULL_CHECK(levelJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "level", levelJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "level", levelJson));
return code; return code;
} }
@ -214,19 +232,19 @@ static void buildAlterSTableJson(void* alterData, int32_t alterDataLen, cJSON**
RAW_NULL_CHECK(json); RAW_NULL_CHECK(json);
cJSON* type = cJSON_CreateString("alter"); cJSON* type = cJSON_CreateString("alter");
RAW_NULL_CHECK(type); RAW_NULL_CHECK(type);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
SName name = {0}; SName name = {0};
RAW_RETURN_CHECK(tNameFromString(&name, req.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)); RAW_RETURN_CHECK(tNameFromString(&name, req.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE));
cJSON* tableType = cJSON_CreateString("super"); cJSON* tableType = cJSON_CreateString("super");
RAW_NULL_CHECK(tableType); RAW_NULL_CHECK(tableType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableType", tableType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
cJSON* tableName = cJSON_CreateString(name.tname); cJSON* tableName = cJSON_CreateString(name.tname);
RAW_NULL_CHECK(tableName); RAW_NULL_CHECK(tableName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableName", tableName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
cJSON* alterType = cJSON_CreateNumber(req.alterType); cJSON* alterType = cJSON_CreateNumber(req.alterType);
RAW_NULL_CHECK(alterType); RAW_NULL_CHECK(alterType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "alterType", alterType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "alterType", alterType));
switch (req.alterType) { switch (req.alterType) {
case TSDB_ALTER_TABLE_ADD_TAG: case TSDB_ALTER_TABLE_ADD_TAG:
case TSDB_ALTER_TABLE_ADD_COLUMN: { case TSDB_ALTER_TABLE_ADD_COLUMN: {
@ -234,22 +252,22 @@ static void buildAlterSTableJson(void* alterData, int32_t alterDataLen, cJSON**
RAW_NULL_CHECK(field); RAW_NULL_CHECK(field);
cJSON* colName = cJSON_CreateString(field->name); cJSON* colName = cJSON_CreateString(field->name);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
cJSON* colType = cJSON_CreateNumber(field->type); cJSON* colType = cJSON_CreateNumber(field->type);
RAW_NULL_CHECK(colType); RAW_NULL_CHECK(colType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colType", colType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY || if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY ||
field->type == TSDB_DATA_TYPE_GEOMETRY) { field->type == TSDB_DATA_TYPE_GEOMETRY) {
int32_t length = field->bytes - VARSTR_HEADER_SIZE; int32_t length = field->bytes - VARSTR_HEADER_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} else if (field->type == TSDB_DATA_TYPE_NCHAR) { } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} }
break; break;
} }
@ -258,22 +276,22 @@ static void buildAlterSTableJson(void* alterData, int32_t alterDataLen, cJSON**
RAW_NULL_CHECK(field); RAW_NULL_CHECK(field);
cJSON* colName = cJSON_CreateString(field->name); cJSON* colName = cJSON_CreateString(field->name);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
cJSON* colType = cJSON_CreateNumber(field->type); cJSON* colType = cJSON_CreateNumber(field->type);
RAW_NULL_CHECK(colType); RAW_NULL_CHECK(colType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colType", colType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY || if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY ||
field->type == TSDB_DATA_TYPE_GEOMETRY) { field->type == TSDB_DATA_TYPE_GEOMETRY) {
int32_t length = field->bytes - VARSTR_HEADER_SIZE; int32_t length = field->bytes - VARSTR_HEADER_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} else if (field->type == TSDB_DATA_TYPE_NCHAR) { } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} }
RAW_RETURN_CHECK(setCompressOption(json, field->compress)); RAW_RETURN_CHECK(setCompressOption(json, field->compress));
break; break;
@ -284,7 +302,7 @@ static void buildAlterSTableJson(void* alterData, int32_t alterDataLen, cJSON**
RAW_NULL_CHECK(field); RAW_NULL_CHECK(field);
cJSON* colName = cJSON_CreateString(field->name); cJSON* colName = cJSON_CreateString(field->name);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
break; break;
} }
case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES: case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES:
@ -293,21 +311,21 @@ static void buildAlterSTableJson(void* alterData, int32_t alterDataLen, cJSON**
RAW_NULL_CHECK(field); RAW_NULL_CHECK(field);
cJSON* colName = cJSON_CreateString(field->name); cJSON* colName = cJSON_CreateString(field->name);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
cJSON* colType = cJSON_CreateNumber(field->type); cJSON* colType = cJSON_CreateNumber(field->type);
RAW_NULL_CHECK(colType); RAW_NULL_CHECK(colType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colType", colType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY || if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY ||
field->type == TSDB_DATA_TYPE_GEOMETRY) { field->type == TSDB_DATA_TYPE_GEOMETRY) {
int32_t length = field->bytes - VARSTR_HEADER_SIZE; int32_t length = field->bytes - VARSTR_HEADER_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} else if (field->type == TSDB_DATA_TYPE_NCHAR) { } else if (field->type == TSDB_DATA_TYPE_NCHAR) {
int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t length = (field->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} }
break; break;
} }
@ -319,10 +337,10 @@ static void buildAlterSTableJson(void* alterData, int32_t alterDataLen, cJSON**
RAW_NULL_CHECK(newField); RAW_NULL_CHECK(newField);
cJSON* colName = cJSON_CreateString(oldField->name); cJSON* colName = cJSON_CreateString(oldField->name);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
cJSON* colNewName = cJSON_CreateString(newField->name); cJSON* colNewName = cJSON_CreateString(newField->name);
RAW_NULL_CHECK(colNewName); RAW_NULL_CHECK(colNewName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colNewName", colNewName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colNewName", colNewName));
break; break;
} }
case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: { case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: {
@ -330,7 +348,7 @@ static void buildAlterSTableJson(void* alterData, int32_t alterDataLen, cJSON**
RAW_NULL_CHECK(field); RAW_NULL_CHECK(field);
cJSON* colName = cJSON_CreateString(field->name); cJSON* colName = cJSON_CreateString(field->name);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
RAW_RETURN_CHECK(setCompressOption(json, field->bytes)); RAW_RETURN_CHECK(setCompressOption(json, field->bytes));
break; break;
} }
@ -391,51 +409,47 @@ static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) {
int64_t id = pCreateReq->uid; int64_t id = pCreateReq->uid;
uint8_t tagNum = pCreateReq->ctb.tagNum; uint8_t tagNum = pCreateReq->ctb.tagNum;
int32_t code = 0; int32_t code = 0;
cJSON* tags = NULL; SArray* pTagVals = NULL;
char* pJson = NULL;
cJSON* tableName = cJSON_CreateString(name); cJSON* tableName = cJSON_CreateString(name);
RAW_NULL_CHECK(tableName); RAW_NULL_CHECK(tableName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableName", tableName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
cJSON* using = cJSON_CreateString(sname); cJSON* using = cJSON_CreateString(sname);
RAW_NULL_CHECK(using); RAW_NULL_CHECK(using);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "using", using)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "using", using));
cJSON* tagNumJson = cJSON_CreateNumber(tagNum); cJSON* tagNumJson = cJSON_CreateNumber(tagNum);
RAW_NULL_CHECK(tagNumJson); RAW_NULL_CHECK(tagNumJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tagNum", tagNumJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tagNum", tagNumJson));
tags = cJSON_CreateArray(); cJSON* tags = cJSON_CreateArray();
RAW_NULL_CHECK(tags); RAW_NULL_CHECK(tags);
SArray* pTagVals = NULL; RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tags", tags));
RAW_RETURN_CHECK(tTagToValArray(pTag, &pTagVals)); RAW_RETURN_CHECK(tTagToValArray(pTag, &pTagVals));
if (tTagIsJson(pTag)) { if (tTagIsJson(pTag)) {
STag* p = (STag*)pTag; STag* p = (STag*)pTag;
if (p->nTag == 0) { if (p->nTag == 0) {
uError("p->nTag == 0"); uError("p->nTag == 0");
goto end; goto end;
} }
char* pJson = NULL;
parseTagDatatoJson(pTag, &pJson, NULL); parseTagDatatoJson(pTag, &pJson, NULL);
if (pJson == NULL) { RAW_NULL_CHECK(pJson);
uError("parseTagDatatoJson failed, pJson == NULL");
goto end;
}
cJSON* tag = cJSON_CreateObject(); cJSON* tag = cJSON_CreateObject();
RAW_NULL_CHECK(tag); RAW_NULL_CHECK(tag);
RAW_FALSE_CHECK(tmqAddJsonArrayItem(tags, tag));
STagVal* pTagVal = taosArrayGet(pTagVals, 0); STagVal* pTagVal = taosArrayGet(pTagVals, 0);
RAW_NULL_CHECK(pTagVal); RAW_NULL_CHECK(pTagVal);
char* ptname = taosArrayGet(tagName, 0); char* ptname = taosArrayGet(tagName, 0);
RAW_NULL_CHECK(ptname); RAW_NULL_CHECK(ptname);
cJSON* tname = cJSON_CreateString(ptname); cJSON* tname = cJSON_CreateString(ptname);
RAW_NULL_CHECK(tname); RAW_NULL_CHECK(tname);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "name", tname)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "name", tname));
cJSON* ttype = cJSON_CreateNumber(TSDB_DATA_TYPE_JSON); cJSON* ttype = cJSON_CreateNumber(TSDB_DATA_TYPE_JSON);
RAW_NULL_CHECK(ttype); RAW_NULL_CHECK(ttype);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "type", ttype)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "type", ttype));
cJSON* tvalue = cJSON_CreateString(pJson); cJSON* tvalue = cJSON_CreateString(pJson);
RAW_NULL_CHECK(tvalue); RAW_NULL_CHECK(tvalue);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "value", tvalue)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "value", tvalue));
RAW_FALSE_CHECK(cJSON_AddItemToArray(tags, tag));
taosMemoryFree(pJson);
goto end; goto end;
} }
@ -444,36 +458,34 @@ static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) {
RAW_NULL_CHECK(pTagVal); RAW_NULL_CHECK(pTagVal);
cJSON* tag = cJSON_CreateObject(); cJSON* tag = cJSON_CreateObject();
RAW_NULL_CHECK(tag); RAW_NULL_CHECK(tag);
RAW_FALSE_CHECK(tmqAddJsonArrayItem(tags, tag));
char* ptname = taosArrayGet(tagName, i); char* ptname = taosArrayGet(tagName, i);
RAW_NULL_CHECK(ptname); RAW_NULL_CHECK(ptname);
cJSON* tname = cJSON_CreateString(ptname); cJSON* tname = cJSON_CreateString(ptname);
RAW_NULL_CHECK(tname); RAW_NULL_CHECK(tname);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "name", tname)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "name", tname));
cJSON* ttype = cJSON_CreateNumber(pTagVal->type); cJSON* ttype = cJSON_CreateNumber(pTagVal->type);
RAW_NULL_CHECK(ttype); RAW_NULL_CHECK(ttype);
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "type", ttype)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "type", ttype));
cJSON* tvalue = NULL; cJSON* tvalue = NULL;
if (IS_VAR_DATA_TYPE(pTagVal->type)) { if (IS_VAR_DATA_TYPE(pTagVal->type)) {
char* buf = NULL;
int64_t bufSize = 0; int64_t bufSize = 0;
if (pTagVal->type == TSDB_DATA_TYPE_VARBINARY) { if (pTagVal->type == TSDB_DATA_TYPE_VARBINARY) {
bufSize = pTagVal->nData * 2 + 2 + 3; bufSize = pTagVal->nData * 2 + 2 + 3;
} else { } else {
bufSize = pTagVal->nData + 3; bufSize = pTagVal->nData + 3;
} }
buf = taosMemoryCalloc(bufSize, 1); char* buf = taosMemoryCalloc(bufSize, 1);
RAW_NULL_CHECK(buf); RAW_NULL_CHECK(buf);
if (!buf) goto end;
if (dataConverToStr(buf, bufSize, pTagVal->type, pTagVal->pData, pTagVal->nData, NULL) != TSDB_CODE_SUCCESS) { if (dataConverToStr(buf, bufSize, pTagVal->type, pTagVal->pData, pTagVal->nData, NULL) != TSDB_CODE_SUCCESS) {
taosMemoryFree(buf); taosMemoryFree(buf);
goto end; goto end;
} }
tvalue = cJSON_CreateString(buf); tvalue = cJSON_CreateString(buf);
RAW_NULL_CHECK(tvalue);
taosMemoryFree(buf); taosMemoryFree(buf);
RAW_NULL_CHECK(tvalue);
} else { } else {
double val = 0; double val = 0;
GET_TYPED_DATA(val, double, pTagVal->type, &pTagVal->i64); GET_TYPED_DATA(val, double, pTagVal->type, &pTagVal->i64);
@ -481,12 +493,11 @@ static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) {
RAW_NULL_CHECK(tvalue); RAW_NULL_CHECK(tvalue);
} }
RAW_FALSE_CHECK(cJSON_AddItemToObject(tag, "value", tvalue)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(tag, "value", tvalue));
RAW_FALSE_CHECK(cJSON_AddItemToArray(tags, tag));
} }
end: end:
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tags", tags)); taosMemoryFree(pJson);
taosArrayDestroy(pTagVals); taosArrayDestroy(pTagVals);
} }
@ -497,22 +508,23 @@ static void buildCreateCTableJson(SVCreateTbReq* pCreateReq, int32_t nReqs, cJSO
RAW_NULL_CHECK(json); RAW_NULL_CHECK(json);
cJSON* type = cJSON_CreateString("create"); cJSON* type = cJSON_CreateString("create");
RAW_NULL_CHECK(type); RAW_NULL_CHECK(type);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
cJSON* tableType = cJSON_CreateString("child"); cJSON* tableType = cJSON_CreateString("child");
RAW_NULL_CHECK(tableType); RAW_NULL_CHECK(tableType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableType", tableType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
buildChildElement(json, pCreateReq); buildChildElement(json, pCreateReq);
cJSON* createList = cJSON_CreateArray(); cJSON* createList = cJSON_CreateArray();
RAW_NULL_CHECK(createList); RAW_NULL_CHECK(createList);
RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "createList", createList));
for (int i = 0; nReqs > 1 && i < nReqs; i++) { for (int i = 0; nReqs > 1 && i < nReqs; i++) {
cJSON* create = cJSON_CreateObject(); cJSON* create = cJSON_CreateObject();
RAW_NULL_CHECK(create); RAW_NULL_CHECK(create);
buildChildElement(create, pCreateReq + i); buildChildElement(create, pCreateReq + i);
RAW_FALSE_CHECK(cJSON_AddItemToArray(createList, create)); RAW_FALSE_CHECK(tmqAddJsonArrayItem(createList, create));
} }
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "createList", createList));
end: end:
*pJson = json; *pJson = json;
@ -619,62 +631,62 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
RAW_NULL_CHECK(json); RAW_NULL_CHECK(json);
cJSON* type = cJSON_CreateString("alter"); cJSON* type = cJSON_CreateString("alter");
RAW_NULL_CHECK(type); RAW_NULL_CHECK(type);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL || cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL ||
vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL
? "child" ? "child"
: "normal"); : "normal");
RAW_NULL_CHECK(tableType); RAW_NULL_CHECK(tableType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableType", tableType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
cJSON* tableName = cJSON_CreateString(vAlterTbReq.tbName); cJSON* tableName = cJSON_CreateString(vAlterTbReq.tbName);
RAW_NULL_CHECK(tableName); RAW_NULL_CHECK(tableName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableName", tableName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
cJSON* alterType = cJSON_CreateNumber(vAlterTbReq.action); cJSON* alterType = cJSON_CreateNumber(vAlterTbReq.action);
RAW_NULL_CHECK(alterType); RAW_NULL_CHECK(alterType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "alterType", alterType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "alterType", alterType));
switch (vAlterTbReq.action) { switch (vAlterTbReq.action) {
case TSDB_ALTER_TABLE_ADD_COLUMN: { case TSDB_ALTER_TABLE_ADD_COLUMN: {
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type); cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type);
RAW_NULL_CHECK(colType); RAW_NULL_CHECK(colType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colType", colType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY || vAlterTbReq.type == TSDB_DATA_TYPE_VARBINARY || if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY || vAlterTbReq.type == TSDB_DATA_TYPE_VARBINARY ||
vAlterTbReq.type == TSDB_DATA_TYPE_GEOMETRY) { vAlterTbReq.type == TSDB_DATA_TYPE_GEOMETRY) {
int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE; int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) { } else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) {
int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} }
break; break;
} }
case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: { case TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION: {
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type); cJSON* colType = cJSON_CreateNumber(vAlterTbReq.type);
RAW_NULL_CHECK(colType); RAW_NULL_CHECK(colType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colType", colType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY || vAlterTbReq.type == TSDB_DATA_TYPE_VARBINARY || if (vAlterTbReq.type == TSDB_DATA_TYPE_BINARY || vAlterTbReq.type == TSDB_DATA_TYPE_VARBINARY ||
vAlterTbReq.type == TSDB_DATA_TYPE_GEOMETRY) { vAlterTbReq.type == TSDB_DATA_TYPE_GEOMETRY) {
int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE; int32_t length = vAlterTbReq.bytes - VARSTR_HEADER_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) { } else if (vAlterTbReq.type == TSDB_DATA_TYPE_NCHAR) {
int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t length = (vAlterTbReq.bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} }
RAW_RETURN_CHECK(setCompressOption(json, vAlterTbReq.compress)); RAW_RETURN_CHECK(setCompressOption(json, vAlterTbReq.compress));
break; break;
@ -682,43 +694,43 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
case TSDB_ALTER_TABLE_DROP_COLUMN: { case TSDB_ALTER_TABLE_DROP_COLUMN: {
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
break; break;
} }
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: { case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: {
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
cJSON* colType = cJSON_CreateNumber(vAlterTbReq.colModType); cJSON* colType = cJSON_CreateNumber(vAlterTbReq.colModType);
RAW_NULL_CHECK(colType); RAW_NULL_CHECK(colType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colType", colType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colType", colType));
if (vAlterTbReq.colModType == TSDB_DATA_TYPE_BINARY || vAlterTbReq.colModType == TSDB_DATA_TYPE_VARBINARY || if (vAlterTbReq.colModType == TSDB_DATA_TYPE_BINARY || vAlterTbReq.colModType == TSDB_DATA_TYPE_VARBINARY ||
vAlterTbReq.colModType == TSDB_DATA_TYPE_GEOMETRY) { vAlterTbReq.colModType == TSDB_DATA_TYPE_GEOMETRY) {
int32_t length = vAlterTbReq.colModBytes - VARSTR_HEADER_SIZE; int32_t length = vAlterTbReq.colModBytes - VARSTR_HEADER_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} else if (vAlterTbReq.colModType == TSDB_DATA_TYPE_NCHAR) { } else if (vAlterTbReq.colModType == TSDB_DATA_TYPE_NCHAR) {
int32_t length = (vAlterTbReq.colModBytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t length = (vAlterTbReq.colModBytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
cJSON* cbytes = cJSON_CreateNumber(length); cJSON* cbytes = cJSON_CreateNumber(length);
RAW_NULL_CHECK(cbytes); RAW_NULL_CHECK(cbytes);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colLength", cbytes)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colLength", cbytes));
} }
break; break;
} }
case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: { case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: {
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
cJSON* colNewName = cJSON_CreateString(vAlterTbReq.colNewName); cJSON* colNewName = cJSON_CreateString(vAlterTbReq.colNewName);
RAW_NULL_CHECK(colNewName); RAW_NULL_CHECK(colNewName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colNewName", colNewName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colNewName", colNewName));
break; break;
} }
case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: { case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: {
cJSON* tagName = cJSON_CreateString(vAlterTbReq.tagName); cJSON* tagName = cJSON_CreateString(vAlterTbReq.tagName);
RAW_NULL_CHECK(tagName); RAW_NULL_CHECK(tagName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", tagName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", tagName));
bool isNull = vAlterTbReq.isNull; bool isNull = vAlterTbReq.isNull;
if (vAlterTbReq.tagType == TSDB_DATA_TYPE_JSON) { if (vAlterTbReq.tagType == TSDB_DATA_TYPE_JSON) {
@ -757,12 +769,12 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
cJSON* colValue = cJSON_CreateString(buf); cJSON* colValue = cJSON_CreateString(buf);
taosMemoryFree(buf); taosMemoryFree(buf);
RAW_NULL_CHECK(colValue); RAW_NULL_CHECK(colValue);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colValue", colValue)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colValue", colValue));
} }
cJSON* isNullCJson = cJSON_CreateBool(isNull); cJSON* isNullCJson = cJSON_CreateBool(isNull);
RAW_NULL_CHECK(isNullCJson); RAW_NULL_CHECK(isNullCJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colValueNull", isNullCJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colValueNull", isNullCJson));
break; break;
} }
case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: { case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: {
@ -774,14 +786,17 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
cJSON* tags = cJSON_CreateArray(); cJSON* tags = cJSON_CreateArray();
RAW_NULL_CHECK(tags); RAW_NULL_CHECK(tags);
RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tags", tags));
for (int32_t i = 0; i < nTags; i++) { for (int32_t i = 0; i < nTags; i++) {
cJSON* member = cJSON_CreateObject(); cJSON* member = cJSON_CreateObject();
RAW_NULL_CHECK(member); RAW_NULL_CHECK(member);
RAW_FALSE_CHECK(tmqAddJsonArrayItem(tags, member));
SMultiTagUpateVal* pTagVal = taosArrayGet(vAlterTbReq.pMultiTag, i); SMultiTagUpateVal* pTagVal = taosArrayGet(vAlterTbReq.pMultiTag, i);
cJSON* tagName = cJSON_CreateString(pTagVal->tagName); cJSON* tagName = cJSON_CreateString(pTagVal->tagName);
RAW_NULL_CHECK(tagName); RAW_NULL_CHECK(tagName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colName", tagName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(member, "colName", tagName));
if (pTagVal->tagType == TSDB_DATA_TYPE_JSON) { if (pTagVal->tagType == TSDB_DATA_TYPE_JSON) {
uError("processAlterTable isJson false"); uError("processAlterTable isJson false");
@ -789,14 +804,13 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
} }
bool isNull = pTagVal->isNull; bool isNull = pTagVal->isNull;
if (!isNull) { if (!isNull) {
char* buf = NULL;
int64_t bufSize = 0; int64_t bufSize = 0;
if (pTagVal->tagType == TSDB_DATA_TYPE_VARBINARY) { if (pTagVal->tagType == TSDB_DATA_TYPE_VARBINARY) {
bufSize = pTagVal->nTagVal * 2 + 2 + 3; bufSize = pTagVal->nTagVal * 2 + 2 + 3;
} else { } else {
bufSize = pTagVal->nTagVal + 3; bufSize = pTagVal->nTagVal + 3;
} }
buf = taosMemoryCalloc(bufSize, 1); char* buf = taosMemoryCalloc(bufSize, 1);
RAW_NULL_CHECK(buf); RAW_NULL_CHECK(buf);
if (dataConverToStr(buf, bufSize, pTagVal->tagType, pTagVal->pTagVal, pTagVal->nTagVal, NULL) != if (dataConverToStr(buf, bufSize, pTagVal->tagType, pTagVal->pTagVal, pTagVal->nTagVal, NULL) !=
TSDB_CODE_SUCCESS) { TSDB_CODE_SUCCESS) {
@ -806,21 +820,19 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
cJSON* colValue = cJSON_CreateString(buf); cJSON* colValue = cJSON_CreateString(buf);
taosMemoryFree(buf); taosMemoryFree(buf);
RAW_NULL_CHECK(colValue); RAW_NULL_CHECK(colValue);
RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colValue", colValue)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(member, "colValue", colValue));
} }
cJSON* isNullCJson = cJSON_CreateBool(isNull); cJSON* isNullCJson = cJSON_CreateBool(isNull);
RAW_NULL_CHECK(isNullCJson); RAW_NULL_CHECK(isNullCJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colValueNull", isNullCJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(member, "colValueNull", isNullCJson));
RAW_FALSE_CHECK(cJSON_AddItemToArray(tags, member));
} }
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tags", tags));
break; break;
} }
case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: { case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: {
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName); cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
RAW_NULL_CHECK(colName); RAW_NULL_CHECK(colName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colName", colName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "colName", colName));
RAW_RETURN_CHECK(setCompressOption(json, vAlterTbReq.compress)); RAW_RETURN_CHECK(setCompressOption(json, vAlterTbReq.compress));
break; break;
} }
@ -858,13 +870,13 @@ static void processDropSTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
RAW_NULL_CHECK(json); RAW_NULL_CHECK(json);
cJSON* type = cJSON_CreateString("drop"); cJSON* type = cJSON_CreateString("drop");
RAW_NULL_CHECK(type); RAW_NULL_CHECK(type);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
cJSON* tableType = cJSON_CreateString("super"); cJSON* tableType = cJSON_CreateString("super");
RAW_NULL_CHECK(tableType); RAW_NULL_CHECK(tableType);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableType", tableType)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableType", tableType));
cJSON* tableName = cJSON_CreateString(req.name); cJSON* tableName = cJSON_CreateString(req.name);
RAW_NULL_CHECK(tableName); RAW_NULL_CHECK(tableName);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableName", tableName)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableName", tableName));
end: end:
uDebug("processDropSTable return"); uDebug("processDropSTable return");
@ -897,10 +909,10 @@ static void processDeleteTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
RAW_NULL_CHECK(json); RAW_NULL_CHECK(json);
cJSON* type = cJSON_CreateString("delete"); cJSON* type = cJSON_CreateString("delete");
RAW_NULL_CHECK(type); RAW_NULL_CHECK(type);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
cJSON* sqlJson = cJSON_CreateString(sql); cJSON* sqlJson = cJSON_CreateString(sql);
RAW_NULL_CHECK(sqlJson); RAW_NULL_CHECK(sqlJson);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "sql", sqlJson)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "sql", sqlJson));
end: end:
uDebug("processDeleteTable return"); uDebug("processDeleteTable return");
@ -928,16 +940,17 @@ static void processDropTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
RAW_NULL_CHECK(json); RAW_NULL_CHECK(json);
cJSON* type = cJSON_CreateString("drop"); cJSON* type = cJSON_CreateString("drop");
RAW_NULL_CHECK(type); RAW_NULL_CHECK(type);
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type)); RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "type", type));
cJSON* tableNameList = cJSON_CreateArray(); cJSON* tableNameList = cJSON_CreateArray();
RAW_NULL_CHECK(tableNameList); RAW_NULL_CHECK(tableNameList);
RAW_FALSE_CHECK(tmqAddJsonObjectItem(json, "tableNameList", tableNameList));
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) { for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
SVDropTbReq* pDropTbReq = req.pReqs + iReq; SVDropTbReq* pDropTbReq = req.pReqs + iReq;
cJSON* tableName = cJSON_CreateString(pDropTbReq->name); cJSON* tableName = cJSON_CreateString(pDropTbReq->name);
RAW_NULL_CHECK(tableName); RAW_NULL_CHECK(tableName);
RAW_FALSE_CHECK(cJSON_AddItemToArray(tableNameList, tableName)); RAW_FALSE_CHECK(tmqAddJsonArrayItem(tableNameList, tableName));
} }
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableNameList", tableNameList));
end: end:
uDebug("processDropTable return"); uDebug("processDropTable return");
@ -2183,6 +2196,8 @@ static void processBatchMetaToJson(SMqBatchMetaRsp* pMsgRsp, char** string) {
RAW_FALSE_CHECK(cJSON_AddStringToObject(pJson, "tmq_meta_version", TMQ_META_VERSION)); RAW_FALSE_CHECK(cJSON_AddStringToObject(pJson, "tmq_meta_version", TMQ_META_VERSION));
cJSON* pMetaArr = cJSON_CreateArray(); cJSON* pMetaArr = cJSON_CreateArray();
RAW_NULL_CHECK(pMetaArr); RAW_NULL_CHECK(pMetaArr);
RAW_FALSE_CHECK(tmqAddJsonObjectItem(pJson, "metas", pMetaArr));
int32_t num = taosArrayGetSize(rsp.batchMetaReq); int32_t num = taosArrayGetSize(rsp.batchMetaReq);
for (int32_t i = 0; i < num; i++) { for (int32_t i = 0; i < num; i++) {
int32_t* len = taosArrayGet(rsp.batchMetaLen, i); int32_t* len = taosArrayGet(rsp.batchMetaLen, i);
@ -2198,10 +2213,9 @@ static void processBatchMetaToJson(SMqBatchMetaRsp* pMsgRsp, char** string) {
cJSON* pItem = NULL; cJSON* pItem = NULL;
processSimpleMeta(&metaRsp, &pItem); processSimpleMeta(&metaRsp, &pItem);
tDeleteMqMetaRsp(&metaRsp); tDeleteMqMetaRsp(&metaRsp);
RAW_FALSE_CHECK(cJSON_AddItemToArray(pMetaArr, pItem)); RAW_FALSE_CHECK(tmqAddJsonArrayItem(pMetaArr, pItem));
} }
RAW_FALSE_CHECK(cJSON_AddItemToObject(pJson, "metas", pMetaArr));
tDeleteMqBatchMetaRsp(&rsp); tDeleteMqBatchMetaRsp(&rsp);
char* fullStr = cJSON_PrintUnformatted(pJson); char* fullStr = cJSON_PrintUnformatted(pJson);
cJSON_Delete(pJson); cJSON_Delete(pJson);

View File

@ -797,7 +797,7 @@ static int32_t mndGetStreamNameFromSmaName(char *streamName, char *smaName) {
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
return code; return code;
} }
sprintf(streamName, "%d.%s", n.acctId, n.tname); snprintf(streamName, TSDB_TABLE_FNAME_LEN,"%d.%s", n.acctId, n.tname);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -1222,7 +1222,7 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp
memcpy(rsp->dbFName, pSma->db, sizeof(pSma->db)); memcpy(rsp->dbFName, pSma->db, sizeof(pSma->db));
memcpy(rsp->tblFName, pSma->stb, sizeof(pSma->stb)); memcpy(rsp->tblFName, pSma->stb, sizeof(pSma->stb));
strcpy(rsp->indexType, TSDB_INDEX_TYPE_SMA); tstrncpy(rsp->indexType, TSDB_INDEX_TYPE_SMA, TSDB_INDEX_TYPE_LEN);
SNodeList *pList = NULL; SNodeList *pList = NULL;
int32_t extOffset = 0; int32_t extOffset = 0;
@ -1255,8 +1255,8 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
strcpy(rsp->dbFName, pStb->db); tstrncpy(rsp->dbFName, pStb->db, TSDB_DB_FNAME_LEN);
strcpy(rsp->tbName, pStb->name + strlen(pStb->db) + 1); tstrncpy(rsp->tbName, pStb->name + strlen(pStb->db) + 1, TSDB_TABLE_NAME_LEN);
rsp->suid = pStb->uid; rsp->suid = pStb->uid;
rsp->version = pStb->smaVer; rsp->version = pStb->smaVer;
mndReleaseStb(pMnode, pStb); mndReleaseStb(pMnode, pStb);
@ -1632,7 +1632,7 @@ static int32_t mndCreateTSMABuildCreateStreamReq(SCreateTSMACxt *pCxt) {
f.bytes = pExprNode->resType.bytes; f.bytes = pExprNode->resType.bytes;
f.type = pExprNode->resType.type; f.type = pExprNode->resType.type;
f.flags = COL_SMA_ON; f.flags = COL_SMA_ON;
strcpy(f.name, pExprNode->userAlias); tstrncpy(f.name, pExprNode->userAlias, TSDB_COL_NAME_LEN);
if (NULL == taosArrayPush(pCxt->pCreateStreamReq->pCols, &f)) { if (NULL == taosArrayPush(pCxt->pCreateStreamReq->pCols, &f)) {
code = terrno; code = terrno;
break; break;
@ -1735,7 +1735,7 @@ static int32_t mndCreateTSMATxnPrepare(SCreateTSMACxt* pCxt) {
} }
dropStbReq.igNotExists = true; dropStbReq.igNotExists = true;
strncpy(dropStbReq.name, pCxt->targetStbFullName, TSDB_TABLE_FNAME_LEN); tstrncpy(dropStbReq.name, pCxt->targetStbFullName, TSDB_TABLE_FNAME_LEN);
dropStbUndoAction.epSet = createStreamRedoAction.epSet; dropStbUndoAction.epSet = createStreamRedoAction.epSet;
dropStbUndoAction.acceptableCode = TSDB_CODE_MND_STB_NOT_EXIST; dropStbUndoAction.acceptableCode = TSDB_CODE_MND_STB_NOT_EXIST;
dropStbUndoAction.retryCode = TSDB_CODE_MND_STREAM_MUST_BE_DELETED; dropStbUndoAction.retryCode = TSDB_CODE_MND_STREAM_MUST_BE_DELETED;
@ -1836,7 +1836,7 @@ static int32_t mndTSMAGenerateOutputName(const char* tsmaName, char* streamName,
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
return code; return code;
} }
sprintf(streamName, "%d.%s", smaName.acctId, smaName.tname); snprintf(streamName, TSDB_TABLE_FNAME_LEN, "%d.%s", smaName.acctId, smaName.tname);
snprintf(targetStbName, TSDB_TABLE_FNAME_LEN, "%s"TSMA_RES_STB_POSTFIX, tsmaName); snprintf(targetStbName, TSDB_TABLE_FNAME_LEN, "%s"TSMA_RES_STB_POSTFIX, tsmaName);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -2486,7 +2486,7 @@ static int32_t mndGetSomeTsmas(SMnode* pMnode, STableTSMAInfoRsp* pRsp, tsmaFilt
mndReleaseStb(pMnode, pStb); mndReleaseStb(pMnode, pStb);
TAOS_RETURN(code); TAOS_RETURN(code);
} }
sprintf(streamName, "%d.%s", smaName.acctId, smaName.tname); snprintf(streamName, TSDB_TABLE_FNAME_LEN, "%d.%s", smaName.acctId, smaName.tname);
pStream = NULL; pStream = NULL;
code = mndAcquireStream(pMnode, streamName, &pStream); code = mndAcquireStream(pMnode, streamName, &pStream);

View File

@ -1931,11 +1931,6 @@ static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChange
sdbCancelFetch(pSdb, pIter); sdbCancelFetch(pSdb, pIter);
return terrno = code; return terrno = code;
} }
code = mndStreamRegisterTrans(pTrans, MND_STREAM_TASK_UPDATE_NAME, pStream->uid);
if (code) {
mError("failed to register trans, transId:%d, and continue", pTrans->id);
}
} }
if (!includeAllNodes) { if (!includeAllNodes) {
@ -1951,6 +1946,12 @@ static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChange
mDebug("stream:0x%" PRIx64 " %s involved node changed, create update trans, transId:%d", pStream->uid, mDebug("stream:0x%" PRIx64 " %s involved node changed, create update trans, transId:%d", pStream->uid,
pStream->name, pTrans->id); pStream->name, pTrans->id);
// NOTE: for each stream, we register one trans entry for task update
code = mndStreamRegisterTrans(pTrans, MND_STREAM_TASK_UPDATE_NAME, pStream->uid);
if (code) {
mError("failed to register trans, transId:%d, and continue", pTrans->id);
}
code = mndStreamSetUpdateEpsetAction(pMnode, pStream, pChangeInfo, pTrans); code = mndStreamSetUpdateEpsetAction(pMnode, pStream, pChangeInfo, pTrans);
// todo: not continue, drop all and retry again // todo: not continue, drop all and retry again

View File

@ -35,7 +35,11 @@ int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt)
size_t keyLen = 0; size_t keyLen = 0;
void *pIter = NULL; void *pIter = NULL;
SArray *pList = taosArrayInit(4, sizeof(SKeyInfo)); SArray *pList = taosArrayInit(4, sizeof(SKeyInfo));
int32_t num = 0; int32_t numOfChkpt = 0;
if (pNumOfActiveChkpt != NULL) {
*pNumOfActiveChkpt = 0;
}
if (pList == NULL) { if (pList == NULL) {
return terrno; return terrno;
@ -50,15 +54,15 @@ int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt)
void *pKey = taosHashGetKey(pEntry, &keyLen); void *pKey = taosHashGetKey(pEntry, &keyLen);
// key is the name of src/dst db name // key is the name of src/dst db name
SKeyInfo info = {.pKey = pKey, .keyLen = keyLen}; SKeyInfo info = {.pKey = pKey, .keyLen = keyLen};
mDebug("transId:%d %s startTs:%" PRId64 " cleared since finished", pEntry->transId, pEntry->name, mDebug("transId:%d stream:0x%" PRIx64 " %s startTs:%" PRId64 " cleared since finished", pEntry->transId,
pEntry->startTime); pEntry->streamId, pEntry->name, pEntry->startTime);
void* p = taosArrayPush(pList, &info); void* p = taosArrayPush(pList, &info);
if (p == NULL) { if (p == NULL) {
return terrno; return terrno;
} }
} else { } else {
if (strcmp(pEntry->name, MND_STREAM_CHECKPOINT_NAME) == 0) { if (strcmp(pEntry->name, MND_STREAM_CHECKPOINT_NAME) == 0) {
num++; numOfChkpt++;
} }
mndReleaseTrans(pMnode, pTrans); mndReleaseTrans(pMnode, pTrans);
} }
@ -78,48 +82,34 @@ int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt)
} }
} }
mDebug("clear %d finished stream-trans, remained:%d, active checkpoint trans:%d", size, mDebug("clear %d finished stream-trans, active trans:%d, active checkpoint trans:%d", size,
taosHashGetSize(execInfo.transMgmt.pDBTrans), num); taosHashGetSize(execInfo.transMgmt.pDBTrans), numOfChkpt);
taosArrayDestroy(pList); taosArrayDestroy(pList);
if (pNumOfActiveChkpt != NULL) { if (pNumOfActiveChkpt != NULL) {
*pNumOfActiveChkpt = num; *pNumOfActiveChkpt = numOfChkpt;
} }
return 0; return 0;
} }
// * Transactions of different streams are not related. Here only check the conflict of transaction for a given stream. static int32_t doStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *pTransName) {
// For a given stream:
// 1. checkpoint trans is conflict with any other trans except for the drop and reset trans.
// 2. create/drop/reset/update trans are conflict with any other trans.
int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *pTransName, bool lock) {
if (lock) {
streamMutexLock(&execInfo.lock);
}
int32_t num = taosHashGetSize(execInfo.transMgmt.pDBTrans); int32_t num = taosHashGetSize(execInfo.transMgmt.pDBTrans);
if (num <= 0) { if (num <= 0) {
if (lock) {
streamMutexUnlock(&execInfo.lock);
}
return 0; return 0;
} }
// if any task updates exist, any other stream trans are not allowed to be created
int32_t code = mndStreamClearFinishedTrans(pMnode, NULL); int32_t code = mndStreamClearFinishedTrans(pMnode, NULL);
if (code) { if (code) {
mError("failed to clear finish trans, code:%s", tstrerror(code)); mError("failed to clear finish trans, code:%s, and continue", tstrerror(code));
} }
SStreamTransInfo *pEntry = taosHashGet(execInfo.transMgmt.pDBTrans, &streamId, sizeof(streamId)); SStreamTransInfo *pEntry = taosHashGet(execInfo.transMgmt.pDBTrans, &streamId, sizeof(streamId));
if (pEntry != NULL) { if (pEntry != NULL) {
SStreamTransInfo tInfo = *pEntry; SStreamTransInfo tInfo = *pEntry;
if (lock) {
streamMutexUnlock(&execInfo.lock);
}
if (strcmp(tInfo.name, MND_STREAM_CHECKPOINT_NAME) == 0) { if (strcmp(tInfo.name, MND_STREAM_CHECKPOINT_NAME) == 0) {
if ((strcmp(pTransName, MND_STREAM_DROP_NAME) != 0) && (strcmp(pTransName, MND_STREAM_TASK_RESET_NAME) != 0) && if ((strcmp(pTransName, MND_STREAM_DROP_NAME) != 0) && (strcmp(pTransName, MND_STREAM_TASK_RESET_NAME) != 0) &&
(strcmp(pTransName, MND_STREAM_RESTART_NAME) != 0)) { (strcmp(pTransName, MND_STREAM_RESTART_NAME) != 0)) {
@ -141,11 +131,25 @@ int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char
mDebug("stream:0x%" PRIx64 " no conflict trans existed, continue create trans", streamId); mDebug("stream:0x%" PRIx64 " no conflict trans existed, continue create trans", streamId);
} }
return TSDB_CODE_SUCCESS;
}
// * Transactions of different streams are not related. Here only check the conflict of transaction for a given stream.
// For a given stream:
// 1. checkpoint trans is conflict with any other trans except for the drop and reset trans.
// 2. create/drop/reset/update trans are conflict with any other trans.
int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *pTransName, bool lock) {
if (lock) {
streamMutexLock(&execInfo.lock);
}
int32_t code = doStreamTransConflictCheck(pMnode, streamId, pTransName);
if (lock) { if (lock) {
streamMutexUnlock(&execInfo.lock); streamMutexUnlock(&execInfo.lock);
} }
return 0; return code;
} }
int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId) { int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId) {

View File

@ -52,10 +52,17 @@ static bool mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans, bool t
static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans, bool topHalf); static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans, bool topHalf);
static bool mndTransPerformFinishStage(SMnode *pMnode, STrans *pTrans, bool topHalf); static bool mndTransPerformFinishStage(SMnode *pMnode, STrans *pTrans, bool topHalf);
static bool mndCannotExecuteTransAction(SMnode *pMnode, bool topHalf) { static inline bool mndTransIsInSyncContext(bool topHalf) { return !topHalf; }
return (!pMnode->deploy && !mndIsLeader(pMnode)) || !topHalf;
static bool mndCannotExecuteTrans(SMnode *pMnode, bool topHalf) {
bool isLeader = mndIsLeader(pMnode);
bool ret = (!pMnode->deploy && !isLeader) || mndTransIsInSyncContext(topHalf);
if (ret) mDebug("cannot execute trans action, deploy:%d, isLeader:%d, topHalf:%d", pMnode->deploy, isLeader, topHalf);
return ret;
} }
static inline char *mndStrExecutionContext(bool topHalf) { return topHalf ? "transContext" : "syncContext"; }
static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans); static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans);
static int32_t mndProcessTransTimer(SRpcMsg *pReq); static int32_t mndProcessTransTimer(SRpcMsg *pReq);
static int32_t mndProcessTtl(SRpcMsg *pReq); static int32_t mndProcessTtl(SRpcMsg *pReq);
@ -1335,7 +1342,7 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi
// execute in trans context // execute in trans context
static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) { static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction, bool topHalf) {
if (pAction->msgSent) return 0; if (pAction->msgSent) return 0;
if (mndCannotExecuteTransAction(pMnode, topHalf)) { if (mndCannotExecuteTrans(pMnode, topHalf)) {
TAOS_RETURN(TSDB_CODE_MND_TRANS_CTX_SWITCH); TAOS_RETURN(TSDB_CODE_MND_TRANS_CTX_SWITCH);
} }
@ -1481,8 +1488,8 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans, bool topHalf) { static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans, bool topHalf) {
int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->redoActions, topHalf); int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->redoActions, topHalf);
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) { if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) {
mError("trans:%d, failed to execute redoActions since:%s, code:0x%x, topHalf(TransContext):%d", pTrans->id, mError("trans:%d, failed to execute redoActions since:%s, code:0x%x, in %s", pTrans->id, terrstr(), terrno,
terrstr(), terrno, topHalf); mndStrExecutionContext(topHalf));
} }
return code; return code;
} }
@ -1490,8 +1497,8 @@ static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans, bool t
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans, bool topHalf) { static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans, bool topHalf) {
int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->undoActions, topHalf); int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->undoActions, topHalf);
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) { if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) {
mError("trans:%d, failed to execute undoActions since %s. topHalf(TransContext):%d", pTrans->id, terrstr(), mError("trans:%d, failed to execute undoActions since %s. in %s", pTrans->id, terrstr(),
topHalf); mndStrExecutionContext(topHalf));
} }
return code; return code;
} }
@ -1499,8 +1506,8 @@ static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans, bool t
static int32_t mndTransExecuteCommitActions(SMnode *pMnode, STrans *pTrans, bool topHalf) { static int32_t mndTransExecuteCommitActions(SMnode *pMnode, STrans *pTrans, bool topHalf) {
int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->commitActions, topHalf); int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->commitActions, topHalf);
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) { if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) {
mError("trans:%d, failed to execute commitActions since %s. topHalf(TransContext):%d", pTrans->id, terrstr(), mError("trans:%d, failed to execute commitActions since %s. in %s", pTrans->id, terrstr(),
topHalf); mndStrExecutionContext(topHalf));
} }
return code; return code;
} }
@ -1520,7 +1527,7 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr
for (int32_t action = pTrans->actionPos; action < numOfActions; ++action) { for (int32_t action = pTrans->actionPos; action < numOfActions; ++action) {
STransAction *pAction = taosArrayGet(pActions, action); STransAction *pAction = taosArrayGet(pActions, action);
mInfo("trans:%d, current action:%d, stage:%s, actionType(0:log,1:msg):%d", pTrans->id, pTrans->actionPos, mInfo("trans:%d, current action:%d, stage:%s, actionType(1:msg,2:log):%d", pTrans->id, pTrans->actionPos,
mndTransStr(pAction->stage), pAction->actionType); mndTransStr(pAction->stage), pAction->actionType);
code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf); code = mndTransExecSingleAction(pMnode, pTrans, pAction, topHalf);
@ -1551,11 +1558,11 @@ static int32_t mndTransExecuteActionsSerial(SMnode *pMnode, STrans *pTrans, SArr
} }
mndSetTransLastAction(pTrans, pAction); mndSetTransLastAction(pTrans, pAction);
if (mndCannotExecuteTransAction(pMnode, topHalf)) { if (mndCannotExecuteTrans(pMnode, topHalf)) {
pTrans->lastErrorNo = code; pTrans->lastErrorNo = code;
pTrans->code = code; pTrans->code = code;
mInfo("trans:%d, %s:%d, topHalf(TransContext):%d, not execute next action, code:%s", pTrans->id, mInfo("trans:%d, %s:%d, cannot execute next action in %s, code:%s", pTrans->id, mndTransStr(pAction->stage),
mndTransStr(pAction->stage), action, topHalf, tstrerror(code)); action, mndStrExecutionContext(topHalf), tstrerror(code));
break; break;
} }
@ -1656,20 +1663,21 @@ static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans, bool
code = mndTransExecuteRedoActions(pMnode, pTrans, topHalf); code = mndTransExecuteRedoActions(pMnode, pTrans, topHalf);
} }
if (mndCannotExecuteTransAction(pMnode, topHalf)) { if (code != 0 && code != TSDB_CODE_MND_TRANS_CTX_SWITCH && mndTransIsInSyncContext(topHalf)) {
pTrans->lastErrorNo = code; pTrans->lastErrorNo = code;
pTrans->code = code; pTrans->code = code;
bool continueExec = true; mInfo(
if (code != 0 && code != TSDB_CODE_MND_TRANS_CTX_SWITCH) { "trans:%d, failed to execute, will retry redo action stage in 100 ms , in %s, "
taosMsleep(100); "continueExec:%d, code:%s",
continueExec = true; pTrans->id, mndStrExecutionContext(topHalf), continueExec, tstrerror(code));
} else { taosMsleep(100);
continueExec = false; return true;
} else {
if (mndCannotExecuteTrans(pMnode, topHalf)) {
mInfo("trans:%d, cannot continue to execute redo action stage in %s, continueExec:%d, code:%s", pTrans->id,
mndStrExecutionContext(topHalf), continueExec, tstrerror(code));
return false;
} }
mInfo("trans:%d, cannot execute redo action stage, topHalf(TransContext):%d, continueExec:%d, code:%s", pTrans->id,
topHalf, continueExec, tstrerror(code));
return continueExec;
} }
terrno = code; terrno = code;
@ -1712,9 +1720,9 @@ static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans, bool
return continueExec; return continueExec;
} }
// in trans context // execute in trans context
static bool mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans, bool topHalf) { static bool mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
if (mndCannotExecuteTransAction(pMnode, topHalf)) return false; if (mndCannotExecuteTrans(pMnode, topHalf)) return false;
bool continueExec = true; bool continueExec = true;
int32_t code = mndTransCommit(pMnode, pTrans); int32_t code = mndTransCommit(pMnode, pTrans);
@ -1768,7 +1776,7 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans, bool
code = mndTransExecuteUndoActions(pMnode, pTrans, topHalf); code = mndTransExecuteUndoActions(pMnode, pTrans, topHalf);
} }
if (mndCannotExecuteTransAction(pMnode, topHalf)) return false; if (mndCannotExecuteTrans(pMnode, topHalf)) return false;
terrno = code; terrno = code;
if (code == 0) { if (code == 0) {
@ -1789,7 +1797,7 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans, bool
// in trans context // in trans context
static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans, bool topHalf) { static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
if (mndCannotExecuteTransAction(pMnode, topHalf)) return false; if (mndCannotExecuteTrans(pMnode, topHalf)) return false;
bool continueExec = true; bool continueExec = true;
int32_t code = mndTransRollback(pMnode, pTrans); int32_t code = mndTransRollback(pMnode, pTrans);
@ -1806,8 +1814,9 @@ static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans, bool to
return continueExec; return continueExec;
} }
// excute in trans context
static bool mndTransPerformPreFinishStage(SMnode *pMnode, STrans *pTrans, bool topHalf) { static bool mndTransPerformPreFinishStage(SMnode *pMnode, STrans *pTrans, bool topHalf) {
if (mndCannotExecuteTransAction(pMnode, topHalf)) return false; if (mndCannotExecuteTrans(pMnode, topHalf)) return false;
bool continueExec = true; bool continueExec = true;
int32_t code = mndTransPreFinish(pMnode, pTrans); int32_t code = mndTransPreFinish(pMnode, pTrans);
@ -1850,8 +1859,8 @@ void mndTransExecuteImp(SMnode *pMnode, STrans *pTrans, bool topHalf) {
bool continueExec = true; bool continueExec = true;
while (continueExec) { while (continueExec) {
mInfo("trans:%d, continue to execute, stage:%s createTime:%" PRId64 " topHalf(TransContext):%d", pTrans->id, mInfo("trans:%d, continue to execute stage:%s in %s, createTime:%" PRId64 "", pTrans->id,
mndTransStr(pTrans->stage), pTrans->createdTime, topHalf); mndTransStr(pTrans->stage), mndStrExecutionContext(topHalf), pTrans->createdTime);
pTrans->lastExecTime = taosGetTimestampMs(); pTrans->lastExecTime = taosGetTimestampMs();
switch (pTrans->stage) { switch (pTrans->stage) {
case TRN_STAGE_PREPARE: case TRN_STAGE_PREPARE:

View File

@ -254,11 +254,12 @@ static void tdRSmaTaskInit(SStreamMeta *pMeta, SRSmaInfoItem *pItem, SStreamTask
} }
static void tdRSmaTaskRemove(SStreamMeta *pMeta, int64_t streamId, int32_t taskId) { static void tdRSmaTaskRemove(SStreamMeta *pMeta, int64_t streamId, int32_t taskId) {
streamMetaWLock(pMeta);
int32_t code = streamMetaUnregisterTask(pMeta, streamId, taskId); int32_t code = streamMetaUnregisterTask(pMeta, streamId, taskId);
if (code != 0) { if (code != 0) {
smaError("vgId:%d, rsma task:%" PRIi64 ",%d drop failed since %s", pMeta->vgId, streamId, taskId, tstrerror(code)); smaError("vgId:%d, rsma task:%" PRIi64 ",%d drop failed since %s", pMeta->vgId, streamId, taskId, tstrerror(code));
} }
streamMetaWLock(pMeta);
int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta); int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta);
if (streamMetaCommit(pMeta) < 0) { if (streamMetaCommit(pMeta) < 0) {
// persist to disk // persist to disk

View File

@ -1122,91 +1122,76 @@ _OVER:
return code; return code;
} }
// always return success to mnode
//todo: handle failure of build and send msg to mnode
static void doSendChkptSourceRsp(SStreamCheckpointSourceReq* pReq, SRpcHandleInfo* pRpcInfo, int32_t code,
int32_t taskId) {
SRpcMsg rsp = {0};
int32_t ret = streamTaskBuildCheckpointSourceRsp(pReq, pRpcInfo, &rsp, code);
if (ret) { // suppress the error in build checkpoint source rsp
tqError("s-task:0x%x failed to build checkpoint-source rsp, code:%s", taskId, tstrerror(ret));
}
tmsgSendRsp(&rsp); // error occurs
}
// no matter what kinds of error happened, make sure the mnode will receive the success execution code. // no matter what kinds of error happened, make sure the mnode will receive the success execution code.
int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) { int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp) {
int32_t vgId = TD_VID(pTq->pVnode); int32_t vgId = TD_VID(pTq->pVnode);
SStreamMeta* pMeta = pTq->pStreamMeta; SStreamMeta* pMeta = pTq->pStreamMeta;
char* msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); char* msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
int32_t len = pMsg->contLen - sizeof(SMsgHead); int32_t len = pMsg->contLen - sizeof(SMsgHead);
int32_t code = 0; int32_t code = 0;
SStreamCheckpointSourceReq req = {0};
SDecoder decoder = {0};
SStreamTask* pTask = NULL;
int64_t checkpointId = 0;
// disable auto rsp to mnode // disable auto rsp to mnode
pRsp->info.handle = NULL; pRsp->info.handle = NULL;
SStreamCheckpointSourceReq req = {0};
SDecoder decoder;
tDecoderInit(&decoder, (uint8_t*)msg, len); tDecoderInit(&decoder, (uint8_t*)msg, len);
if (tDecodeStreamCheckpointSourceReq(&decoder, &req) < 0) { if (tDecodeStreamCheckpointSourceReq(&decoder, &req) < 0) {
code = TSDB_CODE_MSG_DECODE_ERROR; code = TSDB_CODE_MSG_DECODE_ERROR;
tDecoderClear(&decoder); tDecoderClear(&decoder);
tqError("vgId:%d failed to decode checkpoint-source msg, code:%s", vgId, tstrerror(code)); tqError("vgId:%d failed to decode checkpoint-source msg, code:%s", vgId, tstrerror(code));
doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
SRpcMsg rsp = {0}; return TSDB_CODE_SUCCESS; // always return success to mnode,
int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:0x%x failed to build checkpoint-source rsp, code:%s", req.taskId, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; // always return success to mnode, todo: handle failure of build and send msg to mnode
} }
tDecoderClear(&decoder); tDecoderClear(&decoder);
if (!vnodeIsRoleLeader(pTq->pVnode)) { if (!vnodeIsRoleLeader(pTq->pVnode)) {
tqDebug("vgId:%d not leader, ignore checkpoint-source msg, s-task:0x%x", vgId, req.taskId); tqDebug("vgId:%d not leader, ignore checkpoint-source msg, s-task:0x%x", vgId, req.taskId);
SRpcMsg rsp = {0}; doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); return TSDB_CODE_SUCCESS; // always return success to mnode
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:0x%x failed to build checkpoint-source rsp, code:%s", req.taskId, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; // always return success to mnode, todo: handle failure of build and send msg to mnode
} }
if (!pTq->pVnode->restored) { if (!pTq->pVnode->restored) {
tqDebug("vgId:%d checkpoint-source msg received during restoring, checkpointId:%" PRId64 tqDebug("vgId:%d checkpoint-source msg received during restoring, checkpointId:%" PRId64
", transId:%d s-task:0x%x ignore it", ", transId:%d s-task:0x%x ignore it",
vgId, req.checkpointId, req.transId, req.taskId); vgId, req.checkpointId, req.transId, req.taskId);
SRpcMsg rsp = {0}; doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); return TSDB_CODE_SUCCESS; // always return success to mnode
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:0x%x failed to build checkpoint-source rsp, code:%s", req.taskId, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; // always return success to mnode, , todo: handle failure of build and send msg to mnode
} }
SStreamTask* pTask = NULL;
code = streamMetaAcquireTask(pMeta, req.streamId, req.taskId, &pTask); code = streamMetaAcquireTask(pMeta, req.streamId, req.taskId, &pTask);
if (pTask == NULL || code != 0) { if (pTask == NULL || code != 0) {
tqError("vgId:%d failed to find s-task:0x%x, ignore checkpoint msg. checkpointId:%" PRId64 tqError("vgId:%d failed to find s-task:0x%x, ignore checkpoint msg. checkpointId:%" PRId64
" transId:%d it may have been destroyed", " transId:%d it may have been destroyed",
vgId, req.taskId, req.checkpointId, req.transId); vgId, req.taskId, req.checkpointId, req.transId);
SRpcMsg rsp = {0}; doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (pTask->status.downstreamReady != 1) { if (pTask->status.downstreamReady != 1) {
streamTaskSetFailedChkptInfo(pTask, req.transId, req.checkpointId); // record the latest failed checkpoint id // record the latest failed checkpoint id
streamTaskSetFailedChkptInfo(pTask, req.transId, req.checkpointId);
tqError("s-task:%s not ready for checkpoint, since downstream not ready, ignore this checkpointId:%" PRId64 tqError("s-task:%s not ready for checkpoint, since downstream not ready, ignore this checkpointId:%" PRId64
", transId:%d set it failed", ", transId:%d set it failed",
pTask->id.idStr, req.checkpointId, req.transId); pTask->id.idStr, req.checkpointId, req.transId);
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);
doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
SRpcMsg rsp = {0};
int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; // todo retry handle error return TSDB_CODE_SUCCESS; // todo retry handle error
} }
@ -1221,14 +1206,7 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
streamMutexUnlock(&pTask->lock); streamMutexUnlock(&pTask->lock);
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);
doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
SRpcMsg rsp = {0};
int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} else { } else {
@ -1240,7 +1218,6 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
// check if the checkpoint msg already sent or not. // check if the checkpoint msg already sent or not.
if (status == TASK_STATUS__CK) { if (status == TASK_STATUS__CK) {
int64_t checkpointId = 0;
streamTaskGetActiveCheckpointInfo(pTask, NULL, &checkpointId); streamTaskGetActiveCheckpointInfo(pTask, NULL, &checkpointId);
tqWarn("s-task:%s repeatly recv checkpoint-source msg checkpointId:%" PRId64 tqWarn("s-task:%s repeatly recv checkpoint-source msg checkpointId:%" PRId64
@ -1249,7 +1226,7 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
streamMutexUnlock(&pTask->lock); streamMutexUnlock(&pTask->lock);
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);
doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SYN_PROPOSE_NOT_READY, req.taskId);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { // checkpoint already finished, and not in checkpoint status } else { // checkpoint already finished, and not in checkpoint status
if (req.checkpointId <= pTask->chkInfo.checkpointId) { if (req.checkpointId <= pTask->chkInfo.checkpointId) {
@ -1259,15 +1236,7 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
streamMutexUnlock(&pTask->lock); streamMutexUnlock(&pTask->lock);
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);
doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
SRpcMsg rsp = {0};
int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} }
@ -1278,7 +1247,9 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
if (code) { if (code) {
qError("s-task:%s (vgId:%d) failed to process checkpoint-source req, code:%s", pTask->id.idStr, vgId, qError("s-task:%s (vgId:%d) failed to process checkpoint-source req, code:%s", pTask->id.idStr, vgId,
tstrerror(code)); tstrerror(code));
return code; streamMetaReleaseTask(pMeta, pTask);
doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
return TSDB_CODE_SUCCESS;
} }
if (req.mndTrigger) { if (req.mndTrigger) {
@ -1293,13 +1264,8 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
code = streamAddCheckpointSourceRspMsg(&req, &pMsg->info, pTask); code = streamAddCheckpointSourceRspMsg(&req, &pMsg->info, pTask);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
SRpcMsg rsp = {0}; streamTaskSetCheckpointFailed(pTask); // set the checkpoint failed
int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); doSendChkptSourceRsp(&req, &pMsg->info, TSDB_CODE_SUCCESS, req.taskId);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS;
} }
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);

View File

@ -13,9 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <common/tmsg.h>
#include "tcommon.h" #include "tcommon.h"
#include "tmsg.h"
#include "tq.h" #include "tq.h"
#define IS_NEW_SUBTB_RULE(_t) (((_t)->ver >= SSTREAM_TASK_SUBTABLE_CHANGED_VER) && ((_t)->subtableWithoutMd5 != 1)) #define IS_NEW_SUBTB_RULE(_t) (((_t)->ver >= SSTREAM_TASK_SUBTABLE_CHANGED_VER) && ((_t)->subtableWithoutMd5 != 1))
@ -50,7 +48,7 @@ static int32_t doPutSinkTableInfoIntoCache(SSHashObj* pSinkTableMap, STableSinkI
static bool doGetSinkTableInfoFromCache(SSHashObj* pTableInfoMap, uint64_t groupId, STableSinkInfo** pInfo); static bool doGetSinkTableInfoFromCache(SSHashObj* pTableInfoMap, uint64_t groupId, STableSinkInfo** pInfo);
static int32_t doRemoveSinkTableInfoInCache(SSHashObj* pSinkTableMap, uint64_t groupId, const char* id); static int32_t doRemoveSinkTableInfoInCache(SSHashObj* pSinkTableMap, uint64_t groupId, const char* id);
static int32_t checkTagSchema(SStreamTask* pTask, SVnode* pVnode); static int32_t checkTagSchema(SStreamTask* pTask, SVnode* pVnode);
static void reubuildAndSendMultiResBlock(SStreamTask* pTask, const SArray* pBlocks, SVnode* pVnode, int64_t earlyTs); static void rebuildAndSendMultiResBlock(SStreamTask* pTask, const SArray* pBlocks, SVnode* pVnode, int64_t earlyTs);
static int32_t handleResultBlockMsg(SStreamTask* pTask, SSDataBlock* pDataBlock, int32_t index, SVnode* pVnode, static int32_t handleResultBlockMsg(SStreamTask* pTask, SSDataBlock* pDataBlock, int32_t index, SVnode* pVnode,
int64_t earlyTs); int64_t earlyTs);
static int32_t doWaitForDstTableDropped(SVnode* pVnode, SStreamTask* pTask, const char* dstTableName); static int32_t doWaitForDstTableDropped(SVnode* pVnode, SStreamTask* pTask, const char* dstTableName);
@ -1187,7 +1185,7 @@ void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data) {
return; return;
} }
reubuildAndSendMultiResBlock(pTask, pBlocks, pVnode, earlyTs); rebuildAndSendMultiResBlock(pTask, pBlocks, pVnode, earlyTs);
} }
} }
@ -1290,7 +1288,7 @@ int32_t doBuildAndSendDeleteMsg(SVnode* pVnode, char* stbFullName, SSDataBlock*
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void reubuildAndSendMultiResBlock(SStreamTask* pTask, const SArray* pBlocks, SVnode* pVnode, int64_t earlyTs) { void rebuildAndSendMultiResBlock(SStreamTask* pTask, const SArray* pBlocks, SVnode* pVnode, int64_t earlyTs) {
int32_t code = 0; int32_t code = 0;
const char* id = pTask->id.idStr; const char* id = pTask->id.idStr;
int32_t vgId = pTask->pMeta->vgId; int32_t vgId = pTask->pMeta->vgId;

View File

@ -17,19 +17,20 @@
#include "vnd.h" #include "vnd.h"
#define MAX_REPEAT_SCAN_THRESHOLD 3 #define MAX_REPEAT_SCAN_THRESHOLD 3
#define SCAN_WAL_IDLE_DURATION 100 #define SCAN_WAL_IDLE_DURATION 500 // idle for 500ms to do next wal scan
typedef struct SBuildScanWalMsgParam { typedef struct SBuildScanWalMsgParam {
int64_t metaId; int64_t metaId;
int32_t numOfTasks; int32_t numOfTasks;
} SBuildScanWalMsgParam; } SBuildScanWalMsgParam;
static int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle); static int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta);
static int32_t setWalReaderStartOffset(SStreamTask* pTask, int32_t vgId); static int32_t setWalReaderStartOffset(SStreamTask* pTask, int32_t vgId);
static bool handleFillhistoryScanComplete(SStreamTask* pTask, int64_t ver); static bool handleFillhistoryScanComplete(SStreamTask* pTask, int64_t ver);
static bool taskReadyForDataFromWal(SStreamTask* pTask); static bool taskReadyForDataFromWal(SStreamTask* pTask);
static int32_t doPutDataIntoInputQ(SStreamTask* pTask, int64_t maxVer, int32_t* numOfItems, bool* pSucc); static int32_t doPutDataIntoInputQ(SStreamTask* pTask, int64_t maxVer, int32_t* numOfItems, bool* pSucc);
static int32_t tqScanWalInFuture(STQ* pTq, int32_t numOfTasks, int32_t idleDuration); static int32_t tqScanWalInFuture(STQ* pTq, int32_t numOfTasks, int32_t idleDuration);
static int32_t doScanWalAsync(STQ* pTq, bool ckPause);
// extract data blocks(submit/delete) from WAL, and add them into the input queue for all the sources tasks. // extract data blocks(submit/delete) from WAL, and add them into the input queue for all the sources tasks.
int32_t tqScanWal(STQ* pTq) { int32_t tqScanWal(STQ* pTq) {
@ -37,12 +38,11 @@ int32_t tqScanWal(STQ* pTq) {
int32_t vgId = pMeta->vgId; int32_t vgId = pMeta->vgId;
int64_t st = taosGetTimestampMs(); int64_t st = taosGetTimestampMs();
int32_t numOfTasks = 0; int32_t numOfTasks = 0;
bool shouldIdle = true;
tqDebug("vgId:%d continue to check if data in wal are available, scanCounter:%d", vgId, pMeta->scanInfo.scanCounter); tqDebug("vgId:%d continue to check if data in wal are available, scanCounter:%d", vgId, pMeta->scanInfo.scanCounter);
// check all tasks // check all tasks
int32_t code = doScanWalForAllTasks(pMeta, &shouldIdle); int32_t code = doScanWalForAllTasks(pMeta);
if (code) { if (code) {
tqError("vgId:%d failed to start all tasks, try next time, code:%s", vgId, tstrerror(code)); tqError("vgId:%d failed to start all tasks, try next time, code:%s", vgId, tstrerror(code));
return code; return code;
@ -133,10 +133,9 @@ int32_t tqScanWalInFuture(STQ* pTq, int32_t numOfTasks, int32_t idleDuration) {
} }
int32_t tqScanWalAsync(STQ* pTq, bool ckPause) { int32_t tqScanWalAsync(STQ* pTq, bool ckPause) {
int32_t vgId = TD_VID(pTq->pVnode);
SStreamMeta* pMeta = pTq->pStreamMeta; SStreamMeta* pMeta = pTq->pStreamMeta;
bool alreadyRestored = pTq->pVnode->restored; bool alreadyRestored = pTq->pVnode->restored;
int32_t numOfTasks = 0; int32_t code = 0;
// do not launch the stream tasks, if it is a follower or not restored vnode. // do not launch the stream tasks, if it is a follower or not restored vnode.
if (!(vnodeIsRoleLeader(pTq->pVnode) && alreadyRestored)) { if (!(vnodeIsRoleLeader(pTq->pVnode) && alreadyRestored)) {
@ -144,47 +143,8 @@ int32_t tqScanWalAsync(STQ* pTq, bool ckPause) {
} }
streamMetaWLock(pMeta); streamMetaWLock(pMeta);
code = doScanWalAsync(pTq, ckPause);
numOfTasks = taosArrayGetSize(pMeta->pTaskList);
if (numOfTasks == 0) {
tqDebug("vgId:%d no stream tasks existed to run", vgId);
streamMetaWUnLock(pMeta);
return 0;
}
if (pMeta->startInfo.startAllTasks) {
tqTrace("vgId:%d in restart procedure, not scan wal", vgId);
streamMetaWUnLock(pMeta);
return 0;
}
pMeta->scanInfo.scanCounter += 1;
if (pMeta->scanInfo.scanCounter > MAX_REPEAT_SCAN_THRESHOLD) {
pMeta->scanInfo.scanCounter = MAX_REPEAT_SCAN_THRESHOLD;
}
if (pMeta->scanInfo.scanCounter > 1) {
tqDebug("vgId:%d wal read task has been launched, remain scan times:%d", vgId, pMeta->scanInfo.scanCounter);
streamMetaWUnLock(pMeta);
return 0;
}
int32_t numOfPauseTasks = pMeta->numOfPausedTasks;
if (ckPause && numOfTasks == numOfPauseTasks) {
tqDebug("vgId:%d ignore all submit, all streams had been paused, reset the walScanCounter", vgId);
// reset the counter value, since we do not launch the scan wal operation.
pMeta->scanInfo.scanCounter = 0;
streamMetaWUnLock(pMeta);
return 0;
}
tqDebug("vgId:%d create msg to start wal scan to launch stream tasks, numOfTasks:%d, vnd restored:%d", vgId,
numOfTasks, alreadyRestored);
int32_t code = streamTaskSchedTask(&pTq->pVnode->msgCb, vgId, 0, 0, STREAM_EXEC_T_EXTRACT_WAL_DATA);
streamMetaWUnLock(pMeta); streamMetaWUnLock(pMeta);
return code; return code;
} }
@ -368,11 +328,8 @@ int32_t doPutDataIntoInputQ(SStreamTask* pTask, int64_t maxVer, int32_t* numOfIt
return code; return code;
} }
int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle) { int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta) {
*pScanIdle = true;
bool noDataInWal = true;
int32_t vgId = pStreamMeta->vgId; int32_t vgId = pStreamMeta->vgId;
int32_t numOfTasks = taosArrayGetSize(pStreamMeta->pTaskList); int32_t numOfTasks = taosArrayGetSize(pStreamMeta->pTaskList);
if (numOfTasks == 0) { if (numOfTasks == 0) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -410,8 +367,6 @@ int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle) {
continue; continue;
} }
*pScanIdle = false;
// seek the stored version and extract data from WAL // seek the stored version and extract data from WAL
code = setWalReaderStartOffset(pTask, vgId); code = setWalReaderStartOffset(pTask, vgId);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
@ -437,7 +392,6 @@ int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle) {
streamMutexUnlock(&pTask->lock); streamMutexUnlock(&pTask->lock);
if ((numOfItems > 0) || hasNewData) { if ((numOfItems > 0) || hasNewData) {
noDataInWal = false;
code = streamTrySchedExec(pTask); code = streamTrySchedExec(pTask);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
streamMetaReleaseTask(pStreamMeta, pTask); streamMetaReleaseTask(pStreamMeta, pTask);
@ -449,11 +403,47 @@ int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle) {
streamMetaReleaseTask(pStreamMeta, pTask); streamMetaReleaseTask(pStreamMeta, pTask);
} }
// all wal are checked, and no new data available in wal.
if (noDataInWal) {
*pScanIdle = true;
}
taosArrayDestroy(pTaskList); taosArrayDestroy(pTaskList);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t doScanWalAsync(STQ* pTq, bool ckPause) {
SStreamMeta* pMeta = pTq->pStreamMeta;
bool alreadyRestored = pTq->pVnode->restored;
int32_t vgId = pMeta->vgId;
int32_t numOfTasks = taosArrayGetSize(pMeta->pTaskList);
if (numOfTasks == 0) {
tqDebug("vgId:%d no stream tasks existed to run", vgId);
return 0;
}
if (pMeta->startInfo.startAllTasks) {
tqTrace("vgId:%d in restart procedure, not scan wal", vgId);
return 0;
}
pMeta->scanInfo.scanCounter += 1;
if (pMeta->scanInfo.scanCounter > MAX_REPEAT_SCAN_THRESHOLD) {
pMeta->scanInfo.scanCounter = MAX_REPEAT_SCAN_THRESHOLD;
}
if (pMeta->scanInfo.scanCounter > 1) {
tqDebug("vgId:%d wal read task has been launched, remain scan times:%d", vgId, pMeta->scanInfo.scanCounter);
return 0;
}
int32_t numOfPauseTasks = pMeta->numOfPausedTasks;
if (ckPause && numOfTasks == numOfPauseTasks) {
tqDebug("vgId:%d ignore all submit, all streams had been paused, reset the walScanCounter", vgId);
// reset the counter value, since we do not launch the scan wal operation.
pMeta->scanInfo.scanCounter = 0;
return 0;
}
tqDebug("vgId:%d create msg to start wal scan to launch stream tasks, numOfTasks:%d, vnd restored:%d", vgId,
numOfTasks, alreadyRestored);
return streamTaskSchedTask(&pTq->pVnode->msgCb, vgId, 0, 0, STREAM_EXEC_T_EXTRACT_WAL_DATA);
}

View File

@ -718,8 +718,6 @@ int32_t tqStreamTaskProcessDropReq(SStreamMeta* pMeta, char* msg, int32_t msgLen
} }
} }
streamMetaWUnLock(pMeta);
// drop the related fill-history task firstly // drop the related fill-history task firstly
if (hTaskId.taskId != 0 && hTaskId.streamId != 0) { if (hTaskId.taskId != 0 && hTaskId.streamId != 0) {
tqDebug("s-task:0x%x vgId:%d drop rel fill-history task:0x%x firstly", pReq->taskId, vgId, (int32_t)hTaskId.taskId); tqDebug("s-task:0x%x vgId:%d drop rel fill-history task:0x%x firstly", pReq->taskId, vgId, (int32_t)hTaskId.taskId);
@ -737,7 +735,6 @@ int32_t tqStreamTaskProcessDropReq(SStreamMeta* pMeta, char* msg, int32_t msgLen
} }
// commit the update // commit the update
streamMetaWLock(pMeta);
int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta); int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta);
tqDebug("vgId:%d task:0x%x dropped, remain tasks:%d", vgId, pReq->taskId, numOfTasks); tqDebug("vgId:%d task:0x%x dropped, remain tasks:%d", vgId, pReq->taskId, numOfTasks);

View File

@ -977,6 +977,11 @@ void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
extern int32_t vnodeAsyncRetention(SVnode *pVnode, int64_t now); extern int32_t vnodeAsyncRetention(SVnode *pVnode, int64_t now);
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
if (!pVnode->restored) {
vInfo("vgId:%d, ignore trim req during restoring. ver:%" PRId64, TD_VID(pVnode), ver);
return 0;
}
int32_t code = 0; int32_t code = 0;
SVTrimDbReq trimReq = {0}; SVTrimDbReq trimReq = {0};

View File

@ -987,7 +987,14 @@ _end:
} }
void resetStreamFillSup(SStreamFillSupporter* pFillSup) { void resetStreamFillSup(SStreamFillSupporter* pFillSup) {
tSimpleHashClear(pFillSup->pResMap); _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
SSHashObj* pNewMap = tSimpleHashInit(16, hashFn);
if (pNewMap != NULL) {
tSimpleHashCleanup(pFillSup->pResMap);
pFillSup->pResMap = pNewMap;
} else {
tSimpleHashClear(pFillSup->pResMap);
}
pFillSup->hasDelete = false; pFillSup->hasDelete = false;
} }
void resetStreamFillInfo(SStreamFillOperatorInfo* pInfo) { void resetStreamFillInfo(SStreamFillOperatorInfo* pInfo) {
@ -1406,6 +1413,7 @@ static int32_t doStreamForceFillNext(SOperatorInfo* pOperator, SSDataBlock** ppR
} }
pInfo->stateStore.streamStateClearExpiredState(pInfo->pState); pInfo->stateStore.streamStateClearExpiredState(pInfo->pState);
resetStreamFillInfo(pInfo);
setStreamOperatorCompleted(pOperator); setStreamOperatorCompleted(pOperator);
(*ppRes) = NULL; (*ppRes) = NULL;
goto _end; goto _end;
@ -1477,6 +1485,7 @@ static int32_t doStreamForceFillNext(SOperatorInfo* pOperator, SSDataBlock** ppR
if ((*ppRes) == NULL) { if ((*ppRes) == NULL) {
pInfo->stateStore.streamStateClearExpiredState(pInfo->pState); pInfo->stateStore.streamStateClearExpiredState(pInfo->pState);
resetStreamFillInfo(pInfo);
setStreamOperatorCompleted(pOperator); setStreamOperatorCompleted(pOperator);
} }

View File

@ -120,6 +120,36 @@ void initIntervalSlicePoint(SStreamAggSupporter* pAggSup, STimeWindow* pTWin, in
pPoint->pLastRow = POINTER_SHIFT(pPoint->pFinished, sizeof(bool)); pPoint->pLastRow = POINTER_SHIFT(pPoint->pFinished, sizeof(bool));
} }
int32_t getIntervalSlicePrevStateBuf(SStreamAggSupporter* pAggSup, SInterval* pInterval, SWinKey* pCurKey,
SInervalSlicePoint* pPrevPoint) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
SWinKey prevKey = {.groupId = pCurKey->groupId};
SET_WIN_KEY_INVALID(prevKey.ts);
int32_t prevVLen = 0;
int32_t prevWinCode = TSDB_CODE_SUCCESS;
code = pAggSup->stateStore.streamStateGetPrev(pAggSup->pState, pCurKey, &prevKey, (void**)&pPrevPoint->pResPos,
&prevVLen, &prevWinCode);
QUERY_CHECK_CODE(code, lino, _end);
if (prevWinCode == TSDB_CODE_SUCCESS) {
STimeWindow prevSTW = {.skey = prevKey.ts};
prevSTW.ekey = taosTimeGetIntervalEnd(prevSTW.skey, pInterval);
initIntervalSlicePoint(pAggSup, &prevSTW, pCurKey->groupId, pPrevPoint);
qDebug("===stream=== set stream twa prev point buf.ts:%" PRId64 ", groupId:%" PRIu64 ", res:%d",
pPrevPoint->winKey.win.skey, pPrevPoint->winKey.groupId, prevWinCode);
} else {
SET_WIN_KEY_INVALID(pPrevPoint->winKey.win.skey);
SET_WIN_KEY_INVALID(pPrevPoint->winKey.win.ekey);
}
_end:
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
}
return code;
}
static int32_t getIntervalSliceCurStateBuf(SStreamAggSupporter* pAggSup, SInterval* pInterval, bool needPrev, STimeWindow* pTWin, int64_t groupId, static int32_t getIntervalSliceCurStateBuf(SStreamAggSupporter* pAggSup, SInterval* pInterval, bool needPrev, STimeWindow* pTWin, int64_t groupId,
SInervalSlicePoint* pCurPoint, SInervalSlicePoint* pPrevPoint, int32_t* pWinCode) { SInervalSlicePoint* pCurPoint, SInervalSlicePoint* pPrevPoint, int32_t* pWinCode) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
@ -136,24 +166,8 @@ static int32_t getIntervalSliceCurStateBuf(SStreamAggSupporter* pAggSup, SInterv
initIntervalSlicePoint(pAggSup, pTWin, groupId, pCurPoint); initIntervalSlicePoint(pAggSup, pTWin, groupId, pCurPoint);
if (needPrev) { if (needPrev) {
SWinKey prevKey = {.groupId = groupId}; code = getIntervalSlicePrevStateBuf(pAggSup, pInterval, &curKey, pPrevPoint);
SET_WIN_KEY_INVALID(prevKey.ts);
int32_t prevVLen = 0;
int32_t prevWinCode = TSDB_CODE_SUCCESS;
code = pAggSup->stateStore.streamStateGetPrev(pAggSup->pState, &curKey, &prevKey, (void**)&pPrevPoint->pResPos,
&prevVLen, &prevWinCode);
QUERY_CHECK_CODE(code, lino, _end); QUERY_CHECK_CODE(code, lino, _end);
if (prevWinCode == TSDB_CODE_SUCCESS) {
STimeWindow prevSTW = {.skey = prevKey.ts};
prevSTW.ekey = taosTimeGetIntervalEnd(prevSTW.skey, pInterval);
initIntervalSlicePoint(pAggSup, &prevSTW, groupId, pPrevPoint);
qDebug("===stream=== set stream twa prev point buf.ts:%" PRId64 ", groupId:%" PRIu64 ", res:%d", pPrevPoint->winKey.win.skey,
pPrevPoint->winKey.groupId, prevWinCode);
} else {
SET_WIN_KEY_INVALID(pPrevPoint->winKey.win.skey);
SET_WIN_KEY_INVALID(pPrevPoint->winKey.win.ekey);
}
} }
_end: _end:
@ -265,13 +279,15 @@ static int32_t doStreamIntervalSliceAggImpl(SOperatorInfo* pOperator, SSDataBloc
STimeWindow curWin = STimeWindow curWin =
getActiveTimeWindow(NULL, pResultRowInfo, curTs, &pInfo->interval, TSDB_ORDER_ASC); getActiveTimeWindow(NULL, pResultRowInfo, curTs, &pInfo->interval, TSDB_ORDER_ASC);
while (1) { while (1) {
if (curTs > pInfo->endTs) {
break;
}
int32_t winCode = TSDB_CODE_SUCCESS; int32_t winCode = TSDB_CODE_SUCCESS;
code = getIntervalSliceCurStateBuf(&pInfo->streamAggSup, &pInfo->interval, pInfo->hasInterpoFunc, &curWin, groupId, &curPoint, &prevPoint, &winCode); if (curTs <= pInfo->endTs) {
QUERY_CHECK_CODE(code, lino, _end); code = getIntervalSliceCurStateBuf(&pInfo->streamAggSup, &pInfo->interval, pInfo->hasInterpoFunc, &curWin, groupId, &curPoint, &prevPoint, &winCode);
QUERY_CHECK_CODE(code, lino, _end);
} else if (pInfo->hasInterpoFunc) {
SWinKey curKey = {.ts = curWin.skey, .groupId = groupId};
code = getIntervalSlicePrevStateBuf(&pInfo->streamAggSup, &pInfo->interval, &curKey, &prevPoint);
QUERY_CHECK_CODE(code, lino, _end);
}
if (pInfo->hasInterpoFunc && IS_VALID_WIN_KEY(prevPoint.winKey.win.skey) && isInterpoWindowFinished(&prevPoint) == false) { if (pInfo->hasInterpoFunc && IS_VALID_WIN_KEY(prevPoint.winKey.win.skey) && isInterpoWindowFinished(&prevPoint) == false) {
code = setIntervalSliceOutputBuf(&prevPoint, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset); code = setIntervalSliceOutputBuf(&prevPoint, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset);
@ -288,6 +304,12 @@ static int32_t doStreamIntervalSliceAggImpl(SOperatorInfo* pOperator, SSDataBloc
code = saveWinResult(&prevKey, prevPoint.pResPos, pInfo->pUpdatedMap); code = saveWinResult(&prevKey, prevPoint.pResPos, pInfo->pUpdatedMap);
QUERY_CHECK_CODE(code, lino, _end); QUERY_CHECK_CODE(code, lino, _end);
setInterpoWindowFinished(&prevPoint); setInterpoWindowFinished(&prevPoint);
} else if (IS_VALID_WIN_KEY(prevPoint.winKey.win.skey)) {
releaseOutputBuf(pInfo->streamAggSup.pState, prevPoint.pResPos, &pInfo->streamAggSup.stateStore);
}
if (curTs > pInfo->endTs) {
break;
} }
code = setIntervalSliceOutputBuf(&curPoint, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset); code = setIntervalSliceOutputBuf(&curPoint, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset);
@ -300,7 +322,7 @@ static int32_t doStreamIntervalSliceAggImpl(SOperatorInfo* pOperator, SSDataBloc
forwardRows = getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, curWin.ekey, binarySearchForKey, NULL, forwardRows = getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, curWin.ekey, binarySearchForKey, NULL,
TSDB_ORDER_ASC); TSDB_ORDER_ASC);
int32_t prevEndPos = (forwardRows - 1) + startPos; int32_t prevEndPos = (forwardRows - 1) + startPos;
if (pInfo->hasInterpoFunc && winCode != TSDB_CODE_SUCCESS) { if (pInfo->hasInterpoFunc) {
int32_t endRowId = getQualifiedRowNumDesc(pSup, pBlock, tsCols, prevEndPos, false); int32_t endRowId = getQualifiedRowNumDesc(pSup, pBlock, tsCols, prevEndPos, false);
TSKEY endRowTs = tsCols[endRowId]; TSKEY endRowTs = tsCols[endRowId];
transBlockToSliceResultRow(pBlock, endRowId, endRowTs, curPoint.pLastRow, 0, NULL, NULL, pInfo->pOffsetInfo); transBlockToSliceResultRow(pBlock, endRowId, endRowTs, curPoint.pLastRow, 0, NULL, NULL, pInfo->pOffsetInfo);

View File

@ -4952,7 +4952,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.paramInfoPattern = 0, .paramInfoPattern = 0,
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_ALL_TYPE}}, .outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_ALL_TYPE}},
.translateFunc = translateSelectValue, .translateFunc = translateSelectValue,
.getEnvFunc = getSelectivityFuncEnv, .getEnvFunc = getGroupKeyFuncEnv,
.initFunc = functionSetup, .initFunc = functionSetup,
.processFunc = groupConstValueFunction, .processFunc = groupConstValueFunction,
.finalizeFunc = groupConstValueFinalize, .finalizeFunc = groupConstValueFinalize,

View File

@ -26,9 +26,9 @@
(pDst)->fldname = (pSrc)->fldname; \ (pDst)->fldname = (pSrc)->fldname; \
} while (0) } while (0)
#define COPY_CHAR_ARRAY_FIELD(fldname) \ #define COPY_CHAR_ARRAY_FIELD(fldname) \
do { \ do { \
strcpy((pDst)->fldname, (pSrc)->fldname); \ tstrncpy((pDst)->fldname, (pSrc)->fldname, sizeof((pDst)->fldname)); \
} while (0) } while (0)
#define COPY_OBJECT_FIELD(fldname, size) \ #define COPY_OBJECT_FIELD(fldname, size) \

View File

@ -2341,7 +2341,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) {
return NULL; return NULL;
} }
sprintf(buf, "%s", pNode->datum.b ? "true" : "false"); snprintf(buf, MAX_NUM_STR_SIZE, "%s", pNode->datum.b ? "true" : "false");
return buf; return buf;
} }
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
@ -2354,7 +2354,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) {
return NULL; return NULL;
} }
sprintf(buf, "%" PRId64, pNode->datum.i); snprintf(buf, MAX_NUM_STR_SIZE, "%" PRId64, pNode->datum.i);
return buf; return buf;
} }
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
@ -2366,7 +2366,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) {
return NULL; return NULL;
} }
sprintf(buf, "%" PRIu64, pNode->datum.u); snprintf(buf, MAX_NUM_STR_SIZE, "%" PRIu64, pNode->datum.u);
return buf; return buf;
} }
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
@ -2376,7 +2376,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) {
return NULL; return NULL;
} }
sprintf(buf, "%e", pNode->datum.d); snprintf(buf, MAX_NUM_STR_SIZE, "%e", pNode->datum.d);
return buf; return buf;
} }
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
@ -2532,7 +2532,7 @@ static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pN
} }
if (pCol->projRefIdx > 0) { if (pCol->projRefIdx > 0) {
len = taosHashBinary(name, strlen(name)); len = taosHashBinary(name, strlen(name));
len += sprintf(name + len, "_%d", pCol->projRefIdx); len += tsnprintf(name + len, TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN - len, "_%d", pCol->projRefIdx);
} }
SNode** pNodeFound = taosHashGet(pCxt->pColHash, name, len); SNode** pNodeFound = taosHashGet(pCxt->pColHash, name, len);
if (pNodeFound == NULL) { if (pNodeFound == NULL) {
@ -2952,17 +2952,16 @@ int32_t nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARCHAR:
case TSDB_DATA_TYPE_VARBINARY: case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_GEOMETRY: case TSDB_DATA_TYPE_GEOMETRY:
pVal->pz = taosMemoryMalloc(pVal->nLen + 1); pVal->pz = taosMemoryCalloc(1, pVal->nLen + 1);
if (pVal->pz) { if (pVal->pz) {
memcpy(pVal->pz, pNode->datum.p, pVal->nLen); memcpy(pVal->pz, pNode->datum.p, varDataTLen(pNode->datum.p));
pVal->pz[pVal->nLen] = 0;
} else { } else {
code = terrno; code = terrno;
} }
break; break;
case TSDB_DATA_TYPE_JSON: case TSDB_DATA_TYPE_JSON:
pVal->nLen = getJsonValueLen(pNode->datum.p); pVal->nLen = getJsonValueLen(pNode->datum.p);
pVal->pz = taosMemoryMalloc(pVal->nLen); pVal->pz = taosMemoryCalloc(1, pVal->nLen);
if (pVal->pz) { if (pVal->pz) {
memcpy(pVal->pz, pNode->datum.p, pVal->nLen); memcpy(pVal->pz, pNode->datum.p, pVal->nLen);
} else { } else {

View File

@ -142,13 +142,13 @@ static int32_t parseEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* p
(void)strdequote(ep); (void)strdequote(ep);
(void)strtrim(ep); (void)strtrim(ep);
if (NULL == pPort) { if (NULL == pPort) {
strcpy(pFqdn, ep); tstrncpy(pFqdn, ep, TSDB_FQDN_LEN);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
char* pColon = strchr(ep, ':'); char* pColon = strchr(ep, ':');
if (NULL == pColon) { if (NULL == pColon) {
*pPort = tsServerPort; *pPort = tsServerPort;
strcpy(pFqdn, ep); tstrncpy(pFqdn, ep, TSDB_FQDN_LEN);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
strncpy(pFqdn, ep, pColon - ep); strncpy(pFqdn, ep, pColon - ep);
@ -320,12 +320,12 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
if (nodesIsExprNode(pRealizedExpr)) { if (nodesIsExprNode(pRealizedExpr)) {
SExprNode* pExpr = (SExprNode*)pRealizedExpr; SExprNode* pExpr = (SExprNode*)pRealizedExpr;
if (QUERY_NODE_COLUMN == nodeType(pExpr)) { if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
strcpy(pExpr->aliasName, ((SColumnNode*)pExpr)->colName); tstrncpy(pExpr->aliasName, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
strcpy(pExpr->userAlias, ((SColumnNode*)pExpr)->colName); tstrncpy(pExpr->userAlias, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
} else if (pRawExpr->isPseudoColumn) { } else if (pRawExpr->isPseudoColumn) {
// all pseudo column are translate to function with same name // all pseudo column are translate to function with same name
strcpy(pExpr->userAlias, ((SFunctionNode*)pExpr)->functionName); tstrncpy(pExpr->userAlias, ((SFunctionNode*)pExpr)->functionName, TSDB_COL_NAME_LEN);
strcpy(pExpr->aliasName, ((SFunctionNode*)pExpr)->functionName); tstrncpy(pExpr->aliasName, ((SFunctionNode*)pExpr)->functionName, TSDB_COL_NAME_LEN);
} else { } else {
int32_t len = TMIN(sizeof(pExpr->aliasName) - 1, pRawExpr->n); int32_t len = TMIN(sizeof(pExpr->aliasName) - 1, pRawExpr->n);
@ -333,9 +333,9 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
// Len of pRawExpr->p could be larger than len of aliasName[TSDB_COL_NAME_LEN]. // Len of pRawExpr->p could be larger than len of aliasName[TSDB_COL_NAME_LEN].
// If aliasName is truncated, hash value of aliasName could be the same. // If aliasName is truncated, hash value of aliasName could be the same.
uint64_t hashVal = MurmurHash3_64(pRawExpr->p, pRawExpr->n); uint64_t hashVal = MurmurHash3_64(pRawExpr->p, pRawExpr->n);
sprintf(pExpr->aliasName, "%" PRIu64, hashVal); snprintf(pExpr->aliasName, TSDB_COL_NAME_LEN, "%" PRIu64, hashVal);
strncpy(pExpr->userAlias, pRawExpr->p, len); strncpy(pExpr->userAlias, pRawExpr->p, len);
pExpr->userAlias[len] = '\0'; pExpr->userAlias[len] = 0;
} }
} }
pRawExpr->pNode = NULL; pRawExpr->pNode = NULL;
@ -948,11 +948,11 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
goto _err; goto _err;
} }
if ('+' == pVal->literal[0]) { if ('+' == pVal->literal[0]) {
sprintf(pNewLiteral, "-%s", pVal->literal + 1); snprintf(pNewLiteral, strlen(pVal->literal) + 2, "-%s", pVal->literal + 1);
} else if ('-' == pVal->literal[0]) { } else if ('-' == pVal->literal[0]) {
sprintf(pNewLiteral, "%s", pVal->literal + 1); snprintf(pNewLiteral, strlen(pVal->literal) + 2, "%s", pVal->literal + 1);
} else { } else {
sprintf(pNewLiteral, "-%s", pVal->literal); snprintf(pNewLiteral, strlen(pVal->literal) + 2, "-%s", pVal->literal);
} }
taosMemoryFree(pVal->literal); taosMemoryFree(pVal->literal);
pVal->literal = pNewLiteral; pVal->literal = pNewLiteral;
@ -1025,7 +1025,7 @@ static SNode* createPrimaryKeyCol(SAstCreateContext* pCxt, const SToken* pFuncNa
CHECK_MAKE_NODE(pCol); CHECK_MAKE_NODE(pCol);
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID; pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
if (NULL == pFuncName) { if (NULL == pFuncName) {
strcpy(pCol->colName, ROWTS_PSEUDO_COLUMN_NAME); tstrncpy(pCol->colName, ROWTS_PSEUDO_COLUMN_NAME, TSDB_COL_NAME_LEN);
} else { } else {
strncpy(pCol->colName, pFuncName->z, pFuncName->n); strncpy(pCol->colName, pFuncName->z, pFuncName->n);
} }
@ -1058,7 +1058,7 @@ SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType d
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func); pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func); CHECK_MAKE_NODE(func);
strcpy(func->functionName, "cast"); tstrncpy(func->functionName, "cast", TSDB_FUNC_NAME_LEN);
func->node.resType = dt; func->node.resType = dt;
if (TSDB_DATA_TYPE_VARCHAR == dt.type || TSDB_DATA_TYPE_GEOMETRY == dt.type || TSDB_DATA_TYPE_VARBINARY == dt.type) { if (TSDB_DATA_TYPE_VARCHAR == dt.type || TSDB_DATA_TYPE_GEOMETRY == dt.type || TSDB_DATA_TYPE_VARBINARY == dt.type) {
func->node.resType.bytes = func->node.resType.bytes + VARSTR_HEADER_SIZE; func->node.resType.bytes = func->node.resType.bytes + VARSTR_HEADER_SIZE;
@ -1082,7 +1082,7 @@ SNode* createPositionFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SNode*
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func); pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func); CHECK_MAKE_NODE(func);
strcpy(func->functionName, "position"); tstrncpy(func->functionName, "position", TSDB_FUNC_NAME_LEN);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr); pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2); pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
@ -1100,7 +1100,7 @@ SNode* createTrimFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, ETrimType t
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func); pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func); CHECK_MAKE_NODE(func);
strcpy(func->functionName, "trim"); tstrncpy(func->functionName, "trim", TSDB_FUNC_NAME_LEN);
func->trimType = type; func->trimType = type;
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr); pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
@ -1117,7 +1117,7 @@ SNode* createTrimFunctionNodeExt(SAstCreateContext* pCxt, SNode* pExpr, SNode* p
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func); pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func); CHECK_MAKE_NODE(func);
strcpy(func->functionName, "trim"); tstrncpy(func->functionName, "trim", TSDB_FUNC_NAME_LEN);
func->trimType = type; func->trimType = type;
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr); pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
@ -1137,7 +1137,7 @@ SNode* createSubstrFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SNode* pE
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func); pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func); CHECK_MAKE_NODE(func);
strcpy(func->functionName, "substr"); tstrncpy(func->functionName, "substr", TSDB_FUNC_NAME_LEN);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr); pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2); pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
@ -1155,7 +1155,7 @@ SNode* createSubstrFunctionNodeExt(SAstCreateContext* pCxt, SNode* pExpr, SNode*
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func); pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&func);
CHECK_MAKE_NODE(func); CHECK_MAKE_NODE(func);
strcpy(func->functionName, "substr"); tstrncpy(func->functionName, "substr", TSDB_FUNC_NAME_LEN);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr); pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2); pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr2);
@ -1239,10 +1239,10 @@ SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, SToken* pT
taosRandStr(tempTable->table.tableAlias, 8); taosRandStr(tempTable->table.tableAlias, 8);
} }
if (QUERY_NODE_SELECT_STMT == nodeType(pSubquery)) { if (QUERY_NODE_SELECT_STMT == nodeType(pSubquery)) {
strcpy(((SSelectStmt*)pSubquery)->stmtName, tempTable->table.tableAlias); tstrncpy(((SSelectStmt*)pSubquery)->stmtName, tempTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
((SSelectStmt*)pSubquery)->isSubquery = true; ((SSelectStmt*)pSubquery)->isSubquery = true;
} else if (QUERY_NODE_SET_OPERATOR == nodeType(pSubquery)) { } else if (QUERY_NODE_SET_OPERATOR == nodeType(pSubquery)) {
strcpy(((SSetOperator*)pSubquery)->stmtName, tempTable->table.tableAlias); tstrncpy(((SSetOperator*)pSubquery)->stmtName, tempTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
} }
return (SNode*)tempTable; return (SNode*)tempTable;
_err: _err:
@ -1447,7 +1447,7 @@ SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues) {
fill->pWStartTs = NULL; fill->pWStartTs = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&(fill->pWStartTs)); pCxt->errCode = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&(fill->pWStartTs));
CHECK_MAKE_NODE(fill->pWStartTs); CHECK_MAKE_NODE(fill->pWStartTs);
strcpy(((SFunctionNode*)fill->pWStartTs)->functionName, "_wstart"); tstrncpy(((SFunctionNode*)fill->pWStartTs)->functionName, "_wstart", TSDB_FUNC_NAME_LEN);
return (SNode*)fill; return (SNode*)fill;
_err: _err:
nodesDestroyNode((SNode*)fill); nodesDestroyNode((SNode*)fill);
@ -1779,7 +1779,7 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode*
setSubquery(setOp->pLeft); setSubquery(setOp->pLeft);
setOp->pRight = pRight; setOp->pRight = pRight;
setSubquery(setOp->pRight); setSubquery(setOp->pRight);
sprintf(setOp->stmtName, "%p", setOp); snprintf(setOp->stmtName, TSDB_TABLE_NAME_LEN, "%p", setOp);
return (SNode*)setOp; return (SNode*)setOp;
_err: _err:
nodesDestroyNode(pLeft); nodesDestroyNode(pLeft);
@ -2337,8 +2337,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode*
SCreateTableStmt* pStmt = NULL; SCreateTableStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreExists = ignoreExists; pStmt->ignoreExists = ignoreExists;
pStmt->pCols = pCols; pStmt->pCols = pCols;
pStmt->pTags = pTags; pStmt->pTags = pTags;
@ -2359,10 +2359,10 @@ SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SN
SCreateSubTableClause* pStmt = NULL; SCreateSubTableClause* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_CLAUSE, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_CLAUSE, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
strcpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName); tstrncpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName); tstrncpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreExists = ignoreExists; pStmt->ignoreExists = ignoreExists;
pStmt->pSpecificTags = pSpecificTags; pStmt->pSpecificTags = pSpecificTags;
pStmt->pValsOfTags = pValsOfTags; pStmt->pValsOfTags = pValsOfTags;
@ -2385,8 +2385,8 @@ SNode* createCreateSubTableFromFileClause(SAstCreateContext* pCxt, bool ignoreEx
SCreateSubTableFromFileClause* pStmt = NULL; SCreateSubTableFromFileClause* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_FROM_FILE_CLAUSE, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName); tstrncpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName); tstrncpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreExists = ignoreExists; pStmt->ignoreExists = ignoreExists;
pStmt->pSpecificTags = pSpecificTags; pStmt->pSpecificTags = pSpecificTags;
if (TK_NK_STRING == pFilePath->type) { if (TK_NK_STRING == pFilePath->type) {
@ -2420,8 +2420,8 @@ SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNod
SDropTableClause* pStmt = NULL; SDropTableClause* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_CLAUSE, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_CLAUSE, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreNotExists = ignoreNotExists; pStmt->ignoreNotExists = ignoreNotExists;
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
return (SNode*)pStmt; return (SNode*)pStmt;
@ -2448,8 +2448,8 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool igno
SDropSuperTableStmt* pStmt = NULL; SDropSuperTableStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_SUPER_TABLE_STMT, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_SUPER_TABLE_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
pStmt->ignoreNotExists = ignoreNotExists; pStmt->ignoreNotExists = ignoreNotExists;
pStmt->withOpt = withOpt; pStmt->withOpt = withOpt;
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
@ -2460,8 +2460,8 @@ _err:
} }
static SNode* createAlterTableStmtFinalize(SNode* pRealTable, SAlterTableStmt* pStmt) { static SNode* createAlterTableStmtFinalize(SNode* pRealTable, SAlterTableStmt* pStmt) {
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
return (SNode*)pStmt; return (SNode*)pStmt;
} }
@ -2780,8 +2780,8 @@ SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode*
SShowCreateTableStmt* pStmt = NULL; SShowCreateTableStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
return (SNode*)pStmt; return (SNode*)pStmt;
_err: _err:
@ -2794,8 +2794,8 @@ SNode* createShowCreateViewStmt(SAstCreateContext* pCxt, ENodeType type, SNode*
SShowCreateViewStmt* pStmt = NULL; SShowCreateViewStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->viewName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->viewName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
return (SNode*)pStmt; return (SNode*)pStmt;
_err: _err:
@ -2808,8 +2808,8 @@ SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable
SShowTableDistributedStmt* pStmt = NULL; SShowTableDistributedStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
return (SNode*)pStmt; return (SNode*)pStmt;
_err: _err:
@ -2965,7 +2965,7 @@ SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const ST
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_USER_STMT, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_USER_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName); COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
strcpy(pStmt->password, password); tstrncpy(pStmt->password, password, TSDB_USET_PASSWORD_LEN);
pStmt->sysinfo = sysinfo; pStmt->sysinfo = sysinfo;
pStmt->createDb = createDb; pStmt->createDb = createDb;
pStmt->isImport = is_import; pStmt->isImport = is_import;
@ -2987,7 +2987,7 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t al
char password[TSDB_USET_PASSWORD_LEN] = {0}; char password[TSDB_USET_PASSWORD_LEN] = {0};
SToken* pVal = pAlterInfo; SToken* pVal = pAlterInfo;
CHECK_NAME(checkPassword(pCxt, pVal, password)); CHECK_NAME(checkPassword(pCxt, pVal, password));
strcpy(pStmt->password, password); tstrncpy(pStmt->password, password, TSDB_USET_PASSWORD_LEN);
break; break;
} }
case TSDB_ALTER_USER_ENABLE: { case TSDB_ALTER_USER_ENABLE: {
@ -3297,8 +3297,8 @@ SNode* createCreateTopicStmtUseTable(SAstCreateContext* pCxt, bool ignoreExists,
pStmt->withMeta = withMeta; pStmt->withMeta = withMeta;
pStmt->pWhere = pWhere; pStmt->pWhere = pWhere;
strcpy(pStmt->subDbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->subDbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->subSTbName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->subSTbName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
return (SNode*)pStmt; return (SNode*)pStmt;
_err: _err:
@ -3411,8 +3411,8 @@ SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
SDescribeStmt* pStmt = NULL; SDescribeStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(QUERY_NODE_DESCRIBE_STMT, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_DESCRIBE_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
return (SNode*)pStmt; return (SNode*)pStmt;
_err: _err:
@ -3492,8 +3492,8 @@ SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pVie
} }
pStmt->pQuerySql = tstrdup(pAs->z + i); pStmt->pQuerySql = tstrdup(pAs->z + i);
CHECK_OUT_OF_MEM(pStmt->pQuerySql); CHECK_OUT_OF_MEM(pStmt->pQuerySql);
strcpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName); tstrncpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName); tstrncpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName, TSDB_VIEW_NAME_LEN);
nodesDestroyNode(pView); nodesDestroyNode(pView);
pStmt->orReplace = orReplace; pStmt->orReplace = orReplace;
pStmt->pQuery = pQuery; pStmt->pQuery = pQuery;
@ -3511,8 +3511,8 @@ SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode*
pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_VIEW_STMT, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_VIEW_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
pStmt->ignoreNotExists = ignoreNotExists; pStmt->ignoreNotExists = ignoreNotExists;
strcpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName); tstrncpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName); tstrncpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName, TSDB_VIEW_NAME_LEN);
nodesDestroyNode(pView); nodesDestroyNode(pView);
return (SNode*)pStmt; return (SNode*)pStmt;
_err: _err:
@ -3597,8 +3597,8 @@ SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken
pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT, (SNode**)&pStmt); pCxt->errCode = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt); CHECK_MAKE_NODE(pStmt);
COPY_STRING_FORM_ID_TOKEN(pStmt->streamName, pStreamName); COPY_STRING_FORM_ID_TOKEN(pStmt->streamName, pStreamName);
strcpy(pStmt->targetDbName, ((SRealTableNode*)pRealTable)->table.dbName); tstrncpy(pStmt->targetDbName, ((SRealTableNode*)pRealTable)->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pStmt->targetTabName, ((SRealTableNode*)pRealTable)->table.tableName); tstrncpy(pStmt->targetTabName, ((SRealTableNode*)pRealTable)->table.tableName, TSDB_TABLE_NAME_LEN);
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
pStmt->ignoreExists = ignoreExists; pStmt->ignoreExists = ignoreExists;
pStmt->pOptions = (SStreamOptions*)pOptions; pStmt->pOptions = (SStreamOptions*)pOptions;
@ -3852,9 +3852,9 @@ SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols
pStmt->pCols = pCols; pStmt->pCols = pCols;
pStmt->pQuery = pQuery; pStmt->pQuery = pQuery;
if (QUERY_NODE_SELECT_STMT == nodeType(pQuery)) { if (QUERY_NODE_SELECT_STMT == nodeType(pQuery)) {
strcpy(((SSelectStmt*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias); tstrncpy(((SSelectStmt*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias, TSDB_TABLE_NAME_LEN);
} else if (QUERY_NODE_SET_OPERATOR == nodeType(pQuery)) { } else if (QUERY_NODE_SET_OPERATOR == nodeType(pQuery)) {
strcpy(((SSetOperator*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias); tstrncpy(((SSetOperator*)pQuery)->stmtName, ((STableNode*)pTable)->tableAlias, TSDB_TABLE_NAME_LEN);
} }
return (SNode*)pStmt; return (SNode*)pStmt;
_err: _err:

View File

@ -480,8 +480,8 @@ static int32_t collectMetaKeyFromExplain(SCollectMetaKeyCxt* pCxt, SExplainStmt*
static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStmt* pStmt) { static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStmt* pStmt) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId}; SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pStmt->dbName); tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
strcpy(name.tname, pStmt->tableName); tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name); int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
#ifdef TD_ENTERPRISE #ifdef TD_ENTERPRISE
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -781,8 +781,8 @@ static int32_t collectMetaKeyFromShowCreateDatabase(SCollectMetaKeyCxt* pCxt, SS
static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShowCreateTableStmt* pStmt) { static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShowCreateTableStmt* pStmt) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId}; SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pStmt->dbName); tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
strcpy(name.tname, pStmt->tableName); tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name); int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = reserveTableCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache); code = reserveTableCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
@ -799,8 +799,8 @@ static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShow
static int32_t collectMetaKeyFromShowCreateView(SCollectMetaKeyCxt* pCxt, SShowCreateViewStmt* pStmt) { static int32_t collectMetaKeyFromShowCreateView(SCollectMetaKeyCxt* pCxt, SShowCreateViewStmt* pStmt) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId}; SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pStmt->dbName); tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
strcpy(name.tname, pStmt->viewName); tstrncpy(name.tname, pStmt->viewName, TSDB_TABLE_NAME_LEN);
char dbFName[TSDB_DB_FNAME_LEN]; char dbFName[TSDB_DB_FNAME_LEN];
(void)tNameGetFullDbName(&name, dbFName); (void)tNameGetFullDbName(&name, dbFName);
int32_t code = catalogRemoveViewMeta(pCxt->pParseCxt->pCatalog, dbFName, 0, pStmt->viewName, 0); int32_t code = catalogRemoveViewMeta(pCxt->pParseCxt->pCatalog, dbFName, 0, pStmt->viewName, 0);
@ -841,8 +841,8 @@ static int32_t collectMetaKeyFromInsert(SCollectMetaKeyCxt* pCxt, SInsertStmt* p
static int32_t collectMetaKeyFromShowBlockDist(SCollectMetaKeyCxt* pCxt, SShowTableDistributedStmt* pStmt) { static int32_t collectMetaKeyFromShowBlockDist(SCollectMetaKeyCxt* pCxt, SShowTableDistributedStmt* pStmt) {
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId}; SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
strcpy(name.dbname, pStmt->dbName); tstrncpy(name.dbname, pStmt->dbName, TSDB_DB_NAME_LEN);
strcpy(name.tname, pStmt->tableName); tstrncpy(name.tname, pStmt->tableName, TSDB_TABLE_NAME_LEN);
int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name); int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = collectMetaKeyFromRealTableImpl(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ); code = collectMetaKeyFromRealTableImpl(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ);

View File

@ -134,8 +134,8 @@ EDealRes rewriteAuthTable(SNode* pNode, void* pContext) {
if (QUERY_NODE_COLUMN == nodeType(pNode)) { if (QUERY_NODE_COLUMN == nodeType(pNode)) {
SColumnNode* pCol = (SColumnNode*)pNode; SColumnNode* pCol = (SColumnNode*)pNode;
SAuthRewriteCxt* pCxt = (SAuthRewriteCxt*)pContext; SAuthRewriteCxt* pCxt = (SAuthRewriteCxt*)pContext;
strcpy(pCol->tableName, pCxt->pTarget->tableName); tstrncpy(pCol->tableName, pCxt->pTarget->tableName, TSDB_TABLE_NAME_LEN);
strcpy(pCol->tableAlias, pCxt->pTarget->tableAlias); tstrncpy(pCol->tableAlias, pCxt->pTarget->tableAlias, TSDB_TABLE_NAME_LEN);
} }
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;

View File

@ -178,14 +178,14 @@ static EDealRes doFindAndReplaceNode(SNode** pNode, void* pContext) {
SCalcConstContext* pCxt = pContext; SCalcConstContext* pCxt = pContext;
if (pCxt->replaceCxt.pTarget == *pNode) { if (pCxt->replaceCxt.pTarget == *pNode) {
char aliasName[TSDB_COL_NAME_LEN] = {0}; char aliasName[TSDB_COL_NAME_LEN] = {0};
strcpy(aliasName, ((SExprNode*)*pNode)->aliasName); tstrncpy(aliasName, ((SExprNode*)*pNode)->aliasName, TSDB_COL_NAME_LEN);
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
*pNode = NULL; *pNode = NULL;
pCxt->code = nodesCloneNode(pCxt->replaceCxt.pNew, pNode); pCxt->code = nodesCloneNode(pCxt->replaceCxt.pNew, pNode);
if (NULL == *pNode) { if (NULL == *pNode) {
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
strcpy(((SExprNode*)*pNode)->aliasName, aliasName); tstrncpy(((SExprNode*)*pNode)->aliasName, aliasName, TSDB_COL_NAME_LEN);
pCxt->replaceCxt.replaced = true; pCxt->replaceCxt.replaced = true;
return DEAL_RES_END; return DEAL_RES_END;
@ -228,14 +228,14 @@ static int32_t calcConstProject(SCalcConstContext* pCxt, SNode* pProject, bool d
SAssociationNode* pAssNode = taosArrayGet(pAssociation, i); SAssociationNode* pAssNode = taosArrayGet(pAssociation, i);
SNode** pCol = pAssNode->pPlace; SNode** pCol = pAssNode->pPlace;
if (*pCol == pAssNode->pAssociationNode) { if (*pCol == pAssNode->pAssociationNode) {
strcpy(aliasName, ((SExprNode*)*pCol)->aliasName); tstrncpy(aliasName, ((SExprNode*)*pCol)->aliasName, TSDB_COL_NAME_LEN);
SArray* pOrigAss = NULL; SArray* pOrigAss = NULL;
TSWAP(((SExprNode*)*pCol)->pAssociation, pOrigAss); TSWAP(((SExprNode*)*pCol)->pAssociation, pOrigAss);
nodesDestroyNode(*pCol); nodesDestroyNode(*pCol);
*pCol = NULL; *pCol = NULL;
code = nodesCloneNode(*pNew, pCol); code = nodesCloneNode(*pNew, pCol);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
strcpy(((SExprNode*)*pCol)->aliasName, aliasName); tstrncpy(((SExprNode*)*pCol)->aliasName, aliasName, TSDB_COL_NAME_LEN);
TSWAP(pOrigAss, ((SExprNode*)*pCol)->pAssociation); TSWAP(pOrigAss, ((SExprNode*)*pCol)->pAssociation);
} }
taosArrayDestroy(pOrigAss); taosArrayDestroy(pOrigAss);

View File

@ -927,7 +927,7 @@ int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSc
for (int32_t i = 0; i < numOfBound; ++i) { for (int32_t i = 0; i < numOfBound; ++i) {
schema = &pSchema[boundColumns[i]]; schema = &pSchema[boundColumns[i]];
strcpy((*fields)[i].name, schema->name); tstrncpy((*fields)[i].name, schema->name, 65);
(*fields)[i].type = schema->type; (*fields)[i].type = schema->type;
(*fields)[i].bytes = schema->bytes; (*fields)[i].bytes = schema->bytes;
} }

File diff suppressed because it is too large Load Diff

View File

@ -250,7 +250,7 @@ int32_t generateSyntaxErrMsgExt(SMsgBuf* pBuf, int32_t errCode, const char* pFor
int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) { int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
if (pBuf->buf) { if (pBuf->buf) {
strncpy(pBuf->buf, msg, pBuf->len); tstrncpy(pBuf->buf, msg, pBuf->len);
} }
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
@ -277,7 +277,7 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
} }
char buf[64] = {0}; // only extract part of sql string char buf[64] = {0}; // only extract part of sql string
strncpy(buf, sourceStr, tListLen(buf) - 1); tstrncpy(buf, sourceStr, tListLen(buf));
if (additionalInfo != NULL) { if (additionalInfo != NULL) {
snprintf(pBuf->buf, pBuf->len, msgFormat2, buf, additionalInfo); snprintf(pBuf->buf, pBuf->len, msgFormat2, buf, additionalInfo);
@ -454,7 +454,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi
continue; continue;
} }
STagVal val = {0}; STagVal val = {0};
// strcpy(val.colName, colName); // TSDB_DB_FNAME_LENme, colName);
val.pKey = jsonKey; val.pKey = jsonKey;
retCode = taosHashPut(keyHash, jsonKey, keyLen, &keyLen, retCode = taosHashPut(keyHash, jsonKey, keyLen, &keyLen,
CHAR_BYTES); // add key to hash to remove dumplicate, value is useless CHAR_BYTES); // add key to hash to remove dumplicate, value is useless
@ -596,15 +596,15 @@ int32_t getVnodeSysTableTargetName(int32_t acctId, SNode* pWhere, SName* pName)
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type, static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
char* pStr, bool isView) { char* pStr, bool isView) {
return sprintf(pStr, "%s*%d*%s*%s*%d*%d", pUser, acctId, pDb, (NULL == pTable || '\0' == pTable[0]) ? "``" : pTable, return snprintf(pStr, USER_AUTH_KEY_MAX_LEN, "%s*%d*%s*%s*%d*%d", pUser, acctId, pDb,
type, isView); (NULL == pTable || '\0' == pTable[0]) ? "``" : pTable, type, isView);
} }
static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) { static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
char* p = strchr(pStart, '*'); char* p = strchr(pStart, '*');
char buf[10] = {0}; char buf[10] = {0};
if (NULL == p) { if (NULL == p) {
strcpy(buf, pStart); tstrncpy(buf, pStart, 10);
*pNext = NULL; *pNext = NULL;
} else { } else {
strncpy(buf, pStart, p - pStart); strncpy(buf, pStart, p - pStart);
@ -616,7 +616,7 @@ static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
static void getStringFromAuthStr(const char* pStart, char* pStr, char** pNext) { static void getStringFromAuthStr(const char* pStart, char* pStr, char** pNext) {
char* p = strchr(pStart, '*'); char* p = strchr(pStart, '*');
if (NULL == p) { if (NULL == p) {
strcpy(pStr, pStart); tstrncpy(pStr, pStart, strlen(pStart) + 1);
*pNext = NULL; *pNext = NULL;
} else { } else {
strncpy(pStr, pStart, p - pStart); strncpy(pStr, pStart, p - pStart);
@ -708,7 +708,7 @@ static int32_t buildTableReqFromDb(SHashObj* pDbsHash, SArray** pDbs) {
SParseTablesMetaReq* p = taosHashIterate(pDbsHash, NULL); SParseTablesMetaReq* p = taosHashIterate(pDbsHash, NULL);
while (NULL != p) { while (NULL != p) {
STablesReq req = {0}; STablesReq req = {0};
strcpy(req.dbFName, p->dbFName); tstrncpy(req.dbFName, p->dbFName, TSDB_DB_FNAME_LEN);
int32_t code = buildTableReq(p->pTables, &req.pTables); int32_t code = buildTableReq(p->pTables, &req.pTables);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
if (NULL == taosArrayPush(*pDbs, &req)) { if (NULL == taosArrayPush(*pDbs, &req)) {
@ -832,7 +832,7 @@ int32_t createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode*
select->isDistinct = isDistinct; select->isDistinct = isDistinct;
select->pProjectionList = pProjectionList; select->pProjectionList = pProjectionList;
select->pFromTable = pTable; select->pFromTable = pTable;
sprintf(select->stmtName, "%p", select); snprintf(select->stmtName, TSDB_TABLE_NAME_LEN, "%p", select);
select->timeLineResMode = select->isDistinct ? TIME_LINE_NONE : TIME_LINE_GLOBAL; select->timeLineResMode = select->isDistinct ? TIME_LINE_NONE : TIME_LINE_GLOBAL;
select->timeLineCurMode = TIME_LINE_GLOBAL; select->timeLineCurMode = TIME_LINE_GLOBAL;
select->onlyHasKeepOrderFunc = true; select->onlyHasKeepOrderFunc = true;

View File

@ -221,7 +221,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam, vo
static EDealRes rewriteQueryExprAliasImpl(SNode* pNode, void* pContext) { static EDealRes rewriteQueryExprAliasImpl(SNode* pNode, void* pContext) {
if (nodesIsExprNode(pNode) && QUERY_NODE_COLUMN != nodeType(pNode)) { if (nodesIsExprNode(pNode) && QUERY_NODE_COLUMN != nodeType(pNode)) {
sprintf(((SExprNode*)pNode)->aliasName, "#%d", *(int32_t*)pContext); snprintf(((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN, "#%d", *(int32_t*)pContext);
++(*(int32_t*)pContext); ++(*(int32_t*)pContext);
} }
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
@ -528,9 +528,6 @@ int32_t qStmtBindParams2(SQuery* pQuery, TAOS_STMT2_BIND* pParams, int32_t colId
nodesDestroyNode(pQuery->pRoot); nodesDestroyNode(pQuery->pRoot);
pQuery->pRoot = NULL; pQuery->pRoot = NULL;
code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot); code = nodesCloneNode(pQuery->pPrepareRoot, &pQuery->pRoot);
if (NULL == pQuery->pRoot) {
code = code;
}
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
rewriteExprAlias(pQuery->pRoot); rewriteExprAlias(pQuery->pRoot);

View File

@ -119,9 +119,9 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
} }
SExprNode* pToBeRewrittenExpr = (SExprNode*)(*pNode); SExprNode* pToBeRewrittenExpr = (SExprNode*)(*pNode);
pCol->node.resType = pToBeRewrittenExpr->resType; pCol->node.resType = pToBeRewrittenExpr->resType;
strcpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName); tstrncpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName, TSDB_COL_NAME_LEN);
strcpy(pCol->node.userAlias, ((SExprNode*)pExpr)->userAlias); tstrncpy(pCol->node.userAlias, ((SExprNode*)pExpr)->userAlias, TSDB_COL_NAME_LEN);
strcpy(pCol->colName, ((SExprNode*)pExpr)->aliasName); tstrncpy(pCol->colName, ((SExprNode*)pExpr)->aliasName, TSDB_COL_NAME_LEN);
pCol->node.projIdx = ((SExprNode*)(*pNode))->projIdx; pCol->node.projIdx = ((SExprNode*)(*pNode))->projIdx;
if (QUERY_NODE_FUNCTION == nodeType(pExpr)) { if (QUERY_NODE_FUNCTION == nodeType(pExpr)) {
setColumnInfo((SFunctionNode*)pExpr, pCol, pCxt->isPartitionBy); setColumnInfo((SFunctionNode*)pExpr, pCol, pCxt->isPartitionBy);
@ -150,7 +150,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_LOGIC_CONDITION:
case QUERY_NODE_FUNCTION: { case QUERY_NODE_FUNCTION: {
if ('\0' == ((SExprNode*)pNode)->aliasName[0]) { if ('\0' == ((SExprNode*)pNode)->aliasName[0]) {
sprintf(((SExprNode*)pNode)->aliasName, "#expr_%p", pNode); snprintf(((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN, "#expr_%p", pNode);
} }
return DEAL_RES_IGNORE_CHILD; return DEAL_RES_IGNORE_CHILD;
} }
@ -311,12 +311,12 @@ static SNode* createFirstCol(SRealTableNode* pTable, const SSchema* pSchema) {
pCol->tableId = pTable->pMeta->uid; pCol->tableId = pTable->pMeta->uid;
pCol->colId = pSchema->colId; pCol->colId = pSchema->colId;
pCol->colType = COLUMN_TYPE_COLUMN; pCol->colType = COLUMN_TYPE_COLUMN;
strcpy(pCol->tableAlias, pTable->table.tableAlias); tstrncpy(pCol->tableAlias, pTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
strcpy(pCol->tableName, pTable->table.tableName); tstrncpy(pCol->tableName, pTable->table.tableName, TSDB_TABLE_NAME_LEN);
pCol->isPk = pSchema->flags & COL_IS_KEY; pCol->isPk = pSchema->flags & COL_IS_KEY;
pCol->tableHasPk = hasPkInTable(pTable->pMeta); pCol->tableHasPk = hasPkInTable(pTable->pMeta);
pCol->numOfPKs = pTable->pMeta->tableInfo.numOfPKs; pCol->numOfPKs = pTable->pMeta->tableInfo.numOfPKs;
strcpy(pCol->colName, pSchema->name); tstrncpy(pCol->colName, pSchema->name, TSDB_COL_NAME_LEN);
return (SNode*)pCol; return (SNode*)pCol;
} }
@ -392,8 +392,8 @@ static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealT
pScan->scanRange = TSWINDOW_INITIALIZER; pScan->scanRange = TSWINDOW_INITIALIZER;
pScan->tableName.type = TSDB_TABLE_NAME_T; pScan->tableName.type = TSDB_TABLE_NAME_T;
pScan->tableName.acctId = pCxt->pPlanCxt->acctId; pScan->tableName.acctId = pCxt->pPlanCxt->acctId;
strcpy(pScan->tableName.dbname, pRealTable->table.dbName); tstrncpy(pScan->tableName.dbname, pRealTable->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pScan->tableName.tname, pRealTable->table.tableName); tstrncpy(pScan->tableName.tname, pRealTable->table.tableName, TSDB_TABLE_NAME_LEN);
pScan->showRewrite = pCxt->pPlanCxt->showRewrite; pScan->showRewrite = pCxt->pPlanCxt->showRewrite;
pScan->ratio = pRealTable->ratio; pScan->ratio = pRealTable->ratio;
pScan->dataRequired = FUNC_DATA_REQUIRED_DATA_LOAD; pScan->dataRequired = FUNC_DATA_REQUIRED_DATA_LOAD;
@ -785,12 +785,12 @@ static int32_t addWinJoinPrimKeyToAggFuncs(SSelectStmt* pSelect, SNodeList** pLi
} }
SSchema* pColSchema = &pProbeTable->pMeta->schema[0]; SSchema* pColSchema = &pProbeTable->pMeta->schema[0];
strcpy(pCol->dbName, pProbeTable->table.dbName); tstrncpy(pCol->dbName, pProbeTable->table.dbName, TSDB_DB_NAME_LEN);
strcpy(pCol->tableAlias, pProbeTable->table.tableAlias); tstrncpy(pCol->tableAlias, pProbeTable->table.tableAlias, TSDB_TABLE_NAME_LEN);
strcpy(pCol->tableName, pProbeTable->table.tableName); tstrncpy(pCol->tableName, pProbeTable->table.tableName, TSDB_TABLE_NAME_LEN);
strcpy(pCol->colName, pColSchema->name); tstrncpy(pCol->colName, pColSchema->name, TSDB_COL_NAME_LEN);
strcpy(pCol->node.aliasName, pColSchema->name); tstrncpy(pCol->node.aliasName, pColSchema->name, TSDB_COL_NAME_LEN);
strcpy(pCol->node.userAlias, pColSchema->name); tstrncpy(pCol->node.userAlias, pColSchema->name, TSDB_COL_NAME_LEN);
pCol->tableId = pProbeTable->pMeta->uid; pCol->tableId = pProbeTable->pMeta->uid;
pCol->tableType = pProbeTable->pMeta->tableType; pCol->tableType = pProbeTable->pMeta->tableType;
pCol->colId = pColSchema->colId; pCol->colId = pColSchema->colId;
@ -1557,7 +1557,7 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pSort->pSortKeys = NULL; pSort->pSortKeys = NULL;
code = nodesCloneList(pSelect->pOrderByList, &pSort->pSortKeys); code = nodesCloneList(pSelect->pOrderByList, &pSort->pSortKeys);
if (NULL != pSort->pSortKeys) { if (TSDB_CODE_SUCCESS == code) {
SNode* pNode = NULL; SNode* pNode = NULL;
SOrderByExprNode* firstSortKey = (SOrderByExprNode*)nodesListGetNode(pSort->pSortKeys, 0); SOrderByExprNode* firstSortKey = (SOrderByExprNode*)nodesListGetNode(pSort->pSortKeys, 0);
if (isPrimaryKeySort(pSelect->pOrderByList)) pSort->node.outputTsOrder = firstSortKey->order; if (isPrimaryKeySort(pSelect->pOrderByList)) pSort->node.outputTsOrder = firstSortKey->order;
@ -1624,10 +1624,7 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel
pProject->pProjections = NULL; pProject->pProjections = NULL;
code = nodesCloneList(pSelect->pProjectionList, &pProject->pProjections); code = nodesCloneList(pSelect->pProjectionList, &pProject->pProjections);
if (NULL == pProject->pProjections) { tstrncpy(pProject->stmtName, pSelect->stmtName, TSDB_TABLE_NAME_LEN);
code = code;
}
strcpy(pProject->stmtName, pSelect->stmtName);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = createColumnByProjections(pCxt, pSelect->stmtName, pSelect->pProjectionList, &pProject->node.pTargets); code = createColumnByProjections(pCxt, pSelect->stmtName, pSelect->pProjectionList, &pProject->node.pTargets);
@ -2117,7 +2114,7 @@ static int32_t createVnodeModifLogicNodeByDelete(SLogicPlanContext* pCxt, SDelet
pModify->tableId = pRealTable->pMeta->uid; pModify->tableId = pRealTable->pMeta->uid;
pModify->tableType = pRealTable->pMeta->tableType; pModify->tableType = pRealTable->pMeta->tableType;
snprintf(pModify->tableName, sizeof(pModify->tableName), "%s", pRealTable->table.tableName); snprintf(pModify->tableName, sizeof(pModify->tableName), "%s", pRealTable->table.tableName);
strcpy(pModify->tsColName, pRealTable->pMeta->schema->name); tstrncpy(pModify->tsColName, pRealTable->pMeta->schema->name, TSDB_COL_NAME_LEN);
pModify->deleteTimeRange = pDelete->timeRange; pModify->deleteTimeRange = pDelete->timeRange;
pModify->pAffectedRows = NULL; pModify->pAffectedRows = NULL;
code = nodesCloneNode(pDelete->pCountFunc, &pModify->pAffectedRows); code = nodesCloneNode(pDelete->pCountFunc, &pModify->pAffectedRows);

View File

@ -188,7 +188,7 @@ static EDealRes optRebuildTbanme(SNode** pNode, void* pContext) {
*(int32_t*)pContext = code; *(int32_t*)pContext = code;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
strcpy(pFunc->functionName, "tbname"); tstrncpy(pFunc->functionName, "tbname", TSDB_FUNC_NAME_LEN);
pFunc->funcType = FUNCTION_TYPE_TBNAME; pFunc->funcType = FUNCTION_TYPE_TBNAME;
pFunc->node.resType = ((SColumnNode*)*pNode)->node.resType; pFunc->node.resType = ((SColumnNode*)*pNode)->node.resType;
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
@ -1302,9 +1302,7 @@ static int32_t pdcJoinAddPreFilterColsToTarget(SOptimizeContext* pCxt, SJoinLogi
SNodeList* pCondCols = NULL; SNodeList* pCondCols = NULL;
code = nodesMakeList(&pCondCols); code = nodesMakeList(&pCondCols);
SNodeList* pTargets = NULL; SNodeList* pTargets = NULL;
if (NULL == pCondCols) { if (TSDB_CODE_SUCCESS == code) {
code = code;
} else {
code = nodesCollectColumnsFromNode(pJoin->pColOnCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols); code = nodesCollectColumnsFromNode(pJoin->pColOnCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -2959,9 +2957,9 @@ static int32_t smaIndexOptCreateSmaCol(SNode* pFunc, uint64_t tableId, int32_t c
pCol->tableType = TSDB_SUPER_TABLE; pCol->tableType = TSDB_SUPER_TABLE;
pCol->colId = colId; pCol->colId = colId;
pCol->colType = COLUMN_TYPE_COLUMN; pCol->colType = COLUMN_TYPE_COLUMN;
strcpy(pCol->colName, ((SExprNode*)pFunc)->aliasName); tstrncpy(pCol->colName, ((SExprNode*)pFunc)->aliasName, TSDB_COL_NAME_LEN);
pCol->node.resType = ((SExprNode*)pFunc)->resType; pCol->node.resType = ((SExprNode*)pFunc)->resType;
strcpy(pCol->node.aliasName, ((SExprNode*)pFunc)->aliasName); tstrncpy(pCol->node.aliasName, ((SExprNode*)pFunc)->aliasName, TSDB_COL_NAME_LEN);
*ppNode = pCol; *ppNode = pCol;
return code; return code;
} }
@ -3030,7 +3028,7 @@ static int32_t smaIndexOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNo
} }
SExprNode exprNode; SExprNode exprNode;
exprNode.resType = ((SExprNode*)pWsNode)->resType; exprNode.resType = ((SExprNode*)pWsNode)->resType;
sprintf(exprNode.aliasName, "#expr_%d", index + 1); snprintf(exprNode.aliasName, TSDB_COL_NAME_LEN, "#expr_%d", index + 1);
SColumnNode* pkNode = NULL; SColumnNode* pkNode = NULL;
code = smaIndexOptCreateSmaCol((SNode*)&exprNode, tableId, PRIMARYKEY_TIMESTAMP_COL_ID, &pkNode); code = smaIndexOptCreateSmaCol((SNode*)&exprNode, tableId, PRIMARYKEY_TIMESTAMP_COL_ID, &pkNode);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
@ -3200,7 +3198,7 @@ static void partTagsSetAlias(char* pAlias, const char* pTableAlias, const char*
int32_t len = tsnprintf(name, TSDB_COL_FNAME_LEN, "%s.%s", pTableAlias, pColName); int32_t len = tsnprintf(name, TSDB_COL_FNAME_LEN, "%s.%s", pTableAlias, pColName);
(void)taosHashBinary(name, len); (void)taosHashBinary(name, len);
strncpy(pAlias, name, TSDB_COL_NAME_LEN - 1); tstrncpy(pAlias, name, TSDB_COL_NAME_LEN);
} }
static int32_t partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode, SFunctionNode** ppNode) { static int32_t partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode, SFunctionNode** ppNode) {
@ -3218,7 +3216,7 @@ static int32_t partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode, SF
SColumnNode* pCol = (SColumnNode*)pNode; SColumnNode* pCol = (SColumnNode*)pNode;
partTagsSetAlias(pFunc->node.aliasName, pCol->tableAlias, pCol->colName); partTagsSetAlias(pFunc->node.aliasName, pCol->tableAlias, pCol->colName);
} else { } else {
strcpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName); tstrncpy(pFunc->node.aliasName, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
} }
code = nodesCloneNode(pNode, &pNew); code = nodesCloneNode(pNode, &pNew);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -3507,7 +3505,7 @@ static EDealRes eliminateProjOptRewriteScanTableAlias(SNode* pNode, void* pConte
if (QUERY_NODE_COLUMN == nodeType(pNode)) { if (QUERY_NODE_COLUMN == nodeType(pNode)) {
SColumnNode* pCol = (SColumnNode*)pNode; SColumnNode* pCol = (SColumnNode*)pNode;
RewriteTableAliasCxt* pCtx = (RewriteTableAliasCxt*)pContext; RewriteTableAliasCxt* pCtx = (RewriteTableAliasCxt*)pContext;
strncpy(pCol->tableAlias, pCtx->newTableAlias, TSDB_TABLE_NAME_LEN); tstrncpy(pCol->tableAlias, pCtx->newTableAlias, TSDB_TABLE_NAME_LEN);
} }
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
@ -3761,7 +3759,7 @@ static int32_t rewriteTailOptCreateProjectExpr(SFunctionNode* pFunc, SNode** ppN
if (NULL == pExpr) { if (NULL == pExpr) {
return code; return code;
} }
strcpy(((SExprNode*)pExpr)->aliasName, pFunc->node.aliasName); tstrncpy(((SExprNode*)pExpr)->aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
*ppNode = pExpr; *ppNode = pExpr;
return code; return code;
} }
@ -3917,15 +3915,15 @@ static int32_t rewriteUniqueOptCreateFirstFunc(SFunctionNode* pSelectValue, SNod
return code; return code;
} }
strcpy(pFunc->functionName, "first"); tstrncpy(pFunc->functionName, "first", TSDB_FUNC_NAME_LEN);
if (NULL != pSelectValue) { if (NULL != pSelectValue) {
strcpy(pFunc->node.aliasName, pSelectValue->node.aliasName); tstrncpy(pFunc->node.aliasName, pSelectValue->node.aliasName, TSDB_COL_NAME_LEN);
} else { } else {
int64_t pointer = (int64_t)pFunc; int64_t pointer = (int64_t)pFunc;
char name[TSDB_FUNC_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0}; char name[TSDB_FUNC_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pFunc->functionName, pointer); int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pFunc->functionName, pointer);
(void)taosHashBinary(name, len); (void)taosHashBinary(name, len);
strncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN - 1); tstrncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN);
} }
SNode* pNew = NULL; SNode* pNew = NULL;
code = nodesCloneNode(pCol, &pNew); code = nodesCloneNode(pCol, &pNew);
@ -4023,15 +4021,15 @@ static int32_t rewriteUniqueOptCreateProjectCol(SFunctionNode* pFunc, SNode** pp
if (FUNCTION_TYPE_UNIQUE == pFunc->funcType) { if (FUNCTION_TYPE_UNIQUE == pFunc->funcType) {
SExprNode* pExpr = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); SExprNode* pExpr = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
if (QUERY_NODE_COLUMN == nodeType(pExpr)) { if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
strcpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias); tstrncpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias, TSDB_TABLE_NAME_LEN);
strcpy(pCol->colName, ((SColumnNode*)pExpr)->colName); tstrncpy(pCol->colName, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
} else { } else {
strcpy(pCol->colName, pExpr->aliasName); tstrncpy(pCol->colName, pExpr->aliasName, TSDB_COL_NAME_LEN);
} }
} else { } else {
strcpy(pCol->colName, pFunc->node.aliasName); tstrncpy(pCol->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
} }
strcpy(pCol->node.aliasName, pFunc->node.aliasName); tstrncpy(pCol->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
*ppNode = (SNode*)pCol; *ppNode = (SNode*)pCol;
return code; return code;
} }
@ -4405,7 +4403,7 @@ static int32_t lastRowScanBuildFuncTypes(SScanLogicNode* pScan, SColumnNode* pCo
return terrno; return terrno;
} }
pFuncTypeParam->pCol->colId = pColNode->colId; pFuncTypeParam->pCol->colId = pColNode->colId;
strcpy(pFuncTypeParam->pCol->name, pColNode->colName); tstrncpy(pFuncTypeParam->pCol->name, pColNode->colName, TSDB_COL_NAME_LEN);
if (NULL == taosArrayPush(pScan->pFuncTypes, pFuncTypeParam)) { if (NULL == taosArrayPush(pScan->pFuncTypes, pFuncTypeParam)) {
taosMemoryFree(pFuncTypeParam); taosMemoryFree(pFuncTypeParam);
return terrno; return terrno;
@ -4482,15 +4480,15 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
break; break;
} }
sprintf(((SColumnNode*)newColNode)->colName, "#dup_col.%p", newColNode); snprintf(((SColumnNode*)newColNode)->colName, TSDB_COL_NAME_LEN, "#dup_col.%p", newColNode);
sprintf(((SColumnNode*)pParamNode)->colName, "#dup_col.%p", newColNode); snprintf(((SColumnNode*)pParamNode)->colName, TSDB_COL_NAME_LEN, "#dup_col.%p", newColNode);
if (FUNCTION_TYPE_LAST_ROW == funcType && if (FUNCTION_TYPE_LAST_ROW == funcType &&
((SColumnNode*)pParamNode)->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { ((SColumnNode*)pParamNode)->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
if (!adjLastRowTsColName) { if (!adjLastRowTsColName) {
adjLastRowTsColName = true; adjLastRowTsColName = true;
strncpy(tsColName, ((SColumnNode*)pParamNode)->colName, TSDB_COL_NAME_LEN); tstrncpy(tsColName, ((SColumnNode*)pParamNode)->colName, TSDB_COL_NAME_LEN);
} else { } else {
strncpy(((SColumnNode*)pParamNode)->colName, tsColName, TSDB_COL_NAME_LEN); tstrncpy(((SColumnNode*)pParamNode)->colName, tsColName, TSDB_COL_NAME_LEN);
nodesDestroyNode(newColNode); nodesDestroyNode(newColNode);
continue; continue;
} }
@ -4614,7 +4612,7 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
((cxt.pLastCols->length == 1 && nodesEqualNode((SNode*)pPKTsCol, nodesListGetNode(cxt.pLastCols, 0))) || ((cxt.pLastCols->length == 1 && nodesEqualNode((SNode*)pPKTsCol, nodesListGetNode(cxt.pLastCols, 0))) ||
(pScan->node.pTargets->length == 2 && cxt.pkBytes > 0))) { (pScan->node.pTargets->length == 2 && cxt.pkBytes > 0))) {
// when select last(ts),tbname,ts from ..., we add another ts to targets // when select last(ts),tbname,ts from ..., we add another ts to targets
sprintf(pPKTsCol->colName, "#sel_val.%p", pPKTsCol); snprintf(pPKTsCol->colName, TSDB_COL_NAME_LEN, "#sel_val.%p", pPKTsCol);
SNode* pNew = NULL; SNode* pNew = NULL;
code = nodesCloneNode((SNode*)pPKTsCol, &pNew); code = nodesCloneNode((SNode*)pPKTsCol, &pNew);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -4631,7 +4629,7 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
if (pNonPKCol && cxt.pLastCols->length == 1 && if (pNonPKCol && cxt.pLastCols->length == 1 &&
nodesEqualNode((SNode*)pNonPKCol, nodesListGetNode(cxt.pLastCols, 0))) { nodesEqualNode((SNode*)pNonPKCol, nodesListGetNode(cxt.pLastCols, 0))) {
// when select last(c1), c1 from ..., we add c1 to targets // when select last(c1), c1 from ..., we add c1 to targets
sprintf(pNonPKCol->colName, "#sel_val.%p", pNonPKCol); snprintf(pNonPKCol->colName, TSDB_COL_NAME_LEN, "#sel_val.%p", pNonPKCol);
SNode* pNew = NULL; SNode* pNew = NULL;
code = nodesCloneNode((SNode*)pNonPKCol, &pNew); code = nodesCloneNode((SNode*)pNonPKCol, &pNew);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -5403,10 +5401,10 @@ static bool tbCntScanOptIsEligibleLogicCond(STbCntScanOptInfo* pInfo, SLogicCond
} }
if (!hasDbCond && 0 == strcmp(pCol->colName, "db_name")) { if (!hasDbCond && 0 == strcmp(pCol->colName, "db_name")) {
hasDbCond = true; hasDbCond = true;
strcpy(pInfo->table.dbname, pVal->literal); tstrncpy(pInfo->table.dbname, pVal->literal, TSDB_DB_NAME_LEN);
} else if (!hasStbCond && 0 == strcmp(pCol->colName, "stable_name")) { } else if (!hasStbCond && 0 == strcmp(pCol->colName, "stable_name")) {
hasStbCond = true; hasStbCond = true;
strcpy(pInfo->table.tname, pVal->literal); tstrncpy(pInfo->table.tname, pVal->literal, TSDB_TABLE_NAME_LEN);
} else { } else {
return false; return false;
} }
@ -5470,8 +5468,8 @@ static int32_t tbCntScanOptCreateTableCountFunc(SNode** ppNode) {
if (NULL == pFunc) { if (NULL == pFunc) {
return code; return code;
} }
strcpy(pFunc->functionName, "_table_count"); tstrncpy(pFunc->functionName, "_table_count", TSDB_FUNC_NAME_LEN);
strcpy(pFunc->node.aliasName, "_table_count"); tstrncpy(pFunc->node.aliasName, "_table_count", TSDB_COL_NAME_LEN);
code = fmGetFuncInfo(pFunc, NULL, 0); code = fmGetFuncInfo(pFunc, NULL, 0);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
nodesDestroyNode((SNode*)pFunc); nodesDestroyNode((SNode*)pFunc);
@ -5483,8 +5481,8 @@ static int32_t tbCntScanOptCreateTableCountFunc(SNode** ppNode) {
static int32_t tbCntScanOptRewriteScan(STbCntScanOptInfo* pInfo) { static int32_t tbCntScanOptRewriteScan(STbCntScanOptInfo* pInfo) {
pInfo->pScan->scanType = SCAN_TYPE_TABLE_COUNT; pInfo->pScan->scanType = SCAN_TYPE_TABLE_COUNT;
strcpy(pInfo->pScan->tableName.dbname, pInfo->table.dbname); tstrncpy(pInfo->pScan->tableName.dbname, pInfo->table.dbname, TSDB_DB_NAME_LEN);
strcpy(pInfo->pScan->tableName.tname, pInfo->table.tname); tstrncpy(pInfo->pScan->tableName.tname, pInfo->table.tname, TSDB_TABLE_NAME_LEN);
NODES_DESTORY_LIST(pInfo->pScan->node.pTargets); NODES_DESTORY_LIST(pInfo->pScan->node.pTargets);
NODES_DESTORY_LIST(pInfo->pScan->pScanCols); NODES_DESTORY_LIST(pInfo->pScan->pScanCols);
NODES_DESTORY_NODE(pInfo->pScan->node.pConditions); NODES_DESTORY_NODE(pInfo->pScan->node.pConditions);
@ -5534,8 +5532,8 @@ static int32_t tbCntScanOptCreateSumFunc(SFunctionNode* pCntFunc, SNode* pParam,
if (NULL == pFunc) { if (NULL == pFunc) {
return code; return code;
} }
strcpy(pFunc->functionName, "sum"); tstrncpy(pFunc->functionName, "sum", TSDB_FUNC_NAME_LEN);
strcpy(pFunc->node.aliasName, pCntFunc->node.aliasName); tstrncpy(pFunc->node.aliasName, pCntFunc->node.aliasName, TSDB_COL_NAME_LEN);
code = createColumnByRewriteExpr(pParam, &pFunc->pParameterList); code = createColumnByRewriteExpr(pParam, &pFunc->pParameterList);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = fmGetFuncInfo(pFunc, NULL, 0); code = fmGetFuncInfo(pFunc, NULL, 0);
@ -6312,29 +6310,22 @@ static int32_t stbJoinOptCreateDynQueryCtrlNode(SLogicNode* pRoot, SLogicNode* p
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pDynCtrl->node.pChildren = NULL; pDynCtrl->node.pChildren = NULL;
code = nodesMakeList(&pDynCtrl->node.pChildren); code = nodesMakeList(&pDynCtrl->node.pChildren);
if (NULL == pDynCtrl->node.pChildren) {
code = code;
}
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pDynCtrl->stbJoin.pVgList = NULL; pDynCtrl->stbJoin.pVgList = NULL;
code = nodesMakeList(&pDynCtrl->stbJoin.pVgList); code = nodesMakeList(&pDynCtrl->stbJoin.pVgList);
if (NULL == pDynCtrl->stbJoin.pVgList) {
code = code;
}
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pDynCtrl->stbJoin.pUidList = NULL; pDynCtrl->stbJoin.pUidList = NULL;
code = nodesMakeList(&pDynCtrl->stbJoin.pUidList); code = nodesMakeList(&pDynCtrl->stbJoin.pUidList);
if (NULL == pDynCtrl->stbJoin.pUidList) {
code = code;
}
} }
SJoinLogicNode* pHJoin = (SJoinLogicNode*)pPrev; SJoinLogicNode* pHJoin = (SJoinLogicNode*)pPrev;
code = nodesListStrictAppend(pDynCtrl->stbJoin.pUidList, nodesListGetNode(pHJoin->node.pTargets, 0)); if (TSDB_CODE_SUCCESS == code) {
code = nodesListStrictAppend(pDynCtrl->stbJoin.pUidList, nodesListGetNode(pHJoin->node.pTargets, 0));
}
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = nodesListStrictAppend(pDynCtrl->stbJoin.pUidList, nodesListGetNode(pHJoin->node.pTargets, 2)); code = nodesListStrictAppend(pDynCtrl->stbJoin.pUidList, nodesListGetNode(pHJoin->node.pTargets, 2));
} }
@ -6353,9 +6344,6 @@ static int32_t stbJoinOptCreateDynQueryCtrlNode(SLogicNode* pRoot, SLogicNode* p
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pDynCtrl->node.pTargets = NULL; pDynCtrl->node.pTargets = NULL;
code = nodesCloneList(pPost->pTargets, &pDynCtrl->node.pTargets); code = nodesCloneList(pPost->pTargets, &pDynCtrl->node.pTargets);
if (!pDynCtrl->node.pTargets) {
code = code;
}
} }
} }
@ -7117,10 +7105,9 @@ int32_t tsmaOptCreateTsmaScanCols(const STSMAOptUsefulTsma* pTsma, const SNodeLi
pCol->tableType = TSDB_SUPER_TABLE; pCol->tableType = TSDB_SUPER_TABLE;
pCol->tableId = pTsma->targetTbUid; pCol->tableId = pTsma->targetTbUid;
pCol->colType = COLUMN_TYPE_COLUMN; pCol->colType = COLUMN_TYPE_COLUMN;
strcpy(pCol->tableName, pTsma->targetTbName); tstrncpy(pCol->tableName, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
strcpy(pCol->dbName, pTsma->pTsma->targetDbFName); tstrncpy(pCol->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
strcpy(pCol->colName, pFunc->node.aliasName); tstrncpy(pCol->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
strcpy(pCol->node.aliasName, pFunc->node.aliasName);
pCol->node.resType.type = TSDB_DATA_TYPE_BINARY; pCol->node.resType.type = TSDB_DATA_TYPE_BINARY;
code = nodesListMakeStrictAppend(&pScanCols, (SNode*)pCol); code = nodesListMakeStrictAppend(&pScanCols, (SNode*)pCol);
} }
@ -7144,8 +7131,8 @@ static int32_t tsmaOptRewriteTag(const STSMAOptCtx* pTsmaOptCtx, const STSMAOptU
for (int32_t i = 0; i < pTsma->pTsma->pTags->size; ++i) { for (int32_t i = 0; i < pTsma->pTsma->pTags->size; ++i) {
const SSchema* pSchema = taosArrayGet(pTsma->pTsma->pTags, i); const SSchema* pSchema = taosArrayGet(pTsma->pTsma->pTags, i);
if (strcmp(pTagCol->colName, pSchema->name) == 0) { if (strcmp(pTagCol->colName, pSchema->name) == 0) {
strcpy(pTagCol->tableName, pTsma->targetTbName); tstrncpy(pTagCol->tableName, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
strcpy(pTagCol->tableAlias, pTsma->targetTbName); tstrncpy(pTagCol->tableAlias, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
pTagCol->tableId = pTsma->targetTbUid; pTagCol->tableId = pTsma->targetTbUid;
pTagCol->tableType = TSDB_SUPER_TABLE; pTagCol->tableType = TSDB_SUPER_TABLE;
pTagCol->colId = pSchema->colId; pTagCol->colId = pSchema->colId;
@ -7170,8 +7157,8 @@ static int32_t tsmaOptRewriteTbname(const STSMAOptCtx* pTsmaOptCtx, SNode** pTbN
nodesDestroyNode(*pTbNameNode); nodesDestroyNode(*pTbNameNode);
SColumnNode* pCol = (SColumnNode*)pRewrittenFunc; SColumnNode* pCol = (SColumnNode*)pRewrittenFunc;
const SSchema* pSchema = taosArrayGet(pTsma->pTsma->pTags, pTsma->pTsma->pTags->size - 1); const SSchema* pSchema = taosArrayGet(pTsma->pTsma->pTags, pTsma->pTsma->pTags->size - 1);
strcpy(pCol->tableName, pTsma->targetTbName); tstrncpy(pCol->tableName, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
strcpy(pCol->tableAlias, pTsma->targetTbName); tstrncpy(pCol->tableAlias, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
pCol->tableId = pTsma->targetTbUid; pCol->tableId = pTsma->targetTbUid;
pCol->tableType = TSDB_SUPER_TABLE; pCol->tableType = TSDB_SUPER_TABLE;
pCol->colId = pSchema->colId; pCol->colId = pSchema->colId;
@ -7296,7 +7283,7 @@ static int32_t tsmaOptRewriteScan(STSMAOptCtx* pTsmaOptCtx, SScanLogicNode* pNew
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
pNewScan->stableId = pTsma->pTsma->destTbUid; pNewScan->stableId = pTsma->pTsma->destTbUid;
pNewScan->tableId = pTsma->targetTbUid; pNewScan->tableId = pTsma->targetTbUid;
strcpy(pNewScan->tableName.tname, pTsma->targetTbName); tstrncpy(pNewScan->tableName.tname, pTsma->targetTbName, TSDB_TABLE_NAME_LEN);
} }
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
code = tsmaOptRewriteNodeList(pNewScan->pScanPseudoCols, pTsmaOptCtx, pTsma, true, true); code = tsmaOptRewriteNodeList(pNewScan->pScanPseudoCols, pTsmaOptCtx, pTsma, true, true);
@ -7349,12 +7336,12 @@ static int32_t tsmaOptCreateWStart(int8_t precision, SFunctionNode** pWStartOut)
if (NULL == pWStart) { if (NULL == pWStart) {
return code; return code;
} }
strcpy(pWStart->functionName, "_wstart"); tstrncpy(pWStart->functionName, "_wstart", TSDB_FUNC_NAME_LEN);
int64_t pointer = (int64_t)pWStart; int64_t pointer = (int64_t)pWStart;
char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0}; char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWStart->functionName, pointer); int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWStart->functionName, pointer);
(void)taosHashBinary(name, len); (void)taosHashBinary(name, len);
strncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN - 1); tstrncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN);
pWStart->node.resType.precision = precision; pWStart->node.resType.precision = precision;
code = fmGetFuncInfo(pWStart, NULL, 0); code = fmGetFuncInfo(pWStart, NULL, 0);
@ -7457,12 +7444,12 @@ static int32_t tsmaOptGeneratePlan(STSMAOptCtx* pTsmaOptCtx) {
for (int32_t j = 0; j < pTsmaOptCtx->pScan->pTsmas->size; ++j) { for (int32_t j = 0; j < pTsmaOptCtx->pScan->pTsmas->size; ++j) {
if (taosArrayGetP(pTsmaOptCtx->pScan->pTsmas, j) == pTsma->pTsma) { if (taosArrayGetP(pTsmaOptCtx->pScan->pTsmas, j) == pTsma->pTsma) {
const STsmaTargetTbInfo* ptbInfo = taosArrayGet(pTsmaOptCtx->pScan->pTsmaTargetTbInfo, j); const STsmaTargetTbInfo* ptbInfo = taosArrayGet(pTsmaOptCtx->pScan->pTsmaTargetTbInfo, j);
strcpy(pTsma->targetTbName, ptbInfo->tableName); tstrncpy(pTsma->targetTbName, ptbInfo->tableName, TSDB_TABLE_NAME_LEN);
pTsma->targetTbUid = ptbInfo->uid; pTsma->targetTbUid = ptbInfo->uid;
} }
} }
} else { } else {
strcpy(pTsma->targetTbName, pTsma->pTsma->targetTb); tstrncpy(pTsma->targetTbName, pTsma->pTsma->targetTb, TSDB_TABLE_NAME_LEN);
pTsma->targetTbUid = pTsma->pTsma->destTbUid; pTsma->targetTbUid = pTsma->pTsma->destTbUid;
} }
} }

View File

@ -40,9 +40,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) { if (!*ppKey) {
return terrno; return terrno;
} }
strcat(*ppKey, pStmtName); TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
strcat(*ppKey, "."); TAOS_STRNCAT(*ppKey, ".", 2);
strcat(*ppKey, pCol->node.aliasName); TAOS_STRNCAT(*ppKey, pCol->node.aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey)); *pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code; return code;
} else { } else {
@ -50,7 +50,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) { if (!*ppKey) {
return terrno; return terrno;
} }
strcat(*ppKey, pCol->node.aliasName); TAOS_STRNCAT(*ppKey, pCol->node.aliasName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey); *pLen = strlen(*ppKey);
return code; return code;
} }
@ -60,7 +60,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) { if (!*ppKey) {
return terrno; return terrno;
} }
strcat(*ppKey, pCol->colName); TAOS_STRNCAT(*ppKey, pCol->colName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey); *pLen = strlen(*ppKey);
return code; return code;
} }
@ -69,9 +69,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) { if (!*ppKey) {
return terrno; return terrno;
} }
strcat(*ppKey, pCol->tableAlias); TAOS_STRNCAT(*ppKey, pCol->tableAlias, TSDB_TABLE_NAME_LEN);
strcat(*ppKey, "."); TAOS_STRNCAT(*ppKey, ".", 2);
strcat(*ppKey, pCol->colName); TAOS_STRNCAT(*ppKey, pCol->colName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey)); *pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code; return code;
} else if (QUERY_NODE_FUNCTION == nodeType(pNode)) { } else if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
@ -84,9 +84,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) { if (!*ppKey) {
return terrno; return terrno;
} }
strcat(*ppKey, pStmtName); TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
strcat(*ppKey, "."); TAOS_STRNCAT(*ppKey, ".", 2);
strcat(*ppKey, ((SExprNode*)pNode)->aliasName); TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey)); *pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code; return code;
} }
@ -94,9 +94,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) { if (!*ppKey) {
return terrno; return terrno;
} }
strcat(*ppKey, pVal->literal); TAOS_STRNCAT(*ppKey, pVal->literal, strlen(pVal->literal));
strcat(*ppKey, "."); TAOS_STRNCAT(*ppKey, ".", 2);
strcat(*ppKey, ((SExprNode*)pNode)->aliasName); TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey)); *pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code; return code;
} }
@ -108,9 +108,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) { if (!*ppKey) {
return terrno; return terrno;
} }
strcat(*ppKey, pStmtName); TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
strcat(*ppKey, "."); TAOS_STRNCAT(*ppKey, ".", 2);
strcat(*ppKey, ((SExprNode*)pNode)->aliasName); TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey)); *pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code; return code;
} }
@ -119,7 +119,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) { if (!*ppKey) {
return terrno; return terrno;
} }
strcat(*ppKey, ((SExprNode*)pNode)->aliasName); TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey); *pLen = strlen(*ppKey);
return code; return code;
} }
@ -228,7 +228,7 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD
code = putSlotToHash(name, len, pDataBlockDesc->dataBlockId, slotId, pNode, pHash); code = putSlotToHash(name, len, pDataBlockDesc->dataBlockId, slotId, pNode, pHash);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
if (nodeType(pNode) == QUERY_NODE_COLUMN && ((SColumnNode*)pNode)->resIdx > 0) { if (nodeType(pNode) == QUERY_NODE_COLUMN && ((SColumnNode*)pNode)->resIdx > 0) {
sprintf(name + strlen(name), "_%d", ((SColumnNode*)pNode)->resIdx); snprintf(name + strlen(name), 16, "_%d", ((SColumnNode*)pNode)->resIdx);
code = putSlotToHash(name, strlen(name), pDataBlockDesc->dataBlockId, slotId, pNode, pProjIdxDescHash); code = putSlotToHash(name, strlen(name), pDataBlockDesc->dataBlockId, slotId, pNode, pProjIdxDescHash);
} }
} }
@ -395,7 +395,7 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
} }
SSlotIndex* pIndex = NULL; SSlotIndex* pIndex = NULL;
if (((SColumnNode*)pNode)->projRefIdx > 0) { if (((SColumnNode*)pNode)->projRefIdx > 0) {
sprintf(name + strlen(name), "_%d", ((SColumnNode*)pNode)->projRefIdx); snprintf(name + strlen(name), 16, "_%d", ((SColumnNode*)pNode)->projRefIdx);
pIndex = taosHashGet(pCxt->pLeftProjIdxHash, name, strlen(name)); pIndex = taosHashGet(pCxt->pLeftProjIdxHash, name, strlen(name));
if (!pIndex) { if (!pIndex) {
pIndex = taosHashGet(pCxt->pRightProdIdxHash, name, strlen(name)); pIndex = taosHashGet(pCxt->pRightProdIdxHash, name, strlen(name));
@ -566,9 +566,6 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS
if (TSDB_CODE_SUCCESS == code && NULL != pScanLogicNode->pScanPseudoCols) { if (TSDB_CODE_SUCCESS == code && NULL != pScanLogicNode->pScanPseudoCols) {
pScanPhysiNode->pScanPseudoCols = NULL; pScanPhysiNode->pScanPseudoCols = NULL;
code = nodesCloneList(pScanLogicNode->pScanPseudoCols, &pScanPhysiNode->pScanPseudoCols); code = nodesCloneList(pScanLogicNode->pScanPseudoCols, &pScanPhysiNode->pScanPseudoCols);
if (NULL == pScanPhysiNode->pScanPseudoCols) {
code = code;
}
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -588,9 +585,6 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS
if (NULL != pScanLogicNode->pTagCond) { if (NULL != pScanLogicNode->pTagCond) {
pSubplan->pTagCond = NULL; pSubplan->pTagCond = NULL;
code = nodesCloneNode(pScanLogicNode->pTagCond, &pSubplan->pTagCond); code = nodesCloneNode(pScanLogicNode->pTagCond, &pSubplan->pTagCond);
if (NULL == pSubplan->pTagCond) {
code = code;
}
} }
} }
@ -598,9 +592,6 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS
if (NULL != pScanLogicNode->pTagIndexCond) { if (NULL != pScanLogicNode->pTagIndexCond) {
pSubplan->pTagIndexCond = NULL; pSubplan->pTagIndexCond = NULL;
code = nodesCloneNode(pScanLogicNode->pTagIndexCond, &pSubplan->pTagIndexCond); code = nodesCloneNode(pScanLogicNode->pTagIndexCond, &pSubplan->pTagIndexCond);
if (NULL == pSubplan->pTagIndexCond) {
code = code;
}
} }
} }
@ -1690,11 +1681,11 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode)
SExprNode* pRewrittenExpr = (SExprNode*)pExpr; SExprNode* pRewrittenExpr = (SExprNode*)pExpr;
pCol->node.resType = pRewrittenExpr->resType; pCol->node.resType = pRewrittenExpr->resType;
if ('\0' != pRewrittenExpr->aliasName[0]) { if ('\0' != pRewrittenExpr->aliasName[0]) {
strcpy(pCol->colName, pRewrittenExpr->aliasName); tstrncpy(pCol->colName, pRewrittenExpr->aliasName, TSDB_COL_NAME_LEN);
} else { } else {
snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId, snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId,
pCxt->rewriteId); pCxt->rewriteId);
strcpy(pCol->colName, pRewrittenExpr->aliasName); tstrncpy(pCol->colName, pRewrittenExpr->aliasName, TSDB_COL_NAME_LEN);
} }
nodesDestroyNode(*pNode); nodesDestroyNode(*pNode);
*pNode = (SNode*)pCol; *pNode = (SNode*)pCol;
@ -1715,7 +1706,7 @@ static int32_t rewriteValueToOperator(SRewritePrecalcExprsCxt* pCxt, SNode** pNo
} }
SValueNode* pVal = (SValueNode*)*pNode; SValueNode* pVal = (SValueNode*)*pNode;
pOper->node.resType = pVal->node.resType; pOper->node.resType = pVal->node.resType;
strcpy(pOper->node.aliasName, pVal->node.aliasName); tstrncpy(pOper->node.aliasName, pVal->node.aliasName, TSDB_COL_NAME_LEN);
pOper->opType = OP_TYPE_ASSIGN; pOper->opType = OP_TYPE_ASSIGN;
pOper->pRight = *pNode; pOper->pRight = *pNode;
*pNode = (SNode*)pOper; *pNode = (SNode*)pOper;
@ -1976,9 +1967,6 @@ static int32_t createInterpFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pCh
pInterpFunc->rangeInterval = pFuncLogicNode->rangeInterval; pInterpFunc->rangeInterval = pFuncLogicNode->rangeInterval;
pInterpFunc->rangeIntervalUnit = pFuncLogicNode->rangeIntervalUnit; pInterpFunc->rangeIntervalUnit = pFuncLogicNode->rangeIntervalUnit;
code = nodesCloneNode(pFuncLogicNode->pFillValues, &pInterpFunc->pFillValues); code = nodesCloneNode(pFuncLogicNode->pFillValues, &pInterpFunc->pFillValues);
if (TSDB_CODE_SUCCESS != code) {
code = code;
}
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -2894,7 +2882,7 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod
pInserter->tableId = pModify->tableId; pInserter->tableId = pModify->tableId;
pInserter->stableId = pModify->stableId; pInserter->stableId = pModify->stableId;
pInserter->tableType = pModify->tableType; pInserter->tableType = pModify->tableType;
strcpy(pInserter->tableName, pModify->tableName); tstrncpy(pInserter->tableName, pModify->tableName, TSDB_TABLE_NAME_LEN);
pInserter->explain = (QUERY_NODE_EXPLAIN_STMT == nodeType(pCxt->pPlanCxt->pAstRoot) ? true : false); pInserter->explain = (QUERY_NODE_EXPLAIN_STMT == nodeType(pCxt->pPlanCxt->pAstRoot) ? true : false);
if (pModify->pVgroupList) { if (pModify->pVgroupList) {
pInserter->vgId = pModify->pVgroupList->vgroups[0].vgId; pInserter->vgId = pModify->pVgroupList->vgroups[0].vgId;
@ -2906,9 +2894,6 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pInserter->sink.pInputDataBlockDesc = NULL; pInserter->sink.pInputDataBlockDesc = NULL;
code = nodesCloneNode((SNode*)pSubplan->pNode->pOutputDataBlockDesc, (SNode**)&pInserter->sink.pInputDataBlockDesc); code = nodesCloneNode((SNode*)pSubplan->pNode->pOutputDataBlockDesc, (SNode**)&pInserter->sink.pInputDataBlockDesc);
if (NULL == pInserter->sink.pInputDataBlockDesc) {
code = code;
}
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -2947,8 +2932,8 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode*
pDeleter->tableId = pModify->tableId; pDeleter->tableId = pModify->tableId;
pDeleter->tableType = pModify->tableType; pDeleter->tableType = pModify->tableType;
strcpy(pDeleter->tableFName, pModify->tableName); tstrncpy(pDeleter->tableFName, pModify->tableName, TSDB_TABLE_NAME_LEN);
strcpy(pDeleter->tsColName, pModify->tsColName); tstrncpy(pDeleter->tsColName, pModify->tsColName, TSDB_COL_NAME_LEN);
pDeleter->deleteTimeRange = pModify->deleteTimeRange; pDeleter->deleteTimeRange = pModify->deleteTimeRange;
code = setNodeSlotId(pCxt, pRoot->pOutputDataBlockDesc->dataBlockId, -1, pModify->pAffectedRows, code = setNodeSlotId(pCxt, pRoot->pOutputDataBlockDesc->dataBlockId, -1, pModify->pAffectedRows,
@ -2962,9 +2947,6 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode*
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pDeleter->sink.pInputDataBlockDesc = NULL; pDeleter->sink.pInputDataBlockDesc = NULL;
code = nodesCloneNode((SNode*)pRoot->pOutputDataBlockDesc, (SNode**)&pDeleter->sink.pInputDataBlockDesc); code = nodesCloneNode((SNode*)pRoot->pOutputDataBlockDesc, (SNode**)&pDeleter->sink.pInputDataBlockDesc);
if (NULL == pDeleter->sink.pInputDataBlockDesc) {
code = code;
}
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {

View File

@ -428,12 +428,12 @@ static int32_t stbSplAppendWStart(SNodeList* pFuncs, int32_t* pIndex, uint8_t pr
if (NULL == pWStart) { if (NULL == pWStart) {
return code; return code;
} }
strcpy(pWStart->functionName, "_wstart"); tstrncpy(pWStart->functionName, "_wstart", TSDB_FUNC_NAME_LEN);
int64_t pointer = (int64_t)pWStart; int64_t pointer = (int64_t)pWStart;
char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0}; char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWStart->functionName, pointer); int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWStart->functionName, pointer);
(void)taosHashBinary(name, len); (void)taosHashBinary(name, len);
strncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN - 1); tstrncpy(pWStart->node.aliasName, name, TSDB_COL_NAME_LEN);
pWStart->node.resType.precision = precision; pWStart->node.resType.precision = precision;
code = fmGetFuncInfo(pWStart, NULL, 0); code = fmGetFuncInfo(pWStart, NULL, 0);
@ -460,12 +460,12 @@ static int32_t stbSplAppendWEnd(SWindowLogicNode* pWin, int32_t* pIndex) {
if (NULL == pWEnd) { if (NULL == pWEnd) {
return code; return code;
} }
strcpy(pWEnd->functionName, "_wend"); tstrncpy(pWEnd->functionName, "_wend", TSDB_FUNC_NAME_LEN);
int64_t pointer = (int64_t)pWEnd; int64_t pointer = (int64_t)pWEnd;
char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0}; char name[TSDB_COL_NAME_LEN + TSDB_POINTER_PRINT_BYTES + TSDB_NAME_DELIMITER_LEN + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWEnd->functionName, pointer); int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%" PRId64 "", pWEnd->functionName, pointer);
(void)taosHashBinary(name, len); (void)taosHashBinary(name, len);
strncpy(pWEnd->node.aliasName, name, TSDB_COL_NAME_LEN - 1); tstrncpy(pWEnd->node.aliasName, name, TSDB_COL_NAME_LEN);
code = fmGetFuncInfo(pWEnd, NULL, 0); code = fmGetFuncInfo(pWEnd, NULL, 0);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -1135,8 +1135,8 @@ static int32_t stbSplAggNodeCreateMerge(SSplitContext* pCtx, SStableSplitInfo* p
if (!nodesEqualNode(pParam, (SNode*)pCol)) continue; if (!nodesEqualNode(pParam, (SNode*)pCol)) continue;
// use the colName of group_key func to make sure finding the right slot id for merge keys. // use the colName of group_key func to make sure finding the right slot id for merge keys.
strcpy(pCol->colName, pFunc->node.aliasName); tstrncpy(pCol->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
strcpy(pCol->node.aliasName, pFunc->node.aliasName); tstrncpy(pCol->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
memset(pCol->tableAlias, 0, TSDB_TABLE_NAME_LEN); memset(pCol->tableAlias, 0, TSDB_TABLE_NAME_LEN);
break; break;
} }
@ -1265,15 +1265,15 @@ static int32_t stbSplCreateColumnNode(SExprNode* pExpr, SNode** ppNode) {
return code; return code;
} }
if (QUERY_NODE_COLUMN == nodeType(pExpr)) { if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
strcpy(pCol->dbName, ((SColumnNode*)pExpr)->dbName); tstrncpy(pCol->dbName, ((SColumnNode*)pExpr)->dbName, TSDB_DB_NAME_LEN);
strcpy(pCol->tableName, ((SColumnNode*)pExpr)->tableName); tstrncpy(pCol->tableName, ((SColumnNode*)pExpr)->tableName, TSDB_TABLE_NAME_LEN);
strcpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias); tstrncpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias, TSDB_TABLE_NAME_LEN);
strcpy(pCol->colName, ((SColumnNode*)pExpr)->colName); tstrncpy(pCol->colName, ((SColumnNode*)pExpr)->colName, TSDB_COL_NAME_LEN);
} else { } else {
strcpy(pCol->colName, pExpr->aliasName); tstrncpy(pCol->colName, pExpr->aliasName, TSDB_COL_NAME_LEN);
} }
strcpy(pCol->node.aliasName, pExpr->aliasName); tstrncpy(pCol->node.aliasName, pExpr->aliasName, TSDB_COL_NAME_LEN);
strcpy(pCol->node.userAlias, pExpr->userAlias); tstrncpy(pCol->node.userAlias, pExpr->userAlias, TSDB_COL_NAME_LEN);
pCol->node.resType = pExpr->resType; pCol->node.resType = pExpr->resType;
*ppNode = (SNode*)pCol; *ppNode = (SNode*)pCol;
return code; return code;
@ -1358,9 +1358,6 @@ static int32_t stbSplCreatePartSortNode(SSortLogicNode* pSort, SLogicNode** pOut
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SSortLogicNode* pPartSort = NULL; SSortLogicNode* pPartSort = NULL;
code = nodesCloneNode((SNode*)pSort, (SNode**)&pPartSort); code = nodesCloneNode((SNode*)pSort, (SNode**)&pPartSort);
if (NULL == pPartSort) {
code = code;
}
SNodeList* pMergeKeys = NULL; SNodeList* pMergeKeys = NULL;
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -1541,9 +1538,6 @@ static int32_t stbSplCreateMergeScanNode(SScanLogicNode* pScan, SLogicNode** pOu
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SScanLogicNode* pMergeScan = NULL; SScanLogicNode* pMergeScan = NULL;
code = nodesCloneNode((SNode*)pScan, (SNode**)&pMergeScan); code = nodesCloneNode((SNode*)pScan, (SNode**)&pMergeScan);
if (NULL == pMergeScan) {
code = code;
}
SNodeList* pMergeKeys = NULL; SNodeList* pMergeKeys = NULL;
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {

View File

@ -68,14 +68,14 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) {
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
pCol->node.resType = pExpr->resType; pCol->node.resType = pExpr->resType;
strcpy(pCol->colName, pExpr->aliasName); tstrncpy(pCol->colName, pExpr->aliasName, TSDB_COL_NAME_LEN);
if (QUERY_NODE_FUNCTION == nodeType(pNode)) { if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
SFunctionNode* pFunc = (SFunctionNode*)pNode; SFunctionNode* pFunc = (SFunctionNode*)pNode;
if (pFunc->funcType == FUNCTION_TYPE_TBNAME) { if (pFunc->funcType == FUNCTION_TYPE_TBNAME) {
SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0); SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0);
if (NULL != pVal) { if (NULL != pVal) {
strcpy(pCol->tableAlias, pVal->literal); tstrncpy(pCol->tableAlias, pVal->literal, TSDB_TABLE_NAME_LEN);
strcpy(pCol->tableName, pVal->literal); tstrncpy(pCol->tableName, pVal->literal, TSDB_TABLE_NAME_LEN);
} }
} }
} }
@ -636,9 +636,9 @@ SFunctionNode* createGroupKeyAggFunc(SColumnNode* pGroupCol) {
SFunctionNode* pFunc = NULL; SFunctionNode* pFunc = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc); int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
if (pFunc) { if (pFunc) {
strcpy(pFunc->functionName, "_group_key"); tstrncpy(pFunc->functionName, "_group_key", TSDB_FUNC_NAME_LEN);
strcpy(pFunc->node.aliasName, pGroupCol->node.aliasName); tstrncpy(pFunc->node.aliasName, pGroupCol->node.aliasName, TSDB_COL_NAME_LEN);
strcpy(pFunc->node.userAlias, pGroupCol->node.userAlias); tstrncpy(pFunc->node.userAlias, pGroupCol->node.userAlias, TSDB_COL_NAME_LEN);
SNode* pNew = NULL; SNode* pNew = NULL;
code = nodesCloneNode((SNode*)pGroupCol, &pNew); code = nodesCloneNode((SNode*)pGroupCol, &pNew);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -655,7 +655,7 @@ SFunctionNode* createGroupKeyAggFunc(SColumnNode* pGroupCol) {
char name[TSDB_FUNC_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_POINTER_PRINT_BYTES + 1] = {0}; char name[TSDB_FUNC_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_POINTER_PRINT_BYTES + 1] = {0};
int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%p", pFunc->functionName, pFunc); int32_t len = tsnprintf(name, sizeof(name) - 1, "%s.%p", pFunc->functionName, pFunc);
(void)taosHashBinary(name, len); (void)taosHashBinary(name, len);
strncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN - 1); tstrncpy(pFunc->node.aliasName, name, TSDB_COL_NAME_LEN);
} }
} }
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {

View File

@ -1249,7 +1249,6 @@ EDealRes sclRewriteFunction(SNode **pNode, SScalarCtx *ctx) {
ctx->code = TSDB_CODE_OUT_OF_MEMORY; ctx->code = TSDB_CODE_OUT_OF_MEMORY;
return DEAL_RES_ERROR; return DEAL_RES_ERROR;
} }
res->node.resType.bytes = varDataTLen(output.columnData->pData);
(void)memcpy(res->datum.p, output.columnData->pData, varDataTLen(output.columnData->pData)); (void)memcpy(res->datum.p, output.columnData->pData, varDataTLen(output.columnData->pData));
} else { } else {
ctx->code = nodesSetValueNodeValue(res, output.columnData->pData); ctx->code = nodesSetValueNodeValue(res, output.columnData->pData);

View File

@ -1129,7 +1129,11 @@ int32_t schLaunchRemoteTask(SSchJob *pJob, SSchTask *pTask) {
int32_t schLaunchLocalTask(SSchJob *pJob, SSchTask *pTask) { int32_t schLaunchLocalTask(SSchJob *pJob, SSchTask *pTask) {
// SCH_ERR_JRET(schSetTaskCandidateAddrs(pJob, pTask)); // SCH_ERR_JRET(schSetTaskCandidateAddrs(pJob, pTask));
if (NULL == schMgmt.queryMgmt) { if (NULL == schMgmt.queryMgmt) {
SCH_ERR_RET(qWorkerInit(NODE_TYPE_CLIENT, CLIENT_HANDLE, (void **)&schMgmt.queryMgmt, NULL)); void* p = NULL;
SCH_ERR_RET(qWorkerInit(NODE_TYPE_CLIENT, CLIENT_HANDLE, &p, NULL));
if (atomic_val_compare_exchange_ptr(&schMgmt.queryMgmt, NULL, p)) {
qWorkerDestroy(&p);
}
} }
SArray *explainRes = NULL; SArray *explainRes = NULL;

View File

@ -37,7 +37,7 @@ extern "C" {
#define META_HB_CHECK_INTERVAL 200 #define META_HB_CHECK_INTERVAL 200
#define META_HB_SEND_IDLE_COUNTER 25 // send hb every 5 sec #define META_HB_SEND_IDLE_COUNTER 25 // send hb every 5 sec
#define STREAM_TASK_KEY_LEN ((sizeof(int64_t)) << 1) #define STREAM_TASK_KEY_LEN ((sizeof(int64_t)) << 1)
#define STREAM_TASK_QUEUE_CAPACITY 20480 #define STREAM_TASK_QUEUE_CAPACITY 5120
#define STREAM_TASK_QUEUE_CAPACITY_IN_SIZE (30) #define STREAM_TASK_QUEUE_CAPACITY_IN_SIZE (30)
// clang-format off // clang-format off

View File

@ -4378,7 +4378,6 @@ void streamStateParTagSeekKeyNext_rocksdb(SStreamState* pState, const int64_t gr
} }
int32_t streamStateParTagGetKVByCur_rocksdb(SStreamStateCur* pCur, int64_t* pGroupId, const void** pVal, int32_t* pVLen) { int32_t streamStateParTagGetKVByCur_rocksdb(SStreamStateCur* pCur, int64_t* pGroupId, const void** pVal, int32_t* pVLen) {
stDebug("streamStateFillGetKVByCur_rocksdb");
if (!pCur) { if (!pCur) {
return -1; return -1;
} }

View File

@ -613,7 +613,6 @@ int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SV
{ // destroy the related fill-history tasks { // destroy the related fill-history tasks
// drop task should not in the meta-lock, and drop the related fill-history task now // drop task should not in the meta-lock, and drop the related fill-history task now
streamMetaWUnLock(pMeta);
if (pReq->dropRelHTask) { if (pReq->dropRelHTask) {
code = streamMetaUnregisterTask(pMeta, pReq->hStreamId, pReq->hTaskId); code = streamMetaUnregisterTask(pMeta, pReq->hStreamId, pReq->hTaskId);
int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta); int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta);
@ -621,7 +620,6 @@ int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SV
id, vgId, pReq->taskId, numOfTasks); id, vgId, pReq->taskId, numOfTasks);
} }
streamMetaWLock(pMeta);
if (pReq->dropRelHTask) { if (pReq->dropRelHTask) {
code = streamMetaCommit(pMeta); code = streamMetaCommit(pMeta);
} }
@ -656,9 +654,11 @@ int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SV
pInfo->processedVer <= pReq->checkpointVer); pInfo->processedVer <= pReq->checkpointVer);
if (!valid) { if (!valid) {
stFatal("invalid checkpoint id check, current checkpointId:%" PRId64 " checkpointVer:%" PRId64 stFatal("s-task:%s invalid checkpointId update info recv, current checkpointId:%" PRId64 " checkpointVer:%" PRId64
" processedVer:%" PRId64 " req checkpointId:%" PRId64 " checkpointVer:%" PRId64, " processedVer:%" PRId64 " req checkpointId:%" PRId64 " checkpointVer:%" PRId64 " discard it",
pInfo->checkpointId, pInfo->checkpointVer, pInfo->processedVer, pReq->checkpointId, pReq->checkpointVer); id, pInfo->checkpointId, pInfo->checkpointVer, pInfo->processedVer, pReq->checkpointId,
pReq->checkpointVer);
streamMutexUnlock(&pTask->lock);
return TSDB_CODE_STREAM_INTERNAL_ERROR; return TSDB_CODE_STREAM_INTERNAL_ERROR;
} }
@ -695,8 +695,6 @@ int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SV
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
streamMetaWUnLock(pMeta);
// drop task should not in the meta-lock, and drop the related fill-history task now // drop task should not in the meta-lock, and drop the related fill-history task now
if (pReq->dropRelHTask) { if (pReq->dropRelHTask) {
code = streamMetaUnregisterTask(pMeta, pReq->hStreamId, pReq->hTaskId); code = streamMetaUnregisterTask(pMeta, pReq->hStreamId, pReq->hTaskId);
@ -705,9 +703,7 @@ int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SV
(int32_t)pReq->hTaskId, numOfTasks); (int32_t)pReq->hTaskId, numOfTasks);
} }
streamMetaWLock(pMeta);
code = streamMetaCommit(pMeta); code = streamMetaCommit(pMeta);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -522,7 +522,10 @@ static int32_t doSetStreamInputBlock(SStreamTask* pTask, const void* pInput, int
if (pItem->type == STREAM_INPUT__GET_RES) { if (pItem->type == STREAM_INPUT__GET_RES) {
const SStreamTrigger* pTrigger = (const SStreamTrigger*)pInput; const SStreamTrigger* pTrigger = (const SStreamTrigger*)pInput;
code = qSetMultiStreamInput(pExecutor, pTrigger->pBlock, 1, STREAM_INPUT__DATA_BLOCK); code = qSetMultiStreamInput(pExecutor, pTrigger->pBlock, 1, STREAM_INPUT__DATA_BLOCK);
if (pTask->info.trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) {
stDebug("s-task:%s set force_window_close as source block, skey:%"PRId64, id, pTrigger->pBlock->info.window.skey);
(*pVer) = pTrigger->pBlock->info.window.skey;
}
} else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) { } else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
const SStreamDataSubmit* pSubmit = (const SStreamDataSubmit*)pInput; const SStreamDataSubmit* pSubmit = (const SStreamDataSubmit*)pInput;
code = qSetMultiStreamInput(pExecutor, &pSubmit->submit, 1, STREAM_INPUT__DATA_SUBMIT); code = qSetMultiStreamInput(pExecutor, &pSubmit->submit, 1, STREAM_INPUT__DATA_SUBMIT);
@ -671,7 +674,7 @@ static int32_t doStreamTaskExecImpl(SStreamTask* pTask, SStreamQueueItem* pBlock
doRecordThroughput(&pTask->execInfo, totalBlocks, totalSize, blockSize, st, pTask->id.idStr); doRecordThroughput(&pTask->execInfo, totalBlocks, totalSize, blockSize, st, pTask->id.idStr);
// update the currentVer if processing the submit blocks. // update the currentVer if processing the submitted blocks.
if (!(pInfo->checkpointVer <= pInfo->nextProcessVer && ver >= pInfo->checkpointVer)) { if (!(pInfo->checkpointVer <= pInfo->nextProcessVer && ver >= pInfo->checkpointVer)) {
stError("s-task:%s invalid info, checkpointVer:%" PRId64 ", nextProcessVer:%" PRId64 " currentVer:%" PRId64, id, stError("s-task:%s invalid info, checkpointVer:%" PRId64 ", nextProcessVer:%" PRId64 " currentVer:%" PRId64, id,
pInfo->checkpointVer, pInfo->nextProcessVer, ver); pInfo->checkpointVer, pInfo->nextProcessVer, ver);
@ -688,6 +691,34 @@ static int32_t doStreamTaskExecImpl(SStreamTask* pTask, SStreamQueueItem* pBlock
return code; return code;
} }
// do nothing after sync executor state to storage backend, untill checkpoint is completed.
static int32_t doHandleChkptBlock(SStreamTask* pTask) {
int32_t code = 0;
const char* id = pTask->id.idStr;
streamMutexLock(&pTask->lock);
SStreamTaskState pState = streamTaskGetStatus(pTask);
if (pState.state == TASK_STATUS__CK) { // todo other thread may change the status
stDebug("s-task:%s checkpoint block received, set status:%s", id, pState.name);
code = streamTaskBuildCheckpoint(pTask); // ignore this error msg, and continue
} else { // todo refactor
if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) {
code = streamTaskSendCheckpointSourceRsp(pTask);
} else {
code = streamTaskSendCheckpointReadyMsg(pTask);
}
if (code != TSDB_CODE_SUCCESS) {
// todo: let's retry send rsp to upstream/mnode
stError("s-task:%s failed to send checkpoint rsp to upstream, checkpointId:%d, code:%s", id, 0,
tstrerror(code));
}
}
streamMutexUnlock(&pTask->lock);
return code;
}
int32_t flushStateDataInExecutor(SStreamTask* pTask, SStreamQueueItem* pCheckpointBlock) { int32_t flushStateDataInExecutor(SStreamTask* pTask, SStreamQueueItem* pCheckpointBlock) {
const char* id = pTask->id.idStr; const char* id = pTask->id.idStr;
@ -832,36 +863,16 @@ static int32_t doStreamExecTask(SStreamTask* pTask) {
} }
} }
if (type != STREAM_INPUT__CHECKPOINT) { if (type == STREAM_INPUT__CHECKPOINT) {
code = doHandleChkptBlock(pTask);
streamFreeQitem(pInput);
return code;
} else {
code = doStreamTaskExecImpl(pTask, pInput, numOfBlocks); code = doStreamTaskExecImpl(pTask, pInput, numOfBlocks);
streamFreeQitem(pInput); streamFreeQitem(pInput);
if (code) { if (code) {
return code; return code;
} }
} else { // todo other thread may change the status
// do nothing after sync executor state to storage backend, untill the vnode-level checkpoint is completed.
streamMutexLock(&pTask->lock);
SStreamTaskState pState = streamTaskGetStatus(pTask);
if (pState.state == TASK_STATUS__CK) {
stDebug("s-task:%s checkpoint block received, set status:%s", id, pState.name);
code = streamTaskBuildCheckpoint(pTask); // ignore this error msg, and continue
} else { // todo refactor
if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) {
code = streamTaskSendCheckpointSourceRsp(pTask);
} else {
code = streamTaskSendCheckpointReadyMsg(pTask);
}
if (code != TSDB_CODE_SUCCESS) {
// todo: let's retry send rsp to upstream/mnode
stError("s-task:%s failed to send checkpoint rsp to upstream, checkpointId:%d, code:%s", id, 0,
tstrerror(code));
}
}
streamMutexUnlock(&pTask->lock);
streamFreeQitem(pInput);
return code;
} }
} }
} }

View File

@ -501,8 +501,6 @@ _err:
void streamMetaInitBackend(SStreamMeta* pMeta) { void streamMetaInitBackend(SStreamMeta* pMeta) {
pMeta->streamBackend = streamBackendInit(pMeta->path, pMeta->chkpId, pMeta->vgId); pMeta->streamBackend = streamBackendInit(pMeta->path, pMeta->chkpId, pMeta->vgId);
if (pMeta->streamBackend == NULL) { if (pMeta->streamBackend == NULL) {
streamMetaWUnLock(pMeta);
while (1) { while (1) {
streamMetaWLock(pMeta); streamMetaWLock(pMeta);
pMeta->streamBackend = streamBackendInit(pMeta->path, pMeta->chkpId, pMeta->vgId); pMeta->streamBackend = streamBackendInit(pMeta->path, pMeta->chkpId, pMeta->vgId);
@ -908,8 +906,6 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t
int32_t code = 0; int32_t code = 0;
STaskId id = {.streamId = streamId, .taskId = taskId}; STaskId id = {.streamId = streamId, .taskId = taskId};
streamMetaWLock(pMeta);
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask); code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
if (code == 0) { if (code == 0) {
// desc the paused task counter // desc the paused task counter
@ -958,10 +954,8 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t
} }
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);
streamMetaWUnLock(pMeta);
} else { } else {
stDebug("vgId:%d failed to find the task:0x%x, it may have been dropped already", vgId, taskId); stDebug("vgId:%d failed to find the task:0x%x, it may have been dropped already", vgId, taskId);
streamMetaWUnLock(pMeta);
} }
return 0; return 0;

View File

@ -211,6 +211,7 @@ static int32_t doCreateForceWindowTrigger(SStreamTask* pTask, int32_t* pNextTrig
const char* id = pTask->id.idStr; const char* id = pTask->id.idStr;
int8_t precision = pTask->info.interval.precision; int8_t precision = pTask->info.interval.precision;
SStreamTrigger* pTrigger = NULL; SStreamTrigger* pTrigger = NULL;
bool isFull = false;
while (1) { while (1) {
code = streamCreateForcewindowTrigger(&pTrigger, pTask->info.delaySchedParam, &pTask->info.interval, code = streamCreateForcewindowTrigger(&pTrigger, pTask->info.delaySchedParam, &pTask->info.interval,
@ -233,7 +234,6 @@ static int32_t doCreateForceWindowTrigger(SStreamTask* pTask, int32_t* pNextTrig
// check whether the time window gaps exist or not // check whether the time window gaps exist or not
int64_t now = taosGetTimestamp(precision); int64_t now = taosGetTimestamp(precision);
int64_t ekey = pTrigger->pBlock->info.window.skey + pTask->info.interval.interval;
// there are gaps, needs to be filled // there are gaps, needs to be filled
STimeWindow w = pTrigger->pBlock->info.window; STimeWindow w = pTrigger->pBlock->info.window;
@ -245,13 +245,18 @@ static int32_t doCreateForceWindowTrigger(SStreamTask* pTask, int32_t* pNextTrig
} }
pTask->status.latestForceWindow = w; pTask->status.latestForceWindow = w;
if (ekey + pTask->info.watermark + pTask->info.interval.interval > now) { isFull = streamQueueIsFull(pTask->inputq.queue);
int64_t prev = convertTimePrecision(*pNextTrigger, precision, TSDB_TIME_PRECISION_MILLI);
if ((w.ekey + pTask->info.watermark + pTask->info.interval.interval > now) || isFull) {
int64_t prev = convertTimePrecision(*pNextTrigger, precision, TSDB_TIME_PRECISION_MILLI);
if (!isFull) {
*pNextTrigger = w.ekey + pTask->info.watermark + pTask->info.interval.interval - now;
}
*pNextTrigger = ekey + pTask->info.watermark + pTask->info.interval.interval - now;
*pNextTrigger = convertTimePrecision(*pNextTrigger, precision, TSDB_TIME_PRECISION_MILLI); *pNextTrigger = convertTimePrecision(*pNextTrigger, precision, TSDB_TIME_PRECISION_MILLI);
stDebug("s-task:%s generate %d time window(s), trigger delay adjust from %" PRId64 " to %d", id, num, prev, pTask->chkInfo.nextProcessVer = w.ekey + pTask->info.interval.interval;
*pNextTrigger); stDebug("s-task:%s generate %d time window(s), trigger delay adjust from %" PRId64 " to %d, set ver:%" PRId64, id,
num, prev, *pNextTrigger, pTask->chkInfo.nextProcessVer);
return code; return code;
} else { } else {
stDebug("s-task:%s gap exist for force_window_close, current force_window_skey:%" PRId64, id, w.skey); stDebug("s-task:%s gap exist for force_window_close, current force_window_skey:%" PRId64, id, w.skey);
@ -308,7 +313,7 @@ void streamTaskSchedHelper(void* param, void* tmrId) {
} }
if (streamTaskGetStatus(pTask).state == TASK_STATUS__CK) { if (streamTaskGetStatus(pTask).state == TASK_STATUS__CK) {
nextTrigger = TRIGGER_RECHECK_INTERVAL; // retry in 10 seec nextTrigger = TRIGGER_RECHECK_INTERVAL; // retry in 10 sec
stDebug("s-task:%s in checkpoint procedure, not retrieve result, next:%dms", id, TRIGGER_RECHECK_INTERVAL); stDebug("s-task:%s in checkpoint procedure, not retrieve result, next:%dms", id, TRIGGER_RECHECK_INTERVAL);
} else { } else {
if (pTask->info.trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE && pTask->info.taskLevel == TASK_LEVEL__SOURCE) { if (pTask->info.trigger == STREAM_TRIGGER_FORCE_WINDOW_CLOSE && pTask->info.taskLevel == TASK_LEVEL__SOURCE) {

View File

@ -947,6 +947,7 @@ int32_t recoverSession(SStreamFileState* pFileState, int64_t ckId) {
} }
SRowBuffPos* pPos = createSessionWinBuff(pFileState, &key, pVal, &vlen); SRowBuffPos* pPos = createSessionWinBuff(pFileState, &key, pVal, &vlen);
pPos->beUsed = false;
winRes = putSessionWinResultBuff(pFileState, pPos); winRes = putSessionWinResultBuff(pFileState, pPos);
if (winRes != TSDB_CODE_SUCCESS) { if (winRes != TSDB_CODE_SUCCESS) {
break; break;
@ -1008,6 +1009,7 @@ int32_t recoverSnapshot(SStreamFileState* pFileState, int64_t ckId) {
memcpy(pNewPos->pRowBuff, pVal, vlen); memcpy(pNewPos->pRowBuff, pVal, vlen);
taosMemoryFreeClear(pVal); taosMemoryFreeClear(pVal);
pNewPos->beFlushed = true; pNewPos->beFlushed = true;
pNewPos->beUsed = false;
qDebug("===stream=== read checkpoint state from disc. %s", __func__); qDebug("===stream=== read checkpoint state from disc. %s", __func__);
code = tSimpleHashPut(pFileState->rowStateBuff, pNewPos->pKey, pFileState->keyLen, &pNewPos, POINTER_BYTES); code = tSimpleHashPut(pFileState->rowStateBuff, pNewPos->pKey, pFileState->keyLen, &pNewPos, POINTER_BYTES);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
@ -1090,6 +1092,7 @@ int32_t recoverFillSnapshot(SStreamFileState* pFileState, int64_t ckId) {
if (vlen != pFileState->rowSize) { if (vlen != pFileState->rowSize) {
qError("row size mismatch, expect:%d, actual:%d", pFileState->rowSize, vlen); qError("row size mismatch, expect:%d, actual:%d", pFileState->rowSize, vlen);
destroyRowBuffPos(pNewPos);
code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
taosMemoryFreeClear(pVal); taosMemoryFreeClear(pVal);
QUERY_CHECK_CODE(code, lino, _end); QUERY_CHECK_CODE(code, lino, _end);
@ -1098,6 +1101,7 @@ int32_t recoverFillSnapshot(SStreamFileState* pFileState, int64_t ckId) {
memcpy(pNewPos->pRowBuff, pVal, vlen); memcpy(pNewPos->pRowBuff, pVal, vlen);
taosMemoryFreeClear(pVal); taosMemoryFreeClear(pVal);
pNewPos->beFlushed = true; pNewPos->beFlushed = true;
pNewPos->beUsed = false;
qDebug("===stream=== read checkpoint state from disc. %s", __func__); qDebug("===stream=== read checkpoint state from disc. %s", __func__);
winRes = tSimpleHashPut(pFileState->rowStateBuff, pNewPos->pKey, pFileState->keyLen, &pNewPos, POINTER_BYTES); winRes = tSimpleHashPut(pFileState->rowStateBuff, pNewPos->pKey, pFileState->keyLen, &pNewPos, POINTER_BYTES);
if (winRes != TSDB_CODE_SUCCESS) { if (winRes != TSDB_CODE_SUCCESS) {
@ -1228,6 +1232,8 @@ void setFillInfo(SStreamFileState* pFileState) {
} }
void clearExpiredState(SStreamFileState* pFileState) { void clearExpiredState(SStreamFileState* pFileState) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
SSHashObj* pSearchBuff = pFileState->searchBuff; SSHashObj* pSearchBuff = pFileState->searchBuff;
void* pIte = NULL; void* pIte = NULL;
int32_t iter = 0; int32_t iter = 0;
@ -1246,6 +1252,13 @@ void clearExpiredState(SStreamFileState* pFileState) {
} }
taosArrayRemoveBatch(pWinStates, 0, size - 1, NULL); taosArrayRemoveBatch(pWinStates, 0, size - 1, NULL);
} }
code = clearRowBuff(pFileState);
QUERY_CHECK_CODE(code, lino, _end);
_end:
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
}
} }
int32_t getStateSearchRowBuff(SStreamFileState* pFileState, const SWinKey* pKey, void** pVal, int32_t* pVLen, int32_t getStateSearchRowBuff(SStreamFileState* pFileState, const SWinKey* pKey, void** pVal, int32_t* pVLen,

View File

@ -1464,7 +1464,7 @@ int32_t syncNodeRestore(SSyncNode* pSyncNode) {
// 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); pSyncNode->commitIndex = TMAX(pSyncNode->commitIndex, commitIndex);
sInfo("vgId:%d, restore sync until commitIndex:%" PRId64, pSyncNode->vgId, pSyncNode->commitIndex); sInfo("vgId:%d, restore began, and keep syncing until commitIndex:%" PRId64, pSyncNode->vgId, pSyncNode->commitIndex);
if (pSyncNode->fsmState != SYNC_FSM_STATE_INCOMPLETE && if (pSyncNode->fsmState != SYNC_FSM_STATE_INCOMPLETE &&
(code = syncLogBufferCommit(pSyncNode->pLogBuf, pSyncNode, pSyncNode->commitIndex)) < 0) { (code = syncLogBufferCommit(pSyncNode->pLogBuf, pSyncNode, pSyncNode->commitIndex)) < 0) {

View File

@ -19,7 +19,6 @@
typedef union { typedef union {
volatile int64_t i; volatile int64_t i;
volatile double d; volatile double d;
//double d;
} double_number; } double_number;
#ifdef WINDOWS #ifdef WINDOWS
@ -345,7 +344,7 @@ void atomic_store_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
double atomic_store_double(double volatile *ptr, double val){ void atomic_store_double(double volatile* ptr, double val) {
for (;;) { for (;;) {
double_number old_num = {0}; double_number old_num = {0};
old_num.d = *ptr; // current old value old_num.d = *ptr; // current old value
@ -354,9 +353,9 @@ double atomic_store_double(double volatile *ptr, double val){
new_num.d = val; new_num.d = val;
double_number ret_num = {0}; double_number ret_num = {0};
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t *)ptr, old_num.i, new_num.i); ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
if (ret_num.i == old_num.i) return ret_num.d; if (ret_num.i == old_num.i) return;
} }
} }
@ -414,16 +413,16 @@ int64_t atomic_exchange_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
double atomic_exchange_double(double volatile *ptr, int64_t val){ double atomic_exchange_double(double volatile* ptr, double val) {
for (;;) { for (;;) {
double_number old_num = {0}; double_number old_num = {0};
old_num.d = *ptr; // current old value old_num.d = *ptr; // current old value
double_number new_num = {0}; double_number new_num = {0};
int64_t iNew = val; new_num.d = val;
double_number ret_num = {0}; double_number ret_num = {0};
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t *)ptr, old_num.i, new_num.i); ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
if (ret_num.i == old_num.i) { if (ret_num.i == old_num.i) {
return ret_num.d; return ret_num.d;
@ -589,7 +588,7 @@ int64_t atomic_fetch_add_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
double atomic_fetch_add_double(double volatile *ptr, double val){ double atomic_fetch_add_double(double volatile* ptr, double val) {
for (;;) { for (;;) {
double_number old_num = {0}; double_number old_num = {0};
old_num.d = *ptr; // current old value old_num.d = *ptr; // current old value
@ -598,13 +597,13 @@ double atomic_fetch_add_double(double volatile *ptr, double val){
new_num.d = old_num.d + val; new_num.d = old_num.d + val;
double_number ret_num = {0}; double_number ret_num = {0};
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t *)ptr, old_num.i, new_num.i); ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
if (ret_num.i == old_num.i) return ret_num.d; if (ret_num.i == old_num.i) return ret_num.d;
} }
} }
void* atomic_fetch_add_ptr(void* ptr, void* val) { void* atomic_fetch_add_ptr(void* ptr, int64_t val) {
#ifdef WINDOWS #ifdef WINDOWS
return _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)); return _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val));
#elif defined(_TD_NINGSI_60) #elif defined(_TD_NINGSI_60)
@ -710,7 +709,7 @@ int64_t atomic_fetch_sub_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
double atomic_fetch_sub_double(double volatile *ptr, double val){ double atomic_fetch_sub_double(double volatile* ptr, double val) {
for (;;) { for (;;) {
double_number old_num = {0}; double_number old_num = {0};
old_num.d = *ptr; // current old value old_num.d = *ptr; // current old value
@ -719,13 +718,13 @@ double atomic_fetch_sub_double(double volatile *ptr, double val){
new_num.d = old_num.d - val; new_num.d = old_num.d - val;
double_number ret_num = {0}; double_number ret_num = {0};
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t *)ptr, old_num.i, new_num.i); ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
if (ret_num.i == old_num.i) return ret_num.d; if (ret_num.i == old_num.i) return ret_num.d;
} }
} }
void* atomic_fetch_sub_ptr(void* ptr, void* val) { void* atomic_fetch_sub_ptr(void* ptr, int64_t val) {
#ifdef WINDOWS #ifdef WINDOWS
return interlocked_fetch_sub_ptr(ptr, val); return interlocked_fetch_sub_ptr(ptr, val);
#elif defined(_TD_NINGSI_60) #elif defined(_TD_NINGSI_60)
@ -777,7 +776,7 @@ int64_t atomic_and_fetch_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
void* atomic_and_fetch_ptr(void* ptr, void* val) { void* atomic_and_fetch_ptr(void* ptr, int64_t val) {
#ifdef WINDOWS #ifdef WINDOWS
return interlocked_and_fetch_ptr((void* volatile*)(ptr), (void*)(val)); return interlocked_and_fetch_ptr((void* volatile*)(ptr), (void*)(val));
#elif defined(_TD_NINGSI_60) #elif defined(_TD_NINGSI_60)
@ -829,7 +828,7 @@ int64_t atomic_fetch_and_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
void* atomic_fetch_and_ptr(void* ptr, void* val) { void* atomic_fetch_and_ptr(void* ptr, int64_t val) {
#ifdef WINDOWS #ifdef WINDOWS
return interlocked_fetch_and_ptr((void* volatile*)(ptr), (void*)(val)); return interlocked_fetch_and_ptr((void* volatile*)(ptr), (void*)(val));
#elif defined(_TD_NINGSI_60) #elif defined(_TD_NINGSI_60)
@ -881,7 +880,7 @@ int64_t atomic_or_fetch_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
void* atomic_or_fetch_ptr(void* ptr, void* val) { void* atomic_or_fetch_ptr(void* ptr, int64_t val) {
#ifdef WINDOWS #ifdef WINDOWS
return interlocked_or_fetch_ptr((void* volatile*)(ptr), (void*)(val)); return interlocked_or_fetch_ptr((void* volatile*)(ptr), (void*)(val));
#elif defined(_TD_NINGSI_60) #elif defined(_TD_NINGSI_60)
@ -933,7 +932,7 @@ int64_t atomic_fetch_or_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
void* atomic_fetch_or_ptr(void* ptr, void* val) { void* atomic_fetch_or_ptr(void* ptr, int64_t val) {
#ifdef WINDOWS #ifdef WINDOWS
return interlocked_fetch_or_ptr((void* volatile*)(ptr), (void*)(val)); return interlocked_fetch_or_ptr((void* volatile*)(ptr), (void*)(val));
#elif defined(_TD_NINGSI_60) #elif defined(_TD_NINGSI_60)
@ -985,7 +984,7 @@ int64_t atomic_xor_fetch_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
void* atomic_xor_fetch_ptr(void* ptr, void* val) { void* atomic_xor_fetch_ptr(void* ptr, int64_t val) {
#ifdef WINDOWS #ifdef WINDOWS
return interlocked_xor_fetch_ptr((void* volatile*)(ptr), (void*)(val)); return interlocked_xor_fetch_ptr((void* volatile*)(ptr), (void*)(val));
#elif defined(_TD_NINGSI_60) #elif defined(_TD_NINGSI_60)
@ -1037,7 +1036,7 @@ int64_t atomic_fetch_xor_64(int64_t volatile* ptr, int64_t val) {
#endif #endif
} }
void* atomic_fetch_xor_ptr(void* ptr, void* val) { void* atomic_fetch_xor_ptr(void* ptr, int64_t val) {
#ifdef WINDOWS #ifdef WINDOWS
return interlocked_fetch_xor_ptr((void* volatile*)(ptr), (void*)(val)); return interlocked_fetch_xor_ptr((void* volatile*)(ptr), (void*)(val));
#elif defined(_TD_NINGSI_60) #elif defined(_TD_NINGSI_60)

View File

@ -39,7 +39,7 @@ enum {
WRDE_SYNTAX /* Shell syntax error. */ WRDE_SYNTAX /* Shell syntax error. */
}; };
int wordexp(char *words, wordexp_t *pwordexp, int flags) { int32_t wordexp(char *words, wordexp_t *pwordexp, int32_t flags) {
pwordexp->we_offs = 0; pwordexp->we_offs = 0;
pwordexp->we_wordc = 1; pwordexp->we_wordc = 1;
pwordexp->we_wordv[0] = pwordexp->wordPos; pwordexp->we_wordv[0] = pwordexp->wordPos;
@ -197,14 +197,10 @@ int32_t taosMulMkDir(const char *dirname) {
} }
} }
if (code < 0 && errno == EEXIST) { return 0;
return 0;
}
return code;
} }
int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { int32_t taosMulModeMkDir(const char *dirname, int32_t mode, bool checkAccess) {
if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) { if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) {
terrno = TSDB_CODE_INVALID_PARA; terrno = TSDB_CODE_INVALID_PARA;
return terrno; return terrno;
@ -326,7 +322,7 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1); int32_t days = (int32_t)(TABS(sec - fileSec) / 86400 + 1);
if (days > keepDays) { if (days > keepDays) {
TAOS_UNUSED(taosRemoveFile(filename)); TAOS_UNUSED(taosRemoveFile(filename));
uInfo("file:%s is removed, days:%d keepDays:%d, sed:%" PRId64, filename, days, keepDays, fileSec); // printf("file:%s is removed, days:%d keepDays:%d, sed:%" PRId64, filename, days, keepDays, fileSec);
} else { } else {
// printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays); // printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
} }
@ -340,7 +336,9 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
OS_PARAM_CHECK(dirname); OS_PARAM_CHECK(dirname);
OS_PARAM_CHECK(outname); OS_PARAM_CHECK(outname);
wordexp_t full_path; if (dirname[0] == 0) return 0;
wordexp_t full_path = {0};
int32_t code = wordexp(dirname, &full_path, 0); int32_t code = wordexp(dirname, &full_path, 0);
switch (code) { switch (code) {
case 0: case 0:
@ -357,13 +355,12 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
} }
wordfree(&full_path); wordfree(&full_path);
return 0; return 0;
} }
int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) { int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
OS_PARAM_CHECK(dirname); OS_PARAM_CHECK(dirname);
OS_PARAM_CHECK(realPath);
char tmp[PATH_MAX] = {0}; char tmp[PATH_MAX] = {0};
#ifdef WINDOWS #ifdef WINDOWS
if (_fullpath(tmp, dirname, maxlen) != NULL) { if (_fullpath(tmp, dirname, maxlen) != NULL) {
@ -377,12 +374,14 @@ int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
tstrncpy(realPath, tmp, maxlen); tstrncpy(realPath, tmp, maxlen);
} }
return 0; return 0;
} else {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return terrno;
} }
} else {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
} }
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
} }
bool taosIsDir(const char *dirname) { bool taosIsDir(const char *dirname) {
@ -454,7 +453,7 @@ TdDirPtr taosOpenDir(const char *dirname) {
} }
#ifdef WINDOWS #ifdef WINDOWS
char szFind[MAX_PATH]; //这是要找的 char szFind[MAX_PATH]; // 这是要找的
HANDLE hFind; HANDLE hFind;
TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir)); TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir));
@ -462,7 +461,7 @@ TdDirPtr taosOpenDir(const char *dirname) {
return NULL; return NULL;
} }
snprintf(szFind, sizeof(szFind), "%s%s", dirname, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录 snprintf(szFind, sizeof(szFind), "%s%s", dirname, "\\*.*"); // 利用通配符找这个目录下的所以文件,包括目录
pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData)); pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
if (INVALID_HANDLE_VALUE == pDir->hFind) { if (INVALID_HANDLE_VALUE == pDir->hFind) {
@ -585,14 +584,14 @@ void taosGetCwd(char *buf, int32_t len) {
#endif #endif
} }
int taosGetDirSize(const char *path, int64_t *size) { int32_t taosGetDirSize(const char *path, int64_t *size) {
int32_t code; int32_t code = 0;
char fullPath[PATH_MAX + 100] = {0};
TdDirPtr pDir = taosOpenDir(path); TdDirPtr pDir = taosOpenDir(path);
if (pDir == NULL) { if (pDir == NULL) {
return code = terrno; return code = terrno;
} }
int32_t nBytes = 0;
char fullPath[1024] = {0};
int64_t totalSize = 0; int64_t totalSize = 0;
TdDirEntryPtr de = NULL; TdDirEntryPtr de = NULL;
@ -601,31 +600,23 @@ int taosGetDirSize(const char *path, int64_t *size) {
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) { if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
continue; continue;
} }
nBytes = snprintf(fullPath, sizeof(fullPath), "%s%s%s", path, TD_DIRSEP, name); (void)snprintf(fullPath, sizeof(fullPath), "%s%s%s", path, TD_DIRSEP, name);
if (nBytes <= 0 || nBytes >= sizeof(fullPath)) {
TAOS_UNUSED(taosCloseDir(&pDir));
return TSDB_CODE_OUT_OF_RANGE;
}
int64_t subSize = 0; int64_t subSize = 0;
if (taosIsDir(fullPath)) { if (taosIsDir(fullPath)) {
code = taosGetDirSize(fullPath, &subSize); code = taosGetDirSize(fullPath, &subSize);
if (code != 0) {
TAOS_UNUSED(taosCloseDir(&pDir));
return code;
}
} else { } else {
code = taosStatFile(fullPath, &subSize, NULL, NULL); code = taosStatFile(fullPath, &subSize, NULL, NULL);
if (code != 0) {
TAOS_UNUSED(taosCloseDir(&pDir));
return code;
}
} }
if (code != 0) goto _OVER;
totalSize += subSize; totalSize += subSize;
fullPath[0] = 0; fullPath[0] = 0;
} }
_OVER:
*size = totalSize; *size = totalSize;
TAOS_UNUSED(taosCloseDir(&pDir)); TAOS_UNUSED(taosCloseDir(&pDir));
return 0; return code;
} }

View File

@ -233,15 +233,19 @@ int32_t taosBlockSIGPIPE() {
} }
int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) { int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) {
int32_t code = 0;
OS_PARAM_CHECK(fqdn); OS_PARAM_CHECK(fqdn);
OS_PARAM_CHECK(ip); OS_PARAM_CHECK(ip);
int64_t limitMs = 1000;
int64_t st = taosGetTimestampMs(), cost = 0;
#ifdef WINDOWS #ifdef WINDOWS
// Initialize Winsock // Initialize Winsock
WSADATA wsaData; WSADATA wsaData;
int iResult; int iResult;
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) { if (iResult != 0) {
return TAOS_SYSTEM_WINSOCKET_ERROR(WSAGetLastError()); code = TAOS_SYSTEM_WINSOCKET_ERROR(WSAGetLastError());
goto _err;
} }
#endif #endif
@ -260,12 +264,12 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) {
inRetry = true; inRetry = true;
continue; continue;
} else if (EAI_SYSTEM == ret) { } else if (EAI_SYSTEM == ret) {
terrno = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
return terrno; goto _err;
} }
terrno = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
return terrno; goto _err;
} }
struct sockaddr *sa = result->ai_addr; struct sockaddr *sa = result->ai_addr;
@ -275,8 +279,7 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) {
*ip = ia.s_addr; *ip = ia.s_addr;
freeaddrinfo(result); freeaddrinfo(result);
goto _err;
return 0;
} }
#else #else
struct addrinfo hints = {0}; struct addrinfo hints = {0};
@ -292,7 +295,7 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) {
struct in_addr ia = si->sin_addr; struct in_addr ia = si->sin_addr;
*ip = ia.s_addr; *ip = ia.s_addr;
freeaddrinfo(result); freeaddrinfo(result);
return 0; goto _err;
} else { } else {
#ifdef EAI_SYSTEM #ifdef EAI_SYSTEM
if (ret == EAI_SYSTEM) { if (ret == EAI_SYSTEM) {
@ -305,9 +308,16 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) {
#endif #endif
*ip = 0xFFFFFFFF; *ip = 0xFFFFFFFF;
return TSDB_CODE_RPC_FQDN_ERROR; code = TSDB_CODE_RPC_FQDN_ERROR;
goto _err;
} }
#endif #endif
_err:
cost = taosGetTimestampMs() - st;
if (cost >= limitMs) {
uWarn("get ip from fqdn:%s, cost:%" PRId64 "ms", fqdn, cost);
}
return code;
} }
int32_t taosGetFqdn(char *fqdn) { int32_t taosGetFqdn(char *fqdn) {

View File

@ -71,6 +71,9 @@ add_test(
COMMAND osTimeTests COMMAND osTimeTests
) )
if(TD_LINUX)
add_executable(osAtomicTests "osAtomicTests.cpp") add_executable(osAtomicTests "osAtomicTests.cpp")
target_link_libraries(osAtomicTests os util gtest_main) target_link_libraries(osAtomicTests os util gtest_main)
add_test( add_test(
@ -78,6 +81,22 @@ add_test(
COMMAND osAtomicTests COMMAND osAtomicTests
) )
add_executable(osDirTests "osDirTests.cpp")
target_link_libraries(osDirTests os util gtest_main)
add_test(
NAME osDirTests
COMMAND osDirTests
)
add_executable(osEnvTests "osEnvTests.cpp")
target_link_libraries(osEnvTests os util gtest_main)
add_test(
NAME osEnvTests
COMMAND osEnvTests
)
endif()
add_executable(osSemaphoreTests "osSemaphoreTests.cpp") add_executable(osSemaphoreTests "osSemaphoreTests.cpp")
target_link_libraries(osSemaphoreTests os util gtest_main) target_link_libraries(osSemaphoreTests os util gtest_main)
add_test( add_test(

View File

@ -29,87 +29,434 @@
#include "os.h" #include "os.h"
#include "tlog.h" #include "tlog.h"
TEST(osAtomicTests, Exchange16) { TEST(osAtomicTests, atomic_load) {
int16_t value = 123; int8_t result8 = 0, value8 = 8;
int16_t new_value = 456; int16_t result16 = 0, value16 = 16;
int16_t result = atomic_exchange_16(&value, new_value); int32_t result32 = 0, value32 = 32;
EXPECT_EQ(result, 123); int64_t result64 = 0, value64 = 64;
EXPECT_EQ(value, 456); void* resultp = &result64;
void* valuep = &value64;
result8 = atomic_load_8(&value8);
result16 = atomic_load_16(&value16);
result32 = atomic_load_32(&value32);
result64 = atomic_load_64(&value64);
resultp = atomic_load_ptr(&valuep);
EXPECT_EQ(result8, 8);
EXPECT_EQ(result16, 16);
EXPECT_EQ(result32, 32);
EXPECT_EQ(result64, 64);
EXPECT_EQ(resultp, &value64);
EXPECT_EQ(value8, 8);
EXPECT_EQ(value16, 16);
EXPECT_EQ(value32, 32);
EXPECT_EQ(value64, 64);
EXPECT_EQ(valuep, &value64);
} }
TEST(osAtomicTests, Exchange32) { TEST(osAtomicTests, atomic_store) {
int32_t value = 123; int8_t result8 = 0, value8 = 8;
int32_t new_value = 456; int16_t result16 = 0, value16 = 16;
int32_t result = atomic_exchange_32(&value, new_value); int32_t result32 = 0, value32 = 32;
EXPECT_EQ(result, 123); int64_t result64 = 0, value64 = 64;
EXPECT_EQ(value, 456); double resultd = 0, valued = 64;
void* resultp = &result64;
void* valuep = &value64;
atomic_store_8(&result8, value8);
atomic_store_16(&result16, value16);
atomic_store_32(&result32, value32);
atomic_store_64(&result64, value64);
atomic_store_double(&resultd, valued);
atomic_store_ptr(&resultp, valuep);
EXPECT_EQ(result8, 8);
EXPECT_EQ(result16, 16);
EXPECT_EQ(result32, 32);
EXPECT_EQ(result64, 64);
EXPECT_DOUBLE_EQ(resultd, 64);
EXPECT_EQ(resultp, &value64);
} }
TEST(osAtomicTests, Exchange64) { TEST(osAtomicTests, atomic_exchange) {
int64_t value = 123; int8_t result8 = 0, value8 = 8, newval8 = 18;
int64_t new_value = 456; int16_t result16 = 0, value16 = 16, newval16 = 116;
int64_t result = atomic_exchange_64(&value, new_value); int32_t result32 = 0, value32 = 32, newval32 = 132;
EXPECT_EQ(result, 123); int64_t result64 = 0, value64 = 64, newval64 = 164;
EXPECT_EQ(value, 456); double resultd = 0, valued = 64, newvald = 164;
void* valuep = &value64;
void* newvalp = &newval64;
void* resultp = &result64;
result8 = atomic_exchange_8(&value8, newval8);
result16 = atomic_exchange_16(&value16, newval16);
result32 = atomic_exchange_32(&value32, newval32);
result64 = atomic_exchange_64(&value64, newval64);
resultd = atomic_exchange_double(&valued, newvald);
resultp = atomic_exchange_ptr(&valuep, newvalp);
EXPECT_EQ(value8, 18);
EXPECT_EQ(value16, 116);
EXPECT_EQ(value32, 132);
EXPECT_EQ(value64, 164);
EXPECT_DOUBLE_EQ(valued, 164);
EXPECT_EQ(valuep, &newval64);
EXPECT_EQ(result8, 8);
EXPECT_EQ(result16, 16);
EXPECT_EQ(result32, 32);
EXPECT_EQ(result64, 64);
EXPECT_DOUBLE_EQ(resultd, 64);
EXPECT_EQ(resultp, &value64);
} }
TEST(osAtomicTests, ExchangePtr) { TEST(osAtomicTests, atomic_val_compare_exchange) {
int value1 = 123; int8_t result8 = 0, value8 = 8, oldval8 = 8, newval8 = 18;
int value2 = 456; int16_t result16 = 0, value16 = 16, oldval16 = 16, newval16 = 116;
int* ptr = &value1; int32_t result32 = 0, value32 = 32, oldval32 = 32, newval32 = 132;
int* result = (int*)atomic_exchange_ptr(&ptr, &value2); int64_t result64 = 0, value64 = 64, oldval64 = 64, newval64 = 164;
EXPECT_EQ(result, &value1); void* resultp = NULL;
EXPECT_EQ(*ptr, 456); void* valuep = &value64;
void* oldvalp = &value64;
void* newvalp = &newval64;
result8 = atomic_val_compare_exchange_8(&value8, oldval8, newval8);
result16 = atomic_val_compare_exchange_16(&value16, oldval16, newval16);
result32 = atomic_val_compare_exchange_32(&value32, oldval32, newval32);
result64 = atomic_val_compare_exchange_64(&value64, oldval64, newval64);
resultp = atomic_val_compare_exchange_ptr(&valuep, oldvalp, newvalp);
EXPECT_EQ(result8, 8);
EXPECT_EQ(value8, 18);
EXPECT_EQ(result16, 16);
EXPECT_EQ(value16, 116);
EXPECT_EQ(result32, 32);
EXPECT_EQ(value32, 132);
EXPECT_EQ(result64, 64);
EXPECT_EQ(value64, 164);
EXPECT_EQ(resultp, &value64);
EXPECT_EQ(valuep, &newval64);
oldval8 = 9;
oldval16 = 99;
oldval32 = 999;
oldval64 = 9999;
oldvalp = NULL;
result8 = atomic_val_compare_exchange_8(&value8, oldval8, newval8);
result16 = atomic_val_compare_exchange_16(&value16, oldval16, newval16);
result32 = atomic_val_compare_exchange_32(&value32, oldval32, newval32);
result64 = atomic_val_compare_exchange_64(&value64, oldval64, newval64);
resultp = atomic_val_compare_exchange_ptr(&valuep, oldvalp, newvalp);
EXPECT_EQ(result8, 18);
EXPECT_EQ(value8, 18);
EXPECT_EQ(result16, 116);
EXPECT_EQ(value16, 116);
EXPECT_EQ(result32, 132);
EXPECT_EQ(value32, 132);
EXPECT_EQ(result64, 164);
EXPECT_EQ(value64, 164);
EXPECT_EQ(resultp, &newval64);
EXPECT_EQ(valuep, &newval64);
} }
TEST(osAtomicTests, ValCompareExchange8) { TEST(osAtomicTests, atomic_add_fetch) {
int8_t value = 12; int8_t result8 = 0, value8 = 8;
int8_t oldval = 12; int16_t result16 = 0, value16 = 16;
int8_t newval = 45; int32_t result32 = 0, value32 = 32;
int8_t result = atomic_val_compare_exchange_8(&value, oldval, newval); int64_t result64 = 0, value64 = 64;
EXPECT_EQ(result, 12);
EXPECT_EQ(value, 45);
oldval = 78; int64_t valuex = 128;
result = atomic_val_compare_exchange_8(&value, oldval, newval); int64_t* valuep = &valuex;
EXPECT_EQ(result, 45); int64_t resultx = 0;
EXPECT_EQ(value, 45);
result8 = atomic_add_fetch_8(&value8, 10);
result16 = atomic_add_fetch_16(&value16, 10);
result32 = atomic_add_fetch_32(&value32, 10);
result64 = atomic_add_fetch_64(&value64, 10);
resultx = (int64_t)atomic_add_fetch_ptr(valuep, 10);
EXPECT_EQ(result8, 18);
EXPECT_EQ(value8, 18);
EXPECT_EQ(result16, 26);
EXPECT_EQ(value16, 26);
EXPECT_EQ(result32, 42);
EXPECT_EQ(value32, 42);
EXPECT_EQ(result64, 74);
EXPECT_EQ(value64, 74);
EXPECT_EQ(resultx, 138);
EXPECT_EQ(*valuep, 138);
EXPECT_EQ(valuex, 138);
} }
TEST(osAtomicTests, ValCompareExchange16) { TEST(osAtomicTests, atomic_fetch_add) {
int16_t value = 123; int8_t result8 = 0, value8 = 8;
int16_t oldval = 123; int16_t result16 = 0, value16 = 16;
int16_t newval = 456; int32_t result32 = 0, value32 = 32;
int16_t result = atomic_val_compare_exchange_16(&value, oldval, newval); int64_t result64 = 0, value64 = 64;
EXPECT_EQ(result, 123); double resultd = 0, valued = 64;
EXPECT_EQ(value, 456);
oldval = 789; int64_t valuex = 128;
result = atomic_val_compare_exchange_16(&value, oldval, newval); int64_t* valuep = &valuex;
EXPECT_EQ(result, 456); int64_t resultx = 0;
EXPECT_EQ(value, 456);
result8 = atomic_fetch_add_8(&value8, 10);
result16 = atomic_fetch_add_16(&value16, 10);
result32 = atomic_fetch_add_32(&value32, 10);
result64 = atomic_fetch_add_64(&value64, 10);
resultd = atomic_fetch_add_double(&valued, 10);
resultx = (int64_t)atomic_fetch_add_ptr(valuep, 10);
EXPECT_EQ(result8, 8);
EXPECT_EQ(value8, 18);
EXPECT_EQ(result16, 16);
EXPECT_EQ(value16, 26);
EXPECT_EQ(result32, 32);
EXPECT_EQ(value32, 42);
EXPECT_EQ(result64, 64);
EXPECT_EQ(value64, 74);
EXPECT_DOUBLE_EQ(resultd, 64);
EXPECT_DOUBLE_EQ(valued, 74);
EXPECT_EQ(resultx, 128);
EXPECT_EQ(*valuep, 138);
EXPECT_EQ(valuex, 138);
} }
TEST(osAtomicTests, TestAtomicExchange8) { TEST(osAtomicTests, atomic_sub_fetch) {
volatile int8_t value = 42; int8_t result8 = 0, value8 = 8;
int8_t new_value = 100; int16_t result16 = 0, value16 = 16;
int8_t old_value = atomic_exchange_8(&value, new_value); int32_t result32 = 0, value32 = 32;
EXPECT_EQ(old_value, 42); int64_t result64 = 0, value64 = 64;
EXPECT_EQ(value, new_value);
int64_t valuex = 128;
int64_t* valuep = &valuex;
int64_t resultx = 0;
result8 = atomic_sub_fetch_8(&value8, 10);
result16 = atomic_sub_fetch_16(&value16, 10);
result32 = atomic_sub_fetch_32(&value32, 10);
result64 = atomic_sub_fetch_64(&value64, 10);
resultx = (int64_t)atomic_sub_fetch_ptr(valuep, 10);
EXPECT_EQ(result8, -2);
EXPECT_EQ(value8, -2);
EXPECT_EQ(result16, 6);
EXPECT_EQ(value16, 6);
EXPECT_EQ(result32, 22);
EXPECT_EQ(value32, 22);
EXPECT_EQ(result64, 54);
EXPECT_EQ(value64, 54);
EXPECT_EQ(resultx, 118);
EXPECT_EQ(*valuep, 118);
EXPECT_EQ(valuex, 118);
} }
TEST(osAtomicTests, TestAtomicAddFetch16) { TEST(osAtomicTests, atomic_fetch_sub) {
volatile int16_t value = 42; int8_t result8 = 0, value8 = 8;
int16_t increment = 10; int16_t result16 = 0, value16 = 16;
int16_t new_value = atomic_add_fetch_16(&value, increment); int32_t result32 = 0, value32 = 32;
EXPECT_EQ(new_value, 52); int64_t result64 = 0, value64 = 64;
EXPECT_EQ(value, 52); double resultd = 0, valued = 64;
int64_t valuex = 128;
int64_t* valuep = &valuex;
int64_t resultx = 0;
result8 = atomic_fetch_sub_8(&value8, 10);
result16 = atomic_fetch_sub_16(&value16, 10);
result32 = atomic_fetch_sub_32(&value32, 10);
result64 = atomic_fetch_sub_64(&value64, 10);
resultd = atomic_fetch_sub_double(&valued, 10);
resultx = (int64_t)atomic_fetch_sub_ptr(valuep, 10);
EXPECT_EQ(result8, 8);
EXPECT_EQ(value8, -2);
EXPECT_EQ(result16, 16);
EXPECT_EQ(value16, 6);
EXPECT_EQ(result32, 32);
EXPECT_EQ(value32, 22);
EXPECT_EQ(result64, 64);
EXPECT_EQ(value64, 54);
EXPECT_DOUBLE_EQ(resultd, 64);
EXPECT_DOUBLE_EQ(valued, 54);
EXPECT_EQ(resultx, 128);
EXPECT_EQ(*valuep, 118);
EXPECT_EQ(valuex, 118);
} }
//TEST(osAtomicTests, AddFetchPtr) { TEST(osAtomicTests, atomic_and_fetch) {
// uintptr_t val = 0; int8_t result8 = 0, value8 = 3;
// uintptr_t* ptr = &val; int16_t result16 = 0, value16 = 3;
// uintptr_t ret = atomic_add_fetch_ptr(ptr, 10); int32_t result32 = 0, value32 = 3;
// EXPECT_EQ(ret, 10); int64_t result64 = 0, value64 = 3;
// EXPECT_EQ(val, 10);
//} int64_t valuex = 3;
int64_t* valuep = &valuex;
int64_t resultx = 0;
result8 = atomic_and_fetch_8(&value8, 5);
result16 = atomic_and_fetch_16(&value16, 5);
result32 = atomic_and_fetch_32(&value32, 5);
result64 = atomic_and_fetch_64(&value64, 5);
resultx = (int64_t)atomic_and_fetch_ptr(valuep, 5);
EXPECT_EQ(result8, 1);
EXPECT_EQ(value8, 1);
EXPECT_EQ(result16, 1);
EXPECT_EQ(value16, 1);
EXPECT_EQ(result32, 1);
EXPECT_EQ(value32, 1);
EXPECT_EQ(result64, 1);
EXPECT_EQ(value64, 1);
EXPECT_EQ(resultx, 1);
EXPECT_EQ(*valuep, 1);
EXPECT_EQ(valuex, 1);
}
TEST(osAtomicTests, atomic_fetch_and) {
int8_t result8 = 0, value8 = 3;
int16_t result16 = 0, value16 = 3;
int32_t result32 = 0, value32 = 3;
int64_t result64 = 0, value64 = 3;
int64_t valuex = 3;
int64_t* valuep = &valuex;
int64_t resultx = 0;
result8 = atomic_fetch_and_8(&value8, 5);
result16 = atomic_fetch_and_16(&value16, 5);
result32 = atomic_fetch_and_32(&value32, 5);
result64 = atomic_fetch_and_64(&value64, 5);
resultx = (int64_t)atomic_fetch_and_ptr(valuep, 5);
EXPECT_EQ(result8, 3);
EXPECT_EQ(value8, 1);
EXPECT_EQ(result16, 3);
EXPECT_EQ(value16, 1);
EXPECT_EQ(result32, 3);
EXPECT_EQ(value32, 1);
EXPECT_EQ(result64, 3);
EXPECT_EQ(value64, 1);
EXPECT_EQ(resultx, 3);
EXPECT_EQ(*valuep, 1);
EXPECT_EQ(valuex, 1);
}
TEST(osAtomicTests, atomic_or_fetch) {
int8_t result8 = 0, value8 = 3;
int16_t result16 = 0, value16 = 3;
int32_t result32 = 0, value32 = 3;
int64_t result64 = 0, value64 = 3;
int64_t valuex = 3;
int64_t* valuep = &valuex;
int64_t resultx = 0;
result8 = atomic_or_fetch_8(&value8, 5);
result16 = atomic_or_fetch_16(&value16, 5);
result32 = atomic_or_fetch_32(&value32, 5);
result64 = atomic_or_fetch_64(&value64, 5);
resultx = (int64_t)atomic_or_fetch_ptr(valuep, 5);
EXPECT_EQ(result8, 7);
EXPECT_EQ(value8, 7);
EXPECT_EQ(result16, 7);
EXPECT_EQ(value16, 7);
EXPECT_EQ(result32, 7);
EXPECT_EQ(value32, 7);
EXPECT_EQ(result64, 7);
EXPECT_EQ(value64, 7);
EXPECT_EQ(resultx, 7);
EXPECT_EQ(*valuep, 7);
EXPECT_EQ(valuex, 7);
}
TEST(osAtomicTests, atomic_fetch_or) {
int8_t result8 = 0, value8 = 3;
int16_t result16 = 0, value16 = 3;
int32_t result32 = 0, value32 = 3;
int64_t result64 = 0, value64 = 3;
int64_t valuex = 3;
int64_t* valuep = &valuex;
int64_t resultx = 0;
result8 = atomic_fetch_or_8(&value8, 5);
result16 = atomic_fetch_or_16(&value16, 5);
result32 = atomic_fetch_or_32(&value32, 5);
result64 = atomic_fetch_or_64(&value64, 5);
resultx = (int64_t)atomic_fetch_or_ptr(valuep, 5);
EXPECT_EQ(result8, 3);
EXPECT_EQ(value8, 7);
EXPECT_EQ(result16, 3);
EXPECT_EQ(value16, 7);
EXPECT_EQ(result32, 3);
EXPECT_EQ(value32, 7);
EXPECT_EQ(result64, 3);
EXPECT_EQ(value64, 7);
EXPECT_EQ(resultx, 3);
EXPECT_EQ(*valuep, 7);
EXPECT_EQ(valuex, 7);
}
TEST(osAtomicTests, atomic_xor_fetch) {
int8_t result8 = 0, value8 = 3;
int16_t result16 = 0, value16 = 3;
int32_t result32 = 0, value32 = 3;
int64_t result64 = 0, value64 = 3;
int64_t valuex = 3;
int64_t* valuep = &valuex;
int64_t resultx = 0;
result8 = atomic_xor_fetch_8(&value8, 5);
result16 = atomic_xor_fetch_16(&value16, 5);
result32 = atomic_xor_fetch_32(&value32, 5);
result64 = atomic_xor_fetch_64(&value64, 5);
resultx = (int64_t)atomic_xor_fetch_ptr(valuep, 5);
EXPECT_EQ(result8, 6);
EXPECT_EQ(value8, 6);
EXPECT_EQ(result16, 6);
EXPECT_EQ(value16, 6);
EXPECT_EQ(result32, 6);
EXPECT_EQ(value32, 6);
EXPECT_EQ(result64, 6);
EXPECT_EQ(value64, 6);
EXPECT_EQ(resultx, 6);
EXPECT_EQ(*valuep, 6);
EXPECT_EQ(valuex, 6);
}
TEST(osAtomicTests, atomic_fetch_xor) {
int8_t result8 = 0, value8 = 3;
int16_t result16 = 0, value16 = 3;
int32_t result32 = 0, value32 = 3;
int64_t result64 = 0, value64 = 3;
int64_t valuex = 3;
int64_t* valuep = &valuex;
int64_t resultx = 0;
result8 = atomic_fetch_xor_8(&value8, 5);
result16 = atomic_fetch_xor_16(&value16, 5);
result32 = atomic_fetch_xor_32(&value32, 5);
result64 = atomic_fetch_xor_64(&value64, 5);
resultx = (int64_t)atomic_fetch_xor_ptr(valuep, 5);
EXPECT_EQ(result8, 3);
EXPECT_EQ(value8, 6);
EXPECT_EQ(result16, 3);
EXPECT_EQ(value16, 6);
EXPECT_EQ(result32, 3);
EXPECT_EQ(value32, 6);
EXPECT_EQ(result64, 3);
EXPECT_EQ(value64, 6);
EXPECT_EQ(resultx, 3);
EXPECT_EQ(*valuep, 6);
EXPECT_EQ(valuex, 6);
}

View File

@ -0,0 +1,464 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#pragma GCC diagnostic ignored "-Wpointer-arith"
#include "os.h"
#include "tlog.h"
TEST(osDirTests, taosRemoveDir) {
int32_t ret = 0;
const char* testDir = "/tmp/tdengine-test-dir";
if (taosDirExist(testDir)) {
taosRemoveDir(testDir);
}
taosRemoveDir(testDir);
ret = taosMkDir(testDir);
EXPECT_EQ(ret, 0);
const char* testFile = "/tmp/tdengine-test-dir/test-file";
TdFilePtr testFilePtr = taosCreateFile(testFile, TD_FILE_CREATE);
EXPECT_NE(testFilePtr, nullptr);
ret = taosCloseFile(&testFilePtr);
EXPECT_EQ(ret, 0);
const char* testDir2 = "/tmp/tdengine-test-dir/test-dir2";
ret = taosMkDir(testDir2);
EXPECT_EQ(ret, 0);
const char* testFile2 = "/tmp/tdengine-test-dir/test-dir2/test-file2";
TdFilePtr testFilePtr2 = taosCreateFile(testFile2, TD_FILE_CREATE);
EXPECT_NE(testFilePtr2, nullptr);
ret = taosCloseFile(&testFilePtr2);
EXPECT_EQ(ret, 0);
taosRemoveDir(testDir);
bool exist = taosDirExist(testDir);
EXPECT_EQ(exist, false);
taosRemoveDir("/tmp/tdengine-test-dir");
}
TEST(osDirTests, taosDirExist) {
const char* dir1 = NULL;
bool exist = taosDirExist(dir1);
EXPECT_EQ(exist, false);
char dir2[2048] = {0};
for (int32_t i = 0; i < 2047; ++i) {
dir2[i] = 1;
}
exist = taosDirExist(dir2);
EXPECT_EQ(exist, false);
taosRemoveDir("/tmp/tdengine-test-dir");
}
TEST(osDirTests, taosMulMkDir) {
int32_t ret = 0;
const char* dir1 = NULL;
ret = taosMulMkDir(dir1);
EXPECT_EQ(ret, -1);
char dir2[2048] = {0};
for (int32_t i = 0; i < 2047; ++i) {
dir2[i] = '1';
}
ret = taosMulMkDir(dir2);
EXPECT_EQ(ret, -1);
const char* dir3 = "/tmp/tdengine-test-dir/1/2/3/4";
taosRemoveDir(dir3);
ret = taosMulMkDir(dir3);
EXPECT_EQ(ret, 0);
taosRemoveDir(dir3);
const char* dir4 = "./tdengine-test-dir/1/2/3/4";
taosRemoveDir(dir4);
ret = taosMulMkDir(dir4);
EXPECT_EQ(ret, 0);
taosRemoveDir(dir4);
const char* dir5 = "tdengine-test-dir/1/2/3/4";
taosRemoveDir(dir5);
ret = taosMulMkDir(dir5);
EXPECT_EQ(ret, 0);
ret = taosMulMkDir(dir5);
EXPECT_EQ(ret, 0);
taosRemoveDir(dir5);
const char* testFile = "/tmp/tdengine-test-dir/test-file";
TdFilePtr testFilePtr = taosCreateFile(testFile, TD_FILE_CREATE);
EXPECT_NE(testFilePtr, nullptr);
ret = taosCloseFile(&testFilePtr);
EXPECT_EQ(ret, 0);
char dir6[2048] = {0};
strcpy(dir6, "/tmp/tdengine-test-dir/test-file/1/2/3/4");
ret = taosMulMkDir(dir6);
EXPECT_NE(ret, 0);
taosRemoveDir("/tmp/tdengine-test-dir");
}
TEST(osDirTests, taosMulModeMkDir) {
int32_t ret = 0;
const char* dir1 = NULL;
ret = taosMulModeMkDir(dir1, 777, true);
EXPECT_NE(ret, 0);
char dir2[2048] = {0};
for (int32_t i = 0; i < 2047; ++i) {
dir2[i] = '1';
}
ret = taosMulModeMkDir(dir2, 777, true);
EXPECT_NE(ret, 0);
const char* dir3 = "/tmp/tdengine-test-dir/1/2/3/4";
taosRemoveDir(dir3);
ret = taosMulMkDir(dir3);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir3, 777, true);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir3, 777, false);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir3, 999, true);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir3, 999, false);
EXPECT_EQ(ret, 0);
taosRemoveDir(dir3);
const char* dir4 = "./tdengine-test-dir/1/2/3/4";
taosRemoveDir(dir4);
ret = taosMulModeMkDir(dir4, 777, true);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir4, 777, false);
EXPECT_EQ(ret, 0);
taosRemoveDir(dir4);
const char* dir5 = "tdengine-test-dir/1/2/3/4";
taosRemoveDir(dir5);
ret = taosMulModeMkDir(dir5, 777, true);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir5, 777, false);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir5, 777, true);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir5, 777, false);
EXPECT_EQ(ret, 0);
taosRemoveDir(dir5);
const char* testFile = "/tmp/tdengine-test-dir/test-file";
TdFilePtr testFilePtr = taosCreateFile(testFile, TD_FILE_CREATE);
EXPECT_NE(testFilePtr, nullptr);
ret = taosCloseFile(&testFilePtr);
EXPECT_EQ(ret, 0);
char dir6[2048] = {0};
strcpy(dir6, "/tmp/tdengine-test-dir/test-file/1/2/3/4");
ret = taosMulModeMkDir(dir6, 777, true);
EXPECT_NE(ret, 0);
const char* dir7 = "tdengine-test-dir/1/2/3/5";
taosRemoveDir(dir7);
ret = taosMulModeMkDir(dir7, 999, true);
EXPECT_EQ(ret, 0);
ret = taosMulModeMkDir(dir7, 999, false);
EXPECT_EQ(ret, 0);
taosRemoveDir("/tmp/tdengine-test-dir");
}
TEST(osDirTests, taosRemoveOldFiles) {
int32_t ret = 0;
const char* testDir = "/tmp/tdengine-test-dir";
if (taosDirExist(testDir)) {
taosRemoveDir(testDir);
}
taosRemoveDir(testDir);
ret = taosMkDir(testDir);
EXPECT_EQ(ret, 0);
const char* testFile = "/tmp/tdengine-test-dir/test-file";
TdFilePtr testFilePtr = taosCreateFile(testFile, TD_FILE_CREATE);
EXPECT_NE(testFilePtr, nullptr);
ret = taosCloseFile(&testFilePtr);
EXPECT_EQ(ret, 0);
taosRemoveOldFiles(testFile, 10);
const char* testDir2 = "/tmp/tdengine-test-dir/test-dir2";
ret = taosMkDir(testDir2);
EXPECT_EQ(ret, 0);
const char* testFile3 = "/tmp/tdengine-test-dir/log.1433726073.gz";
TdFilePtr testFilePtr3 = taosCreateFile(testFile3, TD_FILE_CREATE);
EXPECT_NE(testFilePtr3, nullptr);
ret = taosCloseFile(&testFilePtr3);
EXPECT_EQ(ret, 0);
const char* testFile4 = "/tmp/tdengine-test-dir/log.80.gz";
TdFilePtr testFilePtr4 = taosCreateFile(testFile4, TD_FILE_CREATE);
EXPECT_NE(testFilePtr4, nullptr);
ret = taosCloseFile(&testFilePtr4);
EXPECT_EQ(ret, 0);
char testFile5[1024];
snprintf(testFile5, 1024, "/tmp/tdengine-test-dir/log.%d.gz", taosGetTimestampSec());
TdFilePtr testFilePtr5 = taosCreateFile(testFile5, TD_FILE_CREATE);
EXPECT_NE(testFilePtr5, nullptr);
ret = taosCloseFile(&testFilePtr5);
EXPECT_EQ(ret, 0);
const char* testFile6 = "/tmp/tdengine-test-dir/log.1433726073.gz";
TdFilePtr testFilePtr6 = taosCreateFile(testFile6, TD_FILE_CREATE);
EXPECT_NE(testFilePtr6, nullptr);
ret = taosCloseFile(&testFilePtr6);
EXPECT_EQ(ret, 0);
taosRemoveOldFiles(testDir, 10);
bool exist = taosDirExist(testDir);
EXPECT_EQ(exist, true);
taosRemoveDir("/tmp/tdengine-test-dir");
}
TEST(osDirTests, taosExpandDir) {
int32_t ret = 0;
const char* testDir = "/tmp/tdengine-test-dir";
ret = taosMkDir(testDir);
EXPECT_EQ(ret, 0);
char fullpath[1024] = {0};
ret = taosExpandDir(testDir, NULL, 1024);
EXPECT_NE(ret, 0);
ret = taosExpandDir(NULL, fullpath, 1024);
EXPECT_NE(ret, 0);
ret = taosExpandDir(testDir, fullpath, 1024);
EXPECT_EQ(ret, 0);
ret = taosExpandDir("/x123", fullpath, 1024);
EXPECT_EQ(ret, 0);
ret = taosExpandDir("", fullpath, 1024);
EXPECT_EQ(ret, 0);
char dir2[2048] = {0};
for (int32_t i = 0; i < 2047; ++i) {
dir2[i] = '1';
}
ret = taosExpandDir(dir2, fullpath, 1024);
EXPECT_EQ(ret, 0);
taosRemoveDir("/tmp/tdengine-test-dir");
}
TEST(osDirTests, taosRealPath) {
int32_t ret = 0;
char testDir[PATH_MAX * 2] = "/tmp/tdengine-test-dir";
ret = taosMkDir(testDir);
EXPECT_EQ(ret, 0);
char fullpath[PATH_MAX * 2] = {0};
ret = taosRealPath(testDir, NULL, PATH_MAX * 2);
EXPECT_EQ(ret, 0);
ret = taosRealPath(NULL, fullpath, PATH_MAX * 2);
EXPECT_NE(ret, 0);
ret = taosRealPath(testDir, fullpath, PATH_MAX * 2);
EXPECT_EQ(ret, 0);
ret = taosRealPath(testDir, fullpath, 12);
EXPECT_NE(ret, 0);
ret = taosRealPath("/c/d", fullpath, 1024);
EXPECT_NE(ret, 0);
taosRemoveDir("/tmp/tdengine-test-dir");
}
TEST(osDirTests, taosIsDir) {
bool ret = taosIsDir("/c/d");
EXPECT_EQ(ret, false);
}
TEST(osDirTests, taosDirName) {
char* ret = taosDirName(NULL);
EXPECT_EQ(ret, nullptr);
char name1[24] = "xyz";
ret = taosDirName(name1);
EXPECT_NE(ret, nullptr);
EXPECT_EQ(name1[0], 0);
char name2[24] = "/root/xyz";
ret = taosDirName(name2);
EXPECT_NE(ret, nullptr);
EXPECT_STREQ(ret, "/root");
}
TEST(osDirTests, taosDirEntryBaseName) {
char* ret = taosDirEntryBaseName(NULL);
EXPECT_EQ(ret, nullptr);
char name1[12] = "/";
ret = taosDirEntryBaseName(name1);
EXPECT_STREQ(ret, "/");
char name2[12] = "/root/";
ret = taosDirEntryBaseName(name2);
EXPECT_STREQ(ret, "root");
char name3[12] = "/root";
ret = taosDirEntryBaseName(name3);
EXPECT_STREQ(ret, "root");
char name4[12] = "root";
ret = taosDirEntryBaseName(name4);
EXPECT_STREQ(ret, "root");
}
TEST(osDirTests, taosOpenDir) {
TdDirPtr ret = taosOpenDir(NULL);
EXPECT_EQ(ret, nullptr);
}
TEST(osDirTests, taosReadDir) {
TdDirEntryPtr rddir = taosReadDir(NULL);
EXPECT_EQ(rddir, nullptr);
int32_t ret = 0;
const char* testDir = "/tmp/tdengine-test-dir";
ret = taosMkDir(testDir);
EXPECT_EQ(ret, 0);
const char* testFile = "/tmp/tdengine-test-dir/test-file";
TdFilePtr testFilePtr = taosCreateFile(testFile, TD_FILE_CREATE);
EXPECT_NE(testFilePtr, nullptr);
ret = taosCloseFile(&testFilePtr);
EXPECT_EQ(ret, 0);
TdDirPtr dir = taosOpenDir(testFile);
EXPECT_EQ(dir, nullptr);
const char* testDir2 = "/tmp/tdengine-test-dir/test-dir2";
ret = taosMkDir(testDir2);
EXPECT_EQ(ret, 0);
const char* testFile2 = "/tmp/tdengine-test-dir/test-dir2/test-file2";
TdFilePtr testFilePtr2 = taosCreateFile(testFile2, TD_FILE_CREATE);
EXPECT_NE(testFilePtr2, nullptr);
ret = taosCloseFile(&testFilePtr2);
EXPECT_EQ(ret, 0);
dir = taosOpenDir(testFile);
EXPECT_EQ(dir, nullptr);
rddir = taosReadDir(dir);
EXPECT_EQ(rddir, nullptr);
dir = taosOpenDir(testDir);
EXPECT_NE(dir, nullptr);
rddir = taosReadDir(dir);
EXPECT_NE(rddir, nullptr);
bool entry = taosDirEntryIsDir(NULL);
EXPECT_EQ(entry, false);
char* entryname = taosGetDirEntryName(NULL);
EXPECT_EQ(entryname, nullptr);
entryname = taosGetDirEntryName(rddir);
EXPECT_NE(entryname, nullptr);
int32_t code = taosCloseDir(NULL);
EXPECT_NE(code, 0);
code = taosCloseDir(&dir);
EXPECT_EQ(code, 0);
taosRemoveDir("/tmp/tdengine-test-dir");
}
TEST(osDirTests, taosGetDirSize) {
TdDirEntryPtr rddir = taosReadDir(NULL);
EXPECT_EQ(rddir, nullptr);
int32_t ret = 0;
const char* testDir = "/tmp/tdengine-test-dir";
ret = taosMkDir(testDir);
EXPECT_EQ(ret, 0);
const char* testFile = "/tmp/tdengine-test-dir/test-file";
TdFilePtr testFilePtr = taosCreateFile(testFile, TD_FILE_CREATE);
EXPECT_NE(testFilePtr, nullptr);
ret = taosCloseFile(&testFilePtr);
EXPECT_EQ(ret, 0);
TdDirPtr dir = taosOpenDir(testFile);
EXPECT_EQ(dir, nullptr);
const char* testDir2 = "/tmp/tdengine-test-dir/test-dir2";
ret = taosMkDir(testDir2);
EXPECT_EQ(ret, 0);
const char* testFile2 = "/tmp/tdengine-test-dir/test-dir2/test-file2";
TdFilePtr testFilePtr2 = taosCreateFile(testFile2, TD_FILE_CREATE);
EXPECT_NE(testFilePtr2, nullptr);
ret = taosCloseFile(&testFilePtr2);
EXPECT_EQ(ret, 0);
int64_t size = -1;
ret = taosGetDirSize(testFile, &size);
EXPECT_NE(ret, 0);
ret = taosGetDirSize(testDir, &size);
EXPECT_EQ(ret, 0);
taosRemoveDir("/tmp/tdengine-test-dir");
taosRemoveDir("./tdengine-test-dir/1/2/3/5");
taosRemoveDir("./tdengine-test-dir/1/2/3/4");
taosRemoveDir("./tdengine-test-dir/1/2/3");
taosRemoveDir("./tdengine-test-dir/1/2");
taosRemoveDir("./tdengine-test-dir/1");
taosRemoveDir("./tdengine-test-dir/");
taosRemoveDir("tdengine-test-dir/1/2/3/5");
taosRemoveDir("tdengine-test-dir/1/2/3/4");
taosRemoveDir("tdengine-test-dir/1/2/3");
taosRemoveDir("tdengine-test-dir/1/2");
taosRemoveDir("tdengine-test-dir/1");
taosRemoveDir("tdengine-test-dir/");
taosRemoveDir("tdengine-test-dir/");
}

View File

@ -0,0 +1,93 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#pragma GCC diagnostic ignored "-Wpointer-arith"
#include "os.h"
#include "tlog.h"
TEST(osEnvTests, osDefaultInit) {
int32_t ret = 0;
strcpy(tsTimezoneStr, "");
strcpy(tsTempDir, "");
tsNumOfCores = 0;
ret = osDefaultInit();
EXPECT_EQ(ret, 0);
strcpy(tsTempDir, "/tmp");
ret = osDefaultInit();
EXPECT_EQ(ret, 0);
osCleanup();
}
TEST(osEnvTests, osUpdate) {
int32_t ret = 0;
strcpy(tsLogDir, "");
strcpy(tsDataDir, "");
strcpy(tsTempDir, "");
ret = osUpdate();
EXPECT_EQ(ret, 0);
}
TEST(osEnvTests, osSufficient) {
bool ret = 0;
tsLogSpace.size.avail = 10000;
tsDataSpace.size.avail = 10000;
tsTempSpace.size.avail = 10000;
tsLogSpace.reserved = 2000;
tsDataSpace.reserved = 2000;
tsDataSpace.reserved = 2000;
ret = osLogSpaceAvailable();
EXPECT_EQ(ret, true);
ret = osTempSpaceAvailable();
EXPECT_EQ(ret, true);
ret = osDataSpaceAvailable();
EXPECT_EQ(ret, true);
ret = osLogSpaceSufficient();
EXPECT_EQ(ret, true);
ret = osDataSpaceSufficient();
EXPECT_EQ(ret, true);
ret = osTempSpaceSufficient();
EXPECT_EQ(ret, true);
osSetSystemLocale(NULL, NULL);
osSetSystemLocale(NULL, NULL);
osSetSystemLocale("1", "2");
osSetProcPath(1, NULL);
osSetProcPath(0, (char **)&ret);
}

View File

@ -33,6 +33,13 @@ ENDIF()
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/include/common) INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/include/common)
add_executable(heapTest "heapTest.cpp")
target_link_libraries(heapTest os util gtest_main)
add_test(
NAME heapTest
COMMAND heapTest
)
# arrayTest # arrayTest
add_executable(arrayTest "arrayTest.cpp") add_executable(arrayTest "arrayTest.cpp")
target_link_libraries(arrayTest os util gtest_main) target_link_libraries(arrayTest os util gtest_main)

View File

@ -20,7 +20,7 @@ int32_t heapCompare(const HeapNode* a, const HeapNode* b) {
return 1; return 1;
} }
TEST(TD_UTIL_HEAP_TEST, heapTest) { TEST(heapTest, heapTest) {
Heap* heap = heapCreate(heapCompare); Heap* heap = heapCreate(heapCompare);
ASSERT_TRUE(heap != NULL); ASSERT_TRUE(heap != NULL);
ASSERT_EQ(0, heapSize(heap)); ASSERT_EQ(0, heapSize(heap));

View File

@ -80,7 +80,7 @@ else
fi fi
mv ${REP_REAL_PATH}/debug ${WORKDIR}/debugSan rm -rf ${REP_REAL_PATH}/debug
date date
ret=$? ret=$?

View File

@ -1082,6 +1082,7 @@
,,n,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/insertMix.py -N 3 ,,n,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/insertMix.py -N 3
,,n,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/stt.py -N 3 ,,n,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/stt.py -N 3
,,n,system-test,python3 ./test.py -f eco-system/meta/database/keep_time_offset.py ,,n,system-test,python3 ./test.py -f eco-system/meta/database/keep_time_offset.py
,,y,system-test,./pytest.sh python3 ./test.py -f eco-system/manager/schema_change.py -N 3 -M 3
#tsim test #tsim test
,,y,script,./test.sh -f tsim/query/timeline.sim ,,y,script,./test.sh -f tsim/query/timeline.sim

View File

@ -27,7 +27,6 @@ function runCasesOneByOne () {
|| echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT || echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
end_time=`date +%s` end_time=`date +%s`
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
if $case failed
elif [[ "$line" == *"$2"* ]]; then elif [[ "$line" == *"$2"* ]]; then
if [[ "$cmd" == *"pytest.sh"* ]]; then if [[ "$cmd" == *"pytest.sh"* ]]; then

View File

@ -289,6 +289,64 @@ if $data51 != $query1_data51 then
goto loop3 goto loop3
endi endi
print ======step3
sql create database test3 vgroups 1;
sql use test3;
sql create stable st(ts timestamp, a int, b int , c int)tags(ta int,tb int,tc int);
sql create table t1 using st tags(1,1,1);
sql create table t2 using st tags(2,2,2);
sql create stream streams3 trigger force_window_close IGNORE EXPIRED 1 IGNORE UPDATE 1 into streamt3 as select _wstart, twa(a), ta from st partition by tbname,ta interval(10s);
run tsim/stream/checkTaskStatus.sim
sql insert into t1 values(now + 3000a,1,1,1);
sql flush database test;
sql insert into t1 values(now + 3001a,10,10,10);
sql insert into t1 values(now + 13s,50,50,50);
sleep 1000
print sql select _wstart, twa(a), ta from st partition by tbname,ta interval(10s) order by 1;
sql select _wstart, twa(a), ta from st partition by tbname,ta interval(10s) order by 1;
$query_data01 = $data01
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
$loop_count = 0
loop4:
sleep 2000
$loop_count = $loop_count + 1
if $loop_count == 20 then
return -1
endi
print 2 sql select * from streamt3 order by 1;
sql select * from streamt3 order by 1;
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
if $data01 != $query_data01 then
print ======data01======$data01
print ====query_data01=$query_data01
goto loop4
endi
print end print end
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -515,6 +515,18 @@ class TDTestCase:
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1") tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0,0,0) tdSql.checkData(0,0,0)
tdSql.query(f"select * from {dbname}.stb1")
rows = tdSql.queryRows
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1 or (1<2)")
tdSql.checkRows(rows)
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1 and (1<2)")
tdSql.checkRows(1)
tdSql.checkData(0,0,0)
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1 and (1>2)")
tdSql.checkRows(0)
tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1 or (1>2)")
tdSql.checkRows(1)
tdSql.checkData(0,0,0)
tdSql.query( tdSql.query(
f"select abs(c1+t1)*t1 from {dbname}.stb1 where abs(c1)/floor(abs(ceil(t1))) ==1") f"select abs(c1+t1)*t1 from {dbname}.stb1 where abs(c1)/floor(abs(ceil(t1))) ==1")

View File

@ -451,7 +451,74 @@ class TDTestCase:
sql = "select avg(c1), concat(t9,t10) from db.stb group by concat(t9,t10), concat(t9,t10),tbname" sql = "select avg(c1), concat(t9,t10) from db.stb group by concat(t9,t10), concat(t9,t10),tbname"
tdSql.query(sql, queryTimes=1) tdSql.query(sql, queryTimes=1)
tdSql.checkRows(5) tdSql.checkRows(5)
def test_TS_5727(self):
tdSql.execute(f" use {self.dbname} ")
stableName = "test5727"
sql = f"CREATE STABLE {self.dbname}.{stableName} (`ts` TIMESTAMP, `WaterConsumption` FLOAT, \
`ElecConsumption` INT, `Status` BOOL, `status2` BOOL, `online` BOOL) \
TAGS (`ActivationTime` TIMESTAMP, `ProductId` INT, \
`ProductMac` VARCHAR(24), `location` INT)"
tdSql.execute(sql)
sql = f'CREATE TABLE {self.dbname}.`d00` USING {self.dbname}.{stableName} \
(`ActivationTime`, `ProductId`, `ProductMac`, `location`) \
TAGS (1733124710578, 1001, "00:11:22:33:44:55", 100000)'
tdSql.execute(sql)
sql = f'CREATE TABLE {self.dbname}.`d01` USING {self.dbname}.{stableName} \
(`ActivationTime`, `ProductId`, `ProductMac`, `location`) \
TAGS (1733124723572, 1002, "00:12:22:33:44:55", 200000)'
tdSql.execute(sql)
sql = f'CREATE TABLE {self.dbname}.`d02` USING {self.dbname}.{stableName} \
(`ActivationTime`, `ProductId`, `ProductMac`, `location`) \
TAGS (1733124730908, 1003, "00:11:23:33:44:55", 100000)'
tdSql.execute(sql)
sql = f'insert into {self.dbname}.d00 values(now - 2s, 5, 5, true, true, false);'
tdSql.execute(sql)
sql = f'insert into {self.dbname}.d01 values(now - 1s, 6, 5, true, true, true);'
tdSql.execute(sql)
sql = f'insert into {self.dbname}.d02 values(now, 6, 7, true, true, true);'
tdSql.execute(sql)
sql = f'select `location`, tbname from {self.dbname}.{stableName} where ts < now group by tbname order by tbname;'
tdSql.query(sql)
tdSql.checkRows(3)
tdSql.checkData(0, 0, 100000)
tdSql.checkData(1, 0, 200000)
tdSql.checkData(2, 0, 100000)
tdSql.checkData(0, 1, "d00")
tdSql.checkData(1, 1, "d01")
tdSql.checkData(2, 1, "d02")
sql = f'select tbname,last(online) as online,location from {self.dbname}.{stableName} where ts < now group by tbname order by tbname;'
tdSql.query(sql)
tdSql.checkRows(3)
tdSql.checkData(0, 0, "d00")
tdSql.checkData(1, 0, "d01")
tdSql.checkData(2, 0, "d02")
tdSql.checkData(0, 1, False)
tdSql.checkData(1, 1, True)
tdSql.checkData(2, 1, True)
tdSql.checkData(0, 2, 100000)
tdSql.checkData(1, 2, 200000)
tdSql.checkData(2, 2, 100000)
sql = f'select location,tbname,last_row(online) as online from {self.dbname}.{stableName} where ts < now group by tbname order by tbname;'
tdSql.query(sql)
tdSql.checkRows(3)
tdSql.checkData(0, 0, 100000)
tdSql.checkData(1, 0, 200000)
tdSql.checkData(2, 0, 100000)
tdSql.checkData(0, 1, "d00")
tdSql.checkData(1, 1, "d01")
tdSql.checkData(2, 1, "d02")
tdSql.checkData(0, 2, False)
tdSql.checkData(1, 2, True)
tdSql.checkData(2, 2, True)
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
self.prepare_db() self.prepare_db()
@ -493,6 +560,8 @@ class TDTestCase:
# self.test_groupby('group', 5, 5) # self.test_groupby('group', 5, 5)
self.test_error() self.test_error()
self.test_TS_5727()
def stop(self): def stop(self):

View File

@ -64,6 +64,10 @@ class TDTestCase:
tdSql.query(f"select tbname , max(c1) from {dbname}.sub_stb_1 where c1 is null group by c1 order by c1 desc ") tdSql.query(f"select tbname , max(c1) from {dbname}.sub_stb_1 where c1 is null group by c1 order by c1 desc ")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0,0,"sub_stb_1") tdSql.checkData(0,0,"sub_stb_1")
tdSql.query(f"select tbname , max(c1) from {dbname}.sub_stb_1 group by c1 order by c1 desc ")
rows = tdSql.queryRows
tdSql.query(f"select tbname , max(c1) from {dbname}.sub_stb_1 where c1 is null or (1<2) group by c1 order by c1 desc ")
tdSql.checkRows(rows)
tdSql.query(f"select max(c1) ,c2 ,t2,tbname from {dbname}.stb group by abs(c1) order by abs(c1)") tdSql.query(f"select max(c1) ,c2 ,t2,tbname from {dbname}.stb group by abs(c1) order by abs(c1)")
tdSql.checkRows(self.row_nums+1) tdSql.checkRows(self.row_nums+1)

View File

@ -75,6 +75,25 @@ class TDTestCase:
tdSql.checkData(1, 1, 3) tdSql.checkData(1, 1, 3)
tdSql.checkData(2, 1, 9) tdSql.checkData(2, 1, 9)
tdSql.query(f"select * from {dbname}.stb_1 order by ts")
rows = tdSql.queryRows
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 2) or (1<2) order by ts")
tdSql.checkRows(rows)
tdSql.query(f"select * from (select * from {dbname}.stb_1 where col1 in (1, 9, 3) or (1<2) order by ts)")
tdSql.checkRows(rows)
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 2) and (1<2) order by ts")
tdSql.checkRows(2)
tdSql.checkData(0, 1, 1)
tdSql.checkData(1, 1, 2)
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 9, 3) and (1<2) order by ts")
tdSql.checkRows(3)
tdSql.checkData(0, 1, 1)
tdSql.checkData(1, 1, 3)
tdSql.checkData(2, 1, 9)
tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 9, 3, 'xy') order by ts") tdSql.query(f"select * from {dbname}.stb_1 where col1 in (1, 9, 3, 'xy') order by ts")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.checkData(0, 1, 1) tdSql.checkData(0, 1, 1)
@ -160,7 +179,7 @@ class TDTestCase:
tdSql.prepare() tdSql.prepare()
self.timeZoneTest() self.timeZoneTest()
# self.inAndNotinTest() self.inAndNotinTest()
def stop(self): def stop(self):

View File

@ -28,6 +28,10 @@ class TDTestCase:
for type_name in stype: for type_name in stype:
tdsql.execute(f"drop table if exists {dbname}.{stbname}") tdsql.execute(f"drop table if exists {dbname}.{stbname}")
tdsql.execute(f"create table if not exists {dbname}.{stbname} (ts timestamp, v1 {type_name}) tags(t1 {type_name})") tdsql.execute(f"create table if not exists {dbname}.{stbname} (ts timestamp, v1 {type_name}) tags(t1 {type_name})")
tdsql.query(f"select t1, * from {dbname}.{stbname} where t1 not in (1, 2) or (1<2) order by t1")
tdsql.checkRows(0)
tdsql.execute(f"insert into {dbname}.sub_1 using {dbname}.{stbname} tags(1) values({self.ts}, 10)") tdsql.execute(f"insert into {dbname}.sub_1 using {dbname}.{stbname} tags(1) values({self.ts}, 10)")
tdsql.execute(f"insert into {dbname}.sub_2 using {dbname}.{stbname} tags(2) values({self.ts + 1000}, 20)") tdsql.execute(f"insert into {dbname}.sub_2 using {dbname}.{stbname} tags(2) values({self.ts + 1000}, 20)")
tdsql.execute(f"insert into {dbname}.sub_3 using {dbname}.{stbname} tags(3) values({self.ts + 2000}, 30)") tdsql.execute(f"insert into {dbname}.sub_3 using {dbname}.{stbname} tags(3) values({self.ts + 2000}, 30)")
@ -36,6 +40,11 @@ class TDTestCase:
tdsql.query(f"select t1, * from {dbname}.{stbname} where t1 not in (1, 2) order by t1") tdsql.query(f"select t1, * from {dbname}.{stbname} where t1 not in (1, 2) order by t1")
tdsql.checkRows(1) tdsql.checkRows(1)
tdsql.checkData(0, 0, 3) tdsql.checkData(0, 0, 3)
tdsql.query(f"select * from {dbname}.{stbname} where t1 not in (1, 2) or (1<2) order by t1")
tdsql.checkRows(3)
tdsql.checkData(0, 1, 10)
tdsql.checkData(1, 1, 20)
tdsql.checkData(2, 1, 30)
# Test case 2: NOT BETWEEN # Test case 2: NOT BETWEEN
tdsql.query(f"select * from {dbname}.{stbname} where v1 not between 10 and 20 order by t1") tdsql.query(f"select * from {dbname}.{stbname} where v1 not between 10 and 20 order by t1")

View File

@ -426,6 +426,15 @@ class TDTestCase:
tdLog.printNoPrefix("==========step4:after wal, all check again ") tdLog.printNoPrefix("==========step4:after wal, all check again ")
self.all_test() self.all_test()
self.test_TD_33137()
def test_TD_33137(self):
sql = "select 'asd' union all select 'asdasd'"
tdSql.query(sql, queryTimes=1)
tdSql.checkRows(2)
sql = "select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, stable_name `TABLE_NAME`, 'TABLE' `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_stables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, table_name `TABLE_NAME`, case when `type`='SYSTEM_TABLE' then 'TABLE' when `type`='NORMAL_TABLE' then 'TABLE' when `type`='CHILD_TABLE' then 'TABLE' else 'UNKNOWN' end `TABLE_TYPE`, table_comment `REMARKS` from information_schema.ins_tables union all select db_name `TABLE_CAT`, '' `TABLE_SCHEM`, view_name `TABLE_NAME`, 'VIEW' `TABLE_TYPE`, NULL `REMARKS` from information_schema.ins_views"
tdSql.query(sql, queryTimes=1)
tdSql.checkRows(48)
def stop(self): def stop(self):
tdSql.close() tdSql.close()

View File

@ -133,8 +133,17 @@ class TDTestCase:
if len(tags) < 10: if len(tags) < 10:
return return
sel_cols = random.sample(columns, random.randint(2,int(len(columns)/10))) # cmax
sel_tags = random.sample(tags, random.randint(1,int(len(tags)/10))) cmax = int(len(columns)/10)
if cmax <=2 :
cmax = 3
sel_cols = random.sample(columns, random.randint(2, cmax))
# tmax
tmax = int(len(tags)/10)
if tmax <=1 :
tmax = 2
sel_tags = random.sample(tags, random.randint(1, tmax))
field_cols = ",".join(sel_cols) field_cols = ",".join(sel_cols)
field_tags = ",".join(sel_tags) field_tags = ",".join(sel_tags)
@ -217,18 +226,43 @@ class TDTestCase:
#time.sleep(0.3) #time.sleep(0.3)
# create db and stb
def create(self, db, stb, cols, tags):
# create db
sql = f"create database {db} ;"
tdSql.execute(sql)
# switch db
tdSql.execute(f"use {db};")
# cols
sql1 = ""
for k, v in cols.items():
sql1 += f",{k} {v}"
# tags
sql2 = ""
for k, v in tags.items():
if sql2 == "":
sql2 = f"{k} {v}"
else:
sql2 += f",{k} {v}"
# create stb
sql = f"create table {db}.{stb}(ts timestamp {sql1}) tags({sql2})"
tdSql.execute(sql)
# run # run
def run(self): def run(self):
# seed # seed
random.seed(int(time.time())) random.seed(int(time.time()))
self.dbname = "schema_change" self.dbname = "schema_change"
# switch db # create db
tdSql.execute(f"use {self.dbname};") self.create(self.dbname, "meters", self.column_dict, self.tag_dict)
# change meters # change meters
self.change_schema(1000000) self.change_schema(1000)
def stop(self): def stop(self):