提交 174b0283 编写于 作者: C Cary Xu

Merge branch 'develop' into feature/TD-6117

...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
TDengine支持多种接口写入数据,包括SQL, Prometheus, Telegraf, EMQ MQTT Broker, HiveMQ Broker, CSV文件等,后续还将提供Kafka, OPC等接口。数据可以单条插入,也可以批量插入,可以插入一个数据采集点的数据,也可以同时插入多个数据采集点的数据。支持多线程插入,支持时间乱序数据插入,也支持历史数据插入。 TDengine支持多种接口写入数据,包括SQL, Prometheus, Telegraf, EMQ MQTT Broker, HiveMQ Broker, CSV文件等,后续还将提供Kafka, OPC等接口。数据可以单条插入,也可以批量插入,可以插入一个数据采集点的数据,也可以同时插入多个数据采集点的数据。支持多线程插入,支持时间乱序数据插入,也支持历史数据插入。
## <a class="anchor" id="sql"></a>SQL写入 ## <a class="anchor" id="sql"></a>SQL 写入
应用通过C/C++、JDBC、GO、C#或Python Connector 执行SQL insert语句来插入数据,用户还可以通过TAOS Shell,手动输入SQL insert语句插入数据。比如下面这条insert 就将一条记录写入到表d1001中: 应用通过C/C++、JDBC、GO、C#或Python Connector 执行SQL insert语句来插入数据,用户还可以通过TAOS Shell,手动输入SQL insert语句插入数据。比如下面这条insert 就将一条记录写入到表d1001中:
```mysql ```mysql
...@@ -27,11 +27,73 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, ...@@ -27,11 +27,73 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6,
- 对同一张表,如果新插入记录的时间戳已经存在,默认情形下(UPDATE=0)新记录将被直接抛弃,也就是说,在一张表里,时间戳必须是唯一的。如果应用自动生成记录,很有可能生成的时间戳是一样的,这样,成功插入的记录条数会小于应用插入的记录条数。如果在创建数据库时使用了 UPDATE 1 选项,插入相同时间戳的新记录将覆盖原有记录。 - 对同一张表,如果新插入记录的时间戳已经存在,默认情形下(UPDATE=0)新记录将被直接抛弃,也就是说,在一张表里,时间戳必须是唯一的。如果应用自动生成记录,很有可能生成的时间戳是一样的,这样,成功插入的记录条数会小于应用插入的记录条数。如果在创建数据库时使用了 UPDATE 1 选项,插入相同时间戳的新记录将覆盖原有记录。
- 写入的数据的时间戳必须大于当前时间减去配置参数keep的时间。如果keep配置为3650天,那么无法写入比3650天还早的数据。写入数据的时间戳也不能大于当前时间加配置参数days。如果days为2,那么无法写入比当前时间还晚2天的数据。 - 写入的数据的时间戳必须大于当前时间减去配置参数keep的时间。如果keep配置为3650天,那么无法写入比3650天还早的数据。写入数据的时间戳也不能大于当前时间加配置参数days。如果days为2,那么无法写入比当前时间还晚2天的数据。
## <a class="anchor" id="prometheus"></a>Prometheus直接写入 ## <a class="anchor" id="schemaless"></a>Schemaless 写入
在物联网应用中,常会采集比较多的数据项,用于实现智能控制、业务分析、设备监控等。由于应用逻辑的版本升级,或者设备自身的硬件调整等原因,数据采集项就有可能比较频繁地出现变动。为了在这种情况下方便地完成数据记录工作,TDengine 从 2.2.0.0 版本开始,提供 Schemaless 写入方式,可以免于预先创建超级表/数据子表,而是随着数据写入,自动创建与数据对应的存储结构。并且在必要时,Schemaless 将自动增加必要的数据列,保证用户写入的数据可以被正确存储。目前,TDengine 的 C/C++ Connector 提供支持 Schemaless 的操作接口,详情请参见 [Schemaless 方式写入接口](https://www.taosdata.com/cn/documentation/connector#schemaless) 章节。这里对 Schemaless 的数据表达格式进行描述。
### Schemaless 数据行协议
Schemaless 采用一个字符串来表达最终存储的一个数据行(可以向 Schemaless 写入 API 中一次传入多个字符串来实现多个数据行的批量写入),其格式约定如下:
```json
measurement,tag_set field_set timestamp
```
其中,
* measurement 将作为数据表名。它与 tag_set 之间使用一个英文逗号来分隔。
* tag_set 将作为标签数据,其格式形如 `<tag_key>=<tag_value>,<tag_key>=<tag_value>`,也即可以使用英文逗号来分隔多个标签数据。它与 field_set 之间使用一个半角空格来分隔。
* field_set 将作为普通列数据,其格式形如 `<field_key>=<field_value>,<field_key>=<field_value>`,同样是使用英文逗号来分隔多个普通列的数据。它与 timestamp 之间使用一个半角空格来分隔。
* timestamp 即本行数据对应的主键时间戳。
在 Schemaless 的数据行协议中,tag_set、field_set 中的每个数据项都需要对自身的数据类型进行描述。具体来说:
* 如果两边有英文双引号,表示 BIANRY(32) 类型。例如 `"abc"`
* 如果两边有英文双引号而且带有 L 前缀,表示 NCHAR(32) 类型。例如 `L"报错信息"`
* 对空格、等号(=)、逗号(,)、双引号("),前面需要使用反斜杠(\)进行转义。(都指的是英文半角符号)
* 数值类型将通过后缀来区分数据类型:
- 没有后缀,为 FLOAT 类型;
- 后缀为 f32,为 FLOAT 类型;
- 后缀为 f64,为 DOUBLE 类型;
- 后缀为 i8,表示为 TINYINT (INT8) 类型;
- 后缀为 i16,表示为 SMALLINT (INT16) 类型;
- 后缀为 i32,表示为 INT (INT32) 类型;
- 后缀为 i64,表示为 BIGINT (INT64) 类型;
- 后缀为 b,表示为 BOOL 类型。
* t, T, true, True, TRUE, f, F, false, False 将直接作为 BOOL 型来处理。
timestamp 位置的时间戳通过后缀来声明时间精度,具体如下:
* 不带任何后缀的长整数会被当作微秒来处理;
* 当后缀为 s 时,表示秒时间戳;
* 当后缀为 ms 时,表示毫秒时间戳;
* 当后缀为 us 时,表示微秒时间戳;
* 当后缀为 ns 时,表示纳秒时间戳;
* 当时间戳为 0 时,表示采用客户端的当前时间(因此,同一批提交的数据中,时间戳 0 会被解释为同一个时间点,于是就有可能导致时间戳重复)。
例如,如下 Schemaless 数据行表示:向名为 st 的超级表下的 t1 标签为 3(BIGINT 类型)、t2 标签为 4(DOUBLE 类型)、t3 标签为 "t3"(BINARY 类型)的数据子表,写入 c1 列为 3(BIGINT 类型)、c2 列为 false(BOOL 类型)、c3 列为 "passit"(NCHAR 类型)、c4 列为 4(DOUBLE 类型)、主键时间戳为 1626006833639000000(纳秒精度)的一行数据。
```json
st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000ns
```
### Schemaless 的处理逻辑
Schemaless 按照如下原则来处理行数据:
1. 当 tag_set 中有 ID 字段时,该字段的值将作为数据子表的表名。
2. 没有 ID 字段时,将使用 `measurement + tag_value1 + tag_value2 + ...` 的 md5 值来作为子表名。
3. 如果指定的超级表名不存在,则 Schemaless 会创建这个超级表。
4. 如果指定的数据子表不存在,则 Schemaless 会使用 tag values 创建这个数据子表。
5. 如果数据行中指定的标签列或普通列不存在,则 Schemaless 会在超级表中增加对应的标签列或普通列(只增不减)。
6. 如果超级表中存在一些标签列或普通列未在一个数据行中被指定取值,那么这些列的值在这一行中会被置为 NULL。
7. 对 BINARY 或 NCHAR 列,如果数据行中所提供值的长度超出了列类型的限制,那么 Schemaless 会增加该列允许存储的字符长度上限(只增不减),以保证数据的完整保存。
8. 如果指定的数据子表已经存在,而且本次指定的标签列取值跟已保存的值不一样,那么最新的数据行中的值会覆盖旧的标签列取值。
9. 整个处理过程中遇到的错误会中断写入过程,并返回错误代码。
**注意:**Schemaless 所有的处理逻辑,仍会遵循 TDengine 对数据结构的底层限制,例如每行数据的总长度不能超过 16k 字节。这方面的具体限制约束请参见 [TAOS SQL 边界限制](https://www.taosdata.com/cn/documentation/taos-sql#limitation) 章节。
关于 Schemaless 的字符串编码处理、时区设置等,均会沿用 TAOSC 客户端的设置。
## <a class="anchor" id="prometheus"></a>Prometheus 直接写入
[Prometheus](https://www.prometheus.io/)作为Cloud Native Computing Fundation毕业的项目,在性能监控以及K8S性能监控领域有着非常广泛的应用。TDengine提供一个小工具[Bailongma](https://github.com/taosdata/Bailongma),只需对Prometheus做简单配置,无需任何代码,就可将Prometheus采集的数据直接写入TDengine,并按规则在TDengine自动创建库和相关表项。博文[用Docker容器快速搭建一个Devops监控Demo](https://www.taosdata.com/blog/2020/02/03/1189.html)即是采用Bailongma将Prometheus和Telegraf的数据写入TDengine中的示例,可以参考。 [Prometheus](https://www.prometheus.io/)作为Cloud Native Computing Fundation毕业的项目,在性能监控以及K8S性能监控领域有着非常广泛的应用。TDengine提供一个小工具[Bailongma](https://github.com/taosdata/Bailongma),只需对Prometheus做简单配置,无需任何代码,就可将Prometheus采集的数据直接写入TDengine,并按规则在TDengine自动创建库和相关表项。博文[用Docker容器快速搭建一个Devops监控Demo](https://www.taosdata.com/blog/2020/02/03/1189.html)即是采用Bailongma将Prometheus和Telegraf的数据写入TDengine中的示例,可以参考。
### 从源代码编译blm_prometheus ### 从源代码编译 blm_prometheus
用户需要从github下载[Bailongma](https://github.com/taosdata/Bailongma)的源码,使用Golang语言编译器编译生成可执行文件。在开始编译前,需要准备好以下条件: 用户需要从github下载[Bailongma](https://github.com/taosdata/Bailongma)的源码,使用Golang语言编译器编译生成可执行文件。在开始编译前,需要准备好以下条件:
- Linux操作系统的服务器 - Linux操作系统的服务器
...@@ -46,11 +108,11 @@ go build ...@@ -46,11 +108,11 @@ go build
一切正常的情况下,就会在对应的目录下生成一个blm_prometheus的可执行程序。 一切正常的情况下,就会在对应的目录下生成一个blm_prometheus的可执行程序。
### 安装Prometheus ### 安装 Prometheus
通过Prometheus的官网下载安装。具体请见:[下载地址](https://prometheus.io/download/) 通过Prometheus的官网下载安装。具体请见:[下载地址](https://prometheus.io/download/)
### 配置Prometheus ### 配置 Prometheus
参考Prometheus的[配置文档](https://prometheus.io/docs/prometheus/latest/configuration/configuration/),在Prometheus的配置文件中的<remote_write>部分,增加以下配置: 参考Prometheus的[配置文档](https://prometheus.io/docs/prometheus/latest/configuration/configuration/),在Prometheus的配置文件中的<remote_write>部分,增加以下配置:
...@@ -60,7 +122,8 @@ go build ...@@ -60,7 +122,8 @@ go build
启动Prometheus后,可以通过taos客户端查询确认数据是否成功写入。 启动Prometheus后,可以通过taos客户端查询确认数据是否成功写入。
### 启动blm_prometheus程序 ### 启动 blm_prometheus 程序
blm_prometheus程序有以下选项,在启动blm_prometheus程序时可以通过设定这些选项来设定blm_prometheus的配置。 blm_prometheus程序有以下选项,在启动blm_prometheus程序时可以通过设定这些选项来设定blm_prometheus的配置。
```bash ```bash
--tdengine-name --tdengine-name
...@@ -94,7 +157,8 @@ remote_write: ...@@ -94,7 +157,8 @@ remote_write:
- url: "http://10.1.2.3:8088/receive" - url: "http://10.1.2.3:8088/receive"
``` ```
### 查询prometheus写入数据 ### 查询 prometheus 写入数据
prometheus产生的数据格式如下: prometheus产生的数据格式如下:
```json ```json
{ {
...@@ -105,10 +169,10 @@ prometheus产生的数据格式如下: ...@@ -105,10 +169,10 @@ prometheus产生的数据格式如下:
instance="192.168.99.116:8443", instance="192.168.99.116:8443",
job="kubernetes-apiservers", job="kubernetes-apiservers",
le="125000", le="125000",
resource="persistentvolumes", s resource="persistentvolumes",
cope="cluster", scope="cluster",
verb="LIST", verb="LIST",
version=v1" version="v1"
} }
} }
``` ```
...@@ -118,11 +182,11 @@ use prometheus; ...@@ -118,11 +182,11 @@ use prometheus;
select * from apiserver_request_latencies_bucket; select * from apiserver_request_latencies_bucket;
``` ```
## <a class="anchor" id="telegraf"></a>Telegraf直接写入 ## <a class="anchor" id="telegraf"></a>Telegraf 直接写入
[Telegraf](https://www.influxdata.com/time-series-platform/telegraf/)是一流行的IT运维数据采集开源工具,TDengine提供一个小工具[Bailongma](https://github.com/taosdata/Bailongma),只需在Telegraf做简单配置,无需任何代码,就可将Telegraf采集的数据直接写入TDengine,并按规则在TDengine自动创建库和相关表项。博文[用Docker容器快速搭建一个Devops监控Demo](https://www.taosdata.com/blog/2020/02/03/1189.html)即是采用bailongma将Prometheus和Telegraf的数据写入TDengine中的示例,可以参考。 [Telegraf](https://www.influxdata.com/time-series-platform/telegraf/)是一流行的IT运维数据采集开源工具,TDengine提供一个小工具[Bailongma](https://github.com/taosdata/Bailongma),只需在Telegraf做简单配置,无需任何代码,就可将Telegraf采集的数据直接写入TDengine,并按规则在TDengine自动创建库和相关表项。博文[用Docker容器快速搭建一个Devops监控Demo](https://www.taosdata.com/blog/2020/02/03/1189.html)即是采用bailongma将Prometheus和Telegraf的数据写入TDengine中的示例,可以参考。
### 从源代码编译blm_telegraf ### 从源代码编译 blm_telegraf
用户需要从github下载[Bailongma](https://github.com/taosdata/Bailongma)的源码,使用Golang语言编译器编译生成可执行文件。在开始编译前,需要准备好以下条件: 用户需要从github下载[Bailongma](https://github.com/taosdata/Bailongma)的源码,使用Golang语言编译器编译生成可执行文件。在开始编译前,需要准备好以下条件:
...@@ -139,11 +203,11 @@ go build ...@@ -139,11 +203,11 @@ go build
一切正常的情况下,就会在对应的目录下生成一个blm_telegraf的可执行程序。 一切正常的情况下,就会在对应的目录下生成一个blm_telegraf的可执行程序。
### 安装Telegraf ### 安装 Telegraf
目前TDengine支持Telegraf 1.7.4以上的版本。用户可以根据当前的操作系统,到Telegraf官网下载安装包,并执行安装。下载地址如下:https://portal.influxdata.com/downloads 。 目前TDengine支持Telegraf 1.7.4以上的版本。用户可以根据当前的操作系统,到Telegraf官网下载安装包,并执行安装。下载地址如下:https://portal.influxdata.com/downloads 。
### 配置Telegraf ### 配置 Telegraf
修改Telegraf配置文件/etc/telegraf/telegraf.conf中与TDengine有关的配置项。 修改Telegraf配置文件/etc/telegraf/telegraf.conf中与TDengine有关的配置项。
...@@ -160,7 +224,8 @@ go build ...@@ -160,7 +224,8 @@ go build
关于如何使用Telegraf采集数据以及更多有关使用Telegraf的信息,请参考Telegraf官方的[文档](https://docs.influxdata.com/telegraf/v1.11/) 关于如何使用Telegraf采集数据以及更多有关使用Telegraf的信息,请参考Telegraf官方的[文档](https://docs.influxdata.com/telegraf/v1.11/)
### 启动blm_telegraf程序 ### 启动 blm_telegraf 程序
blm_telegraf程序有以下选项,在启动blm_telegraf程序时可以通过设定这些选项来设定blm_telegraf的配置。 blm_telegraf程序有以下选项,在启动blm_telegraf程序时可以通过设定这些选项来设定blm_telegraf的配置。
```bash ```bash
...@@ -196,7 +261,7 @@ blm_telegraf对telegraf提供服务的端口号。 ...@@ -196,7 +261,7 @@ blm_telegraf对telegraf提供服务的端口号。
url = "http://10.1.2.3:8089/telegraf" url = "http://10.1.2.3:8089/telegraf"
``` ```
### 查询telegraf写入数据 ### 查询 telegraf 写入数据
telegraf产生的数据格式如下: telegraf产生的数据格式如下:
```json ```json
......
...@@ -64,7 +64,10 @@ TDengine提供了丰富的应用程序开发接口,其中包括C/C++、Java、 ...@@ -64,7 +64,10 @@ TDengine提供了丰富的应用程序开发接口,其中包括C/C++、Java、
编辑taos.cfg文件(默认路径/etc/taos/taos.cfg),将firstEP修改为TDengine服务器的End Point,例如:h1.taos.com:6030 编辑taos.cfg文件(默认路径/etc/taos/taos.cfg),将firstEP修改为TDengine服务器的End Point,例如:h1.taos.com:6030
**提示: 如本机没有部署TDengine服务,仅安装了应用驱动,则taos.cfg中仅需配置firstEP,无需配置FQDN。** **提示: **
1. **如本机没有部署TDengine服务,仅安装了应用驱动,则taos.cfg中仅需配置firstEP,无需配置FQDN。**
2. **为防止与服务器端连接时出现“unable to resolve FQDN”错误,建议确认客户端的hosts文件已经配置正确的FQDN值。**
**Windows x64/x86** **Windows x64/x86**
...@@ -96,7 +99,7 @@ TDengine提供了丰富的应用程序开发接口,其中包括C/C++、Java、 ...@@ -96,7 +99,7 @@ TDengine提供了丰富的应用程序开发接口,其中包括C/C++、Java、
**提示:** **提示:**
1. **如利用FQDN连接服务器,必须确认本机网络环境DNS已配置好,或在hosts文件中添加FQDN寻址记录,如编辑C:\Windows\system32\drivers\etc\hosts,添加如下的记录:`192.168.1.99 h1.taos.com` ** 1. **如利用FQDN连接服务器,必须确认本机网络环境DNS已配置好,或在hosts文件中添加FQDN寻址记录,如编辑C:\Windows\system32\drivers\etc\hosts,添加如下的记录:`192.168.1.99 h1.taos.com` **
2**卸载:运行unins000.exe可卸载TDengine应用驱动。** 2. **卸载:运行unins000.exe可卸载TDengine应用驱动。**
### 安装验证 ### 安装验证
...@@ -309,7 +312,7 @@ TDengine的异步API均采用非阻塞调用模式。应用程序可以用多线 ...@@ -309,7 +312,7 @@ TDengine的异步API均采用非阻塞调用模式。应用程序可以用多线
<a class="anchor" id="stmt"></a> <a class="anchor" id="stmt"></a>
### 参数绑定 API ### 参数绑定 API
除了直接调用 `taos_query` 进行查询,TDengine 也提供了支持参数绑定的 Prepare API,与 MySQL 一样,这些 API 目前也仅支持用问号 `?` 来代表待绑定的参数。 除了直接调用 `taos_query` 进行查询,TDengine 也提供了支持参数绑定的 Prepare API,与 MySQL 一样,这些 API 目前也仅支持用问号 `?` 来代表待绑定的参数。文档中有时也会把此功能称为“原生接口写入”。
从 2.1.1.0 和 2.1.2.0 版本开始,TDengine 大幅改进了参数绑定接口对数据写入(INSERT)场景的支持。这样在通过参数绑定接口写入数据时,就避免了 SQL 语法解析的资源消耗,从而在绝大多数情况下显著提升写入性能。此时的典型操作步骤如下: 从 2.1.1.0 和 2.1.2.0 版本开始,TDengine 大幅改进了参数绑定接口对数据写入(INSERT)场景的支持。这样在通过参数绑定接口写入数据时,就避免了 SQL 语法解析的资源消耗,从而在绝大多数情况下显著提升写入性能。此时的典型操作步骤如下:
1. 调用 `taos_stmt_init` 创建参数绑定对象; 1. 调用 `taos_stmt_init` 创建参数绑定对象;
...@@ -400,6 +403,25 @@ typedef struct TAOS_MULTI_BIND { ...@@ -400,6 +403,25 @@ typedef struct TAOS_MULTI_BIND {
(2.1.3.0 版本新增) (2.1.3.0 版本新增)
用于在其他 stmt API 返回错误(返回错误码或空指针)时获取错误信息。 用于在其他 stmt API 返回错误(返回错误码或空指针)时获取错误信息。
<a class="anchor" id="schemaless"></a>
### Schemaless 方式写入接口
除了使用 SQL 方式或者使用参数绑定 API 写入数据外,还可以使用 Schemaless 的方式完成写入。Schemaless 可以免于预先创建超级表/数据子表的数据结构,而是可以直接写入数据,TDengine 系统会根据写入的数据内容自动创建和维护所需要的表结构。Schemaless 的使用方式详见 [Schemaless 写入](https://www.taosdata.com/cn/documentation/insert#schemaless) 章节,这里介绍与之配套使用的 C/C++ API。
- `int taos_insert_lines(TAOS* taos, char* lines[], int numLines)`
(2.2.0.0 版本新增)
以 Schemaless 格式写入多行数据。其中:
* taos:调用 taos_connect 返回的数据库连接。
* lines:由 char 字符串指针组成的数组,指向本次想要写入数据库的多行数据。
* numLines:lines 数据的总行数。
返回值为 0 表示写入成功,非零值表示出错。具体错误代码请参见 [taoserror.h](https://github.com/taosdata/TDengine/blob/develop/src/inc/taoserror.h) 文件。
说明:
1. 此接口是一个同步阻塞式接口,使用时机与 `taos_query()` 一致。
2. 在调用此接口之前,必须先调用 `taos_select_db()` 来确定目前是在向哪个 DB 来写入。
### 连续查询接口 ### 连续查询接口
TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时间段,对一张或多张数据库的表(数据流)进行各种实时聚合计算操作。操作简单,仅有打开、关闭流的API。具体如下: TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时间段,对一张或多张数据库的表(数据流)进行各种实时聚合计算操作。操作简单,仅有打开、关闭流的API。具体如下:
......
...@@ -1258,9 +1258,13 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 ...@@ -1258,9 +1258,13 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
适用于:**表、超级表**。 适用于:**表、超级表**。
说明:(从 2.0.15.0 版本开始新增此函数)INTERP 必须指定时间断面,如果该时间断面不存在直接对应的数据,那么会根据 FILL 参数的设定进行插值。此外,条件语句里面可附带筛选条件,例如标签、tbname。 说明:(从 2.0.15.0 版本开始新增此函数)
INTERP 查询要求查询的时间区间必须位于数据集合(表)的所有记录的时间范围之内。如果给定的时间戳位于时间范围之外,即使有插值指令,仍然不返回结果。 1)INTERP 必须指定时间断面,如果该时间断面不存在直接对应的数据,那么会根据 FILL 参数的设定进行插值。此外,条件语句里面可附带筛选条件,例如标签、tbname。
2)INTERP 查询要求查询的时间区间必须位于数据集合(表)的所有记录的时间范围之内。如果给定的时间戳位于时间范围之外,即使有插值指令,仍然不返回结果。
3)单个 INTERP 函数查询只能够针对一个时间点进行查询,如果需要返回等时间间隔的断面数据,可以通过 INTERP 配合 EVERY 的方式来进行查询处理(而不是使用 INTERVAL),其含义是每隔固定长度的时间进行插值。
示例: 示例:
```sql ```sql
...@@ -1284,6 +1288,18 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 ...@@ -1284,6 +1288,18 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
Query OK, 1 row(s) in set (0.003056s) Query OK, 1 row(s) in set (0.003056s)
``` ```
如下所示代码表示在时间区间 `['2017-7-14 18:40:00', '2017-7-14 18:40:00.014']` 中每隔 5 毫秒 进行一次断面计算。
```sql
taos> SELECT INTERP(current) FROM d636 WHERE ts>='2017-7-14 18:40:00' AND ts<='2017-7-14 18:40:00.014' EVERY(5a);
ts | interp(current) |
=================================================
2017-07-14 18:40:00.000 | 10.04179 |
2017-07-14 18:40:00.010 | 10.16123 |
Query OK, 2 row(s) in set (0.003487s)
```
### 计算函数 ### 计算函数
- **DIFF** - **DIFF**
......
...@@ -66,7 +66,11 @@ Run install_client.sh to install. ...@@ -66,7 +66,11 @@ Run install_client.sh to install.
Edit the taos.cfg file (default path/etc/taos/taos.cfg) and change firstEP to End Point of the TDengine server, for example: [h1.taos.com](http://h1.taos.com/):6030. Edit the taos.cfg file (default path/etc/taos/taos.cfg) and change firstEP to End Point of the TDengine server, for example: [h1.taos.com](http://h1.taos.com/):6030.
**Tip: If no TDengine service deployed in this machine, but only the application driver is installed, only firstEP needs to be configured in taos.cfg, and FQDN does not.** **Tip: **
**1. If no TDengine service deployed in this machine, but only the application driver is installed, only firstEP needs to be configured in taos.cfg, and FQDN does not.**
**2. To prevent “unable to resolve FQDN” error when connecting to the server, ensure that the hosts file of the client has the correct FQDN value.**
**Windows x64/x86** **Windows x64/x86**
...@@ -128,7 +132,7 @@ taos> ...@@ -128,7 +132,7 @@ taos>
**Windows (x64/x86) environment:** **Windows (x64/x86) environment:**
Under cmd, enter the c:\ tdengine directory and directly execute taos.exe, and you should be able to connect to tdengine service normally and jump to taos shell interface. For example: Under cmd, enter the c:\TDengine directory and directly execute taos.exe, and you should be able to connect to tdengine service normally and jump to taos shell interface. For example:
```mysql ```mysql
C:\TDengine>taos C:\TDengine>taos
......
# TAOS SQL # TAOS SQL
TDengine provides a SQL-style language, TAOS SQL, to insert or query data. To read through this document, you should have some basic understanding about SQL. TDengine provides a SQL-style language, TAOS SQL, to insert or query data. This document introduces TAOS SQL and supports other common tips. To read through this document, readers should have basic understanding about SQL.
TAOS SQL is the main way for users to write and query data to TDengine. TAOS SQL is similar to standard SQL to facilitate users to get started quickly. Strictly speaking, TAOS SQL is not and does not attempt to provide SQL standard syntax. In addition, since TDengine does not provide deletion function for time-series data, the relevant function of data deletion is non-existent in TAO SQL. TAOS SQL is the main tool for users to write and query data into/from TDengine. TAOS SQL provides a syntax style similar to standard SQL to facilitate users to get started quickly. Strictly speaking, TAOS SQL is not and does not attempt to provide SQL standard syntax. In addition, since TDengine does not provide deletion functionality for time-series data, the relevant functions of data deletion is unsupported in TAO SQL.
Let’s take a look at the conventions used for syntax descriptions. Let’s take a look at the conventions used for syntax descriptions.
...@@ -37,7 +37,7 @@ With TDengine, the most important thing is timestamp. When creating and insertin ...@@ -37,7 +37,7 @@ With TDengine, the most important thing is timestamp. When creating and insertin
- Epch Time: a timestamp value can also be a long integer representing milliseconds since 1970-01-01 08:00:00.000. - Epch Time: a timestamp value can also be a long integer representing milliseconds since 1970-01-01 08:00:00.000.
- Arithmetic operations can be applied to timestamp. For example: now-2h represents a timestamp which is 2 hours ago from the current server time. Units include u( microsecond), a (milliseconds), s (seconds), m (minutes), h (hours), d (days), w (weeks). In `select * from t1 where ts > now-2w and ts <= now-1w`, which queries data of the whole week before two weeks. To specify the interval of down sampling, you can also use n(calendar month) and y(calendar year) as time units. - Arithmetic operations can be applied to timestamp. For example: now-2h represents a timestamp which is 2 hours ago from the current server time. Units include u( microsecond), a (milliseconds), s (seconds), m (minutes), h (hours), d (days), w (weeks). In `select * from t1 where ts > now-2w and ts <= now-1w`, which queries data of the whole week before two weeks. To specify the interval of down sampling, you can also use n(calendar month) and y(calendar year) as time units.
Default time precision of TDengine is millisecond, you can change it to microseocnd by setting parameter enableMicrosecond. TDengine's timestamp is set to millisecond accuracy by default. Microsecond/nanosecond accuracy can be set using CREATE DATABASE with PRECISION parameter. (Nanosecond resolution is supported from version 2.1.5.0 onwards.)
In TDengine, the following 10 data types can be used in data model of an ordinary table. In TDengine, the following 10 data types can be used in data model of an ordinary table.
...@@ -1244,4 +1244,4 @@ TAOS SQL supports join columns of two tables by Primary Key timestamp between th ...@@ -1244,4 +1244,4 @@ TAOS SQL supports join columns of two tables by Primary Key timestamp between th
**Availability of is no null** **Availability of is no null**
Is not null supports all types of columns. Non-null expression is < > "" and only applies to columns of non-numeric types. Is not null supports all types of columns. Non-null expression is < > "" and only applies to columns of non-numeric types.
\ No newline at end of file
...@@ -102,6 +102,12 @@ elif echo $osinfo | grep -qwi "centos" ; then ...@@ -102,6 +102,12 @@ elif echo $osinfo | grep -qwi "centos" ; then
elif echo $osinfo | grep -qwi "fedora" ; then elif echo $osinfo | grep -qwi "fedora" ; then
# echo "This is fedora system" # echo "This is fedora system"
os_type=2 os_type=2
elif echo $osinfo | grep -qwi "Linx" ; then
# echo "This is Linx system"
os_type=1
service_mod=0
initd_mod=0
service_config_dir="/etc/systemd/system"
else else
echo " osinfo: ${osinfo}" echo " osinfo: ${osinfo}"
echo " This is an officially unverified linux system," echo " This is an officially unverified linux system,"
......
/*
* Copyright (c) 2021 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/>.
*/
#ifndef TDENGINE_TSCPARSELINE_H
#define TDENGINE_TSCPARSELINE_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
char* key;
uint8_t type;
int16_t length;
char* value;
} TAOS_SML_KV;
typedef struct {
char* stableName;
char* childTableName;
TAOS_SML_KV* tags;
int32_t tagNum;
// first kv must be timestamp
TAOS_SML_KV* fields;
int32_t fieldNum;
} TAOS_SML_DATA_POINT;
typedef enum {
SML_TIME_STAMP_NOW,
SML_TIME_STAMP_SECONDS,
SML_TIME_STAMP_MILLI_SECONDS,
SML_TIME_STAMP_MICRO_SECONDS,
SML_TIME_STAMP_NANO_SECONDS
} SMLTimeStampType;
typedef struct {
uint64_t id;
SHashObj* smlDataToSchema;
} SSmlLinesInfo;
int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info);
bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlLinesInfo* info);
int32_t isValidChildTableName(const char *pTbName, int16_t len);
bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
uint16_t len, SSmlLinesInfo* info);
int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
uint16_t len, SSmlLinesInfo* info);
void destroySmlDataPoint(TAOS_SML_DATA_POINT* point);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_TSCPARSELINE_H
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "tscLog.h" #include "tscLog.h"
#include "taos.h" #include "taos.h"
#include "tscParseLine.h"
typedef struct { typedef struct {
char sTableName[TSDB_TABLE_NAME_LEN]; char sTableName[TSDB_TABLE_NAME_LEN];
...@@ -27,38 +28,6 @@ typedef struct { ...@@ -27,38 +28,6 @@ typedef struct {
uint8_t precision; uint8_t precision;
} SSmlSTableSchema; } SSmlSTableSchema;
typedef struct {
char* key;
uint8_t type;
int16_t length;
char* value;
} TAOS_SML_KV;
typedef struct {
char* stableName;
char* childTableName;
TAOS_SML_KV* tags;
int32_t tagNum;
// first kv must be timestamp
TAOS_SML_KV* fields;
int32_t fieldNum;
} TAOS_SML_DATA_POINT;
typedef enum {
SML_TIME_STAMP_NOW,
SML_TIME_STAMP_SECONDS,
SML_TIME_STAMP_MILLI_SECONDS,
SML_TIME_STAMP_MICRO_SECONDS,
SML_TIME_STAMP_NANO_SECONDS
} SMLTimeStampType;
typedef struct {
uint64_t id;
SHashObj* smlDataToSchema;
} SSmlLinesInfo;
//================================================================================================= //=================================================================================================
static uint64_t linesSmlHandleId = 0; static uint64_t linesSmlHandleId = 0;
...@@ -1565,8 +1534,8 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info) ...@@ -1565,8 +1534,8 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info)
return true; return true;
} }
//len does not include '\0' from value. //len does not include '\0' from value.
static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
uint16_t len, SSmlLinesInfo* info) { uint16_t len, SSmlLinesInfo* info) {
if (len <= 0) { if (len <= 0) {
return false; return false;
} }
...@@ -1708,7 +1677,7 @@ static int32_t getTimeStampValue(char *value, uint16_t len, ...@@ -1708,7 +1677,7 @@ static int32_t getTimeStampValue(char *value, uint16_t len,
if (len >= 2) { if (len >= 2) {
for (int i = 0; i < len - 2; ++i) { for (int i = 0; i < len - 2; ++i) {
if(!isdigit(value[i])) { if(!isdigit(value[i])) {
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_INVALID_TIME_STAMP;
} }
} }
} }
...@@ -1743,20 +1712,20 @@ static int32_t getTimeStampValue(char *value, uint16_t len, ...@@ -1743,20 +1712,20 @@ static int32_t getTimeStampValue(char *value, uint16_t len,
break; break;
} }
default: { default: {
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_INVALID_TIME_STAMP;
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value, int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
uint16_t len, SSmlLinesInfo* info) { uint16_t len, SSmlLinesInfo* info) {
int32_t ret; int32_t ret;
SMLTimeStampType type; SMLTimeStampType type;
int64_t tsVal; int64_t tsVal;
if (!isTimeStamp(value, len, &type)) { if (!isTimeStamp(value, len, &type)) {
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_INVALID_TIME_STAMP;
} }
ret = getTimeStampValue(value, len, type, &tsVal); ret = getTimeStampValue(value, len, type, &tsVal);
...@@ -1805,7 +1774,7 @@ static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index, SSmlLine ...@@ -1805,7 +1774,7 @@ static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index, SSmlLine
return ret; return ret;
} }
static bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlLinesInfo* info) { bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlLinesInfo* info) {
char *val = NULL; char *val = NULL;
char *cur = key; char *cur = key;
char keyLower[TSDB_COL_NAME_LEN]; char keyLower[TSDB_COL_NAME_LEN];
...@@ -1842,7 +1811,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -1842,7 +1811,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
while (*cur != '\0') { while (*cur != '\0') {
if (len > TSDB_COL_NAME_LEN) { if (len > TSDB_COL_NAME_LEN) {
tscError("SML:0x%"PRIx64" Key field cannot exceeds 65 characters", info->id); tscError("SML:0x%"PRIx64" Key field cannot exceeds 65 characters", info->id);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
} }
//unescaped '=' identifies a tag key //unescaped '=' identifies a tag key
if (*cur == '=' && *(cur - 1) != '\\') { if (*cur == '=' && *(cur - 1) != '\\') {
...@@ -1902,7 +1871,7 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index, ...@@ -1902,7 +1871,7 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
free(pKV->key); free(pKV->key);
pKV->key = NULL; pKV->key = NULL;
free(value); free(value);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_INVALID_VALUE;
} }
free(value); free(value);
...@@ -1931,7 +1900,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index ...@@ -1931,7 +1900,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index
tscError("SML:0x%"PRIx64" Measurement field cannot exceeds 193 characters", info->id); tscError("SML:0x%"PRIx64" Measurement field cannot exceeds 193 characters", info->id);
free(pSml->stableName); free(pSml->stableName);
pSml->stableName = NULL; pSml->stableName = NULL;
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
} }
//first unescaped comma or space identifies measurement //first unescaped comma or space identifies measurement
//if space detected first, meaning no tag in the input //if space detected first, meaning no tag in the input
...@@ -1958,7 +1927,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index ...@@ -1958,7 +1927,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index
} }
//Table name can only contain digits(0-9),alphebet(a-z),underscore(_) //Table name can only contain digits(0-9),alphebet(a-z),underscore(_)
static int32_t isValidChildTableName(const char *pTbName, int16_t len) { int32_t isValidChildTableName(const char *pTbName, int16_t len) {
const char *cur = pTbName; const char *cur = pTbName;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
if(!isdigit(cur[i]) && !isalpha(cur[i]) && (cur[i] != '_')) { if(!isdigit(cur[i]) && !isalpha(cur[i]) && (cur[i] != '_')) {
...@@ -2146,14 +2115,14 @@ int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* faile ...@@ -2146,14 +2115,14 @@ int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* faile
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tscError("SML:0x%"PRIx64" data point line parse failed. line %d : %s", info->id, i, lines[i]); tscError("SML:0x%"PRIx64" data point line parse failed. line %d : %s", info->id, i, lines[i]);
destroySmlDataPoint(&point); destroySmlDataPoint(&point);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return code;
} else { } else {
tscDebug("SML:0x%"PRIx64" data point line parse success. line %d", info->id, i); tscDebug("SML:0x%"PRIx64" data point line parse success. line %d", info->id, i);
} }
taosArrayPush(points, &point); taosArrayPush(points, &point);
} }
return 0; return TSDB_CODE_SUCCESS;
} }
int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { int taos_insert_lines(TAOS* taos, char* lines[], int numLines) {
......
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hash.h"
#include "taos.h"
#include "tscUtil.h"
#include "tsclient.h"
#include "tscLog.h"
#include "tscParseLine.h"
#define MAX_TELNET_FILEDS_NUM 2
#define OTS_TIMESTAMP_COLUMN_NAME "ts"
#define OTS_METRIC_VALUE_COLUMN_NAME "value"
/* telnet style API parser */
static uint64_t HandleId = 0;
static uint64_t genUID() {
uint64_t id;
do {
id = atomic_add_fetch_64(&HandleId, 1);
} while (id == 0);
return id;
}
static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, SSmlLinesInfo* info) {
const char *cur = *index;
uint16_t len = 0;
pSml->stableName = tcalloc(TSDB_TABLE_NAME_LEN + 1, 1); // +1 to avoid 1772 line over write
if (pSml->stableName == NULL){
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
if (isdigit(*cur)) {
tscError("OTD:0x%"PRIx64" Metric cannnot start with digit", info->id);
tfree(pSml->stableName);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
while (*cur != '\0') {
if (len > TSDB_TABLE_NAME_LEN) {
tscError("OTD:0x%"PRIx64" Metric cannot exceeds 193 characters", info->id);
tfree(pSml->stableName);
return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
}
if (*cur == ' ') {
break;
}
pSml->stableName[len] = *cur;
cur++;
len++;
}
if (len == 0 || *cur == '\0') {
tfree(pSml->stableName);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
pSml->stableName[len] = '\0';
*index = cur + 1;
tscDebug("OTD:0x%"PRIx64" Stable name in metric:%s|len:%d", info->id, pSml->stableName, len);
return TSDB_CODE_SUCCESS;
}
static int32_t parseTelnetTimeStamp(TAOS_SML_KV **pTS, int *num_kvs, const char **index, SSmlLinesInfo* info) {
//Timestamp must be the first KV to parse
assert(*num_kvs == 0);
const char *start, *cur;
int32_t ret = TSDB_CODE_SUCCESS;
int len = 0;
char key[] = OTS_TIMESTAMP_COLUMN_NAME;
char *value = NULL;
start = cur = *index;
//allocate fields for timestamp and value
*pTS = tcalloc(MAX_TELNET_FILEDS_NUM, sizeof(TAOS_SML_KV));
while(*cur != '\0') {
if (*cur == ' ') {
break;
}
cur++;
len++;
}
if (len > 0 && *cur != '\0') {
value = tcalloc(len + 1, 1);
memcpy(value, start, len);
} else {
tfree(*pTS);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
ret = convertSmlTimeStamp(*pTS, value, len, info);
if (ret) {
tfree(value);
tfree(*pTS);
return ret;
}
tfree(value);
(*pTS)->key = tcalloc(sizeof(key), 1);
memcpy((*pTS)->key, key, sizeof(key));
*num_kvs += 1;
*index = cur + 1;
return ret;
}
static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const char **index, SSmlLinesInfo* info) {
//skip timestamp
TAOS_SML_KV *pVal = *pKVs + 1;
const char *start, *cur;
int32_t ret = TSDB_CODE_SUCCESS;
int len = 0;
char key[] = OTS_METRIC_VALUE_COLUMN_NAME;
char *value = NULL;
start = cur = *index;
while(*cur != '\0') {
if (*cur == ' ') {
break;
}
cur++;
len++;
}
if (len > 0 && *cur != '\0') {
value = tcalloc(len + 1, 1);
memcpy(value, start, len);
} else {
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
if (!convertSmlValueType(pVal, value, len, info)) {
tscError("OTD:0x%"PRIx64" Failed to convert metric value string(%s) to any type",
info->id, value);
tfree(value);
return TSDB_CODE_TSC_INVALID_VALUE;
}
tfree(value);
pVal->key = tcalloc(sizeof(key), 1);
memcpy(pVal->key, key, sizeof(key));
*num_kvs += 1;
*index = cur + 1;
return ret;
}
static int32_t parseTelnetTagKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash, SSmlLinesInfo* info) {
const char *cur = *index;
char key[TSDB_COL_NAME_LEN + 1]; // +1 to avoid key[len] over write
uint16_t len = 0;
//key field cannot start with digit
if (isdigit(*cur)) {
tscError("OTD:0x%"PRIx64" Tag key cannnot start with digit", info->id);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
while (*cur != '\0') {
if (len > TSDB_COL_NAME_LEN) {
tscError("OTD:0x%"PRIx64" Tag key cannot exceeds 65 characters", info->id);
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
}
if (*cur == '=') {
break;
}
key[len] = *cur;
cur++;
len++;
}
if (len == 0 || *cur == '\0') {
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
key[len] = '\0';
if (checkDuplicateKey(key, pHash, info)) {
return TSDB_CODE_TSC_DUP_TAG_NAMES;
}
pKV->key = tcalloc(len + 1, 1);
memcpy(pKV->key, key, len + 1);
//tscDebug("OTD:0x%"PRIx64" Key:%s|len:%d", info->id, pKV->key, len);
*index = cur + 1;
return TSDB_CODE_SUCCESS;
}
static int32_t parseTelnetTagValue(TAOS_SML_KV *pKV, const char **index,
bool *is_last_kv, SSmlLinesInfo* info) {
const char *start, *cur;
char *value = NULL;
uint16_t len = 0;
start = cur = *index;
while (1) {
// ',' or '\0' identifies a value
if (*cur == ',' || *cur == '\0') {
// '\0' indicates end of value
*is_last_kv = (*cur == '\0') ? true : false;
break;
}
cur++;
len++;
}
if (len == 0) {
tfree(pKV->key);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
value = tcalloc(len + 1, 1);
memcpy(value, start, len);
value[len] = '\0';
if (!convertSmlValueType(pKV, value, len, info)) {
tscError("OTD:0x%"PRIx64" Failed to convert sml value string(%s) to any type",
info->id, value);
//free previous alocated key field
tfree(pKV->key);
tfree(value);
return TSDB_CODE_TSC_INVALID_VALUE;
}
tfree(value);
*index = (*cur == '\0') ? cur : cur + 1;
return TSDB_CODE_SUCCESS;
}
static int32_t parseTelnetTagKvs(TAOS_SML_KV **pKVs, int *num_kvs,
const char **index, char **childTableName,
SHashObj *pHash, SSmlLinesInfo* info) {
const char *cur = *index;
int32_t ret = TSDB_CODE_SUCCESS;
TAOS_SML_KV *pkv;
bool is_last_kv = false;
int32_t capacity = 4;
*pKVs = tcalloc(capacity, sizeof(TAOS_SML_KV));
pkv = *pKVs;
while (*cur != '\0') {
ret = parseTelnetTagKey(pkv, &cur, pHash, info);
if (ret) {
tscError("OTD:0x%"PRIx64" Unable to parse key", info->id);
return ret;
}
ret = parseTelnetTagValue(pkv, &cur, &is_last_kv, info);
if (ret) {
tscError("OTD:0x%"PRIx64" Unable to parse value", info->id);
return ret;
}
if ((strcasecmp(pkv->key, "ID") == 0) && pkv->type == TSDB_DATA_TYPE_BINARY) {
ret = isValidChildTableName(pkv->value, pkv->length);
if (ret) {
return ret;
}
*childTableName = malloc(pkv->length + 1);
memcpy(*childTableName, pkv->value, pkv->length);
(*childTableName)[pkv->length] = '\0';
tfree(pkv->key);
tfree(pkv->value);
} else {
*num_kvs += 1;
}
if (is_last_kv) {
break;
}
//reallocate addtional memory for more kvs
if ((*num_kvs + 1) > capacity) {
TAOS_SML_KV *more_kvs = NULL;
capacity *= 3; capacity /= 2;
more_kvs = realloc(*pKVs, capacity * sizeof(TAOS_SML_KV));
if (!more_kvs) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
*pKVs = more_kvs;
}
//move pKV points to next TAOS_SML_KV block
pkv = *pKVs + *num_kvs;
}
return ret;
}
int32_t tscParseTelnetLine(const char* line, TAOS_SML_DATA_POINT* smlData, SSmlLinesInfo* info) {
const char* index = line;
int32_t ret = TSDB_CODE_SUCCESS;
//Parse metric
ret = parseTelnetMetric(smlData, &index, info);
if (ret) {
tscError("OTD:0x%"PRIx64" Unable to parse metric", info->id);
return ret;
}
tscDebug("OTD:0x%"PRIx64" Parse metric finished", info->id);
//Parse timestamp
ret = parseTelnetTimeStamp(&smlData->fields, &smlData->fieldNum, &index, info);
if (ret) {
tscError("OTD:0x%"PRIx64" Unable to parse timestamp", info->id);
return ret;
}
tscDebug("OTD:0x%"PRIx64" Parse timestamp finished", info->id);
//Parse value
ret = parseTelnetMetricValue(&smlData->fields, &smlData->fieldNum, &index, info);
if (ret) {
tscError("OTD:0x%"PRIx64" Unable to parse metric value", info->id);
return ret;
}
tscDebug("OTD:0x%"PRIx64" Parse metric value finished", info->id);
//Parse tagKVs
SHashObj *keyHashTable = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
ret = parseTelnetTagKvs(&smlData->tags, &smlData->tagNum, &index, &smlData->childTableName, keyHashTable, info);
if (ret) {
tscError("OTD:0x%"PRIx64" Unable to parse tags", info->id);
taosHashCleanup(keyHashTable);
return ret;
}
tscDebug("OTD:0x%"PRIx64" Parse tags finished", info->id);
taosHashCleanup(keyHashTable);
return TSDB_CODE_SUCCESS;
}
int32_t tscParseTelnetLines(char* lines[], int numLines, SArray* points, SArray* failedLines, SSmlLinesInfo* info) {
for (int32_t i = 0; i < numLines; ++i) {
TAOS_SML_DATA_POINT point = {0};
int32_t code = tscParseTelnetLine(lines[i], &point, info);
if (code != TSDB_CODE_SUCCESS) {
tscError("OTD:0x%"PRIx64" data point line parse failed. line %d : %s", info->id, i, lines[i]);
destroySmlDataPoint(&point);
return code;
} else {
tscDebug("OTD:0x%"PRIx64" data point line parse success. line %d", info->id, i);
}
taosArrayPush(points, &point);
}
return TSDB_CODE_SUCCESS;
}
int taos_insert_telnet_lines(TAOS* taos, char* lines[], int numLines) {
int32_t code = 0;
SSmlLinesInfo* info = tcalloc(1, sizeof(SSmlLinesInfo));
info->id = genUID();
if (numLines <= 0 || numLines > 65536) {
tscError("OTD:0x%"PRIx64" taos_insert_telnet_lines numLines should be between 1 and 65536. numLines: %d", info->id, numLines);
tfree(info);
code = TSDB_CODE_TSC_APP_ERROR;
return code;
}
for (int i = 0; i < numLines; ++i) {
if (lines[i] == NULL) {
tscError("OTD:0x%"PRIx64" taos_insert_telnet_lines line %d is NULL", info->id, i);
tfree(info);
code = TSDB_CODE_TSC_APP_ERROR;
return code;
}
}
SArray* lpPoints = taosArrayInit(numLines, sizeof(TAOS_SML_DATA_POINT));
if (lpPoints == NULL) {
tscError("OTD:0x%"PRIx64" taos_insert_telnet_lines failed to allocate memory", info->id);
tfree(info);
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
tscDebug("OTD:0x%"PRIx64" taos_insert_telnet_lines begin inserting %d lines, first line: %s", info->id, numLines, lines[0]);
code = tscParseTelnetLines(lines, numLines, lpPoints, NULL, info);
size_t numPoints = taosArrayGetSize(lpPoints);
if (code != 0) {
goto cleanup;
}
TAOS_SML_DATA_POINT* points = TARRAY_GET_START(lpPoints);
code = tscSmlInsert(taos, points, (int)numPoints, info);
if (code != 0) {
tscError("OTD:0x%"PRIx64" taos_insert_telnet_lines error: %s", info->id, tstrerror((code)));
}
cleanup:
tscDebug("OTD:0x%"PRIx64" taos_insert_telnet_lines finish inserting %d lines. code: %d", info->id, numLines, code);
points = TARRAY_GET_START(lpPoints);
numPoints = taosArrayGetSize(lpPoints);
for (int i=0; i<numPoints; ++i) {
destroySmlDataPoint(points+i);
}
taosArrayDestroy(lpPoints);
tfree(info);
return code;
}
int taos_telnet_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
SSmlLinesInfo* info = tcalloc(1, sizeof(SSmlLinesInfo));
info->id = genUID();
int code = tscSmlInsert(taos, points, numPoint, info);
tfree(info);
return code;
}
...@@ -1067,6 +1067,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1067,6 +1067,8 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg += pCond->len; pMsg += pCond->len;
} }
} else {
pQueryMsg->tagCondLen = 0;
} }
if (pQueryInfo->bufLen > 0) { if (pQueryInfo->bufLen > 0) {
...@@ -1138,6 +1140,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1138,6 +1140,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
} else { } else {
pQueryMsg->udfContentOffset = 0; pQueryMsg->udfContentOffset = 0;
pQueryMsg->udfContentLen = 0;
} }
memcpy(pMsg, pSql->sqlstr, sqlLen); memcpy(pMsg, pSql->sqlstr, sqlLen);
...@@ -2631,7 +2634,11 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) { ...@@ -2631,7 +2634,11 @@ int tscProcessAlterTableMsgRsp(SSqlObj *pSql) {
tfree(pTableMetaInfo->pTableMeta); tfree(pTableMetaInfo->pTableMeta);
if (isSuperTable) { // if it is a super table, iterate the hashTable and remove all the childTableMeta if (isSuperTable) { // if it is a super table, iterate the hashTable and remove all the childTableMeta
taosHashClear(tscTableMetaMap); if (pSql->res.pRsp == NULL) {
tscDebug("0x%"PRIx64" unexpected resp from mnode, super table: %s failed to update super table meta ", pSql->self, name);
return 0;
}
return tscProcessTableMetaRsp(pSql);
} }
return 0; return 0;
......
...@@ -2085,7 +2085,7 @@ int32_t tscAllocPayloadFast(SSqlCmd *pCmd, size_t size) { ...@@ -2085,7 +2085,7 @@ int32_t tscAllocPayloadFast(SSqlCmd *pCmd, size_t size) {
assert(pCmd->allocSize == 0); assert(pCmd->allocSize == 0);
pCmd->payload = malloc(size); pCmd->payload = malloc(size);
pCmd->allocSize = size; pCmd->allocSize = (uint32_t) size;
} else if (pCmd->allocSize < size) { } else if (pCmd->allocSize < size) {
char* tmp = realloc(pCmd->payload, size); char* tmp = realloc(pCmd->payload, size);
if (tmp == NULL) { if (tmp == NULL) {
...@@ -2093,7 +2093,7 @@ int32_t tscAllocPayloadFast(SSqlCmd *pCmd, size_t size) { ...@@ -2093,7 +2093,7 @@ int32_t tscAllocPayloadFast(SSqlCmd *pCmd, size_t size) {
} }
pCmd->payload = tmp; pCmd->payload = tmp;
pCmd->allocSize = size; pCmd->allocSize = (uint32_t) size;
} }
assert(pCmd->allocSize >= size); assert(pCmd->allocSize >= size);
......
...@@ -229,6 +229,8 @@ extern uint32_t maxRange; ...@@ -229,6 +229,8 @@ extern uint32_t maxRange;
extern uint32_t curRange; extern uint32_t curRange;
extern char Compressor[]; extern char Compressor[];
#endif #endif
// long query
extern int8_t tsDeadLockKillQuery;
typedef struct { typedef struct {
char dir[TSDB_FILENAME_LEN]; char dir[TSDB_FILENAME_LEN];
......
...@@ -284,6 +284,9 @@ uint32_t curRange = 100; // range ...@@ -284,6 +284,9 @@ uint32_t curRange = 100; // range
char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR
#endif #endif
// long query death-lock
int8_t tsDeadLockKillQuery = 0;
int32_t (*monStartSystemFp)() = NULL; int32_t (*monStartSystemFp)() = NULL;
void (*monStopSystemFp)() = NULL; void (*monStopSystemFp)() = NULL;
void (*monExecuteSQLFp)(char *sql) = NULL; void (*monExecuteSQLFp)(char *sql) = NULL;
...@@ -1618,7 +1621,17 @@ static void doInitGlobalConfig(void) { ...@@ -1618,7 +1621,17 @@ static void doInitGlobalConfig(void) {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
assert(tsGlobalConfigNum <= TSDB_CFG_MAX_NUM); // enable kill long query
cfg.option = "deadLockKillQuery";
cfg.ptr = &tsDeadLockKillQuery;
cfg.valType = TAOS_CFG_VTYPE_INT8;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
cfg.minValue = 0;
cfg.maxValue = 1;
cfg.ptrLength = 1;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
#ifdef TD_TSZ #ifdef TD_TSZ
// lossy compress // lossy compress
cfg.option = "lossyColumns"; cfg.option = "lossyColumns";
...@@ -1672,6 +1685,9 @@ static void doInitGlobalConfig(void) { ...@@ -1672,6 +1685,9 @@ static void doInitGlobalConfig(void) {
cfg.ptrLength = 0; cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM);
#else
assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5);
#endif #endif
} }
......
...@@ -827,6 +827,16 @@ def taos_insert_lines(connection, lines): ...@@ -827,6 +827,16 @@ def taos_insert_lines(connection, lines):
if errno != 0: if errno != 0:
raise LinesError("insert lines error", errno) raise LinesError("insert lines error", errno)
def taos_insert_telnet_lines(connection, lines):
# type: (c_void_p, list[str] | tuple(str)) -> None
num_of_lines = len(lines)
lines = (c_char_p(line.encode("utf-8")) for line in lines)
lines_type = ctypes.c_char_p * num_of_lines
p_lines = lines_type(*lines)
errno = _libtaos.taos_insert_telnet_lines(connection, p_lines, num_of_lines)
if errno != 0:
raise LinesError("insert telnet lines error", errno)
class CTaosInterface(object): class CTaosInterface(object):
def __init__(self, config=None): def __init__(self, config=None):
......
...@@ -145,6 +145,15 @@ class TaosConnection(object): ...@@ -145,6 +145,15 @@ class TaosConnection(object):
""" """
return taos_insert_lines(self._conn, lines) return taos_insert_lines(self._conn, lines)
def insert_telnet_lines(self, lines):
"""OpenTSDB telnet style API format support
## Example
cpu_load 1626056811855516532ns 2.0f32 id="tb1",host="host0",interface="eth0"
"""
return taos_insert_telnet_lines(self._conn, lines)
def cursor(self): def cursor(self):
# type: () -> TaosCursor # type: () -> TaosCursor
"""Return a new Cursor object using the connection.""" """Return a new Cursor object using the connection."""
......
...@@ -76,6 +76,11 @@ void* qGetResultRetrieveMsg(qinfo_t qinfo); ...@@ -76,6 +76,11 @@ void* qGetResultRetrieveMsg(qinfo_t qinfo);
*/ */
int32_t qKillQuery(qinfo_t qinfo); int32_t qKillQuery(qinfo_t qinfo);
//kill by qid
int32_t qKillQueryByQId(void* pMgmt, int64_t qId, int32_t waitMs, int32_t waitCount);
bool qSolveCommitNoBlock(void* pRepo, void* pMgmt);
int32_t qQueryCompleted(qinfo_t qinfo); int32_t qQueryCompleted(qinfo_t qinfo);
/** /**
......
...@@ -172,6 +172,8 @@ DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList); ...@@ -172,6 +172,8 @@ DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList);
DLL_EXPORT int taos_insert_lines(TAOS* taos, char* lines[], int numLines); DLL_EXPORT int taos_insert_lines(TAOS* taos, char* lines[], int numLines);
DLL_EXPORT int taos_insert_telnet_lines(TAOS* taos, char* lines[], int numLines);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -35,6 +35,7 @@ int32_t* taosGetErrno(); ...@@ -35,6 +35,7 @@ int32_t* taosGetErrno();
#define terrno (*taosGetErrno()) #define terrno (*taosGetErrno())
#define TSDB_CODE_SUCCESS 0 #define TSDB_CODE_SUCCESS 0
#define TSDB_CODE_FAILED -1 // unknown or needn't tell detail error
// rpc // rpc
#define TSDB_CODE_RPC_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0001) //"Action in progress") #define TSDB_CODE_RPC_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0001) //"Action in progress")
...@@ -106,6 +107,7 @@ int32_t* taosGetErrno(); ...@@ -106,6 +107,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TSC_DUP_COL_NAMES TAOS_DEF_ERROR_CODE(0, 0x021D) //"duplicated column names") #define TSDB_CODE_TSC_DUP_COL_NAMES TAOS_DEF_ERROR_CODE(0, 0x021D) //"duplicated column names")
#define TSDB_CODE_TSC_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x021E) //"Invalid tag length") #define TSDB_CODE_TSC_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x021E) //"Invalid tag length")
#define TSDB_CODE_TSC_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x021F) //"Invalid column length") #define TSDB_CODE_TSC_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x021F) //"Invalid column length")
#define TSDB_CODE_TSC_DUP_TAG_NAMES TAOS_DEF_ERROR_CODE(0, 0x0220) //"duplicated tag names")
// mnode // mnode
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed") #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed")
......
...@@ -39,6 +39,7 @@ extern "C" { ...@@ -39,6 +39,7 @@ extern "C" {
#define TSDB_STATUS_COMMIT_START 1 #define TSDB_STATUS_COMMIT_START 1
#define TSDB_STATUS_COMMIT_OVER 2 #define TSDB_STATUS_COMMIT_OVER 2
#define TSDB_STATUS_COMMIT_NOBLOCK 3 //commit no block, need to be solved
// TSDB STATE DEFINITION // TSDB STATE DEFINITION
#define TSDB_STATE_OK 0x0 #define TSDB_STATE_OK 0x0
...@@ -413,6 +414,11 @@ int tsdbSyncRecv(void *pRepo, SOCKET socketFd); ...@@ -413,6 +414,11 @@ int tsdbSyncRecv(void *pRepo, SOCKET socketFd);
// For TSDB Compact // For TSDB Compact
int tsdbCompact(STsdbRepo *pRepo); int tsdbCompact(STsdbRepo *pRepo);
// For TSDB Health Monitor
// no problem return true
bool tsdbNoProblem(STsdbRepo* pRepo);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -98,6 +98,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -98,6 +98,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
tstrncpy(g_password, (char *)(argv[i] + 2), SHELL_MAX_PASSWORD_LEN); tstrncpy(g_password, (char *)(argv[i] + 2), SHELL_MAX_PASSWORD_LEN);
} }
arguments->password = g_password; arguments->password = g_password;
arguments->is_use_passwd = true;
strcpy(argv[i], ""); strcpy(argv[i], "");
argc -= 1; argc -= 1;
} }
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -1209,14 +1209,14 @@ _dump_db_point: ...@@ -1209,14 +1209,14 @@ _dump_db_point:
fprintf(fp, "USE %s;\n\n", g_dbInfos[0]->name); fprintf(fp, "USE %s;\n\n", g_dbInfos[0]->name);
int32_t totalNumOfThread = 1; // 0: all normal talbe into .tables.tmp.0 int32_t totalNumOfThread = 1; // 0: all normal table into .tables.tmp.0
int normalTblFd = -1; int normalTblFd = -1;
int32_t retCode; int32_t retCode;
int superTblCnt = 0 ; int superTblCnt = 0 ;
for (int i = 1; g_args.arg_list[i]; i++) { for (int i = 1; g_args.arg_list[i]; i++) {
if (taosGetTableRecordInfo(g_args.arg_list[i], if (taosGetTableRecordInfo(g_args.arg_list[i],
&tableRecordInfo, taos) < 0) { &tableRecordInfo, taos) < 0) {
errorPrint("input the invalide table %s\n", errorPrint("input the invalid table %s\n",
g_args.arg_list[i]); g_args.arg_list[i]);
continue; continue;
} }
...@@ -1341,11 +1341,10 @@ static int taosGetTableDes( ...@@ -1341,11 +1341,10 @@ static int taosGetTableDes(
return count; return count;
} }
// if chidl-table have tag, using select tagName from table to get tagValue // if child-table have tag, using select tagName from table to get tagValue
for (int i = 0 ; i < count; i++) { for (int i = 0 ; i < count; i++) {
if (strcmp(stableDes->cols[i].note, "TAG") != 0) continue; if (strcmp(stableDes->cols[i].note, "TAG") != 0) continue;
sprintf(sqlstr, "select %s from %s.%s", sprintf(sqlstr, "select %s from %s.%s",
stableDes->cols[i].field, dbName, table); stableDes->cols[i].field, dbName, table);
...@@ -2443,7 +2442,7 @@ static int taosGetFilesNum(const char *directoryName, ...@@ -2443,7 +2442,7 @@ static int taosGetFilesNum(const char *directoryName,
} }
if (fileNum <= 0) { if (fileNum <= 0) {
errorPrint("directory:%s is empry\n", directoryName); errorPrint("directory:%s is empty\n", directoryName);
exit(-1); exit(-1);
} }
...@@ -2620,9 +2619,9 @@ static int taosDumpInOneFile(TAOS* taos, FILE* fp, char* fcharset, ...@@ -2620,9 +2619,9 @@ static int taosDumpInOneFile(TAOS* taos, FILE* fp, char* fcharset,
memcpy(cmd + cmd_len, line, read_len); memcpy(cmd + cmd_len, line, read_len);
cmd[read_len + cmd_len]= '\0'; cmd[read_len + cmd_len]= '\0';
if (queryDbImpl(taos, cmd)) { if (queryDbImpl(taos, cmd)) {
errorPrint("%s() LN%d, error sql: linenu:%d, file:%s\n", errorPrint("%s() LN%d, error sql: lineno:%d, file:%s\n",
__func__, __LINE__, lineNo, fileName); __func__, __LINE__, lineNo, fileName);
fprintf(g_fpOfResult, "error sql: linenu:%d, file:%s\n", lineNo, fileName); fprintf(g_fpOfResult, "error sql: lineno:%d, file:%s\n", lineNo, fileName);
} }
memset(cmd, 0, TSDB_MAX_ALLOWED_SQL_LEN); memset(cmd, 0, TSDB_MAX_ALLOWED_SQL_LEN);
......
...@@ -1231,7 +1231,9 @@ static int32_t mnodeAddSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1231,7 +1231,9 @@ static int32_t mnodeAddSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) {
SSTableObj *pStable = (SSTableObj *)pMsg->pTable; SSTableObj *pStable = (SSTableObj *)pMsg->pTable;
mLInfo("msg:%p, app:%p stable %s, add tag result:%s, numOfTags:%d", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, mLInfo("msg:%p, app:%p stable %s, add tag result:%s, numOfTags:%d", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId,
tstrerror(code), pStable->numOfTags); tstrerror(code), pStable->numOfTags);
if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg);
}
return code; return code;
} }
...@@ -1287,6 +1289,9 @@ static int32_t mnodeDropSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1287,6 +1289,9 @@ static int32_t mnodeDropSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) {
SSTableObj *pStable = (SSTableObj *)pMsg->pTable; SSTableObj *pStable = (SSTableObj *)pMsg->pTable;
mLInfo("msg:%p, app:%p stable %s, drop tag result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, mLInfo("msg:%p, app:%p stable %s, drop tag result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId,
tstrerror(code)); tstrerror(code));
if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg);
}
return code; return code;
} }
...@@ -1321,6 +1326,9 @@ static int32_t mnodeModifySuperTableTagNameCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1321,6 +1326,9 @@ static int32_t mnodeModifySuperTableTagNameCb(SMnodeMsg *pMsg, int32_t code) {
SSTableObj *pStable = (SSTableObj *)pMsg->pTable; SSTableObj *pStable = (SSTableObj *)pMsg->pTable;
mLInfo("msg:%p, app:%p stable %s, modify tag result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, mLInfo("msg:%p, app:%p stable %s, modify tag result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId,
tstrerror(code)); tstrerror(code));
if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg);
}
return code; return code;
} }
...@@ -1376,6 +1384,9 @@ static int32_t mnodeAddSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1376,6 +1384,9 @@ static int32_t mnodeAddSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
SSTableObj *pStable = (SSTableObj *)pMsg->pTable; SSTableObj *pStable = (SSTableObj *)pMsg->pTable;
mLInfo("msg:%p, app:%p stable %s, add column result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, mLInfo("msg:%p, app:%p stable %s, add column result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId,
tstrerror(code)); tstrerror(code));
if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg);
}
return code; return code;
} }
...@@ -1444,6 +1455,9 @@ static int32_t mnodeDropSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1444,6 +1455,9 @@ static int32_t mnodeDropSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
SSTableObj *pStable = (SSTableObj *)pMsg->pTable; SSTableObj *pStable = (SSTableObj *)pMsg->pTable;
mLInfo("msg:%p, app:%p stable %s, delete column result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, mLInfo("msg:%p, app:%p stable %s, delete column result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId,
tstrerror(code)); tstrerror(code));
if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg);
}
return code; return code;
} }
...@@ -1489,6 +1503,9 @@ static int32_t mnodeChangeSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -1489,6 +1503,9 @@ static int32_t mnodeChangeSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
SSTableObj *pStable = (SSTableObj *)pMsg->pTable; SSTableObj *pStable = (SSTableObj *)pMsg->pTable;
mLInfo("msg:%p, app:%p stable %s, change column result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, mLInfo("msg:%p, app:%p stable %s, change column result:%s", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId,
tstrerror(code)); tstrerror(code));
if (code == TSDB_CODE_SUCCESS) {
code = mnodeGetSuperTableMeta(pMsg);
}
return code; return code;
} }
......
...@@ -31,7 +31,6 @@ void taosCloseDll(void *handle) { ...@@ -31,7 +31,6 @@ void taosCloseDll(void *handle) {
int taosSetConsoleEcho(bool on) int taosSetConsoleEcho(bool on)
{ {
#if 0
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL) #define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
int err; int err;
struct termios term; struct termios term;
...@@ -52,7 +51,6 @@ int taosSetConsoleEcho(bool on) ...@@ -52,7 +51,6 @@ int taosSetConsoleEcho(bool on)
return -1; return -1;
} }
#endif
return 0; return 0;
} }
...@@ -147,6 +147,7 @@ typedef struct HttpContext { ...@@ -147,6 +147,7 @@ typedef struct HttpContext {
int32_t state; int32_t state;
uint8_t reqType; uint8_t reqType;
uint8_t parsed; uint8_t parsed;
uint8_t error;
char ipstr[22]; char ipstr[22];
char user[TSDB_USER_LEN]; // parsed from auth token or login message char user[TSDB_USER_LEN]; // parsed from auth token or login message
char pass[HTTP_PASSWORD_LEN]; char pass[HTTP_PASSWORD_LEN];
......
...@@ -188,11 +188,12 @@ void httpCloseContextByApp(HttpContext *pContext) { ...@@ -188,11 +188,12 @@ void httpCloseContextByApp(HttpContext *pContext) {
pContext->parsed = false; pContext->parsed = false;
bool keepAlive = true; bool keepAlive = true;
if (parser && parser->httpVersion == HTTP_VERSION_10 && parser->keepAlive != HTTP_KEEPALIVE_ENABLE) { if (pContext->error == true) {
keepAlive = false;
} else if (parser && parser->httpVersion == HTTP_VERSION_10 && parser->keepAlive != HTTP_KEEPALIVE_ENABLE) {
keepAlive = false; keepAlive = false;
} else if (parser && parser->httpVersion != HTTP_VERSION_10 && parser->keepAlive == HTTP_KEEPALIVE_DISABLE) { } else if (parser && parser->httpVersion != HTTP_VERSION_10 && parser->keepAlive == HTTP_KEEPALIVE_DISABLE) {
keepAlive = false; keepAlive = false;
} else {
} }
if (keepAlive) { if (keepAlive) {
......
...@@ -663,7 +663,7 @@ static int32_t httpParserOnTarget(HttpParser *parser, HTTP_PARSER_STATE state, c ...@@ -663,7 +663,7 @@ static int32_t httpParserOnTarget(HttpParser *parser, HTTP_PARSER_STATE state, c
HttpContext *pContext = parser->pContext; HttpContext *pContext = parser->pContext;
int32_t ok = 0; int32_t ok = 0;
do { do {
if (!isspace(c) && c != '\r' && c != '\n') { if (!isspace(c)) {
if (httpAppendString(&parser->str, &c, 1)) { if (httpAppendString(&parser->str, &c, 1)) {
httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c);
ok = -1; ok = -1;
...@@ -1157,6 +1157,10 @@ static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) { ...@@ -1157,6 +1157,10 @@ static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) {
httpOnError(parser, HTTP_CODE_INTERNAL_SERVER_ERROR, TSDB_CODE_HTTP_PARSE_ERROR_STATE); httpOnError(parser, HTTP_CODE_INTERNAL_SERVER_ERROR, TSDB_CODE_HTTP_PARSE_ERROR_STATE);
} }
if (ok != 0) {
pContext->error = true;
}
return ok; return ok;
} }
......
...@@ -2402,11 +2402,11 @@ bool isQueryKilled(SQInfo *pQInfo) { ...@@ -2402,11 +2402,11 @@ bool isQueryKilled(SQInfo *pQInfo) {
// query has been executed more than tsShellActivityTimer, and the retrieve has not arrived // query has been executed more than tsShellActivityTimer, and the retrieve has not arrived
// abort current query execution. // abort current query execution.
if (pQInfo->owner != 0 && ((taosGetTimestampSec() - pQInfo->startExecTs) > getMaximumIdleDurationSec()) && if (pQInfo->owner != 0 && ((taosGetTimestampSec() - pQInfo->startExecTs/1000) > getMaximumIdleDurationSec()) &&
(!needBuildResAfterQueryComplete(pQInfo))) { (!needBuildResAfterQueryComplete(pQInfo))) {
assert(pQInfo->startExecTs != 0); assert(pQInfo->startExecTs != 0);
qDebug("QInfo:%" PRIu64 " retrieve not arrive beyond %d sec, abort current query execution, start:%" PRId64 qDebug("QInfo:%" PRIu64 " retrieve not arrive beyond %d ms, abort current query execution, start:%" PRId64
", current:%d", pQInfo->qId, 1, pQInfo->startExecTs, taosGetTimestampSec()); ", current:%d", pQInfo->qId, 1, pQInfo->startExecTs, taosGetTimestampSec());
return true; return true;
} }
...@@ -8413,6 +8413,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S ...@@ -8413,6 +8413,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
} }
pQInfo->qId = qId; pQInfo->qId = qId;
pQInfo->startExecTs = 0;
pQInfo->runtimeEnv.pUdfInfo = pUdfInfo; pQInfo->runtimeEnv.pUdfInfo = pUdfInfo;
......
...@@ -35,7 +35,7 @@ typedef struct SQueryMgmt { ...@@ -35,7 +35,7 @@ typedef struct SQueryMgmt {
bool closed; bool closed;
} SQueryMgmt; } SQueryMgmt;
static void queryMgmtKillQueryFn(void* handle) { static void queryMgmtKillQueryFn(void* handle, void* param1) {
void** fp = (void**)handle; void** fp = (void**)handle;
qKillQuery(*fp); qKillQuery(*fp);
} }
...@@ -215,6 +215,51 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi ...@@ -215,6 +215,51 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
return code; return code;
} }
#ifdef TEST_IMPL
// wait moment
int waitMoment(SQInfo* pQInfo){
if(pQInfo->sql) {
int ms = 0;
char* pcnt = strstr(pQInfo->sql, " count(*)");
if(pcnt) return 0;
char* pos = strstr(pQInfo->sql, " t_");
if(pos){
pos += 3;
ms = atoi(pos);
while(*pos >= '0' && *pos <= '9'){
pos ++;
}
char unit_char = *pos;
if(unit_char == 'h'){
ms *= 3600*1000;
} else if(unit_char == 'm'){
ms *= 60*1000;
} else if(unit_char == 's'){
ms *= 1000;
}
}
if(ms == 0) return 0;
printf("test wait sleep %dms. sql=%s ...\n", ms, pQInfo->sql);
if(ms < 1000) {
taosMsleep(ms);
} else {
int used_ms = 0;
while(used_ms < ms) {
taosMsleep(1000);
used_ms += 1000;
if(isQueryKilled(pQInfo)){
printf("test check query is canceled, sleep break.%s\n", pQInfo->sql);
break;
}
}
}
}
return 1;
}
#endif
bool qTableQuery(qinfo_t qinfo, uint64_t *qId) { bool qTableQuery(qinfo_t qinfo, uint64_t *qId) {
SQInfo *pQInfo = (SQInfo *)qinfo; SQInfo *pQInfo = (SQInfo *)qinfo;
assert(pQInfo && pQInfo->signature == pQInfo); assert(pQInfo && pQInfo->signature == pQInfo);
...@@ -228,7 +273,8 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId) { ...@@ -228,7 +273,8 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId) {
} }
*qId = pQInfo->qId; *qId = pQInfo->qId;
pQInfo->startExecTs = taosGetTimestampSec(); if(pQInfo->startExecTs == 0)
pQInfo->startExecTs = taosGetTimestampMs();
if (isQueryKilled(pQInfo)) { if (isQueryKilled(pQInfo)) {
qDebug("QInfo:0x%"PRIx64" it is already killed, abort", pQInfo->qId); qDebug("QInfo:0x%"PRIx64" it is already killed, abort", pQInfo->qId);
...@@ -259,7 +305,9 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId) { ...@@ -259,7 +305,9 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId) {
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
pRuntimeEnv->outputBuf = pRuntimeEnv->proot->exec(pRuntimeEnv->proot, &newgroup); pRuntimeEnv->outputBuf = pRuntimeEnv->proot->exec(pRuntimeEnv->proot, &newgroup);
pQInfo->summary.elapsedTime += (taosGetTimestampUs() - st); pQInfo->summary.elapsedTime += (taosGetTimestampUs() - st);
#ifdef TEST_IMPL
waitMoment(pQInfo);
#endif
publishOperatorProfEvent(pRuntimeEnv->proot, QUERY_PROF_AFTER_OPERATOR_EXEC); publishOperatorProfEvent(pRuntimeEnv->proot, QUERY_PROF_AFTER_OPERATOR_EXEC);
pRuntimeEnv->resultInfo.total += GET_NUM_OF_RESULTS(pRuntimeEnv); pRuntimeEnv->resultInfo.total += GET_NUM_OF_RESULTS(pRuntimeEnv);
...@@ -479,7 +527,7 @@ void qQueryMgmtNotifyClosed(void* pQMgmt) { ...@@ -479,7 +527,7 @@ void qQueryMgmtNotifyClosed(void* pQMgmt) {
pQueryMgmt->closed = true; pQueryMgmt->closed = true;
pthread_mutex_unlock(&pQueryMgmt->lock); pthread_mutex_unlock(&pQueryMgmt->lock);
taosCacheRefresh(pQueryMgmt->qinfoPool, queryMgmtKillQueryFn); taosCacheRefresh(pQueryMgmt->qinfoPool, queryMgmtKillQueryFn, NULL);
} }
void qQueryMgmtReOpen(void *pQMgmt) { void qQueryMgmtReOpen(void *pQMgmt) {
...@@ -574,3 +622,148 @@ void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool freeHandle) { ...@@ -574,3 +622,148 @@ void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool freeHandle) {
taosCacheRelease(pQueryMgmt->qinfoPool, pQInfo, freeHandle); taosCacheRelease(pQueryMgmt->qinfoPool, pQInfo, freeHandle);
return 0; return 0;
} }
//kill by qid
int32_t qKillQueryByQId(void* pMgmt, int64_t qId, int32_t waitMs, int32_t waitCount) {
int32_t error = TSDB_CODE_SUCCESS;
void** handle = qAcquireQInfo(pMgmt, qId);
if(handle == NULL) return terrno;
SQInfo* pQInfo = (SQInfo*)(*handle);
if (pQInfo == NULL || !isValidQInfo(pQInfo)) {
return TSDB_CODE_QRY_INVALID_QHANDLE;
}
qWarn("QId:0x%"PRIx64" be killed(no memory commit).", pQInfo->qId);
setQueryKilled(pQInfo);
// wait query stop
int32_t loop = 0;
while (pQInfo->owner != 0) {
taosMsleep(waitMs);
if(loop++ > waitCount){
error = TSDB_CODE_FAILED;
break;
}
}
qReleaseQInfo(pMgmt, (void **)&handle, true);
return error;
}
// local struct
typedef struct {
int64_t qId;
int64_t startExecTs;
} SLongQuery;
// callbark for sort compare
static int compareLongQuery(const void* p1, const void* p2) {
// sort desc
SLongQuery* plq1 = *(SLongQuery**)p1;
SLongQuery* plq2 = *(SLongQuery**)p2;
if(plq1->startExecTs == plq2->startExecTs) {
return 0;
} else if(plq1->startExecTs > plq2->startExecTs) {
return 1;
} else {
return -1;
}
}
// callback for taosCacheRefresh
static void cbFoundItem(void* handle, void* param1) {
SQInfo * qInfo = *(SQInfo**) handle;
if(qInfo == NULL) return ;
SArray* qids = (SArray*) param1;
if(qids == NULL) return ;
bool usedMem = true;
bool usedIMem = true;
SMemTable* mem = qInfo->query.memRef.snapshot.omem;
SMemTable* imem = qInfo->query.memRef.snapshot.imem;
if(mem == NULL || T_REF_VAL_GET(mem) == 0)
usedMem = false;
if(imem == NULL || T_REF_VAL_GET(mem) == 0)
usedIMem = false ;
if(!usedMem && !usedIMem)
return ;
// push to qids
SLongQuery* plq = (SLongQuery*)malloc(sizeof(SLongQuery));
plq->qId = qInfo->qId;
plq->startExecTs = qInfo->startExecTs;
taosArrayPush(qids, &plq);
}
// longquery
void* qObtainLongQuery(void* param){
SQueryMgmt* qMgmt = (SQueryMgmt*)param;
if(qMgmt == NULL || qMgmt->qinfoPool == NULL)
return NULL;
SArray* qids = taosArrayInit(4, sizeof(int64_t*));
if(qids == NULL) return NULL;
// Get each item
taosCacheRefresh(qMgmt->qinfoPool, cbFoundItem, qids);
size_t cnt = taosArrayGetSize(qids);
if(cnt == 0) {
taosArrayDestroy(qids);
return NULL;
}
if(cnt > 1)
taosArraySort(qids, compareLongQuery);
return qids;
}
//solve tsdb no block to commit
bool qFixedNoBlock(void* pRepo, void* pMgmt, int32_t longQueryMs) {
SQueryMgmt *pQueryMgmt = pMgmt;
bool fixed = false;
// qid top list
SArray *qids = (SArray*)qObtainLongQuery(pQueryMgmt);
if(qids == NULL) return false;
// kill Query
int64_t now = taosGetTimestampMs();
size_t cnt = taosArrayGetSize(qids);
size_t i;
SLongQuery* plq;
for(i=0; i < cnt; i++) {
plq = (SLongQuery* )taosArrayGetP(qids, i);
if(plq->startExecTs > now) continue;
if(now - plq->startExecTs >= longQueryMs) {
qKillQueryByQId(pMgmt, plq->qId, 500, 10); // wait 50*100 ms
if(tsdbNoProblem(pRepo)) {
fixed = true;
qWarn("QId:0x%"PRIx64" fixed problem after kill this query.", plq->qId);
break;
}
}
}
// free qids
for(i=0; i < cnt; i++) {
free(taosArrayGetP(qids, i));
}
taosArrayDestroy(qids);
return fixed;
}
//solve tsdb no block to commit
bool qSolveCommitNoBlock(void* pRepo, void* pMgmt) {
qWarn("pRepo=%p start solve problem.", pRepo);
if(qFixedNoBlock(pRepo, pMgmt, 10*60*1000)) {
return true;
}
if(qFixedNoBlock(pRepo, pMgmt, 2*60*1000)){
return true;
}
if(qFixedNoBlock(pRepo, pMgmt, 30*1000)){
return true;
}
qWarn("pRepo=%p solve problem failed.", pRepo);
return false;
}
...@@ -407,7 +407,7 @@ void rpcSendRequest(void *shandle, const SRpcEpSet *pEpSet, SRpcMsg *pMsg, int64 ...@@ -407,7 +407,7 @@ void rpcSendRequest(void *shandle, const SRpcEpSet *pEpSet, SRpcMsg *pMsg, int64
if (type == TSDB_MSG_TYPE_QUERY || type == TSDB_MSG_TYPE_CM_RETRIEVE if (type == TSDB_MSG_TYPE_QUERY || type == TSDB_MSG_TYPE_CM_RETRIEVE
|| type == TSDB_MSG_TYPE_FETCH || type == TSDB_MSG_TYPE_CM_STABLE_VGROUP || type == TSDB_MSG_TYPE_FETCH || type == TSDB_MSG_TYPE_CM_STABLE_VGROUP
|| type == TSDB_MSG_TYPE_CM_TABLES_META || type == TSDB_MSG_TYPE_CM_TABLE_META || type == TSDB_MSG_TYPE_CM_TABLES_META || type == TSDB_MSG_TYPE_CM_TABLE_META
|| type == TSDB_MSG_TYPE_CM_SHOW || type == TSDB_MSG_TYPE_DM_STATUS) || type == TSDB_MSG_TYPE_CM_SHOW || type == TSDB_MSG_TYPE_DM_STATUS || type == TSDB_MSG_TYPE_CM_ALTER_TABLE)
pContext->connType = RPC_CONN_TCPC; pContext->connType = RPC_CONN_TCPC;
pContext->rid = taosAddRef(tsRpcRefId, pContext); pContext->rid = taosAddRef(tsRpcRefId, pContext);
......
...@@ -29,6 +29,7 @@ typedef struct { ...@@ -29,6 +29,7 @@ typedef struct {
int tBufBlocks; int tBufBlocks;
int nBufBlocks; int nBufBlocks;
int nRecycleBlocks; int nRecycleBlocks;
int nElasticBlocks;
int64_t index; int64_t index;
SList* bufBlockList; SList* bufBlockList;
} STsdbBufPool; } STsdbBufPool;
...@@ -41,6 +42,10 @@ int tsdbOpenBufPool(STsdbRepo* pRepo); ...@@ -41,6 +42,10 @@ int tsdbOpenBufPool(STsdbRepo* pRepo);
void tsdbCloseBufPool(STsdbRepo* pRepo); void tsdbCloseBufPool(STsdbRepo* pRepo);
SListNode* tsdbAllocBufBlockFromPool(STsdbRepo* pRepo); SListNode* tsdbAllocBufBlockFromPool(STsdbRepo* pRepo);
int tsdbExpandPool(STsdbRepo* pRepo, int32_t oldTotalBlocks); int tsdbExpandPool(STsdbRepo* pRepo, int32_t oldTotalBlocks);
void tsdbRecycleBufferBlock(STsdbBufPool* pPool, SListNode *pNode); void tsdbRecycleBufferBlock(STsdbBufPool* pPool, SListNode *pNode, bool bELastic);
// health cite
STsdbBufBlock *tsdbNewBufBlock(int bufBlockSize);
void tsdbFreeBufBlock(STsdbBufBlock *pBufBlock);
#endif /* _TD_TSDB_BUFFER_H_ */ #endif /* _TD_TSDB_BUFFER_H_ */
/*
* 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/>.
*/
#ifndef _TD_TSDB_HEALTH_H_
#define _TD_TSDB_HEALTH_H_
bool tsdbUrgeQueryFree(STsdbRepo* pRepo);
int32_t tsdbInsertNewBlock(STsdbRepo* pRepo);
bool tsdbIdleMemEnough();
bool tsdbAllowNewBlock(STsdbRepo* pRepo);
#endif /* _TD_TSDB_BUFFER_H_ */
...@@ -97,6 +97,7 @@ struct STsdbRepo { ...@@ -97,6 +97,7 @@ struct STsdbRepo {
SMergeBuf mergeBuf; //used when update=2 SMergeBuf mergeBuf; //used when update=2
int8_t compactState; // compact state: inCompact/noCompact/waitingCompact? int8_t compactState; // compact state: inCompact/noCompact/waitingCompact?
pthread_t* pthread;
}; };
#define REPO_ID(r) (r)->config.tsdbId #define REPO_ID(r) (r)->config.tsdbId
......
...@@ -14,12 +14,10 @@ ...@@ -14,12 +14,10 @@
*/ */
#include "tsdbint.h" #include "tsdbint.h"
#include "tsdbHealth.h"
#define POOL_IS_EMPTY(b) (listNEles((b)->bufBlockList) == 0) #define POOL_IS_EMPTY(b) (listNEles((b)->bufBlockList) == 0)
static STsdbBufBlock *tsdbNewBufBlock(int bufBlockSize);
static void tsdbFreeBufBlock(STsdbBufBlock *pBufBlock);
// ---------------- INTERNAL FUNCTIONS ---------------- // ---------------- INTERNAL FUNCTIONS ----------------
STsdbBufPool *tsdbNewBufPool() { STsdbBufPool *tsdbNewBufPool() {
STsdbBufPool *pBufPool = (STsdbBufPool *)calloc(1, sizeof(*pBufPool)); STsdbBufPool *pBufPool = (STsdbBufPool *)calloc(1, sizeof(*pBufPool));
...@@ -65,10 +63,10 @@ int tsdbOpenBufPool(STsdbRepo *pRepo) { ...@@ -65,10 +63,10 @@ int tsdbOpenBufPool(STsdbRepo *pRepo) {
STsdbBufPool *pPool = pRepo->pPool; STsdbBufPool *pPool = pRepo->pPool;
ASSERT(pPool != NULL); ASSERT(pPool != NULL);
pPool->bufBlockSize = pCfg->cacheBlockSize * 1024 * 1024; // MB pPool->bufBlockSize = pCfg->cacheBlockSize * 1024 * 1024; // MB
pPool->tBufBlocks = pCfg->totalBlocks; pPool->tBufBlocks = pCfg->totalBlocks;
pPool->nBufBlocks = 0; pPool->nBufBlocks = 0;
pPool->nElasticBlocks = 0;
pPool->index = 0; pPool->index = 0;
pPool->nRecycleBlocks = 0; pPool->nRecycleBlocks = 0;
...@@ -120,6 +118,18 @@ SListNode *tsdbAllocBufBlockFromPool(STsdbRepo *pRepo) { ...@@ -120,6 +118,18 @@ SListNode *tsdbAllocBufBlockFromPool(STsdbRepo *pRepo) {
STsdbBufPool *pBufPool = pRepo->pPool; STsdbBufPool *pBufPool = pRepo->pPool;
while (POOL_IS_EMPTY(pBufPool)) { while (POOL_IS_EMPTY(pBufPool)) {
if(tsDeadLockKillQuery) {
// supply new Block
if(tsdbInsertNewBlock(pRepo) > 0) {
tsdbWarn("vgId:%d add new elastic block . elasticBlocks=%d cur free Blocks=%d", REPO_ID(pRepo), pBufPool->nElasticBlocks, pBufPool->bufBlockList->numOfEles);
break;
} else {
// no newBlock, kill query free
if(!tsdbUrgeQueryFree(pRepo))
tsdbWarn("vgId:%d Urge query free thread start failed.", REPO_ID(pRepo));
}
}
pRepo->repoLocked = false; pRepo->repoLocked = false;
pthread_cond_wait(&(pBufPool->poolNotEmpty), &(pRepo->mutex)); pthread_cond_wait(&(pBufPool->poolNotEmpty), &(pRepo->mutex));
pRepo->repoLocked = true; pRepo->repoLocked = true;
...@@ -139,11 +149,11 @@ SListNode *tsdbAllocBufBlockFromPool(STsdbRepo *pRepo) { ...@@ -139,11 +149,11 @@ SListNode *tsdbAllocBufBlockFromPool(STsdbRepo *pRepo) {
} }
// ---------------- LOCAL FUNCTIONS ---------------- // ---------------- LOCAL FUNCTIONS ----------------
static STsdbBufBlock *tsdbNewBufBlock(int bufBlockSize) { STsdbBufBlock *tsdbNewBufBlock(int bufBlockSize) {
STsdbBufBlock *pBufBlock = (STsdbBufBlock *)malloc(sizeof(*pBufBlock) + bufBlockSize); STsdbBufBlock *pBufBlock = (STsdbBufBlock *)malloc(sizeof(*pBufBlock) + bufBlockSize);
if (pBufBlock == NULL) { if (pBufBlock == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
goto _err; return NULL;
} }
pBufBlock->blockId = 0; pBufBlock->blockId = 0;
...@@ -151,13 +161,9 @@ static STsdbBufBlock *tsdbNewBufBlock(int bufBlockSize) { ...@@ -151,13 +161,9 @@ static STsdbBufBlock *tsdbNewBufBlock(int bufBlockSize) {
pBufBlock->remain = bufBlockSize; pBufBlock->remain = bufBlockSize;
return pBufBlock; return pBufBlock;
_err:
tsdbFreeBufBlock(pBufBlock);
return NULL;
} }
static void tsdbFreeBufBlock(STsdbBufBlock *pBufBlock) { tfree(pBufBlock); } void tsdbFreeBufBlock(STsdbBufBlock *pBufBlock) { tfree(pBufBlock); }
int tsdbExpandPool(STsdbRepo* pRepo, int32_t oldTotalBlocks) { int tsdbExpandPool(STsdbRepo* pRepo, int32_t oldTotalBlocks) {
if (oldTotalBlocks == pRepo->config.totalBlocks) { if (oldTotalBlocks == pRepo->config.totalBlocks) {
...@@ -193,10 +199,16 @@ err: ...@@ -193,10 +199,16 @@ err:
return err; return err;
} }
void tsdbRecycleBufferBlock(STsdbBufPool* pPool, SListNode *pNode) { void tsdbRecycleBufferBlock(STsdbBufPool* pPool, SListNode *pNode, bool bELastic) {
STsdbBufBlock *pBufBlock = NULL; STsdbBufBlock *pBufBlock = NULL;
tdListNodeGetData(pPool->bufBlockList, pNode, (void *)(&pBufBlock)); tdListNodeGetData(pPool->bufBlockList, pNode, (void *)(&pBufBlock));
tsdbFreeBufBlock(pBufBlock); tsdbFreeBufBlock(pBufBlock);
free(pNode); free(pNode);
pPool->nBufBlocks--; if(bELastic)
} {
pPool->nElasticBlocks--;
tsdbWarn("pPool=%p elastic block reduce one . nElasticBlocks=%d cur free Blocks=%d", pPool, pPool->nElasticBlocks, pPool->bufBlockList->numOfEles);
}
else
pPool->nBufBlocks--;
}
\ No newline at end of file
/*
* 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 "os.h"
#include "taosmsg.h"
#include "tarray.h"
#include "query.h"
#include "tglobal.h"
#include "tlist.h"
#include "tsdbint.h"
#include "tsdbBuffer.h"
#include "tsdbLog.h"
#include "tsdbHealth.h"
#include "ttimer.h"
#include "tthread.h"
// return malloc new block count
int32_t tsdbInsertNewBlock(STsdbRepo * pRepo) {
STsdbBufPool *pPool = pRepo->pPool;
int32_t cnt = 0;
if(tsdbAllowNewBlock(pRepo)) {
STsdbBufBlock *pBufBlock = tsdbNewBufBlock(pPool->bufBlockSize);
if (pBufBlock) {
if (tdListAppend(pPool->bufBlockList, (void *)(&pBufBlock)) < 0) {
// append error
tsdbFreeBufBlock(pBufBlock);
} else {
pPool->nElasticBlocks ++;
cnt ++ ;
}
}
}
return cnt;
}
// switch anther thread to run
void* cbKillQueryFree(void* param) {
STsdbRepo* pRepo = (STsdbRepo*)param;
// vnode
if(pRepo->appH.notifyStatus) {
pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_NOBLOCK, TSDB_CODE_SUCCESS);
}
// free
if(pRepo->pthread){
void* p = pRepo->pthread;
pRepo->pthread = NULL;
free(p);
}
return NULL;
}
// return true do free , false do nothing
bool tsdbUrgeQueryFree(STsdbRepo * pRepo) {
// check previous running
if(pRepo->pthread && taosThreadRunning(pRepo->pthread)) {
tsdbWarn("vgId:%d pre urge thread is runing. nBlocks=%d nElasticBlocks=%d", REPO_ID(pRepo), pRepo->pPool->nBufBlocks, pRepo->pPool->nElasticBlocks);
return false;
}
// create new
pRepo->pthread = taosCreateThread(cbKillQueryFree, pRepo);
if(pRepo->pthread == NULL) {
tsdbError("vgId:%d create urge thread error.", REPO_ID(pRepo));
return false;
}
return true;
}
bool tsdbAllowNewBlock(STsdbRepo* pRepo) {
int32_t nMaxElastic = pRepo->config.totalBlocks/3;
STsdbBufPool* pPool = pRepo->pPool;
if(pPool->nElasticBlocks >= nMaxElastic) {
tsdbWarn("vgId:%d tsdbAllowNewBlock return fasle. nElasticBlock(%d) >= MaxElasticBlocks(%d)", REPO_ID(pRepo), pPool->nElasticBlocks, nMaxElastic);
return false;
}
return true;
}
bool tsdbNoProblem(STsdbRepo* pRepo) {
if(listNEles(pRepo->pPool->bufBlockList) == 0)
return false;
return true;
}
\ No newline at end of file
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
// no test file errors here // no test file errors here
#include "taosdef.h" #include "taosdef.h"
#include "tsdbint.h" #include "tsdbint.h"
#include "ttimer.h"
#include "tthread.h"
#define IS_VALID_PRECISION(precision) \ #define IS_VALID_PRECISION(precision) \
(((precision) >= TSDB_TIME_PRECISION_MILLI) && ((precision) <= TSDB_TIME_PRECISION_NANO)) (((precision) >= TSDB_TIME_PRECISION_MILLI) && ((precision) <= TSDB_TIME_PRECISION_NANO))
...@@ -126,6 +128,10 @@ int tsdbCloseRepo(STsdbRepo *repo, int toCommit) { ...@@ -126,6 +128,10 @@ int tsdbCloseRepo(STsdbRepo *repo, int toCommit) {
terrno = TSDB_CODE_SUCCESS; terrno = TSDB_CODE_SUCCESS;
tsdbStopStream(pRepo); tsdbStopStream(pRepo);
if(pRepo->pthread){
taosDestoryThread(pRepo->pthread);
pRepo->pthread = NULL;
}
if (toCommit) { if (toCommit) {
tsdbSyncCommit(repo); tsdbSyncCommit(repo);
...@@ -547,6 +553,7 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) { ...@@ -547,6 +553,7 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) {
pRepo->appH = *pAppH; pRepo->appH = *pAppH;
} }
pRepo->repoLocked = false; pRepo->repoLocked = false;
pRepo->pthread = NULL;
int code = pthread_mutex_init(&(pRepo->mutex), NULL); int code = pthread_mutex_init(&(pRepo->mutex), NULL);
if (code != 0) { if (code != 0) {
......
...@@ -99,17 +99,22 @@ int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) { ...@@ -99,17 +99,22 @@ int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
STsdbBufPool *pBufPool = pRepo->pPool; STsdbBufPool *pBufPool = pRepo->pPool;
SListNode *pNode = NULL; SListNode *pNode = NULL;
bool recycleBlocks = pBufPool->nRecycleBlocks > 0; bool addNew = false;
if (tsdbLockRepo(pRepo) < 0) return -1; if (tsdbLockRepo(pRepo) < 0) return -1;
while ((pNode = tdListPopHead(pMemTable->bufBlockList)) != NULL) { while ((pNode = tdListPopHead(pMemTable->bufBlockList)) != NULL) {
if (pBufPool->nRecycleBlocks > 0) { if (pBufPool->nRecycleBlocks > 0) {
tsdbRecycleBufferBlock(pBufPool, pNode); tsdbRecycleBufferBlock(pBufPool, pNode, false);
pBufPool->nRecycleBlocks -= 1; pBufPool->nRecycleBlocks -= 1;
} else { } else {
tdListAppendNode(pBufPool->bufBlockList, pNode); if(pBufPool->nElasticBlocks > 0 && listNEles(pBufPool->bufBlockList) > 2) {
tsdbRecycleBufferBlock(pBufPool, pNode, true);
} else {
tdListAppendNode(pBufPool->bufBlockList, pNode);
addNew = true;
}
} }
} }
if (!recycleBlocks) { if (addNew) {
int code = pthread_cond_signal(&pBufPool->poolNotEmpty); int code = pthread_cond_signal(&pBufPool->poolNotEmpty);
if (code != 0) { if (code != 0) {
if (tsdbUnlockRepo(pRepo) < 0) return -1; if (tsdbUnlockRepo(pRepo) < 0) return -1;
......
...@@ -33,6 +33,7 @@ extern "C" { ...@@ -33,6 +33,7 @@ extern "C" {
#endif #endif
typedef void (*__cache_free_fn_t)(void*); typedef void (*__cache_free_fn_t)(void*);
typedef void (*__cache_trav_fn_t)(void*, void*);
typedef struct SCacheStatis { typedef struct SCacheStatis {
int64_t missCount; int64_t missCount;
...@@ -176,7 +177,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj); ...@@ -176,7 +177,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj);
* @param fp * @param fp
* @return * @return
*/ */
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp); void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void* param1);
/** /**
* stop background refresh worker thread * stop background refresh worker thread
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#define TSDB_CFG_MAX_NUM 116 // 110 + 6 with lossy option #define TSDB_CFG_MAX_NUM 122
#define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_PRINT_LEN 23
#define TSDB_CFG_OPTION_LEN 24 #define TSDB_CFG_OPTION_LEN 24
#define TSDB_CFG_VALUE_LEN 41 #define TSDB_CFG_VALUE_LEN 41
......
/*
* 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/>.
*/
#ifndef TDENGINE_TTHREAD_H
#define TDENGINE_TTHREAD_H
#ifdef __cplusplus
extern "C" {
#endif
#include "os.h"
#include "taosdef.h"
// create new thread
pthread_t* taosCreateThread( void *(*__start_routine) (void *), void* param);
// destory thread
bool taosDestoryThread(pthread_t* pthread);
// thread running return true
bool taosThreadRunning(pthread_t* pthread);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_TTHREAD_H
...@@ -505,7 +505,8 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { ...@@ -505,7 +505,8 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
typedef struct SHashTravSupp { typedef struct SHashTravSupp {
SCacheObj* pCacheObj; SCacheObj* pCacheObj;
int64_t time; int64_t time;
__cache_free_fn_t fp; __cache_trav_fn_t fp;
void* param1;
} SHashTravSupp; } SHashTravSupp;
static bool travHashTableEmptyFn(void* param, void* data) { static bool travHashTableEmptyFn(void* param, void* data) {
...@@ -645,7 +646,7 @@ void doCleanupDataCache(SCacheObj *pCacheObj) { ...@@ -645,7 +646,7 @@ void doCleanupDataCache(SCacheObj *pCacheObj) {
// todo memory leak if there are object with refcount greater than 0 in hash table? // todo memory leak if there are object with refcount greater than 0 in hash table?
taosHashCleanup(pCacheObj->pHashTable); taosHashCleanup(pCacheObj->pHashTable);
taosTrashcanEmpty(pCacheObj, false); taosTrashcanEmpty(pCacheObj, true);
__cache_lock_destroy(pCacheObj); __cache_lock_destroy(pCacheObj);
...@@ -667,17 +668,17 @@ bool travHashTableFn(void* param, void* data) { ...@@ -667,17 +668,17 @@ bool travHashTableFn(void* param, void* data) {
} }
if (ps->fp) { if (ps->fp) {
(ps->fp)(pNode->data); (ps->fp)(pNode->data, ps->param1);
} }
// do not remove element in hash table // do not remove element in hash table
return true; return true;
} }
static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_free_fn_t fp) { static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_trav_fn_t fp, void* param1) {
assert(pCacheObj != NULL); assert(pCacheObj != NULL);
SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = fp, .time = time}; SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = fp, .time = time, .param1 = param1};
taosHashCondTraverse(pCacheObj->pHashTable, travHashTableFn, &sup); taosHashCondTraverse(pCacheObj->pHashTable, travHashTableFn, &sup);
} }
...@@ -748,7 +749,7 @@ void* taosCacheTimedRefresh(void *handle) { ...@@ -748,7 +749,7 @@ void* taosCacheTimedRefresh(void *handle) {
// refresh data in hash table // refresh data in hash table
if (elemInHash > 0) { if (elemInHash > 0) {
int64_t now = taosGetTimestampMs(); int64_t now = taosGetTimestampMs();
doCacheRefresh(pCacheObj, now, NULL); doCacheRefresh(pCacheObj, now, NULL, NULL);
} }
taosTrashcanEmpty(pCacheObj, false); taosTrashcanEmpty(pCacheObj, false);
...@@ -766,13 +767,13 @@ void* taosCacheTimedRefresh(void *handle) { ...@@ -766,13 +767,13 @@ void* taosCacheTimedRefresh(void *handle) {
return NULL; return NULL;
} }
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp) { void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void* param1) {
if (pCacheObj == NULL) { if (pCacheObj == NULL) {
return; return;
} }
int64_t now = taosGetTimestampMs(); int64_t now = taosGetTimestampMs();
doCacheRefresh(pCacheObj, now, fp); doCacheRefresh(pCacheObj, now, fp, param1);
} }
void taosStopCacheRefreshWorker(void) { void taosStopCacheRefreshWorker(void) {
......
...@@ -112,9 +112,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_EXCEED_SQL_LIMIT, "SQL statement too lon ...@@ -112,9 +112,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_EXCEED_SQL_LIMIT, "SQL statement too lon
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_FILE_EMPTY, "File is empty") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_FILE_EMPTY, "File is empty")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_LINE_SYNTAX_ERROR, "Syntax error in Line") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_LINE_SYNTAX_ERROR, "Syntax error in Line")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_META_CACHED, "No table meta cached") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_META_CACHED, "No table meta cached")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DUP_COL_NAMES, "duplicated column names") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DUP_COL_NAMES, "duplicated column names")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TAG_LENGTH, "Invalid tag length") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TAG_LENGTH, "Invalid tag length")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_COLUMN_LENGTH, "Invalid column length") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_COLUMN_LENGTH, "Invalid column length")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DUP_TAG_NAMES, "duplicated tag names")
// mnode // mnode
TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, "Message not processed") TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, "Message not processed")
......
/*
* 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 "os.h"
#include "tthread.h"
#include "tglobal.h"
#include "taosdef.h"
#include "tutil.h"
#include "tulog.h"
#include "taoserror.h"
// create new thread
pthread_t* taosCreateThread( void *(*__start_routine) (void *), void* param) {
pthread_t* pthread = (pthread_t*)malloc(sizeof(pthread_t));
pthread_attr_t thattr;
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
int32_t ret = pthread_create(pthread, &thattr, __start_routine, param);
pthread_attr_destroy(&thattr);
if (ret != 0) {
free(pthread);
return NULL;
}
return pthread;
}
// destory thread
bool taosDestoryThread(pthread_t* pthread) {
if(pthread == NULL) return false;
if(taosThreadRunning(pthread)) {
pthread_cancel(*pthread);
pthread_join(*pthread, NULL);
}
free(pthread);
return true;
}
// thread running return true
bool taosThreadRunning(pthread_t* pthread) {
if(pthread == NULL) return false;
int ret = pthread_kill(*pthread, 0);
if(ret == ESRCH)
return false;
if(ret == EINVAL)
return false;
// alive
return true;
}
...@@ -560,5 +560,10 @@ static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno) { ...@@ -560,5 +560,10 @@ static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno) {
return vnodeSaveVersion(pVnode); return vnodeSaveVersion(pVnode);
} }
// timer thread callback
if(status == TSDB_STATUS_COMMIT_NOBLOCK) {
qSolveCommitNoBlock(pVnode->tsdb, pVnode->qMgmt);
}
return 0; return 0;
} }
const taos = require('../tdengine');
var conn = taos.connect({config:"/etc/taos"});
var c1 = conn.cursor();
function checkData(sql,row,col,data){
c1.execute(sql)
var d = c1.fetchall();
let checkdata = d[row][col];
if (checkdata == data) {
// console.log('check pass')
}
else{
console.log('check failed')
console.log(checkdata)
console.log(data)
}
}
// nano basic case
c1.execute('reset query cache')
c1.execute('drop database if exists db')
c1.execute('create database db precision "ns";')
c1.execute('use db');
c1.execute('create table tb (ts timestamp, speed int)')
c1.execute('insert into tb values(\'2021-06-10 00:00:00.100000001\', 1);')
c1.execute('insert into tb values(1623254400150000000, 2);')
c1.execute('import into tb values(1623254400300000000, 3);')
c1.execute('import into tb values(1623254400299999999, 4);')
c1.execute('insert into tb values(1623254400300000001, 5);')
c1.execute('insert into tb values(1623254400999999999, 7);')
c1.execute('insert into tb values(1623254400123456789, 8);')
sql = 'select * from tb;'
console.log('*******************************************')
console.log('this is area about checkdata result')
//check data about insert data
checkData(sql,0,0,'2021-06-10 00:00:00.100000001')
checkData(sql,1,0,'2021-06-10 00:00:00.123456789')
checkData(sql,2,0,'2021-06-10 00:00:00.150000000')
checkData(sql,3,0,'2021-06-10 00:00:00.299999999') //error
checkData(sql,4,0,'2021-06-10 00:00:00.300000000')
checkData(sql,5,0,'2021-06-10 00:00:00.300000001')
checkData(sql,6,0,'2021-06-10 00:00:00.999999999') //error
// // us basic case
// c1.execute('reset query cache')
// c1.execute('drop database if exists db')
// c1.execute('create database db precision "us";')
// c1.execute('use db');
// c1.execute('create table tb (ts timestamp, speed int)')
// c1.execute('insert into tb values(\'2021-06-10 00:00:00.100001\', 1);')
// c1.execute('insert into tb values(1623254400150000, 2);')
// c1.execute('import into tb values(1623254400300000, 3);')
// c1.execute('import into tb values(1623254400299999, 4);')
// c1.execute('insert into tb values(1623254400300001, 5);')
// c1.execute('insert into tb values(1623254400999999, 7);')
// c1.execute('insert into tb values(1623254400123789, 8);')
// sql = 'select * from tb;'
// console.log('*******************************************')
// //check data about insert data
// checkData(sql,0,0,'2021-06-10 00:00:00.100001')
// checkData(sql,1,0,'2021-06-10 00:00:00.123789')
// checkData(sql,2,0,'2021-06-10 00:00:00.150000')
// checkData(sql,3,0,'2021-06-10 00:00:00.299999')
// checkData(sql,4,0,'2021-06-10 00:00:00.300000')
// checkData(sql,5,0,'2021-06-10 00:00:00.300001')
// checkData(sql,6,0,'2021-06-10 00:00:00.999999')
// console.log('*******************************************')
// // ms basic case
// c1.execute('reset query cache')
// c1.execute('drop database if exists db')
// c1.execute('create database db precision "ms";')
// c1.execute('use db');
// c1.execute('create table tb (ts timestamp, speed int)')
// c1.execute('insert into tb values(\'2021-06-10 00:00:00.101\', 1);')
// c1.execute('insert into tb values(1623254400150, 2);')
// c1.execute('import into tb values(1623254400300, 3);')
// c1.execute('import into tb values(1623254400299, 4);')
// c1.execute('insert into tb values(1623254400301, 5);')
// c1.execute('insert into tb values(1623254400789, 7);')
// c1.execute('insert into tb values(1623254400999, 8);')
// sql = 'select * from tb;'
// console.log('*******************************************')
// console.log('this is area about checkdata result')
// //check data about insert data
// checkData(sql,0,0,'2021-06-10 00:00:00.101')
// checkData(sql,1,0,'2021-06-10 00:00:00.150')
// checkData(sql,2,0,'2021-06-10 00:00:00.299')
// checkData(sql,3,0,'2021-06-10 00:00:00.300')
// checkData(sql,4,0,'2021-06-10 00:00:00.301')
// checkData(sql,5,0,'2021-06-10 00:00:00.789')
// checkData(sql,6,0,'2021-06-10 00:00:00.999')
console.log('*******************************************')
// offfical query result to show
// console.log('this is area about fetch all data')
// var query = c1.query(sql)
// var promise = query.execute();
// promise.then(function(result) {
// result.pretty();
// });
console.log('*******************************************')
// checkData(sql,3,1,3)
// checkData(sql,4,1,5)
// checkData(sql,5,1,7)
// checkData(3,1,3)
// checkData(4,1,5)
// checkData(5,1,7)
// tdSql.query('select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400100000002;')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb where ts > \'2021-06-10 0:00:00.100000001\' and ts < \'2021-06-10 0:00:00.160000000\';')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb where ts > 1623254400100000000 and ts < 1623254400150000000;')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb where ts > \'2021-06-10 0:00:00.100000000\' and ts < \'2021-06-10 0:00:00.150000000\';')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb where ts > 1623254400400000000;')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb where ts < \'2021-06-10 00:00:00.400000000\';')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb where ts > now + 400000000b;')
// tdSql.checkRows(0)
// tdSql.query('select count(*) from tb where ts >= \'2021-06-10 0:00:00.100000001\';')
// tdSql.checkData(0,0,6)
// tdSql.query('select count(*) from tb where ts <= 1623254400300000000;')
// tdSql.checkData(0,0,4)
// tdSql.query('select count(*) from tb where ts = \'2021-06-10 0:00:00.000000000\';')
// tdSql.checkRows(0)
// tdSql.query('select count(*) from tb where ts = 1623254400150000000;')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb where ts = \'2021-06-10 0:00:00.100000001\';')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb where ts between 1623254400000000000 and 1623254400400000000;')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb where ts between \'2021-06-10 0:00:00.299999999\' and \'2021-06-10 0:00:00.300000001\';')
// tdSql.checkData(0,0,3)
// tdSql.query('select avg(speed) from tb interval(5000000000b);')
// tdSql.checkRows(1)
// tdSql.query('select avg(speed) from tb interval(100000000b)')
// tdSql.checkRows(4)
// tdSql.error('select avg(speed) from tb interval(1b);')
// tdSql.error('select avg(speed) from tb interval(999b);')
// tdSql.query('select avg(speed) from tb interval(1000b);')
// tdSql.checkRows(5)
// tdSql.query('select avg(speed) from tb interval(1u);')
// tdSql.checkRows(5)
// tdSql.query('select avg(speed) from tb interval(100000000b) sliding (100000000b);')
// tdSql.checkRows(4)
// tdSql.query('select last(*) from tb')
// tdSql.checkData(0,0, '2021-06-10 0:00:00.999999999')
// tdSql.checkData(0,0, 1623254400999999999)
// tdSql.query('select first(*) from tb')
// tdSql.checkData(0,0, 1623254400100000001)
// tdSql.checkData(0,0, '2021-06-10 0:00:00.100000001')
// c1.execute('insert into tb values(now + 500000000b, 6);')
// tdSql.query('select * from tb;')
// tdSql.checkRows(7)
// tdLog.debug('testing nanosecond support in other timestamps')
// c1.execute('create table tb2 (ts timestamp, speed int, ts2 timestamp);')
// c1.execute('insert into tb2 values(\'2021-06-10 0:00:00.100000001\', 1, \'2021-06-11 0:00:00.100000001\');')
// c1.execute('insert into tb2 values(1623254400150000000, 2, 1623340800150000000);')
// c1.execute('import into tb2 values(1623254400300000000, 3, 1623340800300000000);')
// c1.execute('import into tb2 values(1623254400299999999, 4, 1623340800299999999);')
// c1.execute('insert into tb2 values(1623254400300000001, 5, 1623340800300000001);')
// c1.execute('insert into tb2 values(1623254400999999999, 7, 1623513600999999999);')
// tdSql.query('select * from tb2;')
// tdSql.checkData(0,0,'2021-06-10 0:00:00.100000001')
// tdSql.checkData(1,0,'2021-06-10 0:00:00.150000000')
// tdSql.checkData(2,1,4)
// tdSql.checkData(3,1,3)
// tdSql.checkData(4,2,'2021-06-11 00:00:00.300000001')
// tdSql.checkData(5,2,'2021-06-13 00:00:00.999999999')
// tdSql.checkRows(6)
// tdSql.query('select count(*) from tb2 where ts2 > 1623340800000000000 and ts2 < 1623340800150000000;')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb2 where ts2 > \'2021-06-11 0:00:00.100000000\' and ts2 < \'2021-06-11 0:00:00.100000002\';')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb2 where ts2 > 1623340800500000000;')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb2 where ts2 < \'2021-06-11 0:00:00.400000000\';')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb2 where ts2 > now + 400000000b;')
// tdSql.checkRows(0)
// tdSql.query('select count(*) from tb2 where ts2 >= \'2021-06-11 0:00:00.100000001\';')
// tdSql.checkData(0,0,6)
// tdSql.query('select count(*) from tb2 where ts2 <= 1623340800400000000;')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb2 where ts2 = \'2021-06-11 0:00:00.000000000\';')
// tdSql.checkRows(0)
// tdSql.query('select count(*) from tb2 where ts2 = \'2021-06-11 0:00:00.300000001\';')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb2 where ts2 = 1623340800300000001;')
// tdSql.checkData(0,0,1)
// tdSql.query('select count(*) from tb2 where ts2 between 1623340800000000000 and 1623340800450000000;')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb2 where ts2 between \'2021-06-11 0:00:00.299999999\' and \'2021-06-11 0:00:00.300000001\';')
// tdSql.checkData(0,0,3)
// tdSql.query('select count(*) from tb2 where ts2 <> 1623513600999999999;')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb2 where ts2 <> \'2021-06-11 0:00:00.100000001\';')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb2 where ts2 <> \'2021-06-11 0:00:00.100000000\';')
// tdSql.checkData(0,0,6)
// tdSql.query('select count(*) from tb2 where ts2 != 1623513600999999999;')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb2 where ts2 != \'2021-06-11 0:00:00.100000001\';')
// tdSql.checkData(0,0,5)
// tdSql.query('select count(*) from tb2 where ts2 != \'2021-06-11 0:00:00.100000000\';')
// tdSql.checkData(0,0,6)
// c1.execute('insert into tb2 values(now + 500000000b, 6, now +2d);')
// tdSql.query('select * from tb2;')
// tdSql.checkRows(7)
// tdLog.debug('testing ill nanosecond format handling')
// c1.execute('create table tb3 (ts timestamp, speed int);')
// tdSql.error('insert into tb3 values(16232544001500000, 2);')
// c1.execute('insert into tb3 values(\'2021-06-10 0:00:00.123456\', 2);')
// tdSql.query('select * from tb3 where ts = \'2021-06-10 0:00:00.123456000\';')
// tdSql.checkRows(1)
// c1.execute('insert into tb3 values(\'2021-06-10 0:00:00.123456789000\', 2);')
// tdSql.query('select * from tb3 where ts = \'2021-06-10 0:00:00.123456789\';')
// tdSql.checkRows(1)
// # check timezone support
// c1.execute('use db;')
// c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);')
// c1.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10 0:00:00.123456789+07:00" , 1.0);' )
// tdSql.query("select first(*) from tb1;")
// tdSql.checkData(0,0,1623258000123456789)
// c1.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10T0:00:00.123456789+06:00" , 2.0);' )
// tdSql.query("select last(*) from tb1;")
// tdSql.checkData(0,0,1623261600123456789)
// c1.execute('create database usdb precision "us";')
// c1.execute('use usdb;')
// c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);')
// c1.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456" , 1 ) values("2021-06-10 0:00:00.123456+07:00" , 1.0);' )
// res = tdSql.getResult("select first(*) from tb1;")
// print(res)
// if res == [(datetime.datetime(2021, 6, 10, 1, 0, 0, 123456), 1.0)]:
// tdLog.info('check timezone pass about us database')
// c1.execute('create database msdb precision "ms";')
// c1.execute('use msdb;')
// c1.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);')
// c1.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123" , 1 ) values("2021-06-10 0:00:00.123+07:00" , 1.0);' )
// res = tdSql.getResult("select first(*) from tb1;")
// print(res)
// if res ==[(datetime.datetime(2021, 6, 10, 1, 0, 0, 123000), 1.0)]:
// tdLog.info('check timezone pass about ms database')
// c1.execute('create database if not exists ' + dbname + ' precision "ns"');
// c1.execute('use ' + dbname)
// c1.execute('create table if not exists tstest (ts timestamp, _int int);');
// c1.execute('insert into tstest values(1625801548423914405, 0)');
// // Select
// console.log('select * from tstest');
// c1.execute('select * from tstest');
// var d = c1.fetchall();
// console.log(c1.fields);
// let ts = d[0][0];
// console.log(ts);
// if (ts.taosTimestamp() != 1625801548423914405) {
// throw "nanosecond not match!";
// }
// if (ts.getNanoseconds() % 1000000 !== 914405) {
// throw "nanosecond precision error";
// }
// setTimeout(function () {
// c1.query('drop database nodejs_ns_test;');
// }, 200);
// setTimeout(function () {
// conn.close();
// }, 2000);
FROM tdengine/tdengine-beta:latest
ENV DEBIAN_FRONTEND=noninteractive
ARG MIRROR=archive.ubuntu.com
RUN sed -Ei 's/\w+.ubuntu.com/'${MIRROR}'/' /etc/apt/sources.list && apt update && apt install mono-devel -y
RUN apt-get install wget -y \
&& wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& rm packages-microsoft-prod.deb \
&& apt-get update && apt-get install -y dotnet-sdk-5.0
COPY ./*.cs *.csproj /tmp/
WORKDIR /tmp/
RUN dotnet build -c Release && cp bin/Release/net5.0/taosdemo bin/Release/net5.0/taosdemo.* /usr/local/bin/ && rm -rf /tmp/*
FROM tdengine/tdengine-beta:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install wget -y \
&& wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& rm packages-microsoft-prod.deb \
&& apt-get update && apt-get install -y dotnet-runtime-5.0
COPY --from=0 /usr/local/bin/taosdemo* /usr/local/bin/
CMD ["/usr/local/bin/taosdemo"]
# C# Taosdemo
## For Mono
install build environment install build environment
===
```sh
yum/apt install mono-complete yum/apt install mono-complete
```
build C# version taosdemo build C# version taosdemo.
===
```sh
mcs -out:taosdemo *.cs mcs -out:taosdemo *.cs
./taosdemo --help
```
## For DotNet
install dotnet environment.
```sh
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& rm packages-microsoft-prod.deb \
&& apt-get update && apt-get install -y dotnet-sdk-5.0
```
Build DotNet version taosdemo.
```sh
dotnet build -c Release
./bin/Release/net5.0/taosdemo --help
```
## Usage
run C# version taosdemo ```
===
Usage: mono taosdemo.exe [OPTION...] Usage: mono taosdemo.exe [OPTION...]
--help Show usage. --help Show usage.
...@@ -34,3 +62,4 @@ Usage: mono taosdemo.exe [OPTION...] ...@@ -34,3 +62,4 @@ Usage: mono taosdemo.exe [OPTION...]
-v Print verbose output -v Print verbose output
-g Print debug output -g Print debug output
-y Skip read key for continous test, default is not skip -y Skip read key for continous test, default is not skip
```
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>
// sample code to verify all TDengine API // sample code to verify all TDengine API
// to compile: gcc -o apitest apitest.c -ltaos // to compile: gcc -o apitest apitest.c -ltaos
#include "taoserror.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <taos.h> #include <taos.h>
#include <unistd.h> #include <unistd.h>
static void prepare_data(TAOS* taos) { static void prepare_data(TAOS* taos) {
TAOS_RES *result; TAOS_RES *result;
result = taos_query(taos, "drop database if exists test;"); result = taos_query(taos, "drop database if exists test;");
...@@ -1014,6 +1017,186 @@ int32_t verify_schema_less(TAOS* taos) { ...@@ -1014,6 +1017,186 @@ int32_t verify_schema_less(TAOS* taos) {
return (code); return (code);
} }
void verify_telnet_insert(TAOS* taos) {
TAOS_RES *result;
result = taos_query(taos, "drop database if exists test;");
taos_free_result(result);
usleep(100000);
result = taos_query(taos, "create database db precision 'ms';");
taos_free_result(result);
usleep(100000);
(void)taos_select_db(taos, "db");
int32_t code = 0;
/* metric */
char* lines0[] = {
"stb0_0 1626006833639000000ns 4i8 host=\"host0\",interface=\"eth0\"",
"stb0_1 1626006833639000000ns 4i8 host=\"host0\",interface=\"eth0\"",
"stb0_2 1626006833639000000ns 4i8 host=\"host0\",interface=\"eth0\"",
};
code = taos_insert_telnet_lines(taos, lines0, 3);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
/* timestamp */
char* lines1[] = {
"stb1 1626006833s 1i8 host=\"host0\"",
"stb1 1626006833639000000ns 2i8 host=\"host0\"",
"stb1 1626006833640000us 3i8 host=\"host0\"",
"stb1 1626006833641123 4i8 host=\"host0\"",
"stb1 1626006833651ms 5i8 host=\"host0\"",
"stb1 0 6i8 host=\"host0\"",
};
code = taos_insert_telnet_lines(taos, lines1, 6);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
/* metric value */
//tinyin
char* lines2_0[] = {
"stb2_0 1626006833651ms -127i8 host=\"host0\"",
"stb2_0 1626006833652ms 127i8 host=\"host0\""
};
code = taos_insert_telnet_lines(taos, lines2_0, 2);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//smallint
char* lines2_1[] = {
"stb2_1 1626006833651ms -32767i16 host=\"host0\"",
"stb2_1 1626006833652ms 32767i16 host=\"host0\""
};
code = taos_insert_telnet_lines(taos, lines2_1, 2);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//int
char* lines2_2[] = {
"stb2_2 1626006833651ms -2147483647i32 host=\"host0\"",
"stb2_2 1626006833652ms 2147483647i32 host=\"host0\""
};
code = taos_insert_telnet_lines(taos, lines2_2, 2);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//bigint
char* lines2_3[] = {
"stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"",
"stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\""
};
code = taos_insert_telnet_lines(taos, lines2_3, 2);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//float
char* lines2_4[] = {
"stb2_4 1626006833610ms 3f32 host=\"host0\"",
"stb2_4 1626006833620ms -3f32 host=\"host0\"",
"stb2_4 1626006833630ms 3.4f32 host=\"host0\"",
"stb2_4 1626006833640ms -3.4f32 host=\"host0\"",
"stb2_4 1626006833650ms 3.4E10f32 host=\"host0\"",
"stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"",
"stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"",
"stb2_4 1626006833680ms -3.4e-2f32 host=\"host0\"",
"stb2_4 1626006833690ms 3.15 host=\"host0\"",
"stb2_4 1626006833700ms 3.4E38f32 host=\"host0\"",
"stb2_4 1626006833710ms -3.4E38f32 host=\"host0\""
};
code = taos_insert_telnet_lines(taos, lines2_4, 11);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//double
char* lines2_5[] = {
"stb2_5 1626006833610ms 3f64 host=\"host0\"",
"stb2_5 1626006833620ms -3f64 host=\"host0\"",
"stb2_5 1626006833630ms 3.4f64 host=\"host0\"",
"stb2_5 1626006833640ms -3.4f64 host=\"host0\"",
"stb2_5 1626006833650ms 3.4E10f64 host=\"host0\"",
"stb2_5 1626006833660ms -3.4e10f64 host=\"host0\"",
"stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"",
"stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"",
"stb2_5 1626006833690ms 1.7E308f64 host=\"host0\"",
"stb2_5 1626006833700ms -1.7E308f64 host=\"host0\""
};
code = taos_insert_telnet_lines(taos, lines2_5, 10);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//bool
char* lines2_6[] = {
"stb2_6 1626006833610ms t host=\"host0\"",
"stb2_6 1626006833620ms T host=\"host0\"",
"stb2_6 1626006833630ms true host=\"host0\"",
"stb2_6 1626006833640ms True host=\"host0\"",
"stb2_6 1626006833650ms TRUE host=\"host0\"",
"stb2_6 1626006833660ms f host=\"host0\"",
"stb2_6 1626006833670ms F host=\"host0\"",
"stb2_6 1626006833680ms false host=\"host0\"",
"stb2_6 1626006833690ms False host=\"host0\"",
"stb2_6 1626006833700ms FALSE host=\"host0\""
};
code = taos_insert_telnet_lines(taos, lines2_6, 10);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//binary
char* lines2_7[] = {
"stb2_7 1626006833610ms \"binary_val.!@#$%^&*\" host=\"host0\"",
"stb2_7 1626006833620ms \"binary_val.:;,./?|+-=\" host=\"host0\"",
"stb2_7 1626006833630ms \"binary_val.()[]{}<>\" host=\"host0\""
};
code = taos_insert_telnet_lines(taos, lines2_7, 3);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//nchar
char* lines2_8[] = {
"stb2_8 1626006833610ms L\"nchar_val数值一\" host=\"host0\"",
"stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\"",
};
code = taos_insert_telnet_lines(taos, lines2_8, 2);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
/* tags */
//tag value types
char* lines3_0[] = {
"stb3_0 1626006833610ms 1 t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=3.4E38f32,t6=1.7E308f64,t7=true,t8=\"binary_val_1\",t9=L\"标签值1\"",
"stb3_0 1626006833610ms 2 t1=-127i8,t2=-32767i16,t3=-2147483647i32,t4=-9223372036854775807i64,t5=-3.4E38f32,t6=-1.7E308f64,t7=false,t8=\"binary_val_2\",t9=L\"标签值2\""
};
code = taos_insert_telnet_lines(taos, lines3_0, 2);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
//tag ID as child table name
char* lines3_1[] = {
"stb3_1 1626006833610ms 1 id=\"child_table1\",host=\"host1\"",
"stb3_1 1626006833610ms 2 host=\"host2\",iD=\"child_table2\"",
"stb3_1 1626006833610ms 3 ID=\"child_table3\",host=\"host3\""
};
code = taos_insert_telnet_lines(taos, lines3_1, 3);
if (code) {
printf("code: %d, %s.\n", code, tstrerror(code));
}
return;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
const char* host = "127.0.0.1"; const char* host = "127.0.0.1";
const char* user = "root"; const char* user = "root";
...@@ -1034,6 +1217,8 @@ int main(int argc, char *argv[]) { ...@@ -1034,6 +1217,8 @@ int main(int argc, char *argv[]) {
printf("************ verify schema-less *************\n"); printf("************ verify schema-less *************\n");
verify_schema_less(taos); verify_schema_less(taos);
printf("************ verify telnet-insert *************\n");
verify_telnet_insert(taos);
printf("************ verify query *************\n"); printf("************ verify query *************\n");
verify_query(taos); verify_query(taos);
...@@ -1051,7 +1236,7 @@ int main(int argc, char *argv[]) { ...@@ -1051,7 +1236,7 @@ int main(int argc, char *argv[]) {
verify_prepare2(taos); verify_prepare2(taos);
printf("************ verify prepare3 *************\n"); printf("************ verify prepare3 *************\n");
verify_prepare3(taos); verify_prepare3(taos);
printf("************ verify stream *************\n"); printf("************ verify stream *************\n");
verify_stream(taos); verify_stream(taos);
printf("done\n"); printf("done\n");
......
@echo off @echo off
echo ==== start Go connector test cases test ==== echo ==== start Go connector test cases test ====
cd /d %~dp0 cd /d %~dp0
...@@ -18,3 +19,10 @@ rem case002.bat ...@@ -18,3 +19,10 @@ rem case002.bat
:: cd case002 :: cd case002
:: case002.bat :: case002.bat
rem cd nanosupport
rem nanoCase.bat
:: cd nanosupport
:: nanoCase.bat
\ No newline at end of file
...@@ -19,6 +19,4 @@ go env -w GOPROXY=https://goproxy.io,direct ...@@ -19,6 +19,4 @@ go env -w GOPROXY=https://goproxy.io,direct
bash ./case001/case001.sh $severIp $serverPort bash ./case001/case001.sh $severIp $serverPort
bash ./case002/case002.sh $severIp $serverPort bash ./case002/case002.sh $severIp $serverPort
#bash ./case003/case003.sh $severIp $serverPort #bash ./case003/case003.sh $severIp $serverPort
bash ./nanosupport/nanoCase.sh $severIp $serverPort
cd nanosupport
go run main.go
module demotest
go 1.13
require github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed h1:inSmPB0XSiyPZ6B66KnMsfyVVshH0mg2L0ld1b2aLtA=
github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed/go.mod h1:k0UvvUy5mlSz4M+InxT3MZYO/eaTWXs7hO9ndLTeevU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
@echo off @echo off
echo ==== start run cases001.go echo ==== start run cases002.go
del go.* del go.*
go mod init demotest go mod init demotest
......
...@@ -43,10 +43,9 @@ func main() { ...@@ -43,10 +43,9 @@ func main() {
os.Exit(1) os.Exit(1)
} }
defer db.Close() defer db.Close()
db.Exec("drop if exists database test") db.Exec("drop database if exists test")
db.Exec("create if not exists database test") db.Exec("create database if not exists test ")
db.Exec("use test") db.Exec("use test")
db.Exec("drop if exists database test")
db.Exec("create table test (ts timestamp ,level int)") db.Exec("create table test (ts timestamp ,level int)")
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
sqlcmd := fmt.Sprintf("insert into test values(%d,%d)", ts+i, i) sqlcmd := fmt.Sprintf("insert into test values(%d,%d)", ts+i, i)
......
#!/bin/bash #!/bin/bash
echo "==== start run cases001.go" echo "==== start run cases002.go"
set +e set +e
#set -x #set -x
......
module taos
go 1.16
require github.com/taosdata/go-utils v0.0.0-20210811075537-2ce661ccb743
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk=
github.com/gin-contrib/gzip v0.0.3/go.mod h1:YxxswVZIqOvcHEQpsSn+QF5guQtO1dCfy0shBPy4jFc=
github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/panjf2000/ants/v2 v2.4.6 h1:drmj9mcygn2gawZ155dRbo+NfXEfAssjZNU1qoIb4gQ=
github.com/panjf2000/ants/v2 v2.4.6/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed h1:inSmPB0XSiyPZ6B66KnMsfyVVshH0mg2L0ld1b2aLtA=
github.com/taosdata/driver-go v0.0.0-20210811072315-2cda9f1dc9ed/go.mod h1:k0UvvUy5mlSz4M+InxT3MZYO/eaTWXs7hO9ndLTeevU=
github.com/taosdata/go-utils v0.0.0-20210811075537-2ce661ccb743 h1:w90OkSLXv4d7uEcU8fH70pB5tawNYYZ1qjhDfg7oFTQ=
github.com/taosdata/go-utils v0.0.0-20210811075537-2ce661ccb743/go.mod h1:WRQlPHYbVvsRmtIDJ4GS31BbiTQnFHFdhh0XpLavTIg=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
@echo off
echo ==== start run nanosupport.go
del go.*
go mod init nano
go mod tidy
go build
nano.exe -h %1 -p %2
cd ..
#!/bin/bash
echo "==== start run nanosupport.go "
set +e
#set -x
script_dir="$(dirname $(readlink -f $0))"
#echo "pwd: $script_dir, para0: $0"
#execName=$0
#execName=`echo ${execName##*/}`
#goName=`echo ${execName%.*}`
###### step 3: start build
cd $script_dir
rm -f go.*
go mod init nano
go mod tidy
go build
sleep 10s
./nano -h $1 -p $2
...@@ -3,7 +3,7 @@ package main ...@@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"taos/connector" "nano/connector"
"time" "time"
"github.com/taosdata/go-utils/tdengine/config" "github.com/taosdata/go-utils/tdengine/config"
......
...@@ -21,7 +21,8 @@ fi ...@@ -21,7 +21,8 @@ fi
today=`date +"%Y%m%d"` today=`date +"%Y%m%d"`
WORK_DIR=/root/pxiao WORK_DIR=/root/pxiao
PERFORMANCE_TEST_REPORT=$WORK_DIR/TDengine/tests/performance-report-$branch-$type-$today.log name=`echo $branch | cut -d '/' -f2`
PERFORMANCE_TEST_REPORT=$WORK_DIR/TDinternal/community/tests/performance-report-$name-$type-$today.log
# Coloured Echoes # # Coloured Echoes #
function red_echo { echo -e "\033[31m$@\033[0m"; } # function red_echo { echo -e "\033[31m$@\033[0m"; } #
...@@ -54,11 +55,12 @@ function stopTaosd { ...@@ -54,11 +55,12 @@ function stopTaosd {
} }
function buildTDengine { function buildTDengine {
echoInfo "Build TDengine" echoInfo "Build TDinternal"
cd $WORK_DIR/TDengine cd $WORK_DIR/TDinternal
git remote update > /dev/null git remote update > /dev/null
git reset --hard HEAD git reset --hard HEAD
git fetch
git checkout $branch git checkout $branch
REMOTE_COMMIT=`git rev-parse --short remotes/origin/$branch` REMOTE_COMMIT=`git rev-parse --short remotes/origin/$branch`
LOCAL_COMMIT=`git rev-parse --short @` LOCAL_COMMIT=`git rev-parse --short @`
...@@ -69,13 +71,22 @@ function buildTDengine { ...@@ -69,13 +71,22 @@ function buildTDengine {
echo "repo up-to-date" echo "repo up-to-date"
fi fi
cd community
git reset --hard HEAD
cd ..
echo "git submodule update --init --recursive"
git submodule update --init --recursive
git pull > /dev/null 2>&1 git pull > /dev/null 2>&1
if [ $type = "jemalloc" ];then
echo "git submodule update --init --recursive" cd community
git submodule update --init --recursive git remote update > /dev/null
fi git reset --hard HEAD
git fetch
git checkout $branch
REMOTE_COMMIT=`git rev-parse --short remotes/origin/$branch`
LOCAL_COMMIT=`git rev-parse --short @` LOCAL_COMMIT=`git rev-parse --short @`
cd debug cd ../debug
rm -rf * rm -rf *
if [ $type = "jemalloc" ];then if [ $type = "jemalloc" ];then
echo "cmake .. -DJEMALLOC_ENABLED=true > /dev/null" echo "cmake .. -DJEMALLOC_ENABLED=true > /dev/null"
...@@ -83,6 +94,10 @@ function buildTDengine { ...@@ -83,6 +94,10 @@ function buildTDengine {
else else
cmake .. > /dev/null cmake .. > /dev/null
fi fi
#cp $WORK_DIR/taosdemoPerformance.py $WORK_DIR/TDinternal/community/tests/pytest/tools/
#cp $WORK_DIR/insertFromCSVPerformance.py $WORK_DIR/TDinternal/community/tests/pytest/insert/
#cp $WORK_DIR/queryPerformance.py $WORK_DIR/TDinternal/community/tests/pytest/query/
rm -rf $WORK_DIR/TDinternal/community/tests/pytest/query/operator.py
make > /dev/null 2>&1 make > /dev/null 2>&1
make install > /dev/null 2>&1 make install > /dev/null 2>&1
echo "Build TDengine on remote server" echo "Build TDengine on remote server"
...@@ -91,24 +106,24 @@ function buildTDengine { ...@@ -91,24 +106,24 @@ function buildTDengine {
function runQueryPerfTest { function runQueryPerfTest {
[ -f $PERFORMANCE_TEST_REPORT ] && rm $PERFORMANCE_TEST_REPORT [ -f $PERFORMANCE_TEST_REPORT ] && rm $PERFORMANCE_TEST_REPORT
nohup $WORK_DIR/TDengine/debug/build/bin/taosd -c /etc/perf/ > /dev/null 2>&1 & nohup $WORK_DIR/TDinternal/debug/build/bin/taosd -c /etc/perf/ > /dev/null 2>&1 &
echoInfo "Wait TDengine to start" echoInfo "Wait TDengine to start"
sleep 60 sleep 60
echoInfo "Run Performance Test" echoInfo "Run Performance Test"
cd $WORK_DIR/TDengine/tests/pytest cd $WORK_DIR/TDinternal/community/tests/pytest
python3 query/queryPerformance.py -c $LOCAL_COMMIT -b $branch -T $type | tee -a $PERFORMANCE_TEST_REPORT python3 query/queryPerformance.py -c $LOCAL_COMMIT -b $branch -T $type -d perf2 | tee -a $PERFORMANCE_TEST_REPORT
python3 insert/insertFromCSVPerformance.py -c $LOCAL_COMMIT -b $branch -T $type | tee -a $PERFORMANCE_TEST_REPORT python3 insert/insertFromCSVPerformance.py -c $LOCAL_COMMIT -b $branch -T $type | tee -a $PERFORMANCE_TEST_REPORT
echo "=========== taosdemo performance: 4 int columns, 10000 tables, 100000 recoreds per table ===========" | tee -a $PERFORMANCE_TEST_REPORT echo "=========== taosdemo performance: 4 int columns, 10000 tables, 100000 recoreds per table ===========" | tee -a $PERFORMANCE_TEST_REPORT
python3 tools/taosdemoPerformance.py -c $LOCAL_COMMIT -b $branch -T $type | tee -a $PERFORMANCE_TEST_REPORT python3 tools/taosdemoPerformance.py -c $LOCAL_COMMIT -b $branch -T $type | tee -a $PERFORMANCE_TEST_REPORT
echo "=========== taosdemo performance: 400 int columns, 400 double columns, 200 binary(128) columns, 10000 tables, 1000 recoreds per table ===========" | tee -a $PERFORMANCE_TEST_REPORT echo "=========== taosdemo performance: 400 int columns, 400 double columns, 200 binary(128) columns, 10000 tables, 10 recoreds per table ===========" | tee -a $PERFORMANCE_TEST_REPORT
python3 tools/taosdemoPerformance.py -c $LOCAL_COMMIT -b $branch -T $type -i 400 -D 400 -B 200 -t 10000 -r 100 | tee -a $PERFORMANCE_TEST_REPORT python3 tools/taosdemoPerformance.py -c $LOCAL_COMMIT -b $branch -T $type -i 400 -D 400 -B 200 -t 10000 -r 10 | tee -a $PERFORMANCE_TEST_REPORT
echo "=========== taosdemo performance: 1900 int columns, 1900 double columns, 200 binary(128) columns, 10000 tables, 1000 recoreds per table ===========" | tee -a $PERFORMANCE_TEST_REPORT echo "=========== taosdemo performance: 1900 int columns, 1900 double columns, 200 binary(128) columns, 10000 tables, 10 recoreds per table ===========" | tee -a $PERFORMANCE_TEST_REPORT
python3 tools/taosdemoPerformance.py -c $LOCAL_COMMIT -b $branch -T $type -i 1900 -D 1900 -B 200 -t 10000 -r 100 | tee -a $PERFORMANCE_TEST_REPORT python3 tools/taosdemoPerformance.py -c $LOCAL_COMMIT -b $branch -T $type -i 1900 -D 1900 -B 200 -t 10000 -r 10 | tee -a $PERFORMANCE_TEST_REPORT
} }
...@@ -121,7 +136,7 @@ function sendReport { ...@@ -121,7 +136,7 @@ function sendReport {
sed -i 's/\x1b\[[0-9;]*m//g' $PERFORMANCE_TEST_REPORT sed -i 's/\x1b\[[0-9;]*m//g' $PERFORMANCE_TEST_REPORT
BODY_CONTENT=`cat $PERFORMANCE_TEST_REPORT` BODY_CONTENT=`cat $PERFORMANCE_TEST_REPORT`
echo -e "From: <support@taosdata.com>\nto: ${receiver}\nsubject: Query Performace Report ${branch} ${jemalloc} commit ID: ${LOCAL_COMMIT}\n\n${today}:\n${BODY_CONTENT}" | \ echo -e "From: <support@taosdata.com>\nto: ${receiver}\nsubject: Query Performace Report ${branch} ${type} commit ID: ${LOCAL_COMMIT}\n\n${today}:\n${BODY_CONTENT}" | \
(cat - && uuencode $PERFORMANCE_TEST_REPORT performance-test-report-$today.log) | \ (cat - && uuencode $PERFORMANCE_TEST_REPORT performance-test-report-$today.log) | \
/usr/sbin/ssmtp "${receiver}" && echo "Report Sent!" /usr/sbin/ssmtp "${receiver}" && echo "Report Sent!"
} }
......
# ################################################################# # #################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc. # Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved. # All rights reserved.
...@@ -21,7 +20,7 @@ from util.sql import * ...@@ -21,7 +20,7 @@ from util.sql import *
import time import time
from datetime import datetime from datetime import datetime
import os import os
import datetime
class TDTestCase: class TDTestCase:
def init(self, conn, logSql): def init(self, conn, logSql):
...@@ -209,43 +208,6 @@ class TDTestCase: ...@@ -209,43 +208,6 @@ class TDTestCase:
tdSql.query('select * from tb3 where ts = \'2021-06-10 0:00:00.123456789\';') tdSql.query('select * from tb3 where ts = \'2021-06-10 0:00:00.123456789\';')
tdSql.checkRows(1) tdSql.checkRows(1)
# check timezone support
tdSql.execute('drop database if exists nsdb;')
tdSql.execute('create database nsdb precision "ns";')
tdSql.execute('use nsdb;')
tdSql.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);')
tdSql.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10T0:00:00.123456789+07:00" , 1.0);' )
tdSql.query("select first(*) from tb1;")
res = tdSql.getResult("select first(*) from tb1;")
tdSql.checkData(0,0,1623258000123456789)
tdSql.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456789" , 1 ) values("2021-06-10T0:00:00.123456789+06:00" , 2.0);' )
tdSql.query("select last(*) from tb1;")
tdSql.execute('create database usdb precision "us";')
tdSql.execute('use usdb;')
tdSql.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);')
tdSql.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123456" , 1 ) values("2021-06-10T0:00:00.123456+07:00" , 1.0);' )
res = tdSql.getResult("select first(*) from tb1;")
print(res)
if res == [(datetime.datetime(2021, 6, 10, 1, 0, 0, 123456), 1.0)]:
tdLog.info('check timezone pass about us database')
tdSql.execute('drop database if exists msdb;')
tdSql.execute('create database msdb precision "ms";')
tdSql.execute('use msdb;')
tdSql.execute('create stable st (ts timestamp ,speed float ) tags(time timestamp ,id int);')
tdSql.execute('insert into tb1 using st tags("2021-06-10 0:00:00.123" , 1 ) values("2021-06-10T0:00:00.123+07:00" , 1.0);' )
res = tdSql.getResult("select first(*) from tb1;")
print(res)
if res ==[(datetime.datetime(2021, 6, 10, 1, 0, 0, 123000), 1.0)]:
tdLog.info('check timezone pass about ms database')
os.system('rm -rf ./*.py.sql')
os.system('sudo timedatectl set-ntp on') os.system('sudo timedatectl set-ntp on')
def stop(self): def stop(self):
...@@ -254,4 +216,4 @@ class TDTestCase: ...@@ -254,4 +216,4 @@ class TDTestCase:
tdCases.addWindows(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
...@@ -13,7 +13,6 @@ python3 ./test.py -f insert/tinyint.py ...@@ -13,7 +13,6 @@ python3 ./test.py -f insert/tinyint.py
python3 ./test.py -f insert/date.py python3 ./test.py -f insert/date.py
python3 ./test.py -f insert/binary.py python3 ./test.py -f insert/binary.py
python3 ./test.py -f insert/nchar.py python3 ./test.py -f insert/nchar.py
#python3 ./test.py -f insert/nchar-boundary.py #python3 ./test.py -f insert/nchar-boundary.py
python3 ./test.py -f insert/nchar-unicode.py python3 ./test.py -f insert/nchar-unicode.py
python3 ./test.py -f insert/multi.py python3 ./test.py -f insert/multi.py
...@@ -83,9 +82,8 @@ python3 ./test.py -f tag_lite/tinyint.py ...@@ -83,9 +82,8 @@ python3 ./test.py -f tag_lite/tinyint.py
python3 ./test.py -f tag_lite/timestamp.py python3 ./test.py -f tag_lite/timestamp.py
python3 ./test.py -f tag_lite/TestModifyTag.py python3 ./test.py -f tag_lite/TestModifyTag.py
#python3 ./test.py -f dbmgmt/database-name-boundary.py
#nano support test python3 test.py -f dbmgmt/nanoSecondCheck.py
python3 test.py -f nanosupport/nanosupportTestCase.py
python3 ./test.py -f import_merge/importBlock1HO.py python3 ./test.py -f import_merge/importBlock1HO.py
python3 ./test.py -f import_merge/importBlock1HPO.py python3 ./test.py -f import_merge/importBlock1HPO.py
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys
import numpy as np
from util.log import * from util.log import *
from util.cases import * from util.cases import *
from util.sql import * from util.sql import *
...@@ -24,8 +26,17 @@ class TDTestCase: ...@@ -24,8 +26,17 @@ class TDTestCase:
tdSql.init(conn.cursor(), logSql) tdSql.init(conn.cursor(), logSql)
def run(self): def run(self):
# tdSql.query("show variables")
# tdSql.checkData(54, 1, 864000)
tdSql.execute("show variables")
res = tdSql.cursor.fetchall()
resList = np.array(res)
index = np.where(resList == "offlineThreshold")
index_value = np.dstack((index[0])).squeeze()
tdSql.query("show variables") tdSql.query("show variables")
tdSql.checkData(55, 1, 864000) tdSql.checkData(index_value, 1, 864000)
pass
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
###################################################################
# Copyright (c) 2021 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self._conn = conn
def run(self):
print("running {}".format(__file__))
tdSql.execute("drop database if exists test")
tdSql.execute("create database if not exists test precision 'us'")
tdSql.execute('use test')
### metric ###
print("============= step1 : test metric ================")
lines0 = [
"stb0_0 1626006833639000000ns 4i8 host=\"host0\",interface=\"eth0\"",
"stb0_1 1626006833639000000ns 4i8 host=\"host0\",interface=\"eth0\"",
"stb0_2 1626006833639000000ns 4i8 host=\"host0\",interface=\"eth0\"",
]
code = self._conn.insert_telnet_lines(lines0)
print("insert_telnet_lines result {}".format(code))
tdSql.query("show stables")
tdSql.checkRows(3)
tdSql.query("describe stb0_0")
tdSql.checkRows(4)
tdSql.query("describe stb0_1")
tdSql.checkRows(4)
tdSql.query("describe stb0_2")
tdSql.checkRows(4)
### timestamp ###
print("============= step2 : test timestamp ================")
lines1 = [
"stb1 1626006833s 1i8 host=\"host0\"",
"stb1 1626006833639000000ns 2i8 host=\"host0\"",
"stb1 1626006833640000us 3i8 host=\"host0\"",
"stb1 1626006833641123 4i8 host=\"host0\"",
"stb1 1626006833651ms 5i8 host=\"host0\"",
"stb1 0 6i8 host=\"host0\"",
]
code = self._conn.insert_telnet_lines(lines1)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb1")
tdSql.checkRows(6)
### metric value ###
print("============= step3 : test metric value ================")
#tinyint
lines2_0 = [
"stb2_0 1626006833651ms -127i8 host=\"host0\"",
"stb2_0 1626006833652ms 127i8 host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_0)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_0")
tdSql.checkRows(2)
tdSql.query("describe stb2_0")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "TINYINT")
#smallint
lines2_1 = [
"stb2_1 1626006833651ms -32767i16 host=\"host0\"",
"stb2_1 1626006833652ms 32767i16 host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_1)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_1")
tdSql.checkRows(2)
tdSql.query("describe stb2_1")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "SMALLINT")
#int
lines2_2 = [
"stb2_2 1626006833651ms -2147483647i32 host=\"host0\"",
"stb2_2 1626006833652ms 2147483647i32 host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_2)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_2")
tdSql.checkRows(2)
tdSql.query("describe stb2_2")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "INT")
#bigint
lines2_3 = [
"stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"",
"stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_3)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_3")
tdSql.checkRows(2)
tdSql.query("describe stb2_3")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "BIGINT")
#float
lines2_4 = [
"stb2_4 1626006833610ms 3f32 host=\"host0\"",
"stb2_4 1626006833620ms -3f32 host=\"host0\"",
"stb2_4 1626006833630ms 3.4f32 host=\"host0\"",
"stb2_4 1626006833640ms -3.4f32 host=\"host0\"",
"stb2_4 1626006833650ms 3.4E10f32 host=\"host0\"",
"stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"",
"stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"",
"stb2_4 1626006833680ms -3.4e-2f32 host=\"host0\"",
"stb2_4 1626006833690ms 3.15 host=\"host0\"",
"stb2_4 1626006833700ms 3.4E38f32 host=\"host0\"",
"stb2_4 1626006833710ms -3.4E38f32 host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_4)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_4")
tdSql.checkRows(11)
tdSql.query("describe stb2_4")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "FLOAT")
#double
lines2_5 = [
"stb2_5 1626006833610ms 3f64 host=\"host0\"",
"stb2_5 1626006833620ms -3f64 host=\"host0\"",
"stb2_5 1626006833630ms 3.4f64 host=\"host0\"",
"stb2_5 1626006833640ms -3.4f64 host=\"host0\"",
"stb2_5 1626006833650ms 3.4E10f64 host=\"host0\"",
"stb2_5 1626006833660ms -3.4e10f64 host=\"host0\"",
"stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"",
"stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"",
"stb2_5 1626006833690ms 1.7E308f64 host=\"host0\"",
"stb2_5 1626006833700ms -1.7E308f64 host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_5)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_5")
tdSql.checkRows(10)
tdSql.query("describe stb2_5")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "DOUBLE")
#bool
lines2_6 = [
"stb2_6 1626006833610ms t host=\"host0\"",
"stb2_6 1626006833620ms T host=\"host0\"",
"stb2_6 1626006833630ms true host=\"host0\"",
"stb2_6 1626006833640ms True host=\"host0\"",
"stb2_6 1626006833650ms TRUE host=\"host0\"",
"stb2_6 1626006833660ms f host=\"host0\"",
"stb2_6 1626006833670ms F host=\"host0\"",
"stb2_6 1626006833680ms false host=\"host0\"",
"stb2_6 1626006833690ms False host=\"host0\"",
"stb2_6 1626006833700ms FALSE host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_6)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_6")
tdSql.checkRows(10)
tdSql.query("describe stb2_6")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "BOOL")
#binary
lines2_7 = [
"stb2_7 1626006833610ms \"binary_val.!@#$%^&*\" host=\"host0\"",
"stb2_7 1626006833620ms \"binary_val.:;,./?|+-=\" host=\"host0\"",
"stb2_7 1626006833630ms \"binary_val.()[]{}<>\" host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_7)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_7")
tdSql.checkRows(3)
tdSql.query("describe stb2_7")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "BINARY")
#nchar
lines2_8 = [
"stb2_8 1626006833610ms L\"nchar_val数值一\" host=\"host0\"",
"stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\""
]
code = self._conn.insert_telnet_lines(lines2_8)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_8")
tdSql.checkRows(2)
tdSql.query("describe stb2_8")
tdSql.checkRows(3)
tdSql.checkData(1, 1, "NCHAR")
### tags ###
print("============= step3 : test tags ================")
#tag value types
lines3_0 = [
"stb3_0 1626006833610ms 1 t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=3.4E38f32,t6=1.7E308f64,t7=true,t8=\"binary_val_1\",t9=L\"标签值1\"",
"stb3_0 1626006833610ms 2 t1=-127i8,t2=-32767i16,t3=-2147483647i32,t4=-9223372036854775807i64,t5=-3.4E38f32,t6=-1.7E308f64,t7=false,t8=\"binary_val_2\",t9=L\"标签值2\""
]
code = self._conn.insert_telnet_lines(lines3_0)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb3_0")
tdSql.checkRows(2)
tdSql.query("describe stb3_0")
tdSql.checkRows(11)
tdSql.checkData(2, 1, "TINYINT")
tdSql.checkData(2, 3, "TAG")
tdSql.checkData(3, 1, "SMALLINT")
tdSql.checkData(3, 3, "TAG")
tdSql.checkData(4, 1, "INT")
tdSql.checkData(4, 3, "TAG")
tdSql.checkData(5, 1, "BIGINT")
tdSql.checkData(5, 3, "TAG")
tdSql.checkData(6, 1, "FLOAT")
tdSql.checkData(6, 3, "TAG")
tdSql.checkData(7, 1, "DOUBLE")
tdSql.checkData(7, 3, "TAG")
tdSql.checkData(8, 1, "BOOL")
tdSql.checkData(8, 3, "TAG")
tdSql.checkData(9, 1, "BINARY")
tdSql.checkData(9, 3, "TAG")
tdSql.checkData(10, 1, "NCHAR")
tdSql.checkData(10, 3, "TAG")
#tag ID as child table name
lines3_1 = [
"stb3_1 1626006833610ms 1 id=\"child_table1\",host=\"host1\"",
"stb3_1 1626006833610ms 2 host=\"host2\",iD=\"child_table2\"",
"stb3_1 1626006833610ms 3 ID=\"child_table3\",host=\"host3\""
]
code = self._conn.insert_telnet_lines(lines3_1)
print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb3_1")
tdSql.checkRows(3)
tdSql.query("show tables like \"child%\"")
tdSql.checkRows(3)
tdSql.checkData(0, 0, "child_table1")
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# Copyright (c) 2021 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import traceback
import random
import string
from taos.error import LinesError
import time
from copy import deepcopy
import numpy as np
from util.log import *
from util.cases import *
from util.sql import *
from util.common import tdCom
import threading
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self._conn = conn
def createDb(self, name="test", db_update_tag=0):
if db_update_tag == 0:
tdSql.execute(f"drop database if exists {name}")
tdSql.execute(f"create database if not exists {name} precision 'us'")
else:
tdSql.execute(f"drop database if exists {name}")
tdSql.execute(f"create database if not exists {name} precision 'us' update 1")
tdSql.execute(f'use {name}')
def timeTrans(self, time_value):
if time_value.endswith("ns"):
ts = int(''.join(list(filter(str.isdigit, time_value))))/1000000000
elif time_value.endswith("us") or time_value.isdigit() and int(time_value) != 0:
ts = int(''.join(list(filter(str.isdigit, time_value))))/1000000
elif time_value.endswith("ms"):
ts = int(''.join(list(filter(str.isdigit, time_value))))/1000
elif time_value.endswith("s") and list(time_value)[-1] not in "num":
ts = int(''.join(list(filter(str.isdigit, time_value))))/1
elif int(time_value) == 0:
ts = time.time()
else:
print("input ts maybe not right format")
ulsec = repr(ts).split('.')[1][:6]
if len(ulsec) < 6 and int(ulsec) != 0:
ulsec = int(ulsec) * (10 ** (6 - len(ulsec)))
elif int(ulsec) == 0:
ulsec *= 6
# * follow two rows added for tsCheckCase
td_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
return td_ts
#td_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts))
td_ts = time.strftime("%Y-%m-%d %H:%M:%S.{}".format(ulsec), time.localtime(ts))
return td_ts
#return repr(datetime.datetime.strptime(td_ts, "%Y-%m-%d %H:%M:%S.%f"))
def dateToTs(self, datetime_input):
return int(time.mktime(time.strptime(datetime_input, "%Y-%m-%d %H:%M:%S.%f")))
def getTdTypeValue(self, value):
if value.endswith("i8"):
td_type = "TINYINT"
td_tag_value = ''.join(list(value)[:-2])
elif value.endswith("i16"):
td_type = "SMALLINT"
td_tag_value = ''.join(list(value)[:-3])
elif value.endswith("i32"):
td_type = "INT"
td_tag_value = ''.join(list(value)[:-3])
elif value.endswith("i64"):
td_type = "BIGINT"
td_tag_value = ''.join(list(value)[:-3])
elif value.endswith("u64"):
td_type = "BIGINT UNSIGNED"
td_tag_value = ''.join(list(value)[:-3])
elif value.endswith("f32"):
td_type = "FLOAT"
td_tag_value = ''.join(list(value)[:-3])
td_tag_value = '{}'.format(np.float32(td_tag_value))
elif value.endswith("f64"):
td_type = "DOUBLE"
td_tag_value = ''.join(list(value)[:-3])
elif value.startswith('L"'):
td_type = "NCHAR"
td_tag_value = ''.join(list(value)[2:-1])
elif value.startswith('"') and value.endswith('"'):
td_type = "BINARY"
td_tag_value = ''.join(list(value)[1:-1])
elif value.lower() == "t" or value == "true" or value == "True" or value == "TRUE":
td_type = "BOOL"
td_tag_value = "True"
elif value.lower() == "f" or value == "false" or value == "False" or value == "FALSE":
td_type = "BOOL"
td_tag_value = "False"
else:
td_type = "FLOAT"
td_tag_value = value
return td_type, td_tag_value
def typeTrans(self, type_list):
type_num_list = []
for tp in type_list:
if tp.upper() == "TIMESTAMP":
type_num_list.append(9)
elif tp.upper() == "BOOL":
type_num_list.append(1)
elif tp.upper() == "TINYINT":
type_num_list.append(2)
elif tp.upper() == "SMALLINT":
type_num_list.append(3)
elif tp.upper() == "INT":
type_num_list.append(4)
elif tp.upper() == "BIGINT":
type_num_list.append(5)
elif tp.upper() == "FLOAT":
type_num_list.append(6)
elif tp.upper() == "DOUBLE":
type_num_list.append(7)
elif tp.upper() == "BINARY":
type_num_list.append(8)
elif tp.upper() == "NCHAR":
type_num_list.append(10)
elif tp.upper() == "BIGINT UNSIGNED":
type_num_list.append(14)
return type_num_list
def inputHandle(self, input_sql):
input_sql_split_list = input_sql.split(" ")
stb_name = input_sql_split_list[0]
#'stb2_5 1626006833610ms 3f64 host="host0"',
stb_tag_list = input_sql_split_list[3].split(',')
stb_col_value = input_sql_split_list[2]
ts_value = self.timeTrans(input_sql_split_list[1])
tag_name_list = []
tag_value_list = []
td_tag_value_list = []
td_tag_type_list = []
col_name_list = []
col_value_list = []
td_col_value_list = []
td_col_type_list = []
for elm in stb_tag_list:
if "id=" in elm.lower():
tb_name = elm.split('=')[1]
else:
tag_name_list.append(elm.split("=")[0])
tag_value_list.append(elm.split("=")[1])
tb_name = ""
td_tag_value_list.append(self.getTdTypeValue(elm.split("=")[1])[1])
td_tag_type_list.append(self.getTdTypeValue(elm.split("=")[1])[0])
col_name_list.append('value')
col_value_list.append(stb_col_value)
td_col_value_list.append(self.getTdTypeValue(stb_col_value)[1])
td_col_type_list.append(self.getTdTypeValue(stb_col_value)[0])
final_field_list = []
final_field_list.extend(col_name_list)
final_field_list.extend(tag_name_list)
final_type_list = []
final_type_list.append("TIMESTAMP")
final_type_list.extend(td_col_type_list)
final_type_list.extend(td_tag_type_list)
final_type_list = self.typeTrans(final_type_list)
final_value_list = []
final_value_list.append(ts_value)
final_value_list.extend(td_col_value_list)
final_value_list.extend(td_tag_value_list)
return final_value_list, final_field_list, final_type_list, stb_name, tb_name
def genFullTypeSql(self, stb_name="", tb_name="", value="", t0="", t1="127i8", t2="32767i16", t3="2147483647i32",
t4="9223372036854775807i64", t5="11.12345f32", t6="22.123456789f64", t7="\"binaryTagValue\"",
t8="L\"ncharTagValue\"", ts="1626006833639000000ns",
id_noexist_tag=None, id_change_tag=None, id_upper_tag=None, id_double_tag=None,
t_add_tag=None, t_mul_tag=None, t_multi_tag=None, t_blank_tag=None):
if stb_name == "":
stb_name = tdCom.getLongName(len=6, mode="letters")
if tb_name == "":
tb_name = f'{stb_name}_{random.randint(0, 65535)}_{random.randint(0, 65535)}'
if t0 == "":
t0 = random.choice(["f", "F", "false", "False", "t", "T", "true", "True", "TRUE", "FALSE"])
if value == "":
value = random.choice(["f", "F", "false", "False", "t", "T", "true", "True", "TRUE", "FALSE"])
if id_upper_tag is not None:
id = "ID"
else:
id = "id"
sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}\",t0={t0},t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6},t7={t7},t8={t8}'
if id_noexist_tag is not None:
sql_seq = f'{stb_name} {ts} {value} t0={t0},t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6},t7={t7},t8={t8}'
if t_add_tag is not None:
sql_seq = f'{stb_name} {ts} {value} t0={t0},t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6},t7={t7},t8={t8},t9={t8}'
if id_change_tag is not None:
sql_seq = f'{stb_name} {ts} {value} t0={t0},{id}=\"{tb_name}\",t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6},t7={t7},t8={t8}'
if id_double_tag is not None:
sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}_1\",t0={t0},t1={t1},{id}=\"{tb_name}_2\",t2={t2},t3={t3},t4={t4},t5={t5},t6={t6},t7={t7},t8={t8}'
if t_add_tag is not None:
sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}\",t0={t0},t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6},t7={t7},t8={t8},t11={t1},t10={t8}'
if t_mul_tag is not None:
sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}\",t0={t0},t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6}'
if id_noexist_tag is not None:
sql_seq = f'{stb_name} {ts} {value} t0={t0},t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6}'
if t_multi_tag is not None:
sql_seq = f'{stb_name} {ts} {value},{value} {id}=\"{tb_name}\",t0={t0},t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6}'
if t_blank_tag is not None:
sql_seq = f'{stb_name} {ts} {id}=\"{tb_name}\",t0={t0},t1={t1},t2={t2},t3={t3},t4={t4},t5={t5},t6={t6},t7={t7},t8={t8}'
return sql_seq, stb_name
def genMulTagColStr(self, genType, count=1):
"""
genType must be tag/col
"""
tag_str = ""
col_str = ""
if genType == "tag":
for i in range(0, count):
if i < (count-1):
tag_str += f't{i}=f,'
else:
tag_str += f't{i}=f'
return tag_str
if genType == "col":
col_str = "t"
return col_str
def genLongSql(self, tag_count):
stb_name = tdCom.getLongName(7, mode="letters")
tb_name = f'{stb_name}_1'
tag_str = self.genMulTagColStr("tag", tag_count)
col_str = self.genMulTagColStr("col")
ts = "1626006833640000000ns"
long_sql = stb_name + ' ' + ts + ' ' + col_str + ' ' + f'id=\"{tb_name}\"' + ',' + tag_str
return long_sql, stb_name
def getNoIdTbName(self, stb_name):
query_sql = f"select tbname from {stb_name}"
tb_name = self.resHandle(query_sql, True)[0][0]
return tb_name
def resHandle(self, query_sql, query_tag):
tdSql.execute('reset query cache')
row_info = tdSql.query(query_sql, query_tag)
print(query_sql)
print(row_info)
col_info = tdSql.getColNameList(query_sql, query_tag)
res_row_list = []
sub_list = []
for row_mem in row_info:
for i in row_mem:
sub_list.append(str(i))
res_row_list.append(sub_list)
res_field_list_without_ts = col_info[0][1:]
res_type_list = col_info[1]
return res_row_list, res_field_list_without_ts, res_type_list
def resCmp(self, input_sql, stb_name, query_sql="select * from", condition="", ts=None, id=True, none_check_tag=None):
expect_list = self.inputHandle(input_sql)
self._conn.insert_telnet_lines([input_sql])
query_sql = f"{query_sql} {stb_name} {condition}"
res_row_list, res_field_list_without_ts, res_type_list = self.resHandle(query_sql, True)
res = tdSql.query(f'select * from {stb_name}', True)
print(res)
res = tdSql.query(f'select * from {stb_name}', True)
print(res)
time.sleep(2)
res = tdSql.query(f'select * from {stb_name}', True)
print(res)
time.sleep(2)
res = tdSql.query(f'select * from {stb_name}', True)
print(res)
time.sleep(2)
res = tdSql.query(f'select * from {stb_name}', True)
print(res)
if ts == 0:
res_ts = self.dateToTs(res_row_list[0][0])
current_time = time.time()
if current_time - res_ts < 60:
tdSql.checkEqual(res_row_list[0][1:], expect_list[0][1:])
else:
print("timeout")
tdSql.checkEqual(res_row_list[0], expect_list[0])
else:
if none_check_tag is not None:
none_index_list = [i for i,x in enumerate(res_row_list[0]) if x=="None"]
none_index_list.reverse()
for j in none_index_list:
res_row_list[0].pop(j)
expect_list[0].pop(j)
tdSql.checkEqual(res_row_list[0], expect_list[0])
tdSql.checkEqual(res_field_list_without_ts, expect_list[1])
for i in range(len(res_type_list)):
tdSql.checkEqual(res_type_list[i], expect_list[2][i])
# tdSql.checkEqual(res_type_list, expect_list[2])
def initCheckCase(self):
"""
normal tags and cols, one for every elm
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
def boolTypeCheckCase(self):
"""
check all normal type
"""
tdCom.cleanTb()
full_type_list = ["f", "F", "false", "False", "t", "T", "true", "True"]
for t_type in full_type_list:
input_sql, stb_name = self.genFullTypeSql(t0=t_type)
self.resCmp(input_sql, stb_name)
def symbolsCheckCase(self):
"""
check symbols = `~!@#$%^&*()_-+={[}]\|:;'\",<.>/?
"""
'''
please test :
binary_symbols = '\"abcd`~!@#$%^&*()_-{[}]|:;<.>?lfjal"\'\'"\"'
'''
tdCom.cleanTb()
binary_symbols = '"aaa"'
# binary_symbols = '"abcd`~!@#$%^&*()_-{[}]|:;<.>?lfjal"'
nchar_symbols = f'L{binary_symbols}'
input_sql1, stb_name1 = self.genFullTypeSql(value=binary_symbols, t7=binary_symbols, t8=nchar_symbols)
# input_sql2, stb_name2 = self.genFullTypeSql(value=nchar_symbols, t7=binary_symbols, t8=nchar_symbols)
self.resCmp(input_sql1, stb_name1)
# self.resCmp(input_sql2, stb_name2)
def tsCheckCase(self):
"""
test ts list --> ["1626006833639000000ns", "1626006833639019us", "1626006833640ms", "1626006834s", "1626006822639022"]
# ! us级时间戳都为0时,数据库中查询显示,但python接口拿到的结果不显示 .000000的情况请确认,目前修改时间处理代码可以通过
"""
tdCom.cleanTb()
ts_list = ["1626006833639000000ns", "1626006833639019us", "1626006833640ms", "1626006834s", "1626006822639022", 0]
for ts in ts_list:
input_sql, stb_name = self.genFullTypeSql(ts=ts)
self.resCmp(input_sql, stb_name, ts=ts)
def idSeqCheckCase(self):
"""
check id.index in tags
eg: t0=**,id=**,t1=**
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql(id_change_tag=True)
self.resCmp(input_sql, stb_name)
def idUpperCheckCase(self):
"""
check id param
eg: id and ID
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql(id_upper_tag=True)
self.resCmp(input_sql, stb_name)
input_sql, stb_name = self.genFullTypeSql(id_change_tag=True, id_upper_tag=True)
self.resCmp(input_sql, stb_name)
def noIdCheckCase(self):
"""
id not exist
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql(id_noexist_tag=True)
self.resCmp(input_sql, stb_name)
query_sql = f"select tbname from {stb_name}"
res_row_list = self.resHandle(query_sql, True)[0]
if len(res_row_list[0][0]) > 0:
tdSql.checkColNameList(res_row_list, res_row_list)
else:
tdSql.checkColNameList(res_row_list, "please check noIdCheckCase")
def maxColTagCheckCase(self):
"""
max tag count is 128
"""
for input_sql in [self.genLongSql(128)[0]]:
tdCom.cleanTb()
self._conn.insert_telnet_lines([input_sql])
for input_sql in [self.genLongSql(129)[0]]:
tdCom.cleanTb()
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
def idIllegalNameCheckCase(self):
"""
test illegal id name
mix "`~!@#$¥%^&*()-+={}|[]、「」【】\:;《》<>?"
"""
tdCom.cleanTb()
rstr = list("`~!@#$¥%^&*()-+={}|[]、「」【】\:;《》<>?")
for i in rstr:
input_sql = self.genFullTypeSql(tb_name=f"\"aaa{i}bbb\"")[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
def idStartWithNumCheckCase(self):
"""
id is start with num
"""
tdCom.cleanTb()
input_sql = self.genFullTypeSql(tb_name=f"\"1aaabbb\"")[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
def nowTsCheckCase(self):
"""
check now unsupported
"""
tdCom.cleanTb()
input_sql = self.genFullTypeSql(ts="now")[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
def dateFormatTsCheckCase(self):
"""
check date format ts unsupported
"""
tdCom.cleanTb()
input_sql = self.genFullTypeSql(ts="2021-07-21\ 19:01:46.920")[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
def illegalTsCheckCase(self):
"""
check ts format like 16260068336390us19
"""
tdCom.cleanTb()
input_sql = self.genFullTypeSql(ts="16260068336390us19")[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
def tagValueLengthCheckCase(self):
"""
check full type tag value limit
"""
tdCom.cleanTb()
# i8
for t1 in ["-127i8", "127i8"]:
input_sql, stb_name = self.genFullTypeSql(t1=t1)
self.resCmp(input_sql, stb_name)
for t1 in ["-128i8", "128i8"]:
input_sql = self.genFullTypeSql(t1=t1)[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
#i16
for t2 in ["-32767i16", "32767i16"]:
input_sql, stb_name = self.genFullTypeSql(t2=t2)
self.resCmp(input_sql, stb_name)
for t2 in ["-32768i16", "32768i16"]:
input_sql = self.genFullTypeSql(t2=t2)[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
#i32
for t3 in ["-2147483647i32", "2147483647i32"]:
input_sql, stb_name = self.genFullTypeSql(t3=t3)
self.resCmp(input_sql, stb_name)
for t3 in ["-2147483648i32", "2147483648i32"]:
input_sql = self.genFullTypeSql(t3=t3)[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
#i64
for t4 in ["-9223372036854775807i64", "9223372036854775807i64"]:
input_sql, stb_name = self.genFullTypeSql(t4=t4)
self.resCmp(input_sql, stb_name)
for t4 in ["-9223372036854775808i64", "9223372036854775808i64"]:
input_sql = self.genFullTypeSql(t4=t4)[0]
try:
self._conn.insert_telnet_lines([input_sql])
except LinesError:
pass
# f32
for t5 in [f"{-3.4028234663852885981170418348451692544*(10**38)}f32", f"{3.4028234663852885981170418348451692544*(10**38)}f32"]:
input_sql, stb_name = self.genFullTypeSql(t5=t5)
self.resCmp(input_sql, stb_name)
# * limit set to 4028234664*(10**38)
for t5 in [f"{-3.4028234664*(10**38)}f32", f"{3.4028234664*(10**38)}f32"]:
input_sql = self.genFullTypeSql(t5=t5)[0]
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# f64
for t6 in [f'{-1.79769*(10**308)}f64', f'{-1.79769*(10**308)}f64']:
input_sql, stb_name = self.genFullTypeSql(t6=t6)
self.resCmp(input_sql, stb_name)
# * limit set to 1.797693134862316*(10**308)
for c6 in [f'{-1.797693134862316*(10**308)}f64', f'{-1.797693134862316*(10**308)}f64']:
input_sql = self.genFullTypeSql(c6=c6)[0]
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# binary
stb_name = tdCom.getLongName(7, "letters")
input_sql = f'{stb_name} 1626006833639000000ns t t0=t,t1="{tdCom.getLongName(16374, "letters")}"'
self._conn.insert_telnet_lines([input_sql])
input_sql = f'{stb_name} 1626006833639000000ns t t0=t,t1="{tdCom.getLongName(16375, "letters")}"'
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
pass
# nchar
# * legal nchar could not be larger than 16374/4
stb_name = tdCom.getLongName(7, "letters")
input_sql = f'{stb_name} 1626006833639000000ns t t0=t,t1=L"{tdCom.getLongName(4093, "letters")}"'
self._conn.insert_telnet_lines([input_sql])
input_sql = f'{stb_name} 1626006833639000000ns t t0=t,t1=L"{tdCom.getLongName(4094, "letters")}"'
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
def colValueLengthCheckCase(self):
"""
check full type col value limit
"""
tdCom.cleanTb()
# i8
for c1 in ["-127i8", "127i8"]:
input_sql, stb_name = self.genFullTypeSql(c1=c1)
self.resCmp(input_sql, stb_name)
for c1 in ["-128i8", "128i8"]:
input_sql = self.genFullTypeSql(c1=c1)[0]
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# i16
for c2 in ["-32767i16"]:
input_sql, stb_name = self.genFullTypeSql(c2=c2)
self.resCmp(input_sql, stb_name)
for c2 in ["-32768i16", "32768i16"]:
input_sql = self.genFullTypeSql(c2=c2)[0]
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# i32
for c3 in ["-2147483647i32"]:
input_sql, stb_name = self.genFullTypeSql(c3=c3)
self.resCmp(input_sql, stb_name)
for c3 in ["-2147483648i32", "2147483648i32"]:
input_sql = self.genFullTypeSql(c3=c3)[0]
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# i64
for c4 in ["-9223372036854775807i64"]:
input_sql, stb_name = self.genFullTypeSql(c4=c4)
self.resCmp(input_sql, stb_name)
for c4 in ["-9223372036854775808i64", "9223372036854775808i64"]:
input_sql = self.genFullTypeSql(c4=c4)[0]
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# f32
for c5 in [f"{-3.4028234663852885981170418348451692544*(10**38)}f32", f"{3.4028234663852885981170418348451692544*(10**38)}f32"]:
input_sql, stb_name = self.genFullTypeSql(c5=c5)
self.resCmp(input_sql, stb_name)
# * limit set to 4028234664*(10**38)
for c5 in [f"{-3.4028234664*(10**38)}f32", f"{3.4028234664*(10**38)}f32"]:
input_sql = self.genFullTypeSql(c5=c5)[0]
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# f64
for c6 in [f'{-1.79769313486231570814527423731704356798070567525844996598917476803157260780*(10**308)}f64', f'{-1.79769313486231570814527423731704356798070567525844996598917476803157260780*(10**308)}f64']:
input_sql, stb_name = self.genFullTypeSql(c6=c6)
self.resCmp(input_sql, stb_name)
# * limit set to 1.797693134862316*(10**308)
for c6 in [f'{-1.797693134862316*(10**308)}f64', f'{-1.797693134862316*(10**308)}f64']:
input_sql = self.genFullTypeSql(c6=c6)[0]
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# # binary
stb_name = tdCom.getLongName(7, "letters")
input_sql = f'{stb_name} 1626006833639000000ns "{tdCom.getLongName(16374, "letters")}" t0=t'
self._conn.insert_telnet_lines([input_sql])
input_sql = f'{stb_name} 1626006833639000000ns "{tdCom.getLongName(16375, "letters")}" t0=t'
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# nchar
# * legal nchar could not be larger than 16374/4
stb_name = tdCom.getLongName(7, "letters")
input_sql = f'{stb_name} 1626006833639000000ns L"{tdCom.getLongName(4093, "letters")}" t0=t'
self._conn.insert_telnet_lines([input_sql])
input_sql = f'{stb_name} 1626006833639000000ns L"{tdCom.getLongName(4094, "letters")}" t0=t'
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
def tagColIllegalValueCheckCase(self):
"""
test illegal tag col value
"""
tdCom.cleanTb()
# bool
for i in ["TrUe", "tRue", "trUe", "truE", "FalsE", "fAlse", "faLse", "falSe", "falsE"]:
input_sql1 = self.genFullTypeSql(t0=i)[0]
try:
self._conn.insert_telnet_lines([input_sql1])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
input_sql2 = self.genFullTypeSql(value=i)[0]
try:
self._conn.insert_telnet_lines([input_sql2])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# i8 i16 i32 i64 f32 f64
for input_sql in [
self.genFullTypeSql(t1="1s2i8")[0],
self.genFullTypeSql(t2="1s2i16")[0],
self.genFullTypeSql(t3="1s2i32")[0],
self.genFullTypeSql(t4="1s2i64")[0],
self.genFullTypeSql(t5="11.1s45f32")[0],
self.genFullTypeSql(t6="11.1s45f64")[0],
]:
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# check binary and nchar blank
stb_name = tdCom.getLongName(7, "letters")
input_sql1 = f'{stb_name} 1626006833639000000ns "abc aaa" t0=t'
input_sql2 = f'{stb_name} 1626006833639000000ns L"abc aaa" t0=t'
input_sql3 = f'{stb_name} 1626006833639000000ns t t0="abc aaa"'
input_sql4 = f'{stb_name} 1626006833639000000ns t t0=L"abc aaa"'
for input_sql in [input_sql1, input_sql2, input_sql3, input_sql4]:
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
# check accepted binary and nchar symbols
# # * ~!@#$¥%^&*()-+={}|[]、「」:;
for symbol in list('~!@#$¥%^&*()-+={}|[]、「」:;'):
input_sql1 = f'{stb_name} 1626006833639000000ns "abc{symbol}aaa" t0=t'
input_sql2 = f'{stb_name} 1626006833639000000ns t t0=t,t1="abc{symbol}aaa"'
self._conn.insert_telnet_lines([input_sql1])
self._conn.insert_telnet_lines([input_sql2])
def duplicateIdTagColInsertCheckCase(self):
"""
check duplicate Id Tag Col
"""
tdCom.cleanTb()
input_sql_id = self.genFullTypeSql(id_double_tag=True)[0]
try:
self._conn.insert_telnet_lines([input_sql_id])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
input_sql = self.genFullTypeSql()[0]
input_sql_tag = input_sql.replace("t5", "t6")
try:
self._conn.insert_telnet_lines([input_sql_tag])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
##### stb exist #####
def noIdStbExistCheckCase(self):
"""
case no id when stb exist
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql(tb_name="sub_table_0123456", t0="f", value="f")
self.resCmp(input_sql, stb_name)
input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, id_noexist_tag=True, t0="f", value="f")
self.resCmp(input_sql, stb_name, condition='where tbname like "t_%"')
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(2)
# TODO cover other case
def duplicateInsertExistCheckCase(self):
"""
check duplicate insert when stb exist
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
self._conn.insert_telnet_lines([input_sql])
self.resCmp(input_sql, stb_name)
def tagColBinaryNcharLengthCheckCase(self):
"""
check length increase
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
tb_name = tdCom.getLongName(5, "letters")
input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name,t7="\"binaryTagValuebinaryTagValue\"", t8="L\"ncharTagValuencharTagValue\"", c7="\"binaryTagValuebinaryTagValue\"", c8="L\"ncharTagValuencharTagValue\"")
self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"')
def tagColAddDupIDCheckCase(self):
"""
check column and tag count add, stb and tb duplicate
* tag: alter table ...
* col: when update==0 and ts is same, unchange
* so this case tag&&value will be added,
* col is added without value when update==0
* col is added with value when update==1
"""
tdCom.cleanTb()
tb_name = tdCom.getLongName(7, "letters")
for db_update_tag in [0, 1]:
if db_update_tag == 1 :
self.createDb("test_update", db_update_tag=db_update_tag)
input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, t0="f", value="f")
self.resCmp(input_sql, stb_name)
self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t0="f", value="f", ct_add_tag=True)
if db_update_tag == 1 :
self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"')
else:
self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"', none_check_tag=True)
def tagColAddCheckCase(self):
"""
check column and tag count add
"""
tdCom.cleanTb()
tb_name = tdCom.getLongName(7, "letters")
input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, t0="f", value="f")
self.resCmp(input_sql, stb_name)
tb_name_1 = tdCom.getLongName(7, "letters")
input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name_1, t0="f", value="f", ct_add_tag=True)
self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name_1}"')
res_row_list = self.resHandle(f"select c10,c11,t10,t11 from {tb_name}", True)[0]
tdSql.checkEqual(res_row_list[0], ['None', 'None', 'None', 'None'])
self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"', none_check_tag=True)
def tagMd5Check(self):
"""
condition: stb not change
insert two table, keep tag unchange, change col
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql(t0="f", value="f", id_noexist_tag=True)
self.resCmp(input_sql, stb_name)
tb_name1 = self.getNoIdTbName(stb_name)
input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, t0="f", value="f", id_noexist_tag=True)
self.resCmp(input_sql, stb_name)
tb_name2 = self.getNoIdTbName(stb_name)
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(1)
tdSql.checkEqual(tb_name1, tb_name2)
input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, t0="f", value="f", id_noexist_tag=True, ct_add_tag=True)
self._conn.insert_telnet_lines([input_sql])
tb_name3 = self.getNoIdTbName(stb_name)
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(2)
tdSql.checkNotEqual(tb_name1, tb_name3)
# * tag binary max is 16384, col+ts binary max 49151
def tagColBinaryMaxLengthCheckCase(self):
"""
every binary and nchar must be length+2
"""
tdCom.cleanTb()
stb_name = tdCom.getLongName(7, "letters")
tb_name = f'{stb_name}_1'
input_sql = f'{stb_name},id="{tb_name}",t0=t c0=f 1626006833639000000ns'
self._conn.insert_telnet_lines([input_sql])
# * every binary and nchar must be length+2, so here is two tag, max length could not larger than 16384-2*2
input_sql = f'{stb_name},t0=t,t1="{tdCom.getLongName(16374, "letters")}",t2="{tdCom.getLongName(5, "letters")}" c0=f 1626006833639000000ns'
self._conn.insert_telnet_lines([input_sql])
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(2)
input_sql = f'{stb_name},t0=t,t1="{tdCom.getLongName(16374, "letters")}",t2="{tdCom.getLongName(6, "letters")}" c0=f 1626006833639000000ns'
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError:
pass
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(2)
# # * check col,col+ts max in describe ---> 16143
input_sql = f'{stb_name},t0=t c0=f,c1="{tdCom.getLongName(16374, "letters")}",c2="{tdCom.getLongName(16374, "letters")}",c3="{tdCom.getLongName(16374, "letters")}",c4="{tdCom.getLongName(12, "letters")}" 1626006833639000000ns'
self._conn.insert_telnet_lines([input_sql])
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(3)
input_sql = f'{stb_name},t0=t c0=f,c1="{tdCom.getLongName(16374, "letters")}",c2="{tdCom.getLongName(16374, "letters")}",c3="{tdCom.getLongName(16374, "letters")}",c4="{tdCom.getLongName(13, "letters")}" 1626006833639000000ns'
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(3)
# * tag nchar max is 16374/4, col+ts nchar max 49151
def tagColNcharMaxLengthCheckCase(self):
"""
check nchar length limit
"""
tdCom.cleanTb()
stb_name = tdCom.getLongName(7, "letters")
tb_name = f'{stb_name}_1'
input_sql = f'{stb_name},id="{tb_name}",t0=t c0=f 1626006833639000000ns'
code = self._conn.insert_telnet_lines([input_sql])
# * legal nchar could not be larger than 16374/4
input_sql = f'{stb_name},t0=t,t1=L"{tdCom.getLongName(4093, "letters")}",t2=L"{tdCom.getLongName(1, "letters")}" c0=f 1626006833639000000ns'
self._conn.insert_telnet_lines([input_sql])
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(2)
input_sql = f'{stb_name},t0=t,t1=L"{tdCom.getLongName(4093, "letters")}",t2=L"{tdCom.getLongName(2, "letters")}" c0=f 1626006833639000000ns'
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(2)
input_sql = f'{stb_name},t0=t c0=f,c1=L"{tdCom.getLongName(4093, "letters")}",c2=L"{tdCom.getLongName(4093, "letters")}",c3=L"{tdCom.getLongName(4093, "letters")}",c4=L"{tdCom.getLongName(4, "letters")}" 1626006833639000000ns'
self._conn.insert_telnet_lines([input_sql])
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(3)
input_sql = f'{stb_name},t0=t c0=f,c1=L"{tdCom.getLongName(4093, "letters")}",c2=L"{tdCom.getLongName(4093, "letters")}",c3=L"{tdCom.getLongName(4093, "letters")}",c4=L"{tdCom.getLongName(5, "letters")}" 1626006833639000000ns'
try:
self._conn.insert_telnet_lines([input_sql])
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(3)
def batchInsertCheckCase(self):
"""
test batch insert
"""
tdCom.cleanTb()
stb_name = tdCom.getLongName(8, "letters")
tdSql.execute(f'create stable {stb_name}(ts timestamp, f int) tags(t1 bigint)')
lines = ["st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
"st123456,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns",
f"{stb_name},t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\"iam\" 1626056811823316532ns",
"stf567890,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns",
"st123456,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000ns",
f"{stb_name},t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532ns",
f"{stb_name},t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532ns",
"st123456,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns",
"st123456,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641000000ns"
]
self._conn.insert_telnet_lines(lines)
def multiInsertCheckCase(self, count):
"""
test multi insert
"""
tdCom.cleanTb()
sql_list = []
stb_name = tdCom.getLongName(8, "letters")
tdSql.execute(f'create stable {stb_name}(ts timestamp, f int) tags(t1 bigint)')
for i in range(count):
input_sql = self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True)[0]
sql_list.append(input_sql)
self._conn.insert_telnet_lines(sql_list)
def batchErrorInsertCheckCase(self):
"""
test batch error insert
"""
tdCom.cleanTb()
stb_name = tdCom.getLongName(8, "letters")
lines = ["st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
f"{stb_name},t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns"]
try:
self._conn.insert_telnet_lines(lines)
raise Exception("should not reach here")
except LinesError as err:
tdSql.checkNotEqual(err.errno, 0)
def genSqlList(self, count=5, stb_name="", tb_name=""):
"""
stb --> supertable
tb --> table
ts --> timestamp, same default
col --> column, same default
tag --> tag, same default
d --> different
s --> same
a --> add
m --> minus
"""
d_stb_d_tb_list = list()
s_stb_s_tb_list = list()
s_stb_s_tb_a_col_a_tag_list = list()
s_stb_s_tb_m_col_m_tag_list = list()
s_stb_d_tb_list = list()
s_stb_d_tb_a_col_m_tag_list = list()
s_stb_d_tb_a_tag_m_col_list = list()
s_stb_s_tb_d_ts_list = list()
s_stb_s_tb_d_ts_a_col_m_tag_list = list()
s_stb_s_tb_d_ts_a_tag_m_col_list = list()
s_stb_d_tb_d_ts_list = list()
s_stb_d_tb_d_ts_a_col_m_tag_list = list()
s_stb_d_tb_d_ts_a_tag_m_col_list = list()
for i in range(count):
d_stb_d_tb_list.append(self.genFullTypeSql(t0="f", c0="f"))
s_stb_s_tb_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"'))
s_stb_s_tb_a_col_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', ct_add_tag=True))
s_stb_s_tb_m_col_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', ct_min_tag=True))
s_stb_d_tb_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True))
s_stb_d_tb_a_col_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ct_am_tag=True))
s_stb_d_tb_a_tag_m_col_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ct_ma_tag=True))
s_stb_s_tb_d_ts_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', ts=0))
s_stb_s_tb_d_ts_a_col_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', ts=0, ct_am_tag=True))
s_stb_s_tb_d_ts_a_tag_m_col_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', ts=0, ct_ma_tag=True))
s_stb_d_tb_d_ts_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0))
s_stb_d_tb_d_ts_a_col_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0, ct_am_tag=True))
s_stb_d_tb_d_ts_a_tag_m_col_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', c7=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0, ct_ma_tag=True))
return d_stb_d_tb_list, s_stb_s_tb_list, s_stb_s_tb_a_col_a_tag_list, s_stb_s_tb_m_col_m_tag_list, \
s_stb_d_tb_list, s_stb_d_tb_a_col_m_tag_list, s_stb_d_tb_a_tag_m_col_list, s_stb_s_tb_d_ts_list, \
s_stb_s_tb_d_ts_a_col_m_tag_list, s_stb_s_tb_d_ts_a_tag_m_col_list, s_stb_d_tb_d_ts_list, \
s_stb_d_tb_d_ts_a_col_m_tag_list, s_stb_d_tb_d_ts_a_tag_m_col_list
def genMultiThreadSeq(self, sql_list):
tlist = list()
for insert_sql in sql_list:
t = threading.Thread(target=self._conn.insert_telnet_lines,args=([insert_sql[0]],))
tlist.append(t)
return tlist
def multiThreadRun(self, tlist):
for t in tlist:
t.start()
for t in tlist:
t.join()
def stbInsertMultiThreadCheckCase(self):
"""
thread input different stb
"""
tdCom.cleanTb()
input_sql = self.genSqlList()[0]
self.multiThreadRun(self.genMultiThreadSeq(input_sql))
tdSql.query(f"show tables;")
tdSql.checkRows(5)
def sStbStbDdataInsertMultiThreadCheckCase(self):
"""
thread input same stb tb, different data, result keep first data
"""
tdCom.cleanTb()
tb_name = tdCom.getLongName(7, "letters")
input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name)
self.resCmp(input_sql, stb_name)
s_stb_s_tb_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[1]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_list))
tdSql.query(f"show tables;")
tdSql.checkRows(1)
expected_tb_name = self.getNoIdTbName(stb_name)[0]
tdSql.checkEqual(tb_name, expected_tb_name)
tdSql.query(f"select * from {stb_name};")
tdSql.checkRows(1)
def sStbStbDdataAtcInsertMultiThreadCheckCase(self):
"""
thread input same stb tb, different data, add columes and tags, result keep first data
"""
tdCom.cleanTb()
tb_name = tdCom.getLongName(7, "letters")
input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name)
self.resCmp(input_sql, stb_name)
s_stb_s_tb_a_col_a_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[2]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_a_col_a_tag_list))
tdSql.query(f"show tables;")
tdSql.checkRows(1)
expected_tb_name = self.getNoIdTbName(stb_name)[0]
tdSql.checkEqual(tb_name, expected_tb_name)
tdSql.query(f"select * from {stb_name};")
tdSql.checkRows(1)
def sStbStbDdataMtcInsertMultiThreadCheckCase(self):
"""
thread input same stb tb, different data, minus columes and tags, result keep first data
"""
tdCom.cleanTb()
tb_name = tdCom.getLongName(7, "letters")
input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name)
self.resCmp(input_sql, stb_name)
s_stb_s_tb_m_col_m_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[3]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_m_col_m_tag_list))
tdSql.query(f"show tables;")
tdSql.checkRows(1)
expected_tb_name = self.getNoIdTbName(stb_name)[0]
tdSql.checkEqual(tb_name, expected_tb_name)
tdSql.query(f"select * from {stb_name};")
tdSql.checkRows(1)
def sStbDtbDdataInsertMultiThreadCheckCase(self):
"""
thread input same stb, different tb, different data
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
s_stb_d_tb_list = self.genSqlList(stb_name=stb_name)[4]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_list))
tdSql.query(f"show tables;")
tdSql.checkRows(6)
def sStbDtbDdataAcMtInsertMultiThreadCheckCase(self):
"""
#! concurrency conflict
"""
"""
thread input same stb, different tb, different data, add col, mul tag
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
s_stb_d_tb_a_col_m_tag_list = self.genSqlList(stb_name=stb_name)[5]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_a_col_m_tag_list))
tdSql.query(f"show tables;")
tdSql.checkRows(6)
def sStbDtbDdataAtMcInsertMultiThreadCheckCase(self):
"""
#! concurrency conflict
"""
"""
thread input same stb, different tb, different data, add tag, mul col
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
s_stb_d_tb_a_tag_m_col_list = self.genSqlList(stb_name=stb_name)[6]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_a_tag_m_col_list))
tdSql.query(f"show tables;")
tdSql.checkRows(6)
def sStbStbDdataDtsInsertMultiThreadCheckCase(self):
"""
thread input same stb tb, different ts
"""
tdCom.cleanTb()
tb_name = tdCom.getLongName(7, "letters")
input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name)
self.resCmp(input_sql, stb_name)
s_stb_s_tb_d_ts_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[7]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_list))
tdSql.query(f"show tables;")
tdSql.checkRows(1)
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(6)
def sStbStbDdataDtsAcMtInsertMultiThreadCheckCase(self):
"""
thread input same stb tb, different ts, add col, mul tag
"""
tdCom.cleanTb()
tb_name = tdCom.getLongName(7, "letters")
input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name)
self.resCmp(input_sql, stb_name)
s_stb_s_tb_d_ts_a_col_m_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[8]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_a_col_m_tag_list))
tdSql.query(f"show tables;")
tdSql.checkRows(1)
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(6)
tdSql.query(f"select * from {stb_name} where t8 is not NULL")
tdSql.checkRows(6)
tdSql.query(f"select * from {tb_name} where c11 is not NULL;")
tdSql.checkRows(5)
def sStbStbDdataDtsAtMcInsertMultiThreadCheckCase(self):
"""
thread input same stb tb, different ts, add tag, mul col
"""
tdCom.cleanTb()
tb_name = tdCom.getLongName(7, "letters")
input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name)
self.resCmp(input_sql, stb_name)
s_stb_s_tb_d_ts_a_tag_m_col_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[9]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_a_tag_m_col_list))
tdSql.query(f"show tables;")
tdSql.checkRows(1)
tdSql.query(f"select * from {stb_name}")
tdSql.checkRows(6)
for c in ["c7", "c8", "c9"]:
tdSql.query(f"select * from {stb_name} where {c} is NULL")
tdSql.checkRows(5)
for t in ["t10", "t11"]:
tdSql.query(f"select * from {stb_name} where {t} is not NULL;")
tdSql.checkRows(6)
def sStbDtbDdataDtsInsertMultiThreadCheckCase(self):
"""
thread input same stb, different tb, data, ts
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
s_stb_d_tb_d_ts_list = self.genSqlList(stb_name=stb_name)[10]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_d_ts_list))
tdSql.query(f"show tables;")
tdSql.checkRows(6)
def sStbDtbDdataDtsAcMtInsertMultiThreadCheckCase(self):
"""
# ! concurrency conflict
"""
"""
thread input same stb, different tb, data, ts, add col, mul tag
"""
tdCom.cleanTb()
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
s_stb_d_tb_d_ts_a_col_m_tag_list = self.genSqlList(stb_name=stb_name)[11]
self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_d_ts_a_col_m_tag_list))
tdSql.query(f"show tables;")
tdSql.checkRows(6)
def test(self):
# input_sql1 = "stb2_5 1626006833610ms 3f64 host=\"host0\",host2=L\"host2\""
# input_sql2 = "rfasta,id=\"rfasta_1\",t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64 c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64 1626006933640000000ns"
try:
input_sql, stb_name = self.genFullTypeSql()
self.resCmp(input_sql, stb_name)
except LinesError as err:
print(err.errno)
# self._conn.insert_telnet_lines([input_sql2])
# input_sql3 = f'abcd,id="cc¥Ec",t0=True,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7="ndsfdrum",t8=L"ncharTagValue" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7="igwoehkm",c8=L"ncharColValue",c9=7u64 0'
# print(input_sql3)
# input_sql4 = 'hmemeb,id="kilrcrldgf",t0=F,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7="fysodjql",t8=L"ncharTagValue" c0=True,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7="waszbfvc",c8=L"ncharColValue",c9=7u64 0'
# code = self._conn.insert_telnet_lines([input_sql3])
# print(code)
# self._conn.insert_telnet_lines([input_sql4])
def runAll(self):
# self.initCheckCase()
# self.boolTypeCheckCase()
self.symbolsCheckCase()
# self.tsCheckCase()
# self.idSeqCheckCase()
# self.idUpperCheckCase()
# self.noIdCheckCase()
# self.maxColTagCheckCase()
# self.idIllegalNameCheckCase()
# self.idStartWithNumCheckCase()
# self.nowTsCheckCase()
# self.dateFormatTsCheckCase()
# self.illegalTsCheckCase()
# self.tagValueLengthCheckCase()
# self.colValueLengthCheckCase()
# self.tagColIllegalValueCheckCase()
# self.duplicateIdTagColInsertCheckCase()
# self.noIdStbExistCheckCase()
# self.duplicateInsertExistCheckCase()
# self.tagColBinaryNcharLengthCheckCase()
# self.tagColAddDupIDCheckCase()
# self.tagColAddCheckCase()
# self.tagMd5Check()
# self.tagColBinaryMaxLengthCheckCase()
# # self.tagColNcharMaxLengthCheckCase()
# self.batchInsertCheckCase()
# self.multiInsertCheckCase(1000)
# self.batchErrorInsertCheckCase()
# # MultiThreads
# self.stbInsertMultiThreadCheckCase()
# self.sStbStbDdataInsertMultiThreadCheckCase()
# self.sStbStbDdataAtcInsertMultiThreadCheckCase()
# self.sStbStbDdataMtcInsertMultiThreadCheckCase()
# self.sStbDtbDdataInsertMultiThreadCheckCase()
# # # ! concurrency conflict
# # self.sStbDtbDdataAcMtInsertMultiThreadCheckCase()
# # self.sStbDtbDdataAtMcInsertMultiThreadCheckCase()
# self.sStbStbDdataDtsInsertMultiThreadCheckCase()
# # # ! concurrency conflict
# # self.sStbStbDdataDtsAcMtInsertMultiThreadCheckCase()
# # self.sStbStbDdataDtsAtMcInsertMultiThreadCheckCase()
# self.sStbDtbDdataDtsInsertMultiThreadCheckCase()
# # ! concurrency conflict
# # self.sStbDtbDdataDtsAcMtInsertMultiThreadCheckCase()
def run(self):
print("running {}".format(__file__))
self.createDb()
try:
self.runAll()
except Exception as err:
print(''.join(traceback.format_exception(None, err, err.__traceback__)))
raise err
# self.tagColIllegalValueCheckCase()
# self.test()
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
...@@ -44,7 +44,7 @@ class TDTestCase: ...@@ -44,7 +44,7 @@ class TDTestCase:
projPath = selfPath[:selfPath.find("tests")] projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath): for root, dirs, files in os.walk(projPath):
if ("taosdump" in files): if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root)) rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath): if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")] buildPath = root[:len(root) - len("/build/bin")]
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
"batch_create_tbl_num": 10, "batch_create_tbl_num": 10,
"data_source": "rand", "data_source": "rand",
"insert_mode": "taosc", "insert_mode": "taosc",
"insert_rows": 1000, "insert_rows": 1001,
"childtable_limit": 0, "childtable_limit": 0,
"childtable_offset":0, "childtable_offset":0,
"multi_thread_write_one_tbl": "no", "multi_thread_write_one_tbl": "no",
......
...@@ -120,7 +120,7 @@ class taosdemoPerformace: ...@@ -120,7 +120,7 @@ class taosdemoPerformace:
projPath = selfPath[:selfPath.find("tests")] projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath): for root, dirs, files in os.walk(projPath):
if ("taosdemo" in files): if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root)) rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath): if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")] buildPath = root[:len(root) - len("/build/bin")]
......
...@@ -36,7 +36,7 @@ class TDTestCase: ...@@ -36,7 +36,7 @@ class TDTestCase:
projPath = selfPath[:selfPath.find("tests")] projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath): for root, dirs, files in os.walk(projPath):
if ("taosdemo" in files): if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root)) rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath): if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")] buildPath = root[:len(root) - len("/build/bin")]
......
...@@ -26,7 +26,7 @@ class TDTestCase: ...@@ -26,7 +26,7 @@ class TDTestCase:
tdLog.debug("start to execute %s" % __file__) tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql) tdSql.init(conn.cursor(), logSql)
self.numberOfTables = 10 self.numberOfTables = 8
self.numberOfRecords = 1000000 self.numberOfRecords = 1000000
def getBuildPath(self): def getBuildPath(self):
...@@ -86,7 +86,7 @@ class TDTestCase: ...@@ -86,7 +86,7 @@ class TDTestCase:
while True: while True:
print("query started") print("query started")
try: try:
tdSql.query("select * from test.t9") tdSql.query("select * from test.t7")
except Exception as e: except Exception as e:
tdLog.info("select * test failed") tdLog.info("select * test failed")
time.sleep(2) time.sleep(2)
...@@ -100,8 +100,8 @@ class TDTestCase: ...@@ -100,8 +100,8 @@ class TDTestCase:
print("alter table test.meters add column c10 int") print("alter table test.meters add column c10 int")
tdSql.execute("alter table test.meters add column c10 int") tdSql.execute("alter table test.meters add column c10 int")
print("insert into test.t9 values (now, 1, 2, 3, 4, 0)") print("insert into test.t7 values (now, 1, 2, 3, 4, 0)")
tdSql.execute("insert into test.t9 values (now, 1, 2, 3, 4, 0)") tdSql.execute("insert into test.t7 values (now, 1, 2, 3, 4, 0)")
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
......
...@@ -37,7 +37,7 @@ class TDTestCase: ...@@ -37,7 +37,7 @@ class TDTestCase:
projPath = selfPath[:selfPath.find("tests")] projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath): for root, dirs, files in os.walk(projPath):
if ("taosdump" in files): if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root)) rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath): if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")] buildPath = root[:len(root) - len("/build/bin")]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册