Merge branch '3.0' into fix/TD-30990
This commit is contained in:
commit
4701a92f26
|
@ -401,7 +401,7 @@ pipeline {
|
|||
}
|
||||
}
|
||||
stage('linux test') {
|
||||
agent{label " slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 "}
|
||||
agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || worker03 || slave215 || slave217 || slave219 "}
|
||||
options { skipDefaultCheckout() }
|
||||
when {
|
||||
changeRequest()
|
||||
|
|
|
@ -49,6 +49,7 @@ table_option: {
|
|||
7. Escape character "\`" can be used to avoid the conflict between table names and reserved keywords, above rules will be bypassed when using escape character on table names, but the upper limit for the name length is still valid. The table names specified using escape character are case sensitive.
|
||||
For example \`aBc\` and \`abc\` are different table names but `abc` and `aBc` are same table names because they are both converted to `abc` internally.
|
||||
Only ASCII visible characters can be used with escape character.
|
||||
8. For the details of using `ENCODE` and `COMPRESS`, please refer to [Encode and Compress for Column](../compress).
|
||||
|
||||
**Parameter description**
|
||||
|
||||
|
|
|
@ -13,17 +13,29 @@ create_definition:
|
|||
col_name column_definition
|
||||
|
||||
column_definition:
|
||||
type_name
|
||||
type_name [comment 'string_value'] [PRIMARY KEY] [ENCODE 'encode_type'] [COMPRESS 'compress_type'] [LEVEL 'level_type']
|
||||
|
||||
table_options:
|
||||
table_option ...
|
||||
|
||||
table_option: {
|
||||
COMMENT 'string_value'
|
||||
| SMA(col_name [, col_name] ...)
|
||||
| TTL value
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
**More explanations**
|
||||
- Each supertable can have a maximum of 4096 columns, including tags. The minimum number of columns is 3: a timestamp column used as the key, one tag column, and one data column.
|
||||
- The TAGS keyword defines the tag columns for the supertable. The following restrictions apply to tag columns:
|
||||
1. Each supertable can have a maximum of 4096 columns, including tags. The minimum number of columns is 3: a timestamp column used as the key, one tag column, and one data column.
|
||||
2. Since version 3.3.0.0, besides the timestamp, you can specify another column as primary key using `PRIMARY KEY` keyword, the column specified using `primary key` must be type of integer or varchar.
|
||||
2. The TAGS keyword defines the tag columns for the supertable. The following restrictions apply to tag columns:
|
||||
- A tag column can use the TIMESTAMP data type, but the values in the column must be fixed numbers. Timestamps including formulae, such as "now + 10s", cannot be stored in a tag column.
|
||||
- The name of a tag column cannot be the same as the name of any other column.
|
||||
- The name of a tag column cannot be a reserved keyword.
|
||||
- Each supertable must contain between 1 and 128 tags. The total length of the TAGS keyword cannot exceed 16 KB.
|
||||
- For more information about table parameters, see Create a Table.
|
||||
3. Regarding how to use `ENCODE` and `COMPRESS`, please refer to [Encode and Compress for Column](../compress).
|
||||
3. For more information about table parameters, see [Create a Table](../table).
|
||||
|
||||
## View a Supertable
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ select _wstart, tbname, avg(voltage) from meters partition by tbname interval(10
|
|||
|
||||
## Windowed Queries
|
||||
|
||||
Aggregation by time window is supported in TDengine. For example, in the case where temperature sensors report the temperature every seconds, the average temperature for every 10 minutes can be retrieved by performing a query with a time window. Window related clauses are used to divide the data set to be queried into subsets and then aggregation is performed across the subsets. There are four kinds of windows: time window, status window, session window, and event window. There are two kinds of time windows: sliding window and flip time/tumbling window. The syntax of window clause is as follows:
|
||||
Aggregation by time window is supported in TDengine. For example, in the case where temperature sensors report the temperature every seconds, the average temperature for every 10 minutes can be retrieved by performing a query with a time window. Window related clauses are used to divide the data set to be queried into subsets and then aggregation is performed across the subsets. There are five kinds of windows: time window, status window, session window, event window, and count window. There are two kinds of time windows: sliding window and flip time/tumbling window. The syntax of window clause is as follows:
|
||||
|
||||
```sql
|
||||
window_clause: {
|
||||
|
|
|
@ -729,6 +729,57 @@ The charset that takes effect is UTF-8.
|
|||
| Value Range | -1: none message is compressed; 0: all messages are compressed; N (N>0): messages exceeding N bytes are compressed |
|
||||
| Default | -1 |
|
||||
|
||||
### fPrecision
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Application | Server Only |
|
||||
| Meaning | Compression precision for float data type |
|
||||
| Value Range | 0.1 ~ 0.00000001 |
|
||||
| Default | 0.00000001 |
|
||||
| Note | The floating value below this setting will be cut off |
|
||||
|
||||
### dPrecision
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Applicable | Server Only |
|
||||
| Meaning | Compression precision for double data type |
|
||||
| Value Range | 0.1 ~ 0.0000000000000001 |
|
||||
| Default | 0.0000000000000001 |
|
||||
| Note | The floating value below this setting will be cut off |
|
||||
|
||||
### lossyColumn
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Applicable | Server Only |
|
||||
| Meaning | Enable TSZ lossy compression for float and/or double |
|
||||
| Value Range | float, double |
|
||||
| Default | none: disable TSZ lossy compression |
|
||||
|
||||
**补充说明**
|
||||
1. It's only available since 3.2.0.0 version, and can't downgrade to previous version once upgrading to 3.2.0.0 and enabling this parameter
|
||||
2. TSZ compression algorithm compresses data based on data prediction technique, so it's more suitable for data with specific pattern
|
||||
3. TSZ compression algorithm may take longer time but it has better compression ratio, so it's suitable when you have enough CPU resources and are more sensitive to disk occupation
|
||||
4. Example: enable TSZ for both float and double
|
||||
```shell
|
||||
lossyColumns float|double
|
||||
```
|
||||
5. After configuring, taosd service needs to restarted. After restarting, if you see the following output in taosd logfile, it means the function has been enabled
|
||||
```sql
|
||||
02/22 10:49:27.607990 00002933 UTL lossyColumns float|double
|
||||
```
|
||||
|
||||
### ifAdtFse
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Applicable | Server Only |
|
||||
| Meaning | Replace HUFFMAN with FSE in TSZ, FSE is faster when compressing but slower when uncompressing |
|
||||
| Value Range | 0: Use HUFFMAN, 1: Use FSE |
|
||||
| Default | 0: Use HUFFMAN |
|
||||
|
||||
|
||||
## Other Parameters
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ table_option: {
|
|||
6. 使用数据类型 BINARY/NCHAR/GEOMETRY,需指定其最长的字节数,如 BINARY(20),表示 20 字节。
|
||||
7. 为了兼容支持更多形式的表名,TDengine 引入新的转义符 "\`",可以让表名与关键词不冲突,同时不受限于上述表名称合法性约束检查。但是同样具有长度限制要求。使用转义字符以后,不再对转义字符中的内容进行大小写统一,
|
||||
例如:\`aBc\` 和 \`abc\` 是不同的表名,但是 abc 和 aBc 是相同的表名。
|
||||
8. 关于 `ENCODE` 和 `COMPRESS` 的使用,请参考[按列压缩](../compress)
|
||||
|
||||
**参数说明**
|
||||
|
||||
|
|
|
@ -13,17 +13,28 @@ create_definition:
|
|||
col_name column_definition
|
||||
|
||||
column_definition:
|
||||
type_name
|
||||
type_name [comment 'string_value'] [PRIMARY KEY] [ENCODE 'encode_type'] [COMPRESS 'compress_type'] [LEVEL 'level_type']
|
||||
|
||||
table_options:
|
||||
table_option ...
|
||||
|
||||
table_option: {
|
||||
COMMENT 'string_value'
|
||||
| SMA(col_name [, col_name] ...)
|
||||
| TTL value
|
||||
}
|
||||
```
|
||||
|
||||
**使用说明**
|
||||
- 超级表中列的最大个数为 4096,需要注意,这里的 4096 是包含 TAG 列在内的,最小个数为 3,包含一个时间戳主键、一个 TAG 列和一个数据列。
|
||||
- TAGS语法指定超级表的标签列,标签列需要遵循以下约定:
|
||||
1. 超级表中列的最大个数为 4096,需要注意,这里的 4096 是包含 TAG 列在内的,最小个数为 3,包含一个时间戳主键、一个 TAG 列和一个数据列。
|
||||
2. 除时间戳主键列之外,还可以通过 PRIMARY KEY 关键字指定第二列为额外的主键列。被指定为主键列的第二列必须为整型或字符串类型(varchar)
|
||||
3. TAGS语法指定超级表的标签列,标签列需要遵循以下约定:
|
||||
- TAGS 中的 TIMESTAMP 列写入数据时需要提供给定值,而暂不支持四则运算,例如 NOW + 10s 这类表达式。
|
||||
- TAGS 列名不能与其他列名相同。
|
||||
- TAGS 列名不能为预留关键字。
|
||||
- TAGS 最多允许 128 个,至少 1 个,总长度不超过 16 KB。
|
||||
- 关于表参数的详细说明,参见 CREATE TABLE 中的介绍。
|
||||
4. 关于 `ENCODE` 和 `COMPRESS` 的使用,请参考 [按列压缩](../compress)
|
||||
5. 关于 table_option 中的参数说明,请参考 [建表 SQL 说明](../table)
|
||||
|
||||
## 查看超级表
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ select _wstart, tbname, avg(voltage) from meters partition by tbname interval(10
|
|||
|
||||
## 窗口切分查询
|
||||
|
||||
TDengine 支持按时间窗口切分方式进行聚合结果查询,比如温度传感器每秒采集一次数据,但需查询每隔 10 分钟的温度平均值。这种场景下可以使用窗口子句来获得需要的查询结果。窗口子句用于针对查询的数据集合按照窗口切分成为查询子集并进行聚合,窗口包含时间窗口(time window)、状态窗口(status window)、会话窗口(session window)、事件窗口(event window)四种窗口。其中时间窗口又可划分为滑动时间窗口和翻转时间窗口。
|
||||
TDengine 支持按时间窗口切分方式进行聚合结果查询,比如温度传感器每秒采集一次数据,但需查询每隔 10 分钟的温度平均值。这种场景下可以使用窗口子句来获得需要的查询结果。窗口子句用于针对查询的数据集合按照窗口切分成为查询子集并进行聚合,窗口包含时间窗口(time window)、状态窗口(status window)、会话窗口(session window)、事件窗口(event window)、计数窗口(count window)五种窗口。其中时间窗口又可划分为滑动时间窗口和翻转时间窗口。
|
||||
|
||||
窗口子句语法如下:
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
title: 可配置压缩算法
|
||||
sidebar_label: 可配置压缩
|
||||
description: 可配置压缩算法
|
||||
---
|
||||
|
|
@ -784,6 +784,57 @@ charset 的有效值是 UTF-8。
|
|||
| 取值范围 | -1: 所有消息都不压缩; 0: 所有消息都压缩; N (N>0): 只有大于 N 个字节的消息才压缩 |
|
||||
| 缺省值 | -1 |
|
||||
|
||||
### fPrecision
|
||||
FLOAT 类型压缩精度控制:
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 设置 float 类型浮点数压缩精度 |
|
||||
| 取值范围 | 0.1 ~ 0.00000001 |
|
||||
| 缺省值 | 0.00000001 |
|
||||
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
|
||||
|
||||
### dPrecision
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 设置 double 类型浮点数压缩精度 |
|
||||
| 取值范围 | 0.1 ~ 0.0000000000000001 |
|
||||
| 缺省值 | 0.0000000000000001 |
|
||||
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
|
||||
|
||||
### lossyColumn
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 对 float 和/或 double 类型启用 TSZ 有损压缩 |
|
||||
| 取值范围 | float, double |
|
||||
| 缺省值 | none:表示关闭无损压缩 |
|
||||
|
||||
**补充说明**
|
||||
1. 在 3.2.0.0 ~ 3.3.0.0(不包含)版本生效,启用该参数后不能回退到升级前的版本
|
||||
2. TSZ 压缩算法是通过数据预测技术完成的压缩,所以更适合有规律变化的数据
|
||||
3. TSZ 压缩时间会更长一些,如果您的服务器 CPU 空闲多,存储空间小的情况下适合选用
|
||||
4. 示例:对 float 和 double 类型都启用有损压缩
|
||||
```shell
|
||||
lossyColumns float|double
|
||||
```
|
||||
5. 配置需重启服务生效,重启如果在 taosd 日志中看到以下内容,表明配置已生效:
|
||||
```sql
|
||||
02/22 10:49:27.607990 00002933 UTL lossyColumns float|double
|
||||
```
|
||||
|
||||
### ifAdtFse
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 在启用 TSZ 有损压缩时,使用 FSE 算法替换 HUFFMAN 算法, FSE 算法压缩速度更快,但解压稍慢,追求压缩速度可选用此算法 |
|
||||
| 取值范围 | 0:关闭 1:打开 |
|
||||
| 缺省值 | 0:关闭 |
|
||||
|
||||
## 3.0 中有效的配置参数列表
|
||||
|
||||
| # | **参数** | **适用于 2.X ** | **适用于 3.0 ** | 3.0 版本的当前行为 |
|
||||
|
@ -922,8 +973,5 @@ charset 的有效值是 UTF-8。
|
|||
| 73 | probeSeconds | 是 | 否 | 3.0 行为未知 |
|
||||
| 74 | probeKillSeconds | 是 | 否 | 3.0 行为未知 |
|
||||
| 75 | probeInterval | 是 | 否 | 3.0 行为未知 |
|
||||
| 76 | lossyColumns | 是 | 否 | 3.0 行为未知 |
|
||||
| 77 | fPrecision | 是 | 否 | 3.0 行为未知 |
|
||||
| 78 | dPrecision | 是 | 否 | 3.0 行为未知 |
|
||||
| 79 | maxRange | 是 | 否 | 3.0 行为未知 |
|
||||
| 80 | range | 是 | 否 | 3.0 行为未知 |
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
---
|
||||
title: TSZ 压缩算法
|
||||
description: TDengine 对浮点数进行高效压缩的算法
|
||||
---
|
||||
|
||||
TSZ 压缩算法是 TDengine 为浮点数据类型提供的可选压缩算法,可以实现浮点数有损至无损全状态压缩,相比默认压缩算法, TSZ 压缩算法压缩率更高,即使切至无损状态,压缩率也会比默认压缩高一倍。
|
||||
|
||||
## 适合场景
|
||||
|
||||
- TSZ 压缩算法是通过数据预测技术完成的压缩,所以更适合有规律变化的数据
|
||||
- TSZ 压缩时间会更长一些,如果您的服务器 CPU 空闲多,存储空间小的情况下适合选用
|
||||
|
||||
## 使用步骤
|
||||
- TDengine 支持版本为 3.2.0.0 或以上
|
||||
- 开启选项
|
||||
在 taos.cfg 配置中增加以下内容,即可开启 TSZ 压缩算法,功能打开后,会替换默认算法。
|
||||
以下表示字段类型是 float 及 double 类型都使用此压缩算法,也可以单独只配置一个
|
||||
|
||||
```sql
|
||||
lossyColumns float|double
|
||||
```
|
||||
|
||||
- 配置需重启服务生效
|
||||
- Taosd 日志输出以下内容,表明功能已生效:
|
||||
|
||||
```sql
|
||||
02/22 10:49:27.607990 00002933 UTL lossyColumns float|double
|
||||
```
|
||||
|
||||
## 配置参数
|
||||
|
||||
### fPrecision
|
||||
FLOAT 类型精度控制:
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 设置 float 类型浮点数压缩精度 |
|
||||
| 取值范围 | 0.1 ~ 0.00000001 |
|
||||
| 缺省值 | 0.00000001 |
|
||||
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
|
||||
|
||||
|
||||
|
||||
### dPrecision
|
||||
DOUBLE 类型精度控制:
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 设置 double 类型浮点数压缩精度 |
|
||||
| 取值范围 | 0.1 ~ 0.0000000000000001 |
|
||||
| 缺省值 | 0.0000000000000001 |
|
||||
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
|
||||
|
||||
|
||||
### ifAdtFse
|
||||
TSZ 压缩中可选择的算法 FSE,默认为 HUFFMAN:
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 使用 FSE 算法替换 HUFFMAN 算法, FSE 算法压缩速度更快,但解压稍慢,追求压缩速度可选用此算法 |
|
||||
| 取值范围 | 0:关闭 1:打开 |
|
||||
| 缺省值 | 0:关闭 |
|
||||
|
||||
|
||||
## 注意事项
|
||||
- 打开 TSZ 后生成的存储数据格式,回退至 3.2.0.0 之前的版本,数据将不能被识别
|
|
@ -3612,6 +3612,7 @@ typedef struct {
|
|||
|
||||
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
|
||||
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
|
||||
void tDeleteSTqOffset(void* val);
|
||||
|
||||
typedef struct SMqVgOffset {
|
||||
int64_t consumerId;
|
||||
|
|
|
@ -81,7 +81,7 @@ typedef struct {
|
|||
// uint64_t uid; // child table uid, may be useful
|
||||
} RandTableName;
|
||||
|
||||
void buildChildTableName(RandTableName* rName);
|
||||
int32_t buildChildTableName(RandTableName* rName);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -381,7 +381,7 @@ typedef struct SStateStore {
|
|||
void** ppVal, int32_t* pVLen);
|
||||
int32_t (*streamStateCountWinAdd)(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||
|
||||
SUpdateInfo* (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen);
|
||||
int32_t (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen, SUpdateInfo** ppInfo);
|
||||
TSKEY (*updateInfoFillBlockData)(SUpdateInfo* pInfo, SSDataBlock* pBlock, int32_t primaryTsCol, int32_t primaryKeyCol);
|
||||
bool (*updateInfoIsUpdated)(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
||||
bool (*updateInfoIsTableInserted)(SUpdateInfo* pInfo, int64_t tbUid);
|
||||
|
@ -389,12 +389,12 @@ typedef struct SStateStore {
|
|||
|
||||
void (*updateInfoDestroy)(SUpdateInfo* pInfo);
|
||||
void (*windowSBfDelete)(SUpdateInfo* pInfo, uint64_t count);
|
||||
void (*windowSBfAdd)(SUpdateInfo* pInfo, uint64_t count);
|
||||
int32_t (*windowSBfAdd)(SUpdateInfo* pInfo, uint64_t count);
|
||||
|
||||
SUpdateInfo* (*updateInfoInitP)(SInterval* pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen);
|
||||
int32_t (*updateInfoInitP)(SInterval* pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen, SUpdateInfo** ppInfo);
|
||||
void (*updateInfoAddCloseWindowSBF)(SUpdateInfo* pInfo);
|
||||
void (*updateInfoDestoryColseWinSBF)(SUpdateInfo* pInfo);
|
||||
int32_t (*updateInfoSerialize)(void* buf, int32_t bufLen, const SUpdateInfo* pInfo);
|
||||
int32_t (*updateInfoSerialize)(void* buf, int32_t bufLen, const SUpdateInfo* pInfo, int32_t* pLen);
|
||||
int32_t (*updateInfoDeserialize)(void* buf, int32_t bufLen, SUpdateInfo* pInfo);
|
||||
|
||||
SStreamStateCur* (*streamStateSessionSeekKeyNext)(SStreamState* pState, const SSessionKey* key);
|
||||
|
|
|
@ -149,10 +149,10 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char*
|
|||
|
||||
void qDestroyBoundColInfo(void* pInfo);
|
||||
|
||||
SQuery* smlInitHandle();
|
||||
int32_t smlInitHandle(SQuery** query);
|
||||
int32_t smlBuildRow(STableDataCxt* pTableCxt);
|
||||
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* kv, int32_t index);
|
||||
STableDataCxt* smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta);
|
||||
int32_t smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta, STableDataCxt** cxt);
|
||||
|
||||
void clearColValArraySml(SArray* pCols);
|
||||
int32_t smlBindData(SQuery* handle, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols,
|
||||
|
@ -163,8 +163,8 @@ int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCr
|
|||
int numFields, bool needChangeLength, char* errstr, int32_t errstrLen);
|
||||
|
||||
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
|
||||
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
|
||||
SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap);
|
||||
int32_t serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap, SArray** pOut);
|
||||
int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut);
|
||||
void destoryCatalogReq(SCatalogReq *pCatalogReq);
|
||||
bool isPrimaryKeyImpl(SNode* pExpr);
|
||||
int32_t insAppendStmtTableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo);
|
||||
|
|
|
@ -58,12 +58,13 @@ extern int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict
|
|||
extern int32_t filterConverNcharColumns(SFilterInfo *pFilterInfo, int32_t rows, bool *gotNchar);
|
||||
extern int32_t filterFreeNcharColumns(SFilterInfo *pFilterInfo);
|
||||
extern void filterFreeInfo(SFilterInfo *info);
|
||||
extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pColsAgg, int32_t numOfCols, int32_t numOfRows);
|
||||
extern int32_t filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows,
|
||||
bool *keep);
|
||||
|
||||
/* condition split interface */
|
||||
int32_t filterPartitionCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode **pTagIndexCond, SNode **pTagCond,
|
||||
SNode **pOtherCond);
|
||||
bool filterIsMultiTableColsCond(SNode *pCond);
|
||||
int32_t filterIsMultiTableColsCond(SNode *pCond, bool *res);
|
||||
EConditionType filterClassifyCondition(SNode *pNode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -59,8 +59,6 @@ extern "C" {
|
|||
#define STREAM_EXEC_T_STOP_ALL_TASKS (-5)
|
||||
#define STREAM_EXEC_T_RESUME_TASK (-6)
|
||||
#define STREAM_EXEC_T_ADD_FAILED_TASK (-7)
|
||||
// the load and start stream task should be executed after snode has started successfully, since the load of stream
|
||||
// tasks may incur the download of checkpoint data from remote, which may consume significant network and CPU resources.
|
||||
|
||||
typedef struct SStreamTask SStreamTask;
|
||||
typedef struct SStreamQueue SStreamQueue;
|
||||
|
@ -190,7 +188,7 @@ typedef struct {
|
|||
SSDataBlock* pBlock;
|
||||
} SStreamRefDataBlock;
|
||||
|
||||
SStreamDataSubmit* streamDataSubmitNew(SPackedData* pData, int32_t type);
|
||||
int32_t streamDataSubmitNew(SPackedData* pData, int32_t type, SStreamDataSubmit** pSubmit);
|
||||
void streamDataSubmitDestroy(SStreamDataSubmit* pDataSubmit);
|
||||
|
||||
typedef struct {
|
||||
|
@ -237,6 +235,8 @@ typedef struct {
|
|||
int64_t stbUid;
|
||||
char stbFullName[TSDB_TABLE_FNAME_LEN];
|
||||
SSchemaWrapper* pSchemaWrapper;
|
||||
SSchemaWrapper* pTagSchema;
|
||||
bool autoCreateCtb;
|
||||
void* vnode; // not available to encoder and decoder
|
||||
FTbSink* tbSinkFunc;
|
||||
STSchema* pTSchema;
|
||||
|
@ -528,8 +528,8 @@ typedef struct STaskUpdateEntry {
|
|||
|
||||
typedef int32_t (*__state_trans_user_fn)(SStreamTask*, void* param);
|
||||
|
||||
SStreamTask* tNewStreamTask(int64_t streamId, int8_t taskLevel, SEpSet* pEpset, bool fillHistory, int64_t triggerParam,
|
||||
SArray* pTaskList, bool hasFillhistory, int8_t subtableWithoutMd5);
|
||||
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);
|
||||
int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||
|
@ -629,8 +629,10 @@ int32_t streamSetupScheduleTrigger(SStreamTask* pTask);
|
|||
int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pMsg);
|
||||
int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, int32_t code);
|
||||
|
||||
SStreamUpstreamEpInfo* streamTaskGetUpstreamTaskEpInfo(SStreamTask* pTask, int32_t taskId);
|
||||
int32_t streamTaskGetUpstreamTaskEpInfo(SStreamTask* pTask, int32_t taskId, SStreamUpstreamEpInfo** pEpInfo);
|
||||
#if 0
|
||||
SEpSet* streamTaskGetDownstreamEpInfo(SStreamTask* pTask, int32_t taskId);
|
||||
#endif
|
||||
|
||||
void streamTaskInputFail(SStreamTask* pTask);
|
||||
|
||||
|
@ -639,8 +641,8 @@ bool streamTaskShouldPause(const SStreamTask* pStatus);
|
|||
bool streamTaskIsIdle(const SStreamTask* pTask);
|
||||
bool streamTaskReadyToRun(const SStreamTask* pTask, char** pStatus);
|
||||
|
||||
char* createStreamTaskIdStr(int64_t streamId, int32_t taskId);
|
||||
SStreamTaskState* streamTaskGetStatus(const SStreamTask* pTask);
|
||||
int32_t createStreamTaskIdStr(int64_t streamId, int32_t taskId, const char** pId);
|
||||
SStreamTaskState streamTaskGetStatus(const SStreamTask* pTask);
|
||||
const char* streamTaskGetStatusStr(ETaskStatus status);
|
||||
void streamTaskResetStatus(SStreamTask* pTask);
|
||||
void streamTaskSetStatusReady(SStreamTask* pTask);
|
||||
|
@ -724,18 +726,18 @@ SScanhistoryDataInfo streamScanHistoryData(SStreamTask* pTask, int64_t st);
|
|||
// stream task meta
|
||||
void streamMetaInit();
|
||||
void streamMetaCleanup();
|
||||
SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskBuild expandFunc, FTaskExpand expandTaskFn,
|
||||
int32_t vgId, int64_t stage, startComplete_fn_t fn);
|
||||
int32_t streamMetaOpen(const char* path, void* ahandle, FTaskBuild expandFunc, FTaskExpand expandTaskFn, int32_t vgId,
|
||||
int64_t stage, startComplete_fn_t fn, SStreamMeta** pMeta);
|
||||
void streamMetaClose(SStreamMeta* streamMeta);
|
||||
int32_t streamMetaSaveTask(SStreamMeta* pMeta, SStreamTask* pTask); // save to stream meta store
|
||||
int32_t streamMetaRemoveTask(SStreamMeta* pMeta, STaskId* pKey);
|
||||
int32_t streamMetaRegisterTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTask, bool* pAdded);
|
||||
int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t taskId);
|
||||
int32_t streamMetaGetNumOfTasks(SStreamMeta* pMeta);
|
||||
SStreamTask* streamMetaAcquireTaskNoLock(SStreamMeta* pMeta, int64_t streamId, int32_t taskId);
|
||||
SStreamTask* streamMetaAcquireTask(SStreamMeta* pMeta, int64_t streamId, int32_t taskId);
|
||||
int32_t streamMetaAcquireTaskNoLock(SStreamMeta* pMeta, int64_t streamId, int32_t taskId, SStreamTask** pTask);
|
||||
int32_t streamMetaAcquireTask(SStreamMeta* pMeta, int64_t streamId, int32_t taskId, SStreamTask** pTask);
|
||||
void streamMetaReleaseTask(SStreamMeta* pMeta, SStreamTask* pTask);
|
||||
SStreamTask* streamMetaAcquireOneTask(SStreamTask* pTask);
|
||||
void streamMetaAcquireOneTask(SStreamTask* pTask);
|
||||
void streamMetaClear(SStreamMeta* pMeta);
|
||||
void streamMetaInitBackend(SStreamMeta* pMeta);
|
||||
int32_t streamMetaCommit(SStreamMeta* pMeta);
|
||||
|
@ -758,7 +760,7 @@ void streamMetaRUnLock(SStreamMeta* pMeta);
|
|||
void streamMetaWLock(SStreamMeta* pMeta);
|
||||
void streamMetaWUnLock(SStreamMeta* pMeta);
|
||||
void streamMetaResetStartInfo(STaskStartInfo* pMeta, int32_t vgId);
|
||||
SArray* streamMetaSendMsgBeforeCloseTasks(SStreamMeta* pMeta);
|
||||
int32_t streamMetaSendMsgBeforeCloseTasks(SStreamMeta* pMeta, SArray** pTaskList);
|
||||
void streamMetaUpdateStageRole(SStreamMeta* pMeta, int64_t stage, bool isLeader);
|
||||
void streamMetaLoadAllTasks(SStreamMeta* pMeta);
|
||||
int32_t streamMetaStartAllTasks(SStreamMeta* pMeta);
|
||||
|
@ -769,6 +771,8 @@ int32_t streamTaskSendRestoreChkptMsg(SStreamTask* pTask);
|
|||
|
||||
// timer
|
||||
tmr_h streamTimerGetInstance();
|
||||
void streamTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* handle, tmr_h* pTmrId, int32_t vgId,
|
||||
const char* pMsg);
|
||||
|
||||
// checkpoint
|
||||
int32_t streamProcessCheckpointSourceReq(SStreamTask* pTask, SStreamCheckpointSourceReq* pReq);
|
||||
|
@ -785,11 +789,11 @@ int32_t streamTaskBuildCheckpointSourceRsp(SStreamCheckpointSourceReq* pReq, SRp
|
|||
int32_t setCode);
|
||||
int32_t streamSendChkptReportMsg(SStreamTask* pTask, SCheckpointInfo* pCheckpointInfo, int8_t dropRelHTask);
|
||||
int32_t streamTaskUpdateTaskCheckpointInfo(SStreamTask* pTask, bool restored, SVUpdateCheckpointInfoReq* pReq);
|
||||
SActiveCheckpointInfo* streamTaskCreateActiveChkptInfo();
|
||||
int32_t streamTaskCreateActiveChkptInfo(SActiveCheckpointInfo** pRes);
|
||||
|
||||
// stream task state machine, and event handling
|
||||
SStreamTaskSM* streamCreateStateMachine(SStreamTask* pTask);
|
||||
void* streamDestroyStateMachine(SStreamTaskSM* pSM);
|
||||
int32_t streamCreateStateMachine(SStreamTask* pTask);
|
||||
void streamDestroyStateMachine(SStreamTaskSM* pSM);
|
||||
int32_t streamTaskHandleEvent(SStreamTaskSM* pSM, EStreamTaskEvent event);
|
||||
int32_t streamTaskHandleEventAsync(SStreamTaskSM* pSM, EStreamTaskEvent event, __state_trans_user_fn callbackFn,
|
||||
void* param);
|
||||
|
@ -803,7 +807,7 @@ int32_t streamTaskBroadcastRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* r
|
|||
void streamTaskSendRetrieveRsp(SStreamRetrieveReq* pReq, SRpcMsg* pRsp);
|
||||
|
||||
int32_t streamProcessHeartbeatRsp(SStreamMeta* pMeta, SMStreamHbRspMsg* pRsp);
|
||||
int32_t streamTaskSendPreparedCheckpointsourceRsp(SStreamTask* pTask);
|
||||
int32_t streamTaskSendCheckpointsourceRsp(SStreamTask* pTask);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -15,28 +15,28 @@
|
|||
#ifndef _TSTREAMUPDATE_H_
|
||||
#define _TSTREAMUPDATE_H_
|
||||
|
||||
#include "storageapi.h"
|
||||
#include "taosdef.h"
|
||||
#include "tarray.h"
|
||||
#include "tcommon.h"
|
||||
#include "tmsg.h"
|
||||
#include "storageapi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SUpdateInfo *updateInfoInitP(SInterval *pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen);
|
||||
SUpdateInfo *updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen);
|
||||
int32_t updateInfoInitP(SInterval* pInterval, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen, SUpdateInfo** ppInfo);
|
||||
int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType, int32_t pkLen, SUpdateInfo** ppInfo);
|
||||
TSKEY updateInfoFillBlockData(SUpdateInfo* pInfo, SSDataBlock* pBlock, int32_t primaryTsCol, int32_t primaryKeyCol);
|
||||
bool updateInfoIsUpdated(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
||||
bool updateInfoIsTableInserted(SUpdateInfo* pInfo, int64_t tbUid);
|
||||
void updateInfoDestroy(SUpdateInfo* pInfo);
|
||||
void updateInfoAddCloseWindowSBF(SUpdateInfo* pInfo);
|
||||
void updateInfoDestoryColseWinSBF(SUpdateInfo* pInfo);
|
||||
int32_t updateInfoSerialize(void *buf, int32_t bufLen, const SUpdateInfo *pInfo);
|
||||
int32_t updateInfoSerialize(void* buf, int32_t bufLen, const SUpdateInfo* pInfo, int32_t* pLen);
|
||||
int32_t updateInfoDeserialize(void* buf, int32_t bufLen, SUpdateInfo* pInfo);
|
||||
void windowSBfDelete(SUpdateInfo* pInfo, uint64_t count);
|
||||
void windowSBfAdd(SUpdateInfo *pInfo, uint64_t count);
|
||||
int32_t windowSBfAdd(SUpdateInfo* pInfo, uint64_t count);
|
||||
bool isIncrementalTimeStamp(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts, void* pPkVal, int32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -220,7 +220,7 @@ void syslog(int unused, const char *format, ...);
|
|||
// Linux, length of name must <= 16 (the last '\0' included)
|
||||
#define setThreadName(name) \
|
||||
do { \
|
||||
prctl(PR_SET_NAME, (name)); \
|
||||
(void)prctl(PR_SET_NAME, (name)); \
|
||||
} while (0)
|
||||
#define getThreadName(name) \
|
||||
do { \
|
||||
|
|
|
@ -32,9 +32,9 @@ extern "C" {
|
|||
#define TSWAP(a, b) \
|
||||
do { \
|
||||
char *__tmp = (char*)alloca(sizeof(a)); \
|
||||
memcpy(__tmp, &(a), sizeof(a)); \
|
||||
memcpy(&(a), &(b), sizeof(a)); \
|
||||
memcpy(&(b), __tmp, sizeof(a)); \
|
||||
(void)memcpy(__tmp, &(a), sizeof(a)); \
|
||||
(void)memcpy(&(a), &(b), sizeof(a)); \
|
||||
(void)memcpy(&(b), __tmp, sizeof(a)); \
|
||||
} while (0)
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
|
|
@ -54,6 +54,8 @@ void taosMemoryTrim(int32_t size);
|
|||
void *taosMemoryMallocAlign(uint32_t alignment, int64_t size);
|
||||
|
||||
#define TAOS_MEMSET(_s, _c, _n) ((void)memset(_s, _c, _n))
|
||||
#define TAOS_MEMCPY(_d, _s, _n) ((void)memcpy(_d, _s, _n))
|
||||
#define TAOS_MEMMOVE(_d, _s, _n) ((void)memmove(_d, _s, _n))
|
||||
|
||||
#define taosMemoryFreeClear(ptr) \
|
||||
do { \
|
||||
|
|
|
@ -55,11 +55,12 @@ typedef enum { M2C = 0, C2M } ConvType;
|
|||
|
||||
#define tstrncpy(dst, src, size) \
|
||||
do { \
|
||||
strncpy((dst), (src), (size)); \
|
||||
(void)strncpy((dst), (src), (size)); \
|
||||
(dst)[(size)-1] = 0; \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_STRCPY(_dst, _src) ((void)strcpy(_dst, _src))
|
||||
#define TAOS_STRNCPY(_dst, _src, _size) ((void)strncpy(_dst, _src, _size))
|
||||
|
||||
char *tstrdup(const char *src);
|
||||
int32_t taosUcs4len(TdUcs4 *ucs4);
|
||||
|
|
|
@ -224,6 +224,7 @@ int32_t taosGetErrSize();
|
|||
// #define TSDB_CODE_MND_FAILED_TO_INIT_STEP TAOS_DEF_ERROR_CODE(0, 0x0314) // 2.x
|
||||
#define TSDB_CODE_MND_USER_DISABLED TAOS_DEF_ERROR_CODE(0, 0x0315)
|
||||
#define TSDB_CODE_MND_INVALID_PLATFORM TAOS_DEF_ERROR_CODE(0, 0x0316)
|
||||
#define TSDB_CODE_MND_RETURN_VALUE_NULL TAOS_DEF_ERROR_CODE(0, 0x0317)
|
||||
|
||||
// mnode-sdb
|
||||
#define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0320) // internal
|
||||
|
@ -596,6 +597,7 @@ int32_t taosGetErrSize();
|
|||
#define TSDB_CODE_QRY_GEO_NOT_SUPPORT_ERROR TAOS_DEF_ERROR_CODE(0, 0x0731)
|
||||
#define TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0732)
|
||||
#define TSDB_CODE_QRY_INVALID_JOIN_CONDITION TAOS_DEF_ERROR_CODE(0, 0x0733)
|
||||
#define TSDB_CODE_QRY_FILTER_NOT_SUPPORT_TYPE TAOS_DEF_ERROR_CODE(0, 0x0734)
|
||||
|
||||
// grant
|
||||
#define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800)
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "os.h"
|
||||
#include "tencode.h"
|
||||
#include "thash.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -39,7 +41,7 @@ typedef struct SBloomFilter {
|
|||
double errorRate;
|
||||
} SBloomFilter;
|
||||
|
||||
SBloomFilter *tBloomFilterInit(uint64_t expectedEntries, double errorRate);
|
||||
int32_t tBloomFilterInit(uint64_t expectedEntries, double errorRate, SBloomFilter** ppBF);
|
||||
int32_t tBloomFilterPutHash(SBloomFilter* pBF, uint64_t hash1, uint64_t hash2);
|
||||
int32_t tBloomFilterPut(SBloomFilter* pBF, const void* keyBuf, uint32_t len);
|
||||
int32_t tBloomFilterNoContain(const SBloomFilter* pBF, uint64_t h1, uint64_t h2);
|
||||
|
@ -47,7 +49,7 @@ void tBloomFilterDestroy(SBloomFilter *pBF);
|
|||
void tBloomFilterDump(const SBloomFilter* pBF);
|
||||
bool tBloomFilterIsFull(const SBloomFilter* pBF);
|
||||
int32_t tBloomFilterEncode(const SBloomFilter* pBF, SEncoder* pEncoder);
|
||||
SBloomFilter *tBloomFilterDecode(SDecoder *pDecoder);
|
||||
int32_t tBloomFilterDecode(SDecoder* pDecoder, SBloomFilter** ppBF);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "taoserror.h"
|
||||
#include "tcoding.h"
|
||||
#include "tutil.h"
|
||||
|
||||
struct SBuffer {
|
||||
uint32_t size;
|
||||
|
@ -67,8 +68,7 @@ static FORCE_INLINE int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capa
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPut(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferEnsureCapacity(buffer, buffer->size + size));
|
||||
memcpy((char *)buffer->data + buffer->size, data, size);
|
||||
buffer->size += size;
|
||||
return 0;
|
||||
|
@ -119,10 +119,8 @@ static FORCE_INLINE int32_t tBufferPutU16v(SBuffer *buffer, uint16_t value) { re
|
|||
static FORCE_INLINE int32_t tBufferPutU32v(SBuffer *buffer, uint32_t value) { return tBufferPutU64v(buffer, value); }
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPutU64v(SBuffer *buffer, uint64_t value) {
|
||||
int32_t code;
|
||||
while (value >= 0x80) {
|
||||
code = tBufferPutU8(buffer, (value & 0x7F) | 0x80);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutU8(buffer, (value & 0x7F) | 0x80));
|
||||
value >>= 7;
|
||||
}
|
||||
return tBufferPutU8(buffer, value);
|
||||
|
@ -141,8 +139,7 @@ static FORCE_INLINE int32_t tBufferPutI64v(SBuffer *buffer, int64_t value) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPutBinary(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferPutU32v(buffer, size);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutU32v(buffer, size));
|
||||
return tBufferPut(buffer, data, size);
|
||||
}
|
||||
|
||||
|
@ -324,8 +321,7 @@ static int32_t tBufferGetF32(SBufferReader *reader, float *value) {
|
|||
float f;
|
||||
uint32_t u;
|
||||
} u;
|
||||
int32_t code = tBufferGetU32(reader, &u.u);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetU32(reader, &u.u));
|
||||
if (value) {
|
||||
*value = u.f;
|
||||
}
|
||||
|
@ -337,8 +333,7 @@ static int32_t tBufferGetF64(SBufferReader *reader, double *value) {
|
|||
double f;
|
||||
uint64_t u;
|
||||
} u;
|
||||
int32_t code = tBufferGetU64(reader, &u.u);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetU64(reader, &u.u));
|
||||
if (value) {
|
||||
*value = u.f;
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ typedef int32_t (*_equal_fn_t)(const void *, const void *, size_t len);
|
|||
typedef void (*_hash_before_fn_t)(void *);
|
||||
typedef void (*_hash_free_fn_t)(void *);
|
||||
|
||||
#define HASH_KEY_ALREADY_EXISTS (-2)
|
||||
#define HASH_NODE_EXIST(code) (code == HASH_KEY_ALREADY_EXISTS)
|
||||
#define HASH_NODE_EXIST(code) (code == TSDB_CODE_DUP_KEY)
|
||||
|
||||
/**
|
||||
* murmur hash algorithm
|
||||
|
|
|
@ -73,10 +73,10 @@ struct STaosQnode {
|
|||
char item[];
|
||||
};
|
||||
|
||||
STaosQueue *taosOpenQueue();
|
||||
int32_t taosOpenQueue(STaosQueue **queue);
|
||||
void taosCloseQueue(STaosQueue *queue);
|
||||
void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp);
|
||||
void *taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize);
|
||||
int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void **item);
|
||||
void taosFreeQitem(void *pItem);
|
||||
int32_t taosWriteQitem(STaosQueue *queue, void *pItem);
|
||||
int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
|
||||
|
@ -87,7 +87,7 @@ int64_t taosQueueMemorySize(STaosQueue *queue);
|
|||
void taosSetQueueCapacity(STaosQueue *queue, int64_t size);
|
||||
void taosSetQueueMemoryCapacity(STaosQueue *queue, int64_t mem);
|
||||
|
||||
STaosQall *taosAllocateQall();
|
||||
int32_t taosAllocateQall(STaosQall **qall);
|
||||
void taosFreeQall(STaosQall *qall);
|
||||
int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall);
|
||||
int32_t taosGetQitem(STaosQall *qall, void **ppItem);
|
||||
|
@ -97,7 +97,7 @@ int64_t taosQallMemSize(STaosQall *qll);
|
|||
int64_t taosQallUnAccessedItemSize(STaosQall *qall);
|
||||
int64_t taosQallUnAccessedMemSize(STaosQall *qall);
|
||||
|
||||
STaosQset *taosOpenQset();
|
||||
int32_t taosOpenQset(STaosQset **qset);
|
||||
void taosCloseQset(STaosQset *qset);
|
||||
void taosQsetThreadResume(STaosQset *qset);
|
||||
int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle);
|
||||
|
|
|
@ -32,13 +32,13 @@ typedef struct SScalableBf {
|
|||
_hash_fn_t hashFn2;
|
||||
} SScalableBf;
|
||||
|
||||
SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate);
|
||||
int32_t tScalableBfInit(uint64_t expectedEntries, double errorRate, SScalableBf** ppSBf);
|
||||
int32_t tScalableBfPutNoCheck(SScalableBf* pSBf, const void* keyBuf, uint32_t len);
|
||||
int32_t tScalableBfPut(SScalableBf* pSBf, const void* keyBuf, uint32_t len);
|
||||
int32_t tScalableBfNoContain(const SScalableBf* pSBf, const void* keyBuf, uint32_t len);
|
||||
void tScalableBfDestroy(SScalableBf* pSBf);
|
||||
int32_t tScalableBfEncode(const SScalableBf* pSBf, SEncoder* pEncoder);
|
||||
SScalableBf *tScalableBfDecode(SDecoder *pDecoder);
|
||||
int32_t tScalableBfDecode(SDecoder* pDecoder, SScalableBf** ppSBf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "tdef.h"
|
||||
#include "thash.h"
|
||||
#include "tmd5.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -171,6 +172,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_UNUSED(expr) (void)(expr)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -8,6 +8,7 @@ if command -v sudo > /dev/null; then
|
|||
csudo="sudo "
|
||||
fi
|
||||
|
||||
${csudo}mkdir -p ${insmetaPath}
|
||||
${csudo}chmod -R 744 ${insmetaPath}
|
||||
cd ${insmetaPath}
|
||||
${csudo}./post.sh
|
||||
|
|
|
@ -33,6 +33,7 @@ else
|
|||
${csudo}rm -f ${bin_link_dir}/taosadapter || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosdemo || :
|
||||
${csudo}rm -f ${bin_link_dir}/taoskeeper || :
|
||||
${csudo}rm -f ${bin_link_dir}/taos-explorer || :
|
||||
${csudo}rm -f ${cfg_link_dir}/* || :
|
||||
${csudo}rm -f ${inc_link_dir}/taos.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosdef.h || :
|
||||
|
|
|
@ -76,11 +76,11 @@ if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then
|
|||
cp ${compile_dir}/test/cfg/taosadapter.service ${pkg_dir}${install_home_path}/cfg || :
|
||||
fi
|
||||
|
||||
if [ -f "%{_compiledir}/../../../explorer/target/taos-explorer.service" ]; then
|
||||
cp %{_compiledir}/../../../explorer/target/taos-explorer.service ${pkg_dir}${install_home_path}/cfg || :
|
||||
if [ -f "${compile_dir}/../../../explorer/target/taos-explorer.service" ]; then
|
||||
cp ${compile_dir}/../../../explorer/target/taos-explorer.service ${pkg_dir}${install_home_path}/cfg || :
|
||||
fi
|
||||
if [ -f "%{_compiledir}/../../../explorer/server/example/explorer.toml" ]; then
|
||||
cp %{_compiledir}/../../../explorer/server/example/explorer.toml ${pkg_dir}${install_home_path}/cfg || :
|
||||
if [ -f "${compile_dir}/../../../explorer/server/example/explorer.toml" ]; then
|
||||
cp ${compile_dir}/../../../explorer/server/example/explorer.toml ${pkg_dir}${install_home_path}/cfg || :
|
||||
fi
|
||||
|
||||
cp ${taoskeeper_binary} ${pkg_dir}${install_home_path}/bin
|
||||
|
@ -90,6 +90,11 @@ cp ${compile_dir}/../packaging/tools/preun.sh ${pkg_dir}${install_home_pat
|
|||
cp ${compile_dir}/../packaging/tools/startPre.sh ${pkg_dir}${install_home_path}/bin
|
||||
cp ${compile_dir}/../packaging/tools/set_core.sh ${pkg_dir}${install_home_path}/bin
|
||||
cp ${compile_dir}/../packaging/tools/taosd-dump-cfg.gdb ${pkg_dir}${install_home_path}/bin
|
||||
cp ${top_dir}/../enterprise/packaging/start-all.sh ${pkg_dir}${install_home_path}/bin
|
||||
cp ${top_dir}/../enterprise/packaging/stop-all.sh ${pkg_dir}${install_home_path}/bin
|
||||
sed -i "s/versionType=\"enterprise\"/versionType=\"community\"/g" ${pkg_dir}${install_home_path}/bin/start-all.sh
|
||||
sed -i "s/versionType=\"enterprise\"/versionType=\"community\"/g" ${pkg_dir}${install_home_path}/bin/stop-all.sh
|
||||
|
||||
|
||||
cp ${compile_dir}/build/bin/taosd ${pkg_dir}${install_home_path}/bin
|
||||
cp ${compile_dir}/build/bin/udfd ${pkg_dir}${install_home_path}/bin
|
||||
|
|
|
@ -70,8 +70,8 @@ else
|
|||
fi
|
||||
|
||||
cd ${top_dir}
|
||||
echo "${top_dir}/../enterprise/packaging/build_taoskeeper.sh -r ${arch} -e taoskeeper"
|
||||
taoskeeper_binary=`${top_dir}/../enterprise/packaging/build_taoskeeper.sh -r $arch -e taoskeeper`
|
||||
echo "${top_dir}/../enterprise/packaging/build_taoskeeper.sh -r ${arch} -e taoskeeper -t ver-${tdengine_ver}"
|
||||
taoskeeper_binary=`${top_dir}/../enterprise/packaging/build_taoskeeper.sh -r $arch -e taoskeeper -t ver-${tdengine_ver}`
|
||||
echo "taoskeeper_binary: ${taoskeeper_binary}"
|
||||
cd ${package_dir}
|
||||
|
||||
|
|
|
@ -56,6 +56,10 @@ mkdir -p %{buildroot}%{homepath}/include
|
|||
#mkdir -p %{buildroot}%{homepath}/init.d
|
||||
mkdir -p %{buildroot}%{homepath}/script
|
||||
|
||||
if [ -f %{_compiledir}/../packaging/cfg/taosd.service ]; then
|
||||
cp %{_compiledir}/../packaging/cfg/taosd.service %{buildroot}%{homepath}/cfg
|
||||
fi
|
||||
|
||||
cp %{_compiledir}/../packaging/cfg/taos.cfg %{buildroot}%{homepath}/cfg
|
||||
if [ -f %{_compiledir}/test/cfg/taosadapter.toml ]; then
|
||||
cp %{_compiledir}/test/cfg/taosadapter.toml %{buildroot}%{homepath}/cfg
|
||||
|
@ -91,6 +95,10 @@ cp %{_compiledir}/build/bin/taosd %{buildroot}%{homepath}/bin
|
|||
cp %{_compiledir}/build/bin/udfd %{buildroot}%{homepath}/bin
|
||||
cp %{_compiledir}/build/bin/taosBenchmark %{buildroot}%{homepath}/bin
|
||||
cp %{_compiledir}/build/bin/taosdump %{buildroot}%{homepath}/bin
|
||||
cp %{_compiledir}/../../enterprise/packaging/start-all.sh %{buildroot}%{homepath}/bin
|
||||
cp %{_compiledir}/../../enterprise/packaging/stop-all.sh %{buildroot}%{homepath}/bin
|
||||
sed -i "s/versionType=\"enterprise\"/versionType=\"community\"/g" %{buildroot}%{homepath}/bin/start-all.sh
|
||||
sed -i "s/versionType=\"enterprise\"/versionType=\"community\"/g" %{buildroot}%{homepath}/bin/stop-all.sh
|
||||
|
||||
if [ -f %{_compiledir}/../../../explorer/target/release/taos-explorer ]; then
|
||||
cp %{_compiledir}/../../../explorer/target/release/taos-explorer %{buildroot}%{homepath}/bin
|
||||
|
|
|
@ -156,7 +156,7 @@ done
|
|||
|
||||
#echo "verType=${verType} interactiveFqdn=${interactiveFqdn}"
|
||||
|
||||
tools=(${clientName} ${benchmarkName} ${dumpName} ${demoName} remove.sh udfd set_core.sh TDinsight.sh start_pre.sh)
|
||||
tools=(${clientName} ${benchmarkName} ${dumpName} ${demoName} remove.sh udfd set_core.sh TDinsight.sh start_pre.sh start-all.sh stop-all.sh)
|
||||
if [ "${verMode}" == "cluster" ]; then
|
||||
services=(${serverName} ${adapterName} ${xname} ${explorerName} ${keeperName})
|
||||
elif [ "${verMode}" == "edge" ]; then
|
||||
|
@ -221,6 +221,8 @@ function install_bin() {
|
|||
${csudo}cp -r ${script_dir}/bin/remove.sh ${install_main_dir}/bin
|
||||
else
|
||||
${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin
|
||||
${csudo}cp ${script_dir}/start-all.sh ${install_main_dir}/bin
|
||||
${csudo}cp ${script_dir}/stop-all.sh ${install_main_dir}/bin
|
||||
fi
|
||||
|
||||
if [[ "${verMode}" == "cluster" && "${verType}" != "client" ]]; then
|
||||
|
@ -576,7 +578,9 @@ function install_taosd_config() {
|
|||
${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$serverFqdn/" ${script_dir}/cfg/${configFile}
|
||||
${csudo}echo "monitor 1" >>${script_dir}/cfg/${configFile}
|
||||
${csudo}echo "monitorFQDN ${serverFqdn}" >>${script_dir}/cfg/${configFile}
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
${csudo}echo "audit 1" >>${script_dir}/cfg/${configFile}
|
||||
fi
|
||||
|
||||
if [ -f "${configDir}/${configFile}" ]; then
|
||||
${csudo}cp ${fileName} ${configDir}/${configFile}.new
|
||||
|
@ -594,6 +598,7 @@ function install_config() {
|
|||
[ ! -z $1 ] && return 0 || : # only install client
|
||||
|
||||
if ((${update_flag} == 1)); then
|
||||
install_taosd_config
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
@ -652,8 +657,6 @@ function install_data() {
|
|||
function install_connector() {
|
||||
if [ -d "${script_dir}/connector/" ]; then
|
||||
${csudo}cp -rf ${script_dir}/connector/ ${install_main_dir}/ || echo "failed to copy connector"
|
||||
${csudo}cp ${script_dir}/start-all.sh ${install_main_dir}/ || echo "failed to copy start-all.sh"
|
||||
${csudo}cp ${script_dir}/stop-all.sh ${install_main_dir}/ || echo "failed to copy stop-all.sh"
|
||||
${csudo}cp ${script_dir}/README.md ${install_main_dir}/ || echo "failed to copy README.md"
|
||||
fi
|
||||
}
|
||||
|
@ -911,38 +914,35 @@ function updateProduct() {
|
|||
echo -e "${GREEN_DARK}To configure ${productName} ${NC}\t\t: edit ${configDir}/${configFile}"
|
||||
[ -f ${configDir}/${adapterName}.toml ] && [ -f ${installDir}/bin/${adapterName} ] &&
|
||||
echo -e "${GREEN_DARK}To configure ${adapterName} ${NC}\t: edit ${configDir}/${adapterName}.toml"
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
echo -e "${GREEN_DARK}To configure ${explorerName} ${NC}\t: edit ${configDir}/explorer.toml"
|
||||
fi
|
||||
if ((${service_mod} == 0)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}\t\t: ${csudo}systemctl start ${serverName}${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} server ${NC}\t: ${csudo}systemctl start ${serverName}${NC}"
|
||||
[ -f ${service_config_dir}/${clientName}adapter.service ] && [ -f ${installDir}/bin/${clientName}adapter ] &&
|
||||
echo -e "${GREEN_DARK}To start ${clientName}Adapter ${NC}\t\t: ${csudo}systemctl start ${clientName}adapter ${NC}"
|
||||
elif ((${service_mod} == 1)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}\t\t: ${csudo}service ${serverName} start${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} server ${NC}\t: ${csudo}service ${serverName} start${NC}"
|
||||
[ -f ${service_config_dir}/${clientName}adapter.service ] && [ -f ${installDir}/bin/${clientName}adapter ] &&
|
||||
echo -e "${GREEN_DARK}To start ${clientName}Adapter ${NC}\t\t: ${csudo}service ${clientName}adapter start${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}\t\t: ./${serverName}${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} server ${NC}\t: ./${serverName}${NC}"
|
||||
[ -f ${installDir}/bin/${clientName}adapter ] &&
|
||||
echo -e "${GREEN_DARK}To start ${clientName}Adapter ${NC}\t\t: ${clientName}adapter ${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN_DARK}To enable ${clientName}keeper ${NC}\t\t: sudo systemctl enable ${clientName}keeper ${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${clientName}keeper ${NC}\t\t: sudo systemctl start ${clientName}keeper ${NC}"
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
echo -e "${GREEN_DARK}To start ${clientName}x ${NC}\t\t\t: sudo systemctl start ${clientName}x ${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${clientName}-explorer ${NC}\t\t: sudo systemctl start ${clientName}-explorer ${NC}"
|
||||
fi
|
||||
echo -e "${GREEN_DARK}To start ${clientName}-explorer ${NC}\t\t: sudo systemctl start ${clientName}-explorer ${NC}"
|
||||
|
||||
echo
|
||||
echo "${productName} is updated successfully!"
|
||||
echo
|
||||
|
||||
echo -e "\033[44;32;1mTo start all the components : sudo start-all.sh${NC}"
|
||||
echo -e "\033[44;32;1mTo access ${productName} Commnd Line Interface : ${clientName} -h $serverFqdn${NC}"
|
||||
echo -e "\033[44;32;1mTo access ${productName} Graphic User Interface : http://$serverFqdn:6060${NC}"
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
echo -e "\033[44;32;1mTo start all the components : ./start-all.sh${NC}"
|
||||
fi
|
||||
echo -e "\033[44;32;1mTo access ${productName} : ${clientName} -h $serverFqdn${NC}"
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
echo -e "\033[44;32;1mTo access the management system : http://$serverFqdn:6060${NC}"
|
||||
echo -e "\033[44;32;1mTo read the user manual : http://$serverFqdn:6060/docs${NC}"
|
||||
fi
|
||||
else
|
||||
|
@ -1007,39 +1007,36 @@ function installProduct() {
|
|||
echo -e "${GREEN_DARK}To configure ${productName} ${NC}\t\t: edit ${configDir}/${configFile}"
|
||||
[ -f ${configDir}/${clientName}adapter.toml ] && [ -f ${installDir}/bin/${clientName}adapter ] &&
|
||||
echo -e "${GREEN_DARK}To configure ${clientName}Adapter ${NC}\t: edit ${configDir}/${clientName}adapter.toml"
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
echo -e "${GREEN_DARK}To configure ${clientName}-explorer ${NC}\t: edit ${configDir}/explorer.toml"
|
||||
fi
|
||||
if ((${service_mod} == 0)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}\t\t: ${csudo}systemctl start ${serverName}${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} server ${NC}\t: ${csudo}systemctl start ${serverName}${NC}"
|
||||
[ -f ${service_config_dir}/${clientName}adapter.service ] && [ -f ${installDir}/bin/${clientName}adapter ] &&
|
||||
echo -e "${GREEN_DARK}To start ${clientName}Adapter ${NC}\t\t: ${csudo}systemctl start ${clientName}adapter ${NC}"
|
||||
elif ((${service_mod} == 1)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}\t\t: ${csudo}service ${serverName} start${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} server ${NC}\t: ${csudo}service ${serverName} start${NC}"
|
||||
[ -f ${service_config_dir}/${clientName}adapter.service ] && [ -f ${installDir}/bin/${clientName}adapter ] &&
|
||||
echo -e "${GREEN_DARK}To start ${clientName}Adapter ${NC}\t\t: ${csudo}service ${clientName}adapter start${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}\t\t: ${serverName}${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} server ${NC}\t: ${serverName}${NC}"
|
||||
[ -f ${installDir}/bin/${clientName}adapter ] &&
|
||||
echo -e "${GREEN_DARK}To start ${clientName}Adapter ${NC}\t\t: ${clientName}adapter ${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN_DARK}To enable ${clientName}keeper ${NC}\t\t: sudo systemctl enable ${clientName}keeper ${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${clientName}keeper ${NC}\t\t: sudo systemctl start ${clientName}keeper ${NC}"
|
||||
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
echo -e "${GREEN_DARK}To start ${clientName}x ${NC}\t\t\t: sudo systemctl start ${clientName}x ${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${clientName}-explorer ${NC}\t\t: sudo systemctl start ${clientName}-explorer ${NC}"
|
||||
fi
|
||||
echo -e "${GREEN_DARK}To start ${clientName}-explorer ${NC}\t\t: sudo systemctl start ${clientName}-explorer ${NC}"
|
||||
|
||||
echo
|
||||
echo "${productName} is installed successfully!"
|
||||
echo
|
||||
|
||||
echo -e "\033[44;32;1mTo start all the components : sudo start-all.sh${NC}"
|
||||
echo -e "\033[44;32;1mTo access ${productName} Commnd Line Interface : ${clientName} -h $serverFqdn${NC}"
|
||||
echo -e "\033[44;32;1mTo access ${productName} Graphic User Interface : http://$serverFqdn:6060${NC}"
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
echo -e "\033[44;32;1mTo start all the components : sudo ./start-all.sh${NC}"
|
||||
fi
|
||||
echo -e "\033[44;32;1mTo access ${productName} : ${clientName} -h $serverFqdn${NC}"
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
echo -e "\033[44;32;1mTo access the management system : http://$serverFqdn:6060${NC}"
|
||||
echo -e "\033[44;32;1mTo read the user manual : http://$serverFqdn:6060/docs-en${NC}"
|
||||
fi
|
||||
echo
|
||||
|
|
|
@ -232,7 +232,7 @@ fi
|
|||
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
sed 's/verMode=edge/verMode=cluster/g' ${install_dir}/bin/remove.sh >>remove_temp.sh
|
||||
sed -i "s/PREFIX=\"taos\"/PREFIX=\"${serverName2}\"/g" remove_temp.sh
|
||||
sed -i "s/PREFIX=\"taos\"/PREFIX=\"${clientName2}\"/g" remove_temp.sh
|
||||
sed -i "s/productName=\"TDengine\"/productName=\"${productName2}\"/g" remove_temp.sh
|
||||
mv remove_temp.sh ${install_dir}/bin/remove.sh
|
||||
fi
|
||||
|
|
|
@ -104,6 +104,8 @@ fi
|
|||
|
||||
function log_print(){
|
||||
now=$(date +"%D %T")
|
||||
${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
|
||||
${csudo} touch ${install_log_path}
|
||||
echo "$now $1" >> ${install_log_path}
|
||||
}
|
||||
|
||||
|
@ -235,11 +237,14 @@ function install_bin() {
|
|||
${csudo}rm -f ${bin_link_dir}/taosadapter || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosBenchmark || :
|
||||
${csudo}rm -f ${bin_link_dir}/taoskeeper || :
|
||||
${csudo}rm -f ${bin_link_dir}/taos-explorer || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosdemo || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosdump || :
|
||||
${csudo}rm -f ${bin_link_dir}/rmtaos || :
|
||||
${csudo}rm -f ${bin_link_dir}/set_core || :
|
||||
${csudo}rm -f ${bin_link_dir}/*explorer || :
|
||||
${csudo}rm -f ${bin_link_dir}/start-all.sh || :
|
||||
${csudo}rm -f ${bin_link_dir}/stop-all.sh || :
|
||||
|
||||
${csudo}chmod 0555 ${bin_dir}/*
|
||||
|
||||
|
@ -275,8 +280,14 @@ function install_bin() {
|
|||
if [ -x ${bin_dir}/taoskeeper ]; then
|
||||
${csudo}ln -sf ${bin_dir}/taoskeeper ${bin_link_dir}/taoskeeper 2>>${install_log_path} || return 1
|
||||
fi
|
||||
if [ -x ${bin_dir}/*explorer ]; then
|
||||
${csudo}ln -s ${bin_dir}/*explorer ${bin_link_dir}/*explorer 2>>${install_log_path} || return 1
|
||||
if [ -x ${bin_dir}/taos-explorer ]; then
|
||||
${csudo}ln -s ${bin_dir}/taos-explorer ${bin_link_dir}/taos-explorer 2>>${install_log_path} || return 1
|
||||
fi
|
||||
if [ -x ${bin_dir}/start-all.sh ]; then
|
||||
${csudo}ln -s ${bin_dir}/start-all.sh ${bin_link_dir}/start-all.sh 2>>${install_log_path} || return 1
|
||||
fi
|
||||
if [ -x ${bin_dir}/stop-all.sh ]; then
|
||||
${csudo}ln -s ${bin_dir}/stop-all.sh ${bin_link_dir}/stop-all.sh 2>>${install_log_path} || return 1
|
||||
fi
|
||||
log_print "install bin success"
|
||||
}
|
||||
|
@ -474,6 +485,22 @@ function install_taoskeeper_config() {
|
|||
${csudo}ln -s ${cfg_install_dir}/taoskeeper.toml ${cfg_dir}
|
||||
}
|
||||
|
||||
function install_taos-explorer_config() {
|
||||
if [ ! -f "${cfg_install_dir}/explorer.toml" ]; then
|
||||
[ ! -d ${cfg_install_dir} ] &&
|
||||
${csudo}${csudo}mkdir -p ${cfg_install_dir}
|
||||
[ -f ${cfg_dir}/explorer.toml ] && ${csudo}cp ${cfg_dir}/explorer.toml ${cfg_install_dir}
|
||||
[ -f ${cfg_install_dir}/explorer.toml ] &&
|
||||
${csudo}chmod 644 ${cfg_install_dir}/explorer.toml
|
||||
fi
|
||||
|
||||
[ -f ${cfg_dir}/explorer.toml ] &&
|
||||
${csudo}mv ${cfg_dir}/explorer.toml ${cfg_dir}/explorer.toml.new
|
||||
|
||||
[ -f ${cfg_install_dir}/explorer.toml ] &&
|
||||
${csudo}ln -s ${cfg_install_dir}/explorer.toml ${cfg_dir}
|
||||
}
|
||||
|
||||
function install_config() {
|
||||
log_print "start install config from ${cfg_dir} to ${cfg_install_dir}"
|
||||
if [ ! -f "${cfg_install_dir}/taos.cfg" ]; then
|
||||
|
@ -610,29 +637,11 @@ function clean_service_on_systemd() {
|
|||
function install_service_on_systemd() {
|
||||
clean_service_on_systemd
|
||||
|
||||
taosd_service_config="${service_config_dir}/taosd.service"
|
||||
[ -f ${script_dir}/../cfg/taosd.service ] &&\
|
||||
${csudo}cp ${script_dir}/../cfg/taosd.service \
|
||||
${service_config_dir}/ || :
|
||||
|
||||
${csudo}bash -c "echo '[Unit]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'After=network-online.target' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Wants=network-online.target' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo '[Service]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Type=simple' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Restart=always' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo '[Install]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}"
|
||||
${csudo}systemctl daemon-reload
|
||||
${csudo}systemctl enable taosd
|
||||
}
|
||||
|
||||
|
@ -652,6 +661,11 @@ function install_service_on_launchctl() {
|
|||
${csudo}cp ${install_main_dir}/service/com.taosdata.taoskeeper.plist /Library/LaunchDaemons/com.taosdata.taoskeeper.plist || :
|
||||
${csudo}launchctl load -w /Library/LaunchDaemons/com.taosdata.taoskeeper.plist || :
|
||||
fi
|
||||
if [ -f ${install_main_dir}/service/com.taosdata.taos-explorer.plist ]; then
|
||||
${csudo}launchctl unload -w /Library/LaunchDaemons/com.taosdata.taos-explorer.plist > /dev/null 2>&1 || :
|
||||
${csudo}cp ${install_main_dir}/service/com.taosdata.taos-explorer.plist /Library/LaunchDaemons/com.taosdata.taos-explorer.plist || :
|
||||
${csudo}launchctl load -w /Library/LaunchDaemons/com.taosdata.taos-explorer.plist || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_taosadapter_service() {
|
||||
|
@ -672,6 +686,15 @@ function install_taoskeeper_service() {
|
|||
fi
|
||||
}
|
||||
|
||||
function install_taos-explorer_service() {
|
||||
if ((${service_mod}==0)); then
|
||||
[ -f ${script_dir}/../cfg/taos-explorer.service ] &&\
|
||||
${csudo}cp ${script_dir}/../cfg/taos-explorer.service \
|
||||
${service_config_dir}/ || :
|
||||
${csudo}systemctl daemon-reload
|
||||
fi
|
||||
}
|
||||
|
||||
function install_service() {
|
||||
log_print "start install service"
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
|
@ -748,8 +771,10 @@ function install_TDengine() {
|
|||
install_config
|
||||
install_taosadapter_config
|
||||
install_taoskeeper_config
|
||||
install_taos-explorer_config
|
||||
install_taosadapter_service
|
||||
install_taoskeeper_service
|
||||
install_taos-explorer_service
|
||||
install_service
|
||||
install_app
|
||||
|
||||
|
@ -757,40 +782,38 @@ function install_TDengine() {
|
|||
#echo
|
||||
#echo -e "\033[44;32;1mTDengine is installed successfully!${NC}"
|
||||
echo
|
||||
echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg"
|
||||
echo -e "${GREEN_DARK}To configure TDengine ${NC}\t: edit /etc/taos/taos.cfg"
|
||||
echo -e "${GREEN_DARK}To configure taosAdapter ${NC}\t: edit /etc/taos/taosadapter.toml"
|
||||
echo -e "${GREEN_DARK}To configure taos-explorer ${NC}\t: edit /etc/taos/explorer.toml"
|
||||
if ((${service_mod}==0)); then
|
||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}systemctl start taosd${NC}"
|
||||
echo -e "${GREEN_DARK}To start TDengine server ${NC}\t: ${csudo}systemctl start taosd${NC}"
|
||||
echo -e "${GREEN_DARK}To start taosAdapter ${NC}\t: ${csudo}systemctl start taosadapter${NC}"
|
||||
echo -e "${GREEN_DARK}To start taoskeeper ${NC}\t: ${csudo}systemctl start taoskeeper${NC}"
|
||||
echo -e "${GREEN_DARK}To start taos-explorer ${NC}\t: ${csudo}systemctl start taos-explorer${NC}"
|
||||
elif ((${service_mod}==1)); then
|
||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo}update-rc.d taosd default ${RED} for the first time${NC}"
|
||||
echo -e "${GREEN_DARK}To start TDengine server ${NC}\t: ${csudo}update-rc.d taosd default ${RED} for the first time${NC}"
|
||||
echo -e " : ${csudo}service taosd start ${RED} after${NC}"
|
||||
echo -e "${GREEN_DARK}To start taosAdapter ${NC}\t: ${csudo}update-rc.d taosadapter default ${RED} for the first time${NC}"
|
||||
echo -e " : ${csudo}service taosd taosadapter ${RED} after${NC}"
|
||||
echo -e "${GREEN_DARK}To start taoskeeper ${NC}\t: ${csudo}update-rc.d taoskeeper default ${RED} for the first time${NC}"
|
||||
echo -e " : ${csudo}service taosd taoskeeper ${RED} after${NC}"
|
||||
echo -e "${GREEN_DARK}To start taos-explorer ${NC}\t: ${csudo}update-rc.d taos-explorer default ${RED} for the first time${NC}"
|
||||
echo -e " : ${csudo}service taosd taos-explorer ${RED} after${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}"
|
||||
echo -e "${GREEN_DARK}To start TDengine server ${NC}\t: ./taosd${NC}"
|
||||
echo -e "${GREEN_DARK}To start taosAdapter ${NC}\t: ./taosadapter${NC}"
|
||||
echo -e "${GREEN_DARK}To start taoskeeper ${NC}\t: ./taoskeeper${NC}"
|
||||
echo -e "${GREEN_DARK}To start taos-explorer ${NC}\t: ./taos-explorer${NC}"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if [ ! -z "$firstEp" ]; then
|
||||
tmpFqdn=${firstEp%%:*}
|
||||
substr=":"
|
||||
if [[ $firstEp =~ $substr ]];then
|
||||
tmpPort=${firstEp#*:}
|
||||
else
|
||||
tmpPort=""
|
||||
fi
|
||||
if [[ "$tmpPort" != "" ]];then
|
||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}"
|
||||
fi
|
||||
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
|
||||
echo
|
||||
elif [ ! -z "$serverFqdn" ]; then
|
||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $serverFqdn${GREEN_DARK} to login into TDengine server${NC}"
|
||||
echo
|
||||
fi
|
||||
log_print "install TDengine successfully!"
|
||||
echo
|
||||
echo -e "\033[44;32;1mTDengine is installed successfully!${NC}"
|
||||
echo "TDengine is installed successfully!"
|
||||
echo
|
||||
echo -e "\033[44;32;1mTo start all the components : sudo start-all.sh${NC}"
|
||||
echo -e "\033[44;32;1mTo access ${productName} Commnd Line Interface : taos -h $serverFqdn${NC}"
|
||||
echo -e "\033[44;32;1mTo access ${productName} Graphic User Interface : http://$serverFqdn:6060${NC}"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,25 +31,22 @@ else
|
|||
lib64_link_dir="/usr/local/lib"
|
||||
inc_link_dir="/usr/local/include"
|
||||
fi
|
||||
serverName="taosd"
|
||||
clientName="taos"
|
||||
uninstallScript="rmtaos"
|
||||
|
||||
PREFIX="taos"
|
||||
serverName="${PREFIX}d"
|
||||
clientName="${PREFIX}"
|
||||
uninstallScript="rm${PREFIX}"
|
||||
adapterName="${PREFIX}adapter"
|
||||
demoName="${PREFIX}demo"
|
||||
benchmarkName="${PREFIX}Benchmark"
|
||||
dumpName="${PREFIX}dump"
|
||||
keeperName="${PREFIX}keeper"
|
||||
xName="${PREFIX}x"
|
||||
explorerName="${PREFIX}-explorer"
|
||||
tarbitratorName="tarbitratord"
|
||||
productName="TDengine"
|
||||
|
||||
serverName2="taosd"
|
||||
clientName2="taos"
|
||||
productName2="TDengine"
|
||||
|
||||
adapterName2="${clientName2}adapter"
|
||||
demoName2="${clientName2}demo"
|
||||
benchmarkName2="${clientName2}Benchmark"
|
||||
dumpName2="${clientName2}dump"
|
||||
keeperName2="${clientName2}keeper"
|
||||
xName2="${clientName2}x"
|
||||
explorerName2="${clientName2}-explorer"
|
||||
uninstallScript2="rm${clientName2}"
|
||||
|
||||
installDir="/usr/local/${clientName2}"
|
||||
installDir="/usr/local/${PREFIX}"
|
||||
|
||||
#install main path
|
||||
install_main_dir=${installDir}
|
||||
|
@ -57,15 +54,11 @@ data_link_dir=${installDir}/data
|
|||
log_link_dir=${installDir}/log
|
||||
cfg_link_dir=${installDir}/cfg
|
||||
local_bin_link_dir="/usr/local/bin"
|
||||
|
||||
|
||||
service_config_dir="/etc/systemd/system"
|
||||
taos_service_name=${serverName2}
|
||||
taosadapter_service_name="${clientName2}adapter"
|
||||
tarbitrator_service_name="tarbitratord"
|
||||
|
||||
config_dir="/etc/${clientName2}"
|
||||
config_dir="/etc/${PREFIX}"
|
||||
|
||||
services=(${PREFIX}"d" ${PREFIX}"adapter" ${PREFIX}"x" ${PREFIX}"-explorer" ${PREFIX}"keeper")
|
||||
tools=(${PREFIX} ${PREFIX}"Benchmark" ${PREFIX}"dump" ${PREFIX}"demo" udfd set_core.sh TDinsight.sh $uninstallScript start-all.sh stop-all.sh)
|
||||
|
||||
csudo=""
|
||||
if command -v sudo >/dev/null; then
|
||||
|
@ -92,215 +85,26 @@ else
|
|||
service_mod=2
|
||||
fi
|
||||
|
||||
function kill_taosadapter() {
|
||||
pid=$(ps -ef | grep "${adapterName2}" | grep -v "grep" | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
||||
function kill_taosd() {
|
||||
pid=$(ps -ef | grep ${serverName2} | grep -v "grep" | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
||||
function kill_tarbitrator() {
|
||||
pid=$(ps -ef | grep "tarbitrator" | grep -v "grep" | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_bin() {
|
||||
# Remove link
|
||||
${csudo}rm -f ${bin_link_dir}/${clientName} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${serverName} || :
|
||||
echo "${serverName} is removed successfully"
|
||||
${csudo}rm -f ${bin_link_dir}/udfd || :
|
||||
${csudo}rm -f ${bin_link_dir}/${adapterName2} || :
|
||||
echo "${adapterName2} is removed successfully"
|
||||
${csudo}rm -f ${bin_link_dir}/${benchmarkName2} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${demoName2} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${dumpName2} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${uninstallScript} || :
|
||||
${csudo}rm -f ${bin_link_dir}/tarbitrator || :
|
||||
${csudo}rm -f ${bin_link_dir}/set_core || :
|
||||
${csudo}rm -f ${bin_link_dir}/TDinsight.sh || :
|
||||
${csudo}rm -f ${bin_link_dir}/${keeperName2} || :
|
||||
|
||||
|
||||
if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then
|
||||
${csudo}rm -f ${bin_link_dir}/${xName2} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${explorerName2} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${clientName2} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${benchmarkName2} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${dumpName2} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${uninstallScript2} || :
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_local_bin() {
|
||||
${csudo}rm -f ${local_bin_link_dir}/${benchmarkName2} || :
|
||||
${csudo}rm -f ${local_bin_link_dir}/${demoName2} || :
|
||||
}
|
||||
|
||||
function clean_lib() {
|
||||
# Remove link
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
[ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || :
|
||||
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
[ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || :
|
||||
#${csudo}rm -rf ${v15_java_app_dir} || :
|
||||
|
||||
}
|
||||
|
||||
function clean_header() {
|
||||
# Remove link
|
||||
${csudo}rm -f ${inc_link_dir}/taos.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosdef.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
||||
|
||||
[ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || :
|
||||
}
|
||||
|
||||
function clean_config() {
|
||||
# Remove link
|
||||
${csudo}rm -f ${cfg_link_dir}/* || :
|
||||
}
|
||||
|
||||
function clean_log() {
|
||||
# Remove link
|
||||
${csudo}rm -rf ${log_link_dir} || :
|
||||
}
|
||||
|
||||
function clean_service_on_systemd() {
|
||||
taosd_service_config="${service_config_dir}/${taos_service_name}.service"
|
||||
if systemctl is-active --quiet ${taos_service_name}; then
|
||||
echo "${taos_service_name} is running, stopping it..."
|
||||
${csudo}systemctl stop ${taos_service_name} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${taos_service_name} &>/dev/null || echo &>/dev/null
|
||||
${csudo}rm -f ${taosd_service_config}
|
||||
|
||||
taosadapter_service_config="${service_config_dir}/${clientName2}adapter.service"
|
||||
if systemctl is-active --quiet ${taosadapter_service_name}; then
|
||||
echo "${clientName2}Adapter is running, stopping it..."
|
||||
${csudo}systemctl stop ${taosadapter_service_name} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${taosadapter_service_name} &>/dev/null || echo &>/dev/null
|
||||
[ -f ${taosadapter_service_config} ] && ${csudo}rm -f ${taosadapter_service_config}
|
||||
|
||||
tarbitratord_service_config="${service_config_dir}/${tarbitrator_service_name}.service"
|
||||
if systemctl is-active --quiet ${tarbitrator_service_name}; then
|
||||
echo "${productName2} tarbitrator is running, stopping it..."
|
||||
${csudo}systemctl stop ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
|
||||
|
||||
}
|
||||
|
||||
function clean_service_on_sysvinit() {
|
||||
if ps aux | grep -v grep | grep ${serverName} &>/dev/null; then
|
||||
echo "${serverName2} is running, stopping it..."
|
||||
${csudo}service ${serverName} stop || :
|
||||
fi
|
||||
|
||||
if ps aux | grep -v grep | grep tarbitrator &>/dev/null; then
|
||||
echo "${productName2} tarbitrator is running, stopping it..."
|
||||
${csudo}service tarbitratord stop || :
|
||||
fi
|
||||
|
||||
if ((${initd_mod} == 1)); then
|
||||
if [ -e ${service_config_dir}/${serverName} ]; then
|
||||
${csudo}chkconfig --del ${serverName} || :
|
||||
fi
|
||||
if [ -e ${service_config_dir}/tarbitratord ]; then
|
||||
${csudo}chkconfig --del tarbitratord || :
|
||||
fi
|
||||
elif ((${initd_mod} == 2)); then
|
||||
if [ -e ${service_config_dir}/${serverName} ]; then
|
||||
${csudo}insserv -r ${serverName} || :
|
||||
fi
|
||||
if [ -e ${service_config_dir}/tarbitratord ]; then
|
||||
${csudo}insserv -r tarbitratord || :
|
||||
fi
|
||||
elif ((${initd_mod} == 3)); then
|
||||
if [ -e ${service_config_dir}/${serverName} ]; then
|
||||
${csudo}update-rc.d -f ${serverName} remove || :
|
||||
fi
|
||||
if [ -e ${service_config_dir}/tarbitratord ]; then
|
||||
${csudo}update-rc.d -f tarbitratord remove || :
|
||||
fi
|
||||
fi
|
||||
|
||||
${csudo}rm -f ${service_config_dir}/${serverName} || :
|
||||
${csudo}rm -f ${service_config_dir}/tarbitratord || :
|
||||
|
||||
if $(which init &>/dev/null); then
|
||||
${csudo}init q || :
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_service_on_launchctl() {
|
||||
${csudouser}launchctl unload -w /Library/LaunchDaemons/com.taosdata.taosd.plist > /dev/null 2>&1 || :
|
||||
${csudo}rm /Library/LaunchDaemons/com.taosdata.taosd.plist > /dev/null 2>&1 || :
|
||||
${csudouser}launchctl unload -w /Library/LaunchDaemons/com.taosdata.${clientName2}adapter.plist > /dev/null 2>&1 || :
|
||||
${csudo}rm /Library/LaunchDaemons/com.taosdata.${clientName2}adapter.plist > /dev/null 2>&1 || :
|
||||
}
|
||||
|
||||
function clean_service() {
|
||||
if ((${service_mod} == 0)); then
|
||||
clean_service_on_systemd
|
||||
elif ((${service_mod} == 1)); then
|
||||
clean_service_on_sysvinit
|
||||
else
|
||||
if [ "$osType" = "Darwin" ]; then
|
||||
clean_service_on_launchctl
|
||||
fi
|
||||
kill_taosadapter
|
||||
kill_taosd
|
||||
kill_tarbitrator
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_data_and_config() {
|
||||
data_dir=`grep dataDir /etc/taos/taos.cfg | grep -v '#' | tail -n 1 | awk {'print $2'}`
|
||||
if [ X"$data_dir" == X"" ]; then
|
||||
data_dir="/var/lib/taos"
|
||||
fi
|
||||
log_dir=`grep logDir /etc/taos/taos.cfg | grep -v '#' | tail -n 1 | awk {'print $2'}`
|
||||
if [ X"$log_dir" == X"" ]; then
|
||||
log_dir="/var/log/taos"
|
||||
fi
|
||||
[ -d "${config_dir}" ] && ${csudo}rm -rf ${config_dir}/*
|
||||
[ -d "${data_dir}" ] && ${csudo}rm -rf ${data_dir}/*
|
||||
[ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir}/*
|
||||
}
|
||||
|
||||
_kill_service_of() {
|
||||
kill_service_of() {
|
||||
_service=$1
|
||||
pid=$(ps -ef | grep "$_service" | grep -v "grep" | awk '{print $2}')
|
||||
pid=$(ps -ef | grep $_service | grep -v grep | grep -v $uninstallScript | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
||||
_clean_service_on_systemd_of() {
|
||||
clean_service_on_systemd_of() {
|
||||
_service=$1
|
||||
_service_config="${service_config_dir}/${_service}.service"
|
||||
if systemctl is-active --quiet ${_service}; then
|
||||
echo "taoskeeper is running, stopping it..."
|
||||
echo "${_service} is running, stopping it..."
|
||||
${csudo}systemctl stop ${_service} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${_service} &>/dev/null || echo &>/dev/null
|
||||
${csudo}rm -f ${_service_config}
|
||||
}
|
||||
_clean_service_on_sysvinit_of() {
|
||||
|
||||
clean_service_on_sysvinit_of() {
|
||||
_service=$1
|
||||
if pidof ${_service} &>/dev/null; then
|
||||
echo "${_service} is running, stopping it..."
|
||||
|
@ -327,45 +131,99 @@ _clean_service_on_sysvinit_of() {
|
|||
fi
|
||||
}
|
||||
|
||||
_clean_service_of() {
|
||||
clean_service_of() {
|
||||
_service=$1
|
||||
if ((${service_mod} == 0)); then
|
||||
_clean_service_on_systemd_of $_service
|
||||
clean_service_on_systemd_of $_service
|
||||
elif ((${service_mod} == 1)); then
|
||||
_clean_service_on_sysvinit_of $_service
|
||||
clean_service_on_sysvinit_of $_service
|
||||
else
|
||||
_kill_service_of $_service
|
||||
kill_service_of $_service
|
||||
fi
|
||||
}
|
||||
|
||||
remove_taoskeeper() {
|
||||
# remove taoskeeper bin
|
||||
_clean_service_of taoskeeper
|
||||
[ -e "${bin_link_dir}/taoskeeper" ] && ${csudo}rm -rf ${bin_link_dir}/taoskeeper
|
||||
[ -e "${installDir}/taoskeeper" ] && ${csudo}rm -rf ${installDir}/taoskeeper
|
||||
[ -e "${cfg_link_dir}/metrics.toml" ] || ${csudo}rm -rf ${cfg_link_dir}/metrics.toml
|
||||
echo "taosKeeper is removed successfully!"
|
||||
}
|
||||
|
||||
function uninstall_taosx() {
|
||||
if [ -f ${installDir}/uninstall.sh ]; then
|
||||
cd ${installDir}
|
||||
bash uninstall.sh
|
||||
remove_service_of() {
|
||||
_service=$1
|
||||
clean_service_of ${_service}
|
||||
if [[ -e "${bin_link_dir}/${_service}" || -e "${installDir}/bin/${_service}" || -e "${local_bin_link_dir}/${_service}" ]]; then
|
||||
${csudo}rm -rf ${bin_link_dir}/${_service}
|
||||
${csudo}rm -rf ${installDir}/bin/${_service}
|
||||
${csudo}rm -rf ${local_bin_link_dir}/${_service}
|
||||
echo "${_service} is removed successfully!"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
uninstall_taosx
|
||||
fi
|
||||
remove_tools_of() {
|
||||
_tool=$1
|
||||
kill_service_of ${_tool}
|
||||
[ -e "${bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${bin_link_dir}/${_tool} || :
|
||||
[ -e "${installDir}/bin/${_tool}" ] && ${csudo}rm -rf ${installDir}/bin/${_tool} || :
|
||||
[ -e "${local_bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${local_bin_link_dir}/${_tool} || :
|
||||
}
|
||||
|
||||
remove_taoskeeper
|
||||
# Stop service and disable booting start.
|
||||
clean_service
|
||||
# Remove binary file and links
|
||||
clean_bin
|
||||
# Remove links of local bin
|
||||
clean_local_bin
|
||||
# Remove header file.
|
||||
remove_bin() {
|
||||
for _service in "${services[@]}"; do
|
||||
remove_service_of ${_service}
|
||||
done
|
||||
|
||||
for _tool in "${tools[@]}"; do
|
||||
remove_tools_of ${_tool}
|
||||
done
|
||||
}
|
||||
|
||||
function clean_lib() {
|
||||
# Remove link
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
[ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || :
|
||||
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
[ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || :
|
||||
#${csudo}rm -rf ${v15_java_app_dir} || :
|
||||
}
|
||||
|
||||
function clean_header() {
|
||||
# Remove link
|
||||
${csudo}rm -f ${inc_link_dir}/taos.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosdef.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taoserror.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/tdef.h || :
|
||||
${csudo}rm -f ${inc_link_dir}/taosudf.h || :
|
||||
|
||||
[ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || :
|
||||
}
|
||||
|
||||
function clean_config() {
|
||||
# Remove link
|
||||
${csudo}rm -f ${cfg_link_dir}/* || :
|
||||
}
|
||||
|
||||
function clean_log() {
|
||||
# Remove link
|
||||
${csudo}rm -rf ${log_link_dir} || :
|
||||
}
|
||||
|
||||
function clean_service_on_launchctl() {
|
||||
${csudouser}launchctl unload -w /Library/LaunchDaemons/com.taosdata.taosd.plist > /dev/null 2>&1 || :
|
||||
${csudo}rm /Library/LaunchDaemons/com.taosdata.taosd.plist > /dev/null 2>&1 || :
|
||||
${csudouser}launchctl unload -w /Library/LaunchDaemons/com.taosdata.${clientName2}adapter.plist > /dev/null 2>&1 || :
|
||||
${csudo}rm /Library/LaunchDaemons/com.taosdata.${clientName2}adapter.plist > /dev/null 2>&1 || :
|
||||
}
|
||||
|
||||
function remove_data_and_config() {
|
||||
data_dir=`grep dataDir /etc/taos/taos.cfg | grep -v '#' | tail -n 1 | awk {'print $2'}`
|
||||
if [ X"$data_dir" == X"" ]; then
|
||||
data_dir="/var/lib/${PREFIX}"
|
||||
fi
|
||||
log_dir=`grep logDir /etc/taos/taos.cfg | grep -v '#' | tail -n 1 | awk {'print $2'}`
|
||||
if [ X"$log_dir" == X"" ]; then
|
||||
log_dir="/var/log/${PREFIX}"
|
||||
fi
|
||||
[ -d "${config_dir}" ] && ${csudo}rm -rf ${config_dir}
|
||||
[ -d "${data_dir}" ] && ${csudo}rm -rf ${data_dir}
|
||||
[ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir}
|
||||
}
|
||||
|
||||
remove_bin
|
||||
clean_header
|
||||
# Remove lib file
|
||||
clean_lib
|
||||
|
@ -375,8 +233,7 @@ clean_log
|
|||
clean_config
|
||||
# Remove data link directory
|
||||
${csudo}rm -rf ${data_link_dir} || :
|
||||
|
||||
${csudo}rm -rf ${install_main_dir}
|
||||
${csudo}rm -rf ${install_main_dir} || :
|
||||
if [[ -e /etc/os-release ]]; then
|
||||
osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
|
||||
else
|
||||
|
@ -394,6 +251,7 @@ elif echo $osinfo | grep -qwi "centos"; then
|
|||
${csudo}rpm -e --noscripts tdengine >/dev/null 2>&1 || :
|
||||
fi
|
||||
if [ "$osType" = "Darwin" ]; then
|
||||
clean_service_on_launchctl
|
||||
${csudo}rm -rf /Applications/TDengine.app
|
||||
fi
|
||||
|
||||
|
@ -411,6 +269,7 @@ if [ X$answer == X"y" ] || [ X$answer == X"Y" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
command -v systemctl >/dev/null 2>&1 && ${csudo}systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
echo
|
||||
echo "${productName2} is removed successfully!"
|
||||
echo "${productName} is removed successfully!"
|
||||
echo
|
||||
|
|
|
@ -38,7 +38,8 @@ if command -v sudo > /dev/null; then
|
|||
fi
|
||||
|
||||
function kill_client() {
|
||||
if [ -n "$(ps aux | grep -v grep | grep ${clientName})" ]; then
|
||||
pid=$(ps -ef | grep ${clientName2} | grep -v grep | grep -v $uninstallScript2 | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ extern "C" {
|
|||
#define IS_SLASH_LETTER_IN_MEASUREMENT(sql) \
|
||||
(*((sql)-1) == SLASH && (*(sql) == COMMA || *(sql) == SPACE || *(sql) == SLASH))
|
||||
|
||||
#define MOVE_FORWARD_ONE(sql, len) (memmove((void *)((sql)-1), (sql), len))
|
||||
#define MOVE_FORWARD_ONE(sql, len) ((void)memmove((void *)((sql)-1), (sql), len))
|
||||
|
||||
#define PROCESS_SLASH_IN_MEASUREMENT(key, keyLen) \
|
||||
for (int i = 1; i < keyLen; ++i) { \
|
||||
|
@ -211,19 +211,19 @@ extern int64_t smlFactorS[];
|
|||
|
||||
typedef int32_t (*_equal_fn_sml)(const void *, const void *);
|
||||
|
||||
SSmlHandle *smlBuildSmlInfo(TAOS *taos);
|
||||
int32_t smlBuildSmlInfo(TAOS *taos, SSmlHandle **handle);
|
||||
void smlDestroyInfo(SSmlHandle *info);
|
||||
int smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset);
|
||||
int smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset);
|
||||
bool smlParseNumberOld(SSmlKv *kvVal, SSmlMsgBuf *msg);
|
||||
int32_t smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2);
|
||||
bool smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg);
|
||||
void smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2);
|
||||
int32_t smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg);
|
||||
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision);
|
||||
SSmlTableInfo* smlBuildTableInfo(int numRows, const char* measure, int32_t measureLen);
|
||||
SSmlSTableMeta* smlBuildSTableMeta(bool isDataFormat);
|
||||
int32_t smlBuildTableInfo(int numRows, const char* measure, int32_t measureLen, SSmlTableInfo** tInfo);
|
||||
int32_t smlBuildSTableMeta(bool isDataFormat, SSmlSTableMeta** sMeta);
|
||||
int32_t smlSetCTableName(SSmlTableInfo *oneTable);
|
||||
void getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo);
|
||||
STableMeta* smlGetMeta(SSmlHandle *info, const void* measure, int32_t measureLen);
|
||||
int32_t getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo);
|
||||
int32_t smlGetMeta(SSmlHandle *info, const void* measure, int32_t measureLen, STableMeta **pTableMeta);
|
||||
int32_t is_same_child_table_telnet(const void *a, const void *b);
|
||||
int64_t smlParseOpenTsdbTime(SSmlHandle *info, const char *data, int32_t len);
|
||||
int32_t smlClearForRerun(SSmlHandle *info);
|
||||
|
@ -236,7 +236,7 @@ int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLine
|
|||
int32_t smlParseTelnetString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements);
|
||||
int32_t smlParseJSON(SSmlHandle *info, char *payload);
|
||||
|
||||
SSmlSTableMeta* smlBuildSuperTableInfo(SSmlHandle *info, SSmlLineInfo *currElement);
|
||||
int32_t smlBuildSuperTableInfo(SSmlHandle *info, SSmlLineInfo *currElement, SSmlSTableMeta** sMeta);
|
||||
bool isSmlTagAligned(SSmlHandle *info, int cnt, SSmlKv *kv);
|
||||
bool isSmlColAligned(SSmlHandle *info, int cnt, SSmlKv *kv);
|
||||
int32_t smlProcessChildTable(SSmlHandle *info, SSmlLineInfo *elements);
|
||||
|
|
|
@ -744,7 +744,7 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
|
|||
req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
|
||||
}
|
||||
|
||||
if (taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv)) < 0) {
|
||||
if (taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv)) != 0) {
|
||||
taosMemoryFree(user);
|
||||
code = terrno ? terrno : TSDB_CODE_APP_ERROR;
|
||||
goto _return;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "clientMonitor.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "tmisce.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tglobal.h"
|
||||
#include "tqueue.h"
|
||||
#include "cJSON.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tmisce.h"
|
||||
#include "tqueue.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
SRWLatch monitorLock;
|
||||
void* monitorTimer;
|
||||
|
@ -116,8 +116,12 @@ static int32_t monitorReportAsyncCB(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
if (code != 0) {
|
||||
tscError("failed to send slow log:%s, clusterId:%" PRIx64, p->data, p->clusterId);
|
||||
}
|
||||
MonitorSlowLogData tmp = {.clusterId = p->clusterId, .type = p->type, .fileName = p->fileName,
|
||||
.pFile= p->pFile, .offset = p->offset, .data = NULL};
|
||||
MonitorSlowLogData tmp = {.clusterId = p->clusterId,
|
||||
.type = p->type,
|
||||
.fileName = p->fileName,
|
||||
.pFile = p->pFile,
|
||||
.offset = p->offset,
|
||||
.data = NULL};
|
||||
if (monitorPutData2MonitorQueue(tmp) == 0) {
|
||||
p->fileName = NULL;
|
||||
}
|
||||
|
@ -247,7 +251,8 @@ void monitorCreateClient(int64_t clusterId) {
|
|||
}
|
||||
|
||||
taos_collector_registry_register_collector(pMonitor->registry, pMonitor->colector);
|
||||
pMonitor->counters = (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pMonitor->counters =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pMonitor->counters == NULL) {
|
||||
tscError("failed to create monitor counters");
|
||||
goto fail;
|
||||
|
@ -265,7 +270,8 @@ void monitorCreateClient(int64_t clusterId) {
|
|||
pMonitor = NULL;
|
||||
goto fail;
|
||||
}
|
||||
pMonitor->timer = taosTmrStart(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, (void*)pMonitor, monitorTimer);
|
||||
pMonitor->timer =
|
||||
taosTmrStart(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, (void*)pMonitor, monitorTimer);
|
||||
if (pMonitor->timer == NULL) {
|
||||
tscError("failed to start timer");
|
||||
goto fail;
|
||||
|
@ -283,7 +289,8 @@ fail:
|
|||
taosWUnLockLatch(&monitorLock);
|
||||
}
|
||||
|
||||
void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* help, size_t label_key_count, const char** label_keys) {
|
||||
void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* help, size_t label_key_count,
|
||||
const char** label_keys) {
|
||||
taosWLockLatch(&monitorLock);
|
||||
MonitorClient** ppMonitor = (MonitorClient**)taosHashGet(monitorCounterHash, &clusterId, LONG_BYTES);
|
||||
if (ppMonitor == NULL || *ppMonitor == NULL) {
|
||||
|
@ -291,8 +298,7 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char*
|
|||
goto end;
|
||||
}
|
||||
taos_counter_t* newCounter = taos_counter_new(name, help, label_key_count, label_keys);
|
||||
if (newCounter == NULL)
|
||||
return;
|
||||
if (newCounter == NULL) return;
|
||||
MonitorClient* pMonitor = *ppMonitor;
|
||||
taos_collector_add_metric(pMonitor->colector, newCounter);
|
||||
if (taosHashPut(pMonitor->counters, name, strlen(name), &newCounter, POINTER_BYTES) != 0) {
|
||||
|
@ -300,7 +306,8 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char*
|
|||
taos_counter_destroy(newCounter);
|
||||
goto end;
|
||||
}
|
||||
tscInfo("[monitor] monitorCreateClientCounter %"PRIx64"(%p):%s : %p.", pMonitor->clusterId, pMonitor, name, newCounter);
|
||||
tscInfo("[monitor] monitorCreateClientCounter %" PRIx64 "(%p):%s : %p.", pMonitor->clusterId, pMonitor, name,
|
||||
newCounter);
|
||||
|
||||
end:
|
||||
taosWUnLockLatch(&monitorLock);
|
||||
|
@ -453,7 +460,8 @@ static int64_t getFileSize(char* path){
|
|||
return fileSize;
|
||||
}
|
||||
|
||||
static int32_t sendSlowLog(int64_t clusterId, char* data, TdFilePtr pFile, int64_t offset, SLOW_LOG_QUEUE_TYPE type, char* fileName, void* pTransporter, SEpSet *epSet){
|
||||
static int32_t sendSlowLog(int64_t clusterId, char* data, TdFilePtr pFile, int64_t offset, SLOW_LOG_QUEUE_TYPE type,
|
||||
char* fileName, void* pTransporter, SEpSet* epSet) {
|
||||
if (data == NULL) {
|
||||
taosMemoryFree(fileName);
|
||||
return -1;
|
||||
|
@ -473,7 +481,8 @@ static int32_t sendSlowLog(int64_t clusterId, char* data, TdFilePtr pFile, int64
|
|||
return sendReport(pTransporter, epSet, data, MONITOR_TYPE_SLOW_LOG, pParam);
|
||||
}
|
||||
|
||||
static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offset, int64_t size, SLOW_LOG_QUEUE_TYPE type, char* fileName){
|
||||
static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offset, int64_t size,
|
||||
SLOW_LOG_QUEUE_TYPE type, char* fileName) {
|
||||
SAppInstInfo* pInst = getAppInstByClusterId(clusterId);
|
||||
if (pInst == NULL) {
|
||||
tscError("failed to get app instance by clusterId:%" PRId64, clusterId);
|
||||
|
@ -481,7 +490,8 @@ static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offs
|
|||
}
|
||||
SEpSet ep = getEpSet_s(&pInst->mgmtEp);
|
||||
char* data = readFile(pFile, offset, size);
|
||||
return sendSlowLog(clusterId, data, (type == SLOW_LOG_READ_BEGINNIG ? pFile : NULL), *offset, type, fileName, pInst->pTransporter, &ep);
|
||||
return sendSlowLog(clusterId, data, (type == SLOW_LOG_READ_BEGINNIG ? pFile : NULL), *offset, type, fileName,
|
||||
pInst->pTransporter, &ep);
|
||||
}
|
||||
|
||||
static void monitorSendSlowLogAtBeginning(int64_t clusterId, char** fileName, TdFilePtr pFile, int64_t offset) {
|
||||
|
@ -567,7 +577,8 @@ static void processFileRemoved(SlowLogClient* pClient){
|
|||
taosUnLockFile(pClient->pFile);
|
||||
taosCloseFile(&(pClient->pFile));
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile =
|
||||
taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tscError("failed to open file:%s since %s", pClient->path, terrstr());
|
||||
|
@ -640,9 +651,7 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId){
|
|||
}
|
||||
|
||||
char* name = taosGetDirEntryName(de);
|
||||
if (strcmp(name, ".") == 0 ||
|
||||
strcmp(name, "..") == 0 ||
|
||||
strstr(name, namePrefix) == NULL) {
|
||||
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0 || strstr(name, namePrefix) == NULL) {
|
||||
tscInfo("skip file:%s, for cluster id:%" PRIx64, name, clusterId);
|
||||
continue;
|
||||
}
|
||||
|
@ -682,7 +691,7 @@ static void* monitorThreadFunc(void *param){
|
|||
tscDebug("monitorThreadFunc start");
|
||||
int64_t quitTime = 0;
|
||||
while (1) {
|
||||
if (atomic_load_32(&slowLogFlag) > 0 > 0) {
|
||||
if (atomic_load_32(&slowLogFlag) > 0) {
|
||||
if (quitCnt == 0) {
|
||||
monitorSendAllSlowLogAtQuit();
|
||||
if (quitCnt == 0) {
|
||||
|
@ -702,7 +711,8 @@ static void* monitorThreadFunc(void *param){
|
|||
if (slowLogData != NULL) {
|
||||
if (slowLogData->type == SLOW_LOG_READ_BEGINNIG) {
|
||||
if (slowLogData->pFile != NULL) {
|
||||
monitorSendSlowLogAtBeginning(slowLogData->clusterId, &(slowLogData->fileName), slowLogData->pFile, slowLogData->offset);
|
||||
monitorSendSlowLogAtBeginning(slowLogData->clusterId, &(slowLogData->fileName), slowLogData->pFile,
|
||||
slowLogData->offset);
|
||||
} else {
|
||||
monitorSendAllSlowLogFromTempDir(slowLogData->clusterId);
|
||||
}
|
||||
|
@ -757,8 +767,11 @@ static void tscMonitorStop() {
|
|||
}
|
||||
|
||||
int32_t monitorInit() {
|
||||
int32_t code;
|
||||
|
||||
tscInfo("[monitor] tscMonitor init");
|
||||
monitorCounterHash = (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
monitorCounterHash =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (monitorCounterHash == NULL) {
|
||||
tscError("failed to create monitorCounterHash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -766,7 +779,8 @@ int32_t monitorInit() {
|
|||
}
|
||||
taosHashSetFreeFp(monitorCounterHash, destroyMonitorClient);
|
||||
|
||||
monitorSlowLogHash = (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
monitorSlowLogHash =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (monitorSlowLogHash == NULL) {
|
||||
tscError("failed to create monitorSlowLogHash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -798,8 +812,9 @@ int32_t monitorInit() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
monitorQueue = taosOpenQueue();
|
||||
if(monitorQueue == NULL){
|
||||
code = taosOpenQueue(&monitorQueue);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("open queue error since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -829,17 +844,22 @@ void monitorClose() {
|
|||
}
|
||||
|
||||
int32_t monitorPutData2MonitorQueue(MonitorSlowLogData data) {
|
||||
int32_t code;
|
||||
MonitorSlowLogData* slowLogData;
|
||||
|
||||
if (atomic_load_32(&slowLogFlag) == -2) {
|
||||
tscError("[monitor] slow log thread is exiting");
|
||||
return -1;
|
||||
}
|
||||
MonitorSlowLogData* slowLogData = taosAllocateQitem(sizeof(MonitorSlowLogData), DEF_QITEM, 0);
|
||||
if (slowLogData == NULL) {
|
||||
|
||||
code = taosAllocateQitem(sizeof(MonitorSlowLogData), DEF_QITEM, 0, (void**)&slowLogData);
|
||||
if (code) {
|
||||
tscError("[monitor] failed to allocate slow log data");
|
||||
return -1;
|
||||
return terrno = code;
|
||||
}
|
||||
*slowLogData = data;
|
||||
tscDebug("[monitor] write slow log to queue, clusterId:%"PRIx64 " type:%s, data:%s", slowLogData->clusterId, queueTypeStr[slowLogData->type], slowLogData->data);
|
||||
tscDebug("[monitor] write slow log to queue, clusterId:%" PRIx64 " type:%s, data:%s", slowLogData->clusterId,
|
||||
queueTypeStr[slowLogData->type], slowLogData->data);
|
||||
if (taosWriteQitem(monitorQueue, slowLogData) == 0) {
|
||||
tsem2_post(&monitorSem);
|
||||
} else {
|
||||
|
|
|
@ -1116,9 +1116,9 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
if (taosHashGetSize(pVgroupHashmap) == 0) {
|
||||
goto end;
|
||||
}
|
||||
SArray* pBufArray = serializeVgroupsCreateTableBatch(pVgroupHashmap);
|
||||
if (NULL == pBufArray) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SArray* pBufArray = NULL;
|
||||
code = serializeVgroupsCreateTableBatch(pVgroupHashmap, &pBufArray);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -1264,9 +1264,9 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
if (taosHashGetSize(pVgroupHashmap) == 0) {
|
||||
goto end;
|
||||
}
|
||||
SArray* pBufArray = serializeVgroupsDropTableBatch(pVgroupHashmap);
|
||||
if (NULL == pBufArray) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SArray* pBufArray = NULL;
|
||||
code = serializeVgroupsDropTableBatch(pVgroupHashmap, &pBufArray);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -1572,9 +1572,8 @@ int taos_write_raw_block_with_fields_with_reqid(TAOS* taos, int rows, char* pDat
|
|||
}
|
||||
// uError("td23101 0vgId:%d, vgId:%d, name:%s, uid:%"PRIu64, vgData.vgId, pTableMeta->vgId, tbname, pTableMeta->uid);
|
||||
|
||||
pQuery = smlInitHandle();
|
||||
if (pQuery == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = smlInitHandle(&pQuery);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
|
@ -1656,9 +1655,9 @@ int taos_write_raw_block_with_reqid(TAOS* taos, int rows, char* pData, const cha
|
|||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
pQuery = smlInitHandle();
|
||||
if (pQuery == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
code = smlInitHandle(&pQuery);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
|
@ -1755,12 +1754,12 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
conn.requestObjRefId = pRequest->self;
|
||||
conn.mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
pQuery = smlInitHandle();
|
||||
if (pQuery == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = smlInitHandle(&pQuery);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SET_ERROR_MSG("init sml handle failed");
|
||||
goto end;
|
||||
}
|
||||
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
while (++rspObj.common.resIter < rspObj.rsp.common.blockNum) {
|
||||
void* pRetrieve = taosArrayGetP(rspObj.rsp.common.blockData, rspObj.common.resIter);
|
||||
|
@ -1903,12 +1902,12 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
conn.requestObjRefId = pRequest->self;
|
||||
conn.mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
pQuery = smlInitHandle();
|
||||
if (pQuery == NULL) {
|
||||
code = smlInitHandle(&pQuery);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SET_ERROR_MSG("init sml handle failed");
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
|
||||
uDebug(LOG_ID_TAG " write raw metadata block num:%d", LOG_ID_VALUE, rspObj.rsp.common.blockNum);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -29,29 +29,29 @@
|
|||
(start)++; \
|
||||
}
|
||||
|
||||
static char *smlJsonGetObj(char *payload) {
|
||||
static int32_t smlJsonGetObj(char **payload) {
|
||||
int leftBracketCnt = 0;
|
||||
bool isInQuote = false;
|
||||
while (*payload) {
|
||||
if (*payload == '"' && *(payload - 1) != '\\') {
|
||||
while (**payload) {
|
||||
if (**payload == '"' && *((*payload) - 1) != '\\') {
|
||||
isInQuote = !isInQuote;
|
||||
} else if (!isInQuote && unlikely(*payload == '{')) {
|
||||
} else if (!isInQuote && unlikely(**payload == '{')) {
|
||||
leftBracketCnt++;
|
||||
payload++;
|
||||
(*payload)++;
|
||||
continue;
|
||||
} else if (!isInQuote && unlikely(*payload == '}')) {
|
||||
} else if (!isInQuote && unlikely(**payload == '}')) {
|
||||
leftBracketCnt--;
|
||||
payload++;
|
||||
(*payload)++;
|
||||
if (leftBracketCnt == 0) {
|
||||
return payload;
|
||||
return 0;
|
||||
} else if (leftBracketCnt < 0) {
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
payload++;
|
||||
(*payload)++;
|
||||
}
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset) {
|
||||
|
@ -99,8 +99,9 @@ int smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset) {
|
|||
offset[index++] = *start - sTmp;
|
||||
element->timestamp = (*start);
|
||||
if (*(*start) == '{') {
|
||||
char *tmp = smlJsonGetObj((*start));
|
||||
if (tmp) {
|
||||
char *tmp = *start;
|
||||
int32_t code = smlJsonGetObj(&tmp);
|
||||
if (code == 0) {
|
||||
element->timestampLen = tmp - (*start);
|
||||
*start = tmp;
|
||||
}
|
||||
|
@ -127,8 +128,9 @@ int smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset) {
|
|||
offset[index++] = *start - sTmp;
|
||||
element->cols = (*start);
|
||||
if (*(*start) == '{') {
|
||||
char *tmp = smlJsonGetObj((*start));
|
||||
if (tmp) {
|
||||
char *tmp = *start;
|
||||
int32_t code = smlJsonGetObj(&tmp);
|
||||
if (code == 0) {
|
||||
element->colsLen = tmp - (*start);
|
||||
*start = tmp;
|
||||
}
|
||||
|
@ -153,8 +155,9 @@ int smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset) {
|
|||
JUMP_JSON_SPACE((*start))
|
||||
offset[index++] = *start - sTmp;
|
||||
element->tags = (*start);
|
||||
char *tmp = smlJsonGetObj((*start));
|
||||
if (tmp) {
|
||||
char *tmp = *start;
|
||||
int32_t code = smlJsonGetObj(&tmp);
|
||||
if (code == 0) {
|
||||
element->tagsLen = tmp - (*start);
|
||||
*start = tmp;
|
||||
}
|
||||
|
@ -209,8 +212,9 @@ int smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset) {
|
|||
(*start) += offset[index++];
|
||||
element->timestamp = *start;
|
||||
if (*(*start) == '{') {
|
||||
char *tmp = smlJsonGetObj((*start));
|
||||
if (tmp) {
|
||||
char *tmp = *start;
|
||||
int32_t code = smlJsonGetObj(&tmp);
|
||||
if (code == 0) {
|
||||
element->timestampLen = tmp - (*start);
|
||||
*start = tmp;
|
||||
}
|
||||
|
@ -227,8 +231,9 @@ int smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset) {
|
|||
(*start) += offset[index++];
|
||||
element->cols = *start;
|
||||
if (*(*start) == '{') {
|
||||
char *tmp = smlJsonGetObj((*start));
|
||||
if (tmp) {
|
||||
char *tmp = *start;
|
||||
int32_t code = smlJsonGetObj(&tmp);
|
||||
if (code == 0) {
|
||||
element->colsLen = tmp - (*start);
|
||||
*start = tmp;
|
||||
}
|
||||
|
@ -244,8 +249,9 @@ int smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset) {
|
|||
} else if ((*start)[1] == 't' && (*start)[2] == 'a') {
|
||||
(*start) += offset[index++];
|
||||
element->tags = (*start);
|
||||
char *tmp = smlJsonGetObj((*start));
|
||||
if (tmp) {
|
||||
char *tmp = *start;
|
||||
int32_t code = smlJsonGetObj(&tmp);
|
||||
if (code == 0) {
|
||||
element->tagsLen = tmp - (*start);
|
||||
*start = tmp;
|
||||
}
|
||||
|
@ -261,7 +267,7 @@ int smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset) {
|
|||
uError("elements != %d", OTD_JSON_FIELDS_NUM);
|
||||
return TSDB_CODE_TSC_INVALID_JSON;
|
||||
}
|
||||
return 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static inline int32_t smlParseMetricFromJSON(SSmlHandle *info, cJSON *metric, SSmlLineInfo *elements) {
|
||||
|
@ -466,7 +472,11 @@ static int32_t smlParseValueFromJSON(cJSON *root, SSmlKv *kv) {
|
|||
break;
|
||||
}
|
||||
case cJSON_String: {
|
||||
smlConvertJSONString(kv, "binary", root);
|
||||
int32_t ret = smlConvertJSONString(kv, "binary", root);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
uError("OTD:Failed to parse binary value from JSON Obj");
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case cJSON_Object: {
|
||||
|
@ -492,20 +502,17 @@ static int32_t smlProcessTagJson(SSmlHandle *info, cJSON *tags){
|
|||
int32_t tagNum = cJSON_GetArraySize(tags);
|
||||
if (unlikely(tagNum == 0)) {
|
||||
uError("SML:Tag should not be empty");
|
||||
terrno = TSDB_CODE_TSC_INVALID_JSON;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_INVALID_JSON;
|
||||
}
|
||||
for (int32_t i = 0; i < tagNum; ++i) {
|
||||
cJSON *tag = cJSON_GetArrayItem(tags, i);
|
||||
if (unlikely(tag == NULL)) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_JSON;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_INVALID_JSON;
|
||||
}
|
||||
size_t keyLen = strlen(tag->string);
|
||||
if (unlikely(IS_INVALID_COL_LEN(keyLen))) {
|
||||
uError("OTD:Tag key length is 0 or too large than 64");
|
||||
terrno = TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
}
|
||||
|
||||
// add kv to SSmlKv
|
||||
|
@ -516,19 +523,19 @@ static int32_t smlProcessTagJson(SSmlHandle *info, cJSON *tags){
|
|||
// value
|
||||
int32_t ret = smlParseValueFromJSON(tag, &kv);
|
||||
if (unlikely(ret != TSDB_CODE_SUCCESS)) {
|
||||
terrno = ret;
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
if (taosArrayPush(preLineKV, &kv) == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
|
||||
if (info->dataFormat && !isSmlTagAligned(info, cnt, &kv)) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_INVALID_JSON;
|
||||
}
|
||||
|
||||
cnt++;
|
||||
}
|
||||
return 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo *elements) {
|
||||
|
@ -536,12 +543,18 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo
|
|||
if(info->dataFormat){
|
||||
ret = smlProcessSuperTable(info, elements);
|
||||
if(ret != 0){
|
||||
return terrno;
|
||||
if(info->reRun){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
ret = smlProcessTagJson(info, tags);
|
||||
if(ret != 0){
|
||||
return terrno;
|
||||
if(info->reRun){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
ret = smlJoinMeasureTag(elements);
|
||||
if(ret != 0){
|
||||
|
@ -703,6 +716,9 @@ static int32_t smlParseJSONStringExt(SSmlHandle *info, cJSON *root, SSmlLineInfo
|
|||
// Parse tags
|
||||
bool needFree = info->dataFormat;
|
||||
elements->tags = cJSON_PrintUnformatted(tagsJson);
|
||||
if (elements->tags == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
elements->tagsLen = strlen(elements->tags);
|
||||
if (is_same_child_table_telnet(elements, &info->preLine) != 0) {
|
||||
ret = smlParseTagsFromJSON(info, tagsJson, elements);
|
||||
|
@ -729,7 +745,8 @@ static int32_t smlParseJSONStringExt(SSmlHandle *info, cJSON *root, SSmlLineInfo
|
|||
// notice!!! put ts back to tag to ensure get meta->precision
|
||||
int64_t ts = smlParseTSFromJSON(info, tsJson);
|
||||
if (unlikely(ts < 0)) {
|
||||
uError("OTD:0x%" PRIx64 " Unable to parse timestamp from JSON payload", info->id);
|
||||
char* tmp = cJSON_PrintUnformatted(tsJson);
|
||||
uError("OTD:0x%" PRIx64 " Unable to parse timestamp from JSON payload %s %s %" PRId64, info->id, info->msgBuf.buf,tmp, ts);
|
||||
return TSDB_CODE_INVALID_TIMESTAMP;
|
||||
}
|
||||
SSmlKv kvTs = {0};
|
||||
|
@ -823,7 +840,7 @@ static int32_t smlParseJSONString(SSmlHandle *info, char **start, SSmlLineInfo *
|
|||
}
|
||||
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (unlikely(**start == '\0' && elements->measure == NULL)) return TSDB_CODE_SUCCESS;
|
||||
|
@ -844,18 +861,23 @@ static int32_t smlParseJSONString(SSmlHandle *info, char **start, SSmlLineInfo *
|
|||
cJSON *valueJson = cJSON_Parse(elements->cols);
|
||||
if (unlikely(valueJson == NULL)) {
|
||||
uError("SML:0x%" PRIx64 " parse json cols failed:%s", info->id, elements->cols);
|
||||
elements->cols[elements->colsLen] = tmp;
|
||||
return TSDB_CODE_TSC_INVALID_JSON;
|
||||
}
|
||||
taosArrayPush(info->tagJsonArray, &valueJson);
|
||||
if (taosArrayPush(info->tagJsonArray, &valueJson) == NULL){
|
||||
cJSON_Delete(valueJson);
|
||||
elements->cols[elements->colsLen] = tmp;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
ret = smlParseValueFromJSONObj(valueJson, &kv);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:Failed to parse value from JSON Obj:%s", elements->cols);
|
||||
uError("SML:0x%" PRIx64 " Failed to parse value from JSON Obj:%s", info->id, elements->cols);
|
||||
elements->cols[elements->colsLen] = tmp;
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
elements->cols[elements->colsLen] = tmp;
|
||||
} else if (smlParseValue(&kv, &info->msgBuf) != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:cols invalidate:%s", elements->cols);
|
||||
uError("SML:0x%" PRIx64 " cols invalidate:%s", info->id, elements->cols);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
|
@ -870,7 +892,11 @@ static int32_t smlParseJSONString(SSmlHandle *info, char **start, SSmlLineInfo *
|
|||
return TSDB_CODE_TSC_INVALID_JSON;
|
||||
}
|
||||
|
||||
taosArrayPush(info->tagJsonArray, &tagsJson);
|
||||
if (taosArrayPush(info->tagJsonArray, &tagsJson) == NULL){
|
||||
cJSON_Delete(tagsJson);
|
||||
uError("SML:0x%" PRIx64 " taosArrayPush failed", info->id);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
ret = smlParseTagsFromJSON(info, tagsJson, elements);
|
||||
if (unlikely(ret)) {
|
||||
uError("OTD:0x%" PRIx64 " Unable to parse tags from JSON payload", info->id);
|
||||
|
@ -937,7 +963,7 @@ int32_t smlParseJSON(SSmlHandle *info, char *payload) {
|
|||
return ret;
|
||||
}
|
||||
info->lines = (SSmlLineInfo *)tmp;
|
||||
memset(info->lines + cnt, 0, (payloadNum - cnt) * sizeof(SSmlLineInfo));
|
||||
(void)memset(info->lines + cnt, 0, (payloadNum - cnt) * sizeof(SSmlLineInfo));
|
||||
}
|
||||
ret = smlParseJSONString(info, &dataPointStart, info->lines + cnt);
|
||||
if ((info->lines + cnt)->measure == NULL) break;
|
||||
|
|
|
@ -103,7 +103,10 @@ int32_t smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg) {
|
|||
return code;
|
||||
}
|
||||
char* tmp = taosMemoryCalloc(pVal->length, 1);
|
||||
memcpy(tmp, pVal->value + NCHAR_ADD_LEN - 1, pVal->length - NCHAR_ADD_LEN);
|
||||
if (tmp == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(void)memcpy(tmp, pVal->value + NCHAR_ADD_LEN - 1, pVal->length - NCHAR_ADD_LEN);
|
||||
code = doGeomFromText(tmp, (unsigned char **)&pVal->value, &pVal->length);
|
||||
taosMemoryFree(tmp);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -149,7 +152,7 @@ int32_t smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg) {
|
|||
if(data == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(data, pVal->value + (NCHAR_ADD_LEN - 1), pVal->length);
|
||||
(void)memcpy(data, pVal->value + (NCHAR_ADD_LEN - 1), pVal->length);
|
||||
pVal->value = data;
|
||||
}
|
||||
|
||||
|
@ -212,8 +215,7 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){
|
|||
while (*sql < sqlEnd) {
|
||||
if (unlikely(IS_SPACE(*sql,escapeChar) || IS_COMMA(*sql,escapeChar))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
|
||||
terrno = TSDB_CODE_SML_INVALID_DATA;
|
||||
return -1;
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
if (unlikely(IS_EQUAL(*sql,escapeChar))) {
|
||||
keyLen = *sql - key;
|
||||
|
@ -230,8 +232,7 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){
|
|||
|
||||
if (unlikely(IS_INVALID_COL_LEN(keyLen - keyLenEscaped))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid key or key is too long than 64", key);
|
||||
terrno = TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
}
|
||||
|
||||
// parse value
|
||||
|
@ -245,8 +246,7 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){
|
|||
break;
|
||||
} else if (unlikely(IS_EQUAL(*sql,escapeChar))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
|
||||
terrno = TSDB_CODE_SML_INVALID_DATA;
|
||||
return -1;
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
|
||||
if (IS_SLASH_LETTER_IN_TAG_FIELD_KEY(*sql)) {
|
||||
|
@ -261,24 +261,28 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){
|
|||
|
||||
if (unlikely(valueLen == 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid value", value);
|
||||
terrno = TSDB_CODE_SML_INVALID_DATA;
|
||||
return -1;
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
|
||||
if (unlikely(valueLen - valueLenEscaped > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)) {
|
||||
terrno = TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
|
||||
return -1;
|
||||
return TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
|
||||
}
|
||||
|
||||
if (keyEscaped) {
|
||||
char *tmp = (char *)taosMemoryMalloc(keyLen);
|
||||
memcpy(tmp, key, keyLen);
|
||||
if (tmp == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(void)memcpy(tmp, key, keyLen);
|
||||
PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, keyLen);
|
||||
key = tmp;
|
||||
}
|
||||
if (valueEscaped) {
|
||||
char *tmp = (char *)taosMemoryMalloc(valueLen);
|
||||
memcpy(tmp, value, valueLen);
|
||||
if (tmp == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(void)memcpy(tmp, value, valueLen);
|
||||
PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, valueLen);
|
||||
value = tmp;
|
||||
}
|
||||
|
@ -289,11 +293,12 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){
|
|||
.length = valueLen,
|
||||
.keyEscaped = keyEscaped,
|
||||
.valueEscaped = valueEscaped};
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
if(taosArrayPush(preLineKV, &kv) == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (info->dataFormat && !isSmlTagAligned(info, cnt, &kv)) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_INVALID_JSON;
|
||||
}
|
||||
|
||||
cnt++;
|
||||
|
@ -302,7 +307,7 @@ static int32_t smlProcessTagLine(SSmlHandle *info, char **sql, char *sqlEnd){
|
|||
}
|
||||
(*sql)++;
|
||||
}
|
||||
return 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t smlParseTagLine(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLineInfo *elements) {
|
||||
|
@ -315,13 +320,19 @@ static int32_t smlParseTagLine(SSmlHandle *info, char **sql, char *sqlEnd, SSmlL
|
|||
if(info->dataFormat){
|
||||
ret = smlProcessSuperTable(info, elements);
|
||||
if(ret != 0){
|
||||
return terrno;
|
||||
if(info->reRun){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret = smlProcessTagLine(info, sql, sqlEnd);
|
||||
if(ret != 0){
|
||||
return terrno;
|
||||
if (info->reRun){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
return smlProcessChildTable(info, elements);
|
||||
|
@ -410,7 +421,10 @@ static int32_t smlParseColLine(SSmlHandle *info, char **sql, char *sqlEnd, SSmlL
|
|||
|
||||
if (keyEscaped) {
|
||||
char *tmp = (char *)taosMemoryMalloc(kv.keyLen);
|
||||
memcpy(tmp, key, kv.keyLen);
|
||||
if (tmp == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(void)memcpy(tmp, key, kv.keyLen);
|
||||
PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, kv.keyLen);
|
||||
kv.key = tmp;
|
||||
kv.keyEscaped = keyEscaped;
|
||||
|
@ -418,7 +432,10 @@ static int32_t smlParseColLine(SSmlHandle *info, char **sql, char *sqlEnd, SSmlL
|
|||
|
||||
if (valueEscaped) {
|
||||
char *tmp = (char *)taosMemoryMalloc(kv.length);
|
||||
memcpy(tmp, kv.value, kv.length);
|
||||
if (tmp == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(void)memcpy(tmp, kv.value, kv.length);
|
||||
PROCESS_SLASH_IN_FIELD_VALUE(tmp, kv.length);
|
||||
ASSERT(kv.type != TSDB_DATA_TYPE_GEOMETRY);
|
||||
if(kv.type == TSDB_DATA_TYPE_VARBINARY){
|
||||
|
@ -437,8 +454,13 @@ static int32_t smlParseColLine(SSmlHandle *info, char **sql, char *sqlEnd, SSmlL
|
|||
} else {
|
||||
if (currElement->colArray == NULL) {
|
||||
currElement->colArray = taosArrayInit_s(sizeof(SSmlKv), 1);
|
||||
if (currElement->colArray == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (taosArrayPush(currElement->colArray, &kv) == NULL){ // reserve for timestamp
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
taosArrayPush(currElement->colArray, &kv); // reserve for timestamp
|
||||
}
|
||||
|
||||
cnt++;
|
||||
|
|
|
@ -84,8 +84,7 @@ static int32_t smlProcessTagTelnet(SSmlHandle *info, char *data, char *sqlEnd){
|
|||
while (sql < sqlEnd) {
|
||||
if (unlikely(*sql == SPACE)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", sql);
|
||||
terrno = TSDB_CODE_SML_INVALID_DATA;
|
||||
return -1;
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
if (unlikely(*sql == EQUAL)) {
|
||||
keyLen = sql - key;
|
||||
|
@ -97,8 +96,7 @@ static int32_t smlProcessTagTelnet(SSmlHandle *info, char *data, char *sqlEnd){
|
|||
|
||||
if (unlikely(IS_INVALID_COL_LEN(keyLen))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid key or key is too long than 64", key);
|
||||
terrno = TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
}
|
||||
|
||||
// parse value
|
||||
|
@ -111,8 +109,7 @@ static int32_t smlProcessTagTelnet(SSmlHandle *info, char *data, char *sqlEnd){
|
|||
}
|
||||
if (unlikely(*sql == EQUAL)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", sql);
|
||||
terrno = TSDB_CODE_SML_INVALID_DATA;
|
||||
return -1;
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
sql++;
|
||||
}
|
||||
|
@ -120,13 +117,11 @@ static int32_t smlProcessTagTelnet(SSmlHandle *info, char *data, char *sqlEnd){
|
|||
|
||||
if (unlikely(valueLen == 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid value", value);
|
||||
terrno = TSDB_CODE_TSC_INVALID_VALUE;
|
||||
return -1;
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (unlikely(valueLen > (TSDB_MAX_TAGS_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)) {
|
||||
terrno = TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
|
||||
return -1;
|
||||
return TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
|
||||
}
|
||||
|
||||
SSmlKv kv = {.key = key,
|
||||
|
@ -136,14 +131,15 @@ static int32_t smlProcessTagTelnet(SSmlHandle *info, char *data, char *sqlEnd){
|
|||
.length = valueLen,
|
||||
.keyEscaped = false,
|
||||
.valueEscaped = false};
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
if (taosArrayPush(preLineKV, &kv) == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (info->dataFormat && !isSmlTagAligned(info, cnt, &kv)) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
return -1;
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
return 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SSmlLineInfo *elements) {
|
||||
|
@ -156,13 +152,19 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
|||
if(info->dataFormat){
|
||||
ret = smlProcessSuperTable(info, elements);
|
||||
if(ret != 0){
|
||||
return terrno;
|
||||
if(info->reRun){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret = smlProcessTagTelnet(info, data, sqlEnd);
|
||||
if(ret != 0){
|
||||
return terrno;
|
||||
if (info->reRun){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = smlJoinMeasureTag(elements);
|
||||
|
|
|
@ -733,11 +733,15 @@ end:
|
|||
}
|
||||
|
||||
static void generateTimedTask(int64_t refId, int32_t type) {
|
||||
tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, refId);
|
||||
tmq_t* tmq;
|
||||
int8_t* pTaskType;
|
||||
int32_t code;
|
||||
|
||||
tmq = taosAcquireRef(tmqMgmt.rsetId, refId);
|
||||
if (tmq == NULL) return;
|
||||
|
||||
int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t), DEF_QITEM, 0);
|
||||
if (pTaskType != NULL){
|
||||
code = taosAllocateQitem(sizeof(int8_t), DEF_QITEM, 0, (void**)&pTaskType);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
*pTaskType = type;
|
||||
if (taosWriteQitem(tmq->delayedTask, pTaskType) == 0) {
|
||||
tsem2_post(&tmq->rspSem);
|
||||
|
@ -890,7 +894,12 @@ static void defaultCommitCbFn(tmq_t* pTmq, int32_t code, void* param) {
|
|||
}
|
||||
|
||||
int32_t tmqHandleAllDelayedTask(tmq_t* pTmq) {
|
||||
STaosQall* qall = taosAllocateQall();
|
||||
STaosQall* qall;
|
||||
int32_t code;
|
||||
|
||||
code = taosAllocateQall(&qall);
|
||||
if (code) return code;
|
||||
|
||||
taosReadAllQitems(pTmq->delayedTask, qall);
|
||||
|
||||
int32_t numOfItems = taosQallItemSize(qall);
|
||||
|
@ -914,7 +923,8 @@ int32_t tmqHandleAllDelayedTask(tmq_t* pTmq) {
|
|||
asyncCommitAllOffsets(pTmq, pCallbackFn, pTmq->commitCbUserParam);
|
||||
tscDebug("consumer:0x%" PRIx64 " next commit to vnode(s) in %.2fs", pTmq->consumerId,
|
||||
pTmq->autoCommitInterval / 1000.0);
|
||||
taosTmrReset(tmqAssignDelayedCommitTask, pTmq->autoCommitInterval, (void*)(pTmq->refId), tmqMgmt.timer, &pTmq->commitTimer);
|
||||
taosTmrReset(tmqAssignDelayedCommitTask, pTmq->autoCommitInterval, (void*)(pTmq->refId), tmqMgmt.timer,
|
||||
&pTmq->commitTimer);
|
||||
} else {
|
||||
tscError("consumer:0x%" PRIx64 " invalid task type:%d", pTmq->consumerId, *pTaskType);
|
||||
}
|
||||
|
@ -1101,6 +1111,8 @@ void tmqMgmtClose(void) {
|
|||
if (errstr != NULL) snprintf(errstr, errstrLen, MSG);
|
||||
|
||||
tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||
int32_t code;
|
||||
|
||||
if (conf == NULL) {
|
||||
SET_ERROR_MSG_TMQ("configure is null")
|
||||
return NULL;
|
||||
|
@ -1124,12 +1136,31 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
const char* pass = conf->pass == NULL ? TSDB_DEFAULT_PASS : conf->pass;
|
||||
|
||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||
pTmq->mqueue = taosOpenQueue();
|
||||
pTmq->delayedTask = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
code = taosOpenQueue(&pTmq->mqueue);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
SET_ERROR_MSG_TMQ("open queue failed")
|
||||
goto _failed;
|
||||
}
|
||||
|
||||
if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL ||
|
||||
conf->groupId[0] == 0) {
|
||||
code = taosOpenQueue(&pTmq->delayedTask);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
SET_ERROR_MSG_TMQ("open delayed task queue failed")
|
||||
goto _failed;
|
||||
}
|
||||
|
||||
code = taosAllocateQall(&pTmq->qall);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
SET_ERROR_MSG_TMQ("allocate qall failed")
|
||||
goto _failed;
|
||||
}
|
||||
|
||||
if (conf->groupId[0] == 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
SET_ERROR_MSG_TMQ("malloc tmq element failed or group is empty")
|
||||
|
@ -1315,7 +1346,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
// init ep timer
|
||||
tmq->epTimer = taosTmrStart(tmqAssignAskEpTask, DEFAULT_ASKEP_INTERVAL, (void*)(tmq->refId), tmqMgmt.timer);
|
||||
// init auto commit timer
|
||||
tmq->commitTimer = taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, (void*)(tmq->refId), tmqMgmt.timer);
|
||||
tmq->commitTimer =
|
||||
taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, (void*)(tmq->refId), tmqMgmt.timer);
|
||||
|
||||
FAIL:
|
||||
taosArrayDestroyP(req.topicNames, taosMemoryFree);
|
||||
|
@ -1381,11 +1413,11 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
goto FAIL;
|
||||
}
|
||||
|
||||
SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM, 0);
|
||||
if (pRspWrapper == NULL) {
|
||||
SMqPollRspWrapper* pRspWrapper;
|
||||
code = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM, 0, (void**)&pRspWrapper);
|
||||
if (code) {
|
||||
tscWarn("consumer:0x%" PRIx64 " msg discard from vgId:%d, since out of memory", tmq->consumerId, vgId);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -2600,9 +2632,9 @@ int32_t askEpCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
doUpdateLocalEp(tmq, head->epoch, &rsp);
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
} else {
|
||||
SMqAskEpRspWrapper* pWrapper = taosAllocateQitem(sizeof(SMqAskEpRspWrapper), DEF_QITEM, 0);
|
||||
if (pWrapper == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SMqAskEpRspWrapper* pWrapper;
|
||||
code = taosAllocateQitem(sizeof(SMqAskEpRspWrapper), DEF_QITEM, 0, (void**)&pWrapper);
|
||||
if (code) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,13 +40,16 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
msgBuf.len = 256;
|
||||
SSmlLineInfo elements = {0};
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(NULL);
|
||||
SSmlHandle *info = nullptr;
|
||||
int32_t code = smlBuildSmlInfo(nullptr, &info);
|
||||
ASSERT_EQ(code, 0);
|
||||
info->protocol = TSDB_SML_LINE_PROTOCOL;
|
||||
info->dataFormat = false;
|
||||
// case 1
|
||||
char *tmp = "\\,st,t1=3,t2=4,t3=t3 c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 1626006833639000000 ,32,c=3";
|
||||
char *sql = (char *)taosMemoryCalloc(256, 1);
|
||||
memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
ASSERT_NE(sql, nullptr);
|
||||
(void)memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
int ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(elements.measure, sql);
|
||||
|
@ -62,22 +65,22 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
|
||||
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 1 + elements.colsLen + 1);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = NULL;
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 2 false
|
||||
tmp = "st,t1=3,t2=4,t3=t3 c1=3i64,c3=\"passit hello,c1=2,c2=false,c4=4f64 1626006833639000000";
|
||||
memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
(void)memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_NE(ret, 0);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = NULL;
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 4 tag is null
|
||||
tmp = "st, c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 1626006833639000000";
|
||||
memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
(void)memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(elements.measure, sql);
|
||||
|
@ -92,13 +95,13 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
|
||||
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 1 + elements.colsLen + 1);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = NULL;
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 5 tag is null
|
||||
tmp = " st c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 1626006833639000000 ";
|
||||
memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
(void)memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(elements.measure, sql + 1);
|
||||
|
@ -112,36 +115,36 @@ TEST(testCase, smlParseInfluxString_Test) {
|
|||
|
||||
ASSERT_EQ(elements.timestamp, sql + 1 + elements.measureTagsLen + 3 + elements.colsLen + 2);
|
||||
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = NULL;
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 6
|
||||
tmp = " st c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 ";
|
||||
memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
(void)memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_EQ(ret, 0);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = NULL;
|
||||
smlClearForRerun(info);
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
ASSERT_EQ(smlClearForRerun(info), 0);
|
||||
|
||||
// case 7
|
||||
tmp = " st , ";
|
||||
memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
(void)memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_NE(ret, 0);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = NULL;
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
// case 8 false
|
||||
tmp = ", st , ";
|
||||
memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
(void)memcpy(sql, tmp, strlen(tmp) + 1);
|
||||
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
|
||||
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
|
||||
ASSERT_NE(ret, 0);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = NULL;
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
elements.colArray = nullptr;
|
||||
|
||||
taosMemoryFree(sql);
|
||||
smlDestroyInfo(info);
|
||||
|
@ -228,7 +231,9 @@ TEST(testCase, smlParseCols_Error_Test) {
|
|||
"escape_test,tag1=\"tag1_value\",tag2=\"tag2_value\" col0=\"co\"l\"0_value\",col1=\"col1_value\" 1680918783010000000"
|
||||
};
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(NULL);
|
||||
SSmlHandle *info = nullptr;
|
||||
int32_t code = smlBuildSmlInfo(nullptr, &info);
|
||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
info->protocol = TSDB_SML_LINE_PROTOCOL;
|
||||
info->dataFormat = false;
|
||||
for (int i = 0; i < sizeof(data) / sizeof(data[0]); i++) {
|
||||
|
@ -238,13 +243,14 @@ TEST(testCase, smlParseCols_Error_Test) {
|
|||
msgBuf.len = 256;
|
||||
int32_t len = strlen(data[i]);
|
||||
char *sql = (char *)taosMemoryCalloc(256, 1);
|
||||
memcpy(sql, data[i], len + 1);
|
||||
ASSERT_NE(sql, nullptr);
|
||||
(void)memcpy(sql, data[i], len + 1);
|
||||
SSmlLineInfo elements = {0};
|
||||
int32_t ret = smlParseInfluxString(info, sql, sql + len, &elements);
|
||||
// printf("i:%d\n", i);
|
||||
ASSERT_NE(ret, TSDB_CODE_SUCCESS);
|
||||
taosMemoryFree(sql);
|
||||
taosArrayDestroy(elements.colArray);
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
}
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
|
@ -254,7 +260,9 @@ TEST(testCase, smlParseCols_Test) {
|
|||
SSmlMsgBuf msgBuf;
|
||||
msgBuf.buf = msg;
|
||||
msgBuf.len = 256;
|
||||
SSmlHandle *info = smlBuildSmlInfo(NULL);
|
||||
SSmlHandle *info = nullptr;
|
||||
int32_t code = smlBuildSmlInfo(nullptr, &info);
|
||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
info->protocol = TSDB_SML_LINE_PROTOCOL;
|
||||
info->dataFormat = false;
|
||||
SSmlLineInfo elements = {0};
|
||||
|
@ -267,7 +275,8 @@ TEST(testCase, smlParseCols_Test) {
|
|||
"cboolf=f,cnch_=l\"iuwq\" 1626006833639000000";
|
||||
int32_t len = strlen(data);
|
||||
char *sql = (char *)taosMemoryCalloc(1024, 1);
|
||||
memcpy(sql, data, len + 1);
|
||||
ASSERT_NE(sql, nullptr);
|
||||
(void)memcpy(sql, data, len + 1);
|
||||
int32_t ret = smlParseInfluxString(info, sql, sql + len, &elements);
|
||||
ASSERT_EQ(ret, TSDB_CODE_SUCCESS);
|
||||
int32_t size = taosArrayGetSize(elements.colArray);
|
||||
|
@ -275,6 +284,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// binary
|
||||
SSmlKv *kv = (SSmlKv *)taosArrayGet(elements.colArray, 1);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cb=in", 5), 0);
|
||||
ASSERT_EQ(kv->keyLen, 5);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BINARY);
|
||||
|
@ -285,6 +295,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// nchar
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 2);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cnch", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
|
||||
|
@ -293,6 +304,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// bool
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 3);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cbool", 5), 0);
|
||||
ASSERT_EQ(kv->keyLen, 5);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BOOL);
|
||||
|
@ -301,6 +313,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// double
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 4);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cf64", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_DOUBLE);
|
||||
|
@ -310,6 +323,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// float
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 5);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cf64_", 5), 0);
|
||||
ASSERT_EQ(kv->keyLen, 5);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_DOUBLE);
|
||||
|
@ -319,6 +333,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// float
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 6);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cf32", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_FLOAT);
|
||||
|
@ -328,6 +343,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// tiny int
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 7);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci8", 3), 0);
|
||||
ASSERT_EQ(kv->keyLen, 3);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_TINYINT);
|
||||
|
@ -336,6 +352,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// unsigned tiny int
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 8);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cu8", 3), 0);
|
||||
ASSERT_EQ(kv->keyLen, 3);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_UTINYINT);
|
||||
|
@ -344,6 +361,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// small int
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 9);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci16", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_SMALLINT);
|
||||
|
@ -352,6 +370,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// unsigned smallint
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 10);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cu16", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_USMALLINT);
|
||||
|
@ -360,6 +379,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// int
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 11);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci32", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_INT);
|
||||
|
@ -368,6 +388,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// unsigned int
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 12);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cu32", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_UINT);
|
||||
|
@ -376,6 +397,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// bigint
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 13);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci64", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BIGINT);
|
||||
|
@ -384,6 +406,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// bigint
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 14);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "ci", 2), 0);
|
||||
ASSERT_EQ(kv->keyLen, 2);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BIGINT);
|
||||
|
@ -392,6 +415,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// unsigned bigint
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 15);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cu64", 4), 0);
|
||||
ASSERT_EQ(kv->keyLen, 4);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_UBIGINT);
|
||||
|
@ -400,6 +424,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// bool
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 16);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cbooltrue", 9), 0);
|
||||
ASSERT_EQ(kv->keyLen, 9);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BOOL);
|
||||
|
@ -408,6 +433,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// bool
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 17);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cboolt", 6), 0);
|
||||
ASSERT_EQ(kv->keyLen, 6);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BOOL);
|
||||
|
@ -416,6 +442,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// bool
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 18);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cboolf", 6), 0);
|
||||
ASSERT_EQ(kv->keyLen, 6);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BOOL);
|
||||
|
@ -424,13 +451,14 @@ TEST(testCase, smlParseCols_Test) {
|
|||
|
||||
// nchar
|
||||
kv = (SSmlKv *)taosArrayGet(elements.colArray, 19);
|
||||
ASSERT_NE(kv, nullptr);
|
||||
ASSERT_EQ(strncasecmp(kv->key, "cnch_", 5), 0);
|
||||
ASSERT_EQ(kv->keyLen, 5);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
|
||||
ASSERT_EQ(kv->length, 4);
|
||||
ASSERT_EQ(strncasecmp(kv->value, "iuwq", 4), 0);
|
||||
|
||||
taosArrayDestroy(elements.colArray);
|
||||
(void)taosArrayDestroy(elements.colArray);
|
||||
taosMemoryFree(sql);
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
|
@ -471,7 +499,9 @@ TEST(testCase, smlParseNumber_Test) {
|
|||
}
|
||||
|
||||
TEST(testCase, smlParseTelnetLine_error_Test) {
|
||||
SSmlHandle *info = smlBuildSmlInfo(NULL);
|
||||
SSmlHandle *info = nullptr;
|
||||
int32_t code = smlBuildSmlInfo(nullptr, &info);
|
||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
info->dataFormat = false;
|
||||
info->protocol = TSDB_SML_TELNET_PROTOCOL;
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
@ -509,7 +539,9 @@ TEST(testCase, smlParseTelnetLine_error_Test) {
|
|||
}
|
||||
|
||||
TEST(testCase, smlParseTelnetLine_Test) {
|
||||
SSmlHandle *info = smlBuildSmlInfo(NULL);
|
||||
SSmlHandle *info = nullptr;
|
||||
int32_t code = smlBuildSmlInfo(nullptr, &info);
|
||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
info->dataFormat = false;
|
||||
info->protocol = TSDB_SML_TELNET_PROTOCOL;
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
@ -528,7 +560,9 @@ TEST(testCase, smlParseTelnetLine_Test) {
|
|||
}
|
||||
|
||||
//TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) {
|
||||
// SSmlHandle *info = smlBuildSmlInfo(NULL);
|
||||
// SSmlHandle *info = nullptr;
|
||||
// int32_t code = smlBuildSmlInfo(nullptr, &info);
|
||||
// ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
// info->protocol = TSDB_SML_JSON_PROTOCOL;
|
||||
// ASSERT_NE(info, nullptr);
|
||||
//
|
||||
|
@ -568,7 +602,7 @@ TEST(testCase, smlParseNumber_performance_Test) {
|
|||
for (int j = 0; j < 10000000; ++j) {
|
||||
kv.value = str[i];
|
||||
kv.length = strlen(str[i]);
|
||||
smlParseNumber(&kv, &msgBuf);
|
||||
(void)smlParseNumber(&kv, &msgBuf); //ignore result
|
||||
}
|
||||
printf("smlParseNumber:%s cost:%" PRId64, str[i], taosGetTimestampUs() - t1);
|
||||
printf("\n");
|
||||
|
@ -576,7 +610,7 @@ TEST(testCase, smlParseNumber_performance_Test) {
|
|||
for (int j = 0; j < 10000000; ++j) {
|
||||
kv.value = str[i];
|
||||
kv.length = strlen(str[i]);
|
||||
smlParseNumberOld(&kv, &msgBuf);
|
||||
(void)smlParseNumberOld(&kv, &msgBuf); //ignore result
|
||||
}
|
||||
printf("smlParseNumberOld:%s cost:%" PRId64, str[i], taosGetTimestampUs() - t2);
|
||||
printf("\n\n");
|
||||
|
|
|
@ -2492,7 +2492,10 @@ int32_t buildCtbNameByGroupIdImpl(const char* stbFullName, uint64_t groupId, cha
|
|||
RandTableName rname = {
|
||||
.tags = tags, .stbFullName = stbFullName, .stbFullNameLen = strlen(stbFullName), .ctbShortName = cname};
|
||||
|
||||
buildChildTableName(&rname);
|
||||
int32_t code = buildChildTableName(&rname);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
return code;
|
||||
}
|
||||
taosArrayDestroy(tags);
|
||||
|
||||
if ((rname.ctbShortName && rname.ctbShortName[0]) == 0) {
|
||||
|
|
|
@ -504,7 +504,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
|||
if (cfgAddString(pCfg, "secondEp", "", CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "fqdn", defaultFqdn, CFG_SCOPE_SERVER, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056, CFG_SCOPE_SERVER, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "tempDir", tsTempDir, CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "tempDir", tsTempDir, CFG_SCOPE_BOTH, CFG_DYN_NONE) != 0) return -1;
|
||||
if (cfgAddFloat(pCfg, "minimalTmpDirGB", 1.0f, 0.001f, 10000000, CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "shellActivityTimer", tsShellActivityTimer, 1, 120, CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0)
|
||||
return -1;
|
||||
|
|
|
@ -9258,6 +9258,12 @@ void tOffsetDestroy(void *param) {
|
|||
taosMemoryFreeClear(pVal->primaryKey.pData);
|
||||
}
|
||||
}
|
||||
|
||||
void tDeleteSTqOffset(void *param) {
|
||||
STqOffset *pVal = (STqOffset *)param;
|
||||
tOffsetDestroy(&pVal->val);
|
||||
}
|
||||
|
||||
int32_t tEncodeSTqOffset(SEncoder *pEncoder, const STqOffset *pOffset) {
|
||||
if (tEncodeSTqOffsetVal(pEncoder, &pOffset->val) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pOffset->subKey) < 0) return -1;
|
||||
|
@ -9297,12 +9303,12 @@ int32_t tEncodeSTqCheckInfo(SEncoder *pEncoder, const STqCheckInfo *pInfo) {
|
|||
int32_t tDecodeSTqCheckInfo(SDecoder *pDecoder, STqCheckInfo *pInfo) {
|
||||
if (tDecodeCStrTo(pDecoder, pInfo->topic) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pInfo->ntbUid) < 0) return -1;
|
||||
int32_t sz;
|
||||
int32_t sz = 0;
|
||||
if (tDecodeI32(pDecoder, &sz) < 0) return -1;
|
||||
pInfo->colIdList = taosArrayInit(sz, sizeof(int16_t));
|
||||
if (pInfo->colIdList == NULL) return -1;
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
int16_t colId;
|
||||
int16_t colId = 0;
|
||||
if (tDecodeI16(pDecoder, &colId) < 0) return -1;
|
||||
taosArrayPush(pInfo->colIdList, &colId);
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName
|
|||
int32_t tNameExtractFullName(const SName* name, char* dst) {
|
||||
// invalid full name format, abort
|
||||
if (!tNameIsValid(name)) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
int32_t len = snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname);
|
||||
|
@ -154,8 +154,7 @@ int32_t tNameGetDbName(const SName* name, char* dst) {
|
|||
const char* tNameGetDbNameP(const SName* name) { return &name->dbname[0]; }
|
||||
|
||||
int32_t tNameGetFullDbName(const SName* name, char* dst) {
|
||||
snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname);
|
||||
return 0;
|
||||
return snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname);
|
||||
}
|
||||
|
||||
bool tNameIsEmpty(const SName* name) { return name->type == 0 || name->acctId == 0; }
|
||||
|
@ -293,17 +292,19 @@ static int compareKv(const void* p1, const void* p2) {
|
|||
/*
|
||||
* use stable name and tags to grearate child table name
|
||||
*/
|
||||
void buildChildTableName(RandTableName* rName) {
|
||||
int32_t buildChildTableName(RandTableName* rName) {
|
||||
SStringBuilder sb = {0};
|
||||
taosStringBuilderAppendStringLen(&sb, rName->stbFullName, rName->stbFullNameLen);
|
||||
if (sb.buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
taosArraySort(rName->tags, compareKv);
|
||||
for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) {
|
||||
taosStringBuilderAppendChar(&sb, ',');
|
||||
SSmlKv* tagKv = taosArrayGet(rName->tags, j);
|
||||
if(tagKv == NULL) {
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
taosStringBuilderAppendStringLen(&sb, tagKv->key, tagKv->keyLen);
|
||||
taosStringBuilderAppendChar(&sb, '=');
|
||||
if (IS_VAR_DATA_TYPE(tagKv->type)) {
|
||||
|
@ -323,8 +324,9 @@ void buildChildTableName(RandTableName* rName) {
|
|||
rName->ctbShortName[0] = 't';
|
||||
rName->ctbShortName[1] = '_';
|
||||
for (int i = 0; i < 16; i++) {
|
||||
sprintf(temp, "%02x", context.digest[i]);
|
||||
strcat(rName->ctbShortName, temp);
|
||||
(void)sprintf(temp, "%02x", context.digest[i]);
|
||||
(void)strcat(rName->ctbShortName, temp);
|
||||
}
|
||||
taosStringBuilderDestroy(&sb);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -153,6 +153,8 @@ int32_t mmPutMsgToFetchQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
int32_t code;
|
||||
|
||||
SSingleWorker *pWorker = NULL;
|
||||
switch (qtype) {
|
||||
case WRITE_QUEUE:
|
||||
|
@ -181,13 +183,15 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
}
|
||||
|
||||
if (pWorker == NULL) return -1;
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
||||
if (pMsg == NULL) return -1;
|
||||
SRpcMsg *pMsg;
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) return code;
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
pRpc->pCont = NULL;
|
||||
|
||||
dTrace("msg:%p, is created and will put into %s queue, type:%s len:%d", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType), pRpc->contLen);
|
||||
int32_t code = mmPutMsgToWorker(pMgmt, pWorker, pMsg);
|
||||
dTrace("msg:%p, is created and will put into %s queue, type:%s len:%d", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType),
|
||||
pRpc->contLen);
|
||||
code = mmPutMsgToWorker(pMgmt, pWorker, pMsg);
|
||||
if (code != 0) {
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -58,8 +58,11 @@ int32_t qmPutNodeMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
||||
if (pMsg == NULL) return -1;
|
||||
int32_t code;
|
||||
SRpcMsg *pMsg;
|
||||
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) return code;
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
pRpc->pCont = NULL;
|
||||
|
||||
|
|
|
@ -126,8 +126,11 @@ void smStopWorker(SSnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
||||
if (pMsg == NULL) {
|
||||
int32_t code;
|
||||
SRpcMsg *pMsg;
|
||||
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
|
|
|
@ -377,14 +377,14 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pMgmt->createLock);
|
||||
//taosThreadMutexLock(&pMgmt->createLock);
|
||||
code = vmWriteVnodeListToFile(pMgmt);
|
||||
if (code != 0) {
|
||||
code = terrno != 0 ? terrno : code;
|
||||
taosThreadMutexUnlock(&pMgmt->createLock);
|
||||
//taosThreadMutexUnlock(&pMgmt->createLock);
|
||||
goto _OVER;
|
||||
}
|
||||
taosThreadMutexUnlock(&pMgmt->createLock);
|
||||
//taosThreadMutexUnlock(&pMgmt->createLock);
|
||||
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
|
@ -988,7 +988,7 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TRIM, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_S3MIGRATE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE, vmPutMsgToMultiMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_VNODE_TYPE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -311,6 +311,7 @@ int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
int32_t code;
|
||||
if (pRpc->contLen < sizeof(SMsgHead)) {
|
||||
dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
|
||||
pRpc->contLen);
|
||||
|
@ -320,8 +321,9 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
}
|
||||
|
||||
EQItype itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg *pMsg;
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
|
@ -335,7 +337,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
pRpc->pCont = NULL;
|
||||
|
||||
int32_t code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
|
||||
code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
|
||||
if (code != 0) {
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -210,8 +210,8 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
pRpc->info.wrapper = pWrapper;
|
||||
|
||||
EQItype itype = IsReq(pRpc) ? RPC_QITEM : DEF_QITEM; // rsp msg is not restricted by tsRpcQueueMemoryUsed
|
||||
pMsg = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen);
|
||||
if (pMsg == NULL) goto _OVER;
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) goto _OVER;
|
||||
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
dGTrace("msg:%p, is created, type:%s handle:%p len:%d", pMsg, TMSG_INFO(pRpc->msgType), pMsg->info.handle,
|
||||
|
|
|
@ -54,6 +54,7 @@ int32_t mndInitAcct(SMnode *pMnode) {
|
|||
void mndCleanupAcct(SMnode *pMnode) {}
|
||||
|
||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SAcctObj acctObj = {0};
|
||||
tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
|
||||
acctObj.createdTime = taosGetTimestampMs();
|
||||
|
@ -76,7 +77,10 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
};
|
||||
|
||||
SSdbRaw *pRaw = mndAcctActionEncode(&acctObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
if (pRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("acct:%s, will be created when deploying, raw:%p", acctObj.acct, pRaw);
|
||||
|
@ -84,21 +88,24 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-acct");
|
||||
if (pTrans == NULL) {
|
||||
sdbFreeRaw(pRaw);
|
||||
mError("acct:%s, failed to create since %s", acctObj.acct, terrstr());
|
||||
return -1;
|
||||
code = terrno;
|
||||
mError("acct:%s, failed to create since %s", acctObj.acct, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, used to create acct:%s", pTrans->id, acctObj.acct);
|
||||
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
|
||||
code = mndTransAppendCommitlog(pTrans, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, tstrerror(code));
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -216,31 +223,36 @@ static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessCreateAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_CREATE_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_CREATE_ACCT);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_ALTER_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_ALTER_ACCT);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_DROP_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_DROP_ACCT)) != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
|
@ -57,6 +57,7 @@ static int32_t mndArbCheckToken(const char *token1, const char *token2) {
|
|||
}
|
||||
|
||||
int32_t mndInitArbGroup(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SSdbTable table = {
|
||||
.sdbType = SDB_ARBGROUP,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
|
@ -78,6 +79,10 @@ int32_t mndInitArbGroup(SMnode *pMnode) {
|
|||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_ARBGROUP, mndCancelGetNextArbGroup);
|
||||
|
||||
arbUpdateHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
if (arbUpdateHash == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
@ -248,50 +253,74 @@ _OVER:
|
|||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendRedolog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupUndoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pUndoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
if (pUndoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendUndolog(pTrans, pUndoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupCommitLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw) != 0)) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropArbGroupPrepareLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendRedolog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropArbGroupCommitLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -343,6 +372,7 @@ static int32_t mndSendArbHeartBeatReq(SDnodeObj *pDnode, char *arbToken, int64_t
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SArbGroup *pArbGroup = NULL;
|
||||
|
@ -377,7 +407,7 @@ static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-hb timer");
|
||||
pIter = taosHashIterate(pDnodeHash, NULL);
|
||||
while (pIter) {
|
||||
|
@ -386,7 +416,7 @@ static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
|||
pIter = taosHashIterate(pDnodeHash, pIter);
|
||||
}
|
||||
taosHashCleanup(pDnodeHash);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int64_t nowMs = taosGetTimestampMs();
|
||||
|
@ -447,6 +477,7 @@ static void *mndBuildArbCheckSyncReq(int32_t *pContLen, int32_t vgId, char *arbT
|
|||
|
||||
static int32_t mndSendArbCheckSyncReq(SMnode *pMnode, int32_t vgId, char *arbToken, int64_t term, char *member0Token,
|
||||
char *member1Token) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = 0;
|
||||
void *pHead = mndBuildArbCheckSyncReq(&contLen, vgId, arbToken, term, member0Token, member1Token);
|
||||
if (!pHead) {
|
||||
|
@ -459,10 +490,12 @@ static int32_t mndSendArbCheckSyncReq(SMnode *pMnode, int32_t vgId, char *arbTok
|
|||
if (epSet.numOfEps == 0) {
|
||||
mError("vgId:%d, failed to send check-sync request since no epSet found", vgId);
|
||||
rpcFreeCont(pHead);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
if (code != 0) {
|
||||
mError("vgId:%d, failed to send check-sync request since 0x%x", vgId, code);
|
||||
} else {
|
||||
|
@ -502,11 +535,14 @@ static void *mndBuildArbSetAssignedLeaderReq(int32_t *pContLen, int32_t vgId, ch
|
|||
|
||||
static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, int32_t vgId, char *arbToken,
|
||||
int64_t term, char *memberToken) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = 0;
|
||||
void *pHead = mndBuildArbSetAssignedLeaderReq(&contLen, vgId, arbToken, term, memberToken);
|
||||
if (!pHead) {
|
||||
mError("vgId:%d, failed to build set-assigned request", vgId);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_SYNC_SET_ASSIGNED_LEADER, .pCont = pHead, .contLen = contLen};
|
||||
|
||||
|
@ -514,9 +550,11 @@ static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, i
|
|||
if (epSet.numOfEps == 0) {
|
||||
mError("dnodeId:%d vgId:%d, failed to send arb-set-assigned request to dnode since no epSet found", dnodeId, vgId);
|
||||
rpcFreeCont(pHead);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
int32_t code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
if (code != 0) {
|
||||
mError("dnodeId:%d vgId:%d, failed to send arb-set-assigned request to dnode since 0x%x", dnodeId, vgId, code);
|
||||
} else {
|
||||
|
@ -526,6 +564,7 @@ static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, i
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SArbGroup *pArbGroup = NULL;
|
||||
|
@ -533,14 +572,16 @@ static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
|
|||
void *pIter = NULL;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-check-sync timer");
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
int64_t term = mndGetTerm(pMnode);
|
||||
if (term < 0) {
|
||||
mError("arb failed to get term since %s", terrstr());
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int64_t roleTimeMs = mndGetRoleTimeMs(pMnode);
|
||||
|
@ -747,13 +788,13 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
||||
int ret = -1;
|
||||
int code = -1;
|
||||
size_t sz = 0;
|
||||
|
||||
SMArbUpdateGroupBatchReq req = {0};
|
||||
if (tDeserializeSMArbUpdateGroupBatchReq(pReq->pCont, pReq->contLen, &req) != 0) {
|
||||
if ((code = tDeserializeSMArbUpdateGroupBatchReq(pReq->pCont, pReq->contLen, &req)) != 0) {
|
||||
mError("arb failed to decode arb-update-group request");
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
|
@ -789,7 +830,7 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
|||
|
||||
mndTransAddArbGroupId(pTrans, newGroup.vgId);
|
||||
|
||||
if (mndSetCreateArbGroupCommitLogs(pTrans, &newGroup) != 0) {
|
||||
if ((code = mndSetCreateArbGroupCommitLogs(pTrans, &newGroup)) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, trans:%d, since %s", newGroup.vgId, pTrans->id,
|
||||
terrstr());
|
||||
goto _OVER;
|
||||
|
@ -803,13 +844,13 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
|||
sdbRelease(pMnode->pSdb, pOldGroup);
|
||||
}
|
||||
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
if ((code = mndTransCheckConflict(pMnode, pTrans)) != 0) goto _OVER;
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (ret != 0) {
|
||||
if (code != 0) {
|
||||
// failed to update arbgroup
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
SMArbUpdateGroup *pUpdateGroup = taosArrayGet(req.updateArray, i);
|
||||
|
@ -819,7 +860,7 @@ _OVER:
|
|||
|
||||
mndTransDrop(pTrans);
|
||||
tFreeSMArbUpdateGroupBatchReq(&req);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static void mndArbGroupDupObj(SArbGroup *pGroup, SArbGroup *pNew) {
|
||||
|
@ -841,10 +882,11 @@ static void mndArbGroupResetAssignedLeader(SArbGroup *pGroup) {
|
|||
}
|
||||
|
||||
static int32_t mndArbGroupUpdateTrans(SMnode *pMnode, SArbGroup *pNew) {
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_ARBGROUP, NULL, "update-arbgroup");
|
||||
if (pTrans == NULL) {
|
||||
mError("failed to update arbgroup in create trans, vgId:%d, since %s", pNew->vgId, terrstr());
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -854,23 +896,22 @@ static int32_t mndArbGroupUpdateTrans(SMnode *pMnode, SArbGroup *pNew) {
|
|||
pNew->assignedLeader.token, pNew->assignedLeader.acked);
|
||||
|
||||
mndTransAddArbGroupId(pTrans, pNew->vgId);
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
ret = -1;
|
||||
if ((code = mndTransCheckConflict(pMnode, pTrans)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateArbGroupCommitLogs(pTrans, pNew) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, since %s", pNew->vgId, terrstr());
|
||||
if ((code = mndSetCreateArbGroupCommitLogs(pTrans, pNew)) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, since %s", pNew->vgId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool mndUpdateArbGroupByHeartBeat(SArbGroup *pGroup, SVArbHbRspMember *pRspMember, int64_t nowMs, int32_t dnodeId,
|
||||
|
@ -993,11 +1034,13 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndUpdateArbSync(SMnode *pMnode, int32_t vgId, char *member0Token, char *member1Token, bool newIsSync) {
|
||||
int32_t code = 0;
|
||||
SArbGroup *pGroup = sdbAcquire(pMnode->pSdb, SDB_ARBGROUP, &vgId);
|
||||
if (pGroup == NULL) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
mInfo("failed to update arb sync, vgId:%d not found", vgId);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
|
@ -1018,38 +1061,36 @@ static int32_t mndProcessArbHbRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-hb response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbHeartBeatRsp arbHbRsp = {0};
|
||||
if (tDeserializeSVArbHeartBeatRsp(pRsp->pCont, pRsp->contLen, &arbHbRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbHeartBeatRsp(pRsp->pCont, pRsp->contLen, &arbHbRsp)) != 0) {
|
||||
mInfo("arb hb-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, arbHbRsp.arbToken) != 0) {
|
||||
mInfo("arb hearbeat skip update for dnodeId:%d, arb token mismatch, local:[%s] msg:[%s]", arbHbRsp.dnodeId,
|
||||
arbToken, arbHbRsp.arbToken);
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
code = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
(void)mndUpdateArbHeartBeat(pMnode, arbHbRsp.dnodeId, arbHbRsp.hbMembers);
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbHeartBeatRsp(&arbHbRsp);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
||||
|
@ -1058,27 +1099,25 @@ static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-check-sync response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbCheckSyncRsp syncRsp = {0};
|
||||
if (tDeserializeSVArbCheckSyncRsp(pRsp->pCont, pRsp->contLen, &syncRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbCheckSyncRsp(pRsp->pCont, pRsp->contLen, &syncRsp)) != 0) {
|
||||
mInfo("arb check-sync-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
if (pRsp->code == TSDB_CODE_MND_ARB_TOKEN_MISMATCH) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, syncRsp.arbToken) != 0) {
|
||||
|
@ -1089,16 +1128,16 @@ static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
|||
}
|
||||
|
||||
bool newIsSync = (syncRsp.errCode == TSDB_CODE_SUCCESS);
|
||||
if (mndUpdateArbSync(pMnode, syncRsp.vgId, syncRsp.member0Token, syncRsp.member1Token, newIsSync) != 0) {
|
||||
if ((code = mndUpdateArbSync(pMnode, syncRsp.vgId, syncRsp.member0Token, syncRsp.member1Token, newIsSync)) != 0) {
|
||||
mInfo("failed to update arb sync for vgId:%d, since:%s", syncRsp.vgId, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbCheckSyncRsp(&syncRsp);
|
||||
return ret;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
bool mndUpdateArbGroupBySetAssignedLeader(SArbGroup *pGroup, int32_t vgId, char *memberToken, int32_t errcode,
|
||||
|
@ -1138,35 +1177,35 @@ static int32_t mndProcessArbSetAssignedLeaderRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-set-assigned response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbSetAssignedLeaderRsp setAssignedRsp = {0};
|
||||
if (tDeserializeSVArbSetAssignedLeaderRsp(pRsp->pCont, pRsp->contLen, &setAssignedRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbSetAssignedLeaderRsp(pRsp->pCont, pRsp->contLen, &setAssignedRsp)) != 0) {
|
||||
mInfo("arb set-assigned-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, setAssignedRsp.arbToken) != 0) {
|
||||
mInfo("skip update arb assigned for vgId:%d, arb token mismatch, local:[%s] msg:[%s]", setAssignedRsp.vgId,
|
||||
arbToken, setAssignedRsp.arbToken);
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
code = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SArbGroup *pGroup = mndAcquireArbGroup(pMnode, setAssignedRsp.vgId);
|
||||
if (!pGroup) {
|
||||
mError("failed to set arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, terrstr());
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -1174,17 +1213,17 @@ static int32_t mndProcessArbSetAssignedLeaderRsp(SRpcMsg *pRsp) {
|
|||
bool updateAssigned = mndUpdateArbGroupBySetAssignedLeader(pGroup, setAssignedRsp.vgId, setAssignedRsp.memberToken,
|
||||
pRsp->code, &newGroup);
|
||||
if (updateAssigned) {
|
||||
if (mndPullupArbUpdateGroup(pMnode, &newGroup) != 0) {
|
||||
mInfo("failed to pullup update arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, terrstr());
|
||||
if ((code = mndPullupArbUpdateGroup(pMnode, &newGroup)) != 0) {
|
||||
mInfo("failed to pullup update arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbSetAssignedLeaderRsp(&setAssignedRsp);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveArbGroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "audit.h"
|
||||
#include "mndCluster.h"
|
||||
#include "audit.h"
|
||||
#include "mndGrant.h"
|
||||
#include "mndPrivilege.h"
|
||||
#include "mndShow.h"
|
||||
|
@ -61,11 +61,13 @@ int32_t mndInitCluster(SMnode *pMnode) {
|
|||
void mndCleanupCluster(SMnode *pMnode) {}
|
||||
|
||||
int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
SClusterObj *pCluster = sdbAcquire(pSdb, SDB_CLUSTER, &pMnode->clusterId);
|
||||
if (pCluster == NULL) {
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
tstrncpy(clusterName, pCluster->name, len);
|
||||
|
@ -247,7 +249,10 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
|||
mInfo("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
|
||||
|
||||
SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
if (pRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("cluster:%" PRId64 ", will be created when deploying, raw:%p", clusterObj.id, pRaw);
|
||||
|
@ -256,21 +261,22 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
|||
if (pTrans == NULL) {
|
||||
sdbFreeRaw(pRaw);
|
||||
mError("cluster:%" PRId64 ", failed to create since %s", clusterObj.id, terrstr());
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, used to create cluster:%" PRId64, pTrans->id, clusterObj.id);
|
||||
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -347,22 +353,33 @@ static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
mInfo("update cluster uptime to %d", clusterObj.upTime);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "update-uptime");
|
||||
if (pTrans == NULL) return -1;
|
||||
if (pTrans == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SSdbRaw *pCommitRaw = mndClusterActionEncode(&clusterObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
if (pCommitRaw == NULL) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -374,13 +391,12 @@ int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
|
|||
SMnode *pMnode = pReq->info.node;
|
||||
SMCfgClusterReq cfgReq = {0};
|
||||
if (tDeserializeSMCfgClusterReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mInfo("cluster: start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_CLUSTER) != 0) {
|
||||
code = terrno != 0 ? terrno : TSDB_CODE_MND_NO_RIGHTS;
|
||||
if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_CLUSTER)) != 0) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -410,17 +426,17 @@ int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
{ // audit
|
||||
auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql, TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1));
|
||||
auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
|
||||
TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1));
|
||||
}
|
||||
_exit:
|
||||
tFreeSMCfgClusterReq(&cfgReq);
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, terrstr());
|
||||
} else {
|
||||
mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) {
|
||||
|
|
|
@ -75,11 +75,11 @@ int32_t tDeserializeSCompactObj(void *buf, int32_t bufLen, SCompactObj *pObj) {
|
|||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tStartDecode(&decoder));
|
||||
|
||||
if (tDecodeI32(&decoder, &pObj->compactId) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pObj->dbname) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pObj->startTime) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactId));
|
||||
TAOS_CHECK_RETURN(tDecodeCStrTo(&decoder, pObj->dbname));
|
||||
TAOS_CHECK_RETURN(tDecodeI64(&decoder, &pObj->startTime));
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
|
@ -174,13 +174,10 @@ SSdbRow *mndCompactActionDecode(SSdbRaw *pRaw) {
|
|||
}
|
||||
SDB_GET_BINARY(pRaw, dataPos, buf, tlen, OVER);
|
||||
|
||||
if (tDeserializeSCompactObj(buf, tlen, pCompact) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
if ((terrno = tDeserializeSCompactObj(buf, tlen, pCompact)) < 0) {
|
||||
goto OVER;
|
||||
}
|
||||
|
||||
// taosInitRWLatch(&pView->lock);
|
||||
|
||||
OVER:
|
||||
taosMemoryFreeClear(buf);
|
||||
if (terrno != TSDB_CODE_SUCCESS) {
|
||||
|
@ -227,6 +224,7 @@ void mndReleaseCompact(SMnode *pMnode, SCompactObj *pCompact) {
|
|||
|
||||
// compact db
|
||||
int32_t mndAddCompactToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *pCompact, SDbObj *pDb, SCompactDbRsp *rsp) {
|
||||
int32_t code = 0;
|
||||
pCompact->compactId = tGenIdPI32();
|
||||
|
||||
strcpy(pCompact->dbname, pDb->name);
|
||||
|
@ -234,10 +232,14 @@ int32_t mndAddCompactToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *pCompac
|
|||
pCompact->startTime = taosGetTimestampMs();
|
||||
|
||||
SSdbRaw *pVgRaw = mndCompactActionEncode(pCompact);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendPrepareLog(pTrans, pVgRaw) != 0) {
|
||||
if (pVgRaw == NULL) {
|
||||
code = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendPrepareLog(pTrans, pVgRaw)) != 0) {
|
||||
sdbFreeRaw(pVgRaw);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
|
||||
|
@ -335,44 +337,62 @@ static void *mndBuildKillCompactReq(SMnode *pMnode, SVgObj *pVgroup, int32_t *pC
|
|||
|
||||
static int32_t mndAddKillCompactAction(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup, int32_t compactId,
|
||||
int32_t dnodeid) {
|
||||
int32_t code = 0;
|
||||
STransAction action = {0};
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, dnodeid);
|
||||
if (pDnode == NULL) return -1;
|
||||
if (pDnode == NULL) {
|
||||
code = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildKillCompactReq(pMnode, pVgroup, &contLen, compactId, dnodeid);
|
||||
if (pReq == NULL) return -1;
|
||||
if (pReq == NULL) {
|
||||
code = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_KILL_COMPACT;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndKillCompact(SMnode *pMnode, SRpcMsg *pReq, SCompactObj *pCompact) {
|
||||
int32_t code = 0;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB, pReq, "kill-compact");
|
||||
if (pTrans == NULL) {
|
||||
mError("compact:%" PRId32 ", failed to drop since %s", pCompact->compactId, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, used to kill compact:%" PRId32, pTrans->id, pCompact->compactId);
|
||||
|
||||
mndTransSetDbName(pTrans, pCompact->dbname, NULL);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndCompactActionEncode(pCompact);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
mndTransDrop(pTrans);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
|
@ -386,14 +406,20 @@ static int32_t mndKillCompact(SMnode *pMnode, SRpcMsg *pReq, SCompactObj *pCompa
|
|||
SVgObj *pVgroup = mndAcquireVgroup(pMnode, pDetail->vgId);
|
||||
if (pVgroup == NULL) {
|
||||
mError("trans:%d, failed to append redo action since %s", pTrans->id, terrstr());
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndAddKillCompactAction(pMnode, pTrans, pVgroup, pCompact->compactId, pDetail->dnodeId) != 0) {
|
||||
if ((code = mndAddKillCompactAction(pMnode, pTrans, pVgroup, pCompact->compactId, pDetail->dnodeId)) != 0) {
|
||||
mError("trans:%d, failed to append redo action since %s", pTrans->id, terrstr());
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndReleaseVgroup(pMnode, pVgroup);
|
||||
|
@ -412,10 +438,10 @@ static int32_t mndKillCompact(SMnode *pMnode, SRpcMsg *pReq, SCompactObj *pCompa
|
|||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -423,30 +449,27 @@ static int32_t mndKillCompact(SMnode *pMnode, SRpcMsg *pReq, SCompactObj *pCompa
|
|||
}
|
||||
|
||||
int32_t mndProcessKillCompactReq(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SKillCompactReq killCompactReq = {0};
|
||||
if (tDeserializeSKillCompactReq(pReq->pCont, pReq->contLen, &killCompactReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
|
||||
if ((code = tDeserializeSKillCompactReq(pReq->pCont, pReq->contLen, &killCompactReq)) != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mInfo("start to kill compact:%" PRId32, killCompactReq.compactId);
|
||||
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
int32_t code = -1;
|
||||
SCompactObj *pCompact = mndAcquireCompact(pMnode, killCompactReq.compactId);
|
||||
if (pCompact == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_COMPACT_ID;
|
||||
code = TSDB_CODE_MND_INVALID_COMPACT_ID;
|
||||
tFreeSKillCompactReq(&killCompactReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (0 != mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_COMPACT_DB)) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_COMPACT_DB), &lino, _OVER);
|
||||
|
||||
if (mndKillCompact(pMnode, pReq, pCompact) < 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndKillCompact(pMnode, pReq, pCompact), &lino, _OVER);
|
||||
|
||||
code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
|
@ -463,12 +486,14 @@ _OVER:
|
|||
tFreeSKillCompactReq(&killCompactReq);
|
||||
sdbRelease(pMnode->pSdb, pCompact);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
// update progress
|
||||
static int32_t mndUpdateCompactProgress(SMnode *pMnode, SRpcMsg *pReq, int32_t compactId,
|
||||
SQueryCompactProgressRsp *rsp) {
|
||||
int32_t code = 0;
|
||||
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
SCompactDetailObj *pDetail = NULL;
|
||||
|
@ -479,9 +504,10 @@ static int32_t mndUpdateCompactProgress(SMnode *pMnode, SRpcMsg *pReq, int32_t c
|
|||
pDetail->newNumberFileset = rsp->numberFileset;
|
||||
pDetail->newFinished = rsp->finished;
|
||||
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
|
@ -491,14 +517,13 @@ static int32_t mndUpdateCompactProgress(SMnode *pMnode, SRpcMsg *pReq, int32_t c
|
|||
}
|
||||
|
||||
int32_t mndProcessQueryCompactRsp(SRpcMsg *pReq) {
|
||||
SQueryCompactProgressRsp req = {0};
|
||||
int32_t code = 0;
|
||||
SQueryCompactProgressRsp req = {0};
|
||||
code = tDeserializeSQueryCompactProgressRsp(pReq->pCont, pReq->contLen, &req);
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
mError("failed to deserialize vnode-query-compact-progress-rsp, ret:%d, pCont:%p, len:%d", code, pReq->pCont,
|
||||
pReq->contLen);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mDebug("compact:%d, receive query response, vgId:%d, dnodeId:%d, numberFileset:%d, finished:%d", req.compactId,
|
||||
|
@ -508,13 +533,12 @@ int32_t mndProcessQueryCompactRsp(SRpcMsg *pReq) {
|
|||
|
||||
code = mndUpdateCompactProgress(pMnode, pReq, req.compactId, &req);
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("compact:%d, failed to update progress, vgId:%d, dnodeId:%d, numberFileset:%d, finished:%d", req.compactId,
|
||||
req.vgId, req.dnodeId, req.numberFileset, req.finished);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
// timer
|
||||
|
@ -531,7 +555,10 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) {
|
|||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pDetail->dnodeId);
|
||||
if (pDnode == NULL) break;
|
||||
addEpIntoEpSet(&epSet, pDnode->fqdn, pDnode->port);
|
||||
if (addEpIntoEpSet(&epSet, pDnode->fqdn, pDnode->port) != 0) {
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
continue;
|
||||
}
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SQueryCompactProgressReq req;
|
||||
|
@ -541,8 +568,6 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) {
|
|||
|
||||
int32_t contLen = tSerializeSQueryCompactProgressReq(NULL, 0, &req);
|
||||
if (contLen < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
sdbCancelFetch(pMnode->pSdb, pDetail);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
continue;
|
||||
}
|
||||
|
@ -551,7 +576,6 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) {
|
|||
|
||||
SMsgHead *pHead = rpcMallocCont(contLen);
|
||||
if (pHead == NULL) {
|
||||
sdbCancelFetch(pMnode->pSdb, pDetail);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
continue;
|
||||
}
|
||||
|
@ -563,13 +587,6 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) {
|
|||
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_VND_QUERY_COMPACT_PROGRESS, .contLen = contLen};
|
||||
|
||||
// rpcMsg.pCont = rpcMallocCont(contLen);
|
||||
// if (rpcMsg.pCont == NULL) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// memcpy(rpcMsg.pCont, pHead, contLen);
|
||||
|
||||
rpcMsg.pCont = pHead;
|
||||
|
||||
char detail[1024] = {0};
|
||||
|
@ -589,6 +606,7 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) {
|
|||
}
|
||||
|
||||
static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
|
||||
int32_t code = 0;
|
||||
bool needSave = false;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
|
@ -612,7 +630,7 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
|
|||
}
|
||||
|
||||
SCompactObj *pCompact = mndAcquireCompact(pMnode, compactId);
|
||||
if (pCompact == NULL) return 0;
|
||||
if (pCompact == NULL) TAOS_RETURN(code);
|
||||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pCompact->dbname);
|
||||
if (pDb == NULL) {
|
||||
|
@ -625,13 +643,15 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
|
|||
|
||||
if (!needSave) {
|
||||
mDebug("compact:%" PRId32 ", no need to save", compactId);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB, NULL, "update-compact-progress");
|
||||
if (pTrans == NULL) {
|
||||
mError("trans:%" PRId32 ", failed to create since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("compact:%d, trans:%d, used to update compact progress.", compactId, pTrans->id);
|
||||
|
||||
|
@ -654,10 +674,20 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
|
|||
pDetail->finished = pDetail->newFinished;
|
||||
|
||||
SSdbRaw *pCommitRaw = mndCompactDetailActionEncode(pDetail);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("compact:%d, trans:%d, failed to append commit log since %s", pDetail->compactId, pTrans->id, terrstr());
|
||||
if (pCommitRaw == NULL) {
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||
mError("compact:%d, trans:%d, failed to append commit log since %s", pDetail->compactId, pTrans->id, terrstr());
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
mndTransDrop(pTrans);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
}
|
||||
|
@ -678,11 +708,13 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
|
|||
|
||||
if (pDetail->numberFileset == -1 && pDetail->finished == -1) {
|
||||
allFinished = false;
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
break;
|
||||
}
|
||||
if (pDetail->numberFileset != -1 && pDetail->finished != -1 && pDetail->numberFileset != pDetail->finished) {
|
||||
allFinished = false;
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
break;
|
||||
}
|
||||
|
@ -710,11 +742,19 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
|
|||
|
||||
if (pDetail->compactId == pCompact->compactId) {
|
||||
SSdbRaw *pCommitRaw = mndCompactDetailActionEncode(pDetail);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
if (pCommitRaw == NULL) {
|
||||
mndTransDrop(pTrans);
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||
mError("compact:%d, trans:%d, failed to append commit log since %s", pDetail->compactId, pTrans->id,
|
||||
terrstr());
|
||||
sdbCancelFetch(pMnode->pSdb, pIter);
|
||||
sdbRelease(pMnode->pSdb, pDetail);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
mInfo("compact:%d, add drop compactdetail action", pDetail->compactDetailId);
|
||||
|
@ -724,20 +764,26 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
|
|||
}
|
||||
|
||||
SSdbRaw *pCommitRaw = mndCompactActionEncode(pCompact);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
if (pCommitRaw == NULL) {
|
||||
mndTransDrop(pTrans);
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||
mError("compact:%d, trans:%d, failed to append commit log since %s", compactId, pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
mInfo("compact:%d, add drop compact action", pCompact->compactId);
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("compact:%d, trans:%d, failed to prepare since %s", compactId, pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
sdbRelease(pMnode->pSdb, pCompact);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pCompact);
|
||||
|
@ -746,6 +792,7 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
|
|||
}
|
||||
|
||||
void mndCompactPullup(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SArray *pArray = taosArrayInit(sdbGetSize(pSdb, SDB_COMPACT), sizeof(int32_t));
|
||||
if (pArray == NULL) return;
|
||||
|
@ -766,7 +813,9 @@ void mndCompactPullup(SMnode *pMnode) {
|
|||
if (pCompact != NULL) {
|
||||
mInfo("compact:%d, begin to pull up", pCompact->compactId);
|
||||
mndCompactSendProgressReq(pMnode, pCompact);
|
||||
mndSaveCompactProgress(pMnode, pCompact->compactId);
|
||||
if ((code = mndSaveCompactProgress(pMnode, pCompact->compactId)) != 0) {
|
||||
mError("compact:%d, failed to save compact progress since %s", pCompact->compactId, tstrerror(code));
|
||||
}
|
||||
}
|
||||
mndReleaseCompact(pMnode, pCompact);
|
||||
}
|
||||
|
|
|
@ -125,17 +125,17 @@ int32_t tDeserializeSCompactDetailObj(void *buf, int32_t bufLen, SCompactDetailO
|
|||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tStartDecode(&decoder));
|
||||
|
||||
if (tDecodeI32(&decoder, &pObj->compactDetailId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pObj->compactId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pObj->vgId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pObj->dnodeId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pObj->numberFileset) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pObj->finished) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pObj->startTime) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pObj->newNumberFileset) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pObj->newFinished) < 0) return -1;
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactDetailId));
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactId));
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->vgId));
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->dnodeId));
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->numberFileset));
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->finished));
|
||||
TAOS_CHECK_RETURN(tDecodeI64(&decoder, &pObj->startTime));
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->newNumberFileset));
|
||||
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->newFinished));
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
|
@ -231,13 +231,10 @@ SSdbRow *mndCompactDetailActionDecode(SSdbRaw *pRaw) {
|
|||
}
|
||||
SDB_GET_BINARY(pRaw, dataPos, buf, tlen, OVER);
|
||||
|
||||
if (tDeserializeSCompactDetailObj(buf, tlen, pCompact) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
if ((terrno = tDeserializeSCompactDetailObj(buf, tlen, pCompact)) < 0) {
|
||||
goto OVER;
|
||||
}
|
||||
|
||||
//taosInitRWLatch(&pView->lock);
|
||||
|
||||
OVER:
|
||||
taosMemoryFreeClear(buf);
|
||||
if (terrno != TSDB_CODE_SUCCESS) {
|
||||
|
@ -274,6 +271,7 @@ int32_t mndCompactDetailActionUpdate(SSdb *pSdb, SCompactDetailObj *pOldCompact,
|
|||
|
||||
int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj* pCompact, SVgObj *pVgroup,
|
||||
SVnodeGid *pVgid, int32_t index){
|
||||
int32_t code = 0;
|
||||
SCompactDetailObj compactDetail = {0};
|
||||
compactDetail.compactDetailId = index;
|
||||
compactDetail.compactId = pCompact->compactId;
|
||||
|
@ -292,9 +290,11 @@ int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj* p
|
|||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) {
|
||||
sdbFreeRaw(pVgRaw);
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
|
|
@ -95,26 +95,21 @@ static int32_t validateTopics(const SArray *pTopicList, SMnode *pMnode, const ch
|
|||
bool enableReplay) {
|
||||
SMqTopicObj *pTopic = NULL;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
int32_t numOfTopics = taosArrayGetSize(pTopicList);
|
||||
for (int32_t i = 0; i < numOfTopics; i++) {
|
||||
char *pOneTopic = taosArrayGetP(pTopicList, i);
|
||||
pTopic = mndAcquireTopic(pMnode, pOneTopic);
|
||||
if (pTopic == NULL) { // terrno has been set by callee function
|
||||
code = -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto FAILED;
|
||||
}
|
||||
|
||||
if (mndCheckTopicPrivilege(pMnode, pUser, MND_OPER_SUBSCRIBE, pTopic) != 0) {
|
||||
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
goto FAILED;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckTopicPrivilege(pMnode, pUser, MND_OPER_SUBSCRIBE, pTopic), &lino, FAILED);
|
||||
|
||||
if ((terrno = grantCheckExpire(TSDB_GRANT_SUBSCRIPTION)) < 0) {
|
||||
code = terrno;
|
||||
goto FAILED;
|
||||
}
|
||||
TAOS_CHECK_GOTO(grantCheckExpire(TSDB_GRANT_SUBSCRIPTION), &lino, FAILED);
|
||||
|
||||
if (enableReplay) {
|
||||
if (pTopic->subType != TOPIC_SUB_TYPE__COLUMN) {
|
||||
|
@ -123,7 +118,8 @@ static int32_t validateTopics(const SArray *pTopicList, SMnode *pMnode, const ch
|
|||
} else if (pTopic->ntbUid == 0 && pTopic->ctbStbUid == 0) {
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pTopic->db);
|
||||
if (pDb == NULL) {
|
||||
code = -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto FAILED;
|
||||
}
|
||||
if (pDb->cfg.numOfVgroups != 1) {
|
||||
|
@ -141,11 +137,12 @@ static int32_t validateTopics(const SArray *pTopicList, SMnode *pMnode, const ch
|
|||
return 0;
|
||||
FAILED:
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMqConsumerRecoverMsg *pRecoverMsg = pMsg->pCont;
|
||||
SMqConsumerObj *pConsumerNew = NULL;
|
||||
|
@ -153,7 +150,8 @@ static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) {
|
|||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pRecoverMsg->consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
mError("cannot find consumer %" PRId64 " when processing consumer recover msg", pRecoverMsg->consumerId);
|
||||
code = -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto END;
|
||||
}
|
||||
|
||||
|
@ -161,42 +159,39 @@ static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) {
|
|||
pConsumer->status, mndConsumerStatusName(pConsumer->status));
|
||||
|
||||
if (pConsumer->status != MQ_CONSUMER_STATUS_LOST) {
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_READY;
|
||||
code = -1;
|
||||
code = TSDB_CODE_MND_CONSUMER_NOT_READY;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup, CONSUMER_UPDATE_REC, NULL, NULL);
|
||||
if (pConsumerNew == NULL){
|
||||
code = -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pMsg, "recover-csm");
|
||||
if (pTrans == NULL) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
code = validateTopics(pConsumer->assignedTopics, pMnode, pMsg->info.conn.user, false);
|
||||
if (code != 0) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto END;
|
||||
}
|
||||
|
||||
code = mndSetConsumerCommitLogs(pTrans, pConsumerNew);
|
||||
if (code != 0) {
|
||||
goto END;
|
||||
}
|
||||
TAOS_CHECK_GOTO(validateTopics(pConsumer->assignedTopics, pMnode, pMsg->info.conn.user, false), &lino, END);
|
||||
|
||||
TAOS_CHECK_GOTO(mndSetConsumerCommitLogs(pTrans, pConsumerNew), &lino, END);
|
||||
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
END:
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMqConsumerClearMsg *pClearMsg = pMsg->pCont;
|
||||
SMqConsumerObj *pConsumerNew = NULL;
|
||||
|
@ -205,7 +200,7 @@ static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) {
|
|||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pClearMsg->consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
mError("consumer:0x%" PRIx64 " failed to be found to clear it", pClearMsg->consumerId);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mInfo("consumer:0x%" PRIx64 " needs to be cleared, status %s", pClearMsg->consumerId,
|
||||
|
@ -213,21 +208,20 @@ static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) {
|
|||
|
||||
pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup, -1, NULL, NULL);
|
||||
if (pConsumerNew == NULL){
|
||||
code = -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "clear-csm");
|
||||
if (pTrans == NULL) {
|
||||
code = -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto END;
|
||||
}
|
||||
|
||||
// this is the drop action, not the update action
|
||||
code = mndSetConsumerDropLogs(pTrans, pConsumerNew);
|
||||
if (code != 0) {
|
||||
goto END;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndSetConsumerDropLogs(pTrans, pConsumerNew), &lino, END);
|
||||
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
|
||||
|
@ -235,7 +229,7 @@ END:
|
|||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t checkPrivilege(SMnode *pMnode, SMqConsumerObj *pConsumer, SMqHbRsp *rsp, char *user) {
|
||||
|
@ -310,10 +304,7 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
|||
SMqHbRsp rsp = {0};
|
||||
SMqConsumerObj *pConsumer = NULL;
|
||||
|
||||
if (tDeserializeSMqHbReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||
code = TSDB_CODE_TMQ_INVALID_MSG;
|
||||
goto end;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tDeserializeSMqHbReq(pMsg->pCont, pMsg->contLen, &req), NULL, end);
|
||||
|
||||
int64_t consumerId = req.consumerId;
|
||||
pConsumer = mndAcquireConsumer(pMnode, consumerId);
|
||||
|
@ -322,10 +313,8 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
|||
code = TSDB_CODE_MND_CONSUMER_NOT_EXIST;
|
||||
goto end;
|
||||
}
|
||||
code = checkPrivilege(pMnode, pConsumer, &rsp, pMsg->info.conn.user);
|
||||
if (code != 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
TAOS_CHECK_GOTO(checkPrivilege(pMnode, pConsumer, &rsp, pMsg->info.conn.user), NULL, end);
|
||||
|
||||
atomic_store_32(&pConsumer->hbStatus, 0);
|
||||
|
||||
|
@ -343,7 +332,7 @@ end:
|
|||
tDestroySMqHbRsp(&rsp);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
tDestroySMqHbReq(&req);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t addEpSetInfo(SMnode *pMnode, SMqConsumerObj *pConsumer, int32_t epoch, SMqAskEpRsp *rsp){
|
||||
|
@ -431,6 +420,7 @@ static int32_t addEpSetInfo(SMnode *pMnode, SMqConsumerObj *pConsumer, int32_t e
|
|||
}
|
||||
|
||||
static int32_t buildAskEpRsp(SRpcMsg *pMsg, SMqAskEpRsp *rsp, int32_t serverEpoch, int64_t consumerId){
|
||||
int32_t code = 0;
|
||||
// encode rsp
|
||||
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqAskEpRsp(NULL, rsp);
|
||||
void *buf = rpcMallocCont(tlen);
|
||||
|
@ -452,7 +442,7 @@ static int32_t buildAskEpRsp(SRpcMsg *pMsg, SMqAskEpRsp *rsp, int32_t serverEpoc
|
|||
// send rsp
|
||||
pMsg->info.rsp = buf;
|
||||
pMsg->info.rspLen = tlen;
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
||||
|
@ -461,9 +451,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
|||
SMqAskEpRsp rsp = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
if (tDeserializeSMqAskEpReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tDeserializeSMqAskEpReq(pMsg->pCont, pMsg->contLen, &req));
|
||||
|
||||
int64_t consumerId = req.consumerId;
|
||||
|
||||
|
@ -517,19 +505,29 @@ END:
|
|||
}
|
||||
|
||||
int32_t mndSetConsumerDropLogs(STrans *pTrans, SMqConsumerObj *pConsumer) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSetConsumerCommitLogs(STrans *pTrans, SMqConsumerObj *pConsumer) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
return 0;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static void freeItem(void *param) {
|
||||
|
@ -585,6 +583,7 @@ static int32_t getTopicAddDelete(SMqConsumerObj *pExistedConsumer, SMqConsumerOb
|
|||
}
|
||||
|
||||
static int32_t checkAndSortTopic(SMnode *pMnode, SArray *pTopicList){
|
||||
int32_t code = 0;
|
||||
taosArraySort(pTopicList, taosArrayCompareString);
|
||||
taosArrayRemoveDuplicate(pTopicList, taosArrayCompareString, freeItem);
|
||||
|
||||
|
@ -592,11 +591,10 @@ static int32_t checkAndSortTopic(SMnode *pMnode, SArray *pTopicList){
|
|||
for (int i = 0; i < newTopicNum; i++) {
|
||||
int32_t gNum = mndGetGroupNumByTopic(pMnode, (const char *)taosArrayGetP(pTopicList, i));
|
||||
if (gNum >= MND_MAX_GROUP_PER_TOPIC) {
|
||||
terrno = TSDB_CODE_TMQ_GROUP_OUT_OF_RANGE;
|
||||
return -1;
|
||||
return TSDB_CODE_TMQ_GROUP_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static SMqConsumerObj* buildSubConsumer(SMnode *pMnode, SCMSubscribeReq *subscribe){
|
||||
|
@ -672,7 +670,8 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pMsg, "subscribe");
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _over;
|
||||
}
|
||||
|
||||
|
@ -683,21 +682,21 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
|
||||
pConsumerNew = buildSubConsumer(pMnode, &subscribe);
|
||||
if(pConsumerNew == NULL){
|
||||
code = -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _over;
|
||||
}
|
||||
code = mndSetConsumerCommitLogs(pTrans, pConsumerNew);
|
||||
if (code != 0) goto _over;
|
||||
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
if (code != 0) goto _over;
|
||||
TAOS_CHECK_GOTO(mndSetConsumerCommitLogs(pTrans, pConsumerNew), NULL, _over);
|
||||
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _over);
|
||||
code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
_over:
|
||||
mndTransDrop(pTrans);
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
taosArrayDestroyP(subscribe.topicNames, (FDelete)taosMemoryFree);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) {
|
||||
|
|
|
@ -242,11 +242,11 @@ static int32_t doAddSinkTask(SStreamObj* pStream, SMnode* pMnode, SVgObj* pVgrou
|
|||
int64_t uid = (isFillhistory) ? pStream->hTaskUid : pStream->uid;
|
||||
SArray** pTaskList = (isFillhistory) ? taosArrayGetLast(pStream->pHTasksList) : taosArrayGetLast(pStream->tasks);
|
||||
|
||||
SStreamTask* pTask = tNewStreamTask(uid, TASK_LEVEL__SINK, pEpset, isFillhistory, 0, *pTaskList,
|
||||
pStream->conf.fillHistory, pStream->subTableWithoutMd5);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = tNewStreamTask(uid, TASK_LEVEL__SINK, pEpset, isFillhistory, 0, *pTaskList, pStream->conf.fillHistory,
|
||||
pStream->subTableWithoutMd5, &pTask);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
mDebug("doAddSinkTask taskId:%s, vgId:%d, isFillHistory:%d", pTask->id.idStr, pVgroup->vgId, isFillhistory);
|
||||
|
@ -353,18 +353,13 @@ static void haltInitialTaskStatus(SStreamTask* pTask, SSubplan* pPlan, bool isFi
|
|||
}
|
||||
}
|
||||
|
||||
static SStreamTask* buildSourceTask(SStreamObj* pStream, SEpSet* pEpset, bool isFillhistory, bool useTriggerParam) {
|
||||
static int32_t buildSourceTask(SStreamObj* pStream, SEpSet* pEpset, bool isFillhistory, bool useTriggerParam, SStreamTask** pTask) {
|
||||
uint64_t uid = (isFillhistory) ? pStream->hTaskUid : pStream->uid;
|
||||
SArray** pTaskList = (isFillhistory) ? taosArrayGetLast(pStream->pHTasksList) : taosArrayGetLast(pStream->tasks);
|
||||
|
||||
SStreamTask* pTask =
|
||||
tNewStreamTask(uid, TASK_LEVEL__SOURCE, pEpset, isFillhistory, useTriggerParam ? pStream->conf.triggerParam : 0,
|
||||
*pTaskList, pStream->conf.fillHistory, pStream->subTableWithoutMd5);
|
||||
if (pTask == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pTask;
|
||||
int32_t code = tNewStreamTask(uid, TASK_LEVEL__SOURCE, pEpset, isFillhistory, useTriggerParam ? pStream->conf.triggerParam : 0,
|
||||
*pTaskList, pStream->conf.fillHistory, pStream->subTableWithoutMd5, pTask);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void addNewTaskList(SStreamObj* pStream) {
|
||||
|
@ -398,10 +393,10 @@ static void setHTasksId(SStreamObj* pStream) {
|
|||
|
||||
static int32_t doAddSourceTask(SMnode* pMnode, SSubplan* plan, SStreamObj* pStream, SEpSet* pEpset, int64_t skey,
|
||||
SArray* pVerList, SVgObj* pVgroup, bool isFillhistory, bool useTriggerParam) {
|
||||
SStreamTask* pTask = buildSourceTask(pStream, pEpset, isFillhistory, useTriggerParam);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = buildSourceTask(pStream, pEpset, isFillhistory, useTriggerParam, &pTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
mDebug("doAddSourceTask taskId:%s, vgId:%d, isFillHistory:%d", pTask->id.idStr, pVgroup->vgId, isFillhistory);
|
||||
|
@ -412,10 +407,9 @@ static int32_t doAddSourceTask(SMnode* pMnode, SSubplan* plan, SStreamObj* pStre
|
|||
|
||||
streamTaskSetDataRange(pTask, skey, pVerList, pVgroup->vgId);
|
||||
|
||||
int32_t code = mndAssignStreamTaskToVgroup(pMnode, pTask, plan, pVgroup);
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
return terrno;
|
||||
code = mndAssignStreamTaskToVgroup(pMnode, pTask, plan, pVgroup);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return TDB_CODE_SUCCESS;
|
||||
|
@ -498,28 +492,29 @@ static int32_t addSourceTask(SMnode* pMnode, SSubplan* plan, SStreamObj* pStream
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SStreamTask* buildAggTask(SStreamObj* pStream, SEpSet* pEpset, bool isFillhistory, bool useTriggerParam) {
|
||||
static int32_t buildAggTask(SStreamObj* pStream, SEpSet* pEpset, bool isFillhistory, bool useTriggerParam,
|
||||
SStreamTask** pAggTask) {
|
||||
*pAggTask = NULL;
|
||||
|
||||
uint64_t uid = (isFillhistory) ? pStream->hTaskUid : pStream->uid;
|
||||
SArray** pTaskList = (isFillhistory) ? taosArrayGetLast(pStream->pHTasksList) : taosArrayGetLast(pStream->tasks);
|
||||
|
||||
SStreamTask* pAggTask =
|
||||
int32_t code =
|
||||
tNewStreamTask(uid, TASK_LEVEL__AGG, pEpset, isFillhistory, useTriggerParam ? pStream->conf.triggerParam : 0,
|
||||
*pTaskList, pStream->conf.fillHistory, pStream->subTableWithoutMd5);
|
||||
if (pAggTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pAggTask;
|
||||
*pTaskList, pStream->conf.fillHistory, pStream->subTableWithoutMd5, pAggTask);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t doAddAggTask(SStreamObj* pStream, SMnode* pMnode, SSubplan* plan, SEpSet* pEpset, SVgObj* pVgroup,
|
||||
SSnodeObj* pSnode, bool isFillhistory, bool useTriggerParam) {
|
||||
int32_t code = 0;
|
||||
SStreamTask* pTask = buildAggTask(pStream, pEpset, isFillhistory, useTriggerParam);
|
||||
if (pTask == NULL) {
|
||||
return terrno;
|
||||
SStreamTask* pTask = NULL;
|
||||
|
||||
code = buildAggTask(pStream, pEpset, isFillhistory, useTriggerParam, &pTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pSnode != NULL) {
|
||||
code = mndAssignStreamTaskToSnode(pMnode, pTask, plan, pSnode);
|
||||
mDebug("doAddAggTask taskId:%s, snode id:%d, isFillHistory:%d", pTask->id.idStr, pSnode->id, isFillhistory);
|
||||
|
|
|
@ -105,6 +105,7 @@ SArray *mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady) {
|
|||
mInfo("vgId:%d replica:%d inconsistent with other vgroups replica:%d, not ready for stream operations",
|
||||
pVgroup->vgId, pVgroup->replica, replica);
|
||||
*allReady = false;
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -399,32 +399,32 @@ TEST_F(MndTestSdb, 00_API) {
|
|||
SSdbRaw *pRaw2 = sdbAllocRaw(SDB_USER, 1, -128);
|
||||
ASSERT_EQ(pRaw2 == NULL, 1);
|
||||
|
||||
ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt32(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt32(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt16(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt16(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt64(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt64(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawBinary(NULL, 0, "12", 3), -1);
|
||||
ASSERT_EQ(sdbSetRawBinary(pRaw1, 9028, "12", 3), -1);
|
||||
ASSERT_EQ(sdbSetRawDataLen(NULL, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawDataLen(pRaw1, 9000), -1);
|
||||
ASSERT_EQ(sdbSetRawStatus(NULL, SDB_STATUS_READY), -1);
|
||||
ASSERT_EQ(sdbSetRawStatus(pRaw1, SDB_STATUS_INIT), -1);
|
||||
ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt32(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt32(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt16(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt16(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt64(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt64(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawBinary(NULL, 0, "12", 3), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawBinary(pRaw1, 9028, "12", 3), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawDataLen(NULL, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawDataLen(pRaw1, 9000), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawStatus(NULL, SDB_STATUS_READY), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawStatus(pRaw1, SDB_STATUS_INIT), TSDB_CODE_INVALID_PARA);
|
||||
|
||||
ASSERT_EQ(sdbGetRawInt8(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt8(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt32(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt32(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt16(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt16(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt64(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt64(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawBinary(NULL, 0, 0, 4096), -1);
|
||||
ASSERT_EQ(sdbGetRawBinary(pRaw1, 9000, 0, 112), -1);
|
||||
ASSERT_EQ(sdbGetRawSoftVer(NULL, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt8(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt8(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt32(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt32(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt16(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt16(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt64(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt64(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawBinary(NULL, 0, 0, 4096), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawBinary(pRaw1, 9000, 0, 112), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawSoftVer(NULL, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawTotalSize(NULL), -1);
|
||||
|
||||
// sdbHash.c
|
||||
|
|
|
@ -112,6 +112,8 @@ void sdbCleanup(SSdb *pSdb) {
|
|||
}
|
||||
|
||||
int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
||||
int32_t code = 0;
|
||||
|
||||
ESdbType sdbType = table.sdbType;
|
||||
EKeyType keyType = table.keyType;
|
||||
pSdb->keyTypes[sdbType] = table.keyType;
|
||||
|
@ -134,8 +136,8 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
|||
|
||||
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_ENTRY_LOCK);
|
||||
if (hash == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pSdb->maxId[sdbType] = 0;
|
||||
|
@ -146,16 +148,17 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
|||
}
|
||||
|
||||
static int32_t sdbCreateDir(SSdb *pSdb) {
|
||||
int32_t code = 0;
|
||||
if (taosMulMkDir(pSdb->currDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->currDir, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->currDir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosMkDir(pSdb->tmpDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->tmpDir, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->tmpDir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -14,18 +14,19 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "crypt.h"
|
||||
#include "sdb.h"
|
||||
#include "sync.h"
|
||||
#include "tchecksum.h"
|
||||
#include "wal.h"
|
||||
#include "tglobal.h"
|
||||
#include "crypt.h"
|
||||
#include "wal.h"
|
||||
|
||||
#define SDB_TABLE_SIZE 24
|
||||
#define SDB_RESERVE_SIZE 512
|
||||
#define SDB_FILE_VER 1
|
||||
|
||||
static int32_t sdbDeployData(SSdb *pSdb) {
|
||||
int32_t code = 0;
|
||||
mInfo("start to deploy sdb");
|
||||
|
||||
for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
|
||||
|
@ -33,8 +34,9 @@ static int32_t sdbDeployData(SSdb *pSdb) {
|
|||
if (fp == NULL) continue;
|
||||
|
||||
mInfo("start to deploy sdb:%s", sdbTableName(i));
|
||||
if ((*fp)(pSdb->pMnode) != 0) {
|
||||
mError("failed to deploy sdb:%s since %s", sdbTableName(i), terrstr());
|
||||
code = (*fp)(pSdb->pMnode);
|
||||
if (code != 0) {
|
||||
mError("failed to deploy sdb:%s since %s", sdbTableName(i), tstrerror(code));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -80,61 +82,62 @@ static void sdbResetData(SSdb *pSdb) {
|
|||
}
|
||||
|
||||
static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||
int32_t code = 0;
|
||||
int64_t sver = 0;
|
||||
int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (sver != SDB_FILE_VER) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||
int64_t maxId = 0;
|
||||
ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (i < SDB_MAX) {
|
||||
pSdb->maxId[i] = maxId;
|
||||
|
@ -145,12 +148,12 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
int64_t ver = 0;
|
||||
ret = taosReadFile(pFile, &ver, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (i < SDB_MAX) {
|
||||
pSdb->tableVer[i] = ver;
|
||||
|
@ -160,37 +163,38 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
char reserve[SDB_RESERVE_SIZE] = {0};
|
||||
ret = taosReadFile(pFile, reserve, sizeof(reserve));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(reserve)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||
int32_t code = 0;
|
||||
int64_t sver = SDB_FILE_VER;
|
||||
if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||
|
@ -199,8 +203,8 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
maxId = pSdb->maxId[i];
|
||||
}
|
||||
if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,15 +214,15 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
ver = pSdb->tableVer[i];
|
||||
}
|
||||
if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
char reserve[SDB_RESERVE_SIZE] = {0};
|
||||
if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -237,21 +241,22 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
|
||||
SSdbRaw *pRaw = taosMemoryMalloc(bufLen + 100);
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
taosMemoryFree(pRaw);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mInfo("read sdb file:%s finished since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mInfo("read sdb file:%s finished since %s", file, tstrerror(code));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sdbReadFileHead(pSdb, pFile) != 0) {
|
||||
mError("failed to read sdb file:%s head since %s", file, terrstr());
|
||||
code = sdbReadFileHead(pSdb, pFile);
|
||||
if (code != 0) {
|
||||
mError("failed to read sdb file:%s head since %s", file, tstrerror(code));
|
||||
taosMemoryFree(pRaw);
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
|
@ -285,7 +290,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
bufLen = pRaw->dataLen * 2;
|
||||
SSdbRaw *pNewRaw = taosMemoryMalloc(bufLen + 100);
|
||||
if (pNewRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since malloc new sdbRaw size:%d failed", bufLen);
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -312,6 +317,10 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
int32_t count = 0;
|
||||
|
||||
char *plantContent = taosMemoryMalloc(ENCRYPTED_LEN(pRaw->dataLen));
|
||||
if (plantContent == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SCryptOpts opts;
|
||||
opts.len = ENCRYPTED_LEN(pRaw->dataLen);
|
||||
|
@ -355,8 +364,7 @@ _OVER:
|
|||
taosCloseFile(&pFile);
|
||||
sdbFreeRaw(pRaw);
|
||||
|
||||
terrno = code;
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t sdbReadFile(SSdb *pSdb) {
|
||||
|
@ -365,7 +373,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
|
|||
sdbResetData(pSdb);
|
||||
int32_t code = sdbReadFileImp(pSdb);
|
||||
if (code != 0) {
|
||||
mError("failed to read sdb file since %s", terrstr());
|
||||
mError("failed to read sdb file since %s", tstrerror(code));
|
||||
sdbResetData(pSdb);
|
||||
}
|
||||
|
||||
|
@ -388,13 +396,14 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
|
||||
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s for write since %s", tmpfile, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (sdbWriteFileHead(pSdb, pFile) != 0) {
|
||||
mError("failed to write sdb file:%s head since %s", tmpfile, terrstr());
|
||||
code = sdbWriteFileHead(pSdb, pFile);
|
||||
if (code != 0) {
|
||||
mError("failed to write sdb file:%s head since %s", tmpfile, tstrerror(code));
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
}
|
||||
|
@ -549,19 +558,22 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) {
|
|||
}
|
||||
}
|
||||
if (code != 0) {
|
||||
mError("failed to write sdb file since %s", terrstr());
|
||||
mError("failed to write sdb file since %s", tstrerror(code));
|
||||
}
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t sdbDeploy(SSdb *pSdb) {
|
||||
if (sdbDeployData(pSdb) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = sdbDeployData(pSdb);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (sdbWriteFile(pSdb, 0) != 0) {
|
||||
return -1;
|
||||
code = sdbWriteFile(pSdb, 0);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -605,6 +617,7 @@ static void sdbCloseIter(SSdbIter *pIter) {
|
|||
}
|
||||
|
||||
int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *term, int64_t *config) {
|
||||
int32_t code = 0;
|
||||
SSdbIter *pIter = sdbCreateIter(pSdb);
|
||||
if (pIter == NULL) return -1;
|
||||
|
||||
|
@ -617,19 +630,19 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
|||
int64_t commitConfig = pSdb->commitConfig;
|
||||
if (taosCopyFile(datafile, pIter->name) < 0) {
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
|
||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
|
||||
if (pIter->file == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s since %s", pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*ppIter = pIter;
|
||||
|
@ -645,21 +658,22 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
|||
void sdbStopRead(SSdb *pSdb, SSdbIter *pIter) { sdbCloseIter(pIter); }
|
||||
|
||||
int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
||||
int32_t code = 0;
|
||||
int32_t maxlen = 4096;
|
||||
void *pBuf = taosMemoryCalloc(1, maxlen);
|
||||
if (pBuf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen);
|
||||
if (readlen < 0 || readlen > maxlen) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, terrstr(), pIter->total);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total);
|
||||
*ppBuf = NULL;
|
||||
*len = 0;
|
||||
taosMemoryFree(pBuf);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
} else if (readlen == 0) {
|
||||
mInfo("sdbiter:%p, read snapshot to the end, total:%" PRId64, pIter, pIter->total);
|
||||
*ppBuf = NULL;
|
||||
|
@ -676,15 +690,19 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
|||
}
|
||||
|
||||
int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
|
||||
int32_t code = 0;
|
||||
SSdbIter *pIter = sdbCreateIter(pSdb);
|
||||
if (pIter == NULL) return -1;
|
||||
if (pIter == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pIter->file == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open %s since %s", pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open %s since %s", pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*ppIter = pIter;
|
||||
|
@ -702,8 +720,8 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
|||
}
|
||||
|
||||
if (taosFsyncFile(pIter->file) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -713,13 +731,14 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
|||
char datafile[PATH_MAX] = {0};
|
||||
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
|
||||
if (taosRenameFile(pIter->name, datafile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (sdbReadFile(pSdb) != 0) {
|
||||
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, terrstr());
|
||||
code = sdbReadFile(pSdb);
|
||||
if (code != 0) {
|
||||
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -742,11 +761,12 @@ _OVER:
|
|||
}
|
||||
|
||||
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
||||
int32_t code = 0;
|
||||
int32_t writelen = taosWriteFile(pIter->file, pBuf, len);
|
||||
if (writelen != len) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to write len:%d since %s, total:%" PRId64, len, terrstr(), pIter->total);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pIter->total += writelen;
|
||||
|
|
|
@ -53,14 +53,15 @@ void sdbFreeRaw(SSdbRaw *pRaw) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int8_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -68,14 +69,15 @@ int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(uint8_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -83,14 +85,15 @@ int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int32_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -98,14 +101,15 @@ int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int16_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -113,14 +117,15 @@ int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int64_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -128,14 +133,15 @@ int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + valLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (pVal != NULL) {
|
||||
|
@ -145,14 +151,15 @@ int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_
|
|||
}
|
||||
|
||||
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pRaw->dataLen = dataLen;
|
||||
|
@ -160,14 +167,15 @@ int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (status == SDB_STATUS_INIT) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pRaw->status = status;
|
||||
|
@ -175,14 +183,15 @@ int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int8_t *)(pRaw->pData + dataPos);
|
||||
|
@ -190,14 +199,15 @@ int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(uint8_t *)(pRaw->pData + dataPos);
|
||||
|
@ -205,14 +215,15 @@ int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int32_t *)(pRaw->pData + dataPos);
|
||||
|
@ -220,14 +231,15 @@ int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int16_t *)(pRaw->pData + dataPos);
|
||||
|
@ -235,14 +247,15 @@ int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int64_t *)(pRaw->pData + dataPos);
|
||||
|
@ -250,14 +263,15 @@ int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + valLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (pVal != NULL) {
|
||||
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
||||
|
@ -266,9 +280,10 @@ int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valL
|
|||
}
|
||||
|
||||
int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*sver = pRaw->sver;
|
||||
|
|
|
@ -41,7 +41,7 @@ int32_t sndBuildStreamTask(SSnode *pSnode, SStreamTask *pTask, int64_t nextProce
|
|||
SCheckpointInfo *pChkInfo = &pTask->chkInfo;
|
||||
tqSetRestoreVersionInfo(pTask);
|
||||
|
||||
char *p = streamTaskGetStatus(pTask)->name;
|
||||
char *p = streamTaskGetStatus(pTask).name;
|
||||
if (pTask->info.fillHistory) {
|
||||
sndInfo("vgId:%d build stream task, s-task:%s, checkpointId:%" PRId64 " checkpointVer:%" PRId64
|
||||
" nextProcessVer:%" PRId64
|
||||
|
@ -71,9 +71,9 @@ SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
|||
startRsync();
|
||||
|
||||
pSnode->msgCb = pOption->msgCb;
|
||||
pSnode->pMeta = streamMetaOpen(path, pSnode, (FTaskBuild *)sndBuildStreamTask, tqExpandStreamTask, SNODE_HANDLE, taosGetTimestampMs(), tqStartTaskCompleteCallback);
|
||||
if (pSnode->pMeta == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t code = streamMetaOpen(path, pSnode, (FTaskBuild *)sndBuildStreamTask, tqExpandStreamTask, SNODE_HANDLE,
|
||||
taosGetTimestampMs(), tqStartTaskCompleteCallback, &pSnode->pMeta);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,11 +68,8 @@ set(
|
|||
"src/tq/tqOffset.c"
|
||||
"src/tq/tqPush.c"
|
||||
"src/tq/tqSink.c"
|
||||
"src/tq/tqCommit.c"
|
||||
"src/tq/tqStreamTask.c"
|
||||
"src/tq/tqHandleSnapshot.c"
|
||||
"src/tq/tqCheckInfoSnapshot.c"
|
||||
"src/tq/tqOffsetSnapshot.c"
|
||||
"src/tq/tqSnapshot.c"
|
||||
"src/tq/tqStreamStateSnap.c"
|
||||
"src/tq/tqStreamTaskSnap.c"
|
||||
|
||||
|
|
|
@ -41,8 +41,6 @@ extern "C" {
|
|||
#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0)
|
||||
// clang-format on
|
||||
|
||||
typedef struct STqOffsetStore STqOffsetStore;
|
||||
|
||||
#define IS_OFFSET_RESET_TYPE(_t) ((_t) < 0)
|
||||
|
||||
// tqExec
|
||||
|
@ -101,10 +99,11 @@ struct STQ {
|
|||
SHashObj* pPushMgr; // subKey -> STqHandle
|
||||
SHashObj* pHandle; // subKey -> STqHandle
|
||||
SHashObj* pCheckInfo; // topic -> SAlterCheckInfo
|
||||
STqOffsetStore* pOffsetStore;
|
||||
SHashObj* pOffset; // subKey -> STqOffsetVal
|
||||
TDB* pMetaDB;
|
||||
TTB* pExecStore;
|
||||
TTB* pCheckStore;
|
||||
TTB* pOffsetStore;
|
||||
SStreamMeta* pStreamMeta;
|
||||
};
|
||||
|
||||
|
@ -128,29 +127,22 @@ int32_t tqPushEmptyDataRsp(STqHandle* pHandle, int32_t vgId);
|
|||
int32_t tqMetaOpen(STQ* pTq);
|
||||
int32_t tqMetaClose(STQ* pTq);
|
||||
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle);
|
||||
int32_t tqMetaDeleteHandle(STQ* pTq, const char* key);
|
||||
int32_t tqMetaSaveCheckInfo(STQ* pTq, const char* key, const void* value, int32_t vLen);
|
||||
int32_t tqMetaDeleteCheckInfo(STQ* pTq, const char* key);
|
||||
int32_t tqMetaRestoreCheckInfo(STQ* pTq);
|
||||
int32_t tqMetaGetHandle(STQ* pTq, const char* key);
|
||||
int32_t tqCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle);
|
||||
|
||||
STqOffsetStore* tqOffsetOpen(STQ* pTq);
|
||||
int32_t tqMetaSaveInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen, const void* value, int32_t vLen);
|
||||
int32_t tqMetaDeleteInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen);
|
||||
int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle);
|
||||
int32_t tqMetaDecodeCheckInfo(STqCheckInfo *info, void *pVal, int32_t vLen);
|
||||
int32_t tqMetaDecodeOffsetInfo(STqOffset *info, void *pVal, int32_t vLen);
|
||||
int32_t tqMetaGetHandle(STQ* pTq, const char* key, STqHandle** pHandle);
|
||||
void* tqMetaGetOffset(STQ* pTq, const char* subkey);
|
||||
int32_t tqMetaTransform(STQ* pTq);
|
||||
void tqOffsetClose(STqOffsetStore*);
|
||||
STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey);
|
||||
int32_t tqOffsetWrite(STqOffsetStore* pStore, const STqOffset* pOffset);
|
||||
int32_t tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey);
|
||||
int32_t tqOffsetCommitFile(STqOffsetStore* pStore);
|
||||
|
||||
// tqSink
|
||||
int32_t tqBuildDeleteReq(STQ* pTq, const char* stbFullName, const SSDataBlock* pDataBlock, SBatchDeleteReq* deleteReq,
|
||||
const char* pIdStr, bool newSubTableRule);
|
||||
void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data);
|
||||
|
||||
// tqOffset
|
||||
char* tqOffsetBuildFName(const char* path, int32_t fVer);
|
||||
int32_t tqOffsetRestoreFromFile(STqOffsetStore* pStore, const char* fname);
|
||||
int32_t tqBuildFName(char** data, const char* path, char* name);
|
||||
int32_t tqOffsetRestoreFromFile(STQ* pTq, char* name);
|
||||
|
||||
// tq util
|
||||
int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void** pRefBlock, int32_t type);
|
||||
|
@ -166,6 +158,25 @@ int32_t doMergeExistedRows(SSubmitTbData* pExisted, const SSubmitTbData* pNew, c
|
|||
SVCreateTbReq* buildAutoCreateTableReq(const char* stbFullName, int64_t suid, int32_t numOfCols,
|
||||
SSDataBlock* pDataBlock, SArray* pTagArray, bool newSubTableRule);
|
||||
|
||||
#define TQ_ERR_GO_TO_END(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
goto END; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TQ_ERR_RETURN(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
return code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define TQ_SUBSCRIBE_NAME "subscribe"
|
||||
#define TQ_OFFSET_NAME "offset-ver0"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -147,7 +147,6 @@ int32_t tsdbRowKeyCmpr(const STsdbRowKey *key1, const STsdbRowKey *key2);
|
|||
void tsdbRowGetKey(TSDBROW *row, STsdbRowKey *key);
|
||||
void tColRowGetPrimaryKey(SBlockData *pBlock, int32_t irow, SRowKey *key);
|
||||
|
||||
|
||||
// STSDBRowIter
|
||||
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tsdbRowClose(STSDBRowIter *pIter);
|
||||
|
@ -259,7 +258,6 @@ int32_t tsdbGetNRowsInTbData(STbData *pTbData);
|
|||
typedef enum { TSDB_HEAD_FILE = 0, TSDB_DATA_FILE, TSDB_LAST_FILE, TSDB_SMA_FILE } EDataFileT;
|
||||
|
||||
bool tsdbDelFileIsSame(SDelFile *pDelFile1, SDelFile *pDelFile2);
|
||||
int32_t tsdbDFileRollback(STsdb *pTsdb, SDFileSet *pSet, EDataFileT ftype);
|
||||
int32_t tPutHeadFile(uint8_t *p, SHeadFile *pHeadFile);
|
||||
int32_t tPutDataFile(uint8_t *p, SDataFile *pDataFile);
|
||||
int32_t tPutSttFile(uint8_t *p, SSttFile *pSttFile);
|
||||
|
|
|
@ -70,10 +70,6 @@ typedef struct STsdbSnapRAWReader STsdbSnapRAWReader;
|
|||
typedef struct STsdbSnapRAWWriter STsdbSnapRAWWriter;
|
||||
typedef struct STqSnapReader STqSnapReader;
|
||||
typedef struct STqSnapWriter STqSnapWriter;
|
||||
typedef struct STqOffsetReader STqOffsetReader;
|
||||
typedef struct STqOffsetWriter STqOffsetWriter;
|
||||
typedef struct STqCheckInfoReader STqCheckInfoReader;
|
||||
typedef struct STqCheckInfoWriter STqCheckInfoWriter;
|
||||
typedef struct SStreamTaskReader SStreamTaskReader;
|
||||
typedef struct SStreamTaskWriter SStreamTaskWriter;
|
||||
typedef struct SStreamStateReader SStreamStateReader;
|
||||
|
@ -222,8 +218,8 @@ typedef struct SMetaInfo {
|
|||
int32_t metaGetInfo(SMeta* pMeta, int64_t uid, SMetaInfo* pInfo, SMetaReader* pReader);
|
||||
|
||||
// tsdb
|
||||
int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg, int8_t rollback, bool force);
|
||||
int tsdbClose(STsdb** pTsdb);
|
||||
int32_t tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg, int8_t rollback, bool force);
|
||||
int32_t tsdbClose(STsdb** pTsdb);
|
||||
int32_t tsdbBegin(STsdb* pTsdb);
|
||||
// int32_t tsdbPrepareCommit(STsdb* pTsdb);
|
||||
// int32_t tsdbCommit(STsdb* pTsdb, SCommitInfo* pInfo);
|
||||
|
@ -266,7 +262,6 @@ int32_t tqProcessTaskCheckpointReadyRsp(STQ* pTq, SRpcMsg* pMsg);
|
|||
int32_t tqBuildStreamTask(void* pTq, SStreamTask* pTask, int64_t ver);
|
||||
int32_t tqScanWal(STQ* pTq);
|
||||
|
||||
int tqCommit(STQ*);
|
||||
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd);
|
||||
int32_t tqCheckColModifiable(STQ* pTq, int64_t tbUid, int32_t colId);
|
||||
// tq-mq
|
||||
|
@ -349,29 +344,17 @@ int32_t tsdbSnapRAWWrite(STsdbSnapRAWWriter* pWriter, SSnapDataHdr* pHdr);
|
|||
int32_t tsdbSnapRAWWriterPrepareClose(STsdbSnapRAWWriter* pWriter);
|
||||
int32_t tsdbSnapRAWWriterClose(STsdbSnapRAWWriter** ppWriter, int8_t rollback);
|
||||
// STqSnapshotReader ==
|
||||
int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapReader** ppReader);
|
||||
int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, int8_t type, STqSnapReader** ppReader);
|
||||
int32_t tqSnapReaderClose(STqSnapReader** ppReader);
|
||||
int32_t tqSnapRead(STqSnapReader* pReader, uint8_t** ppData);
|
||||
// STqSnapshotWriter ======================================
|
||||
int32_t tqSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapWriter** ppWriter);
|
||||
int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback);
|
||||
int32_t tqSnapWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
|
||||
// STqCheckInfoshotReader ==
|
||||
int32_t tqCheckInfoReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqCheckInfoReader** ppReader);
|
||||
int32_t tqCheckInfoReaderClose(STqCheckInfoReader** ppReader);
|
||||
int32_t tqCheckInfoRead(STqCheckInfoReader* pReader, uint8_t** ppData);
|
||||
// STqCheckInfoshotWriter ======================================
|
||||
int32_t tqCheckInfoWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqCheckInfoWriter** ppWriter);
|
||||
int32_t tqCheckInfoWriterClose(STqCheckInfoWriter** ppWriter, int8_t rollback);
|
||||
int32_t tqCheckInfoWrite(STqCheckInfoWriter* pWriter, uint8_t* pData, uint32_t nData);
|
||||
// STqOffsetReader ========================================
|
||||
int32_t tqOffsetReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqOffsetReader** ppReader);
|
||||
int32_t tqOffsetReaderClose(STqOffsetReader** ppReader);
|
||||
int32_t tqOffsetSnapRead(STqOffsetReader* pReader, uint8_t** ppData);
|
||||
// STqOffsetWriter ========================================
|
||||
int32_t tqOffsetWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqOffsetWriter** ppWriter);
|
||||
int32_t tqOffsetWriterClose(STqOffsetWriter** ppWriter, int8_t rollback);
|
||||
int32_t tqOffsetSnapWrite(STqOffsetWriter* pWriter, uint8_t* pData, uint32_t nData);
|
||||
int32_t tqSnapHandleWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
|
||||
|
||||
int32_t tqSnapCheckInfoWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
|
||||
int32_t tqSnapOffsetWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
|
||||
|
||||
// SStreamTaskWriter ======================================
|
||||
|
||||
int32_t streamTaskSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTaskReader** ppReader);
|
||||
|
|
|
@ -297,8 +297,17 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
sprintf(pStreamTask->exec.qmsg, "%s", RSMA_EXEC_TASK_FLAG);
|
||||
pStreamTask->chkInfo.checkpointId = streamMetaGetLatestCheckpointId(pStreamTask->pMeta);
|
||||
tdRSmaTaskInit(pStreamTask->pMeta, pItem, &pStreamTask->id);
|
||||
pStreamTask->status.pSM = streamCreateStateMachine(pStreamTask);
|
||||
pStreamTask->chkInfo.pActiveInfo = streamTaskCreateActiveChkptInfo();
|
||||
|
||||
int32_t code = streamCreateStateMachine(pStreamTask);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = streamTaskCreateActiveChkptInfo(&pStreamTask->chkInfo.pActiveInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pStreamState = streamStateOpen(taskInfDir, pStreamTask, pStreamTask->id.streamId, pStreamTask->id.taskId);
|
||||
if (!pStreamState) {
|
||||
terrno = TSDB_CODE_RSMA_STREAM_STATE_OPEN;
|
||||
|
@ -362,6 +371,8 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
* @return int32_t
|
||||
*/
|
||||
int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, const char *tbName) {
|
||||
int32_t code;
|
||||
|
||||
if ((param->qmsgLen[0] == 0) && (param->qmsgLen[1] == 0)) {
|
||||
smaDebug("vgId:%d, no qmsg1/qmsg2 for rollup table %s %" PRIi64, SMA_VID(pSma), tbName, suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -401,13 +412,18 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con
|
|||
pRSmaInfo->suid = suid;
|
||||
T_REF_INIT_VAL(pRSmaInfo, 1);
|
||||
|
||||
if (!(pRSmaInfo->queue = taosOpenQueue()) || !(pRSmaInfo->qall = taosAllocateQall()) ||
|
||||
tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 0) < 0 ||
|
||||
code = taosOpenQueue(&pRSmaInfo->queue);
|
||||
if (code) goto _err;
|
||||
|
||||
code = taosAllocateQall(&pRSmaInfo->qall);
|
||||
if (code) goto _err;
|
||||
|
||||
if (tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 0) < 0 ||
|
||||
tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 1) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (taosHashPut(RSMA_INFO_HASH(pStat), &suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) < 0) {
|
||||
if (taosHashPut(RSMA_INFO_HASH(pStat), &suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) != 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
|
@ -533,12 +549,12 @@ static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid)
|
|||
taosArrayDestroy(pUidArray);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) < 0) {
|
||||
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) < 0) {
|
||||
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
@ -795,11 +811,13 @@ _exit:
|
|||
*/
|
||||
static int32_t tdExecuteRSmaImplAsync(SSma *pSma, int64_t version, const void *pMsg, int32_t len, int32_t inputType,
|
||||
SRSmaInfo *pInfo, tb_uid_t suid) {
|
||||
int32_t code;
|
||||
int32_t size = RSMA_EXEC_MSG_HLEN + len; // header + payload
|
||||
void * qItem = taosAllocateQitem(size, DEF_QITEM, 0);
|
||||
void *qItem;
|
||||
|
||||
if (!qItem) {
|
||||
return TSDB_CODE_FAILED;
|
||||
code = taosAllocateQitem(size, DEF_QITEM, 0, (void **)&qItem);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
void *pItem = qItem;
|
||||
|
|
|
@ -76,9 +76,12 @@ STQ* tqOpen(const char* path, SVnode* pVnode) {
|
|||
taosInitRWLatch(&pTq->lock);
|
||||
pTq->pPushMgr = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK);
|
||||
|
||||
pTq->pCheckInfo = taosHashInit(64, MurmurHash3_32, true, HASH_ENTRY_LOCK);
|
||||
pTq->pCheckInfo = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
taosHashSetFreeFp(pTq->pCheckInfo, (FDelete)tDeleteSTqCheckInfo);
|
||||
|
||||
pTq->pOffset = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_ENTRY_LOCK);
|
||||
taosHashSetFreeFp(pTq->pOffset, (FDelete)tDeleteSTqOffset);
|
||||
|
||||
int32_t code = tqInitialize(pTq);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tqClose(pTq);
|
||||
|
@ -90,26 +93,19 @@ STQ* tqOpen(const char* path, SVnode* pVnode) {
|
|||
|
||||
int32_t tqInitialize(STQ* pTq) {
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
pTq->pStreamMeta =
|
||||
streamMetaOpen(pTq->path, pTq, tqBuildStreamTask, tqExpandStreamTask, vgId, -1, tqStartTaskCompleteCallback);
|
||||
if (pTq->pStreamMeta == NULL) {
|
||||
return -1;
|
||||
|
||||
int32_t code = streamMetaOpen(pTq->path, pTq, tqBuildStreamTask, tqExpandStreamTask, vgId, -1,
|
||||
tqStartTaskCompleteCallback, &pTq->pStreamMeta);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
streamMetaLoadAllTasks(pTq->pStreamMeta);
|
||||
|
||||
if (tqMetaTransform(pTq) < 0) {
|
||||
if (tqMetaOpen(pTq) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tqMetaRestoreCheckInfo(pTq) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pTq->pOffsetStore = tqOffsetOpen(pTq);
|
||||
if (pTq->pOffsetStore == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -133,10 +129,10 @@ void tqClose(STQ* pTq) {
|
|||
pIter = taosHashIterate(pTq->pPushMgr, pIter);
|
||||
}
|
||||
|
||||
tqOffsetClose(pTq->pOffsetStore);
|
||||
taosHashCleanup(pTq->pHandle);
|
||||
taosHashCleanup(pTq->pPushMgr);
|
||||
taosHashCleanup(pTq->pCheckInfo);
|
||||
taosHashCleanup(pTq->pOffset);
|
||||
taosMemoryFree(pTq->path);
|
||||
tqMetaClose(pTq);
|
||||
|
||||
|
@ -221,7 +217,7 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t sversion, char* msg, int32_t
|
|||
goto end;
|
||||
}
|
||||
|
||||
STqOffset* pSavedOffset = tqOffsetRead(pTq->pOffsetStore, pOffset->subKey);
|
||||
STqOffset* pSavedOffset = (STqOffset*)tqMetaGetOffset(pTq, pOffset->subKey);
|
||||
if (pSavedOffset != NULL && tqOffsetEqual(pOffset, pSavedOffset)) {
|
||||
tqInfo("not update the offset, vgId:%d sub:%s since committed:%" PRId64 " less than/equal to existed:%" PRId64,
|
||||
vgId, pOffset->subKey, pOffset->val.version, pSavedOffset->val.version);
|
||||
|
@ -229,10 +225,14 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t sversion, char* msg, int32_t
|
|||
}
|
||||
|
||||
// save the new offset value
|
||||
code = tqOffsetWrite(pTq->pOffsetStore, pOffset);
|
||||
if(code != 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto end;
|
||||
if (taosHashPut(pTq->pOffset, pOffset->subKey, strlen(pOffset->subKey), pOffset, sizeof(STqOffset))){
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tqMetaSaveInfo(pTq, pTq->pOffsetStore, pOffset->subKey, strlen(pOffset->subKey), msg, msgLen - sizeof(vgOffset.consumerId)) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -360,21 +360,12 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
while (1) {
|
||||
taosWLockLatch(&pTq->lock);
|
||||
// 1. find handle
|
||||
pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey));
|
||||
if (pHandle == NULL) {
|
||||
do {
|
||||
if (tqMetaGetHandle(pTq, req.subKey) == 0) {
|
||||
pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey));
|
||||
if (pHandle != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
code = tqMetaGetHandle(pTq, req.subKey, &pHandle);
|
||||
if (code != TDB_CODE_SUCCESS) {
|
||||
tqError("tmq poll: consumer:0x%" PRIx64 " vgId:%d subkey %s not found", consumerId, vgId, req.subKey);
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
code = -1;
|
||||
goto END;
|
||||
} while (0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 2. check rebalance status
|
||||
|
@ -443,7 +434,7 @@ int32_t tqProcessVgCommittedInfoReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
STqOffset* pSavedOffset = tqOffsetRead(pTq->pOffsetStore, vgOffset.offset.subKey);
|
||||
STqOffset* pSavedOffset = (STqOffset*)tqMetaGetOffset(pTq, vgOffset.offset.subKey);
|
||||
if (pSavedOffset == NULL) {
|
||||
terrno = TSDB_CODE_TMQ_NO_COMMITTED;
|
||||
return terrno;
|
||||
|
@ -523,7 +514,7 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
if (reqOffset.type == TMQ_OFFSET__LOG) {
|
||||
dataRsp.common.rspOffset.version = reqOffset.version;
|
||||
} else if (reqOffset.type < 0) {
|
||||
STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, req.subKey);
|
||||
STqOffset* pOffset = (STqOffset*)(STqOffset*)tqMetaGetOffset(pTq, req.subKey);
|
||||
if (pOffset != NULL) {
|
||||
if (pOffset->val.type != TMQ_OFFSET__LOG) {
|
||||
tqError("consumer:0x%" PRIx64 " vgId:%d subkey:%s, no valid wal info", consumerId, vgId, req.subKey);
|
||||
|
@ -590,12 +581,14 @@ int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
}
|
||||
|
||||
taosWLockLatch(&pTq->lock);
|
||||
code = tqOffsetDelete(pTq->pOffsetStore, pReq->subKey);
|
||||
if (code != 0) {
|
||||
tqError("cannot process tq delete req %s, since no such offset in cache", pReq->subKey);
|
||||
if (taosHashRemove(pTq->pOffset, pReq->subKey, strlen(pReq->subKey)) != 0) {
|
||||
tqError("cannot process tq delete req %s, since no such offset in hash", pReq->subKey);
|
||||
}
|
||||
if (tqMetaDeleteInfo(pTq, pTq->pOffsetStore, pReq->subKey, strlen(pReq->subKey)) != 0) {
|
||||
tqError("cannot process tq delete req %s, since no such offset in tdb", pReq->subKey);
|
||||
}
|
||||
|
||||
if (tqMetaDeleteHandle(pTq, pReq->subKey) < 0) {
|
||||
if (tqMetaDeleteInfo(pTq, pTq->pExecStore, pReq->subKey, strlen(pReq->subKey)) < 0) {
|
||||
tqError("cannot process tq delete req %s, since no such offset in tdb", pReq->subKey);
|
||||
}
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
|
@ -605,18 +598,16 @@ int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
|
||||
int32_t tqProcessAddCheckInfoReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
|
||||
STqCheckInfo info = {0};
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, (uint8_t*)msg, msgLen);
|
||||
if (tDecodeSTqCheckInfo(&decoder, &info) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
if(tqMetaDecodeCheckInfo(&info, msg, msgLen) != 0){
|
||||
return -1;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
if (taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo)) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tDeleteSTqCheckInfo(&info);
|
||||
return -1;
|
||||
}
|
||||
if (tqMetaSaveCheckInfo(pTq, info.topic, msg, msgLen) < 0) {
|
||||
if (tqMetaSaveInfo(pTq, pTq->pCheckStore, info.topic, strlen(info.topic), msg, msgLen) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -628,7 +619,8 @@ int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t sversion, char* msg, int32_t
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
if (tqMetaDeleteCheckInfo(pTq, msg) < 0) {
|
||||
if (tqMetaDeleteInfo(pTq, pTq->pCheckStore, msg, strlen(msg)) < 0) {
|
||||
tqError("cannot process tq delete check info req %s, since no such check info", msg);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -652,19 +644,10 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
tqInfo("vgId:%d, tq process sub req:%s, Id:0x%" PRIx64 " -> Id:0x%" PRIx64, pTq->pVnode->config.vgId, req.subKey,
|
||||
req.oldConsumerId, req.newConsumerId);
|
||||
|
||||
STqHandle* pHandle = NULL;
|
||||
while (1) {
|
||||
pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey));
|
||||
if (pHandle) {
|
||||
break;
|
||||
}
|
||||
taosRLockLatch(&pTq->lock);
|
||||
ret = tqMetaGetHandle(pTq, req.subKey);
|
||||
STqHandle* pHandle = NULL;
|
||||
(void)tqMetaGetHandle(pTq, req.subKey, &pHandle); //ignore return code
|
||||
taosRUnLockLatch(&pTq->lock);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pHandle == NULL) {
|
||||
if (req.oldConsumerId != -1) {
|
||||
tqError("vgId:%d, build new consumer handle %s for consumer:0x%" PRIx64 ", but old consumerId:0x%" PRIx64,
|
||||
|
@ -675,7 +658,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
goto end;
|
||||
}
|
||||
STqHandle handle = {0};
|
||||
ret = tqCreateHandle(pTq, &req, &handle);
|
||||
ret = tqMetaCreateHandle(pTq, &req, &handle);
|
||||
if (ret < 0) {
|
||||
tqDestroyTqHandle(&handle);
|
||||
goto end;
|
||||
|
@ -767,7 +750,7 @@ int32_t tqBuildStreamTask(void* pTqObj, SStreamTask* pTask, int64_t nextProcessV
|
|||
SCheckpointInfo* pChkInfo = &pTask->chkInfo;
|
||||
tqSetRestoreVersionInfo(pTask);
|
||||
|
||||
char* p = streamTaskGetStatus(pTask)->name;
|
||||
char* p = streamTaskGetStatus(pTask).name;
|
||||
const char* pNext = streamTaskGetStatusStr(pTask->status.taskStatus);
|
||||
|
||||
if (pTask->info.fillHistory) {
|
||||
|
@ -856,7 +839,8 @@ int32_t handleStep2Async(SStreamTask* pStreamTask, void* param) {
|
|||
|
||||
SStreamMeta* pMeta = pStreamTask->pMeta;
|
||||
STaskId hId = pStreamTask->hTaskInfo.id;
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pStreamTask->pMeta, hId.streamId, hId.taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pStreamTask->pMeta, hId.streamId, hId.taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqWarn("s-task:0x%x failed to acquired it to exec step 2, scan wal quit", (int32_t) hId.taskId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -874,7 +858,8 @@ int32_t tqProcessTaskScanHistory(STQ* pTq, SRpcMsg* pMsg) {
|
|||
SStreamMeta* pMeta = pTq->pStreamMeta;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d failed to acquire stream task:0x%x during scan history data, task may have been destroyed",
|
||||
pMeta->vgId, pReq->taskId);
|
||||
|
@ -883,7 +868,7 @@ int32_t tqProcessTaskScanHistory(STQ* pTq, SRpcMsg* pMsg) {
|
|||
|
||||
// do recovery step1
|
||||
const char* id = pTask->id.idStr;
|
||||
char* pStatus = streamTaskGetStatus(pTask)->name;
|
||||
char* pStatus = streamTaskGetStatus(pTask).name;
|
||||
|
||||
// avoid multi-thread exec
|
||||
while (1) {
|
||||
|
@ -939,15 +924,15 @@ int32_t tqProcessTaskScanHistory(STQ* pTq, SRpcMsg* pMsg) {
|
|||
if (retInfo.ret == TASK_SCANHISTORY_REXEC) {
|
||||
streamExecScanHistoryInFuture(pTask, retInfo.idleTime);
|
||||
} else {
|
||||
SStreamTaskState* p = streamTaskGetStatus(pTask);
|
||||
ETaskStatus s = p->state;
|
||||
SStreamTaskState p = streamTaskGetStatus(pTask);
|
||||
ETaskStatus s = p.state;
|
||||
|
||||
if (s == TASK_STATUS__PAUSE) {
|
||||
tqDebug("s-task:%s is paused in the step1, elapsed time:%.2fs total:%.2fs, sched-status:%d", pTask->id.idStr,
|
||||
el, pTask->execInfo.step1El, status);
|
||||
} else if (s == TASK_STATUS__STOP || s == TASK_STATUS__DROPPING) {
|
||||
tqDebug("s-task:%s status:%p not continue scan-history data, total elapsed time:%.2fs quit", pTask->id.idStr,
|
||||
p->name, pTask->execInfo.step1El);
|
||||
p.name, pTask->execInfo.step1El);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -961,7 +946,8 @@ int32_t tqProcessTaskScanHistory(STQ* pTq, SRpcMsg* pMsg) {
|
|||
ASSERT(pTask->info.fillHistory == 1);
|
||||
|
||||
// 1. get the related stream task
|
||||
SStreamTask* pStreamTask = streamMetaAcquireTask(pMeta, pTask->streamTaskId.streamId, pTask->streamTaskId.taskId);
|
||||
SStreamTask* pStreamTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, pTask->streamTaskId.streamId, pTask->streamTaskId.taskId, &pStreamTask);
|
||||
if (pStreamTask == NULL) {
|
||||
tqError("failed to find s-task:0x%" PRIx64 ", it may have been destroyed, drop related fill-history task:%s",
|
||||
pTask->streamTaskId.taskId, pTask->id.idStr);
|
||||
|
@ -1121,7 +1107,8 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, req.streamId, req.taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, req.streamId, req.taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d failed to find s-task:0x%x, ignore checkpoint msg. checkpointId:%" PRId64
|
||||
" transId:%d it may have been destroyed",
|
||||
|
@ -1147,7 +1134,7 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
|
|||
|
||||
// todo save the checkpoint failed info
|
||||
taosThreadMutexLock(&pTask->lock);
|
||||
ETaskStatus status = streamTaskGetStatus(pTask)->state;
|
||||
ETaskStatus status = streamTaskGetStatus(pTask).state;
|
||||
|
||||
if (req.mndTrigger == 1) {
|
||||
if (status == TASK_STATUS__HALT || status == TASK_STATUS__PAUSE) {
|
||||
|
|
|
@ -1,196 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "meta.h"
|
||||
#include "tdbInt.h"
|
||||
#include "tq.h"
|
||||
|
||||
// STqCheckInfoReader ========================================
|
||||
struct STqCheckInfoReader {
|
||||
STQ* pTq;
|
||||
int64_t sver;
|
||||
int64_t ever;
|
||||
TBC* pCur;
|
||||
};
|
||||
|
||||
int32_t tqCheckInfoReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqCheckInfoReader** ppReader) {
|
||||
int32_t code = 0;
|
||||
STqCheckInfoReader* pReader = NULL;
|
||||
|
||||
// alloc
|
||||
pReader = (STqCheckInfoReader*)taosMemoryCalloc(1, sizeof(STqCheckInfoReader));
|
||||
if (pReader == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
pReader->pTq = pTq;
|
||||
pReader->sver = sver;
|
||||
pReader->ever = ever;
|
||||
|
||||
// impl
|
||||
code = tdbTbcOpen(pTq->pCheckStore, &pReader->pCur, NULL);
|
||||
if (code) {
|
||||
taosMemoryFree(pReader);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
code = tdbTbcMoveToFirst(pReader->pCur);
|
||||
if (code) {
|
||||
taosMemoryFree(pReader);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
tqInfo("vgId:%d, vnode checkinfo tq reader opened", TD_VID(pTq->pVnode));
|
||||
|
||||
*ppReader = pReader;
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tqError("vgId:%d, vnode checkinfo tq reader open failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
|
||||
*ppReader = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqCheckInfoReaderClose(STqCheckInfoReader** ppReader) {
|
||||
int32_t code = 0;
|
||||
|
||||
tdbTbcClose((*ppReader)->pCur);
|
||||
taosMemoryFree(*ppReader);
|
||||
*ppReader = NULL;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqCheckInfoRead(STqCheckInfoReader* pReader, uint8_t** ppData) {
|
||||
int32_t code = 0;
|
||||
void* pKey = NULL;
|
||||
void* pVal = NULL;
|
||||
int32_t kLen = 0;
|
||||
int32_t vLen = 0;
|
||||
|
||||
if (tdbTbcNext(pReader->pCur, &pKey, &kLen, &pVal, &vLen)) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
*ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + vLen);
|
||||
if (*ppData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
SSnapDataHdr* pHdr = (SSnapDataHdr*)(*ppData);
|
||||
pHdr->type = SNAP_DATA_TQ_CHECKINFO;
|
||||
pHdr->size = vLen;
|
||||
memcpy(pHdr->data, pVal, vLen);
|
||||
|
||||
_exit:
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
|
||||
tqInfo("vgId:%d, vnode check info tq read data, vLen:%d", TD_VID(pReader->pTq->pVnode), vLen);
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
|
||||
tqError("vgId:%d, vnode check info tq read data failed since %s", TD_VID(pReader->pTq->pVnode), tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
// STqCheckInfoWriter ========================================
|
||||
struct STqCheckInfoWriter {
|
||||
STQ* pTq;
|
||||
int64_t sver;
|
||||
int64_t ever;
|
||||
TXN* txn;
|
||||
};
|
||||
|
||||
int32_t tqCheckInfoWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqCheckInfoWriter** ppWriter) {
|
||||
int32_t code = 0;
|
||||
STqCheckInfoWriter* pWriter;
|
||||
|
||||
// alloc
|
||||
pWriter = (STqCheckInfoWriter*)taosMemoryCalloc(1, sizeof(*pWriter));
|
||||
if (pWriter == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
pWriter->pTq = pTq;
|
||||
pWriter->sver = sver;
|
||||
pWriter->ever = ever;
|
||||
|
||||
if (tdbBegin(pTq->pMetaDB, &pWriter->txn, tdbDefaultMalloc, tdbDefaultFree, NULL, 0) < 0) {
|
||||
code = -1;
|
||||
taosMemoryFree(pWriter);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
*ppWriter = pWriter;
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tqError("vgId:%d, tq check info writer open failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
|
||||
*ppWriter = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqCheckInfoWriterClose(STqCheckInfoWriter** ppWriter, int8_t rollback) {
|
||||
int32_t code = 0;
|
||||
STqCheckInfoWriter* pWriter = *ppWriter;
|
||||
STQ* pTq = pWriter->pTq;
|
||||
|
||||
if (rollback) {
|
||||
tdbAbort(pWriter->pTq->pMetaDB, pWriter->txn);
|
||||
} else {
|
||||
code = tdbCommit(pWriter->pTq->pMetaDB, pWriter->txn);
|
||||
if (code) goto _err;
|
||||
code = tdbPostCommit(pWriter->pTq->pMetaDB, pWriter->txn);
|
||||
if (code) goto _err;
|
||||
}
|
||||
|
||||
taosMemoryFree(pWriter);
|
||||
*ppWriter = NULL;
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tqError("vgId:%d, tq check info writer close failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqCheckInfoWrite(STqCheckInfoWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||
int32_t code = 0;
|
||||
STQ* pTq = pWriter->pTq;
|
||||
STqCheckInfo info = {0};
|
||||
SDecoder decoder;
|
||||
SDecoder* pDecoder = &decoder;
|
||||
|
||||
tDecoderInit(pDecoder, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
||||
code = tDecodeSTqCheckInfo(pDecoder, &info);
|
||||
if (code) goto _err;
|
||||
code = taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo));
|
||||
if (code) goto _err;
|
||||
code = tqMetaSaveCheckInfo(pTq, info.topic, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
||||
if (code) goto _err;
|
||||
tDecoderClear(pDecoder);
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tDecoderClear(pDecoder);
|
||||
tqError("vgId:%d, vnode check info tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
|
||||
return code;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tq.h"
|
||||
|
||||
int tqCommit(STQ* pTq) {
|
||||
#if 0
|
||||
// stream meta commit does not be aligned to the vnode commit
|
||||
if (streamMetaCommit(pTq->pStreamMeta) < 0) {
|
||||
tqError("vgId:%d, failed to commit stream meta since %s", TD_VID(pTq->pVnode), terrstr());
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return tqOffsetCommitFile(pTq->pOffsetStore);
|
||||
}
|
|
@ -75,125 +75,98 @@ int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqMetaOpen(STQ* pTq) {
|
||||
if (tdbOpen(pTq->path, 16 * 1024, 1, &pTq->pMetaDB, 0, 0, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbTbOpen("tq.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pExecStore, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbTbOpen("tq.check.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pCheckStore, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqMetaClose(STQ* pTq) {
|
||||
if (pTq->pExecStore) {
|
||||
tdbTbClose(pTq->pExecStore);
|
||||
}
|
||||
if (pTq->pCheckStore) {
|
||||
tdbTbClose(pTq->pCheckStore);
|
||||
}
|
||||
tdbClose(pTq->pMetaDB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqMetaSaveCheckInfo(STQ* pTq, const char* key, const void* value, int32_t vLen) {
|
||||
TXN* txn;
|
||||
|
||||
if (tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) <
|
||||
0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbTbUpsert(pTq->pCheckStore, key, strlen(key), value, vLen, txn) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbCommit(pTq->pMetaDB, txn) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbPostCommit(pTq->pMetaDB, txn) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqMetaDeleteCheckInfo(STQ* pTq, const char* key) {
|
||||
TXN* txn;
|
||||
|
||||
if (tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) <
|
||||
0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbTbDelete(pTq->pCheckStore, key, (int)strlen(key), txn) < 0) {
|
||||
tqWarn("vgId:%d, tq try delete checkinfo failed %s", pTq->pVnode->config.vgId, key);
|
||||
}
|
||||
|
||||
if (tdbCommit(pTq->pMetaDB, txn) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbPostCommit(pTq->pMetaDB, txn) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqMetaRestoreCheckInfo(STQ* pTq) {
|
||||
TBC* pCur = NULL;
|
||||
if (tdbTbcOpen(pTq->pCheckStore, &pCur, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* pKey = NULL;
|
||||
int kLen = 0;
|
||||
void* pVal = NULL;
|
||||
int vLen = 0;
|
||||
SDecoder decoder;
|
||||
int32_t code = 0;
|
||||
|
||||
tdbTbcMoveToFirst(pCur);
|
||||
|
||||
while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) {
|
||||
STqCheckInfo info;
|
||||
int32_t tqMetaDecodeCheckInfo(STqCheckInfo *info, void *pVal, int32_t vLen){
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
|
||||
code = tDecodeSTqCheckInfo(&decoder, &info);
|
||||
int32_t code = tDecodeSTqCheckInfo(&decoder, info);
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
tDeleteSTqCheckInfo(info);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
code = taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo));
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
tdbTbcClose(pCur);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqMetaDecodeOffsetInfo(STqOffset *info, void *pVal, int32_t vLen){
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
|
||||
int32_t code = tDecodeSTqOffset(&decoder, info);
|
||||
if (code != 0) {
|
||||
tDeleteSTqOffset(info);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqMetaSaveInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen, const void* value, int32_t vLen) {
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TXN* txn = NULL;
|
||||
|
||||
TQ_ERR_RETURN(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||
TQ_ERR_RETURN(tdbTbUpsert(ttb, key, kLen, value, vLen, txn));
|
||||
TQ_ERR_RETURN(tdbCommit(pTq->pMetaDB, txn));
|
||||
TQ_ERR_RETURN(tdbPostCommit(pTq->pMetaDB, txn));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqMetaDeleteInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen) {
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TXN* txn = NULL;
|
||||
|
||||
TQ_ERR_RETURN(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||
TQ_ERR_RETURN(tdbTbDelete(ttb, key, kLen, txn));
|
||||
TQ_ERR_RETURN(tdbCommit(pTq->pMetaDB, txn));
|
||||
TQ_ERR_RETURN(tdbPostCommit(pTq->pMetaDB, txn));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tqMetaTransformOffsetInfo(STQ* pTq, char* path) {
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TQ_ERR_RETURN(tqOffsetRestoreFromFile(pTq, path));
|
||||
|
||||
END:
|
||||
return code;
|
||||
}
|
||||
|
||||
void* tqMetaGetOffset(STQ* pTq, const char* subkey){
|
||||
void* data = taosHashGet(pTq->pOffset, subkey, strlen(subkey));
|
||||
if (data == NULL) {
|
||||
int vLen = 0;
|
||||
if (tdbTbGet(pTq->pOffsetStore, subkey, strlen(subkey), &data, &vLen) < 0) {
|
||||
tdbFree(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STqOffset offset = {0};
|
||||
if (tqMetaDecodeOffsetInfo(&offset, data, vLen) != TDB_CODE_SUCCESS) {
|
||||
tdbFree(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(taosHashPut(pTq->pOffset, subkey, strlen(subkey), &offset, sizeof(STqOffset)) != 0){
|
||||
tDeleteSTqOffset(&offset);
|
||||
tdbFree(data);
|
||||
return NULL;
|
||||
}
|
||||
tdbFree(data);
|
||||
|
||||
return taosHashGet(pTq->pOffset, subkey, strlen(subkey));
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) {
|
||||
int32_t code;
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
int32_t vlen;
|
||||
void* buf = NULL;
|
||||
SEncoder encoder;
|
||||
tEncodeSize(tEncodeSTqHandle, pHandle, vlen, code);
|
||||
if (code < 0) {
|
||||
goto end;
|
||||
goto END;
|
||||
}
|
||||
|
||||
tqDebug("tq save %s(%d) handle consumer:0x%" PRIx64 " epoch:%d vgId:%d", pHandle->subKey,
|
||||
|
@ -202,71 +175,35 @@ int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) {
|
|||
buf = taosMemoryCalloc(1, vlen);
|
||||
if (buf == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
goto END;
|
||||
}
|
||||
|
||||
tEncoderInit(&encoder, buf, vlen);
|
||||
|
||||
code = tEncodeSTqHandle(&encoder, pHandle);
|
||||
if (code < 0) {
|
||||
goto end;
|
||||
goto END;
|
||||
}
|
||||
|
||||
TXN* txn = NULL;
|
||||
code = tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||
if (code < 0) {
|
||||
goto end;
|
||||
}
|
||||
TQ_ERR_GO_TO_END(tqMetaSaveInfo(pTq, pTq->pExecStore, key, (int)strlen(key), buf, vlen));
|
||||
|
||||
code = tdbTbUpsert(pTq->pExecStore, key, (int)strlen(key), buf, vlen, txn);
|
||||
if (code < 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
code = tdbCommit(pTq->pMetaDB, txn);
|
||||
if (code < 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
code = tdbPostCommit(pTq->pMetaDB, txn);
|
||||
end:
|
||||
END:
|
||||
tEncoderClear(&encoder);
|
||||
taosMemoryFree(buf);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqMetaDeleteHandle(STQ* pTq, const char* key) {
|
||||
TXN* txn;
|
||||
|
||||
if (tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) <
|
||||
0) {
|
||||
return -1;
|
||||
}
|
||||
static int tqMetaInitHandle(STQ* pTq, STqHandle* handle){
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
|
||||
if (tdbTbDelete(pTq->pExecStore, key, (int)strlen(key), txn) < 0) {
|
||||
}
|
||||
|
||||
if (tdbCommit(pTq->pMetaDB, txn) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbPostCommit(pTq->pMetaDB, txn) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int buildHandle(STQ* pTq, STqHandle* handle) {
|
||||
SVnode* pVnode = pTq->pVnode;
|
||||
int32_t vgId = TD_VID(pVnode);
|
||||
|
||||
handle->pRef = walOpenRef(pVnode->pWal);
|
||||
if (handle->pRef == NULL) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
TAOS_CHECK_RETURN(walSetRefVer(handle->pRef, handle->snapshotVer));
|
||||
TQ_ERR_RETURN(walSetRefVer(handle->pRef, handle->snapshotVer));
|
||||
|
||||
SReadHandle reader = {
|
||||
.vnode = pVnode,
|
||||
|
@ -282,18 +219,18 @@ static int buildHandle(STQ* pTq, STqHandle* handle) {
|
|||
&handle->execHandle.numOfCols, handle->consumerId);
|
||||
if (handle->execHandle.task == NULL) {
|
||||
tqError("cannot create exec task for %s", handle->subKey);
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
void* scanner = NULL;
|
||||
qExtractStreamScanner(handle->execHandle.task, &scanner);
|
||||
(void)qExtractStreamScanner(handle->execHandle.task, &scanner);
|
||||
if (scanner == NULL) {
|
||||
tqError("cannot extract stream scanner for %s", handle->subKey);
|
||||
return -1;
|
||||
return TSDB_CODE_SCH_INTERNAL_ERROR;
|
||||
}
|
||||
handle->execHandle.pTqReader = qExtractReaderFromStreamScanner(scanner);
|
||||
if (handle->execHandle.pTqReader == NULL) {
|
||||
tqError("cannot extract exec reader for %s", handle->subKey);
|
||||
return -1;
|
||||
return TSDB_CODE_SCH_INTERNAL_ERROR;
|
||||
}
|
||||
} else if (handle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
handle->pWalReader = walOpenReader(pVnode->pWal, NULL, 0);
|
||||
|
@ -308,7 +245,7 @@ static int buildHandle(STQ* pTq, STqHandle* handle) {
|
|||
if (handle->execHandle.execTb.qmsg != NULL && strcmp(handle->execHandle.execTb.qmsg, "") != 0) {
|
||||
if (nodesStringToNode(handle->execHandle.execTb.qmsg, &handle->execHandle.execTb.node) != 0) {
|
||||
tqError("nodesStringToNode error in sub stable, since %s", terrstr());
|
||||
return -1;
|
||||
return TSDB_CODE_SCH_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
buildSnapContext(reader.vnode, reader.version, handle->execHandle.execTb.suid, handle->execHandle.subType,
|
||||
|
@ -321,7 +258,7 @@ static int buildHandle(STQ* pTq, STqHandle* handle) {
|
|||
if (ret != TDB_CODE_SUCCESS) {
|
||||
tqError("qGetTableList error:%d handle %s consumer:0x%" PRIx64, ret, handle->subKey, handle->consumerId);
|
||||
taosArrayDestroy(tbUidList);
|
||||
return -1;
|
||||
return TSDB_CODE_SCH_INTERNAL_ERROR;
|
||||
}
|
||||
tqInfo("vgId:%d, tq try to get ctb for stb subscribe, suid:%" PRId64, pVnode->config.vgId,
|
||||
handle->execHandle.execTb.suid);
|
||||
|
@ -332,24 +269,23 @@ static int buildHandle(STQ* pTq, STqHandle* handle) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int restoreHandle(STQ* pTq, void* pVal, int vLen, STqHandle* handle) {
|
||||
static int32_t tqMetaRestoreHandle(STQ* pTq, void* pVal, int vLen, STqHandle* handle){
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
SDecoder decoder;
|
||||
int32_t code = 0;
|
||||
SDecoder decoder = {0};
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
|
||||
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
|
||||
code = tDecodeSTqHandle(&decoder, handle);
|
||||
if (code) goto end;
|
||||
code = buildHandle(pTq, handle);
|
||||
if (code) goto end;
|
||||
tqInfo("restoreHandle %s consumer 0x%" PRIx64 " vgId:%d", handle->subKey, handle->consumerId, vgId);
|
||||
TQ_ERR_GO_TO_END(tDecodeSTqHandle(&decoder, handle));
|
||||
TQ_ERR_GO_TO_END(tqMetaInitHandle(pTq, handle));
|
||||
tqInfo("tqMetaRestoreHandle %s consumer 0x%" PRIx64 " vgId:%d", handle->subKey, handle->consumerId, vgId);
|
||||
code = taosHashPut(pTq->pHandle, handle->subKey, strlen(handle->subKey), handle, sizeof(STqHandle));
|
||||
|
||||
end:
|
||||
END:
|
||||
tDecoderClear(&decoder);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) {
|
||||
int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle){
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
memcpy(handle->subKey, req->subKey, TSDB_SUBSCRIBE_KEY_LEN);
|
||||
|
@ -369,165 +305,180 @@ int32_t tqCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) {
|
|||
|
||||
handle->snapshotVer = walGetCommittedVer(pTq->pVnode->pWal);
|
||||
|
||||
if (buildHandle(pTq, handle) < 0) {
|
||||
if(tqMetaInitHandle(pTq, handle) < 0){
|
||||
return -1;
|
||||
}
|
||||
tqInfo("tqCreateHandle %s consumer 0x%" PRIx64 " vgId:%d, snapshotVer:%" PRId64, handle->subKey, handle->consumerId,
|
||||
vgId, handle->snapshotVer);
|
||||
tqInfo("tqMetaCreateHandle %s consumer 0x%" PRIx64 " vgId:%d, snapshotVer:%" PRId64, handle->subKey, handle->consumerId, vgId, handle->snapshotVer);
|
||||
return taosHashPut(pTq->pHandle, handle->subKey, strlen(handle->subKey), handle, sizeof(STqHandle));
|
||||
}
|
||||
|
||||
static int32_t tqMetaTransformInfo(TDB* pMetaDB, TTB* pExecStoreOld, TTB* pExecStoreNew) {
|
||||
static int32_t tqMetaTransformInfo(TDB* pMetaDB, TTB* pOld, TTB* pNew){
|
||||
TBC* pCur = NULL;
|
||||
if (tdbTbcOpen(pExecStoreOld, &pCur, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TXN* txn;
|
||||
if (tdbBegin(pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* pKey = NULL;
|
||||
int kLen = 0;
|
||||
void* pVal = NULL;
|
||||
int vLen = 0;
|
||||
TXN* txn = NULL;
|
||||
|
||||
tdbTbcMoveToFirst(pCur);
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
|
||||
TQ_ERR_GO_TO_END(tdbTbcOpen(pOld, &pCur, NULL));
|
||||
TQ_ERR_GO_TO_END(tdbBegin(pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||
|
||||
TQ_ERR_GO_TO_END(tdbTbcMoveToFirst(pCur));
|
||||
while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) {
|
||||
if (tdbTbUpsert(pExecStoreNew, pKey, kLen, pVal, vLen, txn) < 0) {
|
||||
tqError("transform sub info error");
|
||||
TQ_ERR_GO_TO_END (tdbTbUpsert(pNew, pKey, kLen, pVal, vLen, txn));
|
||||
}
|
||||
|
||||
TQ_ERR_GO_TO_END (tdbCommit(pMetaDB, txn));
|
||||
TQ_ERR_GO_TO_END (tdbPostCommit(pMetaDB, txn));
|
||||
|
||||
END:
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
(void)tdbTbcClose(pCur);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqMetaGetHandle(STQ* pTq, const char* key, STqHandle** pHandle) {
|
||||
void* data = taosHashGet(pTq->pHandle, key, strlen(key));
|
||||
if(data == NULL){
|
||||
int vLen = 0;
|
||||
if (tdbTbGet(pTq->pExecStore, key, (int)strlen(key), &data, &vLen) < 0) {
|
||||
tdbFree(data);
|
||||
return TSDB_CODE_MND_SUBSCRIBE_NOT_EXIST;
|
||||
}
|
||||
STqHandle handle = {0};
|
||||
if (tqMetaRestoreHandle(pTq, data, vLen, &handle) != 0){
|
||||
tdbFree(data);
|
||||
tqDestroyTqHandle(&handle);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tdbFree(data);
|
||||
*pHandle = taosHashGet(pTq->pHandle, key, strlen(key));
|
||||
if(*pHandle == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}else{
|
||||
*pHandle = data;
|
||||
}
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tqMetaOpenTdb(STQ* pTq) {
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TQ_ERR_GO_TO_END(tdbOpen(pTq->path, 16 * 1024, 1, &pTq->pMetaDB, 0, 0, NULL));
|
||||
TQ_ERR_GO_TO_END(tdbTbOpen("tq.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pExecStore, 0));
|
||||
TQ_ERR_GO_TO_END(tdbTbOpen("tq.check.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pCheckStore, 0));
|
||||
TQ_ERR_GO_TO_END(tdbTbOpen("tq.offset.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pOffsetStore, 0));
|
||||
|
||||
END:
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t replaceTqPath(char** path){
|
||||
char* tpath = NULL;
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TQ_ERR_RETURN(tqBuildFName(&tpath, *path, TQ_SUBSCRIBE_NAME));
|
||||
taosMemoryFree(*path);
|
||||
*path = tpath;
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tqMetaRestoreCheckInfo(STQ* pTq) {
|
||||
TBC* pCur = NULL;
|
||||
void* pKey = NULL;
|
||||
int kLen = 0;
|
||||
void* pVal = NULL;
|
||||
int vLen = 0;
|
||||
int32_t code = 0;
|
||||
STqCheckInfo info = {0};
|
||||
|
||||
TQ_ERR_GO_TO_END(tdbTbcOpen(pTq->pCheckStore, &pCur, NULL));
|
||||
TQ_ERR_GO_TO_END(tdbTbcMoveToFirst(pCur));
|
||||
|
||||
while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) {
|
||||
TQ_ERR_GO_TO_END(tqMetaDecodeCheckInfo(&info, pVal, vLen));
|
||||
TQ_ERR_GO_TO_END(taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo)));
|
||||
}
|
||||
info.colIdList = NULL;
|
||||
|
||||
END:
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
tdbTbcClose(pCur);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
tdbTbcClose(pCur);
|
||||
|
||||
if (tdbCommit(pMetaDB, txn) < 0) {
|
||||
return -1;
|
||||
tDeleteSTqCheckInfo(&info);
|
||||
return code;
|
||||
}
|
||||
|
||||
if (tdbPostCommit(pMetaDB, txn) < 0) {
|
||||
return -1;
|
||||
int32_t tqMetaOpen(STQ* pTq) {
|
||||
char* maindb = NULL;
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TQ_ERR_GO_TO_END(tqBuildFName(&maindb, pTq->path, TDB_MAINDB_NAME));
|
||||
if(!taosCheckExistFile(maindb)){
|
||||
TQ_ERR_GO_TO_END(replaceTqPath(&pTq->path));
|
||||
TQ_ERR_GO_TO_END(tqMetaOpenTdb(pTq));
|
||||
}else{
|
||||
TQ_ERR_GO_TO_END(tqMetaTransform(pTq));
|
||||
taosRemoveFile(maindb);
|
||||
}
|
||||
return 0;
|
||||
TQ_ERR_GO_TO_END(tqMetaRestoreCheckInfo(pTq));
|
||||
|
||||
END:
|
||||
taosMemoryFree(maindb);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqMetaTransform(STQ* pTq) {
|
||||
int32_t len = strlen(pTq->path) + 64;
|
||||
char* maindb = taosMemoryCalloc(1, len);
|
||||
sprintf(maindb, "%s%s%s", pTq->path, TD_DIRSEP, TDB_MAINDB_NAME);
|
||||
|
||||
if (!taosCheckExistFile(maindb)) {
|
||||
taosMemoryFree(maindb);
|
||||
char* tpath = taosMemoryCalloc(1, len);
|
||||
if (tpath == NULL) {
|
||||
return -1;
|
||||
}
|
||||
sprintf(tpath, "%s%s%s", pTq->path, TD_DIRSEP, "subscribe");
|
||||
taosMemoryFree(pTq->path);
|
||||
pTq->path = tpath;
|
||||
return tqMetaOpen(pTq);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TDB* pMetaDB = NULL;
|
||||
TTB* pExecStore = NULL;
|
||||
TTB* pCheckStore = NULL;
|
||||
char* offsetNew = NULL;
|
||||
char* offset = tqOffsetBuildFName(pTq->path, 0);
|
||||
if (offset == NULL) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
char* offset = NULL;
|
||||
TQ_ERR_GO_TO_END(tqBuildFName(&offset, pTq->path, TQ_OFFSET_NAME));
|
||||
|
||||
if (tdbOpen(pTq->path, 16 * 1024, 1, &pMetaDB, 0, 0, NULL) < 0) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
TQ_ERR_GO_TO_END(tdbOpen(pTq->path, 16 * 1024, 1, &pMetaDB, 0, 0, NULL));
|
||||
TQ_ERR_GO_TO_END(tdbTbOpen("tq.db", -1, -1, NULL, pMetaDB, &pExecStore, 0));
|
||||
TQ_ERR_GO_TO_END(tdbTbOpen("tq.check.db", -1, -1, NULL, pMetaDB, &pCheckStore, 0));
|
||||
|
||||
if (tdbTbOpen("tq.db", -1, -1, NULL, pMetaDB, &pExecStore, 0) < 0) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
TQ_ERR_GO_TO_END(replaceTqPath(&pTq->path));
|
||||
TQ_ERR_GO_TO_END(tqMetaOpenTdb(pTq));
|
||||
|
||||
if (tdbTbOpen("tq.check.db", -1, -1, NULL, pMetaDB, &pCheckStore, 0) < 0) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
TQ_ERR_GO_TO_END(tqMetaTransformInfo(pTq->pMetaDB, pExecStore, pTq->pExecStore));
|
||||
TQ_ERR_GO_TO_END(tqMetaTransformInfo(pTq->pMetaDB, pCheckStore, pTq->pCheckStore));
|
||||
|
||||
char* tpath = taosMemoryCalloc(1, len);
|
||||
if (tpath == NULL) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
sprintf(tpath, "%s%s%s", pTq->path, TD_DIRSEP, "subscribe");
|
||||
taosMemoryFree(pTq->path);
|
||||
pTq->path = tpath;
|
||||
if (tqMetaOpen(pTq) < 0) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (tqMetaTransformInfo(pTq->pMetaDB, pExecStore, pTq->pExecStore) < 0) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (tqMetaTransformInfo(pTq->pMetaDB, pCheckStore, pTq->pCheckStore) < 0) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
tdbTbClose(pExecStore);
|
||||
pExecStore = NULL;
|
||||
tdbTbClose(pCheckStore);
|
||||
pCheckStore = NULL;
|
||||
tdbClose(pMetaDB);
|
||||
pMetaDB = NULL;
|
||||
|
||||
offsetNew = tqOffsetBuildFName(pTq->path, 0);
|
||||
if (offsetNew == NULL) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME));
|
||||
if(taosCheckExistFile(offset) && taosCopyFile(offset, offsetNew) < 0){
|
||||
tqError("copy offset file error");
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
taosRemoveFile(maindb);
|
||||
taosRemoveFile(offset);
|
||||
TQ_ERR_GO_TO_END(tqMetaTransformOffsetInfo(pTq, offsetNew));
|
||||
(void)taosRemoveFile(offset);
|
||||
(void)taosRemoveFile(offsetNew);
|
||||
|
||||
END:
|
||||
taosMemoryFree(maindb);
|
||||
taosMemoryFree(offset);
|
||||
taosMemoryFree(offsetNew);
|
||||
|
||||
tdbTbClose(pExecStore);
|
||||
tdbTbClose(pCheckStore);
|
||||
tdbClose(pMetaDB);
|
||||
//return 0 always, so ignore
|
||||
(void)tdbTbClose(pExecStore);
|
||||
(void)tdbTbClose(pCheckStore);
|
||||
(void)tdbClose(pMetaDB);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqMetaGetHandle(STQ* pTq, const char* key) {
|
||||
void* pVal = NULL;
|
||||
int vLen = 0;
|
||||
|
||||
if (tdbTbGet(pTq->pExecStore, key, (int)strlen(key), &pVal, &vLen) < 0) {
|
||||
return -1;
|
||||
int32_t tqMetaClose(STQ* pTq) {
|
||||
if (pTq->pExecStore) {
|
||||
(void)tdbTbClose(pTq->pExecStore);
|
||||
}
|
||||
STqHandle handle = {0};
|
||||
int code = restoreHandle(pTq, pVal, vLen, &handle);
|
||||
if (code < 0) {
|
||||
tqDestroyTqHandle(&handle);
|
||||
if (pTq->pCheckStore) {
|
||||
(void)tdbTbClose(pTq->pCheckStore);
|
||||
}
|
||||
tdbFree(pVal);
|
||||
return code;
|
||||
if (pTq->pOffsetStore) {
|
||||
(void)tdbTbClose(pTq->pOffsetStore);
|
||||
}
|
||||
(void)tdbClose(pTq->pMetaDB);
|
||||
return 0;
|
||||
}
|
|
@ -16,192 +16,70 @@
|
|||
|
||||
#include "tq.h"
|
||||
|
||||
struct STqOffsetStore {
|
||||
STQ* pTq;
|
||||
SHashObj* pHash; // SHashObj<subscribeKey, offset>
|
||||
int8_t needCommit;
|
||||
};
|
||||
|
||||
char* tqOffsetBuildFName(const char* path, int32_t fVer) {
|
||||
int32_t len = strlen(path);
|
||||
char* fname = taosMemoryCalloc(1, len + 40);
|
||||
int32_t tqBuildFName(char** data, const char* path, char* name) {
|
||||
int32_t len = strlen(path) + strlen(name) + 2;
|
||||
char* fname = taosMemoryCalloc(1, len);
|
||||
if(fname == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
snprintf(fname, len + 40, "%s/offset-ver%d", path, fVer);
|
||||
return fname;
|
||||
int32_t code = snprintf(fname, len, "%s%s%s", path, TD_DIRSEP, name);
|
||||
if (code < 0){
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
taosMemoryFree(fname);
|
||||
return code;
|
||||
}
|
||||
*data = fname;
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tqOffsetRestoreFromFile(STqOffsetStore* pStore, const char* fname) {
|
||||
TdFilePtr pFile = taosOpenFile(fname, TD_FILE_READ);
|
||||
int32_t tqOffsetRestoreFromFile(STQ* pTq, char* name) {
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
void* pMemBuf = NULL;
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(name, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
code = TDB_CODE_SUCCESS;
|
||||
goto END;
|
||||
}
|
||||
|
||||
int32_t vgId = TD_VID(pStore->pTq->pVnode);
|
||||
int64_t code = 0;
|
||||
int64_t ret = 0;
|
||||
int32_t size = 0;
|
||||
while (1) {
|
||||
if ((code = taosReadFile(pFile, &size, INT_BYTES)) != INT_BYTES) {
|
||||
if (code == 0) {
|
||||
break;
|
||||
} else {
|
||||
return -1;
|
||||
if ((ret = taosReadFile(pFile, &size, INT_BYTES)) != INT_BYTES) {
|
||||
if (ret != 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
goto END;
|
||||
}
|
||||
|
||||
size = htonl(size);
|
||||
void* pMemBuf = taosMemoryCalloc(1, size);
|
||||
pMemBuf = taosMemoryCalloc(1, size);
|
||||
if (pMemBuf == NULL) {
|
||||
tqError("vgId:%d failed to restore offset from file, since out of memory, malloc size:%d", vgId, size);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
|
||||
if ((code = taosReadFile(pFile, pMemBuf, size)) != size) {
|
||||
taosMemoryFree(pMemBuf);
|
||||
return -1;
|
||||
if (taosReadFile(pFile, pMemBuf, size) != size) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto END;
|
||||
}
|
||||
|
||||
STqOffset offset = {0};
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, pMemBuf, size);
|
||||
if (tDecodeSTqOffset(&decoder, &offset) < 0) {
|
||||
TQ_ERR_GO_TO_END(tqMetaDecodeOffsetInfo(&offset, pMemBuf, size));
|
||||
code = taosHashPut(pTq->pOffset, offset.subKey, strlen(offset.subKey), &offset, sizeof(STqOffset));
|
||||
if (code != TDB_CODE_SUCCESS) {
|
||||
tDeleteSTqOffset(&offset);
|
||||
goto END;
|
||||
}
|
||||
TQ_ERR_GO_TO_END(tqMetaSaveInfo(pTq, pTq->pOffsetStore, offset.subKey, strlen(offset.subKey), pMemBuf, size));
|
||||
|
||||
taosMemoryFree(pMemBuf);
|
||||
tDecoderClear(&decoder);
|
||||
pMemBuf = NULL;
|
||||
}
|
||||
|
||||
END:
|
||||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(pMemBuf);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
if (taosHashPut(pStore->pHash, offset.subKey, strlen(offset.subKey), &offset, sizeof(STqOffset)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// todo remove this
|
||||
if (offset.val.type == TMQ_OFFSET__LOG) {
|
||||
STqHandle* pHandle = taosHashGet(pStore->pTq->pHandle, offset.subKey, strlen(offset.subKey));
|
||||
if (pHandle) {
|
||||
if (walSetRefVer(pHandle->pRef, offset.val.version) < 0) {
|
||||
// tqError("vgId: %d, tq handle %s ref ver %" PRId64 "error", pStore->pTq->pVnode->config.vgId, pHandle->subKey,
|
||||
// offset.val.version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taosMemoryFree(pMemBuf);
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STqOffsetStore* tqOffsetOpen(STQ* pTq) {
|
||||
STqOffsetStore* pStore = taosMemoryCalloc(1, sizeof(STqOffsetStore));
|
||||
if (pStore == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pStore->pTq = pTq;
|
||||
pStore->needCommit = 0;
|
||||
pTq->pOffsetStore = pStore;
|
||||
|
||||
pStore->pHash = taosHashInit(64, MurmurHash3_32, true, HASH_ENTRY_LOCK);
|
||||
if (pStore->pHash == NULL) {
|
||||
taosMemoryFree(pStore);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosHashSetFreeFp(pStore->pHash, tOffsetDestroy);
|
||||
char* fname = tqOffsetBuildFName(pStore->pTq->path, 0);
|
||||
if (tqOffsetRestoreFromFile(pStore, fname) < 0) {
|
||||
taosMemoryFree(fname);
|
||||
taosMemoryFree(pStore);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosMemoryFree(fname);
|
||||
return pStore;
|
||||
}
|
||||
|
||||
void tqOffsetClose(STqOffsetStore* pStore) {
|
||||
if(pStore == NULL) return;
|
||||
tqOffsetCommitFile(pStore);
|
||||
taosHashCleanup(pStore->pHash);
|
||||
taosMemoryFree(pStore);
|
||||
}
|
||||
|
||||
STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey) {
|
||||
return (STqOffset*)taosHashGet(pStore->pHash, subscribeKey, strlen(subscribeKey));
|
||||
}
|
||||
|
||||
int32_t tqOffsetWrite(STqOffsetStore* pStore, const STqOffset* pOffset) {
|
||||
pStore->needCommit = 1;
|
||||
return taosHashPut(pStore->pHash, pOffset->subKey, strlen(pOffset->subKey), pOffset, sizeof(STqOffset));
|
||||
}
|
||||
|
||||
int32_t tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey) {
|
||||
return taosHashRemove(pStore->pHash, subscribeKey, strlen(subscribeKey));
|
||||
}
|
||||
|
||||
int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
|
||||
if (!pStore->needCommit) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO file name should be with a newer version
|
||||
char* fname = tqOffsetBuildFName(pStore->pTq->path, 0);
|
||||
TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
const char* err = strerror(errno);
|
||||
tqError("vgId:%d, failed to open offset file %s, since %s", TD_VID(pStore->pTq->pVnode), fname, err);
|
||||
taosMemoryFree(fname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosMemoryFree(fname);
|
||||
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pStore->pHash, pIter);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
STqOffset* pOffset = (STqOffset*)pIter;
|
||||
int32_t bodyLen;
|
||||
int32_t code;
|
||||
tEncodeSize(tEncodeSTqOffset, pOffset, bodyLen, code);
|
||||
|
||||
if (code < 0) {
|
||||
taosHashCancelIterate(pStore->pHash, pIter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t totLen = INT_BYTES + bodyLen;
|
||||
void* buf = taosMemoryCalloc(1, totLen);
|
||||
void* abuf = POINTER_SHIFT(buf, INT_BYTES);
|
||||
|
||||
*(int32_t*)buf = htonl(bodyLen);
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, abuf, bodyLen);
|
||||
tEncodeSTqOffset(&encoder, pOffset);
|
||||
|
||||
// write file
|
||||
int64_t writeLen;
|
||||
if ((writeLen = taosWriteFile(pFile, buf, totLen)) != totLen) {
|
||||
tqError("write offset incomplete, len %d, write len %" PRId64, bodyLen, writeLen);
|
||||
taosHashCancelIterate(pStore->pHash, pIter);
|
||||
taosMemoryFree(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosMemoryFree(buf);
|
||||
}
|
||||
|
||||
// close and rename file
|
||||
taosCloseFile(&pFile);
|
||||
pStore->needCommit = 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,168 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "meta.h"
|
||||
#include "tdbInt.h"
|
||||
#include "tq.h"
|
||||
|
||||
// STqOffsetReader ========================================
|
||||
struct STqOffsetReader {
|
||||
STQ* pTq;
|
||||
int64_t sver;
|
||||
int64_t ever;
|
||||
int8_t readEnd;
|
||||
};
|
||||
|
||||
int32_t tqOffsetReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqOffsetReader** ppReader) {
|
||||
STqOffsetReader* pReader = NULL;
|
||||
|
||||
pReader = taosMemoryCalloc(1, sizeof(STqOffsetReader));
|
||||
if (pReader == NULL) {
|
||||
*ppReader = NULL;
|
||||
return -1;
|
||||
}
|
||||
pReader->pTq = pTq;
|
||||
pReader->sver = sver;
|
||||
pReader->ever = ever;
|
||||
|
||||
tqInfo("vgId:%d, vnode snapshot tq offset reader opened", TD_VID(pTq->pVnode));
|
||||
|
||||
*ppReader = pReader;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqOffsetReaderClose(STqOffsetReader** ppReader) {
|
||||
taosMemoryFree(*ppReader);
|
||||
*ppReader = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqOffsetSnapRead(STqOffsetReader* pReader, uint8_t** ppData) {
|
||||
if (pReader->readEnd != 0) return 0;
|
||||
|
||||
char* fname = tqOffsetBuildFName(pReader->pTq->path, 0);
|
||||
TdFilePtr pFile = taosOpenFile(fname, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
taosMemoryFree(fname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t sz = 0;
|
||||
if (taosStatFile(fname, &sz, NULL, NULL) < 0) {
|
||||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(fname);
|
||||
return -1;
|
||||
}
|
||||
taosMemoryFree(fname);
|
||||
|
||||
SSnapDataHdr* buf = taosMemoryCalloc(1, sz + sizeof(SSnapDataHdr));
|
||||
if (buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosCloseFile(&pFile);
|
||||
return terrno;
|
||||
}
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SSnapDataHdr));
|
||||
int64_t contLen = taosReadFile(pFile, abuf, sz);
|
||||
if (contLen != sz) {
|
||||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(buf);
|
||||
return -1;
|
||||
}
|
||||
buf->size = sz;
|
||||
buf->type = SNAP_DATA_TQ_OFFSET;
|
||||
*ppData = (uint8_t*)buf;
|
||||
|
||||
pReader->readEnd = 1;
|
||||
taosCloseFile(&pFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// STqOffseWriter ========================================
|
||||
struct STqOffsetWriter {
|
||||
STQ* pTq;
|
||||
int64_t sver;
|
||||
int64_t ever;
|
||||
int32_t tmpFileVer;
|
||||
char* fname;
|
||||
};
|
||||
|
||||
int32_t tqOffsetWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqOffsetWriter** ppWriter) {
|
||||
int32_t code = 0;
|
||||
STqOffsetWriter* pWriter;
|
||||
|
||||
pWriter = (STqOffsetWriter*)taosMemoryCalloc(1, sizeof(STqOffsetWriter));
|
||||
if (pWriter == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
pWriter->pTq = pTq;
|
||||
pWriter->sver = sver;
|
||||
pWriter->ever = ever;
|
||||
|
||||
*ppWriter = pWriter;
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tqError("vgId:%d, tq snapshot writer open failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
|
||||
*ppWriter = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqOffsetWriterClose(STqOffsetWriter** ppWriter, int8_t rollback) {
|
||||
STqOffsetWriter* pWriter = *ppWriter;
|
||||
STQ* pTq = pWriter->pTq;
|
||||
char* fname = tqOffsetBuildFName(pTq->path, 0);
|
||||
|
||||
if (rollback) {
|
||||
if (taosRemoveFile(pWriter->fname) < 0) {
|
||||
taosMemoryFree(fname);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (taosRenameFile(pWriter->fname, fname) < 0) {
|
||||
taosMemoryFree(fname);
|
||||
return -1;
|
||||
}
|
||||
if (tqOffsetRestoreFromFile(pTq->pOffsetStore, fname) < 0) {
|
||||
taosMemoryFree(fname);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
taosMemoryFree(fname);
|
||||
taosMemoryFree(pWriter->fname);
|
||||
taosMemoryFree(pWriter);
|
||||
*ppWriter = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqOffsetSnapWrite(STqOffsetWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||
STQ* pTq = pWriter->pTq;
|
||||
pWriter->tmpFileVer = 1;
|
||||
pWriter->fname = tqOffsetBuildFName(pTq->path, pWriter->tmpFileVer);
|
||||
TdFilePtr pFile = taosOpenFile(pWriter->fname, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||
SSnapDataHdr* pHdr = (SSnapDataHdr*)pData;
|
||||
int64_t size = pHdr->size;
|
||||
if (pFile) {
|
||||
int64_t contLen = taosWriteFile(pFile, pHdr->data, size);
|
||||
if (contLen != size) {
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
}
|
||||
taosCloseFile(&pFile);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -339,10 +339,8 @@ int32_t extractMsgFromWal(SWalReader* pReader, void** pItem, int64_t maxVer, con
|
|||
memcpy(data, pBody, len);
|
||||
SPackedData data1 = (SPackedData){.ver = ver, .msgLen = len, .msgStr = data};
|
||||
|
||||
*pItem = (SStreamQueueItem*)streamDataSubmitNew(&data1, STREAM_INPUT__DATA_SUBMIT);
|
||||
if (*pItem == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
terrno = code;
|
||||
code = streamDataSubmitNew(&data1, STREAM_INPUT__DATA_SUBMIT, (SStreamDataSubmit**)pItem);
|
||||
if (code != 0) {
|
||||
tqError("%s failed to create data submit for stream since out of memory", id);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -725,6 +725,7 @@ int32_t setDstTableDataUid(SVnode* pVnode, SStreamTask* pTask, SSDataBlock* pDat
|
|||
if (metaGetTableEntryByName(&mr, dstTableName) < 0) {
|
||||
metaReaderClear(&mr);
|
||||
|
||||
if (pTask->outputInfo.tbSink.autoCreateCtb) {
|
||||
tqDebug("s-task:%s stream write into table:%s, table auto created", id, dstTableName);
|
||||
|
||||
SArray* pTagArray = taosArrayInit(pTSchema->numOfCols + 1, sizeof(STagVal));
|
||||
|
@ -736,13 +737,21 @@ int32_t setDstTableDataUid(SVnode* pVnode, SStreamTask* pTask, SSDataBlock* pDat
|
|||
taosArrayDestroy(pTagArray);
|
||||
|
||||
if (pTableData->pCreateTbReq == NULL) {
|
||||
tqError("s-task:%s failed to build auto create table req, code:%s", id, tstrerror(terrno));
|
||||
tqError("s-task:%s failed to build auto create dst-table req:%s, code:%s", id, dstTableName,
|
||||
tstrerror(terrno));
|
||||
taosMemoryFree(pTableSinkInfo);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pTableSinkInfo->uid = 0;
|
||||
doPutIntoCache(pTask->outputInfo.tbSink.pTblInfo, pTableSinkInfo, groupId, id);
|
||||
} else {
|
||||
metaReaderClear(&mr);
|
||||
|
||||
tqError("s-task:%s vgId:%d dst-table:%s not auto-created, and not create in tsdb, discard data", id,
|
||||
vgId, dstTableName);
|
||||
return TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
} else {
|
||||
bool isValid = isValidDstChildTable(&mr, vgId, dstTableName, suid);
|
||||
if (!isValid) {
|
||||
|
@ -798,6 +807,24 @@ void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data) {
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
const char* id = pTask->id.idStr;
|
||||
int64_t earlyTs = tsdbGetEarliestTs(pVnode->pTsdb);
|
||||
STaskOutputInfo* pOutputInfo = &pTask->outputInfo;
|
||||
|
||||
if (pTask->outputInfo.tbSink.pTagSchema == NULL) {
|
||||
SMetaReader mer1 = {0};
|
||||
metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
|
||||
|
||||
code = metaReaderGetTableEntryByUid(&mer1, pOutputInfo->tbSink.stbUid);
|
||||
pOutputInfo->tbSink.pTagSchema = tCloneSSchemaWrapper(&mer1.me.stbEntry.schemaTag);
|
||||
metaReaderClear(&mer1);
|
||||
|
||||
SSchemaWrapper* pTagSchema = pOutputInfo->tbSink.pTagSchema;
|
||||
SSchema* pCol1 = &pTagSchema->pSchema[0];
|
||||
if (pTagSchema->nCols == 1 && pCol1->type == TSDB_DATA_TYPE_UBIGINT && strcmp(pCol1->name, "group_id") == 0) {
|
||||
pOutputInfo->tbSink.autoCreateCtb = true;
|
||||
} else {
|
||||
pOutputInfo->tbSink.autoCreateCtb = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool onlySubmitData = hasOnlySubmitData(pBlocks, numOfBlocks);
|
||||
if (!onlySubmitData) {
|
||||
|
@ -829,6 +856,7 @@ void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data) {
|
|||
SSubmitTbData tbData = {.suid = suid, .uid = 0, .sver = pTSchema->version, .flags = TD_REQ_FROM_APP};
|
||||
code = setDstTableDataUid(pVnode, pTask, pDataBlock, stbFullName, &tbData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tqError("vgId:%d s-task:%s dst-table not exist, stb:%s discard stream results", vgId, id, stbFullName);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -882,6 +910,7 @@ void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data) {
|
|||
if (index == NULL) { // no data yet, append it
|
||||
code = setDstTableDataUid(pVnode, pTask, pDataBlock, stbFullName, &tbData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tqError("vgId:%d dst-table gid:%" PRId64 " not exist, discard stream results", vgId, groupId);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,10 @@ struct STqSnapReader {
|
|||
int64_t sver;
|
||||
int64_t ever;
|
||||
TBC* pCur;
|
||||
int8_t type;
|
||||
};
|
||||
|
||||
int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapReader** ppReader) {
|
||||
int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, int8_t type, STqSnapReader** ppReader) {
|
||||
int32_t code = 0;
|
||||
STqSnapReader* pReader = NULL;
|
||||
|
||||
|
@ -38,9 +39,21 @@ int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapReader** p
|
|||
pReader->pTq = pTq;
|
||||
pReader->sver = sver;
|
||||
pReader->ever = ever;
|
||||
pReader->type = type;
|
||||
|
||||
// impl
|
||||
code = tdbTbcOpen(pTq->pExecStore, &pReader->pCur, NULL);
|
||||
TTB *pTb = NULL;
|
||||
if (type == SNAP_DATA_TQ_CHECKINFO) {
|
||||
pTb = pTq->pCheckStore;
|
||||
} else if (type == SNAP_DATA_TQ_HANDLE) {
|
||||
pTb = pTq->pExecStore;
|
||||
} else if (type == SNAP_DATA_TQ_OFFSET) {
|
||||
pTb = pTq->pOffsetStore;
|
||||
} else {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
code = tdbTbcOpen(pTb, &pReader->pCur, NULL);
|
||||
if (code) {
|
||||
taosMemoryFree(pReader);
|
||||
goto _err;
|
||||
|
@ -91,7 +104,7 @@ int32_t tqSnapRead(STqSnapReader* pReader, uint8_t** ppData) {
|
|||
}
|
||||
|
||||
SSnapDataHdr* pHdr = (SSnapDataHdr*)(*ppData);
|
||||
pHdr->type = SNAP_DATA_TQ_HANDLE;
|
||||
pHdr->type = pReader->type;
|
||||
pHdr->size = vLen;
|
||||
memcpy(pHdr->data, pVal, vLen);
|
||||
|
||||
|
@ -169,7 +182,7 @@ _err:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tqSnapWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||
int32_t tqSnapHandleWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||
int32_t code = 0;
|
||||
STQ* pTq = pWriter->pTq;
|
||||
SDecoder decoder = {0};
|
||||
|
@ -180,7 +193,7 @@ int32_t tqSnapWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
|||
code = tDecodeSTqHandle(pDecoder, &handle);
|
||||
if (code) goto end;
|
||||
taosWLockLatch(&pTq->lock);
|
||||
code = tqMetaSaveHandle(pTq, handle.subKey, &handle);
|
||||
code = tqMetaSaveInfo(pTq, pTq->pExecStore, handle.subKey, (int)strlen(handle.subKey), pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
|
||||
end:
|
||||
|
@ -189,3 +202,42 @@ end:
|
|||
tqInfo("vgId:%d, vnode snapshot tq write result:%d", TD_VID(pTq->pVnode), code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqSnapCheckInfoWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||
int32_t code = 0;
|
||||
STQ* pTq = pWriter->pTq;
|
||||
STqCheckInfo info = {0};
|
||||
if(tqMetaDecodeCheckInfo(&info, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr)) != 0){
|
||||
goto _err;
|
||||
}
|
||||
|
||||
code = tqMetaSaveInfo(pTq, pTq->pCheckStore, &info.topic, strlen(info.topic), pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
||||
tDeleteSTqCheckInfo(&info);
|
||||
if (code) goto _err;
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tqError("vgId:%d, vnode check info tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqSnapOffsetWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||
int32_t code = 0;
|
||||
STQ* pTq = pWriter->pTq;
|
||||
|
||||
STqOffset info = {0};
|
||||
if(tqMetaDecodeOffsetInfo(&info, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr)) != 0){
|
||||
goto _err;
|
||||
}
|
||||
|
||||
code = tqMetaSaveInfo(pTq, pTq->pOffsetStore, info.subKey, strlen(info.subKey), pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
||||
tDeleteSTqOffset(&info);
|
||||
if (code) goto _err;
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tqError("vgId:%d, vnode check info tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
|
||||
return code;
|
||||
}
|
|
@ -226,15 +226,15 @@ bool taskReadyForDataFromWal(SStreamTask* pTask) {
|
|||
}
|
||||
|
||||
// not in ready state, do not handle the data from wal
|
||||
SStreamTaskState* pState = streamTaskGetStatus(pTask);
|
||||
if (pState->state != TASK_STATUS__READY) {
|
||||
tqTrace("s-task:%s not ready for submit block in wal, status:%s", pTask->id.idStr, pState->name);
|
||||
SStreamTaskState pState = streamTaskGetStatus(pTask);
|
||||
if (pState.state != TASK_STATUS__READY) {
|
||||
tqTrace("s-task:%s not ready for submit block in wal, status:%s", pTask->id.idStr, pState.name);
|
||||
return false;
|
||||
}
|
||||
|
||||
// fill-history task has entered into the last phase, no need to anything
|
||||
if ((pTask->info.fillHistory == 1) && pTask->status.appendTranstateBlock) {
|
||||
ASSERT(pState->state == TASK_STATUS__READY);
|
||||
ASSERT(pState.state == TASK_STATUS__READY);
|
||||
// the maximum version of data in the WAL has reached already, the step2 is done
|
||||
tqDebug("s-task:%s fill-history reach the maximum ver:%" PRId64 ", not scan wal anymore", pTask->id.idStr,
|
||||
pTask->dataRange.range.maxVer);
|
||||
|
@ -324,7 +324,8 @@ int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle) {
|
|||
|
||||
for (int32_t i = 0; i < numOfTasks; ++i) {
|
||||
STaskId* pTaskId = taosArrayGet(pTaskList, i);
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pStreamMeta, pTaskId->streamId, pTaskId->taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pStreamMeta, pTaskId->streamId, pTaskId->taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
@ -337,7 +338,7 @@ int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle) {
|
|||
*pScanIdle = false;
|
||||
|
||||
// seek the stored version and extract data from WAL
|
||||
int32_t code = setWalReaderStartOffset(pTask, vgId);
|
||||
code = setWalReaderStartOffset(pTask, vgId);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
streamMetaReleaseTask(pStreamMeta, pTask);
|
||||
continue;
|
||||
|
@ -348,9 +349,9 @@ int32_t doScanWalForAllTasks(SStreamMeta* pStreamMeta, bool* pScanIdle) {
|
|||
|
||||
taosThreadMutexLock(&pTask->lock);
|
||||
|
||||
SStreamTaskState* pState = streamTaskGetStatus(pTask);
|
||||
if (pState->state != TASK_STATUS__READY) {
|
||||
tqDebug("s-task:%s not ready for submit block from wal, status:%s", pTask->id.idStr, pState->name);
|
||||
SStreamTaskState pState = streamTaskGetStatus(pTask);
|
||||
if (pState.state != TASK_STATUS__READY) {
|
||||
tqDebug("s-task:%s not ready for submit block from wal, status:%s", pTask->id.idStr, pState.name);
|
||||
taosThreadMutexUnlock(&pTask->lock);
|
||||
streamMetaReleaseTask(pStreamMeta, pTask);
|
||||
continue;
|
||||
|
|
|
@ -81,7 +81,7 @@ static int32_t tqInitTaosxRsp(SMqDataRspCommon* pRsp, STqOffsetVal pOffset) {
|
|||
static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
SRpcMsg* pMsg, bool* pBlockReturned) {
|
||||
uint64_t consumerId = pRequest->consumerId;
|
||||
STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, pRequest->subKey);
|
||||
STqOffset* pOffset = (STqOffset*)tqMetaGetOffset(pTq, pRequest->subKey);
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
*pBlockReturned = false;
|
||||
|
@ -164,7 +164,8 @@ static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle,
|
|||
taosWUnLockLatch(&pTq->lock);
|
||||
}
|
||||
|
||||
tOffsetCopy(&dataRsp.common.reqOffset, pOffset); // reqOffset represents the current date offset, may be changed if wal not exists
|
||||
tOffsetCopy(&dataRsp.common.reqOffset,
|
||||
pOffset); // reqOffset represents the current date offset, may be changed if wal not exists
|
||||
code = tqSendDataRsp(pHandle, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
|
||||
|
||||
end : {
|
||||
|
@ -185,7 +186,8 @@ end : {
|
|||
int32_t len = pHead->bodyLen - sizeof(SMsgHead); \
|
||||
tDecoderInit(&decoder, data, len); \
|
||||
if (DECODE_FUNC(&decoder, &req) == 0 && (req.source & TD_REQ_FROM_TAOX) != 0) { \
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, jump meta for, vgId:%d offset %" PRId64 " msgType %d", \
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, jump meta for, vgId:%d offset %" PRId64 \
|
||||
" msgType %d", \
|
||||
pRequest->consumerId, pRequest->epoch, vgId, fetchVer, pHead->msgType); \
|
||||
fetchVer++; \
|
||||
DELETE_FUNC(&req); \
|
||||
|
@ -195,8 +197,7 @@ end : {
|
|||
DELETE_FUNC(&req); \
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
static void tDeleteCommon(void* parm) {
|
||||
}
|
||||
static void tDeleteCommon(void* parm) {}
|
||||
|
||||
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
SRpcMsg* pMsg, STqOffsetVal* offset) {
|
||||
|
@ -416,8 +417,8 @@ static void initMqRspHead(SMqRspHead* pMsgHead, int32_t type, int32_t epoch, int
|
|||
pMsgHead->walever = ever;
|
||||
}
|
||||
|
||||
int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqBatchMetaRsp* pRsp,
|
||||
int32_t vgId) {
|
||||
int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq,
|
||||
const SMqBatchMetaRsp* pRsp, int32_t vgId) {
|
||||
int32_t len = 0;
|
||||
int32_t code = 0;
|
||||
tEncodeSize(tEncodeMqBatchMetaRsp, pRsp, len, code);
|
||||
|
@ -444,8 +445,8 @@ int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SM
|
|||
SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
|
||||
|
||||
tmsgSendRsp(&resp);
|
||||
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type: batch meta, size:%ld offset type:%d", vgId,
|
||||
pReq->consumerId, pReq->epoch, taosArrayGetSize(pRsp->batchMetaReq), pRsp->rspOffset.type);
|
||||
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type: batch meta, size:%ld offset type:%d",
|
||||
vgId, pReq->consumerId, pReq->epoch, taosArrayGetSize(pRsp->batchMetaReq), pRsp->rspOffset.type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -527,6 +528,7 @@ int32_t tqDoSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const void* pRsp,
|
|||
}
|
||||
|
||||
int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void** pRefBlock, int32_t type) {
|
||||
int32_t code;
|
||||
SDecoder* pCoder = &(SDecoder){0};
|
||||
SDeleteRes* pRes = &(SDeleteRes){0};
|
||||
|
||||
|
@ -570,11 +572,11 @@ int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void*
|
|||
|
||||
taosArrayDestroy(pRes->uidList);
|
||||
if (type == 0) {
|
||||
*pRefBlock = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0);
|
||||
if (*pRefBlock == NULL) {
|
||||
code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
|
||||
if (code) {
|
||||
blockDataCleanup(pDelBlock);
|
||||
taosMemoryFree(pDelBlock);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
((SStreamRefDataBlock*)(*pRefBlock))->type = STREAM_INPUT__REF_DATA_BLOCK;
|
||||
|
|
|
@ -140,17 +140,19 @@ int32_t tqStreamTaskRestoreCheckpoint(SStreamMeta* pMeta, int64_t streamId, int3
|
|||
}
|
||||
|
||||
tqDebug("vgId:%d restore task:0x%" PRIx64 "-0x%x checkpointId", vgId, streamId, taskId);
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, streamId, taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, streamId, taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("failed to acquire task:0x%x when trying to restore checkpointId", taskId);
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
}
|
||||
|
||||
int32_t code = streamTaskSendRestoreChkptMsg(pTask);
|
||||
code = streamTaskSendRestoreChkptMsg(pTask);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
return code;
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
@ -230,7 +232,7 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
|
|||
updated = streamTaskUpdateEpsetInfo(pTask, req.pNodeList);
|
||||
|
||||
// send the checkpoint-source-rsp for source task to end the checkpoint trans in mnode
|
||||
streamTaskSendPreparedCheckpointsourceRsp(pTask);
|
||||
(void) streamTaskSendCheckpointsourceRsp(pTask);
|
||||
streamTaskResetStatus(pTask);
|
||||
|
||||
streamTaskStopMonitorCheckRsp(&pTask->taskCheckInfo, pTask->id.idStr);
|
||||
|
@ -329,7 +331,8 @@ int32_t tqStreamTaskProcessDispatchReq(SStreamMeta* pMeta, SRpcMsg* pMsg) {
|
|||
|
||||
tqDebug("s-task:0x%x recv dispatch msg from 0x%x(vgId:%d)", req.taskId, req.upstreamTaskId, req.upstreamNodeId);
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, req.streamId, req.taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, req.streamId, req.taskId, &pTask);
|
||||
if (pTask) {
|
||||
SRpcMsg rsp = {.info = pMsg->info, .code = 0};
|
||||
if (streamProcessDispatchMsg(pTask, &req, &rsp) != 0) {
|
||||
|
@ -388,7 +391,8 @@ int32_t tqStreamTaskProcessDispatchRsp(SStreamMeta* pMeta, SRpcMsg* pMsg) {
|
|||
tqDebug("s-task:0x%x vgId:%d recv dispatch-rsp from 0x%x vgId:%d", pRsp->upstreamTaskId, pRsp->upstreamNodeId,
|
||||
pRsp->downstreamTaskId, pRsp->downstreamNodeId);
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pRsp->streamId, pRsp->upstreamTaskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pRsp->streamId, pRsp->upstreamTaskId, &pTask);
|
||||
if (pTask) {
|
||||
streamProcessDispatchRsp(pTask, pRsp, pMsg->code);
|
||||
streamMetaReleaseTask(pMeta, pTask);
|
||||
|
@ -411,7 +415,8 @@ int32_t tqStreamTaskProcessRetrieveReq(SStreamMeta* pMeta, SRpcMsg* pMsg) {
|
|||
tDecodeStreamRetrieveReq(&decoder, &req);
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, req.streamId, req.dstTaskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, req.streamId, req.dstTaskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d process retrieve req, failed to acquire task:0x%x, it may have been dropped already", pMeta->vgId,
|
||||
req.dstTaskId);
|
||||
|
@ -419,7 +424,6 @@ int32_t tqStreamTaskProcessRetrieveReq(SStreamMeta* pMeta, SRpcMsg* pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) {
|
||||
code = streamProcessRetrieveReq(pTask, &req);
|
||||
} else {
|
||||
|
@ -484,7 +488,8 @@ int32_t tqStreamTaskProcessCheckRsp(SStreamMeta* pMeta, SRpcMsg* pMsg, bool isLe
|
|||
return streamMetaAddFailedTask(pMeta, rsp.streamId, rsp.upstreamTaskId);
|
||||
}
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, rsp.streamId, rsp.upstreamTaskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, rsp.streamId, rsp.upstreamTaskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
return streamMetaAddFailedTask(pMeta, rsp.streamId, rsp.upstreamTaskId);
|
||||
}
|
||||
|
@ -511,7 +516,8 @@ int32_t tqStreamTaskProcessCheckpointReadyMsg(SStreamMeta* pMeta, SRpcMsg* pMsg)
|
|||
}
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, req.streamId, req.upstreamTaskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, req.streamId, req.upstreamTaskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d failed to find s-task:0x%x, it may have been destroyed already", vgId, req.downstreamTaskId);
|
||||
return TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
|
@ -598,7 +604,8 @@ int32_t tqStreamTaskProcessDeployReq(SStreamMeta* pMeta, SMsgCb* cb, int64_t sve
|
|||
tqDebug("vgId:%d s-task:0x%x is deployed and add into meta, numOfTasks:%d", vgId, taskId, numOfTasks);
|
||||
|
||||
if (restored) {
|
||||
SStreamTask* p = streamMetaAcquireTask(pMeta, streamId, taskId);
|
||||
SStreamTask* p = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, streamId, taskId, &p);
|
||||
if ((p != NULL) && (p->info.fillHistory == 0)) {
|
||||
tqStreamStartOneTaskAsync(pMeta, cb, streamId, taskId);
|
||||
}
|
||||
|
@ -773,7 +780,8 @@ int32_t tqStreamTaskProcessRunReq(SStreamMeta* pMeta, SRpcMsg* pMsg, bool isLead
|
|||
int32_t code = streamMetaAddFailedTask(pMeta, pReq->streamId, pReq->taskId);
|
||||
return code;
|
||||
} else if (type == STREAM_EXEC_T_RESUME_TASK) { // task resume to run after idle for a while
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask);
|
||||
|
||||
if (pTask != NULL) {
|
||||
char* pStatus = NULL;
|
||||
|
@ -794,7 +802,8 @@ int32_t tqStreamTaskProcessRunReq(SStreamMeta* pMeta, SRpcMsg* pMsg, bool isLead
|
|||
return 0;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask);
|
||||
if (pTask != NULL) { // even in halt status, the data in inputQ must be processed
|
||||
char* p = NULL;
|
||||
if (streamTaskReadyToRun(pTask, &p)) {
|
||||
|
@ -862,7 +871,8 @@ int32_t tqStartTaskCompleteCallback(SStreamMeta* pMeta) {
|
|||
int32_t tqStreamTaskProcessTaskResetReq(SStreamMeta* pMeta, char* pMsg) {
|
||||
SVPauseStreamTaskReq* pReq = (SVPauseStreamTaskReq*)pMsg;
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d process task-reset req, failed to acquire task:0x%x, it may have been dropped already",
|
||||
pMeta->vgId, pReq->taskId);
|
||||
|
@ -875,8 +885,8 @@ int32_t tqStreamTaskProcessTaskResetReq(SStreamMeta* pMeta, char* pMsg) {
|
|||
streamTaskClearCheckInfo(pTask, true);
|
||||
|
||||
// clear flag set during do checkpoint, and open inputQ for all upstream tasks
|
||||
SStreamTaskState* pState = streamTaskGetStatus(pTask);
|
||||
if (pState->state == TASK_STATUS__CK) {
|
||||
SStreamTaskState pState = streamTaskGetStatus(pTask);
|
||||
if (pState.state == TASK_STATUS__CK) {
|
||||
int32_t tranId = 0;
|
||||
int64_t activeChkId = 0;
|
||||
streamTaskGetActiveCheckpointInfo(pTask, &tranId, &activeChkId);
|
||||
|
@ -885,13 +895,13 @@ int32_t tqStreamTaskProcessTaskResetReq(SStreamMeta* pMeta, char* pMsg) {
|
|||
pTask->id.idStr, activeChkId, tranId);
|
||||
|
||||
streamTaskSetStatusReady(pTask);
|
||||
} else if (pState->state == TASK_STATUS__UNINIT) {
|
||||
} else if (pState.state == TASK_STATUS__UNINIT) {
|
||||
// tqDebug("s-task:%s start task by checking downstream tasks", pTask->id.idStr);
|
||||
// ASSERT(pTask->status.downstreamReady == 0);
|
||||
// tqStreamTaskRestoreCheckpoint(pMeta, pTask->id.streamId, pTask->id.taskId);
|
||||
tqDebug("s-task:%s status:%s do nothing after receiving reset-task from mnode", pTask->id.idStr, pState->name);
|
||||
tqDebug("s-task:%s status:%s do nothing after receiving reset-task from mnode", pTask->id.idStr, pState.name);
|
||||
} else {
|
||||
tqDebug("s-task:%s status:%s do nothing after receiving reset-task from mnode", pTask->id.idStr, pState->name);
|
||||
tqDebug("s-task:%s status:%s do nothing after receiving reset-task from mnode", pTask->id.idStr, pState.name);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pTask->lock);
|
||||
|
@ -903,7 +913,8 @@ int32_t tqStreamTaskProcessTaskResetReq(SStreamMeta* pMeta, char* pMsg) {
|
|||
int32_t tqStreamTaskProcessRetrieveTriggerReq(SStreamMeta* pMeta, SRpcMsg* pMsg) {
|
||||
SRetrieveChkptTriggerReq* pReq = (SRetrieveChkptTriggerReq*)pMsg->pCont;
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->upstreamTaskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->upstreamTaskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d process retrieve checkpoint trigger, checkpointId:%" PRId64
|
||||
" from s-task:0x%x, failed to acquire task:0x%x, it may have been dropped already",
|
||||
|
@ -925,8 +936,8 @@ int32_t tqStreamTaskProcessRetrieveTriggerReq(SStreamMeta* pMeta, SRpcMsg* pMsg)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SStreamTaskState* pState = streamTaskGetStatus(pTask);
|
||||
if (pState->state == TASK_STATUS__CK) { // recv the checkpoint-source/trigger already
|
||||
SStreamTaskState pState = streamTaskGetStatus(pTask);
|
||||
if (pState.state == TASK_STATUS__CK) { // recv the checkpoint-source/trigger already
|
||||
int32_t transId = 0;
|
||||
int64_t checkpointId = 0;
|
||||
|
||||
|
@ -955,7 +966,7 @@ int32_t tqStreamTaskProcessRetrieveTriggerReq(SStreamMeta* pMeta, SRpcMsg* pMsg)
|
|||
TSDB_CODE_ACTION_IN_PROGRESS);
|
||||
}
|
||||
} else { // upstream not recv the checkpoint-source/trigger till now
|
||||
ASSERT(pState->state == TASK_STATUS__READY || pState->state == TASK_STATUS__HALT);
|
||||
ASSERT(pState.state == TASK_STATUS__READY || pState.state == TASK_STATUS__HALT);
|
||||
tqWarn(
|
||||
"s-task:%s not recv checkpoint-source from mnode or checkpoint-trigger from upstream yet, wait for all "
|
||||
"upstream sending checkpoint-source/trigger",
|
||||
|
@ -971,7 +982,8 @@ int32_t tqStreamTaskProcessRetrieveTriggerReq(SStreamMeta* pMeta, SRpcMsg* pMsg)
|
|||
int32_t tqStreamTaskProcessRetrieveTriggerRsp(SStreamMeta* pMeta, SRpcMsg* pMsg) {
|
||||
SCheckpointTriggerRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pRsp->streamId, pRsp->taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pRsp->streamId, pRsp->taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError(
|
||||
"vgId:%d process retrieve checkpoint-trigger, failed to acquire task:0x%x, it may have been dropped already",
|
||||
|
@ -990,7 +1002,8 @@ int32_t tqStreamTaskProcessRetrieveTriggerRsp(SStreamMeta* pMeta, SRpcMsg* pMsg)
|
|||
int32_t tqStreamTaskProcessTaskPauseReq(SStreamMeta* pMeta, char* pMsg) {
|
||||
SVPauseStreamTaskReq* pReq = (SVPauseStreamTaskReq*)pMsg;
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d process pause req, failed to acquire task:0x%x, it may have been dropped already", pMeta->vgId,
|
||||
pReq->taskId);
|
||||
|
@ -1003,7 +1016,8 @@ int32_t tqStreamTaskProcessTaskPauseReq(SStreamMeta* pMeta, char* pMsg) {
|
|||
|
||||
SStreamTask* pHistoryTask = NULL;
|
||||
if (HAS_RELATED_FILLHISTORY_TASK(pTask)) {
|
||||
pHistoryTask = streamMetaAcquireTask(pMeta, pTask->hTaskInfo.id.streamId, pTask->hTaskInfo.id.taskId);
|
||||
pHistoryTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, pTask->hTaskInfo.id.streamId, pTask->hTaskInfo.id.taskId, &pHistoryTask);
|
||||
if (pHistoryTask == NULL) {
|
||||
tqError("vgId:%d process pause req, failed to acquire fill-history task:0x%" PRIx64
|
||||
", it may have been dropped already",
|
||||
|
@ -1033,7 +1047,7 @@ static int32_t tqProcessTaskResumeImpl(void* handle, SStreamTask* pTask, int64_t
|
|||
}
|
||||
|
||||
streamTaskResume(pTask);
|
||||
ETaskStatus status = streamTaskGetStatus(pTask)->state;
|
||||
ETaskStatus status = streamTaskGetStatus(pTask).state;
|
||||
|
||||
int32_t level = pTask->info.taskLevel;
|
||||
if (status == TASK_STATUS__READY || status == TASK_STATUS__SCAN_HISTORY || status == TASK_STATUS__CK) {
|
||||
|
@ -1070,28 +1084,30 @@ int32_t tqStreamTaskProcessTaskResumeReq(void* handle, int64_t sversion, char* m
|
|||
|
||||
SStreamMeta* pMeta = fromVnode ? ((STQ*)handle)->pStreamMeta : handle;
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("s-task:0x%x failed to acquire task to resume, it may have been dropped or stopped", pReq->taskId);
|
||||
return TSDB_CODE_STREAM_TASK_IVLD_STATUS;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pTask->lock);
|
||||
SStreamTaskState* pState = streamTaskGetStatus(pTask);
|
||||
tqDebug("s-task:%s start to resume from paused, current status:%s", pTask->id.idStr, pState->name);
|
||||
SStreamTaskState pState = streamTaskGetStatus(pTask);
|
||||
tqDebug("s-task:%s start to resume from paused, current status:%s", pTask->id.idStr, pState.name);
|
||||
taosThreadMutexUnlock(&pTask->lock);
|
||||
|
||||
int32_t code = tqProcessTaskResumeImpl(handle, pTask, sversion, pReq->igUntreated, fromVnode);
|
||||
code = tqProcessTaskResumeImpl(handle, pTask, sversion, pReq->igUntreated, fromVnode);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
STaskId* pHTaskId = &pTask->hTaskInfo.id;
|
||||
SStreamTask* pHTask = streamMetaAcquireTask(pMeta, pHTaskId->streamId, pHTaskId->taskId);
|
||||
SStreamTask* pHTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, pHTaskId->streamId, pHTaskId->taskId, &pHTask);
|
||||
if (pHTask) {
|
||||
taosThreadMutexLock(&pHTask->lock);
|
||||
SStreamTaskState* p = streamTaskGetStatus(pHTask);
|
||||
tqDebug("s-task:%s related history task start to resume from paused, current status:%s", pHTask->id.idStr, p->name);
|
||||
SStreamTaskState p = streamTaskGetStatus(pHTask);
|
||||
tqDebug("s-task:%s related history task start to resume from paused, current status:%s", pHTask->id.idStr, p.name);
|
||||
taosThreadMutexUnlock(&pHTask->lock);
|
||||
|
||||
code = tqProcessTaskResumeImpl(handle, pHTask, sversion, pReq->igUntreated, fromVnode);
|
||||
|
@ -1121,7 +1137,8 @@ int32_t tqStreamProcessConsensusChkptRsp2(SStreamMeta* pMeta, SRpcMsg* pMsg) { r
|
|||
int32_t tqStreamProcessCheckpointReadyRsp(SStreamMeta* pMeta, SRpcMsg* pMsg) {
|
||||
SMStreamCheckpointReadyRspMsg* pRsp = pMsg->pCont;
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, pRsp->streamId, pRsp->downstreamTaskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
int32_t code = streamMetaAcquireTask(pMeta, pRsp->streamId, pRsp->downstreamTaskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d failed to acquire task:0x%x when handling checkpoint-ready msg, it may have been dropped",
|
||||
pRsp->downstreamNodeId, pRsp->downstreamTaskId);
|
||||
|
@ -1154,7 +1171,8 @@ int32_t tqStreamTaskProcessConsenChkptIdReq(SStreamMeta* pMeta, SRpcMsg* pMsg) {
|
|||
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pMeta, req.streamId, req.taskId);
|
||||
SStreamTask* pTask = NULL;
|
||||
code = streamMetaAcquireTask(pMeta, req.streamId, req.taskId, &pTask);
|
||||
if (pTask == NULL) {
|
||||
tqError("vgId:%d process set consensus checkpointId req, failed to acquire task:0x%x, it may have been dropped already",
|
||||
pMeta->vgId, req.taskId);
|
||||
|
|
|
@ -1307,186 +1307,6 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
|
||||
static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCacheRowsReader *pr, int16_t *aCols,
|
||||
int nCols, int16_t *slotIds);
|
||||
#ifdef BUILD_NO_CALL
|
||||
static SLastCol *tsdbCacheLookup(STsdb *pTsdb, tb_uid_t uid, int16_t cid, int8_t ltype) {
|
||||
SLastCol *pLastCol = NULL;
|
||||
|
||||
char *err = NULL;
|
||||
size_t vlen = 0;
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
char *value = NULL;
|
||||
value = rocksdb_get(pTsdb->rCache.db, pTsdb->rCache.readoptions, (char *)key, klen, &vlen, &err);
|
||||
if (NULL != err) {
|
||||
tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, err);
|
||||
rocksdb_free(err);
|
||||
}
|
||||
|
||||
pLastCol = tsdbCacheDeserialize(value);
|
||||
|
||||
return pLastCol;
|
||||
}
|
||||
|
||||
int32_t tsdbCacheGetSlow(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCacheRowsReader *pr, int8_t ltype) {
|
||||
rocksdb_writebatch_t *wb = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
SArray *pCidList = pr->pCidList;
|
||||
int num_keys = TARRAY_SIZE(pCidList);
|
||||
|
||||
char **keys_list = taosMemoryMalloc(num_keys * sizeof(char *));
|
||||
size_t *keys_list_sizes = taosMemoryMalloc(num_keys * sizeof(size_t));
|
||||
char *key_list = taosMemoryMalloc(num_keys * ROCKS_KEY_LEN);
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
int16_t cid = *(int16_t *)taosArrayGet(pCidList, i);
|
||||
|
||||
memcpy(key_list + i * ROCKS_KEY_LEN, &(SLastKey){.ltype = ltype, .uid = uid, .cid = cid}, ROCKS_KEY_LEN);
|
||||
keys_list[i] = key_list + i * ROCKS_KEY_LEN;
|
||||
keys_list_sizes[i] = ROCKS_KEY_LEN;
|
||||
}
|
||||
|
||||
char **values_list = taosMemoryCalloc(num_keys, sizeof(char *));
|
||||
size_t *values_list_sizes = taosMemoryCalloc(num_keys, sizeof(size_t));
|
||||
char **errs = taosMemoryMalloc(num_keys * sizeof(char *));
|
||||
rocksdb_multi_get(pTsdb->rCache.db, pTsdb->rCache.readoptions, num_keys, (const char *const *)keys_list,
|
||||
keys_list_sizes, values_list, values_list_sizes, errs);
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
if (errs[i]) {
|
||||
rocksdb_free(errs[i]);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(key_list);
|
||||
taosMemoryFree(keys_list);
|
||||
taosMemoryFree(keys_list_sizes);
|
||||
taosMemoryFree(errs);
|
||||
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
bool freeCol = true;
|
||||
SArray *pTmpColArray = NULL;
|
||||
SLastCol *pLastCol = tsdbCacheDeserialize(values_list[i]);
|
||||
int16_t cid = *(int16_t *)taosArrayGet(pCidList, i);
|
||||
SLastCol noneCol = {.ts = TSKEY_MIN, .colVal = COL_VAL_NONE(cid, pr->pSchema->columns[pr->pSlotIds[i]].type)};
|
||||
if (pLastCol) {
|
||||
reallocVarData(&pLastCol->colVal);
|
||||
} else {
|
||||
taosThreadMutexLock(&pTsdb->rCache.rMutex);
|
||||
|
||||
pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
// recalc: load from tsdb
|
||||
int16_t aCols[1] = {cid};
|
||||
int16_t slotIds[1] = {pr->pSlotIds[i]};
|
||||
pTmpColArray = NULL;
|
||||
|
||||
if (ltype) {
|
||||
mergeLastCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
} else {
|
||||
mergeLastRowCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
}
|
||||
|
||||
if (pTmpColArray && TARRAY_SIZE(pTmpColArray) >= 1) {
|
||||
pLastCol = taosArrayGet(pTmpColArray, 0);
|
||||
freeCol = false;
|
||||
}
|
||||
|
||||
// still null, then make up a none col value
|
||||
if (!pLastCol) {
|
||||
pLastCol = &noneCol;
|
||||
freeCol = false;
|
||||
}
|
||||
|
||||
// store result back to rocks cache
|
||||
wb = pTsdb->rCache.rwritebatch;
|
||||
char *value = NULL;
|
||||
size_t vlen = 0;
|
||||
tsdbCacheSerialize(pLastCol, &value, &vlen);
|
||||
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = pLastCol->colVal.cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
|
||||
|
||||
taosMemoryFree(value);
|
||||
} else {
|
||||
reallocVarData(&pLastCol->colVal);
|
||||
}
|
||||
|
||||
if (wb) {
|
||||
rocksMayWrite(pTsdb, false, true, false);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pTsdb->rCache.rMutex);
|
||||
}
|
||||
|
||||
taosArrayPush(pLastArray, pLastCol);
|
||||
taosArrayDestroy(pTmpColArray);
|
||||
if (freeCol) {
|
||||
taosMemoryFree(pLastCol);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(values_list);
|
||||
taosMemoryFree(values_list_sizes);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static SLastCol *tsdbCacheLoadCol(STsdb *pTsdb, SCacheRowsReader *pr, int16_t slotid, tb_uid_t uid, int16_t cid,
|
||||
int8_t ltype) {
|
||||
SLastCol *pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
rocksdb_writebatch_t *wb = NULL;
|
||||
|
||||
taosThreadMutexLock(&pTsdb->rCache.rMutex);
|
||||
pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
// recalc: load from tsdb
|
||||
int16_t aCols[1] = {cid};
|
||||
int16_t slotIds[1] = {slotid};
|
||||
SArray *pTmpColArray = NULL;
|
||||
|
||||
if (ltype) {
|
||||
mergeLastCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
} else {
|
||||
mergeLastRowCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
}
|
||||
|
||||
if (pTmpColArray && TARRAY_SIZE(pTmpColArray) >= 1) {
|
||||
pLastCol = taosArrayGet(pTmpColArray, 0);
|
||||
}
|
||||
|
||||
// still null, then make up a none col value
|
||||
SLastCol noneCol = {.ts = TSKEY_MIN, .colVal = COL_VAL_NONE(cid, pr->pSchema->columns[slotid].type)};
|
||||
if (!pLastCol) {
|
||||
pLastCol = &noneCol;
|
||||
}
|
||||
|
||||
// store result back to rocks cache
|
||||
wb = pTsdb->rCache.rwritebatch;
|
||||
char *value = NULL;
|
||||
size_t vlen = 0;
|
||||
tsdbCacheSerialize(pLastCol, &value, &vlen);
|
||||
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = pLastCol->colVal.cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
|
||||
taosMemoryFree(value);
|
||||
|
||||
SLastCol *pTmpLastCol = taosMemoryCalloc(1, sizeof(SLastCol));
|
||||
*pTmpLastCol = *pLastCol;
|
||||
pLastCol = pTmpLastCol;
|
||||
|
||||
taosArrayDestroy(pTmpColArray);
|
||||
}
|
||||
|
||||
if (wb) {
|
||||
rocksMayWrite(pTsdb, false, true, false);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pTsdb->rCache.rMutex);
|
||||
}
|
||||
|
||||
return pLastCol;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SArray *remainCols,
|
||||
SCacheRowsReader *pr, int8_t ltype) {
|
||||
|
@ -3453,8 +3273,9 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
taosArrayPush(aColArray, &aCols[i]);
|
||||
}
|
||||
|
||||
TSKEY lastRowTs = TSKEY_MAX;
|
||||
STsdbRowKey lastRowKey = {.key.ts = TSKEY_MAX};
|
||||
|
||||
// inverse iterator
|
||||
CacheNextRowIter iter = {0};
|
||||
nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr);
|
||||
|
||||
|
@ -3478,10 +3299,11 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
}
|
||||
// int16_t nCol = pTSchema->numOfCols;
|
||||
|
||||
TSKEY rowTs = TSDBROW_TS(pRow);
|
||||
STsdbRowKey rowKey = {0};
|
||||
tsdbRowGetKey(pRow, &rowKey);
|
||||
|
||||
if (lastRowTs == TSKEY_MAX) {
|
||||
lastRowTs = rowTs;
|
||||
if (lastRowKey.key.ts == TSKEY_MAX) { // first time
|
||||
lastRowKey = rowKey;
|
||||
|
||||
for (int16_t iCol = noneCol; iCol < nCols; ++iCol) {
|
||||
if (iCol >= nLastCol) {
|
||||
|
@ -3501,13 +3323,13 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
if (slotIds[iCol] == 0) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowTs}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowKey.key.ts}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey = rowKey.key, .colVal = *pColVal});
|
||||
continue;
|
||||
}
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
|
||||
*pCol = (SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
*pCol = (SLastCol){.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /*&& pColVal->value.nData > 0*/) {
|
||||
if (pColVal->value.nData > 0) {
|
||||
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||
|
@ -3554,10 +3376,11 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
continue;
|
||||
}
|
||||
SColVal *tColVal = &lastColVal->colVal;
|
||||
if (COL_VAL_IS_VALUE(tColVal)) continue;
|
||||
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
if (!COL_VAL_IS_VALUE(tColVal) && COL_VAL_IS_VALUE(pColVal)) {
|
||||
SLastCol lastCol = {.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
if (COL_VAL_IS_VALUE(pColVal)) {
|
||||
SLastCol lastCol = {.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /* && pColVal->value.nData > 0 */) {
|
||||
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pColArray, iCol);
|
||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||
|
@ -3580,7 +3403,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
if (aColIndex >= 0) {
|
||||
taosArrayRemove(aColArray, aColIndex);
|
||||
}
|
||||
} else if (!COL_VAL_IS_VALUE(tColVal) && !COL_VAL_IS_VALUE(pColVal) && !setNoneCol) {
|
||||
} else if (!COL_VAL_IS_VALUE(pColVal) && !setNoneCol) {
|
||||
noneCol = iCol;
|
||||
setNoneCol = true;
|
||||
}
|
||||
|
@ -3637,8 +3460,7 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
taosArrayPush(aColArray, &aCols[i]);
|
||||
}
|
||||
|
||||
TSKEY lastRowTs = TSKEY_MAX;
|
||||
|
||||
// inverse iterator
|
||||
CacheNextRowIter iter = {0};
|
||||
nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr);
|
||||
|
||||
|
@ -3662,9 +3484,8 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
}
|
||||
// int16_t nCol = pTSchema->numOfCols;
|
||||
|
||||
TSKEY rowTs = TSDBROW_TS(pRow);
|
||||
|
||||
lastRowTs = rowTs;
|
||||
STsdbRowKey rowKey = {0};
|
||||
tsdbRowGetKey(pRow, &rowKey);
|
||||
|
||||
for (int16_t iCol = noneCol; iCol < nCols; ++iCol) {
|
||||
if (iCol >= nLastCol) {
|
||||
|
@ -3680,13 +3501,13 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
if (slotIds[iCol] == 0) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowTs}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowKey.key.ts}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey = rowKey.key, .colVal = *pColVal});
|
||||
continue;
|
||||
}
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
|
||||
*pCol = (SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
*pCol = (SLastCol){.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /*&& pColVal->value.nData > 0*/) {
|
||||
if (pColVal->value.nData > 0) {
|
||||
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||
|
|
|
@ -41,26 +41,23 @@ int32_t tsdbBegin(STsdb *pTsdb) {
|
|||
if (!pTsdb) return code;
|
||||
|
||||
SMemTable *pMemTable;
|
||||
code = tsdbMemTableCreate(pTsdb, &pMemTable);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbMemTableCreate(pTsdb, &pMemTable), &lino, _exit);
|
||||
|
||||
// lock
|
||||
if ((code = taosThreadMutexLock(&pTsdb->mutex))) {
|
||||
code = TAOS_SYSTEM_ERROR(code);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(code), &lino, _exit);
|
||||
}
|
||||
|
||||
pTsdb->mem = pMemTable;
|
||||
|
||||
// unlock
|
||||
if ((code = taosThreadMutexUnlock(&pTsdb->mutex))) {
|
||||
code = TAOS_SYSTEM_ERROR(code);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(code), &lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
tsdbError("vgId:%d, %s failed at %s:%d since %s", TD_VID(pTsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -92,12 +92,12 @@ static int32_t tsdbCommitOpenWriter(SCommitter2 *committer) {
|
|||
}
|
||||
}
|
||||
|
||||
code = tsdbFSetWriterOpen(&config, &committer->writer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbFSetWriterOpen(&config, &committer->writer), &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -122,32 +122,28 @@ static int32_t tsdbCommitTSData(SCommitter2 *committer) {
|
|||
committer->ctx->tbid->uid = row->uid;
|
||||
|
||||
if (metaGetInfo(committer->tsdb->pVnode->pMeta, row->uid, &info, NULL) != 0) {
|
||||
code = tsdbIterMergerSkipTableData(committer->dataIterMerger, committer->ctx->tbid);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterMergerSkipTableData(committer->dataIterMerger, committer->ctx->tbid), &lino, _exit);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t ts = TSDBROW_TS(&row->row);
|
||||
if (ts > committer->ctx->maxKey) {
|
||||
code = tsdbIterMergerSkipTableData(committer->dataIterMerger, committer->ctx->tbid);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterMergerSkipTableData(committer->dataIterMerger, committer->ctx->tbid), &lino, _exit);
|
||||
continue;
|
||||
}
|
||||
|
||||
committer->ctx->hasTSData = true;
|
||||
numOfRow++;
|
||||
|
||||
code = tsdbFSetWriteRow(committer->writer, row);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbIterMergerNext(committer->dataIterMerger);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbFSetWriteRow(committer->writer, row), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterMergerNext(committer->dataIterMerger), &lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
} else {
|
||||
tsdbDebug("vgId:%d fid:%d commit %" PRId64 " rows", TD_VID(committer->tsdb->pVnode), committer->ctx->info->fid,
|
||||
numOfRow);
|
||||
|
@ -176,8 +172,7 @@ static int32_t tsdbCommitTombData(SCommitter2 *committer) {
|
|||
committer->ctx->tbid->uid = record->uid;
|
||||
|
||||
if (metaGetInfo(committer->tsdb->pVnode->pMeta, record->uid, &info, NULL) != 0) {
|
||||
code = tsdbIterMergerSkipTableData(committer->tombIterMerger, committer->ctx->tbid);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterMergerSkipTableData(committer->tombIterMerger, committer->ctx->tbid), &lino, _exit);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -192,18 +187,17 @@ static int32_t tsdbCommitTombData(SCommitter2 *committer) {
|
|||
|
||||
if (!skip) {
|
||||
numRecord++;
|
||||
code = tsdbFSetWriteTombRecord(committer->writer, record);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbFSetWriteTombRecord(committer->writer, record), &lino, _exit);
|
||||
}
|
||||
}
|
||||
|
||||
code = tsdbIterMergerNext(committer->tombIterMerger);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterMergerNext(committer->tombIterMerger), &lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
} else {
|
||||
tsdbDebug("vgId:%d fid:%d commit %" PRId64 " tomb records", TD_VID(committer->tsdb->pVnode),
|
||||
committer->ctx->info->fid, numRecord);
|
||||
|
@ -241,11 +235,9 @@ static int32_t tsdbCommitOpenReader(SCommitter2 *committer) {
|
|||
.file = fobj->f[0],
|
||||
};
|
||||
|
||||
code = tsdbSttFileReaderOpen(fobj->fname, &config, &sttReader);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbSttFileReaderOpen(fobj->fname, &config, &sttReader), &lino, _exit);
|
||||
|
||||
code = TARRAY2_APPEND(committer->sttReaderArray, sttReader);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TARRAY2_APPEND(committer->sttReaderArray, sttReader), &lino, _exit);
|
||||
|
||||
STFileOp op = {
|
||||
.optype = TSDB_FOP_REMOVE,
|
||||
|
@ -253,15 +245,15 @@ static int32_t tsdbCommitOpenReader(SCommitter2 *committer) {
|
|||
.of = fobj->f[0],
|
||||
};
|
||||
|
||||
code = TARRAY2_APPEND(committer->fopArray, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TARRAY2_APPEND(committer->fopArray, op), &lino, _exit);
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbCommitCloseReader(committer);
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -295,21 +287,15 @@ static int32_t tsdbCommitOpenIter(SCommitter2 *committer) {
|
|||
.numOfPKs = 0,
|
||||
};
|
||||
|
||||
code = tsdbIterOpen(&config, &iter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = TARRAY2_APPEND(committer->dataIterArray, iter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterOpen(&config, &iter), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(TARRAY2_APPEND(committer->dataIterArray, iter), &lino, _exit);
|
||||
|
||||
// mem tomb iter
|
||||
config.type = TSDB_ITER_TYPE_MEMT_TOMB;
|
||||
config.memt = committer->tsdb->imem;
|
||||
|
||||
code = tsdbIterOpen(&config, &iter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = TARRAY2_APPEND(committer->tombIterArray, iter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterOpen(&config, &iter), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(TARRAY2_APPEND(committer->tombIterArray, iter), &lino, _exit);
|
||||
|
||||
// STT
|
||||
SSttFileReader *sttReader;
|
||||
|
@ -318,34 +304,27 @@ static int32_t tsdbCommitOpenIter(SCommitter2 *committer) {
|
|||
config.type = TSDB_ITER_TYPE_STT;
|
||||
config.sttReader = sttReader;
|
||||
|
||||
code = tsdbIterOpen(&config, &iter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = TARRAY2_APPEND(committer->dataIterArray, iter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterOpen(&config, &iter), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(TARRAY2_APPEND(committer->dataIterArray, iter), &lino, _exit);
|
||||
|
||||
// tomb iter
|
||||
config.type = TSDB_ITER_TYPE_STT_TOMB;
|
||||
config.sttReader = sttReader;
|
||||
|
||||
code = tsdbIterOpen(&config, &iter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterOpen(&config, &iter), &lino, _exit);
|
||||
|
||||
code = TARRAY2_APPEND(committer->tombIterArray, iter);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TARRAY2_APPEND(committer->tombIterArray, iter), &lino, _exit);
|
||||
}
|
||||
|
||||
// open merger
|
||||
code = tsdbIterMergerOpen(committer->dataIterArray, &committer->dataIterMerger, false);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbIterMergerOpen(committer->tombIterArray, &committer->tombIterMerger, true);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterMergerOpen(committer->dataIterArray, &committer->dataIterMerger, false), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbIterMergerOpen(committer->tombIterArray, &committer->tombIterMerger, true), &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbCommitCloseIter(committer);
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -361,8 +340,10 @@ static int32_t tsdbCommitFileSetBegin(SCommitter2 *committer) {
|
|||
committer->ctx->expLevel = tsdbFidLevel(committer->ctx->info->fid, &tsdb->keepCfg, committer->now);
|
||||
tsdbFidKeyRange(committer->ctx->info->fid, committer->minutes, committer->precision, &committer->ctx->minKey,
|
||||
&committer->ctx->maxKey);
|
||||
code = tfsAllocDisk(committer->tsdb->pVnode->pTfs, committer->ctx->expLevel, &committer->ctx->did);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
TAOS_CHECK_GOTO(tfsAllocDisk(committer->tsdb->pVnode->pTfs, committer->ctx->expLevel, &committer->ctx->did), &lino,
|
||||
_exit);
|
||||
|
||||
tfsMkdirRecurAt(committer->tsdb->pVnode->pTfs, committer->tsdb->path, committer->ctx->did);
|
||||
committer->ctx->tbid->suid = 0;
|
||||
committer->ctx->tbid->uid = 0;
|
||||
|
@ -371,18 +352,13 @@ static int32_t tsdbCommitFileSetBegin(SCommitter2 *committer) {
|
|||
ASSERT(committer->dataIterMerger == NULL);
|
||||
ASSERT(committer->writer == NULL);
|
||||
|
||||
code = tsdbCommitOpenReader(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbCommitOpenIter(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbCommitOpenWriter(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitOpenReader(committer), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitOpenIter(committer), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitOpenWriter(committer), &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done, fid:%d minKey:%" PRId64 " maxKey:%" PRId64 " expLevel:%d", TD_VID(tsdb->pVnode),
|
||||
__func__, committer->ctx->info->fid, committer->ctx->minKey, committer->ctx->maxKey,
|
||||
|
@ -395,18 +371,14 @@ static int32_t tsdbCommitFileSetEnd(SCommitter2 *committer) {
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
code = tsdbCommitCloseWriter(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbCommitCloseIter(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbCommitCloseReader(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitCloseWriter(committer), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitCloseIter(committer), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitCloseReader(committer), &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done, fid:%d", TD_VID(committer->tsdb->pVnode), __func__, committer->ctx->info->fid);
|
||||
}
|
||||
|
@ -417,24 +389,15 @@ static int32_t tsdbCommitFileSet(SCommitter2 *committer) {
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
// fset commit start
|
||||
code = tsdbCommitFileSetBegin(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// commit fset
|
||||
code = tsdbCommitTSData(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbCommitTombData(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// fset commit end
|
||||
code = tsdbCommitFileSetEnd(committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitFileSetBegin(committer), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitTSData(committer), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitTombData(committer), &lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitFileSetEnd(committer), &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(committer->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done, fid:%d", TD_VID(committer->tsdb->pVnode), __func__, committer->ctx->info->fid);
|
||||
}
|
||||
|
@ -464,9 +427,6 @@ static uint32_t tFileSetCommitInfoHash(const void *arg) {
|
|||
}
|
||||
|
||||
static int32_t tsdbCommitInfoDestroy(STsdb *pTsdb) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
if (pTsdb->commitInfo) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) {
|
||||
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i);
|
||||
|
@ -480,12 +440,7 @@ static int32_t tsdbCommitInfoDestroy(STsdb *pTsdb) {
|
|||
pTsdb->commitInfo->arr = NULL;
|
||||
taosMemoryFreeClear(pTsdb->commitInfo);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbCommitInfoInit(STsdb *pTsdb) {
|
||||
|
@ -494,11 +449,10 @@ static int32_t tsdbCommitInfoInit(STsdb *pTsdb) {
|
|||
|
||||
pTsdb->commitInfo = taosMemoryCalloc(1, sizeof(*pTsdb->commitInfo));
|
||||
if (pTsdb->commitInfo == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
|
||||
code = vHashInit(&pTsdb->commitInfo->ht, tFileSetCommitInfoHash, tFileSetCommitInfoCompare);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(vHashInit(&pTsdb->commitInfo->ht, tFileSetCommitInfoHash, tFileSetCommitInfoCompare), &lino, _exit);
|
||||
|
||||
pTsdb->commitInfo->arr = taosArrayInit(0, sizeof(SFileSetCommitInfo *));
|
||||
if (pTsdb->commitInfo->arr == NULL) {
|
||||
|
@ -508,7 +462,7 @@ static int32_t tsdbCommitInfoInit(STsdb *pTsdb) {
|
|||
_exit:
|
||||
if (code) {
|
||||
tsdbCommitInfoDestroy(pTsdb);
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(pTsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -520,22 +474,21 @@ static int32_t tsdbCommitInfoAdd(STsdb *tsdb, int32_t fid) {
|
|||
SFileSetCommitInfo *tinfo;
|
||||
|
||||
if ((tinfo = taosMemoryMalloc(sizeof(*tinfo))) == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
tinfo->fid = fid;
|
||||
tinfo->fset = NULL;
|
||||
|
||||
code = vHashPut(tsdb->commitInfo->ht, tinfo);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(vHashPut(tsdb->commitInfo->ht, tinfo), &lino, _exit);
|
||||
|
||||
if ((taosArrayPush(tsdb->commitInfo->arr, &tinfo)) == NULL) {
|
||||
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
taosArraySort(tsdb->commitInfo->arr, tFileSetCommitInfoPCompare);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(tsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -547,8 +500,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) {
|
|||
STFileSet *fset = NULL;
|
||||
SRBTreeIter iter;
|
||||
|
||||
code = tsdbCommitInfoInit(tsdb);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitInfoInit(tsdb), &lino, _exit);
|
||||
|
||||
// scan time-series data
|
||||
iter = tRBTreeIterCreate(tsdb->imem->tbDataTree, 1);
|
||||
|
@ -581,8 +533,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) {
|
|||
};
|
||||
vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info);
|
||||
if (info == NULL) {
|
||||
code = tsdbCommitInfoAdd(tsdb, fid);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitInfoAdd(tsdb, fid), &lino, _exit);
|
||||
}
|
||||
|
||||
from.key.ts = maxKey + 1;
|
||||
|
@ -640,7 +591,11 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) {
|
|||
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i);
|
||||
tsdbBeginTaskOnFileSet(tsdb, info->fid, &fset);
|
||||
if (fset) {
|
||||
tsdbTFileSetInitCopy(tsdb, fset, &info->fset);
|
||||
code = tsdbTFileSetInitCopy(tsdb, fset, &info->fset);
|
||||
if (code) {
|
||||
taosThreadMutexUnlock(&tsdb->mutex);
|
||||
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -649,7 +604,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) {
|
|||
_exit:
|
||||
if (code) {
|
||||
tsdbCommitInfoDestroy(tsdb);
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(tsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -670,12 +625,11 @@ static int32_t tsdbOpenCommitter(STsdb *tsdb, SCommitInfo *info, SCommitter2 *co
|
|||
committer->cid = tsdbFSAllocEid(tsdb->pFS);
|
||||
committer->now = taosGetTimestampSec();
|
||||
|
||||
code = tsdbCommitInfoBuild(tsdb);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitInfoBuild(tsdb), &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done", TD_VID(tsdb->pVnode), __func__);
|
||||
}
|
||||
|
@ -687,8 +641,7 @@ static int32_t tsdbCloseCommitter(SCommitter2 *committer, int32_t eno) {
|
|||
int32_t lino = 0;
|
||||
|
||||
if (eno == 0) {
|
||||
code = tsdbFSEditBegin(committer->tsdb->pFS, committer->fopArray, TSDB_FEDIT_COMMIT);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbFSEditBegin(committer->tsdb->pFS, committer->fopArray, TSDB_FEDIT_COMMIT), &lino, _exit);
|
||||
} else {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
|
@ -705,8 +658,8 @@ static int32_t tsdbCloseCommitter(SCommitter2 *committer, int32_t eno) {
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s, eid:%" PRId64, TD_VID(committer->tsdb->pVnode), __func__, lino,
|
||||
tstrerror(code), committer->cid);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s, eid:%" PRId64, TD_VID(committer->tsdb->pVnode), __func__, __FILE__,
|
||||
lino, tstrerror(code), committer->cid);
|
||||
} else {
|
||||
tsdbDebug("vgId:%d %s done, eid:%" PRId64, TD_VID(committer->tsdb->pVnode), __func__, committer->cid);
|
||||
}
|
||||
|
@ -740,22 +693,19 @@ int32_t tsdbCommitBegin(STsdb *tsdb, SCommitInfo *info) {
|
|||
} else {
|
||||
SCommitter2 committer = {0};
|
||||
|
||||
code = tsdbOpenCommitter(tsdb, info, &committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbOpenCommitter(tsdb, info, &committer), &lino, _exit);
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) {
|
||||
committer.ctx->info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i);
|
||||
code = tsdbCommitFileSet(&committer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCommitFileSet(&committer), &lino, _exit);
|
||||
}
|
||||
|
||||
code = tsdbCloseCommitter(&committer, code);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbCloseCommitter(&committer, code), &lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
||||
} else {
|
||||
tsdbInfo("vgId:%d %s done, nRow:%" PRId64 " nDel:%" PRId64, TD_VID(tsdb->pVnode), __func__, nRow, nDel);
|
||||
}
|
||||
|
@ -792,7 +742,7 @@ int32_t tsdbCommitCommit(STsdb *tsdb) {
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(tsdb->pVnode), __func__, lino, tstrerror(code));
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
|
||||
} else {
|
||||
tsdbInfo("vgId:%d %s done", TD_VID(tsdb->pVnode), __func__);
|
||||
}
|
||||
|
@ -805,8 +755,7 @@ int32_t tsdbCommitAbort(STsdb *pTsdb) {
|
|||
|
||||
if (pTsdb->imem == NULL) goto _exit;
|
||||
|
||||
code = tsdbFSEditAbort(pTsdb->pFS);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbFSEditAbort(pTsdb->pFS), &lino, _exit);
|
||||
|
||||
taosThreadMutexLock(&pTsdb->mutex);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) {
|
||||
|
|
|
@ -23,8 +23,7 @@ int32_t tsdbDataFileRAWReaderOpen(const char *fname, const SDataFileRAWReaderCon
|
|||
|
||||
reader[0] = taosMemoryCalloc(1, sizeof(SDataFileRAWReader));
|
||||
if (reader[0] == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
|
||||
reader[0]->config[0] = config[0];
|
||||
|
@ -32,25 +31,26 @@ int32_t tsdbDataFileRAWReaderOpen(const char *fname, const SDataFileRAWReaderCon
|
|||
int32_t lcn = config->file.lcn;
|
||||
if (fname) {
|
||||
if (fname) {
|
||||
code = tsdbOpenFile(fname, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbOpenFile(fname, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn), &lino, _exit);
|
||||
}
|
||||
} else {
|
||||
char fname1[TSDB_FILENAME_LEN];
|
||||
tsdbTFileName(config->tsdb, &config->file, fname1);
|
||||
code = tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn), &lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(config->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(config->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbDataFileRAWReaderClose(SDataFileRAWReader **reader) {
|
||||
if (reader[0] == NULL) return 0;
|
||||
if (reader[0] == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (reader[0]->fd) {
|
||||
tsdbCloseFile(&reader[0]->fd);
|
||||
|
@ -75,12 +75,14 @@ int32_t tsdbDataFileRAWReadBlockData(SDataFileRAWReader *reader, STsdbDataRAWBlo
|
|||
|
||||
int32_t encryptAlgorithm = reader->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||
char *encryptKey = reader->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||
code = tsdbReadFile(reader->fd, pBlock->offset, pBlock->data, pBlock->dataLength, 0, encryptAlgorithm, encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(
|
||||
tsdbReadFile(reader->fd, pBlock->offset, pBlock->data, pBlock->dataLength, 0, encryptAlgorithm, encryptKey),
|
||||
&lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(reader->config->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(reader->config->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -91,18 +93,20 @@ int32_t tsdbDataFileRAWWriterOpen(const SDataFileRAWWriterConfig *config, SDataF
|
|||
int32_t lino = 0;
|
||||
|
||||
SDataFileRAWWriter *writer = taosMemoryCalloc(1, sizeof(SDataFileRAWWriter));
|
||||
if (!writer) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (!writer) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
||||
}
|
||||
|
||||
writer->config[0] = config[0];
|
||||
|
||||
code = tsdbDataFileRAWWriterDoOpen(writer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbDataFileRAWWriterDoOpen(writer), &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(config->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
taosMemoryFree(writer);
|
||||
writer = NULL;
|
||||
TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
|
||||
}
|
||||
ppWriter[0] = writer;
|
||||
return code;
|
||||
|
@ -126,21 +130,20 @@ static int32_t tsdbDataFileRAWWriterCloseCommit(SDataFileRAWWriter *writer, TFil
|
|||
.fid = writer->config->fid,
|
||||
.nf = writer->file,
|
||||
};
|
||||
code = TARRAY2_APPEND(opArr, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit);
|
||||
|
||||
int32_t encryptAlgorithm = writer->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
|
||||
char *encryptKey = writer->config->tsdb->pVnode->config.tsdbCfg.encryptKey;
|
||||
|
||||
if (writer->fd) {
|
||||
code = tsdbFsyncFile(writer->fd, encryptAlgorithm, encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbFsyncFile(writer->fd, encryptAlgorithm, encryptKey), &lino, _exit);
|
||||
tsdbCloseFile(&writer->fd);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -157,12 +160,12 @@ static int32_t tsdbDataFileRAWWriterOpenDataFD(SDataFileRAWWriter *writer) {
|
|||
}
|
||||
|
||||
tsdbTFileName(writer->config->tsdb, &writer->file, fname);
|
||||
code = tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, writer->file.lcn);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, writer->file.lcn), &lino, _exit);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -174,30 +177,30 @@ int32_t tsdbDataFileRAWWriterDoOpen(SDataFileRAWWriter *writer) {
|
|||
writer->file = writer->config->file;
|
||||
writer->ctx->offset = 0;
|
||||
|
||||
code = tsdbDataFileRAWWriterOpenDataFD(writer);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbDataFileRAWWriterOpenDataFD(writer), &lino, _exit);
|
||||
|
||||
writer->ctx->opened = true;
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbDataFileRAWWriterClose(SDataFileRAWWriter **writer, bool abort, TFileOpArray *opArr) {
|
||||
if (writer[0] == NULL) return 0;
|
||||
if (writer[0] == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
if (writer[0]->ctx->opened) {
|
||||
if (abort) {
|
||||
code = tsdbDataFileRAWWriterCloseAbort(writer[0]);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbDataFileRAWWriterCloseAbort(writer[0]), &lino, _exit);
|
||||
} else {
|
||||
code = tsdbDataFileRAWWriterCloseCommit(writer[0], opArr);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbDataFileRAWWriterCloseCommit(writer[0], opArr), &lino, _exit);
|
||||
}
|
||||
tsdbDataFileRAWWriterDoClose(writer[0]);
|
||||
}
|
||||
|
@ -206,7 +209,8 @@ int32_t tsdbDataFileRAWWriterClose(SDataFileRAWWriter **writer, bool abort, TFil
|
|||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(writer[0]->config->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer[0]->config->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -216,15 +220,16 @@ int32_t tsdbDataFileRAWWriteBlockData(SDataFileRAWWriter *writer, const STsdbDat
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
code = tsdbWriteFile(writer->fd, writer->ctx->offset, (const uint8_t *)pDataBlock->data, pDataBlock->dataLength,
|
||||
encryptAlgorithm, encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
TAOS_CHECK_GOTO(tsdbWriteFile(writer->fd, writer->ctx->offset, (const uint8_t *)pDataBlock->data,
|
||||
pDataBlock->dataLength, encryptAlgorithm, encryptKey),
|
||||
&lino, _exit);
|
||||
|
||||
writer->ctx->offset += pDataBlock->dataLength;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TSDB_ERROR_LOG(TD_VID(writer->config->tsdb->pVnode), lino, code);
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(writer->config->tsdb->pVnode), __func__, __FILE__, lino,
|
||||
tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -101,8 +101,8 @@ int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, uint32_t cmpr
|
|||
int32_t encryptAlgorithm, char *encryptKey);
|
||||
int32_t tsdbFileWriteBrinBlk(STsdbFD *fd, TBrinBlkArray *brinBlkArray, SFDataPtr *ptr, int64_t *fileSize,
|
||||
int32_t encryptAlgorithm, char *encryptKey);
|
||||
int32_t tsdbFileWriteHeadFooter(STsdbFD *fd, int64_t *fileSize, const SHeadFooter *footer,
|
||||
int32_t encryptAlgorithm, char* encryptKey);
|
||||
int32_t tsdbFileWriteHeadFooter(STsdbFD *fd, int64_t *fileSize, const SHeadFooter *footer, int32_t encryptAlgorithm,
|
||||
char *encryptKey);
|
||||
|
||||
// tomb
|
||||
int32_t tsdbDataFileWriteTombRecord(SDataFileWriter *writer, const STombRecord *record);
|
||||
|
@ -111,8 +111,8 @@ int32_t tsdbFileWriteTombBlock(STsdbFD *fd, STombBlock *tombBlock, int8_t cmprAl
|
|||
int32_t encryptAlgorithm, char *encryptKey);
|
||||
int32_t tsdbFileWriteTombBlk(STsdbFD *fd, const TTombBlkArray *tombBlkArray, SFDataPtr *ptr, int64_t *fileSize,
|
||||
int32_t encryptAlgorithm, char *encryptKey);
|
||||
int32_t tsdbFileWriteTombFooter(STsdbFD *fd, const STombFooter *footer, int64_t *fileSize,
|
||||
int32_t encryptAlgorithm, char* encryptKey);
|
||||
int32_t tsdbFileWriteTombFooter(STsdbFD *fd, const STombFooter *footer, int64_t *fileSize, int32_t encryptAlgorithm,
|
||||
char *encryptKey);
|
||||
|
||||
// utils
|
||||
int32_t tsdbWriterUpdVerRange(SVersionRange *range, int64_t minVer, int64_t maxVer);
|
||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define TSDB_ERROR_LOG(vid, lino, code) \
|
||||
tsdbError("vgId:%d %s failed at line %d since %s", vid, __func__, lino, tstrerror(code))
|
||||
tsdbError("vgId:%d %s failed at %s:%d since %s", vid, __func__, __FILE__, lino, tstrerror(code))
|
||||
|
||||
typedef struct SFDataPtr {
|
||||
int64_t offset;
|
||||
|
@ -34,8 +34,8 @@ typedef struct SFDataPtr {
|
|||
extern int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppFD, int32_t lcn);
|
||||
extern void tsdbCloseFile(STsdbFD **ppFD);
|
||||
|
||||
extern int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t size,
|
||||
int32_t encryptAlgorithm, char* encryptKey);
|
||||
extern int32_t tsdbWriteFile(STsdbFD *pFD, int64_t offset, const uint8_t *pBuf, int64_t size, int32_t encryptAlgorithm,
|
||||
char *encryptKey);
|
||||
extern int32_t tsdbReadFile(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64_t size, int64_t szHint,
|
||||
int32_t encryptAlgorithm, char *encryptKey);
|
||||
extern int32_t tsdbReadFileToBuffer(STsdbFD *pFD, int64_t offset, int64_t size, SBuffer *buffer, int64_t szHint,
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
#include "vnd.h"
|
||||
|
||||
int32_t tsdbSttLvlInit(int32_t level, SSttLvl **lvl) {
|
||||
if (!(lvl[0] = taosMemoryMalloc(sizeof(SSttLvl)))) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (!(lvl[0] = taosMemoryMalloc(sizeof(SSttLvl)))) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
lvl[0]->level = level;
|
||||
TARRAY2_INIT(lvl[0]->fobjArr);
|
||||
return 0;
|
||||
|
@ -81,14 +83,14 @@ static int32_t tsdbSttLvlFilteredInitEx(STsdb *pTsdb, const SSttLvl *lvl1, int64
|
|||
return code;
|
||||
}
|
||||
|
||||
TARRAY2_APPEND(lvl[0]->fobjArr, fobj);
|
||||
TAOS_CHECK_RETURN(TARRAY2_APPEND(lvl[0]->fobjArr, fobj));
|
||||
} else {
|
||||
STFileOp op = {
|
||||
.optype = TSDB_FOP_REMOVE,
|
||||
.fid = fobj1->f->fid,
|
||||
.of = fobj1->f[0],
|
||||
};
|
||||
TARRAY2_APPEND(fopArr, op);
|
||||
TAOS_CHECK_RETURN(TARRAY2_APPEND(fopArr, op));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -150,74 +150,6 @@ void tsdbSmaFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSmaFile *pSmaF, ch
|
|||
|
||||
bool tsdbDelFileIsSame(SDelFile *pDelFile1, SDelFile *pDelFile2) { return pDelFile1->commitID == pDelFile2->commitID; }
|
||||
|
||||
int32_t tsdbDFileRollback(STsdb *pTsdb, SDFileSet *pSet, EDataFileT ftype) {
|
||||
int32_t code = 0;
|
||||
int64_t size = 0;
|
||||
int64_t n;
|
||||
TdFilePtr pFD;
|
||||
char fname[TSDB_FILENAME_LEN] = {0};
|
||||
char hdr[TSDB_FHDR_SIZE] = {0};
|
||||
|
||||
// truncate
|
||||
switch (ftype) {
|
||||
case TSDB_DATA_FILE:
|
||||
size = pSet->pDataF->size;
|
||||
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
|
||||
tPutDataFile(hdr, pSet->pDataF);
|
||||
break;
|
||||
case TSDB_SMA_FILE:
|
||||
size = pSet->pSmaF->size;
|
||||
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
|
||||
tPutSmaFile(hdr, pSet->pSmaF);
|
||||
break;
|
||||
default:
|
||||
goto _err; // make the coverity scan happy
|
||||
}
|
||||
|
||||
taosCalcChecksumAppend(0, hdr, TSDB_FHDR_SIZE);
|
||||
|
||||
// open
|
||||
pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_WRITE_THROUGH);
|
||||
if (pFD == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// ftruncate
|
||||
if (taosFtruncateFile(pFD, tsdbLogicToFileSize(size, pTsdb->pVnode->config.tsdbPageSize)) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// update header
|
||||
n = taosLSeekFile(pFD, 0, SEEK_SET);
|
||||
if (n < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
n = taosWriteFile(pFD, hdr, TSDB_FHDR_SIZE);
|
||||
if (n < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// sync
|
||||
if (taosFsyncFile(pFD) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// close
|
||||
taosCloseFile(&pFD);
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tsdbError("vgId:%d, tsdb rollback file failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tPutDFileSet(uint8_t *p, SDFileSet *pSet) {
|
||||
int32_t n = 0;
|
||||
|
||||
|
@ -249,7 +181,7 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
|
|||
// head
|
||||
pSet->pHeadF = (SHeadFile *)taosMemoryCalloc(1, sizeof(SHeadFile));
|
||||
if (pSet->pHeadF == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pSet->pHeadF->nRef = 1;
|
||||
n += tGetHeadFile(p + n, pSet->pHeadF);
|
||||
|
@ -257,7 +189,7 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
|
|||
// data
|
||||
pSet->pDataF = (SDataFile *)taosMemoryCalloc(1, sizeof(SDataFile));
|
||||
if (pSet->pDataF == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pSet->pDataF->nRef = 1;
|
||||
n += tGetDataFile(p + n, pSet->pDataF);
|
||||
|
@ -265,7 +197,7 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
|
|||
// sma
|
||||
pSet->pSmaF = (SSmaFile *)taosMemoryCalloc(1, sizeof(SSmaFile));
|
||||
if (pSet->pSmaF == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pSet->pSmaF->nRef = 1;
|
||||
n += tGetSmaFile(p + n, pSet->pSmaF);
|
||||
|
@ -275,7 +207,7 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
|
|||
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||
pSet->aSttF[iStt] = (SSttFile *)taosMemoryCalloc(1, sizeof(SSttFile));
|
||||
if (pSet->aSttF[iStt] == NULL) {
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pSet->aSttF[iStt]->nRef = 1;
|
||||
n += tGetSttFile(p + n, pSet->aSttF[iStt]);
|
||||
|
|
|
@ -165,8 +165,7 @@ static int32_t data_to_json(const STFile *file, cJSON *json) { return tfile_to_j
|
|||
static int32_t sma_to_json(const STFile *file, cJSON *json) { return tfile_to_json(file, json); }
|
||||
static int32_t tomb_to_json(const STFile *file, cJSON *json) { return tfile_to_json(file, json); }
|
||||
static int32_t stt_to_json(const STFile *file, cJSON *json) {
|
||||
int32_t code = tfile_to_json(file, json);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tfile_to_json(file, json));
|
||||
|
||||
/* lvl */
|
||||
if (cJSON_AddNumberToObject(json, "level", file->stt->level) == NULL) {
|
||||
|
@ -181,8 +180,7 @@ static int32_t data_from_json(const cJSON *json, STFile *file) { return tfile_fr
|
|||
static int32_t sma_from_json(const cJSON *json, STFile *file) { return tfile_from_json(json, file); }
|
||||
static int32_t tomb_from_json(const cJSON *json, STFile *file) { return tfile_from_json(json, file); }
|
||||
static int32_t stt_from_json(const cJSON *json, STFile *file) {
|
||||
int32_t code = tfile_from_json(json, file);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tfile_from_json(json, file));
|
||||
|
||||
const cJSON *item;
|
||||
|
||||
|
@ -202,7 +200,9 @@ int32_t tsdbTFileToJson(const STFile *file, cJSON *json) {
|
|||
return g_tfile_info[file->type].to_json(file, json);
|
||||
} else {
|
||||
cJSON *item = cJSON_AddObjectToObject(json, g_tfile_info[file->type].suffix);
|
||||
if (item == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (item == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return g_tfile_info[file->type].to_json(file, item);
|
||||
}
|
||||
}
|
||||
|
@ -211,13 +211,11 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) {
|
|||
f[0] = (STFile){.type = ftype};
|
||||
|
||||
if (ftype == TSDB_FTYPE_STT) {
|
||||
int32_t code = g_tfile_info[ftype].from_json(json, f);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(g_tfile_info[ftype].from_json(json, f));
|
||||
} else {
|
||||
const cJSON *item = cJSON_GetObjectItem(json, g_tfile_info[ftype].suffix);
|
||||
if (cJSON_IsObject(item)) {
|
||||
int32_t code = g_tfile_info[ftype].from_json(item, f);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(g_tfile_info[ftype].from_json(item, f));
|
||||
} else {
|
||||
return TSDB_CODE_NOT_FOUND;
|
||||
}
|
||||
|
@ -228,7 +226,9 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) {
|
|||
|
||||
int32_t tsdbTFileObjInit(STsdb *pTsdb, const STFile *f, STFileObj **fobj) {
|
||||
fobj[0] = taosMemoryMalloc(sizeof(*fobj[0]));
|
||||
if (!fobj[0]) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (!fobj[0]) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
taosThreadMutexInit(&fobj[0]->mutex, NULL);
|
||||
fobj[0]->f[0] = f[0];
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue