Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
77f27b62
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
77f27b62
编写于
8月 16, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of
https://github.com/taosdata/TDengine
into refact/tsdb_last
上级
fde0bf83
131b7670
变更
16
显示空白变更内容
内联
并排
Showing
16 changed file
with
2153 addition
and
1780 deletion
+2153
-1780
docs/examples/node/nativeexample/subscribe_demo.js
docs/examples/node/nativeexample/subscribe_demo.js
+3
-2
docs/zh/07-develop/07-tmq.mdx
docs/zh/07-develop/07-tmq.mdx
+20
-4
docs/zh/12-taos-sql/29-changes.md
docs/zh/12-taos-sql/29-changes.md
+103
-0
docs/zh/12-taos-sql/index.md
docs/zh/12-taos-sql/index.md
+1
-1
docs/zh/14-reference/12-config/index.md
docs/zh/14-reference/12-config/index.md
+170
-0
docs/zh/28-releases.md
docs/zh/28-releases.md
+1
-1
examples/c/tmq.c
examples/c/tmq.c
+11
-23
include/client/taos.h
include/client/taos.h
+22
-18
include/util/taoserror.h
include/util/taoserror.h
+1
-0
include/util/tref.h
include/util/tref.h
+2
-2
source/client/src/clientMain.c
source/client/src/clientMain.c
+1
-0
source/client/src/taosx.c
source/client/src/taosx.c
+1628
-0
source/client/src/tmq.c
source/client/src/tmq.c
+187
-1727
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+1
-1
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+1
-1
source/util/src/terror.c
source/util/src/terror.c
+1
-0
未找到文件。
docs/examples/node/nativeexample/subscribe_demo.js
浏览文件 @
77f27b62
...
...
@@ -28,7 +28,8 @@ function runConsumer() {
console
.
log
(
msg
.
topicPartition
);
console
.
log
(
msg
.
block
);
console
.
log
(
msg
.
fields
)
consumer
.
commit
(
msg
);
// fixme(@xiaolei): commented temp, should be fixed.
//consumer.commit(msg);
console
.
log
(
`=======consumer
${
i
}
done`
)
}
...
...
docs/zh/07-develop/07-tmq.mdx
浏览文件 @
77f27b62
...
...
@@ -238,6 +238,9 @@ public class MetersDeserializer extends ReferenceDeserializer<Meters> {
一个 consumer 支持同时订阅多个 topic。
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
```c
// 创建订阅 topics 列表
tmq_list_t* topicList = tmq_list_new();
...
...
@@ -248,8 +251,23 @@ tmq_list_destroy(topicList);
```
</TabItem>
<TabItem value="java" label="Java">
```java
List<String> topics = new ArrayList<>();
topics.add("tmq_topic");
consumer.subscribe(topics);
```
</TabItem>
</Tabs>
## 消费
以下代码展示了不同语言下如何对 TMQ 消息进行消费。
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
...
...
@@ -267,10 +285,6 @@ while (running) {
<TabItem value="java" label="Java">
```java
List<String> topics = new ArrayList<>();
topics.add("tmq_topic");
consumer.subscribe(topics);
while(running){
ConsumerRecords<Meters> meters = consumer.poll(Duration.ofMillis(100));
for (Meters meter : meters) {
...
...
@@ -284,6 +298,8 @@ while(running){
## 结束消费
消费结束后,应当取消订阅。
<Tabs defaultValue="java" groupId="lang">
<TabItem value="c" label="C">
...
...
docs/zh/12-taos-sql/29-changes.md
0 → 100644
浏览文件 @
77f27b62
---
sidebar_label
:
3.0 版本语法变更
title
:
3.0 版本语法变更
description
:
"
TDengine
3.0
版本的语法变更说明"
---
## SQL 基本元素变更
| # |
**元素**
|
**差异性**
|
**说明**
|
| - | :-------: | :--------: | :------- |
| 1 | VARCHAR | 新增 | BINARY类型的别名。
| 2 | TIMESTAMP字面量 | 新增 | 新增支持 TIMESTAMP 'timestamp format' 语法。
| 3 | _ROWTS伪列 | 新增 | 表示时间戳主键。是_C0伪列的别名。
| 4 | INFORMATION_SCHEMA | 新增 | 包含各种SCHEMA定义的系统数据库。
| 5 | PERFORMANCE_SCHEMA | 新增 | 包含运行信息的系统数据库。
| 6 | 连续查询 | 废除 | 不再支持连续查询。相关的各种语法和接口废除。
| 7 | 混合运算 | 增强 | 查询中的混合运算(标量运算和矢量运算混合)全面增强,SELECT的各个子句均全面支持符合语法语义的混合运算。
| 8 | 标签运算 | 新增 |在查询中,标签列可以像普通列一样参与各种运算,用于各种子句。
| 9 | 时间线子句和时间函数用于超级表查询 | 增强 |没有PARTITION BY时,超级表的数据会被合并成一条时间线。
## SQL 语句变更
在 TDengine 中,普通表的数据模型中可使用以下数据类型。
| # |
**语句**
|
**差异性**
|
**说明**
|
| - | :-------: | :--------: | :------- |
| 1 | ALTER ACCOUNT | 废除 | 2.x中为企业版功能,3.0不再支持。语法暂时保留了,执行报“This statement is no longer supported”错误。
| 2 | ALTER ALL DNODES | 新增 | 修改所有DNODE的参数。
| 3 | ALTER DATABASE | 调整 | 废除
<ul><li>
QUORUM:写入需要的副本确认数。3.0版本使用STRICT来指定强一致还是弱一致。3.0.0版本STRICT暂不支持修改。
</li><li>
BLOCKS:VNODE使用的内存块数。3.0版本使用BUFFER来表示VNODE写入内存池的大小。
</li><li>
UPDATE:更新操作的支持模式。3.0版本所有数据库都支持部分列更新。
</li><li>
CACHELAST:缓存最新一行数据的模式。3.0版本用CACHEMODEL代替。
</li><li>
COMP:3.0版本暂不支持修改。
<br/>
新增
</li><li>
CACHEMODEL:表示是否在内存中缓存子表的最近数据。
</li><li>
CACHESIZE:表示缓存子表最近数据的内存大小。
</li><li>
WAL_FSYNC_PERIOD:代替原FSYNC参数。
</li><li>
WAL_LEVEL:代替原WAL参数。
<br/>
调整
</li><li>
REPLICA:3.0.0版本暂不支持修改。
</li><li>
KEEP:3.0版本新增支持带单位的设置方式。
</li></ul>
| 4 | ALTER STABLE | 调整 | 废除
<ul><li>
CHANGE TAG:修改标签列的名称。3.0版本使用RENAME TAG代替。
<br/>
新增
</li><li>
RENAME TAG:代替原CHANGE TAG子句。
</li><li>
COMMENT:修改超级表的注释。
</li></ul>
| 5 | ALTER TABLE | 调整 | 废除
<ul><li>
CHANGE TAG:修改标签列的名称。3.0版本使用RENAME TAG代替。
<br/>
新增
</li><li>
RENAME TAG:代替原CHANGE TAG子句。
</li><li>
COMMENT:修改表的注释。
</li><li>
TTL:修改表的生命周期。
</li></ul>
| 6 | ALTER USER | 调整 | 废除
<ul><li>
PRIVILEGE:修改用户权限。3.0版本使用GRANT和REVOKE来授予和回收权限。
<br/>
新增
</li><li>
ENABLE:启用或停用此用户。
</li><li>
SYSINFO:修改用户是否可查看系统信息。
</li></ul>
| 7 | BALANCE VGROUP | 新增 | 集群存储负载均衡。3.0.0版本暂不支持。
| 8 | COMPACT VNODES | 暂不支持 | 整理指定VNODE的数据。3.0.0版本暂不支持。
| 9 | CREATE ACCOUNT | 废除 | 2.x中为企业版功能,3.0不再支持。语法暂时保留了,执行报“This statement is no longer supported”错误。
| 10 | CREATE DATABASE | 调整 | 废除
<ul><li>
BLOCKS:VNODE使用的内存块数。3.0版本使用BUFFER来表示VNODE写入内存池的大小。
</li><li>
CACHE:VNODE使用的内存块的大小。3.0版本使用BUFFER来表示VNODE写入内存池的大小。
</li><li>
CACHELAST:缓存最新一行数据的模式。3.0版本用CACHEMODEL代替。
</li><li>
DAYS:数据文件存储数据的时间跨度。3.0版本使用DURATION代替。
</li><li>
FSYNC:当 WAL 设置为 2 时,执行 fsync 的周期。3.0版本使用WAL_FSYNC_PERIOD代替。
</li><li>
QUORUM:写入需要的副本确认数。3.0版本使用STRICT来指定强一致还是弱一致。
</li><li>
UPDATE:更新操作的支持模式。3.0版本所有数据库都支持部分列更新。
</li><li>
WAL:WAL 级别。3.0版本使用WAL_LEVEL代替。
<br/>
新增
</li><li>
BUFFER:一个 VNODE 写入内存池大小。
</li><li>
CACHEMODEL:表示是否在内存中缓存子表的最近数据。
</li><li>
CACHESIZE:表示缓存子表最近数据的内存大小。
</li><li>
DURATION:代替原DAYS参数。新增支持带单位的设置方式。
</li><li>
PAGES:一个 VNODE 中元数据存储引擎的缓存页个数。
</li><li>
PAGESIZE:一个 VNODE 中元数据存储引擎的页大小。
</li><li>
RETENTIONS:表示数据的聚合周期和保存时长。
</li><li>
STRICT:表示数据同步的一致性要求。
</li><li>
SINGLE_STABLE:表示此数据库中是否只可以创建一个超级表。
</li><li>
VGROUPS:数据库中初始VGROUP的数目。
</li><li>
WAL_FSYNC_PERIOD:代替原FSYNC参数。
</li><li>
WAL_LEVEL:代替原WAL参数。
</li><li>
WAL_RETENTION_PERIOD:wal文件的额外保留策略,用于数据订阅。
</li><li>
WAL_RETENTION_SIZE:wal文件的额外保留策略,用于数据订阅。
</li><li>
WAL_ROLL_PERIOD:wal文件切换时长。
</li><li>
WAL_SEGMENT_SIZE:wal单个文件大小。
<br/>
调整
</li><li>
KEEP:3.0版本新增支持带单位的设置方式。
</li></ul>
| 11 | CREATE DNODE | 调整 | 新增主机名和端口号分开指定语法
<ul><li>
CREATE DNODE dnode_host_name PORT port_val
</li></ul>
| 12 | CREATE INDEX | 新增 | 创建SMA索引。
| 13 | CREATE MNODE | 新增 | 创建管理节点。
| 14 | CREATE QNODE | 新增 | 创建查询节点。
| 15 | CREATE SNODE | 新增 | 创建流计算节点。3.0.0版本暂不支持。
| 16 | CREATE STABLE | 调整 | 新增表参数语法
<li>
COMMENT:表注释。
</li>
| 17 | CREATE STREAM | 新增 | 创建流。
| 18 | CREATE TABLE | 调整 | 新增表参数语法
<ul><li>
COMMENT:表注释。
</li><li>
WATERMARK:指定窗口的关闭时间。
</li><li>
MAX_DELAY:用于控制推送计算结果的最大延迟。
</li><li>
ROLLUP:指定的聚合函数,提供基于多层级的降采样聚合结果。
</li><li>
SMA:提供基于数据块的自定义预计算功能。
</li><li>
TTL:用来指定表的生命周期的参数。
</li></ul>
| 18 | CREATE TOPIC | 新增 | 创建订阅主题。
| 19 | DROP ACCOUNT | 废除 | 2.x中为企业版功能,3.0不再支持。语法暂时保留了,执行报“This statement is no longer supported”错误。
| 20 | DROP BNODE | 新增 | 删除backup节点。3.0.0版本暂不支持。
| 21 | DROP CONSUMER GROUP | 新增 | 删除消费组。
| 22 | DROP DNODE | 新增 | 删除数据节点。3.0.0版本暂不支持。
| 23 | DROP INDEX | 新增 | 删除索引。
| 24 | DROP MNODE | 新增 | 创建管理节点。
| 25 | DROP QNODE | 新增 | 创建查询节点。
| 26 | DROP SNODE | 新增 | 删除流计算节点。3.0.0版本暂不支持。
| 27 | DROP STREAM | 新增 | 删除流。
| 28 | DROP TABLE | 调整 | 新增批量删除语法
| 29 | DROP TOPIC | 新增 | 删除订阅主题。
| 30 | EXPLAIN | 新增 | 查看查询语句的执行计划。
| 31 | GRANT | 新增 | 授予用户权限。
| 32 | KILL TRANSACTION | 新增 | 终止管理节点的事务。
| 33 | KILL STREAM | 废除 | 终止连续查询。3.0版本不再支持连续查询,而是用更通用的流计算来代替。
| 34 | MERGE VGROUP | 新增 | 合并VGROUP。
| 35 | REDISTRIBUTE VGROUP | 新增 | 调整VGROUP的数据分布。3.0.0版本暂不支持。
| 36 | REVOKE | 新增 | 回收用户权限。
| 37 | SELECT | 调整 |
<ul><li>
SELECT关闭隐式结果列,输出列均需要由SELECT子句来指定。
</li><li>
DISTINCT功能全面支持。2.x版本只支持对标签列去重,并且不可以和JOIN、GROUP BY等子句混用。
</li><li>
JOIN功能增强。增加支持:JOIN后WHERE条件中有OR条件;JOIN后的多表运算;JOIN后的多表GROUP BY。
</li><li>
FROM后子查询功能大幅增强。不限制子查询嵌套层数;支持子查询和UNION ALL混合使用;移除其他一些之前版本的语法限制。
</li><li>
WHERE后可以使用任意的标量表达式。
</li><li>
GROUP BY功能增强。支持任意标量表达式及其组合的分组。
</li><li>
SESSION可以用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
</li><li>
STATE_WINDOW可以用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
</li><li>
ORDER BY功能大幅增强。不再必须和GROUP BY子句一起使用;不再有排序表达式个数的限制;增加支持NULLS FIRST/LAST语法功能;支持符合语法语义的任意表达式。
</li><li>
新增PARTITION BY语法。替代原来的GROUP BY tags。
</li></ul>
| 38 | SHOW ACCOUNTS | 废除 | 2.x中为企业版功能,3.0不再支持。语法暂时保留了,执行报“This statement is no longer supported”错误。
| 39 | SHOW APPS |新增 | 显示接入集群的应用(客户端)信息。
| 40 | SHOW BNODES |新增 | 显示当前系统中存在的 BNODE 的信息。3.0.0版本暂不支持。
| 41 | SHOW CONSUMERS | 新增 | 显示当前数据库下所有活跃的消费者的信息。
| 42 | SHOW DATABASES | 调整 | 3.0版本只显示数据库名。
| 43 | SHOW FUNCTIONS | 调整 | 3.0版本只显示自定义函数名。
| 44 | SHOW LICENCE | 新增 | 和SHOW GRANTS 命令等效。
| 45 | SHOW INDEXES | 新增 | 显示已创建的索引。
| 46 | SHOW LOCAL VARIABLES | 新增 | 显示当前客户端配置参数的运行值。
| 47 | SHOW MODULES | 废除 | 显示当前系统中所安装的组件的信息。
| 48 | SHOW QNODES | 新增 | 显示当前系统中QNODE的信息。
| 49 | SHOW SNODES | 新增 | 显示当前系统中SNODE的信息。3.0.0版本暂不支持。
| 50 | SHOW STABLES | 调整 | 3.0版本只显示超级表名。
| 51 | SHOW STREAMS | 调整 | 2.x版本此命令显示系统中已创建的连续查询的信息。3.0版本废除了连续查询,用流代替。此命令显示已创建的流。
| 52 | SHOW SUBSCRIPTIONS | 新增 | 显示当前数据库下的所有的订阅关系
| 53 | SHOW TABLES | 调整 | 3.0版本只显示表名。
| 54 | SHOW TABLE DISTRIBUTED | 新增 | 显示表的数据分布信息。代替2.x版本中的SELECT _block_dist() FROM { tb_name | stb_name }方式。
| 55 | SHOW TOPICS | 新增 | 显示当前数据库下的所有订阅主题。
| 56 | SHOW TRANSACTIONS | 新增 | 显示当前系统中正在执行的事务的信息。
| 57 | SHOW DNODE VARIABLES | 新增 |显示指定DNODE的配置参数。
| 58 | SHOW VNODES | 暂不支持 | 显示当前系统中VNODE的信息。3.0.0版本暂不支持。
| 59 | SPLIT VGROUP | 新增 | 拆分VGROUP。
| 60 | TRIM DATABASE | 新增 | 删除过期数据,并根据多级存储的配置归整数据。
## SQL 函数变更
| # |
**函数**
|
**差异性**
|
**说明**
|
| - | :-------: | :--------: | :------- |
| 1 | TWA | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 2 | IRATE | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 3 | LEASTSQUARES | 增强 | 可以用于超级表了。
| 4 | ELAPSED | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 5 | DIFF | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 6 | DERIVATIVE | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 7 | CSUM | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 8 | MAVG | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 9 | SAMPLE | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 10 | STATECOUNT | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
| 11 | STATEDURATION | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
docs/zh/12-taos-sql/index.md
浏览文件 @
77f27b62
...
...
@@ -3,7 +3,7 @@ title: TAOS SQL
description
:
"
TAOS
SQL
支持的语法规则、主要查询功能、支持的
SQL
查询函数,以及常用技巧等内容"
---
本文档说明 TAOS SQL 支持的语法规则、主要查询功能、支持的 SQL 查询函数,以及常用技巧等内容。阅读本文档需要读者具有基本的 SQL 语言的基础。
本文档说明 TAOS SQL 支持的语法规则、主要查询功能、支持的 SQL 查询函数,以及常用技巧等内容。阅读本文档需要读者具有基本的 SQL 语言的基础。
TDengine 3.0 版本相比 2.x 版本做了大量改进和优化,特别是查询引擎进行了彻底的重构,因此 SQL 语法相比 2.x 版本有很多变更。详细的变更内容请见
[
3.0 版本语法变更
](
/taos-sql/changes
)
章节
TAOS SQL 是用户对 TDengine 进行数据写入和查询的主要工具。TAOS SQL 提供标准的 SQL 语法,并针对时序数据和业务的特点优化和新增了许多语法和功能。TAOS SQL 语句的最大长度为 1M。TAOS SQL 不支持关键字的缩写,例如 DELETE 不能缩写为 DEL。
...
...
docs/zh/14-reference/12-config/index.md
浏览文件 @
77f27b62
...
...
@@ -647,3 +647,173 @@ charset 的有效值是 UTF-8。
| 含义 | 是否启动 udf 服务 |
| 取值范围 | 0: 不启动;1:启动 |
| 缺省值 | 1 |
## 2.X 与 3.0 配置参数对比
| # |
**参数**
|
**适用于 2.X 版本**
|
**适用于 3.0 版本**
|
| --- | :-----------------: | --------------- | --------------- |
| 1 | firstEp | 是 | 是 |
| 2 | secondEp | 是 | 是 |
| 3 | fqdn | 是 | 是 |
| 4 | serverPort | 是 | 是 |
| 5 | maxShellConns | 是 | 是 |
| 6 | monitor | 是 | 是 |
| 7 | monitorFqdn | 否 | 是 |
| 8 | monitorPort | 否 | 是 |
| 9 | monitorInterval | 是 | 是 |
| 10 | monitorMaxLogs | 否 | 是 |
| 11 | monitorComp | 否 | 是 |
| 12 | telemetryReporting | 是 | 是 |
| 13 | telemetryInterval | 否 | 是 |
| 14 | telemetryServer | 否 | 是 |
| 15 | telemetryPort | 否 | 是 |
| 16 | queryPolicy | 否 | 是 |
| 17 | querySmaOptimize | 否 | 是 |
| 18 | queryBufferSize | 是 | 是 |
| 19 | maxNumOfDistinctRes | 是 | 是 |
| 20 | minSlidingTime | 是 | 是 |
| 21 | minIntervalTime | 是 | 是 |
| 22 | countAlwaysReturnValue | 是 | 是 |
| 23 | dataDir | 是 | 是 |
| 24 | minimalDataDirGB | 是 | 是 |
| 25 | supportVnodes | 否 | 是 |
| 26 | tempDir | 是 | 是 |
| 27 | minimalTmpDirGB | 是 | 是 |
| 28 | compressMsgSize | 是 | 是 |
| 29 | compressColData | 是 | 是 |
| 30 | smlChildTableName | 是 | 是 |
| 31 | smlTagName | 是 | 是 |
| 32 | smlDataFormat | 否 | 是 |
| 33 | statusInterval | 是 | 是 |
| 34 | shellActivityTimer | 是 | 是 |
| 35 | transPullupInterval | 否 | 是 |
| 36 | mqRebalanceInterval | 否 | 是 |
| 37 | ttlUnit | 否 | 是 |
| 38 | ttlPushInterval | 否 | 是 |
| 39 | numOfTaskQueueThreads | 否 | 是 |
| 40 | numOfRpcThreads | 否 | 是 |
| 41 | numOfCommitThreads | 是 | 是 |
| 42 | numOfMnodeReadThreads | 否 | 是 |
| 43 | numOfVnodeQueryThreads | 否 | 是 |
| 44 | numOfVnodeStreamThreads | 否 | 是 |
| 45 | numOfVnodeFetchThreads | 否 | 是 |
| 46 | numOfVnodeWriteThreads | 否 | 是 |
| 47 | numOfVnodeSyncThreads | 否 | 是 |
| 48 | numOfQnodeQueryThreads | 否 | 是 |
| 49 | numOfQnodeFetchThreads | 否 | 是 |
| 50 | numOfSnodeSharedThreads | 否 | 是 |
| 51 | numOfSnodeUniqueThreads | 否 | 是 |
| 52 | rpcQueueMemoryAllowed | 否 | 是 |
| 53 | logDir | 是 | 是 |
| 54 | minimalLogDirGB | 是 | 是 |
| 55 | numOfLogLines | 是 | 是 |
| 56 | asyncLog | 是 | 是 |
| 57 | logKeepDays | 是 | 是 |
| 58 | debugFlag | 是 | 是 |
| 59 | tmrDebugFlag | 是 | 是 |
| 60 | uDebugFlag | 是 | 是 |
| 61 | rpcDebugFlag | 是 | 是 |
| 62 | jniDebugFlag | 是 | 是 |
| 63 | qDebugFlag | 是 | 是 |
| 64 | cDebugFlag | 是 | 是 |
| 65 | dDebugFlag | 是 | 是 |
| 66 | vDebugFlag | 是 | 是 |
| 67 | mDebugFlag | 是 | 是 |
| 68 | wDebugFlag | 是 | 是 |
| 69 | sDebugFlag | 是 | 是 |
| 70 | tsdbDebugFlag | 是 | 是 |
| 71 | tqDebugFlag | 否 | 是 |
| 72 | fsDebugFlag | 是 | 是 |
| 73 | udfDebugFlag | 否 | 是 |
| 74 | smaDebugFlag | 否 | 是 |
| 75 | idxDebugFlag | 否 | 是 |
| 76 | tdbDebugFlag | 否 | 是 |
| 77 | metaDebugFlag | 否 | 是 |
| 78 | timezone | 是 | 是 |
| 79 | locale | 是 | 是 |
| 80 | charset | 是 | 是 |
| 81 | udf | 是 | 是 |
| 82 | enableCoreFile | 是 | 是 |
| 83 | arbitrator | 是 | 否 |
| 84 | numOfThreadsPerCore | 是 | 否 |
| 85 | numOfMnodes | 是 | 否 |
| 86 | vnodeBak | 是 | 否 |
| 87 | balance | 是 | 否 |
| 88 | balanceInterval | 是 | 否 |
| 89 | offlineThreshold | 是 | 否 |
| 90 | role | 是 | 否 |
| 91 | dnodeNopLoop | 是 | 否 |
| 92 | keepTimeOffset | 是 | 否 |
| 93 | rpcTimer | 是 | 否 |
| 94 | rpcMaxTime | 是 | 否 |
| 95 | rpcForceTcp | 是 | 否 |
| 96 | tcpConnTimeout | 是 | 否 |
| 97 | syncCheckInterval | 是 | 否 |
| 98 | maxTmrCtrl | 是 | 否 |
| 99 | monitorReplica | 是 | 否 |
| 100 | smlTagNullName | 是 | 否 |
| 101 | keepColumnName | 是 | 否 |
| 102 | ratioOfQueryCores | 是 | 否 |
| 103 | maxStreamCompDelay | 是 | 否 |
| 104 | maxFirstStreamCompDelay | 是 | 否 |
| 105 | retryStreamCompDelay | 是 | 否 |
| 106 | streamCompDelayRatio | 是 | 否 |
| 107 | maxVgroupsPerDb | 是 | 否 |
| 108 | maxTablesPerVnode | 是 | 否 |
| 109 | minTablesPerVnode | 是 | 否 |
| 110 | tableIncStepPerVnode | 是 | 否 |
| 111 | cache | 是 | 否 |
| 112 | blocks | 是 | 否 |
| 113 | days | 是 | 否 |
| 114 | keep | 是 | 否 |
| 115 | minRows | 是 | 否 |
| 116 | maxRows | 是 | 否 |
| 117 | quorum | 是 | 否 |
| 118 | comp | 是 | 否 |
| 119 | walLevel | 是 | 否 |
| 120 | fsync | 是 | 否 |
| 121 | replica | 是 | 否 |
| 122 | partitions | 是 | 否 |
| 123 | quorum | 是 | 否 |
| 124 | update | 是 | 否 |
| 125 | cachelast | 是 | 否 |
| 126 | maxSQLLength | 是 | 否 |
| 127 | maxWildCardsLength | 是 | 否 |
| 128 | maxRegexStringLen | 是 | 否 |
| 129 | maxNumOfOrderedRes | 是 | 否 |
| 130 | maxConnections | 是 | 否 |
| 131 | mnodeEqualVnodeNum | 是 | 否 |
| 132 | http | 是 | 否 |
| 133 | httpEnableRecordSql | 是 | 否 |
| 134 | httpMaxThreads | 是 | 否 |
| 135 | restfulRowLimit | 是 | 否 |
| 136 | httpDbNameMandatory | 是 | 否 |
| 137 | httpKeepAlive | 是 | 否 |
| 138 | enableRecordSql | 是 | 否 |
| 139 | maxBinaryDisplayWidth | 是 | 否 |
| 140 | stream | 是 | 否 |
| 141 | retrieveBlockingModel | 是 | 否 |
| 142 | tsdbMetaCompactRatio | 是 | 否 |
| 143 | defaultJSONStrType | 是 | 否 |
| 144 | walFlushSize | 是 | 否 |
| 145 | keepTimeOffset | 是 | 否 |
| 146 | flowctrl | 是 | 否 |
| 147 | slaveQuery | 是 | 否 |
| 148 | adjustMaster | 是 | 否 |
| 149 | topicBinaryLen | 是 | 否 |
| 150 | telegrafUseFieldNum | 是 | 否 |
| 151 | deadLockKillQuery | 是 | 否 |
| 152 | clientMerge | 是 | 否 |
| 153 | sdbDebugFlag | 是 | 否 |
| 154 | odbcDebugFlag | 是 | 否 |
| 155 | httpDebugFlag | 是 | 否 |
| 156 | monDebugFlag | 是 | 否 |
| 157 | cqDebugFlag | 是 | 否 |
| 158 | shortcutFlag | 是 | 否 |
| 159 | probeSeconds | 是 | 否 |
| 160 | probeKillSeconds | 是 | 否 |
| 161 | probeInterval | 是 | 否 |
| 162 | lossyColumns | 是 | 否 |
| 163 | fPrecision | 是 | 否 |
| 164 | dPrecision | 是 | 否 |
| 165 | maxRange | 是 | 否 |
| 166 | range | 是 | 否 |
docs/zh/28-releases.md
浏览文件 @
77f27b62
...
...
@@ -3,7 +3,7 @@ sidebar_label: 发布历史
title
:
发布历史
---
import Release from "/components/Release";
import Release from "/components/Release
V3
";
<Release
versionPrefix=
"3.0"
/>
examples/c/tmq.c
浏览文件 @
77f27b62
...
...
@@ -45,10 +45,9 @@ static int32_t msg_process(TAOS_RES* msg) {
int32_t
numOfFields
=
taos_field_count
(
msg
);
int32_t
*
length
=
taos_fetch_lengths
(
msg
);
int32_t
precision
=
taos_result_precision
(
msg
);
const
char
*
tbName
=
tmq_get_table_name
(
msg
);
rows
++
;
taos_print_row
(
buf
,
row
,
fields
,
numOfFields
);
printf
(
"row content
from %s: %s
\n
"
,
(
tbName
!=
NULL
?
tbName
:
"table null"
)
,
buf
);
printf
(
"row content
: %s
\n
"
,
buf
);
}
return
rows
;
...
...
@@ -167,7 +166,7 @@ int32_t create_topic() {
}
taos_free_result
(
pRes
);
pRes
=
taos_query
(
pConn
,
"create topic topicname as select ts, c1, c2, c3 from tmqdb.stb where c1 > 1"
);
pRes
=
taos_query
(
pConn
,
"create topic topicname as select ts, c1, c2, c3
, tbname
from tmqdb.stb where c1 > 1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to create topic topicname, reason:%s
\n
"
,
taos_errstr
(
pRes
));
return
-
1
;
...
...
@@ -199,9 +198,7 @@ tmq_t* build_consumer() {
if
(
TMQ_CONF_OK
!=
code
)
return
NULL
;
code
=
tmq_conf_set
(
conf
,
"auto.offset.reset"
,
"earliest"
);
if
(
TMQ_CONF_OK
!=
code
)
return
NULL
;
code
=
tmq_conf_set
(
conf
,
"experimental.snapshot.enable"
,
"true"
);
if
(
TMQ_CONF_OK
!=
code
)
return
NULL
;
code
=
tmq_conf_set
(
conf
,
"msg.with.table.name"
,
"true"
);
code
=
tmq_conf_set
(
conf
,
"experimental.snapshot.enable"
,
"false"
);
if
(
TMQ_CONF_OK
!=
code
)
return
NULL
;
tmq_conf_set_auto_commit_cb
(
conf
,
tmq_commit_cb_print
,
NULL
);
...
...
@@ -220,14 +217,7 @@ tmq_list_t* build_topic_list() {
return
topicList
;
}
void
basic_consume_loop
(
tmq_t
*
tmq
,
tmq_list_t
*
topicList
)
{
int32_t
code
;
if
((
code
=
tmq_subscribe
(
tmq
,
topicList
)))
{
fprintf
(
stderr
,
"%% Failed to tmq_subscribe(): %s
\n
"
,
tmq_err2str
(
code
));
return
;
}
void
basic_consume_loop
(
tmq_t
*
tmq
)
{
int32_t
totalRows
=
0
;
int32_t
msgCnt
=
0
;
int32_t
timeout
=
5000
;
...
...
@@ -237,8 +227,8 @@ void basic_consume_loop(tmq_t* tmq, tmq_list_t* topicList) {
msgCnt
++
;
totalRows
+=
msg_process
(
tmqmsg
);
taos_free_result
(
tmqmsg
);
/*} else {*/
/*break;*/
}
else
{
break
;
}
}
...
...
@@ -267,14 +257,12 @@ int main(int argc, char* argv[]) {
return
-
1
;
}
basic_consume_loop
(
tmq
,
topic_list
);
code
=
tmq_unsubscribe
(
tmq
);
if
(
code
)
{
fprintf
(
stderr
,
"%% Failed to unsubscribe: %s
\n
"
,
tmq_err2str
(
code
));
}
else
{
fprintf
(
stderr
,
"%% unsubscribe
\n
"
);
if
((
code
=
tmq_subscribe
(
tmq
,
topic_list
)))
{
fprintf
(
stderr
,
"%% Failed to tmq_subscribe(): %s
\n
"
,
tmq_err2str
(
code
));
}
tmq_list_destroy
(
topic_list
);
basic_consume_loop
(
tmq
);
code
=
tmq_consumer_close
(
tmq
);
if
(
code
)
{
...
...
include/client/taos.h
浏览文件 @
77f27b62
...
...
@@ -244,33 +244,37 @@ DLL_EXPORT void tmq_conf_set_auto_commit_cb(tmq_conf_t *conf, tmq_comm
/* -------------------------TMQ MSG HANDLE INTERFACE---------------------- */
DLL_EXPORT
const
char
*
tmq_get_topic_name
(
TAOS_RES
*
res
);
DLL_EXPORT
const
char
*
tmq_get_db_name
(
TAOS_RES
*
res
);
DLL_EXPORT
int32_t
tmq_get_vgroup_id
(
TAOS_RES
*
res
);
/* ------------------------------ TAOSX -----------------------------------*/
// note: following apis are unstable
enum
tmq_res_t
{
TMQ_RES_INVALID
=
-
1
,
TMQ_RES_DATA
=
1
,
TMQ_RES_TABLE_META
=
2
,
};
typedef
struct
tmq_raw_data
{
void
*
raw
;
typedef
struct
tmq_raw_data
{
void
*
raw
;
uint32_t
raw_len
;
uint16_t
raw_type
;
}
tmq_raw_data
;
typedef
enum
tmq_res_t
tmq_res_t
;
DLL_EXPORT
const
char
*
tmq_get_table_name
(
TAOS_RES
*
res
);
DLL_EXPORT
tmq_res_t
tmq_get_res_type
(
TAOS_RES
*
res
);
DLL_EXPORT
int32_t
tmq_get_raw
(
TAOS_RES
*
res
,
tmq_raw_data
*
raw
);
DLL_EXPORT
int32_t
tmq_write_raw
(
TAOS
*
taos
,
tmq_raw_data
raw
);
DLL_EXPORT
int
taos_write_raw_block
(
TAOS
*
taos
,
int
numOfRows
,
char
*
pData
,
const
char
*
tbname
);
DLL_EXPORT
int
taos_write_raw_block
(
TAOS
*
taos
,
int
numOfRows
,
char
*
pData
,
const
char
*
tbname
);
DLL_EXPORT
void
tmq_free_raw
(
tmq_raw_data
raw
);
DLL_EXPORT
char
*
tmq_get_json_meta
(
TAOS_RES
*
res
);
// Returning null means error. Returned result need to be freed by tmq_free_json_meta
DLL_EXPORT
void
tmq_free_json_meta
(
char
*
jsonMeta
);
DLL_EXPORT
const
char
*
tmq_get_topic_name
(
TAOS_RES
*
res
);
DLL_EXPORT
const
char
*
tmq_get_db_name
(
TAOS_RES
*
res
);
DLL_EXPORT
int32_t
tmq_get_vgroup_id
(
TAOS_RES
*
res
);
DLL_EXPORT
const
char
*
tmq_get_table_name
(
TAOS_RES
*
res
);
// Returning null means error. Returned result need to be freed by tmq_free_json_meta
DLL_EXPORT
char
*
tmq_get_json_meta
(
TAOS_RES
*
res
);
DLL_EXPORT
void
tmq_free_json_meta
(
char
*
jsonMeta
);
/* ----------------------------
-- TMQ
END -------------------------------- */
/* ----------------------------
TAOSX
END -------------------------------- */
typedef
enum
{
TSDB_SRV_STATUS_UNAVAILABLE
=
0
,
...
...
include/util/taoserror.h
浏览文件 @
77f27b62
...
...
@@ -622,6 +622,7 @@ int32_t* taosGetErrno();
//tmq
#define TSDB_CODE_TMQ_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x4000)
#define TSDB_CODE_TMQ_CONSUMER_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x4001)
#define TSDB_CODE_TMQ_CONSUMER_CLOSED TAOS_DEF_ERROR_CODE(0, 0x4002)
#ifdef __cplusplus
}
...
...
include/util/tref.h
浏览文件 @
77f27b62
...
...
@@ -29,11 +29,11 @@ int32_t taosOpenRef(int32_t max, void (*fp)(void *));
// close the reference set, refId is the return value by taosOpenRef
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
int32_t
taosCloseRef
(
int32_t
r
ef
Id
);
int32_t
taosCloseRef
(
int32_t
r
set
Id
);
// add ref, p is the pointer to resource or pointer ID
// return Reference ID(rid) allocated. On error, -1 is returned, and terrno is set appropriately
int64_t
taosAddRef
(
int32_t
r
ef
Id
,
void
*
p
);
int64_t
taosAddRef
(
int32_t
r
set
Id
,
void
*
p
);
// remove ref, rid is the reference ID returned by taosAddRef
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
...
...
source/client/src/clientMain.c
浏览文件 @
77f27b62
...
...
@@ -192,6 +192,7 @@ void taos_free_result(TAOS_RES *res) {
if
(
pRsp
->
rsp
.
withSchema
)
taosArrayDestroyP
(
pRsp
->
rsp
.
blockSchema
,
(
FDelete
)
tDeleteSSchemaWrapper
);
pRsp
->
resInfo
.
pRspMsg
=
NULL
;
doFreeReqResultInfo
(
&
pRsp
->
resInfo
);
taosMemoryFree
(
pRsp
);
}
else
if
(
TD_RES_TMQ_META
(
res
))
{
SMqMetaRspObj
*
pRspObj
=
(
SMqMetaRspObj
*
)
res
;
taosMemoryFree
(
pRspObj
->
metaRsp
.
metaRsp
);
...
...
source/client/src/taosx.c
0 → 100644
浏览文件 @
77f27b62
/*
* 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 "cJSON.h"
#include "clientInt.h"
#include "clientLog.h"
#include "parser.h"
#include "tdatablock.h"
#include "tdef.h"
#include "tglobal.h"
#include "tmsgtype.h"
#include "tqueue.h"
#include "tref.h"
#include "ttimer.h"
static
char
*
buildCreateTableJson
(
SSchemaWrapper
*
schemaRow
,
SSchemaWrapper
*
schemaTag
,
char
*
name
,
int64_t
id
,
int8_t
t
)
{
char
*
string
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
return
string
;
}
cJSON
*
type
=
cJSON_CreateString
(
"create"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// char uid[32] = {0};
// sprintf(uid, "%"PRIi64, id);
// cJSON* id_ = cJSON_CreateString(uid);
// cJSON_AddItemToObject(json, "id", id_);
cJSON
*
tableName
=
cJSON_CreateString
(
name
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
t
==
TSDB_NORMAL_TABLE
?
"normal"
:
"super"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
// cJSON* version = cJSON_CreateNumber(1);
// cJSON_AddItemToObject(json, "version", version);
cJSON
*
columns
=
cJSON_CreateArray
();
for
(
int
i
=
0
;
i
<
schemaRow
->
nCols
;
i
++
)
{
cJSON
*
column
=
cJSON_CreateObject
();
SSchema
*
s
=
schemaRow
->
pSchema
+
i
;
cJSON
*
cname
=
cJSON_CreateString
(
s
->
name
);
cJSON_AddItemToObject
(
column
,
"name"
,
cname
);
cJSON
*
ctype
=
cJSON_CreateNumber
(
s
->
type
);
cJSON_AddItemToObject
(
column
,
"type"
,
ctype
);
if
(
s
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
s
->
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
column
,
"length"
,
cbytes
);
}
else
if
(
s
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
s
->
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
column
,
"length"
,
cbytes
);
}
cJSON_AddItemToArray
(
columns
,
column
);
}
cJSON_AddItemToObject
(
json
,
"columns"
,
columns
);
cJSON
*
tags
=
cJSON_CreateArray
();
for
(
int
i
=
0
;
schemaTag
&&
i
<
schemaTag
->
nCols
;
i
++
)
{
cJSON
*
tag
=
cJSON_CreateObject
();
SSchema
*
s
=
schemaTag
->
pSchema
+
i
;
cJSON
*
tname
=
cJSON_CreateString
(
s
->
name
);
cJSON_AddItemToObject
(
tag
,
"name"
,
tname
);
cJSON
*
ttype
=
cJSON_CreateNumber
(
s
->
type
);
cJSON_AddItemToObject
(
tag
,
"type"
,
ttype
);
if
(
s
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
s
->
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
tag
,
"length"
,
cbytes
);
}
else
if
(
s
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
s
->
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
tag
,
"length"
,
cbytes
);
}
cJSON_AddItemToArray
(
tags
,
tag
);
}
cJSON_AddItemToObject
(
json
,
"tags"
,
tags
);
string
=
cJSON_PrintUnformatted
(
json
);
cJSON_Delete
(
json
);
return
string
;
}
static
char
*
buildAlterSTableJson
(
void
*
alterData
,
int32_t
alterDataLen
)
{
SMAlterStbReq
req
=
{
0
};
cJSON
*
json
=
NULL
;
char
*
string
=
NULL
;
if
(
tDeserializeSMAlterStbReq
(
alterData
,
alterDataLen
,
&
req
)
!=
0
)
{
goto
end
;
}
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
end
;
}
cJSON
*
type
=
cJSON_CreateString
(
"alter"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// cJSON* uid = cJSON_CreateNumber(id);
// cJSON_AddItemToObject(json, "uid", uid);
SName
name
=
{
0
};
tNameFromString
(
&
name
,
req
.
name
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
cJSON
*
tableName
=
cJSON_CreateString
(
name
.
tname
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
"super"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
cJSON
*
alterType
=
cJSON_CreateNumber
(
req
.
alterType
);
cJSON_AddItemToObject
(
json
,
"alterType"
,
alterType
);
switch
(
req
.
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_TAG
:
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
{
TAOS_FIELD
*
field
=
taosArrayGet
(
req
.
pFields
,
0
);
cJSON
*
colName
=
cJSON_CreateString
(
field
->
name
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colType
=
cJSON_CreateNumber
(
field
->
type
);
cJSON_AddItemToObject
(
json
,
"colType"
,
colType
);
if
(
field
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
field
->
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
else
if
(
field
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
field
->
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
break
;
}
case
TSDB_ALTER_TABLE_DROP_TAG
:
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
{
TAOS_FIELD
*
field
=
taosArrayGet
(
req
.
pFields
,
0
);
cJSON
*
colName
=
cJSON_CreateString
(
field
->
name
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
{
TAOS_FIELD
*
field
=
taosArrayGet
(
req
.
pFields
,
0
);
cJSON
*
colName
=
cJSON_CreateString
(
field
->
name
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colType
=
cJSON_CreateNumber
(
field
->
type
);
cJSON_AddItemToObject
(
json
,
"colType"
,
colType
);
if
(
field
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
field
->
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
else
if
(
field
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
field
->
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
{
TAOS_FIELD
*
oldField
=
taosArrayGet
(
req
.
pFields
,
0
);
TAOS_FIELD
*
newField
=
taosArrayGet
(
req
.
pFields
,
1
);
cJSON
*
colName
=
cJSON_CreateString
(
oldField
->
name
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colNewName
=
cJSON_CreateString
(
newField
->
name
);
cJSON_AddItemToObject
(
json
,
"colNewName"
,
colNewName
);
break
;
}
default:
break
;
}
string
=
cJSON_PrintUnformatted
(
json
);
end:
cJSON_Delete
(
json
);
tFreeSMAltertbReq
(
&
req
);
return
string
;
}
static
char
*
processCreateStb
(
SMqMetaRsp
*
metaRsp
)
{
SVCreateStbReq
req
=
{
0
};
SDecoder
coder
;
char
*
string
=
NULL
;
// decode and process req
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVCreateStbReq
(
&
coder
,
&
req
)
<
0
)
{
goto
_err
;
}
string
=
buildCreateTableJson
(
&
req
.
schemaRow
,
&
req
.
schemaTag
,
req
.
name
,
req
.
suid
,
TSDB_SUPER_TABLE
);
tDecoderClear
(
&
coder
);
return
string
;
_err:
tDecoderClear
(
&
coder
);
return
string
;
}
static
char
*
processAlterStb
(
SMqMetaRsp
*
metaRsp
)
{
SVCreateStbReq
req
=
{
0
};
SDecoder
coder
;
char
*
string
=
NULL
;
// decode and process req
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVCreateStbReq
(
&
coder
,
&
req
)
<
0
)
{
goto
_err
;
}
string
=
buildAlterSTableJson
(
req
.
alterOriData
,
req
.
alterOriDataLen
);
tDecoderClear
(
&
coder
);
return
string
;
_err:
tDecoderClear
(
&
coder
);
return
string
;
}
static
char
*
buildCreateCTableJson
(
STag
*
pTag
,
char
*
sname
,
char
*
name
,
SArray
*
tagName
,
int64_t
id
,
uint8_t
tagNum
)
{
char
*
string
=
NULL
;
SArray
*
pTagVals
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
return
string
;
}
cJSON
*
type
=
cJSON_CreateString
(
"create"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// char cid[32] = {0};
// sprintf(cid, "%"PRIi64, id);
// cJSON* cid_ = cJSON_CreateString(cid);
// cJSON_AddItemToObject(json, "id", cid_);
cJSON
*
tableName
=
cJSON_CreateString
(
name
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
"child"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
cJSON
*
using
=
cJSON_CreateString
(
sname
);
cJSON_AddItemToObject
(
json
,
"using"
,
using
);
cJSON
*
tagNumJson
=
cJSON_CreateNumber
(
tagNum
);
cJSON_AddItemToObject
(
json
,
"tagNum"
,
tagNumJson
);
// cJSON* version = cJSON_CreateNumber(1);
// cJSON_AddItemToObject(json, "version", version);
cJSON
*
tags
=
cJSON_CreateArray
();
int32_t
code
=
tTagToValArray
(
pTag
,
&
pTagVals
);
if
(
code
)
{
goto
end
;
}
if
(
tTagIsJson
(
pTag
))
{
STag
*
p
=
(
STag
*
)
pTag
;
if
(
p
->
nTag
==
0
)
{
goto
end
;
}
char
*
pJson
=
parseTagDatatoJson
(
pTag
);
cJSON
*
tag
=
cJSON_CreateObject
();
STagVal
*
pTagVal
=
taosArrayGet
(
pTagVals
,
0
);
char
*
ptname
=
taosArrayGet
(
tagName
,
0
);
cJSON
*
tname
=
cJSON_CreateString
(
ptname
);
cJSON_AddItemToObject
(
tag
,
"name"
,
tname
);
// cJSON* cid_ = cJSON_CreateString("");
// cJSON_AddItemToObject(tag, "cid", cid_);
cJSON
*
ttype
=
cJSON_CreateNumber
(
TSDB_DATA_TYPE_JSON
);
cJSON_AddItemToObject
(
tag
,
"type"
,
ttype
);
cJSON
*
tvalue
=
cJSON_CreateString
(
pJson
);
cJSON_AddItemToObject
(
tag
,
"value"
,
tvalue
);
cJSON_AddItemToArray
(
tags
,
tag
);
taosMemoryFree
(
pJson
);
goto
end
;
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pTagVals
);
i
++
)
{
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
i
);
cJSON
*
tag
=
cJSON_CreateObject
();
char
*
ptname
=
taosArrayGet
(
tagName
,
i
);
cJSON
*
tname
=
cJSON_CreateString
(
ptname
);
cJSON_AddItemToObject
(
tag
,
"name"
,
tname
);
// cJSON* cid = cJSON_CreateNumber(pTagVal->cid);
// cJSON_AddItemToObject(tag, "cid", cid);
cJSON
*
ttype
=
cJSON_CreateNumber
(
pTagVal
->
type
);
cJSON_AddItemToObject
(
tag
,
"type"
,
ttype
);
cJSON
*
tvalue
=
NULL
;
if
(
IS_VAR_DATA_TYPE
(
pTagVal
->
type
))
{
char
*
buf
=
taosMemoryCalloc
(
pTagVal
->
nData
+
3
,
1
);
if
(
!
buf
)
goto
end
;
dataConverToStr
(
buf
,
pTagVal
->
type
,
pTagVal
->
pData
,
pTagVal
->
nData
,
NULL
);
tvalue
=
cJSON_CreateString
(
buf
);
taosMemoryFree
(
buf
);
}
else
{
double
val
=
0
;
GET_TYPED_DATA
(
val
,
double
,
pTagVal
->
type
,
&
pTagVal
->
i64
);
tvalue
=
cJSON_CreateNumber
(
val
);
}
cJSON_AddItemToObject
(
tag
,
"value"
,
tvalue
);
cJSON_AddItemToArray
(
tags
,
tag
);
}
end:
cJSON_AddItemToObject
(
json
,
"tags"
,
tags
);
string
=
cJSON_PrintUnformatted
(
json
);
cJSON_Delete
(
json
);
taosArrayDestroy
(
pTagVals
);
return
string
;
}
static
char
*
processCreateTable
(
SMqMetaRsp
*
metaRsp
)
{
SDecoder
decoder
=
{
0
};
SVCreateTbBatchReq
req
=
{
0
};
SVCreateTbReq
*
pCreateReq
;
char
*
string
=
NULL
;
// decode
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
decoder
,
data
,
len
);
if
(
tDecodeSVCreateTbBatchReq
(
&
decoder
,
&
req
)
<
0
)
{
goto
_exit
;
}
// loop to create table
for
(
int32_t
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
pCreateReq
=
req
.
pReqs
+
iReq
;
if
(
pCreateReq
->
type
==
TSDB_CHILD_TABLE
)
{
string
=
buildCreateCTableJson
((
STag
*
)
pCreateReq
->
ctb
.
pTag
,
pCreateReq
->
ctb
.
name
,
pCreateReq
->
name
,
pCreateReq
->
ctb
.
tagName
,
pCreateReq
->
uid
,
pCreateReq
->
ctb
.
tagNum
);
}
else
if
(
pCreateReq
->
type
==
TSDB_NORMAL_TABLE
)
{
string
=
buildCreateTableJson
(
&
pCreateReq
->
ntb
.
schemaRow
,
NULL
,
pCreateReq
->
name
,
pCreateReq
->
uid
,
TSDB_NORMAL_TABLE
);
}
}
tDecoderClear
(
&
decoder
);
_exit:
tDecoderClear
(
&
decoder
);
return
string
;
}
static
char
*
processAlterTable
(
SMqMetaRsp
*
metaRsp
)
{
SDecoder
decoder
=
{
0
};
SVAlterTbReq
vAlterTbReq
=
{
0
};
char
*
string
=
NULL
;
// decode
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
decoder
,
data
,
len
);
if
(
tDecodeSVAlterTbReq
(
&
decoder
,
&
vAlterTbReq
)
<
0
)
{
goto
_exit
;
}
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
_exit
;
}
cJSON
*
type
=
cJSON_CreateString
(
"alter"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// cJSON* uid = cJSON_CreateNumber(id);
// cJSON_AddItemToObject(json, "uid", uid);
cJSON
*
tableName
=
cJSON_CreateString
(
vAlterTbReq
.
tbName
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
vAlterTbReq
.
action
==
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
?
"child"
:
"normal"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
cJSON
*
alterType
=
cJSON_CreateNumber
(
vAlterTbReq
.
action
);
cJSON_AddItemToObject
(
json
,
"alterType"
,
alterType
);
switch
(
vAlterTbReq
.
action
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
{
cJSON
*
colName
=
cJSON_CreateString
(
vAlterTbReq
.
colName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colType
=
cJSON_CreateNumber
(
vAlterTbReq
.
type
);
cJSON_AddItemToObject
(
json
,
"colType"
,
colType
);
if
(
vAlterTbReq
.
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
vAlterTbReq
.
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
else
if
(
vAlterTbReq
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
vAlterTbReq
.
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
break
;
}
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
{
cJSON
*
colName
=
cJSON_CreateString
(
vAlterTbReq
.
colName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
{
cJSON
*
colName
=
cJSON_CreateString
(
vAlterTbReq
.
colName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colType
=
cJSON_CreateNumber
(
vAlterTbReq
.
colModType
);
cJSON_AddItemToObject
(
json
,
"colType"
,
colType
);
if
(
vAlterTbReq
.
colModType
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
vAlterTbReq
.
colModBytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
else
if
(
vAlterTbReq
.
colModType
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
vAlterTbReq
.
colModBytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
{
cJSON
*
colName
=
cJSON_CreateString
(
vAlterTbReq
.
colName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colNewName
=
cJSON_CreateString
(
vAlterTbReq
.
colNewName
);
cJSON_AddItemToObject
(
json
,
"colNewName"
,
colNewName
);
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
:
{
cJSON
*
tagName
=
cJSON_CreateString
(
vAlterTbReq
.
tagName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
tagName
);
bool
isNull
=
vAlterTbReq
.
isNull
;
if
(
vAlterTbReq
.
tagType
==
TSDB_DATA_TYPE_JSON
)
{
STag
*
jsonTag
=
(
STag
*
)
vAlterTbReq
.
pTagVal
;
if
(
jsonTag
->
nTag
==
0
)
isNull
=
true
;
}
if
(
!
isNull
)
{
char
*
buf
=
NULL
;
if
(
vAlterTbReq
.
tagType
==
TSDB_DATA_TYPE_JSON
)
{
ASSERT
(
tTagIsJson
(
vAlterTbReq
.
pTagVal
)
==
true
);
buf
=
parseTagDatatoJson
(
vAlterTbReq
.
pTagVal
);
}
else
{
buf
=
taosMemoryCalloc
(
vAlterTbReq
.
nTagVal
+
1
,
1
);
dataConverToStr
(
buf
,
vAlterTbReq
.
tagType
,
vAlterTbReq
.
pTagVal
,
vAlterTbReq
.
nTagVal
,
NULL
);
}
cJSON
*
colValue
=
cJSON_CreateString
(
buf
);
cJSON_AddItemToObject
(
json
,
"colValue"
,
colValue
);
taosMemoryFree
(
buf
);
}
cJSON
*
isNullCJson
=
cJSON_CreateBool
(
isNull
);
cJSON_AddItemToObject
(
json
,
"colValueNull"
,
isNullCJson
);
break
;
}
default:
break
;
}
string
=
cJSON_PrintUnformatted
(
json
);
_exit:
tDecoderClear
(
&
decoder
);
return
string
;
}
static
char
*
processDropSTable
(
SMqMetaRsp
*
metaRsp
)
{
SDecoder
decoder
=
{
0
};
SVDropStbReq
req
=
{
0
};
char
*
string
=
NULL
;
// decode
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
decoder
,
data
,
len
);
if
(
tDecodeSVDropStbReq
(
&
decoder
,
&
req
)
<
0
)
{
goto
_exit
;
}
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
_exit
;
}
cJSON
*
type
=
cJSON_CreateString
(
"drop"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
cJSON
*
tableName
=
cJSON_CreateString
(
req
.
name
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
"super"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
string
=
cJSON_PrintUnformatted
(
json
);
_exit:
tDecoderClear
(
&
decoder
);
return
string
;
}
static
char
*
processDropTable
(
SMqMetaRsp
*
metaRsp
)
{
SDecoder
decoder
=
{
0
};
SVDropTbBatchReq
req
=
{
0
};
char
*
string
=
NULL
;
// decode
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
decoder
,
data
,
len
);
if
(
tDecodeSVDropTbBatchReq
(
&
decoder
,
&
req
)
<
0
)
{
goto
_exit
;
}
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
_exit
;
}
cJSON
*
type
=
cJSON_CreateString
(
"drop"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// cJSON* uid = cJSON_CreateNumber(id);
// cJSON_AddItemToObject(json, "uid", uid);
// cJSON* tableType = cJSON_CreateString("normal");
// cJSON_AddItemToObject(json, "tableType", tableType);
cJSON
*
tableNameList
=
cJSON_CreateArray
();
for
(
int32_t
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
SVDropTbReq
*
pDropTbReq
=
req
.
pReqs
+
iReq
;
cJSON
*
tableName
=
cJSON_CreateString
(
pDropTbReq
->
name
);
cJSON_AddItemToArray
(
tableNameList
,
tableName
);
}
cJSON_AddItemToObject
(
json
,
"tableNameList"
,
tableNameList
);
string
=
cJSON_PrintUnformatted
(
json
);
_exit:
tDecoderClear
(
&
decoder
);
return
string
;
}
static
int32_t
taosCreateStb
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVCreateStbReq
req
=
{
0
};
SDecoder
coder
;
SMCreateStbReq
pReq
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVCreateStbReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
// build create stable
pReq
.
pColumns
=
taosArrayInit
(
req
.
schemaRow
.
nCols
,
sizeof
(
SField
));
for
(
int32_t
i
=
0
;
i
<
req
.
schemaRow
.
nCols
;
i
++
)
{
SSchema
*
pSchema
=
req
.
schemaRow
.
pSchema
+
i
;
SField
field
=
{.
type
=
pSchema
->
type
,
.
bytes
=
pSchema
->
bytes
};
strcpy
(
field
.
name
,
pSchema
->
name
);
taosArrayPush
(
pReq
.
pColumns
,
&
field
);
}
pReq
.
pTags
=
taosArrayInit
(
req
.
schemaTag
.
nCols
,
sizeof
(
SField
));
for
(
int32_t
i
=
0
;
i
<
req
.
schemaTag
.
nCols
;
i
++
)
{
SSchema
*
pSchema
=
req
.
schemaTag
.
pSchema
+
i
;
SField
field
=
{.
type
=
pSchema
->
type
,
.
bytes
=
pSchema
->
bytes
};
strcpy
(
field
.
name
,
pSchema
->
name
);
taosArrayPush
(
pReq
.
pTags
,
&
field
);
}
pReq
.
colVer
=
req
.
schemaRow
.
version
;
pReq
.
tagVer
=
req
.
schemaTag
.
version
;
pReq
.
numOfColumns
=
req
.
schemaRow
.
nCols
;
pReq
.
numOfTags
=
req
.
schemaTag
.
nCols
;
pReq
.
commentLen
=
-
1
;
pReq
.
suid
=
req
.
suid
;
pReq
.
source
=
TD_REQ_FROM_TAOX
;
pReq
.
igExists
=
true
;
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SName
tableName
;
tNameExtractFullName
(
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
req
.
name
,
&
tableName
),
pReq
.
name
);
SCmdMsgInfo
pCmdMsg
=
{
0
};
pCmdMsg
.
epSet
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
pCmdMsg
.
msgType
=
TDMT_MND_CREATE_STB
;
pCmdMsg
.
msgLen
=
tSerializeSMCreateStbReq
(
NULL
,
0
,
&
pReq
);
pCmdMsg
.
pMsg
=
taosMemoryMalloc
(
pCmdMsg
.
msgLen
);
if
(
NULL
==
pCmdMsg
.
pMsg
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
tSerializeSMCreateStbReq
(
pCmdMsg
.
pMsg
,
pCmdMsg
.
msgLen
,
&
pReq
);
SQuery
pQuery
=
{
0
};
pQuery
.
execMode
=
QUERY_EXEC_MODE_RPC
;
pQuery
.
pCmdMsg
=
&
pCmdMsg
;
pQuery
.
msgType
=
pQuery
.
pCmdMsg
->
msgType
;
pQuery
.
stableQuery
=
true
;
launchQueryImpl
(
pRequest
,
&
pQuery
,
true
,
NULL
);
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
SCatalog
*
pCatalog
=
NULL
;
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
catalogRemoveTableMeta
(
pCatalog
,
&
tableName
);
}
code
=
pRequest
->
code
;
taosMemoryFree
(
pCmdMsg
.
pMsg
);
end:
destroyRequest
(
pRequest
);
tFreeSMCreateStbReq
(
&
pReq
);
tDecoderClear
(
&
coder
);
return
code
;
}
static
int32_t
taosDropStb
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVDropStbReq
req
=
{
0
};
SDecoder
coder
;
SMDropStbReq
pReq
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVDropStbReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
// build drop stable
pReq
.
igNotExists
=
true
;
pReq
.
source
=
TD_REQ_FROM_TAOX
;
pReq
.
suid
=
req
.
suid
;
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SName
tableName
=
{
0
};
tNameExtractFullName
(
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
req
.
name
,
&
tableName
),
pReq
.
name
);
SCmdMsgInfo
pCmdMsg
=
{
0
};
pCmdMsg
.
epSet
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
pCmdMsg
.
msgType
=
TDMT_MND_DROP_STB
;
pCmdMsg
.
msgLen
=
tSerializeSMDropStbReq
(
NULL
,
0
,
&
pReq
);
pCmdMsg
.
pMsg
=
taosMemoryMalloc
(
pCmdMsg
.
msgLen
);
if
(
NULL
==
pCmdMsg
.
pMsg
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
tSerializeSMDropStbReq
(
pCmdMsg
.
pMsg
,
pCmdMsg
.
msgLen
,
&
pReq
);
SQuery
pQuery
=
{
0
};
pQuery
.
execMode
=
QUERY_EXEC_MODE_RPC
;
pQuery
.
pCmdMsg
=
&
pCmdMsg
;
pQuery
.
msgType
=
pQuery
.
pCmdMsg
->
msgType
;
pQuery
.
stableQuery
=
true
;
launchQueryImpl
(
pRequest
,
&
pQuery
,
true
,
NULL
);
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
SCatalog
*
pCatalog
=
NULL
;
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
catalogRemoveTableMeta
(
pCatalog
,
&
tableName
);
}
code
=
pRequest
->
code
;
taosMemoryFree
(
pCmdMsg
.
pMsg
);
end:
destroyRequest
(
pRequest
);
tDecoderClear
(
&
coder
);
return
code
;
}
typedef
struct
SVgroupCreateTableBatch
{
SVCreateTbBatchReq
req
;
SVgroupInfo
info
;
char
dbName
[
TSDB_DB_NAME_LEN
];
}
SVgroupCreateTableBatch
;
static
void
destroyCreateTbReqBatch
(
void
*
data
)
{
SVgroupCreateTableBatch
*
pTbBatch
=
(
SVgroupCreateTableBatch
*
)
data
;
taosArrayDestroy
(
pTbBatch
->
req
.
pArray
);
}
static
int32_t
taosCreateTable
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVCreateTbBatchReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SHashObj
*
pVgroupHashmap
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVCreateTbBatchReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SVCreateTbReq
*
pCreateReq
=
NULL
;
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
pVgroupHashmap
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
pVgroupHashmap
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
taosHashSetFreeFp
(
pVgroupHashmap
,
destroyCreateTbReqBatch
);
SRequestConnInfo
conn
=
{.
pTrans
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
,
.
mgmtEps
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
)};
pRequest
->
tableList
=
taosArrayInit
(
req
.
nReqs
,
sizeof
(
SName
));
// loop to create table
for
(
int32_t
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
pCreateReq
=
req
.
pReqs
+
iReq
;
SVgroupInfo
pInfo
=
{
0
};
SName
pName
=
{
0
};
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
pCreateReq
->
name
,
&
pName
);
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
taosArrayPush
(
pRequest
->
tableList
,
&
pName
);
SVgroupCreateTableBatch
*
pTableBatch
=
taosHashGet
(
pVgroupHashmap
,
&
pInfo
.
vgId
,
sizeof
(
pInfo
.
vgId
));
if
(
pTableBatch
==
NULL
)
{
SVgroupCreateTableBatch
tBatch
=
{
0
};
tBatch
.
info
=
pInfo
;
strcpy
(
tBatch
.
dbName
,
pRequest
->
pDb
);
tBatch
.
req
.
pArray
=
taosArrayInit
(
4
,
sizeof
(
struct
SVCreateTbReq
));
taosArrayPush
(
tBatch
.
req
.
pArray
,
pCreateReq
);
taosHashPut
(
pVgroupHashmap
,
&
pInfo
.
vgId
,
sizeof
(
pInfo
.
vgId
),
&
tBatch
,
sizeof
(
tBatch
));
}
else
{
// add to the correct vgroup
taosArrayPush
(
pTableBatch
->
req
.
pArray
,
pCreateReq
);
}
}
SArray
*
pBufArray
=
serializeVgroupsCreateTableBatch
(
pVgroupHashmap
);
if
(
NULL
==
pBufArray
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
msgType
=
TDMT_VND_CREATE_TABLE
;
pQuery
->
stableQuery
=
false
;
pQuery
->
pRoot
=
nodesMakeNode
(
QUERY_NODE_CREATE_TABLE_STMT
);
code
=
rewriteToVnodeModifyOpStmt
(
pQuery
,
pBufArray
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
removeMeta
(
pTscObj
,
pRequest
->
tableList
);
}
code
=
pRequest
->
code
;
end:
taosHashCleanup
(
pVgroupHashmap
);
destroyRequest
(
pRequest
);
tDecoderClear
(
&
coder
);
qDestroyQuery
(
pQuery
);
return
code
;
}
typedef
struct
SVgroupDropTableBatch
{
SVDropTbBatchReq
req
;
SVgroupInfo
info
;
char
dbName
[
TSDB_DB_NAME_LEN
];
}
SVgroupDropTableBatch
;
static
void
destroyDropTbReqBatch
(
void
*
data
)
{
SVgroupDropTableBatch
*
pTbBatch
=
(
SVgroupDropTableBatch
*
)
data
;
taosArrayDestroy
(
pTbBatch
->
req
.
pArray
);
}
static
int32_t
taosDropTable
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVDropTbBatchReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SHashObj
*
pVgroupHashmap
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVDropTbBatchReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SVDropTbReq
*
pDropReq
=
NULL
;
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
pVgroupHashmap
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
pVgroupHashmap
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
taosHashSetFreeFp
(
pVgroupHashmap
,
destroyDropTbReqBatch
);
SRequestConnInfo
conn
=
{.
pTrans
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
,
.
mgmtEps
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
)};
pRequest
->
tableList
=
taosArrayInit
(
req
.
nReqs
,
sizeof
(
SName
));
// loop to create table
for
(
int32_t
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
pDropReq
=
req
.
pReqs
+
iReq
;
pDropReq
->
igNotExists
=
true
;
SVgroupInfo
pInfo
=
{
0
};
SName
pName
=
{
0
};
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
pDropReq
->
name
,
&
pName
);
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
taosArrayPush
(
pRequest
->
tableList
,
&
pName
);
SVgroupDropTableBatch
*
pTableBatch
=
taosHashGet
(
pVgroupHashmap
,
&
pInfo
.
vgId
,
sizeof
(
pInfo
.
vgId
));
if
(
pTableBatch
==
NULL
)
{
SVgroupDropTableBatch
tBatch
=
{
0
};
tBatch
.
info
=
pInfo
;
tBatch
.
req
.
pArray
=
taosArrayInit
(
TARRAY_MIN_SIZE
,
sizeof
(
SVDropTbReq
));
taosArrayPush
(
tBatch
.
req
.
pArray
,
pDropReq
);
taosHashPut
(
pVgroupHashmap
,
&
pInfo
.
vgId
,
sizeof
(
pInfo
.
vgId
),
&
tBatch
,
sizeof
(
tBatch
));
}
else
{
// add to the correct vgroup
taosArrayPush
(
pTableBatch
->
req
.
pArray
,
pDropReq
);
}
}
SArray
*
pBufArray
=
serializeVgroupsDropTableBatch
(
pVgroupHashmap
);
if
(
NULL
==
pBufArray
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
msgType
=
TDMT_VND_DROP_TABLE
;
pQuery
->
stableQuery
=
false
;
pQuery
->
pRoot
=
nodesMakeNode
(
QUERY_NODE_DROP_TABLE_STMT
);
code
=
rewriteToVnodeModifyOpStmt
(
pQuery
,
pBufArray
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
removeMeta
(
pTscObj
,
pRequest
->
tableList
);
}
code
=
pRequest
->
code
;
end:
taosHashCleanup
(
pVgroupHashmap
);
destroyRequest
(
pRequest
);
tDecoderClear
(
&
coder
);
qDestroyQuery
(
pQuery
);
return
code
;
}
// delete from db.tabl where .. -> delete from tabl where ..
// delete from db .tabl where .. -> delete from tabl where ..
// static void getTbName(char *sql){
// char *ch = sql;
//
// bool inBackQuote = false;
// int8_t dotIndex = 0;
// while(*ch != '\0'){
// if(!inBackQuote && *ch == '`'){
// inBackQuote = true;
// ch++;
// continue;
// }
//
// if(inBackQuote && *ch == '`'){
// inBackQuote = false;
// ch++;
//
// continue;
// }
//
// if(!inBackQuote && *ch == '.'){
// dotIndex ++;
// if(dotIndex == 2){
// memmove(sql, ch + 1, strlen(ch + 1) + 1);
// break;
// }
// }
// ch++;
// }
//}
static
int32_t
taosDeleteData
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SDeleteRes
req
=
{
0
};
SDecoder
coder
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeDeleteRes
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
// getTbName(req.tableFName);
char
sql
[
256
]
=
{
0
};
sprintf
(
sql
,
"delete from `%s` where `%s` >= %"
PRId64
" and `%s` <= %"
PRId64
,
req
.
tableFName
,
req
.
tsColName
,
req
.
skey
,
req
.
tsColName
,
req
.
ekey
);
printf
(
"delete sql:%s
\n
"
,
sql
);
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
SRequestObj
*
pRequest
=
(
SRequestObj
*
)
res
;
code
=
pRequest
->
code
;
if
(
code
==
TSDB_CODE_PAR_TABLE_NOT_EXIST
)
{
code
=
TSDB_CODE_SUCCESS
;
}
taos_free_result
(
res
);
end:
tDecoderClear
(
&
coder
);
return
code
;
}
static
int32_t
taosAlterTable
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVAlterTbReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SArray
*
pArray
=
NULL
;
SVgDataBlocks
*
pVgData
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVAlterTbReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
// do not deal TSDB_ALTER_TABLE_UPDATE_OPTIONS
if
(
req
.
action
==
TSDB_ALTER_TABLE_UPDATE_OPTIONS
)
{
goto
end
;
}
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
SRequestConnInfo
conn
=
{.
pTrans
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
,
.
mgmtEps
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
)};
SVgroupInfo
pInfo
=
{
0
};
SName
pName
=
{
0
};
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
req
.
tbName
,
&
pName
);
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
pArray
=
taosArrayInit
(
1
,
sizeof
(
void
*
));
if
(
NULL
==
pArray
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pVgData
=
taosMemoryCalloc
(
1
,
sizeof
(
SVgDataBlocks
));
if
(
NULL
==
pVgData
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pVgData
->
vg
=
pInfo
;
pVgData
->
pData
=
taosMemoryMalloc
(
metaLen
);
if
(
NULL
==
pVgData
->
pData
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
memcpy
(
pVgData
->
pData
,
meta
,
metaLen
);
((
SMsgHead
*
)
pVgData
->
pData
)
->
vgId
=
htonl
(
pInfo
.
vgId
);
pVgData
->
size
=
metaLen
;
pVgData
->
numOfTables
=
1
;
taosArrayPush
(
pArray
,
&
pVgData
);
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
msgType
=
TDMT_VND_ALTER_TABLE
;
pQuery
->
stableQuery
=
false
;
pQuery
->
pRoot
=
nodesMakeNode
(
QUERY_NODE_ALTER_TABLE_STMT
);
code
=
rewriteToVnodeModifyOpStmt
(
pQuery
,
pArray
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
pVgData
=
NULL
;
pArray
=
NULL
;
code
=
pRequest
->
code
;
if
(
code
==
TSDB_CODE_VND_TABLE_NOT_EXIST
)
{
code
=
TSDB_CODE_SUCCESS
;
}
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
SExecResult
*
pRes
=
&
pRequest
->
body
.
resInfo
.
execRes
;
if
(
pRes
->
res
!=
NULL
)
{
code
=
handleAlterTbExecRes
(
pRes
->
res
,
pCatalog
);
}
}
end:
taosArrayDestroy
(
pArray
);
if
(
pVgData
)
taosMemoryFreeClear
(
pVgData
->
pData
);
taosMemoryFreeClear
(
pVgData
);
destroyRequest
(
pRequest
);
tDecoderClear
(
&
coder
);
qDestroyQuery
(
pQuery
);
return
code
;
}
typedef
struct
{
SVgroupInfo
vg
;
void
*
data
;
}
VgData
;
static
void
destroyVgHash
(
void
*
data
)
{
VgData
*
vgData
=
(
VgData
*
)
data
;
taosMemoryFreeClear
(
vgData
->
data
);
}
int
taos_write_raw_block
(
TAOS
*
taos
,
int
rows
,
char
*
pData
,
const
char
*
tbname
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
STableMeta
*
pTableMeta
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SRequestObj
*
pRequest
=
(
SRequestObj
*
)
createRequest
(
*
(
int64_t
*
)
taos
,
TSDB_SQL_INSERT
);
if
(
!
pRequest
)
{
uError
(
"WriteRaw:createRequest error request is null"
);
code
=
terrno
;
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
uError
(
"WriteRaw:not use db"
);
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
SName
pName
=
{
TSDB_TABLE_NAME_T
,
pRequest
->
pTscObj
->
acctId
,
{
0
},
{
0
}};
strcpy
(
pName
.
dbname
,
pRequest
->
pDb
);
strcpy
(
pName
.
tname
,
tbname
);
struct
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pRequest
->
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw: get gatlog error"
);
goto
end
;
}
SRequestConnInfo
conn
=
{
0
};
conn
.
pTrans
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
;
conn
.
requestId
=
pRequest
->
requestId
;
conn
.
requestObjRefId
=
pRequest
->
self
;
conn
.
mgmtEps
=
getEpSet_s
(
&
pRequest
->
pTscObj
->
pAppInfo
->
mgmtEp
);
SVgroupInfo
vgData
=
{
0
};
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
vgData
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw:catalogGetTableHashVgroup failed. table name: %s"
,
tbname
);
goto
end
;
}
code
=
catalogGetTableMeta
(
pCatalog
,
&
conn
,
&
pName
,
&
pTableMeta
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw:catalogGetTableMeta failed. table name: %s"
,
tbname
);
goto
end
;
}
uint64_t
suid
=
(
TSDB_NORMAL_TABLE
==
pTableMeta
->
tableType
?
0
:
pTableMeta
->
suid
);
uint64_t
uid
=
pTableMeta
->
uid
;
int32_t
numOfCols
=
pTableMeta
->
tableInfo
.
numOfColumns
;
uint16_t
fLen
=
0
;
int32_t
rowSize
=
0
;
int16_t
nVar
=
0
;
for
(
int
i
=
0
;
i
<
numOfCols
;
i
++
)
{
SSchema
*
schema
=
pTableMeta
->
schema
+
i
;
fLen
+=
TYPE_BYTES
[
schema
->
type
];
rowSize
+=
schema
->
bytes
;
if
(
IS_VAR_DATA_TYPE
(
schema
->
type
))
{
nVar
++
;
}
}
int32_t
extendedRowSize
=
rowSize
+
TD_ROW_HEAD_LEN
-
sizeof
(
TSKEY
)
+
nVar
*
sizeof
(
VarDataOffsetT
)
+
(
int32_t
)
TD_BITMAP_BYTES
(
numOfCols
-
1
);
int32_t
schemaLen
=
0
;
int32_t
submitLen
=
sizeof
(
SSubmitBlk
)
+
schemaLen
+
rows
*
extendedRowSize
;
int32_t
totalLen
=
sizeof
(
SSubmitReq
)
+
submitLen
;
SSubmitReq
*
subReq
=
taosMemoryCalloc
(
1
,
totalLen
);
SSubmitBlk
*
blk
=
POINTER_SHIFT
(
subReq
,
sizeof
(
SSubmitReq
));
void
*
blkSchema
=
POINTER_SHIFT
(
blk
,
sizeof
(
SSubmitBlk
));
STSRow
*
rowData
=
POINTER_SHIFT
(
blkSchema
,
schemaLen
);
SRowBuilder
rb
=
{
0
};
tdSRowInit
(
&
rb
,
pTableMeta
->
sversion
);
tdSRowSetTpInfo
(
&
rb
,
numOfCols
,
fLen
);
int32_t
dataLen
=
0
;
char
*
pStart
=
pData
+
getVersion1BlockMetaSize
(
pData
,
numOfCols
);
int32_t
*
colLength
=
(
int32_t
*
)
pStart
;
pStart
+=
sizeof
(
int32_t
)
*
numOfCols
;
SResultColumn
*
pCol
=
taosMemoryCalloc
(
numOfCols
,
sizeof
(
SResultColumn
));
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
if
(
IS_VAR_DATA_TYPE
(
pTableMeta
->
schema
[
i
].
type
))
{
pCol
[
i
].
offset
=
(
int32_t
*
)
pStart
;
pStart
+=
rows
*
sizeof
(
int32_t
);
}
else
{
pCol
[
i
].
nullbitmap
=
pStart
;
pStart
+=
BitmapLen
(
rows
);
}
pCol
[
i
].
pData
=
pStart
;
pStart
+=
colLength
[
i
];
}
for
(
int32_t
j
=
0
;
j
<
rows
;
j
++
)
{
tdSRowResetBuf
(
&
rb
,
rowData
);
int32_t
offset
=
0
;
for
(
int32_t
k
=
0
;
k
<
numOfCols
;
k
++
)
{
const
SSchema
*
pColumn
=
&
pTableMeta
->
schema
[
k
];
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
type
))
{
if
(
pCol
[
k
].
offset
[
j
]
!=
-
1
)
{
char
*
data
=
pCol
[
k
].
pData
+
pCol
[
k
].
offset
[
j
];
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NORM
,
data
,
true
,
offset
,
k
);
}
else
{
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NULL
,
NULL
,
false
,
offset
,
k
);
}
}
else
{
if
(
!
colDataIsNull_f
(
pCol
[
k
].
nullbitmap
,
j
))
{
char
*
data
=
pCol
[
k
].
pData
+
pColumn
->
bytes
*
j
;
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NORM
,
data
,
true
,
offset
,
k
);
}
else
{
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NULL
,
NULL
,
false
,
offset
,
k
);
}
}
offset
+=
TYPE_BYTES
[
pColumn
->
type
];
}
tdSRowEnd
(
&
rb
);
int32_t
rowLen
=
TD_ROW_LEN
(
rowData
);
rowData
=
POINTER_SHIFT
(
rowData
,
rowLen
);
dataLen
+=
rowLen
;
}
taosMemoryFree
(
pCol
);
blk
->
uid
=
htobe64
(
uid
);
blk
->
suid
=
htobe64
(
suid
);
blk
->
sversion
=
htonl
(
pTableMeta
->
sversion
);
blk
->
schemaLen
=
htonl
(
schemaLen
);
blk
->
numOfRows
=
htonl
(
rows
);
blk
->
dataLen
=
htonl
(
dataLen
);
subReq
->
length
=
sizeof
(
SSubmitReq
)
+
sizeof
(
SSubmitBlk
)
+
schemaLen
+
dataLen
;
subReq
->
numOfBlocks
=
1
;
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
if
(
NULL
==
pQuery
)
{
uError
(
"create SQuery error"
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
haveResultSet
=
false
;
pQuery
->
msgType
=
TDMT_VND_SUBMIT
;
pQuery
->
pRoot
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VNODE_MODIF_STMT
);
if
(
NULL
==
pQuery
->
pRoot
)
{
uError
(
"create pQuery->pRoot error"
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
SVnodeModifOpStmt
*
nodeStmt
=
(
SVnodeModifOpStmt
*
)(
pQuery
->
pRoot
);
nodeStmt
->
payloadType
=
PAYLOAD_TYPE_KV
;
nodeStmt
->
pDataBlocks
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SVgDataBlocks
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
SVgDataBlocks
));
if
(
NULL
==
dst
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
dst
->
vg
=
vgData
;
dst
->
numOfTables
=
subReq
->
numOfBlocks
;
dst
->
size
=
subReq
->
length
;
dst
->
pData
=
(
char
*
)
subReq
;
subReq
->
header
.
vgId
=
htonl
(
dst
->
vg
.
vgId
);
subReq
->
version
=
htonl
(
1
);
subReq
->
header
.
contLen
=
htonl
(
subReq
->
length
);
subReq
->
length
=
htonl
(
subReq
->
length
);
subReq
->
numOfBlocks
=
htonl
(
subReq
->
numOfBlocks
);
subReq
=
NULL
;
// no need free
taosArrayPush
(
nodeStmt
->
pDataBlocks
,
&
dst
);
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
code
=
pRequest
->
code
;
end:
taosMemoryFreeClear
(
pTableMeta
);
qDestroyQuery
(
pQuery
);
return
code
;
}
static
int32_t
tmqWriteRaw
(
TAOS
*
taos
,
void
*
data
,
int32_t
dataLen
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SHashObj
*
pVgHash
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SMqRspObj
rspObj
=
{
0
};
SDecoder
decoder
=
{
0
};
terrno
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
(
SRequestObj
*
)
createRequest
(
*
(
int64_t
*
)
taos
,
TSDB_SQL_INSERT
);
if
(
!
pRequest
)
{
uError
(
"WriteRaw:createRequest error request is null"
);
return
terrno
;
}
rspObj
.
resIter
=
-
1
;
rspObj
.
resType
=
RES_TYPE__TMQ
;
tDecoderInit
(
&
decoder
,
data
,
dataLen
);
code
=
tDecodeSMqDataRsp
(
&
decoder
,
&
rspObj
.
rsp
);
if
(
code
!=
0
)
{
uError
(
"WriteRaw:decode smqDataRsp error"
);
code
=
TSDB_CODE_INVALID_MSG
;
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
uError
(
"WriteRaw:not use db"
);
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
pVgHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_NO_LOCK
);
taosHashSetFreeFp
(
pVgHash
,
destroyVgHash
);
struct
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pRequest
->
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw: get gatlog error"
);
goto
end
;
}
SRequestConnInfo
conn
=
{
0
};
conn
.
pTrans
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
;
conn
.
requestId
=
pRequest
->
requestId
;
conn
.
requestObjRefId
=
pRequest
->
self
;
conn
.
mgmtEps
=
getEpSet_s
(
&
pRequest
->
pTscObj
->
pAppInfo
->
mgmtEp
);
printf
(
"raw data block num:%d
\n
"
,
rspObj
.
rsp
.
blockNum
);
while
(
++
rspObj
.
resIter
<
rspObj
.
rsp
.
blockNum
)
{
SRetrieveTableRsp
*
pRetrieve
=
(
SRetrieveTableRsp
*
)
taosArrayGetP
(
rspObj
.
rsp
.
blockData
,
rspObj
.
resIter
);
if
(
!
rspObj
.
rsp
.
withSchema
)
{
uError
(
"WriteRaw:no schema, iter:%d"
,
rspObj
.
resIter
);
goto
end
;
}
SSchemaWrapper
*
pSW
=
(
SSchemaWrapper
*
)
taosArrayGetP
(
rspObj
.
rsp
.
blockSchema
,
rspObj
.
resIter
);
setResSchemaInfo
(
&
rspObj
.
resInfo
,
pSW
->
pSchema
,
pSW
->
nCols
);
code
=
setQueryResultFromRsp
(
&
rspObj
.
resInfo
,
pRetrieve
,
false
,
false
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw: setQueryResultFromRsp error"
);
goto
end
;
}
uint16_t
fLen
=
0
;
int32_t
rowSize
=
0
;
int16_t
nVar
=
0
;
for
(
int
i
=
0
;
i
<
pSW
->
nCols
;
i
++
)
{
SSchema
*
schema
=
pSW
->
pSchema
+
i
;
fLen
+=
TYPE_BYTES
[
schema
->
type
];
rowSize
+=
schema
->
bytes
;
if
(
IS_VAR_DATA_TYPE
(
schema
->
type
))
{
nVar
++
;
}
}
int32_t
rows
=
rspObj
.
resInfo
.
numOfRows
;
int32_t
extendedRowSize
=
rowSize
+
TD_ROW_HEAD_LEN
-
sizeof
(
TSKEY
)
+
nVar
*
sizeof
(
VarDataOffsetT
)
+
(
int32_t
)
TD_BITMAP_BYTES
(
pSW
->
nCols
-
1
);
int32_t
schemaLen
=
0
;
int32_t
submitLen
=
sizeof
(
SSubmitBlk
)
+
schemaLen
+
rows
*
extendedRowSize
;
const
char
*
tbName
=
(
const
char
*
)
taosArrayGetP
(
rspObj
.
rsp
.
blockTbName
,
rspObj
.
resIter
);
if
(
!
tbName
)
{
uError
(
"WriteRaw: tbname is null"
);
code
=
TSDB_CODE_TMQ_INVALID_MSG
;
goto
end
;
}
printf
(
"raw data tbname:%s
\n
"
,
tbName
);
SName
pName
=
{
TSDB_TABLE_NAME_T
,
pRequest
->
pTscObj
->
acctId
,
{
0
},
{
0
}};
strcpy
(
pName
.
dbname
,
pRequest
->
pDb
);
strcpy
(
pName
.
tname
,
tbName
);
VgData
vgData
=
{
0
};
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
(
vgData
.
vg
));
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw:catalogGetTableHashVgroup failed. table name: %s"
,
tbName
);
goto
end
;
}
SSubmitReq
*
subReq
=
NULL
;
SSubmitBlk
*
blk
=
NULL
;
void
*
hData
=
taosHashGet
(
pVgHash
,
&
vgData
.
vg
.
vgId
,
sizeof
(
vgData
.
vg
.
vgId
));
if
(
hData
)
{
vgData
=
*
(
VgData
*
)
hData
;
int32_t
totalLen
=
((
SSubmitReq
*
)(
vgData
.
data
))
->
length
+
submitLen
;
void
*
tmp
=
taosMemoryRealloc
(
vgData
.
data
,
totalLen
);
if
(
tmp
==
NULL
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
vgData
.
data
=
tmp
;
((
VgData
*
)
hData
)
->
data
=
tmp
;
subReq
=
(
SSubmitReq
*
)(
vgData
.
data
);
blk
=
POINTER_SHIFT
(
vgData
.
data
,
subReq
->
length
);
}
else
{
int32_t
totalLen
=
sizeof
(
SSubmitReq
)
+
submitLen
;
void
*
tmp
=
taosMemoryCalloc
(
1
,
totalLen
);
if
(
tmp
==
NULL
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
vgData
.
data
=
tmp
;
taosHashPut
(
pVgHash
,
(
const
char
*
)
&
vgData
.
vg
.
vgId
,
sizeof
(
vgData
.
vg
.
vgId
),
(
char
*
)
&
vgData
,
sizeof
(
vgData
));
subReq
=
(
SSubmitReq
*
)(
vgData
.
data
);
subReq
->
length
=
sizeof
(
SSubmitReq
);
subReq
->
numOfBlocks
=
0
;
blk
=
POINTER_SHIFT
(
vgData
.
data
,
sizeof
(
SSubmitReq
));
}
STableMeta
*
pTableMeta
=
NULL
;
code
=
catalogGetTableMeta
(
pCatalog
,
&
conn
,
&
pName
,
&
pTableMeta
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw:catalogGetTableMeta failed. table name: %s"
,
tbName
);
goto
end
;
}
uint64_t
suid
=
(
TSDB_NORMAL_TABLE
==
pTableMeta
->
tableType
?
0
:
pTableMeta
->
suid
);
uint64_t
uid
=
pTableMeta
->
uid
;
taosMemoryFreeClear
(
pTableMeta
);
void
*
blkSchema
=
POINTER_SHIFT
(
blk
,
sizeof
(
SSubmitBlk
));
STSRow
*
rowData
=
POINTER_SHIFT
(
blkSchema
,
schemaLen
);
SRowBuilder
rb
=
{
0
};
tdSRowInit
(
&
rb
,
pSW
->
version
);
tdSRowSetTpInfo
(
&
rb
,
pSW
->
nCols
,
fLen
);
int32_t
dataLen
=
0
;
for
(
int32_t
j
=
0
;
j
<
rows
;
j
++
)
{
tdSRowResetBuf
(
&
rb
,
rowData
);
doSetOneRowPtr
(
&
rspObj
.
resInfo
);
rspObj
.
resInfo
.
current
+=
1
;
int32_t
offset
=
0
;
for
(
int32_t
k
=
0
;
k
<
pSW
->
nCols
;
k
++
)
{
const
SSchema
*
pColumn
=
&
pSW
->
pSchema
[
k
];
char
*
data
=
rspObj
.
resInfo
.
row
[
k
];
if
(
!
data
)
{
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NULL
,
NULL
,
false
,
offset
,
k
);
}
else
{
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
type
))
{
data
-=
VARSTR_HEADER_SIZE
;
}
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NORM
,
data
,
true
,
offset
,
k
);
}
offset
+=
TYPE_BYTES
[
pColumn
->
type
];
}
tdSRowEnd
(
&
rb
);
int32_t
rowLen
=
TD_ROW_LEN
(
rowData
);
rowData
=
POINTER_SHIFT
(
rowData
,
rowLen
);
dataLen
+=
rowLen
;
}
blk
->
uid
=
htobe64
(
uid
);
blk
->
suid
=
htobe64
(
suid
);
blk
->
sversion
=
htonl
(
pSW
->
version
);
blk
->
schemaLen
=
htonl
(
schemaLen
);
blk
->
numOfRows
=
htonl
(
rows
);
blk
->
dataLen
=
htonl
(
dataLen
);
subReq
->
length
+=
sizeof
(
SSubmitBlk
)
+
schemaLen
+
dataLen
;
subReq
->
numOfBlocks
++
;
}
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
if
(
NULL
==
pQuery
)
{
uError
(
"create SQuery error"
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
haveResultSet
=
false
;
pQuery
->
msgType
=
TDMT_VND_SUBMIT
;
pQuery
->
pRoot
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VNODE_MODIF_STMT
);
if
(
NULL
==
pQuery
->
pRoot
)
{
uError
(
"create pQuery->pRoot error"
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
SVnodeModifOpStmt
*
nodeStmt
=
(
SVnodeModifOpStmt
*
)(
pQuery
->
pRoot
);
nodeStmt
->
payloadType
=
PAYLOAD_TYPE_KV
;
int32_t
numOfVg
=
taosHashGetSize
(
pVgHash
);
nodeStmt
->
pDataBlocks
=
taosArrayInit
(
numOfVg
,
POINTER_BYTES
);
VgData
*
vData
=
(
VgData
*
)
taosHashIterate
(
pVgHash
,
NULL
);
while
(
vData
)
{
SVgDataBlocks
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
SVgDataBlocks
));
if
(
NULL
==
dst
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
dst
->
vg
=
vData
->
vg
;
SSubmitReq
*
subReq
=
(
SSubmitReq
*
)(
vData
->
data
);
dst
->
numOfTables
=
subReq
->
numOfBlocks
;
dst
->
size
=
subReq
->
length
;
dst
->
pData
=
(
char
*
)
subReq
;
vData
->
data
=
NULL
;
// no need free
subReq
->
header
.
vgId
=
htonl
(
dst
->
vg
.
vgId
);
subReq
->
version
=
htonl
(
1
);
subReq
->
header
.
contLen
=
htonl
(
subReq
->
length
);
subReq
->
length
=
htonl
(
subReq
->
length
);
subReq
->
numOfBlocks
=
htonl
(
subReq
->
numOfBlocks
);
taosArrayPush
(
nodeStmt
->
pDataBlocks
,
&
dst
);
vData
=
(
VgData
*
)
taosHashIterate
(
pVgHash
,
vData
);
}
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
code
=
pRequest
->
code
;
end:
tDecoderClear
(
&
decoder
);
qDestroyQuery
(
pQuery
);
destroyRequest
(
pRequest
);
taosHashCleanup
(
pVgHash
);
return
code
;
}
char
*
tmq_get_json_meta
(
TAOS_RES
*
res
)
{
if
(
!
TD_RES_TMQ_META
(
res
))
{
return
NULL
;
}
SMqMetaRspObj
*
pMetaRspObj
=
(
SMqMetaRspObj
*
)
res
;
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_CREATE_STB
)
{
return
processCreateStb
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_ALTER_STB
)
{
return
processAlterStb
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_DROP_STB
)
{
return
processDropSTable
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_CREATE_TABLE
)
{
return
processCreateTable
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_ALTER_TABLE
)
{
return
processAlterTable
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_DROP_TABLE
)
{
return
processDropTable
(
&
pMetaRspObj
->
metaRsp
);
}
return
NULL
;
}
void
tmq_free_json_meta
(
char
*
jsonMeta
)
{
taosMemoryFreeClear
(
jsonMeta
);
}
int32_t
tmq_get_raw
(
TAOS_RES
*
res
,
tmq_raw_data
*
raw
)
{
if
(
!
raw
||
!
res
)
{
return
TSDB_CODE_INVALID_PARA
;
}
if
(
TD_RES_TMQ_META
(
res
))
{
SMqMetaRspObj
*
pMetaRspObj
=
(
SMqMetaRspObj
*
)
res
;
raw
->
raw
=
pMetaRspObj
->
metaRsp
.
metaRsp
;
raw
->
raw_len
=
pMetaRspObj
->
metaRsp
.
metaRspLen
;
raw
->
raw_type
=
pMetaRspObj
->
metaRsp
.
resMsgType
;
}
else
if
(
TD_RES_TMQ
(
res
))
{
SMqRspObj
*
rspObj
=
((
SMqRspObj
*
)
res
);
int32_t
len
=
0
;
int32_t
code
=
0
;
tEncodeSize
(
tEncodeSMqDataRsp
,
&
rspObj
->
rsp
,
len
,
code
);
if
(
code
<
0
)
{
return
-
1
;
}
void
*
buf
=
taosMemoryCalloc
(
1
,
len
);
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
buf
,
len
);
tEncodeSMqDataRsp
(
&
encoder
,
&
rspObj
->
rsp
);
tEncoderClear
(
&
encoder
);
raw
->
raw
=
buf
;
raw
->
raw_len
=
len
;
raw
->
raw_type
=
RES_TYPE__TMQ
;
}
else
{
return
TSDB_CODE_TMQ_INVALID_MSG
;
}
return
TSDB_CODE_SUCCESS
;
}
void
tmq_free_raw
(
tmq_raw_data
raw
)
{
if
(
raw
.
raw_type
==
RES_TYPE__TMQ
)
{
taosMemoryFree
(
raw
.
raw
);
}
}
int32_t
tmq_write_raw
(
TAOS
*
taos
,
tmq_raw_data
raw
)
{
if
(
!
taos
)
{
return
TSDB_CODE_INVALID_PARA
;
}
if
(
raw
.
raw_type
==
TDMT_VND_CREATE_STB
)
{
return
taosCreateStb
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_ALTER_STB
)
{
return
taosCreateStb
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_DROP_STB
)
{
return
taosDropStb
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_CREATE_TABLE
)
{
return
taosCreateTable
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_ALTER_TABLE
)
{
return
taosAlterTable
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_DROP_TABLE
)
{
return
taosDropTable
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_DELETE
)
{
return
taosDeleteData
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
RES_TYPE__TMQ
)
{
return
tmqWriteRaw
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
return
TSDB_CODE_INVALID_PARA
;
}
source/client/src/tmq.c
浏览文件 @
77f27b62
...
...
@@ -30,6 +30,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool async);
typedef
struct
{
int8_t
inited
;
tmr_h
timer
;
int32_t
rsetId
;
}
SMqMgmt
;
static
SMqMgmt
tmqMgmt
=
{
0
};
...
...
@@ -70,6 +71,7 @@ struct tmq_conf_t {
};
struct
tmq_t
{
int64_t
refId
;
// conf
char
groupId
[
TSDB_CGROUP_LEN
];
char
clientId
[
256
];
...
...
@@ -146,7 +148,7 @@ typedef struct {
typedef
struct
{
// subscribe info
char
*
topicName
;
char
topicName
[
TSDB_TOPIC_FNAME_LEN
]
;
char
db
[
TSDB_DB_FNAME_LEN
];
SArray
*
vgs
;
// SArray<SMqClientVg>
...
...
@@ -166,29 +168,32 @@ typedef struct {
}
SMqPollRspWrapper
;
typedef
struct
{
tmq_t
*
tmq
;
int64_t
refId
;
int32_t
epoch
;
tsem_t
rspSem
;
int32_t
rspErr
;
}
SMqSubscribeCbParam
;
typedef
struct
{
tmq_t
*
tmq
;
int64_t
refId
;
int32_t
epoch
;
int32_t
code
;
int32_t
async
;
tsem_t
rspSem
;
}
SMqAskEpCbParam
;
typedef
struct
{
tmq_t
*
tmq
;
int64_t
refId
;
int32_t
epoch
;
SMqClientVg
*
pVg
;
SMqClientTopic
*
pTopic
;
int32_t
epoch
;
int32_t
vgId
;
tsem_t
rspSem
;
}
SMqPollCbParam
;
typedef
struct
{
tmq_t
*
tmq
;
int64_t
refId
;
int32_t
epoch
;
int8_t
automatic
;
int8_t
async
;
int32_t
waitingRspNum
;
...
...
@@ -369,6 +374,38 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
return
sprintf
(
dst
,
"%s:%d"
,
topicName
,
vg
);
}
int32_t
tmqCommitDone
(
SMqCommitCbParamSet
*
pParamSet
)
{
tmq_t
*
tmq
=
taosAcquireRef
(
tmqMgmt
.
rsetId
,
pParamSet
->
refId
);
if
(
tmq
==
NULL
)
{
if
(
!
pParamSet
->
async
)
{
tsem_destroy
(
&
pParamSet
->
rspSem
);
}
taosMemoryFree
(
pParamSet
);
terrno
=
TSDB_CODE_TMQ_CONSUMER_CLOSED
;
return
-
1
;
}
// if no more waiting rsp
if
(
pParamSet
->
async
)
{
// call async cb func
if
(
pParamSet
->
automatic
&&
tmq
->
commitCb
)
{
tmq
->
commitCb
(
tmq
,
pParamSet
->
rspErr
,
tmq
->
commitCbUserParam
);
}
else
if
(
!
pParamSet
->
automatic
&&
pParamSet
->
userCb
)
{
// sem post
pParamSet
->
userCb
(
tmq
,
pParamSet
->
rspErr
,
pParamSet
->
userParam
);
}
taosMemoryFree
(
pParamSet
);
}
else
{
tsem_post
(
&
pParamSet
->
rspSem
);
}
#if 0
taosArrayDestroyP(pParamSet->successfulOffsets, taosMemoryFree);
taosArrayDestroyP(pParamSet->failedOffsets, taosMemoryFree);
#endif
return
0
;
}
int32_t
tmqCommitCb
(
void
*
param
,
SDataBuf
*
pBuf
,
int32_t
code
)
{
SMqCommitCbParam
*
pParam
=
(
SMqCommitCbParam
*
)
param
;
SMqCommitCbParamSet
*
pParamSet
=
(
SMqCommitCbParamSet
*
)
pParam
->
params
;
...
...
@@ -392,25 +429,7 @@ int32_t tmqCommitCb(void* param, SDataBuf* pBuf, int32_t code) {
ASSERT
(
waitingRspNum
>=
0
);
if
(
waitingRspNum
==
0
)
{
// if no more waiting rsp
if
(
pParamSet
->
async
)
{
// call async cb func
if
(
pParamSet
->
automatic
&&
pParamSet
->
tmq
->
commitCb
)
{
pParamSet
->
tmq
->
commitCb
(
pParamSet
->
tmq
,
pParamSet
->
rspErr
,
pParamSet
->
tmq
->
commitCbUserParam
);
}
else
if
(
!
pParamSet
->
automatic
&&
pParamSet
->
userCb
)
{
// sem post
pParamSet
->
userCb
(
pParamSet
->
tmq
,
pParamSet
->
rspErr
,
pParamSet
->
userParam
);
}
}
else
{
tsem_post
(
&
pParamSet
->
rspSem
);
}
taosMemoryFree
(
pParamSet
);
#if 0
taosArrayDestroyP(pParamSet->successfulOffsets, taosMemoryFree);
taosArrayDestroyP(pParamSet->failedOffsets, taosMemoryFree);
#endif
tmqCommitDone
(
pParamSet
);
}
return
0
;
}
...
...
@@ -504,7 +523,8 @@ int32_t tmqCommitMsgImpl(tmq_t* tmq, const TAOS_RES* msg, int8_t async, tmq_comm
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pParamSet
->
tmq
=
tmq
;
pParamSet
->
refId
=
tmq
->
refId
;
pParamSet
->
epoch
=
tmq
->
epoch
;
pParamSet
->
automatic
=
0
;
pParamSet
->
async
=
async
;
pParamSet
->
userCb
=
userCb
;
...
...
@@ -565,13 +585,19 @@ int32_t tmqCommitInner(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_t
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pParamSet
->
tmq
=
tmq
;
pParamSet
->
refId
=
tmq
->
refId
;
pParamSet
->
epoch
=
tmq
->
epoch
;
pParamSet
->
automatic
=
automatic
;
pParamSet
->
async
=
async
;
pParamSet
->
userCb
=
userCb
;
pParamSet
->
userParam
=
userParam
;
tsem_init
(
&
pParamSet
->
rspSem
,
0
,
0
);
// init as 1 to prevent concurrency issue
pParamSet
->
waitingRspNum
=
1
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
tmq
->
clientTopics
);
i
++
)
{
SMqClientTopic
*
pTopic
=
taosArrayGet
(
tmq
->
clientTopics
,
i
);
...
...
@@ -600,10 +626,17 @@ int32_t tmqCommitInner(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_t
return
0
;
}
int32_t
waitingRspNum
=
atomic_sub_fetch_32
(
&
pParamSet
->
waitingRspNum
,
1
);
ASSERT
(
waitingRspNum
>=
0
);
if
(
waitingRspNum
==
0
)
{
tmqCommitDone
(
pParamSet
);
}
if
(
!
async
)
{
tsem_wait
(
&
pParamSet
->
rspSem
);
code
=
pParamSet
->
rspErr
;
tsem_destroy
(
&
pParamSet
->
rspSem
);
taosMemoryFree
(
pParamSet
);
}
else
{
code
=
0
;
}
...
...
@@ -616,38 +649,50 @@ int32_t tmqCommitInner(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_t
}
}
if
(
!
async
)
{
#if 0
if (!async) {
taosArrayDestroyP(pParamSet->successfulOffsets, taosMemoryFree);
taosArrayDestroyP(pParamSet->failedOffsets, taosMemoryFree);
#endif
}
#endif
return
0
;
}
void
tmqAssignAskEpTask
(
void
*
param
,
void
*
tmrId
)
{
tmq_t
*
tmq
=
(
tmq_t
*
)
param
;
int64_t
refId
=
*
(
int64_t
*
)
param
;
tmq_t
*
tmq
=
taosAcquireRef
(
tmqMgmt
.
rsetId
,
refId
);
if
(
tmq
!=
NULL
)
{
int8_t
*
pTaskType
=
taosAllocateQitem
(
sizeof
(
int8_t
),
DEF_QITEM
);
*
pTaskType
=
TMQ_DELAYED_TASK__ASK_EP
;
taosWriteQitem
(
tmq
->
delayedTask
,
pTaskType
);
tsem_post
(
&
tmq
->
rspSem
);
}
taosMemoryFree
(
param
);
}
void
tmqAssignDelayedCommitTask
(
void
*
param
,
void
*
tmrId
)
{
tmq_t
*
tmq
=
(
tmq_t
*
)
param
;
int64_t
refId
=
*
(
int64_t
*
)
param
;
tmq_t
*
tmq
=
taosAcquireRef
(
tmqMgmt
.
rsetId
,
refId
);
if
(
tmq
!=
NULL
)
{
int8_t
*
pTaskType
=
taosAllocateQitem
(
sizeof
(
int8_t
),
DEF_QITEM
);
*
pTaskType
=
TMQ_DELAYED_TASK__COMMIT
;
taosWriteQitem
(
tmq
->
delayedTask
,
pTaskType
);
tsem_post
(
&
tmq
->
rspSem
);
}
taosMemoryFree
(
param
);
}
void
tmqAssignDelayedReportTask
(
void
*
param
,
void
*
tmrId
)
{
tmq_t
*
tmq
=
(
tmq_t
*
)
param
;
int64_t
refId
=
*
(
int64_t
*
)
param
;
tmq_t
*
tmq
=
taosAcquireRef
(
tmqMgmt
.
rsetId
,
refId
);
if
(
tmq
!=
NULL
)
{
int8_t
*
pTaskType
=
taosAllocateQitem
(
sizeof
(
int8_t
),
DEF_QITEM
);
*
pTaskType
=
TMQ_DELAYED_TASK__REPORT
;
taosWriteQitem
(
tmq
->
delayedTask
,
pTaskType
);
tsem_post
(
&
tmq
->
rspSem
);
}
taosMemoryFree
(
param
);
}
int32_t
tmqHbCb
(
void
*
param
,
SDataBuf
*
pMsg
,
int32_t
code
)
{
...
...
@@ -656,8 +701,11 @@ int32_t tmqHbCb(void* param, SDataBuf* pMsg, int32_t code) {
}
void
tmqSendHbReq
(
void
*
param
,
void
*
tmrId
)
{
// TODO replace with ref
tmq_t
*
tmq
=
(
tmq_t
*
)
param
;
int64_t
refId
=
*
(
int64_t
*
)
param
;
tmq_t
*
tmq
=
taosAcquireRef
(
tmqMgmt
.
rsetId
,
refId
);
if
(
tmq
==
NULL
)
{
return
;
}
int64_t
consumerId
=
tmq
->
consumerId
;
int32_t
epoch
=
tmq
->
epoch
;
SMqHbReq
*
pReq
=
taosMemoryMalloc
(
sizeof
(
SMqHbReq
));
...
...
@@ -687,7 +735,7 @@ void tmqSendHbReq(void* param, void* tmrId) {
asyncSendMsgToServer
(
tmq
->
pTscObj
->
pAppInfo
->
pTransporter
,
&
epSet
,
&
transporterId
,
sendInfo
);
OVER:
taosTmrReset
(
tmqSendHbReq
,
1000
,
tmq
,
tmqMgmt
.
timer
,
&
tmq
->
hbLiveTimer
);
taosTmrReset
(
tmqSendHbReq
,
1000
,
param
,
tmqMgmt
.
timer
,
&
tmq
->
hbLiveTimer
);
}
int32_t
tmqHandleAllDelayedTask
(
tmq_t
*
tmq
)
{
...
...
@@ -700,10 +748,18 @@ int32_t tmqHandleAllDelayedTask(tmq_t* tmq) {
if
(
*
pTaskType
==
TMQ_DELAYED_TASK__ASK_EP
)
{
tmqAskEp
(
tmq
,
true
);
taosTmrReset
(
tmqAssignAskEpTask
,
1000
,
tmq
,
tmqMgmt
.
timer
,
&
tmq
->
epTimer
);
int64_t
*
pRefId
=
taosMemoryMalloc
(
sizeof
(
int64_t
));
*
pRefId
=
tmq
->
refId
;
taosTmrReset
(
tmqAssignAskEpTask
,
1000
,
pRefId
,
tmqMgmt
.
timer
,
&
tmq
->
epTimer
);
}
else
if
(
*
pTaskType
==
TMQ_DELAYED_TASK__COMMIT
)
{
tmqCommitInner
(
tmq
,
NULL
,
1
,
1
,
tmq
->
commitCb
,
tmq
->
commitCbUserParam
);
taosTmrReset
(
tmqAssignDelayedCommitTask
,
tmq
->
autoCommitInterval
,
tmq
,
tmqMgmt
.
timer
,
&
tmq
->
commitTimer
);
int64_t
*
pRefId
=
taosMemoryMalloc
(
sizeof
(
int64_t
));
*
pRefId
=
tmq
->
refId
;
taosTmrReset
(
tmqAssignDelayedCommitTask
,
tmq
->
autoCommitInterval
,
pRefId
,
tmqMgmt
.
timer
,
&
tmq
->
commitTimer
);
}
else
if
(
*
pTaskType
==
TMQ_DELAYED_TASK__REPORT
)
{
}
else
{
ASSERT
(
0
);
...
...
@@ -738,7 +794,6 @@ void tmqClearUnhandleMsg(tmq_t* tmq) {
int32_t
tmqSubscribeCb
(
void
*
param
,
SDataBuf
*
pMsg
,
int32_t
code
)
{
SMqSubscribeCbParam
*
pParam
=
(
SMqSubscribeCbParam
*
)
param
;
pParam
->
rspErr
=
code
;
/*tmq_t* tmq = pParam->tmq;*/
tsem_post
(
&
pParam
->
rspSem
);
return
0
;
}
...
...
@@ -761,40 +816,27 @@ int32_t tmq_unsubscribe(tmq_t* tmq) {
return
rsp
;
}
#if 0
tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
tmq_t* pTmq = taosMemoryCalloc(sizeof(tmq_t), 1);
if (pTmq == NULL) {
return NULL;
}
pTmq->pTscObj = (STscObj*)conn;
pTmq->status = 0;
pTmq->pollCnt = 0;
pTmq->epoch = 0;
pTmq->epStatus = 0;
pTmq->epSkipCnt = 0;
// set conf
strcpy(pTmq->clientId, conf->clientId);
strcpy(pTmq->groupId, conf->groupId);
pTmq->autoCommit = conf->autoCommit;
pTmq->commit_cb = conf->commit_cb;
pTmq->resetOffsetCfg = conf->resetOffset;
pTmq->consumerId = generateRequestId() & (((uint64_t)-1) >> 1);
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
if (pTmq->clientTopics == NULL) {
taosMemoryFree(pTmq);
return NULL;
}
void
tmqFreeImpl
(
void
*
handle
)
{
tmq_t
*
tmq
=
(
tmq_t
*
)
handle
;
pTmq->mqueue = taosOpenQueue();
pTmq->qall = taosAllocateQall();
// TODO stop timer
if
(
tmq
->
mqueue
)
taosCloseQueue
(
tmq
->
mqueue
);
if
(
tmq
->
delayedTask
)
taosCloseQueue
(
tmq
->
delayedTask
);
if
(
tmq
->
qall
)
taosFreeQall
(
tmq
->
qall
);
tsem_
init(&pTmq->rspSem, 0, 0
);
tsem_
destroy
(
&
tmq
->
rspSem
);
return pTmq;
int32_t
sz
=
taosArrayGetSize
(
tmq
->
clientTopics
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqClientTopic
*
pTopic
=
taosArrayGet
(
tmq
->
clientTopics
,
i
);
if
(
pTopic
->
schema
.
nCols
)
taosMemoryFree
(
pTopic
->
schema
.
pSchema
);
int32_t
vgSz
=
taosArrayGetSize
(
pTopic
->
vgs
);
taosArrayDestroy
(
pTopic
->
vgs
);
}
taosArrayDestroy
(
tmq
->
clientTopics
);
taos_close_internal
(
tmq
->
pTscObj
);
taosMemoryFree
(
tmq
);
}
#endif
tmq_t
*
tmq_consumer_new
(
tmq_conf_t
*
conf
,
char
*
errstr
,
int32_t
errstrLen
)
{
// init timer
...
...
@@ -806,6 +848,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
tmqMgmt
.
rsetId
=
taosOpenRef
(
10000
,
tmqFreeImpl
);
}
tmq_t
*
pTmq
=
taosMemoryCalloc
(
1
,
sizeof
(
tmq_t
));
...
...
@@ -874,8 +917,17 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
goto
FAIL
;
}
pTmq
->
refId
=
taosAddRef
(
tmqMgmt
.
rsetId
,
pTmq
);
if
(
pTmq
->
refId
<
0
)
{
tmqFreeImpl
(
pTmq
);
return
NULL
;
}
int64_t
*
pRefId
=
taosMemoryMalloc
(
sizeof
(
int64_t
));
*
pRefId
=
pTmq
->
refId
;
if
(
pTmq
->
hbBgEnable
)
{
pTmq
->
hbLiveTimer
=
taosTmrStart
(
tmqSendHbReq
,
1000
,
p
Tmq
,
tmqMgmt
.
timer
);
pTmq
->
hbLiveTimer
=
taosTmrStart
(
tmqSendHbReq
,
1000
,
p
RefId
,
tmqMgmt
.
timer
);
}
tscInfo
(
"consumer %"
PRId64
" is setup, consumer group %s"
,
pTmq
->
consumerId
,
pTmq
->
groupId
);
...
...
@@ -933,7 +985,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
SMqSubscribeCbParam
param
=
{
.
rspErr
=
0
,
.
tmq
=
tmq
,
.
refId
=
tmq
->
refId
,
.
epoch
=
tmq
->
epoch
,
};
if
(
tsem_init
(
&
param
.
rspSem
,
0
,
0
)
!=
0
)
goto
FAIL
;
...
...
@@ -975,12 +1028,16 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
// init ep timer
if
(
tmq
->
epTimer
==
NULL
)
{
tmq
->
epTimer
=
taosTmrStart
(
tmqAssignAskEpTask
,
1000
,
tmq
,
tmqMgmt
.
timer
);
int64_t
*
pRefId1
=
taosMemoryMalloc
(
sizeof
(
int64_t
));
*
pRefId1
=
tmq
->
refId
;
tmq
->
epTimer
=
taosTmrStart
(
tmqAssignAskEpTask
,
1000
,
pRefId1
,
tmqMgmt
.
timer
);
}
// init auto commit timer
if
(
tmq
->
autoCommit
&&
tmq
->
commitTimer
==
NULL
)
{
tmq
->
commitTimer
=
taosTmrStart
(
tmqAssignDelayedCommitTask
,
tmq
->
autoCommitInterval
,
tmq
,
tmqMgmt
.
timer
);
int64_t
*
pRefId2
=
taosMemoryMalloc
(
sizeof
(
int64_t
));
*
pRefId2
=
tmq
->
refId
;
tmq
->
commitTimer
=
taosTmrStart
(
tmqAssignDelayedCommitTask
,
tmq
->
autoCommitInterval
,
pRefId2
,
tmqMgmt
.
timer
);
}
code
=
0
;
...
...
@@ -1002,9 +1059,18 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
SMqPollCbParam
*
pParam
=
(
SMqPollCbParam
*
)
param
;
SMqClientVg
*
pVg
=
pParam
->
pVg
;
SMqClientTopic
*
pTopic
=
pParam
->
pTopic
;
tmq_t
*
tmq
=
pParam
->
tmq
;
int32_t
vgId
=
pParam
->
vgId
;
tmq_t
*
tmq
=
taosAcquireRef
(
tmqMgmt
.
rsetId
,
pParam
->
refId
);
if
(
tmq
==
NULL
)
{
tsem_destroy
(
&
pParam
->
rspSem
);
taosMemoryFree
(
pParam
);
taosMemoryFree
(
pMsg
->
pData
);
terrno
=
TSDB_CODE_TMQ_CONSUMER_CLOSED
;
return
-
1
;
}
int32_t
epoch
=
pParam
->
epoch
;
int32_t
vgId
=
pParam
->
vgId
;
taosMemoryFree
(
pParam
);
if
(
code
!=
0
)
{
tscWarn
(
"msg discard from vgId:%d, epoch %d, since %s"
,
vgId
,
epoch
,
terrstr
());
...
...
@@ -1129,7 +1195,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
SMqClientTopic
topic
=
{
0
};
SMqSubTopicEp
*
pTopicEp
=
taosArrayGet
(
pRsp
->
topics
,
i
);
topic
.
schema
=
pTopicEp
->
schema
;
t
opic
.
topicName
=
strdup
(
pTopicEp
->
topic
);
t
strncpy
(
topic
.
topicName
,
pTopicEp
->
topic
,
TSDB_TOPIC_FNAME_LEN
);
tstrncpy
(
topic
.
db
,
pTopicEp
->
db
,
TSDB_DB_FNAME_LEN
);
tscDebug
(
"consumer:%"
PRId64
", update topic: %s"
,
tmq
->
consumerId
,
topic
.
topicName
);
...
...
@@ -1158,7 +1224,16 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
}
taosArrayPush
(
newTopics
,
&
topic
);
}
if
(
tmq
->
clientTopics
)
taosArrayDestroy
(
tmq
->
clientTopics
);
if
(
tmq
->
clientTopics
)
{
int32_t
sz
=
taosArrayGetSize
(
tmq
->
clientTopics
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqClientTopic
*
pTopic
=
taosArrayGet
(
tmq
->
clientTopics
,
i
);
if
(
pTopic
->
schema
.
nCols
)
taosMemoryFree
(
pTopic
->
schema
.
pSchema
);
int32_t
vgSz
=
taosArrayGetSize
(
pTopic
->
vgs
);
taosArrayDestroy
(
pTopic
->
vgs
);
}
taosArrayDestroy
(
tmq
->
clientTopics
);
}
taosHashCleanup
(
pHash
);
tmq
->
clientTopics
=
newTopics
;
...
...
@@ -1173,8 +1248,20 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
int32_t
tmqAskEpCb
(
void
*
param
,
SDataBuf
*
pMsg
,
int32_t
code
)
{
SMqAskEpCbParam
*
pParam
=
(
SMqAskEpCbParam
*
)
param
;
tmq_t
*
tmq
=
pParam
->
tmq
;
int8_t
async
=
pParam
->
async
;
tmq_t
*
tmq
=
taosAcquireRef
(
tmqMgmt
.
rsetId
,
pParam
->
refId
);
if
(
tmq
==
NULL
)
{
if
(
!
async
)
{
tsem_destroy
(
&
pParam
->
rspSem
);
}
else
{
taosMemoryFree
(
pParam
);
}
taosMemoryFree
(
pMsg
->
pData
);
terrno
=
TSDB_CODE_TMQ_CONSUMER_CLOSED
;
return
-
1
;
}
pParam
->
code
=
code
;
if
(
code
!=
0
)
{
tscError
(
"consumer:%"
PRId64
", get topic endpoint error, not ready, wait:%d"
,
tmq
->
consumerId
,
pParam
->
async
);
...
...
@@ -1254,7 +1341,8 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) {
/*atomic_store_8(&tmq->epStatus, 0);*/
return
-
1
;
}
pParam
->
tmq
=
tmq
;
pParam
->
refId
=
tmq
->
refId
;
pParam
->
epoch
=
tmq
->
epoch
;
pParam
->
async
=
async
;
tsem_init
(
&
pParam
->
rspSem
,
0
,
0
);
...
...
@@ -1294,31 +1382,6 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) {
return
code
;
}
#if 0
int32_t tmq_seek(tmq_t* tmq, const tmq_topic_vgroup_t* offset) {
const SMqOffset* pOffset = &offset->offset;
if (strcmp(pOffset->cgroup, tmq->groupId) != 0) {
return TMQ_RESP_ERR__FAIL;
}
int32_t sz = taosArrayGetSize(tmq->clientTopics);
for (int32_t i = 0; i < sz; i++) {
SMqClientTopic* clientTopic = taosArrayGet(tmq->clientTopics, i);
if (strcmp(clientTopic->topicName, pOffset->topicName) == 0) {
int32_t vgSz = taosArrayGetSize(clientTopic->vgs);
for (int32_t j = 0; j < vgSz; j++) {
SMqClientVg* pVg = taosArrayGet(clientTopic->vgs, j);
if (pVg->vgId == pOffset->vgId) {
pVg->currentOffset = pOffset->offset;
tmqClearUnhandleMsg(tmq);
return TMQ_RESP_ERR__SUCCESS;
}
}
}
}
return TMQ_RESP_ERR__FAIL;
}
#endif
SMqPollReq
*
tmqBuildConsumeReqImpl
(
tmq_t
*
tmq
,
int64_t
timeout
,
SMqClientTopic
*
pTopic
,
SMqClientVg
*
pVg
)
{
SMqPollReq
*
pReq
=
taosMemoryCalloc
(
1
,
sizeof
(
SMqPollReq
));
if
(
pReq
==
NULL
)
{
...
...
@@ -1412,11 +1475,12 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) {
tsem_post
(
&
tmq
->
rspSem
);
return
-
1
;
}
pParam
->
tmq
=
tmq
;
pParam
->
refId
=
tmq
->
refId
;
pParam
->
epoch
=
tmq
->
epoch
;
pParam
->
pVg
=
pVg
;
pParam
->
pTopic
=
pTopic
;
pParam
->
vgId
=
pVg
->
vgId
;
pParam
->
epoch
=
tmq
->
epoch
;
SMsgSendInfo
*
sendInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SMsgSendInfo
));
if
(
sendInfo
==
NULL
)
{
...
...
@@ -1556,7 +1620,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
}
#endif
// in no topic status
also need process delayed task
// in no topic status
, delayed task also need to be processed
if
(
atomic_load_8
(
&
tmq
->
status
)
==
TMQ_CONSUMER_STATUS__INIT
)
{
return
NULL
;
}
...
...
@@ -1621,7 +1685,7 @@ int32_t tmq_consumer_close(tmq_t* tmq) {
/*return rsp;*/
return
0
;
}
// TODO: free resources
taosRemoveRef
(
tmqMgmt
.
rsetId
,
tmq
->
refId
);
return
0
;
}
...
...
@@ -1697,1610 +1761,6 @@ const char* tmq_get_table_name(TAOS_RES* res) {
return
NULL
;
}
static
char
*
buildCreateTableJson
(
SSchemaWrapper
*
schemaRow
,
SSchemaWrapper
*
schemaTag
,
char
*
name
,
int64_t
id
,
int8_t
t
)
{
char
*
string
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
return
string
;
}
cJSON
*
type
=
cJSON_CreateString
(
"create"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// char uid[32] = {0};
// sprintf(uid, "%"PRIi64, id);
// cJSON* id_ = cJSON_CreateString(uid);
// cJSON_AddItemToObject(json, "id", id_);
cJSON
*
tableName
=
cJSON_CreateString
(
name
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
t
==
TSDB_NORMAL_TABLE
?
"normal"
:
"super"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
// cJSON* version = cJSON_CreateNumber(1);
// cJSON_AddItemToObject(json, "version", version);
cJSON
*
columns
=
cJSON_CreateArray
();
for
(
int
i
=
0
;
i
<
schemaRow
->
nCols
;
i
++
)
{
cJSON
*
column
=
cJSON_CreateObject
();
SSchema
*
s
=
schemaRow
->
pSchema
+
i
;
cJSON
*
cname
=
cJSON_CreateString
(
s
->
name
);
cJSON_AddItemToObject
(
column
,
"name"
,
cname
);
cJSON
*
ctype
=
cJSON_CreateNumber
(
s
->
type
);
cJSON_AddItemToObject
(
column
,
"type"
,
ctype
);
if
(
s
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
s
->
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
column
,
"length"
,
cbytes
);
}
else
if
(
s
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
s
->
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
column
,
"length"
,
cbytes
);
}
cJSON_AddItemToArray
(
columns
,
column
);
}
cJSON_AddItemToObject
(
json
,
"columns"
,
columns
);
cJSON
*
tags
=
cJSON_CreateArray
();
for
(
int
i
=
0
;
schemaTag
&&
i
<
schemaTag
->
nCols
;
i
++
)
{
cJSON
*
tag
=
cJSON_CreateObject
();
SSchema
*
s
=
schemaTag
->
pSchema
+
i
;
cJSON
*
tname
=
cJSON_CreateString
(
s
->
name
);
cJSON_AddItemToObject
(
tag
,
"name"
,
tname
);
cJSON
*
ttype
=
cJSON_CreateNumber
(
s
->
type
);
cJSON_AddItemToObject
(
tag
,
"type"
,
ttype
);
if
(
s
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
s
->
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
tag
,
"length"
,
cbytes
);
}
else
if
(
s
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
s
->
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
tag
,
"length"
,
cbytes
);
}
cJSON_AddItemToArray
(
tags
,
tag
);
}
cJSON_AddItemToObject
(
json
,
"tags"
,
tags
);
string
=
cJSON_PrintUnformatted
(
json
);
cJSON_Delete
(
json
);
return
string
;
}
static
char
*
buildAlterSTableJson
(
void
*
alterData
,
int32_t
alterDataLen
)
{
SMAlterStbReq
req
=
{
0
};
cJSON
*
json
=
NULL
;
char
*
string
=
NULL
;
if
(
tDeserializeSMAlterStbReq
(
alterData
,
alterDataLen
,
&
req
)
!=
0
)
{
goto
end
;
}
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
end
;
}
cJSON
*
type
=
cJSON_CreateString
(
"alter"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// cJSON* uid = cJSON_CreateNumber(id);
// cJSON_AddItemToObject(json, "uid", uid);
SName
name
=
{
0
};
tNameFromString
(
&
name
,
req
.
name
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
cJSON
*
tableName
=
cJSON_CreateString
(
name
.
tname
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
"super"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
cJSON
*
alterType
=
cJSON_CreateNumber
(
req
.
alterType
);
cJSON_AddItemToObject
(
json
,
"alterType"
,
alterType
);
switch
(
req
.
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_TAG
:
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
{
TAOS_FIELD
*
field
=
taosArrayGet
(
req
.
pFields
,
0
);
cJSON
*
colName
=
cJSON_CreateString
(
field
->
name
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colType
=
cJSON_CreateNumber
(
field
->
type
);
cJSON_AddItemToObject
(
json
,
"colType"
,
colType
);
if
(
field
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
field
->
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
else
if
(
field
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
field
->
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
break
;
}
case
TSDB_ALTER_TABLE_DROP_TAG
:
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
{
TAOS_FIELD
*
field
=
taosArrayGet
(
req
.
pFields
,
0
);
cJSON
*
colName
=
cJSON_CreateString
(
field
->
name
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
{
TAOS_FIELD
*
field
=
taosArrayGet
(
req
.
pFields
,
0
);
cJSON
*
colName
=
cJSON_CreateString
(
field
->
name
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colType
=
cJSON_CreateNumber
(
field
->
type
);
cJSON_AddItemToObject
(
json
,
"colType"
,
colType
);
if
(
field
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
field
->
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
else
if
(
field
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
field
->
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
{
TAOS_FIELD
*
oldField
=
taosArrayGet
(
req
.
pFields
,
0
);
TAOS_FIELD
*
newField
=
taosArrayGet
(
req
.
pFields
,
1
);
cJSON
*
colName
=
cJSON_CreateString
(
oldField
->
name
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colNewName
=
cJSON_CreateString
(
newField
->
name
);
cJSON_AddItemToObject
(
json
,
"colNewName"
,
colNewName
);
break
;
}
default:
break
;
}
string
=
cJSON_PrintUnformatted
(
json
);
end:
cJSON_Delete
(
json
);
tFreeSMAltertbReq
(
&
req
);
return
string
;
}
static
char
*
processCreateStb
(
SMqMetaRsp
*
metaRsp
)
{
SVCreateStbReq
req
=
{
0
};
SDecoder
coder
;
char
*
string
=
NULL
;
// decode and process req
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVCreateStbReq
(
&
coder
,
&
req
)
<
0
)
{
goto
_err
;
}
string
=
buildCreateTableJson
(
&
req
.
schemaRow
,
&
req
.
schemaTag
,
req
.
name
,
req
.
suid
,
TSDB_SUPER_TABLE
);
tDecoderClear
(
&
coder
);
return
string
;
_err:
tDecoderClear
(
&
coder
);
return
string
;
}
static
char
*
processAlterStb
(
SMqMetaRsp
*
metaRsp
)
{
SVCreateStbReq
req
=
{
0
};
SDecoder
coder
;
char
*
string
=
NULL
;
// decode and process req
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVCreateStbReq
(
&
coder
,
&
req
)
<
0
)
{
goto
_err
;
}
string
=
buildAlterSTableJson
(
req
.
alterOriData
,
req
.
alterOriDataLen
);
tDecoderClear
(
&
coder
);
return
string
;
_err:
tDecoderClear
(
&
coder
);
return
string
;
}
static
char
*
buildCreateCTableJson
(
STag
*
pTag
,
char
*
sname
,
char
*
name
,
SArray
*
tagName
,
int64_t
id
,
uint8_t
tagNum
)
{
char
*
string
=
NULL
;
SArray
*
pTagVals
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
return
string
;
}
cJSON
*
type
=
cJSON_CreateString
(
"create"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// char cid[32] = {0};
// sprintf(cid, "%"PRIi64, id);
// cJSON* cid_ = cJSON_CreateString(cid);
// cJSON_AddItemToObject(json, "id", cid_);
cJSON
*
tableName
=
cJSON_CreateString
(
name
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
"child"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
cJSON
*
using
=
cJSON_CreateString
(
sname
);
cJSON_AddItemToObject
(
json
,
"using"
,
using
);
cJSON
*
tagNumJson
=
cJSON_CreateNumber
(
tagNum
);
cJSON_AddItemToObject
(
json
,
"tagNum"
,
tagNumJson
);
// cJSON* version = cJSON_CreateNumber(1);
// cJSON_AddItemToObject(json, "version", version);
cJSON
*
tags
=
cJSON_CreateArray
();
int32_t
code
=
tTagToValArray
(
pTag
,
&
pTagVals
);
if
(
code
)
{
goto
end
;
}
if
(
tTagIsJson
(
pTag
))
{
STag
*
p
=
(
STag
*
)
pTag
;
if
(
p
->
nTag
==
0
)
{
goto
end
;
}
char
*
pJson
=
parseTagDatatoJson
(
pTag
);
cJSON
*
tag
=
cJSON_CreateObject
();
STagVal
*
pTagVal
=
taosArrayGet
(
pTagVals
,
0
);
char
*
ptname
=
taosArrayGet
(
tagName
,
0
);
cJSON
*
tname
=
cJSON_CreateString
(
ptname
);
cJSON_AddItemToObject
(
tag
,
"name"
,
tname
);
// cJSON* cid_ = cJSON_CreateString("");
// cJSON_AddItemToObject(tag, "cid", cid_);
cJSON
*
ttype
=
cJSON_CreateNumber
(
TSDB_DATA_TYPE_JSON
);
cJSON_AddItemToObject
(
tag
,
"type"
,
ttype
);
cJSON
*
tvalue
=
cJSON_CreateString
(
pJson
);
cJSON_AddItemToObject
(
tag
,
"value"
,
tvalue
);
cJSON_AddItemToArray
(
tags
,
tag
);
taosMemoryFree
(
pJson
);
goto
end
;
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pTagVals
);
i
++
)
{
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
i
);
cJSON
*
tag
=
cJSON_CreateObject
();
char
*
ptname
=
taosArrayGet
(
tagName
,
i
);
cJSON
*
tname
=
cJSON_CreateString
(
ptname
);
cJSON_AddItemToObject
(
tag
,
"name"
,
tname
);
// cJSON* cid = cJSON_CreateNumber(pTagVal->cid);
// cJSON_AddItemToObject(tag, "cid", cid);
cJSON
*
ttype
=
cJSON_CreateNumber
(
pTagVal
->
type
);
cJSON_AddItemToObject
(
tag
,
"type"
,
ttype
);
cJSON
*
tvalue
=
NULL
;
if
(
IS_VAR_DATA_TYPE
(
pTagVal
->
type
))
{
char
*
buf
=
taosMemoryCalloc
(
pTagVal
->
nData
+
3
,
1
);
if
(
!
buf
)
goto
end
;
dataConverToStr
(
buf
,
pTagVal
->
type
,
pTagVal
->
pData
,
pTagVal
->
nData
,
NULL
);
tvalue
=
cJSON_CreateString
(
buf
);
taosMemoryFree
(
buf
);
}
else
{
double
val
=
0
;
GET_TYPED_DATA
(
val
,
double
,
pTagVal
->
type
,
&
pTagVal
->
i64
);
tvalue
=
cJSON_CreateNumber
(
val
);
}
cJSON_AddItemToObject
(
tag
,
"value"
,
tvalue
);
cJSON_AddItemToArray
(
tags
,
tag
);
}
end:
cJSON_AddItemToObject
(
json
,
"tags"
,
tags
);
string
=
cJSON_PrintUnformatted
(
json
);
cJSON_Delete
(
json
);
taosArrayDestroy
(
pTagVals
);
return
string
;
}
static
char
*
processCreateTable
(
SMqMetaRsp
*
metaRsp
)
{
SDecoder
decoder
=
{
0
};
SVCreateTbBatchReq
req
=
{
0
};
SVCreateTbReq
*
pCreateReq
;
char
*
string
=
NULL
;
// decode
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
decoder
,
data
,
len
);
if
(
tDecodeSVCreateTbBatchReq
(
&
decoder
,
&
req
)
<
0
)
{
goto
_exit
;
}
// loop to create table
for
(
int32_t
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
pCreateReq
=
req
.
pReqs
+
iReq
;
if
(
pCreateReq
->
type
==
TSDB_CHILD_TABLE
)
{
string
=
buildCreateCTableJson
((
STag
*
)
pCreateReq
->
ctb
.
pTag
,
pCreateReq
->
ctb
.
name
,
pCreateReq
->
name
,
pCreateReq
->
ctb
.
tagName
,
pCreateReq
->
uid
,
pCreateReq
->
ctb
.
tagNum
);
}
else
if
(
pCreateReq
->
type
==
TSDB_NORMAL_TABLE
)
{
string
=
buildCreateTableJson
(
&
pCreateReq
->
ntb
.
schemaRow
,
NULL
,
pCreateReq
->
name
,
pCreateReq
->
uid
,
TSDB_NORMAL_TABLE
);
}
}
tDecoderClear
(
&
decoder
);
_exit:
tDecoderClear
(
&
decoder
);
return
string
;
}
static
char
*
processAlterTable
(
SMqMetaRsp
*
metaRsp
)
{
SDecoder
decoder
=
{
0
};
SVAlterTbReq
vAlterTbReq
=
{
0
};
char
*
string
=
NULL
;
// decode
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
decoder
,
data
,
len
);
if
(
tDecodeSVAlterTbReq
(
&
decoder
,
&
vAlterTbReq
)
<
0
)
{
goto
_exit
;
}
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
_exit
;
}
cJSON
*
type
=
cJSON_CreateString
(
"alter"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// cJSON* uid = cJSON_CreateNumber(id);
// cJSON_AddItemToObject(json, "uid", uid);
cJSON
*
tableName
=
cJSON_CreateString
(
vAlterTbReq
.
tbName
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
vAlterTbReq
.
action
==
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
?
"child"
:
"normal"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
cJSON
*
alterType
=
cJSON_CreateNumber
(
vAlterTbReq
.
action
);
cJSON_AddItemToObject
(
json
,
"alterType"
,
alterType
);
switch
(
vAlterTbReq
.
action
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
{
cJSON
*
colName
=
cJSON_CreateString
(
vAlterTbReq
.
colName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colType
=
cJSON_CreateNumber
(
vAlterTbReq
.
type
);
cJSON_AddItemToObject
(
json
,
"colType"
,
colType
);
if
(
vAlterTbReq
.
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
vAlterTbReq
.
bytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
else
if
(
vAlterTbReq
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
vAlterTbReq
.
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
break
;
}
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
{
cJSON
*
colName
=
cJSON_CreateString
(
vAlterTbReq
.
colName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
{
cJSON
*
colName
=
cJSON_CreateString
(
vAlterTbReq
.
colName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colType
=
cJSON_CreateNumber
(
vAlterTbReq
.
colModType
);
cJSON_AddItemToObject
(
json
,
"colType"
,
colType
);
if
(
vAlterTbReq
.
colModType
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
length
=
vAlterTbReq
.
colModBytes
-
VARSTR_HEADER_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
else
if
(
vAlterTbReq
.
colModType
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
length
=
(
vAlterTbReq
.
colModBytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
cJSON
*
cbytes
=
cJSON_CreateNumber
(
length
);
cJSON_AddItemToObject
(
json
,
"colLength"
,
cbytes
);
}
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
{
cJSON
*
colName
=
cJSON_CreateString
(
vAlterTbReq
.
colName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
colName
);
cJSON
*
colNewName
=
cJSON_CreateString
(
vAlterTbReq
.
colNewName
);
cJSON_AddItemToObject
(
json
,
"colNewName"
,
colNewName
);
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
:
{
cJSON
*
tagName
=
cJSON_CreateString
(
vAlterTbReq
.
tagName
);
cJSON_AddItemToObject
(
json
,
"colName"
,
tagName
);
bool
isNull
=
vAlterTbReq
.
isNull
;
if
(
vAlterTbReq
.
tagType
==
TSDB_DATA_TYPE_JSON
)
{
STag
*
jsonTag
=
(
STag
*
)
vAlterTbReq
.
pTagVal
;
if
(
jsonTag
->
nTag
==
0
)
isNull
=
true
;
}
if
(
!
isNull
)
{
char
*
buf
=
NULL
;
if
(
vAlterTbReq
.
tagType
==
TSDB_DATA_TYPE_JSON
)
{
ASSERT
(
tTagIsJson
(
vAlterTbReq
.
pTagVal
)
==
true
);
buf
=
parseTagDatatoJson
(
vAlterTbReq
.
pTagVal
);
}
else
{
buf
=
taosMemoryCalloc
(
vAlterTbReq
.
nTagVal
+
1
,
1
);
dataConverToStr
(
buf
,
vAlterTbReq
.
tagType
,
vAlterTbReq
.
pTagVal
,
vAlterTbReq
.
nTagVal
,
NULL
);
}
cJSON
*
colValue
=
cJSON_CreateString
(
buf
);
cJSON_AddItemToObject
(
json
,
"colValue"
,
colValue
);
taosMemoryFree
(
buf
);
}
cJSON
*
isNullCJson
=
cJSON_CreateBool
(
isNull
);
cJSON_AddItemToObject
(
json
,
"colValueNull"
,
isNullCJson
);
break
;
}
default:
break
;
}
string
=
cJSON_PrintUnformatted
(
json
);
_exit:
tDecoderClear
(
&
decoder
);
return
string
;
}
static
char
*
processDropSTable
(
SMqMetaRsp
*
metaRsp
)
{
SDecoder
decoder
=
{
0
};
SVDropStbReq
req
=
{
0
};
char
*
string
=
NULL
;
// decode
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
decoder
,
data
,
len
);
if
(
tDecodeSVDropStbReq
(
&
decoder
,
&
req
)
<
0
)
{
goto
_exit
;
}
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
_exit
;
}
cJSON
*
type
=
cJSON_CreateString
(
"drop"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
cJSON
*
tableName
=
cJSON_CreateString
(
req
.
name
);
cJSON_AddItemToObject
(
json
,
"tableName"
,
tableName
);
cJSON
*
tableType
=
cJSON_CreateString
(
"super"
);
cJSON_AddItemToObject
(
json
,
"tableType"
,
tableType
);
string
=
cJSON_PrintUnformatted
(
json
);
_exit:
tDecoderClear
(
&
decoder
);
return
string
;
}
static
char
*
processDropTable
(
SMqMetaRsp
*
metaRsp
)
{
SDecoder
decoder
=
{
0
};
SVDropTbBatchReq
req
=
{
0
};
char
*
string
=
NULL
;
// decode
void
*
data
=
POINTER_SHIFT
(
metaRsp
->
metaRsp
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaRsp
->
metaRspLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
decoder
,
data
,
len
);
if
(
tDecodeSVDropTbBatchReq
(
&
decoder
,
&
req
)
<
0
)
{
goto
_exit
;
}
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
_exit
;
}
cJSON
*
type
=
cJSON_CreateString
(
"drop"
);
cJSON_AddItemToObject
(
json
,
"type"
,
type
);
// cJSON* uid = cJSON_CreateNumber(id);
// cJSON_AddItemToObject(json, "uid", uid);
// cJSON* tableType = cJSON_CreateString("normal");
// cJSON_AddItemToObject(json, "tableType", tableType);
cJSON
*
tableNameList
=
cJSON_CreateArray
();
for
(
int32_t
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
SVDropTbReq
*
pDropTbReq
=
req
.
pReqs
+
iReq
;
cJSON
*
tableName
=
cJSON_CreateString
(
pDropTbReq
->
name
);
cJSON_AddItemToArray
(
tableNameList
,
tableName
);
}
cJSON_AddItemToObject
(
json
,
"tableNameList"
,
tableNameList
);
string
=
cJSON_PrintUnformatted
(
json
);
_exit:
tDecoderClear
(
&
decoder
);
return
string
;
}
static
int32_t
taosCreateStb
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVCreateStbReq
req
=
{
0
};
SDecoder
coder
;
SMCreateStbReq
pReq
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVCreateStbReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
// build create stable
pReq
.
pColumns
=
taosArrayInit
(
req
.
schemaRow
.
nCols
,
sizeof
(
SField
));
for
(
int32_t
i
=
0
;
i
<
req
.
schemaRow
.
nCols
;
i
++
)
{
SSchema
*
pSchema
=
req
.
schemaRow
.
pSchema
+
i
;
SField
field
=
{.
type
=
pSchema
->
type
,
.
bytes
=
pSchema
->
bytes
};
strcpy
(
field
.
name
,
pSchema
->
name
);
taosArrayPush
(
pReq
.
pColumns
,
&
field
);
}
pReq
.
pTags
=
taosArrayInit
(
req
.
schemaTag
.
nCols
,
sizeof
(
SField
));
for
(
int32_t
i
=
0
;
i
<
req
.
schemaTag
.
nCols
;
i
++
)
{
SSchema
*
pSchema
=
req
.
schemaTag
.
pSchema
+
i
;
SField
field
=
{.
type
=
pSchema
->
type
,
.
bytes
=
pSchema
->
bytes
};
strcpy
(
field
.
name
,
pSchema
->
name
);
taosArrayPush
(
pReq
.
pTags
,
&
field
);
}
pReq
.
colVer
=
req
.
schemaRow
.
version
;
pReq
.
tagVer
=
req
.
schemaTag
.
version
;
pReq
.
numOfColumns
=
req
.
schemaRow
.
nCols
;
pReq
.
numOfTags
=
req
.
schemaTag
.
nCols
;
pReq
.
commentLen
=
-
1
;
pReq
.
suid
=
req
.
suid
;
pReq
.
source
=
TD_REQ_FROM_TAOX
;
pReq
.
igExists
=
true
;
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SName
tableName
;
tNameExtractFullName
(
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
req
.
name
,
&
tableName
),
pReq
.
name
);
SCmdMsgInfo
pCmdMsg
=
{
0
};
pCmdMsg
.
epSet
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
pCmdMsg
.
msgType
=
TDMT_MND_CREATE_STB
;
pCmdMsg
.
msgLen
=
tSerializeSMCreateStbReq
(
NULL
,
0
,
&
pReq
);
pCmdMsg
.
pMsg
=
taosMemoryMalloc
(
pCmdMsg
.
msgLen
);
if
(
NULL
==
pCmdMsg
.
pMsg
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
tSerializeSMCreateStbReq
(
pCmdMsg
.
pMsg
,
pCmdMsg
.
msgLen
,
&
pReq
);
SQuery
pQuery
=
{
0
};
pQuery
.
execMode
=
QUERY_EXEC_MODE_RPC
;
pQuery
.
pCmdMsg
=
&
pCmdMsg
;
pQuery
.
msgType
=
pQuery
.
pCmdMsg
->
msgType
;
pQuery
.
stableQuery
=
true
;
launchQueryImpl
(
pRequest
,
&
pQuery
,
true
,
NULL
);
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
SCatalog
*
pCatalog
=
NULL
;
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
catalogRemoveTableMeta
(
pCatalog
,
&
tableName
);
}
code
=
pRequest
->
code
;
taosMemoryFree
(
pCmdMsg
.
pMsg
);
end:
destroyRequest
(
pRequest
);
tFreeSMCreateStbReq
(
&
pReq
);
tDecoderClear
(
&
coder
);
return
code
;
}
static
int32_t
taosDropStb
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVDropStbReq
req
=
{
0
};
SDecoder
coder
;
SMDropStbReq
pReq
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVDropStbReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
// build drop stable
pReq
.
igNotExists
=
true
;
pReq
.
source
=
TD_REQ_FROM_TAOX
;
pReq
.
suid
=
req
.
suid
;
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SName
tableName
=
{
0
};
tNameExtractFullName
(
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
req
.
name
,
&
tableName
),
pReq
.
name
);
SCmdMsgInfo
pCmdMsg
=
{
0
};
pCmdMsg
.
epSet
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
pCmdMsg
.
msgType
=
TDMT_MND_DROP_STB
;
pCmdMsg
.
msgLen
=
tSerializeSMDropStbReq
(
NULL
,
0
,
&
pReq
);
pCmdMsg
.
pMsg
=
taosMemoryMalloc
(
pCmdMsg
.
msgLen
);
if
(
NULL
==
pCmdMsg
.
pMsg
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
tSerializeSMDropStbReq
(
pCmdMsg
.
pMsg
,
pCmdMsg
.
msgLen
,
&
pReq
);
SQuery
pQuery
=
{
0
};
pQuery
.
execMode
=
QUERY_EXEC_MODE_RPC
;
pQuery
.
pCmdMsg
=
&
pCmdMsg
;
pQuery
.
msgType
=
pQuery
.
pCmdMsg
->
msgType
;
pQuery
.
stableQuery
=
true
;
launchQueryImpl
(
pRequest
,
&
pQuery
,
true
,
NULL
);
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
SCatalog
*
pCatalog
=
NULL
;
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
catalogRemoveTableMeta
(
pCatalog
,
&
tableName
);
}
code
=
pRequest
->
code
;
taosMemoryFree
(
pCmdMsg
.
pMsg
);
end:
destroyRequest
(
pRequest
);
tDecoderClear
(
&
coder
);
return
code
;
}
typedef
struct
SVgroupCreateTableBatch
{
SVCreateTbBatchReq
req
;
SVgroupInfo
info
;
char
dbName
[
TSDB_DB_NAME_LEN
];
}
SVgroupCreateTableBatch
;
static
void
destroyCreateTbReqBatch
(
void
*
data
)
{
SVgroupCreateTableBatch
*
pTbBatch
=
(
SVgroupCreateTableBatch
*
)
data
;
taosArrayDestroy
(
pTbBatch
->
req
.
pArray
);
}
static
int32_t
taosCreateTable
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVCreateTbBatchReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SHashObj
*
pVgroupHashmap
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVCreateTbBatchReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SVCreateTbReq
*
pCreateReq
=
NULL
;
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
pVgroupHashmap
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
pVgroupHashmap
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
taosHashSetFreeFp
(
pVgroupHashmap
,
destroyCreateTbReqBatch
);
SRequestConnInfo
conn
=
{.
pTrans
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
,
.
mgmtEps
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
)};
pRequest
->
tableList
=
taosArrayInit
(
req
.
nReqs
,
sizeof
(
SName
));
// loop to create table
for
(
int32_t
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
pCreateReq
=
req
.
pReqs
+
iReq
;
SVgroupInfo
pInfo
=
{
0
};
SName
pName
=
{
0
};
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
pCreateReq
->
name
,
&
pName
);
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
taosArrayPush
(
pRequest
->
tableList
,
&
pName
);
SVgroupCreateTableBatch
*
pTableBatch
=
taosHashGet
(
pVgroupHashmap
,
&
pInfo
.
vgId
,
sizeof
(
pInfo
.
vgId
));
if
(
pTableBatch
==
NULL
)
{
SVgroupCreateTableBatch
tBatch
=
{
0
};
tBatch
.
info
=
pInfo
;
strcpy
(
tBatch
.
dbName
,
pRequest
->
pDb
);
tBatch
.
req
.
pArray
=
taosArrayInit
(
4
,
sizeof
(
struct
SVCreateTbReq
));
taosArrayPush
(
tBatch
.
req
.
pArray
,
pCreateReq
);
taosHashPut
(
pVgroupHashmap
,
&
pInfo
.
vgId
,
sizeof
(
pInfo
.
vgId
),
&
tBatch
,
sizeof
(
tBatch
));
}
else
{
// add to the correct vgroup
taosArrayPush
(
pTableBatch
->
req
.
pArray
,
pCreateReq
);
}
}
SArray
*
pBufArray
=
serializeVgroupsCreateTableBatch
(
pVgroupHashmap
);
if
(
NULL
==
pBufArray
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
msgType
=
TDMT_VND_CREATE_TABLE
;
pQuery
->
stableQuery
=
false
;
pQuery
->
pRoot
=
nodesMakeNode
(
QUERY_NODE_CREATE_TABLE_STMT
);
code
=
rewriteToVnodeModifyOpStmt
(
pQuery
,
pBufArray
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
removeMeta
(
pTscObj
,
pRequest
->
tableList
);
}
code
=
pRequest
->
code
;
end:
taosHashCleanup
(
pVgroupHashmap
);
destroyRequest
(
pRequest
);
tDecoderClear
(
&
coder
);
qDestroyQuery
(
pQuery
);
return
code
;
}
typedef
struct
SVgroupDropTableBatch
{
SVDropTbBatchReq
req
;
SVgroupInfo
info
;
char
dbName
[
TSDB_DB_NAME_LEN
];
}
SVgroupDropTableBatch
;
static
void
destroyDropTbReqBatch
(
void
*
data
)
{
SVgroupDropTableBatch
*
pTbBatch
=
(
SVgroupDropTableBatch
*
)
data
;
taosArrayDestroy
(
pTbBatch
->
req
.
pArray
);
}
static
int32_t
taosDropTable
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVDropTbBatchReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SHashObj
*
pVgroupHashmap
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVDropTbBatchReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SVDropTbReq
*
pDropReq
=
NULL
;
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
pVgroupHashmap
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
pVgroupHashmap
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
taosHashSetFreeFp
(
pVgroupHashmap
,
destroyDropTbReqBatch
);
SRequestConnInfo
conn
=
{.
pTrans
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
,
.
mgmtEps
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
)};
pRequest
->
tableList
=
taosArrayInit
(
req
.
nReqs
,
sizeof
(
SName
));
// loop to create table
for
(
int32_t
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
pDropReq
=
req
.
pReqs
+
iReq
;
pDropReq
->
igNotExists
=
true
;
SVgroupInfo
pInfo
=
{
0
};
SName
pName
=
{
0
};
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
pDropReq
->
name
,
&
pName
);
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
taosArrayPush
(
pRequest
->
tableList
,
&
pName
);
SVgroupDropTableBatch
*
pTableBatch
=
taosHashGet
(
pVgroupHashmap
,
&
pInfo
.
vgId
,
sizeof
(
pInfo
.
vgId
));
if
(
pTableBatch
==
NULL
)
{
SVgroupDropTableBatch
tBatch
=
{
0
};
tBatch
.
info
=
pInfo
;
tBatch
.
req
.
pArray
=
taosArrayInit
(
TARRAY_MIN_SIZE
,
sizeof
(
SVDropTbReq
));
taosArrayPush
(
tBatch
.
req
.
pArray
,
pDropReq
);
taosHashPut
(
pVgroupHashmap
,
&
pInfo
.
vgId
,
sizeof
(
pInfo
.
vgId
),
&
tBatch
,
sizeof
(
tBatch
));
}
else
{
// add to the correct vgroup
taosArrayPush
(
pTableBatch
->
req
.
pArray
,
pDropReq
);
}
}
SArray
*
pBufArray
=
serializeVgroupsDropTableBatch
(
pVgroupHashmap
);
if
(
NULL
==
pBufArray
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
msgType
=
TDMT_VND_DROP_TABLE
;
pQuery
->
stableQuery
=
false
;
pQuery
->
pRoot
=
nodesMakeNode
(
QUERY_NODE_DROP_TABLE_STMT
);
code
=
rewriteToVnodeModifyOpStmt
(
pQuery
,
pBufArray
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
removeMeta
(
pTscObj
,
pRequest
->
tableList
);
}
code
=
pRequest
->
code
;
end:
taosHashCleanup
(
pVgroupHashmap
);
destroyRequest
(
pRequest
);
tDecoderClear
(
&
coder
);
qDestroyQuery
(
pQuery
);
return
code
;
}
// delete from db.tabl where .. -> delete from tabl where ..
// delete from db .tabl where .. -> delete from tabl where ..
// static void getTbName(char *sql){
// char *ch = sql;
//
// bool inBackQuote = false;
// int8_t dotIndex = 0;
// while(*ch != '\0'){
// if(!inBackQuote && *ch == '`'){
// inBackQuote = true;
// ch++;
// continue;
// }
//
// if(inBackQuote && *ch == '`'){
// inBackQuote = false;
// ch++;
//
// continue;
// }
//
// if(!inBackQuote && *ch == '.'){
// dotIndex ++;
// if(dotIndex == 2){
// memmove(sql, ch + 1, strlen(ch + 1) + 1);
// break;
// }
// }
// ch++;
// }
//}
static
int32_t
taosDeleteData
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SDeleteRes
req
=
{
0
};
SDecoder
coder
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeDeleteRes
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
// getTbName(req.tableFName);
char
sql
[
256
]
=
{
0
};
sprintf
(
sql
,
"delete from `%s` where `%s` >= %"
PRId64
" and `%s` <= %"
PRId64
,
req
.
tableFName
,
req
.
tsColName
,
req
.
skey
,
req
.
tsColName
,
req
.
ekey
);
printf
(
"delete sql:%s
\n
"
,
sql
);
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
SRequestObj
*
pRequest
=
(
SRequestObj
*
)
res
;
code
=
pRequest
->
code
;
if
(
code
==
TSDB_CODE_PAR_TABLE_NOT_EXIST
)
{
code
=
TSDB_CODE_SUCCESS
;
}
taos_free_result
(
res
);
end:
tDecoderClear
(
&
coder
);
return
code
;
}
static
int32_t
taosAlterTable
(
TAOS
*
taos
,
void
*
meta
,
int32_t
metaLen
)
{
SVAlterTbReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SArray
*
pArray
=
NULL
;
SVgDataBlocks
*
pVgData
=
NULL
;
code
=
buildRequest
(
*
(
int64_t
*
)
taos
,
""
,
0
,
NULL
,
false
,
&
pRequest
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
// decode and process req
void
*
data
=
POINTER_SHIFT
(
meta
,
sizeof
(
SMsgHead
));
int32_t
len
=
metaLen
-
sizeof
(
SMsgHead
);
tDecoderInit
(
&
coder
,
data
,
len
);
if
(
tDecodeSVAlterTbReq
(
&
coder
,
&
req
)
<
0
)
{
code
=
TSDB_CODE_INVALID_PARA
;
goto
end
;
}
// do not deal TSDB_ALTER_TABLE_UPDATE_OPTIONS
if
(
req
.
action
==
TSDB_ALTER_TABLE_UPDATE_OPTIONS
)
{
goto
end
;
}
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
SRequestConnInfo
conn
=
{.
pTrans
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
,
.
mgmtEps
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
)};
SVgroupInfo
pInfo
=
{
0
};
SName
pName
=
{
0
};
toName
(
pTscObj
->
acctId
,
pRequest
->
pDb
,
req
.
tbName
,
&
pName
);
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
pArray
=
taosArrayInit
(
1
,
sizeof
(
void
*
));
if
(
NULL
==
pArray
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pVgData
=
taosMemoryCalloc
(
1
,
sizeof
(
SVgDataBlocks
));
if
(
NULL
==
pVgData
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pVgData
->
vg
=
pInfo
;
pVgData
->
pData
=
taosMemoryMalloc
(
metaLen
);
if
(
NULL
==
pVgData
->
pData
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
memcpy
(
pVgData
->
pData
,
meta
,
metaLen
);
((
SMsgHead
*
)
pVgData
->
pData
)
->
vgId
=
htonl
(
pInfo
.
vgId
);
pVgData
->
size
=
metaLen
;
pVgData
->
numOfTables
=
1
;
taosArrayPush
(
pArray
,
&
pVgData
);
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
msgType
=
TDMT_VND_ALTER_TABLE
;
pQuery
->
stableQuery
=
false
;
pQuery
->
pRoot
=
nodesMakeNode
(
QUERY_NODE_ALTER_TABLE_STMT
);
code
=
rewriteToVnodeModifyOpStmt
(
pQuery
,
pArray
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
pVgData
=
NULL
;
pArray
=
NULL
;
code
=
pRequest
->
code
;
if
(
code
==
TSDB_CODE_VND_TABLE_NOT_EXIST
)
{
code
=
TSDB_CODE_SUCCESS
;
}
if
(
pRequest
->
code
==
TSDB_CODE_SUCCESS
)
{
SExecResult
*
pRes
=
&
pRequest
->
body
.
resInfo
.
execRes
;
if
(
pRes
->
res
!=
NULL
)
{
code
=
handleAlterTbExecRes
(
pRes
->
res
,
pCatalog
);
}
}
end:
taosArrayDestroy
(
pArray
);
if
(
pVgData
)
taosMemoryFreeClear
(
pVgData
->
pData
);
taosMemoryFreeClear
(
pVgData
);
destroyRequest
(
pRequest
);
tDecoderClear
(
&
coder
);
qDestroyQuery
(
pQuery
);
return
code
;
}
typedef
struct
{
SVgroupInfo
vg
;
void
*
data
;
}
VgData
;
static
void
destroyVgHash
(
void
*
data
)
{
VgData
*
vgData
=
(
VgData
*
)
data
;
taosMemoryFreeClear
(
vgData
->
data
);
}
int
taos_write_raw_block
(
TAOS
*
taos
,
int
rows
,
char
*
pData
,
const
char
*
tbname
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
STableMeta
*
pTableMeta
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SRequestObj
*
pRequest
=
(
SRequestObj
*
)
createRequest
(
*
(
int64_t
*
)
taos
,
TSDB_SQL_INSERT
);
if
(
!
pRequest
)
{
uError
(
"WriteRaw:createRequest error request is null"
);
code
=
terrno
;
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
uError
(
"WriteRaw:not use db"
);
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
SName
pName
=
{
TSDB_TABLE_NAME_T
,
pRequest
->
pTscObj
->
acctId
,
{
0
},
{
0
}};
strcpy
(
pName
.
dbname
,
pRequest
->
pDb
);
strcpy
(
pName
.
tname
,
tbname
);
struct
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pRequest
->
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw: get gatlog error"
);
goto
end
;
}
SRequestConnInfo
conn
=
{
0
};
conn
.
pTrans
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
;
conn
.
requestId
=
pRequest
->
requestId
;
conn
.
requestObjRefId
=
pRequest
->
self
;
conn
.
mgmtEps
=
getEpSet_s
(
&
pRequest
->
pTscObj
->
pAppInfo
->
mgmtEp
);
SVgroupInfo
vgData
=
{
0
};
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
vgData
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw:catalogGetTableHashVgroup failed. table name: %s"
,
tbname
);
goto
end
;
}
code
=
catalogGetTableMeta
(
pCatalog
,
&
conn
,
&
pName
,
&
pTableMeta
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw:catalogGetTableMeta failed. table name: %s"
,
tbname
);
goto
end
;
}
uint64_t
suid
=
(
TSDB_NORMAL_TABLE
==
pTableMeta
->
tableType
?
0
:
pTableMeta
->
suid
);
uint64_t
uid
=
pTableMeta
->
uid
;
int32_t
numOfCols
=
pTableMeta
->
tableInfo
.
numOfColumns
;
uint16_t
fLen
=
0
;
int32_t
rowSize
=
0
;
int16_t
nVar
=
0
;
for
(
int
i
=
0
;
i
<
numOfCols
;
i
++
)
{
SSchema
*
schema
=
pTableMeta
->
schema
+
i
;
fLen
+=
TYPE_BYTES
[
schema
->
type
];
rowSize
+=
schema
->
bytes
;
if
(
IS_VAR_DATA_TYPE
(
schema
->
type
))
{
nVar
++
;
}
}
int32_t
extendedRowSize
=
rowSize
+
TD_ROW_HEAD_LEN
-
sizeof
(
TSKEY
)
+
nVar
*
sizeof
(
VarDataOffsetT
)
+
(
int32_t
)
TD_BITMAP_BYTES
(
numOfCols
-
1
);
int32_t
schemaLen
=
0
;
int32_t
submitLen
=
sizeof
(
SSubmitBlk
)
+
schemaLen
+
rows
*
extendedRowSize
;
int32_t
totalLen
=
sizeof
(
SSubmitReq
)
+
submitLen
;
SSubmitReq
*
subReq
=
taosMemoryCalloc
(
1
,
totalLen
);
SSubmitBlk
*
blk
=
POINTER_SHIFT
(
subReq
,
sizeof
(
SSubmitReq
));
void
*
blkSchema
=
POINTER_SHIFT
(
blk
,
sizeof
(
SSubmitBlk
));
STSRow
*
rowData
=
POINTER_SHIFT
(
blkSchema
,
schemaLen
);
SRowBuilder
rb
=
{
0
};
tdSRowInit
(
&
rb
,
pTableMeta
->
sversion
);
tdSRowSetTpInfo
(
&
rb
,
numOfCols
,
fLen
);
int32_t
dataLen
=
0
;
char
*
pStart
=
pData
+
getVersion1BlockMetaSize
(
pData
,
numOfCols
);
int32_t
*
colLength
=
(
int32_t
*
)
pStart
;
pStart
+=
sizeof
(
int32_t
)
*
numOfCols
;
SResultColumn
*
pCol
=
taosMemoryCalloc
(
numOfCols
,
sizeof
(
SResultColumn
));
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
if
(
IS_VAR_DATA_TYPE
(
pTableMeta
->
schema
[
i
].
type
))
{
pCol
[
i
].
offset
=
(
int32_t
*
)
pStart
;
pStart
+=
rows
*
sizeof
(
int32_t
);
}
else
{
pCol
[
i
].
nullbitmap
=
pStart
;
pStart
+=
BitmapLen
(
rows
);
}
pCol
[
i
].
pData
=
pStart
;
pStart
+=
colLength
[
i
];
}
for
(
int32_t
j
=
0
;
j
<
rows
;
j
++
)
{
tdSRowResetBuf
(
&
rb
,
rowData
);
int32_t
offset
=
0
;
for
(
int32_t
k
=
0
;
k
<
numOfCols
;
k
++
)
{
const
SSchema
*
pColumn
=
&
pTableMeta
->
schema
[
k
];
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
type
))
{
if
(
pCol
[
k
].
offset
[
j
]
!=
-
1
)
{
char
*
data
=
pCol
[
k
].
pData
+
pCol
[
k
].
offset
[
j
];
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NORM
,
data
,
true
,
offset
,
k
);
}
else
{
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NULL
,
NULL
,
false
,
offset
,
k
);
}
}
else
{
if
(
!
colDataIsNull_f
(
pCol
[
k
].
nullbitmap
,
j
))
{
char
*
data
=
pCol
[
k
].
pData
+
pColumn
->
bytes
*
j
;
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NORM
,
data
,
true
,
offset
,
k
);
}
else
{
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NULL
,
NULL
,
false
,
offset
,
k
);
}
}
offset
+=
TYPE_BYTES
[
pColumn
->
type
];
}
tdSRowEnd
(
&
rb
);
int32_t
rowLen
=
TD_ROW_LEN
(
rowData
);
rowData
=
POINTER_SHIFT
(
rowData
,
rowLen
);
dataLen
+=
rowLen
;
}
taosMemoryFree
(
pCol
);
blk
->
uid
=
htobe64
(
uid
);
blk
->
suid
=
htobe64
(
suid
);
blk
->
sversion
=
htonl
(
pTableMeta
->
sversion
);
blk
->
schemaLen
=
htonl
(
schemaLen
);
blk
->
numOfRows
=
htonl
(
rows
);
blk
->
dataLen
=
htonl
(
dataLen
);
subReq
->
length
=
sizeof
(
SSubmitReq
)
+
sizeof
(
SSubmitBlk
)
+
schemaLen
+
dataLen
;
subReq
->
numOfBlocks
=
1
;
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
if
(
NULL
==
pQuery
)
{
uError
(
"create SQuery error"
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
haveResultSet
=
false
;
pQuery
->
msgType
=
TDMT_VND_SUBMIT
;
pQuery
->
pRoot
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VNODE_MODIF_STMT
);
if
(
NULL
==
pQuery
->
pRoot
)
{
uError
(
"create pQuery->pRoot error"
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
SVnodeModifOpStmt
*
nodeStmt
=
(
SVnodeModifOpStmt
*
)(
pQuery
->
pRoot
);
nodeStmt
->
payloadType
=
PAYLOAD_TYPE_KV
;
nodeStmt
->
pDataBlocks
=
taosArrayInit
(
1
,
POINTER_BYTES
);
SVgDataBlocks
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
SVgDataBlocks
));
if
(
NULL
==
dst
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
dst
->
vg
=
vgData
;
dst
->
numOfTables
=
subReq
->
numOfBlocks
;
dst
->
size
=
subReq
->
length
;
dst
->
pData
=
(
char
*
)
subReq
;
subReq
->
header
.
vgId
=
htonl
(
dst
->
vg
.
vgId
);
subReq
->
version
=
htonl
(
1
);
subReq
->
header
.
contLen
=
htonl
(
subReq
->
length
);
subReq
->
length
=
htonl
(
subReq
->
length
);
subReq
->
numOfBlocks
=
htonl
(
subReq
->
numOfBlocks
);
subReq
=
NULL
;
// no need free
taosArrayPush
(
nodeStmt
->
pDataBlocks
,
&
dst
);
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
code
=
pRequest
->
code
;
end:
taosMemoryFreeClear
(
pTableMeta
);
qDestroyQuery
(
pQuery
);
return
code
;
}
static
int32_t
tmqWriteRaw
(
TAOS
*
taos
,
void
*
data
,
int32_t
dataLen
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SHashObj
*
pVgHash
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SMqRspObj
rspObj
=
{
0
};
SDecoder
decoder
=
{
0
};
terrno
=
TSDB_CODE_SUCCESS
;
SRequestObj
*
pRequest
=
(
SRequestObj
*
)
createRequest
(
*
(
int64_t
*
)
taos
,
TSDB_SQL_INSERT
);
if
(
!
pRequest
)
{
uError
(
"WriteRaw:createRequest error request is null"
);
return
terrno
;
}
rspObj
.
resIter
=
-
1
;
rspObj
.
resType
=
RES_TYPE__TMQ
;
tDecoderInit
(
&
decoder
,
data
,
dataLen
);
code
=
tDecodeSMqDataRsp
(
&
decoder
,
&
rspObj
.
rsp
);
if
(
code
!=
0
)
{
uError
(
"WriteRaw:decode smqDataRsp error"
);
code
=
TSDB_CODE_INVALID_MSG
;
goto
end
;
}
if
(
!
pRequest
->
pDb
)
{
uError
(
"WriteRaw:not use db"
);
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
goto
end
;
}
pVgHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_NO_LOCK
);
taosHashSetFreeFp
(
pVgHash
,
destroyVgHash
);
struct
SCatalog
*
pCatalog
=
NULL
;
code
=
catalogGetHandle
(
pRequest
->
pTscObj
->
pAppInfo
->
clusterId
,
&
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw: get gatlog error"
);
goto
end
;
}
SRequestConnInfo
conn
=
{
0
};
conn
.
pTrans
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
;
conn
.
requestId
=
pRequest
->
requestId
;
conn
.
requestObjRefId
=
pRequest
->
self
;
conn
.
mgmtEps
=
getEpSet_s
(
&
pRequest
->
pTscObj
->
pAppInfo
->
mgmtEp
);
printf
(
"raw data block num:%d
\n
"
,
rspObj
.
rsp
.
blockNum
);
while
(
++
rspObj
.
resIter
<
rspObj
.
rsp
.
blockNum
)
{
SRetrieveTableRsp
*
pRetrieve
=
(
SRetrieveTableRsp
*
)
taosArrayGetP
(
rspObj
.
rsp
.
blockData
,
rspObj
.
resIter
);
if
(
!
rspObj
.
rsp
.
withSchema
)
{
uError
(
"WriteRaw:no schema, iter:%d"
,
rspObj
.
resIter
);
goto
end
;
}
SSchemaWrapper
*
pSW
=
(
SSchemaWrapper
*
)
taosArrayGetP
(
rspObj
.
rsp
.
blockSchema
,
rspObj
.
resIter
);
setResSchemaInfo
(
&
rspObj
.
resInfo
,
pSW
->
pSchema
,
pSW
->
nCols
);
code
=
setQueryResultFromRsp
(
&
rspObj
.
resInfo
,
pRetrieve
,
false
,
false
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw: setQueryResultFromRsp error"
);
goto
end
;
}
uint16_t
fLen
=
0
;
int32_t
rowSize
=
0
;
int16_t
nVar
=
0
;
for
(
int
i
=
0
;
i
<
pSW
->
nCols
;
i
++
)
{
SSchema
*
schema
=
pSW
->
pSchema
+
i
;
fLen
+=
TYPE_BYTES
[
schema
->
type
];
rowSize
+=
schema
->
bytes
;
if
(
IS_VAR_DATA_TYPE
(
schema
->
type
))
{
nVar
++
;
}
}
int32_t
rows
=
rspObj
.
resInfo
.
numOfRows
;
int32_t
extendedRowSize
=
rowSize
+
TD_ROW_HEAD_LEN
-
sizeof
(
TSKEY
)
+
nVar
*
sizeof
(
VarDataOffsetT
)
+
(
int32_t
)
TD_BITMAP_BYTES
(
pSW
->
nCols
-
1
);
int32_t
schemaLen
=
0
;
int32_t
submitLen
=
sizeof
(
SSubmitBlk
)
+
schemaLen
+
rows
*
extendedRowSize
;
const
char
*
tbName
=
(
const
char
*
)
taosArrayGetP
(
rspObj
.
rsp
.
blockTbName
,
rspObj
.
resIter
);
if
(
!
tbName
)
{
uError
(
"WriteRaw: tbname is null"
);
code
=
TSDB_CODE_TMQ_INVALID_MSG
;
goto
end
;
}
printf
(
"raw data tbname:%s
\n
"
,
tbName
);
SName
pName
=
{
TSDB_TABLE_NAME_T
,
pRequest
->
pTscObj
->
acctId
,
{
0
},
{
0
}};
strcpy
(
pName
.
dbname
,
pRequest
->
pDb
);
strcpy
(
pName
.
tname
,
tbName
);
VgData
vgData
=
{
0
};
code
=
catalogGetTableHashVgroup
(
pCatalog
,
&
conn
,
&
pName
,
&
(
vgData
.
vg
));
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw:catalogGetTableHashVgroup failed. table name: %s"
,
tbName
);
goto
end
;
}
SSubmitReq
*
subReq
=
NULL
;
SSubmitBlk
*
blk
=
NULL
;
void
*
hData
=
taosHashGet
(
pVgHash
,
&
vgData
.
vg
.
vgId
,
sizeof
(
vgData
.
vg
.
vgId
));
if
(
hData
)
{
vgData
=
*
(
VgData
*
)
hData
;
int32_t
totalLen
=
((
SSubmitReq
*
)(
vgData
.
data
))
->
length
+
submitLen
;
void
*
tmp
=
taosMemoryRealloc
(
vgData
.
data
,
totalLen
);
if
(
tmp
==
NULL
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
vgData
.
data
=
tmp
;
((
VgData
*
)
hData
)
->
data
=
tmp
;
subReq
=
(
SSubmitReq
*
)(
vgData
.
data
);
blk
=
POINTER_SHIFT
(
vgData
.
data
,
subReq
->
length
);
}
else
{
int32_t
totalLen
=
sizeof
(
SSubmitReq
)
+
submitLen
;
void
*
tmp
=
taosMemoryCalloc
(
1
,
totalLen
);
if
(
tmp
==
NULL
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
vgData
.
data
=
tmp
;
taosHashPut
(
pVgHash
,
(
const
char
*
)
&
vgData
.
vg
.
vgId
,
sizeof
(
vgData
.
vg
.
vgId
),
(
char
*
)
&
vgData
,
sizeof
(
vgData
));
subReq
=
(
SSubmitReq
*
)(
vgData
.
data
);
subReq
->
length
=
sizeof
(
SSubmitReq
);
subReq
->
numOfBlocks
=
0
;
blk
=
POINTER_SHIFT
(
vgData
.
data
,
sizeof
(
SSubmitReq
));
}
STableMeta
*
pTableMeta
=
NULL
;
code
=
catalogGetTableMeta
(
pCatalog
,
&
conn
,
&
pName
,
&
pTableMeta
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"WriteRaw:catalogGetTableMeta failed. table name: %s"
,
tbName
);
goto
end
;
}
uint64_t
suid
=
(
TSDB_NORMAL_TABLE
==
pTableMeta
->
tableType
?
0
:
pTableMeta
->
suid
);
uint64_t
uid
=
pTableMeta
->
uid
;
taosMemoryFreeClear
(
pTableMeta
);
void
*
blkSchema
=
POINTER_SHIFT
(
blk
,
sizeof
(
SSubmitBlk
));
STSRow
*
rowData
=
POINTER_SHIFT
(
blkSchema
,
schemaLen
);
SRowBuilder
rb
=
{
0
};
tdSRowInit
(
&
rb
,
pSW
->
version
);
tdSRowSetTpInfo
(
&
rb
,
pSW
->
nCols
,
fLen
);
int32_t
dataLen
=
0
;
for
(
int32_t
j
=
0
;
j
<
rows
;
j
++
)
{
tdSRowResetBuf
(
&
rb
,
rowData
);
doSetOneRowPtr
(
&
rspObj
.
resInfo
);
rspObj
.
resInfo
.
current
+=
1
;
int32_t
offset
=
0
;
for
(
int32_t
k
=
0
;
k
<
pSW
->
nCols
;
k
++
)
{
const
SSchema
*
pColumn
=
&
pSW
->
pSchema
[
k
];
char
*
data
=
rspObj
.
resInfo
.
row
[
k
];
if
(
!
data
)
{
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NULL
,
NULL
,
false
,
offset
,
k
);
}
else
{
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
type
))
{
data
-=
VARSTR_HEADER_SIZE
;
}
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NORM
,
data
,
true
,
offset
,
k
);
}
offset
+=
TYPE_BYTES
[
pColumn
->
type
];
}
tdSRowEnd
(
&
rb
);
int32_t
rowLen
=
TD_ROW_LEN
(
rowData
);
rowData
=
POINTER_SHIFT
(
rowData
,
rowLen
);
dataLen
+=
rowLen
;
}
blk
->
uid
=
htobe64
(
uid
);
blk
->
suid
=
htobe64
(
suid
);
blk
->
sversion
=
htonl
(
pSW
->
version
);
blk
->
schemaLen
=
htonl
(
schemaLen
);
blk
->
numOfRows
=
htonl
(
rows
);
blk
->
dataLen
=
htonl
(
dataLen
);
subReq
->
length
+=
sizeof
(
SSubmitBlk
)
+
schemaLen
+
dataLen
;
subReq
->
numOfBlocks
++
;
}
pQuery
=
(
SQuery
*
)
nodesMakeNode
(
QUERY_NODE_QUERY
);
if
(
NULL
==
pQuery
)
{
uError
(
"create SQuery error"
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
haveResultSet
=
false
;
pQuery
->
msgType
=
TDMT_VND_SUBMIT
;
pQuery
->
pRoot
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VNODE_MODIF_STMT
);
if
(
NULL
==
pQuery
->
pRoot
)
{
uError
(
"create pQuery->pRoot error"
);
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
end
;
}
SVnodeModifOpStmt
*
nodeStmt
=
(
SVnodeModifOpStmt
*
)(
pQuery
->
pRoot
);
nodeStmt
->
payloadType
=
PAYLOAD_TYPE_KV
;
int32_t
numOfVg
=
taosHashGetSize
(
pVgHash
);
nodeStmt
->
pDataBlocks
=
taosArrayInit
(
numOfVg
,
POINTER_BYTES
);
VgData
*
vData
=
(
VgData
*
)
taosHashIterate
(
pVgHash
,
NULL
);
while
(
vData
)
{
SVgDataBlocks
*
dst
=
taosMemoryCalloc
(
1
,
sizeof
(
SVgDataBlocks
));
if
(
NULL
==
dst
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
dst
->
vg
=
vData
->
vg
;
SSubmitReq
*
subReq
=
(
SSubmitReq
*
)(
vData
->
data
);
dst
->
numOfTables
=
subReq
->
numOfBlocks
;
dst
->
size
=
subReq
->
length
;
dst
->
pData
=
(
char
*
)
subReq
;
vData
->
data
=
NULL
;
// no need free
subReq
->
header
.
vgId
=
htonl
(
dst
->
vg
.
vgId
);
subReq
->
version
=
htonl
(
1
);
subReq
->
header
.
contLen
=
htonl
(
subReq
->
length
);
subReq
->
length
=
htonl
(
subReq
->
length
);
subReq
->
numOfBlocks
=
htonl
(
subReq
->
numOfBlocks
);
taosArrayPush
(
nodeStmt
->
pDataBlocks
,
&
dst
);
vData
=
(
VgData
*
)
taosHashIterate
(
pVgHash
,
vData
);
}
launchQueryImpl
(
pRequest
,
pQuery
,
true
,
NULL
);
code
=
pRequest
->
code
;
end:
tDecoderClear
(
&
decoder
);
taos_free_result
(
&
rspObj
);
qDestroyQuery
(
pQuery
);
destroyRequest
(
pRequest
);
taosHashCleanup
(
pVgHash
);
return
code
;
}
char
*
tmq_get_json_meta
(
TAOS_RES
*
res
)
{
if
(
!
TD_RES_TMQ_META
(
res
))
{
return
NULL
;
}
SMqMetaRspObj
*
pMetaRspObj
=
(
SMqMetaRspObj
*
)
res
;
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_CREATE_STB
)
{
return
processCreateStb
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_ALTER_STB
)
{
return
processAlterStb
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_DROP_STB
)
{
return
processDropSTable
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_CREATE_TABLE
)
{
return
processCreateTable
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_ALTER_TABLE
)
{
return
processAlterTable
(
&
pMetaRspObj
->
metaRsp
);
}
else
if
(
pMetaRspObj
->
metaRsp
.
resMsgType
==
TDMT_VND_DROP_TABLE
)
{
return
processDropTable
(
&
pMetaRspObj
->
metaRsp
);
}
return
NULL
;
}
void
tmq_free_json_meta
(
char
*
jsonMeta
)
{
taosMemoryFreeClear
(
jsonMeta
);
}
int32_t
tmq_get_raw
(
TAOS_RES
*
res
,
tmq_raw_data
*
raw
)
{
if
(
!
raw
||
!
res
)
{
return
TSDB_CODE_INVALID_PARA
;
}
if
(
TD_RES_TMQ_META
(
res
))
{
SMqMetaRspObj
*
pMetaRspObj
=
(
SMqMetaRspObj
*
)
res
;
raw
->
raw
=
pMetaRspObj
->
metaRsp
.
metaRsp
;
raw
->
raw_len
=
pMetaRspObj
->
metaRsp
.
metaRspLen
;
raw
->
raw_type
=
pMetaRspObj
->
metaRsp
.
resMsgType
;
}
else
if
(
TD_RES_TMQ
(
res
))
{
SMqRspObj
*
rspObj
=
((
SMqRspObj
*
)
res
);
int32_t
len
=
0
;
int32_t
code
=
0
;
tEncodeSize
(
tEncodeSMqDataRsp
,
&
rspObj
->
rsp
,
len
,
code
);
if
(
code
<
0
)
{
return
-
1
;
}
void
*
buf
=
taosMemoryCalloc
(
1
,
len
);
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
buf
,
len
);
tEncodeSMqDataRsp
(
&
encoder
,
&
rspObj
->
rsp
);
tEncoderClear
(
&
encoder
);
raw
->
raw
=
buf
;
raw
->
raw_len
=
len
;
raw
->
raw_type
=
RES_TYPE__TMQ
;
}
else
{
return
TSDB_CODE_TMQ_INVALID_MSG
;
}
return
TSDB_CODE_SUCCESS
;
}
void
tmq_free_raw
(
tmq_raw_data
raw
)
{
if
(
raw
.
raw_type
==
RES_TYPE__TMQ
)
{
taosMemoryFree
(
raw
.
raw
);
}
}
int32_t
tmq_write_raw
(
TAOS
*
taos
,
tmq_raw_data
raw
)
{
if
(
!
taos
)
{
return
TSDB_CODE_INVALID_PARA
;
}
if
(
raw
.
raw_type
==
TDMT_VND_CREATE_STB
)
{
return
taosCreateStb
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_ALTER_STB
)
{
return
taosCreateStb
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_DROP_STB
)
{
return
taosDropStb
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_CREATE_TABLE
)
{
return
taosCreateTable
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_ALTER_TABLE
)
{
return
taosAlterTable
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_DROP_TABLE
)
{
return
taosDropTable
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
TDMT_VND_DELETE
)
{
return
taosDeleteData
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
else
if
(
raw
.
raw_type
==
RES_TYPE__TMQ
)
{
return
tmqWriteRaw
(
taos
,
raw
.
raw
,
raw
.
raw_len
);
}
return
TSDB_CODE_INVALID_PARA
;
}
void
tmq_commit_async
(
tmq_t
*
tmq
,
const
TAOS_RES
*
msg
,
tmq_commit_cb
*
cb
,
void
*
param
)
{
//
tmqCommitInner
(
tmq
,
msg
,
0
,
1
,
cb
,
param
);
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
77f27b62
...
...
@@ -128,7 +128,7 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn
w
=
getAlignQueryTimeWindow
(
pInterval
,
pInterval
->
precision
,
pBlockInfo
->
window
.
skey
);
assert
(
w
.
ekey
>=
pBlockInfo
->
window
.
skey
);
if
(
w
.
ekey
<
pBlockInfo
->
window
.
ekey
)
{
if
(
TMAX
(
w
.
skey
,
pBlockInfo
->
window
.
skey
)
<=
TMIN
(
w
.
ekey
,
pBlockInfo
->
window
.
ekey
)
)
{
return
true
;
}
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
77f27b62
...
...
@@ -1002,7 +1002,7 @@ static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pS
int32_t
code
=
nodesCollectColumns
(
pSelect
,
SQL_CLAUSE_PARTITION_BY
,
NULL
,
COLLECT_COL_TYPE_ALL
,
&
pPartition
->
node
.
pTargets
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
==
pPartition
->
node
.
pTargets
)
{
code
=
nodesListMakeStrictAppend
(
&
pPartition
->
node
.
pTargets
,
nodes
ListGetNode
(
pCxt
->
pCurrRoot
->
pTargets
,
0
));
code
=
nodesListMakeStrictAppend
(
&
pPartition
->
node
.
pTargets
,
nodes
CloneNode
(
nodesListGetNode
(
pCxt
->
pCurrRoot
->
pTargets
,
0
)
));
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
source/util/src/terror.c
浏览文件 @
77f27b62
...
...
@@ -624,6 +624,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_INDEX_REBUILDING, "Invalid index file"
//tmq
TAOS_DEFINE_ERROR
(
TSDB_CODE_TMQ_INVALID_MSG
,
"Invalid message"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TMQ_CONSUMER_MISMATCH
,
"Consumer mismatch"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TMQ_CONSUMER_CLOSED
,
"Consumer closed"
)
#ifdef TAOS_ERROR_C
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录