Merge remote-tracking branch 'origin/3.0' into merge/mainto3.0
This commit is contained in:
commit
5701340d88
|
@ -28,7 +28,7 @@ jobs:
|
|||
run: |
|
||||
mkdir debug
|
||||
cd debug
|
||||
cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_TEST=off -DBUILD_KEEPER=true
|
||||
cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_TEST=off -DBUILD_KEEPER=true -DBUILD_DEPENDENCY_TESTS=false
|
||||
make -j 4
|
||||
sudo make install
|
||||
which taosd
|
||||
|
@ -48,7 +48,7 @@ jobs:
|
|||
working-directory: tools/keeper
|
||||
run: |
|
||||
go mod tidy
|
||||
go test -v -coverpkg=./... -coverprofile=coverage.out ./...
|
||||
sudo go test -v -ldflags="-X 'github.com/taosdata/taoskeeper/version.IsEnterprise=true'" -coverpkg=./... -coverprofile=coverage.out ./...
|
||||
go tool cover -func=coverage.out
|
||||
|
||||
- name: Clean up
|
||||
|
|
|
@ -261,11 +261,19 @@ if(${TD_DARWIN})
|
|||
endif(${TD_DARWIN})
|
||||
|
||||
add_subdirectory(zlib EXCLUDE_FROM_ALL)
|
||||
|
||||
if(${TD_DARWIN})
|
||||
target_compile_options(zlibstatic PRIVATE -Wno-error=deprecated-non-prototype)
|
||||
endif()
|
||||
target_include_directories(
|
||||
zlibstatic
|
||||
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
|
||||
)
|
||||
|
||||
if(${TD_DARWIN})
|
||||
target_compile_options(zlib PRIVATE -Wno-error=deprecated-non-prototype)
|
||||
endif()
|
||||
target_include_directories(
|
||||
zlib
|
||||
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
|
||||
|
|
|
@ -7,8 +7,4 @@ java -jar target/taosdemo-2.0.1-jar-with-dependencies.jar -host <hostname> -data
|
|||
java -jar target/taosdemo-2.0.1-jar-with-dependencies.jar -host <hostname> -database <db name> -doCreateTable false -superTableSQL "create table weather(ts timestamp, f1 int) tags(t1 nchar(4))" -numOfTables 1000 -numOfRowsPerTable 100000000 -numOfThreadsForInsert 10 -numOfTablesPerSQL 10 -numOfValuesPerSQL 100
|
||||
```
|
||||
|
||||
如果发生错误 Exception in thread "main" java.lang.UnsatisfiedLinkError: no taos in java.library.path
|
||||
请检查是否安装 TDengine 客户端安装包或编译 TDengine 安装。如果确定已经安装过还出现这个错误,可以在命令行 java 后加 -Djava.library.path=/usr/lib 来指定寻找共享库的路径。
|
||||
|
||||
|
||||
If you encounter the error Exception in thread "main" `java.lang.UnsatisfiedLinkError: no taos in java.library.path`, please check whether the TDengine client package is installed or TDengine is compiled and installed. If you are sure it is installed and still encounter this error, you can add `-Djava.library.path=/usr/lib` after the `java` command to specify the path to the shared library.
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tdengine/websocket": "^3.1.0"
|
||||
"@tdengine/websocket": "^3.1.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ const taos = require("@tdengine/websocket");
|
|||
|
||||
let dsn = 'ws://localhost:6041';
|
||||
async function createConnect() {
|
||||
|
||||
try {
|
||||
let conf = new taos.WSConfig(dsn);
|
||||
conf.setUser('root');
|
||||
|
|
|
@ -10,7 +10,6 @@ const groupId = "group1";
|
|||
const clientId = "client1";
|
||||
|
||||
async function createConsumer() {
|
||||
|
||||
let groupId = "group1";
|
||||
let clientId = "client1";
|
||||
let configMap = new Map([
|
||||
|
|
|
@ -3,8 +3,52 @@ title: "ARIMA"
|
|||
sidebar_label: "ARIMA"
|
||||
---
|
||||
|
||||
本节讲述如何 ARIMA 算法的使用方法。
|
||||
本节讲述 ARIMA 算法模型的使用方法。
|
||||
|
||||
## 功能概述
|
||||
|
||||
……
|
||||
ARIMA 即自回归移动平均模型(Autoregressive Integrated Moving Average, ARIMA),也记作 ARIMA(p,d,q),是统计模型中最常见的一种用来进行时间序列预测的模型。
|
||||
ARIMA模型是一种自回归模型,只需要自变量即可预测后续的值。ARIMA模型要求时序数据是**平稳**,或经过差分处理后平稳,如果是不平稳的数据,**无法**获得正确的结果。
|
||||
|
||||
>平稳的时间序列:其性质不随观测时间的变化而变化。具有趋势或季节性的时间序列不是平稳时间序列——趋势和季节性使得时间序列在不同时段呈现不同性质。
|
||||
|
||||
以下参数可以动态输入控制预测过程中生成 合适的 ARIMA 的模型。
|
||||
|
||||
- p= 自回归模型阶数
|
||||
- d= 差分阶数
|
||||
- q= 移动平均模型阶数
|
||||
|
||||
|
||||
### 参数
|
||||
分析平台中使用自动化的 ARIMA 模型进行计算,因此每次计算的时候会根据输入的数据自动拟合最合适的模型,然后根据该模型进行预测输出结果。
|
||||
|参数名称|说明|必填项|
|
||||
|---|---|---|
|
||||
|period|输入时间序列数据每个周期包含的数据点个数。如果不设置该参数或则该参数设置为 0, 将使用非季节性/周期性的 ARIMA 模型预测。|选填|
|
||||
|start_p| 自回归模型阶数的 起始值,0 开始的整数,不推荐大于 10 |选填|
|
||||
|max_p| 自回归模型阶数的 结束值,0 开始的整数,不推荐大于 10 |选填|
|
||||
|start_q| 移动平均模型阶数的起始值, 0 开始的整数,不推荐大于 10 |选填|
|
||||
|max_q| 移动平均模型阶数的结束值, 0 开始的整数,不推荐大于 10 |选填|
|
||||
|d| 差分阶数|选填|
|
||||
|
||||
`start_p`、`max_p` `start_q` `max_q` 四个参数约束了模型在多大的范围内去搜寻合适的最优解。相同输入数据的条件下,参数范围越大,消耗的资源越多,系统响应的时间越长。
|
||||
|
||||
### 示例及结果
|
||||
针对 i32 列进行数据预测,输入列 i32 每 10 个点是一个周期,start_p 起始是 1, 最大拟合是 5,start_q是1,最大值是5,预测结果中返回 95% 置信区间范围边界。
|
||||
```
|
||||
FORECAST(i32, "algo=arima,alpha=95,period=10, start_p=1, max_p=5, start_q=1, max_q=5")
|
||||
```
|
||||
|
||||
```json5
|
||||
{
|
||||
"rows": fc_rows, // 预测结果的行数
|
||||
"period": period, // 返回结果的周期性,同输入
|
||||
"alpha": alpha, // 返回结果的置信区间,同输入
|
||||
"algo": "arima", // 返回结果使用的算法
|
||||
"mse":mse, // 拟合输入时序数据时候生成模型的最小均方误差(MSE)
|
||||
"res": res // 列模式的结果
|
||||
}
|
||||
```
|
||||
|
||||
### 参考文献
|
||||
- https://en.wikipedia.org/wiki/Autoregressive_moving-average_model
|
||||
- https://baike.baidu.com/item/%E8%87%AA%E5%9B%9E%E5%BD%92%E6%BB%91%E5%8A%A8%E5%B9%B3%E5%9D%87%E6%A8%A1%E5%9E%8B/5023931?fromtitle=ARMA%E6%A8%A1%E5%9E%8B&fromid=8048415
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
title: "HoltWinters"
|
||||
sidebar_label: "HoltWinters"
|
||||
---
|
||||
|
||||
本节讲述 HoltWinters 算法模型的使用方法。
|
||||
|
||||
## 功能概述
|
||||
HoltWinters模型又称为多次指数平滑模型(EMA)。对含有线性趋势和周期波动的非平稳序列适用,利用指数平滑法让模型参数不断适应非平稳序列的变化,并对未来趋势进行**短期**预测。
|
||||
HoltWinters有两种不同的季节性组成部分,当季节变化在该时间序列中大致保持不变时,通常选择**加法模型**;而当季节变化与时间序列的水平成比例变化时,通常选择**乘法模型**。
|
||||
该模型对于返回数据也不提供计算的置信区间范围结果。在 95% 置信区间的上下界结果与预测结果相同。
|
||||
|
||||
|
||||
### 参数
|
||||
|
||||
分析平台中使用自动化的 ARIMA 模型进行计算,因此每次计算的时候会根据输入的数据自动拟合最合适的模型,然后根据该模型进行预测输出结果。
|
||||
|参数名称|说明|必填项|
|
||||
|---|---|---|
|
||||
|period| 输入时间序列数据每个周期包含的数据点个数。如果不设置该参数或则该参数设置为 0, 将使用一次(简单)指数平滑方式进行数据拟合,并据此进行未来数据的预测|选填|
|
||||
|trend| 趋势模型使用加法模型还是乘法模型|选填|
|
||||
|seasonal| 季节性采用加法模型还是乘法模型|选填|
|
||||
|
||||
参数 `trend` 和 `seasonal`的均可以选择 `add` (加法模型)或 `mul`(乘法模型)。
|
||||
|
||||
### 示例及结果
|
||||
针对 i32 列进行数据预测,输入列 i32 每 10 个点是一个周期,趋势采用乘法模型,季节采用乘法模型
|
||||
```
|
||||
FORECAST(i32, "algo=holtwinters,period=10,trend=mul,seasonal=mul")
|
||||
```
|
||||
|
||||
```json5
|
||||
{
|
||||
"rows": rows, // 结果的行数
|
||||
"period": period, // 返回结果的周期性, 该结果与输入的周期性相同,如果没有周期性,该值为 0
|
||||
"algo": 'holtwinters' // 返回结果使用的计算模型
|
||||
"mse":mse, // 最小均方误差(minmum square error)
|
||||
"res": res // 具体的结果,按照列形式返回的结果。一般意义上包含了 两列[timestamp][fc_results]。
|
||||
}
|
||||
```
|
||||
|
||||
### 参考文献
|
||||
- https://en.wikipedia.org/wiki/Exponential_smoothing
|
||||
- https://orangematter.solarwinds.com/2019/12/15/holt-winters-forecasting-simplified/
|
|
@ -0,0 +1,46 @@
|
|||
---
|
||||
title: "Anomaly-detection"
|
||||
sidebar_label: "Anomaly-detection"
|
||||
---
|
||||
|
||||
本节讲述 异常检测 算法模型的使用方法。
|
||||
|
||||
## 概述
|
||||
分析平台提供了 6 种异常检查模型,6 种异常检查模型分为 3 个类别,分别属于基于统计的异常检测模型、基于数据密度的检测模型、基于深度学习的异常检测模型。在不指定异常检测使用的方法的情况下,默认调用 iqr 的方法进行计算。
|
||||
|
||||
|
||||
### 统计学异常检测方法
|
||||
|
||||
- k-sigma<sup>[1]</sup>: 即 ***68–95–99.7 rule*** 。***k***值默认为3, 即序列均值的 3 倍标准差范围为边界,超过边界的是异常值。KSigma 要求数据整体上服从正态分布,如果一个点偏离均值K倍标准差,则该点被视为异常点.
|
||||
|
||||
|参数名称|说明|是否必选|默认值|
|
||||
|---|---|---|---|
|
||||
|k|标准差倍数|选填|3|
|
||||
|
||||
|
||||
- IQR<sup>[2]</sup>:四分位距 (Interquartile range, IQR) 是一种衡量变异性的方法. 四分位数将一个按等级排序的数据集划分为四个相等的部分。即 Q1(第 1 个四分位数)、Q2(第 2 个四分位数)和 Q3(第 3 个四分位数)。IQR 定义为 Q3–Q1,位于 Q3+1.5 。无输入参数。
|
||||
|
||||
- Grubbs<sup>[3]</sup>: 又称为 Grubbs' test,即最大标准残差测试。Grubbs 通常用作检验最大值、最小值偏离均值的程度是否为异常,该单变量数据集遵循近似标准正态分布。非正态分布数据集不能使用该方法。无输入参数。
|
||||
|
||||
- SHESD<sup>[4]</sup>: 带有季节性的 ESD 检测算法。ESD 可以检测时间序列数据的多异常点。需要指定异常点比例的上界***k***,最差的情况是至多49.9%。数据集的异常比例一般不超过5%
|
||||
|
||||
|参数名称|说明|是否必选|默认值|
|
||||
|---|---|---|---|
|
||||
|k|异常点在输入数据集中占比,范围是$`1\le K \le 49.9`$ |选填|5|
|
||||
|
||||
|
||||
### 基于数据密度的检测方法
|
||||
LOF<sup>[5]</sup>: 局部离群因子(LOF,又叫局部异常因子)算法是Breunig于2000年提出的一种基于密度的局部离群点检测算法,该方法适用于不同类簇密度分散情况迥异的数据。根据数据点周围的数据密集情况,首先计算每个数据点的一个局部可达密度,然后通过局部可达密度进一步计算得到每个数据点的一个离群因子,该离群因子即标识了一个数据点的离群程度,因子值越大,表示离群程度越高,因子值越小,表示离群程度越低。最后,输出离群程度最大的top(n)个点。
|
||||
|
||||
|
||||
### 基于深度学习的检测方法
|
||||
使用自动编码器的异常检测模型。可以对具有周期性的数据具有较好的检测结果。但是使用该模型需要针对输入的时序数据进行训练,同时将训练完成的模型部署到服务目录中,才能够运行与使用。
|
||||
|
||||
|
||||
### 参考文献
|
||||
1. https://en.wikipedia.org/wiki/68%E2%80%9395%E2%80%9399.7_rule
|
||||
2. https://en.wikipedia.org/wiki/Interquartile_range
|
||||
3. Adikaram, K. K. L. B.; Hussein, M. A.; Effenberger, M.; Becker, T. (2015-01-14). "Data Transformation Technique to Improve the Outlier Detection Power of Grubbs's Test for Data Expected to Follow Linear Relation". Journal of Applied Mathematics. 2015: 1–9. doi:10.1155/2015/708948.
|
||||
4. Hochenbaum, O. S. Vallis, and A. Kejariwal. 2017. Automatic Anomaly Detection in the Cloud Via Statistical Learning. arXiv preprint arXiv:1704.07706 (2017).
|
||||
5. Breunig, M. M.; Kriegel, H.-P.; Ng, R. T.; Sander, J. (2000). LOF: Identifying Density-based Local Outliers (PDF). Proceedings of the 2000 ACM SIGMOD International Conference on Management of Data. SIGMOD. pp. 93–104. doi:10.1145/335191.335388. ISBN 1-58113-217-4.
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
---
|
||||
title: "addins"
|
||||
sidebar_label: "addins"
|
||||
---
|
||||
|
||||
本节说明如何将自己开发的新预测算法和异常检测算法整合到 TDengine 分析平台, 并能够通过 SQL 语句进行调用。
|
||||
|
||||
## 目录结构
|
||||
|
||||

|
||||
|
||||
|目录|说明|
|
||||
|---|---|
|
||||
|taos|Python 源代码目录,其下包含了算法具体保存目录 algo,放置杂项目录 misc, 单元测试和集成测试目录 test。 algo目录下 ad 放置异常检测算法代码, fc 放置预测算法代码|
|
||||
|script|是安装脚本和发布脚本放置目录|
|
||||
|model|放置针对数据集完成的训练模型|
|
||||
|cfg| 配置文件目录|
|
||||
|
||||
## 约定与限制
|
||||
|
||||
定义异常检测算法的 Python 代码文件 需放在 /taos/algo/ad 目录中,预测算法 Python 代码文件需要放在 /taos/algo/fc 目录中,以确保系统启动的时候能够正常加载对应目录下的 Python 文件。
|
||||
|
||||
|
||||
### 类命名规范
|
||||
|
||||
算法类的名称需要 以下划线开始,以 Service 结尾。例如:_KsigmaService 是 KSigma 异常检测算法的实现类。
|
||||
|
||||
### 类继承约定
|
||||
|
||||
异常检测算法需要从 `AbstractAnomalyDetectionService` 继承,并实现其核心抽象方法 `execute`.
|
||||
预测算法需要从 `AbstractForecastService` 继承,同样需要实现其核心抽象方法 `execute`。
|
||||
|
||||
### 类属性初始化
|
||||
每个算法实现的类需要静态初始化两个类属性,分别是
|
||||
|
||||
`name`: 的触发调用关键词,全小写英文字母。
|
||||
`desc`:该算法的描述信息。
|
||||
|
||||
### 核心方法输入与输出约定
|
||||
|
||||
`execute` 是算法处理的核心方法。调用该方法的时候, `self.list` 已经设置好输入数组。
|
||||
异常检测输出结果
|
||||
|
||||
`execute` 的返回值是长度与 `self.list` 相同的数组,数组位置为 -1 的即为异常值点。例如:输入数组是 [2, 2, 2, 2, 100], 如果 100 是异常点,那么返回值是 [1, 1, 1, 1, -1]。
|
||||
预测输出结果
|
||||
|
||||
对于预测算法, `AbstractForecastService` 的对象属性说明如下:
|
||||
|
||||
|属性名称|说明|默认值|
|
||||
|---|---|---|
|
||||
|period|输入时序数据的周期性,多少个数据点表示一个完整的周期。如果没有周期性,那么设置为 0 即可。| 0|
|
||||
|start_ts|预测数据的开始时间| 0|
|
||||
|time_step|预测结果的两个数据点之间时间间隔|0 |
|
||||
|fc_rows|预测结果数量| 0 |
|
||||
|return_conf|返回结果中是否包含执行区间范围,如果算法计算结果不包含置信区间,那么上界和下界与自身相同| 1|
|
||||
|conf|执行区间分位数 0.05|
|
||||
|
||||
|
||||
预测返回结果如下:
|
||||
```python
|
||||
return {
|
||||
"rows": self.fc_rows, # 预测数据行数
|
||||
"period": self.period, # 数据周期性,同输入
|
||||
"algo": "holtwinters", # 预测使用的算法
|
||||
"mse": mse, # 预测算法的 mse
|
||||
"res": res # 结果数组 [时间戳数组, 预测结果数组, 预测结果执行区间下界数组,预测结果执行区间上界数组]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## 示例代码
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
from service import AbstractAnomalyDetectionService
|
||||
|
||||
# 算法实现类名称 需要以下划线 "_" 开始,并以 Service 结束,如下 _IqrService 是 IQR 异常检测算法的实现类。
|
||||
class _IqrService(AbstractAnomalyDetectionService):
|
||||
""" IQR algorithm 定义类,从 AbstractAnomalyDetectionService 继承,并实现 AbstractAnomalyDetectionService类的抽象函数 """
|
||||
|
||||
# 定义算法调用关键词,全小写ASCII码(必须添加)
|
||||
name = 'iqr'
|
||||
|
||||
# 该算法的描述信息(建议添加)
|
||||
desc = """found the anomaly data according to the inter-quartile range"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def execute(self):
|
||||
""" execute 是算法实现逻辑的核心实现,直接修改该实现即可 """
|
||||
|
||||
# self.list 是输入数值列,list 类型,例如:[1,2,3,4,5]。设置 self.list 的方法在父类中已经进行了定义。实现自己的算法,修改该文件即可,以下代码使用自己的实现替换即可。
|
||||
#lower = np.quantile(self.list, 0.25)
|
||||
#upper = np.quantile(self.list, 0.75)
|
||||
|
||||
#min_val = lower - 1.5 * (upper - lower)
|
||||
#max_val = upper + 1.5 * (upper - lower)
|
||||
#threshold = [min_val, max_val]
|
||||
|
||||
# 返回值是与输入数值列长度相同的数据列,异常值对应位置是 -1。例如上述输入数据列,返回数值列是 [1, 1, 1, 1, -1],表示 [5] 是异常值。
|
||||
return [-1 if k < threshold[0] or k > threshold[1] else 1 for k in self.list]
|
||||
|
||||
|
||||
def set_params(self, params):
|
||||
"""该算法无需任何输入参数,直接重载父类该函数,不处理算法参数设置逻辑"""
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
## 单元测试
|
||||
|
||||
在测试文件目录中的 anomaly_test.py 中增加单元测试用例。
|
||||
```python
|
||||
def test_iqr(self):
|
||||
""" 测试 _IqrService 类 """
|
||||
s = loader.get_service("iqr")
|
||||
|
||||
# 设置需要进行检测的输入数据
|
||||
s.set_input_list(AnomalyDetectionTest.input_list)
|
||||
|
||||
# 测试 set_params 的处理逻辑
|
||||
try:
|
||||
s.set_params({"k": 2})
|
||||
except ValueError as e:
|
||||
self.assertEqual(1, 0)
|
||||
|
||||
r = s.execute()
|
||||
|
||||
# 绘制异常检测结果
|
||||
draw_ad_results(AnomalyDetectionTest.input_list, r, "iqr")
|
||||
|
||||
# 检查结果
|
||||
self.assertEqual(r[-1], -1)
|
||||
self.assertEqual(len(r), len(AnomalyDetectionTest.input_list))
|
||||
```
|
||||
|
||||
## 需要模型的算法
|
||||
|
||||
针对特定数据集,进行模型训练的算法,在训练完成后。需要将训练得到的模型保存在 model 目录中。需要注意的是,针对每个算法,需要建立独立的文件夹。例如 auto_encoder 的训练算法在 model 目录下建立了, autoencoder的目录,使用该算法针对不同数据集训练得到的模型,均需要放置在该目录下。
|
||||
|
||||
训练完成后的模型,使用 joblib 进行保存。
|
||||
|
||||
并在 model 目录下建立对应的文件夹存放该模型。
|
||||
|
||||
保存模型的调用,可参考 encoder.py 的方式,用户通过调用 set_params 方法,并指定参数 `{"model": "ad_encoder_keras"}` 的方式,可以调用该模型进行计算。
|
||||
|
||||
具体的调用方式如下:
|
||||
|
||||
```python
|
||||
def test_autoencoder_ad(self):
|
||||
# 获取特定的算法服务
|
||||
s = loader.get_service("ac")
|
||||
data = self.__load_remote_data_for_ad()
|
||||
|
||||
# 设置异常检查的输入数据
|
||||
s.set_input_list(data)
|
||||
|
||||
# 指定调用的模型,该模型是之前针对该数据集进行训练获得
|
||||
s.set_params({"model": "ad_encoder_keras"})
|
||||
# 执行检查动作,并返回结果
|
||||
r = s.execute()
|
||||
|
||||
num_of_error = -(sum(filter(lambda x: x == -1, r)))
|
||||
self.assertEqual(num_of_error, 109)
|
||||
```
|
||||
|
|
@ -5,9 +5,314 @@ title: 数据分析功能
|
|||
|
||||
## 概述
|
||||
|
||||
TDengine 提供数据分析功能的扩展组件,通过引入 ANode,TDengine 能够支持时间序列的机器学习分析
|
||||
|
||||
下图展示了数据分析的技术架构。
|
||||
TDengine 通过 ANode(AnalysisNode) 是提供数据分析功能的扩展组件,通过 Restful 接口提供分析服务,从而拓展 TDengine 的功能,支持时间序列高级分析功能。
|
||||
ANode 是无状态的数据分析节点,集群中可以存在多个 ANode节点,相互之间没有关联。将 ANode 注册到 TDengine 集群以后,通过 SQL 语句即可调用并完成时序分析任务。
|
||||
下图是数据分析的技术架构示意图。
|
||||
|
||||

|
||||
|
||||
## 安装部署
|
||||
### 环境准备
|
||||
ANode 的要求节点上准备有 Python 3.10 及以上版本以及相应的Python包自动安装组件 Pip ,同时请确保能够正常连接互联网。
|
||||
|
||||
### 安装及卸载
|
||||
使用专门的 ANode 安装包 TDengine-enterprise-anode-1.x.x.tar.gz 进行 ANode 的安装部署工作,安装过程与 TDengien 的安装流程一致。
|
||||
|
||||
```bash
|
||||
tar -xzvf TDengine-enterprise-anode-1.0.0.tar.gz
|
||||
cd TDengine-enterprise-anode-1.0.0
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
卸载 ANode,执行命令 `rmtaosanode` 即可。
|
||||
|
||||
### 其他
|
||||
为了避免 ANode 安装后影响目标节点现有的 Python 库。 ANode 使用 Python 虚拟环境运行,安装后的默认 Python 目录处于 `/var/lib/taos/taosanode/venv/`。为了避免反复安装虚拟环境带来的开销,卸载 ANode 并不会自动删除该虚拟环境,如果您确认不需要 Python 的虚拟环境,可以手动删除。
|
||||
|
||||
## 启动及停止服务
|
||||
安装 ANode 以后,可以使用`systemctl`来管理 ANode 的服务。使用如下命令可以启动/停止/检查状态。
|
||||
|
||||
```bash
|
||||
systemctl start taosanoded
|
||||
systemctl stop taosanoded
|
||||
systemctl status taosanoded
|
||||
```
|
||||
|
||||
## 目录及配置说明
|
||||
|目录/文件|说明|
|
||||
|---------------|------|
|
||||
|/usr/local/taos/taosanode/bin|可执行文件目录|
|
||||
|/usr/local/taos/taosanode/resource|资源文件目录,链接到文件夹 /var/lib/taos/taosanode/resource/|
|
||||
|/usr/local/taos/taosanode/lib|库文件目录|
|
||||
|/var/lib/taos/taosanode/model/|模型文件目录,链接到文件夹 /var/lib/taos/taosanode/model|
|
||||
|/var/log/taos/taosanode/|日志文件目录|
|
||||
|/etc/taos/taosanode.ini|配置文件|
|
||||
|
||||
### 配置说明
|
||||
|
||||
Anode 提供的 RestFul 服务使用 uWSGI 驱动,因此 ANode 的配置和 uWSGI 的配置在同一个配置文件中,具体如下:
|
||||
|
||||
```ini
|
||||
[uwsgi]
|
||||
# charset
|
||||
env=LC_ALL=en_US.UTF-8
|
||||
|
||||
# ip:port
|
||||
http = 127.0.0.1:6050
|
||||
|
||||
# the local unix socket file than communicate to Nginx
|
||||
#socket = 127.0.0.1:8001
|
||||
#socket-timeout=10
|
||||
|
||||
# base directory
|
||||
chdir = /usr/local/taos/taosanode/lib
|
||||
|
||||
# initialize python file
|
||||
wsgi-file = /usr/local/taos/taosanode/lib/app.py
|
||||
|
||||
# invoke app model
|
||||
callable = app
|
||||
|
||||
# auto remove unix Socket and pid file when stopping
|
||||
vacuum = true
|
||||
|
||||
# socket exec model
|
||||
#chmod-socket = 664
|
||||
|
||||
# uWSGI pid
|
||||
uid=root
|
||||
|
||||
# uWSGI gid
|
||||
gid=root
|
||||
|
||||
# main process
|
||||
master = true
|
||||
|
||||
# the number of worker processes
|
||||
processes = 2
|
||||
|
||||
# pid file
|
||||
pidfile = /usr/local/taos/taosanode/uwsgi.pid
|
||||
|
||||
# enable threads
|
||||
enable-threads=true
|
||||
|
||||
# the number of threads for each process
|
||||
threads=2
|
||||
|
||||
# memory useage report
|
||||
memory-report = true
|
||||
reload-mercy = 10
|
||||
|
||||
# conflict with systemctl, so do NOT uncomment this
|
||||
# daemonize = /var/log/taos/taosanode/taosanode.log
|
||||
|
||||
# set log
|
||||
logto = /var/log/taos/taosanode/taosanode.log
|
||||
|
||||
# monitor server
|
||||
stats = 127.0.0.1:8387
|
||||
|
||||
# python virtual environment directory
|
||||
virtualenv = /usr/local/taos/taosanode/venv/
|
||||
|
||||
[taosanode]
|
||||
# default app log file
|
||||
app-log = /var/log/taos/taosanode/taosanode.app.log
|
||||
|
||||
# model storage directory
|
||||
model-dir=/usr/local/taos/taosanode/model/
|
||||
|
||||
# default log level
|
||||
log-level = DEBUG
|
||||
```
|
||||
|
||||
**提示**
|
||||
请勿设置 `daemonize` 参数,该参数会导致 uWSGI 与 systemctl 冲突,从而无法正常启动。
|
||||
|
||||
|
||||
## ANode 基本操作
|
||||
### 管理 ANode
|
||||
#### 创建 ANode
|
||||
```sql
|
||||
CREATE ANODE {node_url}
|
||||
```
|
||||
node_url 是提供服务的 ANode 的 IP 和 PORT, 例如:`create anode 'http://localhost:6050'`。启动 ANode 以后如果不注册到 TDengine 集群中,无法提供正常的服务。不建议 ANode 注册到两个或多个集群中。
|
||||
|
||||
#### 查看 ANode
|
||||
列出集群中所有的数据分析节点,包括其 `FQDN`, `PORT`, `STATUS`。
|
||||
```sql
|
||||
SHOW ANODES;
|
||||
```
|
||||
|
||||
#### 查看提供的时序数据分析服务
|
||||
|
||||
```SQL
|
||||
SHOW ANODES FULL;
|
||||
```
|
||||
|
||||
#### 强制刷新 TDengine 集群中分析算法缓存
|
||||
```SQL
|
||||
UPDATE ANODE {node_id}
|
||||
UPDATE ALL ANODES
|
||||
```
|
||||
|
||||
#### 删除 ANode
|
||||
```sql
|
||||
DROP ANODE {anode_id}
|
||||
```
|
||||
删除 ANode 只是将 ANode 从 TDengine 集群中删除,管理 ANode 的启停仍然需要使用`systemctl`命令。
|
||||
|
||||
### 时序数据分析功能
|
||||
|
||||
#### 白噪声检查
|
||||
|
||||
平台提供 Restful的服务检测输入时间序列是否是白噪声时间序列(White Noise Data, WND),白噪声时间序列及随机数序列。
|
||||
此外,分析平台要求输入的数据不能是 , 因此针对的所有数据均默认进行 白噪声检查。当前白噪声检查采用通行的 `Ljung-Box`检验,`Ljung-Box` 统计量检查过程需要遍历整个输入序列并进行计算。
|
||||
如果用户能够明确输入序列一定不是白噪声序列,那么可以通过输入参数,指定预测之前忽略该检查,从而节省分析过程的 CPU 计算资源。
|
||||
同时支持独立地针对输入序列进行白噪声检测(该检测功能暂不独立对外开放)。
|
||||
|
||||
|
||||
#### 数据重采样和时间戳对齐
|
||||
|
||||
数据分析平台支持将输入的数据进行重采样的预处理,从而确保输出结果按照用户指定的等间隔进行处理。处理过程分为两种类别:
|
||||
|
||||
- 数据时间戳对齐。由于真实数据时间可能并非严格按照查询指定的时间戳输入。此时数据平台将自动将数据的时间间隔按照指定的时间间隔进行对齐。例如有输入时间序列:[11, 22, 29, 41],用户指定时间间隔为 10,那么该序列将被对齐重整为以下序列 [10, 20, 30, 40]。
|
||||
- 数据时间重采样。用户输入的时间序列其采样频率超过了指定的查询需要获得结果的时间间隔,例如输入原始数据是 5, 但是输出结果的频率是 10. [0, 5, 10, 15, 20, 25, 30],那么该输入数据列将重采用为间隔 为 10 的输入序列,其结果如下 [0, 10, 20,30]。[5, 15, 25] 处的数据将被丢弃。
|
||||
|
||||
需要注意的是,数据输入平台不支持缺失数据补齐后进行的预测分析,如果输入时间序列数据[11, 22, 29, 49],并且用户要求的时间间隔为 10, 重整对齐后的序列是 [10, 20, 30, 50] 那么该序列进行预测分析将返回错误。
|
||||
|
||||
|
||||
#### 时序数据异常检测
|
||||
异常检测是针对输入的时序数据,使用预设或用户指定的算法确定时间序列中**可能**出现异常时间序列点,对于时间序列中若干个连续的异常点,将自动合并成为一个连续的(闭区间)异常窗口。对于只有单个点的场景,异常窗口窗口退化成为一个起始时间和结束时间相同的点。
|
||||
异常检测生成的异常窗口受检测算法和算法参数的共同影响,对于异常窗口范围内的数据,可以应用 TDengine 提供的聚合和标量函数进行查询或变换处理。
|
||||
对于输入时间序列 (1, 20), (2, 22), (3, 91), (4, 120), (5, 18), (6, 19)。系统检测到 (3, 91), (4, 120) 为异常点,那么返回的异常窗口是闭区间 [3, 4]。
|
||||
|
||||
|
||||
##### 语法
|
||||
|
||||
```SQL
|
||||
ANOMALY_WINDOW(column_name, option_expr)
|
||||
|
||||
option_expr: {"
|
||||
algo=expr1
|
||||
[,wncheck=1|0]
|
||||
[,expr2]
|
||||
"}
|
||||
```
|
||||
|
||||
1. `column`:进行时序数据异常检测的输入数据列,当前只支持单列输入,且只能是数值类型,不能是字符类型(例如:`NCHAR` `VARCHAR` `VARBINARY`等类型),**不支持函数表达式**。
|
||||
2. `options`:字符串。其中使用 K/V 调用异常检测的算法,及与算法相关的参数。采用 逗号分隔的K/V字符串表示,其中的字符串不需要使用单引号、双引号、或转意号等符号,不能使用中文及其他宽字符。例如:`algo=ksigma, k=2` 表示进行异常检测的算法是 ksigma,该算法接受的输入参数是 2。
|
||||
3. 异常检测的结果可以作为外层查询的子查询输入,在 `SELECT` 子句中使用的聚合函数或标量函数与其他类型的窗口查询相同。
|
||||
4. 输入数据默认进行白噪声检查,如果检查结果是输入数据是白噪声,将不会有任何(异常)窗口信息返回。
|
||||
|
||||
**参数说明**
|
||||
|参数|含义|默认值|
|
||||
|---|---|---|
|
||||
|algo|异常检测调用的算法|iqr|
|
||||
|wncheck|对输入数据列是否进行白噪声检查|取值为0或者1,默认值为 1,表示进行白噪声检查|
|
||||
|
||||
异常检测的返回结果以窗口的形式呈现,因此窗口查询相关的伪列在这种场景下仍然可用。可以使用的伪列如下:
|
||||
1. `_WSTART`: 异常窗口开始时间戳
|
||||
2. `_WEND`:异常窗口结束时间戳
|
||||
3. `_WDURATION`:异常窗口持续时间
|
||||
|
||||
**示例**
|
||||
```SQL
|
||||
--- 使用 iqr 算法进行异常检测,检测列 i32 列。
|
||||
SELECT _wstart, _wend, SUM(i32)
|
||||
FROM ai.atb
|
||||
ANOMALY_WINDOW(i32, "algo=iqr");
|
||||
|
||||
--- 使用 ksigma 算法进行异常检测,输入参数 k 值为 2,检测列 i32 列
|
||||
SELECT _wstart, _wend, SUM(i32)
|
||||
FROM ai.atb
|
||||
ANOMALY_WINDOW(i32, "algo=ksigma,k=2");
|
||||
```
|
||||
|
||||
```
|
||||
taos> SELECT _wstart, _wend, count(*) FROM ai.atb ANOMAYL_WINDOW(i32);
|
||||
_wstart | _wend | count(*) |
|
||||
============================================================================
|
||||
2020-01-01 00:00:16.000 | 2020-01-01 00:00:16.001 | 1 |
|
||||
Query OK, 1 row(s) in set (0.028946s)
|
||||
```
|
||||
|
||||
|
||||
**可用异常检测算法**
|
||||
- iqr
|
||||
- ksigma
|
||||
- grubbs
|
||||
- lof
|
||||
- shesd
|
||||
- tac
|
||||
|
||||
|
||||
#### 时序数据预测
|
||||
数据预测以一段训练数据作为输入,预测接下来一个连续时间区间内,时序数据的趋势。
|
||||
|
||||
##### 语法
|
||||
```SQL
|
||||
FORECAST(column_expr, option_expr)
|
||||
|
||||
option_expr: {"
|
||||
algo=expr1
|
||||
[,wncheck=1|0]
|
||||
[,conf=conf_val]
|
||||
[,every=every_val]
|
||||
[,rows=rows_val]
|
||||
[,start=start_ts_val]
|
||||
[,expr2]
|
||||
"}
|
||||
|
||||
```
|
||||
1. `column_expr`:预测的时序数据列。与异常检测相同,只支持数值类型输入。
|
||||
2. `options`:异常检测函数的参数,使用规则与 anomaly_window 相同。预测还支持`conf`, `every`, `rows`, `start`, `rows` 几个参数,其含义如下:
|
||||
|
||||
**参数说明**
|
||||
|
||||
|参数|含义|默认值|
|
||||
|---|---|---|
|
||||
|algo|预测分析使用的算法|holtwinters|
|
||||
|wncheck|白噪声(white noise data)检查|默认值为 1,0 表示不进行检查|
|
||||
|conf|预测数据的置信区间范围 ,取值范围[0, 100]|95|
|
||||
|every|预测数据的采样间隔|输入数据的采样间隔|
|
||||
|start|预测结果的开始时间戳|输入数据最后一个时间戳加上一个采样时间段|
|
||||
|rows|预测结果的记录数|10|
|
||||
|
||||
1. 预测查询结果新增了三个伪列,具体如下: `_FROWTS`:预测结果的时间戳、`_FLOW`:置信区间下界、`_FHIGH`:置信区间上界, 对于没有置信区间的预测算法,其置信区间同预测结果
|
||||
2. 更改参数 `START`:返回预测结果的起始时间,改变这个起始时间不会影响返回的预测数值,只影响起始时间。
|
||||
3. `EVERY`:可以与输入数据的采样频率不同。采样频率只能低于或等于输入数据采样频率,不能**高于**输入数据的采样频率。
|
||||
4. 对于某些不需要计算置信区间的算法,即使指定了置信区间,返回的结果中其上下界退化成为一个点。
|
||||
|
||||
**示例**
|
||||
|
||||
```SQL
|
||||
--- 使用 arima 算法进行预测,预测结果是 10 条记录(默认值),数据进行白噪声检查,默认置信区间 95%.
|
||||
SELECT _flow, _fhigh, _frowts, FORECAST(i32, "algo=arima")
|
||||
FROM ai.ftb;
|
||||
|
||||
--- 使用 arima 算法进行预测,输入数据的是周期数据,每10个采样点是一个周期。返回置信区间是 95%.
|
||||
SELECT _flow, _fhigh, _frowts, FORECAST(i32, "algo=arima,alpha=95,period=10")
|
||||
FROM ai.ftb;
|
||||
```
|
||||
```
|
||||
taos> select _flow, _fhigh, _frowts, forecast(i32) from ai.ftb;
|
||||
_flow | _fhigh | _frowts | forecast(i32) |
|
||||
========================================================================================
|
||||
10.5286684 | 41.8038254 | 2020-01-01 00:01:35.001 | 26 |
|
||||
-21.9861946 | 83.3938904 | 2020-01-01 00:01:36.001 | 30 |
|
||||
-78.5686035 | 144.6729126 | 2020-01-01 00:01:37.001 | 33 |
|
||||
-154.9797363 | 230.3057709 | 2020-01-01 00:01:38.001 | 37 |
|
||||
-253.9852905 | 337.6083984 | 2020-01-01 00:01:39.001 | 41 |
|
||||
-375.7857971 | 466.4594727 | 2020-01-01 00:01:40.001 | 45 |
|
||||
-514.8043823 | 622.4426270 | 2020-01-01 00:01:41.001 | 53 |
|
||||
-680.6343994 | 796.2861328 | 2020-01-01 00:01:42.001 | 57 |
|
||||
-868.4956665 | 992.8603516 | 2020-01-01 00:01:43.001 | 62 |
|
||||
-1076.1566162 | 1214.4498291 | 2020-01-01 00:01:44.001 | 69 |
|
||||
```
|
||||
|
||||
|
||||
**可用预测算法**
|
||||
- arima
|
||||
- holtwinters
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 49 KiB |
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
|
@ -30,6 +30,7 @@ database_option: {
|
|||
| SINGLE_STABLE {0 | 1}
|
||||
| TABLE_PREFIX value
|
||||
| TABLE_SUFFIX value
|
||||
| DNODES value
|
||||
| TSDB_PAGESIZE value
|
||||
| WAL_LEVEL {1 | 2}
|
||||
| WAL_FSYNC_PERIOD value
|
||||
|
@ -70,6 +71,7 @@ database_option: {
|
|||
- TABLE_PREFIX:当其为正值时,在决定把一个表分配到哪个 vgroup 时要忽略表名中指定长度的前缀;当其为负值时,在决定把一个表分配到哪个 vgroup 时只使用表名中指定长度的前缀;例如,假定表名为 "v30001",当 TSDB_PREFIX = 2 时 使用 "0001" 来决定分配到哪个 vgroup ,当 TSDB_PREFIX = -2 时使用 "v3" 来决定分配到哪个 vgroup
|
||||
- TABLE_SUFFIX:当其为正值时,在决定把一个表分配到哪个 vgroup 时要忽略表名中指定长度的后缀;当其为负值时,在决定把一个表分配到哪个 vgroup 时只使用表名中指定长度的后缀;例如,假定表名为 "v30001",当 TSDB_SUFFIX = 2 时 使用 "v300" 来决定分配到哪个 vgroup ,当 TSDB_SUFFIX = -2 时使用 "01" 来决定分配到哪个 vgroup。
|
||||
- TSDB_PAGESIZE:一个 VNODE 中时序数据存储引擎的页大小,单位为 KB,默认为 4 KB。范围为 1 到 16384,即 1 KB到 16 MB。
|
||||
- DNODES:指定 VNODE 所在的 DNODE 列表,如 '1,2,3',以逗号区分且字符间不能有空格,仅企业版支持。
|
||||
- WAL_LEVEL:WAL 级别,默认为 1。
|
||||
- 1:写 WAL,但不执行 fsync。
|
||||
- 2:写 WAL,而且执行 fsync。
|
||||
|
|
|
@ -26,6 +26,7 @@ Node.js 连接器目前仅支持 WebSocket 连接器, 其通过 taosAdapter
|
|||
|
||||
| Node.js 连接器 版本 | 主要变化 | TDengine 版本 |
|
||||
| :------------------: | :----------------------: | :----------------: |
|
||||
| 3.1.1 | 优化了数据传输性能 | 3.3.2.0 及更高版本 |
|
||||
| 3.1.0 | 新版本发布,支持 WebSocket 连接 | 3.2.0.0 及更高版本 |
|
||||
|
||||
## 处理异常
|
||||
|
|
|
@ -81,6 +81,13 @@ typedef enum {
|
|||
TSDB_SML_TIMESTAMP_NANO_SECONDS,
|
||||
} TSDB_SML_TIMESTAMP_TYPE;
|
||||
|
||||
typedef enum TAOS_FIELD_T {
|
||||
TAOS_FIELD_COL = 1,
|
||||
TAOS_FIELD_TAG,
|
||||
TAOS_FIELD_QUERY,
|
||||
TAOS_FIELD_TBNAME,
|
||||
} TAOS_FIELD_T;
|
||||
|
||||
typedef struct taosField {
|
||||
char name[65];
|
||||
int8_t type;
|
||||
|
@ -95,6 +102,15 @@ typedef struct TAOS_FIELD_E {
|
|||
int32_t bytes;
|
||||
} TAOS_FIELD_E;
|
||||
|
||||
typedef struct TAOS_FIELD_STB {
|
||||
char name[65];
|
||||
int8_t type;
|
||||
uint8_t precision;
|
||||
uint8_t scale;
|
||||
int32_t bytes;
|
||||
TAOS_FIELD_T field_type;
|
||||
} TAOS_FIELD_STB;
|
||||
|
||||
#ifdef WINDOWS
|
||||
#define DLL_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
|
@ -195,13 +211,6 @@ DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
|
|||
|
||||
typedef void TAOS_STMT2;
|
||||
|
||||
typedef enum TAOS_FIELD_T {
|
||||
TAOS_FIELD_COL = 1,
|
||||
TAOS_FIELD_TAG,
|
||||
TAOS_FIELD_QUERY,
|
||||
TAOS_FIELD_TBNAME,
|
||||
} TAOS_FIELD_T;
|
||||
|
||||
typedef struct TAOS_STMT2_OPTION {
|
||||
int64_t reqid;
|
||||
bool singleStbInsert;
|
||||
|
@ -232,7 +241,9 @@ DLL_EXPORT int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows);
|
|||
DLL_EXPORT int taos_stmt2_close(TAOS_STMT2 *stmt);
|
||||
DLL_EXPORT int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert);
|
||||
DLL_EXPORT int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields);
|
||||
DLL_EXPORT int taos_stmt2_get_stb_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_STB **fields);
|
||||
DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields);
|
||||
DLL_EXPORT void taos_stmt2_free_stb_fields(TAOS_STMT2 *stmt, TAOS_FIELD_STB *fields);
|
||||
DLL_EXPORT TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt);
|
||||
DLL_EXPORT char *taos_stmt2_error(TAOS_STMT2 *stmt);
|
||||
|
||||
|
@ -251,17 +262,17 @@ DLL_EXPORT int64_t taos_affected_rows64(TAOS_RES *res);
|
|||
DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
|
||||
DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
|
||||
DLL_EXPORT int taos_print_row_with_size(char *str, uint32_t size, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
|
||||
DLL_EXPORT void taos_stop_query(TAOS_RES *res);
|
||||
DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
|
||||
DLL_EXPORT int taos_is_null_by_column(TAOS_RES *res, int columnIndex, bool result[], int *rows);
|
||||
DLL_EXPORT bool taos_is_update_query(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
|
||||
DLL_EXPORT int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows);
|
||||
DLL_EXPORT int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData);
|
||||
DLL_EXPORT int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex);
|
||||
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT void taos_reset_current_db(TAOS *taos);
|
||||
DLL_EXPORT int taos_print_row_with_size(char *str, uint32_t size, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
|
||||
DLL_EXPORT void taos_stop_query(TAOS_RES *res);
|
||||
DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
|
||||
DLL_EXPORT int taos_is_null_by_column(TAOS_RES *res, int columnIndex, bool result[], int *rows);
|
||||
DLL_EXPORT bool taos_is_update_query(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
|
||||
DLL_EXPORT int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows);
|
||||
DLL_EXPORT int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData);
|
||||
DLL_EXPORT int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex);
|
||||
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT void taos_reset_current_db(TAOS *taos);
|
||||
|
||||
DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res);
|
||||
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
|
||||
|
|
|
@ -194,10 +194,10 @@ extern int32_t tsMinIntervalTime;
|
|||
extern int32_t tsMaxInsertBatchRows;
|
||||
|
||||
// build info
|
||||
extern char version[];
|
||||
extern char compatible_version[];
|
||||
extern char gitinfo[];
|
||||
extern char buildinfo[];
|
||||
extern char td_version[];
|
||||
extern char td_compatible_version[];
|
||||
extern char td_gitinfo[];
|
||||
extern char td_buildinfo[];
|
||||
|
||||
// lossy
|
||||
extern char tsLossyColumns[];
|
||||
|
|
|
@ -1337,6 +1337,7 @@ typedef struct {
|
|||
char* sql;
|
||||
int8_t withArbitrator;
|
||||
int8_t encryptAlgorithm;
|
||||
char dnodeListStr[TSDB_DNODE_LIST_LEN];
|
||||
} SCreateDbReq;
|
||||
|
||||
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
|
||||
|
|
|
@ -238,12 +238,26 @@ typedef struct {
|
|||
case TSDB_DATA_TYPE_UBIGINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_FLOAT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
|
||||
case TSDB_DATA_TYPE_FLOAT: { \
|
||||
int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
|
||||
if (n >= (_outputBytes)) { \
|
||||
n = snprintf(_output, (int32_t)(_outputBytes), "%.7e", *(float *)(_input)); \
|
||||
if (n >= (_outputBytes)) { \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
|
||||
} \
|
||||
} \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_DOUBLE: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
|
||||
} \
|
||||
case TSDB_DATA_TYPE_DOUBLE: { \
|
||||
int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
|
||||
if (n >= (_outputBytes)) { \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%.15e", *(double *)(_input)); \
|
||||
if (n >= (_outputBytes)) { \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
|
||||
} \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
case TSDB_DATA_TYPE_UINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \
|
||||
break; \
|
||||
|
|
|
@ -72,6 +72,7 @@ typedef struct SDatabaseOptions {
|
|||
int8_t compressionLevel;
|
||||
int8_t encryptAlgorithm;
|
||||
int32_t daysPerFile;
|
||||
char dnodeListStr[TSDB_DNODE_LIST_LEN];
|
||||
char encryptAlgorithmStr[TSDB_ENCRYPT_ALGO_STR_LEN];
|
||||
SValueNode* pDaysPerFile;
|
||||
int32_t fsyncPeriod;
|
||||
|
|
|
@ -65,7 +65,7 @@ typedef struct SParseCsvCxt {
|
|||
const char* pLastSqlPos; // the location of the last parsed sql
|
||||
} SParseCsvCxt;
|
||||
|
||||
typedef void(*setQueryFn)(int64_t);
|
||||
typedef void (*setQueryFn)(int64_t);
|
||||
|
||||
typedef struct SParseContext {
|
||||
uint64_t requestId;
|
||||
|
@ -147,6 +147,7 @@ int32_t qBindStmtColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, c
|
|||
int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen,
|
||||
int32_t colIdx, int32_t rowNum);
|
||||
int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD_E** fields);
|
||||
int32_t qBuildStmtStbColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_STB** fields);
|
||||
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields);
|
||||
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
|
||||
TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen);
|
||||
|
|
|
@ -70,7 +70,8 @@ typedef struct SActiveCheckpointInfo SActiveCheckpointInfo;
|
|||
#define SSTREAM_TASK_NEED_CONVERT_VER 2
|
||||
#define SSTREAM_TASK_SUBTABLE_CHANGED_VER 3
|
||||
|
||||
extern int32_t streamMetaId;
|
||||
extern int32_t streamMetaRefPool;
|
||||
extern int32_t streamTaskRefPool;
|
||||
|
||||
enum {
|
||||
STREAM_STATUS__NORMAL = 0,
|
||||
|
@ -258,6 +259,7 @@ typedef struct STaskId {
|
|||
typedef struct SStreamTaskId {
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
int64_t refId;
|
||||
const char* idStr;
|
||||
} SStreamTaskId;
|
||||
|
||||
|
@ -291,7 +293,6 @@ typedef struct SStreamStatus {
|
|||
int8_t schedStatus;
|
||||
int8_t statusBackup;
|
||||
int32_t schedIdleTime; // idle time before invoke again
|
||||
int32_t timerActive; // timer is active
|
||||
int64_t lastExecTs; // last exec time stamp
|
||||
int32_t inScanHistorySentinel;
|
||||
bool appendTranstateBlock; // has append the transfer state data block already
|
||||
|
@ -454,7 +455,6 @@ struct SStreamTask {
|
|||
|
||||
// the followings attributes don't be serialized
|
||||
SScanhistorySchedInfo schedHistoryInfo;
|
||||
int32_t refCnt;
|
||||
int32_t transferStateAlignCnt;
|
||||
struct SStreamMeta* pMeta;
|
||||
SSHashObj* pNameMap;
|
||||
|
@ -546,7 +546,7 @@ typedef int32_t (*__state_trans_user_fn)(SStreamTask*, void* param);
|
|||
|
||||
int32_t tNewStreamTask(int64_t streamId, int8_t taskLevel, SEpSet* pEpset, bool fillHistory, int64_t triggerParam,
|
||||
SArray* pTaskList, bool hasFillhistory, int8_t subtableWithoutMd5, SStreamTask** pTask);
|
||||
void tFreeStreamTask(SStreamTask* pTask);
|
||||
void tFreeStreamTask(void* pTask);
|
||||
int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||
int32_t streamTaskInit(SStreamTask* pTask, SStreamMeta* pMeta, SMsgCb* pMsgCb, int64_t ver);
|
||||
|
@ -664,6 +664,8 @@ void streamTaskResetStatus(SStreamTask* pTask);
|
|||
void streamTaskSetStatusReady(SStreamTask* pTask);
|
||||
ETaskStatus streamTaskGetPrevStatus(const SStreamTask* pTask);
|
||||
const char* streamTaskGetExecType(int32_t type);
|
||||
int32_t streamTaskAllocRefId(SStreamTask* pTask, int64_t** pRefId);
|
||||
void streamTaskFreeRefId(int64_t* pRefId);
|
||||
|
||||
bool streamTaskUpdateEpsetInfo(SStreamTask* pTask, SArray* pNodeList);
|
||||
void streamTaskResetUpstreamStageInfo(SStreamTask* pTask);
|
||||
|
@ -752,16 +754,15 @@ int32_t streamMetaRegisterTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTa
|
|||
int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t taskId);
|
||||
int32_t streamMetaGetNumOfTasks(SStreamMeta* pMeta);
|
||||
int32_t streamMetaAcquireTaskNoLock(SStreamMeta* pMeta, int64_t streamId, int32_t taskId, SStreamTask** pTask);
|
||||
int32_t streamMetaAcquireTaskUnsafe(SStreamMeta* pMeta, STaskId* pId, SStreamTask** pTask);
|
||||
int32_t streamMetaAcquireTask(SStreamMeta* pMeta, int64_t streamId, int32_t taskId, SStreamTask** pTask);
|
||||
void streamMetaReleaseTask(SStreamMeta* pMeta, SStreamTask* pTask);
|
||||
int32_t streamMetaAcquireOneTask(SStreamTask* pTask);
|
||||
void streamMetaClear(SStreamMeta* pMeta);
|
||||
void streamMetaInitBackend(SStreamMeta* pMeta);
|
||||
int32_t streamMetaCommit(SStreamMeta* pMeta);
|
||||
int64_t streamMetaGetLatestCheckpointId(SStreamMeta* pMeta);
|
||||
void streamMetaNotifyClose(SStreamMeta* pMeta);
|
||||
void streamMetaStartHb(SStreamMeta* pMeta);
|
||||
bool streamMetaTaskInTimer(SStreamMeta* pMeta);
|
||||
int32_t streamMetaAddTaskLaunchResult(SStreamMeta* pMeta, int64_t streamId, int32_t taskId, int64_t startTs,
|
||||
int64_t endTs, bool ready);
|
||||
int32_t streamMetaInitStartInfo(STaskStartInfo* pStartInfo);
|
||||
|
|
|
@ -352,6 +352,8 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x039A)
|
||||
#define TSDB_CODE_MND_ENCRYPT_NOT_ALLOW_CHANGE TAOS_DEF_ERROR_CODE(0, 0x039B)
|
||||
#define TSDB_CODE_MND_INVALID_WAL_LEVEL TAOS_DEF_ERROR_CODE(0, 0x039C)
|
||||
#define TSDB_CODE_MND_INVALID_DNODE_LIST_FMT TAOS_DEF_ERROR_CODE(0, 0x039D)
|
||||
#define TSDB_CODE_MND_DNODE_LIST_REPEAT TAOS_DEF_ERROR_CODE(0, 0x039E)
|
||||
|
||||
// mnode-node
|
||||
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0)
|
||||
|
|
|
@ -453,6 +453,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_CACHE_MODEL_LAST_ROW 1
|
||||
#define TSDB_CACHE_MODEL_LAST_VALUE 2
|
||||
#define TSDB_CACHE_MODEL_BOTH 3
|
||||
#define TSDB_DNODE_LIST_LEN 256
|
||||
#define TSDB_ENCRYPT_ALGO_STR_LEN 16
|
||||
#define TSDB_ENCRYPT_ALGO_NONE_STR "none"
|
||||
#define TSDB_ENCRYPT_ALGO_SM4_STR "sm4"
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern char version[];
|
||||
extern char compatible_version[];
|
||||
extern char gitinfo[];
|
||||
extern char gitinfoOfInternal[];
|
||||
extern char buildinfo[];
|
||||
extern char td_version[];
|
||||
extern char td_compatible_version[];
|
||||
extern char td_gitinfo[];
|
||||
extern char td_gitinfoOfInternal[];
|
||||
extern char td_buildinfo[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -10,6 +10,10 @@ else()
|
|||
add_library(taos SHARED ${CLIENT_SRC})
|
||||
endif()
|
||||
|
||||
if(${TD_DARWIN})
|
||||
target_compile_options(taos PRIVATE -Wno-error=deprecated-non-prototype)
|
||||
endif()
|
||||
|
||||
INCLUDE_DIRECTORIES(jni)
|
||||
|
||||
target_include_directories(
|
||||
|
@ -46,6 +50,11 @@ set_target_properties(
|
|||
)
|
||||
|
||||
add_library(taos_static STATIC ${CLIENT_SRC})
|
||||
|
||||
if(${TD_DARWIN})
|
||||
target_compile_options(taos_static PRIVATE -Wno-error=deprecated-non-prototype)
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
taos_static
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client"
|
||||
|
|
|
@ -222,6 +222,7 @@ int stmtSetTbTags2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *tags);
|
|||
int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx);
|
||||
int stmtGetTagFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
|
||||
int stmtGetColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
|
||||
int stmtGetStbColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_STB **fields);
|
||||
int stmtGetParamNum2(TAOS_STMT2 *stmt, int *nums);
|
||||
int stmtGetParamTbName(TAOS_STMT2 *stmt, int *nums);
|
||||
int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert);
|
||||
|
|
|
@ -375,7 +375,7 @@ int32_t openTransporter(const char *user, const char *auth, int32_t numOfThread,
|
|||
rpcInit.startReadTimer = 1;
|
||||
rpcInit.readTimeout = tsReadTimeout;
|
||||
|
||||
int32_t code = taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
int32_t code = taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tscError("invalid version string.");
|
||||
return code;
|
||||
|
|
|
@ -1700,7 +1700,7 @@ static int32_t buildConnectMsg(SRequestObj* pRequest, SMsgSendInfo** pMsgSendInf
|
|||
tstrncpy(connectReq.app, appInfo.appName, sizeof(connectReq.app));
|
||||
tstrncpy(connectReq.user, pObj->user, sizeof(connectReq.user));
|
||||
tstrncpy(connectReq.passwd, pObj->pass, sizeof(connectReq.passwd));
|
||||
tstrncpy(connectReq.sVer, version, sizeof(connectReq.sVer));
|
||||
tstrncpy(connectReq.sVer, td_version, sizeof(connectReq.sVer));
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
|
||||
void* pReq = taosMemoryMalloc(contLen);
|
||||
|
@ -1770,19 +1770,15 @@ void updateTargetEpSet(SMsgSendInfo* pSendInfo, STscObj* pTscObj, SRpcMsg* pMsg,
|
|||
}
|
||||
}
|
||||
|
||||
int32_t doProcessMsgFromServer(void* param) {
|
||||
AsyncArg* arg = (AsyncArg*)param;
|
||||
SRpcMsg* pMsg = &arg->msg;
|
||||
SEpSet* pEpSet = arg->pEpset;
|
||||
|
||||
int32_t doProcessMsgFromServerImpl(SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||
SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle;
|
||||
if (pMsg->info.ahandle == NULL) {
|
||||
tscError("doProcessMsgFromServer pMsg->info.ahandle == NULL");
|
||||
taosMemoryFree(arg->pEpset);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosMemoryFree(arg);
|
||||
taosMemoryFree(pEpSet);
|
||||
return TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
STscObj* pTscObj = NULL;
|
||||
|
||||
STraceId* trace = &pMsg->info.traceId;
|
||||
|
@ -1802,10 +1798,9 @@ int32_t doProcessMsgFromServer(void* param) {
|
|||
if (TSDB_CODE_SUCCESS != taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId)) {
|
||||
tscError("doProcessMsgFromServer taosReleaseRef failed");
|
||||
}
|
||||
taosMemoryFree(arg->pEpset);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosMemoryFree(pEpSet);
|
||||
destroySendMsgInfo(pSendInfo);
|
||||
taosMemoryFree(arg);
|
||||
return TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||
}
|
||||
pTscObj = pRequest->pTscObj;
|
||||
|
@ -1844,20 +1839,24 @@ int32_t doProcessMsgFromServer(void* param) {
|
|||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
destroySendMsgInfo(pSendInfo);
|
||||
|
||||
taosMemoryFree(arg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t doProcessMsgFromServer(void* param) {
|
||||
AsyncArg* arg = (AsyncArg*)param;
|
||||
int32_t code = doProcessMsgFromServerImpl(&arg->msg, arg->pEpset);
|
||||
taosMemoryFree(arg);
|
||||
return code;
|
||||
}
|
||||
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||
int32_t code = 0;
|
||||
SEpSet* tEpSet = NULL;
|
||||
if (pEpSet != NULL) {
|
||||
tEpSet = taosMemoryCalloc(1, sizeof(SEpSet));
|
||||
if (NULL == tEpSet) {
|
||||
pMsg->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
destroySendMsgInfo(pMsg->info.ahandle);
|
||||
return;
|
||||
code = terrno;
|
||||
pMsg->code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
(void)memcpy((void*)tEpSet, (void*)pEpSet, sizeof(SEpSet));
|
||||
}
|
||||
|
@ -1879,21 +1878,25 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
|
||||
AsyncArg* arg = taosMemoryCalloc(1, sizeof(AsyncArg));
|
||||
if (NULL == arg) {
|
||||
pMsg->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(tEpSet);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
destroySendMsgInfo(pMsg->info.ahandle);
|
||||
return;
|
||||
code = terrno;
|
||||
pMsg->code = code;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
arg->msg = *pMsg;
|
||||
arg->pEpset = tEpSet;
|
||||
|
||||
if (0 != taosAsyncExec(doProcessMsgFromServer, arg, NULL)) {
|
||||
tscError("failed to sched msg to tsc, tsc ready to quit");
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosMemoryFree(arg->pEpset);
|
||||
destroySendMsgInfo(pMsg->info.ahandle);
|
||||
if ((code = taosAsyncExec(doProcessMsgFromServer, arg, NULL)) != 0) {
|
||||
pMsg->code = code;
|
||||
taosMemoryFree(arg);
|
||||
goto _exit;
|
||||
}
|
||||
return;
|
||||
_exit:
|
||||
tscError("failed to sched msg to tsc since %s", tstrerror(code));
|
||||
code = doProcessMsgFromServerImpl(pMsg, tEpSet);
|
||||
if (code != 0) {
|
||||
tscError("failed to sched msg to tsc, tsc ready quit");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2573,7 +2576,7 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de
|
|||
rpcInit.connLimitNum = connLimitNum;
|
||||
rpcInit.timeToGetConn = tsTimeToGetAvailableConn;
|
||||
rpcInit.readTimeout = tsReadTimeout;
|
||||
if (TSDB_CODE_SUCCESS != taosVersionStrToInt(version, &(rpcInit.compatibilityVer))) {
|
||||
if (TSDB_CODE_SUCCESS != taosVersionStrToInt(td_version, &rpcInit.compatibilityVer)) {
|
||||
tscError("faild to convert taos version from str to int, errcode:%s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ void taos_cleanup(void) {
|
|||
taosCloseRef(id);
|
||||
|
||||
nodesDestroyAllocatorSet();
|
||||
// cleanupAppInfo();
|
||||
// cleanupAppInfo();
|
||||
rpcCleanup();
|
||||
tscDebug("rpc cleanup");
|
||||
|
||||
|
@ -388,7 +388,6 @@ void taos_free_result(TAOS_RES *res) {
|
|||
tDeleteMqBatchMetaRsp(&pRsp->batchMetaRsp);
|
||||
}
|
||||
taosMemoryFree(pRsp);
|
||||
|
||||
}
|
||||
|
||||
void taos_kill_query(TAOS *taos) {
|
||||
|
@ -484,7 +483,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) {
|
||||
return taos_print_row_with_size(str, INT32_MAX, row, fields, num_fields);
|
||||
}
|
||||
int taos_print_row_with_size(char *str, uint32_t size, TAOS_ROW row, TAOS_FIELD *fields, int num_fields){
|
||||
int taos_print_row_with_size(char *str, uint32_t size, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) {
|
||||
int32_t len = 0;
|
||||
for (int i = 0; i < num_fields; ++i) {
|
||||
if (i > 0 && len < size - 1) {
|
||||
|
@ -589,7 +588,7 @@ int taos_print_row_with_size(char *str, uint32_t size, TAOS_ROW row, TAOS_FIELD
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (len < size){
|
||||
if (len < size) {
|
||||
str[len] = 0;
|
||||
}
|
||||
|
||||
|
@ -670,7 +669,7 @@ const char *taos_data_type(int type) {
|
|||
}
|
||||
}
|
||||
|
||||
const char *taos_get_client_info() { return version; }
|
||||
const char *taos_get_client_info() { return td_version; }
|
||||
|
||||
// return int32_t
|
||||
int taos_affected_rows(TAOS_RES *res) {
|
||||
|
@ -2082,7 +2081,7 @@ int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) {
|
|||
}
|
||||
|
||||
int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields) {
|
||||
if (stmt == NULL || NULL == count) {
|
||||
if (stmt == NULL || count == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
|
@ -2103,12 +2102,28 @@ int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count,
|
|||
}
|
||||
}
|
||||
|
||||
int taos_stmt2_get_stb_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_STB **fields) {
|
||||
if (stmt == NULL || count == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtGetStbColFields2(stmt, count, fields);
|
||||
}
|
||||
|
||||
void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields) {
|
||||
(void)stmt;
|
||||
if (!fields) return;
|
||||
taosMemoryFree(fields);
|
||||
}
|
||||
|
||||
DLL_EXPORT void taos_stmt2_free_stb_fields(TAOS_STMT2 *stmt, TAOS_FIELD_STB *fields) {
|
||||
(void)stmt;
|
||||
if (!fields) return;
|
||||
taosMemoryFree(fields);
|
||||
}
|
||||
|
||||
TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt) {
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
|
@ -2144,4 +2159,4 @@ int taos_set_conn_mode(TAOS *taos, int mode, int value) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
char *getBuildInfo() { return buildinfo; }
|
||||
char *getBuildInfo() { return td_buildinfo; }
|
||||
|
|
|
@ -80,8 +80,8 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
goto End;
|
||||
}
|
||||
|
||||
if ((code = taosCheckVersionCompatibleFromStr(version, connectRsp.sVer, 3)) != 0) {
|
||||
tscError("version not compatible. client version: %s, server version: %s", version, connectRsp.sVer);
|
||||
if ((code = taosCheckVersionCompatibleFromStr(td_version, connectRsp.sVer, 3)) != 0) {
|
||||
tscError("version not compatible. client version: %s, server version: %s", td_version, connectRsp.sVer);
|
||||
goto End;
|
||||
}
|
||||
|
||||
|
|
|
@ -1068,6 +1068,34 @@ static int stmtFetchColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int stmtFetchStbColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_STB** fields) {
|
||||
if (pStmt->errCode != TSDB_CODE_SUCCESS) {
|
||||
return pStmt->errCode;
|
||||
}
|
||||
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
tscError("invalid operation to get query column fileds");
|
||||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
}
|
||||
|
||||
STableDataCxt** pDataBlock = NULL;
|
||||
|
||||
if (pStmt->sql.stbInterlaceMode) {
|
||||
pDataBlock = &pStmt->sql.siInfo.pDataCtx;
|
||||
} else {
|
||||
pDataBlock =
|
||||
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (NULL == pDataBlock) {
|
||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
STMT_ERR_RET(qBuildStmtStbColFields(*pDataBlock, fieldNum, fields));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
/*
|
||||
SArray* stmtGetFreeCol(STscStmt2* pStmt, int32_t* idx) {
|
||||
while (true) {
|
||||
|
@ -1808,7 +1836,7 @@ _return:
|
|||
return code;
|
||||
}
|
||||
|
||||
int stmtGetColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) {
|
||||
int stmtParseColFields2(TAOS_STMT2* stmt) {
|
||||
int32_t code = 0;
|
||||
STscStmt2* pStmt = (STscStmt2*)stmt;
|
||||
int32_t preCode = pStmt->errCode;
|
||||
|
@ -1842,8 +1870,6 @@ int stmtGetColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) {
|
|||
STMT_ERRI_JRET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
STMT_ERRI_JRET(stmtFetchColFields2(stmt, nums, fields));
|
||||
|
||||
_return:
|
||||
|
||||
pStmt->errCode = preCode;
|
||||
|
@ -1851,6 +1877,24 @@ _return:
|
|||
return code;
|
||||
}
|
||||
|
||||
int stmtGetColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) {
|
||||
int32_t code = stmtParseColFields2(stmt);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return stmtFetchColFields2(stmt, nums, fields);
|
||||
}
|
||||
|
||||
int stmtGetStbColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_STB** fields) {
|
||||
int32_t code = stmtParseColFields2(stmt);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return stmtFetchStbColFields2(stmt, nums, fields);
|
||||
}
|
||||
|
||||
int stmtGetParamNum2(TAOS_STMT2* stmt, int* nums) {
|
||||
STscStmt2* pStmt = (STscStmt2*)stmt;
|
||||
|
||||
|
|
|
@ -675,10 +675,10 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
|||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "os version", info.version, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "os machine", info.machine, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "version", version, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "compatible_version", compatible_version, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "gitinfo", gitinfo, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "buildinfo", buildinfo, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "version", td_version, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "compatible_version", td_compatible_version, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "gitinfo", td_gitinfo, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_CHECK_RETURN(cfgAddString(pCfg, "buildinfo", td_buildinfo, CFG_SCOPE_BOTH, CFG_DYN_NONE));
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
@ -221,10 +221,9 @@ int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t
|
|||
}
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "memory", tmp), NULL, _exit);
|
||||
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "version", version), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "buildInfo", buildinfo), NULL, _exit);
|
||||
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "gitInfo", gitinfo), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "version", td_version), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "buildInfo", td_buildinfo), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "gitInfo", td_gitinfo), NULL, _exit);
|
||||
|
||||
TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashSig", signum), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tjsonAddIntegerToObject(pJson, "crashTs", taosGetTimestampUs()), NULL, _exit);
|
||||
|
|
|
@ -3874,6 +3874,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
|
|||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->s3ChunkSize));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->s3KeepLocal));
|
||||
TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->s3Compact));
|
||||
TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dnodeListStr));
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
|
@ -3962,6 +3963,10 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq)
|
|||
TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->s3Compact));
|
||||
}
|
||||
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dnodeListStr));
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
_exit:
|
||||
|
|
|
@ -297,12 +297,13 @@ static void dmPrintArgs(int32_t argc, char const *argv[]) {
|
|||
static void dmGenerateGrant() { mndGenerateMachineCode(); }
|
||||
|
||||
static void dmPrintVersion() {
|
||||
printf("%s\n%sd version: %s compatible_version: %s\n", TD_PRODUCT_NAME, CUS_PROMPT, version, compatible_version);
|
||||
printf("git: %s\n", gitinfo);
|
||||
printf("%s\n%sd version: %s compatible_version: %s\n", TD_PRODUCT_NAME, CUS_PROMPT, td_version,
|
||||
td_compatible_version);
|
||||
printf("git: %s\n", td_gitinfo);
|
||||
#ifdef TD_ENTERPRISE
|
||||
printf("gitOfInternal: %s\n", gitinfoOfInternal);
|
||||
printf("gitOfInternal: %s\n", td_gitinfoOfInternal);
|
||||
#endif
|
||||
printf("build: %s\n", buildinfo);
|
||||
printf("build: %s\n", td_buildinfo);
|
||||
}
|
||||
|
||||
static void dmPrintHelp() {
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
aux_source_directory(src MGMT_SNODE)
|
||||
add_library(mgmt_snode STATIC ${MGMT_SNODE})
|
||||
|
||||
if(${TD_DARWIN})
|
||||
target_compile_options(mgmt_snode PRIVATE -Wno-error=deprecated-non-prototype)
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
mgmt_snode
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
aux_source_directory(src MGMT_VNODE)
|
||||
add_library(mgmt_vnode STATIC ${MGMT_VNODE})
|
||||
|
||||
if(${TD_DARWIN})
|
||||
target_compile_options(mgmt_vnode PRIVATE -Wno-error=deprecated-non-prototype)
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
mgmt_vnode
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
|
|
|
@ -741,7 +741,7 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
int32_t vgId = alterReq.vgId;
|
||||
dInfo(
|
||||
"vgId:%d,vnode management handle msgType:%s, start to alter vnode replica:%d selfIndex:%d leanerReplica:%d "
|
||||
"vgId:%d, vnode management handle msgType:%s, start to alter vnode replica:%d selfIndex:%d leanerReplica:%d "
|
||||
"learnerSelfIndex:%d strict:%d changeVersion:%d",
|
||||
vgId, TMSG_INFO(pMsg->msgType), alterReq.replica, alterReq.selfIndex, alterReq.learnerReplica,
|
||||
alterReq.learnerSelfIndex, alterReq.strict, alterReq.changeVersion);
|
||||
|
|
|
@ -138,9 +138,9 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
pRpc->info.handle, pRpc->contLen, pRpc->code, pRpc->info.ahandle, pRpc->info.refId);
|
||||
|
||||
int32_t svrVer = 0;
|
||||
code = taosVersionStrToInt(version, &svrVer);
|
||||
code = taosVersionStrToInt(td_version, &svrVer);
|
||||
if (code != 0) {
|
||||
dError("failed to convert version string:%s to int, code:%d", version, code);
|
||||
dError("failed to convert version string:%s to int, code:%d", td_version, code);
|
||||
goto _OVER;
|
||||
}
|
||||
if ((code = taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) != 0) {
|
||||
|
@ -434,8 +434,8 @@ int32_t dmInitClient(SDnode *pDnode) {
|
|||
rpcInit.startReadTimer = 1;
|
||||
rpcInit.readTimeout = tsReadTimeout;
|
||||
|
||||
if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) {
|
||||
dError("failed to convert version string:%s to int", version);
|
||||
if (taosVersionStrToInt(td_version, &rpcInit.compatibilityVer) != 0) {
|
||||
dError("failed to convert version string:%s to int", td_version);
|
||||
}
|
||||
|
||||
pTrans->clientRpc = rpcOpen(&rpcInit);
|
||||
|
@ -483,8 +483,8 @@ int32_t dmInitStatusClient(SDnode *pDnode) {
|
|||
rpcInit.startReadTimer = 0;
|
||||
rpcInit.readTimeout = 0;
|
||||
|
||||
if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) {
|
||||
dError("failed to convert version string:%s to int", version);
|
||||
if (taosVersionStrToInt(td_version, &rpcInit.compatibilityVer) != 0) {
|
||||
dError("failed to convert version string:%s to int", td_version);
|
||||
}
|
||||
|
||||
pTrans->statusRpc = rpcOpen(&rpcInit);
|
||||
|
@ -533,8 +533,8 @@ int32_t dmInitSyncClient(SDnode *pDnode) {
|
|||
rpcInit.startReadTimer = 1;
|
||||
rpcInit.readTimeout = tsReadTimeout;
|
||||
|
||||
if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) {
|
||||
dError("failed to convert version string:%s to int", version);
|
||||
if (taosVersionStrToInt(td_version, &rpcInit.compatibilityVer) != 0) {
|
||||
dError("failed to convert version string:%s to int", td_version);
|
||||
}
|
||||
|
||||
pTrans->syncRpc = rpcOpen(&rpcInit);
|
||||
|
@ -588,8 +588,8 @@ int32_t dmInitServer(SDnode *pDnode) {
|
|||
rpcInit.compressSize = tsCompressMsgSize;
|
||||
rpcInit.shareConnLimit = tsShareConnLimit * 16;
|
||||
|
||||
if (taosVersionStrToInt(version, &(rpcInit.compatibilityVer)) != 0) {
|
||||
dError("failed to convert version string:%s to int", version);
|
||||
if (taosVersionStrToInt(td_version, &rpcInit.compatibilityVer) != 0) {
|
||||
dError("failed to convert version string:%s to int", td_version);
|
||||
}
|
||||
|
||||
pTrans->serverRpc = rpcOpen(&rpcInit);
|
||||
|
|
|
@ -54,7 +54,7 @@ void TestClient::DoInit() {
|
|||
rpcInit.parent = this;
|
||||
// rpcInit.secret = (char*)secretEncrypt;
|
||||
// rpcInit.spi = 1;
|
||||
taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
|
||||
|
||||
clientRpc = rpcOpen(&rpcInit);
|
||||
ASSERT(clientRpc);
|
||||
|
|
|
@ -37,6 +37,7 @@ const char *mndGetDbStr(const char *src);
|
|||
const char *mndGetStableStr(const char *src);
|
||||
|
||||
int32_t mndProcessCompactDbReq(SRpcMsg *pReq);
|
||||
int32_t mndCheckDbDnodeList(SMnode *pMnode, char *db, char *dnodeListStr, SArray *dnodeList);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -35,9 +35,9 @@ void mndSortVnodeGid(SVgObj *pVgroup);
|
|||
int64_t mndGetVnodesMemory(SMnode *pMnode, int32_t dnodeId);
|
||||
int64_t mndGetVgroupMemory(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
|
||||
SArray *mndBuildDnodesArray(SMnode *, int32_t exceptDnodeId);
|
||||
SArray *mndBuildDnodesArray(SMnode *, int32_t exceptDnodeId, SArray *dnodeList);
|
||||
int32_t mndAllocSmaVgroup(SMnode *, SDbObj *pDb, SVgObj *pVgroup);
|
||||
int32_t mndAllocVgroup(SMnode *, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
int32_t mndAllocVgroup(SMnode *, SDbObj *pDb, SVgObj **ppVgroups, SArray *dnodeList);
|
||||
int32_t mndAddNewVgPrepareAction(SMnode *, STrans *pTrans, SVgObj *pVg);
|
||||
int32_t mndAddCreateVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid);
|
||||
int32_t mndAddAlterVnodeConfirmAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup);
|
||||
|
|
|
@ -462,8 +462,8 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
|||
if (pCfg->cacheLast < TSDB_CACHE_MODEL_NONE || pCfg->cacheLast > TSDB_CACHE_MODEL_BOTH) return code;
|
||||
if (pCfg->hashMethod != 1) return code;
|
||||
if (pCfg->replications > mndGetDnodeSize(pMnode)) {
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
return code;
|
||||
code = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (pCfg->walRetentionPeriod < TSDB_DB_MIN_WAL_RETENTION_PERIOD) return code;
|
||||
if (pCfg->walRetentionSize < TSDB_DB_MIN_WAL_RETENTION_SIZE) return code;
|
||||
|
@ -746,7 +746,7 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, SUserObj *pUser) {
|
||||
static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, SUserObj *pUser, SArray *dnodeList) {
|
||||
int32_t code = 0;
|
||||
SUserObj newUserObj = {0};
|
||||
SDbObj dbObj = {0};
|
||||
|
@ -823,7 +823,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
|||
}
|
||||
|
||||
SVgObj *pVgroups = NULL;
|
||||
if ((code = mndAllocVgroup(pMnode, &dbObj, &pVgroups)) != 0) {
|
||||
if ((code = mndAllocVgroup(pMnode, &dbObj, &pVgroups, dnodeList)) != 0) {
|
||||
mError("db:%s, failed to create, alloc vgroup failed, since %s", pCreate->db, terrstr());
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
@ -925,6 +925,17 @@ _exit:
|
|||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
#ifndef TD_ENTERPRISE
|
||||
int32_t mndCheckDbDnodeList(SMnode *pMnode, char *db, char *dnodeListStr, SArray *dnodeList) {
|
||||
if (dnodeListStr[0] != 0) {
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
return terrno;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
int32_t code = -1;
|
||||
|
@ -932,6 +943,10 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
|||
SDbObj *pDb = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
SCreateDbReq createReq = {0};
|
||||
SArray *dnodeList = NULL;
|
||||
|
||||
dnodeList = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(int32_t));
|
||||
TSDB_CHECK_NULL(dnodeList, code, lino, _OVER, TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
TAOS_CHECK_GOTO(tDeserializeSCreateDbReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER);
|
||||
#ifdef WINDOWS
|
||||
|
@ -975,9 +990,11 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
|||
|
||||
TAOS_CHECK_GOTO(mndCheckDbEncryptKey(pMnode, &createReq), &lino, _OVER);
|
||||
|
||||
TAOS_CHECK_GOTO(mndCheckDbDnodeList(pMnode, createReq.db, createReq.dnodeListStr, dnodeList), &lino, _OVER);
|
||||
|
||||
TAOS_CHECK_GOTO(mndAcquireUser(pMnode, pReq->info.conn.user, &pUser), &lino, _OVER);
|
||||
|
||||
TAOS_CHECK_GOTO(mndCreateDb(pMnode, pReq, &createReq, pUser), &lino, _OVER);
|
||||
TAOS_CHECK_GOTO(mndCreateDb(pMnode, pReq, &createReq, pUser, dnodeList), &lino, _OVER);
|
||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
SName name = {0};
|
||||
|
@ -994,6 +1011,7 @@ _OVER:
|
|||
mndReleaseDb(pMnode, pDb);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
tFreeSCreateDbReq(&createReq);
|
||||
taosArrayDestroy(dnodeList);
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
@ -1168,7 +1186,9 @@ static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
SVgObj *pVgroup = NULL;
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0, NULL);
|
||||
|
||||
TSDB_CHECK_NULL(pArray, code, lino, _err, TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
|
|
|
@ -1021,7 +1021,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
|||
}
|
||||
|
||||
// cluster info
|
||||
tstrncpy(pClusterInfo->version, version, sizeof(pClusterInfo->version));
|
||||
tstrncpy(pClusterInfo->version, td_version, sizeof(pClusterInfo->version));
|
||||
pClusterInfo->monitor_interval = tsMonitorInterval;
|
||||
pClusterInfo->connections_total = mndGetNumOfConnections(pMnode);
|
||||
pClusterInfo->dbs_total = sdbGetSize(pSdb, SDB_DB);
|
||||
|
|
|
@ -239,8 +239,8 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if ((code = taosCheckVersionCompatibleFromStr(connReq.sVer, version, 3)) != 0) {
|
||||
mGError("version not compatible. client version: %s, server version: %s", connReq.sVer, version);
|
||||
if ((code = taosCheckVersionCompatibleFromStr(connReq.sVer, td_version, 3)) != 0) {
|
||||
mGError("version not compatible. client version: %s, server version: %s", connReq.sVer, td_version);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -308,9 +308,9 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
|||
tstrncpy(connectRsp.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN);
|
||||
connectRsp.whiteListVer = pUser->ipWhiteListVer;
|
||||
|
||||
(void)strcpy(connectRsp.sVer, version);
|
||||
(void)snprintf(connectRsp.sDetailVer, sizeof(connectRsp.sDetailVer), "ver:%s\nbuild:%s\ngitinfo:%s", version,
|
||||
buildinfo, gitinfo);
|
||||
tstrncpy(connectRsp.sVer, td_version, sizeof(connectRsp.sVer));
|
||||
(void)snprintf(connectRsp.sDetailVer, sizeof(connectRsp.sDetailVer), "ver:%s\nbuild:%s\ngitinfo:%s", td_version,
|
||||
td_buildinfo, td_gitinfo);
|
||||
mndGetMnodeEpSet(pMnode, &connectRsp.epSet);
|
||||
|
||||
int32_t contLen = tSerializeSConnectRsp(NULL, 0, &connectRsp);
|
||||
|
@ -813,7 +813,7 @@ static int32_t mndProcessSvrVerReq(SRpcMsg *pReq) {
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SServerVerRsp rsp = {0};
|
||||
tstrncpy(rsp.ver, version, sizeof(rsp.ver));
|
||||
tstrncpy(rsp.ver, td_version, sizeof(rsp.ver));
|
||||
|
||||
int32_t contLen = tSerializeSServerVerRsp(NULL, 0, &rsp);
|
||||
if (contLen < 0) {
|
||||
|
|
|
@ -248,7 +248,7 @@ static int32_t doAddSinkTask(SStreamObj* pStream, SMnode* pMnode, SVgObj* pVgrou
|
|||
return code;
|
||||
}
|
||||
|
||||
mDebug("doAddSinkTask taskId:%s, vgId:%d, isFillHistory:%d", pTask->id.idStr, pVgroup->vgId, isFillhistory);
|
||||
mDebug("doAddSinkTask taskId:%s, %p vgId:%d, isFillHistory:%d", pTask->id.idStr, pTask, pVgroup->vgId, isFillhistory);
|
||||
|
||||
pTask->info.nodeId = pVgroup->vgId;
|
||||
pTask->info.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
@ -364,12 +364,13 @@ static int32_t buildSourceTask(SStreamObj* pStream, SEpSet* pEpset, bool isFillh
|
|||
static void addNewTaskList(SStreamObj* pStream) {
|
||||
SArray* pTaskList = taosArrayInit(0, POINTER_BYTES);
|
||||
if (taosArrayPush(pStream->tasks, &pTaskList) == NULL) {
|
||||
mError("failed to put array");
|
||||
mError("failed to put into array");
|
||||
}
|
||||
|
||||
if (pStream->conf.fillHistory) {
|
||||
pTaskList = taosArrayInit(0, POINTER_BYTES);
|
||||
if (taosArrayPush(pStream->pHTasksList, &pTaskList) == NULL) {
|
||||
mError("failed to put array");
|
||||
mError("failed to put into array");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +403,8 @@ static int32_t doAddSourceTask(SMnode* pMnode, SSubplan* plan, SStreamObj* pStre
|
|||
return code;
|
||||
}
|
||||
|
||||
mDebug("doAddSourceTask taskId:%s, vgId:%d, isFillHistory:%d", pTask->id.idStr, pVgroup->vgId, isFillhistory);
|
||||
mDebug("doAddSourceTask taskId:%s, %p vgId:%d, isFillHistory:%d", pTask->id.idStr, pTask, pVgroup->vgId,
|
||||
isFillhistory);
|
||||
|
||||
if (pStream->conf.fillHistory) {
|
||||
haltInitialTaskStatus(pTask, plan, isFillhistory);
|
||||
|
@ -512,19 +514,20 @@ static int32_t doAddAggTask(SStreamObj* pStream, SMnode* pMnode, SSubplan* plan,
|
|||
SSnodeObj* pSnode, bool isFillhistory, bool useTriggerParam) {
|
||||
int32_t code = 0;
|
||||
SStreamTask* pTask = NULL;
|
||||
const char* id = NULL;
|
||||
|
||||
code = buildAggTask(pStream, pEpset, isFillhistory, useTriggerParam, &pTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
id = pTask->id.idStr;
|
||||
if (pSnode != NULL) {
|
||||
code = mndAssignStreamTaskToSnode(pMnode, pTask, plan, pSnode);
|
||||
mDebug("doAddAggTask taskId:%s, snode id:%d, isFillHistory:%d", pTask->id.idStr, pSnode->id, isFillhistory);
|
||||
|
||||
mDebug("doAddAggTask taskId:%s, %p snode id:%d, isFillHistory:%d", id, pTask, pSnode->id, isFillhistory);
|
||||
} else {
|
||||
code = mndAssignStreamTaskToVgroup(pMnode, pTask, plan, pVgroup);
|
||||
mDebug("doAddAggTask taskId:%s, vgId:%d, isFillHistory:%d", pTask->id.idStr, pVgroup->vgId, isFillhistory);
|
||||
mDebug("doAddAggTask taskId:%s, %p vgId:%d, isFillHistory:%d", id, pTask, pVgroup->vgId, isFillhistory);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -678,7 +681,7 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
|||
if (numOfPlanLevel > 1 || externalTargetDB || multiTarget || pStream->fixedSinkVgId) {
|
||||
// add extra sink
|
||||
hasExtraSink = true;
|
||||
int32_t code = addSinkTask(pMnode, pStream, pEpset);
|
||||
code = addSinkTask(pMnode, pStream, pEpset);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -115,9 +115,9 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) {
|
|||
snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "memory", tmp), &lino, _OVER);
|
||||
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "version", version), &lino, _OVER);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "buildInfo", buildinfo), &lino, _OVER);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "gitInfo", gitinfo), &lino, _OVER);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "version", td_version), &lino, _OVER);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "buildInfo", td_buildinfo), &lino, _OVER);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "gitInfo", td_gitinfo), &lino, _OVER);
|
||||
TAOS_CHECK_GOTO(tjsonAddStringToObject(pJson, "email", pMgmt->email), &lino, _OVER);
|
||||
|
||||
mndBuildRuntimeInfo(pMnode, pJson);
|
||||
|
|
|
@ -717,11 +717,28 @@ static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2
|
|||
SDnodeObj *pDnode = pObj;
|
||||
SArray *pArray = p1;
|
||||
int32_t exceptDnodeId = *(int32_t *)p2;
|
||||
SArray *dnodeList = p3;
|
||||
|
||||
if (exceptDnodeId == pDnode->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (dnodeList != NULL) {
|
||||
int32_t dnodeListSize = taosArrayGetSize(dnodeList);
|
||||
if (dnodeListSize > 0) {
|
||||
bool inDnodeList = false;
|
||||
for (int32_t index = 0; index < dnodeListSize; ++index) {
|
||||
int32_t dnodeId = *(int32_t *)taosArrayGet(dnodeList, index);
|
||||
if (pDnode->id == dnodeId) {
|
||||
inDnodeList = true;
|
||||
}
|
||||
}
|
||||
if (!inDnodeList) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
bool online = mndIsDnodeOnline(pDnode, curMs);
|
||||
bool isMnode = mndIsMnode(pMnode, pDnode->id);
|
||||
|
@ -741,7 +758,7 @@ static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2
|
|||
return true;
|
||||
}
|
||||
|
||||
SArray *mndBuildDnodesArray(SMnode *pMnode, int32_t exceptDnodeId) {
|
||||
SArray *mndBuildDnodesArray(SMnode *pMnode, int32_t exceptDnodeId, SArray *dnodeList) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfDnodes = mndGetDnodeSize(pMnode);
|
||||
|
||||
|
@ -752,7 +769,7 @@ SArray *mndBuildDnodesArray(SMnode *pMnode, int32_t exceptDnodeId) {
|
|||
}
|
||||
|
||||
sdbTraverse(pSdb, SDB_DNODE, mndResetDnodesArrayFp, NULL, NULL, NULL);
|
||||
sdbTraverse(pSdb, SDB_DNODE, mndBuildDnodesArrayFp, pArray, &exceptDnodeId, NULL);
|
||||
sdbTraverse(pSdb, SDB_DNODE, mndBuildDnodesArrayFp, pArray, &exceptDnodeId, dnodeList);
|
||||
|
||||
mDebug("build %d dnodes array", (int32_t)taosArrayGetSize(pArray));
|
||||
for (int32_t i = 0; i < (int32_t)taosArrayGetSize(pArray); ++i) {
|
||||
|
@ -845,7 +862,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup
|
|||
|
||||
int32_t mndAllocSmaVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
int32_t code = 0;
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0, NULL);
|
||||
if (pArray == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
|
@ -868,7 +885,7 @@ int32_t mndAllocSmaVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups, SArray *dnodeList) {
|
||||
int32_t code = -1;
|
||||
SArray *pArray = NULL;
|
||||
SVgObj *pVgroups = NULL;
|
||||
|
@ -879,7 +896,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
pArray = mndBuildDnodesArray(pMnode, 0, dnodeList);
|
||||
if (pArray == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
|
@ -2062,7 +2079,7 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
|
|||
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t delDnodeId, bool force, bool unsafe) {
|
||||
int32_t code = 0;
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, delDnodeId);
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, delDnodeId, NULL);
|
||||
if (pArray == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
|
@ -3140,7 +3157,7 @@ int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgro
|
|||
int32_t code = -1;
|
||||
STrans *pTrans = NULL;
|
||||
SDbObj dbObj = {0};
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0, NULL);
|
||||
|
||||
int32_t numOfStreams = 0;
|
||||
if ((code = mndGetNumOfStreams(pMnode, pDb->name, &numOfStreams)) != 0) {
|
||||
|
@ -3506,7 +3523,7 @@ static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) {
|
|||
sdbRelease(pMnode->pSdb, pDnode);
|
||||
}
|
||||
|
||||
pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
pArray = mndBuildDnodesArray(pMnode, 0, NULL);
|
||||
if (pArray == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
|
|
|
@ -39,7 +39,7 @@ TEST_F(MndTestProfile, 01_ConnectMsg) {
|
|||
strcpy(connectReq.db, "");
|
||||
strcpy(connectReq.user, "root");
|
||||
strcpy(connectReq.passwd, secretEncrypt);
|
||||
strcpy(connectReq.sVer, version);
|
||||
strcpy(connectReq.sVer, td_version);
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
|
@ -76,7 +76,7 @@ TEST_F(MndTestProfile, 02_ConnectMsg_NotExistDB) {
|
|||
strcpy(connectReq.db, "not_exist_db");
|
||||
strcpy(connectReq.user, "root");
|
||||
strcpy(connectReq.passwd, secretEncrypt);
|
||||
strcpy(connectReq.sVer, version);
|
||||
strcpy(connectReq.sVer, td_version);
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
|
|
|
@ -64,7 +64,7 @@ TEST_F(MndTestShow, 03_ShowMsg_Conn) {
|
|||
strcpy(connectReq.db, "");
|
||||
strcpy(connectReq.user, "root");
|
||||
strcpy(connectReq.passwd, secretEncrypt);
|
||||
strcpy(connectReq.sVer, version);
|
||||
strcpy(connectReq.sVer, td_version);
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
|
|
|
@ -38,24 +38,23 @@ int32_t sndBuildStreamTask(SSnode *pSnode, SStreamTask *pTask, int64_t nextProce
|
|||
streamTaskOpenAllUpstreamInput(pTask);
|
||||
|
||||
streamTaskResetUpstreamStageInfo(pTask);
|
||||
streamSetupScheduleTrigger(pTask);
|
||||
|
||||
SCheckpointInfo *pChkInfo = &pTask->chkInfo;
|
||||
tqSetRestoreVersionInfo(pTask);
|
||||
|
||||
char *p = streamTaskGetStatus(pTask).name;
|
||||
if (pTask->info.fillHistory) {
|
||||
sndInfo("vgId:%d build stream task, s-task:%s, checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
sndInfo("vgId:%d build stream task, s-task:%s, %p checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
" nextProcessVer:%" PRId64
|
||||
" child id:%d, level:%d, status:%s fill-history:%d, related stream task:0x%x trigger:%" PRId64 " ms",
|
||||
SNODE_HANDLE, pTask->id.idStr, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
|
||||
SNODE_HANDLE, pTask->id.idStr, pTask, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
|
||||
pTask->info.selfChildId, pTask->info.taskLevel, p, pTask->info.fillHistory,
|
||||
(int32_t)pTask->streamTaskId.taskId, pTask->info.delaySchedParam);
|
||||
} else {
|
||||
sndInfo("vgId:%d build stream task, s-task:%s, checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
sndInfo("vgId:%d build stream task, s-task:%s, %p checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
" nextProcessVer:%" PRId64
|
||||
" child id:%d, level:%d, status:%s fill-history:%d, related fill-task:0x%x trigger:%" PRId64 " ms",
|
||||
SNODE_HANDLE, pTask->id.idStr, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
|
||||
SNODE_HANDLE, pTask->id.idStr, pTask, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
|
||||
pTask->info.selfChildId, pTask->info.taskLevel, p, pTask->info.fillHistory,
|
||||
(int32_t)pTask->hTaskInfo.id.taskId, pTask->info.delaySchedParam);
|
||||
}
|
||||
|
|
|
@ -238,13 +238,18 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
|
|||
}
|
||||
|
||||
static void tdRSmaTaskInit(SStreamMeta *pMeta, SRSmaInfoItem *pItem, SStreamTaskId *pId) {
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
SStreamTask *pTask = NULL;
|
||||
|
||||
streamMetaRLock(pMeta);
|
||||
SStreamTask **ppTask = (SStreamTask **)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (ppTask && *ppTask) {
|
||||
pItem->submitReqVer = (*ppTask)->chkInfo.checkpointVer;
|
||||
pItem->fetchResultVer = (*ppTask)->info.delaySchedParam;
|
||||
|
||||
int32_t code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code == 0) {
|
||||
pItem->submitReqVer = pTask->chkInfo.checkpointVer;
|
||||
pItem->fetchResultVer = pTask->info.delaySchedParam;
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
}
|
||||
|
||||
streamMetaRUnLock(pMeta);
|
||||
}
|
||||
|
||||
|
|
|
@ -765,7 +765,6 @@ int32_t tqBuildStreamTask(void* pTqObj, SStreamTask* pTask, int64_t nextProcessV
|
|||
}
|
||||
|
||||
streamTaskResetUpstreamStageInfo(pTask);
|
||||
streamSetupScheduleTrigger(pTask);
|
||||
|
||||
SCheckpointInfo* pChkInfo = &pTask->chkInfo;
|
||||
tqSetRestoreVersionInfo(pTask);
|
||||
|
@ -774,19 +773,19 @@ int32_t tqBuildStreamTask(void* pTqObj, SStreamTask* pTask, int64_t nextProcessV
|
|||
const char* pNext = streamTaskGetStatusStr(pTask->status.taskStatus);
|
||||
|
||||
if (pTask->info.fillHistory) {
|
||||
tqInfo("vgId:%d build stream task, s-task:%s, checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
tqInfo("vgId:%d build stream task, s-task:%s, %p checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
" nextProcessVer:%" PRId64
|
||||
" child id:%d, level:%d, cur-status:%s, next-status:%s fill-history:%d, related stream task:0x%x "
|
||||
"delaySched:%" PRId64 " ms, inputVer:%" PRId64,
|
||||
vgId, pTask->id.idStr, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
|
||||
vgId, pTask->id.idStr, pTask, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
|
||||
pTask->info.selfChildId, pTask->info.taskLevel, p, pNext, pTask->info.fillHistory,
|
||||
(int32_t)pTask->streamTaskId.taskId, pTask->info.delaySchedParam, nextProcessVer);
|
||||
} else {
|
||||
tqInfo("vgId:%d build stream task, s-task:%s, checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
tqInfo("vgId:%d build stream task, s-task:%s, %p checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
" nextProcessVer:%" PRId64
|
||||
" child id:%d, level:%d, cur-status:%s next-status:%s fill-history:%d, related fill-task:0x%x "
|
||||
"delaySched:%" PRId64 " ms, inputVer:%" PRId64,
|
||||
vgId, pTask->id.idStr, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
|
||||
vgId, pTask->id.idStr, pTask, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
|
||||
pTask->info.selfChildId, pTask->info.taskLevel, p, pNext, pTask->info.fillHistory,
|
||||
(int32_t)pTask->hTaskInfo.id.taskId, pTask->info.delaySchedParam, nextProcessVer);
|
||||
|
||||
|
|
|
@ -1113,12 +1113,20 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
|
|||
break;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
if ((pTask->info.taskLevel == TASK_LEVEL__SOURCE) && (pTask->exec.pExecutor != NULL)) {
|
||||
int32_t code = qUpdateTableListForStreamScanner(pTask->exec.pExecutor, tbUidList, isAdd);
|
||||
if (code != 0) {
|
||||
tqError("vgId:%d, s-task:%s update qualified table error for stream task", vgId, pTask->id.idStr);
|
||||
continue;
|
||||
int64_t refId = *(int64_t*)pIter;
|
||||
SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, refId);
|
||||
if (pTask != NULL) {
|
||||
int32_t taskId = pTask->id.taskId;
|
||||
|
||||
if ((pTask->info.taskLevel == TASK_LEVEL__SOURCE) && (pTask->exec.pExecutor != NULL)) {
|
||||
int32_t code = qUpdateTableListForStreamScanner(pTask->exec.pExecutor, tbUidList, isAdd);
|
||||
if (code != 0) {
|
||||
tqError("vgId:%d, s-task:0x%x update qualified table error for stream task", vgId, taskId);
|
||||
}
|
||||
}
|
||||
int32_t ret = taosReleaseRef(streamTaskRefPool, refId);
|
||||
if (ret) {
|
||||
tqError("vgId:%d release task refId failed, refId:%" PRId64, vgId, refId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ static void doStartScanWal(void* param, void* tmrId) {
|
|||
|
||||
SBuildScanWalMsgParam* pParam = (SBuildScanWalMsgParam*)param;
|
||||
|
||||
SStreamMeta* pMeta = taosAcquireRef(streamMetaId, pParam->metaId);
|
||||
SStreamMeta* pMeta = taosAcquireRef(streamMetaRefPool, pParam->metaId);
|
||||
if (pMeta == NULL) {
|
||||
tqError("metaRid:%" PRId64 " not valid now, stream meta has been freed", pParam->metaId);
|
||||
taosMemoryFree(pParam);
|
||||
|
@ -97,7 +97,7 @@ static void doStartScanWal(void* param, void* tmrId) {
|
|||
tqError("vgId:%d failed sched task to scan wal, code:%s", vgId, tstrerror(code));
|
||||
}
|
||||
|
||||
code = taosReleaseRef(streamMetaId, pParam->metaId);
|
||||
code = taosReleaseRef(streamMetaRefPool, pParam->metaId);
|
||||
if (code) {
|
||||
tqError("vgId:%d failed to release ref for streamMeta, rid:%" PRId64 " code:%s", vgId, pParam->metaId,
|
||||
tstrerror(code));
|
||||
|
|
|
@ -685,19 +685,21 @@ int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, b
|
|||
continue;
|
||||
}
|
||||
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
SStreamTask** ppTask = taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (ppTask == NULL) {
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
SStreamTask* pTask = NULL;
|
||||
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code != 0) {
|
||||
tqError("vgId:%d failed to acquire task:0x%x in retrieving progress", pMeta->vgId, pId->taskId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*ppTask)->info.taskLevel != TASK_LEVEL__SOURCE) {
|
||||
if (pTask->info.taskLevel != TASK_LEVEL__SOURCE) {
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
continue;
|
||||
}
|
||||
|
||||
// here we get the required stream source task
|
||||
SStreamTask* pTask = *ppTask;
|
||||
*fhFinished = !HAS_RELATED_FILLHISTORY_TASK(pTask);
|
||||
|
||||
int64_t ver = walReaderGetCurrentVer(pTask->exec.pWalReader);
|
||||
|
@ -713,6 +715,7 @@ int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, b
|
|||
SWalReader* pReader = walOpenReader(pTask->exec.pWalReader->pWal, NULL, 0);
|
||||
if (pReader == NULL) {
|
||||
tqError("failed to open wal reader to extract exec progress, vgId:%d", pMeta->vgId);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -738,6 +741,7 @@ int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, b
|
|||
}
|
||||
|
||||
walCloseReader(pReader);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
}
|
||||
|
||||
streamMetaRUnLock(pMeta);
|
||||
|
|
|
@ -138,13 +138,15 @@ int32_t tqStreamStartOneTaskAsync(SStreamMeta* pMeta, SMsgCb* cb, int64_t stream
|
|||
|
||||
// this is to process request from transaction, always return true.
|
||||
int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pMsg, bool restored) {
|
||||
int32_t vgId = pMeta->vgId;
|
||||
char* msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||
int32_t len = pMsg->contLen - sizeof(SMsgHead);
|
||||
SRpcMsg rsp = {.info = pMsg->info, .code = TSDB_CODE_SUCCESS};
|
||||
int64_t st = taosGetTimestampMs();
|
||||
bool updated = false;
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pMeta->vgId;
|
||||
char* msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||
int32_t len = pMsg->contLen - sizeof(SMsgHead);
|
||||
SRpcMsg rsp = {.info = pMsg->info, .code = TSDB_CODE_SUCCESS};
|
||||
int64_t st = taosGetTimestampMs();
|
||||
bool updated = false;
|
||||
int32_t code = 0;
|
||||
SStreamTask* pTask = NULL;
|
||||
SStreamTask* pHTask = NULL;
|
||||
|
||||
SStreamTaskNodeUpdateMsg req = {0};
|
||||
|
||||
|
@ -170,9 +172,9 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
|
|||
streamMetaWLock(pMeta);
|
||||
|
||||
// the task epset may be updated again and again, when replaying the WAL, the task may be in stop status.
|
||||
STaskId id = {.streamId = req.streamId, .taskId = req.taskId};
|
||||
SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (ppTask == NULL || *ppTask == NULL) {
|
||||
STaskId id = {.streamId = req.streamId, .taskId = req.taskId};
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code != 0) {
|
||||
tqError("vgId:%d failed to acquire task:0x%x when handling update task epset, it may have been dropped", vgId,
|
||||
req.taskId);
|
||||
rsp.code = TSDB_CODE_SUCCESS;
|
||||
|
@ -181,12 +183,13 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
|
|||
return rsp.code;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = *ppTask;
|
||||
const char* idstr = pTask->id.idStr;
|
||||
const char* idstr = pTask->id.idStr;
|
||||
|
||||
if (req.transId <= 0) {
|
||||
tqError("vgId:%d invalid update nodeEp task, transId:%d, discard", vgId, req.taskId);
|
||||
rsp.code = TSDB_CODE_SUCCESS;
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
taosArrayDestroy(req.pNodeList);
|
||||
|
@ -197,6 +200,8 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
|
|||
bool update = streamMetaInitUpdateTaskList(pMeta, req.transId);
|
||||
if (!update) {
|
||||
rsp.code = TSDB_CODE_SUCCESS;
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
taosArrayDestroy(req.pNodeList);
|
||||
|
@ -211,7 +216,10 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
|
|||
tqDebug("s-task:%s (vgId:%d) already update in transId:%d, discard the nodeEp update msg", idstr, vgId,
|
||||
req.transId);
|
||||
rsp.code = TSDB_CODE_SUCCESS;
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
taosArrayDestroy(req.pNodeList);
|
||||
return rsp.code;
|
||||
}
|
||||
|
@ -227,24 +235,23 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
|
|||
|
||||
streamTaskStopMonitorCheckRsp(&pTask->taskCheckInfo, pTask->id.idStr);
|
||||
|
||||
SStreamTask** ppHTask = NULL;
|
||||
if (HAS_RELATED_FILLHISTORY_TASK(pTask)) {
|
||||
ppHTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &pTask->hTaskInfo.id, sizeof(pTask->hTaskInfo.id));
|
||||
if (ppHTask == NULL || *ppHTask == NULL) {
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &pTask->hTaskInfo.id, &pHTask);
|
||||
if (code != 0) {
|
||||
tqError(
|
||||
"vgId:%d failed to acquire fill-history task:0x%x when handling update, may have been dropped already, rel "
|
||||
"stream task:0x%x",
|
||||
vgId, (uint32_t)pTask->hTaskInfo.id.taskId, req.taskId);
|
||||
CLEAR_RELATED_FILLHISTORY_TASK(pTask);
|
||||
} else {
|
||||
tqDebug("s-task:%s fill-history task update nodeEp along with stream task", (*ppHTask)->id.idStr);
|
||||
bool updateEpSet = streamTaskUpdateEpsetInfo(*ppHTask, req.pNodeList);
|
||||
tqDebug("s-task:%s fill-history task update nodeEp along with stream task", pHTask->id.idStr);
|
||||
bool updateEpSet = streamTaskUpdateEpsetInfo(pHTask, req.pNodeList);
|
||||
if (updateEpSet) {
|
||||
updated = updateEpSet;
|
||||
}
|
||||
|
||||
streamTaskResetStatus(*ppHTask);
|
||||
streamTaskStopMonitorCheckRsp(&(*ppHTask)->taskCheckInfo, (*ppHTask)->id.idStr);
|
||||
streamTaskResetStatus(pHTask);
|
||||
streamTaskStopMonitorCheckRsp(&pHTask->taskCheckInfo, pHTask->id.idStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,8 +263,8 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
|
|||
tqError("s-task:%s vgId:%d failed to save task, code:%s", idstr, vgId, tstrerror(code));
|
||||
}
|
||||
|
||||
if (ppHTask != NULL) {
|
||||
code = streamMetaSaveTask(pMeta, *ppHTask);
|
||||
if (pHTask != NULL) {
|
||||
code = streamMetaSaveTask(pMeta, pHTask);
|
||||
if (code) {
|
||||
tqError("s-task:%s vgId:%d failed to save related history task, code:%s", idstr, vgId, tstrerror(code));
|
||||
}
|
||||
|
@ -271,15 +278,17 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
|
|||
tqError("s-task:%s vgId:%d failed to stop task, code:%s", idstr, vgId, tstrerror(code));
|
||||
}
|
||||
|
||||
if (ppHTask != NULL) {
|
||||
code = streamTaskStop(*ppHTask);
|
||||
if (pHTask != NULL) {
|
||||
code = streamTaskStop(pHTask);
|
||||
if (code) {
|
||||
tqError("s-task:%s vgId:%d failed to stop related history task, code:%s", idstr, vgId, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
// keep info
|
||||
streamMetaAddIntoUpdateTaskList(pMeta, pTask, (ppHTask != NULL) ? (*ppHTask) : NULL, req.transId, st);
|
||||
streamMetaAddIntoUpdateTaskList(pMeta, pTask, (pHTask != NULL) ? (pHTask) : NULL, req.transId, st);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
streamMetaReleaseTask(pMeta, pHTask);
|
||||
|
||||
rsp.code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -643,7 +652,6 @@ int32_t tqStreamTaskProcessDeployReq(SStreamMeta* pMeta, SMsgCb* cb, int64_t sve
|
|||
if (code < 0) {
|
||||
tqError("failed to add s-task:0x%x into vgId:%d meta, existed:%d, code:%s", vgId, taskId, numOfTasks,
|
||||
tstrerror(code));
|
||||
tFreeStreamTask(pTask);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -673,7 +681,6 @@ int32_t tqStreamTaskProcessDeployReq(SStreamMeta* pMeta, SMsgCb* cb, int64_t sve
|
|||
}
|
||||
} else {
|
||||
tqWarn("vgId:%d failed to add s-task:0x%x, since already exists in meta store, total:%d", vgId, taskId, numOfTasks);
|
||||
tFreeStreamTask(pTask);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -681,25 +688,25 @@ int32_t tqStreamTaskProcessDeployReq(SStreamMeta* pMeta, SMsgCb* cb, int64_t sve
|
|||
|
||||
int32_t tqStreamTaskProcessDropReq(SStreamMeta* pMeta, char* msg, int32_t msgLen) {
|
||||
SVDropStreamTaskReq* pReq = (SVDropStreamTaskReq*)msg;
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pMeta->vgId;
|
||||
STaskId hTaskId = {0};
|
||||
SStreamTask* pTask = NULL;
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pMeta->vgId;
|
||||
STaskId hTaskId = {0};
|
||||
tqDebug("vgId:%d receive msg to drop s-task:0x%x", vgId, pReq->taskId);
|
||||
|
||||
streamMetaWLock(pMeta);
|
||||
|
||||
STaskId id = {.streamId = pReq->streamId, .taskId = pReq->taskId};
|
||||
SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if ((ppTask != NULL) && ((*ppTask) != NULL)) {
|
||||
int32_t unusedRetRef = streamMetaAcquireOneTask(*ppTask);
|
||||
SStreamTask* pTask = *ppTask;
|
||||
|
||||
STaskId id = {.streamId = pReq->streamId, .taskId = pReq->taskId};
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code == 0) {
|
||||
if (HAS_RELATED_FILLHISTORY_TASK(pTask)) {
|
||||
hTaskId.streamId = pTask->hTaskInfo.id.streamId;
|
||||
hTaskId.taskId = pTask->hTaskInfo.id.taskId;
|
||||
}
|
||||
|
||||
// clear the relationship, and then release the stream tasks, to avoid invalid accessing of already freed
|
||||
// related stream(history) task
|
||||
streamTaskSetRemoveBackendFiles(pTask);
|
||||
code = streamTaskClearHTaskAttr(pTask, pReq->resetRelHalt);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
|
@ -742,18 +749,19 @@ int32_t tqStreamTaskProcessDropReq(SStreamMeta* pMeta, char* msg, int32_t msgLen
|
|||
|
||||
int32_t tqStreamTaskProcessUpdateCheckpointReq(SStreamMeta* pMeta, bool restored, char* msg) {
|
||||
SVUpdateCheckpointInfoReq* pReq = (SVUpdateCheckpointInfoReq*)msg;
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pMeta->vgId;
|
||||
SStreamTask* pTask = NULL;
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pMeta->vgId;
|
||||
tqDebug("vgId:%d receive msg to update-checkpoint-info for s-task:0x%x", vgId, pReq->taskId);
|
||||
|
||||
streamMetaWLock(pMeta);
|
||||
|
||||
STaskId id = {.streamId = pReq->streamId, .taskId = pReq->taskId};
|
||||
SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
|
||||
if (ppTask != NULL && (*ppTask) != NULL) {
|
||||
code = streamTaskUpdateTaskCheckpointInfo(*ppTask, restored, pReq);
|
||||
STaskId id = {.streamId = pReq->streamId, .taskId = pReq->taskId};
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code == 0) {
|
||||
code = streamTaskUpdateTaskCheckpointInfo(pTask, restored, pReq);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
} else { // failed to get the task.
|
||||
int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta);
|
||||
tqError(
|
||||
|
@ -763,7 +771,6 @@ int32_t tqStreamTaskProcessUpdateCheckpointReq(SStreamMeta* pMeta, bool restored
|
|||
}
|
||||
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
// always return success when handling the requirement issued by mnode during transaction.
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -789,11 +796,6 @@ static int32_t restartStreamTasks(SStreamMeta* pMeta, bool isLeader) {
|
|||
tqInfo("vgId:%d tasks are all updated and stopped, restart all tasks, triggered by transId:%d, ts:%" PRId64, vgId,
|
||||
pMeta->updateInfo.completeTransId, pMeta->updateInfo.completeTs);
|
||||
|
||||
while (streamMetaTaskInTimer(pMeta)) {
|
||||
tqDebug("vgId:%d some tasks in timer, wait for 100ms and recheck", pMeta->vgId);
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
streamMetaWLock(pMeta);
|
||||
streamMetaClear(pMeta);
|
||||
|
||||
|
|
|
@ -144,6 +144,11 @@ target_link_libraries(
|
|||
|
||||
# SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin)
|
||||
add_executable(udfd src/udfd.c)
|
||||
|
||||
if(${TD_DARWIN})
|
||||
target_compile_options(udfd PRIVATE -Wno-error=deprecated-non-prototype)
|
||||
endif()
|
||||
|
||||
target_include_directories(
|
||||
udfd
|
||||
PUBLIC
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef struct SUdfdData {
|
|||
#ifdef WINDOWS
|
||||
HANDLE jobHandle;
|
||||
#endif
|
||||
int spawnErr;
|
||||
int32_t spawnErr;
|
||||
uv_pipe_t ctrlPipe;
|
||||
uv_async_t stopAsync;
|
||||
int32_t stopCalled;
|
||||
|
@ -51,15 +51,17 @@ typedef struct SUdfdData {
|
|||
SUdfdData udfdGlobal = {0};
|
||||
|
||||
int32_t udfStartUdfd(int32_t startDnodeId);
|
||||
void udfStopUdfd();
|
||||
void udfStopUdfd();
|
||||
|
||||
extern char **environ;
|
||||
|
||||
static int32_t udfSpawnUdfd(SUdfdData *pData);
|
||||
void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal);
|
||||
void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int32_t termSignal);
|
||||
static void udfUdfdCloseWalkCb(uv_handle_t *handle, void *arg);
|
||||
static void udfUdfdStopAsyncCb(uv_async_t *async);
|
||||
static void udfWatchUdfd(void *args);
|
||||
|
||||
void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) {
|
||||
void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int32_t termSignal) {
|
||||
fnInfo("udfd process exited with status %" PRId64 ", signal %d", exitStatus, termSignal);
|
||||
SUdfdData *pData = process->data;
|
||||
if (exitStatus == 0 && termSignal == 0 || atomic_load_32(&pData->stopCalled)) {
|
||||
|
@ -67,7 +69,7 @@ void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) {
|
|||
} else {
|
||||
fnInfo("udfd process restart");
|
||||
int32_t code = udfSpawnUdfd(pData);
|
||||
if(code != 0) {
|
||||
if (code != 0) {
|
||||
fnError("udfd process restart failed with code:%d", code);
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +77,8 @@ void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) {
|
|||
|
||||
static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
||||
fnInfo("start to init udfd");
|
||||
|
||||
int32_t err = 0;
|
||||
uv_process_options_t options = {0};
|
||||
|
||||
char path[PATH_MAX] = {0};
|
||||
|
@ -126,17 +130,17 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
|||
char thrdPoolSizeEnvItem[32] = {0};
|
||||
snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId);
|
||||
|
||||
float numCpuCores = 4;
|
||||
float numCpuCores = 4;
|
||||
int32_t code = taosGetCpuCores(&numCpuCores, false);
|
||||
if(code != 0) {
|
||||
fnError("failed to get cpu cores, code:%d", code);
|
||||
if (code != 0) {
|
||||
fnError("failed to get cpu cores, code:0x%x", code);
|
||||
}
|
||||
numCpuCores = TMAX(numCpuCores, 2);
|
||||
snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores * 2);
|
||||
snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int32_t)numCpuCores * 2);
|
||||
|
||||
char pathTaosdLdLib[512] = {0};
|
||||
size_t taosdLdLibPathLen = sizeof(pathTaosdLdLib);
|
||||
int ret = uv_os_getenv("LD_LIBRARY_PATH", pathTaosdLdLib, &taosdLdLibPathLen);
|
||||
char pathTaosdLdLib[512] = {0};
|
||||
size_t taosdLdLibPathLen = sizeof(pathTaosdLdLib);
|
||||
int32_t ret = uv_os_getenv("LD_LIBRARY_PATH", pathTaosdLdLib, &taosdLdLibPathLen);
|
||||
if (ret != UV_ENOBUFS) {
|
||||
taosdLdLibPathLen = strlen(pathTaosdLdLib);
|
||||
}
|
||||
|
@ -158,8 +162,8 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
|||
char *taosFqdnEnvItem = NULL;
|
||||
char *taosFqdn = getenv("TAOS_FQDN");
|
||||
if (taosFqdn != NULL) {
|
||||
int subLen = strlen(taosFqdn);
|
||||
int len = strlen("TAOS_FQDN=") + subLen + 1;
|
||||
int32_t subLen = strlen(taosFqdn);
|
||||
int32_t len = strlen("TAOS_FQDN=") + subLen + 1;
|
||||
taosFqdnEnvItem = taosMemoryMalloc(len);
|
||||
if (taosFqdnEnvItem != NULL) {
|
||||
tstrncpy(taosFqdnEnvItem, "TAOS_FQDN=", len);
|
||||
|
@ -171,11 +175,53 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
|||
}
|
||||
}
|
||||
|
||||
char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, ldLibPathEnvItem,taosFqdnEnvItem, NULL};
|
||||
char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, ldLibPathEnvItem, taosFqdnEnvItem, NULL};
|
||||
|
||||
options.env = envUdfd;
|
||||
char **envUdfdWithPEnv = NULL;
|
||||
if (environ != NULL) {
|
||||
int32_t lenEnvUdfd = ARRAY_SIZE(envUdfd);
|
||||
int32_t numEnviron = 0;
|
||||
while (environ[numEnviron] != NULL) {
|
||||
numEnviron++;
|
||||
}
|
||||
|
||||
int err = uv_spawn(&pData->loop, &pData->process, &options);
|
||||
envUdfdWithPEnv = (char **)taosMemoryCalloc(numEnviron + lenEnvUdfd, sizeof(char *));
|
||||
if (envUdfdWithPEnv == NULL) {
|
||||
err = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numEnviron; i++) {
|
||||
int32_t len = strlen(environ[i]) + 1;
|
||||
envUdfdWithPEnv[i] = (char *)taosMemoryCalloc(len, 1);
|
||||
if (envUdfdWithPEnv[i] == NULL) {
|
||||
err = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
tstrncpy(envUdfdWithPEnv[i], environ[i], len);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < lenEnvUdfd; i++) {
|
||||
if (envUdfd[i] != NULL) {
|
||||
int32_t len = strlen(envUdfd[i]) + 1;
|
||||
envUdfdWithPEnv[numEnviron + i] = (char *)taosMemoryCalloc(len, 1);
|
||||
if (envUdfdWithPEnv[numEnviron + i] == NULL) {
|
||||
err = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
tstrncpy(envUdfdWithPEnv[numEnviron + i], envUdfd[i], len);
|
||||
}
|
||||
}
|
||||
envUdfdWithPEnv[numEnviron + lenEnvUdfd - 1] = NULL;
|
||||
|
||||
options.env = envUdfdWithPEnv;
|
||||
} else {
|
||||
options.env = envUdfd;
|
||||
}
|
||||
|
||||
err = uv_spawn(&pData->loop, &pData->process, &options);
|
||||
pData->process.data = (void *)pData;
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -202,7 +248,21 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
|||
} else {
|
||||
fnInfo("udfd is initialized");
|
||||
}
|
||||
if(taosFqdnEnvItem) taosMemoryFree(taosFqdnEnvItem);
|
||||
|
||||
_OVER:
|
||||
if (taosFqdnEnvItem) {
|
||||
taosMemoryFree(taosFqdnEnvItem);
|
||||
}
|
||||
|
||||
if (envUdfdWithPEnv != NULL) {
|
||||
int32_t i = 0;
|
||||
while (envUdfdWithPEnv[i] != NULL) {
|
||||
taosMemoryFree(envUdfdWithPEnv[i]);
|
||||
i++;
|
||||
}
|
||||
taosMemoryFree(envUdfdWithPEnv);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -225,13 +285,13 @@ static void udfWatchUdfd(void *args) {
|
|||
TAOS_UV_CHECK_ERRNO(udfSpawnUdfd(pData));
|
||||
atomic_store_32(&pData->spawnErr, 0);
|
||||
(void)uv_barrier_wait(&pData->barrier);
|
||||
int num = uv_run(&pData->loop, UV_RUN_DEFAULT);
|
||||
int32_t num = uv_run(&pData->loop, UV_RUN_DEFAULT);
|
||||
fnInfo("udfd loop exit with %d active handles, line:%d", num, __LINE__);
|
||||
|
||||
uv_walk(&pData->loop, udfUdfdCloseWalkCb, NULL);
|
||||
num = uv_run(&pData->loop, UV_RUN_DEFAULT);
|
||||
fnInfo("udfd loop exit with %d active handles, line:%d", num, __LINE__);
|
||||
if(uv_loop_close(&pData->loop) != 0) {
|
||||
if (uv_loop_close(&pData->loop) != 0) {
|
||||
fnError("udfd loop close failed, lino:%d", __LINE__);
|
||||
}
|
||||
return;
|
||||
|
@ -240,7 +300,7 @@ _exit:
|
|||
if (terrno != 0) {
|
||||
(void)uv_barrier_wait(&pData->barrier);
|
||||
atomic_store_32(&pData->spawnErr, terrno);
|
||||
if(uv_loop_close(&pData->loop) != 0) {
|
||||
if (uv_loop_close(&pData->loop) != 0) {
|
||||
fnError("udfd loop close failed, lino:%d", __LINE__);
|
||||
}
|
||||
fnError("udfd thread exit with code:%d lino:%d", terrno, terrln);
|
||||
|
@ -271,10 +331,10 @@ int32_t udfStartUdfd(int32_t startDnodeId) {
|
|||
int32_t err = atomic_load_32(&pData->spawnErr);
|
||||
if (err != 0) {
|
||||
uv_barrier_destroy(&pData->barrier);
|
||||
if(uv_async_send(&pData->stopAsync) != 0) {
|
||||
if (uv_async_send(&pData->stopAsync) != 0) {
|
||||
fnError("start udfd: failed to send stop async");
|
||||
}
|
||||
if(uv_thread_join(&pData->thread)!= 0) {
|
||||
if (uv_thread_join(&pData->thread) != 0) {
|
||||
fnError("start udfd: failed to join udfd thread");
|
||||
}
|
||||
pData->needCleanUp = false;
|
||||
|
@ -299,10 +359,10 @@ void udfStopUdfd() {
|
|||
atomic_store_32(&pData->stopCalled, 1);
|
||||
pData->needCleanUp = false;
|
||||
uv_barrier_destroy(&pData->barrier);
|
||||
if(uv_async_send(&pData->stopAsync) != 0) {
|
||||
if (uv_async_send(&pData->stopAsync) != 0) {
|
||||
fnError("stop udfd: failed to send stop async");
|
||||
}
|
||||
if(uv_thread_join(&pData->thread) != 0) {
|
||||
if (uv_thread_join(&pData->thread) != 0) {
|
||||
fnError("stop udfd: failed to join udfd thread");
|
||||
}
|
||||
|
||||
|
@ -341,7 +401,7 @@ typedef void *QUEUE[2];
|
|||
#define QUEUE_NEXT_PREV(q) (QUEUE_PREV(QUEUE_NEXT(q)))
|
||||
|
||||
/* Public macros. */
|
||||
#define QUEUE_DATA(ptr, type, field) ((type *)((char *)(ptr)-offsetof(type, field)))
|
||||
#define QUEUE_DATA(ptr, type, field) ((type *)((char *)(ptr) - offsetof(type, field)))
|
||||
|
||||
/* Important note: mutating the list while QUEUE_FOREACH is
|
||||
* iterating over its elements results in undefined behavior.
|
||||
|
@ -434,8 +494,8 @@ typedef struct SUdfcProxy {
|
|||
QUEUE uvProcTaskQueue;
|
||||
|
||||
uv_mutex_t udfStubsMutex;
|
||||
SArray *udfStubs; // SUdfcFuncStub
|
||||
SArray *expiredUdfStubs; //SUdfcFuncStub
|
||||
SArray *udfStubs; // SUdfcFuncStub
|
||||
SArray *expiredUdfStubs; // SUdfcFuncStub
|
||||
|
||||
uv_mutex_t udfcUvMutex;
|
||||
int8_t initialized;
|
||||
|
@ -458,7 +518,7 @@ typedef struct SUdfcUvSession {
|
|||
typedef struct SClientUvTaskNode {
|
||||
SUdfcProxy *udfc;
|
||||
int8_t type;
|
||||
int errCode;
|
||||
int32_t errCode;
|
||||
|
||||
uv_pipe_t *pipe;
|
||||
|
||||
|
@ -516,7 +576,7 @@ enum {
|
|||
UDFC_STATE_STOPPING, // stopping after udfcClose
|
||||
};
|
||||
|
||||
void getUdfdPipeName(char *pipeName, int32_t size);
|
||||
void getUdfdPipeName(char *pipeName, int32_t size);
|
||||
int32_t encodeUdfSetupRequest(void **buf, const SUdfSetupRequest *setup);
|
||||
void *decodeUdfSetupRequest(const void *buf, SUdfSetupRequest *request);
|
||||
int32_t encodeUdfInterBuf(void **buf, const SUdfInterBuf *state);
|
||||
|
@ -801,12 +861,12 @@ void *decodeUdfResponse(const void *buf, SUdfResponse *rsp) {
|
|||
buf = decodeUdfTeardownResponse(buf, &rsp->teardownRsp);
|
||||
break;
|
||||
default:
|
||||
rsp->code = TSDB_CODE_UDF_INTERNAL_ERROR;
|
||||
rsp->code = TSDB_CODE_UDF_INTERNAL_ERROR;
|
||||
fnError("decode udf response, invalid udf response type %d", rsp->type);
|
||||
break;
|
||||
}
|
||||
if(buf == NULL) {
|
||||
rsp->code = terrno;
|
||||
if (buf == NULL) {
|
||||
rsp->code = terrno;
|
||||
fnError("decode udf response failed, code:0x%x", rsp->code);
|
||||
}
|
||||
return (void *)buf;
|
||||
|
@ -847,12 +907,12 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo
|
|||
udfBlock->numOfRows = block->info.rows;
|
||||
udfBlock->numOfCols = taosArrayGetSize(block->pDataBlock);
|
||||
udfBlock->udfCols = taosMemoryCalloc(taosArrayGetSize(block->pDataBlock), sizeof(SUdfColumn *));
|
||||
if((udfBlock->udfCols) == NULL) {
|
||||
if ((udfBlock->udfCols) == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
for (int32_t i = 0; i < udfBlock->numOfCols; ++i) {
|
||||
udfBlock->udfCols[i] = taosMemoryCalloc(1, sizeof(SUdfColumn));
|
||||
if(udfBlock->udfCols[i] == NULL) {
|
||||
if (udfBlock->udfCols[i] == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
SColumnInfoData *col = (SColumnInfoData *)taosArrayGet(block->pDataBlock, i);
|
||||
|
@ -866,18 +926,18 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo
|
|||
if (IS_VAR_DATA_TYPE(udfCol->colMeta.type)) {
|
||||
udfCol->colData.varLenCol.varOffsetsLen = sizeof(int32_t) * udfBlock->numOfRows;
|
||||
udfCol->colData.varLenCol.varOffsets = taosMemoryMalloc(udfCol->colData.varLenCol.varOffsetsLen);
|
||||
if(udfCol->colData.varLenCol.varOffsets == NULL) {
|
||||
if (udfCol->colData.varLenCol.varOffsets == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
memcpy(udfCol->colData.varLenCol.varOffsets, col->varmeta.offset, udfCol->colData.varLenCol.varOffsetsLen);
|
||||
udfCol->colData.varLenCol.payloadLen = colDataGetLength(col, udfBlock->numOfRows);
|
||||
udfCol->colData.varLenCol.payload = taosMemoryMalloc(udfCol->colData.varLenCol.payloadLen);
|
||||
if(udfCol->colData.varLenCol.payload == NULL) {
|
||||
if (udfCol->colData.varLenCol.payload == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
if (col->reassigned) {
|
||||
for (int32_t row = 0; row < udfCol->colData.numOfRows; ++row) {
|
||||
char* pColData = col->pData + col->varmeta.offset[row];
|
||||
char *pColData = col->pData + col->varmeta.offset[row];
|
||||
int32_t colSize = 0;
|
||||
if (col->info.type == TSDB_DATA_TYPE_JSON) {
|
||||
colSize = getJsonValueLen(pColData);
|
||||
|
@ -894,7 +954,7 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo
|
|||
udfCol->colData.fixLenCol.nullBitmapLen = BitmapLen(udfCol->colData.numOfRows);
|
||||
int32_t bitmapLen = udfCol->colData.fixLenCol.nullBitmapLen;
|
||||
udfCol->colData.fixLenCol.nullBitmap = taosMemoryMalloc(udfCol->colData.fixLenCol.nullBitmapLen);
|
||||
if(udfCol->colData.fixLenCol.nullBitmap == NULL) {
|
||||
if (udfCol->colData.fixLenCol.nullBitmap == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
char *bitmap = udfCol->colData.fixLenCol.nullBitmap;
|
||||
|
@ -927,11 +987,11 @@ int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block) {
|
|||
code = bdGetColumnInfoData(block, 0, &col);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
|
||||
for (int i = 0; i < udfCol->colData.numOfRows; ++i) {
|
||||
for (int32_t i = 0; i < udfCol->colData.numOfRows; ++i) {
|
||||
if (udfColDataIsNull(udfCol, i)) {
|
||||
colDataSetNULL(col, i);
|
||||
} else {
|
||||
char* data = udfColDataGetData(udfCol, i);
|
||||
char *data = udfColDataGetData(udfCol, i);
|
||||
code = colDataSetVal(col, i, data, false);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
|
@ -953,32 +1013,32 @@ int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SS
|
|||
}
|
||||
|
||||
// create the basic block info structure
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pInfo = input[i].columnData;
|
||||
SColumnInfoData d = {0};
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData *pInfo = input[i].columnData;
|
||||
SColumnInfoData d = {0};
|
||||
d.info = pInfo->info;
|
||||
|
||||
TAOS_CHECK_GOTO(blockDataAppendColInfo(output, &d), &lino, _exit);
|
||||
}
|
||||
|
||||
TAOS_CHECK_GOTO(blockDataEnsureCapacity(output, numOfRows), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(blockDataEnsureCapacity(output, numOfRows), &lino, _exit);
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pDest = taosArrayGet(output->pDataBlock, i);
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData *pDest = taosArrayGet(output->pDataBlock, i);
|
||||
|
||||
SColumnInfoData* pColInfoData = input[i].columnData;
|
||||
SColumnInfoData *pColInfoData = input[i].columnData;
|
||||
TAOS_CHECK_GOTO(colDataAssign(pDest, pColInfoData, input[i].numOfRows, &output->info), &lino, _exit);
|
||||
|
||||
if (input[i].numOfRows < numOfRows) {
|
||||
int32_t startRow = input[i].numOfRows;
|
||||
int expandRows = numOfRows - startRow;
|
||||
bool isNull = colDataIsNull_s(pColInfoData, (input+i)->numOfRows - 1);
|
||||
int32_t expandRows = numOfRows - startRow;
|
||||
bool isNull = colDataIsNull_s(pColInfoData, (input + i)->numOfRows - 1);
|
||||
if (isNull) {
|
||||
colDataSetNNULL(pDest, startRow, expandRows);
|
||||
} else {
|
||||
char* src = colDataGetData(pColInfoData, (input + i)->numOfRows - 1);
|
||||
for (int j = 0; j < expandRows; ++j) {
|
||||
TAOS_CHECK_GOTO(colDataSetVal(pDest, startRow+j, src, false), &lino, _exit);
|
||||
char *src = colDataGetData(pColInfoData, (input + i)->numOfRows - 1);
|
||||
for (int32_t j = 0; j < expandRows; ++j) {
|
||||
TAOS_CHECK_GOTO(colDataSetVal(pDest, startRow + j, src, false), &lino, _exit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1000,7 +1060,7 @@ int32_t convertDataBlockToScalarParm(SSDataBlock *input, SScalarParam *output) {
|
|||
output->numOfRows = input->info.rows;
|
||||
|
||||
output->columnData = taosMemoryMalloc(sizeof(SColumnInfoData));
|
||||
if(output->columnData == NULL) {
|
||||
if (output->columnData == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
memcpy(output->columnData, taosArrayGet(input->pDataBlock, 0), sizeof(SColumnInfoData));
|
||||
|
@ -1012,11 +1072,11 @@ int32_t convertDataBlockToScalarParm(SSDataBlock *input, SScalarParam *output) {
|
|||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// memory layout |---SUdfAggRes----|-----final result-----|---inter result----|
|
||||
typedef struct SUdfAggRes {
|
||||
int8_t finalResNum;
|
||||
int8_t interResNum;
|
||||
int8_t finalResNum;
|
||||
int8_t interResNum;
|
||||
int32_t interResBufLen;
|
||||
char *finalResBuf;
|
||||
char *interResBuf;
|
||||
char *finalResBuf;
|
||||
char *interResBuf;
|
||||
} SUdfAggRes;
|
||||
|
||||
void onUdfcPipeClose(uv_handle_t *handle);
|
||||
|
@ -1026,8 +1086,8 @@ bool isUdfcUvMsgComplete(SClientConnBuf *connBuf);
|
|||
void udfcUvHandleRsp(SClientUvConn *conn);
|
||||
void udfcUvHandleError(SClientUvConn *conn);
|
||||
void onUdfcPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf);
|
||||
void onUdfcPipeWrite(uv_write_t *write, int status);
|
||||
void onUdfcPipeConnect(uv_connect_t *connect, int status);
|
||||
void onUdfcPipeWrite(uv_write_t *write, int32_t status);
|
||||
void onUdfcPipeConnect(uv_connect_t *connect, int32_t status);
|
||||
int32_t udfcInitializeUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvTaskNode *uvTask);
|
||||
int32_t udfcQueueUvTask(SClientUvTaskNode *uvTask);
|
||||
int32_t udfcStartUvTask(SClientUvTaskNode *uvTask);
|
||||
|
@ -1037,7 +1097,7 @@ void udfStopAsyncCb(uv_async_t *async);
|
|||
void constructUdfService(void *argsThread);
|
||||
int32_t udfcRunUdfUvTask(SClientUdfTask *task, int8_t uvTaskType);
|
||||
int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle);
|
||||
int compareUdfcFuncSub(const void *elem1, const void *elem2);
|
||||
int32_t compareUdfcFuncSub(const void *elem1, const void *elem2);
|
||||
int32_t doTeardownUdf(UdfcFuncHandle handle);
|
||||
|
||||
int32_t callUdf(UdfcFuncHandle handle, int8_t callType, SSDataBlock *input, SUdfInterBuf *state, SUdfInterBuf *state2,
|
||||
|
@ -1062,9 +1122,9 @@ int32_t udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pRes
|
|||
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx);
|
||||
int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock);
|
||||
|
||||
void cleanupNotExpiredUdfs();
|
||||
void cleanupExpiredUdfs();
|
||||
int compareUdfcFuncSub(const void *elem1, const void *elem2) {
|
||||
void cleanupNotExpiredUdfs();
|
||||
void cleanupExpiredUdfs();
|
||||
int32_t compareUdfcFuncSub(const void *elem1, const void *elem2) {
|
||||
SUdfcFuncStub *stub1 = (SUdfcFuncStub *)elem1;
|
||||
SUdfcFuncStub *stub2 = (SUdfcFuncStub *)elem2;
|
||||
return strcmp(stub1->udfName, stub2->udfName);
|
||||
|
@ -1150,21 +1210,22 @@ void releaseUdfFuncHandle(char *udfName, UdfcFuncHandle handle) {
|
|||
void cleanupExpiredUdfs() {
|
||||
int32_t i = 0;
|
||||
SArray *expiredUdfStubs = taosArrayInit(16, sizeof(SUdfcFuncStub));
|
||||
if(expiredUdfStubs == NULL) {
|
||||
if (expiredUdfStubs == NULL) {
|
||||
fnError("cleanupExpiredUdfs: failed to init array");
|
||||
return;
|
||||
}
|
||||
while (i < taosArrayGetSize(gUdfcProxy.expiredUdfStubs)) {
|
||||
SUdfcFuncStub *stub = taosArrayGet(gUdfcProxy.expiredUdfStubs, i);
|
||||
if (stub->refCount == 0) {
|
||||
fnInfo("tear down udf. expired. udf name: %s, handle: %p, ref count: %d", stub->udfName, stub->handle, stub->refCount);
|
||||
fnInfo("tear down udf. expired. udf name: %s, handle: %p, ref count: %d", stub->udfName, stub->handle,
|
||||
stub->refCount);
|
||||
(void)doTeardownUdf(stub->handle);
|
||||
} else {
|
||||
fnInfo("udf still in use. expired. udf name: %s, ref count: %d, create time: %" PRId64 ", handle: %p", stub->udfName,
|
||||
stub->refCount, stub->createTime, stub->handle);
|
||||
fnInfo("udf still in use. expired. udf name: %s, ref count: %d, create time: %" PRId64 ", handle: %p",
|
||||
stub->udfName, stub->refCount, stub->createTime, stub->handle);
|
||||
UdfcFuncHandle handle = stub->handle;
|
||||
if (handle != NULL && ((SUdfcUvSession *)handle)->udfUvPipe != NULL) {
|
||||
if(taosArrayPush(expiredUdfStubs, stub) == NULL) {
|
||||
if (taosArrayPush(expiredUdfStubs, stub) == NULL) {
|
||||
fnError("cleanupExpiredUdfs: failed to push udf stub to array");
|
||||
}
|
||||
} else {
|
||||
|
@ -1347,7 +1408,8 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
|
|||
return code;
|
||||
}
|
||||
|
||||
SUdfInterBuf state = {.buf = udfRes->interResBuf, .bufLen = udfRes->interResBufLen, .numOfResult = udfRes->interResNum};
|
||||
SUdfInterBuf state = {
|
||||
.buf = udfRes->interResBuf, .bufLen = udfRes->interResBufLen, .numOfResult = udfRes->interResNum};
|
||||
SUdfInterBuf newState = {0};
|
||||
|
||||
udfCode = doCallUdfAggProcess(session, inputBlock, &state, &newState);
|
||||
|
@ -1391,8 +1453,9 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock) {
|
|||
udfRes->interResBuf = (char *)udfRes + sizeof(SUdfAggRes) + session->bytes;
|
||||
|
||||
SUdfInterBuf resultBuf = {0};
|
||||
SUdfInterBuf state = {.buf = udfRes->interResBuf, .bufLen = udfRes->interResBufLen, .numOfResult = udfRes->interResNum};
|
||||
int32_t udfCallCode = 0;
|
||||
SUdfInterBuf state = {
|
||||
.buf = udfRes->interResBuf, .bufLen = udfRes->interResBufLen, .numOfResult = udfRes->interResNum};
|
||||
int32_t udfCallCode = 0;
|
||||
udfCallCode = doCallUdfAggFinalize(session, &state, &resultBuf);
|
||||
if (udfCallCode != 0) {
|
||||
fnError("udfAggFinalize error. doCallUdfAggFinalize step. udf code:%d", udfCallCode);
|
||||
|
@ -1448,7 +1511,7 @@ int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode *
|
|||
SUdfResponse rsp = {0};
|
||||
void *buf = decodeUdfResponse(uvTask->rspBuf.base, &rsp);
|
||||
code = rsp.code;
|
||||
if(code != 0) {
|
||||
if (code != 0) {
|
||||
fnError("udfc get udf task result failure. code: %d", code);
|
||||
}
|
||||
|
||||
|
@ -1474,18 +1537,18 @@ int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode *
|
|||
taosMemoryFree(uvTask->rspBuf.base);
|
||||
} else {
|
||||
code = uvTask->errCode;
|
||||
if(code != 0) {
|
||||
if (code != 0) {
|
||||
fnError("udfc get udf task result failure. code: %d, line:%d", code, __LINE__);
|
||||
}
|
||||
}
|
||||
} else if (uvTask->type == UV_TASK_CONNECT) {
|
||||
code = uvTask->errCode;
|
||||
if(code != 0) {
|
||||
if (code != 0) {
|
||||
fnError("udfc get udf task result failure. code: %d, line:%d", code, __LINE__);
|
||||
}
|
||||
} else if (uvTask->type == UV_TASK_DISCONNECT) {
|
||||
code = uvTask->errCode;
|
||||
if(code != 0) {
|
||||
if (code != 0) {
|
||||
fnError("udfc get udf task result failure. code: %d, line:%d", code, __LINE__);
|
||||
}
|
||||
}
|
||||
|
@ -1620,7 +1683,7 @@ void onUdfcPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) {
|
|||
}
|
||||
}
|
||||
|
||||
void onUdfcPipeWrite(uv_write_t *write, int status) {
|
||||
void onUdfcPipeWrite(uv_write_t *write, int32_t status) {
|
||||
SClientUvConn *conn = write->data;
|
||||
if (status < 0) {
|
||||
fnError("udfc client connection %p write failed. status: %d(%s)", conn, status, uv_strerror(status));
|
||||
|
@ -1631,7 +1694,7 @@ void onUdfcPipeWrite(uv_write_t *write, int status) {
|
|||
taosMemoryFree(write);
|
||||
}
|
||||
|
||||
void onUdfcPipeConnect(uv_connect_t *connect, int status) {
|
||||
void onUdfcPipeConnect(uv_connect_t *connect, int32_t status) {
|
||||
SClientUvTaskNode *uvTask = connect->data;
|
||||
if (status != 0) {
|
||||
fnError("client connect error, task seq: %" PRId64 ", code: %s", uvTask->seqNum, uv_strerror(status));
|
||||
|
@ -1639,7 +1702,7 @@ void onUdfcPipeConnect(uv_connect_t *connect, int status) {
|
|||
uvTask->errCode = status;
|
||||
|
||||
int32_t code = uv_read_start((uv_stream_t *)uvTask->pipe, udfcAllocateBuffer, onUdfcPipeRead);
|
||||
if(code != 0) {
|
||||
if (code != 0) {
|
||||
fnError("udfc client connection %p read start failed. code: %d(%s)", uvTask->pipe, code, uv_strerror(code));
|
||||
uvTask->errCode = code;
|
||||
}
|
||||
|
@ -1678,13 +1741,12 @@ int32_t udfcInitializeUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvT
|
|||
}
|
||||
request.msgLen = bufLen;
|
||||
void *bufBegin = taosMemoryMalloc(bufLen);
|
||||
if(bufBegin == NULL) {
|
||||
if (bufBegin == NULL) {
|
||||
fnError("udfc create uv task, malloc buffer failed. size: %d", bufLen);
|
||||
return terrno;
|
||||
}
|
||||
void *buf = bufBegin;
|
||||
if(encodeUdfRequest(&buf, &request) <= 0)
|
||||
{
|
||||
if (encodeUdfRequest(&buf, &request) <= 0) {
|
||||
fnError("udfc create uv task, encode request failed. size: %d", bufLen);
|
||||
taosMemoryFree(bufBegin);
|
||||
return TSDB_CODE_UDF_UV_EXEC_FAILURE;
|
||||
|
@ -1695,9 +1757,8 @@ int32_t udfcInitializeUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvT
|
|||
} else if (uvTaskType == UV_TASK_DISCONNECT) {
|
||||
uvTask->pipe = task->session->udfUvPipe;
|
||||
}
|
||||
if (uv_sem_init(&uvTask->taskSem, 0) != 0)
|
||||
{
|
||||
if (uvTaskType == UV_TASK_REQ_RSP) {
|
||||
if (uv_sem_init(&uvTask->taskSem, 0) != 0) {
|
||||
if (uvTaskType == UV_TASK_REQ_RSP) {
|
||||
taosMemoryFree(uvTask->reqBuf.base);
|
||||
}
|
||||
fnError("udfc create uv task, init semaphore failed.");
|
||||
|
@ -1733,7 +1794,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) {
|
|||
switch (uvTask->type) {
|
||||
case UV_TASK_CONNECT: {
|
||||
uv_pipe_t *pipe = taosMemoryMalloc(sizeof(uv_pipe_t));
|
||||
if(pipe == NULL) {
|
||||
if (pipe == NULL) {
|
||||
fnError("udfc event loop start connect task malloc pipe failed.");
|
||||
return terrno;
|
||||
}
|
||||
|
@ -1745,7 +1806,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) {
|
|||
uvTask->pipe = pipe;
|
||||
|
||||
SClientUvConn *conn = taosMemoryCalloc(1, sizeof(SClientUvConn));
|
||||
if(conn == NULL) {
|
||||
if (conn == NULL) {
|
||||
fnError("udfc event loop start connect task malloc conn failed.");
|
||||
taosMemoryFree(pipe);
|
||||
return terrno;
|
||||
|
@ -1760,7 +1821,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) {
|
|||
pipe->data = conn;
|
||||
|
||||
uv_connect_t *connReq = taosMemoryMalloc(sizeof(uv_connect_t));
|
||||
if(connReq == NULL) {
|
||||
if (connReq == NULL) {
|
||||
fnError("udfc event loop start connect task malloc connReq failed.");
|
||||
taosMemoryFree(pipe);
|
||||
taosMemoryFree(conn);
|
||||
|
@ -1777,14 +1838,14 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) {
|
|||
code = TSDB_CODE_UDF_PIPE_NOT_EXIST;
|
||||
} else {
|
||||
uv_write_t *write = taosMemoryMalloc(sizeof(uv_write_t));
|
||||
if(write == NULL) {
|
||||
if (write == NULL) {
|
||||
fnError("udfc event loop start req_rsp task malloc write failed.");
|
||||
return terrno;
|
||||
}
|
||||
write->data = pipe->data;
|
||||
QUEUE *connTaskQueue = &((SClientUvConn *)pipe->data)->taskQueue;
|
||||
QUEUE_INSERT_TAIL(connTaskQueue, &uvTask->connTaskQueue);
|
||||
int err = uv_write(write, (uv_stream_t *)pipe, &uvTask->reqBuf, 1, onUdfcPipeWrite);
|
||||
int32_t err = uv_write(write, (uv_stream_t *)pipe, &uvTask->reqBuf, 1, onUdfcPipeWrite);
|
||||
if (err != 0) {
|
||||
taosMemoryFree(write);
|
||||
fnError("udfc event loop start req_rsp task uv_write failed. uvtask: %p, code: %s", uvTask, uv_strerror(err));
|
||||
|
@ -1874,7 +1935,7 @@ void udfStopAsyncCb(uv_async_t *async) {
|
|||
}
|
||||
|
||||
void constructUdfService(void *argsThread) {
|
||||
int32_t code = 0, lino = 0;
|
||||
int32_t code = 0, lino = 0;
|
||||
SUdfcProxy *udfc = (SUdfcProxy *)argsThread;
|
||||
code = uv_loop_init(&udfc->uvLoop);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
|
@ -1891,7 +1952,7 @@ void constructUdfService(void *argsThread) {
|
|||
QUEUE_INIT(&udfc->uvProcTaskQueue);
|
||||
(void)uv_barrier_wait(&udfc->initBarrier);
|
||||
// TODO return value of uv_run
|
||||
int num = uv_run(&udfc->uvLoop, UV_RUN_DEFAULT);
|
||||
int32_t num = uv_run(&udfc->uvLoop, UV_RUN_DEFAULT);
|
||||
fnInfo("udfc uv loop exit. active handle num: %d", num);
|
||||
(void)uv_loop_close(&udfc->uvLoop);
|
||||
|
||||
|
@ -1909,7 +1970,7 @@ _exit:
|
|||
|
||||
int32_t udfcOpen() {
|
||||
int32_t code = 0, lino = 0;
|
||||
int8_t old = atomic_val_compare_exchange_8(&gUdfcProxy.initialized, 0, 1);
|
||||
int8_t old = atomic_val_compare_exchange_8(&gUdfcProxy.initialized, 0, 1);
|
||||
if (old == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -1927,12 +1988,12 @@ int32_t udfcOpen() {
|
|||
code = uv_mutex_init(&proxy->udfStubsMutex);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
proxy->udfStubs = taosArrayInit(8, sizeof(SUdfcFuncStub));
|
||||
if(proxy->udfStubs == NULL) {
|
||||
if (proxy->udfStubs == NULL) {
|
||||
fnError("udfc init failed. udfStubs: %p", proxy->udfStubs);
|
||||
return -1;
|
||||
}
|
||||
proxy->expiredUdfStubs = taosArrayInit(8, sizeof(SUdfcFuncStub));
|
||||
if(proxy->expiredUdfStubs == NULL) {
|
||||
if (proxy->expiredUdfStubs == NULL) {
|
||||
taosArrayDestroy(proxy->udfStubs);
|
||||
fnError("udfc init failed. expiredUdfStubs: %p", proxy->expiredUdfStubs);
|
||||
return -1;
|
||||
|
@ -1956,10 +2017,10 @@ int32_t udfcClose() {
|
|||
|
||||
SUdfcProxy *udfc = &gUdfcProxy;
|
||||
udfc->udfcState = UDFC_STATE_STOPPING;
|
||||
if(uv_async_send(&udfc->loopStopAsync) != 0) {
|
||||
if (uv_async_send(&udfc->loopStopAsync) != 0) {
|
||||
fnError("udfc close error to send stop async");
|
||||
}
|
||||
if(uv_thread_join(&udfc->loopThread) != 0 ) {
|
||||
if (uv_thread_join(&udfc->loopThread) != 0) {
|
||||
fnError("udfc close errir to join loop thread");
|
||||
}
|
||||
uv_mutex_destroy(&udfc->taskQueueMutex);
|
||||
|
@ -1974,9 +2035,9 @@ int32_t udfcClose() {
|
|||
}
|
||||
|
||||
int32_t udfcRunUdfUvTask(SClientUdfTask *task, int8_t uvTaskType) {
|
||||
int32_t code = 0, lino = 0;
|
||||
int32_t code = 0, lino = 0;
|
||||
SClientUvTaskNode *uvTask = taosMemoryCalloc(1, sizeof(SClientUvTaskNode));
|
||||
if(uvTask == NULL) {
|
||||
if (uvTask == NULL) {
|
||||
fnError("udfc client task: %p failed to allocate memory for uvTask", task);
|
||||
return terrno;
|
||||
}
|
||||
|
@ -2006,14 +2067,14 @@ _exit:
|
|||
}
|
||||
|
||||
int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle) {
|
||||
int32_t code = TSDB_CODE_SUCCESS, lino = 0;
|
||||
int32_t code = TSDB_CODE_SUCCESS, lino = 0;
|
||||
SClientUdfTask *task = taosMemoryCalloc(1, sizeof(SClientUdfTask));
|
||||
if(task == NULL) {
|
||||
if (task == NULL) {
|
||||
fnError("doSetupUdf, failed to allocate memory for task");
|
||||
return terrno;
|
||||
}
|
||||
task->session = taosMemoryCalloc(1, sizeof(SUdfcUvSession));
|
||||
if(task->session == NULL) {
|
||||
if (task->session == NULL) {
|
||||
fnError("doSetupUdf, failed to allocate memory for session");
|
||||
taosMemoryFree(task);
|
||||
return terrno;
|
||||
|
@ -2059,7 +2120,7 @@ int32_t callUdf(UdfcFuncHandle handle, int8_t callType, SSDataBlock *input, SUdf
|
|||
return TSDB_CODE_UDF_PIPE_NOT_EXIST;
|
||||
}
|
||||
SClientUdfTask *task = taosMemoryCalloc(1, sizeof(SClientUdfTask));
|
||||
if(task == NULL) {
|
||||
if (task == NULL) {
|
||||
fnError("udfc call udf. failed to allocate memory for task");
|
||||
return terrno;
|
||||
}
|
||||
|
@ -2163,8 +2224,8 @@ int32_t doCallUdfAggFinalize(UdfcFuncHandle handle, SUdfInterBuf *interBuf, SUdf
|
|||
int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t numOfCols, SScalarParam *output) {
|
||||
int8_t callType = TSDB_UDF_CALL_SCALA_PROC;
|
||||
SSDataBlock inputBlock = {0};
|
||||
int32_t code = convertScalarParamToDataBlock(input, numOfCols, &inputBlock);
|
||||
if(code != 0) {
|
||||
int32_t code = convertScalarParamToDataBlock(input, numOfCols, &inputBlock);
|
||||
if (code != 0) {
|
||||
fnError("doCallUdfScalarFunc, convertScalarParamToDataBlock failed. code: %d", code);
|
||||
return code;
|
||||
}
|
||||
|
@ -2180,7 +2241,7 @@ int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t
|
|||
}
|
||||
|
||||
int32_t doTeardownUdf(UdfcFuncHandle handle) {
|
||||
int32_t code = TSDB_CODE_SUCCESS, lino = 0;;
|
||||
int32_t code = TSDB_CODE_SUCCESS, lino = 0;
|
||||
SUdfcUvSession *session = (SUdfcUvSession *)handle;
|
||||
|
||||
if (session->udfUvPipe == NULL) {
|
||||
|
@ -2190,7 +2251,7 @@ int32_t doTeardownUdf(UdfcFuncHandle handle) {
|
|||
}
|
||||
|
||||
SClientUdfTask *task = taosMemoryCalloc(1, sizeof(SClientUdfTask));
|
||||
if(task == NULL) {
|
||||
if (task == NULL) {
|
||||
fnError("doTeardownUdf, failed to allocate memory for task");
|
||||
taosMemoryFree(session);
|
||||
return terrno;
|
||||
|
|
|
@ -1217,7 +1217,7 @@ int32_t udfdOpenClientRpc() {
|
|||
connLimitNum = TMIN(connLimitNum, 500);
|
||||
rpcInit.connLimitNum = connLimitNum;
|
||||
rpcInit.timeToGetConn = tsTimeToGetAvailableConn;
|
||||
TAOS_CHECK_RETURN(taosVersionStrToInt(version, &(rpcInit.compatibilityVer)));
|
||||
TAOS_CHECK_RETURN(taosVersionStrToInt(td_version, &rpcInit.compatibilityVer));
|
||||
global.clientRpc = rpcOpen(&rpcInit);
|
||||
if (global.clientRpc == NULL) {
|
||||
fnError("failed to init dnode rpc client");
|
||||
|
@ -1470,9 +1470,9 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) {
|
|||
}
|
||||
|
||||
static void udfdPrintVersion() {
|
||||
(void)printf("udfd version: %s compatible_version: %s\n", version, compatible_version);
|
||||
(void)printf("git: %s\n", gitinfo);
|
||||
(void)printf("build: %s\n", buildinfo);
|
||||
(void)printf("udfd version: %s compatible_version: %s\n", td_version, td_compatible_version);
|
||||
(void)printf("git: %s\n", td_gitinfo);
|
||||
(void)printf("build: %s\n", td_buildinfo);
|
||||
}
|
||||
|
||||
static int32_t udfdInitLog() {
|
||||
|
|
|
@ -175,8 +175,8 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
|
|||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
case TSDB_DATA_TYPE_GEOMETRY: {
|
||||
int32_t len = pSrc->node.resType.bytes + 1;
|
||||
pDst->datum.p = taosMemoryCalloc(1, len);
|
||||
int32_t len = varDataTLen(pSrc->datum.p);
|
||||
pDst->datum.p = taosMemoryCalloc(1, len + 1);
|
||||
if (NULL == pDst->datum.p) {
|
||||
return terrno;
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ typedef enum EDatabaseOptionType {
|
|||
DB_OPTION_S3_COMPACT,
|
||||
DB_OPTION_KEEP_TIME_OFFSET,
|
||||
DB_OPTION_ENCRYPT_ALGORITHM,
|
||||
DB_OPTION_DNODES,
|
||||
} EDatabaseOptionType;
|
||||
|
||||
typedef enum ETableOptionType {
|
||||
|
|
|
@ -28,6 +28,8 @@ extern "C" {
|
|||
#define QUERY_SMA_OPTIMIZE_DISABLE 0
|
||||
#define QUERY_SMA_OPTIMIZE_ENABLE 1
|
||||
|
||||
#define QUERY_NUMBER_MAX_DISPLAY_LEN 65
|
||||
|
||||
int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, const SMetaData* pMetaData);
|
||||
int32_t continueCreateTbFromFile(SParseContext* pCxt, SQuery** pQuery);
|
||||
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery);
|
||||
|
|
|
@ -286,6 +286,7 @@ db_options(A) ::= db_options(B) S3_KEEPLOCAL NK_VARIABLE(C).
|
|||
db_options(A) ::= db_options(B) S3_COMPACT NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_S3_COMPACT, &C); }
|
||||
db_options(A) ::= db_options(B) KEEP_TIME_OFFSET NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP_TIME_OFFSET, &C); }
|
||||
db_options(A) ::= db_options(B) ENCRYPT_ALGORITHM NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_ENCRYPT_ALGORITHM, &C); }
|
||||
db_options(A) ::= db_options(B) DNODES NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DNODES, &C); }
|
||||
|
||||
alter_db_options(A) ::= alter_db_option(B). { A = createAlterDatabaseOptions(pCxt); A = setAlterDatabaseOption(pCxt, A, &B); }
|
||||
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setAlterDatabaseOption(pCxt, B, &C); }
|
||||
|
|
|
@ -1799,6 +1799,7 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
|||
pOptions->s3Compact = TSDB_DEFAULT_S3_COMPACT;
|
||||
pOptions->withArbitrator = TSDB_DEFAULT_DB_WITH_ARBITRATOR;
|
||||
pOptions->encryptAlgorithm = TSDB_DEFAULT_ENCRYPT_ALGO;
|
||||
pOptions->dnodeListStr[0] = 0;
|
||||
return (SNode*)pOptions;
|
||||
_err:
|
||||
return NULL;
|
||||
|
@ -1842,6 +1843,7 @@ SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt) {
|
|||
pOptions->s3Compact = -1;
|
||||
pOptions->withArbitrator = -1;
|
||||
pOptions->encryptAlgorithm = -1;
|
||||
pOptions->dnodeListStr[0] = 0;
|
||||
return (SNode*)pOptions;
|
||||
_err:
|
||||
return NULL;
|
||||
|
@ -1981,6 +1983,14 @@ static SNode* setDatabaseOptionImpl(SAstCreateContext* pCxt, SNode* pOptions, ED
|
|||
COPY_STRING_FORM_STR_TOKEN(pDbOptions->encryptAlgorithmStr, (SToken*)pVal);
|
||||
pDbOptions->encryptAlgorithm = TSDB_DEFAULT_ENCRYPT_ALGO;
|
||||
break;
|
||||
case DB_OPTION_DNODES:
|
||||
if (((SToken*)pVal)->n >= TSDB_DNODE_LIST_LEN) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "the dnode list is too long (should less than %d)",
|
||||
TSDB_DNODE_LIST_LEN);
|
||||
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||
} else {
|
||||
COPY_STRING_FORM_STR_TOKEN(pDbOptions->dnodeListStr, (SToken*)pVal);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ typedef struct SInsertParseContext {
|
|||
bool forceUpdate;
|
||||
bool needTableTagVal;
|
||||
bool needRequest; // whether or not request server
|
||||
bool isStmtBind; // whether is stmt bind
|
||||
bool isStmtBind; // whether is stmt bind
|
||||
} SInsertParseContext;
|
||||
|
||||
typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param);
|
||||
|
@ -757,7 +757,7 @@ int32_t parseTagValue(SMsgBuf* pMsgBuf, const char** pSql, uint8_t precision, SS
|
|||
STagVal val = {0};
|
||||
int32_t code = parseTagToken(pSql, pToken, pTagSchema, precision, &val, pMsgBuf);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (NULL == taosArrayPush(pTagVals, &val)){
|
||||
if (NULL == taosArrayPush(pTagVals, &val)) {
|
||||
code = terrno;
|
||||
}
|
||||
}
|
||||
|
@ -775,11 +775,14 @@ static int32_t buildCreateTbReq(SVnodeModifyOpStmt* pStmt, STag* pTag, SArray* p
|
|||
return terrno;
|
||||
}
|
||||
return insBuildCreateTbReq(pStmt->pCreateTblReq, pStmt->targetTableName.tname, pTag, pStmt->pTableMeta->suid,
|
||||
pStmt->usingTableName.tname, pTagName, pStmt->pTableMeta->tableInfo.numOfTags,
|
||||
TSDB_DEFAULT_TABLE_TTL);
|
||||
pStmt->usingTableName.tname, pTagName, pStmt->pTableMeta->tableInfo.numOfTags,
|
||||
TSDB_DEFAULT_TABLE_TTL);
|
||||
}
|
||||
|
||||
int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf, int8_t type) {
|
||||
if (pToken->type == TK_NK_QUESTION) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, "insert into super table syntax is not supported for stmt");
|
||||
}
|
||||
if ((pToken->type != TK_NOW && pToken->type != TK_TODAY && pToken->type != TK_NK_INTEGER &&
|
||||
pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && pToken->type != TK_NK_BOOL &&
|
||||
pToken->type != TK_NULL && pToken->type != TK_NK_HEX && pToken->type != TK_NK_OCT && pToken->type != TK_NK_BIN &&
|
||||
|
@ -810,7 +813,7 @@ typedef struct SRewriteTagCondCxt {
|
|||
|
||||
static int32_t rewriteTagCondColumnImpl(STagVal* pVal, SNode** pNode) {
|
||||
SValueNode* pValue = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pValue);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pValue);
|
||||
if (NULL == pValue) {
|
||||
return code;
|
||||
}
|
||||
|
@ -1041,7 +1044,7 @@ static int32_t storeChildTableMeta(SInsertParseContext* pCxt, SVnodeModifyOpStmt
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t code = tNameExtractFullName(&pStmt->targetTableName, tbFName);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosMemoryFree(pBackup);
|
||||
|
@ -1236,7 +1239,7 @@ static int32_t getTargetTableMetaAndVgroup(SInsertParseContext* pCxt, SVnodeModi
|
|||
}
|
||||
|
||||
static int32_t collectUseTable(const SName* pName, SHashObj* pTable) {
|
||||
char fullName[TSDB_TABLE_FNAME_LEN];
|
||||
char fullName[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t code = tNameExtractFullName(pName, fullName);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
|
@ -1382,7 +1385,7 @@ static int32_t getTableDataCxt(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pS
|
|||
pStmt->pTableMeta, &pStmt->pCreateTblReq, pTableCxt, false, false);
|
||||
}
|
||||
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t code = tNameExtractFullName(&pStmt->targetTableName, tbFName);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
|
@ -1824,37 +1827,49 @@ static int32_t doGetStbRowValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
|
|||
code = generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
|
||||
break;
|
||||
}
|
||||
if (pCols->pColIndex[i] < numOfCols) {
|
||||
const SSchema* pSchema = &pSchemas[pCols->pColIndex[i]];
|
||||
SColVal* pVal = taosArrayGet(pStbRowsCxt->aColVals, pCols->pColIndex[i]);
|
||||
code = parseValueToken(pCxt, ppSql, pToken, (SSchema*)pSchema, precision, pVal);
|
||||
if (TK_NK_VARIABLE == pToken->type) {
|
||||
code = buildInvalidOperationMsg(&pCxt->msg, "not expected row value");
|
||||
|
||||
if (TK_NK_QUESTION == pToken->type) {
|
||||
pCxt->isStmtBind = true;
|
||||
if (pCols->pColIndex[i] == tbnameIdx) {
|
||||
*bFoundTbName = true;
|
||||
}
|
||||
} else if (pCols->pColIndex[i] < tbnameIdx) {
|
||||
const SSchema* pTagSchema = &pSchemas[pCols->pColIndex[i]];
|
||||
if (canParseTagsAfter) {
|
||||
tagTokens[(*pNumOfTagTokens)] = *pToken;
|
||||
tagSchemas[(*pNumOfTagTokens)] = (SSchema*)pTagSchema;
|
||||
++(*pNumOfTagTokens);
|
||||
} else {
|
||||
code = checkAndTrimValue(pToken, pCxt->tmpTokenBuf, &pCxt->msg, pTagSchema->type);
|
||||
if (code == TSDB_CODE_SUCCESS && TK_NK_VARIABLE == pToken->type) {
|
||||
if (NULL == pCxt->pComCxt->pStmtCb) {
|
||||
code = buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", pToken->z);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (pCols->pColIndex[i] < numOfCols) {
|
||||
const SSchema* pSchema = &pSchemas[pCols->pColIndex[i]];
|
||||
SColVal* pVal = taosArrayGet(pStbRowsCxt->aColVals, pCols->pColIndex[i]);
|
||||
code = parseValueToken(pCxt, ppSql, pToken, (SSchema*)pSchema, precision, pVal);
|
||||
if (TK_NK_VARIABLE == pToken->type) {
|
||||
code = buildInvalidOperationMsg(&pCxt->msg, "not expected row value");
|
||||
}
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = parseTagValue(&pCxt->msg, ppSql, precision, (SSchema*)pTagSchema, pToken, pTagNames, pTagVals,
|
||||
&pStbRowsCxt->pTag);
|
||||
} else if (pCols->pColIndex[i] < tbnameIdx) {
|
||||
const SSchema* pTagSchema = &pSchemas[pCols->pColIndex[i]];
|
||||
if (canParseTagsAfter) {
|
||||
tagTokens[(*pNumOfTagTokens)] = *pToken;
|
||||
tagSchemas[(*pNumOfTagTokens)] = (SSchema*)pTagSchema;
|
||||
++(*pNumOfTagTokens);
|
||||
} else {
|
||||
code = checkAndTrimValue(pToken, pCxt->tmpTokenBuf, &pCxt->msg, pTagSchema->type);
|
||||
if (code == TSDB_CODE_SUCCESS && TK_NK_VARIABLE == pToken->type) {
|
||||
code = buildInvalidOperationMsg(&pCxt->msg, "not expected row value");
|
||||
}
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = parseTagValue(&pCxt->msg, ppSql, precision, (SSchema*)pTagSchema, pToken, pTagNames, pTagVals,
|
||||
&pStbRowsCxt->pTag);
|
||||
}
|
||||
}
|
||||
} else if (pCols->pColIndex[i] == tbnameIdx) {
|
||||
code = checkAndTrimValue(pToken, pCxt->tmpTokenBuf, &pCxt->msg, TSDB_DATA_TYPE_BINARY);
|
||||
if (TK_NK_VARIABLE == pToken->type) {
|
||||
code = buildInvalidOperationMsg(&pCxt->msg, "not expected tbname");
|
||||
}
|
||||
}
|
||||
} else if (pCols->pColIndex[i] == tbnameIdx) {
|
||||
code = checkAndTrimValue(pToken, pCxt->tmpTokenBuf, &pCxt->msg, TSDB_DATA_TYPE_BINARY);
|
||||
if (TK_NK_VARIABLE == pToken->type) {
|
||||
code = buildInvalidOperationMsg(&pCxt->msg, "not expected tbname");
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = parseTbnameToken(&pCxt->msg, pStbRowsCxt->ctbName.tname, pToken, bFoundTbName);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = parseTbnameToken(&pCxt->msg, pStbRowsCxt->ctbName.tname, pToken, bFoundTbName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1888,6 +1903,11 @@ static int32_t getStbRowValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pS
|
|||
code = buildSyntaxErrMsg(&pCxt->msg, "tbname value expected", pOrigSql);
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS && pStbRowsCxt->ctbName.tname[0] == '\0') {
|
||||
*pGotRow = true;
|
||||
return TSDB_CODE_TSC_STMT_TBNAME_ERROR;
|
||||
}
|
||||
|
||||
bool ctbFirst = true;
|
||||
char ctbFName[TSDB_TABLE_FNAME_LEN];
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
|
@ -1923,8 +1943,8 @@ static int32_t processCtbAutoCreationAndCtbMeta(SInsertParseContext* pCxt, SVnod
|
|||
}
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = insBuildCreateTbReq(pStbRowsCxt->pCreateCtbReq, pStbRowsCxt->ctbName.tname, pStbRowsCxt->pTag,
|
||||
pStbRowsCxt->pStbMeta->uid, pStbRowsCxt->stbName.tname, pStbRowsCxt->aTagNames,
|
||||
getNumOfTags(pStbRowsCxt->pStbMeta), TSDB_DEFAULT_TABLE_TTL);
|
||||
pStbRowsCxt->pStbMeta->uid, pStbRowsCxt->stbName.tname, pStbRowsCxt->aTagNames,
|
||||
getNumOfTags(pStbRowsCxt->pStbMeta), TSDB_DEFAULT_TABLE_TTL);
|
||||
pStbRowsCxt->pTag = NULL;
|
||||
}
|
||||
|
||||
|
@ -1933,9 +1953,9 @@ static int32_t processCtbAutoCreationAndCtbMeta(SInsertParseContext* pCxt, SVnod
|
|||
code = tNameExtractFullName(&pStbRowsCxt->ctbName, ctbFName);
|
||||
SVgroupInfo vg;
|
||||
SRequestConnInfo conn = {.pTrans = pCxt->pComCxt->pTransporter,
|
||||
.requestId = pCxt->pComCxt->requestId,
|
||||
.requestObjRefId = pCxt->pComCxt->requestRid,
|
||||
.mgmtEps = pCxt->pComCxt->mgmtEpSet};
|
||||
.requestId = pCxt->pComCxt->requestId,
|
||||
.requestObjRefId = pCxt->pComCxt->requestRid,
|
||||
.mgmtEps = pCxt->pComCxt->mgmtEpSet};
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = catalogGetTableHashVgroup(pCxt->pComCxt->pCatalog, &conn, &pStbRowsCxt->ctbName, &vg);
|
||||
}
|
||||
|
@ -1979,11 +1999,47 @@ static void clearStbRowsDataContext(SStbRowsDataContext* pStbRowsCxt) {
|
|||
taosMemoryFreeClear(pStbRowsCxt->pCreateCtbReq);
|
||||
}
|
||||
|
||||
static int32_t parseStbBoundInfo(SVnodeModifyOpStmt* pStmt, SStbRowsDataContext* pStbRowsCxt,
|
||||
STableDataCxt** ppTableDataCxt) {
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t code = tNameExtractFullName(&pStmt->targetTableName, tbFName);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (pStmt->usingTableProcessing) {
|
||||
pStmt->pTableMeta->uid = 0;
|
||||
}
|
||||
|
||||
code = insGetTableDataCxt(pStmt->pTableBlockHashObj, tbFName, strlen(tbFName), pStmt->pTableMeta,
|
||||
&pStmt->pCreateTblReq, ppTableDataCxt, false, true);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
insDestroyBoundColInfo(&((*ppTableDataCxt)->boundColsInfo));
|
||||
(*ppTableDataCxt)->boundColsInfo = pStbRowsCxt->boundColsInfo;
|
||||
(*ppTableDataCxt)->boundColsInfo.numOfCols = pStbRowsCxt->boundColsInfo.numOfBound;
|
||||
(*ppTableDataCxt)->boundColsInfo.numOfBound = pStbRowsCxt->boundColsInfo.numOfBound;
|
||||
(*ppTableDataCxt)->boundColsInfo.hasBoundCols = pStbRowsCxt->boundColsInfo.hasBoundCols;
|
||||
(*ppTableDataCxt)->boundColsInfo.pColIndex = taosMemoryCalloc(pStbRowsCxt->boundColsInfo.numOfBound, sizeof(int16_t));
|
||||
if (NULL == (*ppTableDataCxt)->boundColsInfo.pColIndex) {
|
||||
return terrno;
|
||||
}
|
||||
(void)memcpy((*ppTableDataCxt)->boundColsInfo.pColIndex, pStbRowsCxt->boundColsInfo.pColIndex,
|
||||
sizeof(int16_t) * pStmt->pStbRowsCxt->boundColsInfo.numOfBound);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t parseOneStbRow(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, const char** ppSql,
|
||||
SStbRowsDataContext* pStbRowsCxt, bool* pGotRow, SToken* pToken,
|
||||
STableDataCxt** ppTableDataCxt) {
|
||||
bool bFirstTable = false;
|
||||
int32_t code = getStbRowValues(pCxt, pStmt, ppSql, pStbRowsCxt, pGotRow, pToken, &bFirstTable);
|
||||
|
||||
if (code == TSDB_CODE_TSC_STMT_TBNAME_ERROR && *pGotRow) {
|
||||
return parseStbBoundInfo(pStmt, pStbRowsCxt, ppTableDataCxt);
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS || !*pGotRow) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2176,8 +2232,8 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt
|
|||
if (code == TSDB_CODE_SUCCESS) {
|
||||
SStbRowsDataContext* pStbRowsCxt = rowsDataCxt.pStbRowsCxt;
|
||||
void* pData = pTableDataCxt;
|
||||
code = taosHashPut(pStmt->pTableCxtHashObj, &pStbRowsCxt->pCtbMeta->uid, sizeof(pStbRowsCxt->pCtbMeta->uid), &pData,
|
||||
POINTER_BYTES);
|
||||
code = taosHashPut(pStmt->pTableCxtHashObj, &pStbRowsCxt->pCtbMeta->uid, sizeof(pStbRowsCxt->pCtbMeta->uid),
|
||||
&pData, POINTER_BYTES);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
|
@ -2249,7 +2305,7 @@ static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifyOpSt
|
|||
if (!pStmt->stbSyntax && numOfRows > 0) {
|
||||
void* pData = rowsDataCxt.pTableDataCxt;
|
||||
code = taosHashPut(pStmt->pTableCxtHashObj, &pStmt->pTableMeta->uid, sizeof(pStmt->pTableMeta->uid), &pData,
|
||||
POINTER_BYTES);
|
||||
POINTER_BYTES);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -2363,8 +2419,7 @@ static int32_t constructStbRowsDataContext(SVnodeModifyOpStmt* pStmt, SStbRowsDa
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
// col values and bound cols info of STableDataContext is not used
|
||||
pStbRowsCxt->aColVals = taosArrayInit(getNumOfColumns(pStbRowsCxt->pStbMeta), sizeof(SColVal));
|
||||
if (!pStbRowsCxt->aColVals)
|
||||
code = terrno;
|
||||
if (!pStbRowsCxt->aColVals) code = terrno;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = insInitColValues(pStbRowsCxt->pStbMeta, pStbRowsCxt->aColVals);
|
||||
|
@ -2422,9 +2477,6 @@ static int32_t parseInsertStbClauseBottom(SInsertParseContext* pCxt, SVnodeModif
|
|||
// 1. [(tag1_name, ...)] ...
|
||||
// 2. VALUES ... | FILE ...
|
||||
static int32_t parseInsertTableClauseBottom(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||
if (pStmt->stbSyntax && TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) {
|
||||
return buildInvalidOperationMsg(&pCxt->msg, "insert into super table syntax is not supported for stmt");
|
||||
}
|
||||
if (!pStmt->stbSyntax) {
|
||||
STableDataCxt* pTableCxt = NULL;
|
||||
int32_t code = parseSchemaClauseBottom(pCxt, pStmt, &pTableCxt);
|
||||
|
@ -2511,9 +2563,9 @@ static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModif
|
|||
}
|
||||
|
||||
// db.? situation,ensure that the only thing following the '.' mark is '?'
|
||||
char *tbNameAfterDbName = strnchr(pTbName->z, '.', pTbName->n, true);
|
||||
char* tbNameAfterDbName = strnchr(pTbName->z, '.', pTbName->n, true);
|
||||
if ((tbNameAfterDbName != NULL) && (*(tbNameAfterDbName + 1) == '?')) {
|
||||
char *tbName = NULL;
|
||||
char* tbName = NULL;
|
||||
if (NULL == pCxt->pComCxt->pStmtCb) {
|
||||
return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", pTbName->z);
|
||||
}
|
||||
|
@ -2528,7 +2580,8 @@ static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModif
|
|||
if (pCxt->isStmtBind) {
|
||||
if (TK_NK_ID == pTbName->type || (tbNameAfterDbName != NULL && *(tbNameAfterDbName + 1) != '?')) {
|
||||
// In SQL statements, the table name has already been specified.
|
||||
parserWarn("0x%" PRIx64 " table name is specified in sql, ignore the table name in bind param", pCxt->pComCxt->requestId);
|
||||
parserWarn("0x%" PRIx64 " table name is specified in sql, ignore the table name in bind param",
|
||||
pCxt->pComCxt->requestId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2614,7 +2667,7 @@ static void destroySubTableHashElem(void* p) { taosMemoryFree(*(STableMeta**)p);
|
|||
|
||||
static int32_t createVnodeModifOpStmt(SInsertParseContext* pCxt, bool reentry, SNode** pOutput) {
|
||||
SVnodeModifyOpStmt* pStmt = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT, (SNode**)&pStmt);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT, (SNode**)&pStmt);
|
||||
if (NULL == pStmt) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2729,7 +2782,7 @@ static int32_t buildTagNameFromMeta(STableMeta* pMeta, SArray** pTagName) {
|
|||
return terrno;
|
||||
}
|
||||
SSchema* pSchema = getTableTagSchema(pMeta);
|
||||
int32_t code = 0;
|
||||
int32_t code = 0;
|
||||
for (int32_t i = 0; i < pMeta->tableInfo.numOfTags; ++i) {
|
||||
if (NULL == taosArrayPush(*pTagName, pSchema[i].name)) {
|
||||
code = terrno;
|
||||
|
@ -2834,7 +2887,7 @@ static int32_t resetVnodeModifOpStmt(SInsertParseContext* pCxt, SQuery* pQuery)
|
|||
}
|
||||
if (NULL == pStmt->pTableBlockHashObj) {
|
||||
pStmt->pTableBlockHashObj =
|
||||
taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
}
|
||||
if (NULL == pStmt->pVgroupsHashObj || NULL == pStmt->pTableBlockHashObj) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -2866,7 +2919,7 @@ static int32_t initInsertQuery(SInsertParseContext* pCxt, SCatalogReq* pCatalogR
|
|||
|
||||
static int32_t setRefreshMeta(SQuery* pQuery) {
|
||||
SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)pQuery->pRoot;
|
||||
int32_t code = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
if (taosHashGetSize(pStmt->pTableNameHashObj) > 0) {
|
||||
taosArrayDestroy(pQuery->pTableList);
|
||||
|
@ -3065,9 +3118,10 @@ int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatal
|
|||
.forceUpdate = (NULL != pCatalogReq ? pCatalogReq->forceUpdate : false),
|
||||
.isStmtBind = pCxt->isStmtBind};
|
||||
|
||||
int32_t code = initInsertQuery(&context, pCatalogReq, pMetaData, pQuery);
|
||||
int32_t code = initInsertQuery(&context, pCatalogReq, pMetaData, pQuery);
|
||||
SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)((*pQuery)->pRoot);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = parseInsertSqlImpl(&context, (SVnodeModifyOpStmt*)(*pQuery)->pRoot);
|
||||
code = parseInsertSqlImpl(&context, pStmt);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setNextStageInfo(&context, *pQuery, pCatalogReq);
|
||||
|
@ -3076,8 +3130,8 @@ int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatal
|
|||
QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) {
|
||||
code = setRefreshMeta(*pQuery);
|
||||
}
|
||||
insDestroyBoundColInfo(&context.tags);
|
||||
|
||||
insDestroyBoundColInfo(&context.tags);
|
||||
// if no data to insert, set emptyMode to avoid request server
|
||||
if (!context.needRequest) {
|
||||
(*pQuery)->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
|
||||
|
|
|
@ -242,7 +242,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
|||
}
|
||||
|
||||
code = insBuildCreateTbReq(pDataBlock->pData->pCreateTbReq, tName, pTag, suid, sTableName, tagName,
|
||||
pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
|
||||
pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
|
||||
pTag = NULL;
|
||||
|
||||
end:
|
||||
|
@ -594,7 +594,7 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c
|
|||
}
|
||||
|
||||
code = insBuildCreateTbReq(pDataBlock->pData->pCreateTbReq, tName, pTag, suid, sTableName, tagName,
|
||||
pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
|
||||
pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
|
||||
pTag = NULL;
|
||||
|
||||
end:
|
||||
|
@ -797,6 +797,10 @@ int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind,
|
|||
for (int c = 0; c < boundInfo->numOfBound; ++c) {
|
||||
SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]];
|
||||
SColData* pCol = taosArrayGet(pCols, c);
|
||||
if (pCol == NULL || pColSchema == NULL) {
|
||||
code = buildInvalidOperationMsg(&pBuf, "get column schema or column data failed");
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (bind[c].num != rowNum) {
|
||||
code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
|
||||
|
@ -886,7 +890,7 @@ _return:
|
|||
|
||||
int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSchema, int32_t* fieldNum,
|
||||
TAOS_FIELD_E** fields, uint8_t timePrec) {
|
||||
if (fields) {
|
||||
if (fields != NULL) {
|
||||
*fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_E));
|
||||
if (NULL == *fields) {
|
||||
return terrno;
|
||||
|
@ -910,6 +914,44 @@ int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSc
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD_STB** fields,
|
||||
STableMeta* pMeta) {
|
||||
if (fields != NULL) {
|
||||
*fields = taosMemoryCalloc(boundColsInfo.numOfBound, sizeof(TAOS_FIELD_STB));
|
||||
if (NULL == *fields) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
SSchema* schema = &pSchema[boundColsInfo.pColIndex[0]];
|
||||
if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
|
||||
(*fields)[0].precision = pMeta->tableInfo.precision;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < boundColsInfo.numOfBound; ++i) {
|
||||
int16_t idx = boundColsInfo.pColIndex[i];
|
||||
|
||||
if (idx == pMeta->tableInfo.numOfColumns + pMeta->tableInfo.numOfTags) {
|
||||
(*fields)[i].field_type = TAOS_FIELD_TBNAME;
|
||||
tstrncpy((*fields)[i].name, "tbname", sizeof((*fields)[i].name));
|
||||
continue;
|
||||
} else if (idx < pMeta->tableInfo.numOfColumns) {
|
||||
(*fields)[i].field_type = TAOS_FIELD_COL;
|
||||
} else {
|
||||
(*fields)[i].field_type = TAOS_FIELD_TAG;
|
||||
}
|
||||
|
||||
schema = &pSchema[idx];
|
||||
tstrncpy((*fields)[i].name, schema->name, sizeof((*fields)[i].name));
|
||||
(*fields)[i].type = schema->type;
|
||||
(*fields)[i].bytes = schema->bytes;
|
||||
}
|
||||
}
|
||||
|
||||
*fieldNum = boundColsInfo.numOfBound;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields) {
|
||||
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||
SBoundColInfo* tags = (SBoundColInfo*)boundTags;
|
||||
|
@ -939,7 +981,7 @@ int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fiel
|
|||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta);
|
||||
if (pDataBlock->boundColsInfo.numOfBound <= 0) {
|
||||
*fieldNum = 0;
|
||||
if (fields) {
|
||||
if (fields != NULL) {
|
||||
*fields = NULL;
|
||||
}
|
||||
|
||||
|
@ -952,6 +994,23 @@ int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fiel
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBuildStmtStbColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_STB** fields) {
|
||||
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta);
|
||||
if (pDataBlock->boundColsInfo.numOfBound <= 0) {
|
||||
*fieldNum = 0;
|
||||
if (fields != NULL) {
|
||||
*fields = NULL;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
CHECK_CODE(buildStbBoundFields(pDataBlock->boundColsInfo, pSchema, fieldNum, fields, pDataBlock->pMeta));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qResetStmtColumns(SArray* pCols, bool deepClear) {
|
||||
int32_t colNum = taosArrayGetSize(pCols);
|
||||
|
||||
|
|
|
@ -2902,7 +2902,7 @@ static int32_t rewriteDatabaseFunc(STranslateContext* pCxt, SNode** pNode) {
|
|||
}
|
||||
|
||||
static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) {
|
||||
char* pVer = taosStrdup((void*)version);
|
||||
char* pVer = taosStrdup((void*)td_version);
|
||||
if (NULL == pVer) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -3308,25 +3308,26 @@ static int32_t selectCommonType(SDataType* commonType, const SDataType* newType)
|
|||
} else {
|
||||
resultType = gDisplyTypes[type2][type1];
|
||||
}
|
||||
|
||||
if (resultType == -1) {
|
||||
return TSDB_CODE_SCALAR_CONVERT_ERROR;
|
||||
}
|
||||
|
||||
if (commonType->type == newType->type) {
|
||||
commonType->bytes = TMAX(commonType->bytes, newType->bytes);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (resultType == commonType->type) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (resultType == newType->type) {
|
||||
*commonType = *newType;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]);
|
||||
if (resultType == TSDB_DATA_TYPE_VARCHAR && (IS_FLOAT_TYPE(commonType->type) || IS_FLOAT_TYPE(newType->type))) {
|
||||
commonType->bytes += TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE];
|
||||
|
||||
if ((resultType == TSDB_DATA_TYPE_VARCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) {
|
||||
commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN);
|
||||
} else if ((resultType == TSDB_DATA_TYPE_NCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) {
|
||||
commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN * TSDB_NCHAR_SIZE);
|
||||
} else {
|
||||
commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]);
|
||||
}
|
||||
|
||||
commonType->type = resultType;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -7541,6 +7542,8 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
|
|||
pReq->ignoreExist = pStmt->ignoreExists;
|
||||
pReq->withArbitrator = pStmt->pOptions->withArbitrator;
|
||||
pReq->encryptAlgorithm = pStmt->pOptions->encryptAlgorithm;
|
||||
tstrncpy(pReq->dnodeListStr, pStmt->pOptions->dnodeListStr, TSDB_DNODE_LIST_LEN);
|
||||
|
||||
return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq);
|
||||
}
|
||||
|
||||
|
@ -10885,7 +10888,7 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm
|
|||
parseNatualDuration(str, strlen(str), &minDelay, &pVal->unit, pVal->node.resType.precision, false)) {
|
||||
if (pVal->datum.i < minDelay) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||
"stream max delay must be bigger than 5 session");
|
||||
"stream max delay must be bigger than 5 seconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2085,7 +2085,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
|||
(void)memcpy(varDataVal(output), convBuf, len);
|
||||
varDataSetLen(output, len);
|
||||
} else {
|
||||
NUM_TO_STRING(inputType, input, bufSize, buf);
|
||||
int32_t outputSize = (outputLen - VARSTR_HEADER_SIZE) < bufSize ? (outputLen - VARSTR_HEADER_SIZE + 1): bufSize;
|
||||
NUM_TO_STRING(inputType, input, outputSize, buf);
|
||||
int32_t len = (int32_t)strlen(buf);
|
||||
len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE);
|
||||
(void)memcpy(varDataVal(output), buf, len);
|
||||
|
|
|
@ -1031,23 +1031,23 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
|
|||
/*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0};
|
||||
|
||||
int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
|
||||
/*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIME NCHA UTINY USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
|
||||
/*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 8,
|
||||
/*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, 8, -1, -1, -1, -1, 8,
|
||||
/*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, 8, -1, -1, -1, -1, 8,
|
||||
/*SMAL*/ 0, 0, 0, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, 8, -1, -1, -1, -1, 8,
|
||||
/*INT */ 0, 0, 0, 0, 4, 5, 8, 8, 8, 5, 10, 4, 4, 5, 8, 8, -1, -1, -1, -1, 8,
|
||||
/*BIGI*/ 0, 0, 0, 0, 0, 5, 8, 8, 8, 5, 10, 5, 5, 5, 8, 8, -1, -1, -1, -1, 8,
|
||||
/*FLOA*/ 0, 0, 0, 0, 0, 0, 6, 7, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8,
|
||||
/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8,
|
||||
/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, 8, -1, -1, -1, -1, 8,
|
||||
/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 5, 5, 5, 8, 8, -1, -1, -1, -1, 8,
|
||||
/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, -1, -1, -1, -1, 10,
|
||||
/*UTINY*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 13, 14, 8, -1, -1, -1, -1, 8,
|
||||
/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 8, -1, -1, -1, -1, 8,
|
||||
/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 8, -1, -1, -1, -1, 8,
|
||||
/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 8, -1, -1, -1, -1, 8,
|
||||
/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, -1, -1, -1, -1, 8,
|
||||
/*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIM NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
|
||||
/*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 20,
|
||||
/*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1,
|
||||
/*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1,
|
||||
/*SMAL*/ 0, 0, 0, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1,
|
||||
/*INT */ 0, 0, 0, 0, 4, 5, 8, 8, 8, 5, 10, 4, 4, 5, 8, -1, -1, -1, -1, -1, -1,
|
||||
/*BIGI*/ 0, 0, 0, 0, 0, 5, 8, 8, 8, 5, 10, 5, 5, 5, 8, -1, -1, -1, -1, -1, -1,
|
||||
/*FLOA*/ 0, 0, 0, 0, 0, 0, 6, 7, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1,
|
||||
/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 10, 8, 8, 8, 8, -1, -1, -1, -1, -1, -1,
|
||||
/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 10, 8, 8, 8, 8, -1, 16, -1, -1, -1, -1,
|
||||
/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 10, 5, 5, 5, 8, -1, -1, -1, -1, -1, -1,
|
||||
/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, -1, -1, -1, -1, -1, -1,
|
||||
/*UTINY*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1,
|
||||
/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, -1, -1, -1, -1, -1, -1,
|
||||
/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, -1, -1, -1, -1, -1, -1,
|
||||
/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, -1, -1, -1,
|
||||
/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, -1, -1, -1, -1, -1,
|
||||
/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, -1, -1, -1, -1,
|
||||
/*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1,
|
||||
/*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1,
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "streamBackendRocksdb.h"
|
||||
#include "trpc.h"
|
||||
#include "tstream.h"
|
||||
#include "tref.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -70,7 +71,7 @@ struct SActiveCheckpointInfo {
|
|||
SStreamTmrInfo chkptReadyMsgTmr;
|
||||
};
|
||||
|
||||
int32_t streamCleanBeforeQuitTmr(SStreamTmrInfo* pInfo, SStreamTask* pTask);
|
||||
void streamCleanBeforeQuitTmr(SStreamTmrInfo* pInfo, void* param);
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
|
@ -225,6 +226,8 @@ void destroyMetaHbInfo(SMetaHbInfo* pInfo);
|
|||
void streamMetaWaitForHbTmrQuit(SStreamMeta* pMeta);
|
||||
void streamMetaGetHbSendInfo(SMetaHbInfo* pInfo, int64_t* pStartTs, int32_t* pSendCount);
|
||||
int32_t streamMetaSendHbHelper(SStreamMeta* pMeta);
|
||||
int32_t metaRefMgtAdd(int64_t vgId, int64_t* rid);
|
||||
void metaRefMgtRemove(int64_t* pRefId);
|
||||
|
||||
ECHECKPOINT_BACKUP_TYPE streamGetCheckpointBackupType();
|
||||
|
||||
|
|
|
@ -299,13 +299,14 @@ void streamTaskStartMonitorCheckRsp(SStreamTask* pTask) {
|
|||
return;
|
||||
}
|
||||
|
||||
int32_t unusedRetRef = streamMetaAcquireOneTask(pTask); // add task ref here
|
||||
streamTaskInitTaskCheckInfo(pInfo, &pTask->outputInfo, taosGetTimestampMs());
|
||||
|
||||
int32_t ref = atomic_add_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s start check-rsp monitor, ref:%d ", pTask->id.idStr, ref);
|
||||
streamTmrStart(rspMonitorFn, CHECK_RSP_CHECK_INTERVAL, pTask, streamTimer, &pInfo->checkRspTmr, vgId,
|
||||
"check-status-monitor");
|
||||
int64_t* pTaskRefId = NULL;
|
||||
code = streamTaskAllocRefId(pTask, &pTaskRefId);
|
||||
if (code == 0) {
|
||||
streamTmrStart(rspMonitorFn, CHECK_RSP_CHECK_INTERVAL, pTaskRefId, streamTimer, &pInfo->checkRspTmr, vgId,
|
||||
"check-status-monitor");
|
||||
}
|
||||
|
||||
streamMutexUnlock(&pInfo->checkInfoLock);
|
||||
}
|
||||
|
@ -721,21 +722,45 @@ int32_t addDownstreamFailedStatusResultAsync(SMsgCb* pMsgCb, int32_t vgId, int64
|
|||
return streamTaskSchedTask(pMsgCb, vgId, streamId, taskId, STREAM_EXEC_T_ADD_FAILED_TASK);
|
||||
}
|
||||
|
||||
static void doCleanup(SStreamTask* pTask, SArray* pNotReadyList, SArray* pTimeoutList, void* param) {
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
|
||||
taosArrayDestroy(pNotReadyList);
|
||||
taosArrayDestroy(pTimeoutList);
|
||||
streamTaskFreeRefId(param);
|
||||
}
|
||||
|
||||
// this function is executed in timer thread
|
||||
void rspMonitorFn(void* param, void* tmrId) {
|
||||
SStreamTask* pTask = param;
|
||||
SStreamMeta* pMeta = pTask->pMeta;
|
||||
STaskCheckInfo* pInfo = &pTask->taskCheckInfo;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
int64_t timeoutDuration = now - pInfo->timeoutStartTs;
|
||||
const char* id = pTask->id.idStr;
|
||||
int32_t numOfReady = 0;
|
||||
int32_t numOfFault = 0;
|
||||
int32_t numOfNotRsp = 0;
|
||||
int32_t numOfNotReady = 0;
|
||||
int32_t numOfTimeout = 0;
|
||||
int32_t total = taosArrayGetSize(pInfo->pList);
|
||||
int64_t taskRefId = *(int64_t*)param;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
SArray* pNotReadyList = NULL;
|
||||
SArray* pTimeoutList = NULL;
|
||||
SStreamMeta* pMeta = NULL;
|
||||
STaskCheckInfo* pInfo = NULL;
|
||||
int32_t vgId = -1;
|
||||
int64_t timeoutDuration = 0;
|
||||
const char* id = NULL;
|
||||
int32_t total = 0;
|
||||
|
||||
SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
|
||||
if (pTask == NULL) {
|
||||
stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
pMeta = pTask->pMeta;
|
||||
pInfo = &pTask->taskCheckInfo;
|
||||
vgId = pTask->pMeta->vgId;
|
||||
timeoutDuration = now - pInfo->timeoutStartTs;
|
||||
id = pTask->id.idStr;
|
||||
total = (int32_t) taosArrayGetSize(pInfo->pList);
|
||||
|
||||
stDebug("s-task:%s start to do check-downstream-rsp check in tmr", id);
|
||||
|
||||
|
@ -744,12 +769,10 @@ void rspMonitorFn(void* param, void* tmrId) {
|
|||
streamMutexUnlock(&pTask->lock);
|
||||
|
||||
if (state.state == TASK_STATUS__STOP) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s status:%s vgId:%d quit from monitor check-rsp tmr, ref:%d", id, state.name, vgId, ref);
|
||||
|
||||
stDebug("s-task:%s status:%s vgId:%d quit from monitor check-rsp tmr", id, state.name, vgId);
|
||||
streamTaskCompleteCheckRsp(pInfo, true, id);
|
||||
|
||||
// not record the failed of the current task if try to close current vnode
|
||||
// not record the failure of the current task if try to close current vnode
|
||||
// otherwise, the put of message operation may incur invalid read of message queue.
|
||||
if (!pMeta->closeFlag) {
|
||||
int32_t code = addDownstreamFailedStatusResultAsync(pTask->pMsgCb, vgId, pTask->id.streamId, pTask->id.taskId);
|
||||
|
@ -758,33 +781,30 @@ void rspMonitorFn(void* param, void* tmrId) {
|
|||
}
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
doCleanup(pTask, pNotReadyList, pTimeoutList, param);
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.state == TASK_STATUS__DROPPING || state.state == TASK_STATUS__READY) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s status:%s vgId:%d quit from monitor check-rsp tmr, ref:%d", id, state.name, vgId, ref);
|
||||
stDebug("s-task:%s status:%s vgId:%d quit from monitor check-rsp tmr", id, state.name, vgId);
|
||||
|
||||
streamTaskCompleteCheckRsp(pInfo, true, id);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
doCleanup(pTask, pNotReadyList, pTimeoutList, param);
|
||||
return;
|
||||
}
|
||||
|
||||
streamMutexLock(&pInfo->checkInfoLock);
|
||||
if (pInfo->notReadyTasks == 0) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s status:%s vgId:%d all downstream ready, quit from monitor rsp tmr, ref:%d", id, state.name, vgId,
|
||||
ref);
|
||||
stDebug("s-task:%s status:%s vgId:%d all downstream ready, quit from monitor rsp tmr", id, state.name, vgId);
|
||||
|
||||
streamTaskCompleteCheckRsp(pInfo, false, id);
|
||||
streamMutexUnlock(&pInfo->checkInfoLock);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
doCleanup(pTask, pNotReadyList, pTimeoutList, param);
|
||||
return;
|
||||
}
|
||||
|
||||
SArray* pNotReadyList = taosArrayInit(4, sizeof(int64_t));
|
||||
SArray* pTimeoutList = taosArrayInit(4, sizeof(int64_t));
|
||||
pNotReadyList = taosArrayInit(4, sizeof(int64_t));
|
||||
pTimeoutList = taosArrayInit(4, sizeof(int64_t));
|
||||
|
||||
if (state.state == TASK_STATUS__UNINIT) {
|
||||
getCheckRspStatus(pInfo, timeoutDuration, &numOfReady, &numOfFault, &numOfNotRsp, pTimeoutList, pNotReadyList, id);
|
||||
|
@ -795,31 +815,25 @@ void rspMonitorFn(void* param, void* tmrId) {
|
|||
// fault tasks detected, not try anymore
|
||||
bool jumpOut = false;
|
||||
if ((numOfReady + numOfFault + numOfNotReady + numOfTimeout + numOfNotRsp) != total) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
|
||||
stError(
|
||||
"s-task:%s vgId:%d internal error in handling the check downstream procedure, rsp number is inconsistent, "
|
||||
"stop rspMonitor tmr, total:%d, notRsp:%d, notReady:%d, fault:%d, timeout:%d, ready:%d ref:%d",
|
||||
id, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady, ref);
|
||||
"stop rspMonitor tmr, total:%d, notRsp:%d, notReady:%d, fault:%d, timeout:%d, ready:%d",
|
||||
id, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady);
|
||||
jumpOut = true;
|
||||
}
|
||||
|
||||
if (numOfFault > 0) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug(
|
||||
"s-task:%s status:%s vgId:%d all rsp. quit from monitor rsp tmr, since vnode-transfer/leader-change/restart "
|
||||
"detected, total:%d, notRsp:%d, notReady:%d, fault:%d, timeout:%d, ready:%d ref:%d",
|
||||
id, state.name, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady, ref);
|
||||
"detected, total:%d, notRsp:%d, notReady:%d, fault:%d, timeout:%d, ready:%d",
|
||||
id, state.name, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady);
|
||||
jumpOut = true;
|
||||
}
|
||||
|
||||
if (jumpOut) {
|
||||
streamTaskCompleteCheckRsp(pInfo, false, id);
|
||||
streamMutexUnlock(&pInfo->checkInfoLock);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
|
||||
taosArrayDestroy(pNotReadyList);
|
||||
taosArrayDestroy(pTimeoutList);
|
||||
doCleanup(pTask, pNotReadyList, pTimeoutList, param);
|
||||
return;
|
||||
}
|
||||
} else { // unexpected status
|
||||
|
@ -828,11 +842,10 @@ void rspMonitorFn(void* param, void* tmrId) {
|
|||
|
||||
// checking of downstream tasks has been stopped by other threads
|
||||
if (pInfo->stopCheckProcess == 1) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug(
|
||||
"s-task:%s status:%s vgId:%d stopped by other threads to check downstream process, total:%d, notRsp:%d, "
|
||||
"notReady:%d, fault:%d, timeout:%d, ready:%d ref:%d",
|
||||
id, state.name, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady, ref);
|
||||
"notReady:%d, fault:%d, timeout:%d, ready:%d",
|
||||
id, state.name, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady);
|
||||
|
||||
streamTaskCompleteCheckRsp(pInfo, false, id);
|
||||
streamMutexUnlock(&pInfo->checkInfoLock);
|
||||
|
@ -842,10 +855,7 @@ void rspMonitorFn(void* param, void* tmrId) {
|
|||
stError("s-task:%s failed to create async record start failed task, code:%s", id, tstrerror(code));
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
|
||||
taosArrayDestroy(pNotReadyList);
|
||||
taosArrayDestroy(pTimeoutList);
|
||||
doCleanup(pTask, pNotReadyList, pTimeoutList, param);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -857,7 +867,7 @@ void rspMonitorFn(void* param, void* tmrId) {
|
|||
handleTimeoutDownstreamTasks(pTask, pTimeoutList);
|
||||
}
|
||||
|
||||
streamTmrStart(rspMonitorFn, CHECK_RSP_CHECK_INTERVAL, pTask, streamTimer, &pInfo->checkRspTmr, vgId,
|
||||
streamTmrStart(rspMonitorFn, CHECK_RSP_CHECK_INTERVAL, param, streamTimer, &pInfo->checkRspTmr, vgId,
|
||||
"check-status-monitor");
|
||||
streamMutexUnlock(&pInfo->checkInfoLock);
|
||||
|
||||
|
@ -865,7 +875,5 @@ void rspMonitorFn(void* param, void* tmrId) {
|
|||
"s-task:%s vgId:%d continue checking rsp in 300ms, total:%d, notRsp:%d, notReady:%d, fault:%d, timeout:%d, "
|
||||
"ready:%d",
|
||||
id, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady);
|
||||
|
||||
taosArrayDestroy(pNotReadyList);
|
||||
taosArrayDestroy(pTimeoutList);
|
||||
doCleanup(pTask, pNotReadyList, pTimeoutList, NULL);
|
||||
}
|
||||
|
|
|
@ -345,13 +345,15 @@ int32_t streamProcessCheckpointTriggerBlock(SStreamTask* pTask, SStreamDataBlock
|
|||
SStreamTmrInfo* pTmrInfo = &pActiveInfo->chkptTriggerMsgTmr;
|
||||
int8_t old = atomic_val_compare_exchange_8(&pTmrInfo->isActive, 0, 1);
|
||||
if (old == 0) {
|
||||
int32_t ref = atomic_add_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s start checkpoint-trigger monitor in 10s, ref:%d ", pTask->id.idStr, ref);
|
||||
stDebug("s-task:%s start checkpoint-trigger monitor in 10s", pTask->id.idStr);
|
||||
|
||||
int32_t unusedRetRef = streamMetaAcquireOneTask(pTask);
|
||||
streamTmrStart(checkpointTriggerMonitorFn, 200, pTask, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
"trigger-recv-monitor");
|
||||
pTmrInfo->launchChkptId = pActiveInfo->activeId;
|
||||
int64_t* pTaskRefId = NULL;
|
||||
code = streamTaskAllocRefId(pTask, &pTaskRefId);
|
||||
if (code == 0) {
|
||||
streamTmrStart(checkpointTriggerMonitorFn, 200, pTaskRefId, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
"trigger-recv-monitor");
|
||||
pTmrInfo->launchChkptId = pActiveInfo->activeId;
|
||||
}
|
||||
} else { // already launched, do nothing
|
||||
stError("s-task:%s previous checkpoint-trigger monitor tmr is set, not start new one", pTask->id.idStr);
|
||||
}
|
||||
|
@ -890,7 +892,7 @@ int32_t streamTaskBuildCheckpoint(SStreamTask* pTask) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t doChkptStatusCheck(SStreamTask* pTask) {
|
||||
static int32_t doChkptStatusCheck(SStreamTask* pTask, void* param) {
|
||||
const char* id = pTask->id.idStr;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
SActiveCheckpointInfo* pActiveInfo = pTask->chkInfo.pActiveInfo;
|
||||
|
@ -898,25 +900,24 @@ static int32_t doChkptStatusCheck(SStreamTask* pTask) {
|
|||
|
||||
// checkpoint-trigger recv flag is set, quit
|
||||
if (pActiveInfo->allUpstreamTriggerRecv) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stDebug("s-task:%s vgId:%d all checkpoint-trigger recv, quit from monitor checkpoint-trigger, ref:%d", id, vgId,
|
||||
ref);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stDebug("s-task:%s vgId:%d all checkpoint-trigger recv, quit from monitor checkpoint-trigger", id, vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pTmrInfo->launchChkptId != pActiveInfo->activeId) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stWarn("s-task:%s vgId:%d checkpoint-trigger retrieve by previous checkpoint procedure, checkpointId:%" PRId64
|
||||
", quit, ref:%d",
|
||||
id, vgId, pTmrInfo->launchChkptId, ref);
|
||||
", quit",
|
||||
id, vgId, pTmrInfo->launchChkptId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// active checkpoint info is cleared for now
|
||||
if ((pActiveInfo->activeId == 0) || (pActiveInfo->transId == 0) || (pTask->chkInfo.startTs == 0)) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stWarn("s-task:%s vgId:%d active checkpoint may be cleared, quit from retrieve checkpoint-trigger send tmr, ref:%d",
|
||||
id, vgId, ref);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stWarn("s-task:%s vgId:%d active checkpoint may be cleared, quit from retrieve checkpoint-trigger send tmr", id,
|
||||
vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -964,22 +965,22 @@ static int32_t doFindNotSendUpstream(SStreamTask* pTask, SArray* pList, SArray**
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t chkptTriggerRecvMonitorHelper(SStreamTask* pTask, SArray* pNotSendList) {
|
||||
static int32_t chkptTriggerRecvMonitorHelper(SStreamTask* pTask, void* param, SArray* pNotSendList) {
|
||||
const char* id = pTask->id.idStr;
|
||||
SArray* pList = pTask->upstreamInfo.pList; // send msg to retrieve checkpoint trigger msg
|
||||
SActiveCheckpointInfo* pActiveInfo = pTask->chkInfo.pActiveInfo;
|
||||
SStreamTmrInfo* pTmrInfo = &pActiveInfo->chkptTriggerMsgTmr;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
|
||||
int32_t code = doChkptStatusCheck(pTask);
|
||||
int32_t code = doChkptStatusCheck(pTask, param);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = doFindNotSendUpstream(pTask, pList, &pNotSendList);
|
||||
if (code) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stDebug("s-task:%s failed to find not send upstream, code:%s, out of tmr, ref:%d", id, tstrerror(code), ref);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stDebug("s-task:%s failed to find not send upstream, code:%s, out of tmr", id, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -993,37 +994,50 @@ static int32_t chkptTriggerRecvMonitorHelper(SStreamTask* pTask, SArray* pNotSen
|
|||
return code;
|
||||
}
|
||||
|
||||
static void doCleanup(SStreamTask* pTask, SArray* pList) {
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
taosArrayDestroy(pList);
|
||||
}
|
||||
|
||||
void checkpointTriggerMonitorFn(void* param, void* tmrId) {
|
||||
SStreamTask* pTask = param;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
const char* id = pTask->id.idStr;
|
||||
SArray* pNotSendList = NULL;
|
||||
SArray* pList = pTask->upstreamInfo.pList; // send msg to retrieve checkpoint trigger msg
|
||||
int32_t code = 0;
|
||||
int32_t numOfNotSend = 0;
|
||||
SArray* pNotSendList = NULL;
|
||||
int64_t taskRefId = *(int64_t*)param;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
|
||||
SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
|
||||
if (pTask == NULL) {
|
||||
stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
const char* id = pTask->id.idStr;
|
||||
SArray* pList = pTask->upstreamInfo.pList; // send msg to retrieve checkpoint trigger msg
|
||||
SActiveCheckpointInfo* pActiveInfo = pTask->chkInfo.pActiveInfo;
|
||||
SStreamTmrInfo* pTmrInfo = &pActiveInfo->chkptTriggerMsgTmr;
|
||||
|
||||
if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stError("s-task:%s source task should not start the checkpoint-trigger monitor fn, ref:%d quit", id, ref);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stError("s-task:%s source task should not start the checkpoint-trigger monitor fn, quit", id);
|
||||
doCleanup(pTask, pNotSendList);
|
||||
return;
|
||||
}
|
||||
|
||||
// check the status every 100ms
|
||||
if (streamTaskShouldStop(pTask)) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stDebug("s-task:%s vgId:%d quit from monitor checkpoint-trigger, ref:%d", id, vgId, ref);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stDebug("s-task:%s vgId:%d quit from monitor checkpoint-trigger", id, vgId);
|
||||
doCleanup(pTask, pNotSendList);
|
||||
return;
|
||||
}
|
||||
|
||||
if (++pTmrInfo->activeCounter < 50) {
|
||||
streamTmrStart(checkpointTriggerMonitorFn, 200, pTask, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
streamTmrStart(checkpointTriggerMonitorFn, 200, param, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
"trigger-recv-monitor");
|
||||
doCleanup(pTask, pNotSendList);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1035,20 +1049,19 @@ void checkpointTriggerMonitorFn(void* param, void* tmrId) {
|
|||
streamMutexUnlock(&pTask->lock);
|
||||
|
||||
if (state.state != TASK_STATUS__CK) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stDebug("s-task:%s vgId:%d status:%s not in checkpoint status, quit from monitor checkpoint-trigger, ref:%d", id,
|
||||
vgId, state.name, ref);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stDebug("s-task:%s vgId:%d status:%s not in checkpoint status, quit from monitor checkpoint-trigger", id,
|
||||
vgId, state.name);
|
||||
doCleanup(pTask, pNotSendList);
|
||||
return;
|
||||
}
|
||||
|
||||
streamMutexLock(&pActiveInfo->lock);
|
||||
code = chkptTriggerRecvMonitorHelper(pTask, pNotSendList);
|
||||
code = chkptTriggerRecvMonitorHelper(pTask, param, pNotSendList);
|
||||
streamMutexUnlock(&pActiveInfo->lock);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
taosArrayDestroy(pNotSendList);
|
||||
doCleanup(pTask, pNotSendList);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1056,15 +1069,14 @@ void checkpointTriggerMonitorFn(void* param, void* tmrId) {
|
|||
numOfNotSend = taosArrayGetSize(pNotSendList);
|
||||
if (numOfNotSend > 0) {
|
||||
stDebug("s-task:%s start to monitor checkpoint-trigger in 10s", id);
|
||||
streamTmrStart(checkpointTriggerMonitorFn, 200, pTask, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
streamTmrStart(checkpointTriggerMonitorFn, 200, param, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
"trigger-recv-monitor");
|
||||
} else {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stDebug("s-task:%s all checkpoint-trigger recved, quit from monitor checkpoint-trigger tmr, ref:%d", id, ref);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stDebug("s-task:%s all checkpoint-trigger recved, quit from monitor checkpoint-trigger tmr", id);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pNotSendList);
|
||||
doCleanup(pTask, pNotSendList);
|
||||
}
|
||||
|
||||
int32_t doSendRetrieveTriggerMsg(SStreamTask* pTask, SArray* pNotSendList) {
|
||||
|
|
|
@ -518,45 +518,66 @@ static void doSendFailedDispatch(SStreamTask* pTask, SDispatchEntry* pEntry, int
|
|||
}
|
||||
}
|
||||
|
||||
static void cleanupInMonitor(int32_t taskId, int64_t taskRefId, void* param) {
|
||||
int32_t ret = taosReleaseRef(streamTaskRefPool, taskRefId);
|
||||
if (ret) {
|
||||
stError("s-task:0x%x failed to release task refId:%" PRId64, taskId, taskRefId);
|
||||
}
|
||||
streamTaskFreeRefId(param);
|
||||
}
|
||||
|
||||
static void doMonitorDispatchData(void* param, void* tmrId) {
|
||||
SStreamTask* pTask = param;
|
||||
const char* id = pTask->id.idStr;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
SDispatchMsgInfo* pMsgInfo = &pTask->msgInfo;
|
||||
int32_t msgId = pMsgInfo->msgId;
|
||||
int32_t code = 0;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
bool inDispatch = true;
|
||||
SStreamTask* pTask = NULL;
|
||||
int64_t taskRefId = *(int64_t*)param;
|
||||
const char* id = NULL;
|
||||
int32_t vgId = -1;
|
||||
SDispatchMsgInfo* pMsgInfo = NULL;
|
||||
int32_t msgId = -1;
|
||||
|
||||
stDebug("s-task:%s start monitor dispatch data", id);
|
||||
pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
|
||||
if (pTask == NULL) {
|
||||
stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
id = pTask->id.idStr;
|
||||
vgId = pTask->pMeta->vgId;
|
||||
pMsgInfo = &pTask->msgInfo;
|
||||
msgId = pMsgInfo->msgId;
|
||||
|
||||
stDebug("s-task:%s start to monitor dispatch data", id);
|
||||
|
||||
if (streamTaskShouldStop(pTask)) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s should stop, abort from timer, ref:%d", pTask->id.idStr, ref);
|
||||
stDebug("s-task:%s should stop, abort from timer", pTask->id.idStr);
|
||||
setNotInDispatchMonitor(pMsgInfo);
|
||||
cleanupInMonitor(pTask->id.taskId, taskRefId, param);
|
||||
return;
|
||||
}
|
||||
|
||||
// slave task not handle the dispatch, downstream not ready will break the monitor timer
|
||||
// follower not handle the dispatch rsp
|
||||
if ((pTask->pMeta->role == NODE_ROLE_FOLLOWER) || (pTask->status.downstreamReady != 1)) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stError("s-task:%s vgId:%d follower or downstream not ready, jump out of monitor tmr, ref:%d", id, vgId, ref);
|
||||
stError("s-task:%s vgId:%d follower or downstream not ready, jump out of monitor tmr", id, vgId);
|
||||
setNotInDispatchMonitor(pMsgInfo);
|
||||
cleanupInMonitor(pTask->id.taskId, taskRefId, param);
|
||||
return;
|
||||
}
|
||||
|
||||
streamMutexLock(&pMsgInfo->lock);
|
||||
if (pTask->outputq.status == TASK_OUTPUT_STATUS__NORMAL) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s not in dispatch procedure, abort from timer, ref:%d", pTask->id.idStr, ref);
|
||||
|
||||
stDebug("s-task:%s not in dispatch procedure, abort from timer", pTask->id.idStr);
|
||||
pMsgInfo->inMonitor = 0;
|
||||
inDispatch = false;
|
||||
}
|
||||
|
||||
streamMutexUnlock(&pMsgInfo->lock);
|
||||
|
||||
if (!inDispatch) {
|
||||
cleanupInMonitor(pTask->id.taskId, taskRefId, param);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -564,6 +585,7 @@ static void doMonitorDispatchData(void* param, void* tmrId) {
|
|||
if (numOfFailed == 0) {
|
||||
stDebug("s-task:%s no error occurs, check again in %dms", id, DISPATCH_RETRY_INTERVAL_MS);
|
||||
streamStartMonitorDispatchData(pTask, DISPATCH_RETRY_INTERVAL_MS);
|
||||
cleanupInMonitor(pTask->id.taskId, taskRefId, param);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -628,18 +650,23 @@ static void doMonitorDispatchData(void* param, void* tmrId) {
|
|||
}
|
||||
|
||||
if (streamTaskShouldStop(pTask)) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s should stop, abort from timer, ref:%d", pTask->id.idStr, ref);
|
||||
stDebug("s-task:%s should stop, abort from timer", pTask->id.idStr);
|
||||
setNotInDispatchMonitor(pMsgInfo);
|
||||
} else {
|
||||
streamStartMonitorDispatchData(pTask, DISPATCH_RETRY_INTERVAL_MS);
|
||||
}
|
||||
|
||||
cleanupInMonitor(pTask->id.taskId, taskRefId, param);
|
||||
}
|
||||
|
||||
void streamStartMonitorDispatchData(SStreamTask* pTask, int64_t waitDuration) {
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
streamTmrStart(doMonitorDispatchData, waitDuration, pTask, streamTimer, &pTask->msgInfo.pRetryTmr, vgId,
|
||||
"dispatch-monitor");
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
int64_t* pTaskRefId = NULL;
|
||||
int32_t code = streamTaskAllocRefId(pTask, &pTaskRefId);
|
||||
if (code == 0) {
|
||||
streamTmrStart(doMonitorDispatchData, waitDuration, pTaskRefId, streamTimer, &pTask->msgInfo.pRetryTmr, vgId,
|
||||
"dispatch-monitor");
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t doAddDispatchBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, SSDataBlock* pDataBlock,
|
||||
|
@ -854,9 +881,9 @@ int32_t streamDispatchStreamBlock(SStreamTask* pTask) {
|
|||
} else {
|
||||
streamMutexLock(&pTask->msgInfo.lock);
|
||||
if (pTask->msgInfo.inMonitor == 0) {
|
||||
int32_t ref = atomic_add_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s start dispatch monitor tmr in %dms, ref:%d, dispatch code:%s", id, DISPATCH_RETRY_INTERVAL_MS,
|
||||
ref, tstrerror(code));
|
||||
// int32_t ref = atomic_add_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s start dispatch monitor tmr in %dms, dispatch code:%s", id, DISPATCH_RETRY_INTERVAL_MS,
|
||||
tstrerror(code));
|
||||
streamStartMonitorDispatchData(pTask, DISPATCH_RETRY_INTERVAL_MS);
|
||||
pTask->msgInfo.inMonitor = 1;
|
||||
} else {
|
||||
|
@ -911,31 +938,31 @@ int32_t initCheckpointReadyMsg(SStreamTask* pTask, int32_t upstreamNodeId, int32
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t doTaskChkptStatusCheck(SStreamTask* pTask, int32_t num) {
|
||||
static int32_t doTaskChkptStatusCheck(SStreamTask* pTask, void* param, int32_t num) {
|
||||
SActiveCheckpointInfo* pActiveInfo = pTask->chkInfo.pActiveInfo;
|
||||
SStreamTmrInfo* pTmrInfo = &pActiveInfo->chkptReadyMsgTmr;
|
||||
const char* id = pTask->id.idStr;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
|
||||
if (pTmrInfo->launchChkptId != pActiveInfo->activeId) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stWarn("s-task:%s vgId:%d ready-msg send tmr launched by previous checkpoint procedure, checkpointId:%" PRId64
|
||||
", quit, ref:%d",
|
||||
id, vgId, pTmrInfo->launchChkptId, ref);
|
||||
", quit",
|
||||
id, vgId, pTmrInfo->launchChkptId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// active checkpoint info is cleared for now
|
||||
if ((pActiveInfo->activeId == 0) || (pActiveInfo->transId == 0) || (num == 0) || (pTask->chkInfo.startTs == 0)) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stWarn("s-task:%s vgId:%d active checkpoint may be cleared, quit from readyMsg send tmr, ref:%d", id, vgId, ref);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stWarn("s-task:%s vgId:%d active checkpoint may be cleared, quit from readyMsg send tmr", id, vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pTask->upstreamInfo.pList) != num) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stWarn("s-task:%s vgId:%d upstream number:%d not equals sent readyMsg:%d, quit from readyMsg send tmr, ref:%d", id,
|
||||
vgId, (int32_t)taosArrayGetSize(pTask->upstreamInfo.pList), num, ref);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stWarn("s-task:%s vgId:%d upstream number:%d not equals sent readyMsg:%d, quit from readyMsg send tmr", id,
|
||||
vgId, (int32_t)taosArrayGetSize(pTask->upstreamInfo.pList), num);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1011,7 +1038,7 @@ static void doSendChkptReadyMsg(SStreamTask* pTask, SArray* pNotRspList, int64_t
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t chkptReadyMsgSendHelper(SStreamTask* pTask, SArray* pNotRspList) {
|
||||
static int32_t chkptReadyMsgSendHelper(SStreamTask* pTask, void* param, SArray* pNotRspList) {
|
||||
SActiveCheckpointInfo* pActiveInfo = pTask->chkInfo.pActiveInfo;
|
||||
SStreamTmrInfo* pTmrInfo = &pActiveInfo->chkptReadyMsgTmr;
|
||||
SArray* pList = pActiveInfo->pReadyMsgList;
|
||||
|
@ -1021,16 +1048,15 @@ static int32_t chkptReadyMsgSendHelper(SStreamTask* pTask, SArray* pNotRspList)
|
|||
const char* id = pTask->id.idStr;
|
||||
int32_t notRsp = 0;
|
||||
|
||||
int32_t code = doTaskChkptStatusCheck(pTask, num);
|
||||
int32_t code = doTaskChkptStatusCheck(pTask, param, num);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = doFindNotConfirmUpstream(&pNotRspList, pList, num, vgId, pTask->info.taskLevel, id);
|
||||
if (code) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stError("s-task:%s failed to find not rsp checkpoint-ready downstream, code:%s, out of tmr, ref:%d", id,
|
||||
tstrerror(code), ref);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stError("s-task:%s failed to find not rsp checkpoint-ready downstream, code:%s, out of tmr", id, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1045,26 +1071,41 @@ static int32_t chkptReadyMsgSendHelper(SStreamTask* pTask, SArray* pNotRspList)
|
|||
}
|
||||
|
||||
static void chkptReadyMsgSendMonitorFn(void* param, void* tmrId) {
|
||||
SStreamTask* pTask = param;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
const char* id = pTask->id.idStr;
|
||||
SActiveCheckpointInfo* pActiveInfo = pTask->chkInfo.pActiveInfo;
|
||||
SStreamTmrInfo* pTmrInfo = &pActiveInfo->chkptReadyMsgTmr;
|
||||
SArray* pNotRspList = NULL;
|
||||
int32_t code = 0;
|
||||
int32_t notRsp = 0;
|
||||
int64_t taskRefId = *(int64_t*)param;
|
||||
int32_t vgId = -1;
|
||||
const char* id = NULL;
|
||||
SActiveCheckpointInfo* pActiveInfo = NULL;
|
||||
SStreamTmrInfo* pTmrInfo = NULL;
|
||||
|
||||
SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
|
||||
if (pTask == NULL) {
|
||||
stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
vgId = pTask->pMeta->vgId;
|
||||
id = pTask->id.idStr;
|
||||
pActiveInfo = pTask->chkInfo.pActiveInfo;
|
||||
pTmrInfo = &pActiveInfo->chkptReadyMsgTmr;
|
||||
|
||||
// check the status every 100ms
|
||||
if (streamTaskShouldStop(pTask)) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stDebug("s-task:%s vgId:%d status:stop, quit from monitor checkpoint-trigger, ref:%d", id, vgId, ref);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stDebug("s-task:%s vgId:%d status:stop, quit from monitor checkpoint-trigger", id, vgId);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
taosArrayDestroy(pNotRspList);
|
||||
return;
|
||||
}
|
||||
|
||||
if (++pTmrInfo->activeCounter < 50) {
|
||||
streamTmrStart(chkptReadyMsgSendMonitorFn, 200, pTask, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
streamTmrStart(chkptReadyMsgSendMonitorFn, 200, param, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
"chkpt-ready-monitor");
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
taosArrayDestroy(pNotRspList);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1078,15 +1119,16 @@ static void chkptReadyMsgSendMonitorFn(void* param, void* tmrId) {
|
|||
|
||||
// 1. check status in the first place
|
||||
if (state.state != TASK_STATUS__CK) {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
stDebug("s-task:%s vgId:%d status:%s not in checkpoint, quit from monitor checkpoint-ready, ref:%d", id, vgId,
|
||||
state.name, ref);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stDebug("s-task:%s vgId:%d status:%s not in checkpoint, quit from monitor checkpoint-ready", id, vgId,
|
||||
state.name);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
taosArrayDestroy(pNotRspList);
|
||||
return;
|
||||
}
|
||||
|
||||
streamMutexLock(&pActiveInfo->lock);
|
||||
code = chkptReadyMsgSendHelper(pTask, pNotRspList);
|
||||
code = chkptReadyMsgSendHelper(pTask, param, pNotRspList);
|
||||
streamMutexUnlock(&pActiveInfo->lock);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -1098,18 +1140,18 @@ static void chkptReadyMsgSendMonitorFn(void* param, void* tmrId) {
|
|||
notRsp = taosArrayGetSize(pNotRspList);
|
||||
if (notRsp > 0) { // send checkpoint-ready msg again
|
||||
stDebug("s-task:%s start to monitor checkpoint-ready msg recv status in 10s", id);
|
||||
streamTmrStart(chkptReadyMsgSendMonitorFn, 200, pTask, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
streamTmrStart(chkptReadyMsgSendMonitorFn, 200, param, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
"chkpt-ready-monitor");
|
||||
} else {
|
||||
int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask);
|
||||
streamCleanBeforeQuitTmr(pTmrInfo, param);
|
||||
stDebug(
|
||||
"s-task:%s vgId:%d checkpoint-ready msg confirmed by all upstream task(s), clear checkpoint-ready msg and quit "
|
||||
"from timer, ref:%d",
|
||||
id, vgId, ref);
|
||||
// release should be the last execution, since pTask may be destroy after it immidiately.
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
"from timer",
|
||||
id, vgId);
|
||||
}
|
||||
|
||||
// release should be the last execution, since pTask may be destroyed after it immediately.
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
taosArrayDestroy(pNotRspList);
|
||||
}
|
||||
|
||||
|
@ -1160,15 +1202,17 @@ int32_t streamTaskSendCheckpointReadyMsg(SStreamTask* pTask) {
|
|||
|
||||
int8_t old = atomic_val_compare_exchange_8(&pTmrInfo->isActive, 0, 1);
|
||||
if (old == 0) {
|
||||
int32_t ref = atomic_add_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s start checkpoint-ready monitor in 10s, ref:%d ", pTask->id.idStr, ref);
|
||||
int32_t unusedRetRef = streamMetaAcquireOneTask(pTask);
|
||||
stDebug("s-task:%s start checkpoint-ready monitor in 10s", pTask->id.idStr);
|
||||
|
||||
streamTmrStart(chkptReadyMsgSendMonitorFn, 200, pTask, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
"chkpt-ready-monitor");
|
||||
int64_t* pTaskRefId = NULL;
|
||||
int32_t code = streamTaskAllocRefId(pTask, &pTaskRefId);
|
||||
if (code == 0) {
|
||||
streamTmrStart(chkptReadyMsgSendMonitorFn, 200, pTaskRefId, streamTimer, &pTmrInfo->tmrHandle, vgId,
|
||||
"chkpt-ready-monitor");
|
||||
|
||||
// mark the timer monitor checkpointId
|
||||
pTmrInfo->launchChkptId = pActiveInfo->activeId;
|
||||
// mark the timer monitor checkpointId
|
||||
pTmrInfo->launchChkptId = pActiveInfo->activeId;
|
||||
}
|
||||
} else {
|
||||
stError("s-task:%s previous checkpoint-ready monitor tmr is set, not start new one", pTask->id.idStr);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "ttimer.h"
|
||||
#include "wal.h"
|
||||
|
||||
int32_t streamMetaId = 0;
|
||||
int32_t streamMetaRefPool = 0;
|
||||
|
||||
struct SMetaHbInfo {
|
||||
tmr_h hbTmr;
|
||||
|
@ -123,17 +123,21 @@ int32_t streamMetaSendHbHelper(SStreamMeta* pMeta) {
|
|||
|
||||
for(int32_t i = 0; i < numOfTasks; ++i) {
|
||||
SStreamTaskId* pId = taosArrayGet(pMeta->pTaskList, i);
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
SStreamTask** pTask = taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (pTask == NULL) {
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
SStreamTask* pTask = NULL;
|
||||
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*pTask)->info.fillHistory == 1) {
|
||||
if (pTask->info.fillHistory == 1) {
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
continue;
|
||||
}
|
||||
|
||||
epsetAssign(&epset, &(*pTask)->info.mnodeEpset);
|
||||
epsetAssign(&epset, &pTask->info.mnodeEpset);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -159,28 +163,30 @@ int32_t streamMetaSendHbHelper(SStreamMeta* pMeta) {
|
|||
for (int32_t i = 0; i < numOfTasks; ++i) {
|
||||
SStreamTaskId* pId = taosArrayGet(pMeta->pTaskList, i);
|
||||
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
SStreamTask** pTask = taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (pTask == NULL) {
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
SStreamTask* pTask = NULL;
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// not report the status of fill-history task
|
||||
if ((*pTask)->info.fillHistory == 1) {
|
||||
if (pTask->info.fillHistory == 1) {
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
continue;
|
||||
}
|
||||
|
||||
streamMutexLock(&(*pTask)->lock);
|
||||
STaskStatusEntry entry = streamTaskGetStatusEntry(*pTask);
|
||||
streamMutexUnlock(&(*pTask)->lock);
|
||||
streamMutexLock(&pTask->lock);
|
||||
STaskStatusEntry entry = streamTaskGetStatusEntry(pTask);
|
||||
streamMutexUnlock(&pTask->lock);
|
||||
|
||||
entry.inputRate = entry.inputQUsed * 100.0 / (2 * STREAM_TASK_QUEUE_CAPACITY_IN_SIZE);
|
||||
if ((*pTask)->info.taskLevel == TASK_LEVEL__SINK) {
|
||||
entry.sinkQuota = (*pTask)->outputInfo.pTokenBucket->quotaRate;
|
||||
entry.sinkDataSize = SIZE_IN_MiB((*pTask)->execInfo.sink.dataSize);
|
||||
if (pTask->info.taskLevel == TASK_LEVEL__SINK) {
|
||||
entry.sinkQuota = pTask->outputInfo.pTokenBucket->quotaRate;
|
||||
entry.sinkDataSize = SIZE_IN_MiB(pTask->execInfo.sink.dataSize);
|
||||
}
|
||||
|
||||
SActiveCheckpointInfo* p = (*pTask)->chkInfo.pActiveInfo;
|
||||
SActiveCheckpointInfo* p = pTask->chkInfo.pActiveInfo;
|
||||
if (p->activeId != 0) {
|
||||
entry.checkpointInfo.failed = (p->failedId >= p->activeId) ? 1 : 0;
|
||||
entry.checkpointInfo.activeId = p->activeId;
|
||||
|
@ -188,40 +194,42 @@ int32_t streamMetaSendHbHelper(SStreamMeta* pMeta) {
|
|||
|
||||
if (entry.checkpointInfo.failed) {
|
||||
stInfo("s-task:%s set kill checkpoint trans in hbMsg, transId:%d, clear the active checkpointInfo",
|
||||
(*pTask)->id.idStr, p->transId);
|
||||
pTask->id.idStr, p->transId);
|
||||
|
||||
streamMutexLock(&(*pTask)->lock);
|
||||
streamTaskClearCheckInfo((*pTask), true);
|
||||
streamMutexUnlock(&(*pTask)->lock);
|
||||
streamMutexLock(&pTask->lock);
|
||||
streamTaskClearCheckInfo(pTask, true);
|
||||
streamMutexUnlock(&pTask->lock);
|
||||
}
|
||||
}
|
||||
|
||||
streamMutexLock(&(*pTask)->lock);
|
||||
entry.checkpointInfo.consensusChkptId = streamTaskCheckIfReqConsenChkptId(*pTask, pMsg->ts);
|
||||
streamMutexLock(&pTask->lock);
|
||||
entry.checkpointInfo.consensusChkptId = streamTaskCheckIfReqConsenChkptId(pTask, pMsg->ts);
|
||||
if (entry.checkpointInfo.consensusChkptId) {
|
||||
entry.checkpointInfo.consensusTs = pMsg->ts;
|
||||
}
|
||||
streamMutexUnlock(&(*pTask)->lock);
|
||||
streamMutexUnlock(&pTask->lock);
|
||||
|
||||
if ((*pTask)->exec.pWalReader != NULL) {
|
||||
entry.processedVer = walReaderGetCurrentVer((*pTask)->exec.pWalReader) - 1;
|
||||
if (pTask->exec.pWalReader != NULL) {
|
||||
entry.processedVer = walReaderGetCurrentVer(pTask->exec.pWalReader) - 1;
|
||||
if (entry.processedVer < 0) {
|
||||
entry.processedVer = (*pTask)->chkInfo.processedVer;
|
||||
entry.processedVer = pTask->chkInfo.processedVer;
|
||||
}
|
||||
|
||||
walReaderValidVersionRange((*pTask)->exec.pWalReader, &entry.verRange.minVer, &entry.verRange.maxVer);
|
||||
walReaderValidVersionRange(pTask->exec.pWalReader, &entry.verRange.minVer, &entry.verRange.maxVer);
|
||||
}
|
||||
|
||||
addUpdateNodeIntoHbMsg(*pTask, pMsg);
|
||||
addUpdateNodeIntoHbMsg(pTask, pMsg);
|
||||
p = taosArrayPush(pMsg->pTaskStatus, &entry);
|
||||
if (p == NULL) {
|
||||
stError("failed to add taskInfo:0x%x in hbMsg, vgId:%d", (*pTask)->id.taskId, pMeta->vgId);
|
||||
stError("failed to add taskInfo:0x%x in hbMsg, vgId:%d", pTask->id.taskId, pMeta->vgId);
|
||||
}
|
||||
|
||||
if (!hasMnodeEpset) {
|
||||
epsetAssign(&epset, &(*pTask)->info.mnodeEpset);
|
||||
epsetAssign(&epset, &pTask->info.mnodeEpset);
|
||||
hasMnodeEpset = true;
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
}
|
||||
|
||||
pMsg->numOfTasks = taosArrayGetSize(pMsg->pTaskStatus);
|
||||
|
@ -244,9 +252,10 @@ void streamMetaHbToMnode(void* param, void* tmrId) {
|
|||
int32_t vgId = 0;
|
||||
int32_t role = 0;
|
||||
|
||||
SStreamMeta* pMeta = taosAcquireRef(streamMetaId, rid);
|
||||
SStreamMeta* pMeta = taosAcquireRef(streamMetaRefPool, rid);
|
||||
if (pMeta == NULL) {
|
||||
stError("invalid rid:%" PRId64 " failed to acquired stream-meta", rid);
|
||||
stError("invalid meta rid:%" PRId64 " failed to acquired stream-meta", rid);
|
||||
// taosMemoryFree(param);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -256,24 +265,26 @@ void streamMetaHbToMnode(void* param, void* tmrId) {
|
|||
// need to stop, stop now
|
||||
if (pMeta->closeFlag) {
|
||||
pMeta->pHbInfo->hbStart = 0;
|
||||
code = taosReleaseRef(streamMetaId, rid);
|
||||
code = taosReleaseRef(streamMetaRefPool, rid);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
stDebug("vgId:%d jump out of meta timer", vgId);
|
||||
} else {
|
||||
stError("vgId:%d jump out of meta timer, failed to release the meta rid:%" PRId64, vgId, rid);
|
||||
}
|
||||
// taosMemoryFree(param);
|
||||
return;
|
||||
}
|
||||
|
||||
// not leader not send msg
|
||||
if (pMeta->role != NODE_ROLE_LEADER) {
|
||||
pMeta->pHbInfo->hbStart = 0;
|
||||
code = taosReleaseRef(streamMetaId, rid);
|
||||
code = taosReleaseRef(streamMetaRefPool, rid);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
stInfo("vgId:%d role:%d not leader not send hb to mnode", vgId, role);
|
||||
} else {
|
||||
stError("vgId:%d role:%d not leader not send hb to mnodefailed to release the meta rid:%" PRId64, vgId, role, rid);
|
||||
}
|
||||
// taosMemoryFree(param);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -281,7 +292,7 @@ void streamMetaHbToMnode(void* param, void* tmrId) {
|
|||
streamTmrStart(streamMetaHbToMnode, META_HB_CHECK_INTERVAL, param, streamTimer, &pMeta->pHbInfo->hbTmr, vgId,
|
||||
"meta-hb-tmr");
|
||||
|
||||
code = taosReleaseRef(streamMetaId, rid);
|
||||
code = taosReleaseRef(streamMetaRefPool, rid);
|
||||
if (code) {
|
||||
stError("vgId:%d in meta timer, failed to release the meta rid:%" PRId64, vgId, rid);
|
||||
}
|
||||
|
@ -298,12 +309,13 @@ void streamMetaHbToMnode(void* param, void* tmrId) {
|
|||
if (code) {
|
||||
stError("vgId:%d failed to send hmMsg to mnode, try again in 5s, code:%s", pMeta->vgId, tstrerror(code));
|
||||
}
|
||||
|
||||
streamMetaRUnLock(pMeta);
|
||||
|
||||
streamTmrStart(streamMetaHbToMnode, META_HB_CHECK_INTERVAL, param, streamTimer, &pMeta->pHbInfo->hbTmr, pMeta->vgId,
|
||||
"meta-hb-tmr");
|
||||
|
||||
code = taosReleaseRef(streamMetaId, rid);
|
||||
code = taosReleaseRef(streamMetaRefPool, rid);
|
||||
if (code) {
|
||||
stError("vgId:%d in meta timer, failed to release the meta rid:%" PRId64, vgId, rid);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "executor.h"
|
||||
#include "streamBackendRocksdb.h"
|
||||
#include "streamInt.h"
|
||||
#include "tmisce.h"
|
||||
|
@ -28,6 +27,7 @@ static TdThreadOnce streamMetaModuleInit = PTHREAD_ONCE_INIT;
|
|||
int32_t streamBackendId = 0;
|
||||
int32_t streamBackendCfWrapperId = 0;
|
||||
int32_t taskDbWrapperId = 0;
|
||||
int32_t streamTaskRefPool = 0;
|
||||
|
||||
static int32_t streamMetaBegin(SStreamMeta* pMeta);
|
||||
static void streamMetaCloseImpl(void* arg);
|
||||
|
@ -41,14 +41,14 @@ SMetaRefMgt gMetaRefMgt;
|
|||
|
||||
int32_t metaRefMgtInit();
|
||||
void metaRefMgtCleanup();
|
||||
int32_t metaRefMgtAdd(int64_t vgId, int64_t* rid);
|
||||
|
||||
static void streamMetaEnvInit() {
|
||||
streamBackendId = taosOpenRef(64, streamBackendCleanup);
|
||||
streamBackendCfWrapperId = taosOpenRef(64, streamBackendHandleCleanup);
|
||||
taskDbWrapperId = taosOpenRef(64, taskDbDestroy2);
|
||||
|
||||
streamMetaId = taosOpenRef(64, streamMetaCloseImpl);
|
||||
streamMetaRefPool = taosOpenRef(64, streamMetaCloseImpl);
|
||||
streamTaskRefPool = taosOpenRef(64, tFreeStreamTask);
|
||||
|
||||
int32_t code = metaRefMgtInit();
|
||||
if (code) {
|
||||
|
@ -72,7 +72,8 @@ void streamMetaInit() {
|
|||
void streamMetaCleanup() {
|
||||
taosCloseRef(streamBackendId);
|
||||
taosCloseRef(streamBackendCfWrapperId);
|
||||
taosCloseRef(streamMetaId);
|
||||
taosCloseRef(streamMetaRefPool);
|
||||
taosCloseRef(streamTaskRefPool);
|
||||
|
||||
metaRefMgtCleanup();
|
||||
streamTimerCleanUp();
|
||||
|
@ -98,16 +99,12 @@ int32_t metaRefMgtInit() {
|
|||
void metaRefMgtCleanup() {
|
||||
void* pIter = taosHashIterate(gMetaRefMgt.pTable, NULL);
|
||||
while (pIter) {
|
||||
SArray* list = *(SArray**)pIter;
|
||||
for (int i = 0; i < taosArrayGetSize(list); i++) {
|
||||
void* rid = taosArrayGetP(list, i);
|
||||
taosMemoryFree(rid);
|
||||
}
|
||||
taosArrayDestroy(list);
|
||||
int64_t* p = *(int64_t**) pIter;
|
||||
taosMemoryFree(p);
|
||||
pIter = taosHashIterate(gMetaRefMgt.pTable, pIter);
|
||||
}
|
||||
taosHashCleanup(gMetaRefMgt.pTable);
|
||||
|
||||
taosHashCleanup(gMetaRefMgt.pTable);
|
||||
streamMutexDestroy(&gMetaRefMgt.mutex);
|
||||
}
|
||||
|
||||
|
@ -117,35 +114,32 @@ int32_t metaRefMgtAdd(int64_t vgId, int64_t* rid) {
|
|||
|
||||
streamMutexLock(&gMetaRefMgt.mutex);
|
||||
|
||||
p = taosHashGet(gMetaRefMgt.pTable, &vgId, sizeof(vgId));
|
||||
p = taosHashGet(gMetaRefMgt.pTable, &rid, sizeof(rid));
|
||||
if (p == NULL) {
|
||||
SArray* pList = taosArrayInit(8, POINTER_BYTES);
|
||||
if (pList == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
p = taosArrayPush(pList, &rid);
|
||||
if (p == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
code = taosHashPut(gMetaRefMgt.pTable, &vgId, sizeof(vgId), &pList, sizeof(void*));
|
||||
code = taosHashPut(gMetaRefMgt.pTable, &rid, sizeof(rid), &rid, sizeof(void*));
|
||||
if (code) {
|
||||
stError("vgId:%d failed to put into metaRef table, rid:%" PRId64, (int32_t)vgId, *rid);
|
||||
stError("vgId:%d failed to put into refId mgt, refId:%" PRId64" %p, code:%s", (int32_t)vgId, *rid, rid,
|
||||
tstrerror(code));
|
||||
return code;
|
||||
} else { // not
|
||||
// stInfo("add refId:%"PRId64" vgId:%d, %p", *rid, (int32_t)vgId, rid);
|
||||
}
|
||||
} else {
|
||||
SArray* list = *(SArray**)p;
|
||||
void* px = taosArrayPush(list, &rid);
|
||||
if (px == NULL) {
|
||||
code = terrno;
|
||||
}
|
||||
stFatal("try to add refId:%"PRId64" vgId:%d, %p that already added into mgt", *rid, (int32_t) vgId, rid);
|
||||
}
|
||||
|
||||
streamMutexUnlock(&gMetaRefMgt.mutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
void metaRefMgtRemove(int64_t* pRefId) {
|
||||
streamMutexLock(&gMetaRefMgt.mutex);
|
||||
|
||||
int32_t code = taosHashRemove(gMetaRefMgt.pTable, &pRefId, sizeof(pRefId));
|
||||
taosMemoryFree(pRefId);
|
||||
streamMutexUnlock(&gMetaRefMgt.mutex);
|
||||
}
|
||||
|
||||
int32_t streamMetaOpenTdb(SStreamMeta* pMeta) {
|
||||
if (tdbOpen(pMeta->path, 16 * 1024, 1, &pMeta->db, 0, 0, NULL) < 0) {
|
||||
stError("vgId:%d open file:%s failed, stream meta open failed", pMeta->vgId, pMeta->path);
|
||||
|
@ -458,7 +452,7 @@ int32_t streamMetaOpen(const char* path, void* ahandle, FTaskBuild buildTaskFn,
|
|||
TSDB_CHECK_CODE(code, lino, _err);
|
||||
|
||||
// add refId at the end of initialization function
|
||||
pMeta->rid = taosAddRef(streamMetaId, pMeta);
|
||||
pMeta->rid = taosAddRef(streamMetaRefPool, pMeta);
|
||||
|
||||
int64_t* pRid = taosMemoryMalloc(sizeof(int64_t));
|
||||
TSDB_CHECK_NULL(pRid, code, lino, _err, terrno);
|
||||
|
@ -531,17 +525,28 @@ void streamMetaClear(SStreamMeta* pMeta) {
|
|||
// remove all existed tasks in this vnode
|
||||
void* pIter = NULL;
|
||||
while ((pIter = taosHashIterate(pMeta->pTasksMap, pIter)) != NULL) {
|
||||
SStreamTask* p = *(SStreamTask**)pIter;
|
||||
int64_t refId = *(int64_t*)pIter;
|
||||
SStreamTask* p = taosAcquireRef(streamTaskRefPool, refId);
|
||||
if (p == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// release the ref by timer
|
||||
if (p->info.delaySchedParam != 0 && p->info.fillHistory == 0) { // one more ref in timer
|
||||
stDebug("s-task:%s stop schedTimer, and (before) desc ref:%d", p->id.idStr, p->refCnt);
|
||||
stDebug("s-task:%s stop schedTimer", p->id.idStr);
|
||||
streamTmrStop(p->schedInfo.pDelayTimer);
|
||||
p->info.delaySchedParam = 0;
|
||||
streamMetaReleaseTask(pMeta, p);
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, p);
|
||||
int32_t code = taosRemoveRef(streamTaskRefPool, refId);
|
||||
if (code) {
|
||||
stError("vgId:%d remove task refId failed, refId:%" PRId64, pMeta->vgId, refId);
|
||||
}
|
||||
|
||||
code = taosReleaseRef(streamTaskRefPool, refId);
|
||||
if (code) {
|
||||
stError("vgId:%d failed to release refId:%" PRId64, pMeta->vgId, refId);
|
||||
}
|
||||
}
|
||||
|
||||
if (pMeta->streamBackendRid != 0) {
|
||||
|
@ -571,9 +576,9 @@ void streamMetaClose(SStreamMeta* pMeta) {
|
|||
if (pMeta == NULL) {
|
||||
return;
|
||||
}
|
||||
int32_t code = taosRemoveRef(streamMetaId, pMeta->rid);
|
||||
int32_t code = taosRemoveRef(streamMetaRefPool, pMeta->rid);
|
||||
if (code) {
|
||||
stError("vgId:%d failed to remove ref:%" PRId64 ", code:%s", pMeta->vgId, pMeta->rid, tstrerror(code));
|
||||
stError("vgId:%d failed to remove meta ref:%" PRId64 ", code:%s", pMeta->vgId, pMeta->rid, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -660,9 +665,16 @@ int32_t streamMetaSaveTask(SStreamMeta* pMeta, SStreamTask* pTask) {
|
|||
code = tdbTbUpsert(pMeta->pTaskDb, id, STREAM_TASK_KEY_LEN, buf, len, pMeta->txn);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
code = terrno;
|
||||
stError("s-task:%s vgId:%d task meta save to disk failed, code:%s", pTask->id.idStr, vgId, tstrerror(terrno));
|
||||
stError("s-task:%s vgId:%d refId:%" PRId64 " task meta save to disk failed, remove ref, code:%s", pTask->id.idStr,
|
||||
vgId, pTask->id.refId, tstrerror(code));
|
||||
|
||||
int64_t refId = pTask->id.refId;
|
||||
int32_t ret = taosRemoveRef(streamTaskRefPool, pTask->id.refId);
|
||||
if (ret != 0) {
|
||||
stError("s-task:0x%x failed to remove ref, refId:%"PRId64, (int32_t) id[1], refId);
|
||||
}
|
||||
} else {
|
||||
stDebug("s-task:%s vgId:%d task meta save to disk", pTask->id.idStr, vgId);
|
||||
stDebug("s-task:%s vgId:%d refId:%" PRId64 " task meta save to disk", pTask->id.idStr, vgId, pTask->id.refId);
|
||||
}
|
||||
|
||||
taosMemoryFree(buf);
|
||||
|
@ -687,34 +699,54 @@ int32_t streamMetaRegisterTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTa
|
|||
*pAdded = false;
|
||||
|
||||
int32_t code = 0;
|
||||
int64_t refId = 0;
|
||||
STaskId id = streamTaskGetTaskId(pTask);
|
||||
void* p = taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
|
||||
if (p != NULL) {
|
||||
stDebug("s-task:%" PRIx64 " already exist in meta, no need to register", id.taskId);
|
||||
tFreeStreamTask(pTask);
|
||||
return code;
|
||||
}
|
||||
|
||||
if ((code = pMeta->buildTaskFn(pMeta->ahandle, pTask, ver)) != 0) {
|
||||
tFreeStreamTask(pTask);
|
||||
return code;
|
||||
}
|
||||
|
||||
p = taosArrayPush(pMeta->pTaskList, &pTask->id);
|
||||
if (p == NULL) {
|
||||
stError("s-task:0x%" PRIx64 " failed to register task into meta-list, code: out of memory", id.taskId);
|
||||
tFreeStreamTask(pTask);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
code = taosHashPut(pMeta->pTasksMap, &id, sizeof(id), &pTask, POINTER_BYTES);
|
||||
pTask->id.refId = refId = taosAddRef(streamTaskRefPool, pTask);
|
||||
code = taosHashPut(pMeta->pTasksMap, &id, sizeof(id), &pTask->id.refId, sizeof(int64_t));
|
||||
if (code) {
|
||||
stError("s-task:0x%" PRIx64 " failed to register task into meta-list, code: out of memory", id.taskId);
|
||||
|
||||
int32_t ret = taosRemoveRef(streamTaskRefPool, refId);
|
||||
if (ret != 0) {
|
||||
stError("s-task:0x%x failed to remove ref, refId:%"PRId64, (int32_t) id.taskId, refId);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
if ((code = streamMetaSaveTask(pMeta, pTask)) != 0) {
|
||||
int32_t ret = taosRemoveRef(streamTaskRefPool, refId);
|
||||
if (ret) {
|
||||
stError("vgId:%d remove task refId failed, refId:%" PRId64, pMeta->vgId, refId);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
if ((code = streamMetaCommit(pMeta)) != 0) {
|
||||
int32_t ret = taosRemoveRef(streamTaskRefPool, refId);
|
||||
if (ret) {
|
||||
stError("vgId:%d remove task refId failed, refId:%" PRId64, pMeta->vgId, refId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -722,6 +754,9 @@ int32_t streamMetaRegisterTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTa
|
|||
int32_t val = atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1);
|
||||
}
|
||||
|
||||
// enable the scheduler for stream tasks
|
||||
streamSetupScheduleTrigger(pTask);
|
||||
|
||||
*pAdded = true;
|
||||
return code;
|
||||
}
|
||||
|
@ -737,16 +772,72 @@ int32_t streamMetaGetNumOfTasks(SStreamMeta* pMeta) {
|
|||
}
|
||||
|
||||
int32_t streamMetaAcquireTaskNoLock(SStreamMeta* pMeta, int64_t streamId, int32_t taskId, SStreamTask** pTask) {
|
||||
STaskId id = {.streamId = streamId, .taskId = taskId};
|
||||
SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (ppTask == NULL || streamTaskShouldStop(*ppTask)) {
|
||||
*pTask = NULL;
|
||||
QRY_PARAM_CHECK(pTask);
|
||||
STaskId id = {.streamId = streamId, .taskId = taskId};
|
||||
int64_t* pTaskRefId = (int64_t*)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (pTaskRefId == NULL) {
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
}
|
||||
|
||||
int32_t ref = atomic_add_fetch_32(&(*ppTask)->refCnt, 1);
|
||||
stTrace("s-task:%s acquire task, ref:%d", (*ppTask)->id.idStr, ref);
|
||||
*pTask = *ppTask;
|
||||
SStreamTask* p = taosAcquireRef(streamTaskRefPool, *pTaskRefId);
|
||||
if (p == NULL) {
|
||||
stDebug("s-task:%x failed to acquire task refId:%"PRId64", may have been destoried", taskId, *pTaskRefId);
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (p->id.refId != *pTaskRefId) {
|
||||
stFatal("s-task:%x inconsistent refId, task refId:%" PRId64 " try acquire:%" PRId64, taskId, *pTaskRefId,
|
||||
p->id.refId);
|
||||
int32_t ret = taosReleaseRef(streamTaskRefPool, *pTaskRefId);
|
||||
if (ret) {
|
||||
stError("s-task:0x%x failed to release task refId:%" PRId64, taskId, *pTaskRefId);
|
||||
}
|
||||
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (streamTaskShouldStop(p)) {
|
||||
stDebug("s-task:%s is stopped, failed to acquire it now", p->id.idStr);
|
||||
int32_t ret = taosReleaseRef(streamTaskRefPool, *pTaskRefId);
|
||||
if (ret) {
|
||||
stError("s-task:0x%x failed to release task refId:%" PRId64, taskId, *pTaskRefId);
|
||||
}
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
}
|
||||
|
||||
stDebug("s-task:%s acquire task, refId:%" PRId64, p->id.idStr, p->id.refId);
|
||||
*pTask = p;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t streamMetaAcquireTaskUnsafe(SStreamMeta* pMeta, STaskId* pId, SStreamTask** pTask) {
|
||||
QRY_PARAM_CHECK(pTask);
|
||||
int64_t* pTaskRefId = (int64_t*)taosHashGet(pMeta->pTasksMap, pId, sizeof(*pId));
|
||||
|
||||
if (pTaskRefId == NULL) {
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
}
|
||||
|
||||
SStreamTask* p = taosAcquireRef(streamTaskRefPool, *pTaskRefId);
|
||||
if (p == NULL) {
|
||||
stDebug("s-task:%" PRIx64 " failed to acquire task refId:%" PRId64 ", may have been destoried", pId->taskId,
|
||||
*pTaskRefId);
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (p->id.refId != *pTaskRefId) {
|
||||
stFatal("s-task:%" PRIx64 " inconsistent refId, task refId:%" PRId64 " try acquire:%" PRId64, pId->taskId,
|
||||
*pTaskRefId, p->id.refId);
|
||||
int32_t ret = taosReleaseRef(streamTaskRefPool, *pTaskRefId);
|
||||
if (ret) {
|
||||
stError("s-task:0x%" PRIx64 " failed to release task refId:%" PRId64, pId->taskId, *pTaskRefId);
|
||||
}
|
||||
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
}
|
||||
|
||||
stDebug("s-task:%s acquire task, refId:%" PRId64, p->id.idStr, p->id.refId);
|
||||
*pTask = p;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -757,28 +848,17 @@ int32_t streamMetaAcquireTask(SStreamMeta* pMeta, int64_t streamId, int32_t task
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t streamMetaAcquireOneTask(SStreamTask* pTask) {
|
||||
int32_t ref = atomic_add_fetch_32(&pTask->refCnt, 1);
|
||||
stTrace("s-task:%s acquire task, ref:%d", pTask->id.idStr, ref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
void streamMetaReleaseTask(SStreamMeta* UNUSED_PARAM(pMeta), SStreamTask* pTask) {
|
||||
if (pTask == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t taskId = pTask->id.taskId;
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->refCnt, 1);
|
||||
|
||||
// not safe to use the pTask->id.idStr, since pTask may be released by other threads when print logs.
|
||||
if (ref > 0) {
|
||||
stTrace("s-task:0x%x release task, ref:%d", taskId, ref);
|
||||
} else if (ref == 0) {
|
||||
stTrace("s-task:0x%x all refs are gone, free it", taskId);
|
||||
tFreeStreamTask(pTask);
|
||||
} else if (ref < 0) {
|
||||
stError("task ref is invalid, ref:%d, 0x%x", ref, taskId);
|
||||
int64_t refId = pTask->id.refId;
|
||||
stDebug("s-task:0x%x release task, refId:%" PRId64, taskId, pTask->id.refId);
|
||||
int32_t ret = taosReleaseRef(streamTaskRefPool, pTask->id.refId);
|
||||
if (ret) {
|
||||
stError("s-task:0x%x failed to release task refId:%" PRId64, taskId, refId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -816,13 +896,10 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t
|
|||
int32_t code = 0;
|
||||
STaskId id = {.streamId = streamId, .taskId = taskId};
|
||||
|
||||
// pre-delete operation
|
||||
streamMetaWLock(pMeta);
|
||||
|
||||
SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (ppTask) {
|
||||
pTask = *ppTask;
|
||||
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code == 0) {
|
||||
// desc the paused task counter
|
||||
if (streamTaskShouldPause(pTask)) {
|
||||
int32_t num = atomic_sub_fetch_32(&pMeta->numOfPausedTasks, 1);
|
||||
|
@ -834,43 +911,9 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t
|
|||
if (code) {
|
||||
stError("s-task:0x%" PRIx64 " failed to handle dropping event async, code:%s", id.taskId, tstrerror(code));
|
||||
}
|
||||
} else {
|
||||
stDebug("vgId:%d failed to find the task:0x%x, it may be dropped already", vgId, taskId);
|
||||
streamMetaWUnLock(pMeta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
streamMetaWUnLock(pMeta);
|
||||
stDebug("s-task:0x%x vgId:%d set task status:dropping and start to unregister it", taskId, vgId);
|
||||
|
||||
stDebug("s-task:0x%x vgId:%d set task status:dropping and start to unregister it", taskId, vgId);
|
||||
|
||||
while (1) {
|
||||
int32_t timerActive = 0;
|
||||
|
||||
streamMetaRLock(pMeta);
|
||||
ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (ppTask) {
|
||||
// to make sure check status will not start the check downstream status when we start to check timerActive count.
|
||||
streamMutexLock(&pTask->taskCheckInfo.checkInfoLock);
|
||||
timerActive = (*ppTask)->status.timerActive;
|
||||
streamMutexUnlock(&pTask->taskCheckInfo.checkInfoLock);
|
||||
}
|
||||
streamMetaRUnLock(pMeta);
|
||||
|
||||
if (timerActive > 0) {
|
||||
taosMsleep(100);
|
||||
stDebug("s-task:0x%" PRIx64 " wait for quit from timer", id.taskId);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// let's do delete of stream task
|
||||
streamMetaWLock(pMeta);
|
||||
|
||||
ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (ppTask) {
|
||||
pTask = *ppTask;
|
||||
// it is a fill-history task, remove the related stream task's id that points to it
|
||||
if (pTask->info.fillHistory == 0) {
|
||||
int32_t ret = atomic_sub_fetch_32(&pMeta->numOfStreamTasks, 1);
|
||||
|
@ -888,21 +931,22 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t
|
|||
if (sizeInList != size) {
|
||||
stError("vgId:%d tasks number not consistent in list:%d and map:%d, ", vgId, sizeInList, size);
|
||||
}
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
int32_t numOfTmr = pTask->status.timerActive;
|
||||
if (numOfTmr != 0) {
|
||||
stError("s-task:%s vgId:%d invalid timer Active record:%d, internal error", pTask->id.idStr, vgId, numOfTmr);
|
||||
}
|
||||
|
||||
if (pTask->info.delaySchedParam != 0 && pTask->info.fillHistory == 0) {
|
||||
stDebug("s-task:%s stop schedTimer, and (before) desc ref:%d", pTask->id.idStr, pTask->refCnt);
|
||||
stDebug("s-task:%s stop schedTimer", pTask->id.idStr);
|
||||
streamTmrStop(pTask->schedInfo.pDelayTimer);
|
||||
pTask->info.delaySchedParam = 0;
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
}
|
||||
|
||||
|
||||
int64_t refId = pTask->id.refId;
|
||||
int32_t ret = taosRemoveRef(streamTaskRefPool, refId);
|
||||
if (ret != 0) {
|
||||
stError("s-task:0x%x failed to remove ref, refId:%"PRId64, (int32_t) id.taskId, refId);
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
streamMetaWUnLock(pMeta);
|
||||
} else {
|
||||
stDebug("vgId:%d failed to find the task:0x%x, it may have been dropped already", vgId, taskId);
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
@ -1012,13 +1056,13 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) {
|
|||
return;
|
||||
}
|
||||
|
||||
vgId = pMeta->vgId;
|
||||
pRecycleList = taosArrayInit(4, sizeof(STaskId));
|
||||
if (pRecycleList == NULL) {
|
||||
stError("vgId:%d failed prepare load all tasks, code:out of memory", vgId);
|
||||
return;
|
||||
}
|
||||
|
||||
vgId = pMeta->vgId;
|
||||
stInfo("vgId:%d load stream tasks from meta files", vgId);
|
||||
|
||||
code = tdbTbcOpen(pMeta->pTaskDb, &pCur, NULL);
|
||||
|
@ -1062,9 +1106,9 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) {
|
|||
|
||||
if (pTask->status.taskStatus == TASK_STATUS__DROPPING) {
|
||||
int32_t taskId = pTask->id.taskId;
|
||||
tFreeStreamTask(pTask);
|
||||
|
||||
STaskId id = streamTaskGetTaskId(pTask);
|
||||
|
||||
tFreeStreamTask(pTask);
|
||||
void* px = taosArrayPush(pRecycleList, &id);
|
||||
if (px == NULL) {
|
||||
stError("s-task:0x%x failed record the task into recycle list due to out of memory", taskId);
|
||||
|
@ -1100,13 +1144,25 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (taosHashPut(pMeta->pTasksMap, &id, sizeof(id), &pTask, POINTER_BYTES) != 0) {
|
||||
stError("s-task:0x%x failed to put into hashTable, code:%s, continue", pTask->id.taskId, tstrerror(terrno));
|
||||
void* px = taosArrayPop(pMeta->pTaskList);
|
||||
tFreeStreamTask(pTask);
|
||||
pTask->id.refId = taosAddRef(streamTaskRefPool, pTask);
|
||||
|
||||
if (taosHashPut(pMeta->pTasksMap, &id, sizeof(id), &pTask->id.refId, sizeof(int64_t)) != 0) {
|
||||
int64_t refId = pTask->id.refId;
|
||||
stError("s-task:0x%x failed to put into hashTable, code:%s, remove task ref, refId:%" PRId64 " continue",
|
||||
pTask->id.taskId, tstrerror(terrno), refId);
|
||||
|
||||
void* px = taosArrayPop(pMeta->pTaskList);
|
||||
int32_t ret = taosRemoveRef(streamTaskRefPool, refId);
|
||||
if (ret != 0) {
|
||||
stError("s-task:0x%x failed to remove ref, refId:%" PRId64, (int32_t)id.taskId, refId);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// enable the scheduler for stream tasks after acquire the task RefId.
|
||||
streamSetupScheduleTrigger(pTask);
|
||||
|
||||
stInfo("s-task:0x%x vgId:%d set refId:%"PRId64, (int32_t) id.taskId, vgId, pTask->id.refId);
|
||||
if (pTask->info.fillHistory == 0) {
|
||||
int32_t val = atomic_add_fetch_32(&pMeta->numOfStreamTasks, 1);
|
||||
}
|
||||
|
@ -1142,72 +1198,22 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) {
|
|||
}
|
||||
}
|
||||
|
||||
bool streamMetaTaskInTimer(SStreamMeta* pMeta) {
|
||||
bool inTimer = false;
|
||||
streamMetaRLock(pMeta);
|
||||
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pMeta->pTasksMap, pIter);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
if (pTask->status.timerActive >= 1) {
|
||||
stDebug("s-task:%s in timer, blocking tasks in vgId:%d restart, set closing again", pTask->id.idStr, pMeta->vgId);
|
||||
int32_t code = streamTaskStop(pTask);
|
||||
if (code) {
|
||||
stError("s-task:%s failed to stop task, code:%s", pTask->id.idStr, tstrerror(code));
|
||||
}
|
||||
inTimer = true;
|
||||
}
|
||||
}
|
||||
|
||||
streamMetaRUnLock(pMeta);
|
||||
return inTimer;
|
||||
}
|
||||
|
||||
void streamMetaNotifyClose(SStreamMeta* pMeta) {
|
||||
int32_t vgId = pMeta->vgId;
|
||||
int64_t startTs = 0;
|
||||
int32_t sendCount = 0;
|
||||
streamMetaGetHbSendInfo(pMeta->pHbInfo, &startTs, &sendCount);
|
||||
|
||||
streamMetaGetHbSendInfo(pMeta->pHbInfo, &startTs, &sendCount);
|
||||
stInfo("vgId:%d notify all stream tasks that current vnode is closing. isLeader:%d startHb:%" PRId64 ", totalHb:%d",
|
||||
vgId, (pMeta->role == NODE_ROLE_LEADER), startTs, sendCount);
|
||||
|
||||
// wait for the stream meta hb function stopping
|
||||
streamMetaWaitForHbTmrQuit(pMeta);
|
||||
|
||||
streamMetaWLock(pMeta);
|
||||
|
||||
pMeta->closeFlag = true;
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pMeta->pTasksMap, pIter);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
stDebug("vgId:%d s-task:%s set task closing flag", vgId, pTask->id.idStr);
|
||||
int32_t code = streamTaskStop(pTask);
|
||||
if (code) {
|
||||
stError("vgId:%d failed to stop task:0x%x, code:%s", vgId, pTask->id.taskId, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
stDebug("vgId:%d start to check all tasks for closing", vgId);
|
||||
int64_t st = taosGetTimestampMs();
|
||||
|
||||
while (streamMetaTaskInTimer(pMeta)) {
|
||||
stDebug("vgId:%d some tasks in timer, wait for 100ms and recheck", pMeta->vgId);
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
streamMetaRLock(pMeta);
|
||||
|
||||
SArray* pTaskList = NULL;
|
||||
|
@ -1215,14 +1221,34 @@ void streamMetaNotifyClose(SStreamMeta* pMeta) {
|
|||
if (code != TSDB_CODE_SUCCESS) {
|
||||
}
|
||||
|
||||
streamMetaRUnLock(pMeta);
|
||||
int32_t numOfTasks = taosArrayGetSize(pTaskList);
|
||||
for (int32_t i = 0; i < numOfTasks; ++i) {
|
||||
SStreamTaskId* pTaskId = taosArrayGet(pTaskList, i);
|
||||
SStreamTask* pTask = NULL;
|
||||
|
||||
if (pTaskList != NULL) {
|
||||
taosArrayDestroy(pTaskList);
|
||||
code = streamMetaAcquireTaskNoLock(pMeta, pTaskId->streamId, pTaskId->taskId, &pTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int64_t refId = pTask->id.refId;
|
||||
int32_t ret = streamTaskStop(pTask);
|
||||
if (ret) {
|
||||
stError("s-task:0x%x failed to stop task, code:%s", pTaskId->taskId, tstrerror(ret));
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
ret = taosRemoveRef(streamTaskRefPool, refId);
|
||||
if (ret) {
|
||||
stError("vgId:%d failed to remove task:0x%x, refId:%" PRId64, pMeta->vgId, pTaskId->taskId, refId);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t el = taosGetTimestampMs() - st;
|
||||
stDebug("vgId:%d all stream tasks are not in timer, continue close, elapsed time:%" PRId64 " ms", pMeta->vgId, el);
|
||||
taosArrayDestroy(pTaskList);
|
||||
|
||||
double el = (taosGetTimestampMs() - st) / 1000.0;
|
||||
stDebug("vgId:%d stop all %d task(s) completed, elapsed time:%.2f Sec.", pMeta->vgId, numOfTasks, el);
|
||||
streamMetaRUnLock(pMeta);
|
||||
}
|
||||
|
||||
void streamMetaStartHb(SStreamMeta* pMeta) {
|
||||
|
@ -1232,12 +1258,12 @@ void streamMetaStartHb(SStreamMeta* pMeta) {
|
|||
return;
|
||||
}
|
||||
|
||||
*pRid = pMeta->rid;
|
||||
int32_t code = metaRefMgtAdd(pMeta->vgId, pRid);
|
||||
if (code) {
|
||||
return;
|
||||
}
|
||||
|
||||
*pRid = pMeta->rid;
|
||||
streamMetaHbToMnode(pRid, NULL);
|
||||
}
|
||||
|
||||
|
@ -1312,13 +1338,15 @@ bool streamMetaAllTasksReady(const SStreamMeta* pMeta) {
|
|||
for (int32_t i = 0; i < num; ++i) {
|
||||
SStreamTaskId* pId = taosArrayGet(pMeta->pTaskList, i);
|
||||
STaskId id = {.streamId = pId->streamId, .taskId = pId->taskId};
|
||||
SStreamTask** ppTask = taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (ppTask == NULL) {
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTaskUnsafe((SStreamMeta*)pMeta, &id, &pTask);
|
||||
|
||||
if ((*ppTask)->status.downstreamReady == 0) {
|
||||
return false;
|
||||
if (code == 0) {
|
||||
if (pTask->status.downstreamReady == 0) {
|
||||
streamMetaReleaseTask((SStreamMeta*)pMeta, pTask);
|
||||
return false;
|
||||
}
|
||||
streamMetaReleaseTask((SStreamMeta*)pMeta, pTask);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1335,10 +1363,13 @@ int32_t streamMetaResetTaskStatus(SStreamMeta* pMeta) {
|
|||
|
||||
for (int32_t i = 0; i < numOfTasks; ++i) {
|
||||
SStreamTaskId* pTaskId = taosArrayGet(pMeta->pTaskList, i);
|
||||
|
||||
STaskId id = {.streamId = pTaskId->streamId, .taskId = pTaskId->taskId};
|
||||
SStreamTask** pTask = taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
streamTaskResetStatus(*pTask);
|
||||
STaskId id = {.streamId = pTaskId->streamId, .taskId = pTaskId->taskId};
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code == 0) {
|
||||
streamTaskResetStatus(pTask);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1347,7 +1378,7 @@ int32_t streamMetaResetTaskStatus(SStreamMeta* pMeta) {
|
|||
void streamMetaAddIntoUpdateTaskList(SStreamMeta* pMeta, SStreamTask* pTask, SStreamTask* pHTask, int32_t transId,
|
||||
int64_t startTs) {
|
||||
const char* id = pTask->id.idStr;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
int32_t vgId = pMeta->vgId;
|
||||
int32_t code = 0;
|
||||
|
||||
// keep the already updated info
|
||||
|
|
|
@ -20,15 +20,18 @@ static void streamTaskResumeHelper(void* param, void* tmrId);
|
|||
static void streamTaskSchedHelper(void* param, void* tmrId);
|
||||
|
||||
void streamSetupScheduleTrigger(SStreamTask* pTask) {
|
||||
int64_t delaySchema = pTask->info.delaySchedParam;
|
||||
if (delaySchema != 0 && pTask->info.fillHistory == 0) {
|
||||
int32_t ref = streamMetaAcquireOneTask(pTask);
|
||||
stDebug("s-task:%s setup scheduler trigger, ref:%d delay:%" PRId64 " ms", pTask->id.idStr, ref,
|
||||
pTask->info.delaySchedParam);
|
||||
int64_t delayParam = pTask->info.delaySchedParam;
|
||||
if (delayParam != 0 && pTask->info.fillHistory == 0) {
|
||||
int64_t* pTaskRefId = NULL;
|
||||
int32_t code = streamTaskAllocRefId(pTask, &pTaskRefId);
|
||||
if (code == 0) {
|
||||
stDebug("s-task:%s refId:%" PRId64 " enable the scheduler trigger, delay:%" PRId64, pTask->id.idStr,
|
||||
pTask->id.refId, delayParam);
|
||||
|
||||
streamTmrStart(streamTaskSchedHelper, (int32_t)delaySchema, pTask, streamTimer, &pTask->schedInfo.pDelayTimer,
|
||||
pTask->pMeta->vgId, "sched-tmr");
|
||||
pTask->schedInfo.status = TASK_TRIGGER_STATUS__INACTIVE;
|
||||
streamTmrStart(streamTaskSchedHelper, (int32_t)delayParam, pTaskRefId, streamTimer,
|
||||
&pTask->schedInfo.pDelayTimer, pTask->pMeta->vgId, "sched-tmr");
|
||||
pTask->schedInfo.status = TASK_TRIGGER_STATUS__INACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,49 +78,67 @@ void streamTaskClearSchedIdleInfo(SStreamTask* pTask) { pTask->status.schedIdleT
|
|||
void streamTaskSetIdleInfo(SStreamTask* pTask, int32_t idleTime) { pTask->status.schedIdleTime = idleTime; }
|
||||
|
||||
void streamTaskResumeInFuture(SStreamTask* pTask) {
|
||||
int32_t ref = atomic_add_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s task should idle, add into timer to retry in %dms, ref:%d", pTask->id.idStr,
|
||||
pTask->status.schedIdleTime, ref);
|
||||
stDebug("s-task:%s task should idle, add into timer to retry in %dms", pTask->id.idStr,
|
||||
pTask->status.schedIdleTime);
|
||||
|
||||
// add one ref count for task
|
||||
int32_t unusedRetRef = streamMetaAcquireOneTask(pTask);
|
||||
streamTmrStart(streamTaskResumeHelper, pTask->status.schedIdleTime, pTask, streamTimer, &pTask->schedInfo.pIdleTimer,
|
||||
pTask->pMeta->vgId, "resume-task-tmr");
|
||||
int64_t* pTaskRefId = NULL;
|
||||
int32_t code = streamTaskAllocRefId(pTask, &pTaskRefId);
|
||||
if (code == 0) {
|
||||
streamTmrStart(streamTaskResumeHelper, pTask->status.schedIdleTime, pTaskRefId, streamTimer,
|
||||
&pTask->schedInfo.pIdleTimer, pTask->pMeta->vgId, "resume-task-tmr");
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void streamTaskResumeHelper(void* param, void* tmrId) {
|
||||
SStreamTask* pTask = (SStreamTask*)param;
|
||||
int32_t code = 0;
|
||||
int64_t taskRefId = *(int64_t*)param;
|
||||
SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
|
||||
if (pTask == NULL) {
|
||||
stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
SStreamTaskId* pId = &pTask->id;
|
||||
SStreamTaskState p = streamTaskGetStatus(pTask);
|
||||
int32_t code = 0;
|
||||
|
||||
if (p.state == TASK_STATUS__DROPPING || p.state == TASK_STATUS__STOP) {
|
||||
int8_t status = streamTaskSetSchedStatusInactive(pTask);
|
||||
TAOS_UNUSED(status);
|
||||
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s status:%s not resume task, ref:%d", pId->idStr, p.name, ref);
|
||||
|
||||
stDebug("s-task:%s status:%s not resume task", pId->idStr, p.name);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
code = streamTaskSchedTask(pTask->pMsgCb, pTask->info.nodeId, pId->streamId, pId->taskId, STREAM_EXEC_T_RESUME_TASK);
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
if (code) {
|
||||
stError("s-task:%s sched task failed, code:%s, ref:%d", pId->idStr, tstrerror(code), ref);
|
||||
stError("s-task:%s sched task failed, code:%s", pId->idStr, tstrerror(code));
|
||||
} else {
|
||||
stDebug("trigger to resume s-task:%s after idled for %dms, ref:%d", pId->idStr, pTask->status.schedIdleTime, ref);
|
||||
stDebug("trigger to resume s-task:%s after idled for %dms", pId->idStr, pTask->status.schedIdleTime);
|
||||
|
||||
// release the task ref count
|
||||
streamTaskClearSchedIdleInfo(pTask);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamTaskFreeRefId(param);
|
||||
}
|
||||
|
||||
void streamTaskSchedHelper(void* param, void* tmrId) {
|
||||
SStreamTask* pTask = (void*)param;
|
||||
int64_t taskRefId = *(int64_t*)param;
|
||||
SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
|
||||
if (pTask == NULL) {
|
||||
stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
stDebug("s-task:%s acquire task, refId:%"PRId64, pTask->id.idStr, pTask->id.refId);
|
||||
|
||||
const char* id = pTask->id.idStr;
|
||||
int32_t nextTrigger = (int32_t)pTask->info.delaySchedParam;
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
|
@ -125,8 +146,18 @@ void streamTaskSchedHelper(void* param, void* tmrId) {
|
|||
int8_t status = atomic_load_8(&pTask->schedInfo.status);
|
||||
stTrace("s-task:%s in scheduler, trigger status:%d, next:%dms", id, status, nextTrigger);
|
||||
|
||||
if (streamTaskShouldStop(pTask) || streamTaskShouldPause(pTask)) {
|
||||
if (streamTaskShouldStop(pTask)) {
|
||||
stDebug("s-task:%s should stop, jump out of schedTimer", id);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
if (streamTaskShouldPause(pTask)) {
|
||||
stDebug("s-task:%s is paused, recheck in %.2fs", id, nextTrigger/1000.0);
|
||||
streamTmrStart(streamTaskSchedHelper, nextTrigger, param, streamTimer, &pTask->schedInfo.pDelayTimer, vgId,
|
||||
"sched-run-tmr");
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -171,6 +202,7 @@ void streamTaskSchedHelper(void* param, void* tmrId) {
|
|||
}
|
||||
|
||||
_end:
|
||||
streamTmrStart(streamTaskSchedHelper, nextTrigger, pTask, streamTimer, &pTask->schedInfo.pDelayTimer, vgId,
|
||||
streamTmrStart(streamTaskSchedHelper, nextTrigger, param, streamTimer, &pTask->schedInfo.pDelayTimer, vgId,
|
||||
"sched-run-tmr");
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "streamInt.h"
|
||||
#include "streamsm.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimer.h"
|
||||
#include "wal.h"
|
||||
|
@ -24,7 +25,7 @@
|
|||
#define SCANHISTORY_IDLE_TICK ((SCANHISTORY_MAX_IDLE_TIME * 1000) / SCANHISTORY_IDLE_TIME_SLICE)
|
||||
|
||||
typedef struct SLaunchHTaskInfo {
|
||||
SStreamMeta* pMeta;
|
||||
int64_t metaRid;
|
||||
STaskId id;
|
||||
STaskId hTaskId;
|
||||
} SLaunchHTaskInfo;
|
||||
|
@ -87,21 +88,15 @@ void streamExecScanHistoryInFuture(SStreamTask* pTask, int32_t idleDuration) {
|
|||
numOfTicks = SCANHISTORY_IDLE_TICK;
|
||||
}
|
||||
|
||||
// add ref for task
|
||||
SStreamTask* p = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, &p);
|
||||
if (p == NULL || code != 0) {
|
||||
stError("s-task:0x%x failed to acquire task, status:%s, not exec scan-history data", pTask->id.taskId,
|
||||
streamTaskGetStatus(pTask).name);
|
||||
return;
|
||||
}
|
||||
|
||||
pTask->schedHistoryInfo.numOfTicks = numOfTicks;
|
||||
|
||||
int32_t ref = atomic_add_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s scan-history resumed in %.2fs, ref:%d", pTask->id.idStr, numOfTicks * 0.1, ref);
|
||||
streamTmrStart(doExecScanhistoryInFuture, SCANHISTORY_IDLE_TIME_SLICE, pTask, streamTimer,
|
||||
&pTask->schedHistoryInfo.pTimer, vgId, "history-task");
|
||||
stDebug("s-task:%s scan-history resumed in %.2fs", pTask->id.idStr, numOfTicks * 0.1);
|
||||
int64_t* pTaskRefId = NULL;
|
||||
int32_t ret = streamTaskAllocRefId(pTask, &pTaskRefId);
|
||||
if (ret == 0) {
|
||||
streamTmrStart(doExecScanhistoryInFuture, SCANHISTORY_IDLE_TIME_SLICE, pTaskRefId, streamTimer,
|
||||
&pTask->schedHistoryInfo.pTimer, vgId, "history-task");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t streamTaskStartScanHistory(SStreamTask* pTask) {
|
||||
|
@ -220,42 +215,32 @@ int32_t streamLaunchFillHistoryTask(SStreamTask* pTask) {
|
|||
|
||||
// Set the execution conditions, including the query time window and the version range
|
||||
streamMetaRLock(pMeta);
|
||||
SStreamTask** pHTask = taosHashGet(pMeta->pTasksMap, &pTask->hTaskInfo.id, sizeof(pTask->hTaskInfo.id));
|
||||
SStreamTask* pHisTask = NULL;
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &pTask->hTaskInfo.id, &pHisTask);
|
||||
streamMetaRUnLock(pMeta);
|
||||
|
||||
if (pHTask != NULL) { // it is already added into stream meta store.
|
||||
SStreamTask* pHisTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, hStreamId, hTaskId, &pHisTask);
|
||||
if (pHisTask == NULL) {
|
||||
stDebug("s-task:%s failed acquire and start fill-history task, it may have been dropped/stopped", idStr);
|
||||
code = streamMetaAddTaskLaunchResult(pMeta, hStreamId, hTaskId, pExecInfo->checkTs, pExecInfo->readyTs, false);
|
||||
if (code == 0) { // it is already added into stream meta store.
|
||||
if (pHisTask->status.downstreamReady == 1) { // it's ready now, do nothing
|
||||
stDebug("s-task:%s fill-history task is ready, no need to check downstream", pHisTask->id.idStr);
|
||||
code = streamMetaAddTaskLaunchResult(pMeta, hStreamId, hTaskId, pExecInfo->checkTs, pExecInfo->readyTs, true);
|
||||
if (code) {
|
||||
stError("s-task:%s failed to record start task status, code:%s", idStr, tstrerror(code));
|
||||
}
|
||||
} else {
|
||||
if (pHisTask->status.downstreamReady == 1) { // it's ready now, do nothing
|
||||
stDebug("s-task:%s fill-history task is ready, no need to check downstream", pHisTask->id.idStr);
|
||||
code = streamMetaAddTaskLaunchResult(pMeta, hStreamId, hTaskId, pExecInfo->checkTs, pExecInfo->readyTs, true);
|
||||
if (code) {
|
||||
stError("s-task:%s failed to record start task status, code:%s", idStr, tstrerror(code));
|
||||
}
|
||||
} else { // exist, but not ready, continue check downstream task status
|
||||
if (pHisTask->pBackend == NULL) {
|
||||
code = pMeta->expandTaskFn(pHisTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
streamMetaAddFailedTaskSelf(pHisTask, now);
|
||||
stError("s-task:%s failed to expand fill-history task, code:%s", pHisTask->id.idStr, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
checkFillhistoryTaskStatus(pTask, pHisTask);
|
||||
} else { // exist, but not ready, continue check downstream task status
|
||||
if (pHisTask->pBackend == NULL) {
|
||||
code = pMeta->expandTaskFn(pHisTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
streamMetaAddFailedTaskSelf(pHisTask, now);
|
||||
stError("s-task:%s failed to expand fill-history task, code:%s", pHisTask->id.idStr, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pHisTask);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
checkFillhistoryTaskStatus(pTask, pHisTask);
|
||||
}
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pHisTask);
|
||||
return code;
|
||||
} else {
|
||||
return launchNotBuiltFillHistoryTask(pTask);
|
||||
|
@ -296,14 +281,14 @@ void notRetryLaunchFillHistoryTask(SStreamTask* pTask, SLaunchHTaskInfo* pInfo,
|
|||
SStreamMeta* pMeta = pTask->pMeta;
|
||||
SHistoryTaskInfo* pHTaskInfo = &pTask->hTaskInfo;
|
||||
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
// int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
int32_t code = streamMetaAddTaskLaunchResult(pMeta, pInfo->hTaskId.streamId, pInfo->hTaskId.taskId, 0, now, false);
|
||||
|
||||
if (code) {
|
||||
stError("s-task:%s failed to record the start task status, code:%s", pTask->id.idStr, tstrerror(code));
|
||||
} else {
|
||||
stError("s-task:%s max retry:%d reached, quit from retrying launch related fill-history task:0x%x, ref:%d",
|
||||
pTask->id.idStr, MAX_RETRY_LAUNCH_HISTORY_TASK, (int32_t)pHTaskInfo->id.taskId, ref);
|
||||
stError("s-task:%s max retry:%d reached, quit from retrying launch related fill-history task:0x%x",
|
||||
pTask->id.idStr, MAX_RETRY_LAUNCH_HISTORY_TASK, (int32_t)pHTaskInfo->id.taskId);
|
||||
}
|
||||
|
||||
pHTaskInfo->id.taskId = 0;
|
||||
|
@ -315,9 +300,9 @@ void doRetryLaunchFillHistoryTask(SStreamTask* pTask, SLaunchHTaskInfo* pInfo, i
|
|||
SHistoryTaskInfo* pHTaskInfo = &pTask->hTaskInfo;
|
||||
|
||||
if (streamTaskShouldStop(pTask)) { // record the failure
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:0x%" PRIx64 " stopped, not launch rel history task:0x%" PRIx64 ", ref:%d", pInfo->id.taskId,
|
||||
pInfo->hTaskId.taskId, ref);
|
||||
// int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:0x%" PRIx64 " stopped, not launch rel history task:0x%" PRIx64, pInfo->id.taskId,
|
||||
pInfo->hTaskId.taskId);
|
||||
|
||||
int32_t code = streamMetaAddTaskLaunchResult(pMeta, pInfo->hTaskId.streamId, pInfo->hTaskId.taskId, 0, now, false);
|
||||
if (code) {
|
||||
|
@ -336,30 +321,60 @@ void doRetryLaunchFillHistoryTask(SStreamTask* pTask, SLaunchHTaskInfo* pInfo, i
|
|||
}
|
||||
}
|
||||
|
||||
static void doCleanup(SStreamTask* pTask, int64_t metaRid, SLaunchHTaskInfo* pInfo) {
|
||||
SStreamMeta* pMeta = pTask->pMeta;
|
||||
int32_t vgId = pMeta->vgId;
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
int32_t ret = taosReleaseRef(streamMetaRefPool, metaRid);
|
||||
if (ret) {
|
||||
stError("vgId:%d failed to release meta refId:%"PRId64, vgId, metaRid);
|
||||
}
|
||||
|
||||
if (pInfo != NULL) {
|
||||
taosMemoryFree(pInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void tryLaunchHistoryTask(void* param, void* tmrId) {
|
||||
SLaunchHTaskInfo* pInfo = param;
|
||||
SStreamMeta* pMeta = pInfo->pMeta;
|
||||
int64_t metaRid = pInfo->metaRid;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
int32_t code = 0;
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t vgId = 0;
|
||||
|
||||
SStreamMeta* pMeta = taosAcquireRef(streamMetaRefPool, metaRid);
|
||||
if (pMeta == NULL) {
|
||||
stError("invalid meta rid:%" PRId64 " failed to acquired stream-meta", metaRid);
|
||||
taosMemoryFree(pInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
vgId = pMeta->vgId;
|
||||
|
||||
streamMetaWLock(pMeta);
|
||||
|
||||
SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &pInfo->id, sizeof(pInfo->id));
|
||||
if (ppTask == NULL || *ppTask == NULL) {
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &pInfo->id, &pTask);
|
||||
if (code != 0) {
|
||||
stError("s-task:0x%x and rel fill-history task:0x%" PRIx64 " all have been destroyed, not launch",
|
||||
(int32_t)pInfo->id.taskId, pInfo->hTaskId.taskId);
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
int32_t ret = taosReleaseRef(streamMetaRefPool, metaRid);
|
||||
if (ret) {
|
||||
stError("vgId:%d failed to release meta refId:%"PRId64, vgId, metaRid);
|
||||
}
|
||||
|
||||
// already dropped, no need to set the failure info into the stream task meta.
|
||||
taosMemoryFree(pInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
if (streamTaskShouldStop(*ppTask)) {
|
||||
char* p = streamTaskGetStatus(*ppTask).name;
|
||||
int32_t ref = atomic_sub_fetch_32(&(*ppTask)->status.timerActive, 1);
|
||||
stDebug("s-task:%s status:%s should stop, quit launch fill-history task timer, retry:%d, ref:%d",
|
||||
(*ppTask)->id.idStr, p, (*ppTask)->hTaskInfo.retryTimes, ref);
|
||||
if (streamTaskShouldStop(pTask)) {
|
||||
char* p = streamTaskGetStatus(pTask).name;
|
||||
stDebug("s-task:%s status:%s should stop, quit launch fill-history task timer, retry:%d", pTask->id.idStr, p,
|
||||
pTask->hTaskInfo.retryTimes);
|
||||
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
|
@ -369,77 +384,54 @@ void tryLaunchHistoryTask(void* param, void* tmrId) {
|
|||
stError("s-task:0x%" PRId64 " failed to record the start task status, code:%s", pInfo->hTaskId.taskId,
|
||||
tstrerror(code));
|
||||
}
|
||||
taosMemoryFree(pInfo);
|
||||
|
||||
doCleanup(pTask, metaRid, pInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = NULL;
|
||||
code = streamMetaAcquireTaskNoLock(pMeta, pInfo->id.streamId, pInfo->id.taskId, &pTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
// todo
|
||||
}
|
||||
streamMetaWUnLock(pMeta);
|
||||
|
||||
if (pTask != NULL) {
|
||||
SHistoryTaskInfo* pHTaskInfo = &pTask->hTaskInfo;
|
||||
|
||||
pHTaskInfo->tickCount -= 1;
|
||||
if (pHTaskInfo->tickCount > 0) {
|
||||
streamTmrStart(tryLaunchHistoryTask, LAUNCH_HTASK_INTERVAL, pInfo, streamTimer, &pHTaskInfo->pTimer,
|
||||
pTask->pMeta->vgId, " start-history-task-tmr");
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pHTaskInfo->retryTimes > MAX_RETRY_LAUNCH_HISTORY_TASK) {
|
||||
notRetryLaunchFillHistoryTask(pTask, pInfo, now);
|
||||
} else { // not reach the limitation yet, let's continue retrying launch related fill-history task.
|
||||
streamTaskSetRetryInfoForLaunch(pHTaskInfo);
|
||||
if (pTask->status.timerActive < 1) {
|
||||
stError("s-task:%s invalid timerActive recorder:%d, abort timer", pTask->id.idStr, pTask->status.timerActive);
|
||||
return;
|
||||
}
|
||||
|
||||
// abort the timer if intend to stop task
|
||||
SStreamTask* pHTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, pHTaskInfo->id.streamId, pHTaskInfo->id.taskId, &pHTask);
|
||||
if (pHTask == NULL) {
|
||||
doRetryLaunchFillHistoryTask(pTask, pInfo, now);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
return;
|
||||
} else {
|
||||
if (pHTask->pBackend == NULL) {
|
||||
code = pMeta->expandTaskFn(pHTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
streamMetaAddFailedTaskSelf(pHTask, now);
|
||||
stError("failed to expand fill-history task:%s, code:%s", pHTask->id.idStr, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
checkFillhistoryTaskStatus(pTask, pHTask);
|
||||
// not in timer anymore
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:0x%x fill-history task launch completed, retry times:%d, ref:%d", (int32_t)pInfo->id.taskId,
|
||||
pHTaskInfo->retryTimes, ref);
|
||||
}
|
||||
streamMetaReleaseTask(pMeta, pHTask);
|
||||
}
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
} else {
|
||||
code = streamMetaAddTaskLaunchResult(pMeta, pInfo->hTaskId.streamId, pInfo->hTaskId.taskId, 0, now, false);
|
||||
if (code) {
|
||||
stError("s-task:%s failed to record the start task status, code:%s", pTask->id.idStr, tstrerror(code));
|
||||
}
|
||||
|
||||
int32_t ref = atomic_sub_fetch_32(&(*ppTask)->status.timerActive, 1);
|
||||
stError("s-task:0x%x rel fill-history task:0x%" PRIx64 " may have been destroyed, not launch, ref:%d",
|
||||
(int32_t)pInfo->id.taskId, pInfo->hTaskId.taskId, ref);
|
||||
SHistoryTaskInfo* pHTaskInfo = &pTask->hTaskInfo;
|
||||
pHTaskInfo->tickCount -= 1;
|
||||
if (pHTaskInfo->tickCount > 0) {
|
||||
streamTmrStart(tryLaunchHistoryTask, LAUNCH_HTASK_INTERVAL, pInfo, streamTimer, &pHTaskInfo->pTimer,
|
||||
pTask->pMeta->vgId, " start-history-task-tmr");
|
||||
doCleanup(pTask, metaRid, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFree(pInfo);
|
||||
if (pHTaskInfo->retryTimes > MAX_RETRY_LAUNCH_HISTORY_TASK) {
|
||||
notRetryLaunchFillHistoryTask(pTask, pInfo, now);
|
||||
} else { // not reach the limitation yet, let's continue retrying launch related fill-history task.
|
||||
streamTaskSetRetryInfoForLaunch(pHTaskInfo);
|
||||
|
||||
// abort the timer if intend to stop task
|
||||
SStreamTask* pHTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, pHTaskInfo->id.streamId, pHTaskInfo->id.taskId, &pHTask);
|
||||
if (pHTask == NULL) {
|
||||
doRetryLaunchFillHistoryTask(pTask, pInfo, now);
|
||||
doCleanup(pTask, metaRid, NULL);
|
||||
return;
|
||||
} else {
|
||||
if (pHTask->pBackend == NULL) {
|
||||
code = pMeta->expandTaskFn(pHTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
streamMetaAddFailedTaskSelf(pHTask, now);
|
||||
stError("failed to expand fill-history task:%s, code:%s", pHTask->id.idStr, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
checkFillhistoryTaskStatus(pTask, pHTask);
|
||||
// not in timer anymore
|
||||
stDebug("s-task:0x%x fill-history task launch completed, retry times:%d", (int32_t)pInfo->id.taskId,
|
||||
pHTaskInfo->retryTimes);
|
||||
}
|
||||
streamMetaReleaseTask(pMeta, pHTask);
|
||||
}
|
||||
}
|
||||
|
||||
doCleanup(pTask, metaRid, pInfo);
|
||||
}
|
||||
|
||||
int32_t createHTaskLaunchInfo(SStreamMeta* pMeta, STaskId* pTaskId, int64_t hStreamId, int32_t hTaskId,
|
||||
|
@ -455,7 +447,7 @@ int32_t createHTaskLaunchInfo(SStreamMeta* pMeta, STaskId* pTaskId, int64_t hStr
|
|||
(*pInfo)->hTaskId.streamId = hStreamId;
|
||||
(*pInfo)->hTaskId.taskId = hTaskId;
|
||||
|
||||
(*pInfo)->pMeta = pMeta;
|
||||
(*pInfo)->metaRid = pMeta->rid;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -485,12 +477,10 @@ int32_t launchNotBuiltFillHistoryTask(SStreamTask* pTask) {
|
|||
|
||||
// check for the timer
|
||||
if (pTask->hTaskInfo.pTimer == NULL) {
|
||||
int32_t ref = atomic_add_fetch_32(&pTask->status.timerActive, 1);
|
||||
pTask->hTaskInfo.pTimer = taosTmrStart(tryLaunchHistoryTask, WAIT_FOR_MINIMAL_INTERVAL, pInfo, streamTimer);
|
||||
|
||||
if (pTask->hTaskInfo.pTimer == NULL) {
|
||||
ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stError("s-task:%s failed to start timer, related fill-history task not launched, ref:%d", idStr, ref);
|
||||
stError("s-task:%s failed to start timer, related fill-history task not launched", idStr);
|
||||
|
||||
taosMemoryFree(pInfo);
|
||||
code = streamMetaAddTaskLaunchResult(pMeta, hStreamId, hTaskId, pExecInfo->checkTs, pExecInfo->readyTs, false);
|
||||
|
@ -500,18 +490,8 @@ int32_t launchNotBuiltFillHistoryTask(SStreamTask* pTask) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
if (ref < 1) {
|
||||
stError("s-task:%s invalid timerActive recorder:%d, abort timer", pTask->id.idStr, pTask->status.timerActive);
|
||||
return TSDB_CODE_STREAM_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
stDebug("s-task:%s set timer active flag, ref:%d", idStr, ref);
|
||||
stDebug("s-task:%s set timer active flag", idStr);
|
||||
} else { // timer exists
|
||||
if (pTask->status.timerActive < 1) {
|
||||
stError("s-task:%s invalid timerActive recorder:%d, abort timer", pTask->id.idStr, pTask->status.timerActive);
|
||||
return TSDB_CODE_STREAM_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
stDebug("s-task:%s set timer active flag, task timer not null", idStr);
|
||||
streamTmrStart(tryLaunchHistoryTask, WAIT_FOR_MINIMAL_INTERVAL, pInfo, streamTimer, &pTask->hTaskInfo.pTimer,
|
||||
pTask->pMeta->vgId, " start-history-task-tmr");
|
||||
|
@ -590,15 +570,22 @@ int32_t streamTaskSetRangeStreamCalc(SStreamTask* pTask) {
|
|||
}
|
||||
|
||||
void doExecScanhistoryInFuture(void* param, void* tmrId) {
|
||||
SStreamTask* pTask = param;
|
||||
int64_t taskRefId = *(int64_t*) param;
|
||||
|
||||
SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
|
||||
if (pTask == NULL) {
|
||||
stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
pTask->schedHistoryInfo.numOfTicks -= 1;
|
||||
|
||||
SStreamTaskState p = streamTaskGetStatus(pTask);
|
||||
if (p.state == TASK_STATUS__DROPPING || p.state == TASK_STATUS__STOP) {
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s status:%s not start scan-history again, ref:%d", pTask->id.idStr, p.name, ref);
|
||||
|
||||
stDebug("s-task:%s status:%s not start scan-history again", pTask->id.idStr, p.name);
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamTaskFreeRefId(param);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -608,16 +595,19 @@ void doExecScanhistoryInFuture(void* param, void* tmrId) {
|
|||
stError("s-task:%s async start history task failed", pTask->id.idStr);
|
||||
}
|
||||
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
stDebug("s-task:%s fill-history:%d start scan-history data, out of tmr, ref:%d", pTask->id.idStr,
|
||||
pTask->info.fillHistory, ref);
|
||||
|
||||
// release the task.
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
stDebug("s-task:%s fill-history:%d start scan-history data, out of tmr", pTask->id.idStr,
|
||||
pTask->info.fillHistory);
|
||||
} else {
|
||||
streamTmrStart(doExecScanhistoryInFuture, SCANHISTORY_IDLE_TIME_SLICE, pTask, streamTimer,
|
||||
&pTask->schedHistoryInfo.pTimer, pTask->pMeta->vgId, " start-history-task-tmr");
|
||||
int64_t* pTaskRefId = NULL;
|
||||
int32_t code = streamTaskAllocRefId(pTask, &pTaskRefId);
|
||||
if (code == 0) {
|
||||
streamTmrStart(doExecScanhistoryInFuture, SCANHISTORY_IDLE_TIME_SLICE, pTaskRefId, streamTimer,
|
||||
&pTask->schedHistoryInfo.pTimer, pTask->pMeta->vgId, " start-history-task-tmr");
|
||||
}
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pTask->pMeta, pTask);
|
||||
streamTaskFreeRefId(param);
|
||||
}
|
||||
|
||||
int32_t doStartScanHistoryTask(SStreamTask* pTask) {
|
||||
|
|
|
@ -196,19 +196,17 @@ int32_t streamMetaAddTaskLaunchResult(SStreamMeta* pMeta, int64_t streamId, int3
|
|||
STaskId id = {.streamId = streamId, .taskId = taskId};
|
||||
int32_t vgId = pMeta->vgId;
|
||||
bool allRsp = true;
|
||||
SStreamTask* p = NULL;
|
||||
|
||||
streamMetaWLock(pMeta);
|
||||
SStreamTask** p = taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
if (p == NULL) { // task does not exists in current vnode, not record the complete info
|
||||
int32_t code = streamMetaAcquireTaskUnsafe(pMeta, &id, &p);
|
||||
if (code != 0) { // task does not exist in current vnode, not record the complete info
|
||||
stError("vgId:%d s-task:0x%x not exists discard the check downstream info", vgId, taskId);
|
||||
streamMetaWUnLock(pMeta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// clear the send consensus-checkpointId flag
|
||||
// streamMutexLock(&(*p)->lock);
|
||||
// (*p)->status.sendConsensusChkptId = false;
|
||||
// streamMutexUnlock(&(*p)->lock);
|
||||
streamMetaReleaseTask(pMeta, p);
|
||||
|
||||
if (pStartInfo->startAllTasks != 1) {
|
||||
int64_t el = endTs - startTs;
|
||||
|
@ -222,7 +220,7 @@ int32_t streamMetaAddTaskLaunchResult(SStreamMeta* pMeta, int64_t streamId, int3
|
|||
|
||||
STaskInitTs initTs = {.start = startTs, .end = endTs, .success = ready};
|
||||
SHashObj* pDst = ready ? pStartInfo->pReadyTaskSet : pStartInfo->pFailedTaskSet;
|
||||
int32_t code = taosHashPut(pDst, &id, sizeof(id), &initTs, sizeof(STaskInitTs));
|
||||
code = taosHashPut(pDst, &id, sizeof(id), &initTs, sizeof(STaskInitTs));
|
||||
if (code) {
|
||||
if (code == TSDB_CODE_DUP_KEY) {
|
||||
stError("vgId:%d record start task result failed, s-task:0x%" PRIx64
|
||||
|
@ -296,13 +294,14 @@ void displayStatusInfo(SStreamMeta* pMeta, SHashObj* pTaskSet, bool succ) {
|
|||
while ((pIter = taosHashIterate(pTaskSet, pIter)) != NULL) {
|
||||
STaskInitTs* pInfo = pIter;
|
||||
void* key = taosHashGetKey(pIter, &keyLen);
|
||||
|
||||
SStreamTask** pTask1 = taosHashGet(pMeta->pTasksMap, key, sizeof(STaskId));
|
||||
if (pTask1 == NULL) {
|
||||
stInfo("s-task:0x%x is dropped already, %s", (int32_t)((STaskId*)key)->taskId, succ ? "success" : "failed");
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTaskUnsafe(pMeta, key, &pTask);
|
||||
if (code == 0) {
|
||||
stInfo("s-task:%s level:%d vgId:%d, init:%" PRId64 ", initEnd:%" PRId64 ", %s", pTask->id.idStr,
|
||||
pTask->info.taskLevel, vgId, pInfo->start, pInfo->end, pInfo->success ? "success" : "failed");
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
} else {
|
||||
stInfo("s-task:%s level:%d vgId:%d, init:%" PRId64 ", initEnd:%" PRId64 ", %s", (*pTask1)->id.idStr,
|
||||
(*pTask1)->info.taskLevel, vgId, pInfo->start, pInfo->end, pInfo->success ? "success" : "failed");
|
||||
stInfo("s-task:0x%x is dropped already, %s", (int32_t)((STaskId*)key)->taskId, succ ? "success" : "failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -356,7 +355,7 @@ int32_t streamMetaStartOneTask(SStreamMeta* pMeta, int64_t streamId, int32_t tas
|
|||
// fill-history task can only be launched by related stream tasks.
|
||||
STaskExecStatisInfo* pInfo = &pTask->execInfo;
|
||||
if (pTask->info.fillHistory == 1) {
|
||||
stError("s-task:0x%x vgId:%d fill-histroy task, not start here", taskId, vgId);
|
||||
stError("s-task:0x%x vgId:%d fill-history task, not start here", taskId, vgId);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -364,6 +363,7 @@ int32_t streamMetaStartOneTask(SStreamMeta* pMeta, int64_t streamId, int32_t tas
|
|||
// the start all tasks procedure may happen to start the newly deployed stream task, and results in the
|
||||
// concurrently start this task by two threads.
|
||||
streamMutexLock(&pTask->lock);
|
||||
|
||||
SStreamTaskState status = streamTaskGetStatus(pTask);
|
||||
if (status.state != TASK_STATUS__UNINIT) {
|
||||
stError("s-task:0x%x vgId:%d status:%s not uninit status, not start stream task", taskId, vgId, status.name);
|
||||
|
@ -380,6 +380,7 @@ int32_t streamMetaStartOneTask(SStreamMeta* pMeta, int64_t streamId, int32_t tas
|
|||
|
||||
if(pTask->status.downstreamReady != 0) {
|
||||
stFatal("s-task:0x%x downstream should be not ready, but it ready here, internal error happens", taskId);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
return TSDB_CODE_STREAM_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
@ -396,7 +397,7 @@ int32_t streamMetaStartOneTask(SStreamMeta* pMeta, int64_t streamId, int32_t tas
|
|||
streamMutexUnlock(&pTask->lock);
|
||||
}
|
||||
|
||||
// concurrently start task may cause the later started task be failed, and also failed to added into meta result.
|
||||
// concurrently start task may cause the latter started task be failed, and also failed to added into meta result.
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_INIT);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -417,8 +418,10 @@ int32_t streamMetaStartOneTask(SStreamMeta* pMeta, int64_t streamId, int32_t tas
|
|||
int32_t streamMetaStopAllTasks(SStreamMeta* pMeta) {
|
||||
streamMetaRLock(pMeta);
|
||||
|
||||
SArray* pTaskList = NULL;
|
||||
int32_t num = taosArrayGetSize(pMeta->pTaskList);
|
||||
stDebug("vgId:%d stop all %d stream task(s)", pMeta->vgId, num);
|
||||
|
||||
if (num == 0) {
|
||||
stDebug("vgId:%d stop all %d task(s) completed, elapsed time:0 Sec.", pMeta->vgId, num);
|
||||
streamMetaRUnLock(pMeta);
|
||||
|
@ -428,14 +431,12 @@ int32_t streamMetaStopAllTasks(SStreamMeta* pMeta) {
|
|||
int64_t st = taosGetTimestampMs();
|
||||
|
||||
// send hb msg to mnode before closing all tasks.
|
||||
SArray* pTaskList = NULL;
|
||||
int32_t code = streamMetaSendMsgBeforeCloseTasks(pMeta, &pTaskList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t numOfTasks = taosArrayGetSize(pTaskList);
|
||||
|
||||
for (int32_t i = 0; i < numOfTasks; ++i) {
|
||||
SStreamTaskId* pTaskId = taosArrayGet(pTaskList, i);
|
||||
SStreamTask* pTask = NULL;
|
||||
|
@ -445,10 +446,12 @@ int32_t streamMetaStopAllTasks(SStreamMeta* pMeta) {
|
|||
continue;
|
||||
}
|
||||
|
||||
int64_t refId = pTask->id.refId;
|
||||
int32_t ret = streamTaskStop(pTask);
|
||||
if (ret) {
|
||||
stError("s-task:0x%x failed to stop task, code:%s", pTaskId->taskId, tstrerror(ret));
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
}
|
||||
|
||||
|
@ -466,6 +469,7 @@ int32_t streamTaskCheckIfReqConsenChkptId(SStreamTask* pTask, int64_t ts) {
|
|||
|
||||
int32_t vgId = pTask->pMeta->vgId;
|
||||
if (pConChkptInfo->status == TASK_CONSEN_CHKPT_REQ) {
|
||||
// mark the sending of req consensus checkpoint request.
|
||||
pConChkptInfo->status = TASK_CONSEN_CHKPT_SEND;
|
||||
pConChkptInfo->statusTs = ts;
|
||||
stDebug("s-task:%s vgId:%d set requiring consensus-chkptId in hbMsg, ts:%" PRId64, pTask->id.idStr,
|
||||
|
@ -473,6 +477,8 @@ int32_t streamTaskCheckIfReqConsenChkptId(SStreamTask* pTask, int64_t ts) {
|
|||
return 1;
|
||||
} else {
|
||||
int32_t el = (ts - pConChkptInfo->statusTs) / 1000;
|
||||
|
||||
// not recv consensus-checkpoint rsp for 60sec, send it again in hb to mnode
|
||||
if ((pConChkptInfo->status == TASK_CONSEN_CHKPT_SEND) && el > 60) {
|
||||
pConChkptInfo->statusTs = ts;
|
||||
|
||||
|
@ -492,7 +498,7 @@ void streamTaskSetConsenChkptIdRecv(SStreamTask* pTask, int32_t transId, int64_t
|
|||
pInfo->status = TASK_CONSEN_CHKPT_RECV;
|
||||
pInfo->statusTs = ts;
|
||||
|
||||
stDebug("s-task:%s set recv consen-checkpointId, transId:%d", pTask->id.idStr, transId);
|
||||
stInfo("s-task:%s set recv consen-checkpointId, transId:%d", pTask->id.idStr, transId);
|
||||
}
|
||||
|
||||
void streamTaskSetReqConsenChkptId(SStreamTask* pTask, int64_t ts) {
|
||||
|
@ -507,23 +513,24 @@ void streamTaskSetReqConsenChkptId(SStreamTask* pTask, int64_t ts) {
|
|||
}
|
||||
|
||||
int32_t streamMetaAddFailedTask(SStreamMeta* pMeta, int64_t streamId, int32_t taskId) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
int64_t startTs = 0;
|
||||
bool hasFillhistoryTask = false;
|
||||
STaskId hId = {0};
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
int64_t startTs = 0;
|
||||
bool hasFillhistoryTask = false;
|
||||
STaskId hId = {0};
|
||||
STaskId id = {.streamId = streamId, .taskId = taskId};
|
||||
SStreamTask* pTask = NULL;
|
||||
|
||||
stDebug("vgId:%d add start failed task:0x%x", pMeta->vgId, taskId);
|
||||
|
||||
streamMetaRLock(pMeta);
|
||||
|
||||
STaskId id = {.streamId = streamId, .taskId = taskId};
|
||||
SStreamTask** ppTask = taosHashGet(pMeta->pTasksMap, &id, sizeof(id));
|
||||
|
||||
if (ppTask != NULL) {
|
||||
startTs = (*ppTask)->taskCheckInfo.startTs;
|
||||
hasFillhistoryTask = HAS_RELATED_FILLHISTORY_TASK(*ppTask);
|
||||
hId = (*ppTask)->hTaskInfo.id;
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &id, &pTask);
|
||||
if (code == 0) {
|
||||
startTs = pTask->taskCheckInfo.startTs;
|
||||
hasFillhistoryTask = HAS_RELATED_FILLHISTORY_TASK(pTask);
|
||||
hId = pTask->hTaskInfo.id;
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
|
||||
streamMetaRUnLock(pMeta);
|
||||
|
||||
|
|
|
@ -211,22 +211,23 @@ int32_t tDecodeStreamTaskId(SDecoder* pDecoder, STaskId* pTaskId) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tFreeStreamTask(SStreamTask* pTask) {
|
||||
char* p = NULL;
|
||||
int32_t taskId = pTask->id.taskId;
|
||||
void tFreeStreamTask(void* pParam) {
|
||||
char* p = NULL;
|
||||
SStreamTask* pTask = pParam;
|
||||
int32_t taskId = pTask->id.taskId;
|
||||
|
||||
STaskExecStatisInfo* pStatis = &pTask->execInfo;
|
||||
|
||||
ETaskStatus status1 = TASK_STATUS__UNINIT;
|
||||
streamMutexLock(&pTask->lock);
|
||||
if (pTask->status.pSM != NULL) {
|
||||
SStreamTaskState pStatus = streamTaskGetStatus(pTask);
|
||||
p = pStatus.name;
|
||||
status1 = pStatus.state;
|
||||
SStreamTaskState status = streamTaskGetStatus(pTask);
|
||||
p = status.name;
|
||||
status1 = status.state;
|
||||
}
|
||||
streamMutexUnlock(&pTask->lock);
|
||||
|
||||
stDebug("start to free s-task:0x%x %p, state:%s", taskId, pTask, p);
|
||||
stDebug("start to free s-task:0x%x %p, state:%s, refId:%" PRId64, taskId, pTask, p, pTask->id.refId);
|
||||
|
||||
SCheckpointInfo* pCkInfo = &pTask->chkInfo;
|
||||
stDebug("s-task:0x%x task exec summary: create:%" PRId64 ", init:%" PRId64 ", start:%" PRId64
|
||||
|
@ -235,12 +236,6 @@ void tFreeStreamTask(SStreamTask* pTask) {
|
|||
taskId, pStatis->created, pStatis->checkTs, pStatis->readyTs, pStatis->updateCount, pStatis->latestUpdateTs,
|
||||
pCkInfo->checkpointId, pCkInfo->checkpointVer, pCkInfo->nextProcessVer, pStatis->checkpoint);
|
||||
|
||||
// remove the ref by timer
|
||||
while (pTask->status.timerActive > 0) {
|
||||
stDebug("s-task:%s wait for task stop timer activities, ref:%d", pTask->id.idStr, pTask->status.timerActive);
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
if (pTask->schedInfo.pDelayTimer != NULL) {
|
||||
streamTmrStop(pTask->schedInfo.pDelayTimer);
|
||||
pTask->schedInfo.pDelayTimer = NULL;
|
||||
|
@ -428,8 +423,7 @@ int32_t streamTaskInit(SStreamTask* pTask, SStreamMeta* pMeta, SMsgCb* pMsgCb, i
|
|||
return code;
|
||||
}
|
||||
|
||||
pTask->refCnt = 1;
|
||||
|
||||
pTask->id.refId = 0;
|
||||
pTask->inputq.status = TASK_INPUT_STATUS__NORMAL;
|
||||
pTask->outputq.status = TASK_OUTPUT_STATUS__NORMAL;
|
||||
|
||||
|
@ -441,7 +435,6 @@ int32_t streamTaskInit(SStreamTask* pTask, SStreamMeta* pMeta, SMsgCb* pMsgCb, i
|
|||
}
|
||||
|
||||
pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
|
||||
pTask->status.timerActive = 0;
|
||||
|
||||
code = streamCreateStateMachine(pTask);
|
||||
if (pTask->status.pSM == NULL || code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -837,28 +830,31 @@ int8_t streamTaskSetSchedStatusInactive(SStreamTask* pTask) {
|
|||
int32_t streamTaskClearHTaskAttr(SStreamTask* pTask, int32_t resetRelHalt) {
|
||||
int32_t code = 0;
|
||||
SStreamMeta* pMeta = pTask->pMeta;
|
||||
STaskId sTaskId = {.streamId = pTask->streamTaskId.streamId, .taskId = pTask->streamTaskId.taskId};
|
||||
SStreamTask* pStreamTask = NULL;
|
||||
|
||||
if (pTask->info.fillHistory == 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SStreamTask** ppStreamTask = (SStreamTask**)taosHashGet(pMeta->pTasksMap, &sTaskId, sizeof(sTaskId));
|
||||
if (ppStreamTask != NULL) {
|
||||
code = streamMetaAcquireTaskUnsafe(pMeta, &pTask->streamTaskId, &pStreamTask);
|
||||
if (code == 0) {
|
||||
stDebug("s-task:%s clear the related stream task:0x%x attr to fill-history task", pTask->id.idStr,
|
||||
(int32_t)sTaskId.taskId);
|
||||
(int32_t)pTask->streamTaskId.taskId);
|
||||
|
||||
streamMutexLock(&(*ppStreamTask)->lock);
|
||||
CLEAR_RELATED_FILLHISTORY_TASK((*ppStreamTask));
|
||||
streamMutexLock(&(pStreamTask->lock));
|
||||
CLEAR_RELATED_FILLHISTORY_TASK(pStreamTask);
|
||||
|
||||
if (resetRelHalt) {
|
||||
stDebug("s-task:0x%" PRIx64 " set the persistent status attr to be ready, prev:%s, status in sm:%s",
|
||||
sTaskId.taskId, streamTaskGetStatusStr((*ppStreamTask)->status.taskStatus),
|
||||
streamTaskGetStatus(*ppStreamTask).name);
|
||||
(*ppStreamTask)->status.taskStatus = TASK_STATUS__READY;
|
||||
pTask->streamTaskId.taskId, streamTaskGetStatusStr(pStreamTask->status.taskStatus),
|
||||
streamTaskGetStatus(pStreamTask).name);
|
||||
pStreamTask->status.taskStatus = TASK_STATUS__READY;
|
||||
}
|
||||
|
||||
code = streamMetaSaveTask(pMeta, *ppStreamTask);
|
||||
streamMutexUnlock(&(*ppStreamTask)->lock);
|
||||
code = streamMetaSaveTask(pMeta, pStreamTask);
|
||||
streamMutexUnlock(&(pStreamTask->lock));
|
||||
|
||||
streamMetaReleaseTask(pMeta, pStreamTask);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -1282,3 +1278,27 @@ const char* streamTaskGetExecType(int32_t type) {
|
|||
return "invalid-exec-type";
|
||||
}
|
||||
}
|
||||
|
||||
int32_t streamTaskAllocRefId(SStreamTask* pTask, int64_t** pRefId) {
|
||||
*pRefId = taosMemoryMalloc(sizeof(int64_t));
|
||||
if (*pRefId != NULL) {
|
||||
**pRefId = pTask->id.refId;
|
||||
int32_t code = metaRefMgtAdd(pTask->pMeta->vgId, *pRefId);
|
||||
if (code != 0) {
|
||||
stError("s-task:%s failed to add refId:%" PRId64 " into refId-mgmt, code:%s", pTask->id.idStr, pTask->id.refId,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
} else {
|
||||
stError("s-task:%s failed to alloc new ref id, code:%s", pTask->id.idStr, tstrerror(terrno));
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
void streamTaskFreeRefId(int64_t* pRefId) {
|
||||
if (pRefId == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
metaRefMgtRemove(pRefId);
|
||||
}
|
|
@ -66,15 +66,9 @@ void streamTmrStop(tmr_h tmrId) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t streamCleanBeforeQuitTmr(SStreamTmrInfo* pInfo, SStreamTask* pTask) {
|
||||
void streamCleanBeforeQuitTmr(SStreamTmrInfo* pInfo, void* param) {
|
||||
pInfo->activeCounter = 0;
|
||||
pInfo->launchChkptId = 0;
|
||||
atomic_store_8(&pInfo->isActive, 0);
|
||||
|
||||
int32_t ref = atomic_sub_fetch_32(&pTask->status.timerActive, 1);
|
||||
if (ref < 0) {
|
||||
stFatal("invalid task timer ref value:%d, %s", ref, pTask->id.idStr);
|
||||
}
|
||||
|
||||
return ref;
|
||||
streamTaskFreeRefId(param);
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
aux_source_directory(src SYNC_SRC)
|
||||
add_library(sync STATIC ${SYNC_SRC})
|
||||
|
||||
if(${TD_DARWIN})
|
||||
target_compile_options(sync PRIVATE -Wno-error=deprecated-non-prototype)
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
sync
|
||||
PUBLIC common
|
||||
|
|
|
@ -158,7 +158,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
initLogEnv();
|
||||
taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit.compatibilityVer));
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
tError("failed to initialize RPC");
|
||||
|
|
|
@ -127,7 +127,7 @@ int main(int argc, char *argv[]) {
|
|||
rpcInit.cfp = processRequestMsg;
|
||||
rpcInit.idleTime = 2 * 1500;
|
||||
|
||||
taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit.compatibilityVer));
|
||||
rpcDebugFlag = 131;
|
||||
rpcInit.compressSize = -1;
|
||||
|
||||
|
@ -165,7 +165,7 @@ int main(int argc, char *argv[]) {
|
|||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
|
||||
initLogEnv();
|
||||
taosVersionStrToInt(version, &(rpcInit.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit.compatibilityVer));
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
tError("failed to start RPC server");
|
||||
|
|
|
@ -56,7 +56,7 @@ class Client {
|
|||
rpcInit_.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit_.shareConnLimit = 200;
|
||||
|
||||
taosVersionStrToInt(version, &(rpcInit_.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit_.compatibilityVer));
|
||||
this->transCli = rpcOpen(&rpcInit_);
|
||||
tsem_init(&this->sem, 0, 0);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class Client {
|
|||
void Restart(CB cb) {
|
||||
rpcClose(this->transCli);
|
||||
rpcInit_.cfp = cb;
|
||||
taosVersionStrToInt(version, &(rpcInit_.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit_.compatibilityVer));
|
||||
this->transCli = rpcOpen(&rpcInit_);
|
||||
}
|
||||
void Stop() {
|
||||
|
@ -129,7 +129,7 @@ class Server {
|
|||
rpcInit_.cfp = processReq;
|
||||
rpcInit_.user = (char *)user;
|
||||
rpcInit_.connType = TAOS_CONN_SERVER;
|
||||
taosVersionStrToInt(version, &(rpcInit_.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit_.compatibilityVer));
|
||||
}
|
||||
void Start() {
|
||||
this->transSrv = rpcOpen(&this->rpcInit_);
|
||||
|
|
|
@ -56,7 +56,7 @@ class Client {
|
|||
rpcInit_.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit_.shareConnLimit = 200;
|
||||
|
||||
taosVersionStrToInt(version, &(rpcInit_.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit_.compatibilityVer));
|
||||
this->transCli = rpcOpen(&rpcInit_);
|
||||
//tsem_init(&this->sem, 0, 0);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class Client {
|
|||
void Restart(CB cb) {
|
||||
rpcClose(this->transCli);
|
||||
rpcInit_.cfp = cb;
|
||||
taosVersionStrToInt(version, &(rpcInit_.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit_.compatibilityVer));
|
||||
this->transCli = rpcOpen(&rpcInit_);
|
||||
}
|
||||
void Stop() {
|
||||
|
@ -139,7 +139,7 @@ class Server {
|
|||
rpcInit_.cfp = processReq;
|
||||
rpcInit_.user = (char *)user;
|
||||
rpcInit_.connType = TAOS_CONN_SERVER;
|
||||
taosVersionStrToInt(version, &(rpcInit_.compatibilityVer));
|
||||
taosVersionStrToInt(td_version, &(rpcInit_.compatibilityVer));
|
||||
}
|
||||
void Start() {
|
||||
this->transSrv = rpcOpen(&this->rpcInit_);
|
||||
|
|
|
@ -411,14 +411,14 @@ static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) {
|
|||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void printFileSet(SArray* fileSet) {
|
||||
static void printFileSet(int32_t vgId, SArray* fileSet, const char* str) {
|
||||
int32_t sz = taosArrayGetSize(fileSet);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SWalFileInfo* pFileInfo = taosArrayGet(fileSet, i);
|
||||
wInfo("firstVer:%" PRId64 ", lastVer:%" PRId64 ", fileSize:%" PRId64 ", syncedOffset:%" PRId64 ", createTs:%" PRId64
|
||||
", closeTs:%" PRId64,
|
||||
pFileInfo->firstVer, pFileInfo->lastVer, pFileInfo->fileSize, pFileInfo->syncedOffset, pFileInfo->createTs,
|
||||
pFileInfo->closeTs);
|
||||
wInfo("vgId:%d, %s-%d, firstVer:%" PRId64 ", lastVer:%" PRId64 ", fileSize:%" PRId64 ", syncedOffset:%" PRId64
|
||||
", createTs:%" PRId64 ", closeTs:%" PRId64,
|
||||
vgId, str, i, pFileInfo->firstVer, pFileInfo->lastVer, pFileInfo->fileSize, pFileInfo->syncedOffset,
|
||||
pFileInfo->createTs, pFileInfo->closeTs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,6 +430,9 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
|||
regex_t logRegPattern;
|
||||
regex_t idxRegPattern;
|
||||
|
||||
wInfo("vgId:%d, begin to repair meta, wal path:%s, firstVer:%" PRId64 ", lastVer:%" PRId64 ", snapshotVer:%" PRId64,
|
||||
pWal->cfg.vgId, pWal->path, pWal->vers.firstVer, pWal->vers.lastVer, pWal->vers.snapshotVer);
|
||||
|
||||
if (regcomp(&logRegPattern, logPattern, REG_EXTENDED) != 0) {
|
||||
wError("failed to compile log pattern, error:%s", tstrerror(terrno));
|
||||
return terrno;
|
||||
|
@ -482,9 +485,9 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
|||
|
||||
taosArraySort(actualLog, compareWalFileInfo);
|
||||
|
||||
wInfo("vgId:%d, wal path:%s, actual log file num:%d", pWal->cfg.vgId, pWal->path,
|
||||
wInfo("vgId:%d, actual log file, wal path:%s, num:%d", pWal->cfg.vgId, pWal->path,
|
||||
(int32_t)taosArrayGetSize(actualLog));
|
||||
printFileSet(actualLog);
|
||||
printFileSet(pWal->cfg.vgId, actualLog, "actual log file");
|
||||
|
||||
int metaFileNum = taosArrayGetSize(pWal->fileInfoSet);
|
||||
int actualFileNum = taosArrayGetSize(actualLog);
|
||||
|
@ -500,9 +503,9 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
|||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
wInfo("vgId:%d, wal path:%s, meta log file num:%d", pWal->cfg.vgId, pWal->path,
|
||||
wInfo("vgId:%d, log file in meta, wal path:%s, num:%d", pWal->cfg.vgId, pWal->path,
|
||||
(int32_t)taosArrayGetSize(pWal->fileInfoSet));
|
||||
printFileSet(pWal->fileInfoSet);
|
||||
printFileSet(pWal->cfg.vgId, pWal->fileInfoSet, "log file in meta");
|
||||
|
||||
int32_t sz = taosArrayGetSize(pWal->fileInfoSet);
|
||||
|
||||
|
@ -563,7 +566,9 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
|||
// repair ts of files
|
||||
TAOS_CHECK_RETURN(walRepairLogFileTs(pWal, &updateMeta));
|
||||
|
||||
printFileSet(pWal->fileInfoSet);
|
||||
wInfo("vgId:%d, log file after repair, wal path:%s, num:%d", pWal->cfg.vgId, pWal->path,
|
||||
(int32_t)taosArrayGetSize(pWal->fileInfoSet));
|
||||
printFileSet(pWal->cfg.vgId, pWal->fileInfoSet, "file after repair");
|
||||
// update meta file
|
||||
if (updateMeta) {
|
||||
TAOS_CHECK_RETURN(walSaveMeta(pWal));
|
||||
|
@ -571,6 +576,9 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
|||
|
||||
TAOS_CHECK_RETURN(walLogEntriesComplete(pWal));
|
||||
|
||||
wInfo("vgId:%d, success to repair meta, wal path:%s, firstVer:%" PRId64 ", lastVer:%" PRId64 ", snapshotVer:%" PRId64,
|
||||
pWal->cfg.vgId, pWal->path, pWal->vers.firstVer, pWal->vers.lastVer, pWal->vers.snapshotVer);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1157,9 +1165,9 @@ int32_t walLoadMeta(SWal* pWal) {
|
|||
(void)taosCloseFile(&pFile);
|
||||
taosMemoryFree(buf);
|
||||
|
||||
wInfo("vgId:%d, load meta file: %s, firstVer:%" PRId64 ", lastVer:%" PRId64 ", fileInfoSet size:%d", pWal->cfg.vgId,
|
||||
wInfo("vgId:%d, meta file loaded: %s, firstVer:%" PRId64 ", lastVer:%" PRId64 ", fileInfoSet size:%d", pWal->cfg.vgId,
|
||||
fnameStr, pWal->vers.firstVer, pWal->vers.lastVer, (int32_t)taosArrayGetSize(pWal->fileInfoSet));
|
||||
printFileSet(pWal->fileInfoSet);
|
||||
printFileSet(pWal->cfg.vgId, pWal->fileInfoSet, "file in meta");
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
|
|
@ -268,6 +268,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_IN_CREATING, "Database in creating
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SYS_TABLENAME, "Invalid system table name")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ENCRYPT_NOT_ALLOW_CHANGE, "Encryption is not allowed to be changed after database is created")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_WAL_LEVEL, "Invalid option, wal_level 0 should be used with replica 1")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_LIST_FMT, "Invalid dnode list format")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_LIST_REPEAT, "Duplicate items in the dnode list")
|
||||
|
||||
// mnode-node
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_MNODE_ALREADY_EXIST, "Mnode already exists")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
char version[64] = "${TD_VER_NUMBER}";
|
||||
char compatible_version[12] = "${TD_VER_COMPATIBLE}";
|
||||
char gitinfo[48] = "${TD_VER_GIT}";
|
||||
char gitinfoOfInternal[48] = "${TD_VER_GIT_INTERNAL}";
|
||||
char buildinfo[64] = "${TD_VER_OSTYPE}-${TD_VER_CPUTYPE} ${TD_VER_DATE}";
|
||||
char td_version[64] = "${TD_VER_NUMBER}";
|
||||
char td_compatible_version[12] = "${TD_VER_COMPATIBLE}";
|
||||
char td_gitinfo[48] = "${TD_VER_GIT}";
|
||||
char td_gitinfoOfInternal[48] = "${TD_VER_GIT_INTERNAL}";
|
||||
char td_buildinfo[64] = "${TD_VER_OSTYPE}-${TD_VER_CPUTYPE} ${TD_VER_DATE}";
|
||||
|
||||
void libtaos_${TD_LIB_VER_NUMBER}_${TD_VER_OSTYPE}_${TD_VER_CPUTYPE}_${TD_VER_VERTYPE}() {};
|
|
@ -0,0 +1,375 @@
|
|||
from frame.log import *
|
||||
from frame.cases import *
|
||||
from frame.sql import *
|
||||
from frame.caseBase import *
|
||||
from frame import *
|
||||
from frame.eos import *
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
class TDTestCase(TBase):
|
||||
"""Verify the case...when... expression in the query statement
|
||||
"""
|
||||
def init(self, conn, logSql, replicaVar=1):
|
||||
self.replicaVar = int(replicaVar)
|
||||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor())
|
||||
self.stable_schema = {
|
||||
"columns": {
|
||||
"ts": "timestamp",
|
||||
"c_null": "int",
|
||||
"c_bool": "bool",
|
||||
"c_tinyint": "tinyint",
|
||||
"c_smallint": "smallint",
|
||||
"c_int": "int",
|
||||
"c_bigint": "bigint",
|
||||
"c_float": "float",
|
||||
"c_double": "double",
|
||||
"c_varchar": "varchar(16)",
|
||||
"c_timestamp": "timestamp",
|
||||
"c_nchar": "nchar(16)",
|
||||
"c_utinyint": "tinyint unsigned",
|
||||
"c_usmallint": "smallint unsigned",
|
||||
"c_uint": "int unsigned",
|
||||
"c_ubigint": "bigint unsigned",
|
||||
"c_varbinary": "varbinary(16)",
|
||||
"c_geometry": "geometry(32)"
|
||||
},
|
||||
"tags": {
|
||||
"t_null": "int",
|
||||
"t_bool": "bool",
|
||||
"t_tinyint": "tinyint",
|
||||
"t_smallint": "smallint",
|
||||
"t_int": "int",
|
||||
"t_bigint": "bigint",
|
||||
"t_float": "float",
|
||||
"t_double": "double",
|
||||
"t_varchar": "varchar(16)",
|
||||
"t_timestamp": "timestamp",
|
||||
"t_nchar": "nchar(16)",
|
||||
"t_utinyint": "tinyint unsigned",
|
||||
"t_usmallint": "smallint unsigned",
|
||||
"t_uint": "int unsigned",
|
||||
"t_ubigint": "bigint unsigned",
|
||||
"t_varbinary": "varbinary(16)",
|
||||
"t_geometry": "geometry(32)"
|
||||
}
|
||||
}
|
||||
|
||||
def prepare_data(self):
|
||||
# create database
|
||||
tdSql.execute("create database test_case_when;")
|
||||
tdSql.execute("use test_case_when;")
|
||||
# create stable
|
||||
columns = ",".join([f"{k} {v}" for k, v in self.stable_schema["columns"].items()])
|
||||
tags = ",".join([f"{k} {v}" for k, v in self.stable_schema["tags"].items()])
|
||||
st_sql = f"create stable st1 ({columns}) tags ({tags});"
|
||||
tdSql.execute(st_sql)
|
||||
st_sql_json_tag = f"create stable st2 ({columns}) tags (t json);"
|
||||
tdSql.execute(st_sql_json_tag)
|
||||
# create child table
|
||||
tdSql.execute("create table ct1 using st1 tags(NULL, True, 1, 1, 1, 1, 1.1, 1.11, 'aaaaaaaa', '2021-09-01 00:00:00.000', 'aaaaaaaa', 1, 1, 1, 1, \"0x06\",'POINT(1 1)');")
|
||||
tdSql.execute("""create table ct2 using st2 tags('{"name": "test", "location": "beijing"}');""")
|
||||
# insert data
|
||||
ct1_data = [
|
||||
"""'2024-10-01 00:00:00.000', NULL, True, 2, 2, 2, 2, 2.2, 2.22, 'bbbbbbbb', '2021-09-01 00:00:00.000', 'bbbbbbbb', 2, 2, 2, 2, "0x07",'POINT(2 2)'""",
|
||||
"""'2024-10-01 00:00:01.000', NULL, False, 3, 3, 3, 3, 3.3, 3.33, 'cccccccc', '2021-09-01 00:00:00.000', 'cccccccc', 3, 3, 3, 3, "0x08",'POINT(3 3)'""",
|
||||
"""'2024-10-01 00:00:02.000', NULL, True, 4, 4, 4, 4, 4.4, 4.44, 'dddddddd', '2021-09-01 00:00:00.000', 'dddddddd', 4, 4, 4, 4, "0x09",'POINT(4 4)'""",
|
||||
"""'2024-10-01 00:00:03.000', NULL, False, 5, 5, 5, 5, 5.5, 5.55, 'eeeeeeee', '2021-09-01 00:00:00.000', 'eeeeeeee', 5, 5, 5, 5, "0x0A",'POINT(5 5)'""",
|
||||
"""'2024-10-01 00:00:04.000', NULL, True, 6, 6, 6, 6, 6.6, 6.66, 'ffffffff', '2021-09-01 00:00:00.000', 'ffffffff', 6, 6, 6, 6, "0x0B",'POINT(6 6)'""",
|
||||
"""'2024-10-01 00:00:05.000', NULL, False, 7, 7, 7, 7, 7.7, 7.77, 'gggggggg', '2021-09-01 00:00:00.000', 'gggggggg', 7, 7, 7, 7, "0x0C",'POINT(7 7)'""",
|
||||
"""'2024-10-01 00:00:06.000', NULL, True, 8, 8, 8, 8, 8.8, 8.88, 'hhhhhhhh', '2021-09-01 00:00:00.000', 'hhhhhhhh', 8, 8, 8, 8, "0x0D",'POINT(8 8)'""",
|
||||
"""'2024-10-01 00:00:07.000', NULL, False, 9, 9, 9, 9, 9.9, 9.99, 'iiiiiiii', '2021-09-01 00:00:00.000', 'iiiiiiii', 9, 9, 9, 9, "0x0E",'POINT(9 9)'""",
|
||||
"""'2024-10-01 00:00:08.000', NULL, True, 10, 10, 10, 10, 10.10, 10.1010, 'jjjjjjjj', '2021-09-01 00:00:00.000', 'jjjjjjjj', 10, 10, 10, 10, "0x0F",'POINT(10 10)'""",
|
||||
"""'2024-10-01 00:00:09.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"""
|
||||
]
|
||||
ct1_insert_sql = "insert into ct1 values(%s);" % "),(".join(ct1_data)
|
||||
tdSql.execute(ct1_insert_sql)
|
||||
ct2_data = [
|
||||
"""'2024-10-01 00:00:00.000', NULL, True, 2, 2, 2, 2, 2.2, 2.22, 'bbbbbbbb', '2021-09-01 00:00:00.000', 'bbbbbbbb', 2, 2, 2, 2, "0x07",'POINT(2 2)'""",
|
||||
"""'2024-10-01 00:00:01.000', NULL, False, 3, 3, 3, 3, 3.3, 3.33, 'cccccccc', '2021-09-01 00:00:00.000', 'cccccccc', 3, 3, 3, 3, "0x08",'POINT(3 3)'""",
|
||||
"""'2024-10-01 00:00:02.000', NULL, True, 4, 4, 4, 4, 4.4, 4.44, 'dddddddd', '2021-09-01 00:00:00.000', 'dddddddd', 4, 4, 4, 4, "0x09",'POINT(4 4)'""",
|
||||
"""'2024-10-01 00:00:03.000', NULL, False, 5, 5, 5, 5, 5.5, 5.55, 'eeeeeeee', '2021-09-01 00:00:00.000', 'eeeeeeee', 5, 5, 5, 5, "0x0A",'POINT(5 5)'""",
|
||||
"""'2024-10-01 00:00:04.000', NULL, True, 6, 6, 6, 6, 6.6, 6.66, 'ffffffff', '2021-09-01 00:00:00.000', 'ffffffff', 6, 6, 6, 6, "0x0B",'POINT(6 6)'""",
|
||||
"""'2024-10-01 00:00:05.000', NULL, False, 7, 7, 7, 7, 7.7, 7.77, 'gggggggg', '2021-09-01 00:00:00.000', 'gggggggg', 7, 7, 7, 7, "0x0C",'POINT(7 7)'""",
|
||||
"""'2024-10-01 00:00:06.000', NULL, True, 8, 8, 8, 8, 8.8, 8.88, 'hhhhhhhh', '2021-09-01 00:00:00.000', 'hhhhhhhh', 8, 8, 8, 8, "0x0D",'POINT(8 8)'""",
|
||||
"""'2024-10-01 00:00:07.000', NULL, False, 9, 9, 9, 9, 9.9, 9.99, 'iiiiiiii', '2021-09-01 00:00:00.000', 'iiiiiiii', 9, 9, 9, 9, "0x0E",'POINT(9 9)'""",
|
||||
"""'2024-10-01 00:00:08.000', NULL, True, 10, 10, 10, 10, 10.10, 10.1010, 'jjjjjjjj', '2021-09-01 00:00:00.000', 'jjjjjjjj', 10, 10, 10, 10, "0x0F",'POINT(10 10)'""",
|
||||
"""'2024-10-01 00:00:09.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"""
|
||||
]
|
||||
ct2_insert_sql = "insert into ct2 values(%s);" % "),(".join(ct2_data)
|
||||
tdSql.execute(ct2_insert_sql)
|
||||
|
||||
def test_case_when_statements(self):
|
||||
tdSql.execute("use test_case_when;")
|
||||
tdSql.query("select case when c_null is null then c_null else t_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_null is not null then c_null else t_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_bool is null then c_bool else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_bool is not null then c_bool else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_tinyint is null then c_tinyint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_tinyint is not null then c_tinyint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_smallint is null then c_smallint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_smallint is not null then c_smallint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_int is null then c_int else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_int is not null then c_int else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_bigint is null then c_bigint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_bigint is not null then c_bigint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_float is null then c_float else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_float is not null then c_float else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('2.200000',), ('3.300000',), ('4.400000',), ('5.500000',), ('6.600000',), ('7.700000',), ('8.800000',), ('9.900000',), ('10.100000',), (None,)])
|
||||
|
||||
tdSql.query("select case when c_double is null then c_double else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_double is not null then c_double else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('2.220000',), ('3.330000',), ('4.440000',), ('5.550000',), ('6.660000',), ('7.770000',), ('8.880000',), ('9.990000',), ('10.101000',), (None,)])
|
||||
|
||||
tdSql.query("select case when c_varchar is null then c_varchar else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_varchar is not null then c_varchar else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('bbbbbbbb',), ('cccccccc',), ('dddddddd',), ('eeeeeeee',), ('ffffffff',), ('gggggggg',), ('hhhhhhhh',), ('iiiiiiii',), ('jjjjjjjj',), (None,)])
|
||||
|
||||
tdSql.query("select case when c_nchar is null then c_nchar else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_nchar is not null then c_nchar else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('bbbbbbbb',), ('cccccccc',), ('dddddddd',), ('eeeeeeee',), ('ffffffff',), ('gggggggg',), ('hhhhhhhh',), ('iiiiiiii',), ('jjjjjjjj',), (None,)])
|
||||
|
||||
tdSql.query("select case when c_utinyint is null then c_utinyint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_utinyint is not null then c_utinyint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_usmallint is null then c_usmallint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_usmallint is not null then c_usmallint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_uint is null then c_uint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_uint is not null then c_uint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_ubigint is null then c_ubigint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_ubigint is not null then c_ubigint else c_null end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('2',), ('3',), ('4',), ('5',), ('6',), ('7',), ('8',), ('9',), ('10',), (None,)])
|
||||
|
||||
tdSql.error("select case when c_varbinary is null then c_varbinary else c_null end from st1;")
|
||||
tdSql.error("select case when c_varbinary is not null then c_varbinary else c_null end from st1;")
|
||||
|
||||
tdSql.query("select case when c_null is null then NULL else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_null is not null then NULL else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(True,), (False,), (True,), (False,), (True,), (False,), (True,), (False,), (True,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_bool=true then NULL else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(None,), (False,), (None,), (False,), (None,), (False,), (None,), (False,), (None,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_bool!=true then NULL else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(True,), (None,), (True,), (None,), (True,), (None,), (True,), (None,), (True,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_tinyint=2 then c_tinyint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_tinyint!=2 then c_tinyint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_smallint=2 then c_smallint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_smallint!=2 then c_smallint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_int=2 then c_int else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_int!=2 then c_int else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_bigint=2 then c_bigint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_bigint!=2 then c_bigint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_float=2.2 then c_float else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res[1:] == [(0.0,), (1.0,), (0.0,), (1.0,), (0.0,), (1.0,), (0.0,), (1.0,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_float!=2.2 then c_float else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res[0] == (1.0,))
|
||||
|
||||
tdSql.query("select case when c_double=2.22 then c_double else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2.22,), (0.0,), (1.0,), (0.0,), (1.0,), (0.0,), (1.0,), (0.0,), (1.0,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_double!=2.2 then c_double else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2.22,), (3.33,), (4.44,), (5.55,), (6.66,), (7.77,), (8.88,), (9.99,), (10.101,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_varchar='bbbbbbbb' then c_varchar else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('bbbbbbbb',), ('false',), ('true',), ('false',), ('true',), ('false',), ('true',), ('false',), ('true',), (None,)])
|
||||
|
||||
tdSql.query("select case when c_varchar!='bbbbbbbb' then c_varchar else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('true',), ('cccccccc',), ('dddddddd',), ('eeeeeeee',), ('ffffffff',), ('gggggggg',), ('hhhhhhhh',), ('iiiiiiii',), ('jjjjjjjj',), (None,)])
|
||||
|
||||
tdSql.query("select case when c_timestamp='2021-09-01 00:00:00.000' then c_timestamp else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1630425600000,), (1630425600000,), (1630425600000,), (1630425600000,), (1630425600000,), (1630425600000,), (1630425600000,), (1630425600000,), (1630425600000,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_timestamp!='2021-09-01 00:00:00.000' then c_timestamp else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_nchar='bbbbbbbb' then c_nchar else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('bbbbbbbb',), ('false',), ('true',), ('false',), ('true',), ('false',), ('true',), ('false',), ('true',), (None,)])
|
||||
|
||||
tdSql.query("select case when c_nchar!='bbbbbbbb' then c_nchar else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('true',), ('cccccccc',), ('dddddddd',), ('eeeeeeee',), ('ffffffff',), ('gggggggg',), ('hhhhhhhh',), ('iiiiiiii',), ('jjjjjjjj',), (None,)])
|
||||
|
||||
tdSql.query("select case when c_utinyint=2 then c_utinyint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_utinyint!=2 then c_utinyint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_usmallint=2 then c_usmallint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_usmallint!=2 then c_usmallint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_uint=2 then c_uint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_uint!=2 then c_uint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_ubigint=2 then c_ubigint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_ubigint!=2 then c_ubigint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_ubigint=2 then c_ubigint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (1,), (0,), (1,), (0,), (1,), (0,), (1,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_ubigint!=2 then c_ubigint else c_bool end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(1,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.error("select case when c_varbinary='\x30783037' then c_varbinary else c_bool end from st1;")
|
||||
tdSql.error("select case when c_varbinary!='\x30783037' then c_varbinary else c_bool end from st1;")
|
||||
|
||||
tdSql.query("select case when c_null is null then NULL else c_tinyint end from st1;")
|
||||
assert(tdSql.checkRows(10) and all([item[0] is None for item in tdSql.res]))
|
||||
|
||||
tdSql.query("select case when c_null is not null then NULL else c_tinyint end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_bool=true then false else c_tinyint end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(0,), (3,), (0,), (5,), (0,), (7,), (0,), (9,), (0,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_bool!=true then false else c_tinyint end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (0,), (4,), (0,), (6,), (0,), (8,), (0,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_smallint=2 then c_smallint else c_tinyint end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_smallint!=2 then c_smallint else c_tinyint end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_int=2 then c_smallint else c_int end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_int!=2 then c_smallint else c_int end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [(2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,), (None,)])
|
||||
|
||||
tdSql.query("select case when c_float=2.2 then 387897 else 'test message' end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('387897',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',)])
|
||||
|
||||
tdSql.query("select case when c_double=2.22 then 387897 else 'test message' end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('387897',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',)])
|
||||
|
||||
tdSql.query("select case when c_varchar='cccccccc' then 'test' when c_varchar='bbbbbbbb' then 'bbbb' else 'test message' end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('bbbb',), ('test',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',), ('test message',)])
|
||||
|
||||
tdSql.query("select case when ts='2024-10-01 00:00:04.000' then 456646546 when ts>'2024-10-01 00:00:04.000' then 'after today' else 'before today or unknow date' end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('before today or unknow date',), ('before today or unknow date',), ('before today or unknow date',), ('before today or unknow date',), ('456646546',), ('after today',), ('after today',), ('after today',), ('after today',), ('after today',)])
|
||||
|
||||
tdSql.error("select case when c_geometry is null then c_geometry else c_null end from st1;")
|
||||
tdSql.error("select case when c_geometry is not null then c_geometry else c_null end from st1;")
|
||||
tdSql.error("select case when c_geometry='POINT(2 2)' then c_geometry else c_bool end from st1;")
|
||||
tdSql.error("select case when c_geometry!='POINT(2 2)' then c_geometry else c_bool end from st1;")
|
||||
|
||||
tdSql.error("select case when t is null then t else c_null end from st2;")
|
||||
tdSql.error("select case when t is not null then t else c_null end from st2;")
|
||||
tdSql.error("select case when t->'location'='beijing' then t->'location' else c_bool end from st2;")
|
||||
tdSql.error("select case when t->'location'!='beijing' then t->'location' else c_bool end from st1;")
|
||||
|
||||
tdSql.query("select case when c_float!=2.2 then 387897 else 'test message' end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('test message',), ('387897',), ('387897',), ('387897',), ('387897',), ('387897',), ('387897',), ('387897',), ('387897',), ('test message',)])
|
||||
|
||||
tdSql.query("select case when c_double!=2.22 then 387897 else 'test message' end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('test message',), ('387897',), ('387897',), ('387897',), ('387897',), ('387897',), ('387897',), ('387897',), ('387897',), ('test message',)])
|
||||
|
||||
tdSql.query("select case c_tinyint when 2 then -2147483648 when 3 then 'three' else '4294967295' end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('-2147483648',), ('three',), ('4294967295',), ('4294967295',), ('4294967295',), ('4294967295',), ('4294967295',), ('4294967295',), ('4294967295',), ('4294967295',)])
|
||||
|
||||
tdSql.query("select case c_float when 2.2 then 9.2233720e+18 when 3.3 then -9.2233720e+18 else 'aa' end from st1;")
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('9223372000000000000.000000',), ('-9223372000000000000.000000',), ('aa',), ('aa',), ('aa',), ('aa',), ('aa',), ('aa',), ('aa',), ('aa',)])
|
||||
|
||||
tdSql.query("select case t1.c_int when 2 then 'run' when t1.c_int is null then 'other' else t2.c_varchar end from st1 t1, st2 t2 where t1.ts=t2.ts;")
|
||||
print(tdSql.res)
|
||||
assert(tdSql.checkRows(10) and tdSql.res == [('run',), ('cccccccc',), ('dddddddd',), ('eeeeeeee',), ('ffffffff',), ('gggggggg',), ('hhhhhhhh',), ('iiiiiiii',), ('jjjjjjjj',), (None,)])
|
||||
|
||||
tdSql.query("select avg(case when c_tinyint>=2 then c_tinyint else c_null end) from st1;")
|
||||
assert(tdSql.checkRows(1) and tdSql.res == [(6.0,)])
|
||||
|
||||
tdSql.query("select sum(case when c_tinyint>=2 then c_tinyint else c_null end) from st1;")
|
||||
assert(tdSql.checkRows(1) and tdSql.res == [(54,)])
|
||||
|
||||
tdSql.query("select first(case when c_int >=2 then 'abc' else 0 end) from st1;")
|
||||
assert(tdSql.checkRows(1) and tdSql.res == [('abc',)])
|
||||
|
||||
tdSql.query("select last(case when c_int >=2 then c_int else 0 end) from st1;")
|
||||
assert(tdSql.checkRows(1) and tdSql.res == [(0,)])
|
||||
|
||||
def run(self):
|
||||
self.prepare_data()
|
||||
self.test_case_when_statements()
|
||||
|
||||
def stop(self):
|
||||
tdSql.execute("drop database test_case_when;")
|
||||
tdSql.close()
|
||||
tdLog.success("%s successfully executed" % __file__)
|
||||
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -22,6 +22,7 @@
|
|||
,,y,army,./pytest.sh python3 ./test.py -f query/function/cast.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/test_join.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/test_compare.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/test_case_when.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f insert/test_column_tag_boundary.py
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/fill/fill_desc.py -N 3 -L 3 -D 2
|
||||
,,y,army,./pytest.sh python3 ./test.py -f query/fill/fill_null.py
|
||||
|
@ -1085,6 +1086,7 @@
|
|||
,,y,script,./test.sh -f tsim/user/privilege_table.sim
|
||||
,,y,script,./test.sh -f tsim/user/privilege_create_db.sim
|
||||
,,y,script,./test.sh -f tsim/db/alter_option.sim
|
||||
,,y,script,./test.sh -f tsim/db/dnodelist.sim
|
||||
# ,,y,script,./test.sh -f tsim/db/alter_replica_31.sim
|
||||
,,y,script,./test.sh -f tsim/db/basic1.sim
|
||||
,,y,script,./test.sh -f tsim/db/basic2.sim
|
||||
|
|
|
@ -6,15 +6,12 @@ import requests
|
|||
# -*- coding: utf-8 -*-
|
||||
import os ,sys
|
||||
import random
|
||||
import argparse
|
||||
import subprocess
|
||||
import time
|
||||
import platform
|
||||
|
||||
# valgrind mode ?
|
||||
valgrind_mode = False
|
||||
|
||||
msg_dict = {0:"success" , 1:"failed" , 2:"other errors" , 3:"crash occured" , 4:"Invalid read/write" , 5:"memory leak" }
|
||||
msg_dict = {0: "success", 1: "failed", 2: "other errors", 3: "crash occured", 4: "Invalid read/write", 5: "memory leak", 6: "dead locked"}
|
||||
|
||||
# formal
|
||||
hostname = socket.gethostname()
|
||||
|
@ -276,11 +273,15 @@ def check_status():
|
|||
os.system("tail -n 50 %s>>%s"%(result_file,exit_status_logs))
|
||||
|
||||
core_check = subprocess.Popen('ls -l %s | grep "^-" | wc -l'%core_path, shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
|
||||
dead_lock_check = subprocess.Popen("grep -i 'dead locked' %s "%result_file, shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
|
||||
|
||||
if int(core_check.strip().rstrip()) > 0:
|
||||
# it means core files has occured
|
||||
return 3
|
||||
|
||||
if dead_lock_check:
|
||||
return 6
|
||||
|
||||
if "Crash_Gen is now exiting with status code: 1" in run_code:
|
||||
return 1
|
||||
elif "Crash_Gen is now exiting with status code: 0" in run_code:
|
||||
|
|
|
@ -9,15 +9,12 @@ import requests
|
|||
# -*- coding: utf-8 -*-
|
||||
import os ,sys
|
||||
import random
|
||||
import argparse
|
||||
import subprocess
|
||||
import time
|
||||
import platform
|
||||
|
||||
# valgrind mode ?
|
||||
valgrind_mode = True
|
||||
|
||||
msg_dict = {0:"success" , 1:"failed" , 2:"other errors" , 3:"crash occured" , 4:"Invalid read/write" , 5:"memory leak" }
|
||||
msg_dict = {0: "success", 1: "failed", 2: "other errors", 3: "crash occured", 4: "Invalid read/write", 5: "memory leak", 6: "dead locked"}
|
||||
|
||||
# formal
|
||||
hostname = socket.gethostname()
|
||||
|
@ -48,6 +45,7 @@ def send_msg(json):
|
|||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
|
||||
req = requests.post(url=group_url, headers=headers, json=json)
|
||||
inf = req.json()
|
||||
if "StatusCode" in inf and inf["StatusCode"] == 0:
|
||||
|
@ -228,7 +226,6 @@ def get_auto_mix_cmds(args_list ,valgrind=valgrind_mode):
|
|||
|
||||
return crash_gen_cmd
|
||||
|
||||
|
||||
def start_taosd():
|
||||
build_path = get_path()
|
||||
if repo == "community":
|
||||
|
@ -301,6 +298,7 @@ def check_memory():
|
|||
os.mkdir(back_path)
|
||||
|
||||
stderr_file = os.path.join(crash_gen_path , "valgrind.err")
|
||||
stdout_file = os.path.join(crash_gen_path, 'valgrind.out')
|
||||
|
||||
status = 0
|
||||
|
||||
|
@ -319,8 +317,10 @@ def check_memory():
|
|||
grep_res = subprocess.Popen("grep -i 'taosMemoryMalloc' %s "%stderr_file , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
|
||||
|
||||
if grep_res:
|
||||
# mem-leak can be also occure when exit normally when dead lock
|
||||
# os.system("cp %s %s"%(stderr_file , back_path))
|
||||
status = 5
|
||||
dead_lock_res = subprocess.Popen("grep -i 'dead locked' %s "%stdout_file , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
|
||||
status = 6 if dead_lock_res else 5
|
||||
|
||||
return status
|
||||
|
||||
|
|
|
@ -1,23 +1,17 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import os
|
||||
import socket
|
||||
import requests
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
import os ,sys
|
||||
import random
|
||||
import argparse
|
||||
import subprocess
|
||||
import time
|
||||
import platform
|
||||
|
||||
# valgrind mode ?
|
||||
valgrind_mode = True
|
||||
|
||||
msg_dict = {0:"success" , 1:"failed" , 2:"other errors" , 3:"crash occured" , 4:"Invalid read/write" , 5:"memory leak" }
|
||||
msg_dict = {0: "success", 1: "failed", 2: "other errors", 3: "crash occured", 4: "Invalid read/write", 5: "memory leak", 6: "dead locked"}
|
||||
|
||||
# formal
|
||||
hostname = socket.gethostname()
|
||||
|
@ -131,7 +125,6 @@ def random_args(args_list):
|
|||
args_list["--num-threads"]=random.sample(threads,1)[0] #$ debug
|
||||
# args_list["--ignore-errors"]=[] ## can add error codes for detail
|
||||
|
||||
|
||||
args_list["--run-tdengine"]= False
|
||||
args_list["--use-shadow-db"]= False
|
||||
args_list["--dynamic-db-table-names"]= True
|
||||
|
@ -190,7 +183,6 @@ def limits(args_list):
|
|||
|
||||
# else:
|
||||
# pass
|
||||
|
||||
return args_list
|
||||
|
||||
def get_auto_mix_cmds(args_list ,valgrind=valgrind_mode):
|
||||
|
@ -219,16 +211,11 @@ def get_auto_mix_cmds(args_list ,valgrind=valgrind_mode):
|
|||
arguments+=(k+"="+str(v)+" ")
|
||||
|
||||
if valgrind :
|
||||
|
||||
crash_gen_cmd = 'cd %s && ./crash_gen.sh --valgrind -i 3 %s -g 0x32c,0x32d,0x3d3,0x18,0x2501,0x369,0x388,0x061a,0x2550,0x0707,0x0203,0x4012 '%(crash_gen_path ,arguments)
|
||||
|
||||
else:
|
||||
|
||||
crash_gen_cmd = 'cd %s && ./crash_gen.sh -i 3 %s -g 0x32c,0x32d,0x3d3,0x18,0x2501,0x369,0x388,0x061a,0x2550,0x0014,0x0707,0x0203,0x4012'%(crash_gen_path ,arguments)
|
||||
|
||||
return crash_gen_cmd
|
||||
|
||||
|
||||
def start_taosd():
|
||||
build_path = get_path()
|
||||
if repo == "community":
|
||||
|
@ -283,7 +270,6 @@ def check_status():
|
|||
else:
|
||||
return 2
|
||||
|
||||
|
||||
def check_memory():
|
||||
|
||||
build_path = get_path()
|
||||
|
@ -301,7 +287,7 @@ def check_memory():
|
|||
os.mkdir(back_path)
|
||||
|
||||
stderr_file = os.path.join(crash_gen_path , "valgrind.err")
|
||||
|
||||
stdout_file = os.path.join(crash_gen_path, 'valgrind.out')
|
||||
status = 0
|
||||
|
||||
grep_res = subprocess.Popen("grep -i 'Invalid read' %s "%stderr_file , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
|
||||
|
@ -319,13 +305,14 @@ def check_memory():
|
|||
grep_res = subprocess.Popen("grep -i 'taosMemoryMalloc' %s "%stderr_file , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
|
||||
|
||||
if grep_res:
|
||||
# mem-leak can be also occure when exit normally when dead lock
|
||||
# os.system("cp %s %s"%(stderr_file , back_path))
|
||||
status = 5
|
||||
dead_lock_res = subprocess.Popen("grep -i 'dead locked' %s "%stdout_file , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
|
||||
status = 6 if dead_lock_res else 5
|
||||
|
||||
return status
|
||||
|
||||
def main():
|
||||
|
||||
args_list = {"--auto-start-service":False ,"--max-dbs":0,"--connector-type":"native","--debug":False,"--run-tdengine":False,"--ignore-errors":[],
|
||||
"--track-memory-leaks":False , "--larger-data":False, "--mix-oos-data":False, "--dynamic-db-table-names":False,
|
||||
"--per-thread-db-connection":False , "--record-ops":False , "--max-steps":100, "--num-threads":10, "--verify-data":False,"--use-shadow-db":False ,
|
||||
|
@ -405,7 +392,6 @@ def main():
|
|||
print("exception:", e)
|
||||
exit(status)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ exe:
|
|||
gcc $(CFLAGS) ./stmt.c -o $(ROOT)stmt $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stmt2.c -o $(ROOT)stmt2 $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stmt2-example.c -o $(ROOT)stmt2-example $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stmt2-get-fields.c -o $(ROOT)stmt2-get-fields $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stmt2-nohole.c -o $(ROOT)stmt2-nohole $(LFLAGS)
|
||||
gcc $(CFLAGS) ./stmt-crash.c -o $(ROOT)stmt-crash $(LFLAGS)
|
||||
|
||||
|
@ -42,5 +43,6 @@ clean:
|
|||
rm $(ROOT)stmt
|
||||
rm $(ROOT)stmt2
|
||||
rm $(ROOT)stmt2-example
|
||||
rm $(ROOT)stmt2-get-fields
|
||||
rm $(ROOT)stmt2-nohole
|
||||
rm $(ROOT)stmt-crash
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
// TAOS standard API example. The same syntax as MySQL, but only a subet
|
||||
// to compile: gcc -o stmt2-get-fields stmt2-get-fields.c -ltaos
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "taos.h"
|
||||
|
||||
void getFields(TAOS *taos, const char *sql) {
|
||||
TAOS_STMT2_OPTION option = {0};
|
||||
TAOS_STMT2 *stmt = taos_stmt2_init(taos, &option);
|
||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||
if (code != 0) {
|
||||
printf("failed to execute taos_stmt2_prepare. error:%s\n", taos_stmt2_error(stmt));
|
||||
taos_stmt2_close(stmt);
|
||||
return;
|
||||
}
|
||||
int fieldNum = 0;
|
||||
TAOS_FIELD_STB *pFields = NULL;
|
||||
code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields);
|
||||
if (code != 0) {
|
||||
printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt));
|
||||
} else {
|
||||
printf("col nums:%d\n", fieldNum);
|
||||
for (int i = 0; i < fieldNum; i++) {
|
||||
printf("field[%d]: %s, data_type:%d, field_type:%d\n", i, pFields[i].name, pFields[i].type,
|
||||
pFields[i].field_type);
|
||||
}
|
||||
}
|
||||
printf("====================================\n");
|
||||
taos_stmt2_free_stb_fields(stmt, pFields);
|
||||
taos_stmt2_close(stmt);
|
||||
}
|
||||
|
||||
void do_query(TAOS *taos, const char *sql) {
|
||||
TAOS_RES *result = taos_query(taos, sql);
|
||||
int code = taos_errno(result);
|
||||
if (code) {
|
||||
printf("failed to query: %s, reason:%s\n", sql, taos_errstr(result));
|
||||
taos_free_result(result);
|
||||
return;
|
||||
}
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
||||
void do_stmt(TAOS *taos) {
|
||||
do_query(taos, "drop database if exists db");
|
||||
do_query(taos, "create database db");
|
||||
do_query(taos,
|
||||
"create table db.stb (ts timestamp, b binary(10)) tags(t1 "
|
||||
"int, t2 binary(10))");
|
||||
do_query(taos, "CREATE TABLE db.d0 USING db.stb (t1,t2) TAGS (7,'Cali');");
|
||||
do_query(taos, "CREATE TABLE db.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
|
||||
|
||||
printf("field_type: TAOS_FIELD_COL = 1, TAOS_FIELD_TAG=2, TAOS_FIELD_QUERY=3, TAOS_FIELD_TBNAME=4\n");
|
||||
|
||||
// case 1 : INSERT INTO db.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)
|
||||
// test super table
|
||||
const char *sql = "insert into db.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
|
||||
printf("====================================\n");
|
||||
printf("case 1 : %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 2 : INSERT INTO db.d0 VALUES (?,?)
|
||||
// test child table
|
||||
sql = "INSERT INTO db.d0(ts,b) VALUES (?,?)";
|
||||
printf("case 2 : %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 3 : INSERT INTO db.ntb VALUES(?,?,?,?)
|
||||
// test normal table
|
||||
sql = "INSERT INTO db.ntb VALUES(?,?,?,?)";
|
||||
printf("case 3 : %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 4 : INSERT INTO db.? using db.stb TAGS(?,?) VALUES(?,?)
|
||||
// not support this clause
|
||||
sql = "insert into db.? using db.stb tags(?, ?) values(?,?)";
|
||||
printf("case 4 (not support): %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 5 : INSERT INTO db.stb(t1,t2,ts,b) values(?,?,?,?)
|
||||
// no tbname error
|
||||
sql = "INSERT INTO db.stb(t1,t2,ts,b) values(?,?,?,?)";
|
||||
printf("case 5 (no tbname error): %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 6 : INSERT INTO db.d0 using db.stb values(?,?)
|
||||
// none para for ctbname
|
||||
sql = "INSERT INTO db.d0 using db.stb values(?,?)";
|
||||
printf("case 6 (no tags error): %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 7 : insert into db.stb(t1,t2,tbname) values(?,?,?)
|
||||
// no value
|
||||
sql = "insert into db.stb(t1,t2,tbname) values(?,?,?)";
|
||||
printf("case 7 (no PK error): %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 8 : insert into db.stb(ts,b,tbname) values(?,?,?)
|
||||
// no tag
|
||||
sql = "insert into db.stb(ts,b,tbname) values(?,?,?)";
|
||||
printf("case 8 : %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 9 : insert into db.stb(ts,b,tbname) values(?,?,?,?,?)
|
||||
// wrong para nums
|
||||
sql = "insert into db.stb(ts,b,tbname) values(?,?,?,?,?)";
|
||||
printf("case 9 (wrong para nums): %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
|
||||
// case 10 : insert into db.ntb(nts,ni) values(?,?,?,?,?)
|
||||
// wrong para nums
|
||||
sql = "insert into db.ntb(nts,ni) values(?,?)";
|
||||
printf("case 10 : %s\n", sql);
|
||||
getFields(taos, sql);
|
||||
}
|
||||
|
||||
int main() {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", "", 0);
|
||||
if (!taos) {
|
||||
printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
do_stmt(taos);
|
||||
taos_close(taos);
|
||||
taos_cleanup();
|
||||
}
|
|
@ -0,0 +1,258 @@
|
|||
system sh/stop_dnodes.sh
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/deploy.sh -n dnode2 -i 2
|
||||
system sh/deploy.sh -n dnode3 -i 3
|
||||
system sh/deploy.sh -n dnode4 -i 4
|
||||
system sh/deploy.sh -n dnode5 -i 5
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
system sh/exec.sh -n dnode2 -s start
|
||||
system sh/exec.sh -n dnode3 -s start
|
||||
system sh/exec.sh -n dnode4 -s start
|
||||
system sh/exec.sh -n dnode5 -s start
|
||||
|
||||
sql connect
|
||||
sql create dnode $hostname port 7200
|
||||
sql create dnode $hostname port 7300
|
||||
sql create dnode $hostname port 7400
|
||||
sql create dnode $hostname port 7500
|
||||
|
||||
$x = 0
|
||||
step1:
|
||||
$x = $x + 1
|
||||
sleep 1000
|
||||
if $x == 10 then
|
||||
print ====> dnode not ready!
|
||||
return -1
|
||||
endi
|
||||
sql select * from information_schema.ins_dnodes
|
||||
print ===> $data00 $data01 $data02 $data03 $data04 $data05
|
||||
print ===> $data10 $data11 $data12 $data13 $data14 $data15
|
||||
print ===> $data20 $data21 $data22 $data23 $data24 $data25
|
||||
print ===> $data30 $data31 $data32 $data33 $data34 $data35
|
||||
print ===> $data40 $data41 $data42 $data43 $data44 $data45
|
||||
if $rows != 5 then
|
||||
return -1
|
||||
endi
|
||||
if $data(1)[4] != ready then
|
||||
goto step1
|
||||
endi
|
||||
if $data(2)[4] != ready then
|
||||
goto step1
|
||||
endi
|
||||
if $data(3)[4] != ready then
|
||||
goto step1
|
||||
endi
|
||||
if $data(4)[4] != ready then
|
||||
goto step1
|
||||
endi
|
||||
if $data(5)[4] != ready then
|
||||
goto step1
|
||||
endi
|
||||
|
||||
print --- error case
|
||||
|
||||
sql_error create database d1 vgroups 1 dnodes '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';
|
||||
sql_error create database d1 vgroups 1 dnodes '1 ';
|
||||
sql_error create database d1 vgroups 1 dnodes ' 1';
|
||||
sql_error create database d1 vgroups 1 dnodes '1,';
|
||||
sql_error create database d1 vgroups 1 dnodes '1, ';
|
||||
sql_error create database d1 vgroups 1 dnodes 'a ';
|
||||
sql_error create database d1 vgroups 1 dnodes '- ';
|
||||
sql_error create database d1 vgroups 1 dnodes '1,1';
|
||||
sql_error create database d1 vgroups 1 dnodes '1, 1';
|
||||
sql_error create database d1 vgroups 1 dnodes '1,1234567890';
|
||||
sql_error create database d1 vgroups 1 dnodes '1,2,6';
|
||||
sql_error create database d1 vgroups 1 dnodes ',1,2';
|
||||
sql_error create database d1 vgroups 1 dnodes 'x1,2';
|
||||
sql_error create database d1 vgroups 1 dnodes 'c1,ab2';
|
||||
sql_error create database d1 vgroups 1 dnodes '1,1,2';
|
||||
|
||||
sql_error create database d1 vgroups 1 replica 2 dnodes '1';
|
||||
sql_error create database d1 vgroups 1 replica 2 dnodes '1,8';
|
||||
sql_error create database d1 vgroups 1 replica 3 dnodes '1';
|
||||
sql_error create database d1 vgroups 1 replica 3 dnodes '1,2';
|
||||
sql_error create database d1 vgroups 1 replica 3 dnodes '1,2,4,6';
|
||||
|
||||
print --- replica 1
|
||||
|
||||
print --- case10
|
||||
sql create database d10 vgroups 1 dnodes '1';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql_error alter database d10 replica 1 dnodes '1,2,3';
|
||||
sql drop database d10;
|
||||
|
||||
print --- case11
|
||||
sql create database d11 vgroups 1 dnodes '2';
|
||||
sql show dnodes;
|
||||
if $data(2)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d11;
|
||||
|
||||
print --- case12
|
||||
sql create database d12 vgroups 2 dnodes '3,4';
|
||||
sql show dnodes;
|
||||
if $data(3)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data(4)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d12;
|
||||
|
||||
print --- case13
|
||||
sql create database d13 vgroups 2 dnodes '5';
|
||||
sql show dnodes;
|
||||
if $data(5)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d13;
|
||||
|
||||
print --- case14
|
||||
sql create database d14 vgroups 1 dnodes '1,2,5';
|
||||
sql drop database d14;
|
||||
|
||||
print --- case15
|
||||
sql create database d15 vgroups 2 dnodes '1,4,3';
|
||||
sql drop database d15;
|
||||
|
||||
print --- case16
|
||||
sql create database d16 vgroups 3 dnodes '1';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d16;
|
||||
|
||||
print --- case17
|
||||
sql create database d17 vgroups 3 dnodes '1,4';
|
||||
sql drop database d17;
|
||||
|
||||
print --- case18
|
||||
sql create database d18 vgroups 3 dnodes '1,2,4';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data(2)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data(4)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d18;
|
||||
|
||||
print --- replica 2
|
||||
|
||||
print --- case20
|
||||
sql create database d20 replica 2 vgroups 1 dnodes '1,2';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data(2)[2] != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d20;
|
||||
|
||||
print --- case21
|
||||
sql create database d21 replica 2 vgroups 3 dnodes '1,2,3';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
if $data(2)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
if $data(3)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d21;
|
||||
|
||||
print --- case22
|
||||
sql create database d22 replica 2 vgroups 2 dnodes '1,2';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
if $data(2)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d22;
|
||||
|
||||
print --- replica 3
|
||||
|
||||
print --- case30
|
||||
sql create database d30 replica 3 vgroups 3 dnodes '1,2,3';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(2)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(3)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
sql_error alter database d30 replica 1 dnodes '1';
|
||||
sql drop database d30;
|
||||
|
||||
print --- case31
|
||||
sql create database d31 replica 3 vgroups 2 dnodes '1,2,4';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
if $data(2)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
if $data(4)[2] != 2 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d31;
|
||||
|
||||
print --- case32
|
||||
sql create database d32 replica 3 vgroups 4 dnodes '4,2,3,1';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(2)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(3)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(4)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d32;
|
||||
|
||||
print --- case33
|
||||
sql create database d33 replica 3 vgroups 5 dnodes '4,2,3,1,5';
|
||||
sql show dnodes;
|
||||
if $data(1)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(2)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(3)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(4)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data(5)[2] != 3 then
|
||||
return -1
|
||||
endi
|
||||
sql drop database d33;
|
||||
|
||||
return
|
||||
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
system sh/exec.sh -n dnode2 -s stop -x SIGINT
|
||||
system sh/exec.sh -n dnode3 -s stop -x SIGINT
|
|
@ -838,7 +838,7 @@ endi
|
|||
if $data20 != 11 then
|
||||
return -1
|
||||
endi
|
||||
if $data30 != 1664176504 then
|
||||
if $data30 != 1664176504000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
@ -1130,38 +1130,38 @@ if $data00 != varchar_val then
|
|||
return -1
|
||||
endi
|
||||
|
||||
sql select case when ts > '2022-01-01 00:00:00' then c_varchar else c_geometry end as result from t_test;
|
||||
if $data00 != varchar_val then
|
||||
sql select case when 1 then 1234567890987654 else 'abcertyuiojhgfddhjgfcvbn' end;
|
||||
if $data00 != 1234567890987654 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select case when ts > '2022-01-01 00:00:00' then c_bool else c_geometry end as result from t_test;
|
||||
if $data00 != true then
|
||||
sql select case when 0 then 1234567890987654 else 'abcertyuiojhgfddhjgfcvbn' end;
|
||||
if $data00 != abcertyuiojhgfddhjgfcvbn then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select case when 0 then tag_id else c_geometry end as result from t_test;
|
||||
if $data00 != 16842773 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select case when 0 then tag_id else c_nchar end as result from t_test;
|
||||
sql select case when 0 then 1234567890987654 else c_nchar end from t_test;
|
||||
if $data00 != 涛思数据 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select case when 0 then tag_id else c_int end as result from t_test;
|
||||
if $data00 != 123 then
|
||||
sql select case when 1 then 1234567890987654 else c_nchar end from t_test;
|
||||
if $data00 != 1234567890987654 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select case when 0 then tag_id else c_float end as result from t_test;
|
||||
if $data00 != 123.449997 then
|
||||
sql select case when 1 then c_varchar else c_varbinary end from t_test;
|
||||
if $data00 != null then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql_error select case when ts > '2022-01-01 00:00:00' then c_varchar else c_geometry end as result from t_test;
|
||||
sql_error select case when ts > '2022-01-01 00:00:00' then c_bool else c_geometry end as result from t_test;
|
||||
sql_error select case when 0 then tag_id else c_geometry end as result from t_test;
|
||||
sql_error select case when 0 then tag_id else c_nchar end as result from t_test;
|
||||
sql_error select case when 0 then tag_id else c_int end as result from t_test;
|
||||
sql_error select case when 0 then tag_id else c_float end as result from t_test;
|
||||
sql_error select case when c_double > 100 then c_varbinary else c_geometry end as result from t_test;
|
||||
sql_error select case when c_bool then c_double else c_varbinary end as result from t_test;
|
||||
sql_error select case when c_bool then c_varbinary else c_varchar end as result from t_test;
|
||||
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue