Merge branch '3.0' of github.com:taosdata/TDengine into test/chr/TD-14699
This commit is contained in:
commit
9579710f80
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
sidebar_label: 删除数据
|
||||
description: "删除指定表或超级表中的数据记录"
|
||||
title: "删除数据"
|
||||
---
|
||||
|
||||
删除数据是 TDengine 提供的根据指定时间段删除指定表或超级表中数据记录的功能,方便用户清理由于设备故障等原因产生的异常数据。
|
||||
注意:本功能只在企业版 2.6.0.0 及以后的版本中提供,如需此功能请点击下面的链接访问[企业版产品](https://www.taosdata.com/products#enterprise-edition-link)
|
||||
|
||||
|
||||
**语法:**
|
||||
|
||||
```sql
|
||||
DELETE FROM [ db_name. ] tb_name [WHERE condition];
|
||||
```
|
||||
|
||||
**功能:** 删除指定表或超级表中的数据记录
|
||||
|
||||
**参数:**
|
||||
|
||||
- `db_name` : 可选参数,指定要删除表所在的数据库名,不填写则在当前数据库中
|
||||
- `tb_name` : 必填参数,指定要删除数据的表名,可以是普通表、子表,也可以是超级表。
|
||||
- `condition`: 可选参数,指定删除数据的过滤条件,不指定过滤条件则为表中所有数据,请慎重使用。特别说明,这里的where 条件中只支持对第一列时间列的过滤,如果是超级表,支持对 tag 列过滤。
|
||||
|
||||
**特别说明:**
|
||||
|
||||
数据删除后不可恢复,请慎重使用。为了确保删除的数据确实是自己要删除的,建议可以先使用 `select` 语句加 `where` 后的删除条件查看要删除的数据内容,确认无误后再执行 `delete` 命令。
|
||||
|
||||
**示例:**
|
||||
|
||||
`meters` 是一个超级表,`groupid` 是 int 类型的 tag 列,现在要删除 `meters` 表中时间小于 2021-10-01 10:40:00.100 且 tag 列 `groupid` 值为 1 的所有数据,sql 如下:
|
||||
|
||||
```sql
|
||||
delete from meters where ts < '2021-10-01 10:40:00.100' and groupid=1 ;
|
||||
```
|
||||
|
||||
执行后显示结果为:
|
||||
|
||||
```
|
||||
Deleted 102000 row(s) from 1020 table(s) (0.421950s)
|
||||
```
|
||||
|
||||
表示从 1020 个子表中共删除了 102000 行数据
|
|
@ -21,7 +21,7 @@ taosBenchmark 有两种安装方式:
|
|||
|
||||
### 配置和运行方式
|
||||
|
||||
taosBenchmark 支持两种配置方式:[命令行参数](#命令行参数详解) 和 [JSON 配置文件](#配置文件参数详解)。这两种方式是互斥的,在使用配置文件时只能使用一个命令行参数 `-f <json file>` 指定配置文件。在使用命令行参数运行 taosBenchmark 并控制其行为时则不能使用 `-f` 参数而要用其它参数来进行配置。除此之外,taosBenchmark 还提供了一种特殊的运行方式,即无参数运行。
|
||||
taosBenchmark 需要在操作系统的终端执行,该工具支持两种配置方式:[命令行参数](#命令行参数详解) 和 [JSON 配置文件](#配置文件参数详解)。这两种方式是互斥的,在使用配置文件时只能使用一个命令行参数 `-f <json file>` 指定配置文件。在使用命令行参数运行 taosBenchmark 并控制其行为时则不能使用 `-f` 参数而要用其它参数来进行配置。除此之外,taosBenchmark 还提供了一种特殊的运行方式,即无参数运行。
|
||||
|
||||
taosBenchmark 支持对 TDengine 做完备的性能测试,其所支持的 TDengine 功能分为三大类:写入、查询和订阅。这三种功能之间是互斥的,每次运行 taosBenchmark 只能选择其中之一。值得注意的是,所要测试的功能类型在使用命令行配置方式时是不可配置的,命令行配置方式只能测试写入性能。若要测试 TDengine 的查询和订阅性能,必须使用配置文件的方式,通过配置文件中的参数 `filetype` 指定所要测试的功能类型。
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ taos --dump-config
|
|||
| 适用范围 | 仅服务端适用 |
|
||||
| 含义 | 服务器内部的系统监控开关。监控主要负责收集物理节点的负载状况,包括 CPU、内存、硬盘、网络带宽、HTTP 请求量的监控记录,记录信息存储在`LOG`库中。 |
|
||||
| 取值范围 | 0:关闭监控服务, 1:激活监控服务。 |
|
||||
| 缺省值 | 0 |
|
||||
| 缺省值 | 1 |
|
||||
|
||||
### monitorInterval
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ sidebar_label: Grafana
|
|||
title: Grafana
|
||||
---
|
||||
|
||||
import Tabs from "@theme/Tabs";
|
||||
import TabItem from "@theme/TabItem";
|
||||
|
||||
TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/) 快速集成搭建数据监测报警系统,整个过程无需任何代码开发,TDengine 中数据表的内容可以在仪表盘(DashBoard)上进行可视化展现。关于 TDengine 插件的使用您可以在[GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md)中了解更多。
|
||||
|
||||
## 前置条件
|
||||
|
@ -12,12 +15,42 @@ TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/
|
|||
- TDengine 集群已经部署并正常运行
|
||||
- taosAdapter 已经安装并正常运行。具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
|
||||
|
||||
记录以下信息:
|
||||
|
||||
- TDengine 集群 REST API 地址,如:`http://tdengine.local:6041`。
|
||||
- TDengine 集群认证信息,可使用用户名及密码。
|
||||
|
||||
## 安装 Grafana
|
||||
|
||||
目前 TDengine 支持 Grafana 7.0 以上的版本。用户可以根据当前的操作系统,到 Grafana 官网下载安装包,并执行安装。下载地址如下:<https://grafana.com/grafana/download>。
|
||||
目前 TDengine 支持 Grafana 7.5 以上的版本。用户可以根据当前的操作系统,到 Grafana 官网下载安装包,并执行安装。下载地址如下:<https://grafana.com/grafana/download>。
|
||||
|
||||
## 配置 Grafana
|
||||
|
||||
### 安装 Grafana Plugin 并配置数据源
|
||||
|
||||
<Tabs defaultValue="script">
|
||||
<TabItem value="script" label="使用安装脚本">
|
||||
|
||||
将集群信息设置为环境变量;也可以使用 `.env` 文件,请参考 [dotenv](https://hexdocs.pm/dotenvy/dotenv-file-format.html):
|
||||
|
||||
```sh
|
||||
export TDENGINE_API=http://tdengine.local:6041
|
||||
# user + password
|
||||
export TDENGINE_USER=user
|
||||
export TDENGINE_PASSWORD=password
|
||||
```
|
||||
|
||||
运行安装脚本:
|
||||
|
||||
```sh
|
||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/taosdata/grafanaplugin/master/install.sh)"
|
||||
```
|
||||
|
||||
该脚本将自动安装 Grafana 插件并配置数据源。安装完毕后,需要重启 Grafana 服务后生效。
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="manual" label="手动安装并配置">
|
||||
|
||||
使用 [`grafana-cli` 命令行工具](https://grafana.com/docs/grafana/latest/administration/cli/) 进行插件[安装](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation)。
|
||||
|
||||
```bash
|
||||
|
@ -48,11 +81,7 @@ sudo unzip tdengine-datasource-$GF_VERSION.zip -d /var/lib/grafana/plugins/
|
|||
GF_INSTALL_PLUGINS=tdengine-datasource
|
||||
```
|
||||
|
||||
## 使用 Grafana
|
||||
|
||||
### 配置数据源
|
||||
|
||||
用户可以直接通过 <http://localhost:3000> 的网址,登录 Grafana 服务器(用户名/密码:admin/admin),通过左侧 `Configuration -> Data Sources` 可以添加数据源,如下图所示:
|
||||
之后,用户可以直接通过 <http://localhost:3000> 的网址,登录 Grafana 服务器(用户名/密码:admin/admin),通过左侧 `Configuration -> Data Sources` 可以添加数据源,如下图所示:
|
||||
|
||||

|
||||
|
||||
|
@ -72,6 +101,9 @@ GF_INSTALL_PLUGINS=tdengine-datasource
|
|||
|
||||

|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### 创建 Dashboard
|
||||
|
||||
回到主界面创建 Dashboard,点击 Add Query 进入面板查询页面:
|
||||
|
@ -92,4 +124,11 @@ GF_INSTALL_PLUGINS=tdengine-datasource
|
|||
|
||||
### 导入 Dashboard
|
||||
|
||||
在 2.3.3.0 及以上版本,您可以导入 TDinsight Dashboard (Grafana Dashboard ID: [15167](https://grafana.com/grafana/dashboards/15167)) 作为 TDengine 集群的监控可视化工具。安装和使用说明请见 [TDinsight 用户手册](/reference/tdinsight/)。
|
||||
在数据源配置页面,您可以为该数据源导入 TDinsight 面板,作为 TDengine 集群的监控可视化工具。该 Dashboard 已发布在 Grafana:[Dashboard 15167 - TDinsight](https://grafana.com/grafana/dashboards/15167)) 。其他安装方式和相关使用说明请见 [TDinsight 用户手册](/reference/tdinsight/)。
|
||||
|
||||
使用 TDengine 作为数据源的其他面板,可以[在此搜索](https://grafana.com/grafana/dashboards/?dataSource=tdengine-datasource)。以下是一份不完全列表:
|
||||
|
||||
- [15146](https://grafana.com/grafana/dashboards/15146): 监控多个 TDengine 集群
|
||||
- [15155](https://grafana.com/grafana/dashboards/15155): TDengine 告警示例
|
||||
- [15167](https://grafana.com/grafana/dashboards/15167): TDinsight
|
||||
- [16388](https://grafana.com/grafana/dashboards/16388): Telegraf 采集节点信息的数据展示
|
||||
|
|
|
@ -8,31 +8,24 @@ MQTT 是流行的物联网数据传输协议,[EMQX](https://github.com/emqx/em
|
|||
## 前置条件
|
||||
|
||||
要让 EMQX 能正常添加 TDengine 数据源,需要以下几方面的准备工作。
|
||||
|
||||
- TDengine 集群已经部署并正常运行
|
||||
- taosAdapter 已经安装并正常运行。具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter)
|
||||
- 如果使用后文介绍的模拟写入程序,需要安装合适版本的 Node.js,推荐安装 v12。
|
||||
- 如果使用后文介绍的模拟写入程序,需要安装合适版本的 Node.js,推荐安装 v12
|
||||
|
||||
## 安装并启动 EMQX
|
||||
|
||||
用户可以根据当前的操作系统,到 EMQX 官网下载安装包,并执行安装。下载地址如下:<https://www.emqx.io/zh/downloads>。安装后使用 `sudo emqx start` 或 `sudo systemctl start emqx` 启动 EMQX 服务。
|
||||
|
||||
## 在 TDengine 中为接收 MQTT 数据创建相应数据库和表结构
|
||||
|
||||
### 以 Docker 安装 TDengine 为例
|
||||
## 创建数据库和表
|
||||
|
||||
```bash
|
||||
docker exec -it tdengine bash
|
||||
taos
|
||||
```
|
||||
|
||||
### 创建数据库和表
|
||||
在 TDengine 中为接收 MQTT 数据创建相应数据库和表结构。进入 TDengine CLI 复制并执行以下 SQL 语句:
|
||||
|
||||
```sql
|
||||
create database test;
|
||||
use test;
|
||||
create table:
|
||||
|
||||
CREATE TABLE sensor_data (ts timestamp, temperature float, humidity float, volume float, PM10 float, pm25 float, SO2 float, NO2 float, CO float, sensor_id NCHAR(255), area TINYINT, coll_time timestamp);
|
||||
CREATE DATABASE test;
|
||||
USE test;
|
||||
CREATE TABLE sensor_data (ts TIMESTAMP, temperature FLOAT, humidity FLOAT, volume FLOAT, pm10 FLOAT, pm25 FLOAT, so2 FLOAT, no2 FLOAT, co FLOAT, sensor_id NCHAR(255), area TINYINT, coll_time TIMESTAMP);
|
||||
```
|
||||
|
||||
注:表结构以博客[数据传输、存储、展现,EMQX + TDengine 搭建 MQTT 物联网数据可视化平台](https://www.taosdata.com/blog/2020/08/04/1722.html)为例。后续操作均以此博客场景为例进行,请你根据实际应用场景进行修改。
|
||||
|
@ -43,7 +36,7 @@ MQTT 是流行的物联网数据传输协议,[EMQX](https://github.com/emqx/em
|
|||
|
||||
### 登录 EMQX Dashboard
|
||||
|
||||
使用浏览器打开网址 http://IP:18083 并登录 EMQX Dashboard。初次安装用户名为 `admin` 密码为:`public`
|
||||
使用浏览器打开网址 http://IP:18083 并登录 EMQX Dashboard。初次安装用户名为 `admin` 密码为:`public`。
|
||||
|
||||

|
||||
|
||||
|
@ -55,6 +48,17 @@ MQTT 是流行的物联网数据传输协议,[EMQX](https://github.com/emqx/em
|
|||
|
||||
### 编辑 SQL 字段
|
||||
|
||||
复制以下内容输入到 SQL 编辑框:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
payload
|
||||
FROM
|
||||
"sensor/data"
|
||||
```
|
||||
|
||||
其中 `payload` 代表整个消息体, `sensor/data` 为本规则选取的消息主题。
|
||||
|
||||

|
||||
|
||||
### 新增“动作(action handler)”
|
||||
|
@ -65,101 +69,54 @@ MQTT 是流行的物联网数据传输协议,[EMQX](https://github.com/emqx/em
|
|||
|
||||

|
||||
|
||||
选择“发送数据到 Web 服务“并点击“新建资源”按钮:
|
||||
选择“发送数据到 Web 服务”并点击“新建资源”按钮:
|
||||
|
||||
### 编辑“资源(Resource)”
|
||||
|
||||
选择“发送数据到 Web 服务“并填写 请求 URL 为 运行 taosAdapter 的服务器地址和端口(默认为 6041)。其他属性请保持默认值。
|
||||
选择“WebHook”并填写“请求 URL”为 taosAdapter 提供 REST 服务的地址,如果是本地启动的 taosadapter, 那么默认地址为:
|
||||
|
||||
```
|
||||
http://127.0.0.1:6041/rest/sql
|
||||
```
|
||||
|
||||
其他属性请保持默认值。
|
||||
|
||||

|
||||
|
||||
### 编辑“动作(action)”
|
||||
|
||||
编辑资源配置,增加 Authorization 认证的键/值配对项,相关文档请参考[ TDengine REST API 文档](https://docs.taosdata.com/reference/rest-api/)。在消息体中输入规则引擎替换模板。
|
||||
编辑资源配置,增加 Authorization 认证的键/值配对项。默认用户名和密码对应的 Authorization 值为:
|
||||
```
|
||||
Basic cm9vdDp0YW9zZGF0YQ==
|
||||
```
|
||||
相关文档请参考[ TDengine REST API 文档](/reference/rest-api/)。
|
||||
|
||||
在消息体中输入规则引擎替换模板:
|
||||
|
||||
```sql
|
||||
INSERT INTO test.sensor_data VALUES(
|
||||
now,
|
||||
${payload.temperature},
|
||||
${payload.humidity},
|
||||
${payload.volume},
|
||||
${payload.PM10},
|
||||
${payload.pm25},
|
||||
${payload.SO2},
|
||||
${payload.NO2},
|
||||
${payload.CO},
|
||||
'${payload.id}',
|
||||
${payload.area},
|
||||
${payload.ts}
|
||||
)
|
||||
```
|
||||
|
||||

|
||||
|
||||
最后点击左下方的 “Create” 按钮,保存规则。
|
||||
## 编写模拟测试程序
|
||||
|
||||
```javascript
|
||||
// mock.js
|
||||
const mqtt = require('mqtt')
|
||||
const Mock = require('mockjs')
|
||||
const EMQX_SERVER = 'mqtt://localhost:1883'
|
||||
const CLIENT_NUM = 10
|
||||
const STEP = 5000 // 模拟采集时间间隔 ms
|
||||
const AWAIT = 5000 // 每次发送完后休眠时间,防止消息速率过快 ms
|
||||
const CLIENT_POOL = []
|
||||
startMock()
|
||||
function sleep(timer = 100) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, timer)
|
||||
})
|
||||
}
|
||||
async function startMock() {
|
||||
const now = Date.now()
|
||||
for (let i = 0; i < CLIENT_NUM; i++) {
|
||||
const client = await createClient(`mock_client_${i}`)
|
||||
CLIENT_POOL.push(client)
|
||||
}
|
||||
// last 24h every 5s
|
||||
const last = 24 * 3600 * 1000
|
||||
for (let ts = now - last; ts <= now; ts += STEP) {
|
||||
for (const client of CLIENT_POOL) {
|
||||
const mockData = generateMockData()
|
||||
const data = {
|
||||
...mockData,
|
||||
id: client.clientId,
|
||||
area: 0,
|
||||
ts,
|
||||
}
|
||||
client.publish('sensor/data', JSON.stringify(data))
|
||||
}
|
||||
const dateStr = new Date(ts).toLocaleTimeString()
|
||||
console.log(`${dateStr} send success.`)
|
||||
await sleep(AWAIT)
|
||||
}
|
||||
console.log(`Done, use ${(Date.now() - now) / 1000}s`)
|
||||
}
|
||||
/**
|
||||
* Init a virtual mqtt client
|
||||
* @param {string} clientId ClientID
|
||||
*/
|
||||
function createClient(clientId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const client = mqtt.connect(EMQX_SERVER, {
|
||||
clientId,
|
||||
})
|
||||
client.on('connect', () => {
|
||||
console.log(`client ${clientId} connected`)
|
||||
resolve(client)
|
||||
})
|
||||
client.on('reconnect', () => {
|
||||
console.log('reconnect')
|
||||
})
|
||||
client.on('error', (e) => {
|
||||
console.error(e)
|
||||
reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Generate mock data
|
||||
*/
|
||||
function generateMockData() {
|
||||
return {
|
||||
"temperature": parseFloat(Mock.Random.float(22, 100).toFixed(2)),
|
||||
"humidity": parseFloat(Mock.Random.float(12, 86).toFixed(2)),
|
||||
"volume": parseFloat(Mock.Random.float(20, 200).toFixed(2)),
|
||||
"PM10": parseFloat(Mock.Random.float(0, 300).toFixed(2)),
|
||||
"pm25": parseFloat(Mock.Random.float(0, 300).toFixed(2)),
|
||||
"SO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"NO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"CO": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"area": Mock.Random.integer(0, 20),
|
||||
"ts": 1596157444170,
|
||||
}
|
||||
}
|
||||
{{#include docs-examples/other/mock.js}}
|
||||
```
|
||||
|
||||
注意:代码中 CLIENT_NUM 在开始测试中可以先设置一个较小的值,避免硬件性能不能完全处理较大并发客户端数量。
|
||||
|
@ -189,4 +146,3 @@ node mock.js
|
|||
|
||||
TDengine 详细使用方法请参考 [TDengine 官方文档](https://docs.taosdata.com/)。
|
||||
EMQX 详细使用方法请参考 [EMQX 官方文档](https://www.emqx.io/docs/zh/v4.4/rule/rule-engine.html)。
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
sidebar_label: Delete Data
|
||||
description: "Delete data from table or Stable"
|
||||
title: Delete Data
|
||||
---
|
||||
|
||||
TDengine provides the functionality of deleting data from a table or STable according to specified time range, it can be used to cleanup abnormal data generated due to device failure. Please be noted that this functionality is only available in Enterprise version, please refer to [TDengine Enterprise Edition](https://tdengine.com/products#enterprise-edition-link)
|
||||
|
||||
|
||||
**Syntax:**
|
||||
|
||||
```sql
|
||||
DELETE FROM [ db_name. ] tb_name [WHERE condition];
|
||||
```
|
||||
|
||||
**Description:** Delete data from a table or STable
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `db_name`: Optional parameter, specifies the database in which the table exists; if not specified, the current database will be used.
|
||||
- `tb_name`: Mandatory parameter, specifies the table name from which data will be deleted, it can be normal table, subtable or STable.
|
||||
- `condition`: Optional parameter, specifies the data filter condition. If no condition is specified all data will be deleted, so please be cautions to delete data without any condition. The condition used here is only applicable to the first column, i.e. the timestamp column. If the table is a STable, the condition is also applicable to tag columns.
|
||||
|
||||
**More Explanations:**
|
||||
|
||||
The data can't be recovered once deleted, so please be cautious to use the functionality of deleting data. It's better to firstly make sure the data to be deleted using `select` then execute `delete`.
|
||||
|
||||
**Example:**
|
||||
|
||||
`meters` is a STable, in which `groupid` is a tag column of int type. Now we want to delete the data older than 2021-10-01 10:40:00.100 and `groupid` is 1. The SQL for this purpose is like below:
|
||||
|
||||
```sql
|
||||
delete from meters where ts < '2021-10-01 10:40:00.100' and groupid=1 ;
|
||||
```
|
||||
|
||||
The output is:
|
||||
|
||||
```
|
||||
Deleted 102000 row(s) from 1020 table(s) (0.421950s)
|
||||
```
|
||||
|
||||
It means totally 102,000 rows of data have been deleted from 1,020 sub tables.
|
|
@ -48,7 +48,7 @@ Please refer to [version support list](/reference/connector#version-support)
|
|||
|
||||
* Install the [.NET SDK](https://dotnet.microsoft.com/download)
|
||||
* [Nuget Client](https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools) (optional installation)
|
||||
* Install TDengine client driver, please refer to [Install client driver](/reference/connector#Install client driver) for details
|
||||
* Install TDengine client driver, please refer to [Install client driver](/reference/connector/#install-client-driver) for details
|
||||
|
||||
### Install via dotnet CLI
|
||||
|
||||
|
@ -57,7 +57,7 @@ Please refer to [version support list](/reference/connector#version-support)
|
|||
|
||||
You can reference the `TDengine.Connector` published in Nuget to the current project via the `dotnet` command under the path of the existing .NET project.
|
||||
|
||||
``` bash
|
||||
```
|
||||
dotnet add package TDengine.Connector
|
||||
```
|
||||
|
||||
|
@ -66,7 +66,7 @@ dotnet add package TDengine.Connector
|
|||
|
||||
You can download TDengine's source code and directly reference the latest version of the TDengine.Connector library
|
||||
|
||||
```bash
|
||||
```
|
||||
git clone https://github.com/taosdata/TDengine.git
|
||||
cd TDengine/src/connector/C#/src/
|
||||
cp -r TDengineDriver/ myProject
|
||||
|
@ -79,7 +79,7 @@ dotnet add TDengineDriver/TDengineDriver.csproj
|
|||
|
||||
## Create a connection
|
||||
|
||||
``` C#
|
||||
```csharp
|
||||
using TDengineDriver;
|
||||
|
||||
namespace TDengineExample
|
||||
|
|
|
@ -55,25 +55,27 @@ A "REST connection" is a connection between the application and the TDengine ins
|
|||
|
||||
### Pre-installation
|
||||
|
||||
* Install Go development environment (Go 1.14 and above, GCC 4.8.5 and above)
|
||||
* If you use the native connector, please install the TDengine client driver. Please refer to [Install Client Driver](/reference/connector#Install Client Driver) for specific steps
|
||||
- Install Go development environment (Go 1.14 and above, GCC 4.8.5 and above)
|
||||
- If you use the native connector, please install the TDengine client driver. Please refer to [Install Client Driver](/reference/connector/#install-client-driver) for specific steps
|
||||
|
||||
Configure the environment variables and check the command.
|
||||
|
||||
* ```go env``
|
||||
* ```gcc -v``
|
||||
* `go env`
|
||||
* `gcc -v`
|
||||
|
||||
### Use go get to install
|
||||
|
||||
``go get -u github.com/taosdata/driver-go/v2@develop``
|
||||
```
|
||||
go get -u github.com/taosdata/driver-go/v2@develop
|
||||
```
|
||||
|
||||
### Manage with go mod
|
||||
|
||||
1. Initialize the project with the `go mod` command.
|
||||
|
||||
``text
|
||||
```text
|
||||
go mod init taos-demo
|
||||
``` text
|
||||
```
|
||||
|
||||
2. Introduce taosSql
|
||||
|
||||
|
@ -88,7 +90,7 @@ Configure the environment variables and check the command.
|
|||
|
||||
```text
|
||||
go mod tidy
|
||||
``` 4.
|
||||
```
|
||||
|
||||
4. Run the program with `go run taos-demo` or compile the binary with the `go build` command.
|
||||
|
||||
|
@ -309,6 +311,7 @@ func main() {
|
|||
|
||||
:::info
|
||||
This API is created successfully without checking permissions, but only when you execute a Query or Exec, and check if user/password/host/port is legal.
|
||||
|
||||
:::
|
||||
|
||||
* `func (db *DB) Exec(query string, args . .interface{}) (Result, error)`
|
||||
|
|
|
@ -69,7 +69,7 @@ Before using Java Connector to connect to the database, the following conditions
|
|||
### Install the connectors
|
||||
|
||||
<Tabs defaultValue="maven">
|
||||
<TabItem value="maven" label="install via Maven">
|
||||
<TabItem value="maven" label="Install via Maven">
|
||||
|
||||
- [sonatype](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
- [mvnrepository](https://mvnrepository.com/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
|
@ -77,7 +77,7 @@ Before using Java Connector to connect to the database, the following conditions
|
|||
|
||||
Add following dependency in the `pom.xml` file of your Maven project:
|
||||
|
||||
```xml-dtd
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
|
@ -90,7 +90,7 @@ Add following dependency in the `pom.xml` file of your Maven project:
|
|||
|
||||
You can build Java connector from source code after cloning the TDengine project:
|
||||
|
||||
```shell
|
||||
```
|
||||
git clone https://github.com/taosdata/taos-connector-jdbc.git
|
||||
cd taos-connector-jdbc
|
||||
mvn clean install -Dmaven.test.skip=true
|
||||
|
@ -140,8 +140,8 @@ When you use a JDBC native connection to connect to a TDengine cluster, you can
|
|||
|
||||
1. Do not specify hostname and port in Java applications.
|
||||
|
||||
```java
|
||||
public Connection getConn() throws Exception{
|
||||
```java
|
||||
public Connection getConn() throws Exception{
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
String jdbcUrl = "jdbc:TAOS://:/test?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
|
@ -150,30 +150,33 @@ public Connection getConn() throws Exception{
|
|||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||
return conn;
|
||||
}
|
||||
```
|
||||
}
|
||||
```
|
||||
|
||||
2. specify the firstEp and the secondEp in the configuration file taos.cfg
|
||||
|
||||
```shell
|
||||
# first fully qualified domain name (FQDN) for TDengine system
|
||||
firstEp cluster_node1:6030
|
||||
```shell
|
||||
# first fully qualified domain name (FQDN) for TDengine system
|
||||
firstEp cluster_node1:6030
|
||||
|
||||
# second fully qualified domain name (FQDN) for TDengine system, for cluster only
|
||||
secondEp cluster_node2:6030
|
||||
# second fully qualified domain name (FQDN) for TDengine system, for cluster only
|
||||
secondEp cluster_node2:6030
|
||||
|
||||
# default system charset
|
||||
# charset UTF-8
|
||||
# default system charset
|
||||
# charset UTF-8
|
||||
|
||||
# system locale
|
||||
# locale en_US.UTF-8
|
||||
```
|
||||
# system locale
|
||||
# locale en_US.UTF-8
|
||||
```
|
||||
|
||||
In the above example, JDBC uses the client's configuration file to establish a connection to a hostname `cluster_node1`, port 6030, and a database named `test`. When the firstEp node in the cluster fails, JDBC attempts to connect to the cluster using secondEp.
|
||||
|
||||
In TDengine, as long as one node in firstEp and secondEp is valid, the connection to the cluster can be established normally.
|
||||
|
||||
> **Note**: The configuration file here refers to the configuration file on the machine where the application that calls the JDBC Connector is located, the default path is `/etc/taos/taos.cfg` on Linux, and the default path is `C://TDengine/cfg/taos.cfg` on Windows.
|
||||
:::note
|
||||
The configuration file here refers to the configuration file on the machine where the application that calls the JDBC Connector is located, the default path is `/etc/taos/taos.cfg` on Linux, and the default path is `C://TDengine/cfg/taos.cfg` on Windows.
|
||||
|
||||
:::
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="rest" label="REST connection">
|
||||
|
|
|
@ -45,15 +45,15 @@ Add the [libtaos][libtaos] dependency to the [Rust](https://rust-lang.org) proje
|
|||
<Tabs defaultValue="native">
|
||||
<TabItem value="native" label="native connection">
|
||||
|
||||
Add [libtaos][libtaos] to the ``Cargo.toml`'' file.
|
||||
Add [libtaos][libtaos] to the `Cargo.toml` file.
|
||||
|
||||
``toml
|
||||
```toml
|
||||
[dependencies]
|
||||
# use default feature
|
||||
libtaos = "*"
|
||||
```
|
||||
|
||||
</TabItem
|
||||
</TabItem>
|
||||
<TabItem value="rest" label="REST connection">
|
||||
|
||||
Add [libtaos][libtaos] to the `Cargo.toml` file and enable the `rest` feature.
|
||||
|
|
|
@ -21,7 +21,7 @@ There are two ways to install taosBenchmark:
|
|||
|
||||
### Configuration and running methods
|
||||
|
||||
taosBenchmark supports two configuration methods: [Command-line arguments](#Command-line arguments in detailed) and [JSON configuration file](#Configuration file arguments in detailed). These two methods are mutually exclusive. Users can use `-f <json file>` to specify a configuration file. When running taosBenchmark with command-line arguments to control its behavior, users should use other parameters for configuration, but not the `-f` parameter. In addition, taosBenchmark offers a special way of running without parameters.
|
||||
TaosBenchmark needs to be executed on the terminal of the operating system, it supports two configuration methods: [Command-line arguments](#Command-line arguments in detailed) and [JSON configuration file](#Configuration file arguments in detailed). These two methods are mutually exclusive. Users can use `-f <json file>` to specify a configuration file. When running taosBenchmark with command-line arguments to control its behavior, users should use other parameters for configuration, but not the `-f` parameter. In addition, taosBenchmark offers a special way of running without parameters.
|
||||
|
||||
taosBenchmark supports complete performance testing of TDengine. taosBenchmark supports the TDengine functions in three categories: write, query, and subscribe. These three functions are mutually exclusive, and users can select only one of them each time taosBenchmark runs. It is important to note that the type of functionality to be tested is not configurable when using the command-line configuration method, which can only test writing performance. To test the query and subscription performance of the TDengine, you must use the configuration file method and specify the function type to test via the parameter `filetype` in the configuration file.
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ TDengine uses 13 continuous ports, both TCP and UDP, starting with the port spec
|
|||
| Applicable | Server Only |
|
||||
| Meaning | The switch for monitoring inside server. The workload of the hosts, including CPU, memory, disk, network, TTP requests, are collected and stored in a system builtin database `LOG` |
|
||||
| Value Range | 0: monitoring disabled, 1: monitoring enabled |
|
||||
| Default Value | 0 |
|
||||
| Default Value | 1 |
|
||||
|
||||
### monitorInterval
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ sidebar_label: Grafana
|
|||
title: Grafana
|
||||
---
|
||||
|
||||
import Tabs from "@theme/Tabs";
|
||||
import TabItem from "@theme/TabItem";
|
||||
|
||||
TDengine can be quickly integrated with the open-source data visualization system [Grafana](https://www.grafana.com/) to build a data monitoring and alerting system. The whole process does not require any code development. And you can visualize the contents of the data tables in TDengine on a dashboard.
|
||||
|
||||
You can learn more about using the TDengine plugin on [GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md).
|
||||
|
@ -14,12 +17,44 @@ In order for Grafana to add the TDengine data source successfully, the following
|
|||
1. The TDengine cluster is deployed and functioning properly
|
||||
2. taosAdapter is installed and running properly. Please refer to the taosAdapter manual for details.
|
||||
|
||||
Record these values:
|
||||
|
||||
- TDengine REST API url: `http://tdengine.local:6041`.
|
||||
- TDengine cluster authorization, with user + password.
|
||||
|
||||
## Installing Grafana
|
||||
|
||||
TDengine currently supports Grafana versions 7.0 and above. Users can go to the Grafana official website to download the installation package and execute the installation according to the current operating system. The download address is as follows: <https://grafana.com/grafana/download>.
|
||||
TDengine currently supports Grafana versions 7.5 and above. Users can go to the Grafana official website to download the installation package and execute the installation according to the current operating system. The download address is as follows: <https://grafana.com/grafana/download>.
|
||||
|
||||
## Configuring Grafana
|
||||
|
||||
### Install Grafana Plugin and Configure Data Source
|
||||
|
||||
<Tabs defaultValue="script">
|
||||
<TabItem value="script" label="Using Script">
|
||||
|
||||
Set the url and authorization environment variables by `export` or a [`.env`(dotenv) file](https://hexdocs.pm/dotenvy/dotenv-file-format.html):
|
||||
|
||||
```sh
|
||||
export TDENGINE_API=http://tdengine.local:6041
|
||||
# user + password
|
||||
export TDENGINE_USER=user
|
||||
export TDENGINE_PASSWORD=password
|
||||
```
|
||||
|
||||
Run `install.sh`:
|
||||
|
||||
```sh
|
||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/taosdata/grafanaplugin/master/install.sh)"
|
||||
```
|
||||
|
||||
With this script, TDengine data source plugin and the Grafana data source will be installed and created automatically with Grafana provisioning configurations.
|
||||
|
||||
And then, restart Grafana service and open Grafana in web-browser, usually <http://localhost:3000>.
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="manual" label="Install & Configure Manually">
|
||||
|
||||
Follow the installation steps in [Grafana](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation) with the [``grafana-cli`` command-line tool](https://grafana.com/docs/grafana/latest/administration/cli/) for plugin installation.
|
||||
|
||||
```bash
|
||||
|
@ -50,11 +85,7 @@ If Grafana is running in a Docker environment, the TDengine plugin can be automa
|
|||
GF_INSTALL_PLUGINS=tdengine-datasource
|
||||
```
|
||||
|
||||
## Using Grafana
|
||||
|
||||
### Configuring Data Sources
|
||||
|
||||
Users can log in to the Grafana server (username/password: admin/admin) directly through the URL `http://localhost:3000` and add a datasource through `Configuration -> Data Sources` on the left side, as shown in the following figure.
|
||||
Now users can log in to the Grafana server (username/password: admin/admin) directly through the URL `http://localhost:3000` and add a datasource through `Configuration -> Data Sources` on the left side, as shown in the following figure.
|
||||
|
||||

|
||||
|
||||
|
@ -74,6 +105,9 @@ Click `Save & Test` to test. You should see a success message if the test worked
|
|||
|
||||

|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### Create Dashboard
|
||||
|
||||
Go back to the main interface to create a dashboard and click Add Query to enter the panel query page:
|
||||
|
@ -94,4 +128,11 @@ Follow the default prompt to query the average system memory usage for the speci
|
|||
|
||||
### Importing the Dashboard
|
||||
|
||||
In version 2.3.3.0 and above, you can import the TDinsight Dashboard (Grafana Dashboard ID: [15168](https://grafana.com/grafana/dashboards/15167)) as a monitoring visualization tool for TDengine clusters. You can find installation and usage instructions in the TDinsight User Manual (/reference/tdinsight/).
|
||||
You can install TDinsight dashboard in data source configuration page (like `http://localhost:3000/datasources/edit/1/dashboards`) as a monitoring visualization tool for TDengine cluster. The dashboard is published in Grafana as [Dashboard 15167 - TDinsight](https://grafana.com/grafana/dashboards/15167). Check the [TDinsight User Manual](/reference/tdinsight/) for the details.
|
||||
|
||||
For more dashboards using TDengine data source, [search here in Grafana](https://grafana.com/grafana/dashboards/?dataSource=tdengine-datasource). Here is a sub list:
|
||||
|
||||
- [15146](https://grafana.com/grafana/dashboards/15146): Monitor multiple TDengine clusters.
|
||||
- [15155](https://grafana.com/grafana/dashboards/15155): TDengine alert demo.
|
||||
- [15167](https://grafana.com/grafana/dashboards/15167): TDinsight.
|
||||
- [16388](https://grafana.com/grafana/dashboards/16388): Telegraf node metrics dashboard using TDengine data source.
|
||||
|
|
|
@ -16,22 +16,15 @@ The following preparations are required for EMQX to add TDengine data sources co
|
|||
|
||||
Depending on the current operating system, users can download the installation package from the [EMQX official website](https://www.emqx.io/downloads) and execute the installation. After installation, use `sudo emqx start` or `sudo systemctl start emqx` to start the EMQX service.
|
||||
|
||||
## Create the appropriate database and table schema in TDengine for receiving MQTT data
|
||||
|
||||
### Take the Docker installation of TDengine as an example
|
||||
## Create Database and Table
|
||||
|
||||
```bash
|
||||
docker exec -it tdengine bash
|
||||
taos
|
||||
```
|
||||
|
||||
### Create Database and Table
|
||||
In this step we create the appropriate database and table schema in TDengine for receiving MQTT data. Open TDengine CLI and execute SQL bellow:
|
||||
|
||||
```sql
|
||||
CREATE DATABASE test;
|
||||
USE test;
|
||||
|
||||
CREATE TABLE sensor_data (ts timestamp, temperature float, humidity float, volume float, PM10 float, pm25 float, SO2 float, NO2 float, CO float, sensor_id NCHAR(255), area TINYINT, coll_time timestamp);
|
||||
CREATE DATABASE test;
|
||||
USE test;
|
||||
CREATE TABLE sensor_data (ts TIMESTAMP, temperature FLOAT, humidity FLOAT, volume FLOAT, pm10 FLOAT, pm25 FLOAT, so2 FLOAT, no2 FLOAT, co FLOAT, sensor_id NCHAR(255), area TINYINT, coll_time TIMESTAMP);
|
||||
```
|
||||
|
||||
Note: The table schema is based on the blog [(In Chinese) Data Transfer, Storage, Presentation, EMQX + TDengine Build MQTT IoT Data Visualization Platform](https://www.taosdata.com/blog/2020/08/04/1722.html) as an example. Subsequent operations are carried out with this blog scenario too. Please modify it according to your actual application scenario.
|
||||
|
@ -54,6 +47,15 @@ Select "Rule" in the "Rule Engine" on the left and click the "Create" button: !
|
|||
|
||||
### Edit SQL fields
|
||||
|
||||
Copy SQL bellow and paste it to the SQL edit area:
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
payload
|
||||
FROM
|
||||
"sensor/data"
|
||||
```
|
||||
|
||||

|
||||
|
||||
### Add "action handler"
|
||||
|
@ -68,97 +70,45 @@ Select "Data to Web Service" and click the "New Resource" button.
|
|||
|
||||
### Edit "Resource"
|
||||
|
||||
Select "Data to Web Service" and fill in the request URL as the address and port of the server running taosAdapter (default is 6041). Leave the other properties at their default values.
|
||||
Select "WebHook" and fill in the request URL as the address and port of the server running taosAdapter (default is 6041). Leave the other properties at their default values.
|
||||
|
||||

|
||||
|
||||
### Edit "action"
|
||||
|
||||
Edit the resource configuration to add the key/value pairing for Authorization. Please refer to the [ TDengine REST API documentation ](https://docs.taosdata.com/reference/rest-api/) for the authorization in details. Enter the rule engine replacement template in the message body.
|
||||
Edit the resource configuration to add the key/value pairing for Authorization. If you use the default TDengine username and password then the value of key Authorization is:
|
||||
```
|
||||
Basic cm9vdDp0YW9zZGF0YQ==
|
||||
```
|
||||
|
||||
Please refer to the [ TDengine REST API documentation ](/reference/rest-api/) for the authorization in details.
|
||||
|
||||
Enter the rule engine replacement template in the message body:
|
||||
|
||||
```sql
|
||||
INSERT INTO test.sensor_data VALUES(
|
||||
now,
|
||||
${payload.temperature},
|
||||
${payload.humidity},
|
||||
${payload.volume},
|
||||
${payload.PM10},
|
||||
${payload.pm25},
|
||||
${payload.SO2},
|
||||
${payload.NO2},
|
||||
${payload.CO},
|
||||
'${payload.id}',
|
||||
${payload.area},
|
||||
${payload.ts}
|
||||
)
|
||||
```
|
||||
|
||||

|
||||
|
||||
Finally, click the "Create" button at bottom left corner saving the rule.
|
||||
## Compose program to mock data
|
||||
|
||||
```javascript
|
||||
// mock.js
|
||||
const mqtt = require('mqtt')
|
||||
const Mock = require('mockjs')
|
||||
const EMQX_SERVER = 'mqtt://localhost:1883'
|
||||
const CLIENT_NUM = 10
|
||||
const STEP = 5000 // Data interval in ms
|
||||
const AWAIT = 5000 // Sleep time after data be written once to avoid data writing too fast
|
||||
const CLIENT_POOL = []
|
||||
startMock()
|
||||
function sleep(timer = 100) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, timer)
|
||||
})
|
||||
}
|
||||
async function startMock() {
|
||||
const now = Date.now()
|
||||
for (let i = 0; i < CLIENT_NUM; i++) {
|
||||
const client = await createClient(`mock_client_${i}`)
|
||||
CLIENT_POOL.push(client)
|
||||
}
|
||||
// last 24h every 5s
|
||||
const last = 24 * 3600 * 1000
|
||||
for (let ts = now - last; ts <= now; ts += STEP) {
|
||||
for (const client of CLIENT_POOL) {
|
||||
const mockData = generateMockData()
|
||||
const data = {
|
||||
...mockData,
|
||||
id: client.clientId,
|
||||
area: 0,
|
||||
ts,
|
||||
}
|
||||
client.publish('sensor/data', JSON.stringify(data))
|
||||
}
|
||||
const dateStr = new Date(ts).toLocaleTimeString()
|
||||
console.log(`${dateStr} send success.`)
|
||||
await sleep(AWAIT)
|
||||
}
|
||||
console.log(`Done, use ${(Date.now() - now) / 1000}s`)
|
||||
}
|
||||
/**
|
||||
* Init a virtual mqtt client
|
||||
* @param {string} clientId ClientID
|
||||
*/
|
||||
function createClient(clientId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const client = mqtt.connect(EMQX_SERVER, {
|
||||
clientId,
|
||||
})
|
||||
client.on('connect', () => {
|
||||
console.log(`client ${clientId} connected`)
|
||||
resolve(client)
|
||||
})
|
||||
client.on('reconnect', () => {
|
||||
console.log('reconnect')
|
||||
})
|
||||
client.on('error', (e) => {
|
||||
console.error(e)
|
||||
reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Generate mock data
|
||||
*/
|
||||
function generateMockData() {
|
||||
return {
|
||||
"temperature": parseFloat(Mock.Random.float(22, 100).toFixed(2)),
|
||||
"humidity": parseFloat(Mock.Random.float(12, 86).toFixed(2)),
|
||||
"volume": parseFloat(Mock.Random.float(20, 200).toFixed(2)),
|
||||
"PM10": parseFloat(Mock.Random.float(0, 300).toFixed(2)),
|
||||
"pm25": parseFloat(Mock.Random.float(0, 300).toFixed(2)),
|
||||
"SO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"NO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"CO": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"area": Mock.Random.integer(0, 20),
|
||||
"ts": 1596157444170,
|
||||
}
|
||||
}
|
||||
{{#include docs-examples/other/mock.js}}
|
||||
```
|
||||
|
||||
Note: `CLIENT_NUM` in the code can be set to a smaller value at the beginning of the test to avoid hardware performance be not capable to handle a more significant number of concurrent clients.
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
// mock.js
|
||||
const mqtt = require('mqtt')
|
||||
const Mock = require('mockjs')
|
||||
const EMQX_SERVER = 'mqtt://localhost:1883'
|
||||
const CLIENT_NUM = 10
|
||||
const STEP = 5000 // Data interval in ms
|
||||
const AWAIT = 5000 // Sleep time after data be written once to avoid data writing too fast
|
||||
const CLIENT_POOL = []
|
||||
startMock()
|
||||
function sleep(timer = 100) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(resolve, timer)
|
||||
})
|
||||
}
|
||||
async function startMock() {
|
||||
const now = Date.now()
|
||||
for (let i = 0; i < CLIENT_NUM; i++) {
|
||||
const client = await createClient(`mock_client_${i}`)
|
||||
CLIENT_POOL.push(client)
|
||||
}
|
||||
// last 24h every 5s
|
||||
const last = 24 * 3600 * 1000
|
||||
for (let ts = now - last; ts <= now; ts += STEP) {
|
||||
for (const client of CLIENT_POOL) {
|
||||
const mockData = generateMockData()
|
||||
const data = {
|
||||
...mockData,
|
||||
id: client.clientId,
|
||||
area: 0,
|
||||
ts,
|
||||
}
|
||||
client.publish('sensor/data', JSON.stringify(data))
|
||||
}
|
||||
const dateStr = new Date(ts).toLocaleTimeString()
|
||||
console.log(`${dateStr} send success.`)
|
||||
await sleep(AWAIT)
|
||||
}
|
||||
console.log(`Done, use ${(Date.now() - now) / 1000}s`)
|
||||
}
|
||||
/**
|
||||
* Init a virtual mqtt client
|
||||
* @param {string} clientId ClientID
|
||||
*/
|
||||
function createClient(clientId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const client = mqtt.connect(EMQX_SERVER, {
|
||||
clientId,
|
||||
})
|
||||
client.on('connect', () => {
|
||||
console.log(`client ${clientId} connected`)
|
||||
resolve(client)
|
||||
})
|
||||
client.on('reconnect', () => {
|
||||
console.log('reconnect')
|
||||
})
|
||||
client.on('error', (e) => {
|
||||
console.error(e)
|
||||
reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Generate mock data
|
||||
*/
|
||||
function generateMockData() {
|
||||
return {
|
||||
"temperature": parseFloat(Mock.Random.float(22, 100).toFixed(2)),
|
||||
"humidity": parseFloat(Mock.Random.float(12, 86).toFixed(2)),
|
||||
"volume": parseFloat(Mock.Random.float(20, 200).toFixed(2)),
|
||||
"PM10": parseFloat(Mock.Random.float(0, 300).toFixed(2)),
|
||||
"pm25": parseFloat(Mock.Random.float(0, 300).toFixed(2)),
|
||||
"SO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"NO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"CO": parseFloat(Mock.Random.float(0, 50).toFixed(2)),
|
||||
"area": Mock.Random.integer(0, 20),
|
||||
"ts": 1596157444170,
|
||||
}
|
||||
}
|
|
@ -99,14 +99,14 @@ typedef struct TAOS_FIELD_E {
|
|||
#define DLL_EXPORT
|
||||
#endif
|
||||
|
||||
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code);
|
||||
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *res, int code);
|
||||
|
||||
typedef struct TAOS_MULTI_BIND {
|
||||
int buffer_type;
|
||||
void * buffer;
|
||||
void *buffer;
|
||||
uintptr_t buffer_length;
|
||||
int32_t * length;
|
||||
char * is_null;
|
||||
int32_t *length;
|
||||
char *is_null;
|
||||
int num;
|
||||
} TAOS_MULTI_BIND;
|
||||
|
||||
|
@ -131,8 +131,6 @@ DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
|
|||
DLL_EXPORT setConfRet taos_set_config(const char *config);
|
||||
DLL_EXPORT int taos_init(void);
|
||||
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
|
||||
const char *db, int dbLen, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
|
||||
DLL_EXPORT void taos_close(TAOS *taos);
|
||||
|
||||
|
@ -157,7 +155,7 @@ DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
|
|||
DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
|
||||
DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
|
||||
DLL_EXPORT char * taos_stmt_errstr(TAOS_STMT *stmt);
|
||||
DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
|
||||
|
||||
|
@ -179,7 +177,7 @@ DLL_EXPORT bool taos_is_update_query(TAOS_RES *res);
|
|||
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
|
||||
DLL_EXPORT int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows);
|
||||
DLL_EXPORT int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData);
|
||||
DLL_EXPORT int * taos_get_column_data_offset(TAOS_RES *res, int columnIndex);
|
||||
DLL_EXPORT int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex);
|
||||
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT void taos_reset_current_db(TAOS *taos);
|
||||
|
||||
|
@ -194,6 +192,8 @@ DLL_EXPORT int taos_errno(TAOS_RES *tres);
|
|||
|
||||
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param);
|
||||
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param);
|
||||
DLL_EXPORT void taos_fetch_raw_block_a(TAOS_RES* res, __taos_async_fn_t fp, void* param);
|
||||
DLL_EXPORT const void *taos_get_raw_block(TAOS_RES* res);
|
||||
|
||||
// Shuduo: temporary enable for app build
|
||||
#if 1
|
||||
|
@ -209,12 +209,12 @@ DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLi
|
|||
|
||||
/* --------------------------TMQ INTERFACE------------------------------- */
|
||||
|
||||
enum tmq_resp_err_t {
|
||||
enum {
|
||||
TMQ_RESP_ERR__FAIL = -1,
|
||||
TMQ_RESP_ERR__SUCCESS = 0,
|
||||
};
|
||||
|
||||
typedef enum tmq_resp_err_t tmq_resp_err_t;
|
||||
typedef int32_t tmq_resp_err_t;
|
||||
|
||||
typedef struct tmq_t tmq_t;
|
||||
typedef struct tmq_topic_vgroup_t tmq_topic_vgroup_t;
|
||||
|
@ -229,7 +229,7 @@ DLL_EXPORT tmq_list_t *tmq_list_new();
|
|||
DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *);
|
||||
DLL_EXPORT void tmq_list_destroy(tmq_list_t *);
|
||||
DLL_EXPORT int32_t tmq_list_get_size(const tmq_list_t *);
|
||||
DLL_EXPORT char ** tmq_list_to_c_array(const tmq_list_t *);
|
||||
DLL_EXPORT char **tmq_list_to_c_array(const tmq_list_t *);
|
||||
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
|
||||
|
@ -240,7 +240,10 @@ DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
|||
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
|
||||
DLL_EXPORT TAOS_RES * tmq_consumer_poll(tmq_t *tmq, int64_t timeout);
|
||||
|
||||
// timeout: -1 means infinitely waiting
|
||||
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout);
|
||||
|
||||
DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_commit_sync(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets);
|
||||
DLL_EXPORT void tmq_commit_async(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, tmq_commit_cb *cb, void *param);
|
||||
|
@ -260,7 +263,7 @@ enum tmq_conf_res_t {
|
|||
|
||||
typedef enum tmq_conf_res_t tmq_conf_res_t;
|
||||
|
||||
DLL_EXPORT tmq_conf_t * tmq_conf_new();
|
||||
DLL_EXPORT tmq_conf_t *tmq_conf_new();
|
||||
DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const char *value);
|
||||
DLL_EXPORT void tmq_conf_destroy(tmq_conf_t *conf);
|
||||
DLL_EXPORT void tmq_conf_set_auto_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb, void *param);
|
||||
|
|
|
@ -37,19 +37,12 @@ enum {
|
|||
TMQ_MSG_TYPE__EP_RSP,
|
||||
};
|
||||
|
||||
enum {
|
||||
STREAM_TRIGGER__AT_ONCE = 1,
|
||||
STREAM_TRIGGER__WINDOW_CLOSE,
|
||||
STREAM_TRIGGER__BY_COUNT,
|
||||
STREAM_TRIGGER__BY_BATCH_COUNT,
|
||||
STREAM_TRIGGER__BY_EVENT_TIME,
|
||||
};
|
||||
|
||||
typedef enum EStreamType {
|
||||
STREAM_NORMAL = 1,
|
||||
STREAM_INVERT,
|
||||
STREAM_REPROCESS,
|
||||
STREAM_INVALID,
|
||||
STREAM_GET_ALL,
|
||||
} EStreamType;
|
||||
|
||||
typedef struct {
|
||||
|
@ -116,6 +109,8 @@ typedef struct SQueryTableDataCond {
|
|||
int32_t type; // data block load type:
|
||||
int32_t numOfTWindows;
|
||||
STimeWindow* twindows;
|
||||
int32_t startVersion;
|
||||
int32_t endVersion;
|
||||
} SQueryTableDataCond;
|
||||
|
||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||
|
@ -159,19 +154,25 @@ typedef struct SColumn {
|
|||
} SColumn;
|
||||
|
||||
typedef struct STableBlockDistInfo {
|
||||
uint16_t rowSize;
|
||||
uint32_t rowSize;
|
||||
uint16_t numOfFiles;
|
||||
uint32_t numOfTables;
|
||||
uint32_t numOfBlocks;
|
||||
uint64_t totalSize;
|
||||
uint64_t totalRows;
|
||||
int32_t maxRows;
|
||||
int32_t minRows;
|
||||
int32_t defMinRows;
|
||||
int32_t defMaxRows;
|
||||
int32_t firstSeekTimeUs;
|
||||
uint32_t numOfRowsInMemTable;
|
||||
uint32_t numOfInmemRows;
|
||||
uint32_t numOfSmallBlocks;
|
||||
SArray* dataBlockInfos;
|
||||
int32_t blockRowsHisto[20];
|
||||
} STableBlockDistInfo;
|
||||
|
||||
int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDistInfo* pInfo);
|
||||
int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo);
|
||||
|
||||
enum {
|
||||
FUNC_PARAM_TYPE_VALUE = 0x1,
|
||||
FUNC_PARAM_TYPE_COLUMN = 0x2,
|
||||
|
|
|
@ -206,7 +206,7 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3
|
|||
size_t blockDataGetSize(const SSDataBlock* pBlock);
|
||||
size_t blockDataGetRowSize(SSDataBlock* pBlock);
|
||||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock);
|
||||
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock);
|
||||
size_t blockDataGetSerialMetaSize(uint32_t numOfCols);
|
||||
|
||||
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo);
|
||||
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
|
||||
|
@ -238,7 +238,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool
|
|||
const char* stbFullName, int32_t vgId);
|
||||
|
||||
static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) {
|
||||
return blockDataGetSerialMetaSize(pBlock) + blockDataGetSize(pBlock);
|
||||
return blockDataGetSerialMetaSize(pBlock->info.numOfCols) + blockDataGetSize(pBlock);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data,
|
||||
|
|
|
@ -96,6 +96,7 @@ extern bool tsDeadLockKillQuery;
|
|||
|
||||
// query client
|
||||
extern int32_t tsQueryPolicy;
|
||||
extern int32_t tsQuerySmaOptimize;
|
||||
|
||||
// client
|
||||
extern int32_t tsMinSlidingTime;
|
||||
|
|
|
@ -1205,6 +1205,7 @@ typedef struct {
|
|||
int8_t completed; // all results are returned to client
|
||||
int8_t precision;
|
||||
int8_t compressed;
|
||||
int8_t streamBlockType;
|
||||
int32_t compLen;
|
||||
int32_t numOfRows;
|
||||
int32_t numOfCols;
|
||||
|
@ -1340,6 +1341,13 @@ typedef struct {
|
|||
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
|
||||
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
} SSplitVgroupReq;
|
||||
|
||||
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
|
||||
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char spi;
|
||||
|
@ -1486,10 +1494,9 @@ typedef struct {
|
|||
int32_t code;
|
||||
} STaskDropRsp;
|
||||
|
||||
#define STREAM_TRIGGER_AT_ONCE_SMA 0
|
||||
#define STREAM_TRIGGER_AT_ONCE 1
|
||||
#define STREAM_TRIGGER_WINDOW_CLOSE 2
|
||||
#define STREAM_TRIGGER_WINDOW_CLOSE_SMA 3
|
||||
#define STREAM_TRIGGER_MAX_DELAY 3
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
|
@ -2337,15 +2344,17 @@ typedef struct {
|
|||
char indexName[TSDB_INDEX_NAME_LEN];
|
||||
int32_t exprLen;
|
||||
int32_t tagsFilterLen;
|
||||
int32_t numOfVgroups;
|
||||
int64_t indexUid;
|
||||
tb_uid_t tableUid; // super/child/common table uid
|
||||
tb_uid_t dstTbUid; // for dstVgroup
|
||||
int64_t interval;
|
||||
int64_t offset; // use unit by precision of DB
|
||||
int64_t sliding;
|
||||
char* dstTbName; // for dstVgroup
|
||||
char* expr; // sma expression
|
||||
char* tagsFilter;
|
||||
SVgEpSet* pVgEpSet;
|
||||
SSchemaWrapper schemaRow; // for dstVgroup
|
||||
SSchemaWrapper schemaTag; // for dstVgroup
|
||||
} STSma; // Time-range-wise SMA
|
||||
|
||||
typedef STSma SVCreateTSmaReq;
|
||||
|
@ -2430,27 +2439,6 @@ static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int64_t indexUid;
|
||||
STimeWindow queryWindow;
|
||||
} SVGetTsmaExpWndsReq;
|
||||
|
||||
#define SMA_WNDS_EXPIRE_FLAG (0x1)
|
||||
#define SMA_WNDS_IS_EXPIRE(flag) (((flag)&SMA_WNDS_EXPIRE_FLAG) != 0)
|
||||
#define SMA_WNDS_SET_EXPIRE(flag) ((flag) |= SMA_WNDS_EXPIRE_FLAG)
|
||||
|
||||
typedef struct {
|
||||
int64_t indexUid;
|
||||
int8_t flags; // 0x1 all window expired
|
||||
int32_t numExpWnds;
|
||||
TSKEY wndSKeys[];
|
||||
} SVGetTsmaExpWndsRsp;
|
||||
|
||||
int32_t tEncodeSVGetTSmaExpWndsReq(SEncoder* pCoder, const SVGetTsmaExpWndsReq* pReq);
|
||||
int32_t tDecodeSVGetTsmaExpWndsReq(SDecoder* pCoder, SVGetTsmaExpWndsReq* pReq);
|
||||
int32_t tEncodeSVGetTSmaExpWndsRsp(SEncoder* pCoder, const SVGetTsmaExpWndsRsp* pReq);
|
||||
int32_t tDecodeSVGetTsmaExpWndsRsp(SDecoder* pCoder, SVGetTsmaExpWndsRsp* pReq);
|
||||
|
||||
typedef struct {
|
||||
int idx;
|
||||
} SMCreateFullTextReq;
|
||||
|
@ -2485,6 +2473,34 @@ typedef struct {
|
|||
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp);
|
||||
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
} STableIndexReq;
|
||||
|
||||
int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
|
||||
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int64_t dstTbUid;
|
||||
int32_t dstVgId;
|
||||
SEpSet epSet;
|
||||
char* expr;
|
||||
} STableIndexInfo;
|
||||
|
||||
typedef struct {
|
||||
SArray* pIndex;
|
||||
} STableIndexRsp;
|
||||
|
||||
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
|
||||
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
|
||||
|
||||
void tFreeSTableIndexInfo(void* pInfo);
|
||||
|
||||
typedef struct {
|
||||
int8_t mqMsgType;
|
||||
int32_t code;
|
||||
|
@ -2725,8 +2741,8 @@ typedef struct {
|
|||
char* msg;
|
||||
} SVDeleteReq;
|
||||
|
||||
int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq);
|
||||
int32_t tDeserializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq);
|
||||
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
|
||||
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int64_t affectedRows;
|
||||
|
|
|
@ -130,6 +130,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_INDEX, "create-index", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_INDEX, "drop-index", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_INDEX, "get-index", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_TABLE_INDEX, "get-table-index", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "create-topic", SMCreateTopicReq, SMCreateTopicRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "alter-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "drop-topic", NULL, NULL)
|
||||
|
@ -156,6 +157,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_BALANCE_VGROUP, "balance-vgroup", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MERGE_VGROUP, "merge-vgroup", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_REDISTRIBUTE_VGROUP, "redistribute-vgroup", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SPLIT_VGROUP, "split-vgroup", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_VND_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "submit", SSubmitReq, SSubmitRsp)
|
||||
|
@ -172,10 +174,6 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONSUME, "vnode-mq-consume", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_QUERY, "vnode-mq-query", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONNECT, "vnode-mq-connect", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_DISCONNECT, "vnode-mq-disconnect", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_CHANGE, "vnode-mq-vg-change", SMqRebVgReq, SMqRebVgRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_DELETE, "vnode-mq-vg-delete", SMqVDeleteReq, SMqVDeleteRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_TASK, "vnode-cancel-task", NULL, NULL)
|
||||
|
@ -186,30 +184,27 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_EXPLAIN, "vnode-explain", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqPollReq, SMqDataBlkRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_DEPLOY, "vnode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_RUN, "vnode-stream-task-run", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_DISPATCH, "vnode-stream-task-dispatch", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_DISPATCH_WRITE, "vnode-stream-task-dispatch-write", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_RECOVER, "vnode-stream-task-recover", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_DISPATCH_WRITE, "vnode-stream-task-dispatch-write", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_SMA, "vnode-drop-sma", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT_RSMA, "vnode-submit-rsma", SSubmitReq, SSubmitRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_GET_TSMA_EXP_WNDS, "vnode-get-tsma-expired-windows", SVGetTsmaExpWndsReq, SVGetTsmaExpWndsRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_DELETE, "delete-data", SVDeleteReq, SVDeleteRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_CONFIG, "alter-config", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_REPLICA, "alter-replica", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_CONFIRM, "alter-confirm", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_HASHRANGE, "alter-hashrange", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "compact", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_QND_MSG)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_SND_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_SND_TASK_DEPLOY, "snode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_SND_TASK_RUN, "snode-stream-task-run", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SND_TASK_DISPATCH, "snode-stream-task-dispatch", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SND_TASK_RECOVER, "snode-stream-task-recover", NULL, NULL)
|
||||
//shared by snode and vnode
|
||||
TD_NEW_MSG_SEG(TDMT_STREAM_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DEPLOY, "stream-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RUN, "stream-task-run", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DISPATCH, "stream-task-dispatch", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RECOVER, "stream-task-recover", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_SCH_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "link-broken", NULL, NULL)
|
||||
|
@ -225,7 +220,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MON_QM_LOAD, "monitor-qload", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_SYNC_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_TIMEOUT, "sync-timeout", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_TIMEOUT, "sync-timer", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PING, "sync-ping", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PING_REPLY, "sync-ping-reply", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_CLIENT_REQUEST, "sync-client-request", NULL, NULL)
|
||||
|
@ -239,6 +234,9 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_SYNC_COMMON_RESPONSE, "sync-common-response", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_APPLY_MSG, "sync-apply-msg", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE, "sync-config-change", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_SEND, "sync-snapshot-send", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_RSP, "sync-snapshot-rsp", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_LEADER_TRANSFER, "sync-leader-transfer", NULL, NULL)
|
||||
|
||||
#if defined(TD_MSG_NUMBER_)
|
||||
TDMT_MAX
|
||||
|
|
|
@ -192,67 +192,68 @@
|
|||
#define TK_VGROUP 174
|
||||
#define TK_MERGE 175
|
||||
#define TK_REDISTRIBUTE 176
|
||||
#define TK_SYNCDB 177
|
||||
#define TK_DELETE 178
|
||||
#define TK_NULL 179
|
||||
#define TK_NK_QUESTION 180
|
||||
#define TK_NK_ARROW 181
|
||||
#define TK_ROWTS 182
|
||||
#define TK_TBNAME 183
|
||||
#define TK_QSTARTTS 184
|
||||
#define TK_QENDTS 185
|
||||
#define TK_WSTARTTS 186
|
||||
#define TK_WENDTS 187
|
||||
#define TK_WDURATION 188
|
||||
#define TK_CAST 189
|
||||
#define TK_NOW 190
|
||||
#define TK_TODAY 191
|
||||
#define TK_TIMEZONE 192
|
||||
#define TK_COUNT 193
|
||||
#define TK_FIRST 194
|
||||
#define TK_LAST 195
|
||||
#define TK_LAST_ROW 196
|
||||
#define TK_BETWEEN 197
|
||||
#define TK_IS 198
|
||||
#define TK_NK_LT 199
|
||||
#define TK_NK_GT 200
|
||||
#define TK_NK_LE 201
|
||||
#define TK_NK_GE 202
|
||||
#define TK_NK_NE 203
|
||||
#define TK_MATCH 204
|
||||
#define TK_NMATCH 205
|
||||
#define TK_CONTAINS 206
|
||||
#define TK_JOIN 207
|
||||
#define TK_INNER 208
|
||||
#define TK_SELECT 209
|
||||
#define TK_DISTINCT 210
|
||||
#define TK_WHERE 211
|
||||
#define TK_PARTITION 212
|
||||
#define TK_BY 213
|
||||
#define TK_SESSION 214
|
||||
#define TK_STATE_WINDOW 215
|
||||
#define TK_SLIDING 216
|
||||
#define TK_FILL 217
|
||||
#define TK_VALUE 218
|
||||
#define TK_NONE 219
|
||||
#define TK_PREV 220
|
||||
#define TK_LINEAR 221
|
||||
#define TK_NEXT 222
|
||||
#define TK_HAVING 223
|
||||
#define TK_ORDER 224
|
||||
#define TK_SLIMIT 225
|
||||
#define TK_SOFFSET 226
|
||||
#define TK_LIMIT 227
|
||||
#define TK_OFFSET 228
|
||||
#define TK_ASC 229
|
||||
#define TK_NULLS 230
|
||||
#define TK_ID 231
|
||||
#define TK_NK_BITNOT 232
|
||||
#define TK_INSERT 233
|
||||
#define TK_VALUES 234
|
||||
#define TK_IMPORT 235
|
||||
#define TK_NK_SEMI 236
|
||||
#define TK_FILE 237
|
||||
#define TK_SPLIT 177
|
||||
#define TK_SYNCDB 178
|
||||
#define TK_DELETE 179
|
||||
#define TK_NULL 180
|
||||
#define TK_NK_QUESTION 181
|
||||
#define TK_NK_ARROW 182
|
||||
#define TK_ROWTS 183
|
||||
#define TK_TBNAME 184
|
||||
#define TK_QSTARTTS 185
|
||||
#define TK_QENDTS 186
|
||||
#define TK_WSTARTTS 187
|
||||
#define TK_WENDTS 188
|
||||
#define TK_WDURATION 189
|
||||
#define TK_CAST 190
|
||||
#define TK_NOW 191
|
||||
#define TK_TODAY 192
|
||||
#define TK_TIMEZONE 193
|
||||
#define TK_COUNT 194
|
||||
#define TK_FIRST 195
|
||||
#define TK_LAST 196
|
||||
#define TK_LAST_ROW 197
|
||||
#define TK_BETWEEN 198
|
||||
#define TK_IS 199
|
||||
#define TK_NK_LT 200
|
||||
#define TK_NK_GT 201
|
||||
#define TK_NK_LE 202
|
||||
#define TK_NK_GE 203
|
||||
#define TK_NK_NE 204
|
||||
#define TK_MATCH 205
|
||||
#define TK_NMATCH 206
|
||||
#define TK_CONTAINS 207
|
||||
#define TK_JOIN 208
|
||||
#define TK_INNER 209
|
||||
#define TK_SELECT 210
|
||||
#define TK_DISTINCT 211
|
||||
#define TK_WHERE 212
|
||||
#define TK_PARTITION 213
|
||||
#define TK_BY 214
|
||||
#define TK_SESSION 215
|
||||
#define TK_STATE_WINDOW 216
|
||||
#define TK_SLIDING 217
|
||||
#define TK_FILL 218
|
||||
#define TK_VALUE 219
|
||||
#define TK_NONE 220
|
||||
#define TK_PREV 221
|
||||
#define TK_LINEAR 222
|
||||
#define TK_NEXT 223
|
||||
#define TK_HAVING 224
|
||||
#define TK_ORDER 225
|
||||
#define TK_SLIMIT 226
|
||||
#define TK_SOFFSET 227
|
||||
#define TK_LIMIT 228
|
||||
#define TK_OFFSET 229
|
||||
#define TK_ASC 230
|
||||
#define TK_NULLS 231
|
||||
#define TK_ID 232
|
||||
#define TK_NK_BITNOT 233
|
||||
#define TK_INSERT 234
|
||||
#define TK_VALUES 235
|
||||
#define TK_IMPORT 236
|
||||
#define TK_NK_SEMI 237
|
||||
#define TK_FILE 238
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
|
|
@ -21,13 +21,13 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "query.h"
|
||||
#include "tname.h"
|
||||
#include "tcommon.h"
|
||||
#include "taosdef.h"
|
||||
#include "tarray.h"
|
||||
#include "tcommon.h"
|
||||
#include "thash.h"
|
||||
#include "tmsg.h"
|
||||
#include "tname.h"
|
||||
#include "transport.h"
|
||||
|
||||
typedef struct SCatalog SCatalog;
|
||||
|
@ -59,28 +59,35 @@ typedef struct SDbInfo {
|
|||
} SDbInfo;
|
||||
|
||||
typedef struct SCatalogReq {
|
||||
SArray *pDbVgroup; // element is db full name
|
||||
SArray *pDbCfg; // element is db full name
|
||||
SArray *pDbInfo; // element is db full name
|
||||
SArray *pTableMeta; // element is SNAME
|
||||
SArray *pTableHash; // element is SNAME
|
||||
SArray *pUdf; // element is udf name
|
||||
SArray *pIndex; // element is index name
|
||||
SArray *pUser; // element is SUserAuthInfo
|
||||
SArray* pDbVgroup; // element is db full name
|
||||
SArray* pDbCfg; // element is db full name
|
||||
SArray* pDbInfo; // element is db full name
|
||||
SArray* pTableMeta; // element is SNAME
|
||||
SArray* pTableHash; // element is SNAME
|
||||
SArray* pUdf; // element is udf name
|
||||
SArray* pIndex; // element is index name
|
||||
SArray* pUser; // element is SUserAuthInfo
|
||||
SArray* pTableIndex; // element is SNAME
|
||||
bool qNodeRequired; // valid qnode
|
||||
bool forceUpdate;
|
||||
} SCatalogReq;
|
||||
|
||||
typedef struct SMetaRes {
|
||||
int32_t code;
|
||||
void* pRes;
|
||||
} SMetaRes;
|
||||
|
||||
typedef struct SMetaData {
|
||||
SArray *pDbVgroup; // SArray<SArray<SVgroupInfo>*>
|
||||
SArray *pDbCfg; // SArray<SDbCfgInfo>
|
||||
SArray *pDbInfo; // SArray<SDbInfo>
|
||||
SArray *pTableMeta; // SArray<STableMeta*>
|
||||
SArray *pTableHash; // SArray<SVgroupInfo>
|
||||
SArray *pUdfList; // SArray<SFuncInfo>
|
||||
SArray *pIndex; // SArray<SIndexInfo>
|
||||
SArray *pUser; // SArray<bool>
|
||||
SArray *pQnodeList; // SArray<SQueryNodeAddr>
|
||||
SArray* pDbVgroup; // pRes = SArray<SVgroupInfo>*
|
||||
SArray* pDbCfg; // pRes = SDbCfgInfo*
|
||||
SArray* pDbInfo; // pRes = SDbInfo*
|
||||
SArray* pTableMeta; // pRes = STableMeta*
|
||||
SArray* pTableHash; // pRes = SVgroupInfo*
|
||||
SArray* pTableIndex; // pRes = SArray<STableIndexInfo>*
|
||||
SArray* pUdfList; // pRes = SFuncInfo*
|
||||
SArray* pIndex; // pRes = SIndexInfo*
|
||||
SArray* pUser; // pRes = bool*
|
||||
SArray* pQnodeList; // pRes = SQueryNodeAddr*
|
||||
} SMetaData;
|
||||
|
||||
typedef struct SCatalogCfg {
|
||||
|
@ -123,7 +130,7 @@ typedef SUserIndexRsp SIndexInfo;
|
|||
|
||||
typedef void (*catalogCallback)(SMetaData* pResult, void* param, int32_t code);
|
||||
|
||||
int32_t catalogInit(SCatalogCfg *cfg);
|
||||
int32_t catalogInit(SCatalogCfg* cfg);
|
||||
|
||||
/**
|
||||
* Get a cluster's catalog handle for all later operations.
|
||||
|
@ -141,7 +148,7 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle);
|
|||
*/
|
||||
void catalogFreeHandle(SCatalog* pCatalog);
|
||||
|
||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum);
|
||||
int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t* tableNum);
|
||||
|
||||
/**
|
||||
* Get a DB's all vgroup info.
|
||||
|
@ -152,7 +159,8 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers
|
|||
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetDBVgInfo(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, SArray** pVgroupList);
|
||||
int32_t catalogGetDBVgInfo(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps, const char* pDBName,
|
||||
SArray** pVgroupList);
|
||||
|
||||
int32_t catalogUpdateDBVgInfo(SCatalog* pCatalog, const char* dbName, uint64_t dbId, SDBVgInfo* dbInfo);
|
||||
|
||||
|
@ -171,7 +179,8 @@ int32_t catalogRemoveStbMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId,
|
|||
* @param pTableMeta(output, table meta data, NEED to free it by calller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
int32_t catalogGetTableMeta(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps, const SName* pTableName,
|
||||
STableMeta** pTableMeta);
|
||||
|
||||
/**
|
||||
* Get a super table's meta data.
|
||||
|
@ -182,10 +191,10 @@ int32_t catalogGetTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSe
|
|||
* @param pTableMeta(output, table meta data, NEED to free it by calller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetSTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp *rspMsg);
|
||||
int32_t catalogGetSTableMeta(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps, const SName* pTableName,
|
||||
STableMeta** pTableMeta);
|
||||
|
||||
int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp* rspMsg);
|
||||
|
||||
/**
|
||||
* Force refresh DB's local cached vgroup info.
|
||||
|
@ -195,9 +204,9 @@ int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp *rspMsg);
|
|||
* @param dbFName (input, db full name)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRefreshDBVgInfo(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const char* dbFName);
|
||||
int32_t catalogRefreshDBVgInfo(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmtEps, const char* dbFName);
|
||||
|
||||
int32_t catalogChkTbMetaVersion(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, SArray* pTables);
|
||||
int32_t catalogChkTbMetaVersion(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmtEps, SArray* pTables);
|
||||
|
||||
/**
|
||||
* Force refresh a table's local cached meta data.
|
||||
|
@ -208,7 +217,8 @@ int32_t catalogChkTbMetaVersion(SCatalog* pCtg, void *pTrans, const SEpSet* pMgm
|
|||
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRefreshTableMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable);
|
||||
int32_t catalogRefreshTableMeta(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps, const SName* pTableName,
|
||||
int32_t isSTable);
|
||||
|
||||
/**
|
||||
* Force refresh a table's local cached meta data and get the new one.
|
||||
|
@ -220,9 +230,8 @@ int32_t catalogRefreshTableMeta(SCatalog* pCatalog, void *pTransporter, const SE
|
|||
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRefreshGetTableMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);
|
||||
|
||||
|
||||
int32_t catalogRefreshGetTableMeta(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps,
|
||||
const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);
|
||||
|
||||
/**
|
||||
* Get a table's actual vgroup, for stable it's all possible vgroup list.
|
||||
|
@ -233,7 +242,8 @@ int32_t catalogRefreshGetTableMeta(SCatalog* pCatalog, void *pTransporter, const
|
|||
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetTableDistVgInfo(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
|
||||
int32_t catalogGetTableDistVgInfo(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps,
|
||||
const SName* pTableName, SArray** pVgroupList);
|
||||
|
||||
/**
|
||||
* Get a table's vgroup from its name's hash value.
|
||||
|
@ -244,8 +254,8 @@ int32_t catalogGetTableDistVgInfo(SCatalog* pCatalog, void *pTransporter, const
|
|||
* @param vgInfo (output, vgroup info)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetTableHashVgroup(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pName, SVgroupInfo* vgInfo);
|
||||
|
||||
int32_t catalogGetTableHashVgroup(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps, const SName* pName,
|
||||
SVgroupInfo* vgInfo);
|
||||
|
||||
/**
|
||||
* Get all meta data required in pReq.
|
||||
|
@ -256,33 +266,38 @@ int32_t catalogGetTableHashVgroup(SCatalog* pCatalog, void * pTransporter, const
|
|||
* @param pRsp (output, response data)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetAllMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
|
||||
int32_t catalogGetAllMeta(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq,
|
||||
SMetaData* pRsp);
|
||||
|
||||
int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param, int64_t* jobId);
|
||||
int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmtEps, uint64_t reqId,
|
||||
const SCatalogReq* pReq, catalogCallback fp, void* param, int64_t* jobId);
|
||||
|
||||
int32_t catalogGetQnodeList(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList);
|
||||
int32_t catalogGetQnodeList(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList);
|
||||
|
||||
int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableMetaVersion **stables, uint32_t *num);
|
||||
int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableMetaVersion** stables, uint32_t* num);
|
||||
|
||||
int32_t catalogGetExpiredDBs(SCatalog* pCatalog, SDbVgVersion **dbs, uint32_t *num);
|
||||
int32_t catalogGetExpiredDBs(SCatalog* pCatalog, SDbVgVersion** dbs, uint32_t* num);
|
||||
|
||||
int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion **users, uint32_t *num);
|
||||
int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion** users, uint32_t* num);
|
||||
|
||||
int32_t catalogGetDBCfg(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SDbCfgInfo* pDbCfg);
|
||||
int32_t catalogGetDBCfg(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* dbFName, SDbCfgInfo* pDbCfg);
|
||||
|
||||
int32_t catalogGetIndexMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* indexName, SIndexInfo* pInfo);
|
||||
int32_t catalogGetIndexMeta(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* indexName,
|
||||
SIndexInfo* pInfo);
|
||||
|
||||
int32_t catalogGetUdfInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* funcName, SFuncInfo* pInfo);
|
||||
int32_t catalogGetTableIndex(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmtEps, const SName* pTableName,
|
||||
SArray** pRes);
|
||||
|
||||
int32_t catalogChkAuth(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* user, const char* dbFName, AUTH_TYPE type, bool *pass);
|
||||
int32_t catalogGetUdfInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* funcName, SFuncInfo* pInfo);
|
||||
|
||||
int32_t catalogChkAuth(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* user, const char* dbFName,
|
||||
AUTH_TYPE type, bool* pass);
|
||||
|
||||
int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth);
|
||||
|
||||
int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet *epSet);
|
||||
|
||||
|
||||
int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, uint64_t reqId, bool forceUpdate);
|
||||
int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet* epSet);
|
||||
|
||||
int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmtEps, uint64_t reqId, bool forceUpdate);
|
||||
|
||||
/**
|
||||
* Destroy catalog and relase all resources
|
||||
|
|
|
@ -58,7 +58,6 @@ typedef struct SFileBlockInfo {
|
|||
int32_t numBlocksOfStep;
|
||||
} SFileBlockInfo;
|
||||
|
||||
#define TSDB_BLOCK_DIST_STEP_ROWS 8
|
||||
#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results
|
||||
|
||||
#define TOP_BOTTOM_QUERY_LIMIT 100
|
||||
|
@ -146,6 +145,7 @@ typedef struct SqlFunctionCtx {
|
|||
struct SDiskbasedBuf *pBuf;
|
||||
struct SSDataBlock *pSrcBlock;
|
||||
int32_t curBufPage;
|
||||
bool increase;
|
||||
|
||||
char udfName[TSDB_FUNC_NAME_LEN];
|
||||
} SqlFunctionCtx;
|
||||
|
@ -197,6 +197,7 @@ typedef struct SAggFunctionInfo {
|
|||
struct SScalarParam {
|
||||
SColumnInfoData *columnData;
|
||||
SHashObj *pHashFilter;
|
||||
int32_t hashValueType;
|
||||
void *param; // other parameter, such as meta handle from vnode, to extract table name/tag value
|
||||
int32_t numOfRows;
|
||||
};
|
||||
|
|
|
@ -121,6 +121,19 @@ typedef enum EFunctionType {
|
|||
|
||||
// internal function
|
||||
FUNCTION_TYPE_SELECT_VALUE,
|
||||
FUNCTION_TYPE_BLOCK_DIST, // block distribution aggregate function
|
||||
|
||||
// distributed splitting functions
|
||||
FUNCTION_TYPE_APERCENTILE_PARTIAL,
|
||||
FUNCTION_TYPE_APERCENTILE_MERGE,
|
||||
FUNCTION_TYPE_SPREAD_PARTIAL,
|
||||
FUNCTION_TYPE_SPREAD_MERGE,
|
||||
FUNCTION_TYPE_HISTOGRAM_PARTIAL,
|
||||
FUNCTION_TYPE_HISTOGRAM_MERGE,
|
||||
FUNCTION_TYPE_HYPERLOGLOG_PARTIAL,
|
||||
FUNCTION_TYPE_HYPERLOGLOG_MERGE,
|
||||
FUNCTION_TYPE_ELAPSED_PARTIAL,
|
||||
FUNCTION_TYPE_ELAPSED_MERGE,
|
||||
|
||||
// user defined funcion
|
||||
FUNCTION_TYPE_UDF = 10000
|
||||
|
@ -157,6 +170,7 @@ bool fmIsMultiResFunc(int32_t funcId);
|
|||
bool fmIsRepeatScanFunc(int32_t funcId);
|
||||
bool fmIsUserDefinedFunc(int32_t funcId);
|
||||
bool fmIsDistExecFunc(int32_t funcId);
|
||||
bool fmIsForbidFillFunc(int32_t funcId);
|
||||
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
|
||||
|
||||
|
|
|
@ -136,14 +136,14 @@ int indexRebuild(SIndex* index, SIndexOpts* opt);
|
|||
* @param index (output, index json object)
|
||||
* @return error code
|
||||
*/
|
||||
int tIndexJsonOpen(SIndexJsonOpts* opts, const char* path, SIndexJson** index);
|
||||
int indexJsonOpen(SIndexJsonOpts* opts, const char* path, SIndexJson** index);
|
||||
/*
|
||||
* close index
|
||||
* @param index (input, index to be closed)
|
||||
* @return void
|
||||
*/
|
||||
|
||||
void tIndexJsonClose(SIndexJson* index);
|
||||
void indexJsonClose(SIndexJson* index);
|
||||
|
||||
/*
|
||||
* insert terms into index
|
||||
|
@ -152,7 +152,7 @@ void tIndexJsonClose(SIndexJson* index);
|
|||
* @param uid (input, uid of terms)
|
||||
* @return error code
|
||||
*/
|
||||
int tIndexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
|
||||
int indexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
|
||||
/*
|
||||
* search index
|
||||
* @param index (input, index object)
|
||||
|
@ -161,7 +161,7 @@ int tIndexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid);
|
|||
* @return error code
|
||||
*/
|
||||
|
||||
int tIndexJsonSearch(SIndexJson* index, SIndexJsonMultiTermQuery* query, SArray* result);
|
||||
int indexJsonSearch(SIndexJson* index, SIndexJsonMultiTermQuery* query, SArray* result);
|
||||
/*
|
||||
* @param
|
||||
* @param
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef struct SDatabaseOptions {
|
|||
int32_t maxRowsPerBlock;
|
||||
int32_t minRowsPerBlock;
|
||||
SNodeList* pKeep;
|
||||
int32_t keep[3];
|
||||
int64_t keep[3];
|
||||
int32_t pages;
|
||||
int32_t pagesize;
|
||||
char precisionStr[3];
|
||||
|
|
|
@ -207,8 +207,8 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_PROJECT,
|
||||
QUERY_NODE_PHYSICAL_PLAN_JOIN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_AGG,
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
|
||||
QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SORT,
|
||||
|
@ -218,11 +218,11 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_FILL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION_WINDOW,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW,
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION,
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE,
|
||||
QUERY_NODE_PHYSICAL_PLAN_PARTITION,
|
||||
QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
|
||||
QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
|
||||
|
|
|
@ -62,6 +62,7 @@ typedef struct SScanLogicNode {
|
|||
int64_t watermark;
|
||||
int16_t tsColId;
|
||||
double filesFactor;
|
||||
SArray* pSmaIndexes;
|
||||
} SScanLogicNode;
|
||||
|
||||
typedef struct SJoinLogicNode {
|
||||
|
@ -304,6 +305,7 @@ typedef struct SDownstreamSourceNode {
|
|||
typedef struct SExchangePhysiNode {
|
||||
SPhysiNode node;
|
||||
int32_t srcGroupId; // group id of datasource suplans
|
||||
bool singleChannel;
|
||||
SNodeList* pSrcEndPoints; // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
|
||||
} SExchangePhysiNode;
|
||||
|
||||
|
@ -436,7 +438,6 @@ typedef struct SQueryPlan {
|
|||
int32_t numOfSubplans;
|
||||
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
|
||||
SExplainInfo explainInfo;
|
||||
SArray* pPlaceholderValues;
|
||||
} SQueryPlan;
|
||||
|
||||
void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext);
|
||||
|
|
|
@ -144,6 +144,7 @@ typedef struct SRealTableNode {
|
|||
SVgroupsInfo* pVgroupList;
|
||||
char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES
|
||||
double ratio;
|
||||
SArray* pSmaIndexes;
|
||||
} SRealTableNode;
|
||||
|
||||
typedef struct STempTableNode {
|
||||
|
|
|
@ -63,7 +63,7 @@ int32_t qAnalyseSqlSemantic(SParseContext* pCxt, const struct SCatalogReq* pCata
|
|||
void qDestroyQuery(SQuery* pQueryNode);
|
||||
|
||||
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
|
||||
int32_t qSetSTableIdForRSma(SNode* pStmt, int64_t uid);
|
||||
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
|
||||
|
||||
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
|
||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf);
|
||||
|
|
|
@ -210,8 +210,8 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
|||
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST || \
|
||||
(_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \
|
||||
(_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code == TSDB_CODE_PAR_VALUE_TOO_LONG) || \
|
||||
(_code == TSDB_CODE_PAR_INVALID_DROP_COL))
|
||||
(_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code) == TSDB_CODE_PAR_VALUE_TOO_LONG || \
|
||||
(_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID))
|
||||
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
|
||||
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED)
|
||||
|
|
|
@ -131,14 +131,7 @@ static FORCE_INLINE void* streamQueueNextItem(SStreamQueue* queue) {
|
|||
|
||||
SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq);
|
||||
|
||||
static FORCE_INLINE void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit) {
|
||||
int32_t ref = atomic_sub_fetch_32(pDataSubmit->dataRef, 1);
|
||||
ASSERT(ref >= 0);
|
||||
if (ref == 0) {
|
||||
taosMemoryFree(pDataSubmit->data);
|
||||
taosMemoryFree(pDataSubmit->dataRef);
|
||||
}
|
||||
}
|
||||
void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit);
|
||||
|
||||
SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit);
|
||||
|
||||
|
@ -148,7 +141,6 @@ void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput);
|
|||
#endif
|
||||
|
||||
typedef struct {
|
||||
int8_t parallelizable;
|
||||
char* qmsg;
|
||||
// followings are not applicable to encoder and decoder
|
||||
void* inputHandle;
|
||||
|
@ -189,6 +181,7 @@ typedef void FSmaSink(void* vnode, int64_t smaId, const SArray* data);
|
|||
typedef struct {
|
||||
int64_t smaId;
|
||||
// following are not applicable to encoder and decoder
|
||||
void* vnode;
|
||||
FSmaSink* smaSink;
|
||||
} STaskSinkSma;
|
||||
|
||||
|
@ -270,10 +263,10 @@ struct SStreamTask {
|
|||
SStreamQueue* outputQueue;
|
||||
|
||||
// application storage
|
||||
void* ahandle;
|
||||
// void* ahandle;
|
||||
};
|
||||
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId, int32_t childId);
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId);
|
||||
int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||
void tFreeSStreamTask(SStreamTask* pTask);
|
||||
|
@ -311,7 +304,18 @@ static FORCE_INLINE void streamTaskInputFail(SStreamTask* pTask) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBlock* pBlock) {
|
||||
if (pTask->sinkType == TASK_SINK__TABLE) {
|
||||
ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE);
|
||||
pTask->tbSink.tbSinkFunc(pTask, pTask->tbSink.vnode, 0, pBlock->blocks);
|
||||
taosFreeQitem(pBlock);
|
||||
} else if (pTask->sinkType == TASK_SINK__SMA) {
|
||||
ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE);
|
||||
pTask->smaSink.smaSink(pTask->smaSink.vnode, pTask->smaSink.smaId, pBlock->blocks);
|
||||
taosFreeQitem(pBlock);
|
||||
} else {
|
||||
ASSERT(pTask->dispatchType != TASK_DISPATCH__NONE);
|
||||
taosWriteQitem(pTask->outputQueue->queue, pBlock);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -319,26 +323,11 @@ typedef struct {
|
|||
int32_t reserved;
|
||||
} SStreamTaskDeployRsp;
|
||||
|
||||
typedef struct {
|
||||
// SMsgHead head;
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
SArray* data; // SArray<SSDataBlock>
|
||||
} SStreamTaskExecReq;
|
||||
|
||||
typedef struct {
|
||||
// SMsgHead head;
|
||||
SStreamTask* task;
|
||||
} SStreamTaskDeployReq;
|
||||
|
||||
int32_t tEncodeSStreamTaskExecReq(void** buf, const SStreamTaskExecReq* pReq);
|
||||
void* tDecodeSStreamTaskExecReq(const void* buf, SStreamTaskExecReq* pReq);
|
||||
void tFreeSStreamTaskExecReq(SStreamTaskExecReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t reserved;
|
||||
} SStreamTaskExecRsp;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
int64_t streamId;
|
||||
|
@ -351,6 +340,7 @@ typedef struct {
|
|||
int32_t sourceTaskId;
|
||||
int32_t sourceVg;
|
||||
int32_t sourceChildId;
|
||||
int32_t upstreamNodeId;
|
||||
#if 0
|
||||
int64_t sourceVer;
|
||||
#endif
|
||||
|
|
|
@ -48,6 +48,7 @@ typedef enum {
|
|||
TAOS_SYNC_PROPOSE_SUCCESS = 0,
|
||||
TAOS_SYNC_PROPOSE_NOT_LEADER = 1,
|
||||
TAOS_SYNC_PROPOSE_OTHER_ERROR = 2,
|
||||
TAOS_SYNC_ONLY_ONE_REPLICA = 3,
|
||||
} ESyncProposeCode;
|
||||
|
||||
typedef enum {
|
||||
|
@ -83,16 +84,23 @@ typedef struct SReConfigCbMeta {
|
|||
SyncTerm term;
|
||||
SyncTerm currentTerm;
|
||||
SSyncCfg oldCfg;
|
||||
SSyncCfg newCfg;
|
||||
bool isDrop;
|
||||
uint64_t flag;
|
||||
uint64_t seqNum;
|
||||
} SReConfigCbMeta;
|
||||
|
||||
typedef struct SSnapshot {
|
||||
void *data;
|
||||
void* data;
|
||||
SyncIndex lastApplyIndex;
|
||||
SyncTerm lastApplyTerm;
|
||||
SyncIndex lastConfigIndex;
|
||||
} SSnapshot;
|
||||
|
||||
typedef struct SSnapshotMeta {
|
||||
SyncIndex lastConfigIndex;
|
||||
} SSnapshotMeta;
|
||||
|
||||
typedef struct SSyncFSM {
|
||||
void* data;
|
||||
|
||||
|
@ -101,7 +109,7 @@ typedef struct SSyncFSM {
|
|||
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
|
||||
void (*FpRestoreFinishCb)(struct SSyncFSM* pFsm);
|
||||
void (*FpReConfigCb)(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta);
|
||||
void (*FpReConfigCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta);
|
||||
|
||||
int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
||||
|
||||
|
@ -141,10 +149,28 @@ typedef struct SSyncLogStore {
|
|||
// return commit index of log
|
||||
SyncIndex (*getCommitIndex)(struct SSyncLogStore* pLogStore);
|
||||
|
||||
// refactor, log[0 .. n] ==> log[m .. n]
|
||||
int32_t (*syncLogSetBeginIndex)(struct SSyncLogStore* pLogStore, SyncIndex beginIndex);
|
||||
int32_t (*syncLogResetBeginIndex)(struct SSyncLogStore* pLogStore);
|
||||
SyncIndex (*syncLogBeginIndex)(struct SSyncLogStore* pLogStore);
|
||||
SyncIndex (*syncLogEndIndex)(struct SSyncLogStore* pLogStore);
|
||||
bool (*syncLogIsEmpty)(struct SSyncLogStore* pLogStore);
|
||||
int32_t (*syncLogEntryCount)(struct SSyncLogStore* pLogStore);
|
||||
bool (*syncLogInRange)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
||||
|
||||
SyncIndex (*syncLogWriteIndex)(struct SSyncLogStore* pLogStore);
|
||||
SyncIndex (*syncLogLastIndex)(struct SSyncLogStore* pLogStore);
|
||||
SyncTerm (*syncLogLastTerm)(struct SSyncLogStore* pLogStore);
|
||||
|
||||
int32_t (*syncLogAppendEntry)(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
||||
int32_t (*syncLogGetEntry)(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||
int32_t (*syncLogTruncate)(struct SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
||||
|
||||
} SSyncLogStore;
|
||||
|
||||
typedef struct SSyncInfo {
|
||||
bool isStandBy;
|
||||
bool snapshotEnable;
|
||||
SyncGroupId vgId;
|
||||
SSyncCfg syncCfg;
|
||||
char path[TSDB_FILENAME_LEN];
|
||||
|
@ -161,7 +187,6 @@ int64_t syncOpen(const SSyncInfo* pSyncInfo);
|
|||
void syncStart(int64_t rid);
|
||||
void syncStop(int64_t rid);
|
||||
int32_t syncSetStandby(int64_t rid);
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg);
|
||||
ESyncState syncGetMyRole(int64_t rid);
|
||||
const char* syncGetMyRoleStr(int64_t rid);
|
||||
SyncTerm syncGetMyTerm(int64_t rid);
|
||||
|
@ -171,6 +196,13 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
|
|||
bool syncEnvIsStart();
|
||||
const char* syncStr(ESyncState state);
|
||||
bool syncIsRestoreFinish(int64_t rid);
|
||||
int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
|
||||
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg);
|
||||
int32_t syncReconfigRaw(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg);
|
||||
|
||||
int32_t syncLeaderTransfer(int64_t rid);
|
||||
int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader);
|
||||
|
||||
// to be moved to static
|
||||
void syncStartNormal(int64_t rid);
|
||||
|
|
|
@ -33,7 +33,7 @@ SSyncNode* syncNodeAcquire(int64_t rid);
|
|||
void syncNodeRelease(SSyncNode* pNode);
|
||||
|
||||
int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg);
|
||||
int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg);
|
||||
int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo);
|
||||
void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb);
|
||||
char* sync2SimpleStr(int64_t rid);
|
||||
|
||||
|
@ -301,6 +301,7 @@ typedef struct SyncAppendEntries {
|
|||
SyncIndex prevLogIndex;
|
||||
SyncTerm prevLogTerm;
|
||||
SyncIndex commitIndex;
|
||||
SyncTerm privateTerm;
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncAppendEntries;
|
||||
|
@ -332,6 +333,7 @@ typedef struct SyncAppendEntriesReply {
|
|||
SRaftId destId;
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncTerm privateTerm;
|
||||
bool success;
|
||||
SyncIndex matchIndex;
|
||||
} SyncAppendEntriesReply;
|
||||
|
@ -385,6 +387,107 @@ void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg);
|
|||
void syncApplyMsgLog(const SyncApplyMsg* pMsg);
|
||||
void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncSnapshotSend {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
SyncTerm term;
|
||||
SyncIndex lastIndex; // lastIndex of snapshot
|
||||
SyncTerm lastTerm; // lastTerm of snapshot
|
||||
SyncIndex lastConfigIndex;
|
||||
SSyncCfg lastConfig;
|
||||
SyncTerm privateTerm;
|
||||
int32_t seq;
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncSnapshotSend;
|
||||
|
||||
SyncSnapshotSend* syncSnapshotSendBuild(uint32_t dataLen, int32_t vgId);
|
||||
void syncSnapshotSendDestroy(SyncSnapshotSend* pMsg);
|
||||
void syncSnapshotSendSerialize(const SyncSnapshotSend* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncSnapshotSendDeserialize(const char* buf, uint32_t len, SyncSnapshotSend* pMsg);
|
||||
char* syncSnapshotSendSerialize2(const SyncSnapshotSend* pMsg, uint32_t* len);
|
||||
SyncSnapshotSend* syncSnapshotSendDeserialize2(const char* buf, uint32_t len);
|
||||
void syncSnapshotSend2RpcMsg(const SyncSnapshotSend* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncSnapshotSendFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotSend* pMsg);
|
||||
SyncSnapshotSend* syncSnapshotSendFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg);
|
||||
char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg);
|
||||
void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg);
|
||||
void syncSnapshotSendLog(const SyncSnapshotSend* pMsg);
|
||||
void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncSnapshotRsp {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
SyncTerm term;
|
||||
SyncIndex lastIndex;
|
||||
SyncTerm lastTerm;
|
||||
SyncTerm privateTerm;
|
||||
int32_t ack;
|
||||
int32_t code;
|
||||
} SyncSnapshotRsp;
|
||||
|
||||
SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId);
|
||||
void syncSnapshotRspDestroy(SyncSnapshotRsp* pMsg);
|
||||
void syncSnapshotRspSerialize(const SyncSnapshotRsp* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncSnapshotRspDeserialize(const char* buf, uint32_t len, SyncSnapshotRsp* pMsg);
|
||||
char* syncSnapshotRspSerialize2(const SyncSnapshotRsp* pMsg, uint32_t* len);
|
||||
SyncSnapshotRsp* syncSnapshotRspDeserialize2(const char* buf, uint32_t len);
|
||||
void syncSnapshotRsp2RpcMsg(const SyncSnapshotRsp* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncSnapshotRspFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotRsp* pMsg);
|
||||
SyncSnapshotRsp* syncSnapshotRspFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg);
|
||||
char* syncSnapshotRsp2Str(const SyncSnapshotRsp* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncSnapshotRspPrint(const SyncSnapshotRsp* pMsg);
|
||||
void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg);
|
||||
void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg);
|
||||
void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncLeaderTransfer {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
/*
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
*/
|
||||
SRaftId newLeaderId;
|
||||
} SyncLeaderTransfer;
|
||||
|
||||
SyncLeaderTransfer* syncLeaderTransferBuild(int32_t vgId);
|
||||
void syncLeaderTransferDestroy(SyncLeaderTransfer* pMsg);
|
||||
void syncLeaderTransferSerialize(const SyncLeaderTransfer* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncLeaderTransferDeserialize(const char* buf, uint32_t len, SyncLeaderTransfer* pMsg);
|
||||
char* syncLeaderTransferSerialize2(const SyncLeaderTransfer* pMsg, uint32_t* len);
|
||||
SyncLeaderTransfer* syncLeaderTransferDeserialize2(const char* buf, uint32_t len);
|
||||
void syncLeaderTransfer2RpcMsg(const SyncLeaderTransfer* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncLeaderTransferFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLeaderTransfer* pMsg);
|
||||
SyncLeaderTransfer* syncLeaderTransferFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg);
|
||||
char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg);
|
||||
void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg);
|
||||
void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg);
|
||||
void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg);
|
||||
|
||||
// on message ----------------------
|
||||
int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg);
|
||||
int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
|
@ -395,6 +498,29 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg)
|
|||
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||
int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||
int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||
int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||
int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnSnapshotSendCb(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
||||
int32_t syncNodeOnSnapshotRspCb(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||
|
||||
// -----------------------------------------
|
||||
typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg);
|
||||
typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
typedef int32_t (*FpOnClientRequestCb)(SSyncNode* ths, SyncClientRequest* pMsg);
|
||||
typedef int32_t (*FpOnRequestVoteCb)(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||
typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||
typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||
typedef int32_t (*FpOnAppendEntriesReplyCb)(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||
typedef int32_t (*FpOnTimeoutCb)(SSyncNode* pSyncNode, SyncTimeout* pMsg);
|
||||
typedef int32_t (*FpOnSnapshotSendCb)(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
||||
typedef int32_t (*FpOnSnapshotRspCb)(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||
|
||||
// option ----------------------------------
|
||||
bool syncNodeSnapshotEnable(SSyncNode* pSyncNode);
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -33,7 +33,10 @@ extern int32_t tsRpcHeadSize;
|
|||
typedef struct {
|
||||
uint32_t clientIp;
|
||||
uint16_t clientPort;
|
||||
union {
|
||||
char user[TSDB_USER_LEN];
|
||||
int64_t applyIndex;
|
||||
};
|
||||
} SRpcConnInfo;
|
||||
|
||||
typedef struct SRpcHandleInfo {
|
||||
|
@ -43,6 +46,7 @@ typedef struct SRpcHandleInfo {
|
|||
int32_t noResp; // has response or not(default 0, 0: resp, 1: no resp);
|
||||
int32_t persistHandle; // persist handle or not
|
||||
|
||||
SRpcConnInfo connInfo;
|
||||
// app info
|
||||
void *ahandle; // app handle set by client
|
||||
void *wrapper; // wrapper handle
|
||||
|
|
|
@ -141,6 +141,8 @@ typedef struct SWal {
|
|||
// ctl
|
||||
int64_t refId;
|
||||
TdThreadMutex mutex;
|
||||
// ref
|
||||
SHashObj *pRefHash; // ref -> SWalRef
|
||||
// path
|
||||
char path[WAL_PATH_LEN];
|
||||
// reusable write head
|
||||
|
@ -184,7 +186,7 @@ int32_t walRollback(SWal *, int64_t ver);
|
|||
// notify that previous logs can be pruned safely
|
||||
int32_t walBeginSnapshot(SWal *, int64_t ver);
|
||||
int32_t walEndSnapshot(SWal *);
|
||||
void walRestoreFromSnapshot(SWal *, int64_t ver);
|
||||
int32_t walRestoreFromSnapshot(SWal *, int64_t ver);
|
||||
// int32_t walDataCorrupted(SWal*);
|
||||
|
||||
// read
|
||||
|
@ -199,6 +201,16 @@ int32_t walFetchHead(SWalReadHandle *pRead, int64_t ver, SWalHead *pHead);
|
|||
int32_t walFetchBody(SWalReadHandle *pRead, SWalHead **ppHead);
|
||||
int32_t walSkipFetchBody(SWalReadHandle *pRead, const SWalHead *pHead);
|
||||
|
||||
typedef struct {
|
||||
int64_t refId;
|
||||
int64_t ver;
|
||||
} SWalRef;
|
||||
|
||||
SWalRef *walOpenRef(SWal *);
|
||||
void walCloseRef(SWalRef *);
|
||||
int32_t walRefVer(SWalRef *, int64_t ver);
|
||||
int32_t walUnrefVer(SWal *);
|
||||
|
||||
// deprecated
|
||||
#if 0
|
||||
int32_t walRead(SWal *, SWalHead **, int64_t ver);
|
||||
|
|
|
@ -65,7 +65,7 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __
|
|||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t fn, int32_t flags);
|
||||
void *taosbsearch(const void *key, const void *base, int32_t nmemb, int32_t size, __compar_fn_t compar, int32_t flags);
|
||||
|
||||
/**
|
||||
* adjust heap
|
||||
|
@ -82,7 +82,7 @@ void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size
|
|||
* @return
|
||||
*/
|
||||
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar,
|
||||
__ext_compar_fn_t compar, char* buf, bool maxroot);
|
||||
__ext_compar_fn_t compar, char *buf, bool maxroot);
|
||||
|
||||
/**
|
||||
* sort heap to make sure it is a max/min root heap
|
||||
|
@ -97,8 +97,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
|
|||
* @param maxroot: if heap is max root heap
|
||||
* @return
|
||||
*/
|
||||
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar,
|
||||
bool maxroot);
|
||||
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, bool maxroot);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -85,7 +85,6 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_RPC_NETWORK_UNAVAIL TAOS_DEF_ERROR_CODE(0, 0x0102)
|
||||
#define TSDB_CODE_RPC_FQDN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0103)
|
||||
#define TSDB_CODE_RPC_PORT_EADDRINUSE TAOS_DEF_ERROR_CODE(0, 0x0104)
|
||||
#define TSDB_CODE_RPC_INDIRECT_NETWORK_UNAVAIL TAOS_DEF_ERROR_CODE(0, 0x0105)
|
||||
|
||||
//client
|
||||
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
|
||||
|
@ -220,6 +219,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392)
|
||||
#define TSDB_CODE_MND_VGROUP_UN_CHANGED TAOS_DEF_ERROR_CODE(0, 0x0393)
|
||||
#define TSDB_CODE_MND_HAS_OFFLINE_DNODE TAOS_DEF_ERROR_CODE(0, 0x0394)
|
||||
#define TSDB_CODE_MND_INVALID_REPLICA TAOS_DEF_ERROR_CODE(0, 0x0395)
|
||||
|
||||
// mnode-stable
|
||||
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0)
|
||||
|
@ -260,6 +260,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TRANS_CONFLICT TAOS_DEF_ERROR_CODE(0, 0x03D3)
|
||||
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03D4)
|
||||
#define TSDB_CODE_MND_TRANS_CLOG_IS_NULL TAOS_DEF_ERROR_CODE(0, 0x03D5)
|
||||
#define TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL TAOS_DEF_ERROR_CODE(0, 0x03D6)
|
||||
|
||||
// mnode-mq
|
||||
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
|
||||
|
@ -339,9 +340,9 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE TAOS_DEF_ERROR_CODE(0, 0x060D)
|
||||
#define TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x060E)
|
||||
#define TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP TAOS_DEF_ERROR_CODE(0, 0x060F)
|
||||
#define TSDB_CODE_TDB_INVALID_ACTION TAOS_DEF_ERROR_CODE(0, 0x0600)
|
||||
#define TSDB_CODE_TDB_INVALID_CREATE_TB_MSG TAOS_DEF_ERROR_CODE(0, 0x0601)
|
||||
#define TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM TAOS_DEF_ERROR_CODE(0, 0x0602)
|
||||
#define TSDB_CODE_TDB_INVALID_ACTION TAOS_DEF_ERROR_CODE(0, 0x0610)
|
||||
#define TSDB_CODE_TDB_INVALID_CREATE_TB_MSG TAOS_DEF_ERROR_CODE(0, 0x0611)
|
||||
#define TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM TAOS_DEF_ERROR_CODE(0, 0x0612)
|
||||
#define TSDB_CODE_TDB_FILE_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0613)
|
||||
#define TSDB_CODE_TDB_TABLE_RECONFIGURE TAOS_DEF_ERROR_CODE(0, 0x0614)
|
||||
#define TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO TAOS_DEF_ERROR_CODE(0, 0x0615)
|
||||
|
@ -351,9 +352,6 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0619)
|
||||
#define TSDB_CODE_TDB_TABLE_RECREATED TAOS_DEF_ERROR_CODE(0, 0x061A)
|
||||
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x061B)
|
||||
#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x061C)
|
||||
#define TSDB_CODE_TDB_INVALID_SMA_STAT TAOS_DEF_ERROR_CODE(0, 0x061D)
|
||||
#define TSDB_CODE_TDB_TSMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x061E)
|
||||
|
||||
// query
|
||||
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
|
||||
|
@ -654,6 +652,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2654)
|
||||
#define TSDB_CODE_PAR_INVALID_DELETE_WHERE TAOS_DEF_ERROR_CODE(0, 0x2655)
|
||||
#define TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG TAOS_DEF_ERROR_CODE(0, 0x2656)
|
||||
#define TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x2657)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
@ -684,6 +683,19 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_SML_INVALID_DATA TAOS_DEF_ERROR_CODE(0, 0x3002)
|
||||
#define TSDB_CODE_SML_INVALID_DB_CONF TAOS_DEF_ERROR_CODE(0, 0x3003)
|
||||
|
||||
//tsma
|
||||
#define TSDB_CODE_TSMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x3100)
|
||||
#define TSDB_CODE_TSMA_NO_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x3101)
|
||||
#define TSDB_CODE_TSMA_INVALID_ENV TAOS_DEF_ERROR_CODE(0, 0x3102)
|
||||
#define TSDB_CODE_TSMA_INVALID_STAT TAOS_DEF_ERROR_CODE(0, 0x3103)
|
||||
#define TSDB_CODE_TSMA_NO_INDEX_IN_CACHE TAOS_DEF_ERROR_CODE(0, 0x3104)
|
||||
#define TSDB_CODE_TSMA_RM_SKEY_IN_HASH TAOS_DEF_ERROR_CODE(0, 0x3105)
|
||||
|
||||
//rsma
|
||||
#define TSDB_CODE_RSMA_INVALID_ENV TAOS_DEF_ERROR_CODE(0, 0x3150)
|
||||
#define TSDB_CODE_RSMA_INVALID_STAT TAOS_DEF_ERROR_CODE(0, 0x3151)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -32,7 +32,7 @@ extern "C" {
|
|||
#define TD_VER_MAX UINT64_MAX // TODO: use the real max version from query handle
|
||||
|
||||
// Bytes for each type.
|
||||
extern const int32_t TYPE_BYTES[15];
|
||||
extern const int32_t TYPE_BYTES[16];
|
||||
|
||||
// TODO: replace and remove code below
|
||||
#define CHAR_BYTES sizeof(char)
|
||||
|
@ -356,8 +356,8 @@ typedef enum ELogicConditionType {
|
|||
|
||||
#define TSDB_DEFAULT_EXPLAIN_VERBOSE false
|
||||
|
||||
#define TSDB_EXPLAIN_RESULT_ROW_SIZE 1024
|
||||
#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY PLAN"
|
||||
#define TSDB_EXPLAIN_RESULT_ROW_SIZE 512
|
||||
#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY_PLAN"
|
||||
|
||||
#define TSDB_MAX_FIELD_LEN 16384
|
||||
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define _TD_UTIL_JSON_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "tarray.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -66,12 +67,14 @@ typedef int32_t (*FToJson)(const void* pObj, SJson* pJson);
|
|||
int32_t tjsonAddObject(SJson* pJson, const char* pName, FToJson func, const void* pObj);
|
||||
int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj);
|
||||
int32_t tjsonAddArray(SJson* pJson, const char* pName, FToJson func, const void* pArray, int32_t itemSize, int32_t num);
|
||||
int32_t tjsonAddTArray(SJson* pJson, const char* pName, FToJson func, const SArray* pArray);
|
||||
|
||||
typedef int32_t (*FToObject)(const SJson* pJson, void* pObj);
|
||||
|
||||
int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, void* pObj);
|
||||
int32_t tjsonMakeObject(const SJson* pJson, const char* pName, FToObject func, void** pObj, int32_t objSize);
|
||||
int32_t tjsonToArray(const SJson* pJson, const char* pName, FToObject func, void* pArray, int32_t itemSize);
|
||||
int32_t tjsonToTArray(const SJson* pJson, const char* pName, FToObject func, SArray** pArray, int32_t itemSize);
|
||||
|
||||
char* tjsonToString(const SJson* pJson);
|
||||
char* tjsonToUnformattedString(const SJson* pJson);
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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_UTIL_LRUCACHE_H_
|
||||
#define _TD_UTIL_LRUCACHE_H_
|
||||
|
||||
#include "thash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SLRUCache SLRUCache;
|
||||
|
||||
typedef void (*_taos_lru_deleter_t)(const void *key, size_t keyLen, void *value);
|
||||
|
||||
typedef struct LRUHandle LRUHandle;
|
||||
|
||||
typedef enum {
|
||||
TAOS_LRU_PRIORITY_HIGH,
|
||||
TAOS_LRU_PRIORITY_LOW
|
||||
} LRUPriority;
|
||||
|
||||
typedef enum {
|
||||
TAOS_LRU_STATUS_OK,
|
||||
TAOS_LRU_STATUS_FAIL,
|
||||
TAOS_LRU_STATUS_INCOMPLETE,
|
||||
TAOS_LRU_STATUS_OK_OVERWRITTEN
|
||||
} LRUStatus;
|
||||
|
||||
SLRUCache *taosLRUCacheInit(size_t capacity, int numShardBits, double highPriPoolRatio);
|
||||
void taosLRUCacheCleanup(SLRUCache *cache);
|
||||
|
||||
LRUStatus taosLRUCacheInsert(SLRUCache *cache, const void *key, size_t keyLen, void *value, size_t charge,
|
||||
_taos_lru_deleter_t deleter, LRUHandle **handle, LRUPriority priority);
|
||||
LRUHandle *taosLRUCacheLookup(SLRUCache * cache, const void *key, size_t keyLen);
|
||||
void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen);
|
||||
|
||||
void taosLRUCacheEraseUnrefEntries(SLRUCache *cache);
|
||||
|
||||
bool taosLRUCacheRef(SLRUCache *cache, LRUHandle *handle);
|
||||
bool taosLRUCacheRelease(SLRUCache *cache, LRUHandle *handle, bool eraseIfLastRef);
|
||||
|
||||
void* taosLRUCacheValue(SLRUCache *cache, LRUHandle *handle);
|
||||
|
||||
size_t taosLRUCacheGetUsage(SLRUCache *cache);
|
||||
size_t taosLRUCacheGetPinnedUsage(SLRUCache *cache);
|
||||
|
||||
void taosLRUCacheSetCapacity(SLRUCache *cache, size_t capacity);
|
||||
size_t taosLRUCacheGetCapacity(SLRUCache *cache);
|
||||
|
||||
void taosLRUCacheSetStrictCapacity(SLRUCache *cache, bool strict);
|
||||
bool taosLRUCacheIsStrictCapacity(SLRUCache *cache);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _TD_UTIL_LRUCACHE_H_
|
|
@ -188,6 +188,13 @@ SDiskbasedBufStatis getDBufStatis(const SDiskbasedBuf* pBuf);
|
|||
*/
|
||||
void dBufPrintStatis(const SDiskbasedBuf* pBuf);
|
||||
|
||||
/**
|
||||
* Set all of page buffer are not need
|
||||
* @param pBuf
|
||||
* @return
|
||||
*/
|
||||
void clearDiskbasedBuf(SDiskbasedBuf* pBuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,7 +45,7 @@ extern "C" {
|
|||
|
||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||
#define HEARTBEAT_INTERVAL 1500 // ms
|
||||
#define SYNC_ON_TOP_OF_ASYNC 0
|
||||
#define SYNC_ON_TOP_OF_ASYNC 1
|
||||
|
||||
enum {
|
||||
RES_TYPE__QUERY = 1,
|
||||
|
@ -144,7 +144,7 @@ typedef struct STscObj {
|
|||
int32_t numOfReqs; // number of sqlObj bound to this connection
|
||||
SAppInstInfo* pAppInfo;
|
||||
SHashObj* pRequests;
|
||||
int8_t schemalessType;
|
||||
int8_t schemalessType; // todo remove it, this attribute should be move to request
|
||||
} STscObj;
|
||||
|
||||
typedef struct SResultColumn {
|
||||
|
@ -171,6 +171,7 @@ typedef struct SReqResultInfo {
|
|||
uint32_t current;
|
||||
bool completed;
|
||||
int32_t precision;
|
||||
bool convertUcs4;
|
||||
int32_t payloadLen;
|
||||
} SReqResultInfo;
|
||||
|
||||
|
@ -222,7 +223,7 @@ typedef struct SSyncQueryParam {
|
|||
SRequestObj* pRequest;
|
||||
} SSyncQueryParam;
|
||||
|
||||
void* doAsyncFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4);
|
||||
void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4);
|
||||
void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4);
|
||||
|
||||
void doSetOneRowPtr(SReqResultInfo* pResultInfo);
|
||||
|
|
|
@ -167,7 +167,7 @@ void *createTscObj(const char *user, const char *auth, const char *db, int32_t c
|
|||
|
||||
taosThreadMutexInit(&pObj->mutex, NULL);
|
||||
pObj->id = taosAddRef(clientConnRefPool, pObj);
|
||||
pObj->schemalessType = 0;
|
||||
pObj->schemalessType = 1;
|
||||
|
||||
tscDebug("connObj created, 0x%" PRIx64, pObj->id);
|
||||
return pObj;
|
||||
|
@ -191,6 +191,8 @@ void *createRequest(STscObj *pObj, int32_t type) {
|
|||
pRequest->requestId = generateRequestId();
|
||||
pRequest->metric.start = taosGetTimestampUs();
|
||||
|
||||
pRequest->body.resInfo.convertUcs4 = true; // convert ucs4 by default
|
||||
|
||||
pRequest->type = type;
|
||||
pRequest->pTscObj = pObj;
|
||||
pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
|
|
|
@ -580,7 +580,8 @@ void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) {
|
|||
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
if (code != TSDB_CODE_SUCCESS && NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
tscDebug("0x%"PRIx64" client retry to handle the error, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId);
|
||||
tscDebug("0x%"PRIx64" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code),
|
||||
pRequest->retry, pRequest->requestId);
|
||||
pRequest->prevCode = code;
|
||||
doAsyncQuery(pRequest, true);
|
||||
return;
|
||||
|
@ -592,6 +593,7 @@ void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) {
|
|||
pRequest->code = code;
|
||||
}
|
||||
|
||||
tscDebug("schedulerExecCb request type %s", TMSG_INFO(pRequest->type));
|
||||
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) {
|
||||
removeMeta(pTscObj, pRequest->tableList);
|
||||
}
|
||||
|
@ -687,7 +689,6 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE};
|
||||
|
||||
SAppInstInfo* pAppInfo = getAppInfo(pRequest);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = qCreateQueryPlan(&cxt, &pRequest->body.pDag, pNodeList);
|
||||
}
|
||||
|
@ -695,6 +696,9 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
schedulerAsyncExecJob(pAppInfo->pTransporter, pNodeList, pRequest->body.pDag, &pRequest->body.queryJob,
|
||||
pRequest->sqlstr, pRequest->metric.start, schedulerExecCb, pRequest);
|
||||
} else {
|
||||
tscError("0x%"PRIx64" failed to create query plan, code:%s 0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId);
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
}
|
||||
|
||||
//todo not to be released here
|
||||
|
@ -703,6 +707,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
}
|
||||
case QUERY_EXEC_MODE_EMPTY_RESULT:
|
||||
pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1109,7 +1114,7 @@ static void syncFetchFn(void* param, TAOS_RES* res, int32_t numOfRows) {
|
|||
tsem_post(&pParam->sem);
|
||||
}
|
||||
|
||||
void* doAsyncFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
|
||||
void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
|
||||
assert(pRequest != NULL);
|
||||
|
||||
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
||||
|
@ -1121,6 +1126,10 @@ void* doAsyncFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUc
|
|||
}
|
||||
|
||||
SSyncQueryParam* pParam = pRequest->body.param;
|
||||
|
||||
// convert ucs4 to native multi-bytes string
|
||||
pResultInfo->convertUcs4 = convertUcs4;
|
||||
|
||||
taos_fetch_rows_a(pRequest, syncFetchFn, pParam);
|
||||
tsem_wait(&pParam->sem);
|
||||
}
|
||||
|
@ -1280,8 +1289,7 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
|
|||
int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData),
|
||||
varDataVal(dst) + CHAR_BYTES);
|
||||
if (length <= 0) {
|
||||
tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
|
||||
varDataVal(jsonInnerData));
|
||||
tscError("charset:%s to %s. convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
length = 0;
|
||||
}
|
||||
varDataSetLen(dst, length + CHAR_BYTES * 2);
|
||||
|
@ -1340,6 +1348,17 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
|
|||
uint64_t groupId = *(uint64_t*)p;
|
||||
p += sizeof(uint64_t);
|
||||
|
||||
// check fields
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
int16_t type = *(int16_t*) p;
|
||||
p += sizeof(int16_t);
|
||||
|
||||
int32_t bytes = *(int32_t*) p;
|
||||
p += sizeof(int32_t);
|
||||
|
||||
// ASSERT(type == pFields[i].type && bytes == pFields[i].bytes);
|
||||
}
|
||||
|
||||
int32_t* colLength = (int32_t*)p;
|
||||
p += sizeof(int32_t) * numOfCols;
|
||||
|
||||
|
|
|
@ -219,14 +219,13 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
|
||||
if (TD_RES_QUERY(res)) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
return doAsyncFetchRows(pRequest, true, true);
|
||||
#else
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
return doAsyncFetchRow(pRequest, true, true);
|
||||
#else
|
||||
return doFetchRows(pRequest, true, true);
|
||||
#endif
|
||||
|
||||
|
@ -489,6 +488,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
|||
if (res == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (TD_RES_QUERY(res)) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
|
||||
|
@ -500,7 +500,11 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
doFetchRows(pRequest, false, true);
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
doAsyncFetchRows(pRequest, false, true);
|
||||
#else
|
||||
doFetchRows(pRequest, true, true);
|
||||
#endif
|
||||
|
||||
// TODO refactor
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
@ -548,7 +552,11 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
doAsyncFetchRows(pRequest, false, false);
|
||||
#else
|
||||
doFetchRows(pRequest, false, false);
|
||||
#endif
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
|
@ -625,8 +633,10 @@ void retrieveMetaCallback(SMetaData* pResultMeta, void* param, int32_t code) {
|
|||
taosMemoryFree(pWrapper);
|
||||
launchAsyncQuery(pRequest, pQuery);
|
||||
} else {
|
||||
tscDebug("error happens, code:%d", code);
|
||||
if (NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
tscDebug("0x%"PRIx64" client retry to handle the error, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId);
|
||||
tscDebug("0x%"PRIx64" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code),
|
||||
pRequest->retry, pRequest->requestId);
|
||||
pRequest->prevCode = code;
|
||||
doAsyncQuery(pRequest, true);
|
||||
return;
|
||||
|
@ -691,6 +701,7 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext** pCxt) {
|
|||
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||
.pStmtCb = NULL,
|
||||
.pUser = pTscObj->user,
|
||||
.schemalessType = pTscObj->schemalessType,
|
||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||
.async = true,};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -699,13 +710,14 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext** pCxt) {
|
|||
void doAsyncQuery(SRequestObj* pRequest, bool updateMetaForce) {
|
||||
SParseContext* pCxt = NULL;
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) {
|
||||
pRequest->code = pRequest->prevCode;
|
||||
code = pRequest->prevCode;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
int32_t code = createParseContext(pRequest, &pCxt);
|
||||
code = createParseContext(pRequest, &pCxt);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -742,7 +754,7 @@ void doAsyncQuery(SRequestObj* pRequest, bool updateMetaForce) {
|
|||
}
|
||||
|
||||
_error:
|
||||
tscError("0x%"PRIx64" error happens, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId);
|
||||
tscError("0x%"PRIx64" error happens, code:%d - %s, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code), pRequest->requestId);
|
||||
terrno = code;
|
||||
pRequest->code = code;
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
|
@ -763,11 +775,11 @@ static void fetchCallback(void* pResult, void* param, int32_t code) {
|
|||
}
|
||||
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = code;
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResultInfo->pData, true, false);
|
||||
pRequest->code = setQueryResultFromRsp(pResultInfo, (SRetrieveTableRsp*)pResultInfo->pData, pResultInfo->convertUcs4, false);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pRequest->code = code;
|
||||
|
@ -807,6 +819,21 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
|||
schedulerAsyncFetchRows(pRequest->body.queryJob, fetchCallback, pRequest);
|
||||
}
|
||||
|
||||
void taos_fetch_raw_block_a(TAOS_RES* res, __taos_async_fn_t fp, void* param) {
|
||||
ASSERT(res != NULL && fp != NULL);
|
||||
SRequestObj *pRequest = res;
|
||||
|
||||
pRequest->body.resInfo.convertUcs4 = false;
|
||||
taos_fetch_rows_a(res, fp, param);
|
||||
}
|
||||
|
||||
const void* taos_get_raw_block(TAOS_RES* res) {
|
||||
ASSERT(res != NULL);
|
||||
SRequestObj* pRequest = res;
|
||||
|
||||
return pRequest->body.resInfo.pData;
|
||||
}
|
||||
|
||||
TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp,
|
||||
void *param, int interval) {
|
||||
// TODO
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
#include "tname.h"
|
||||
#include "cJSON.h"
|
||||
#include "tglobal.h"
|
||||
#include "osSemaphore.h"
|
||||
#include "osThread.h"
|
||||
|
||||
//=================================================================================================
|
||||
|
||||
#define SPACE ' '
|
||||
|
@ -67,6 +70,9 @@ for (int i = 1; i < keyLen; ++i) { \
|
|||
|
||||
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
|
||||
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
|
||||
|
||||
#define MAX_RETRY_TIMES 5
|
||||
#define LINE_BATCH 20000
|
||||
//=================================================================================================
|
||||
typedef TSDB_SML_PROTOCOL_TYPE SMLProtocolType;
|
||||
|
||||
|
@ -153,8 +159,16 @@ typedef struct {
|
|||
int64_t endTime;
|
||||
} SSmlCostInfo;
|
||||
|
||||
typedef struct{
|
||||
SRequestObj* request;
|
||||
tsem_t sem;
|
||||
TdThreadSpinlock lock;
|
||||
} Params;
|
||||
|
||||
typedef struct {
|
||||
int64_t id;
|
||||
Params *params;
|
||||
bool isLast;
|
||||
|
||||
SMLProtocolType protocol;
|
||||
int8_t precision;
|
||||
|
@ -292,19 +306,10 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
const char* errStr = taos_errstr(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" apply schema action. error: %s", info->id, errStr);
|
||||
taosMsleep(100);
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
// if (code == TSDB_CODE_MND_FIELD_ALREADY_EXIST || code == TSDB_CODE_MND_TAG_ALREADY_EXIST || tscDupColNames) {
|
||||
if (code == TSDB_CODE_MND_TAG_ALREADY_EXIST) {
|
||||
TAOS_RES* res2 = taos_query(info->taos, "RESET QUERY CACHE");
|
||||
code = taos_errno(res2);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SCHEMA_ACTION_ADD_TAG: {
|
||||
|
@ -316,19 +321,10 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
const char* errStr = taos_errstr(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" apply schema action. error : %s", info->id, taos_errstr(res));
|
||||
taosMsleep(100);
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
// if (code ==TSDB_CODE_MND_TAG_ALREADY_EXIST || code == TSDB_CODE_MND_FIELD_ALREAY_EXIST || tscDupColNames) {
|
||||
if (code ==TSDB_CODE_MND_TAG_ALREADY_EXIST) {
|
||||
TAOS_RES* res2 = taos_query(info->taos, "RESET QUERY CACHE");
|
||||
code = taos_errno(res2);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SCHEMA_ACTION_CHANGE_COLUMN_SIZE: {
|
||||
|
@ -339,19 +335,10 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
code = taos_errno(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" apply schema action. error : %s", info->id, taos_errstr(res));
|
||||
taosMsleep(100);
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
// if (code == TSDB_CODE_MND_INVALID_COLUMN_LENGTH || code == TSDB_CODE_TSC_INVALID_COLUMN_LENGTH) {
|
||||
if (code == TSDB_CODE_TSC_INVALID_COLUMN_LENGTH) {
|
||||
TAOS_RES* res2 = taos_query(info->taos, "RESET QUERY CACHE");
|
||||
code = taos_errno(res2);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SCHEMA_ACTION_CHANGE_TAG_SIZE: {
|
||||
|
@ -362,19 +349,10 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
code = taos_errno(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" apply schema action. error : %s", info->id, taos_errstr(res));
|
||||
taosMsleep(100);
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
// if (code == TSDB_CODE_MND_INVALID_TAG_LENGTH || code == TSDB_CODE_TSC_INVALID_TAG_LENGTH) {
|
||||
if (code == TSDB_CODE_TSC_INVALID_TAG_LENGTH) {
|
||||
TAOS_RES* res2 = taos_query(info->taos, "RESET QUERY CACHE");
|
||||
code = taos_errno(res2);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SCHEMA_ACTION_CREATE_STABLE: {
|
||||
|
@ -414,18 +392,10 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
code = taos_errno(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" apply schema action. error : %s", info->id, taos_errstr(res));
|
||||
taosMsleep(100);
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
if (code == TSDB_CODE_MND_STB_ALREADY_EXIST) {
|
||||
TAOS_RES* res2 = taos_query(info->taos, "RESET QUERY CACHE");
|
||||
code = taos_errno(res2);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -459,20 +429,36 @@ static int32_t smlProcessSchemaAction(SSmlHandle* info, SSchema* schemaField, SH
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t smlCheckMeta(SSchema* schema, int32_t length, SArray* cols){
|
||||
SHashObj *hashTmp = taosHashInit(length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
for(uint16_t i = 0; i < length; i++){
|
||||
taosHashPut(hashTmp, schema[i].name, strlen(schema[i].name), &i, SHORT_BYTES);
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < taosArrayGetSize(cols); i++){
|
||||
SSmlKv* kv = (SSmlKv*)taosArrayGetP(cols, i);
|
||||
if(taosHashGet(hashTmp, kv->key, kv->keyLen) == NULL){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t smlModifyDBSchemas(SSmlHandle* info) {
|
||||
int32_t code = 0;
|
||||
SEpSet ep = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
|
||||
SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
|
||||
strcpy(pName.dbname, info->pRequest->pDb);
|
||||
|
||||
SSmlSTableMeta** tableMetaSml = (SSmlSTableMeta**)taosHashIterate(info->superTables, NULL);
|
||||
while (tableMetaSml) {
|
||||
SSmlSTableMeta* sTableData = *tableMetaSml;
|
||||
|
||||
STableMeta *pTableMeta = NULL;
|
||||
SEpSet ep = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
|
||||
bool needCheckMeta = false; // for multi thread
|
||||
|
||||
size_t superTableLen = 0;
|
||||
void *superTable = taosHashGetKey(tableMetaSml, &superTableLen);
|
||||
SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
|
||||
strcpy(pName.dbname, info->pRequest->pDb);
|
||||
memset(pName.tname, 0, TSDB_TABLE_NAME_LEN);
|
||||
memcpy(pName.tname, superTable, superTableLen);
|
||||
|
||||
code = catalogGetSTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, &pTableMeta);
|
||||
|
@ -487,7 +473,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) {
|
|||
code = smlApplySchemaAction(info, &schemaAction);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" smlApplySchemaAction failed. can not create %s", info->id, schemaAction.createSTable.sTableName);
|
||||
return code;
|
||||
goto end;
|
||||
}
|
||||
info->cost.numOfCreateSTables++;
|
||||
}else if (code == TSDB_CODE_SUCCESS) {
|
||||
|
@ -502,7 +488,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) {
|
|||
code = smlProcessSchemaAction(info, pTableMeta->schema, hashTmp, sTableData->tags, &schemaAction, true);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosHashCleanup(hashTmp);
|
||||
return code;
|
||||
goto end;
|
||||
}
|
||||
|
||||
taosHashClear(hashTmp);
|
||||
|
@ -512,81 +498,50 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) {
|
|||
code = smlProcessSchemaAction(info, pTableMeta->schema, hashTmp, sTableData->cols, &schemaAction, false);
|
||||
taosHashCleanup(hashTmp);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
goto end;
|
||||
}
|
||||
|
||||
code = catalogRefreshTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, -1);
|
||||
code = catalogRefreshTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
goto end;
|
||||
}
|
||||
needCheckMeta = true;
|
||||
} else {
|
||||
uError("SML:0x%"PRIx64" load table meta error: %s", info->id, tstrerror(code));
|
||||
return code;
|
||||
goto end;
|
||||
}
|
||||
if(pTableMeta) taosMemoryFree(pTableMeta);
|
||||
|
||||
code = catalogGetSTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, &pTableMeta);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" catalogGetSTableMeta failed. super table name %s", info->id, (char*)superTable);
|
||||
return code;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(needCheckMeta){
|
||||
code = smlCheckMeta(&(pTableMeta->schema[pTableMeta->tableInfo.numOfColumns]), pTableMeta->tableInfo.numOfTags, sTableData->tags);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" check tag failed. super table name %s", info->id, (char*)superTable);
|
||||
goto end;
|
||||
}
|
||||
code = smlCheckMeta(&(pTableMeta->schema[0]), pTableMeta->tableInfo.numOfColumns, sTableData->cols);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%"PRIx64" check cols failed. super table name %s", info->id, (char*)superTable);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
sTableData->tableMeta = pTableMeta;
|
||||
|
||||
tableMetaSml = (SSmlSTableMeta**)taosHashIterate(info->superTables, tableMetaSml);
|
||||
}
|
||||
return 0;
|
||||
|
||||
end:
|
||||
catalogRefreshTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, 1);
|
||||
return code;
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
|
||||
/* Field Escape charaters
|
||||
1: measurement Comma,Space
|
||||
2: tag_key, tag_value, field_key Comma,Equal Sign,Space
|
||||
3: field_value Double quote,Backslash
|
||||
*/
|
||||
//static void escapeSpecialCharacter(uint8_t field, const char **pos) {
|
||||
// const char *cur = *pos;
|
||||
// if (*cur != '\\') {
|
||||
// return;
|
||||
// }
|
||||
// switch (field) {
|
||||
// case 1:
|
||||
// switch (*(cur + 1)) {
|
||||
// case ',':
|
||||
// case ' ':
|
||||
// cur++;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// case 2:
|
||||
// switch (*(cur + 1)) {
|
||||
// case ',':
|
||||
// case ' ':
|
||||
// case '=':
|
||||
// cur++;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// case 3:
|
||||
// switch (*(cur + 1)) {
|
||||
// case '"':
|
||||
// case '\\':
|
||||
// cur++;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// *pos = cur;
|
||||
//}
|
||||
|
||||
static bool smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg){
|
||||
const char *pVal = kvVal->value;
|
||||
int32_t len = kvVal->length;
|
||||
|
@ -1323,9 +1278,46 @@ static void smlDestroyTableInfo(SSmlHandle* info, SSmlTableInfo *tag){
|
|||
taosMemoryFree(tag);
|
||||
}
|
||||
|
||||
static int32_t smlKvTimeArrayCompare(const void* key1, const void* key2) {
|
||||
SArray *s1 = *(SArray **)key1;
|
||||
SArray *s2 = *(SArray **)key2;
|
||||
SSmlKv *kv1 = (SSmlKv *)taosArrayGetP(s1, 0);
|
||||
SSmlKv *kv2 = (SSmlKv *)taosArrayGetP(s2, 0);
|
||||
ASSERT(kv1->type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
ASSERT(kv2->type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
if (kv1->i < kv2->i) {
|
||||
return -1;
|
||||
} else if (kv1->i > kv2->i) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t smlKvTimeHashCompare(const void* key1, const void* key2) {
|
||||
SHashObj *s1 = *(SHashObj **)key1;
|
||||
SHashObj *s2 = *(SHashObj **)key2;
|
||||
SSmlKv *kv1 = (SSmlKv *)taosHashGet(s1, TS, TS_LEN);
|
||||
SSmlKv *kv2 = (SSmlKv *)taosHashGet(s2, TS, TS_LEN);
|
||||
ASSERT(kv1->type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
ASSERT(kv2->type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
if (kv1->i < kv2->i) {
|
||||
return -1;
|
||||
} else if (kv1->i > kv2->i) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t smlDealCols(SSmlTableInfo* oneTable, bool dataFormat, SArray *cols){
|
||||
if(dataFormat){
|
||||
void *p = taosArraySearch(oneTable->cols, &cols, smlKvTimeArrayCompare, TD_GE);
|
||||
if(p == NULL){
|
||||
taosArrayPush(oneTable->cols, &cols);
|
||||
}else{
|
||||
taosArrayInsert(oneTable->cols, TARRAY_ELEM_IDX(oneTable->cols, p), &cols);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1338,8 +1330,13 @@ static int32_t smlDealCols(SSmlTableInfo* oneTable, bool dataFormat, SArray *col
|
|||
SSmlKv *kv = (SSmlKv *)taosArrayGetP(cols, i);
|
||||
taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
|
||||
}
|
||||
taosArrayPush(oneTable->cols, &kvHash);
|
||||
|
||||
void *p = taosArraySearch(oneTable->cols, &kvHash, smlKvTimeHashCompare, TD_GE);
|
||||
if(p == NULL){
|
||||
taosArrayPush(oneTable->cols, &kvHash);
|
||||
}else{
|
||||
taosArrayInsert(oneTable->cols, TARRAY_ELEM_IDX(oneTable->cols, p), &kvHash);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1422,6 +1419,7 @@ static void smlDestroyInfo(SSmlHandle* info){
|
|||
if(!info->dataFormat){
|
||||
taosArrayDestroy(info->colsContainer);
|
||||
}
|
||||
destroyRequest(info->pRequest);
|
||||
taosMemoryFreeClear(info);
|
||||
}
|
||||
|
||||
|
@ -1544,7 +1542,7 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV
|
|||
}
|
||||
|
||||
size_t typeLen = strlen(type->valuestring);
|
||||
if (typeLen == 1 && type->valuestring[0] == 's') {
|
||||
if (typeLen == 1 && (type->valuestring[0] == 's' || type->valuestring[0] == 'S')) {
|
||||
//seconds
|
||||
timeDouble = timeDouble * 1e9;
|
||||
if(smlDoubleToInt64OverFlow(timeDouble)){
|
||||
|
@ -1552,9 +1550,10 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV
|
|||
return TSDB_CODE_TSC_INVALID_TIME_STAMP;
|
||||
}
|
||||
*tsVal = timeDouble;
|
||||
} else if (typeLen == 2 && type->valuestring[1] == 's') {
|
||||
} else if (typeLen == 2 && (type->valuestring[1] == 's' || type->valuestring[1] == 'S')) {
|
||||
switch (type->valuestring[0]) {
|
||||
case 'm':
|
||||
case 'M':
|
||||
//milliseconds
|
||||
timeDouble = timeDouble * 1e6;
|
||||
if(smlDoubleToInt64OverFlow(timeDouble)){
|
||||
|
@ -1564,6 +1563,7 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV
|
|||
*tsVal = timeDouble;
|
||||
break;
|
||||
case 'u':
|
||||
case 'U':
|
||||
//microseconds
|
||||
timeDouble = timeDouble * 1e3;
|
||||
if(smlDoubleToInt64OverFlow(timeDouble)){
|
||||
|
@ -1573,6 +1573,7 @@ static int32_t smlParseTSFromJSONObj(SSmlHandle *info, cJSON *root, int64_t *tsV
|
|||
*tsVal = timeDouble;
|
||||
break;
|
||||
case 'n':
|
||||
case 'N':
|
||||
//nanoseconds
|
||||
*tsVal = timeDouble;
|
||||
break;
|
||||
|
@ -2199,7 +2200,6 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int32_t smlInsertData(SSmlHandle* info) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -2229,6 +2229,7 @@ static int32_t smlInsertData(SSmlHandle* info) {
|
|||
code = smlBindData(info->exec, tableData->tags, (*pMeta)->cols, tableData->cols, info->dataFormat,
|
||||
(*pMeta)->tableMeta, tableData->childTableName, info->msgBuf.buf, info->msgBuf.len);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
uError("SML:0x%"PRIx64" smlBindData failed", info->id);
|
||||
return code;
|
||||
}
|
||||
oneTable = (SSmlTableInfo**)taosHashIterate(info->childTables, oneTable);
|
||||
|
@ -2241,10 +2242,12 @@ static int32_t smlInsertData(SSmlHandle* info) {
|
|||
}
|
||||
info->cost.insertRpcTime = taosGetTimestampUs();
|
||||
|
||||
launchQueryImpl(info->pRequest, info->pQuery, true, NULL);
|
||||
//launchQueryImpl(info->pRequest, info->pQuery, false, NULL);
|
||||
// info->affectedRows = taos_affected_rows(info->pRequest);
|
||||
// return info->pRequest->code;
|
||||
|
||||
info->affectedRows = taos_affected_rows(info->pRequest);
|
||||
return info->pRequest->code;
|
||||
launchAsyncQuery(info->pRequest, info->pQuery);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void smlPrintStatisticInfo(SSmlHandle *info){
|
||||
|
@ -2285,12 +2288,14 @@ static int32_t smlParseLine(SSmlHandle *info, char* lines[], int numLines){
|
|||
|
||||
static int smlProcess(SSmlHandle *info, char* lines[], int numLines) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t retryNum = 0;
|
||||
|
||||
info->cost.parseTime = taosGetTimestampUs();
|
||||
|
||||
code = smlParseLine(info, lines, numLines);
|
||||
if (code != 0) {
|
||||
uError("SML:0x%"PRIx64" smlParseLine error : %s", info->id, tstrerror(code));
|
||||
goto cleanup;
|
||||
return code;
|
||||
}
|
||||
|
||||
info->cost.lineNum = numLines;
|
||||
|
@ -2298,50 +2303,80 @@ static int smlProcess(SSmlHandle *info, char* lines[], int numLines) {
|
|||
info->cost.numOfCTables = taosHashGetSize(info->childTables);
|
||||
|
||||
info->cost.schemaTime = taosGetTimestampUs();
|
||||
|
||||
do{
|
||||
code = smlModifyDBSchemas(info);
|
||||
if (code == 0) break;
|
||||
} while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
|
||||
|
||||
if (code != 0) {
|
||||
uError("SML:0x%"PRIx64" smlModifyDBSchemas error : %s", info->id, tstrerror(code));
|
||||
goto cleanup;
|
||||
return code;
|
||||
}
|
||||
|
||||
info->cost.insertBindTime = taosGetTimestampUs();
|
||||
code = smlInsertData(info);
|
||||
if (code != 0) {
|
||||
uError("SML:0x%"PRIx64" smlInsertData error : %s", info->id, tstrerror(code));
|
||||
goto cleanup;
|
||||
return code;
|
||||
}
|
||||
info->cost.endTime = taosGetTimestampUs();
|
||||
|
||||
cleanup:
|
||||
info->cost.code = code;
|
||||
smlPrintStatisticInfo(info);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t isSchemalessDb(SSmlHandle* info){
|
||||
static int32_t isSchemalessDb(STscObj *taos){
|
||||
SCatalog* catalog = NULL;
|
||||
int32_t code = catalogGetHandle(((STscObj *)taos)->pAppInfo->clusterId, &catalog);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
uError("SML get catalog error %d", code);
|
||||
return code;
|
||||
}
|
||||
|
||||
SName name;
|
||||
tNameSetDbName(&name, info->taos->acctId, info->taos->db, strlen(info->taos->db));
|
||||
tNameSetDbName(&name, taos->acctId, taos->db, strlen(taos->db));
|
||||
char dbFname[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(&name, dbFname);
|
||||
SDbCfgInfo pInfo = {0};
|
||||
SEpSet ep = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
|
||||
SEpSet ep = getEpSet_s(&taos->pAppInfo->mgmtEp);
|
||||
|
||||
int32_t code = catalogGetDBCfg(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, dbFname, &pInfo);
|
||||
code = catalogGetDBCfg(catalog, taos->pAppInfo->pTransporter, &ep, dbFname, &pInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
info->pRequest->code = code;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "catalogGetDBCfg error, code:", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
taosArrayDestroy(pInfo.pRetensions);
|
||||
|
||||
if (!pInfo.schemaless){
|
||||
info->pRequest->code = TSDB_CODE_SML_INVALID_DB_CONF;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "can not insert into schemaless db:", dbFname);
|
||||
return TSDB_CODE_SML_INVALID_DB_CONF;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void smlInsertCallback(void* param, void* res, int32_t code) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
SSmlHandle* info = (SSmlHandle *)param;
|
||||
|
||||
uDebug("SML:0x%"PRIx64" result. code:%d, msg:%s", info->id, pRequest->code, pRequest->msgBuf);
|
||||
// lock
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
taosThreadSpinLock(&info->params->lock);
|
||||
info->params->request->code = code;
|
||||
taosThreadSpinUnlock(&info->params->lock);
|
||||
}
|
||||
// unlock
|
||||
|
||||
printf("SML:0x%" PRIx64 " insert finished, code: %d, total: %d\n", info->id, code, info->affectedRows);
|
||||
Params *pParam = info->params;
|
||||
bool isLast = info->isLast;
|
||||
info->cost.endTime = taosGetTimestampUs();
|
||||
info->cost.code = code;
|
||||
smlPrintStatisticInfo(info);
|
||||
smlDestroyInfo(info);
|
||||
|
||||
if(isLast){
|
||||
tsem_post(&pParam->sem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* taos_schemaless_insert() parse and insert data points into database according to
|
||||
* different protocol.
|
||||
|
@ -2370,47 +2405,88 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSmlHandle* info = smlBuildSmlInfo(taos, request, (SMLProtocolType)protocol, precision);
|
||||
if(!info){
|
||||
return (TAOS_RES*)request;
|
||||
}
|
||||
((STscObj *)taos)->schemalessType = 1;
|
||||
SSmlMsgBuf msg = {ERROR_MSG_BUF_DEFAULT_SIZE, request->msgBuf};
|
||||
|
||||
int cnt = ceil(((double)numLines)/LINE_BATCH);
|
||||
Params params;
|
||||
params.request = request;
|
||||
tsem_init(¶ms.sem, 0, 0);
|
||||
taosThreadSpinInit(&(params.lock), 0);
|
||||
|
||||
info->taos->schemalessType = 1;
|
||||
if(request->pDb == NULL){
|
||||
request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "Database not specified", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "Database not specified", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(isSchemalessDb(info) != TSDB_CODE_SUCCESS){
|
||||
if(isSchemalessDb(((STscObj *)taos)) != TSDB_CODE_SUCCESS){
|
||||
request->code = TSDB_CODE_SML_INVALID_DB_CONF;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "Cannot write data to a non schemaless database", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "Cannot write data to a non schemaless database", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!lines) {
|
||||
request->code = TSDB_CODE_SML_INVALID_DATA;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "lines is null", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "lines is null", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL){
|
||||
request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "protocol invalidate", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(protocol == TSDB_SML_LINE_PROTOCOL && (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)){
|
||||
request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "precision invalidate for line protocol", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
info->pRequest->code = smlProcess(info, lines, numLines);
|
||||
for (int i = 0; i < cnt; ++i) {
|
||||
SRequestObj* req = (SRequestObj*)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
if(!req){
|
||||
request->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
uError("SML:taos_schemaless_insert error request is null");
|
||||
goto end;
|
||||
}
|
||||
SSmlHandle* info = smlBuildSmlInfo(taos, req, (SMLProtocolType)protocol, precision);
|
||||
if(!info){
|
||||
request->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
uError("SML:taos_schemaless_insert error SSmlHandle is null");
|
||||
goto end;
|
||||
}
|
||||
|
||||
int32_t perBatch = LINE_BATCH;
|
||||
|
||||
if(numLines > perBatch){
|
||||
numLines -= perBatch;
|
||||
info->isLast = false;
|
||||
}else{
|
||||
perBatch = numLines;
|
||||
numLines = 0;
|
||||
info->isLast = true;
|
||||
}
|
||||
|
||||
info->params = ¶ms;
|
||||
info->affectedRows = perBatch;
|
||||
info->pRequest->body.queryFp = smlInsertCallback;
|
||||
info->pRequest->body.param = info;
|
||||
int32_t code = smlProcess(info, lines, perBatch);
|
||||
lines += perBatch;
|
||||
if (code != TSDB_CODE_SUCCESS){
|
||||
info->pRequest->body.queryFp(info, req, code);
|
||||
}
|
||||
}
|
||||
tsem_wait(¶ms.sem);
|
||||
|
||||
end:
|
||||
uDebug("result:%s", info->msgBuf.buf);
|
||||
smlDestroyInfo(info);
|
||||
taosThreadSpinDestroy(¶ms.lock);
|
||||
tsem_destroy(¶ms.sem);
|
||||
// ((STscObj *)taos)->schemalessType = 0;
|
||||
((STscObj *)taos)->schemalessType = 1;
|
||||
uDebug("resultend:%s", request->msgBuf);
|
||||
return (TAOS_RES*)request;
|
||||
}
|
||||
|
||||
|
|
|
@ -323,7 +323,7 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
|
|||
|
||||
int32_t tmqCommitCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SMqCommitCbParam* pParam = (SMqCommitCbParam*)param;
|
||||
pParam->rspErr = code == 0 ? TMQ_RESP_ERR__SUCCESS : TMQ_RESP_ERR__FAIL;
|
||||
pParam->rspErr = code;
|
||||
if (pParam->async) {
|
||||
if (pParam->automatic && pParam->tmq->commitCb) {
|
||||
pParam->tmq->commitCb(pParam->tmq, pParam->rspErr, (tmq_topic_vgroup_list_t*)pParam->offsets,
|
||||
|
@ -408,7 +408,7 @@ int32_t tmqCommitInner(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8_
|
|||
pParam->userParam = userParam;
|
||||
if (!async) tsem_init(&pParam->rspSem, 0, 0);
|
||||
|
||||
sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
|
||||
sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) goto END;
|
||||
sendInfo->msgInfo = (SDataBuf){
|
||||
.pData = buf,
|
||||
|
@ -432,12 +432,13 @@ int32_t tmqCommitInner(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8_
|
|||
code = pParam->rspErr;
|
||||
tsem_destroy(&pParam->rspSem);
|
||||
taosMemoryFree(pParam);
|
||||
} else {
|
||||
code = 0;
|
||||
}
|
||||
|
||||
// avoid double free if msg is sent
|
||||
buf = NULL;
|
||||
|
||||
code = 0;
|
||||
END:
|
||||
if (buf) taosMemoryFree(buf);
|
||||
/*if (pParam) taosMemoryFree(pParam);*/
|
||||
|
@ -445,9 +446,9 @@ END:
|
|||
|
||||
if (code != 0 && async) {
|
||||
if (automatic) {
|
||||
tmq->commitCb(tmq, TMQ_RESP_ERR__FAIL, (tmq_topic_vgroup_list_t*)pOffsets, tmq->commitCbUserParam);
|
||||
tmq->commitCb(tmq, code, (tmq_topic_vgroup_list_t*)pOffsets, tmq->commitCbUserParam);
|
||||
} else {
|
||||
userCb(tmq, TMQ_RESP_ERR__FAIL, (tmq_topic_vgroup_list_t*)pOffsets, userParam);
|
||||
userCb(tmq, code, (tmq_topic_vgroup_list_t*)pOffsets, userParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -493,7 +494,6 @@ int32_t tmqHandleAllDelayedTask(tmq_t* tmq) {
|
|||
tmqAskEp(tmq, true);
|
||||
taosTmrReset(tmqAssignDelayedHbTask, 1000, tmq, tmqMgmt.timer, &tmq->hbTimer);
|
||||
} else if (*pTaskType == TMQ_DELAYED_TASK__COMMIT) {
|
||||
/*tmq_commit(tmq, NULL, true);*/
|
||||
tmqCommitInner(tmq, NULL, 1, 1, tmq->commitCb, tmq->commitCbUserParam);
|
||||
taosTmrReset(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, tmq, tmqMgmt.timer, &tmq->commitTimer);
|
||||
} else if (*pTaskType == TMQ_DELAYED_TASK__REPORT) {
|
||||
|
@ -666,94 +666,6 @@ FAIL:
|
|||
|
||||
tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int32_t async) {
|
||||
return tmqCommitInner(tmq, offsets, 0, async, tmq->commitCb, tmq->commitCbUserParam);
|
||||
#if 0
|
||||
// TODO: add read write lock
|
||||
SRequestObj* pRequest = NULL;
|
||||
tmq_resp_err_t resp = TMQ_RESP_ERR__SUCCESS;
|
||||
// build msg
|
||||
// send to mnode
|
||||
SMqCMCommitOffsetReq req;
|
||||
SArray* pOffsets = NULL;
|
||||
|
||||
if (offsets == NULL) {
|
||||
pOffsets = taosArrayInit(0, sizeof(SMqOffset));
|
||||
for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) {
|
||||
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i);
|
||||
for (int j = 0; j < taosArrayGetSize(pTopic->vgs); j++) {
|
||||
SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j);
|
||||
SMqOffset offset;
|
||||
strcpy(offset.topicName, pTopic->topicName);
|
||||
strcpy(offset.cgroup, tmq->groupId);
|
||||
offset.vgId = pVg->vgId;
|
||||
offset.offset = pVg->currentOffset;
|
||||
taosArrayPush(pOffsets, &offset);
|
||||
}
|
||||
}
|
||||
req.num = pOffsets->size;
|
||||
req.offsets = pOffsets->pData;
|
||||
} else {
|
||||
req.num = taosArrayGetSize(&offsets->container);
|
||||
req.offsets = (SMqOffset*)offsets->container.pData;
|
||||
}
|
||||
|
||||
SEncoder encoder;
|
||||
|
||||
tEncoderInit(&encoder, NULL, 0);
|
||||
tEncodeSMqCMCommitOffsetReq(&encoder, &req);
|
||||
int32_t tlen = encoder.pos;
|
||||
void* buf = taosMemoryMalloc(tlen);
|
||||
if (buf == NULL) {
|
||||
tEncoderClear(&encoder);
|
||||
return -1;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
tEncoderInit(&encoder, buf, tlen);
|
||||
tEncodeSMqCMCommitOffsetReq(&encoder, &req);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
pRequest = createRequest(tmq->pTscObj, NULL, NULL, TDMT_MND_MQ_COMMIT_OFFSET);
|
||||
if (pRequest == NULL) {
|
||||
tscError("failed to malloc request");
|
||||
}
|
||||
|
||||
SMqCommitCbParam* pParam = taosMemoryCalloc(1, sizeof(SMqCommitCbParam));
|
||||
if (pParam == NULL) {
|
||||
return -1;
|
||||
}
|
||||
pParam->tmq = tmq;
|
||||
tsem_init(&pParam->rspSem, 0, 0);
|
||||
pParam->async = async;
|
||||
pParam->offsets = pOffsets;
|
||||
|
||||
pRequest->body.requestMsg = (SDataBuf){
|
||||
.pData = buf,
|
||||
.len = tlen,
|
||||
.handle = NULL,
|
||||
};
|
||||
|
||||
SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest);
|
||||
sendInfo->requestObjRefId = 0;
|
||||
sendInfo->param = pParam;
|
||||
sendInfo->fp = tmqCommitCb;
|
||||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
if (!async) {
|
||||
tsem_wait(&pParam->rspSem);
|
||||
resp = pParam->rspErr;
|
||||
tsem_destroy(&pParam->rspSem);
|
||||
taosMemoryFree(pParam);
|
||||
|
||||
if (pOffsets) {
|
||||
taosArrayDestroy(pOffsets);
|
||||
}
|
||||
}
|
||||
|
||||
return resp;
|
||||
#endif
|
||||
}
|
||||
|
||||
tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
||||
|
@ -792,7 +704,7 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
void* abuf = buf;
|
||||
tSerializeSCMSubscribeReq(&abuf, &req);
|
||||
|
||||
SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
|
||||
SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) goto FAIL;
|
||||
|
||||
SMqSubscribeCbParam param = {
|
||||
|
@ -858,93 +770,6 @@ void tmq_conf_set_auto_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb, void* para
|
|||
conf->commitCbUserParam = param;
|
||||
}
|
||||
|
||||
#if 0
|
||||
TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbName, const char* sql) {
|
||||
STscObj* pTscObj = (STscObj*)taos;
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQuery* pQueryNode = NULL;
|
||||
char* astStr = NULL;
|
||||
int32_t sqlLen;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
if (taos == NULL || streamName == NULL || sql == NULL) {
|
||||
tscError("invalid parameters for creating stream, connObj:%p, stream name:%s, sql:%s", taos, streamName, sql);
|
||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
||||
goto _return;
|
||||
}
|
||||
sqlLen = strlen(sql);
|
||||
|
||||
if (strlen(tbName) >= TSDB_TABLE_NAME_LEN) {
|
||||
tscError("output tb name too long, max length:%d", TSDB_TABLE_NAME_LEN - 1);
|
||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (sqlLen > TSDB_MAX_ALLOWED_SQL_LEN) {
|
||||
tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
|
||||
terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
tscDebug("start to create stream: %s", streamName);
|
||||
|
||||
int32_t code = 0;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, false, &pQueryNode, NULL), _return);
|
||||
CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return);
|
||||
|
||||
/*printf("%s\n", pStr);*/
|
||||
|
||||
SName name = {.acctId = pTscObj->acctId, .type = TSDB_TABLE_NAME_T};
|
||||
strcpy(name.dbname, pRequest->pDb);
|
||||
strcpy(name.tname, streamName);
|
||||
|
||||
SCMCreateStreamReq req = {
|
||||
.igExists = 1,
|
||||
.ast = astStr,
|
||||
.sql = (char*)sql,
|
||||
};
|
||||
tNameExtractFullName(&name, req.name);
|
||||
strcpy(req.targetStbFullName, tbName);
|
||||
|
||||
int tlen = tSerializeSCMCreateStreamReq(NULL, 0, &req);
|
||||
void* buf = taosMemoryMalloc(tlen);
|
||||
if (buf == NULL) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
tSerializeSCMCreateStreamReq(buf, tlen, &req);
|
||||
|
||||
pRequest->body.requestMsg = (SDataBuf){
|
||||
.pData = buf,
|
||||
.len = tlen,
|
||||
.handle = NULL,
|
||||
};
|
||||
pRequest->type = TDMT_MND_CREATE_STREAM;
|
||||
|
||||
SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest);
|
||||
SEpSet epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
|
||||
_return:
|
||||
taosMemoryFreeClear(astStr);
|
||||
qDestroyQuery(pQueryNode);
|
||||
/*if (sendInfo != NULL) {*/
|
||||
/*destroySendMsgInfo(sendInfo);*/
|
||||
/*}*/
|
||||
|
||||
if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = terrno;
|
||||
}
|
||||
|
||||
return pRequest;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) {
|
||||
if (tmq_message == NULL) return 0;
|
||||
|
@ -1183,7 +1008,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) {
|
|||
pParam->async = async;
|
||||
tsem_init(&pParam->rspSem, 0, 0);
|
||||
|
||||
SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
|
||||
SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) {
|
||||
tsem_destroy(&pParam->rspSem);
|
||||
taosMemoryFree(pParam);
|
||||
|
@ -1337,7 +1162,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) {
|
|||
pParam->vgId = pVg->vgId;
|
||||
pParam->epoch = tmq->epoch;
|
||||
|
||||
SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
|
||||
SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) {
|
||||
taosMemoryFree(pReq);
|
||||
taosMemoryFree(pParam);
|
||||
|
@ -1456,7 +1281,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
|||
if (rspObj) {
|
||||
return (TAOS_RES*)rspObj;
|
||||
}
|
||||
if (timeout != 0) {
|
||||
if (timeout != -1) {
|
||||
int64_t endTime = taosGetTimestampMs();
|
||||
int64_t leftTime = endTime - startTime;
|
||||
if (leftTime > timeout) {
|
||||
|
@ -1474,16 +1299,16 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
|||
tmq_resp_err_t tmq_consumer_close(tmq_t* tmq) {
|
||||
if (tmq->status == TMQ_CONSUMER_STATUS__READY) {
|
||||
tmq_resp_err_t rsp = tmq_commit_sync(tmq, NULL);
|
||||
if (rsp == TMQ_RESP_ERR__FAIL) {
|
||||
return TMQ_RESP_ERR__FAIL;
|
||||
if (rsp != TMQ_RESP_ERR__SUCCESS) {
|
||||
return rsp;
|
||||
}
|
||||
|
||||
tmq_list_t* lst = tmq_list_new();
|
||||
rsp = tmq_subscribe(tmq, lst);
|
||||
tmq_list_destroy(lst);
|
||||
|
||||
if (rsp == TMQ_RESP_ERR__FAIL) {
|
||||
return TMQ_RESP_ERR__FAIL;
|
||||
if (rsp != TMQ_RESP_ERR__SUCCESS) {
|
||||
return rsp;
|
||||
}
|
||||
}
|
||||
// TODO: free resources
|
||||
|
@ -1493,8 +1318,11 @@ tmq_resp_err_t tmq_consumer_close(tmq_t* tmq) {
|
|||
const char* tmq_err2str(tmq_resp_err_t err) {
|
||||
if (err == TMQ_RESP_ERR__SUCCESS) {
|
||||
return "success";
|
||||
}
|
||||
} else if (err == TMQ_RESP_ERR__FAIL) {
|
||||
return "fail";
|
||||
} else {
|
||||
return tstrerror(err);
|
||||
}
|
||||
}
|
||||
|
||||
const char* tmq_get_topic_name(TAOS_RES* res) {
|
||||
|
@ -1536,10 +1364,11 @@ const char* tmq_get_table_name(TAOS_RES* res) {
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
DLL_EXPORT void tmq_commit_async(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, tmq_commit_cb* cb, void* param) {
|
||||
|
||||
void tmq_commit_async(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, tmq_commit_cb* cb, void* param) {
|
||||
tmqCommitInner(tmq, offsets, 0, 1, cb, param);
|
||||
}
|
||||
|
||||
DLL_EXPORT tmq_resp_err_t tmq_commit_sync(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets) {
|
||||
tmq_resp_err_t tmq_commit_sync(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets) {
|
||||
return tmqCommitInner(tmq, offsets, 0, 0, NULL, NULL);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ TARGET_INCLUDE_DIRECTORIES(
|
|||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
|
||||
#add_test(
|
||||
# NAME smlTest
|
||||
# COMMAND smlTest
|
||||
#)
|
||||
add_test(
|
||||
NAME smlTest
|
||||
COMMAND smlTest
|
||||
)
|
||||
|
|
|
@ -778,33 +778,30 @@ TEST(testCase, async_api_test) {
|
|||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
taos_query(pConn, "use test");
|
||||
taos_query(pConn, "use nest");
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "select * from t1");
|
||||
|
||||
taos_query(pConn, "alter table t1 add column b int");
|
||||
pRes = taos_query(pConn, "insert into t1 values(now, 1, 2)");
|
||||
TAOS_RES* pRes = taos_query(pConn, "select NOW() from (select * from regular_table_2 where tbname in ('regular_table_2_1') and q_bigint <= 9223372036854775807 and q_tinyint <= 127 and q_bool in ( true , false) ) order by ts;");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
// int32_t n = 0;
|
||||
// TAOS_ROW pRow = NULL;
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t* length = taos_fetch_lengths(pRes);
|
||||
// for(int32_t i = 0; i < numOfFields; ++i) {
|
||||
// printf("(%d):%d " , i, length[i]);
|
||||
// }
|
||||
// printf("\n");
|
||||
//
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// memset(str, 0, sizeof(str));
|
||||
// }
|
||||
int32_t n = 0;
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t* length = taos_fetch_lengths(pRes);
|
||||
for(int32_t i = 0; i < numOfFields; ++i) {
|
||||
printf("(%d):%d " , i, length[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
memset(str, 0, sizeof(str));
|
||||
}
|
||||
|
||||
taos_query_a(pConn, "alter table test.m1 comment 'abcde' ", queryCallback, pConn);
|
||||
getchar();
|
||||
|
|
|
@ -476,22 +476,40 @@ TEST(testCase, smlParseCols_Test) {
|
|||
taosMemoryFree(sql);
|
||||
}
|
||||
|
||||
TEST(testCase, smlGetTimestampLen_Test) {
|
||||
uint8_t len = smlGetTimestampLen(0);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(1);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(10);
|
||||
ASSERT_EQ(len, 2);
|
||||
|
||||
len = smlGetTimestampLen(390);
|
||||
ASSERT_EQ(len, 3);
|
||||
|
||||
len = smlGetTimestampLen(-1);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(-10);
|
||||
ASSERT_EQ(len, 2);
|
||||
|
||||
len = smlGetTimestampLen(-390);
|
||||
ASSERT_EQ(len, 3);
|
||||
}
|
||||
|
||||
/*
|
||||
TEST(testCase, smlProcess_influx_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists inflx_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists inflx_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use inflx_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[] = {
|
||||
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0 1451606401000000000",
|
||||
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0,fuel_consumption=25 1451607402000000000",
|
||||
|
@ -505,19 +523,20 @@ TEST(testCase, smlProcess_influx_Test) {
|
|||
"stable,t1=t1,t2=t2,t3=t3 c1=1,c2=2,c3=\"kk\",c4=4 1451629501000000000",
|
||||
"stable,t2=t2,t1=t1,t3=t3 c1=1,c3=\"\",c4=4 1451629602000000000",
|
||||
};
|
||||
int ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_EQ(ret, 0);
|
||||
pRes = taos_schemaless_insert(taos, (char**)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL, 0);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
|
||||
// case 1
|
||||
TAOS_RES *res = taos_query(taos, "select * from t_91e0b182be80332b5c530cbf872f760e");
|
||||
ASSERT_NE(res, nullptr);
|
||||
int fieldNum = taos_field_count(res);
|
||||
pRes = taos_query(taos, "select * from t_91e0b182be80332b5c530cbf872f760e");
|
||||
ASSERT_NE(pRes, nullptr);
|
||||
int fieldNum = taos_field_count(pRes);
|
||||
ASSERT_EQ(fieldNum, 11);
|
||||
printf("fieldNum:%d\n", fieldNum);
|
||||
|
||||
TAOS_ROW row = NULL;
|
||||
int32_t rowIndex = 0;
|
||||
while((row = taos_fetch_row(res)) != NULL) {
|
||||
while((row = taos_fetch_row(pRes)) != NULL) {
|
||||
int64_t ts = *(int64_t*)row[0];
|
||||
double load_capacity = *(double*)row[1];
|
||||
double fuel_capacity = *(double*)row[2];
|
||||
|
@ -546,18 +565,18 @@ TEST(testCase, smlProcess_influx_Test) {
|
|||
}
|
||||
rowIndex++;
|
||||
}
|
||||
taos_free_result(res);
|
||||
taos_free_result(pRes);
|
||||
|
||||
// case 2
|
||||
res = taos_query(taos, "select * from t_6885c584b98481584ee13dac399e173d");
|
||||
ASSERT_NE(res, nullptr);
|
||||
fieldNum = taos_field_count(res);
|
||||
pRes = taos_query(taos, "select * from t_6885c584b98481584ee13dac399e173d");
|
||||
ASSERT_NE(pRes, nullptr);
|
||||
fieldNum = taos_field_count(pRes);
|
||||
ASSERT_EQ(fieldNum, 5);
|
||||
printf("fieldNum:%d\n", fieldNum);
|
||||
|
||||
rowIndex = 0;
|
||||
while((row = taos_fetch_row(res)) != NULL) {
|
||||
int *length = taos_fetch_lengths(res);
|
||||
while((row = taos_fetch_row(pRes)) != NULL) {
|
||||
int *length = taos_fetch_lengths(pRes);
|
||||
|
||||
int64_t ts = *(int64_t*)row[0];
|
||||
double c1 = *(double*)row[1];
|
||||
|
@ -580,20 +599,16 @@ TEST(testCase, smlProcess_influx_Test) {
|
|||
}
|
||||
rowIndex++;
|
||||
}
|
||||
taos_free_result(res);
|
||||
taos_free_result(pRes);
|
||||
|
||||
// case 2
|
||||
res = taos_query(taos, "show tables");
|
||||
ASSERT_NE(res, nullptr);
|
||||
pRes = taos_query(taos, "show tables");
|
||||
ASSERT_NE(pRes, nullptr);
|
||||
|
||||
row = taos_fetch_row(res);
|
||||
int rowNum = taos_affected_rows(res);
|
||||
row = taos_fetch_row(pRes);
|
||||
int rowNum = taos_affected_rows(pRes);
|
||||
ASSERT_EQ(rowNum, 5);
|
||||
taos_free_result(res);
|
||||
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
// different types
|
||||
|
@ -601,122 +616,79 @@ TEST(testCase, smlParseLine_error_Test) {
|
|||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[] = {
|
||||
"measure,t1=3 c1=8",
|
||||
"measure,t2=3 c1=8u8"
|
||||
};
|
||||
int ret = smlProcess(info, (char **)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_NE(ret, 0);
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
|
||||
TEST(testCase, smlGetTimestampLen_Test) {
|
||||
uint8_t len = smlGetTimestampLen(0);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(1);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(10);
|
||||
ASSERT_EQ(len, 2);
|
||||
|
||||
len = smlGetTimestampLen(390);
|
||||
ASSERT_EQ(len, 3);
|
||||
|
||||
len = smlGetTimestampLen(-1);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(-10);
|
||||
ASSERT_EQ(len, 2);
|
||||
|
||||
len = smlGetTimestampLen(-390);
|
||||
ASSERT_EQ(len, 3);
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, smlProcess_telnet_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists telnet_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists telnet_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use telnet_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[] = {
|
||||
"sys.if.bytes.out 1479496100 1.3E0 host=web01 interface=eth0",
|
||||
"sys.if.bytes.out 1479496101 1.3E1 interface=eth0 host=web01 ",
|
||||
"sys.if.bytes.out 1479496102 1.3E3 network=tcp",
|
||||
" sys.procs.running 1479496100 42 host=web01 "
|
||||
};
|
||||
int ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
|
||||
// case 1
|
||||
TAOS_RES *res = taos_query(taos, "select * from t_8c30283b3c4131a071d1e16cf6d7094a");
|
||||
ASSERT_NE(res, nullptr);
|
||||
int fieldNum = taos_field_count(res);
|
||||
pRes = taos_query(taos, "select * from t_8c30283b3c4131a071d1e16cf6d7094a");
|
||||
ASSERT_NE(pRes, nullptr);
|
||||
int fieldNum = taos_field_count(pRes);
|
||||
ASSERT_EQ(fieldNum, 2);
|
||||
|
||||
TAOS_ROW row = taos_fetch_row(res);
|
||||
TAOS_ROW row = taos_fetch_row(pRes);
|
||||
int64_t ts = *(int64_t*)row[0];
|
||||
double c1 = *(double*)row[1];
|
||||
ASSERT_EQ(ts, 1479496100000);
|
||||
ASSERT_EQ(c1, 42);
|
||||
|
||||
int rowNum = taos_affected_rows(res);
|
||||
int rowNum = taos_affected_rows(pRes);
|
||||
ASSERT_EQ(rowNum, 1);
|
||||
taos_free_result(res);
|
||||
taos_free_result(pRes);
|
||||
|
||||
// case 2
|
||||
res = taos_query(taos, "show tables");
|
||||
ASSERT_NE(res, nullptr);
|
||||
pRes = taos_query(taos, "show tables");
|
||||
ASSERT_NE(pRes, nullptr);
|
||||
|
||||
row = taos_fetch_row(res);
|
||||
rowNum = taos_affected_rows(res);
|
||||
row = taos_fetch_row(pRes);
|
||||
rowNum = taos_affected_rows(pRes);
|
||||
ASSERT_EQ(rowNum, 3);
|
||||
taos_free_result(res);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, smlProcess_json1_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists json_db");
|
||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists json_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use json_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql =
|
||||
const char *sql[] = {
|
||||
"[\n"
|
||||
" {\n"
|
||||
" \"metric\": \"sys.cpu.nice\",\n"
|
||||
|
@ -724,6 +696,7 @@ TEST(testCase, smlProcess_json1_Test) {
|
|||
" \"value\": 18,\n"
|
||||
" \"tags\": {\n"
|
||||
" \"host\": \"web01\",\n"
|
||||
" \"id\": \"t1\",\n"
|
||||
" \"dc\": \"lga\"\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
|
@ -736,55 +709,48 @@ TEST(testCase, smlProcess_json1_Test) {
|
|||
" \"dc\": \"lga\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"]";
|
||||
int ret = smlProcess(info, (char **)(&sql), 1);
|
||||
ASSERT_EQ(ret, 0);
|
||||
"]"};
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
|
||||
// case 1
|
||||
TAOS_RES *res = taos_query(taos, "select * from t_cb27a7198d637b4f1c6464bd73f756a7");
|
||||
ASSERT_NE(res, nullptr);
|
||||
int fieldNum = taos_field_count(res);
|
||||
pRes = taos_query(taos, "select * from t1");
|
||||
ASSERT_NE(pRes, nullptr);
|
||||
int fieldNum = taos_field_count(pRes);
|
||||
ASSERT_EQ(fieldNum, 2);
|
||||
|
||||
TAOS_ROW row = taos_fetch_row(res);
|
||||
TAOS_ROW row = taos_fetch_row(pRes);
|
||||
int64_t ts = *(int64_t*)row[0];
|
||||
double c1 = *(double*)row[1];
|
||||
ASSERT_EQ(ts, 1346846400000);
|
||||
ASSERT_EQ(c1, 18);
|
||||
|
||||
int rowNum = taos_affected_rows(res);
|
||||
int rowNum = taos_affected_rows(pRes);
|
||||
ASSERT_EQ(rowNum, 1);
|
||||
taos_free_result(res);
|
||||
taos_free_result(pRes);
|
||||
|
||||
// case 2
|
||||
res = taos_query(taos, "show tables");
|
||||
ASSERT_NE(res, nullptr);
|
||||
pRes = taos_query(taos, "show tables");
|
||||
ASSERT_NE(pRes, nullptr);
|
||||
|
||||
row = taos_fetch_row(res);
|
||||
rowNum = taos_affected_rows(res);
|
||||
row = taos_fetch_row(pRes);
|
||||
rowNum = taos_affected_rows(pRes);
|
||||
ASSERT_EQ(rowNum, 2);
|
||||
taos_free_result(res);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, smlProcess_json2_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
const char *sql =
|
||||
const char *sql[] = {
|
||||
"{\n"
|
||||
" \"metric\": \"meter_current0\",\n"
|
||||
" \"timestamp\": {\n"
|
||||
|
@ -806,29 +772,23 @@ TEST(testCase, smlProcess_json2_Test) {
|
|||
" },\n"
|
||||
" \"id\": \"d1001\"\n"
|
||||
" }\n"
|
||||
"}";
|
||||
int32_t ret = smlProcess(info, (char **)(&sql), -1);
|
||||
ASSERT_EQ(ret, 0);
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
"}"};
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, smlProcess_json3_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
const char *sql =
|
||||
const char *sql[] ={
|
||||
"{\n"
|
||||
" \"metric\": \"meter_current1\",\n"
|
||||
" \"timestamp\": {\n"
|
||||
|
@ -878,29 +838,23 @@ TEST(testCase, smlProcess_json3_Test) {
|
|||
" },\n"
|
||||
" \"id\": \"d1001\"\n"
|
||||
" }\n"
|
||||
"}";
|
||||
int32_t ret = smlProcess(info, (char **)(&sql), -1);
|
||||
ASSERT_EQ(ret, 0);
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
"}"};
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, smlProcess_json4_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
const char *sql = "{\n"
|
||||
const char *sql[] = {"{\n"
|
||||
" \"metric\": \"meter_current2\",\n"
|
||||
" \"timestamp\": {\n"
|
||||
" \"value\" : 1346846500000,\n"
|
||||
|
@ -940,18 +894,17 @@ TEST(testCase, smlProcess_json4_Test) {
|
|||
" \"t9\": false,\n"
|
||||
" \"id\": \"d1001\"\n"
|
||||
" }\n"
|
||||
"}";
|
||||
int32_t ret = smlProcess(info, (char**)(&sql), -1);
|
||||
ASSERT_EQ(ret, 0);
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
"}"};
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseTelnetLine_error_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
|
@ -1000,34 +953,27 @@ TEST(testCase, smlParseTelnetLine_diff_type_Test) {
|
|||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[2] = {
|
||||
"sys.procs.running 1479496104000 42 host=web01",
|
||||
"sys.procs.running 1479496104000 42u8 host=web01"
|
||||
};
|
||||
int32_t ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_NE(ret, 0);
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseTelnetLine_json_error_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
|
@ -1095,19 +1041,13 @@ TEST(testCase, smlParseTelnetLine_diff_json_type1_Test) {
|
|||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[2] = {
|
||||
const char *sql[] = {
|
||||
"[\n"
|
||||
" {\n"
|
||||
" \"metric\": \"sys.cpu.nice\",\n"
|
||||
|
@ -1129,30 +1069,22 @@ TEST(testCase, smlParseTelnetLine_diff_json_type1_Test) {
|
|||
" },\n"
|
||||
"]",
|
||||
};
|
||||
int32_t ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[2] = {
|
||||
const char *sql[] = {
|
||||
"[\n"
|
||||
" {\n"
|
||||
" \"metric\": \"sys.cpu.nice\",\n"
|
||||
|
@ -1174,90 +1106,64 @@ TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) {
|
|||
" },\n"
|
||||
"]",
|
||||
};
|
||||
int32_t ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_TD15662_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists db_15662 precision 'ns'");
|
||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists db_15662 precision 'ns' schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use db_15662");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[] = {
|
||||
"hetrey c0=f,c1=127i8 1626006833639",
|
||||
"hetrey,t1=r c0=f,c1=127i8 1626006833640",
|
||||
};
|
||||
int ret = smlProcess(info, (char **)sql, sizeof(sql) / sizeof(sql[0]));
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_TD15735_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[1] = {
|
||||
"{'metric': 'pekoiw', 'timestamp': {'value': 1626006833639000000, 'type': 'ns'}, 'value': {'value': False, 'type': 'bool'}, 'tags': {'t0': {'value': True, 'type': 'bool'}, 't1': {'value': 127, 'type': 'tinyint'}, 't2': {'value': 32767, 'type': 'smallint'}, 't3': {'value': 2147483647, 'type': 'int'}, 't4': {'value': 9223372036854775807, 'type': 'bigint'}, 't5': {'value': 11.12345027923584, 'type': 'float'}, 't6': {'value': 22.123456789, 'type': 'double'}, 't7': {'value': 'binaryTagValue', 'type': 'binary'}, 't8': {'value': 'ncharTagValue', 'type': 'nchar'}}}",
|
||||
};
|
||||
int32_t ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_NE(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_TD15742_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists TD15742");
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists TD15742 schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use TD15742");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[] = {
|
||||
"test_ms,t0=t c0=f 1626006833641",
|
||||
};
|
||||
int ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_params_Test) {
|
||||
|
@ -1272,14 +1178,40 @@ TEST(testCase, sml_params_Test) {
|
|||
};
|
||||
TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, 1, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_EQ(taos_errno(res), TSDB_CODE_PAR_DB_NOT_SPECIFIED);
|
||||
taos_free_result(pRes);
|
||||
taos_free_result(res);
|
||||
|
||||
pRes = taos_query(taos, "use param");
|
||||
taos_free_result(pRes);
|
||||
taos_free_result(res);
|
||||
|
||||
res = taos_schemaless_insert(taos, (char**)sql, 1, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_EQ(taos_errno(res), TSDB_CODE_SML_INVALID_DB_CONF);
|
||||
taos_free_result(res);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_16384_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists d16384 schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
const char *sql[] = {
|
||||
"qelhxo,id=pnnqhsa,t0=t,t1=127i8 c0=t,c1=127i8 1626006833639000000",
|
||||
};
|
||||
|
||||
pRes = taos_query(taos, "use d16384");
|
||||
taos_free_result(pRes);
|
||||
|
||||
TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, 1, TSDB_SML_LINE_PROTOCOL, 0);
|
||||
ASSERT_EQ(taos_errno(res), 0);
|
||||
taos_free_result(res);
|
||||
|
||||
const char *sql1[] = {
|
||||
"qelhxo,id=pnnqhsa,t0=t,t1=127i8 c0=f,c1=127i8,c11=L\"ncharColValue\",c10=t 1626006833639000000",
|
||||
};
|
||||
TAOS_RES* res1 = taos_schemaless_insert(taos, (char**)sql1, 1, TSDB_SML_LINE_PROTOCOL, 0);
|
||||
ASSERT_EQ(taos_errno(res1), 0);
|
||||
taos_free_result(res1);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_oom_Test) {
|
||||
|
@ -1299,7 +1231,33 @@ TEST(testCase, sml_oom_Test) {
|
|||
pRes = taos_query(taos, "use oom");
|
||||
taos_free_result(pRes);
|
||||
|
||||
TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, 100, TSDB_SML_LINE_PROTOCOL, 0);
|
||||
ASSERT_EQ(taos_errno(res), 0);
|
||||
pRes = taos_schemaless_insert(taos, (char**)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL, 0);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_16368_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists d16368 schemaless 1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use d16368");
|
||||
taos_free_result(pRes);
|
||||
|
||||
const char *sql[] = {
|
||||
"[{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833639000, \"type\": \"us\"}, \"value\": 1, \"tags\": {\"t1\": 3, \"t2\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t3\", \"type\": \"binary\"}}},\n"
|
||||
"{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833739000, \"type\": \"us\"}, \"value\": 2, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},\n"
|
||||
"{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006833639100, \"type\": \"us\"}, \"value\": 3, \"tags\": {\"t2\": {\"value\": 5, \"type\": \"double\"}, \"t3\": {\"value\": \"ste\", \"type\": \"nchar\"}}},\n"
|
||||
"{\"metric\": \"stf567890\", \"timestamp\": {\"value\": 1626006833639200, \"type\": \"us\"}, \"value\": 4, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"bigint\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},\n"
|
||||
"{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833639300, \"type\": \"us\"}, \"value\": {\"value\": 5, \"type\": \"double\"}, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t2\": 5.0, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}}},\n"
|
||||
"{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006833639400, \"type\": \"us\"}, \"value\": {\"value\": 6, \"type\": \"double\"}, \"tags\": {\"t2\": 5.0, \"t3\": {\"value\": \"ste2\", \"type\": \"nchar\"}}},\n"
|
||||
"{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006834639400, \"type\": \"us\"}, \"value\": {\"value\": 7, \"type\": \"double\"}, \"tags\": {\"t2\": {\"value\": 5.0, \"type\": \"double\"}, \"t3\": {\"value\": \"ste2\", \"type\": \"nchar\"}}},\n"
|
||||
"{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833839006, \"type\": \"us\"}, \"value\": {\"value\": 8, \"type\": \"double\"}, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},\n"
|
||||
"{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833939007, \"type\": \"us\"}, \"value\": {\"value\": 9, \"type\": \"double\"}, \"tags\": {\"t1\": 4, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}}]"
|
||||
};
|
||||
pRes = taos_schemaless_insert(taos, (char**)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_MICRO_SECONDS);
|
||||
ASSERT_EQ(taos_errno(pRes), 0);
|
||||
taos_free_result(pRes);
|
||||
}*/
|
||||
|
|
|
@ -91,7 +91,7 @@ static const SSysDbTableSchema userDBSchema[] = {
|
|||
{.name = "precision", .bytes = 2 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "single_stable_model", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL},
|
||||
{.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "schemaless", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL},
|
||||
// {.name = "schemaless", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL},
|
||||
{.name = "retension", .bytes = 60 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
|
||||
// {.name = "update", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, // disable update
|
||||
|
@ -175,7 +175,7 @@ static const SSysDbTableSchema userUsersSchema[] = {
|
|||
};
|
||||
|
||||
static const SSysDbTableSchema grantsSchema[] = {
|
||||
{.name = "version", .bytes = 8 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "version", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "expire time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "storage(GB)", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
|
@ -221,7 +221,7 @@ static const SSysDbTableSchema transSchema[] = {
|
|||
{.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "failed_times", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
{.name = "last_error", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "last_action_info", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema configSchema[] = {
|
||||
|
|
|
@ -294,7 +294,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, in
|
|||
|
||||
int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows) {
|
||||
ASSERT(pColumnInfoData != NULL && pSource != NULL && pColumnInfoData->info.type == pSource->info.type);
|
||||
if (numOfRows == 0) {
|
||||
if (numOfRows <= 0) {
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
|
@ -682,9 +682,10 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock) {
|
|||
* @param pBlock
|
||||
* @return
|
||||
*/
|
||||
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) {
|
||||
// | total rows/total length | block group id | each column length |
|
||||
return sizeof(int32_t) + sizeof(uint64_t) + pBlock->info.numOfCols * sizeof(int32_t);
|
||||
size_t blockDataGetSerialMetaSize(uint32_t numOfCols) {
|
||||
// | total rows/total length | block group id | column schema | each column length |
|
||||
return sizeof(int32_t) + sizeof(uint64_t) + numOfCols * (sizeof(int16_t) + sizeof(int32_t)) +
|
||||
numOfCols * sizeof(int32_t);
|
||||
}
|
||||
|
||||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
||||
|
@ -1131,6 +1132,7 @@ int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, size_t existRows, ui
|
|||
|
||||
if (IS_VAR_DATA_TYPE(pColumn->info.type)) {
|
||||
char* tmp = taosMemoryRealloc(pColumn->varmeta.offset, sizeof(int32_t) * numOfRows);
|
||||
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -1156,6 +1158,7 @@ int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, size_t existRows, ui
|
|||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
memset(tmp + pColumn->info.bytes * existRows, 0, pColumn->info.bytes * (numOfRows - existRows));
|
||||
|
||||
pColumn->pData = tmp;
|
||||
}
|
||||
|
@ -1214,7 +1217,10 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) {
|
|||
|
||||
pBlock->info.numOfCols = numOfCols;
|
||||
pBlock->info.hasVarCol = pDataBlock->info.hasVarCol;
|
||||
pBlock->info.rowSize = pDataBlock->info.rows;
|
||||
pBlock->info.rowSize = pDataBlock->info.rowSize;
|
||||
pBlock->info.groupId = pDataBlock->info.groupId;
|
||||
pBlock->info.childId = pDataBlock->info.childId;
|
||||
pBlock->info.type = pDataBlock->info.type;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData colInfo = {0};
|
||||
|
@ -1233,6 +1239,9 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (pSrc->pData == NULL) {
|
||||
continue;
|
||||
}
|
||||
colDataAssign(pDst, pSrc, pDataBlock->info.rows);
|
||||
}
|
||||
|
||||
|
@ -1244,7 +1253,7 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) {
|
|||
}
|
||||
|
||||
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) {
|
||||
int32_t payloadSize = pageSize - blockDataGetSerialMetaSize(pBlock);
|
||||
int32_t payloadSize = pageSize - blockDataGetSerialMetaSize(pBlock->info.numOfCols);
|
||||
|
||||
int32_t rowSize = pBlock->info.rowSize;
|
||||
|
||||
|
@ -1269,12 +1278,12 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) {
|
|||
|
||||
void colDataDestroy(SColumnInfoData* pColData) {
|
||||
if (IS_VAR_DATA_TYPE(pColData->info.type)) {
|
||||
taosMemoryFree(pColData->varmeta.offset);
|
||||
taosMemoryFreeClear(pColData->varmeta.offset);
|
||||
} else {
|
||||
taosMemoryFree(pColData->nullbitmap);
|
||||
taosMemoryFreeClear(pColData->nullbitmap);
|
||||
}
|
||||
|
||||
taosMemoryFree(pColData->pData);
|
||||
taosMemoryFreeClear(pColData->pData);
|
||||
}
|
||||
|
||||
static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
|
||||
|
@ -1495,12 +1504,13 @@ void blockDebugShowData(const SArray* dataBlocks, const char* flag) {
|
|||
SSDataBlock* pDataBlock = taosArrayGet(dataBlocks, i);
|
||||
int32_t colNum = pDataBlock->info.numOfCols;
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
printf("%s |block type %d |child id %d|\n", flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId);
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
printf("%s |", flag);
|
||||
for (int32_t k = 0; k < colNum; k++) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||
if (pColInfoData->hasNull) {
|
||||
if (colDataIsNull(pColInfoData, rows, j, NULL)) {
|
||||
printf(" %15s |", "NULL");
|
||||
continue;
|
||||
}
|
||||
|
@ -1624,6 +1634,10 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
break;
|
||||
default:
|
||||
if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) {
|
||||
if (pCol->type == pColInfoData->info.type) {
|
||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, var, true, offset,
|
||||
k);
|
||||
} else {
|
||||
char tv[8] = {0};
|
||||
if (pColInfoData->info.type == TSDB_DATA_TYPE_FLOAT) {
|
||||
float v = 0;
|
||||
|
@ -1642,7 +1656,9 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
GET_TYPED_DATA(v, uint64_t, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
}
|
||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, tv, true, offset, k);
|
||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, tv, true, offset,
|
||||
k);
|
||||
}
|
||||
} else {
|
||||
uError("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type);
|
||||
TASSERT(0);
|
||||
|
@ -1748,7 +1764,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
taosArrayClear(tagArray);
|
||||
taosArrayPush(tagArray, &tagVal);
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (!pTag) {
|
||||
if (pTag == NULL) {
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
return NULL;
|
||||
|
@ -1759,9 +1775,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code);
|
||||
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
|
||||
if (code < 0) {
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1771,6 +1785,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
}
|
||||
|
||||
// assign data
|
||||
// TODO
|
||||
ret = taosMemoryCalloc(1, cap + 46);
|
||||
ret = POINTER_SHIFT(ret, 46);
|
||||
ret->header.vgId = vgId;
|
||||
|
@ -1800,8 +1815,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
int32_t schemaLen = 0;
|
||||
if (createTb) {
|
||||
SVCreateTbReq createTbReq = {0};
|
||||
char* cname = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
|
||||
snprintf(cname, TSDB_TABLE_FNAME_LEN, "%s:%ld", stbFullName, pDataBlock->info.groupId);
|
||||
char* cname = buildCtbNameByGroupId(stbFullName, pDataBlock->info.groupId);
|
||||
createTbReq.name = cname;
|
||||
createTbReq.flags = 0;
|
||||
createTbReq.type = TSDB_CHILD_TABLE;
|
||||
|
@ -1815,7 +1829,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
taosArrayPush(tagArray, &tagVal);
|
||||
STag* pTag = NULL;
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (!pTag) {
|
||||
if (pTag == NULL) {
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
taosMemoryFreeClear(ret);
|
||||
|
@ -1883,33 +1897,43 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
|
||||
void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols,
|
||||
int8_t needCompress) {
|
||||
// todo extract method
|
||||
int32_t* actualLen = (int32_t*)data;
|
||||
data += sizeof(int32_t);
|
||||
|
||||
uint64_t* groupId = (uint64_t*)data;
|
||||
data += sizeof(uint64_t);
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
*((int16_t*)data) = pColInfoData->info.type;
|
||||
data += sizeof(int16_t);
|
||||
|
||||
*((int32_t*)data) = pColInfoData->info.bytes;
|
||||
data += sizeof(int32_t);
|
||||
}
|
||||
|
||||
int32_t* colSizes = (int32_t*)data;
|
||||
data += numOfCols * sizeof(int32_t);
|
||||
|
||||
*dataLen = (numOfCols * sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t));
|
||||
*dataLen = blockDataGetSerialMetaSize(numOfCols);
|
||||
|
||||
int32_t numOfRows = pBlock->info.rows;
|
||||
for (int32_t col = 0; col < numOfCols; ++col) {
|
||||
SColumnInfoData* pColRes = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, col);
|
||||
|
||||
// copy the null bitmap
|
||||
size_t metaSize = 0;
|
||||
if (IS_VAR_DATA_TYPE(pColRes->info.type)) {
|
||||
size_t metaSize = numOfRows * sizeof(int32_t);
|
||||
metaSize = numOfRows * sizeof(int32_t);
|
||||
memcpy(data, pColRes->varmeta.offset, metaSize);
|
||||
} else {
|
||||
metaSize = BitmapLen(numOfRows);
|
||||
memcpy(data, pColRes->nullbitmap, metaSize);
|
||||
}
|
||||
|
||||
data += metaSize;
|
||||
(*dataLen) += metaSize;
|
||||
} else {
|
||||
int32_t len = BitmapLen(numOfRows);
|
||||
memcpy(data, pColRes->nullbitmap, len);
|
||||
data += len;
|
||||
(*dataLen) += len;
|
||||
}
|
||||
|
||||
if (needCompress) {
|
||||
colSizes[col] = blockCompressColData(pColRes, numOfRows, data, needCompress);
|
||||
|
@ -1931,6 +1955,7 @@ void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen
|
|||
|
||||
const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t numOfRows, const char* pData) {
|
||||
blockDataEnsureCapacity(pBlock, numOfRows);
|
||||
|
||||
const char* pStart = pData;
|
||||
|
||||
int32_t dataLen = *(int32_t*)pStart;
|
||||
|
@ -1939,6 +1964,29 @@ const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t
|
|||
pBlock->info.groupId = *(uint64_t*)pStart;
|
||||
pStart += sizeof(uint64_t);
|
||||
|
||||
if (pBlock->pDataBlock == NULL) {
|
||||
pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||
taosArraySetSize(pBlock->pDataBlock, numOfCols);
|
||||
}
|
||||
|
||||
pBlock->info.numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||
ASSERT(pBlock->pDataBlock->size >= numOfCols);
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
pColInfoData->info.type = *(int16_t*)pStart;
|
||||
pStart += sizeof(int16_t);
|
||||
|
||||
pColInfoData->info.bytes = *(int32_t*)pStart;
|
||||
pStart += sizeof(int32_t);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||
pBlock->info.hasVarCol = true;
|
||||
}
|
||||
}
|
||||
|
||||
blockDataEnsureCapacity(pBlock, numOfRows);
|
||||
|
||||
int32_t* colLen = (int32_t*)pStart;
|
||||
pStart += sizeof(int32_t) * numOfCols;
|
||||
|
||||
|
@ -1959,11 +2007,17 @@ const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t
|
|||
pColInfoData->pData = taosMemoryMalloc(colLen[i]);
|
||||
}
|
||||
} else {
|
||||
if (pColInfoData->nullbitmap == NULL) {
|
||||
pColInfoData->nullbitmap = taosMemoryCalloc(1, BitmapLen(numOfRows));
|
||||
}
|
||||
memcpy(pColInfoData->nullbitmap, pStart, BitmapLen(numOfRows));
|
||||
pStart += BitmapLen(numOfRows);
|
||||
}
|
||||
|
||||
if (colLen[i] > 0) {
|
||||
if (pColInfoData->pData == NULL) {
|
||||
pColInfoData->pData = taosMemoryCalloc(1, colLen[i]);
|
||||
}
|
||||
memcpy(pColInfoData->pData, pStart, colLen[i]);
|
||||
}
|
||||
|
||||
|
@ -1974,6 +2028,7 @@ const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t
|
|||
pStart += colLen[i];
|
||||
}
|
||||
|
||||
pBlock->info.rows = numOfRows;
|
||||
ASSERT(pStart - pData == dataLen);
|
||||
return pStart;
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
|
|||
if (iColumn == 0) {
|
||||
ASSERT(pColVal->cid == pTColumn->colId);
|
||||
ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
ASSERT(pTColumn->colId == 0);
|
||||
ASSERT(pTColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
|
||||
iColVal++;
|
||||
} else {
|
||||
|
@ -268,6 +268,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
|
|||
nDataT = BIT2_SIZE(pTSchema->numOfCols - 1) + pTSchema->flen + ntv;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
|
@ -283,7 +284,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
|
|||
tflags |= TSROW_KV_BIG;
|
||||
}
|
||||
|
||||
if (nDataT < nDataK) {
|
||||
if (nDataT <= nDataK) {
|
||||
nData = nDataT;
|
||||
} else {
|
||||
nData = nDataK;
|
||||
|
@ -352,7 +353,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
|
|||
ntv = 0;
|
||||
iColVal = 1;
|
||||
|
||||
if (flags & 0xf0 == 0) {
|
||||
if ((flags & 0xf0) == 0) {
|
||||
switch (flags & 0xf) {
|
||||
case TSROW_HAS_VAL:
|
||||
pf = (*ppRow)->pData;
|
||||
|
@ -374,6 +375,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
|
|||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
pTSKVRow = (STSKVRow *)(*ppRow)->pData;
|
||||
|
@ -417,14 +419,28 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
|
|||
}
|
||||
|
||||
_set_none:
|
||||
if (flags & 0xf0 == 0) {
|
||||
if ((flags & 0xf0) == 0) {
|
||||
setBitMap(pb, 0, iColumn - 1, flags);
|
||||
if (flags & TSROW_HAS_VAL) { // set 0
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
*(VarDataOffsetT *)(pf + pTColumn->offset) = 0;
|
||||
} else {
|
||||
tPutValue(pf + pTColumn->offset, &((SValue){0}), pTColumn->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
||||
_set_null:
|
||||
if (flags & 0xf0 == 0) {
|
||||
if ((flags & 0xf0) == 0) {
|
||||
setBitMap(pb, 1, iColumn - 1, flags);
|
||||
if (flags & TSROW_HAS_VAL) { // set 0
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
*(VarDataOffsetT *)(pf + pTColumn->offset) = 0;
|
||||
} else {
|
||||
tPutValue(pf + pTColumn->offset, &((SValue){0}), pTColumn->type);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SET_IDX(pidx, pTSKVRow->nCols, nkv, flags);
|
||||
pTSKVRow->nCols++;
|
||||
|
@ -433,7 +449,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S
|
|||
continue;
|
||||
|
||||
_set_value:
|
||||
if (flags & 0xf0 == 0) {
|
||||
if ((flags & 0xf0) == 0) {
|
||||
setBitMap(pb, 2, iColumn - 1, flags);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
|
@ -489,7 +505,7 @@ void tTSRowFree(STSRow2 *pRow) {
|
|||
}
|
||||
|
||||
void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) {
|
||||
uint8_t isTuple = (pRow->flags & 0xf0 == 0) ? 1 : 0;
|
||||
uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0;
|
||||
STColumn *pTColumn = &pTSchema->columns[iCol];
|
||||
uint8_t flags = pRow->flags & (uint8_t)0xf;
|
||||
SValue value;
|
||||
|
@ -505,7 +521,7 @@ void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal
|
|||
|
||||
if (flags == TSROW_HAS_NONE) {
|
||||
goto _return_none;
|
||||
} else if (flags == TSROW_HAS_NONE) {
|
||||
} else if (flags == TSROW_HAS_NULL) {
|
||||
goto _return_null;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ bool tsSmlDataFormat =
|
|||
|
||||
// query
|
||||
int32_t tsQueryPolicy = 1;
|
||||
int32_t tsQuerySmaOptimize = 1;
|
||||
|
||||
/*
|
||||
* denote if the server needs to compress response message at the application layer to client, including query rsp,
|
||||
|
@ -331,8 +332,9 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
|||
if (cfgAddInt32(pCfg, "compressColData", tsCompressColData, -1, 100000000, 1) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "keepColumnName", tsKeepOriginalColumnName, 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "queryPolicy", tsQueryPolicy, 1, 3, 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "querySmaOptimize", tsQuerySmaOptimize, 0, 1, 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "smlChildTableName", "", 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "smlTagNullName", tsSmlTagName, 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "smlTagName", tsSmlTagName, 1) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "smlDataFormat", tsSmlDataFormat, 1) != 0) return -1;
|
||||
|
||||
tsNumOfTaskQueueThreads = tsNumOfCores / 4;
|
||||
|
@ -532,7 +534,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
}
|
||||
|
||||
tstrncpy(tsSmlChildTableName, cfgGetItem(pCfg, "smlChildTableName")->str, TSDB_TABLE_NAME_LEN);
|
||||
tstrncpy(tsSmlTagName, cfgGetItem(pCfg, "smlTagNullName")->str, TSDB_COL_NAME_LEN);
|
||||
tstrncpy(tsSmlTagName, cfgGetItem(pCfg, "smlTagName")->str, TSDB_COL_NAME_LEN);
|
||||
tsSmlDataFormat = cfgGetItem(pCfg, "smlDataFormat")->bval;
|
||||
|
||||
tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32;
|
||||
|
@ -541,6 +543,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
tsKeepOriginalColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
||||
tsNumOfTaskQueueThreads = cfgGetItem(pCfg, "numOfTaskQueueThreads")->i32;
|
||||
tsQueryPolicy = cfgGetItem(pCfg, "queryPolicy")->i32;
|
||||
tsQuerySmaOptimize = cfgGetItem(pCfg, "querySmaOptimize")->i32;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -2394,6 +2394,113 @@ int32_t tDeserializeSUserIndexRsp(void *buf, int32_t bufLen, SUserIndexRsp *pRsp
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSTableIndexReq(void *buf, int32_t bufLen, STableIndexReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->tbFName) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSTableIndexReq(void *buf, int32_t bufLen, STableIndexReq *pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->tbFName) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSTableIndexInfo(SEncoder *pEncoder, STableIndexInfo *pInfo) {
|
||||
if (tEncodeI8(pEncoder, pInfo->intervalUnit) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pInfo->slidingUnit) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pInfo->interval) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pInfo->offset) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pInfo->sliding) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pInfo->dstTbUid) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pInfo->dstVgId) < 0) return -1;
|
||||
if (tEncodeSEpSet(pEncoder, &pInfo->epSet) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pInfo->expr) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSTableIndexRsp(void *buf, int32_t bufLen, const STableIndexRsp *pRsp) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
int32_t num = taosArrayGetSize(pRsp->pIndex);
|
||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||
if (num > 0) {
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
STableIndexInfo *pInfo = (STableIndexInfo *)taosArrayGet(pRsp->pIndex, i);
|
||||
if (tSerializeSTableIndexInfo(&encoder, pInfo) < 0) return -1;
|
||||
}
|
||||
}
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSTableIndexInfo(SDecoder *pDecoder, STableIndexInfo *pInfo) {
|
||||
if (tDecodeI8(pDecoder, &pInfo->intervalUnit) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pInfo->slidingUnit) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pInfo->interval) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pInfo->offset) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pInfo->sliding) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pInfo->dstTbUid) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pInfo->dstVgId) < 0) return -1;
|
||||
if (tDecodeSEpSet(pDecoder, &pInfo->epSet) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pInfo->expr) < 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSTableIndexRsp(void *buf, int32_t bufLen, STableIndexRsp *pRsp) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
int32_t num = 0;
|
||||
if (tDecodeI32(&decoder, &num) < 0) return -1;
|
||||
if (num > 0) {
|
||||
pRsp->pIndex = taosArrayInit(num, sizeof(STableIndexInfo));
|
||||
if (NULL == pRsp->pIndex) return -1;
|
||||
STableIndexInfo info;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
if (tDeserializeSTableIndexInfo(&decoder, &info) < 0) return -1;
|
||||
if (NULL == taosArrayPush(pRsp->pIndex, &info)) {
|
||||
taosMemoryFree(info.expr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSTableIndexInfo(void *info) {
|
||||
if (NULL == info) {
|
||||
return;
|
||||
}
|
||||
|
||||
STableIndexInfo *pInfo = (STableIndexInfo *)info;
|
||||
|
||||
taosMemoryFree(pInfo->expr);
|
||||
}
|
||||
|
||||
int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
@ -3341,6 +3448,31 @@ int32_t tDeserializeSRedistributeVgroupReq(void *buf, int32_t bufLen, SRedistrib
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSSplitVgroupReq(void *buf, int32_t bufLen, SSplitVgroupReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSSplitVgroupReq(void *buf, int32_t bufLen, SSplitVgroupReq *pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
@ -3745,9 +3877,10 @@ int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) {
|
|||
if (tEncodeCStr(pCoder, pSma->indexName) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pSma->exprLen) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pSma->tagsFilterLen) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pSma->numOfVgroups) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pSma->indexUid) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pSma->tableUid) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pSma->dstTbUid) < 0) return -1;
|
||||
if (tEncodeCStr(pCoder, pSma->dstTbName) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pSma->interval) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pSma->offset) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pSma->sliding) < 0) return -1;
|
||||
|
@ -3757,17 +3890,10 @@ int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) {
|
|||
if (pSma->tagsFilterLen > 0) {
|
||||
if (tEncodeCStr(pCoder, pSma->tagsFilter) < 0) return -1;
|
||||
}
|
||||
for (int32_t v = 0; v < pSma->numOfVgroups; ++v) {
|
||||
if (tEncodeI32(pCoder, pSma->pVgEpSet[v].vgId) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pSma->pVgEpSet[v].epSet.inUse) < 0) return -1;
|
||||
int8_t numOfEps = pSma->pVgEpSet[v].epSet.numOfEps;
|
||||
if (tEncodeI8(pCoder, numOfEps) < 0) return -1;
|
||||
for (int32_t n = 0; n < numOfEps; ++n) {
|
||||
const SEp *pEp = &pSma->pVgEpSet[v].epSet.eps[n];
|
||||
if (tEncodeCStr(pCoder, pEp->fqdn) < 0) return -1;
|
||||
if (tEncodeU16(pCoder, pEp->port) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tEncodeSSchemaWrapper(pCoder, &pSma->schemaRow);
|
||||
tEncodeSSchemaWrapper(pCoder, &pSma->schemaTag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3775,14 +3901,15 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma) {
|
|||
if (tDecodeI8(pCoder, &pSma->version) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->intervalUnit) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->slidingUnit) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pSma->dstVgId) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->timezoneInt) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pSma->dstVgId) < 0) return -1;
|
||||
if (tDecodeCStrTo(pCoder, pSma->indexName) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pSma->exprLen) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pSma->tagsFilterLen) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pSma->numOfVgroups) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pSma->indexUid) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pSma->tableUid) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pSma->dstTbUid) < 0) return -1;
|
||||
if (tDecodeCStr(pCoder, &pSma->dstTbName) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pSma->interval) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pSma->offset) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pSma->sliding) < 0) return -1;
|
||||
|
@ -3796,27 +3923,9 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma) {
|
|||
} else {
|
||||
pSma->tagsFilter = NULL;
|
||||
}
|
||||
if (pSma->numOfVgroups > 0) {
|
||||
pSma->pVgEpSet = (SVgEpSet *)tDecoderMalloc(pCoder, pSma->numOfVgroups * sizeof(SVgEpSet));
|
||||
if (!pSma->pVgEpSet) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(pSma->pVgEpSet, 0, pSma->numOfVgroups * sizeof(SVgEpSet));
|
||||
|
||||
for (int32_t v = 0; v < pSma->numOfVgroups; ++v) {
|
||||
if (tDecodeI32(pCoder, &pSma->pVgEpSet[v].vgId) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->pVgEpSet[v].epSet.inUse) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->pVgEpSet[v].epSet.numOfEps) < 0) return -1;
|
||||
int8_t numOfEps = pSma->pVgEpSet[v].epSet.numOfEps;
|
||||
for (int32_t n = 0; n < numOfEps; ++n) {
|
||||
SEp *pEp = &pSma->pVgEpSet[v].epSet.eps[n];
|
||||
if (tDecodeCStrTo(pCoder, pEp->fqdn) < 0) return -1;
|
||||
if (tDecodeU16(pCoder, &pEp->port) < 0) return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// only needed in dstVgroup
|
||||
tDecodeSSchemaWrapperEx(pCoder, &pSma->schemaRow);
|
||||
tDecodeSSchemaWrapperEx(pCoder, &pSma->schemaTag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3859,55 +3968,6 @@ int32_t tDecodeSVDropTSmaReq(SDecoder *pCoder, SVDropTSmaReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVGetTSmaExpWndsReq(SEncoder *pCoder, const SVGetTsmaExpWndsReq *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pReq->indexUid) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->queryWindow.skey) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->queryWindow.ekey) < 0) return -1;
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVGetTsmaExpWndsReq(SDecoder *pCoder, SVGetTsmaExpWndsReq *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI64(pCoder, &pReq->indexUid) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->queryWindow.skey) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->queryWindow.ekey) < 0) return -1;
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVGetTSmaExpWndsRsp(SEncoder *pCoder, const SVGetTsmaExpWndsRsp *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pReq->indexUid) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pReq->flags) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pReq->numExpWnds) < 0) return -1;
|
||||
for (int32_t i = 0; i < pReq->numExpWnds; ++i) {
|
||||
if (tEncodeI64(pCoder, pReq->wndSKeys[i]) < 0) return -1;
|
||||
}
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVGetTsmaExpWndsRsp(SDecoder *pCoder, SVGetTsmaExpWndsRsp *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI64(pCoder, &pReq->indexUid) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pReq->flags) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pReq->numExpWnds) < 0) return -1;
|
||||
for (int32_t i = 0; i < pReq->numExpWnds; ++i) {
|
||||
if (tDecodeI64(pCoder, &pReq->wndSKeys[i]) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) {
|
||||
int32_t headLen = sizeof(SMsgHead);
|
||||
if (buf != NULL) {
|
||||
|
|
|
@ -76,22 +76,22 @@ void deltaToUtcInitOnce() {
|
|||
|
||||
static int64_t parseFraction(char* str, char** end, int32_t timePrec);
|
||||
static int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim);
|
||||
static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec);
|
||||
static int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec);
|
||||
static int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec);
|
||||
static int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec);
|
||||
static char* forwardToTimeStringEnd(char* str);
|
||||
static bool checkTzPresent(const char* str, int32_t len);
|
||||
|
||||
static int32_t (*parseLocaltimeFp[])(char* timestr, int64_t* time, int32_t timePrec) = {parseLocaltime,
|
||||
static int32_t (*parseLocaltimeFp[])(char* timestr, int32_t len, int64_t* utime, int32_t timePrec) = {parseLocaltime,
|
||||
parseLocaltimeDst};
|
||||
|
||||
int32_t taosParseTime(const char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) {
|
||||
int32_t taosParseTime(const char* timestr, int64_t* utime, int32_t len, int32_t timePrec, int8_t day_light) {
|
||||
/* parse datatime string in with tz */
|
||||
if (strnchr(timestr, 'T', len, false) != NULL) {
|
||||
return parseTimeWithTz(timestr, time, timePrec, 'T');
|
||||
return parseTimeWithTz(timestr, utime, timePrec, 'T');
|
||||
} else if (checkTzPresent(timestr, len)) {
|
||||
return parseTimeWithTz(timestr, time, timePrec, 0);
|
||||
return parseTimeWithTz(timestr, utime, timePrec, 0);
|
||||
} else {
|
||||
return (*parseLocaltimeFp[day_light])((char*)timestr, time, timePrec);
|
||||
return (*parseLocaltimeFp[day_light])((char*)timestr, len, utime, timePrec);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,12 +309,36 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
|
||||
static FORCE_INLINE bool validateTm(struct tm* pTm) {
|
||||
if (pTm == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t dayOfMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
|
||||
int32_t leapYearMonthDay = 29;
|
||||
int32_t year = pTm->tm_year + 1900;
|
||||
bool isLeapYear = ((year % 100) == 0)? ((year % 400) == 0):((year % 4) == 0);
|
||||
|
||||
if (isLeapYear && (pTm->tm_mon == 1)) {
|
||||
if (pTm->tm_mday > leapYearMonthDay) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (pTm->tm_mday > dayOfMonth[pTm->tm_mon]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t parseLocaltime(char* timestr, int32_t len, int64_t* time, int32_t timePrec) {
|
||||
*time = 0;
|
||||
struct tm tm = {0};
|
||||
|
||||
char* str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
if (str == NULL) {
|
||||
if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -343,13 +367,13 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) {
|
||||
int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t timePrec) {
|
||||
*time = 0;
|
||||
struct tm tm = {0};
|
||||
tm.tm_isdst = -1;
|
||||
|
||||
char* str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
if (str == NULL) {
|
||||
if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "tcompression.h"
|
||||
#include "trow.h"
|
||||
|
||||
const int32_t TYPE_BYTES[15] = {
|
||||
const int32_t TYPE_BYTES[16] = {
|
||||
-1, // TSDB_DATA_TYPE_NULL
|
||||
CHAR_BYTES, // TSDB_DATA_TYPE_BOOL
|
||||
CHAR_BYTES, // TSDB_DATA_TYPE_TINYINT
|
||||
|
@ -34,6 +34,7 @@ const int32_t TYPE_BYTES[15] = {
|
|||
SHORT_BYTES, // TSDB_DATA_TYPE_USMALLINT
|
||||
INT_BYTES, // TSDB_DATA_TYPE_UINT
|
||||
sizeof(uint64_t), // TSDB_DATA_TYPE_UBIGINT
|
||||
TSDB_MAX_JSON_TAG_LEN, // TSDB_DATA_TYPE_JSON
|
||||
};
|
||||
|
||||
#define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \
|
||||
|
|
|
@ -5,7 +5,12 @@ MESSAGE(STATUS "build parser unit test")
|
|||
SET(CMAKE_CXX_STANDARD 11)
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
||||
|
||||
ADD_EXECUTABLE(commonTest ${SOURCE_LIST})
|
||||
ADD_EXECUTABLE(commonTest "")
|
||||
TARGET_SOURCES(
|
||||
commonTest
|
||||
PRIVATE
|
||||
"commonTests.cpp"
|
||||
)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
commonTest
|
||||
PUBLIC os util common gtest
|
||||
|
@ -24,7 +29,12 @@ target_sources(
|
|||
PRIVATE
|
||||
"dataformatTest.cpp"
|
||||
)
|
||||
target_link_libraries(dataformatTest gtest gtest_main util)
|
||||
target_link_libraries(dataformatTest gtest gtest_main util common)
|
||||
target_include_directories(
|
||||
dataformatTest
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/common"
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/util"
|
||||
)
|
||||
|
||||
# tmsg test
|
||||
# add_executable(tmsgTest "")
|
||||
|
|
|
@ -1 +1,479 @@
|
|||
#include "gtest/gtest.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/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <taoserror.h>
|
||||
#include <tdataformat.h>
|
||||
#include <tglobal.h>
|
||||
#include <tmsg.h>
|
||||
#include <iostream>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
#define NONE_CSTR "no"
|
||||
#define NULL_CSTR "nu"
|
||||
#define NONE_LEN 2
|
||||
#define NULL_LEN 2
|
||||
const static int16_t MAX_COLS = 14;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
// ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint, c9 bool
|
||||
STSchema *genSTSchema(int16_t nCols) {
|
||||
EXPECT_LE(nCols, MAX_COLS);
|
||||
SSchema *pSchema = (SSchema *)taosMemoryCalloc(nCols, sizeof(SSchema));
|
||||
EXPECT_NE(pSchema, nullptr);
|
||||
|
||||
for (int16_t i = 0; i < nCols; ++i) {
|
||||
pSchema[i].colId = PRIMARYKEY_TIMESTAMP_COL_ID + i;
|
||||
char colName[TSDB_COL_NAME_LEN] = {0};
|
||||
snprintf(colName, TSDB_COL_NAME_LEN, "c%" PRIi16, i);
|
||||
strncpy(pSchema[i].name, colName, TSDB_COL_NAME_LEN);
|
||||
|
||||
switch (i) {
|
||||
case 0: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 1: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_INT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
;
|
||||
} break;
|
||||
case 2: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_BIGINT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 3: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_FLOAT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 4: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 5: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_BINARY;
|
||||
pSchema[i].bytes = 12;
|
||||
} break;
|
||||
case 6: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_NCHAR;
|
||||
pSchema[i].bytes = 42;
|
||||
} break;
|
||||
case 7: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_TINYINT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 8: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 9: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_BOOL;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 10: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_UTINYINT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 11: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_USMALLINT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 12: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_UINT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
case 13: {
|
||||
pSchema[i].type = TSDB_DATA_TYPE_UBIGINT;
|
||||
pSchema[i].bytes = TYPE_BYTES[pSchema[i].type];
|
||||
} break;
|
||||
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
STSchema *pResult = NULL;
|
||||
pResult = tdGetSTSChemaFromSSChema(&pSchema, nCols);
|
||||
|
||||
taosMemoryFree(pSchema);
|
||||
return pResult;
|
||||
}
|
||||
|
||||
// ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint, c9 bool
|
||||
static int32_t genTestData(const char **data, int16_t nCols, SArray **pArray) {
|
||||
if (!(*pArray)) {
|
||||
*pArray = taosArrayInit(nCols, sizeof(SColVal));
|
||||
if (!(*pArray)) return -1;
|
||||
}
|
||||
|
||||
for (int16_t i = 0; i < nCols; ++i) {
|
||||
SColVal colVal = {0};
|
||||
colVal.cid = PRIMARYKEY_TIMESTAMP_COL_ID + i;
|
||||
if (strncasecmp(data[i], NONE_CSTR, NONE_LEN) == 0) {
|
||||
colVal.isNone = 1;
|
||||
taosArrayPush(*pArray, &colVal);
|
||||
continue;
|
||||
} else if (strncasecmp(data[i], NULL_CSTR, NULL_LEN) == 0) {
|
||||
colVal.isNull = 1;
|
||||
taosArrayPush(*pArray, &colVal);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
sscanf(data[i], "%" PRIi64, &colVal.value.ts);
|
||||
break;
|
||||
case 1:
|
||||
sscanf(data[i], "%" PRIi32, &colVal.value.i32);
|
||||
break;
|
||||
case 2:
|
||||
sscanf(data[i], "%" PRIi64, &colVal.value.i64);
|
||||
break;
|
||||
case 3:
|
||||
sscanf(data[i], "%f", &colVal.value.f);
|
||||
break;
|
||||
case 4:
|
||||
sscanf(data[i], "%lf", &colVal.value.d);
|
||||
break;
|
||||
case 5: {
|
||||
int16_t dataLen = strlen(data[i]) + 1;
|
||||
colVal.value.nData = dataLen < 10 ? dataLen : 10;
|
||||
colVal.value.pData = (uint8_t *)data[i];
|
||||
} break;
|
||||
case 6: {
|
||||
int16_t dataLen = strlen(data[i]) + 1;
|
||||
colVal.value.nData = dataLen < 40 ? dataLen : 40;
|
||||
colVal.value.pData = (uint8_t *)data[i]; // just for test, not real nchar
|
||||
} break;
|
||||
case 7:
|
||||
case 9: {
|
||||
int32_t d8;
|
||||
sscanf(data[i], "%" PRId32, &d8);
|
||||
colVal.value.i8 = (int8_t)d8;
|
||||
} break;
|
||||
case 8: {
|
||||
int32_t d16;
|
||||
sscanf(data[i], "%" PRId32, &d16);
|
||||
colVal.value.i16 = (int16_t)d16;
|
||||
} break;
|
||||
case 10: {
|
||||
uint32_t u8;
|
||||
sscanf(data[i], "%" PRId32, &u8);
|
||||
colVal.value.u8 = (uint8_t)u8;
|
||||
} break;
|
||||
case 11: {
|
||||
uint32_t u16;
|
||||
sscanf(data[i], "%" PRId32, &u16);
|
||||
colVal.value.u16 = (uint16_t)u16;
|
||||
} break;
|
||||
case 12: {
|
||||
sscanf(data[i], "%" PRIu32, &colVal.value.u32);
|
||||
} break;
|
||||
case 13: {
|
||||
sscanf(data[i], "%" PRIu64, &colVal.value.u64);
|
||||
} break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
taosArrayPush(*pArray, &colVal);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t debugPrintSColVal(SColVal *cv, int8_t type) {
|
||||
if (cv->isNone) {
|
||||
printf("None ");
|
||||
return 0;
|
||||
}
|
||||
if (cv->isNull) {
|
||||
printf("Null ");
|
||||
return 0;
|
||||
}
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
printf("%s ", cv->value.i8 == 0 ? "false" : "true");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
printf("%" PRIi8 " ", cv->value.i8);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
printf("%" PRIi16 " ", cv->value.i16);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
printf("%" PRIi32 " ", cv->value.i32);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
printf("%" PRIi64 " ", cv->value.i64);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
printf("%f ", cv->value.f);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
printf("%lf ", cv->value.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_VARCHAR: {
|
||||
char tv[15] = {0};
|
||||
snprintf(tv, 15, "%s", cv->value.pData);
|
||||
printf("%s ", tv);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
printf("%" PRIi64 " ", cv->value.i64);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
char tv[15] = {0};
|
||||
snprintf(tv, 15, "%s", cv->value.pData);
|
||||
printf("%s ", tv);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
printf("%" PRIu8 " ", cv->value.u8);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
printf("%" PRIu16 " ", cv->value.u16);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
printf("%" PRIu32 " ", cv->value.u32);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
printf("%" PRIu64 " ", cv->value.u64);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
printf("JSON ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
printf("VARBIN ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
printf("DECIMAL ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
printf("BLOB ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||
printf("MedBLOB ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_MAX:
|
||||
printf("UNDEF ");
|
||||
break;
|
||||
default:
|
||||
printf("UNDEF ");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void debugPrintTSRow(STSRow2 *row, STSchema *pTSchema, const char *tags, int32_t ln) {
|
||||
printf("%s:%d %s:v%d:%d ", tags, ln, (row->flags & 0xf0) ? "KV" : "TP", row->sver, row->nData);
|
||||
for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) {
|
||||
SColVal cv = {0};
|
||||
tTSRowGet(row, pTSchema, i, &cv);
|
||||
debugPrintSColVal(&cv, pTSchema->columns[i].type);
|
||||
}
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static int32_t checkSColVal(const char *rawVal, SColVal *cv, int8_t type) {
|
||||
ASSERT(rawVal);
|
||||
|
||||
if (cv->isNone) {
|
||||
EXPECT_STRCASEEQ(rawVal, NONE_CSTR);
|
||||
return 0;
|
||||
}
|
||||
if (cv->isNull) {
|
||||
EXPECT_STRCASEEQ(rawVal, NULL_CSTR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SValue rawSVal = {0};
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
int32_t d8;
|
||||
sscanf(rawVal, "%" PRId32, &d8);
|
||||
EXPECT_EQ(cv->value.i8, (int8_t)d8);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
int32_t d16;
|
||||
sscanf(rawVal, "%" PRId32, &d16);
|
||||
EXPECT_EQ(cv->value.i16, (int16_t)d16);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
sscanf(rawVal, "%" PRId32, &rawSVal.i32);
|
||||
EXPECT_EQ(cv->value.i32, rawSVal.i32);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
sscanf(rawVal, "%" PRIi64, &rawSVal.i64);
|
||||
EXPECT_EQ(cv->value.i64, rawSVal.i64);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
sscanf(rawVal, "%f", &rawSVal.f);
|
||||
EXPECT_FLOAT_EQ(cv->value.f, rawSVal.f);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
sscanf(rawVal, "%lf", &rawSVal.d);
|
||||
EXPECT_DOUBLE_EQ(cv->value.d, rawSVal.d);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_VARCHAR: {
|
||||
EXPECT_STRCASEEQ(rawVal, (const char *)cv->value.pData);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
sscanf(rawVal, "%" PRIi64, &rawSVal.ts);
|
||||
EXPECT_DOUBLE_EQ(cv->value.ts, rawSVal.ts);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
EXPECT_STRCASEEQ(rawVal, (const char *)cv->value.pData); // informal nchar comparsion
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_UTINYINT: {
|
||||
uint32_t u8;
|
||||
sscanf(rawVal, "%" PRIu32, &u8);
|
||||
EXPECT_EQ(cv->value.u8, (uint8_t)u8);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
uint32_t u16;
|
||||
sscanf(rawVal, "%" PRIu32, &u16);
|
||||
EXPECT_EQ(cv->value.u16, (uint16_t)u16);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
sscanf(rawVal, "%" PRIu32, &rawSVal.u32);
|
||||
EXPECT_EQ(cv->value.u32, rawSVal.u32);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
sscanf(rawVal, "%" PRIu64, &rawSVal.u64);
|
||||
EXPECT_EQ(cv->value.u64, rawSVal.u64);
|
||||
} break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
printf("JSON ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
printf("VARBIN ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
printf("DECIMAL ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
printf("BLOB ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||
printf("MedBLOB ");
|
||||
break;
|
||||
// case TSDB_DATA_TYPE_BINARY:
|
||||
// printf("BINARY ");
|
||||
// break;
|
||||
case TSDB_DATA_TYPE_MAX:
|
||||
printf("UNDEF ");
|
||||
break;
|
||||
default:
|
||||
printf("UNDEF ");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void checkTSRow(const char **data, STSRow2 *row, STSchema *pTSchema) {
|
||||
for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) {
|
||||
SColVal cv = {0};
|
||||
tTSRowGet(row, pTSchema, i, &cv);
|
||||
checkSColVal(data[i], &cv, pTSchema->columns[i].type);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(testCase, AllNormTest) {
|
||||
int16_t nCols = 14;
|
||||
STSRowBuilder rb = {0};
|
||||
STSRow2 *row = nullptr;
|
||||
SArray *pArray = taosArrayInit(nCols, sizeof(SColVal));
|
||||
EXPECT_NE(pArray, nullptr);
|
||||
|
||||
STSchema *pTSchema = genSTSchema(nCols);
|
||||
EXPECT_NE(pTSchema, nullptr);
|
||||
|
||||
// ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint,
|
||||
// c9 bool
|
||||
char *data[14] = {"1653694220000", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no", "no", "no", "no", "no"};
|
||||
|
||||
genTestData((const char **)&data, nCols, &pArray);
|
||||
|
||||
tTSRowNew(&rb, pArray, pTSchema, &row);
|
||||
|
||||
debugPrintTSRow(row, pTSchema, __func__, __LINE__);
|
||||
checkTSRow((const char **)&data, row, pTSchema);
|
||||
|
||||
tsRowBuilderClear(&rb);
|
||||
taosArrayDestroy(pArray);
|
||||
taosMemoryFree(pTSchema);
|
||||
}
|
||||
|
||||
#if 1
|
||||
TEST(testCase, NoneTest) {
|
||||
const static int nCols = 14;
|
||||
const static int nRows = 20;
|
||||
STSRow2 *row = nullptr;
|
||||
SArray *pArray = taosArrayInit(nCols, sizeof(SColVal));
|
||||
EXPECT_NE(pArray, nullptr);
|
||||
|
||||
STSchema *pTSchema = genSTSchema(nCols);
|
||||
EXPECT_NE(pTSchema, nullptr);
|
||||
|
||||
// ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint,
|
||||
// c9 bool c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned
|
||||
const char *data[nRows][nCols] = {
|
||||
{"1653694220000", "no", "20", "10.1", "10.1", "binary10", "no", "10", "10", "nu", "10", "20", "30", "40"},
|
||||
{"1653694220001", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no"},
|
||||
{"1653694220002", "10", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no"},
|
||||
{"1653694220003", "10", "10", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no"},
|
||||
{"1653694220004", "no", "20", "no", "no", "no", "nchar10", "no", "no", "no", "no", "no", "no", "no"},
|
||||
{"1653694220005", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu"},
|
||||
{"1653694220006", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu"},
|
||||
{"1653694220007", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no", "no", "no", "no", "no"},
|
||||
{"1653694220008", "no", "nu", "nu", "nu", "binary10", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no"},
|
||||
{"1653694220009", "no", "nu", "nu", "nu", "binary10", "nu", "nu", "10", "no", "nu", "nu", "nu", "100"},
|
||||
{"1653694220010", "-1", "-1", "-1", "-1", "binary10", "nu", "-1", "0", "0", "0", "0", "0", "0"},
|
||||
{"1653694220011", "-2147483648", "nu", "nu", "nu", "biy10", "nu", "nu", "32767", "no", "nu", "nu", "nu", "100"},
|
||||
{"1653694220012", "2147483647", "nu", "nu", "nu", "ary10", "nu", "nu", "-32768", "no", "nu", "nu", "nu", "100"},
|
||||
{"1653694220013", "no", "-9223372036854775818", "nu", "nu", "b1", "nu", "nu", "10", "no", "nu", "nu", "nu", "nu"},
|
||||
{"1653694220014", "no", "nu", "nu", "nu", "b0", "nu", "nu", "10", "no", "nu", "nu", "nu", "9223372036854775808"},
|
||||
{"1653694220015", "no", "nu", "nu", "nu", "binary30", "char4", "nu", "10", "no", "nu", "nu", "nu",
|
||||
"18446744073709551615"},
|
||||
{"1653694220016", "2147483647", "nu", "nu", "nu", "bin50", "nu", "nu", "10", "no", "nu", "nu", "nu", "100"},
|
||||
{"1653694220017", "2147483646", "0", "0", "0", "binary10", "0", "0", "0", "0", "255", "0", "0", "0"},
|
||||
{"1653694220018", "no", "-9223372036854775808", "nu", "nu", "binary10", "nu", "nu", "10", "no", "nu", "nu",
|
||||
"4294967295", "100"},
|
||||
{"1653694220019", "no", "9223372036854775807", "nu", "nu", "bin10", "nu", "nu", "10", "no", "254", "nu", "nu",
|
||||
"no"}};
|
||||
|
||||
for (int r = 0; r < nRows; ++r) {
|
||||
genTestData((const char **)&data[r], nCols, &pArray);
|
||||
tTSRowNew(NULL, pArray, pTSchema, &row);
|
||||
debugPrintTSRow(row, pTSchema, __func__, __LINE__); // debug print
|
||||
checkTSRow((const char **)&data[r], row, pTSchema); // check
|
||||
tTSRowFree(row);
|
||||
taosArrayClear(pArray);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
taosMemoryFree(pTSchema);
|
||||
}
|
||||
#endif
|
|
@ -38,10 +38,14 @@ static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
|
|||
SStatusRsp statusRsp = {0};
|
||||
if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
|
||||
tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
|
||||
dTrace("status msg received from mnode, dnodeVer:%" PRId64 " saved:%" PRId64, statusRsp.dnodeVer,
|
||||
pMgmt->pData->dnodeVer);
|
||||
if (pMgmt->pData->dnodeVer != statusRsp.dnodeVer) {
|
||||
pMgmt->pData->dnodeVer = statusRsp.dnodeVer;
|
||||
dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg);
|
||||
dmUpdateEps(pMgmt->pData, statusRsp.pDnodeEps);
|
||||
}
|
||||
}
|
||||
rpcFreeCont(pRsp->pCont);
|
||||
tFreeSStatusRsp(&statusRsp);
|
||||
}
|
||||
|
@ -89,7 +93,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
|||
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .info.ahandle = (void *)0x9527};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
|
||||
dTrace("send status msg to mnode");
|
||||
dTrace("send status msg to mnode, dnodeVer:%" PRId64, req.dnodeVer);
|
||||
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pMgmt->pData, &epSet);
|
||||
|
|
|
@ -170,6 +170,9 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_MND_COMPACT_DB, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_GET_DB_CFG, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_VGROUP_LIST, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_REDISTRIBUTE_VGROUP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_MERGE_VGROUP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_BALANCE_VGROUP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_FUNC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_RETRIEVE_FUNC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_FUNC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
@ -181,6 +184,7 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_SMA, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_STREAM, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_GET_INDEX, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_GET_TABLE_INDEX, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
@ -210,12 +214,16 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, mmPutNodeMsgToQueryQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DEPLOY_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIRM_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_HASHRANGE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MON_MM_INFO, mmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MON_MM_LOAD, mmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_TIMEOUT, mmPutNodeMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING, mmPutNodeMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING_REPLY, mmPutNodeMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
|
@ -225,9 +233,8 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_REQUEST_VOTE_REPLY, mmPutNodeMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES, mmPutNodeMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, mmPutNodeMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MON_MM_INFO, mmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MON_MM_LOAD, mmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutNodeMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutNodeMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ static void mmProcessSyncQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t mmPutNodeMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pMsg) {
|
||||
dTrace("msg:%p, put into worker %s, type:%s", pMsg, pWorker->name, TMSG_INFO(pMsg->msgType));
|
||||
dTrace("msg:%p, put into %s queue, type:%s", pMsg, pWorker->name, TMSG_INFO(pMsg->msgType));
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -94,9 +94,10 @@ SArray *smGetMsgHandles() {
|
|||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MON_SM_INFO, smPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
// Requests handled by SNODE
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SND_TASK_DEPLOY, smPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
/*if (dmSetMgmtHandle(pArray, TDMT_SND_TASK_EXEC, smPutNodeMsgToExecQueue, 0) == NULL) goto _OVER;*/
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
_OVER:
|
||||
|
|
|
@ -34,6 +34,7 @@ typedef struct SVnodeMgmt {
|
|||
SQWorkerPool fetchPool;
|
||||
SWWorkerPool syncPool;
|
||||
SWWorkerPool writePool;
|
||||
SWWorkerPool applyPool;
|
||||
SWWorkerPool mergePool;
|
||||
SSingleWorker mgmtWorker;
|
||||
SSingleWorker monitorWorker;
|
||||
|
@ -52,10 +53,9 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t refCount;
|
||||
int32_t vgVersion;
|
||||
int32_t refCount;
|
||||
int8_t dropped;
|
||||
int8_t accessState;
|
||||
char *path;
|
||||
SVnode *pImpl;
|
||||
STaosQueue *pWriteQ;
|
||||
|
|
|
@ -210,8 +210,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d", createReq.vgId, createReq.isTsma,
|
||||
createReq.standby);
|
||||
dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d", createReq.vgId, createReq.isTsma, createReq.standby);
|
||||
vmGenerateVnodeCfg(&createReq, &vnodeCfg);
|
||||
|
||||
if (vmTsmaAdjustDays(&vnodeCfg, &createReq) < 0) {
|
||||
|
@ -324,7 +323,6 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_MON_VM_INFO, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MON_VM_LOAD, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
// Requests handled by VNODE
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_CONTINUE, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
|
||||
|
@ -333,11 +331,6 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_UPDATE_TAG_VAL, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TABLE_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TABLES_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_CONSUME, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_CONNECT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_DISCONNECT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
// if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_SET_CUR, vmPutMsgToWriteQueue, 0)== NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
@ -352,17 +345,21 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RUN, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DISPATCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RECOVER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIRM, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_HASHRANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -49,10 +49,9 @@ int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) {
|
|||
}
|
||||
|
||||
pVnode->vgId = pCfg->vgId;
|
||||
pVnode->refCount = 0;
|
||||
pVnode->vgVersion = pCfg->vgVersion;
|
||||
pVnode->refCount = 0;
|
||||
pVnode->dropped = 0;
|
||||
pVnode->accessState = TSDB_VN_ALL_ACCCESS;
|
||||
pVnode->path = tstrdup(pCfg->path);
|
||||
pVnode->pImpl = pImpl;
|
||||
|
||||
|
@ -96,7 +95,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
dDebug("vgId:%d, vnode is closed", pVnode->vgId);
|
||||
|
||||
if (pVnode->dropped) {
|
||||
dDebug("vgId:%d, vnode is destroyed for dropped:%d", pVnode->vgId, pVnode->dropped);
|
||||
dInfo("vgId:%d, vnode is destroyed, dropped:%d", pVnode->vgId, pVnode->dropped);
|
||||
snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, pVnode->vgId);
|
||||
vnodeDestroy(path, pMgmt->pTfs);
|
||||
}
|
||||
|
|
|
@ -16,10 +16,8 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "vmInt.h"
|
||||
|
||||
#include "sync.h"
|
||||
#include "syncTools.h"
|
||||
|
||||
static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) {
|
||||
if (pMsg->info.handle == NULL) return;
|
||||
SRpcMsg rsp = {
|
||||
.code = code,
|
||||
.pCont = pMsg->info.rsp,
|
||||
|
@ -53,9 +51,9 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
if (IsReq(pMsg)) {
|
||||
if (code != 0 && terrno != 0) {
|
||||
dError("msg:%p failed to process since %s", pMsg, terrstr());
|
||||
code = terrno;
|
||||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
dError("msg:%p, failed to process since %s", pMsg, terrstr());
|
||||
}
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
|
@ -97,110 +95,6 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
int32_t code = 0;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
int64_t sync = vnodeGetSyncHandle(pVnode->pImpl);
|
||||
SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg **));
|
||||
|
||||
for (int32_t m = 0; m < numOfMsgs; m++) {
|
||||
if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
|
||||
dTrace("vgId:%d, msg:%p get from vnode-write queue", pVnode->vgId, pMsg);
|
||||
|
||||
if (taosArrayPush(pArray, &pMsg) == NULL) {
|
||||
dError("vgId:%d, failed to push msg:%p to vnode-write array", pVnode->vgId, pMsg);
|
||||
vmSendRsp(pMsg, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t m = 0; m < taosArrayGetSize(pArray); m++) {
|
||||
pMsg = *(SRpcMsg **)taosArrayGet(pArray, m);
|
||||
code = vnodePreprocessReq(pVnode->pImpl, pMsg);
|
||||
|
||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
dTrace("vgId:%d, msg:%p in progress and no rsp", pVnode->vgId, pMsg);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pMsg->msgType != TDMT_VND_ALTER_REPLICA) {
|
||||
code = syncPropose(sync, pMsg, false);
|
||||
}
|
||||
|
||||
if (code == TAOS_SYNC_PROPOSE_SUCCESS) {
|
||||
dTrace("vgId:%d, msg:%p is proposed and no rsp", pVnode->vgId, pMsg);
|
||||
continue;
|
||||
} else if (code == TAOS_SYNC_PROPOSE_NOT_LEADER) {
|
||||
SEpSet newEpSet = {0};
|
||||
syncGetEpSet(sync, &newEpSet);
|
||||
SEp *pEp = &newEpSet.eps[newEpSet.inUse];
|
||||
if (pEp->port == tsServerPort && strcmp(pEp->fqdn, tsLocalFqdn) == 0) {
|
||||
newEpSet.inUse = (newEpSet.inUse + 1) % newEpSet.numOfEps;
|
||||
}
|
||||
|
||||
dTrace("vgId:%d, msg:%p is redirect since not leader, numOfEps:%d inUse:%d", pVnode->vgId, pMsg,
|
||||
newEpSet.numOfEps, newEpSet.inUse);
|
||||
for (int32_t i = 0; i < newEpSet.numOfEps; ++i) {
|
||||
dTrace("vgId:%d, msg:%p ep:%s:%u", pVnode->vgId, pMsg, newEpSet.eps[i].fqdn, newEpSet.eps[i].port);
|
||||
}
|
||||
|
||||
SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info};
|
||||
tmsgSendRedirectRsp(&rsp, &newEpSet);
|
||||
} else {
|
||||
dError("vgId:%d, msg:%p failed to propose write since %s, code:0x%x", pVnode->vgId, pMsg, tstrerror(code), code);
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; i++) {
|
||||
pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
|
||||
dTrace("vgId:%d, msg:%p is freed", pVnode->vgId, pMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
|
||||
dTrace("vgId:%d, msg:%p get from vnode-apply queue", pVnode->vgId, pMsg);
|
||||
|
||||
// init response rpc msg
|
||||
SRpcMsg rsp = {0};
|
||||
|
||||
// get original rpc msg
|
||||
assert(pMsg->msgType == TDMT_SYNC_APPLY_MSG);
|
||||
SyncApplyMsg *pSyncApplyMsg = syncApplyMsgFromRpcMsg2(pMsg);
|
||||
syncApplyMsgLog2("==vmProcessApplyQueue==", pSyncApplyMsg);
|
||||
SRpcMsg originalRpcMsg;
|
||||
syncApplyMsg2OriginalRpcMsg(pSyncApplyMsg, &originalRpcMsg);
|
||||
|
||||
// apply data into tsdb
|
||||
if (vnodeProcessWriteReq(pVnode->pImpl, &originalRpcMsg, pSyncApplyMsg->fsmMeta.index, &rsp) < 0) {
|
||||
rsp.code = terrno;
|
||||
dError("vgId:%d, msg:%p failed to apply since %s", pVnode->vgId, pMsg, terrstr());
|
||||
}
|
||||
|
||||
syncApplyMsgDestroy(pSyncApplyMsg);
|
||||
rpcFreeCont(originalRpcMsg.pCont);
|
||||
|
||||
// if leader, send response
|
||||
if (pMsg->info.handle != NULL) {
|
||||
rsp.info = pMsg->info;
|
||||
tmsgSendRsp(&rsp);
|
||||
}
|
||||
|
||||
dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, rsp.code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
|
@ -211,12 +105,10 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
|
|||
|
||||
int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL);
|
||||
if (code != 0) {
|
||||
dError("vgId:%d, msg:%p failed to sync since %s", pVnode->vgId, pMsg, terrstr());
|
||||
if (pMsg->info.handle != NULL) {
|
||||
if (terrno != 0) code = terrno;
|
||||
dError("vgId:%d, msg:%p failed to sync since %s", pVnode->vgId, pMsg, terrstr());
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
}
|
||||
|
||||
dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
@ -234,8 +126,8 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
|
||||
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
|
||||
if (code != 0) {
|
||||
dError("vgId:%d, msg:%p failed to merge since %s", pVnode->vgId, pMsg, terrstr());
|
||||
if (terrno != 0) code = terrno;
|
||||
dError("vgId:%d, msg:%p failed to merge since %s", pVnode->vgId, pMsg, terrstr());
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
|
@ -254,7 +146,7 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
dError("vgId:%d, failed to put msg:%p into vnode queue since %s, type:%s", pHead->vgId, pMsg, terrstr(),
|
||||
dError("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s", pHead->vgId, pMsg, terrstr(),
|
||||
TMSG_INFO(pMsg->msgType));
|
||||
return terrno != 0 ? terrno : -1;
|
||||
}
|
||||
|
@ -322,7 +214,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
if (pMsg == NULL) return -1;
|
||||
|
||||
SMsgHead *pHead = pRpc->pCont;
|
||||
dTrace("vgId:%d, msg:%p is created, type:%s", pHead->vgId, pMsg, TMSG_INFO(pMsg->msgType));
|
||||
dTrace("vgId:%d, msg:%p is created, type:%s", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType));
|
||||
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
|
@ -362,9 +254,9 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
|||
}
|
||||
|
||||
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||
pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode, (FItems)vmProcessWriteQueue);
|
||||
pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode->pImpl, (FItems)vnodeProposeMsg);
|
||||
pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue);
|
||||
pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode, (FItems)vmProcessApplyQueue);
|
||||
pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyMsg);
|
||||
pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
|
||||
pVnode->pFetchQ = tQWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItem)vmProcessFetchQueue);
|
||||
pVnode->pMergeQ = tWWorkerAllocQueue(&pMgmt->mergePool, pVnode, (FItems)vmProcessMergeQueue);
|
||||
|
@ -381,8 +273,8 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
|
||||
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||
tWWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ);
|
||||
tWWorkerFreeQueue(&pMgmt->applyPool, pVnode->pApplyQ);
|
||||
tWWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ);
|
||||
tWWorkerFreeQueue(&pMgmt->writePool, pVnode->pApplyQ);
|
||||
tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
|
||||
tQWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
|
||||
tWWorkerFreeQueue(&pMgmt->mergePool, pVnode->pMergeQ);
|
||||
|
@ -413,6 +305,11 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
|||
pWPool->max = tsNumOfVnodeWriteThreads;
|
||||
if (tWWorkerInit(pWPool) != 0) return -1;
|
||||
|
||||
SWWorkerPool *pAPool = &pMgmt->applyPool;
|
||||
pAPool->name = "vnode-apply";
|
||||
pAPool->max = tsNumOfVnodeWriteThreads;
|
||||
if (tWWorkerInit(pAPool) != 0) return -1;
|
||||
|
||||
SWWorkerPool *pSPool = &pMgmt->syncPool;
|
||||
pSPool->name = "vnode-sync";
|
||||
pSPool->max = tsNumOfVnodeSyncThreads;
|
||||
|
@ -449,6 +346,7 @@ void vmStopWorker(SVnodeMgmt *pMgmt) {
|
|||
tSingleWorkerCleanup(&pMgmt->monitorWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
||||
tWWorkerCleanup(&pMgmt->writePool);
|
||||
tWWorkerCleanup(&pMgmt->applyPool);
|
||||
tWWorkerCleanup(&pMgmt->syncPool);
|
||||
tQWorkerCleanup(&pMgmt->queryPool);
|
||||
tQWorkerCleanup(&pMgmt->fetchPool);
|
||||
|
|
|
@ -22,17 +22,17 @@ static void dmSendRsp(SRpcMsg *pMsg);
|
|||
static void dmBuildMnodeRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
|
||||
static inline int32_t dmBuildNodeMsg(SRpcMsg *pMsg, SRpcMsg *pRpc) {
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if (IsReq(pRpc) && rpcGetConnInfo(pRpc->info.handle, &connInfo) != 0) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
dError("failed to build msg since %s, app:%p handle:%p", terrstr(), pRpc->info.ahandle, pRpc->info.handle);
|
||||
return -1;
|
||||
}
|
||||
SRpcConnInfo *pConnInfo = &(pRpc->info.connInfo);
|
||||
// if (IsReq(pRpc)) {
|
||||
// terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
// dError("failed to build msg since %s, app:%p handle:%p", terrstr(), pRpc->info.ahandle, pRpc->info.handle);
|
||||
// return -1;
|
||||
//}
|
||||
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
memcpy(pMsg->conn.user, connInfo.user, TSDB_USER_LEN);
|
||||
pMsg->conn.clientIp = connInfo.clientIp;
|
||||
pMsg->conn.clientPort = connInfo.clientPort;
|
||||
memcpy(pMsg->conn.user, pConnInfo->user, TSDB_USER_LEN);
|
||||
pMsg->conn.clientIp = pConnInfo->clientIp;
|
||||
pMsg->conn.clientPort = pConnInfo->clientPort;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -49,9 +49,9 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
SDnodeTrans * pTrans = &pDnode->trans;
|
||||
int32_t code = -1;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
SRpcMsg * pMsg = NULL;
|
||||
SMgmtWrapper *pWrapper = NULL;
|
||||
SDnodeHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(pRpc->msgType)];
|
||||
|
||||
|
@ -95,6 +95,8 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
int32_t vgId = ntohl(pHead->vgId);
|
||||
if (vgId == QNODE_HANDLE) {
|
||||
pWrapper = &pDnode->wrappers[QNODE];
|
||||
} else if (vgId == SNODE_HANDLE) {
|
||||
pWrapper = &pDnode->wrappers[SNODE];
|
||||
} else if (vgId == MNODE_HANDLE) {
|
||||
pWrapper = &pDnode->wrappers[MNODE];
|
||||
} else {
|
||||
|
@ -165,11 +167,11 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
|
|||
|
||||
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
SArray *pArray = (*pWrapper->func.getHandlesFp)();
|
||||
SArray * pArray = (*pWrapper->func.getHandlesFp)();
|
||||
if (pArray == NULL) return -1;
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SMgmtHandle *pMgmt = taosArrayGet(pArray, i);
|
||||
SMgmtHandle * pMgmt = taosArrayGet(pArray, i);
|
||||
SDnodeHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(pMgmt->msgType)];
|
||||
if (pMgmt->needCheckVgId) {
|
||||
pHandle->needCheckVgId = pMgmt->needCheckVgId;
|
||||
|
|
|
@ -81,6 +81,13 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
}
|
||||
pData->dnodeId = dnodeId->valueint;
|
||||
|
||||
cJSON *dnodeVer = cJSON_GetObjectItem(root, "dnodeVer");
|
||||
if (!dnodeVer || dnodeVer->type != cJSON_String) {
|
||||
dError("failed to read %s since dnodeVer not found", file);
|
||||
goto _OVER;
|
||||
}
|
||||
pData->dnodeVer = atoll(dnodeVer->valuestring);
|
||||
|
||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_String) {
|
||||
dError("failed to read %s since clusterId not found", file);
|
||||
|
@ -193,6 +200,7 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
|||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pData->dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeVer\": \"%" PRId64 "\",\n", pData->dnodeVer);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pData->clusterId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pData->dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n");
|
||||
|
@ -224,30 +232,15 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
|||
}
|
||||
|
||||
pData->updateTime = taosGetTimestampMs();
|
||||
dDebug("successed to write %s", realfile);
|
||||
dDebug("successed to write %s, dnodeVer:%" PRId64, realfile, pData->dnodeVer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmUpdateEps(SDnodeData *pData, SArray *eps) {
|
||||
int32_t numOfEps = taosArrayGetSize(eps);
|
||||
if (numOfEps <= 0) return;
|
||||
|
||||
taosThreadRwlockWrlock(&pData->lock);
|
||||
|
||||
int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pData->dnodeEps);
|
||||
if (numOfEps != numOfEpsOld) {
|
||||
dDebug("new dnode list get from mnode");
|
||||
dDebug("new dnode list get from mnode, dnodeVer:%" PRId64, pData->dnodeVer);
|
||||
dmResetEps(pData, eps);
|
||||
dmWriteEps(pData);
|
||||
} else {
|
||||
int32_t size = numOfEps * sizeof(SDnodeEp);
|
||||
if (memcmp(pData->dnodeEps->pData, eps->pData, size) != 0) {
|
||||
dDebug("new dnode list get from mnode");
|
||||
dmResetEps(pData, eps);
|
||||
dmWriteEps(pData);
|
||||
}
|
||||
}
|
||||
|
||||
taosThreadRwlockUnlock(&pData->lock);
|
||||
}
|
||||
|
||||
|
|
|
@ -120,10 +120,10 @@ typedef struct {
|
|||
SArray* commitActions;
|
||||
int64_t createdTime;
|
||||
int64_t lastExecTime;
|
||||
int32_t lastErrorAction;
|
||||
int32_t lastAction;
|
||||
int32_t lastErrorNo;
|
||||
tmsg_t lastErrorMsgType;
|
||||
SEpSet lastErrorEpset;
|
||||
tmsg_t lastMsgType;
|
||||
SEpSet lastEpset;
|
||||
char dbname[TSDB_DB_FNAME_LEN];
|
||||
int32_t startFunc;
|
||||
int32_t stopFunc;
|
||||
|
@ -301,10 +301,12 @@ typedef struct {
|
|||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
char stb[TSDB_TABLE_FNAME_LEN];
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
char dstTbName[TSDB_TABLE_FNAME_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t uid;
|
||||
int64_t stbUid;
|
||||
int64_t dbUid;
|
||||
int64_t dstTbUid;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
int8_t timezone;
|
||||
|
@ -316,12 +318,12 @@ typedef struct {
|
|||
int32_t tagsFilterLen;
|
||||
int32_t sqlLen;
|
||||
int32_t astLen;
|
||||
int32_t numOfVgroups;
|
||||
char* expr;
|
||||
char* tagsFilter;
|
||||
char* sql;
|
||||
char* ast;
|
||||
SVgEpSet* pVgEpSet;
|
||||
SSchemaWrapper schemaRow; // for dstVgroup
|
||||
SSchemaWrapper schemaTag; // for dstVgroup
|
||||
} SSmaObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -483,6 +485,7 @@ typedef struct {
|
|||
int64_t stbUid;
|
||||
SHashObj* consumerHash; // consumerId -> SMqConsumerEp
|
||||
SArray* unassignedVgs; // SArray<SMqVgEp*>
|
||||
char dbName[TSDB_DB_FNAME_LEN];
|
||||
} SMqSubscribeObj;
|
||||
|
||||
SMqSubscribeObj* tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]);
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
"C" {
|
||||
#endif
|
||||
|
||||
#include "mndInt.h"
|
||||
|
||||
typedef enum {
|
||||
TSDB_GRANT_ALL,
|
||||
TSDB_GRANT_TIME,
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "mndDef.h"
|
||||
|
||||
#include "sdb.h"
|
||||
#include "sync.h"
|
||||
#include "syncTools.h"
|
||||
#include "tcache.h"
|
||||
#include "tdatablock.h"
|
||||
|
@ -75,7 +76,6 @@ typedef struct {
|
|||
} STelemMgmt;
|
||||
|
||||
typedef struct {
|
||||
SWal *pWal;
|
||||
sem_t syncSem;
|
||||
int64_t sync;
|
||||
bool standby;
|
||||
|
@ -108,6 +108,7 @@ typedef struct SMnode {
|
|||
SQHandle *pQuery;
|
||||
SHashObj *infosMeta;
|
||||
SHashObj *perfsMeta;
|
||||
SWal *pWal;
|
||||
SShowMgmt showMgmt;
|
||||
SProfileMgmt profileMgmt;
|
||||
STelemMgmt telemMgmt;
|
||||
|
|
|
@ -29,8 +29,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
|
||||
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream);
|
||||
|
||||
int32_t mndConvertRSmaTask(const char* ast, int64_t uid, int8_t triggerType, int64_t watermark, char** pStr,
|
||||
int32_t* pLen, double filesFactor);
|
||||
int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64_t uid, int8_t triggerType,
|
||||
int64_t watermark, double filesFactor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
|||
int32_t mndTransProcessRsp(SRpcMsg *pRsp);
|
||||
void mndTransPullup(SMnode *pMnode);
|
||||
int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans);
|
||||
void mndTransExecute(SMnode *pMnode, STrans *pTrans);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
|
|||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||
void mndSortVnodeGid(SVgObj *pVgroup);
|
||||
|
||||
SArray *mndBuildDnodesArray(SMnode *, int32_t exceptDnodeId);
|
||||
int32_t mndAllocSmaVgroup(SMnode *, SDbObj *pDb, SVgObj *pVgroup);
|
||||
|
@ -41,6 +42,7 @@ int32_t mndAddAlterVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pV
|
|||
int32_t mndAddDropVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool isRedo);
|
||||
int32_t mndSetMoveVgroupInfoToTrans(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vn, SArray *pArray);
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnodeId);
|
||||
int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SArray *pArray);
|
||||
|
||||
void *mndBuildCreateVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *cntlen, bool standby);
|
||||
void *mndBuildDropVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#define MND_CONSUMER_LOST_HB_CNT 3
|
||||
|
||||
static int8_t mqRebLock = 0;
|
||||
static int8_t mqRebInExecCnt = 0;
|
||||
|
||||
static const char *mndConsumerStatusName(int status);
|
||||
|
||||
|
@ -76,15 +76,15 @@ int32_t mndInitConsumer(SMnode *pMnode) {
|
|||
void mndCleanupConsumer(SMnode *pMnode) {}
|
||||
|
||||
bool mndRebTryStart() {
|
||||
int8_t old = atomic_val_compare_exchange_8(&mqRebLock, 0, 1);
|
||||
int8_t old = atomic_val_compare_exchange_8(&mqRebInExecCnt, 0, 1);
|
||||
return old == 0;
|
||||
}
|
||||
|
||||
void mndRebEnd() { atomic_sub_fetch_8(&mqRebLock, 1); }
|
||||
void mndRebEnd() { atomic_sub_fetch_8(&mqRebInExecCnt, 1); }
|
||||
|
||||
void mndRebCntInc() { atomic_add_fetch_8(&mqRebLock, 1); }
|
||||
void mndRebCntInc() { atomic_add_fetch_8(&mqRebInExecCnt, 1); }
|
||||
|
||||
void mndRebCntDec() { atomic_sub_fetch_8(&mqRebLock, 1); }
|
||||
void mndRebCntDec() { atomic_sub_fetch_8(&mqRebInExecCnt, 1); }
|
||||
|
||||
static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
|
@ -92,12 +92,20 @@ static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) {
|
|||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pLostMsg->consumerId);
|
||||
ASSERT(pConsumer);
|
||||
|
||||
mInfo("receive consumer lost msg, consumer id %ld, status %s", pLostMsg->consumerId,
|
||||
mndConsumerStatusName(pConsumer->status));
|
||||
|
||||
if (pConsumer->status != MQ_CONSUMER_STATUS__READY) {
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__LOST;
|
||||
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg);
|
||||
if (pTrans == NULL) goto FAIL;
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL;
|
||||
|
@ -116,6 +124,14 @@ static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) {
|
|||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pRecoverMsg->consumerId);
|
||||
ASSERT(pConsumer);
|
||||
|
||||
mInfo("receive consumer recover msg, consumer id %ld, status %s", pRecoverMsg->consumerId,
|
||||
mndConsumerStatusName(pConsumer->status));
|
||||
|
||||
if (pConsumer->status != MQ_CONSUMER_STATUS__READY) {
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__RECOVER;
|
||||
|
||||
|
@ -431,6 +447,8 @@ static int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
|
||||
pConsumerOld = mndAcquireConsumer(pMnode, consumerId);
|
||||
if (pConsumerOld == NULL) {
|
||||
mInfo("receive subscribe request from new consumer: %ld", consumerId);
|
||||
|
||||
pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup);
|
||||
tstrncpy(pConsumerNew->clientId, subscribe.clientId, 256);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__MODIFY;
|
||||
|
@ -447,7 +465,12 @@ static int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
|
||||
} else {
|
||||
/*taosRLockLatch(&pConsumerOld->lock);*/
|
||||
|
||||
int32_t status = atomic_load_32(&pConsumerOld->status);
|
||||
|
||||
mInfo("receive subscribe request from old consumer: %ld, current status: %s", consumerId,
|
||||
mndConsumerStatusName(status));
|
||||
|
||||
if (status != MQ_CONSUMER_STATUS__READY) {
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_READY;
|
||||
goto SUBSCRIBE_OVER;
|
||||
|
@ -835,10 +858,11 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *
|
|||
topicSz = 1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < topicSz; i++) {
|
||||
if (numOfRows + topicSz > rowsCapacity) {
|
||||
blockDataEnsureCapacity(pBlock, numOfRows + topicSz);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < topicSz; i++) {
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
|
|
|
@ -636,57 +636,6 @@ static int32_t mndSetAlterDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *p
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SArray *pArray) {
|
||||
if (pVgroup->replica <= 0 || pVgroup->replica == pDb->cfg.replications) {
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_CONFIG) != 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
SVgObj newVgroup = {0};
|
||||
memcpy(&newVgroup, pVgroup, sizeof(SVgObj));
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
if (newVgroup.replica < pDb->cfg.replications) {
|
||||
mInfo("db:%s, vgId:%d, vn:0 dnode:%d, will add 2 vnodes", pVgroup->dbName, pVgroup->vgId,
|
||||
pVgroup->vnodeGid[0].dnodeId);
|
||||
|
||||
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVgroup, &newVgroup.vnodeGid[1], true) != 0) return -1;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVgroup) != 0) return -1;
|
||||
|
||||
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVgroup, &newVgroup.vnodeGid[2], true) != 0) return -1;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVgroup) != 0) return -1;
|
||||
} else {
|
||||
mInfo("db:%s, vgId:%d, will remove 2 vnodes", pVgroup->dbName, pVgroup->vgId);
|
||||
|
||||
SVnodeGid del1 = {0};
|
||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del1) != 0) return -1;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVgroup, &del1, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVgroup) != 0) return -1;
|
||||
|
||||
SVnodeGid del2 = {0};
|
||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del2) != 0) return -1;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVgroup, &del2, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVgroup) != 0) return -1;
|
||||
}
|
||||
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(&newVgroup);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) {
|
||||
sdbFreeRaw(pVgRaw);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
|
@ -1475,10 +1424,10 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in
|
|||
char tmp[128] = {0};
|
||||
int32_t len = 0;
|
||||
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) {
|
||||
len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2,
|
||||
len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2,
|
||||
pDb->cfg.daysToKeep0);
|
||||
} else {
|
||||
len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%d,%d,%d", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1,
|
||||
len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1,
|
||||
pDb->cfg.daysToKeep2);
|
||||
}
|
||||
|
||||
|
@ -1554,8 +1503,8 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, rows, (const char *)statusB, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.schemaless, false);
|
||||
// pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
// colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.schemaless, false);
|
||||
|
||||
char *p = buildRetension(pDb->cfg.pRetensions);
|
||||
|
||||
|
@ -1643,4 +1592,3 @@ static void mndCancelGetNextDb(SMnode *pMnode, void *pIter) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
|
|
|
@ -415,6 +415,7 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) {
|
|||
taosHashPut(pSubNew->consumerHash, &newEp.consumerId, sizeof(int64_t), &newEp, sizeof(SMqConsumerEp));
|
||||
}
|
||||
pSubNew->unassignedVgs = taosArrayDeepCopy(pSub->unassignedVgs, (FCopy)tCloneSMqVgEp);
|
||||
memcpy(pSubNew->dbName, pSub->dbName, TSDB_DB_FNAME_LEN);
|
||||
return pSubNew;
|
||||
}
|
||||
|
||||
|
@ -445,6 +446,7 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
|
|||
}
|
||||
ASSERT(cnt == sz);
|
||||
tlen += taosEncodeArray(buf, pSub->unassignedVgs, (FEncode)tEncodeSMqVgEp);
|
||||
tlen += taosEncodeString(buf, pSub->dbName);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
|
@ -467,6 +469,7 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub) {
|
|||
}
|
||||
|
||||
buf = taosDecodeArray(buf, &pSub->unassignedVgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp));
|
||||
buf = taosDecodeStringTo(buf, pSub->dbName);
|
||||
return (void *)buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -385,7 +385,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
|||
int64_t dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE);
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
bool online = mndIsDnodeOnline(pDnode, curMs);
|
||||
bool dnodeChanged = (statusReq.dnodeVer != dnodeVer);
|
||||
bool dnodeChanged = (statusReq.dnodeVer == 0) || (statusReq.dnodeVer != dnodeVer);
|
||||
bool reboot = (pDnode->rebootTime != statusReq.rebootTime);
|
||||
bool needCheck = !online || dnodeChanged || reboot;
|
||||
|
||||
|
@ -427,7 +427,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
|||
if (!online) {
|
||||
mInfo("dnode:%d, from offline to online", pDnode->id);
|
||||
} else {
|
||||
mDebug("dnode:%d, send dnode epset, online:%d dnode_ver:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
|
||||
mDebug("dnode:%d, send dnode epset, online:%d dnodeVer:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
|
||||
statusReq.dnodeVer, dnodeVer, reboot);
|
||||
}
|
||||
|
||||
|
@ -566,9 +566,11 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM
|
|||
pRaw = NULL;
|
||||
|
||||
if (pMObj != NULL) {
|
||||
mDebug("trans:%d, mnode on dnode:%d will be dropped", pTrans->id, pDnode->id);
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj) != 0) goto _OVER;
|
||||
}
|
||||
if (numOfVnodes > 0) {
|
||||
mDebug("trans:%d, %d vnodes on dnode:%d will be dropped", pTrans->id, numOfVnodes, pDnode->id);
|
||||
if (mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id) != 0) goto _OVER;
|
||||
}
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
|
|
@ -14,19 +14,115 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "mndGrant.h"
|
||||
#include "mndInt.h"
|
||||
#include "mndShow.h"
|
||||
|
||||
#ifndef _GRANT
|
||||
static int32_t mndRetrieveGrant(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { return TSDB_CODE_OPS_NOT_SUPPORT; }
|
||||
|
||||
static int32_t mndRetrieveGrant(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
int32_t numOfRows = 0;
|
||||
char *pWrite;
|
||||
int32_t cols = 0;
|
||||
char tmp[32];
|
||||
char tmp1[32];
|
||||
|
||||
if (pShow->numOfRows < 1) {
|
||||
cols = 0;
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
const char *src = "community";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "false";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
src = "unlimited";
|
||||
STR_WITH_SIZE_TO_VARSTR(tmp, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, tmp, false);
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
pShow->numOfRows += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
int32_t mndInitGrant(SMnode *pMnode) {
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_GRANTS, mndRetrieveGrant);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mndCleanupGrant() {}
|
||||
void grantParseParameter() { mError("can't parsed parameter k"); }
|
||||
int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; }
|
||||
|
|
|
@ -139,10 +139,40 @@ static int32_t mndCreateDir(SMnode *pMnode, const char *path) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndInitWal(SMnode *pMnode) {
|
||||
char path[PATH_MAX + 20] = {0};
|
||||
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
||||
SWalCfg cfg = {
|
||||
.vgId = 1,
|
||||
.fsyncPeriod = 0,
|
||||
.rollPeriod = -1,
|
||||
.segSize = -1,
|
||||
.retentionPeriod = -1,
|
||||
.retentionSize = -1,
|
||||
.level = TAOS_WAL_FSYNC,
|
||||
};
|
||||
|
||||
pMnode->pWal = walOpen(path, &cfg);
|
||||
if (pMnode->pWal == NULL) {
|
||||
mError("failed to open wal since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mndCloseWal(SMnode *pMnode) {
|
||||
if (pMnode->pWal != NULL) {
|
||||
walClose(pMnode->pWal);
|
||||
pMnode->pWal = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndInitSdb(SMnode *pMnode) {
|
||||
SSdbOpt opt = {0};
|
||||
opt.path = pMnode->path;
|
||||
opt.pMnode = pMnode;
|
||||
opt.pWal = pMnode->pWal;
|
||||
|
||||
pMnode->pSdb = sdbInit(&opt);
|
||||
if (pMnode->pSdb == NULL) {
|
||||
|
@ -156,7 +186,6 @@ static int32_t mndOpenSdb(SMnode *pMnode) {
|
|||
if (!pMnode->deploy) {
|
||||
return sdbReadFile(pMnode->pSdb);
|
||||
} else {
|
||||
// return sdbDeploy(pMnode->pSdb);;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -182,13 +211,14 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle
|
|||
}
|
||||
|
||||
static int32_t mndInitSteps(SMnode *pMnode) {
|
||||
if (mndAllocStep(pMnode, "mnode-wal", mndInitWal, mndCloseWal) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-qnode", mndInitQnode, mndCleanupQnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-qnode", mndInitSnode, mndCleanupSnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-qnode", mndInitBnode, mndCleanupBnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-snode", mndInitSnode, mndCleanupSnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-bnode", mndInitBnode, mndCleanupBnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant) != 0) return -1;
|
||||
|
@ -201,7 +231,7 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
|||
if (mndAllocStep(pMnode, "mnode-offset", mndInitOffset, mndCleanupOffset) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-stb", mndInitStb, mndCleanupStb) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-stb", mndInitSma, mndCleanupSma) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-sma", mndInitSma, mndCleanupSma) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-infos", mndInitInfos, mndCleanupInfos) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-perfs", mndInitPerfs, mndCleanupPerfs) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1;
|
||||
|
@ -373,9 +403,64 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
|||
char logBuf[512] = {0};
|
||||
char *syncNodeStr = sync2SimpleStr(pMgmt->sync);
|
||||
snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr);
|
||||
static int64_t mndTick = 0;
|
||||
if (++mndTick % 10 == 1) {
|
||||
mTrace("sync trace msg:%s, %s", TMSG_INFO(pMsg->msgType), syncNodeStr);
|
||||
}
|
||||
syncRpcMsgLog2(logBuf, pMsg);
|
||||
taosMemoryFree(syncNodeStr);
|
||||
|
||||
// ToDo: ugly! use function pointer
|
||||
if (syncNodeSnapshotEnable(pSyncNode)) {
|
||||
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg);
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
||||
syncPingDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
||||
syncPingReplyDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg);
|
||||
syncClientRequestDestroy(pSyncMsg);
|
||||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnRequestVoteSnapshotCb(pSyncNode, pSyncMsg);
|
||||
syncRequestVoteDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnRequestVoteReplySnapshotCb(pSyncNode, pSyncMsg);
|
||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
||||
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnAppendEntriesSnapshotCb(pSyncNode, pSyncMsg);
|
||||
syncAppendEntriesDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnAppendEntriesReplySnapshotCb(pSyncNode, pSyncMsg);
|
||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
||||
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnSnapshotSendCb(pSyncNode, pSyncMsg);
|
||||
syncSnapshotSendDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
||||
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnSnapshotRspCb(pSyncNode, pSyncMsg);
|
||||
syncSnapshotRspDestroy(pSyncMsg);
|
||||
|
||||
} else {
|
||||
mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||
code = TAOS_SYNC_PROPOSE_OTHER_ERROR;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg);
|
||||
|
@ -412,6 +497,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
|||
mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||
code = TAOS_SYNC_PROPOSE_OTHER_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
mndReleaseSyncRef(pMnode);
|
||||
return code;
|
||||
|
|
|
@ -397,17 +397,17 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) >= 3) {
|
||||
terrno = TSDB_CODE_MND_TOO_MANY_MNODES;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) >= 3) {
|
||||
terrno = TSDB_CODE_MND_TOO_MANY_MNODES;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
goto _OVER;
|
||||
|
@ -597,6 +597,11 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!mndIsDnodeOnline(pObj->pDnode, taosGetTimestampMs())) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pUser = mndAcquireUser(pMnode, pReq->conn.user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
|
|
|
@ -183,7 +183,10 @@ static int32_t mndProcessCommitOffsetReq(SRpcMsg *pMsg) {
|
|||
|
||||
for (int32_t i = 0; i < commitOffsetReq.num; i++) {
|
||||
SMqOffset *pOffset = &commitOffsetReq.offsets[i];
|
||||
mInfo("commit offset %ld to vg %d of consumer group %s on topic %s", pOffset->offset, pOffset->vgId,
|
||||
pOffset->cgroup, pOffset->topicName);
|
||||
if (mndMakePartitionKey(key, pOffset->cgroup, pOffset->topicName, pOffset->vgId) < 0) {
|
||||
mError("submit offset to topic %s failed", pOffset->topicName);
|
||||
return -1;
|
||||
}
|
||||
bool create = false;
|
||||
|
|
|
@ -35,8 +35,15 @@
|
|||
|
||||
extern bool tsStreamSchedV;
|
||||
|
||||
int32_t mndConvertRSmaTask(const char* ast, int64_t uid, int8_t triggerType, int64_t watermark, char** pStr,
|
||||
int32_t* pLen, double filesFactor) {
|
||||
static int32_t mndAddTaskToTaskSet(SArray* pArray, SStreamTask* pTask) {
|
||||
int32_t childId = taosArrayGetSize(pArray);
|
||||
pTask->childId = childId;
|
||||
taosArrayPush(pArray, &pTask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64_t uid, int8_t triggerType,
|
||||
int64_t watermark, double filesFactor) {
|
||||
SNode* pAst = NULL;
|
||||
SQueryPlan* pPlan = NULL;
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
@ -46,7 +53,7 @@ int32_t mndConvertRSmaTask(const char* ast, int64_t uid, int8_t triggerType, int
|
|||
goto END;
|
||||
}
|
||||
|
||||
if (qSetSTableIdForRSma(pAst, uid) < 0) {
|
||||
if (qSetSTableIdForRsma(pAst, uid) < 0) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
goto END;
|
||||
}
|
||||
|
@ -79,7 +86,7 @@ int32_t mndConvertRSmaTask(const char* ast, int64_t uid, int8_t triggerType, int
|
|||
}
|
||||
|
||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
if (qSubPlanToString(plan, pStr, pLen) < 0) {
|
||||
if (qSubPlanToString(plan, pDst, pDstLen) < 0) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
goto END;
|
||||
}
|
||||
|
@ -120,6 +127,64 @@ int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddSinkToTask(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, SStreamTask* pTask) {
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
// sink
|
||||
if (pStream->createdBy == STREAM_CREATED_BY__SMA) {
|
||||
pTask->sinkType = TASK_SINK__SMA;
|
||||
pTask->smaSink.smaId = pStream->smaId;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__TABLE;
|
||||
pTask->tbSink.stbUid = pStream->targetStbUid;
|
||||
memcpy(pTask->tbSink.stbFullName, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN);
|
||||
pTask->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddDispatcherToInnerTask(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, SStreamTask* pTask) {
|
||||
pTask->sinkType = TASK_SINK__NONE;
|
||||
if (pStream->fixedSinkVgId == 0) {
|
||||
pTask->dispatchType = TASK_DISPATCH__SHUFFLE;
|
||||
pTask->dispatchMsgType = TDMT_STREAM_TASK_DISPATCH;
|
||||
SDbObj* pDb = mndAcquireDb(pMnode, pStream->targetDb);
|
||||
ASSERT(pDb);
|
||||
|
||||
if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
sdbRelease(pMnode->pSdb, pDb);
|
||||
|
||||
SArray* pVgs = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
|
||||
int32_t sz = taosArrayGetSize(pVgs);
|
||||
SArray* sinkLv = taosArrayGetP(pStream->tasks, 0);
|
||||
int32_t sinkLvSize = taosArrayGetSize(sinkLv);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SVgroupInfo* pVgInfo = taosArrayGet(pVgs, i);
|
||||
for (int32_t j = 0; j < sinkLvSize; j++) {
|
||||
SStreamTask* pLastLevelTask = taosArrayGetP(sinkLv, j);
|
||||
if (pLastLevelTask->nodeId == pVgInfo->vgId) {
|
||||
pVgInfo->taskId = pLastLevelTask->taskId;
|
||||
ASSERT(pVgInfo->taskId != 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pTask->dispatchType = TASK_DISPATCH__FIXED;
|
||||
pTask->dispatchMsgType = TDMT_STREAM_TASK_DISPATCH;
|
||||
SArray* pArray = taosArrayGetP(pStream->tasks, 0);
|
||||
// one sink only
|
||||
ASSERT(taosArrayGetSize(pArray) == 1);
|
||||
SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0);
|
||||
pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId;
|
||||
pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SSubplan* plan, const SVgObj* pVgroup) {
|
||||
int32_t msgLen;
|
||||
pTask->nodeId = pVgroup->vgId;
|
||||
|
@ -132,7 +197,8 @@ int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SS
|
|||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
}
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId);
|
||||
ASSERT(pTask->dispatchType != TASK_DISPATCH__NONE || pTask->sinkType != TASK_SINK__NONE);
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_STREAM_TASK_DEPLOY, pVgroup->vgId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -156,7 +222,7 @@ int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask,
|
|||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
}
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_SND_TASK_DEPLOY, 0);
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_STREAM_TASK_DEPLOY, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -175,7 +241,7 @@ SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) {
|
|||
return pVgroup;
|
||||
}
|
||||
|
||||
int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
SSdb* pSdb = pMnode->pSdb;
|
||||
void* pIter = NULL;
|
||||
SArray* tasks = taosArrayGetP(pStream->tasks, 0);
|
||||
|
@ -186,16 +252,16 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p
|
|||
SVgObj* pVgroup;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != pStream->dbUid) {
|
||||
if (strcmp(pVgroup->dbName, pStream->targetDb) != 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(tasks, &pTask);
|
||||
mndAddTaskToTaskSet(tasks, pTask);
|
||||
|
||||
pTask->nodeId = pVgroup->vgId;
|
||||
pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
@ -222,20 +288,20 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p
|
|||
// dispatch
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId);
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_STREAM_TASK_DEPLOY, pVgroup->vgId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
ASSERT(pStream->fixedSinkVgId != 0);
|
||||
SArray* tasks = taosArrayGetP(pStream->tasks, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(tasks, &pTask);
|
||||
mndAddTaskToTaskSet(tasks, pTask);
|
||||
|
||||
pTask->nodeId = pStream->fixedSinkVgId;
|
||||
#if 0
|
||||
|
@ -267,8 +333,7 @@ int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStr
|
|||
// dispatch
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
|
||||
/*mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId);*/
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pStream->fixedSinkVg.vgId);
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_STREAM_TASK_DEPLOY, pStream->fixedSinkVg.vgId);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -287,32 +352,65 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
pStream->tasks = taosArrayInit(totLevel, sizeof(void*));
|
||||
|
||||
bool hasExtraSink = false;
|
||||
if (totLevel == 2 || strcmp(pStream->sourceDb, pStream->targetDb) != 0) {
|
||||
bool externalTargetDB = strcmp(pStream->sourceDb, pStream->targetDb) != 0;
|
||||
SDbObj* pDbObj = mndAcquireDb(pMnode, pStream->targetDb);
|
||||
ASSERT(pDbObj != NULL);
|
||||
sdbRelease(pSdb, pDbObj);
|
||||
|
||||
bool multiTarget = pDbObj->cfg.numOfVgroups > 1;
|
||||
|
||||
if (totLevel == 2 || externalTargetDB || multiTarget) {
|
||||
SArray* taskOneLevel = taosArrayInit(0, sizeof(void*));
|
||||
taosArrayPush(pStream->tasks, &taskOneLevel);
|
||||
// add extra sink
|
||||
hasExtraSink = true;
|
||||
if (pStream->fixedSinkVgId == 0) {
|
||||
mndAddShuffledSinkToStream(pMnode, pTrans, pStream);
|
||||
mndAddShuffleSinkTasksToStream(pMnode, pTrans, pStream);
|
||||
} else {
|
||||
mndAddFixedSinkToStream(pMnode, pTrans, pStream);
|
||||
mndAddFixedSinkTaskToStream(pMnode, pTrans, pStream);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t level = 0; level < totLevel; level++) {
|
||||
SArray* taskOneLevel = taosArrayInit(0, sizeof(void*));
|
||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, level);
|
||||
ASSERT(LIST_LENGTH(inner->pNodeList) == 1);
|
||||
if (totLevel > 1) {
|
||||
SStreamTask* pFinalTask;
|
||||
// inner plan
|
||||
{
|
||||
SArray* taskInnerLevel = taosArrayInit(0, sizeof(void*));
|
||||
taosArrayPush(pStream->tasks, &taskInnerLevel);
|
||||
|
||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0);
|
||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
ASSERT(plan->subplanType == SUBPLAN_TYPE_MERGE);
|
||||
|
||||
// if (level == totLevel - 1 /* or no snode */) {
|
||||
if (level == totLevel - 1) {
|
||||
// last level, source, must assign to vnode
|
||||
// must be scan type
|
||||
pFinalTask = tNewSStreamTask(pStream->uid);
|
||||
mndAddTaskToTaskSet(taskInnerLevel, pFinalTask);
|
||||
// input
|
||||
pFinalTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK;
|
||||
|
||||
// dispatch
|
||||
if (mndAddDispatcherToInnerTask(pMnode, pTrans, pStream, pFinalTask) < 0) {
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// exec
|
||||
pFinalTask->execType = TASK_EXEC__PIPE;
|
||||
SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->dbUid);
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pFinalTask, plan, pVgroup) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// source plan
|
||||
SArray* taskSourceLevel = taosArrayInit(0, sizeof(void*));
|
||||
taosArrayPush(pStream->tasks, &taskSourceLevel);
|
||||
|
||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 1);
|
||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
ASSERT(plan->subplanType == SUBPLAN_TYPE_SCAN);
|
||||
|
||||
// replicate task to each vnode
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
SVgObj* pVgroup;
|
||||
|
@ -322,152 +420,40 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
// source part
|
||||
pTask->sourceType = TASK_SOURCE__SCAN;
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
mndAddTaskToTaskSet(taskSourceLevel, pTask);
|
||||
|
||||
// input
|
||||
pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK;
|
||||
|
||||
// sink part
|
||||
if (level == 0) {
|
||||
// only for inplace
|
||||
// add fixed vg dispatch
|
||||
pTask->sinkType = TASK_SINK__NONE;
|
||||
if (!hasExtraSink) {
|
||||
#if 1
|
||||
if (pStream->createdBy == STREAM_CREATED_BY__SMA) {
|
||||
pTask->sinkType = TASK_SINK__SMA;
|
||||
pTask->smaSink.smaId = pStream->smaId;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__TABLE;
|
||||
pTask->tbSink.stbUid = pStream->targetStbUid;
|
||||
memcpy(pTask->tbSink.stbFullName, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN);
|
||||
pTask->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__NONE;
|
||||
}
|
||||
|
||||
// dispatch part
|
||||
if (level == 0) {
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
} else {
|
||||
// add fixed ep dispatcher
|
||||
int32_t lastLevel = level - 1;
|
||||
ASSERT(lastLevel == 0);
|
||||
if (hasExtraSink) lastLevel++;
|
||||
SArray* pArray = taosArrayGetP(pStream->tasks, lastLevel);
|
||||
// one merge only
|
||||
ASSERT(taosArrayGetSize(pArray) == 1);
|
||||
SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0);
|
||||
/*pTask->dispatchMsgType = TDMT_VND_TASK_MERGE_EXEC;*/
|
||||
pTask->dispatchMsgType = TDMT_VND_TASK_DISPATCH;
|
||||
pTask->dispatchMsgType = TDMT_STREAM_TASK_DISPATCH;
|
||||
pTask->dispatchType = TASK_DISPATCH__FIXED;
|
||||
|
||||
pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId;
|
||||
pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet;
|
||||
}
|
||||
pTask->fixedEpDispatcher.taskId = pFinalTask->taskId;
|
||||
pTask->fixedEpDispatcher.nodeId = pFinalTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = pFinalTask->epSet;
|
||||
|
||||
// exec part
|
||||
// exec
|
||||
pTask->execType = TASK_EXEC__PIPE;
|
||||
pTask->exec.parallelizable = 1;
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayPush(taskOneLevel, &pTask);
|
||||
}
|
||||
} else {
|
||||
// merge plan
|
||||
|
||||
// TODO if has snode, assign to snode
|
||||
|
||||
// else, assign to vnode
|
||||
ASSERT(plan->subplanType == SUBPLAN_TYPE_MERGE);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
|
||||
// source part, currently only support multi source
|
||||
pTask->sourceType = TASK_SOURCE__PIPE;
|
||||
pTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK;
|
||||
|
||||
// sink part
|
||||
pTask->sinkType = TASK_SINK__NONE;
|
||||
|
||||
// dispatch part
|
||||
ASSERT(hasExtraSink);
|
||||
/*pTask->dispatchType = TASK_DISPATCH__NONE;*/
|
||||
#if 1
|
||||
|
||||
if (hasExtraSink) {
|
||||
// add dispatcher
|
||||
if (pStream->fixedSinkVgId == 0) {
|
||||
pTask->dispatchType = TASK_DISPATCH__SHUFFLE;
|
||||
|
||||
/*pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC;*/
|
||||
pTask->dispatchMsgType = TDMT_VND_TASK_DISPATCH;
|
||||
SDbObj* pDb = mndAcquireDb(pMnode, pStream->targetDb);
|
||||
ASSERT(pDb);
|
||||
if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) {
|
||||
sdbRelease(pSdb, pDb);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pDb);
|
||||
|
||||
// put taskId to useDbRsp
|
||||
// TODO: optimize
|
||||
SArray* pVgs = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
|
||||
int32_t sz = taosArrayGetSize(pVgs);
|
||||
SArray* sinkLv = taosArrayGetP(pStream->tasks, 0);
|
||||
int32_t sinkLvSize = taosArrayGetSize(sinkLv);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SVgroupInfo* pVgInfo = taosArrayGet(pVgs, i);
|
||||
for (int32_t j = 0; j < sinkLvSize; j++) {
|
||||
SStreamTask* pLastLevelTask = taosArrayGetP(sinkLv, j);
|
||||
/*printf("vgid %d node id %d\n", pVgInfo->vgId, pTask->nodeId);*/
|
||||
if (pLastLevelTask->nodeId == pVgInfo->vgId) {
|
||||
pVgInfo->taskId = pLastLevelTask->taskId;
|
||||
/*printf("taskid %d set to %d\n", pVgInfo->taskId, pTask->taskId);*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pTask->dispatchType = TASK_DISPATCH__FIXED;
|
||||
/*pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC;*/
|
||||
pTask->dispatchMsgType = TDMT_VND_TASK_DISPATCH;
|
||||
SArray* pArray = taosArrayGetP(pStream->tasks, 0);
|
||||
// one sink only
|
||||
ASSERT(taosArrayGetSize(pArray) == 1);
|
||||
SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0);
|
||||
pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId;
|
||||
pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// exec part
|
||||
pTask->execType = TASK_EXEC__MERGE;
|
||||
pTask->exec.parallelizable = 0;
|
||||
SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->dbUid);
|
||||
ASSERT(pVgroup);
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayPush(taskOneLevel, &pTask);
|
||||
}
|
||||
|
||||
if (totLevel == 1) {
|
||||
SArray* taskOneLevel = taosArrayInit(0, sizeof(void*));
|
||||
taosArrayPush(pStream->tasks, &taskOneLevel);
|
||||
}
|
||||
|
||||
if (totLevel == 2) {
|
||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0);
|
||||
ASSERT(LIST_LENGTH(inner->pNodeList) == 1);
|
||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
ASSERT(plan->subplanType == SUBPLAN_TYPE_SCAN);
|
||||
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
SVgObj* pVgroup;
|
||||
|
@ -477,27 +463,29 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
mndAddTaskToTaskSet(taskOneLevel, pTask);
|
||||
|
||||
// source part
|
||||
pTask->sourceType = TASK_SOURCE__MERGE;
|
||||
pTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK;
|
||||
// input
|
||||
pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK;
|
||||
|
||||
// sink part
|
||||
pTask->sinkType = TASK_SINK__NONE;
|
||||
|
||||
// dispatch part
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
|
||||
// exec part
|
||||
pTask->execType = TASK_EXEC__NONE;
|
||||
pTask->exec.parallelizable = 0;
|
||||
}
|
||||
// sink or dispatch
|
||||
if (hasExtraSink) {
|
||||
mndAddDispatcherToInnerTask(pMnode, pTrans, pStream, pTask);
|
||||
} else {
|
||||
mndAddSinkToTask(pMnode, pTrans, pStream, pTask);
|
||||
}
|
||||
|
||||
// free memory
|
||||
// exec
|
||||
pTask->execType = TASK_EXEC__PIPE;
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
qDestroyQueryPlan(pPlan);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns +
|
||||
blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(pBlock);
|
||||
blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(pBlock->info.numOfCols);
|
||||
|
||||
SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
|
||||
if (pRsp == NULL) {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "parser.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define TSDB_SMA_VER_NUMBER 1
|
||||
|
@ -40,6 +41,7 @@ static int32_t mndSmaGetVgEpSet(SMnode *pMnode, SDbObj *pDb, SVgEpSet **ppVgEpS
|
|||
static int32_t mndProcessMCreateSmaReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessMDropSmaReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessGetSmaReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq);
|
||||
static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
static void mndCancelGetNextSma(SMnode *pMnode, void *pIter);
|
||||
|
||||
|
@ -59,6 +61,7 @@ int32_t mndInitSma(SMnode *pMnode) {
|
|||
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_SMA_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_SMA_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_GET_INDEX, mndProcessGetSmaReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_GET_TABLE_INDEX, mndProcessGetTbSmaReq);
|
||||
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndRetrieveSma);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndCancelGetNextSma);
|
||||
|
@ -80,10 +83,12 @@ static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
|
|||
SDB_SET_BINARY(pRaw, dataPos, pSma->name, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSma->stb, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSma->db, TSDB_DB_FNAME_LEN, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSma->dstTbName, TSDB_DB_FNAME_LEN, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pSma->createdTime, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pSma->uid, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pSma->stbUid, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pSma->dbUid, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pSma->dstTbUid, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pSma->intervalUnit, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pSma->slidingUnit, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pSma->timezone, _OVER)
|
||||
|
@ -145,10 +150,12 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_BINARY(pRaw, dataPos, pSma->name, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSma->stb, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSma->db, TSDB_DB_FNAME_LEN, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSma->dstTbName, TSDB_DB_FNAME_LEN, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pSma->createdTime, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pSma->uid, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pSma->stbUid, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pSma->dbUid, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pSma->dstTbUid, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSma->intervalUnit, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSma->slidingUnit, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSma->timezone, _OVER)
|
||||
|
@ -258,13 +265,16 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm
|
|||
req.tagsFilterLen = pSma->tagsFilterLen;
|
||||
req.indexUid = pSma->uid;
|
||||
req.tableUid = pSma->stbUid;
|
||||
req.dstVgId = pSma->dstVgId;
|
||||
req.dstTbUid = pSma->dstTbUid;
|
||||
req.interval = pSma->interval;
|
||||
req.offset = pSma->offset;
|
||||
req.sliding = pSma->sliding;
|
||||
req.expr = pSma->expr;
|
||||
req.tagsFilter = pSma->tagsFilter;
|
||||
req.numOfVgroups = pSma->numOfVgroups;
|
||||
req.pVgEpSet = pSma->pVgEpSet;
|
||||
req.schemaRow = pSma->schemaRow;
|
||||
req.schemaTag = pSma->schemaTag;
|
||||
req.dstTbName = pSma->dstTbName;
|
||||
|
||||
// get length
|
||||
int32_t ret = 0;
|
||||
|
@ -423,14 +433,30 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans,
|
|||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
// todo add sma info here
|
||||
SVgEpSet *pVgEpSet = NULL;
|
||||
int32_t numOfVgroups = 0;
|
||||
if (mndSmaGetVgEpSet(pMnode, pDb, &pVgEpSet, &numOfVgroups) != 0) {
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pSma->ast, &pAst) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (qExtractResultSchema(pAst, &pSma->schemaRow.nCols, &pSma->schemaRow.pSchema) != 0) {
|
||||
nodesDestroyNode(pAst);
|
||||
return -1;
|
||||
}
|
||||
nodesDestroyNode(pAst);
|
||||
pSma->schemaRow.version = 1;
|
||||
|
||||
// TODO: the schemaTag generated by qExtractResultXXX later.
|
||||
pSma->schemaTag.nCols = 1;
|
||||
pSma->schemaTag.version = 1;
|
||||
pSma->schemaTag.pSchema = taosMemoryCalloc(1, sizeof(SSchema));
|
||||
if (!pSma->schemaTag.pSchema) {
|
||||
return -1;
|
||||
}
|
||||
pSma->schemaTag.pSchema[0].type = TSDB_DATA_TYPE_BIGINT;
|
||||
pSma->schemaTag.pSchema[0].bytes = TYPE_BYTES[TSDB_DATA_TYPE_BIGINT];
|
||||
pSma->schemaTag.pSchema[0].colId = pSma->schemaRow.nCols + PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
pSma->schemaTag.pSchema[0].flags = 0;
|
||||
snprintf(pSma->schemaTag.pSchema[0].name, TSDB_COL_NAME_LEN, "groupId");
|
||||
|
||||
pSma->pVgEpSet = pVgEpSet;
|
||||
pSma->numOfVgroups = numOfVgroups;
|
||||
|
||||
int32_t smaContLen = 0;
|
||||
void *pSmaReq = mndBuildVCreateSmaReq(pMnode, pVgroup, pSma, &smaContLen);
|
||||
|
@ -462,12 +488,15 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
|
|||
memcpy(smaObj.db, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
smaObj.createdTime = taosGetTimestampMs();
|
||||
smaObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
char resultTbName[TSDB_TABLE_FNAME_LEN + 16] = {0};
|
||||
snprintf(resultTbName, TSDB_TABLE_FNAME_LEN + 16, "td.tsma.rst.tb.%s", pCreate->name);
|
||||
memcpy(smaObj.dstTbName, resultTbName, TSDB_TABLE_FNAME_LEN);
|
||||
smaObj.dstTbUid = mndGenerateUid(smaObj.dstTbName, TSDB_TABLE_FNAME_LEN);
|
||||
smaObj.stbUid = pStb->uid;
|
||||
smaObj.dbUid = pStb->dbUid;
|
||||
smaObj.intervalUnit = pCreate->intervalUnit;
|
||||
smaObj.slidingUnit = pCreate->slidingUnit;
|
||||
smaObj.timezone = pCreate->timezone;
|
||||
smaObj.dstVgId = pCreate->dstVgId;
|
||||
smaObj.interval = pCreate->interval;
|
||||
smaObj.offset = pCreate->offset;
|
||||
smaObj.sliding = pCreate->sliding;
|
||||
|
@ -870,6 +899,64 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndGetTableSma(SMnode *pMnode, STableIndexReq *indexReq, STableIndexRsp *rsp, bool *exist) {
|
||||
int32_t code = 0;
|
||||
SSmaObj *pSma = NULL;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
STableIndexInfo info;
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_SMA, pIter, (void **)&pSma);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (pSma->stb[0] != indexReq->tbFName[0] || strcmp(pSma->stb, indexReq->tbFName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
info.intervalUnit = pSma->intervalUnit;
|
||||
info.slidingUnit = pSma->slidingUnit;
|
||||
info.interval = pSma->interval;
|
||||
info.offset = pSma->offset;
|
||||
info.sliding = pSma->sliding;
|
||||
info.dstTbUid = pSma->dstTbUid;
|
||||
info.dstVgId = pSma->dstVgId;
|
||||
|
||||
SVgObj* pVg = mndAcquireVgroup(pMnode, pSma->dstVgId);
|
||||
if (pVg == NULL) {
|
||||
code = -1;
|
||||
sdbRelease(pSdb, pSma);
|
||||
return code;
|
||||
}
|
||||
info.epSet = mndGetVgroupEpset(pMnode, pVg);
|
||||
|
||||
info.expr = taosMemoryMalloc(pSma->exprLen + 1);
|
||||
if (info.expr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
sdbRelease(pSdb, pSma);
|
||||
return code;
|
||||
}
|
||||
|
||||
memcpy(info.expr, pSma->expr, pSma->exprLen);
|
||||
info.expr[pSma->exprLen] = 0;
|
||||
|
||||
if (NULL == taosArrayPush(rsp->pIndex, &info)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
taosMemoryFree(info.expr);
|
||||
sdbRelease(pSdb, pSma);
|
||||
return code;
|
||||
}
|
||||
|
||||
*exist = true;
|
||||
|
||||
sdbRelease(pSdb, pSma);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessGetSmaReq(SRpcMsg *pReq) {
|
||||
SUserIndexReq indexReq = {0};
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
|
@ -916,6 +1003,59 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) {
|
||||
STableIndexReq indexReq = {0};
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
int32_t code = -1;
|
||||
STableIndexRsp rsp = {0};
|
||||
bool exist = false;
|
||||
|
||||
if (tDeserializeSTableIndexReq(pReq->pCont, pReq->contLen, &indexReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
rsp.pIndex = taosArrayInit(10, sizeof(STableIndexInfo));
|
||||
if (NULL == rsp.pIndex) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = mndGetTableSma(pMnode, &indexReq, &rsp, &exist);
|
||||
if (code) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!exist) {
|
||||
code = -1;
|
||||
terrno = TSDB_CODE_MND_DB_INDEX_NOT_EXIST;
|
||||
} else {
|
||||
int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &rsp);
|
||||
void *pRsp = rpcMallocCont(contLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
tSerializeSTableIndexRsp(pRsp, contLen, &rsp);
|
||||
|
||||
pReq->info.rsp = pRsp;
|
||||
pReq->info.rspLen = contLen;
|
||||
|
||||
code = 0;
|
||||
}
|
||||
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
mError("failed to get table index %s since %s", indexReq.tbFName, terrstr());
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
@ -975,52 +1115,3 @@ static void mndCancelGetNextSma(SMnode *pMnode, void *pIter) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
static int32_t mndSmaGetVgEpSet(SMnode *pMnode, SDbObj *pDb, SVgEpSet **ppVgEpSet, int32_t *numOfVgroups) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void *pIter = NULL;
|
||||
SVgEpSet *pVgEpSet = NULL;
|
||||
int32_t nAllocVgs = 16;
|
||||
int32_t nVgs = 0;
|
||||
|
||||
pVgEpSet = taosMemoryCalloc(nAllocVgs, sizeof(SVgEpSet));
|
||||
if (!pVgEpSet) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != pDb->uid) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nVgs >= nAllocVgs) {
|
||||
void *p = taosMemoryRealloc(pVgEpSet, nAllocVgs * 2 * sizeof(SVgEpSet));
|
||||
if (!p) {
|
||||
taosMemoryFree(pVgEpSet);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pVgEpSet = (SVgEpSet *)p;
|
||||
nAllocVgs *= 2;
|
||||
}
|
||||
|
||||
(pVgEpSet + nVgs)->vgId = pVgroup->vgId;
|
||||
(pVgEpSet + nVgs)->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
++nVgs;
|
||||
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
*ppVgEpSet = pVgEpSet;
|
||||
*numOfVgroups = nVgs;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -395,13 +395,13 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
req.pRSmaParam.xFilesFactor = pStb->xFilesFactor;
|
||||
req.pRSmaParam.delay = pStb->delay;
|
||||
if (pStb->ast1Len > 0) {
|
||||
if (mndConvertRSmaTask(pStb->pAst1, pStb->uid, 0, 0, &req.pRSmaParam.qmsg1, &req.pRSmaParam.qmsg1Len,
|
||||
if (mndConvertRsmaTask(&req.pRSmaParam.qmsg1, &req.pRSmaParam.qmsg1Len, pStb->pAst1, pStb->uid, STREAM_TRIGGER_AT_ONCE, 0,
|
||||
req.pRSmaParam.xFilesFactor) != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (pStb->ast2Len > 0) {
|
||||
if (mndConvertRSmaTask(pStb->pAst2, pStb->uid, 0, 0, &req.pRSmaParam.qmsg2, &req.pRSmaParam.qmsg2Len,
|
||||
if (mndConvertRsmaTask(&req.pRSmaParam.qmsg2, &req.pRSmaParam.qmsg2Len, pStb->pAst2, pStb->uid, STREAM_TRIGGER_AT_ONCE, 0,
|
||||
req.pRSmaParam.xFilesFactor) != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -54,8 +54,8 @@ int32_t mndInitStream(SMnode *pMnode) {
|
|||
};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STREAM, mndProcessCreateStreamReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_TASK_DEPLOY_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_SND_TASK_DEPLOY_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_STREAM_TASK_DEPLOY_RSP, mndTransProcessRsp);
|
||||
/*mndSetMsgHandle(pMnode, TDMT_SND_TASK_DEPLOY_RSP, mndTransProcessRsp);*/
|
||||
/*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM, mndProcessDropStreamReq);*/
|
||||
/*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM_RSP, mndProcessDropStreamInRsp);*/
|
||||
|
||||
|
@ -252,8 +252,12 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast
|
|||
}
|
||||
|
||||
if (qExtractResultSchema(pAst, (int32_t *)&pStream->outputSchema.nCols, &pStream->outputSchema.pSchema) != 0) {
|
||||
nodesDestroyNode(pAst);
|
||||
return -1;
|
||||
}
|
||||
// free
|
||||
nodesDestroyNode(pAst);
|
||||
|
||||
|
||||
#if 0
|
||||
printf("|");
|
||||
|
|
|
@ -402,7 +402,8 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
}
|
||||
|
||||
static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOutputObj *pOutput) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pMsg);
|
||||
mndTransSetDbName(pTrans, pOutput->pSub->dbName);
|
||||
if (pTrans == NULL) return -1;
|
||||
|
||||
// make txn:
|
||||
|
@ -547,6 +548,7 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
|
|||
taosRLockLatch(&pTopic->lock);
|
||||
|
||||
rebOutput.pSub = mndCreateSub(pMnode, pTopic, pRebInfo->key);
|
||||
memcpy(rebOutput.pSub->dbName, pTopic->db, TSDB_DB_FNAME_LEN);
|
||||
ASSERT(taosHashGetSize(rebOutput.pSub->consumerHash) == 0);
|
||||
|
||||
taosRUnLockLatch(&pTopic->lock);
|
||||
|
|
|
@ -17,15 +17,27 @@
|
|||
#include "mndSync.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
int32_t mndSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
static int32_t mndSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
|
||||
return tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg);
|
||||
int32_t code = tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg);
|
||||
if (code != 0) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { return tmsgSendReq(pEpSet, pMsg); }
|
||||
static int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int32_t code = tmsgSendReq(pEpSet, pMsg);
|
||||
if (code != 0) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
SMnode *pMnode = pFsm->data;
|
||||
|
@ -34,7 +46,7 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
|
|||
|
||||
int32_t transId = sdbGetIdFromRaw(pMnode->pSdb, pRaw);
|
||||
pMgmt->errCode = cbMeta.code;
|
||||
mTrace("trans:%d, is proposed, savedTransId:%d code:0x%x, ver:%" PRId64 " term:%" PRId64 " role:%s raw:%p", transId,
|
||||
mDebug("trans:%d, is proposed, saved:%d code:0x%x, index:%" PRId64 " term:%" PRId64 " role:%s raw:%p", transId,
|
||||
pMgmt->transId, cbMeta.code, cbMeta.index, cbMeta.term, syncStr(cbMeta.state), pRaw);
|
||||
|
||||
if (pMgmt->errCode == 0) {
|
||||
|
@ -49,7 +61,17 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
|
|||
}
|
||||
tsem_post(&pMgmt->syncSem);
|
||||
} else {
|
||||
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
||||
if (pTrans != NULL) {
|
||||
mndTransExecute(pMnode, pTrans);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
}
|
||||
|
||||
if (cbMeta.index - sdbGetApplyIndex(pMnode->pSdb) > 100) {
|
||||
SSnapshotMeta sMeta = {0};
|
||||
if (syncGetSnapshotMeta(pMnode->syncMgmt.sync, &sMeta) == 0) {
|
||||
sdbSetCurConfig(pMnode->pSdb, sMeta.lastConfigIndex);
|
||||
}
|
||||
sdbWriteFile(pMnode->pSdb);
|
||||
}
|
||||
}
|
||||
|
@ -57,13 +79,20 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
|
|||
|
||||
int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) {
|
||||
SMnode *pMnode = pFsm->data;
|
||||
pSnapshot->lastApplyIndex = sdbGetApplyIndex(pMnode->pSdb);
|
||||
pSnapshot->lastApplyTerm = sdbGetApplyTerm(pMnode->pSdb);
|
||||
pSnapshot->lastApplyIndex = sdbGetCommitIndex(pMnode->pSdb);
|
||||
pSnapshot->lastApplyTerm = sdbGetCommitTerm(pMnode->pSdb);
|
||||
pSnapshot->lastConfigIndex = sdbGetCurConfig(pMnode->pSdb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mndRestoreFinish(struct SSyncFSM *pFsm) {
|
||||
SMnode *pMnode = pFsm->data;
|
||||
|
||||
SSnapshotMeta sMeta = {0};
|
||||
if (syncGetSnapshotMeta(pMnode->syncMgmt.sync, &sMeta) == 0) {
|
||||
sdbSetCurConfig(pMnode->pSdb, sMeta.lastConfigIndex);
|
||||
}
|
||||
|
||||
if (!pMnode->deploy) {
|
||||
mInfo("mnode sync restore finished, and will handle outstanding transactions");
|
||||
mndTransPullup(pMnode);
|
||||
|
@ -73,13 +102,21 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) {
|
|||
}
|
||||
}
|
||||
|
||||
void mndReConfig(struct SSyncFSM *pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) {
|
||||
void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbMeta) {
|
||||
SMnode *pMnode = pFsm->data;
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
|
||||
#if 0
|
||||
// send response
|
||||
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen, .conn.applyIndex = cbMeta.index};
|
||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
||||
syncGetAndDelRespRpc(pMnode->syncMgmt.sync, cbMeta.seqNum, &rpcMsg.info);
|
||||
#endif
|
||||
|
||||
pMgmt->errCode = cbMeta.code;
|
||||
mInfo("trans:-1, sync reconfig is proposed, savedTransId:%d code:0x%x, curTerm:%" PRId64 " term:%" PRId64,
|
||||
pMgmt->transId, cbMeta.code, cbMeta.index, cbMeta.term);
|
||||
mInfo("trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%" PRId64 " term:%" PRId64, pMgmt->transId,
|
||||
cbMeta.code, cbMeta.index, cbMeta.term);
|
||||
|
||||
if (pMgmt->transId == -1) {
|
||||
if (pMgmt->errCode != 0) {
|
||||
|
@ -144,29 +181,12 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
|
|||
int32_t mndInitSync(SMnode *pMnode) {
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
|
||||
char path[PATH_MAX + 20] = {0};
|
||||
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
||||
SWalCfg cfg = {
|
||||
.vgId = 1,
|
||||
.fsyncPeriod = 0,
|
||||
.rollPeriod = -1,
|
||||
.segSize = -1,
|
||||
.retentionPeriod = -1,
|
||||
.retentionSize = -1,
|
||||
.level = TAOS_WAL_FSYNC,
|
||||
};
|
||||
|
||||
pMgmt->pWal = walOpen(path, &cfg);
|
||||
if (pMgmt->pWal == NULL) {
|
||||
mError("failed to open wal since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSyncInfo syncInfo = {.vgId = 1, .FpSendMsg = mndSyncSendMsg, .FpEqMsg = mndSyncEqMsg};
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP);
|
||||
syncInfo.pWal = pMgmt->pWal;
|
||||
syncInfo.pWal = pMnode->pWal;
|
||||
syncInfo.pFsm = mndSyncMakeFsm(pMnode);
|
||||
syncInfo.isStandBy = pMgmt->standby;
|
||||
syncInfo.snapshotEnable = true;
|
||||
|
||||
SSyncCfg *pCfg = &syncInfo.syncCfg;
|
||||
pCfg->replicaNum = pMnode->replica;
|
||||
|
@ -186,20 +206,16 @@ int32_t mndInitSync(SMnode *pMnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
mDebug("mnode sync is opened, id:%" PRId64, pMgmt->sync);
|
||||
mDebug("mnode-sync is opened, id:%" PRId64, pMgmt->sync);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mndCleanupSync(SMnode *pMnode) {
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
syncStop(pMgmt->sync);
|
||||
mDebug("mnode sync is stopped, id:%" PRId64, pMgmt->sync);
|
||||
mDebug("mnode-sync is stopped, id:%" PRId64, pMgmt->sync);
|
||||
|
||||
tsem_destroy(&pMgmt->syncSem);
|
||||
if (pMgmt->pWal != NULL) {
|
||||
walClose(pMgmt->pWal);
|
||||
}
|
||||
|
||||
memset(pMgmt, 0, sizeof(SSyncMgmt));
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue