chore: merge 3.0
This commit is contained in:
commit
ea7c1338ff
|
@ -1,6 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE OFF)
|
||||
set(TD_BUILD_TAOSA_INTERNAL FALSE)
|
||||
|
||||
#set output directory
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
||||
|
|
|
@ -21,7 +21,7 @@ IF (TD_LINUX)
|
|||
ELSEIF (TD_WINDOWS)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.bat")
|
||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||
INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} :needAdmin ${TD_SOURCE_DIR} ${PROJECT_BINARY_DIR} Windows ${TD_VER_NUMBER})")
|
||||
INSTALL(CODE "execute_process(COMMAND ${TD_MAKE_INSTALL_SH} :needAdmin ${TD_SOURCE_DIR} ${PROJECT_BINARY_DIR} Windows ${TD_VER_NUMBER} ${TD_BUILD_TAOSA_INTERNAL})")
|
||||
ELSEIF (TD_DARWIN)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.sh")
|
||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# taosadapter
|
||||
ExternalProject_Add(taosadapter
|
||||
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
||||
GIT_TAG f0c1753
|
||||
GIT_TAG a2e9920
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -30,6 +30,8 @@ database_option: {
|
|||
| WAL_LEVEL {1 | 2}
|
||||
| VGROUPS value
|
||||
| SINGLE_STABLE {0 | 1}
|
||||
| TABLE_PREFIX value
|
||||
| TABLE_SUFFIX value
|
||||
| WAL_RETENTION_PERIOD value
|
||||
| WAL_ROLL_PERIOD value
|
||||
| WAL_RETENTION_SIZE value
|
||||
|
@ -67,6 +69,8 @@ database_option: {
|
|||
- SINGLE_STABLE: specifies whether the database can contain more than one supertable.
|
||||
- 0: The database can contain multiple supertables.
|
||||
- 1: The database can contain only one supertable.
|
||||
- TABLE_PREFIX:The prefix length in the table name that is ignored when distributing table to vnode based on table name.
|
||||
- TABLE_SUFFIX:The suffix length in the table name that is ignored when distributing table to vnode based on table name.
|
||||
- WAL_RETENTION_PERIOD: specifies the time after which WAL files are deleted. This parameter is used for data subscription. Enter a time in seconds. The default value of single copy is 0. A value of 0 indicates that each WAL file is deleted immediately after its contents are written to disk. -1: WAL files are never deleted. The default value of multiple copy is 4 days.
|
||||
- WAL_RETENTION_SIZE: specifies the size at which WAL files are deleted. This parameter is used for data subscription. Enter a size in KB. The default value of single copy is 0. A value of 0 indicates that each WAL file is deleted immediately after its contents are written to disk. -1: WAL files are never deleted. The default value of multiple copy is -1.
|
||||
- WAL_ROLL_PERIOD: specifies the time after which WAL files are rotated. After this period elapses, a new WAL file is created. The default value of single copy is 0. A value of 0 indicates that a new WAL file is created only after the previous WAL file was written to disk. The default values of multiple copy is 1 day.
|
||||
|
|
|
@ -17,6 +17,7 @@ The following list shows all reserved keywords:
|
|||
- ADD
|
||||
- AFTER
|
||||
- AGGREGATE
|
||||
- ALIVE
|
||||
- ALL
|
||||
- ALTER
|
||||
- ANALYZE
|
||||
|
|
|
@ -178,76 +178,138 @@ SHOW TABLE DISTRIBUTED table_name;
|
|||
|
||||
Shows how table data is distributed.
|
||||
|
||||
Examples: show table distributed d0\G; Display the block distribution of table `d0` in detailed format.
|
||||
Examples: Below is an example of this command to display the block distribution of table `d0` in detailed format.
|
||||
|
||||
```sql
|
||||
show table distributed d0\G;
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary> Show Example </summary>
|
||||
<pre><code>
|
||||
*************************** 1.row ***************************
|
||||
_block_dist: Total_Blocks=[5] Total_Size=[93.65 Kb] Average_size=[18.73 Kb] Compression_Ratio=[23.98 %]
|
||||
|
||||
Total_Blocks : Table `d0` contains total 5 blocks
|
||||
|
||||
Total_Size: The total size of all the data blocks in table `d0` is 93.65 KB
|
||||
|
||||
Average_size: The average size of each block is 18.73 KB
|
||||
|
||||
Compression_Ratio: The data compression rate is 23.98%
|
||||
|
||||
*************************** 2.row ***************************
|
||||
_block_dist: Total_Rows=[20000] Inmem_Rows=[0] MinRows=[3616] MaxRows=[4096] Average_Rows=[4000]
|
||||
|
||||
Total_Rows: Table `d0` contains 20,000 rows
|
||||
|
||||
Inmem_Rows: The rows still in memory, i.e. not committed in disk, is 0, i.e. none such rows
|
||||
|
||||
MinRows: The minimum number of rows in a block is 3,616
|
||||
|
||||
MaxRows: The maximum number of rows in a block is 4,096B
|
||||
|
||||
Average_Rows: The average number of rows in a block is 4,000
|
||||
|
||||
*************************** 3.row ***************************
|
||||
_block_dist: Total_Tables=[1] Total_Files=[2]
|
||||
|
||||
Total_Tables: The number of child tables, 1 in this example
|
||||
|
||||
Total_Files: The number of files storing the table's data, 2 in this example
|
||||
|
||||
*************************** 4.row ***************************
|
||||
|
||||
_block_dist: --------------------------------------------------------------------------------
|
||||
|
||||
*************************** 5.row ***************************
|
||||
|
||||
_block_dist: 0100 |
|
||||
|
||||
*************************** 6.row ***************************
|
||||
|
||||
_block_dist: 0299 |
|
||||
|
||||
*************************** 7.row ***************************
|
||||
|
||||
_block_dist: 0498 |
|
||||
|
||||
*************************** 8.row ***************************
|
||||
|
||||
_block_dist: 0697 |
|
||||
|
||||
*************************** 9.row ***************************
|
||||
|
||||
_block_dist: 0896 |
|
||||
|
||||
*************************** 10.row ***************************
|
||||
|
||||
_block_dist: 1095 |
|
||||
|
||||
*************************** 11.row ***************************
|
||||
|
||||
_block_dist: 1294 |
|
||||
|
||||
*************************** 12.row ***************************
|
||||
|
||||
_block_dist: 1493 |
|
||||
|
||||
*************************** 13.row ***************************
|
||||
|
||||
_block_dist: 1692 |
|
||||
|
||||
*************************** 14.row ***************************
|
||||
|
||||
_block_dist: 1891 |
|
||||
|
||||
*************************** 15.row ***************************
|
||||
|
||||
_block_dist: 2090 |
|
||||
|
||||
*************************** 16.row ***************************
|
||||
|
||||
_block_dist: 2289 |
|
||||
|
||||
*************************** 17.row ***************************
|
||||
|
||||
_block_dist: 2488 |
|
||||
|
||||
*************************** 18.row ***************************
|
||||
|
||||
_block_dist: 2687 |
|
||||
|
||||
*************************** 19.row ***************************
|
||||
|
||||
_block_dist: 2886 |
|
||||
|
||||
*************************** 20.row ***************************
|
||||
|
||||
_block_dist: 3085 |
|
||||
|
||||
*************************** 21.row ***************************
|
||||
|
||||
_block_dist: 3284 |
|
||||
|
||||
*************************** 22.row ***************************
|
||||
|
||||
_block_dist: 3483 ||||||||||||||||| 1 (20.00%)
|
||||
|
||||
*************************** 23.row ***************************
|
||||
|
||||
_block_dist: 3682 |
|
||||
|
||||
*************************** 24.row ***************************
|
||||
|
||||
_block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4 (80.00%)
|
||||
|
||||
Query OK, 24 row(s) in set (0.002444s)
|
||||
|
||||
The above show the block distribution percentage according to the number of rows in each block. In the above example, `_block_dist: 3483 ||||||||||||||||| 1 (20.00%)` means there is one block whose rows is between 3,483 and 3,681. `_block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4 (80.00%)` means there are 4 blocks whose rows is between 3,881 and 4,096. The number of blocks whose rows fall in other range is zero.
|
||||
</code></pre>
|
||||
</details>
|
||||
|
||||
The above show the block distribution percentage according to the number of rows in each block. In the above example, we can get below information:
|
||||
- `_block_dist: 3483 ||||||||||||||||| 1 (20.00%)` means there is one block whose rows is between 3,483 and 3,681.
|
||||
- `_block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4 (80.00%)` means there are 4 blocks whose rows is between 3,881 and 4,096. - The number of blocks whose rows fall in other range is zero.
|
||||
|
||||
## SHOW TAGS
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ taosAdapter provides the following features.
|
|||
- Seamless connection to collectd
|
||||
- Seamless connection to StatsD
|
||||
- Supports Prometheus remote_read and remote_write
|
||||
- Get table's VGroup ID
|
||||
|
||||
## taosAdapter architecture diagram
|
||||
|
||||
|
@ -178,6 +179,7 @@ See [example/config/taosadapter.toml](https://github.com/taosdata/taosadapter/bl
|
|||
node_export is an exporter for machine metrics. Please visit [https://github.com/prometheus/node_exporter](https://github.com/prometheus/node_exporter) for more information.
|
||||
- Support for Prometheus remote_read and remote_write
|
||||
remote_read and remote_write are interfaces for Prometheus data read and write from/to other data storage solution. Please visit [https://prometheus.io/blog/2019/10/10/remote-read-meets-streaming/#remote-apis](https://prometheus.io/blog/2019/10/10/remote-read-meets-streaming/#remote-apis) for more information.
|
||||
- Get table's VGroup ID. For more information about VGroup, please refer to [primary-logic-unit](/tdinternal/arch/#primary-logic-unit).
|
||||
|
||||
## Interfaces
|
||||
|
||||
|
@ -199,7 +201,7 @@ Support InfluxDB query parameters as follows.
|
|||
- `precision` The time precision used by TDengine
|
||||
- `u` TDengine user name
|
||||
- `p` TDengine password
|
||||
- `ttl` The time to live of automatically created sub-table. This value cannot be updated. TDengine will use the ttl value of the frist data of sub-table to create sub-table. For more information, please refer [Create Table](/taos-sql/table/#create-table)
|
||||
- `ttl` The time to live of automatically created sub-table. This value cannot be updated. TDengine will use the ttl value of the first data of sub-table to create sub-table. For more information, please refer [Create Table](/taos-sql/table/#create-table)
|
||||
|
||||
Note: InfluxDB token authorization is not supported at present. Only Basic authorization and query parameter validation are supported.
|
||||
Example: curl --request POST http://127.0.0.1:6041/influxdb/v1/write?db=test --user "root:taosdata" --data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
|
||||
|
@ -241,6 +243,10 @@ node_export is an exporter of hardware and OS metrics exposed by the \*NIX kerne
|
|||
|
||||
<Prometheus />
|
||||
|
||||
### Get table's VGroup ID
|
||||
|
||||
You can call `http://<fqdn>:6041/rest/vgid?db=<db>&table=<table>` to get table's VGroup ID. For more information about VGroup, please refer to [primary-logic-unit](/tdinternal/arch/#primary-logic-unit).
|
||||
|
||||
## Memory usage optimization methods
|
||||
|
||||
taosAdapter will monitor its memory usage during operation and adjust it with two thresholds. Valid values are integers between 1 to 100, and represent a percentage of the system's physical memory.
|
||||
|
|
|
@ -10,6 +10,10 @@ For TDengine 2.x installation packages by version, please visit [here](https://w
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 3.0.2.2
|
||||
|
||||
<Release type="tdengine" version="3.0.2.2" />
|
||||
|
||||
## 3.0.2.1
|
||||
|
||||
<Release type="tdengine" version="3.0.2.1" />
|
||||
|
|
|
@ -10,6 +10,10 @@ For other historical version installers, please visit [here](https://www.taosdat
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 2.4.0
|
||||
|
||||
<Release type="tools" version="2.4.0" />
|
||||
|
||||
## 2.3.3
|
||||
|
||||
<Release type="tools" version="2.3.3" />
|
||||
|
|
|
@ -30,6 +30,8 @@ database_option: {
|
|||
| WAL_LEVEL {1 | 2}
|
||||
| VGROUPS value
|
||||
| SINGLE_STABLE {0 | 1}
|
||||
| TABLE_PREFIX value
|
||||
| TABLE_SUFFIX value
|
||||
| WAL_RETENTION_PERIOD value
|
||||
| WAL_ROLL_PERIOD value
|
||||
| WAL_RETENTION_SIZE value
|
||||
|
@ -67,6 +69,8 @@ database_option: {
|
|||
- SINGLE_STABLE:表示此数据库中是否只可以创建一个超级表,用于超级表列非常多的情况。
|
||||
- 0:表示可以创建多张超级表。
|
||||
- 1:表示只可以创建一张超级表。
|
||||
- TABLE_PREFIX:内部存储引擎根据表名分配存储该表数据的 VNODE 时要忽略的前缀的长度。
|
||||
- TABLE_SUFFIX:内部存储引擎根据表名分配存储该表数据的 VNODE 时要忽略的后缀的长度。
|
||||
- WAL_RETENTION_PERIOD:wal 文件的额外保留策略,用于数据订阅。wal 的保存时长,单位为 s。单副本默认为 0,即落盘后立即删除。-1 表示不删除。多副本默认为 4 天。
|
||||
- WAL_RETENTION_SIZE:wal 文件的额外保留策略,用于数据订阅。wal 的保存的最大上限,单位为 KB。单副本默认为 0,即落盘后立即删除。多副本默认为-1,表示不删除。
|
||||
- WAL_ROLL_PERIOD:wal 文件切换时长,单位为 s。当 wal 文件创建并写入后,经过该时间,会自动创建一个新的 wal 文件。单副本默认为 0,即仅在落盘时创建新文件。多副本默认为 1 天。
|
||||
|
|
|
@ -18,6 +18,7 @@ description: TDengine 保留关键字的详细列表
|
|||
- ADD
|
||||
- AFTER
|
||||
- AGGREGATE
|
||||
- ALIVE
|
||||
- ALL
|
||||
- ALTER
|
||||
- ANALYZE
|
||||
|
|
|
@ -183,6 +183,10 @@ SHOW TABLE DISTRIBUTED table_name;
|
|||
|
||||
语句: show table distributed d0\G; 竖行显示表 d0 的 BLOCK 分布情况
|
||||
|
||||
<details>
|
||||
<summary>显示示例</summary>
|
||||
<pre><code>
|
||||
|
||||
*************************** 1.row ***************************
|
||||
|
||||
_block_dist: Total_Blocks=[5] Total_Size=[93.65 Kb] Average_size=[18.73 Kb] Compression_Ratio=[23.98 %]
|
||||
|
@ -244,6 +248,8 @@ _block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||
|
||||
Query OK, 24 row(s) in set (0.002444s)
|
||||
|
||||
</code></pre>
|
||||
</details>
|
||||
|
||||
上面是块中包含数据行数的块儿分布情况图,这里的 0100 0299 0498 … 表示的是每个块中包含的数据行数,上面的意思就是这个表的 5 个块,分布在 3483 ~3681 行的块有 1 个,占整个块的 20%,分布在 3881 ~ 4096(最大行数)的块数为 4 个,占整个块的 80%, 其它区域内分布块数为 0。
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ description: "TDengine 3.0 版本的语法变更说明"
|
|||
| 9 | SAMPLE | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
|
||||
| 10 | STATECOUNT | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
|
||||
| 11 | STATEDURATION | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
|
||||
| 12 | TIMETRUNCATE | 增强 | 增加ignore_timezone参数,可选是否使用,默认值为1.
|
||||
|
||||
|
||||
## SCHEMALESS 变更
|
||||
|
|
|
@ -21,6 +21,7 @@ taosAdapter 提供以下功能:
|
|||
- 无缝连接到 collectd
|
||||
- 无缝连接到 StatsD
|
||||
- 支持 Prometheus remote_read 和 remote_write
|
||||
- 获取 table 所在的虚拟节点组(VGroup)的 VGroup ID
|
||||
|
||||
## taosAdapter 架构图
|
||||
|
||||
|
@ -178,6 +179,7 @@ AllowWebSockets
|
|||
node_export 是一个机器指标的导出器。请访问 [https://github.com/prometheus/node_exporter](https://github.com/prometheus/node_exporter) 了解更多信息。
|
||||
- 支持 Prometheus remote_read 和 remote_write
|
||||
remote_read 和 remote_write 是 Prometheus 数据读写分离的集群方案。请访问[https://prometheus.io/blog/2019/10/10/remote-read-meets-streaming/#remote-apis](https://prometheus.io/blog/2019/10/10/remote-read-meets-streaming/#remote-apis) 了解更多信息。
|
||||
- 获取 table 所在的虚拟节点组(VGroup)的 VGroup ID。关于虚拟节点组(VGroup)的更多信息,请访问[整体架构文档](/tdinternal/arch/#主要逻辑单元) 。
|
||||
|
||||
## 接口
|
||||
|
||||
|
@ -240,6 +242,10 @@ Prometheus 使用的由 \*NIX 内核暴露的硬件和操作系统指标的输
|
|||
|
||||
<Prometheus />
|
||||
|
||||
### 获取 table 的 VGroup ID
|
||||
|
||||
可以访问 http 接口 `http://<fqdn>:6041/rest/vgid?db=<db>&table=<table>` 获取 table 的 VGroup ID。关于虚拟节点组(VGroup)的更多信息,请访问[整体架构文档](/tdinternal/arch/#主要逻辑单元) 。
|
||||
|
||||
## 内存使用优化方法
|
||||
|
||||
taosAdapter 将监测自身运行过程中内存使用率并通过两个阈值进行调节。有效值范围为 -1 到 100 的整数,单位为系统物理内存的百分比。
|
||||
|
@ -282,7 +288,7 @@ http 返回内容:
|
|||
|
||||
## taosAdapter 监控指标
|
||||
|
||||
taosAdapter 采集 http 相关指标、cpu 百分比和内存百分比。
|
||||
taosAdapter 采集 http 相关指标、CPU 百分比和内存百分比。
|
||||
|
||||
### http 接口
|
||||
|
||||
|
@ -294,13 +300,13 @@ http://<fqdn>:6041/metrics
|
|||
|
||||
### 写入 TDengine
|
||||
|
||||
taosAdapter 支持将 http 监控、cpu 百分比和内存百分比写入 TDengine。
|
||||
taosAdapter 支持将 http 监控、CPU 百分比和内存百分比写入 TDengine。
|
||||
|
||||
有关配置参数
|
||||
|
||||
| **配置项** | **描述** | **默认值** |
|
||||
|-------------------------|--------------------------------------------|----------|
|
||||
| monitor.collectDuration | cpu 和内存采集间隔 | 3s |
|
||||
| monitor.collectDuration | CPU 和内存采集间隔 | 3s |
|
||||
| monitor.identity | 当前taosadapter 的标识符如果不设置将使用 'hostname:port' | |
|
||||
| monitor.incgroup | 是否是 cgroup 中运行(容器中运行设置为 true) | false |
|
||||
| monitor.writeToTD | 是否写入到 TDengine | false |
|
||||
|
|
|
@ -10,6 +10,10 @@ TDengine 2.x 各版本安装包请访问[这里](https://www.taosdata.com/all-do
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 3.0.2.2
|
||||
|
||||
<Release type="tdengine" version="3.0.2.2" />
|
||||
|
||||
## 3.0.2.1
|
||||
|
||||
<Release type="tdengine" version="3.0.2.1" />
|
||||
|
|
|
@ -10,6 +10,10 @@ taosTools 各版本安装包下载链接如下:
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 2.4.0
|
||||
|
||||
<Release type="tools" version="2.4.0" />
|
||||
|
||||
## 2.3.3
|
||||
|
||||
<Release type="tools" version="2.3.3" />
|
||||
|
|
|
@ -341,7 +341,7 @@ typedef struct SExprInfo {
|
|||
|
||||
typedef struct {
|
||||
const char* key;
|
||||
int32_t keyLen;
|
||||
size_t keyLen;
|
||||
uint8_t type;
|
||||
union {
|
||||
const char* value;
|
||||
|
@ -350,7 +350,7 @@ typedef struct {
|
|||
double d;
|
||||
float f;
|
||||
};
|
||||
int32_t length;
|
||||
size_t length;
|
||||
} SSmlKv;
|
||||
|
||||
#define QUERY_ASC_FORWARD_STEP 1
|
||||
|
|
|
@ -265,7 +265,7 @@ void blockDebugShowDataBlocks(const SArray* dataBlocks, const char* flag);
|
|||
// for debug
|
||||
char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** dumpBuf);
|
||||
|
||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataBlocks, STSchema* pTSchema, int32_t vgId,
|
||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq2** pReq, const SSDataBlock* pDataBlocks, const STSchema* pTSchema, int64_t uid, int32_t vgId,
|
||||
tb_uid_t suid);
|
||||
|
||||
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId);
|
||||
|
|
|
@ -44,18 +44,38 @@ typedef struct SColData SColData;
|
|||
#define HAS_VALUE ((uint8_t)0x4)
|
||||
|
||||
// bitmap ================================
|
||||
const static uint8_t BIT2_MAP[4][4] = {{0b00000000, 0b00000001, 0b00000010, 0},
|
||||
{0b00000000, 0b00000100, 0b00001000, 2},
|
||||
{0b00000000, 0b00010000, 0b00100000, 4},
|
||||
{0b00000000, 0b01000000, 0b10000000, 6}};
|
||||
const static uint8_t BIT1_MAP[8] = {0b11111110, 0b11111101, 0b11111011, 0b11110111,
|
||||
0b11101111, 0b11011111, 0b10111111, 0b01111111};
|
||||
|
||||
#define N1(n) ((((uint8_t)1) << (n)) - 1)
|
||||
#define BIT1_SIZE(n) ((((n)-1) >> 3) + 1)
|
||||
#define BIT2_SIZE(n) ((((n)-1) >> 2) + 1)
|
||||
#define SET_BIT1(p, i, v) ((p)[(i) >> 3] = (p)[(i) >> 3] & N1((i)&7) | (((uint8_t)(v)) << ((i)&7)))
|
||||
#define GET_BIT1(p, i) (((p)[(i) >> 3] >> ((i)&7)) & ((uint8_t)1))
|
||||
#define SET_BIT2(p, i, v) ((p)[(i) >> 2] = (p)[(i) >> 2] & N1(BIT2_MAP[(i)&3][3]) | BIT2_MAP[(i)&3][(v)])
|
||||
#define GET_BIT2(p, i) (((p)[(i) >> 2] >> BIT2_MAP[(i)&3][3]) & ((uint8_t)3))
|
||||
const static uint8_t BIT2_MAP[4] = {0b11111100, 0b11110011, 0b11001111, 0b00111111};
|
||||
|
||||
#define ONE ((uint8_t)1)
|
||||
#define THREE ((uint8_t)3)
|
||||
#define DIV_8(i) ((i) >> 3)
|
||||
#define MOD_8(i) ((i)&7)
|
||||
#define DIV_4(i) ((i) >> 2)
|
||||
#define MOD_4(i) ((i)&3)
|
||||
#define MOD_4_TIME_2(i) (MOD_4(i) << 1)
|
||||
#define BIT1_SIZE(n) (DIV_8((n)-1) + 1)
|
||||
#define BIT2_SIZE(n) (DIV_4((n)-1) + 1)
|
||||
#define SET_BIT1(p, i, v) ((p)[DIV_8(i)] = (p)[DIV_8(i)] & BIT1_MAP[MOD_8(i)] | ((v) << MOD_8(i)))
|
||||
#define SET_BIT1_EX(p, i, v) \
|
||||
do { \
|
||||
if (MOD_8(i) == 0) { \
|
||||
(p)[DIV_8(i)] = 0; \
|
||||
} \
|
||||
SET_BIT1(p, i, v); \
|
||||
} while (0)
|
||||
#define GET_BIT1(p, i) (((p)[DIV_8(i)] >> MOD_8(i)) & ONE)
|
||||
#define SET_BIT2(p, i, v) ((p)[DIV_4(i)] = (p)[DIV_4(i)] & BIT2_MAP[MOD_4(i)] | ((v) << MOD_4_TIME_2(i)))
|
||||
#define SET_BIT2_EX(p, i, v) \
|
||||
do { \
|
||||
if (MOD_4(i) == 0) { \
|
||||
(p)[DIV_4(i)] = 0; \
|
||||
} \
|
||||
SET_BIT2(p, i, v); \
|
||||
} while (0)
|
||||
#define GET_BIT2(p, i) (((p)[DIV_4(i)] >> MOD_4_TIME_2(i)) & THREE)
|
||||
|
||||
// SBuffer ================================
|
||||
struct SBuffer {
|
||||
|
@ -70,9 +90,6 @@ int32_t tBufferInit(SBuffer *pBuffer, int64_t size);
|
|||
int32_t tBufferPut(SBuffer *pBuffer, const void *pData, int64_t nData);
|
||||
int32_t tBufferReserve(SBuffer *pBuffer, int64_t nData, void **ppData);
|
||||
|
||||
// STSchema ================================
|
||||
void tDestroyTSchema(STSchema *pTSchema);
|
||||
|
||||
// SColVal ================================
|
||||
#define CV_FLAG_VALUE ((int8_t)0x0)
|
||||
#define CV_FLAG_NONE ((int8_t)0x1)
|
||||
|
@ -87,8 +104,12 @@ void tDestroyTSchema(STSchema *pTSchema);
|
|||
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
|
||||
|
||||
// SRow ================================
|
||||
int32_t tRowBuild(SArray *aColVal, STSchema *pTSchema, SBuffer *pBuffer);
|
||||
int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow);
|
||||
void tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||
void tRowDestroy(SRow *pRow);
|
||||
void tRowSort(SArray *aRowP);
|
||||
int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag);
|
||||
int32_t tRowAppendToColData(SRow *pRow, STSchema *pTSchema, SColData *aColData, int32_t nColData);
|
||||
|
||||
// SRowIter ================================
|
||||
int32_t tRowIterOpen(SRow *pRow, STSchema *pTSchema, SRowIter **ppIter);
|
||||
|
@ -110,15 +131,28 @@ void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remov
|
|||
int32_t parseJsontoTagData(const char *json, SArray *pTagVals, STag **ppTag, void *pMsgBuf);
|
||||
|
||||
// SColData ================================
|
||||
typedef void *(*xMallocFn)(void *, int32_t);
|
||||
void tColDataDestroy(void *ph);
|
||||
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn);
|
||||
void tColDataClear(SColData *pColData);
|
||||
void tColDataDeepClear(SColData *pColData);
|
||||
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
|
||||
void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal);
|
||||
uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal);
|
||||
int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest);
|
||||
int32_t tColDataCopy(SColData *pColDataFrom, SColData *pColData, xMallocFn xMalloc, void *arg);
|
||||
extern void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, int16_t *numOfNull);
|
||||
|
||||
// for stmt bind
|
||||
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind);
|
||||
void tColDataSortMerge(SArray *colDataArr);
|
||||
|
||||
//for raw block
|
||||
int32_t tColDataAddValueByDataBlock(SColData *pColData, int8_t type, int32_t bytes,
|
||||
int32_t nRows, char* lengthOrbitmap, char *data);
|
||||
// for encode/decode
|
||||
int32_t tPutColData(uint8_t *pBuf, SColData *pColData);
|
||||
int32_t tGetColData(uint8_t *pBuf, SColData *pColData);
|
||||
|
||||
// STRUCT ================================
|
||||
struct STColumn {
|
||||
col_id_t colId;
|
||||
|
@ -225,23 +259,9 @@ struct STag {
|
|||
memcpy(varDataVal(x), (str), (_size)); \
|
||||
} while (0);
|
||||
|
||||
// ----------------- SCHEMA BUILDER DEFINITION
|
||||
typedef struct {
|
||||
int32_t tCols;
|
||||
int32_t nCols;
|
||||
schema_ver_t version;
|
||||
uint16_t flen;
|
||||
int32_t tlen;
|
||||
STColumn *columns;
|
||||
} STSchemaBuilder;
|
||||
|
||||
int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version);
|
||||
void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder);
|
||||
void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version);
|
||||
int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags, col_id_t colId, col_bytes_t bytes);
|
||||
STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
|
||||
|
||||
// STSchema ================================
|
||||
STSchema *tBuildTSchema(SSchema *aSchema, int32_t numOfCols, int32_t version);
|
||||
void tDestroyTSchema(STSchema *pTSchema);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ extern int32_t tsNumOfMnodeQueryThreads;
|
|||
extern int32_t tsNumOfMnodeFetchThreads;
|
||||
extern int32_t tsNumOfMnodeReadThreads;
|
||||
extern int32_t tsNumOfVnodeQueryThreads;
|
||||
extern int32_t tsNumOfVnodeStreamThreads;
|
||||
extern float tsRatioOfVnodeStreamThreads;
|
||||
extern int32_t tsNumOfVnodeFetchThreads;
|
||||
extern int32_t tsNumOfVnodeRsmaThreads;
|
||||
extern int32_t tsNumOfQnodeQueryThreads;
|
||||
|
|
|
@ -482,8 +482,6 @@ static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaW
|
|||
return 0;
|
||||
}
|
||||
|
||||
STSchema* tdGetSTSChemaFromSSChema(SSchema* pSchema, int32_t nCols, int32_t sver);
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t igExists;
|
||||
|
@ -1734,6 +1732,8 @@ typedef struct {
|
|||
int32_t execId;
|
||||
} STaskDropReq;
|
||||
|
||||
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
|
||||
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
|
||||
int32_t tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
|
||||
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
|
||||
|
||||
|
@ -1751,6 +1751,8 @@ typedef struct {
|
|||
#define STREAM_FILL_HISTORY_ON 1
|
||||
#define STREAM_FILL_HISTORY_OFF 0
|
||||
#define STREAM_DEFAULT_FILL_HISTORY STREAM_FILL_HISTORY_OFF
|
||||
#define STREAM_CREATE_STABLE_TRUE 1
|
||||
#define STREAM_CREATE_STABLE_FALSE 0
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_STREAM_FNAME_LEN];
|
||||
|
@ -1768,6 +1770,8 @@ typedef struct {
|
|||
SArray* pTags; // array of SField
|
||||
// 3.0.20
|
||||
int64_t checkpointFreq; // ms
|
||||
// 3.0.2.3
|
||||
int8_t createStb;
|
||||
} SCMCreateStreamReq;
|
||||
|
||||
typedef struct {
|
||||
|
@ -2081,10 +2085,15 @@ typedef struct SVCreateTbReq {
|
|||
};
|
||||
} SVCreateTbReq;
|
||||
|
||||
int tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
|
||||
int tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
|
||||
int tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
|
||||
int tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
|
||||
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
|
||||
|
||||
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
|
||||
if (NULL == req) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(req->name);
|
||||
taosMemoryFreeClear(req->comment);
|
||||
if (req->type == TSDB_CHILD_TABLE) {
|
||||
|
@ -3232,6 +3241,57 @@ int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
|||
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
|
||||
#define SUBMIT_REQ_AUTO_CREATE_TABLE 0x1
|
||||
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
|
||||
|
||||
typedef struct {
|
||||
int32_t flags;
|
||||
SVCreateTbReq* pCreateTbReq;
|
||||
int64_t suid;
|
||||
int64_t uid;
|
||||
int32_t sver;
|
||||
union {
|
||||
SArray* aRowP;
|
||||
SArray* aCol;
|
||||
};
|
||||
} SSubmitTbData;
|
||||
|
||||
typedef struct {
|
||||
SArray* aSubmitTbData; // SArray<SSubmitTbData>
|
||||
} SSubmitReq2;
|
||||
|
||||
int32_t tEncodeSSubmitReq2(SEncoder* pCoder, const SSubmitReq2* pReq);
|
||||
int32_t tDecodeSSubmitReq2(SDecoder* pCoder, SSubmitReq2* pReq);
|
||||
void tDestroySSubmitTbData(SSubmitTbData* pTbData, int32_t flag);
|
||||
void tDestroySSubmitReq2(SSubmitReq2* pReq, int32_t flag);
|
||||
|
||||
typedef struct {
|
||||
int32_t affectedRows;
|
||||
SArray* aCreateTbRsp; // SArray<SVCreateTbRsp>
|
||||
} SSubmitRsp2;
|
||||
|
||||
int32_t tEncodeSSubmitRsp2(SEncoder* pCoder, const SSubmitRsp2* pRsp);
|
||||
int32_t tDecodeSSubmitRsp2(SDecoder* pCoder, SSubmitRsp2* pRsp);
|
||||
void tDestroySSubmitRsp2(SSubmitRsp2* pRsp, int32_t flag);
|
||||
|
||||
#define TSDB_MSG_FLG_ENCODE 0x1
|
||||
#define TSDB_MSG_FLG_DECODE 0x2
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
void* msgStr;
|
||||
int32_t msgLen;
|
||||
int64_t ver;
|
||||
};
|
||||
void* pDataBlock;
|
||||
};
|
||||
} SPackedData;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
|
|
@ -190,7 +190,9 @@ int32_t qStreamPrepareTsdbScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts);
|
|||
|
||||
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType);
|
||||
|
||||
int32_t qStreamScanMemData(qTaskInfo_t tinfo, const SSubmitReq* pReq);
|
||||
// int32_t qStreamScanMemData(qTaskInfo_t tinfo, const SSubmitReq* pReq, int64_t ver);
|
||||
//
|
||||
int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit);
|
||||
|
||||
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset);
|
||||
|
||||
|
@ -213,6 +215,7 @@ int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver);
|
|||
int32_t qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver);
|
||||
int32_t qStreamRecoverFinish(qTaskInfo_t tinfo);
|
||||
int32_t qStreamRestoreParam(qTaskInfo_t tinfo);
|
||||
bool qStreamRecoverScanFinished(qTaskInfo_t tinfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ typedef struct SShowTableTagsStmt {
|
|||
SNodeList* pTags;
|
||||
} SShowTableTagsStmt;
|
||||
|
||||
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT } EIndexType;
|
||||
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT, INDEX_TYPE_NORMAL } EIndexType;
|
||||
|
||||
typedef struct SIndexOptions {
|
||||
ENodeType type;
|
||||
|
@ -401,6 +401,7 @@ typedef struct SCreateStreamStmt {
|
|||
SNode* pQuery;
|
||||
SNodeList* pTags;
|
||||
SNode* pSubtable;
|
||||
SNodeList* pCols;
|
||||
} SCreateStreamStmt;
|
||||
|
||||
typedef struct SDropStreamStmt {
|
||||
|
|
|
@ -361,33 +361,33 @@ typedef struct SVgDataBlocks {
|
|||
void* pData; // SSubmitReq + SSubmitBlk + ...
|
||||
} SVgDataBlocks;
|
||||
|
||||
typedef void (*FFreeDataBlockHash)(SHashObj*);
|
||||
typedef void (*FFreeDataBlockArray)(SArray*);
|
||||
typedef void (*FFreeTableBlockHash)(SHashObj*);
|
||||
typedef void (*FFreeVgourpBlockArray)(SArray*);
|
||||
|
||||
typedef struct SVnodeModifyOpStmt {
|
||||
ENodeType nodeType;
|
||||
ENodeType sqlNodeType;
|
||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||
const char* pSql; // current sql statement position
|
||||
int32_t totalRowsNum;
|
||||
int32_t totalTbNum;
|
||||
SName targetTableName;
|
||||
SName usingTableName;
|
||||
const char* pBoundCols;
|
||||
struct STableMeta* pTableMeta;
|
||||
SHashObj* pVgroupsHashObj;
|
||||
SHashObj* pTableBlockHashObj;
|
||||
SHashObj* pSubTableHashObj;
|
||||
SHashObj* pTableNameHashObj;
|
||||
SHashObj* pDbFNameHashObj;
|
||||
SArray* pVgDataBlocks;
|
||||
SVCreateTbReq createTblReq;
|
||||
TdFilePtr fp;
|
||||
FFreeDataBlockHash freeHashFunc;
|
||||
FFreeDataBlockArray freeArrayFunc;
|
||||
bool usingTableProcessing;
|
||||
bool fileProcessing;
|
||||
ENodeType nodeType;
|
||||
ENodeType sqlNodeType;
|
||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||
const char* pSql; // current sql statement position
|
||||
int32_t totalRowsNum;
|
||||
int32_t totalTbNum;
|
||||
SName targetTableName;
|
||||
SName usingTableName;
|
||||
const char* pBoundCols;
|
||||
struct STableMeta* pTableMeta;
|
||||
SHashObj* pVgroupsHashObj;
|
||||
SHashObj* pTableBlockHashObj; // SHashObj<tuid, STableDataCxt*>
|
||||
SHashObj* pSubTableHashObj;
|
||||
SHashObj* pTableNameHashObj;
|
||||
SHashObj* pDbFNameHashObj;
|
||||
SArray* pVgDataBlocks; // SArray<SVgroupDataCxt*>
|
||||
SVCreateTbReq* pCreateTblReq;
|
||||
TdFilePtr fp;
|
||||
FFreeTableBlockHash freeHashFunc;
|
||||
FFreeVgourpBlockArray freeArrayFunc;
|
||||
bool usingTableProcessing;
|
||||
bool fileProcessing;
|
||||
} SVnodeModifyOpStmt;
|
||||
|
||||
typedef struct SExplainOptions {
|
||||
|
|
|
@ -58,7 +58,6 @@ typedef struct SParseContext {
|
|||
bool isSuperUser;
|
||||
bool enableSysInfo;
|
||||
bool async;
|
||||
int8_t schemalessType;
|
||||
const char* svrVer;
|
||||
bool nodeOffline;
|
||||
SArray* pTableMetaPos; // sql table pos => catalog data pos
|
||||
|
@ -85,12 +84,12 @@ int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
|
|||
void qCleanupKeywordsTable();
|
||||
|
||||
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
|
||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf);
|
||||
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc);
|
||||
void qFreeStmtDataBlock(void* pDataBlock);
|
||||
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid, int32_t vgId);
|
||||
void qDestroyStmtDataBlock(void* pBlock);
|
||||
STableMeta* qGetTableMetaInDataBlock(void* pDataBlock);
|
||||
int32_t qResetStmtDataBlock(STableDataCxt* block, bool keepBuf);
|
||||
int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset);
|
||||
int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, bool rebuildCreateTb);
|
||||
void qDestroyStmtDataBlock(STableDataCxt* pBlock);
|
||||
STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock);
|
||||
int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData **pData);
|
||||
|
||||
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx);
|
||||
int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery);
|
||||
|
@ -105,11 +104,18 @@ void destroyBoundColumnInfo(void* pBoundInfo);
|
|||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
|
||||
int32_t msgBufLen);
|
||||
|
||||
void* smlInitHandle(SQuery* pQuery);
|
||||
void smlDestroyHandle(void* pHandle);
|
||||
int32_t smlBindData(void* handle, SArray* tags, SArray* colsSchema, SArray* cols, bool format, STableMeta* pTableMeta,
|
||||
void qDestroyBoundColInfo(void* pInfo);
|
||||
|
||||
SQuery* smlInitHandle();
|
||||
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 smlBindData(SQuery* handle, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols, STableMeta* pTableMeta,
|
||||
char* tableName, const char* sTableName, int32_t sTableNameLen, int32_t ttl, char* msgBuf, int16_t msgBufLen);
|
||||
int32_t smlBuildOutput(void* handle, SHashObj* pVgHash);
|
||||
int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash);
|
||||
|
||||
int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCreateTbReq* pCreateTb, TAOS_FIELD *fields, int numFields);
|
||||
|
||||
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
|
||||
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
|
||||
|
|
|
@ -163,6 +163,23 @@ typedef struct STargetInfo {
|
|||
int32_t vgId;
|
||||
} STargetInfo;
|
||||
|
||||
typedef struct SBoundColInfo {
|
||||
int16_t* pColIndex; // bound index => schema index
|
||||
int32_t numOfCols;
|
||||
int32_t numOfBound;
|
||||
} SBoundColInfo;
|
||||
|
||||
typedef struct STableDataCxt {
|
||||
STableMeta* pMeta;
|
||||
STSchema* pSchema;
|
||||
SBoundColInfo boundColsInfo;
|
||||
SArray* pValues;
|
||||
SSubmitTbData* pData;
|
||||
TSKEY lastTs;
|
||||
bool ordered;
|
||||
bool duplicateTs;
|
||||
} STableDataCxt;
|
||||
|
||||
typedef int32_t (*__async_send_cb_fn_t)(void* param, SDataBuf* pMsg, int32_t code);
|
||||
typedef int32_t (*__async_exec_fn_t)(void* param);
|
||||
|
||||
|
@ -238,6 +255,7 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t
|
|||
char* parseTagDatatoJson(void* p);
|
||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
||||
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
||||
int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst);
|
||||
void freeVgInfo(SDBVgInfo* vgInfo);
|
||||
|
||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen,
|
||||
|
@ -268,7 +286,7 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
|||
((_code) == TSDB_CODE_SYN_NOT_LEADER || (_code) == TSDB_CODE_SYN_RESTORING || (_code) == TSDB_CODE_SYN_INTERNAL_ERROR)
|
||||
#define SYNC_OTHER_LEADER_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_MNODE_NOT_FOUND)
|
||||
|
||||
#define NO_RET_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
|
||||
#define NO_RET_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || (_code) == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED)
|
||||
|
||||
#define NEED_REDIRECT_ERROR(_code) \
|
||||
(NO_RET_REDIRECT_ERROR(_code) || SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || \
|
||||
|
|
|
@ -103,6 +103,7 @@ typedef struct {
|
|||
int8_t type;
|
||||
} SStreamQueueItem;
|
||||
|
||||
#if 0
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int64_t ver;
|
||||
|
@ -116,6 +117,21 @@ typedef struct {
|
|||
SArray* dataRefs; // SArray<int32_t*>
|
||||
SArray* reqs; // SArray<SSubmitReq*>
|
||||
} SStreamMergedSubmit;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int64_t ver;
|
||||
int32_t* dataRef;
|
||||
SPackedData submit;
|
||||
} SStreamDataSubmit2;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int64_t ver;
|
||||
SArray* dataRefs; // SArray<int32_t*>
|
||||
SArray* submits; // SArray<SPackedSubmit>
|
||||
} SStreamMergedSubmit2;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
|
@ -219,11 +235,11 @@ static FORCE_INLINE void* streamQueueNextItem(SStreamQueue* queue) {
|
|||
}
|
||||
}
|
||||
|
||||
SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq);
|
||||
SStreamDataSubmit2* streamDataSubmitNew(SPackedData submit);
|
||||
|
||||
void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit);
|
||||
void streamDataSubmitRefDec(SStreamDataSubmit2* pDataSubmit);
|
||||
|
||||
SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit);
|
||||
SStreamDataSubmit2* streamSubmitRefClone(SStreamDataSubmit2* pSubmit);
|
||||
|
||||
typedef struct {
|
||||
char* qmsg;
|
||||
|
@ -355,14 +371,15 @@ void tFreeSStreamTask(SStreamTask* pTask);
|
|||
|
||||
static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem* pItem) {
|
||||
if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||
SStreamDataSubmit* pSubmitClone = streamSubmitRefClone((SStreamDataSubmit*)pItem);
|
||||
SStreamDataSubmit2* pSubmitClone = streamSubmitRefClone((SStreamDataSubmit2*)pItem);
|
||||
if (pSubmitClone == NULL) {
|
||||
qDebug("task %d %p submit enqueue failed since out of memory", pTask->taskId, pTask);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
return -1;
|
||||
}
|
||||
qDebug("task %d %p submit enqueue %p %p %p", pTask->taskId, pTask, pItem, pSubmitClone, pSubmitClone->data);
|
||||
qDebug("task %d %p submit enqueue %p %p %p %d %" PRId64, pTask->taskId, pTask, pItem, pSubmitClone,
|
||||
pSubmitClone->submit.msgStr, pSubmitClone->submit.msgLen, pSubmitClone->submit.ver);
|
||||
taosWriteQitem(pTask->inputQueue->queue, pSubmitClone);
|
||||
// qStreamInput(pTask->exec.executor, pSubmitClone);
|
||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE ||
|
||||
|
@ -392,21 +409,6 @@ static FORCE_INLINE void streamTaskInputFail(SStreamTask* pTask) {
|
|||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBlock* pBlock) {
|
||||
if (pTask->outputType == TASK_OUTPUT__TABLE) {
|
||||
pTask->tbSink.tbSinkFunc(pTask, pTask->tbSink.vnode, 0, pBlock->blocks);
|
||||
taosArrayDestroyEx(pBlock->blocks, (FDelete)blockDataFreeRes);
|
||||
taosFreeQitem(pBlock);
|
||||
} else if (pTask->outputType == TASK_OUTPUT__SMA) {
|
||||
pTask->smaSink.smaSink(pTask->smaSink.vnode, pTask->smaSink.smaId, pBlock->blocks);
|
||||
taosArrayDestroyEx(pBlock->blocks, (FDelete)blockDataFreeRes);
|
||||
taosFreeQitem(pBlock);
|
||||
} else {
|
||||
taosWriteQitem(pTask->outputQueue->queue, pBlock);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
int64_t streamId;
|
||||
|
@ -584,6 +586,7 @@ int32_t streamProcessRetrieveRsp(SStreamTask* pTask, SStreamRetrieveRsp* pRsp);
|
|||
|
||||
int32_t streamTryExec(SStreamTask* pTask);
|
||||
int32_t streamSchedExec(SStreamTask* pTask);
|
||||
int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBlock* pBlock);
|
||||
|
||||
int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz);
|
||||
|
||||
|
|
|
@ -22,12 +22,16 @@ extern "C" {
|
|||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following sectio
|
||||
#if !defined(WINDOWS)
|
||||
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define malloc MALLOC_FUNC_TAOS_FORBID
|
||||
#define calloc CALLOC_FUNC_TAOS_FORBID
|
||||
#define realloc REALLOC_FUNC_TAOS_FORBID
|
||||
#define free FREE_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
#endif // ifndef ALLOW_FORBID_FUNC
|
||||
|
||||
#endif // if !defined(WINDOWS)
|
||||
|
||||
void *taosMemoryMalloc(int64_t size);
|
||||
void *taosMemoryCalloc(int64_t num, int64_t size);
|
||||
|
|
|
@ -70,6 +70,7 @@ typedef struct {
|
|||
|
||||
SysNameInfo taosGetSysNameInfo();
|
||||
bool taosCheckCurrentInDll();
|
||||
int taosGetlocalhostname(char *hostname, size_t maxLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -62,11 +62,38 @@ void taosResetTerminalMode();
|
|||
taosMemoryFree(strings); \
|
||||
}
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
#define STACKSIZE 64
|
||||
#define taosPrintTrace(flags, level, dflag) \
|
||||
{ \
|
||||
taosPrintLog(flags, level, dflag, \
|
||||
"backtrace not implemented on windows, so detailed stack information cannot be printed"); \
|
||||
}
|
||||
unsigned int i; \
|
||||
void* stack[STACKSIZE]; \
|
||||
unsigned short frames; \
|
||||
SYMBOL_INFO* symbol; \
|
||||
HANDLE process; \
|
||||
\
|
||||
process = GetCurrentProcess(); \
|
||||
\
|
||||
SymInitialize(process, NULL, TRUE); \
|
||||
\
|
||||
frames = CaptureStackBackTrace(0, STACKSIZE, stack, NULL); \
|
||||
symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1); \
|
||||
if (symbol != NULL) { \
|
||||
symbol->MaxNameLen = 255; \
|
||||
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); \
|
||||
\
|
||||
if (frames > 0) { \
|
||||
taosPrintLog(flags, level, dflag, "obtained %d stack frames", frames); \
|
||||
for (i = 0; i < frames; i++) { \
|
||||
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); \
|
||||
taosPrintLog(flags, level, dflag, "frame:%i: %s - 0x%0X", frames - i - 1, symbol->Name, symbol->Address); \
|
||||
} \
|
||||
} \
|
||||
free(symbol); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -52,11 +52,13 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tFree(uint8_t *pBuf) {
|
||||
if (pBuf) {
|
||||
taosMemoryFree(pBuf - sizeof(int64_t));
|
||||
}
|
||||
}
|
||||
#define tFree(BUF) \
|
||||
do { \
|
||||
if (BUF) { \
|
||||
taosMemoryFree((uint8_t *)(BUF) - sizeof(int64_t)); \
|
||||
(BUF) = NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -65,6 +65,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_RPC_PORT_EADDRINUSE TAOS_DEF_ERROR_CODE(0, 0x0017) //
|
||||
#define TSDB_CODE_RPC_BROKEN_LINK TAOS_DEF_ERROR_CODE(0, 0x0018) //
|
||||
#define TSDB_CODE_RPC_TIMEOUT TAOS_DEF_ERROR_CODE(0, 0x0019) //
|
||||
#define TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED TAOS_DEF_ERROR_CODE(0, 0x0020) // "Vgroup could not be connected"
|
||||
#define TSDB_CODE_RPC_SOMENODE_BROKEN_LINK TAOS_DEF_ERROR_CODE(0, 0x0021) //
|
||||
|
||||
//common & util
|
||||
#define TSDB_CODE_OPS_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x0100) //
|
||||
|
@ -156,6 +158,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TSC_QUERY_KILLED TAOS_DEF_ERROR_CODE(0, 0X022D)
|
||||
#define TSDB_CODE_TSC_NO_EXEC_NODE TAOS_DEF_ERROR_CODE(0, 0X022E)
|
||||
#define TSDB_CODE_TSC_NOT_STABLE_ERROR TAOS_DEF_ERROR_CODE(0, 0X022F)
|
||||
#define TSDB_CODE_TSC_STMT_CACHE_ERROR TAOS_DEF_ERROR_CODE(0, 0X0230)
|
||||
|
||||
// mnode-common
|
||||
// #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) // 2.x
|
||||
|
@ -517,6 +520,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912)
|
||||
#define TSDB_CODE_SYN_BATCH_ERROR TAOS_DEF_ERROR_CODE(0, 0x0913)
|
||||
#define TSDB_CODE_SYN_RESTORING TAOS_DEF_ERROR_CODE(0, 0x0914)
|
||||
#define TSDB_CODE_SYN_INVALID_SNAPSHOT_MSG TAOS_DEF_ERROR_CODE(0, 0x0915) // internal
|
||||
#define TSDB_CODE_SYN_BUFFER_FULL TAOS_DEF_ERROR_CODE(0, 0x0916) //
|
||||
#define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF)
|
||||
|
||||
// tq
|
||||
|
|
|
@ -22,19 +22,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define TARRAY(TYPE) \
|
||||
struct { \
|
||||
int32_t tarray_size_; \
|
||||
int32_t tarray_neles_; \
|
||||
struct TYPE* td_array_data_; \
|
||||
}
|
||||
|
||||
#define TARRAY_SIZE(ARRAY) (ARRAY)->tarray_size_
|
||||
#define TARRAY_NELES(ARRAY) (ARRAY)->tarray_neles_
|
||||
#define TARRAY_ELE_AT(ARRAY, IDX) ((ARRAY)->td_array_data_ + idx)
|
||||
#endif
|
||||
|
||||
#define TARRAY_MIN_SIZE 8
|
||||
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
|
||||
#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
|
||||
|
@ -46,6 +33,9 @@ typedef struct SArray {
|
|||
void* pData;
|
||||
} SArray;
|
||||
|
||||
#define TARRAY_SIZE(array) ((array)->size)
|
||||
#define TARRAY_DATA(array) ((array)->pData)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param size
|
||||
|
@ -194,6 +184,13 @@ void taosArrayPopTailBatch(SArray* pArray, size_t cnt);
|
|||
*/
|
||||
void taosArrayRemove(SArray* pArray, size_t index);
|
||||
|
||||
/**
|
||||
* remove batch entry from the given index
|
||||
* @param pArray
|
||||
* @param index
|
||||
*/
|
||||
void taosArrayRemoveBatch(SArray* pArray, size_t index, size_t num, FDelete fp);
|
||||
|
||||
/**
|
||||
* copy the whole array from source to destination
|
||||
* @param pDst
|
||||
|
|
|
@ -189,12 +189,13 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_MAX_COLUMNS 4096
|
||||
#define TSDB_MIN_COLUMNS 2 // PRIMARY COLUMN(timestamp) + other columns
|
||||
|
||||
#define TSDB_NODE_NAME_LEN 64
|
||||
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_CGROUP_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_DB_NAME_LEN 65
|
||||
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_NODE_NAME_LEN 64
|
||||
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_CGROUP_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_USER_CGROUP_LEN (TSDB_USER_LEN + TSDB_CGROUP_LEN) // it is a null-terminated string
|
||||
#define TSDB_DB_NAME_LEN 65
|
||||
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
|
||||
#define TSDB_FUNC_NAME_LEN 65
|
||||
#define TSDB_FUNC_COMMENT_LEN 1024 * 1024
|
||||
|
@ -254,7 +255,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6)
|
||||
#define TSDB_IPv4ADDR_LEN 16
|
||||
#define TSDB_FILENAME_LEN 128
|
||||
#define TSDB_SHOW_SQL_LEN 1024
|
||||
#define TSDB_SHOW_SQL_LEN 2048
|
||||
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
||||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||
|
||||
|
|
|
@ -116,6 +116,7 @@ static int32_t tEncodeI64v(SEncoder* pCoder, int64_t val);
|
|||
static int32_t tEncodeFloat(SEncoder* pCoder, float val);
|
||||
static int32_t tEncodeDouble(SEncoder* pCoder, double val);
|
||||
static int32_t tEncodeBinary(SEncoder* pCoder, const uint8_t* val, uint32_t len);
|
||||
static int32_t tEncodeBinaryEx(SEncoder* pCoder, const uint8_t* val, uint32_t len);
|
||||
static int32_t tEncodeCStrWithLen(SEncoder* pCoder, const char* val, uint32_t len);
|
||||
static int32_t tEncodeCStr(SEncoder* pCoder, const char* val);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define _TD_UTIL_WORKER_H_
|
||||
|
||||
#include "tqueue.h"
|
||||
#include "tarray.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -26,10 +27,10 @@ typedef struct SQWorkerPool SQWorkerPool;
|
|||
typedef struct SWWorkerPool SWWorkerPool;
|
||||
|
||||
typedef struct SQWorker {
|
||||
int32_t id; // worker id
|
||||
int64_t pid; // thread pid
|
||||
TdThread thread; // thread id
|
||||
SQWorkerPool *pool;
|
||||
int32_t id; // worker id
|
||||
int64_t pid; // thread pid
|
||||
TdThread thread; // thread id
|
||||
void *pool;
|
||||
} SQWorker;
|
||||
|
||||
typedef struct SQWorkerPool {
|
||||
|
@ -42,6 +43,14 @@ typedef struct SQWorkerPool {
|
|||
TdThreadMutex mutex;
|
||||
} SQWorkerPool;
|
||||
|
||||
typedef struct SAutoQWorkerPool {
|
||||
float ratio;
|
||||
STaosQset *qset;
|
||||
const char *name;
|
||||
SArray *workers;
|
||||
TdThreadMutex mutex;
|
||||
} SAutoQWorkerPool;
|
||||
|
||||
typedef struct SWWorker {
|
||||
int32_t id; // worker id
|
||||
int64_t pid; // thread pid
|
||||
|
@ -65,6 +74,11 @@ void tQWorkerCleanup(SQWorkerPool *pool);
|
|||
STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp);
|
||||
void tQWorkerFreeQueue(SQWorkerPool *pool, STaosQueue *queue);
|
||||
|
||||
int32_t tAutoQWorkerInit(SAutoQWorkerPool *pool);
|
||||
void tAutoQWorkerCleanup(SAutoQWorkerPool *pool);
|
||||
STaosQueue *tAutoQWorkerAllocQueue(SAutoQWorkerPool *pool, void *ahandle, FItem fp);
|
||||
void tAutoQWorkerFreeQueue(SAutoQWorkerPool *pool, STaosQueue *queue);
|
||||
|
||||
int32_t tWWorkerInit(SWWorkerPool *pool);
|
||||
void tWWorkerCleanup(SWWorkerPool *pool);
|
||||
STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp);
|
||||
|
|
|
@ -14,6 +14,7 @@ set binary_dir=%3
|
|||
set binary_dir=%binary_dir:/=\\%
|
||||
set osType=%4
|
||||
set verNumber=%5
|
||||
set Enterprise=%6
|
||||
set target_dir=C:\\TDengine
|
||||
|
||||
if not exist %target_dir% (
|
||||
|
@ -57,7 +58,33 @@ if exist %binary_dir%\\build\\lib\\taosws.dll (
|
|||
if exist %binary_dir%\\build\\bin\\taosdump.exe (
|
||||
copy %binary_dir%\\build\\bin\\taosdump.exe %target_dir% > nul
|
||||
)
|
||||
|
||||
if %Enterprise% == TRUE (
|
||||
if exist %binary_dir%\\build\\bin\\taosx.exe (
|
||||
copy %binary_dir%\\build\\bin\\taosx.exe %target_dir% > nul
|
||||
)
|
||||
if exist %binary_dir%\\build\\bin\\tmq_sim.exe (
|
||||
copy %binary_dir%\\build\\bin\\tmq_sim.exe %target_dir% > nul
|
||||
)
|
||||
if exist %binary_dir%\\build\\bin\\tsim.exe (
|
||||
copy %binary_dir%\\build\\bin\\tsim.exe %target_dir% > nul
|
||||
)
|
||||
if exist %binary_dir%\\build\\bin\\tmq_taosx_ci.exe (
|
||||
copy %binary_dir%\\build\\bin\\tmq_taosx_ci.exe %target_dir% > nul
|
||||
)
|
||||
if exist %binary_dir%\\build\\bin\\tmq_demo.exe (
|
||||
copy %binary_dir%\\build\\bin\\tmq_demo.exe %target_dir% > nul
|
||||
)
|
||||
if exist %binary_dir%\\build\\bin\\dumper.exe (
|
||||
copy %binary_dir%\\build\\bin\\dumper.exe %target_dir% > nul
|
||||
)
|
||||
if exist %binary_dir%\\build\\bin\\runUdf.exe (
|
||||
copy %binary_dir%\\build\\bin\\runUdf.exe %target_dir% > nul
|
||||
)
|
||||
if exist %binary_dir%\\build\\bin\\create_table.exe (
|
||||
copy %binary_dir%\\build\\bin\\create_table.exe %target_dir% > nul
|
||||
)
|
||||
)
|
||||
|
||||
copy %binary_dir%\\build\\bin\\taosd.exe %target_dir% > nul
|
||||
copy %binary_dir%\\build\\bin\\udfd.exe %target_dir% > nul
|
||||
|
||||
|
|
|
@ -348,7 +348,8 @@ cd ${release_dir}
|
|||
# install_dir has been distinguishes cluster from edege, so comments this code
|
||||
pkg_name=${install_dir}-${osType}-${cpuType}
|
||||
|
||||
taostools_pkg_name=${taostools_install_dir}-${osType}-${cpuType}
|
||||
versionCompFirst=$(echo ${versionComp} | awk -F '.' '{print $1}')
|
||||
taostools_pkg_name=${taostools_install_dir}-${osType}-${cpuType}-comp${versionCompFirst}
|
||||
|
||||
# if [ "$verMode" == "cluster" ]; then
|
||||
# pkg_name=${install_dir}-${osType}-${cpuType}
|
||||
|
|
|
@ -149,7 +149,6 @@ typedef struct STscObj {
|
|||
int32_t numOfReqs; // number of sqlObj bound to this connection
|
||||
SAppInstInfo* pAppInfo;
|
||||
SHashObj* pRequests;
|
||||
int8_t schemalessType; // todo remove it, this attribute should be move to request
|
||||
} STscObj;
|
||||
|
||||
typedef struct SResultColumn {
|
||||
|
|
|
@ -30,7 +30,7 @@ extern "C" {
|
|||
#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", DEBUG_TRACE, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
//#define tscPerf(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", DEBUG_INFO, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscPerf(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", 0, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
// clang-format on
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TDENGINE_CLIENTSML_H
|
||||
#define TDENGINE_CLIENTSML_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "catalog.h"
|
||||
#include "clientInt.h"
|
||||
#include "osThread.h"
|
||||
#include "query.h"
|
||||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
#include "tcommon.h"
|
||||
#include "tdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlog.h"
|
||||
#include "tmsg.h"
|
||||
#include "tname.h"
|
||||
#include "ttime.h"
|
||||
#include "ttypes.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
#if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__)
|
||||
# define expect(expr,value) (__builtin_expect ((expr),(value)) )
|
||||
#else
|
||||
# define expect(expr,value) (expr)
|
||||
#endif
|
||||
|
||||
#ifndef likely
|
||||
#define likely(expr) expect((expr) != 0, 1)
|
||||
#endif
|
||||
#ifndef unlikely
|
||||
#define unlikely(expr) expect((expr) != 0, 0)
|
||||
#endif
|
||||
|
||||
#define SPACE ' '
|
||||
#define COMMA ','
|
||||
#define EQUAL '='
|
||||
#define QUOTE '"'
|
||||
#define SLASH '\\'
|
||||
|
||||
#define JUMP_SPACE(sql, sqlEnd) \
|
||||
while (sql < sqlEnd) { \
|
||||
if (unlikely(*sql == SPACE)) \
|
||||
sql++; \
|
||||
else \
|
||||
break; \
|
||||
}
|
||||
|
||||
#define IS_INVALID_COL_LEN(len) ((len) <= 0 || (len) >= TSDB_COL_NAME_LEN)
|
||||
#define IS_INVALID_TABLE_LEN(len) ((len) <= 0 || (len) >= TSDB_TABLE_NAME_LEN)
|
||||
|
||||
#define TS "_ts"
|
||||
#define TS_LEN 3
|
||||
#define VALUE "_value"
|
||||
#define VALUE_LEN 6
|
||||
|
||||
#define MAX_RETRY_TIMES 5
|
||||
typedef TSDB_SML_PROTOCOL_TYPE SMLProtocolType;
|
||||
|
||||
typedef enum {
|
||||
SCHEMA_ACTION_NULL,
|
||||
SCHEMA_ACTION_CREATE_STABLE,
|
||||
SCHEMA_ACTION_ADD_COLUMN,
|
||||
SCHEMA_ACTION_ADD_TAG,
|
||||
SCHEMA_ACTION_CHANGE_COLUMN_SIZE,
|
||||
SCHEMA_ACTION_CHANGE_TAG_SIZE,
|
||||
} ESchemaAction;
|
||||
|
||||
typedef struct {
|
||||
const void *key;
|
||||
int32_t keyLen;
|
||||
void *value;
|
||||
bool used;
|
||||
}Node;
|
||||
|
||||
typedef struct NodeList{
|
||||
Node data;
|
||||
struct NodeList* next;
|
||||
}NodeList;
|
||||
|
||||
typedef struct {
|
||||
char *measure;
|
||||
char *tags;
|
||||
char *cols;
|
||||
char *timestamp;
|
||||
|
||||
int32_t measureLen;
|
||||
int32_t measureTagsLen;
|
||||
int32_t tagsLen;
|
||||
int32_t colsLen;
|
||||
int32_t timestampLen;
|
||||
|
||||
SArray *colArray;
|
||||
} SSmlLineInfo;
|
||||
|
||||
typedef struct {
|
||||
const char *sTableName; // super table name
|
||||
int32_t sTableNameLen;
|
||||
char childTableName[TSDB_TABLE_NAME_LEN];
|
||||
uint64_t uid;
|
||||
void *key; // for openTsdb
|
||||
|
||||
SArray *tags;
|
||||
|
||||
// elements are SHashObj<cols key string, SSmlKv*> for find by key quickly
|
||||
SArray *cols;
|
||||
STableDataCxt *tableDataCtx;
|
||||
} SSmlTableInfo;
|
||||
|
||||
typedef struct {
|
||||
SArray *tags; // save the origin order to create table
|
||||
SHashObj *tagHash; // elements are <key, index in tags>
|
||||
|
||||
SArray *cols;
|
||||
SHashObj *colHash;
|
||||
|
||||
STableMeta *tableMeta;
|
||||
} SSmlSTableMeta;
|
||||
|
||||
typedef struct {
|
||||
int32_t len;
|
||||
char *buf;
|
||||
} SSmlMsgBuf;
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
int32_t lineNum;
|
||||
|
||||
int32_t numOfSTables;
|
||||
int32_t numOfCTables;
|
||||
int32_t numOfCreateSTables;
|
||||
int32_t numOfAlterColSTables;
|
||||
int32_t numOfAlterTagSTables;
|
||||
|
||||
int64_t parseTime;
|
||||
int64_t schemaTime;
|
||||
int64_t insertBindTime;
|
||||
int64_t insertRpcTime;
|
||||
int64_t endTime;
|
||||
} SSmlCostInfo;
|
||||
|
||||
typedef struct {
|
||||
int64_t id;
|
||||
|
||||
SMLProtocolType protocol;
|
||||
int8_t precision;
|
||||
bool reRun;
|
||||
bool dataFormat; // true means that the name and order of keys in each line are the same(only for influx protocol)
|
||||
bool isRawLine;
|
||||
int32_t ttl;
|
||||
|
||||
NodeList *childTables;
|
||||
NodeList *superTables;
|
||||
SHashObj *pVgHash;
|
||||
|
||||
STscObj *taos;
|
||||
SCatalog *pCatalog;
|
||||
SRequestObj *pRequest;
|
||||
SQuery *pQuery;
|
||||
|
||||
SSmlCostInfo cost;
|
||||
int32_t lineNum;
|
||||
SSmlMsgBuf msgBuf;
|
||||
|
||||
// cJSON *root; // for parse json
|
||||
int8_t offset[4];
|
||||
SSmlLineInfo *lines; // element is SSmlLineInfo
|
||||
|
||||
//
|
||||
SArray *preLineTagKV;
|
||||
SArray *preLineColKV;
|
||||
|
||||
SSmlLineInfo preLine;
|
||||
STableMeta *currSTableMeta;
|
||||
STableDataCxt *currTableDataCtx;
|
||||
bool needModifySchema;
|
||||
} SSmlHandle;
|
||||
|
||||
#define IS_SAME_CHILD_TABLE (elements->measureTagsLen == info->preLine.measureTagsLen \
|
||||
&& memcmp(elements->measure, info->preLine.measure, elements->measureTagsLen) == 0)
|
||||
|
||||
#define IS_SAME_SUPER_TABLE (elements->measureLen == info->preLine.measureLen \
|
||||
&& memcmp(elements->measure, info->preLine.measure, elements->measureLen) == 0)
|
||||
|
||||
#define IS_SAME_KEY (preKV->keyLen == kv.keyLen && memcmp(preKV->key, kv.key, kv.keyLen) == 0)
|
||||
|
||||
extern int64_t smlFactorNS[3];
|
||||
extern int64_t smlFactorS[3];
|
||||
|
||||
typedef int32_t (*_equal_fn_sml)(const void *, const void *);
|
||||
|
||||
SSmlHandle *smlBuildSmlInfo(TAOS *taos);
|
||||
void smlDestroyInfo(SSmlHandle *info);
|
||||
void smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset);
|
||||
void smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset);
|
||||
SArray *smlJsonParseTags(char *start, char *end);
|
||||
bool smlParseNumberOld(SSmlKv *kvVal, SSmlMsgBuf *msg);
|
||||
void* nodeListGet(NodeList* list, const void *key, int32_t len, _equal_fn_sml fn);
|
||||
int nodeListSet(NodeList** list, const void *key, int32_t len, void* value, _equal_fn_sml fn);
|
||||
int nodeListSize(NodeList* list);
|
||||
bool smlDoubleToInt64OverFlow(double num);
|
||||
int32_t smlBuildInvalidDataMsg(SSmlMsgBuf *pBuf, const char *msg1, const char *msg2);
|
||||
bool smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg);
|
||||
int64_t smlGetTimeValue(const char *value, int32_t len, uint8_t fromPrecision, uint8_t toPrecision);
|
||||
int8_t smlGetTsTypeByLen(int32_t len);
|
||||
SSmlTableInfo* smlBuildTableInfo(int numRows, const char* measure, int32_t measureLen);
|
||||
SSmlSTableMeta* smlBuildSTableMeta(bool isDataFormat);
|
||||
int32_t smlSetCTableName(SSmlTableInfo *oneTable);
|
||||
STableMeta* smlGetMeta(SSmlHandle *info, const void* measure, int32_t measureLen);
|
||||
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);
|
||||
int32_t smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg);
|
||||
|
||||
int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements);
|
||||
int32_t smlParseTelnetString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements);
|
||||
int32_t smlParseJSON(SSmlHandle *info, char *payload);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_CLIENTSML_H
|
|
@ -21,8 +21,6 @@ extern "C" {
|
|||
#endif
|
||||
#include "catalog.h"
|
||||
|
||||
typedef void STableDataBlocks;
|
||||
|
||||
typedef enum {
|
||||
STMT_TYPE_INSERT = 1,
|
||||
STMT_TYPE_MULTI_INSERT,
|
||||
|
@ -43,8 +41,8 @@ typedef enum {
|
|||
} STMT_STATUS;
|
||||
|
||||
typedef struct SStmtTableCache {
|
||||
STableDataBlocks *pDataBlock;
|
||||
void *boundTags;
|
||||
STableDataCxt *pDataCtx;
|
||||
void *boundTags;
|
||||
} SStmtTableCache;
|
||||
|
||||
typedef struct SStmtQueryResInfo {
|
||||
|
@ -71,10 +69,11 @@ typedef struct SStmtBindInfo {
|
|||
} SStmtBindInfo;
|
||||
|
||||
typedef struct SStmtExecInfo {
|
||||
int32_t affectedRows;
|
||||
SRequestObj *pRequest;
|
||||
SHashObj *pBlockHash;
|
||||
bool autoCreateTbl;
|
||||
int32_t affectedRows;
|
||||
SRequestObj *pRequest;
|
||||
SHashObj *pBlockHash;
|
||||
STableDataCxt *pCurrBlock;
|
||||
SSubmitTbData *pCurrTbData;
|
||||
} SStmtExecInfo;
|
||||
|
||||
typedef struct SStmtSQLInfo {
|
||||
|
|
|
@ -76,13 +76,19 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
"current:%d, app current:%d",
|
||||
pRequest->self, pTscObj->id, pRequest->requestId, duration / 1000.0, num, currentInst);
|
||||
|
||||
tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64
|
||||
"us, exec:%" PRId64 "us, stmtType:%d",
|
||||
duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart,
|
||||
pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - pRequest->metric.ctgEnd,
|
||||
pRequest->metric.execEnd - pRequest->metric.semanticEnd, pRequest->stmtType);
|
||||
|
||||
if (QUERY_NODE_VNODE_MODIFY_STMT == pRequest->stmtType) {
|
||||
// tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64
|
||||
// "us, exec:%" PRId64 "us",
|
||||
// duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart,
|
||||
// pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd -
|
||||
// pRequest->metric.ctgEnd, pRequest->metric.execEnd - pRequest->metric.semanticEnd);
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
|
||||
// tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64
|
||||
// "us, exec:%" PRId64 "us",
|
||||
// duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart,
|
||||
// pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd -
|
||||
// pRequest->metric.ctgEnd, pRequest->metric.execEnd - pRequest->metric.semanticEnd);
|
||||
// atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
|
||||
} else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) {
|
||||
// tscPerf("select duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64
|
||||
// "us, planner:%" PRId64 "us, exec:%" PRId64 "us, reqId:0x%" PRIx64,
|
||||
|
@ -264,7 +270,6 @@ void *createTscObj(const char *user, const char *auth, const char *db, int32_t c
|
|||
|
||||
taosThreadMutexInit(&pObj->mutex, NULL);
|
||||
pObj->id = taosAddRef(clientConnRefPool, pObj);
|
||||
pObj->schemalessType = 1;
|
||||
|
||||
atomic_add_fetch_64(&pObj->pAppInfo->numOfConns, 1);
|
||||
|
||||
|
|
|
@ -239,7 +239,6 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
|
|||
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||
.pStmtCb = pStmtCb,
|
||||
.pUser = pTscObj->user,
|
||||
.schemalessType = pTscObj->schemalessType,
|
||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||
.enableSysInfo = pTscObj->sysInfo,
|
||||
.svrVer = pTscObj->sVer,
|
||||
|
@ -741,47 +740,21 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
|||
}
|
||||
|
||||
int32_t handleSubmitExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet* epset) {
|
||||
int32_t code = 0;
|
||||
SArray* pArray = NULL;
|
||||
SSubmitRsp* pRsp = (SSubmitRsp*)res;
|
||||
if (pRsp->nBlocks <= 0) {
|
||||
taosMemoryFreeClear(pRsp->pBlocks);
|
||||
SArray* pArray = NULL;
|
||||
SSubmitRsp2* pRsp = (SSubmitRsp2*)res;
|
||||
if (NULL == pRsp->aCreateTbRsp) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pArray = taosArrayInit(pRsp->nBlocks, sizeof(STbSVersion));
|
||||
if (NULL == pArray) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t tbNum = taosArrayGetSize(pRsp->aCreateTbRsp);
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
SVCreateTbRsp* pTbRsp = (SVCreateTbRsp*)taosArrayGet(pRsp->aCreateTbRsp, i);
|
||||
if (pTbRsp->pMeta) {
|
||||
handleCreateTbExecRes(pTbRsp->pMeta, pCatalog);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pRsp->nBlocks; ++i) {
|
||||
SSubmitBlkRsp* blk = pRsp->pBlocks + i;
|
||||
if (blk->pMeta) {
|
||||
handleCreateTbExecRes(blk->pMeta, pCatalog);
|
||||
tFreeSTableMetaRsp(blk->pMeta);
|
||||
taosMemoryFreeClear(blk->pMeta);
|
||||
}
|
||||
|
||||
if (NULL == blk->tblFName || 0 == blk->tblFName[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
STbSVersion tbSver = {.tbFName = blk->tblFName, .sver = blk->sver};
|
||||
taosArrayPush(pArray, &tbSver);
|
||||
}
|
||||
|
||||
SRequestConnInfo conn = {.pTrans = pRequest->pTscObj->pAppInfo->pTransporter,
|
||||
.requestId = pRequest->requestId,
|
||||
.requestObjRefId = pRequest->self,
|
||||
.mgmtEps = *epset};
|
||||
|
||||
code = catalogChkTbMetaVersion(pCatalog, &conn, pArray);
|
||||
|
||||
_return:
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
return code;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet* epset) {
|
||||
|
@ -1430,6 +1403,21 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
memcpy((void*)tEpSet, (void*)pEpSet, sizeof(SEpSet));
|
||||
}
|
||||
|
||||
// pMsg is response msg
|
||||
if (pMsg->msgType == TDMT_MND_CONNECT + 1) {
|
||||
// restore origin code
|
||||
if (pMsg->code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED) {
|
||||
pMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||
} else if (pMsg->code == TSDB_CODE_RPC_SOMENODE_BROKEN_LINK) {
|
||||
pMsg->code = TSDB_CODE_RPC_BROKEN_LINK;
|
||||
}
|
||||
} else {
|
||||
// uniform to one error code: TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED
|
||||
if (pMsg->code == TSDB_CODE_RPC_SOMENODE_BROKEN_LINK) {
|
||||
pMsg->code = TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncArg* arg = taosMemoryCalloc(1, sizeof(AsyncArg));
|
||||
arg->msg = *pMsg;
|
||||
arg->pEpset = tEpSet;
|
||||
|
|
|
@ -866,7 +866,6 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
|||
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||
.pStmtCb = NULL,
|
||||
.pUser = pTscObj->user,
|
||||
.schemalessType = pTscObj->schemalessType,
|
||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||
.enableSysInfo = pTscObj->sysInfo,
|
||||
.async = true,
|
||||
|
|
|
@ -1240,22 +1240,12 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
return code;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SVgroupInfo vg;
|
||||
void* data;
|
||||
} VgData;
|
||||
|
||||
static void destroyVgHash(void* data) {
|
||||
VgData* vgData = (VgData*)data;
|
||||
taosMemoryFreeClear(vgData->data);
|
||||
}
|
||||
|
||||
int taos_write_raw_block_with_fields(TAOS* taos, int rows, char* pData, const char* tbname, TAOS_FIELD* fields,
|
||||
int numFields) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
STableMeta* pTableMeta = NULL;
|
||||
SQuery* pQuery = NULL;
|
||||
SSubmitReq* subReq = NULL;
|
||||
SHashObj* pVgHash = NULL;
|
||||
|
||||
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
|
||||
if (!pRequest) {
|
||||
|
@ -1300,149 +1290,25 @@ int taos_write_raw_block_with_fields(TAOS* taos, int rows, char* pData, const ch
|
|||
uError("WriteRaw:catalogGetTableMeta failed. table name: %s", tbname);
|
||||
goto end;
|
||||
}
|
||||
uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
|
||||
uint64_t uid = pTableMeta->uid;
|
||||
int32_t numOfCols = pTableMeta->tableInfo.numOfColumns;
|
||||
|
||||
uint16_t fLen = 0;
|
||||
int32_t rowSize = 0;
|
||||
int16_t nVar = 0;
|
||||
for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
|
||||
SSchema* schema = pTableMeta->schema + i;
|
||||
fLen += TYPE_BYTES[schema->type];
|
||||
rowSize += schema->bytes;
|
||||
if (IS_VAR_DATA_TYPE(schema->type)) {
|
||||
nVar++;
|
||||
}
|
||||
}
|
||||
|
||||
fLen -= sizeof(TSKEY);
|
||||
|
||||
int32_t extendedRowSize = rowSize + TD_ROW_HEAD_LEN - sizeof(TSKEY) + nVar * sizeof(VarDataOffsetT) +
|
||||
(int32_t)TD_BITMAP_BYTES(numOfCols - 1);
|
||||
int32_t schemaLen = 0;
|
||||
int32_t submitLen = sizeof(SSubmitBlk) + schemaLen + rows * extendedRowSize;
|
||||
|
||||
int32_t totalLen = sizeof(SSubmitReq) + submitLen;
|
||||
subReq = taosMemoryCalloc(1, totalLen);
|
||||
SSubmitBlk* blk = POINTER_SHIFT(subReq, sizeof(SSubmitReq));
|
||||
void* blkSchema = POINTER_SHIFT(blk, sizeof(SSubmitBlk));
|
||||
STSRow* rowData = POINTER_SHIFT(blkSchema, schemaLen);
|
||||
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, pTableMeta->sversion);
|
||||
tdSRowSetTpInfo(&rb, numOfCols, fLen);
|
||||
int32_t dataLen = 0;
|
||||
|
||||
// | version | total length | total rows | total columns | flag seg| block group id | column schema | each column
|
||||
// length |
|
||||
char* pStart = pData + getVersion1BlockMetaSize(pData, numFields);
|
||||
int32_t* colLength = (int32_t*)pStart;
|
||||
pStart += sizeof(int32_t) * numFields;
|
||||
|
||||
SResultColumn* pCol = taosMemoryCalloc(numFields, sizeof(SResultColumn));
|
||||
|
||||
for (int32_t i = 0; i < numFields; ++i) {
|
||||
if (IS_VAR_DATA_TYPE(fields[i].type)) {
|
||||
pCol[i].offset = (int32_t*)pStart;
|
||||
pStart += rows * sizeof(int32_t);
|
||||
} else {
|
||||
pCol[i].nullbitmap = pStart;
|
||||
pStart += BitmapLen(rows);
|
||||
}
|
||||
|
||||
pCol[i].pData = pStart;
|
||||
pStart += colLength[i];
|
||||
}
|
||||
|
||||
SHashObj* schemaHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
for (int i = 0; i < numFields; i++) {
|
||||
TAOS_FIELD* schema = &fields[i];
|
||||
taosHashPut(schemaHash, schema->name, strlen(schema->name), &i, sizeof(int32_t));
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
tdSRowResetBuf(&rb, rowData);
|
||||
int32_t offset = 0;
|
||||
for (int32_t k = 0; k < numOfCols; k++) {
|
||||
const SSchema* pColumn = &pTableMeta->schema[k];
|
||||
int32_t* index = taosHashGet(schemaHash, pColumn->name, strlen(pColumn->name));
|
||||
if (!index) { // add none
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NONE, NULL, false, offset, k);
|
||||
} else {
|
||||
if (IS_VAR_DATA_TYPE(pColumn->type)) {
|
||||
if (pCol[*index].offset[j] != -1) {
|
||||
char* data = pCol[*index].pData + pCol[*index].offset[j];
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, offset, k);
|
||||
} else {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
|
||||
}
|
||||
} else {
|
||||
if (!colDataIsNull_f(pCol[*index].nullbitmap, j)) {
|
||||
char* data = pCol[*index].pData + pColumn->bytes * j;
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, offset, k);
|
||||
} else {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pColumn->colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
offset += TYPE_BYTES[pColumn->type];
|
||||
}
|
||||
}
|
||||
tdSRowEnd(&rb);
|
||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
||||
dataLen += rowLen;
|
||||
}
|
||||
|
||||
taosHashCleanup(schemaHash);
|
||||
taosMemoryFree(pCol);
|
||||
|
||||
blk->uid = htobe64(uid);
|
||||
blk->suid = htobe64(suid);
|
||||
blk->sversion = htonl(pTableMeta->sversion);
|
||||
blk->schemaLen = htonl(schemaLen);
|
||||
blk->numOfRows = htonl(rows);
|
||||
blk->dataLen = htonl(dataLen);
|
||||
subReq->length = sizeof(SSubmitReq) + sizeof(SSubmitBlk) + schemaLen + dataLen;
|
||||
subReq->numOfBlocks = 1;
|
||||
|
||||
pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == pQuery) {
|
||||
uError("create SQuery error");
|
||||
pQuery = smlInitHandle();
|
||||
if (pQuery == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->haveResultSet = false;
|
||||
pQuery->msgType = TDMT_VND_SUBMIT;
|
||||
pQuery->pRoot = (SNode*)nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT);
|
||||
if (NULL == pQuery->pRoot) {
|
||||
uError("create pQuery->pRoot error");
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
SVnodeModifyOpStmt* nodeStmt = (SVnodeModifyOpStmt*)(pQuery->pRoot);
|
||||
nodeStmt->pDataBlocks = taosArrayInit(1, POINTER_BYTES);
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
taosHashPut(pVgHash, (const char*)&vgData.vgId, sizeof(vgData.vgId), (char*)&vgData, sizeof(vgData));
|
||||
|
||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
||||
if (NULL == dst) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = rawBlockBindData(pQuery, pTableMeta, pData, NULL, fields, numFields);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw:rawBlockBindData failed");
|
||||
goto end;
|
||||
}
|
||||
dst->vg = vgData;
|
||||
dst->numOfTables = subReq->numOfBlocks;
|
||||
dst->size = subReq->length;
|
||||
dst->pData = (char*)subReq;
|
||||
subReq->header.vgId = htonl(dst->vg.vgId);
|
||||
subReq->version = htonl(1);
|
||||
subReq->header.contLen = htonl(subReq->length);
|
||||
subReq->length = htonl(subReq->length);
|
||||
subReq->numOfBlocks = htonl(subReq->numOfBlocks);
|
||||
subReq = NULL; // no need free
|
||||
taosArrayPush(nodeStmt->pDataBlocks, &dst);
|
||||
|
||||
code = smlBuildOutput(pQuery, pVgHash);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("smlBuildOutput failed");
|
||||
return code;
|
||||
}
|
||||
|
||||
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||
code = pRequest->code;
|
||||
|
@ -1450,7 +1316,8 @@ int taos_write_raw_block_with_fields(TAOS* taos, int rows, char* pData, const ch
|
|||
end:
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
qDestroyQuery(pQuery);
|
||||
taosMemoryFree(subReq);
|
||||
destroyRequest(pRequest);
|
||||
taosHashCleanup(pVgHash);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1458,7 +1325,7 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname)
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
STableMeta* pTableMeta = NULL;
|
||||
SQuery* pQuery = NULL;
|
||||
SSubmitReq* subReq = NULL;
|
||||
SHashObj* pVgHash = NULL;
|
||||
|
||||
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
|
||||
if (!pRequest) {
|
||||
|
@ -1503,138 +1370,25 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname)
|
|||
uError("WriteRaw:catalogGetTableMeta failed. table name: %s", tbname);
|
||||
goto end;
|
||||
}
|
||||
uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
|
||||
uint64_t uid = pTableMeta->uid;
|
||||
int32_t numOfCols = pTableMeta->tableInfo.numOfColumns;
|
||||
|
||||
uint16_t fLen = 0;
|
||||
int32_t rowSize = 0;
|
||||
int16_t nVar = 0;
|
||||
for (int i = 0; i < numOfCols; i++) {
|
||||
SSchema* schema = pTableMeta->schema + i;
|
||||
fLen += TYPE_BYTES[schema->type];
|
||||
rowSize += schema->bytes;
|
||||
if (IS_VAR_DATA_TYPE(schema->type)) {
|
||||
nVar++;
|
||||
}
|
||||
}
|
||||
fLen -= sizeof(TSKEY);
|
||||
|
||||
int32_t extendedRowSize = rowSize + TD_ROW_HEAD_LEN - sizeof(TSKEY) + nVar * sizeof(VarDataOffsetT) +
|
||||
(int32_t)TD_BITMAP_BYTES(numOfCols - 1);
|
||||
int32_t schemaLen = 0;
|
||||
int32_t submitLen = sizeof(SSubmitBlk) + schemaLen + rows * extendedRowSize;
|
||||
|
||||
int32_t totalLen = sizeof(SSubmitReq) + submitLen;
|
||||
subReq = taosMemoryCalloc(1, totalLen);
|
||||
SSubmitBlk* blk = POINTER_SHIFT(subReq, sizeof(SSubmitReq));
|
||||
void* blkSchema = POINTER_SHIFT(blk, sizeof(SSubmitBlk));
|
||||
STSRow* rowData = POINTER_SHIFT(blkSchema, schemaLen);
|
||||
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, pTableMeta->sversion);
|
||||
tdSRowSetTpInfo(&rb, numOfCols, fLen);
|
||||
int32_t dataLen = 0;
|
||||
|
||||
// | version | total length | total rows | total columns | flag seg| block group id | column schema | each column
|
||||
// length |
|
||||
char* pStart = pData + getVersion1BlockMetaSize(pData, numOfCols);
|
||||
int32_t* colLength = (int32_t*)pStart;
|
||||
pStart += sizeof(int32_t) * numOfCols;
|
||||
|
||||
SResultColumn* pCol = taosMemoryCalloc(numOfCols, sizeof(SResultColumn));
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
if (IS_VAR_DATA_TYPE(pTableMeta->schema[i].type)) {
|
||||
pCol[i].offset = (int32_t*)pStart;
|
||||
pStart += rows * sizeof(int32_t);
|
||||
} else {
|
||||
pCol[i].nullbitmap = pStart;
|
||||
pStart += BitmapLen(rows);
|
||||
}
|
||||
|
||||
pCol[i].pData = pStart;
|
||||
pStart += colLength[i];
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
tdSRowResetBuf(&rb, rowData);
|
||||
int32_t offset = 0;
|
||||
for (int32_t k = 0; k < numOfCols; k++) {
|
||||
const SSchema* pColumn = &pTableMeta->schema[k];
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pColumn->type)) {
|
||||
if (pCol[k].offset[j] != -1) {
|
||||
char* data = pCol[k].pData + pCol[k].offset[j];
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, offset, k);
|
||||
} else {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
|
||||
}
|
||||
} else {
|
||||
if (!colDataIsNull_f(pCol[k].nullbitmap, j)) {
|
||||
char* data = pCol[k].pData + pColumn->bytes * j;
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, offset, k);
|
||||
} else {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
|
||||
}
|
||||
}
|
||||
|
||||
if (pColumn->colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
offset += TYPE_BYTES[pColumn->type];
|
||||
}
|
||||
}
|
||||
tdSRowEnd(&rb);
|
||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
||||
dataLen += rowLen;
|
||||
}
|
||||
|
||||
taosMemoryFree(pCol);
|
||||
|
||||
blk->uid = htobe64(uid);
|
||||
blk->suid = htobe64(suid);
|
||||
blk->sversion = htonl(pTableMeta->sversion);
|
||||
blk->schemaLen = htonl(schemaLen);
|
||||
blk->numOfRows = htonl(rows);
|
||||
blk->dataLen = htonl(dataLen);
|
||||
subReq->length = sizeof(SSubmitReq) + sizeof(SSubmitBlk) + schemaLen + dataLen;
|
||||
subReq->numOfBlocks = 1;
|
||||
|
||||
pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == pQuery) {
|
||||
uError("create SQuery error");
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(subReq);
|
||||
goto end;
|
||||
}
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->haveResultSet = false;
|
||||
pQuery->msgType = TDMT_VND_SUBMIT;
|
||||
pQuery->pRoot = (SNode*)nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT);
|
||||
if (NULL == pQuery->pRoot) {
|
||||
uError("create pQuery->pRoot error");
|
||||
pQuery = smlInitHandle();
|
||||
if (pQuery == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
SVnodeModifyOpStmt* nodeStmt = (SVnodeModifyOpStmt*)(pQuery->pRoot);
|
||||
nodeStmt->pDataBlocks = taosArrayInit(1, POINTER_BYTES);
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
taosHashPut(pVgHash, (const char*)&vgData.vgId, sizeof(vgData.vgId), (char*)&vgData, sizeof(vgData));
|
||||
|
||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
||||
if (NULL == dst) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = rawBlockBindData(pQuery, pTableMeta, pData, NULL, NULL, 0);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw:rawBlockBindData failed");
|
||||
goto end;
|
||||
}
|
||||
dst->vg = vgData;
|
||||
dst->numOfTables = subReq->numOfBlocks;
|
||||
dst->size = subReq->length;
|
||||
dst->pData = (char*)subReq;
|
||||
subReq->header.vgId = htonl(dst->vg.vgId);
|
||||
subReq->version = htonl(1);
|
||||
subReq->header.contLen = htonl(subReq->length);
|
||||
subReq->length = htonl(subReq->length);
|
||||
subReq->numOfBlocks = htonl(subReq->numOfBlocks);
|
||||
subReq = NULL; // no need free
|
||||
taosArrayPush(nodeStmt->pDataBlocks, &dst);
|
||||
|
||||
code = smlBuildOutput(pQuery, pVgHash);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("smlBuildOutput failed");
|
||||
return code;
|
||||
}
|
||||
|
||||
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||
code = pRequest->code;
|
||||
|
@ -1642,7 +1396,8 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname)
|
|||
end:
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
qDestroyQuery(pQuery);
|
||||
taosMemoryFree(subReq);
|
||||
destroyRequest(pRequest);
|
||||
taosHashCleanup(pVgHash);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1679,8 +1434,6 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
goto end;
|
||||
}
|
||||
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
taosHashSetFreeFp(pVgHash, destroyVgHash);
|
||||
struct SCatalog* pCatalog = NULL;
|
||||
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -1694,6 +1447,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;
|
||||
goto end;
|
||||
}
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
uDebug("raw data block num:%d\n", rspObj.rsp.blockNum);
|
||||
while (++rspObj.resIter < rspObj.rsp.blockNum) {
|
||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(rspObj.rsp.blockData, rspObj.resIter);
|
||||
|
@ -1701,14 +1460,6 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
uError("WriteRaw:no schema, iter:%d", rspObj.resIter);
|
||||
goto end;
|
||||
}
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(rspObj.rsp.blockSchema, rspObj.resIter);
|
||||
setResSchemaInfo(&rspObj.resInfo, pSW->pSchema, pSW->nCols);
|
||||
|
||||
code = setQueryResultFromRsp(&rspObj.resInfo, pRetrieve, false, false);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw: setQueryResultFromRsp error");
|
||||
goto end;
|
||||
}
|
||||
|
||||
const char* tbName = (const char*)taosArrayGetP(rspObj.rsp.blockTbName, rspObj.resIter);
|
||||
if (!tbName) {
|
||||
|
@ -1722,13 +1473,6 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
strcpy(pName.dbname, pRequest->pDb);
|
||||
strcpy(pName.tname, tbName);
|
||||
|
||||
VgData vgData = {0};
|
||||
code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &(vgData.vg));
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw:catalogGetTableHashVgroup failed. table name: %s", tbName);
|
||||
goto end;
|
||||
}
|
||||
|
||||
code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
|
||||
if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
|
||||
uError("WriteRaw:catalogGetTableMeta table not exist. table name: %s", tbName);
|
||||
|
@ -1740,164 +1484,29 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
goto end;
|
||||
}
|
||||
|
||||
uint16_t fLen = 0;
|
||||
int32_t rowSize = 0;
|
||||
int16_t nVar = 0;
|
||||
for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
|
||||
SSchema* schema = &pTableMeta->schema[i];
|
||||
fLen += TYPE_BYTES[schema->type];
|
||||
rowSize += schema->bytes;
|
||||
if (IS_VAR_DATA_TYPE(schema->type)) {
|
||||
nVar++;
|
||||
}
|
||||
}
|
||||
fLen -= sizeof(TSKEY);
|
||||
|
||||
int32_t rows = rspObj.resInfo.numOfRows;
|
||||
int32_t extendedRowSize = rowSize + TD_ROW_HEAD_LEN - sizeof(TSKEY) + nVar * sizeof(VarDataOffsetT) +
|
||||
(int32_t)TD_BITMAP_BYTES(pTableMeta->tableInfo.numOfColumns - 1);
|
||||
int32_t schemaLen = 0;
|
||||
int32_t submitLen = sizeof(SSubmitBlk) + schemaLen + rows * extendedRowSize;
|
||||
|
||||
SSubmitReq* subReq = NULL;
|
||||
SSubmitBlk* blk = NULL;
|
||||
void* hData = taosHashGet(pVgHash, &vgData.vg.vgId, sizeof(vgData.vg.vgId));
|
||||
if (hData) {
|
||||
vgData = *(VgData*)hData;
|
||||
|
||||
int32_t totalLen = ((SSubmitReq*)(vgData.data))->length + submitLen;
|
||||
void* tmp = taosMemoryRealloc(vgData.data, totalLen);
|
||||
if (tmp == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
vgData.data = tmp;
|
||||
((VgData*)hData)->data = tmp;
|
||||
subReq = (SSubmitReq*)(vgData.data);
|
||||
blk = POINTER_SHIFT(vgData.data, subReq->length);
|
||||
} else {
|
||||
int32_t totalLen = sizeof(SSubmitReq) + submitLen;
|
||||
void* tmp = taosMemoryCalloc(1, totalLen);
|
||||
if (tmp == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
vgData.data = tmp;
|
||||
taosHashPut(pVgHash, (const char*)&vgData.vg.vgId, sizeof(vgData.vg.vgId), (char*)&vgData, sizeof(vgData));
|
||||
subReq = (SSubmitReq*)(vgData.data);
|
||||
subReq->length = sizeof(SSubmitReq);
|
||||
subReq->numOfBlocks = 0;
|
||||
|
||||
blk = POINTER_SHIFT(vgData.data, sizeof(SSubmitReq));
|
||||
}
|
||||
|
||||
// pSW->pSchema should be same as pTableMeta->schema
|
||||
// ASSERT(pSW->nCols == pTableMeta->tableInfo.numOfColumns);
|
||||
uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
|
||||
uint64_t uid = pTableMeta->uid;
|
||||
int16_t sver = pTableMeta->sversion;
|
||||
|
||||
void* blkSchema = POINTER_SHIFT(blk, sizeof(SSubmitBlk));
|
||||
STSRow* rowData = POINTER_SHIFT(blkSchema, schemaLen);
|
||||
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, sver);
|
||||
tdSRowSetTpInfo(&rb, pTableMeta->tableInfo.numOfColumns, fLen);
|
||||
int32_t totalLen = 0;
|
||||
|
||||
SHashObj* schemaHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
SSchema* schema = &pSW->pSchema[i];
|
||||
taosHashPut(schemaHash, schema->name, strlen(schema->name), &i, sizeof(int32_t));
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
tdSRowResetBuf(&rb, rowData);
|
||||
|
||||
doSetOneRowPtr(&rspObj.resInfo);
|
||||
rspObj.resInfo.current += 1;
|
||||
|
||||
int32_t offset = 0;
|
||||
for (int32_t k = 0; k < pTableMeta->tableInfo.numOfColumns; k++) {
|
||||
const SSchema* pColumn = &pTableMeta->schema[k];
|
||||
int32_t* index = taosHashGet(schemaHash, pColumn->name, strlen(pColumn->name));
|
||||
if (!index) {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NONE, NULL, false, offset, k);
|
||||
} else {
|
||||
char* colData = rspObj.resInfo.row[*index];
|
||||
if (!colData) {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
|
||||
} else {
|
||||
if (IS_VAR_DATA_TYPE(pColumn->type)) {
|
||||
colData -= VARSTR_HEADER_SIZE;
|
||||
}
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, colData, true, offset, k);
|
||||
}
|
||||
}
|
||||
if (pColumn->colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
offset += TYPE_BYTES[pColumn->type];
|
||||
}
|
||||
}
|
||||
tdSRowEnd(&rb);
|
||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
||||
totalLen += rowLen;
|
||||
}
|
||||
|
||||
taosHashCleanup(schemaHash);
|
||||
blk->uid = htobe64(uid);
|
||||
blk->suid = htobe64(suid);
|
||||
blk->sversion = htonl(sver);
|
||||
blk->schemaLen = htonl(schemaLen);
|
||||
blk->numOfRows = htonl(rows);
|
||||
blk->dataLen = htonl(totalLen);
|
||||
subReq->length += sizeof(SSubmitBlk) + schemaLen + totalLen;
|
||||
subReq->numOfBlocks++;
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
rspObj.resInfo.pRspMsg = NULL;
|
||||
doFreeReqResultInfo(&rspObj.resInfo);
|
||||
}
|
||||
|
||||
pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == pQuery) {
|
||||
uError("create SQuery error");
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->haveResultSet = false;
|
||||
pQuery->msgType = TDMT_VND_SUBMIT;
|
||||
pQuery->pRoot = (SNode*)nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT);
|
||||
if (NULL == pQuery->pRoot) {
|
||||
uError("create pQuery->pRoot error");
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
SVnodeModifyOpStmt* nodeStmt = (SVnodeModifyOpStmt*)(pQuery->pRoot);
|
||||
|
||||
int32_t numOfVg = taosHashGetSize(pVgHash);
|
||||
nodeStmt->pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES);
|
||||
|
||||
VgData* vData = (VgData*)taosHashIterate(pVgHash, NULL);
|
||||
while (vData) {
|
||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
||||
if (NULL == dst) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SVgroupInfo vg;
|
||||
code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &vg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw:catalogGetTableHashVgroup failed. table name: %s", tbName);
|
||||
goto end;
|
||||
}
|
||||
dst->vg = vData->vg;
|
||||
SSubmitReq* subReq = (SSubmitReq*)(vData->data);
|
||||
dst->numOfTables = subReq->numOfBlocks;
|
||||
dst->size = subReq->length;
|
||||
dst->pData = (char*)subReq;
|
||||
vData->data = NULL; // no need free
|
||||
subReq->header.vgId = htonl(dst->vg.vgId);
|
||||
subReq->version = htonl(1);
|
||||
subReq->header.contLen = htonl(subReq->length);
|
||||
subReq->length = htonl(subReq->length);
|
||||
subReq->numOfBlocks = htonl(subReq->numOfBlocks);
|
||||
taosArrayPush(nodeStmt->pDataBlocks, &dst);
|
||||
vData = (VgData*)taosHashIterate(pVgHash, vData);
|
||||
|
||||
void* hData = taosHashGet(pVgHash, &vg.vgId, sizeof(vg.vgId));
|
||||
if (hData == NULL) {
|
||||
taosHashPut(pVgHash, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg));
|
||||
}
|
||||
|
||||
code = rawBlockBindData(pQuery, pTableMeta, pRetrieve->data, NULL, NULL, 0);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw:rawBlockBindData failed");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
code = smlBuildOutput(pQuery, pVgHash);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("smlBuildOutput failed");
|
||||
return code;
|
||||
}
|
||||
|
||||
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||
|
@ -1905,8 +1514,6 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
|
||||
end:
|
||||
tDeleteSMqDataRsp(&rspObj.rsp);
|
||||
rspObj.resInfo.pRspMsg = NULL;
|
||||
doFreeReqResultInfo(&rspObj.resInfo);
|
||||
tDecoderClear(&decoder);
|
||||
qDestroyQuery(pQuery);
|
||||
destroyRequest(pRequest);
|
||||
|
@ -1948,8 +1555,6 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
goto end;
|
||||
}
|
||||
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
taosHashSetFreeFp(pVgHash, destroyVgHash);
|
||||
struct SCatalog* pCatalog = NULL;
|
||||
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -1963,6 +1568,13 @@ 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 = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
|
||||
uDebug("raw data block num:%d\n", rspObj.rsp.blockNum);
|
||||
while (++rspObj.resIter < rspObj.rsp.blockNum) {
|
||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(rspObj.rsp.blockData, rspObj.resIter);
|
||||
|
@ -1970,14 +1582,6 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
uError("WriteRaw:no schema, iter:%d", rspObj.resIter);
|
||||
goto end;
|
||||
}
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(rspObj.rsp.blockSchema, rspObj.resIter);
|
||||
setResSchemaInfo(&rspObj.resInfo, pSW->pSchema, pSW->nCols);
|
||||
|
||||
code = setQueryResultFromRsp(&rspObj.resInfo, pRetrieve, false, false);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw: setQueryResultFromRsp error");
|
||||
goto end;
|
||||
}
|
||||
|
||||
const char* tbName = (const char*)taosArrayGetP(rspObj.rsp.blockTbName, rspObj.resIter);
|
||||
if (!tbName) {
|
||||
|
@ -1991,44 +1595,28 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
strcpy(pName.dbname, pRequest->pDb);
|
||||
strcpy(pName.tname, tbName);
|
||||
|
||||
VgData vgData = {0};
|
||||
code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &(vgData.vg));
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw:catalogGetTableHashVgroup failed. table name: %s", tbName);
|
||||
goto end;
|
||||
}
|
||||
|
||||
// find schema data info
|
||||
int32_t schemaLen = 0;
|
||||
void* schemaData = NULL;
|
||||
SVCreateTbReq pCreateReq = {0};
|
||||
|
||||
for (int j = 0; j < rspObj.rsp.createTableNum; j++) {
|
||||
void** dataTmp = taosArrayGet(rspObj.rsp.createTableReq, j);
|
||||
int32_t* lenTmp = taosArrayGet(rspObj.rsp.createTableLen, j);
|
||||
|
||||
SDecoder decoderTmp = {0};
|
||||
SVCreateTbReq pCreateReq = {0};
|
||||
|
||||
SDecoder decoderTmp = {0};
|
||||
tDecoderInit(&decoderTmp, *dataTmp, *lenTmp);
|
||||
memset(&pCreateReq, 0, sizeof(SVCreateTbReq));
|
||||
if (tDecodeSVCreateTbReq(&decoderTmp, &pCreateReq) < 0) {
|
||||
tDecoderClear(&decoderTmp);
|
||||
taosMemoryFreeClear(pCreateReq.comment);
|
||||
taosArrayDestroy(pCreateReq.ctb.tagName);
|
||||
goto end;
|
||||
}
|
||||
|
||||
ASSERT(pCreateReq.type == TSDB_CHILD_TABLE);
|
||||
if (strcmp(tbName, pCreateReq.name) == 0) {
|
||||
schemaLen = *lenTmp;
|
||||
schemaData = *dataTmp;
|
||||
strcpy(pName.tname, pCreateReq.ctb.stbName);
|
||||
tDecoderClear(&decoderTmp);
|
||||
taosMemoryFreeClear(pCreateReq.comment);
|
||||
taosArrayDestroy(pCreateReq.ctb.tagName);
|
||||
break;
|
||||
}
|
||||
tDecoderClear(&decoderTmp);
|
||||
taosMemoryFreeClear(pCreateReq.comment);
|
||||
taosArrayDestroy(pCreateReq.ctb.tagName);
|
||||
}
|
||||
|
||||
code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
|
||||
|
@ -2042,167 +1630,23 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
goto end;
|
||||
}
|
||||
|
||||
uint16_t fLen = 0;
|
||||
int32_t rowSize = 0;
|
||||
int16_t nVar = 0;
|
||||
for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
|
||||
SSchema* schema = &pTableMeta->schema[i];
|
||||
fLen += TYPE_BYTES[schema->type];
|
||||
rowSize += schema->bytes;
|
||||
if (IS_VAR_DATA_TYPE(schema->type)) {
|
||||
nVar++;
|
||||
}
|
||||
}
|
||||
fLen -= sizeof(TSKEY);
|
||||
|
||||
int32_t rows = rspObj.resInfo.numOfRows;
|
||||
int32_t extendedRowSize = rowSize + TD_ROW_HEAD_LEN - sizeof(TSKEY) + nVar * sizeof(VarDataOffsetT) +
|
||||
(int32_t)TD_BITMAP_BYTES(pTableMeta->tableInfo.numOfColumns - 1);
|
||||
|
||||
int32_t submitLen = sizeof(SSubmitBlk) + schemaLen + rows * extendedRowSize;
|
||||
|
||||
SSubmitReq* subReq = NULL;
|
||||
SSubmitBlk* blk = NULL;
|
||||
void* hData = taosHashGet(pVgHash, &vgData.vg.vgId, sizeof(vgData.vg.vgId));
|
||||
if (hData) {
|
||||
vgData = *(VgData*)hData;
|
||||
|
||||
int32_t totalLen = ((SSubmitReq*)(vgData.data))->length + submitLen;
|
||||
void* tmp = taosMemoryRealloc(vgData.data, totalLen);
|
||||
if (tmp == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
vgData.data = tmp;
|
||||
((VgData*)hData)->data = tmp;
|
||||
subReq = (SSubmitReq*)(vgData.data);
|
||||
blk = POINTER_SHIFT(vgData.data, subReq->length);
|
||||
} else {
|
||||
int32_t totalLen = sizeof(SSubmitReq) + submitLen;
|
||||
void* tmp = taosMemoryCalloc(1, totalLen);
|
||||
if (tmp == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
vgData.data = tmp;
|
||||
taosHashPut(pVgHash, (const char*)&vgData.vg.vgId, sizeof(vgData.vg.vgId), (char*)&vgData, sizeof(vgData));
|
||||
subReq = (SSubmitReq*)(vgData.data);
|
||||
subReq->length = sizeof(SSubmitReq);
|
||||
subReq->numOfBlocks = 0;
|
||||
|
||||
blk = POINTER_SHIFT(vgData.data, sizeof(SSubmitReq));
|
||||
}
|
||||
|
||||
// pSW->pSchema should be same as pTableMeta->schema
|
||||
// ASSERT(pSW->nCols == pTableMeta->tableInfo.numOfColumns);
|
||||
uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
|
||||
uint64_t uid = pTableMeta->uid;
|
||||
int16_t sver = pTableMeta->sversion;
|
||||
|
||||
void* blkSchema = POINTER_SHIFT(blk, sizeof(SSubmitBlk));
|
||||
if (schemaData) {
|
||||
memcpy(blkSchema, schemaData, schemaLen);
|
||||
}
|
||||
STSRow* rowData = POINTER_SHIFT(blkSchema, schemaLen);
|
||||
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, sver);
|
||||
tdSRowSetTpInfo(&rb, pTableMeta->tableInfo.numOfColumns, fLen);
|
||||
int32_t totalLen = 0;
|
||||
|
||||
SHashObj* schemaHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
SSchema* schema = &pSW->pSchema[i];
|
||||
taosHashPut(schemaHash, schema->name, strlen(schema->name), &i, sizeof(int32_t));
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
tdSRowResetBuf(&rb, rowData);
|
||||
|
||||
doSetOneRowPtr(&rspObj.resInfo);
|
||||
rspObj.resInfo.current += 1;
|
||||
|
||||
int32_t offset = 0;
|
||||
for (int32_t k = 0; k < pTableMeta->tableInfo.numOfColumns; k++) {
|
||||
const SSchema* pColumn = &pTableMeta->schema[k];
|
||||
int32_t* index = taosHashGet(schemaHash, pColumn->name, strlen(pColumn->name));
|
||||
if (!index) {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NONE, NULL, false, offset, k);
|
||||
} else {
|
||||
char* colData = rspObj.resInfo.row[*index];
|
||||
if (!colData) {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
|
||||
} else {
|
||||
if (IS_VAR_DATA_TYPE(pColumn->type)) {
|
||||
colData -= VARSTR_HEADER_SIZE;
|
||||
}
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, colData, true, offset, k);
|
||||
}
|
||||
}
|
||||
if (pColumn->colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
offset += TYPE_BYTES[pColumn->type];
|
||||
}
|
||||
}
|
||||
tdSRowEnd(&rb);
|
||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
||||
totalLen += rowLen;
|
||||
}
|
||||
|
||||
taosHashCleanup(schemaHash);
|
||||
blk->uid = htobe64(uid);
|
||||
blk->suid = htobe64(suid);
|
||||
blk->sversion = htonl(sver);
|
||||
blk->schemaLen = htonl(schemaLen);
|
||||
blk->numOfRows = htonl(rows);
|
||||
blk->dataLen = htonl(totalLen);
|
||||
subReq->length += sizeof(SSubmitBlk) + schemaLen + totalLen;
|
||||
subReq->numOfBlocks++;
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
rspObj.resInfo.pRspMsg = NULL;
|
||||
doFreeReqResultInfo(&rspObj.resInfo);
|
||||
}
|
||||
|
||||
pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == pQuery) {
|
||||
uError("create SQuery error");
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->haveResultSet = false;
|
||||
pQuery->msgType = TDMT_VND_SUBMIT;
|
||||
pQuery->pRoot = (SNode*)nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT);
|
||||
if (NULL == pQuery->pRoot) {
|
||||
uError("create pQuery->pRoot error");
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
SVnodeModifyOpStmt* nodeStmt = (SVnodeModifyOpStmt*)(pQuery->pRoot);
|
||||
|
||||
int32_t numOfVg = taosHashGetSize(pVgHash);
|
||||
nodeStmt->pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES);
|
||||
|
||||
VgData* vData = (VgData*)taosHashIterate(pVgHash, NULL);
|
||||
while (vData) {
|
||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
||||
if (NULL == dst) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SVgroupInfo vg;
|
||||
code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &vg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw:catalogGetTableHashVgroup failed. table name: %s", tbName);
|
||||
goto end;
|
||||
}
|
||||
|
||||
void* hData = taosHashGet(pVgHash, &vg.vgId, sizeof(vg.vgId));
|
||||
if (hData == NULL) {
|
||||
taosHashPut(pVgHash, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg));
|
||||
}
|
||||
|
||||
code = rawBlockBindData(pQuery, pTableMeta, pRetrieve->data, &pCreateReq, NULL, 0);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("WriteRaw:rawBlockBindData failed");
|
||||
goto end;
|
||||
}
|
||||
dst->vg = vData->vg;
|
||||
SSubmitReq* subReq = (SSubmitReq*)(vData->data);
|
||||
dst->numOfTables = subReq->numOfBlocks;
|
||||
dst->size = subReq->length;
|
||||
dst->pData = (char*)subReq;
|
||||
vData->data = NULL; // no need free
|
||||
subReq->header.vgId = htonl(dst->vg.vgId);
|
||||
subReq->version = htonl(1);
|
||||
subReq->header.contLen = htonl(subReq->length);
|
||||
subReq->length = htonl(subReq->length);
|
||||
subReq->numOfBlocks = htonl(subReq->numOfBlocks);
|
||||
taosArrayPush(nodeStmt->pDataBlocks, &dst);
|
||||
vData = (VgData*)taosHashIterate(pVgHash, vData);
|
||||
}
|
||||
|
||||
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||
|
@ -2210,8 +1654,6 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
|
||||
end:
|
||||
tDeleteSTaosxRsp(&rspObj.rsp);
|
||||
rspObj.resInfo.pRspMsg = NULL;
|
||||
doFreeReqResultInfo(&rspObj.resInfo);
|
||||
tDecoderClear(&decoder);
|
||||
qDestroyQuery(pQuery);
|
||||
destroyRequest(pRequest);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,501 @@
|
|||
/*
|
||||
* 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 <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "clientSml.h"
|
||||
|
||||
#define JUMP_JSON_SPACE(start) \
|
||||
while(*(start)){\
|
||||
if(unlikely(*(start) > 32))\
|
||||
break;\
|
||||
else\
|
||||
(start)++;\
|
||||
}
|
||||
|
||||
SArray *smlJsonParseTags(char *start, char *end){
|
||||
SArray *tags = taosArrayInit(4, sizeof(SSmlKv));
|
||||
while(start < end){
|
||||
SSmlKv kv = {0};
|
||||
kv.type = TSDB_DATA_TYPE_NCHAR;
|
||||
bool isInQuote = false;
|
||||
while(start < end){
|
||||
if(unlikely(!isInQuote && *start == '"')){
|
||||
start++;
|
||||
kv.key = start;
|
||||
isInQuote = true;
|
||||
continue;
|
||||
}
|
||||
if(unlikely(isInQuote && *start == '"')){
|
||||
kv.keyLen = start - kv.key;
|
||||
start++;
|
||||
break;
|
||||
}
|
||||
start++;
|
||||
}
|
||||
bool hasColon = false;
|
||||
while(start < end){
|
||||
if(unlikely(!hasColon && *start == ':')){
|
||||
start++;
|
||||
hasColon = true;
|
||||
continue;
|
||||
}
|
||||
if(unlikely(hasColon && kv.value == NULL && (*start > 32 && *start != '"'))){
|
||||
kv.value = start;
|
||||
start++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(unlikely(hasColon && kv.value != NULL && (*start == '"' || *start == ',' || *start == '}'))){
|
||||
kv.length = start - kv.value;
|
||||
taosArrayPush(tags, &kv);
|
||||
start++;
|
||||
break;
|
||||
}
|
||||
start++;
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
static int32_t smlParseTagsFromJSON(SSmlHandle *info, SSmlLineInfo *elements) {
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
|
||||
if(is_same_child_table_telnet(elements, &info->preLine) == 0){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool isSameMeasure = IS_SAME_SUPER_TABLE;
|
||||
|
||||
int cnt = 0;
|
||||
SArray *preLineKV = info->preLineTagKV;
|
||||
bool isSuperKVInit = true;
|
||||
SArray *superKV = NULL;
|
||||
if(info->dataFormat){
|
||||
if(unlikely(!isSameMeasure)){
|
||||
SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL);
|
||||
|
||||
if(unlikely(sMeta == NULL)){
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
STableMeta * pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
if(pTableMeta == NULL){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
nodeListSet(&info->superTables, elements->measure, elements->measureLen, sMeta, NULL);
|
||||
}
|
||||
info->currSTableMeta = sMeta->tableMeta;
|
||||
superKV = sMeta->tags;
|
||||
|
||||
if(unlikely(taosArrayGetSize(superKV) == 0)){
|
||||
isSuperKVInit = false;
|
||||
}
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
}
|
||||
}else{
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
}
|
||||
|
||||
SArray *tags = smlJsonParseTags(elements->tags, elements->tags + elements->tagsLen);
|
||||
int32_t tagNum = taosArrayGetSize(tags);
|
||||
for (int32_t i = 0; i < tagNum; ++i) {
|
||||
SSmlKv kv = *(SSmlKv*)taosArrayGet(tags, i);
|
||||
|
||||
if(info->dataFormat){
|
||||
if(unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
taosArrayDestroy(tags);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(isSameMeasure){
|
||||
if(unlikely(cnt >= taosArrayGetSize(preLineKV))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
taosArrayDestroy(tags);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)){
|
||||
preKV->length = kv.length;
|
||||
SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL);
|
||||
ASSERT(tableMeta != NULL);
|
||||
|
||||
SSmlKv *oldKV = (SSmlKv *)taosArrayGet(tableMeta->tags, cnt);
|
||||
oldKV->length = kv.length;
|
||||
info->needModifySchema = true;
|
||||
}
|
||||
if(unlikely(!IS_SAME_KEY)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
taosArrayDestroy(tags);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
if(isSuperKVInit){
|
||||
if(unlikely(cnt >= taosArrayGetSize(superKV))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
taosArrayDestroy(tags);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)) {
|
||||
preKV->length = kv.length;
|
||||
}else{
|
||||
kv.length = preKV->length;
|
||||
}
|
||||
info->needModifySchema = true;
|
||||
|
||||
if(unlikely(!IS_SAME_KEY)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
taosArrayDestroy(tags);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(superKV, &kv);
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
taosArrayDestroy(tags);
|
||||
|
||||
SSmlTableInfo *tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements, POINTER_BYTES, is_same_child_table_telnet);
|
||||
if (unlikely(tinfo == NULL)) {
|
||||
tinfo = smlBuildTableInfo(1, elements->measure, elements->measureLen);
|
||||
if (unlikely(!tinfo)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tinfo->tags = taosArrayDup(preLineKV, NULL);
|
||||
|
||||
smlSetCTableName(tinfo);
|
||||
if (info->dataFormat) {
|
||||
info->currSTableMeta->uid = tinfo->uid;
|
||||
tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
|
||||
if (tinfo->tableDataCtx == NULL) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "smlInitTableDataCtx error", NULL);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
SSmlLineInfo *key = (SSmlLineInfo *)taosMemoryMalloc(sizeof(SSmlLineInfo));
|
||||
*key = *elements;
|
||||
tinfo->key = key;
|
||||
nodeListSet(&info->childTables, key, POINTER_BYTES, tinfo, is_same_child_table_telnet);
|
||||
}
|
||||
if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char* smlJsonGetObj(char *payload){
|
||||
int leftBracketCnt = 0;
|
||||
while(*payload) {
|
||||
if (unlikely(*payload == '{')) {
|
||||
leftBracketCnt++;
|
||||
payload++;
|
||||
continue;
|
||||
}
|
||||
if (unlikely(*payload == '}')) {
|
||||
leftBracketCnt--;
|
||||
payload++;
|
||||
if (leftBracketCnt == 0) {
|
||||
return payload;
|
||||
} else if (leftBracketCnt < 0) {
|
||||
return NULL;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
payload++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset){
|
||||
int index = 0;
|
||||
while(*(*start)){
|
||||
if((*start)[0] != '"'){
|
||||
(*start)++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(unlikely(index >= 4)) {
|
||||
uError("index >= 4, %s", *start)
|
||||
break;
|
||||
}
|
||||
char *sTmp = *start;
|
||||
if((*start)[1] == 'm' && (*start)[2] == 'e' && (*start)[3] == 't'
|
||||
&& (*start)[4] == 'r' && (*start)[5] == 'i' && (*start)[6] == 'c' && (*start)[7] == '"'){
|
||||
|
||||
(*start) += 8;
|
||||
bool isInQuote = false;
|
||||
while(*(*start)){
|
||||
if(unlikely(!isInQuote && *(*start) == '"')){
|
||||
(*start)++;
|
||||
offset[index++] = *start - sTmp;
|
||||
element->measure = (*start);
|
||||
isInQuote = true;
|
||||
continue;
|
||||
}
|
||||
if(unlikely(isInQuote && *(*start) == '"')){
|
||||
element->measureLen = (*start) - element->measure;
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}else if((*start)[1] == 't' && (*start)[2] == 'i' && (*start)[3] == 'm'
|
||||
&& (*start)[4] == 'e' && (*start)[5] == 's' && (*start)[6] == 't'
|
||||
&& (*start)[7] == 'a' && (*start)[8] == 'm' && (*start)[9] == 'p' && (*start)[10] == '"'){
|
||||
|
||||
(*start) += 11;
|
||||
bool hasColon = false;
|
||||
while(*(*start)){
|
||||
if(unlikely(!hasColon && *(*start) == ':')){
|
||||
(*start)++;
|
||||
JUMP_JSON_SPACE((*start))
|
||||
offset[index++] = *start - sTmp;
|
||||
element->timestamp = (*start);
|
||||
hasColon = true;
|
||||
continue;
|
||||
}
|
||||
if(unlikely(hasColon && (*(*start) == ',' || *(*start) == '}' || (*(*start)) <= 32))){
|
||||
element->timestampLen = (*start) - element->timestamp;
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}else if((*start)[1] == 'v' && (*start)[2] == 'a' && (*start)[3] == 'l'
|
||||
&& (*start)[4] == 'u' && (*start)[5] == 'e' && (*start)[6] == '"'){
|
||||
|
||||
(*start) += 7;
|
||||
|
||||
bool hasColon = false;
|
||||
while(*(*start)){
|
||||
if(unlikely(!hasColon && *(*start) == ':')){
|
||||
(*start)++;
|
||||
JUMP_JSON_SPACE((*start))
|
||||
offset[index++] = *start - sTmp;
|
||||
element->cols = (*start);
|
||||
hasColon = true;
|
||||
continue;
|
||||
}
|
||||
if(unlikely(hasColon && (*(*start) == ',' || *(*start) == '}' || (*(*start)) <= 32))){
|
||||
element->colsLen = (*start) - element->cols;
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}else if((*start)[1] == 't' && (*start)[2] == 'a' && (*start)[3] == 'g'
|
||||
&& (*start)[4] == 's' && (*start)[5] == '"'){
|
||||
(*start) += 6;
|
||||
|
||||
while(*(*start)){
|
||||
if(unlikely(*(*start) == ':')){
|
||||
(*start)++;
|
||||
JUMP_JSON_SPACE((*start))
|
||||
offset[index++] = *start - sTmp;
|
||||
element->tags = (*start);
|
||||
char* tmp = smlJsonGetObj((*start));
|
||||
if(tmp){
|
||||
element->tagsLen = tmp - (*start);
|
||||
*start = tmp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}
|
||||
if(*(*start) == '}'){
|
||||
(*start)++;
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}
|
||||
|
||||
void smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset){
|
||||
int index = 0;
|
||||
while(*(*start)){
|
||||
if((*start)[0] != '"'){
|
||||
(*start)++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(unlikely(index >= 4)) {
|
||||
uError("index >= 4, %s", *start)
|
||||
break;
|
||||
}
|
||||
if((*start)[1] == 'm'){
|
||||
(*start) += offset[index++];
|
||||
element->measure = *start;
|
||||
while(*(*start)){
|
||||
if(unlikely(*(*start) == '"')){
|
||||
element->measureLen = (*start) - element->measure;
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}else if((*start)[1] == 't' && (*start)[2] == 'i'){
|
||||
(*start) += offset[index++];
|
||||
element->timestamp = *start;
|
||||
while(*(*start)){
|
||||
if(unlikely(*(*start) == ',' || *(*start) == '}' || (*(*start)) <= 32)){
|
||||
element->timestampLen = (*start) - element->timestamp;
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}else if((*start)[1] == 'v'){
|
||||
(*start) += offset[index++];
|
||||
element->cols = *start;
|
||||
while(*(*start)){
|
||||
if(unlikely( *(*start) == ',' || *(*start) == '}' || (*(*start)) <= 32)){
|
||||
element->colsLen = (*start) - element->cols;
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}else if((*start)[1] == 't' && (*start)[2] == 'a'){
|
||||
(*start) += offset[index++];
|
||||
element->tags = (*start);
|
||||
char* tmp = smlJsonGetObj((*start));
|
||||
if(tmp){
|
||||
element->tagsLen = tmp - (*start);
|
||||
*start = tmp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(*(*start) == '}'){
|
||||
(*start)++;
|
||||
break;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t smlParseJSONString(SSmlHandle *info, char **start, SSmlLineInfo *elements) {
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
|
||||
if(info->offset[0] == 0){
|
||||
smlJsonParseObjFirst(start, elements, info->offset);
|
||||
}else{
|
||||
smlJsonParseObj(start, elements, info->offset);
|
||||
}
|
||||
if(**start == '\0') return TSDB_CODE_SUCCESS;
|
||||
|
||||
SSmlKv kv = {.key = VALUE, .keyLen = VALUE_LEN, .value = elements->cols, .length = (size_t)elements->colsLen};
|
||||
if (smlParseNumber(&kv, &info->msgBuf)) {
|
||||
kv.length = (int16_t)tDataTypes[kv.type].bytes;
|
||||
}else{
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
// Parse tags
|
||||
ret = smlParseTagsFromJSON(info, elements);
|
||||
if (unlikely(ret)) {
|
||||
uError("OTD:0x%" PRIx64 " Unable to parse tags from JSON payload", info->id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(unlikely(info->reRun)){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// Parse timestamp
|
||||
// notice!!! put ts back to tag to ensure get meta->precision
|
||||
int64_t ts = smlParseOpenTsdbTime(info, elements->timestamp, elements->timestampLen);
|
||||
if (unlikely(ts < 0)) {
|
||||
uError("OTD:0x%" PRIx64 " Unable to parse timestamp from JSON payload", info->id);
|
||||
return TSDB_CODE_INVALID_TIMESTAMP;
|
||||
}
|
||||
SSmlKv kvTs = { .key = TS, .keyLen = TS_LEN, .type = TSDB_DATA_TYPE_TIMESTAMP, .i = ts, .length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes};
|
||||
|
||||
if(info->dataFormat){
|
||||
ret = smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, &kvTs, 0);
|
||||
if(ret == TSDB_CODE_SUCCESS){
|
||||
ret = smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, &kv, 1);
|
||||
}
|
||||
if(ret == TSDB_CODE_SUCCESS){
|
||||
ret = smlBuildRow(info->currTableDataCtx);
|
||||
}
|
||||
if (unlikely(ret != TSDB_CODE_SUCCESS)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "smlBuildCol error", NULL);
|
||||
return ret;
|
||||
}
|
||||
}else{
|
||||
if(elements->colArray == NULL){
|
||||
elements->colArray = taosArrayInit(16, sizeof(SSmlKv));
|
||||
}
|
||||
taosArrayPush(elements->colArray, &kvTs);
|
||||
taosArrayPush(elements->colArray, &kv);
|
||||
}
|
||||
info->preLine = *elements;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t smlParseJSON(SSmlHandle *info, char *payload) {
|
||||
int32_t payloadNum = 1 << 15;
|
||||
int32_t ret = TSDB_CODE_SUCCESS;
|
||||
|
||||
int cnt = 0;
|
||||
char *dataPointStart = payload;
|
||||
while (1) {
|
||||
if(info->dataFormat) {
|
||||
SSmlLineInfo element = {0};
|
||||
ret = smlParseJSONString(info, &dataPointStart, &element);
|
||||
}else{
|
||||
if(cnt >= payloadNum){
|
||||
payloadNum = payloadNum << 1;
|
||||
void* tmp = taosMemoryRealloc(info->lines, payloadNum * sizeof(SSmlLineInfo));
|
||||
if(tmp != NULL){
|
||||
info->lines = (SSmlLineInfo*)tmp;
|
||||
}
|
||||
}
|
||||
ret = smlParseJSONString(info, &dataPointStart, info->lines + cnt);
|
||||
}
|
||||
if (unlikely(ret != TSDB_CODE_SUCCESS)) {
|
||||
uError("SML:0x%" PRIx64 " Invalid JSON Payload", info->id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(*dataPointStart == '\0') break;
|
||||
|
||||
if(unlikely(info->reRun)){
|
||||
cnt = 0;
|
||||
dataPointStart = payload;
|
||||
info->lineNum = payloadNum;
|
||||
ret = smlClearForRerun(info);
|
||||
if(ret != TSDB_CODE_SUCCESS){
|
||||
return ret;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
info->lineNum = cnt;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,700 @@
|
|||
/*
|
||||
* 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 <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "clientSml.h"
|
||||
|
||||
// comma ,
|
||||
//#define IS_SLASH_COMMA(sql) (*(sql) == COMMA && *((sql)-1) == SLASH)
|
||||
#define IS_COMMA(sql) (*(sql) == COMMA && *((sql)-1) != SLASH)
|
||||
// space
|
||||
//#define IS_SLASH_SPACE(sql) (*(sql) == SPACE && *((sql)-1) == SLASH)
|
||||
#define IS_SPACE(sql) (*(sql) == SPACE && *((sql)-1) != SLASH)
|
||||
// equal =
|
||||
//#define IS_SLASH_EQUAL(sql) (*(sql) == EQUAL && *((sql)-1) == SLASH)
|
||||
#define IS_EQUAL(sql) (*(sql) == EQUAL && *((sql)-1) != SLASH)
|
||||
// quote "
|
||||
//#define IS_SLASH_QUOTE(sql) (*(sql) == QUOTE && *((sql)-1) == SLASH)
|
||||
#define IS_QUOTE(sql) (*(sql) == QUOTE && *((sql)-1) != SLASH)
|
||||
// SLASH
|
||||
//#define IS_SLASH_SLASH(sql) (*(sql) == SLASH && *((sql)-1) == SLASH)
|
||||
|
||||
#define IS_SLASH_LETTER(sql) \
|
||||
(*((sql)-1) == SLASH && (*(sql) == COMMA || *(sql) == SPACE || *(sql) == EQUAL || *(sql) == QUOTE || *(sql) == SLASH)) \
|
||||
// (IS_SLASH_COMMA(sql) || IS_SLASH_SPACE(sql) || IS_SLASH_EQUAL(sql) || IS_SLASH_QUOTE(sql) || IS_SLASH_SLASH(sql))
|
||||
|
||||
#define MOVE_FORWARD_ONE(sql, len) (memmove((void *)((sql)-1), (sql), len))
|
||||
|
||||
#define PROCESS_SLASH(key, keyLen) \
|
||||
for (int i = 1; i < keyLen; ++i) { \
|
||||
if (IS_SLASH_LETTER(key + i)) { \
|
||||
MOVE_FORWARD_ONE(key + i, keyLen - i); \
|
||||
i--; \
|
||||
keyLen--; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
|
||||
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
|
||||
|
||||
uint8_t smlPrecisionConvert[7] = {TSDB_TIME_PRECISION_NANO, TSDB_TIME_PRECISION_HOURS, TSDB_TIME_PRECISION_MINUTES,
|
||||
TSDB_TIME_PRECISION_SECONDS, TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO,
|
||||
TSDB_TIME_PRECISION_NANO};
|
||||
|
||||
static bool smlParseBool(SSmlKv *kvVal) {
|
||||
const char *pVal = kvVal->value;
|
||||
int32_t len = kvVal->length;
|
||||
if ((len == 1) && (pVal[0] == 't' || pVal[0] == 'T')) {
|
||||
kvVal->i = TSDB_TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((len == 1) && (pVal[0] == 'f' || pVal[0] == 'F')) {
|
||||
kvVal->i = TSDB_FALSE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((len == 4) && !strncasecmp(pVal, "true", len)) {
|
||||
kvVal->i = TSDB_TRUE;
|
||||
return true;
|
||||
}
|
||||
if ((len == 5) && !strncasecmp(pVal, "false", len)) {
|
||||
kvVal->i = TSDB_FALSE;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool smlIsBinary(const char *pVal, uint16_t len) {
|
||||
// binary: "abc"
|
||||
if (len < 2) {
|
||||
return false;
|
||||
}
|
||||
if (pVal[0] == '"' && pVal[len - 1] == '"') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool smlIsNchar(const char *pVal, uint16_t len) {
|
||||
// nchar: L"abc"
|
||||
if (len < 3) {
|
||||
return false;
|
||||
}
|
||||
if (pVal[1] == '"' && pVal[len - 1] == '"' && (pVal[0] == 'l' || pVal[0] == 'L')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int64_t smlParseInfluxTime(SSmlHandle *info, const char *data, int32_t len) {
|
||||
uint8_t toPrecision = info->currSTableMeta ? info->currSTableMeta->tableInfo.precision : TSDB_TIME_PRECISION_NANO;
|
||||
|
||||
if(unlikely(len == 0 || (len == 1 && data[0] == '0'))){
|
||||
return taosGetTimestampNs()/smlFactorNS[toPrecision];
|
||||
}
|
||||
|
||||
uint8_t fromPrecision = smlPrecisionConvert[info->precision];
|
||||
|
||||
int64_t ts = smlGetTimeValue(data, len, fromPrecision, toPrecision);
|
||||
if (unlikely(ts == -1)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid timestamp", data);
|
||||
return -1;
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
int32_t smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg) {
|
||||
if (pVal->value[0] == '"'){ // binary
|
||||
if (pVal->length >= 2 && pVal->value[pVal->length - 1] == '"') {
|
||||
pVal->type = TSDB_DATA_TYPE_BINARY;
|
||||
pVal->length -= BINARY_ADD_LEN;
|
||||
if (pVal->length > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
|
||||
return TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
|
||||
}
|
||||
pVal->value += (BINARY_ADD_LEN - 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if(pVal->value[0] == 'l' || pVal->value[0] == 'L'){ // nchar
|
||||
if (pVal->value[1] == '"' && pVal->value[pVal->length - 1] == '"' && pVal->length >= 3){
|
||||
pVal->type = TSDB_DATA_TYPE_NCHAR;
|
||||
pVal->length -= NCHAR_ADD_LEN;
|
||||
if (pVal->length > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||
return TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
|
||||
}
|
||||
pVal->value += (NCHAR_ADD_LEN - 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (pVal->value[0] == 't' || pVal->value[0] == 'T'){
|
||||
if(pVal->length == 1 || (pVal->length == 4 && (pVal->value[1] == 'r' || pVal->value[1] == 'R')
|
||||
&& (pVal->value[2] == 'u' || pVal->value[2] == 'U')
|
||||
&& (pVal->value[3] == 'e' || pVal->value[3] == 'E'))){
|
||||
pVal->i = TSDB_TRUE;
|
||||
pVal->type = TSDB_DATA_TYPE_BOOL;
|
||||
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (pVal->value[0] == 'f' || pVal->value[0] == 'F'){
|
||||
if(pVal->length == 1 || (pVal->length == 5 && (pVal->value[1] == 'a' || pVal->value[1] == 'A')
|
||||
&& (pVal->value[2] == 'l' || pVal->value[2] == 'L')
|
||||
&& (pVal->value[3] == 's' || pVal->value[3] == 'S')
|
||||
&& (pVal->value[4] == 'e' || pVal->value[4] == 'E'))){
|
||||
pVal->i = TSDB_FALSE;
|
||||
pVal->type = TSDB_DATA_TYPE_BOOL;
|
||||
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
// number
|
||||
if (smlParseNumber(pVal, msg)) {
|
||||
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
||||
SSmlLineInfo* currElement, bool isSameMeasure, bool isSameCTable){
|
||||
if(isSameCTable){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
SArray *preLineKV = info->preLineTagKV;
|
||||
bool isSuperKVInit = true;
|
||||
SArray *superKV = NULL;
|
||||
if(info->dataFormat){
|
||||
if(unlikely(!isSameMeasure)){
|
||||
SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL);
|
||||
|
||||
if(unlikely(sMeta == NULL)){
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
STableMeta * pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
if(pTableMeta == NULL){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
nodeListSet(&info->superTables, currElement->measure, currElement->measureLen, sMeta, NULL);
|
||||
}
|
||||
info->currSTableMeta = sMeta->tableMeta;
|
||||
superKV = sMeta->tags;
|
||||
|
||||
if(unlikely(taosArrayGetSize(superKV) == 0)){
|
||||
isSuperKVInit = false;
|
||||
}
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
}
|
||||
}else{
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
}
|
||||
|
||||
|
||||
while (*sql < sqlEnd) {
|
||||
if (unlikely(IS_SPACE(*sql))) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool hasSlash = false;
|
||||
// parse key
|
||||
const char *key = *sql;
|
||||
size_t keyLen = 0;
|
||||
while (*sql < sqlEnd) {
|
||||
if (unlikely(IS_COMMA(*sql))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
if (unlikely(IS_EQUAL(*sql))) {
|
||||
keyLen = *sql - key;
|
||||
(*sql)++;
|
||||
break;
|
||||
}
|
||||
if(!hasSlash){
|
||||
hasSlash = (*(*sql) == SLASH);
|
||||
}
|
||||
(*sql)++;
|
||||
}
|
||||
if(unlikely(hasSlash)) {
|
||||
PROCESS_SLASH(key, keyLen)
|
||||
}
|
||||
|
||||
if (unlikely(IS_INVALID_COL_LEN(keyLen))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid key or key is too long than 64", key);
|
||||
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
}
|
||||
|
||||
// parse value
|
||||
const char *value = *sql;
|
||||
size_t valueLen = 0;
|
||||
hasSlash = false;
|
||||
while (*sql < sqlEnd) {
|
||||
// parse value
|
||||
if (unlikely(IS_SPACE(*sql) || IS_COMMA(*sql))) {
|
||||
break;
|
||||
}else if (unlikely(IS_EQUAL(*sql))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(!hasSlash){
|
||||
hasSlash = (*(*sql) == SLASH);
|
||||
}
|
||||
|
||||
(*sql)++;
|
||||
}
|
||||
valueLen = *sql - value;
|
||||
|
||||
if (unlikely(valueLen == 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid value", value);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(unlikely(hasSlash)) {
|
||||
PROCESS_SLASH(value, valueLen)
|
||||
}
|
||||
|
||||
if (unlikely(valueLen > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)) {
|
||||
return TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
|
||||
}
|
||||
|
||||
SSmlKv kv = {.key = key, .keyLen = keyLen, .type = TSDB_DATA_TYPE_NCHAR, .value = value, .length = valueLen};
|
||||
if(info->dataFormat){
|
||||
if(unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(isSameMeasure){
|
||||
if(unlikely(cnt >= taosArrayGetSize(preLineKV))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)){
|
||||
preKV->length = kv.length;
|
||||
SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL);
|
||||
ASSERT(tableMeta != NULL);
|
||||
|
||||
SSmlKv *oldKV = (SSmlKv *)taosArrayGet(tableMeta->tags, cnt);
|
||||
oldKV->length = kv.length;
|
||||
info->needModifySchema = true;
|
||||
}
|
||||
if(unlikely(!IS_SAME_KEY)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
if(isSuperKVInit){
|
||||
if(unlikely(cnt >= taosArrayGetSize(superKV))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)) {
|
||||
preKV->length = kv.length;
|
||||
}else{
|
||||
kv.length = preKV->length;
|
||||
}
|
||||
info->needModifySchema = true;
|
||||
|
||||
if(unlikely(!IS_SAME_KEY)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(superKV, &kv);
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
}
|
||||
|
||||
cnt++;
|
||||
if(IS_SPACE(*sql)){
|
||||
break;
|
||||
}
|
||||
(*sql)++;
|
||||
}
|
||||
|
||||
void* oneTable = nodeListGet(info->childTables, currElement->measure, currElement->measureTagsLen, NULL);
|
||||
if ((oneTable != NULL)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSmlTableInfo *tinfo = smlBuildTableInfo(1, currElement->measure, currElement->measureLen);
|
||||
if (unlikely(!tinfo)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tinfo->tags = taosArrayDup(preLineKV, NULL);
|
||||
|
||||
smlSetCTableName(tinfo);
|
||||
if(info->dataFormat) {
|
||||
info->currSTableMeta->uid = tinfo->uid;
|
||||
tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
|
||||
if(tinfo->tableDataCtx == NULL){
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "smlInitTableDataCtx error", NULL);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
nodeListSet(&info->childTables, currElement->measure, currElement->measureTagsLen, tinfo, NULL);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
||||
SSmlLineInfo* currElement, bool isSameMeasure, bool isSameCTable){
|
||||
int cnt = 0;
|
||||
SArray *preLineKV = info->preLineColKV;
|
||||
bool isSuperKVInit = true;
|
||||
SArray *superKV = NULL;
|
||||
if(info->dataFormat){
|
||||
if(unlikely(!isSameCTable)){
|
||||
SSmlTableInfo *oneTable = (SSmlTableInfo *)nodeListGet(info->childTables, currElement->measure, currElement->measureTagsLen, NULL);
|
||||
if (unlikely(oneTable == NULL)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "child table should inside", currElement->measure);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
info->currTableDataCtx = oneTable->tableDataCtx;
|
||||
}
|
||||
|
||||
if(unlikely(!isSameMeasure)){
|
||||
SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL);
|
||||
|
||||
if(unlikely(sMeta == NULL)){
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
STableMeta * pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
if(pTableMeta == NULL){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
nodeListSet(&info->superTables, currElement->measure, currElement->measureLen, sMeta, NULL);
|
||||
}
|
||||
info->currSTableMeta = sMeta->tableMeta;
|
||||
superKV = sMeta->cols;
|
||||
if(unlikely(taosArrayGetSize(superKV) == 0)){
|
||||
isSuperKVInit = false;
|
||||
}
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
}
|
||||
}
|
||||
|
||||
while (*sql < sqlEnd) {
|
||||
if (unlikely(IS_SPACE(*sql))) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool hasSlash = false;
|
||||
// parse key
|
||||
const char *key = *sql;
|
||||
size_t keyLen = 0;
|
||||
while (*sql < sqlEnd) {
|
||||
if (unlikely(IS_COMMA(*sql))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
if (unlikely(IS_EQUAL(*sql))) {
|
||||
keyLen = *sql - key;
|
||||
(*sql)++;
|
||||
break;
|
||||
}
|
||||
if(!hasSlash){
|
||||
hasSlash = (*(*sql) == SLASH);
|
||||
}
|
||||
(*sql)++;
|
||||
}
|
||||
if(unlikely(hasSlash)) {
|
||||
PROCESS_SLASH(key, keyLen)
|
||||
}
|
||||
|
||||
if (unlikely(IS_INVALID_COL_LEN(keyLen))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid key or key is too long than 64", key);
|
||||
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
}
|
||||
|
||||
// parse value
|
||||
const char *value = *sql;
|
||||
size_t valueLen = 0;
|
||||
hasSlash = false;
|
||||
bool isInQuote = false;
|
||||
while (*sql < sqlEnd) {
|
||||
// parse value
|
||||
if (unlikely(IS_QUOTE(*sql))) {
|
||||
isInQuote = !isInQuote;
|
||||
(*sql)++;
|
||||
continue;
|
||||
}
|
||||
if (!isInQuote){
|
||||
if (unlikely(IS_SPACE(*sql) || IS_COMMA(*sql))) {
|
||||
break;
|
||||
} else if (unlikely(IS_EQUAL(*sql))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
if(!hasSlash){
|
||||
hasSlash = (*(*sql) == SLASH);
|
||||
}
|
||||
|
||||
(*sql)++;
|
||||
}
|
||||
valueLen = *sql - value;
|
||||
|
||||
if (unlikely(isInQuote)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "only one quote", value);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
if (unlikely(valueLen == 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid value", value);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
if(unlikely(hasSlash)) {
|
||||
PROCESS_SLASH(value, valueLen)
|
||||
}
|
||||
|
||||
SSmlKv kv = {.key = key, .keyLen = keyLen, .value = value, .length = valueLen};
|
||||
int32_t ret = smlParseValue(&kv, &info->msgBuf);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "smlParseValue error", value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(info->dataFormat){
|
||||
//cnt begin 0, add ts so + 2
|
||||
if(unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
// bind data
|
||||
ret = smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, &kv, cnt + 1);
|
||||
if (unlikely(ret != TSDB_CODE_SUCCESS)) {
|
||||
uError("smlBuildCol error, retry");
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(isSameMeasure){
|
||||
if(cnt >= taosArrayGetSize(preLineKV)) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
||||
if(kv.type != preKV->type){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(unlikely(IS_VAR_DATA_TYPE(kv.type) && kv.length > preKV->length)){
|
||||
preKV->length = kv.length;
|
||||
SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL);
|
||||
ASSERT(tableMeta != NULL);
|
||||
|
||||
SSmlKv *oldKV = (SSmlKv *)taosArrayGet(tableMeta->cols, cnt);
|
||||
oldKV->length = kv.length;
|
||||
info->needModifySchema = true;
|
||||
}
|
||||
if(unlikely(!IS_SAME_KEY)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
if(isSuperKVInit){
|
||||
if(unlikely(cnt >= taosArrayGetSize(superKV))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.type != preKV->type)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(IS_VAR_DATA_TYPE(kv.type)){
|
||||
if(kv.length > preKV->length) {
|
||||
preKV->length = kv.length;
|
||||
}else{
|
||||
kv.length = preKV->length;
|
||||
}
|
||||
info->needModifySchema = true;
|
||||
}
|
||||
if(unlikely(!IS_SAME_KEY)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(superKV, &kv);
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
}
|
||||
}else{
|
||||
if(currElement->colArray == NULL){
|
||||
currElement->colArray = taosArrayInit(16, sizeof(SSmlKv));
|
||||
taosArraySetSize(currElement->colArray, 1);
|
||||
}
|
||||
taosArrayPush(currElement->colArray, &kv); //reserve for timestamp
|
||||
}
|
||||
|
||||
cnt++;
|
||||
if(IS_SPACE(*sql)){
|
||||
break;
|
||||
}
|
||||
(*sql)++;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements) {
|
||||
if (!sql) return TSDB_CODE_SML_INVALID_DATA;
|
||||
JUMP_SPACE(sql, sqlEnd)
|
||||
if (unlikely(*sql == COMMA)) return TSDB_CODE_SML_INVALID_DATA;
|
||||
elements->measure = sql;
|
||||
|
||||
// parse measure
|
||||
while (sql < sqlEnd) {
|
||||
if (unlikely((sql != elements->measure) && IS_SLASH_LETTER(sql))) {
|
||||
MOVE_FORWARD_ONE(sql, sqlEnd - sql);
|
||||
sqlEnd--;
|
||||
continue;
|
||||
}
|
||||
if (unlikely(IS_COMMA(sql))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (unlikely(IS_SPACE(sql))) {
|
||||
break;
|
||||
}
|
||||
sql++;
|
||||
}
|
||||
elements->measureLen = sql - elements->measure;
|
||||
if (unlikely(IS_INVALID_TABLE_LEN(elements->measureLen))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "measure is empty or too large than 192", NULL);
|
||||
return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
|
||||
}
|
||||
|
||||
// to get measureTagsLen before
|
||||
const char* tmp = sql;
|
||||
while (tmp < sqlEnd){
|
||||
if (unlikely(IS_SPACE(tmp))) {
|
||||
break;
|
||||
}
|
||||
tmp++;
|
||||
}
|
||||
elements->measureTagsLen = tmp - elements->measure;
|
||||
|
||||
bool isSameCTable = false;
|
||||
bool isSameMeasure = false;
|
||||
if(IS_SAME_CHILD_TABLE){
|
||||
isSameCTable = true;
|
||||
isSameMeasure = true;
|
||||
}else if(info->dataFormat) {
|
||||
isSameMeasure = IS_SAME_SUPER_TABLE;
|
||||
}
|
||||
// parse tag
|
||||
if (*sql == COMMA) sql++;
|
||||
elements->tags = sql;
|
||||
|
||||
int ret = smlParseTagKv(info, &sql, sqlEnd, elements, isSameMeasure, isSameCTable);
|
||||
if(unlikely(ret != TSDB_CODE_SUCCESS)){
|
||||
return ret;
|
||||
}
|
||||
if(unlikely(info->reRun)){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
sql = elements->measure + elements->measureTagsLen;
|
||||
elements->tagsLen = sql - elements->tags;
|
||||
|
||||
// parse cols
|
||||
JUMP_SPACE(sql, sqlEnd)
|
||||
elements->cols = sql;
|
||||
|
||||
ret = smlParseColKv(info, &sql, sqlEnd, elements, isSameMeasure, isSameCTable);
|
||||
if(unlikely(ret != TSDB_CODE_SUCCESS)){
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(unlikely(info->reRun)){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
elements->colsLen = sql - elements->cols;
|
||||
if (unlikely(elements->colsLen == 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "cols is empty", NULL);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
|
||||
// parse timestamp
|
||||
JUMP_SPACE(sql, sqlEnd)
|
||||
elements->timestamp = sql;
|
||||
while (sql < sqlEnd) {
|
||||
if (unlikely(isspace(*sql))) {
|
||||
break;
|
||||
}
|
||||
sql++;
|
||||
}
|
||||
elements->timestampLen = sql - elements->timestamp;
|
||||
|
||||
int64_t ts = smlParseInfluxTime(info, elements->timestamp, elements->timestampLen);
|
||||
if (unlikely(ts <= 0)) {
|
||||
uError("SML:0x%" PRIx64 " smlParseTS error:%" PRId64, info->id, ts);
|
||||
return TSDB_CODE_INVALID_TIMESTAMP;
|
||||
}
|
||||
// add ts to
|
||||
SSmlKv kv = { .key = TS, .keyLen = TS_LEN, .type = TSDB_DATA_TYPE_TIMESTAMP, .i = ts, .length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes};
|
||||
if(info->dataFormat){
|
||||
smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, &kv, 0);
|
||||
smlBuildRow(info->currTableDataCtx);
|
||||
}else{
|
||||
taosArraySet(elements->colArray, 0, &kv);
|
||||
}
|
||||
info->preLine = *elements;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -0,0 +1,333 @@
|
|||
/*
|
||||
* 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 <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "clientSml.h"
|
||||
|
||||
int32_t is_same_child_table_telnet(const void *a, const void *b){
|
||||
SSmlLineInfo *t1 = (SSmlLineInfo *)a;
|
||||
SSmlLineInfo *t2 = (SSmlLineInfo *)b;
|
||||
return (((t1->measureLen == t2->measureLen) && memcmp(t1->measure, t2->measure, t1->measureLen) == 0)
|
||||
&& ((t1->tagsLen == t2->tagsLen) && memcmp(t1->tags, t2->tags, t1->tagsLen) == 0)) ? 0 : 1;
|
||||
}
|
||||
|
||||
int64_t smlParseOpenTsdbTime(SSmlHandle *info, const char *data, int32_t len) {
|
||||
uint8_t toPrecision = info->currSTableMeta ? info->currSTableMeta->tableInfo.precision : TSDB_TIME_PRECISION_NANO;
|
||||
|
||||
if (unlikely(!data)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "timestamp can not be null", NULL);
|
||||
return -1;
|
||||
}
|
||||
if (unlikely(len == 1 && data[0] == '0')) {
|
||||
return taosGetTimestampNs()/smlFactorNS[toPrecision];
|
||||
}
|
||||
int8_t fromPrecision = smlGetTsTypeByLen(len);
|
||||
if (unlikely(fromPrecision == -1)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf,
|
||||
"timestamp precision can only be seconds(10 digits) or milli seconds(13 digits)", data);
|
||||
return -1;
|
||||
}
|
||||
int64_t ts = smlGetTimeValue(data, len, fromPrecision, toPrecision);
|
||||
if (unlikely(ts == -1)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid timestamp", data);
|
||||
return -1;
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
static void smlParseTelnetElement(char **sql, char *sqlEnd, char **data, int32_t *len) {
|
||||
while (*sql < sqlEnd) {
|
||||
if (unlikely((**sql != SPACE && !(*data)))) {
|
||||
*data = *sql;
|
||||
} else if (unlikely(**sql == SPACE && *data)) {
|
||||
*len = *sql - *data;
|
||||
break;
|
||||
}
|
||||
(*sql)++;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SSmlLineInfo *elements, SSmlMsgBuf *msg) {
|
||||
if(is_same_child_table_telnet(elements, &info->preLine) == 0){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool isSameMeasure = IS_SAME_SUPER_TABLE;
|
||||
|
||||
int cnt = 0;
|
||||
SArray *preLineKV = info->preLineTagKV;
|
||||
bool isSuperKVInit = true;
|
||||
SArray *superKV = NULL;
|
||||
if(info->dataFormat){
|
||||
if(!isSameMeasure){
|
||||
SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL);
|
||||
|
||||
if(unlikely(sMeta == NULL)){
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
STableMeta * pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
if(pTableMeta == NULL){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
nodeListSet(&info->superTables, elements->measure, elements->measureLen, sMeta, NULL);
|
||||
}
|
||||
info->currSTableMeta = sMeta->tableMeta;
|
||||
superKV = sMeta->tags;
|
||||
|
||||
if(unlikely(taosArrayGetSize(superKV) == 0)){
|
||||
isSuperKVInit = false;
|
||||
}
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
}
|
||||
}else{
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
}
|
||||
|
||||
const char *sql = data;
|
||||
while (sql < sqlEnd) {
|
||||
JUMP_SPACE(sql, sqlEnd)
|
||||
if (unlikely(*sql == '\0')) break;
|
||||
|
||||
const char *key = sql;
|
||||
size_t keyLen = 0;
|
||||
|
||||
// parse key
|
||||
while (sql < sqlEnd) {
|
||||
if (unlikely(*sql == SPACE)) {
|
||||
smlBuildInvalidDataMsg(msg, "invalid data", sql);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
if (unlikely(*sql == EQUAL)) {
|
||||
keyLen = sql - key;
|
||||
sql++;
|
||||
break;
|
||||
}
|
||||
sql++;
|
||||
}
|
||||
|
||||
if (unlikely(IS_INVALID_COL_LEN(keyLen))) {
|
||||
smlBuildInvalidDataMsg(msg, "invalid key or key is too long than 64", key);
|
||||
return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
|
||||
}
|
||||
// if (smlCheckDuplicateKey(key, keyLen, dumplicateKey)) {
|
||||
// smlBuildInvalidDataMsg(msg, "dumplicate key", key);
|
||||
// return TSDB_CODE_TSC_DUP_NAMES;
|
||||
// }
|
||||
|
||||
// parse value
|
||||
const char *value = sql;
|
||||
size_t valueLen = 0;
|
||||
while (sql < sqlEnd) {
|
||||
// parse value
|
||||
if (unlikely(*sql == SPACE)) {
|
||||
break;
|
||||
}
|
||||
if (unlikely(*sql == EQUAL)) {
|
||||
smlBuildInvalidDataMsg(msg, "invalid data", sql);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
sql++;
|
||||
}
|
||||
valueLen = sql - value;
|
||||
|
||||
if (unlikely(valueLen == 0)) {
|
||||
smlBuildInvalidDataMsg(msg, "invalid value", value);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (unlikely(valueLen > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)) {
|
||||
return TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
|
||||
}
|
||||
|
||||
SSmlKv kv = {.key = key, .keyLen = keyLen, .type = TSDB_DATA_TYPE_NCHAR, .value = value, .length = valueLen};
|
||||
|
||||
if(info->dataFormat){
|
||||
if(unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(isSameMeasure){
|
||||
if(unlikely(cnt >= taosArrayGetSize(preLineKV))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)){
|
||||
preKV->length = kv.length;
|
||||
SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL);
|
||||
ASSERT(tableMeta != NULL);
|
||||
|
||||
SSmlKv *oldKV = (SSmlKv *)taosArrayGet(tableMeta->tags, cnt);
|
||||
oldKV->length = kv.length;
|
||||
info->needModifySchema = true;
|
||||
}
|
||||
if(unlikely(!IS_SAME_KEY)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
if(isSuperKVInit){
|
||||
if(unlikely(cnt >= taosArrayGetSize(superKV))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)) {
|
||||
preKV->length = kv.length;
|
||||
}else{
|
||||
kv.length = preKV->length;
|
||||
}
|
||||
info->needModifySchema = true;
|
||||
|
||||
if(unlikely(!IS_SAME_KEY)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(superKV, &kv);
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
SSmlTableInfo *tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements, POINTER_BYTES, is_same_child_table_telnet);
|
||||
if (unlikely(tinfo == NULL)) {
|
||||
tinfo = smlBuildTableInfo(1, elements->measure, elements->measureLen);
|
||||
if (!tinfo) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tinfo->tags = taosArrayDup(preLineKV, NULL);
|
||||
|
||||
smlSetCTableName(tinfo);
|
||||
if (info->dataFormat) {
|
||||
info->currSTableMeta->uid = tinfo->uid;
|
||||
tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
|
||||
if (tinfo->tableDataCtx == NULL) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "smlInitTableDataCtx error", NULL);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
SSmlLineInfo *key = (SSmlLineInfo *)taosMemoryMalloc(sizeof(SSmlLineInfo));
|
||||
*key = *elements;
|
||||
tinfo->key = key;
|
||||
nodeListSet(&info->childTables, key, POINTER_BYTES, tinfo, is_same_child_table_telnet);
|
||||
}
|
||||
if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
|
||||
int32_t smlParseTelnetString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements) {
|
||||
if (!sql) return TSDB_CODE_SML_INVALID_DATA;
|
||||
|
||||
// parse metric
|
||||
smlParseTelnetElement(&sql, sqlEnd, &elements->measure, &elements->measureLen);
|
||||
if (unlikely((!(elements->measure) || IS_INVALID_TABLE_LEN(elements->measureLen)))) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", sql);
|
||||
return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
|
||||
}
|
||||
|
||||
// parse timestamp
|
||||
smlParseTelnetElement(&sql, sqlEnd, &elements->timestamp, &elements->timestampLen);
|
||||
if (unlikely(!elements->timestamp || elements->timestampLen == 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid timestamp", sql);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
|
||||
bool needConverTime = false; // get TS before parse tag(get meta), so need conver time
|
||||
if(info->dataFormat && info->currSTableMeta == NULL){
|
||||
needConverTime = true;
|
||||
}
|
||||
int64_t ts = smlParseOpenTsdbTime(info, elements->timestamp, elements->timestampLen);
|
||||
if (unlikely(ts < 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid timestamp", sql);
|
||||
return TSDB_CODE_INVALID_TIMESTAMP;
|
||||
}
|
||||
SSmlKv kvTs = { .key = TS, .keyLen = TS_LEN, .type = TSDB_DATA_TYPE_TIMESTAMP, .i = ts, .length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes};
|
||||
|
||||
// parse value
|
||||
smlParseTelnetElement(&sql, sqlEnd, &elements->cols, &elements->colsLen);
|
||||
if (unlikely(!elements->cols || elements->colsLen == 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid value", sql);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
SSmlKv kv = {.key = VALUE, .keyLen = VALUE_LEN, .value = elements->cols, .length = (size_t)elements->colsLen};
|
||||
if (smlParseValue(&kv, &info->msgBuf) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
JUMP_SPACE(sql, sqlEnd)
|
||||
|
||||
elements->tags = sql;
|
||||
elements->tagsLen = sqlEnd - sql;
|
||||
if (unlikely(!elements->tags || elements->tagsLen == 0)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid value", sql);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
int ret = smlParseTelnetTags(info, sql, sqlEnd, elements, &info->msgBuf);
|
||||
if (unlikely(ret != TSDB_CODE_SUCCESS)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(unlikely(info->reRun)){
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(info->dataFormat){
|
||||
if(needConverTime) {
|
||||
kvTs.i = convertTimePrecision(kvTs.i, TSDB_TIME_PRECISION_NANO, info->currSTableMeta->tableInfo.precision);
|
||||
}
|
||||
ret = smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, &kvTs, 0);
|
||||
if(ret == TSDB_CODE_SUCCESS){
|
||||
ret = smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, &kv, 1);
|
||||
}
|
||||
if(ret == TSDB_CODE_SUCCESS){
|
||||
ret = smlBuildRow(info->currTableDataCtx);
|
||||
}
|
||||
if (unlikely(ret != TSDB_CODE_SUCCESS)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "smlBuildCol error", NULL);
|
||||
return ret;
|
||||
}
|
||||
}else{
|
||||
if(elements->colArray == NULL){
|
||||
elements->colArray = taosArrayInit(16, sizeof(SSmlKv));
|
||||
}
|
||||
taosArrayPush(elements->colArray, &kvTs);
|
||||
taosArrayPush(elements->colArray, &kv);
|
||||
}
|
||||
info->preLine = *elements;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -152,9 +152,10 @@ int32_t stmtRestoreQueryFields(STscStmt* pStmt) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t stmtUpdateBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags, SName* tbName, const char* sTableName, bool autoCreateTbl) {
|
||||
int32_t stmtUpdateBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags, SName* tbName, const char* sTableName,
|
||||
bool autoCreateTbl) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
tNameExtractFullName(tbName, tbFName);
|
||||
|
||||
memcpy(&pStmt->bInfo.sname, tbName, sizeof(*tbName));
|
||||
|
@ -171,12 +172,11 @@ int32_t stmtUpdateBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t stmtUpdateExecInfo(TAOS_STMT* stmt, SHashObj* pVgHash, SHashObj* pBlockHash, bool autoCreateTbl) {
|
||||
int32_t stmtUpdateExecInfo(TAOS_STMT* stmt, SHashObj* pVgHash, SHashObj* pBlockHash) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
pStmt->sql.pVgHash = pVgHash;
|
||||
pStmt->exec.pBlockHash = pBlockHash;
|
||||
pStmt->exec.autoCreateTbl = autoCreateTbl;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ int32_t stmtUpdateInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags, SNam
|
|||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
STMT_ERR_RET(stmtUpdateBindInfo(stmt, pTableMeta, tags, tbName, sTableName, autoCreateTbl));
|
||||
STMT_ERR_RET(stmtUpdateExecInfo(stmt, pVgHash, pBlockHash, autoCreateTbl));
|
||||
STMT_ERR_RET(stmtUpdateExecInfo(stmt, pVgHash, pBlockHash));
|
||||
|
||||
pStmt->sql.autoCreateTbl = autoCreateTbl;
|
||||
|
||||
|
@ -214,16 +214,16 @@ int32_t stmtCacheBlock(STscStmt* pStmt) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STableDataBlocks** pSrc = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
STableDataCxt** pSrc = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (!pSrc) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
STableDataBlocks* pDst = NULL;
|
||||
STableDataCxt* pDst = NULL;
|
||||
|
||||
STMT_ERR_RET(qCloneStmtDataBlock(&pDst, *pSrc));
|
||||
STMT_ERR_RET(qCloneStmtDataBlock(&pDst, *pSrc, true));
|
||||
|
||||
SStmtTableCache cache = {
|
||||
.pDataBlock = pDst,
|
||||
.pDataCtx = pDst,
|
||||
.boundTags = pStmt->bInfo.boundTags,
|
||||
};
|
||||
|
||||
|
@ -241,6 +241,8 @@ int32_t stmtCacheBlock(STscStmt* pStmt) {
|
|||
}
|
||||
|
||||
int32_t stmtParseSql(STscStmt* pStmt) {
|
||||
pStmt->exec.pCurrBlock = NULL;
|
||||
|
||||
SStmtCallback stmtCb = {
|
||||
.pStmt = pStmt,
|
||||
.getTbNameFn = stmtGetTbName,
|
||||
|
@ -273,7 +275,7 @@ int32_t stmtCleanBindInfo(STscStmt* pStmt) {
|
|||
pStmt->bInfo.tbName[0] = 0;
|
||||
pStmt->bInfo.tbFName[0] = 0;
|
||||
if (!pStmt->bInfo.tagsCached) {
|
||||
destroyBoundColumnInfo(pStmt->bInfo.boundTags);
|
||||
qDestroyBoundColInfo(pStmt->bInfo.boundTags);
|
||||
taosMemoryFreeClear(pStmt->bInfo.boundTags);
|
||||
}
|
||||
memset(pStmt->bInfo.stbFName, 0, TSDB_TABLE_FNAME_LEN);
|
||||
|
@ -289,29 +291,25 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool deepClean) {
|
|||
size_t keyLen = 0;
|
||||
void* pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
|
||||
while (pIter) {
|
||||
STableDataBlocks* pBlocks = *(STableDataBlocks**)pIter;
|
||||
char* key = taosHashGetKey(pIter, &keyLen);
|
||||
STableMeta* pMeta = qGetTableMetaInDataBlock(pBlocks);
|
||||
STableDataCxt* pBlocks = *(STableDataCxt**)pIter;
|
||||
char* key = taosHashGetKey(pIter, &keyLen);
|
||||
STableMeta* pMeta = qGetTableMetaInDataBlock(pBlocks);
|
||||
|
||||
if (keepTable && (strlen(pStmt->bInfo.tbFName) == keyLen) && strncmp(pStmt->bInfo.tbFName, key, keyLen) == 0) {
|
||||
STMT_ERR_RET(qResetStmtDataBlock(pBlocks, true));
|
||||
if (keepTable && pBlocks == pStmt->exec.pCurrBlock) {
|
||||
ASSERT(NULL == pBlocks->pData);
|
||||
TSWAP(pBlocks->pData, pStmt->exec.pCurrTbData);
|
||||
STMT_ERR_RET(qResetStmtDataBlock(pBlocks, false));
|
||||
|
||||
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (STMT_TYPE_MULTI_INSERT == pStmt->sql.type) {
|
||||
qFreeStmtDataBlock(pBlocks);
|
||||
} else {
|
||||
qDestroyStmtDataBlock(pBlocks);
|
||||
}
|
||||
qDestroyStmtDataBlock(pBlocks);
|
||||
taosHashRemove(pStmt->exec.pBlockHash, key, keyLen);
|
||||
|
||||
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
||||
}
|
||||
|
||||
pStmt->exec.autoCreateTbl = false;
|
||||
|
||||
if (keepTable) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -319,6 +317,9 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool deepClean) {
|
|||
taosHashCleanup(pStmt->exec.pBlockHash);
|
||||
pStmt->exec.pBlockHash = NULL;
|
||||
|
||||
tDestroySSubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
|
||||
taosMemoryFreeClear(pStmt->exec.pCurrTbData);
|
||||
|
||||
STMT_ERR_RET(stmtCleanBindInfo(pStmt));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -337,8 +338,8 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
|||
while (pIter) {
|
||||
SStmtTableCache* pCache = (SStmtTableCache*)pIter;
|
||||
|
||||
qDestroyStmtDataBlock(pCache->pDataBlock);
|
||||
destroyBoundColumnInfo(pCache->boundTags);
|
||||
qDestroyStmtDataBlock(pCache->pDataCtx);
|
||||
qDestroyBoundColInfo(pCache->boundTags);
|
||||
taosMemoryFreeClear(pCache->boundTags);
|
||||
|
||||
pIter = taosHashIterate(pStmt->sql.pTableCache, pIter);
|
||||
|
@ -354,7 +355,8 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t stmtRebuildDataBlock(STscStmt* pStmt, STableDataBlocks* pDataBlock, STableDataBlocks** newBlock, uint64_t uid) {
|
||||
int32_t stmtRebuildDataBlock(STscStmt* pStmt, STableDataCxt* pDataBlock, STableDataCxt** newBlock, uint64_t uid,
|
||||
uint64_t suid) {
|
||||
SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp);
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter,
|
||||
|
@ -366,7 +368,9 @@ int32_t stmtRebuildDataBlock(STscStmt* pStmt, STableDataBlocks* pDataBlock, STab
|
|||
STMT_ERR_RET(
|
||||
taosHashPut(pStmt->sql.pVgHash, (const char*)&vgInfo.vgId, sizeof(vgInfo.vgId), (char*)&vgInfo, sizeof(vgInfo)));
|
||||
|
||||
STMT_ERR_RET(qRebuildStmtDataBlock(newBlock, pDataBlock, uid, vgInfo.vgId));
|
||||
STMT_ERR_RET(qRebuildStmtDataBlock(newBlock, pDataBlock, uid, suid, vgInfo.vgId, pStmt->sql.autoCreateTbl));
|
||||
|
||||
STMT_DLOG("tableDataCxt rebuilt, uid:%" PRId64 ", vgId:%d", uid, vgInfo.vgId);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -375,12 +379,13 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
|||
pStmt->bInfo.needParse = true;
|
||||
pStmt->bInfo.inExecCache = false;
|
||||
|
||||
STableDataBlocks* pBlockInExec =
|
||||
taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (pBlockInExec) {
|
||||
STableDataCxt** pCxtInExec = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (pCxtInExec) {
|
||||
pStmt->bInfo.needParse = false;
|
||||
pStmt->bInfo.inExecCache = true;
|
||||
|
||||
pStmt->exec.pCurrBlock = *pCxtInExec;
|
||||
|
||||
if (pStmt->sql.autoCreateTbl) {
|
||||
tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -407,18 +412,18 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
|||
SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pStmt->bInfo.tbSuid, sizeof(pStmt->bInfo.tbSuid));
|
||||
if (pCache) {
|
||||
pStmt->bInfo.needParse = false;
|
||||
pStmt->exec.autoCreateTbl = true;
|
||||
|
||||
pStmt->bInfo.tbUid = 0;
|
||||
|
||||
STableDataBlocks* pNewBlock = NULL;
|
||||
STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataBlock, &pNewBlock, 0));
|
||||
STableDataCxt* pNewBlock = NULL;
|
||||
STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataCtx, &pNewBlock, 0, pStmt->bInfo.tbSuid));
|
||||
|
||||
if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock,
|
||||
POINTER_BYTES)) {
|
||||
STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pStmt->exec.pCurrBlock = pNewBlock;
|
||||
|
||||
tscDebug("reuse stmt block for tb %s in sqlBlock, suid:0x%" PRIx64, pStmt->bInfo.tbFName, pStmt->bInfo.tbSuid);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -489,14 +494,16 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
|||
pStmt->bInfo.boundTags = pCache->boundTags;
|
||||
pStmt->bInfo.tagsCached = true;
|
||||
|
||||
STableDataBlocks* pNewBlock = NULL;
|
||||
STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataBlock, &pNewBlock, uid));
|
||||
STableDataCxt* pNewBlock = NULL;
|
||||
STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataCtx, &pNewBlock, uid, suid));
|
||||
|
||||
if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock,
|
||||
POINTER_BYTES)) {
|
||||
STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pStmt->exec.pCurrBlock = pNewBlock;
|
||||
|
||||
tscDebug("tb %s in sqlBlock list, set to current", pStmt->bInfo.tbFName);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -614,8 +621,8 @@ int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STableDataBlocks** pDataBlock =
|
||||
(STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
STableDataCxt** pDataBlock =
|
||||
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (NULL == pDataBlock) {
|
||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
||||
|
@ -626,8 +633,6 @@ int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) {
|
|||
pStmt->bInfo.sname.tname, tags, pStmt->exec.pRequest->msgBuf,
|
||||
pStmt->exec.pRequest->msgBufLen));
|
||||
|
||||
pStmt->exec.autoCreateTbl = true;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -637,8 +642,8 @@ int stmtFetchTagFields(STscStmt* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields
|
|||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
}
|
||||
|
||||
STableDataBlocks** pDataBlock =
|
||||
(STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
STableDataCxt** pDataBlock =
|
||||
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (NULL == pDataBlock) {
|
||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
||||
|
@ -655,8 +660,8 @@ int stmtFetchColFields(STscStmt* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields
|
|||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
}
|
||||
|
||||
STableDataBlocks** pDataBlock =
|
||||
(STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
STableDataCxt** pDataBlock =
|
||||
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (NULL == pDataBlock) {
|
||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
||||
|
@ -729,11 +734,18 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STableDataBlocks** pDataBlock =
|
||||
(STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (NULL == pDataBlock) {
|
||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
||||
STableDataCxt** pDataBlock = NULL;
|
||||
|
||||
if (pStmt->exec.pCurrBlock) {
|
||||
pDataBlock = &pStmt->exec.pCurrBlock;
|
||||
} else {
|
||||
pDataBlock =
|
||||
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||
if (NULL == pDataBlock) {
|
||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_CACHE_ERROR);
|
||||
}
|
||||
pStmt->exec.pCurrBlock = *pDataBlock;
|
||||
}
|
||||
|
||||
if (colIdx < 0) {
|
||||
|
@ -779,10 +791,10 @@ int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) {
|
|||
int32_t code = 0;
|
||||
int32_t finalCode = 0;
|
||||
size_t keyLen = 0;
|
||||
STableDataBlocks** pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
|
||||
void* pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
|
||||
while (pIter) {
|
||||
STableDataBlocks* pBlock = *pIter;
|
||||
char* key = taosHashGetKey(pIter, &keyLen);
|
||||
STableDataCxt* pBlock = *(STableDataCxt**)pIter;
|
||||
char* key = taosHashGetKey(pIter, &keyLen);
|
||||
|
||||
STableMeta* pMeta = qGetTableMetaInDataBlock(pBlock);
|
||||
if (pMeta->uid) {
|
||||
|
@ -848,7 +860,7 @@ int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) {
|
|||
|
||||
pMeta->uid = pTableMeta->uid;
|
||||
pStmt->bInfo.tbUid = pTableMeta->uid;
|
||||
taosMemoryFree(pTableMeta);
|
||||
taosMemoryFree(pTableMeta);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
||||
|
@ -861,7 +873,6 @@ int stmtExec(TAOS_STMT* stmt) {
|
|||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
int32_t code = 0;
|
||||
SSubmitRsp* pRsp = NULL;
|
||||
bool autoCreateTbl = pStmt->exec.autoCreateTbl;
|
||||
|
||||
STMT_DLOG_E("start to exec");
|
||||
|
||||
|
@ -870,8 +881,13 @@ int stmtExec(TAOS_STMT* stmt) {
|
|||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL);
|
||||
} else {
|
||||
tDestroySSubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
|
||||
taosMemoryFreeClear(pStmt->exec.pCurrTbData);
|
||||
|
||||
STMT_ERR_RET(qCloneCurrentTbData(pStmt->exec.pCurrBlock, &pStmt->exec.pCurrTbData));
|
||||
|
||||
STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->exec.pBlockHash));
|
||||
launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, (autoCreateTbl ? (void**)&pRsp : NULL));
|
||||
launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL);
|
||||
}
|
||||
|
||||
if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) {
|
||||
|
@ -894,15 +910,6 @@ _return:
|
|||
|
||||
stmtCleanExecInfo(pStmt, (code ? false : true), false);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && autoCreateTbl) {
|
||||
if (NULL == pRsp) {
|
||||
tscError("no submit resp got for auto create table");
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
} else {
|
||||
code = stmtUpdateTableUid(pStmt, pRsp);
|
||||
}
|
||||
}
|
||||
|
||||
tFreeSSubmitRsp(pRsp);
|
||||
|
||||
++pStmt->sql.runTimes;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -19,7 +19,7 @@
|
|||
#include "tlog.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define MALLOC_ALIGN_BYTES 256
|
||||
#define MALLOC_ALIGN_BYTES 32
|
||||
|
||||
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) {
|
||||
ASSERT(pColumnInfoData != NULL);
|
||||
|
@ -38,7 +38,8 @@ int32_t colDataGetFullLength(const SColumnInfoData* pColumnInfoData, int32_t num
|
|||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||
return pColumnInfoData->varmeta.length + sizeof(int32_t) * numOfRows;
|
||||
} else {
|
||||
return ((pColumnInfoData->info.type == TSDB_DATA_TYPE_NULL) ? 0 : pColumnInfoData->info.bytes * numOfRows) + BitmapLen(numOfRows);
|
||||
return ((pColumnInfoData->info.type == TSDB_DATA_TYPE_NULL) ? 0 : pColumnInfoData->info.bytes * numOfRows) +
|
||||
BitmapLen(numOfRows);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,7 +280,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, int
|
|||
pColumnInfoData->varmeta.allocLen = len + oldLen;
|
||||
}
|
||||
|
||||
if (pColumnInfoData->pData && pSource->pData) { // TD-20382
|
||||
if (pColumnInfoData->pData && pSource->pData) { // TD-20382
|
||||
memcpy(pColumnInfoData->pData + oldLen, pSource->pData, len);
|
||||
}
|
||||
pColumnInfoData->varmeta.length = len + oldLen;
|
||||
|
@ -359,7 +360,7 @@ size_t blockDataGetNumOfRows(const SSDataBlock* pBlock) { return pBlock->info.ro
|
|||
|
||||
int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex) {
|
||||
if (pDataBlock->info.rows > 0) {
|
||||
// ASSERT(pDataBlock->info.dataLoad == 1);
|
||||
// ASSERT(pDataBlock->info.dataLoad == 1);
|
||||
}
|
||||
|
||||
if (pDataBlock == NULL || pDataBlock->info.rows <= 0 || pDataBlock->info.dataLoad == 0) {
|
||||
|
@ -1167,8 +1168,11 @@ void blockDataEmpty(SSDataBlock* pDataBlock) {
|
|||
}
|
||||
|
||||
// todo temporarily disable it
|
||||
static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* pBlockInfo, uint32_t numOfRows, bool clearPayload) {
|
||||
|
||||
static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* pBlockInfo, uint32_t numOfRows,
|
||||
bool clearPayload) {
|
||||
ASSERT(numOfRows > 0);
|
||||
|
||||
if (numOfRows <= pBlockInfo->capacity) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1225,7 +1229,7 @@ static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows) {
|
||||
void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows) {
|
||||
pColumn->hasNull = false;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pColumn->info.type)) {
|
||||
|
@ -1953,7 +1957,8 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
|
|||
"===stream===%s|block type %d|child id %d|group id:%" PRIu64 "|uid:%" PRId64
|
||||
"|rows:%d|version:%" PRIu64 "|cal start:%" PRIu64 "|cal end:%" PRIu64 "\n",
|
||||
flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.id.groupId,
|
||||
pDataBlock->info.id.uid, pDataBlock->info.rows, pDataBlock->info.version, pDataBlock->info.calWin.skey, pDataBlock->info.calWin.ekey);
|
||||
pDataBlock->info.id.uid, pDataBlock->info.rows, pDataBlock->info.version,
|
||||
pDataBlock->info.calWin.skey, pDataBlock->info.calWin.ekey);
|
||||
if (len >= size - 1) return dumpBuf;
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
|
@ -2055,6 +2060,7 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
|
|||
* @param suid
|
||||
*
|
||||
*/
|
||||
#if 0
|
||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataBlock, STSchema* pTSchema, int32_t vgId,
|
||||
tb_uid_t suid) {
|
||||
int32_t bufSize = sizeof(SSubmitReq);
|
||||
|
@ -2220,32 +2226,186 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDataBlock, const STSchema* pTSchema,
|
||||
int64_t uid, int32_t vgId, tb_uid_t suid) {
|
||||
SSubmitReq2* pReq = *ppReq;
|
||||
SArray* pVals = NULL;
|
||||
int32_t numOfBlks = 0;
|
||||
int32_t sz = 1;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (NULL == pReq) {
|
||||
if (!(pReq = taosMemoryMalloc(sizeof(SSubmitReq2)))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pReq->aSubmitTbData = taosArrayInit(1, sizeof(SSubmitTbData)))) {
|
||||
goto _end;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock);
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
|
||||
if (colNum <= 1) { // invalid if only with TS col
|
||||
continue;
|
||||
}
|
||||
|
||||
// the rsma result should has the same column number with schema.
|
||||
ASSERT(colNum == pTSchema->numOfCols);
|
||||
|
||||
SSubmitTbData tbData = {0};
|
||||
|
||||
if (!(tbData.aRowP = taosArrayInit(rows, sizeof(SRow*)))) {
|
||||
goto _end;
|
||||
}
|
||||
tbData.suid = suid;
|
||||
tbData.uid = uid;
|
||||
tbData.sver = pTSchema->version;
|
||||
|
||||
if (!pVals && !(pVals = taosArrayInit(colNum, sizeof(SColVal)))) {
|
||||
taosArrayDestroy(tbData.aRowP);
|
||||
goto _end;
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; ++j) { // iterate by row
|
||||
|
||||
taosArrayClear(pVals);
|
||||
|
||||
bool isStartKey = false;
|
||||
int32_t offset = 0;
|
||||
for (int32_t k = 0; k < colNum; ++k) { // iterate by column
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
const STColumn* pCol = &pTSchema->columns[k];
|
||||
void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||
|
||||
switch (pColInfoData->info.type) {
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
ASSERT(pColInfoData->info.type == pCol->type);
|
||||
if (!isStartKey) {
|
||||
isStartKey = true;
|
||||
ASSERT(PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId);
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, (SValue){.val = *(TSKEY*)var});
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else if (colDataIsNull_s(pColInfoData, j)) {
|
||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, (SValue){.val = *(int64_t*)var});
|
||||
taosArrayPush(pVals, &cv);
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY
|
||||
ASSERT(pColInfoData->info.type == pCol->type);
|
||||
if (colDataIsNull_s(pColInfoData, j)) {
|
||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
void* data = colDataGetVarData(pColInfoData, j);
|
||||
SValue sv = (SValue){.nData = varDataLen(data), .pData = varDataVal(data)}; // address copy, no value
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||
uError("the column type %" PRIi16 " is defined but not implemented yet", pColInfoData->info.type);
|
||||
ASSERT(0);
|
||||
break;
|
||||
default:
|
||||
if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) {
|
||||
if (colDataIsNull_s(pColInfoData, j)) {
|
||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type); // should use pCol->type
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
SValue sv;
|
||||
if (pCol->type == pColInfoData->info.type) {
|
||||
memcpy(&sv.val, var, tDataTypes[pCol->type].bytes);
|
||||
} else {
|
||||
/**
|
||||
* 1. sum/avg would convert to int64_t/uint64_t/double during aggregation
|
||||
* 2. below conversion may lead to overflow or loss, the app should select the right data type.
|
||||
*/
|
||||
char tv[8] = {0};
|
||||
if (pColInfoData->info.type == TSDB_DATA_TYPE_FLOAT) {
|
||||
float v = 0;
|
||||
GET_TYPED_DATA(v, float, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
} else if (pColInfoData->info.type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
double v = 0;
|
||||
GET_TYPED_DATA(v, double, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
} else if (IS_SIGNED_NUMERIC_TYPE(pColInfoData->info.type)) {
|
||||
int64_t v = 0;
|
||||
GET_TYPED_DATA(v, int64_t, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
} else {
|
||||
uint64_t v = 0;
|
||||
GET_TYPED_DATA(v, uint64_t, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
}
|
||||
memcpy(&sv.val, tv, tDataTypes[pCol->type].bytes);
|
||||
}
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pColInfoData->info.type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
}
|
||||
} else {
|
||||
uError("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type);
|
||||
ASSERT(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SRow* pRow = NULL;
|
||||
if ((terrno = tRowBuild(pVals, pTSchema, &pRow)) < 0) {
|
||||
tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
|
||||
goto _end;
|
||||
}
|
||||
ASSERT(pRow);
|
||||
taosArrayPush(tbData.aRowP, &pRow);
|
||||
}
|
||||
|
||||
taosArrayPush(pReq->aSubmitTbData, &tbData);
|
||||
}
|
||||
_end:
|
||||
taosArrayDestroy(pVals);
|
||||
if (terrno != 0) {
|
||||
*ppReq = NULL;
|
||||
if (pReq) tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
*ppReq = pReq;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) {
|
||||
ASSERT(stbFullName[0] != 0);
|
||||
SArray* tags = taosArrayInit(0, sizeof(void*));
|
||||
SArray* tags = taosArrayInit(0, sizeof(SSmlKv));
|
||||
if (tags == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSmlKv* pTag = taosMemoryCalloc(1, sizeof(SSmlKv));
|
||||
if (pTag == NULL) {
|
||||
taosArrayDestroy(tags);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
|
||||
if (cname == NULL) {
|
||||
taosArrayDestroy(tags);
|
||||
taosMemoryFree(pTag);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTag->key = "group_id";
|
||||
pTag->keyLen = strlen(pTag->key);
|
||||
pTag->type = TSDB_DATA_TYPE_UBIGINT;
|
||||
pTag->u = groupId;
|
||||
pTag->length = sizeof(uint64_t);
|
||||
SSmlKv pTag = {.key = "group_id",
|
||||
.keyLen = sizeof("group_id") - 1,
|
||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||
.u = groupId,
|
||||
.length = sizeof(uint64_t)};
|
||||
taosArrayPush(tags, &pTag);
|
||||
|
||||
RandTableName rname = {
|
||||
|
@ -2257,7 +2417,6 @@ char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) {
|
|||
|
||||
buildChildTableName(&rname);
|
||||
|
||||
taosMemoryFree(pTag);
|
||||
taosArrayDestroy(tags);
|
||||
|
||||
ASSERT(rname.ctbShortName && rname.ctbShortName[0]);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -47,7 +47,7 @@ int32_t tsNumOfMnodeQueryThreads = 4;
|
|||
int32_t tsNumOfMnodeFetchThreads = 1;
|
||||
int32_t tsNumOfMnodeReadThreads = 1;
|
||||
int32_t tsNumOfVnodeQueryThreads = 4;
|
||||
int32_t tsNumOfVnodeStreamThreads = 2;
|
||||
float tsRatioOfVnodeStreamThreads = 1.0;
|
||||
int32_t tsNumOfVnodeFetchThreads = 4;
|
||||
int32_t tsNumOfVnodeRsmaThreads = 2;
|
||||
int32_t tsNumOfQnodeQueryThreads = 4;
|
||||
|
@ -392,9 +392,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
tsNumOfVnodeQueryThreads = TMAX(tsNumOfVnodeQueryThreads, 4);
|
||||
if (cfgAddInt32(pCfg, "numOfVnodeQueryThreads", tsNumOfVnodeQueryThreads, 4, 1024, 0) != 0) return -1;
|
||||
|
||||
tsNumOfVnodeStreamThreads = tsNumOfCores / 4;
|
||||
tsNumOfVnodeStreamThreads = TMAX(tsNumOfVnodeStreamThreads, 4);
|
||||
if (cfgAddInt32(pCfg, "numOfVnodeStreamThreads", tsNumOfVnodeStreamThreads, 4, 1024, 0) != 0) return -1;
|
||||
if (cfgAddFloat(pCfg, "ratioOfVnodeStreamThreads", tsRatioOfVnodeStreamThreads, 0.01, 100, 0) != 0) return -1;
|
||||
|
||||
tsNumOfVnodeFetchThreads = tsNumOfCores / 4;
|
||||
tsNumOfVnodeFetchThreads = TMAX(tsNumOfVnodeFetchThreads, 4);
|
||||
|
@ -513,11 +511,9 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) {
|
|||
pItem->stype = stype;
|
||||
}
|
||||
|
||||
pItem = cfgGetItem(tsCfg, "numOfVnodeStreamThreads");
|
||||
pItem = cfgGetItem(tsCfg, "ratioOfVnodeStreamThreads");
|
||||
if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) {
|
||||
tsNumOfVnodeStreamThreads = numOfCores / 4;
|
||||
tsNumOfVnodeStreamThreads = TMAX(tsNumOfVnodeStreamThreads, 4);
|
||||
pItem->i32 = tsNumOfVnodeStreamThreads;
|
||||
pItem->fval = tsRatioOfVnodeStreamThreads;
|
||||
pItem->stype = stype;
|
||||
}
|
||||
|
||||
|
@ -710,7 +706,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32;
|
||||
tsNumOfMnodeReadThreads = cfgGetItem(pCfg, "numOfMnodeReadThreads")->i32;
|
||||
tsNumOfVnodeQueryThreads = cfgGetItem(pCfg, "numOfVnodeQueryThreads")->i32;
|
||||
tsNumOfVnodeStreamThreads = cfgGetItem(pCfg, "numOfVnodeStreamThreads")->i32;
|
||||
tsRatioOfVnodeStreamThreads = cfgGetItem(pCfg, "ratioOfVnodeStreamThreads")->fval;
|
||||
tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32;
|
||||
tsNumOfVnodeRsmaThreads = cfgGetItem(pCfg, "numOfVnodeRsmaThreads")->i32;
|
||||
tsNumOfQnodeQueryThreads = cfgGetItem(pCfg, "numOfQnodeQueryThreads")->i32;
|
||||
|
@ -1316,12 +1312,17 @@ void taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal,
|
|||
if (pItem != NULL && (rewrite || pItem->i32 == 0)) {
|
||||
pItem->i32 = flagVal;
|
||||
}
|
||||
*pFlagPtr = flagVal;
|
||||
if (pFlagPtr != NULL) {
|
||||
*pFlagPtr = flagVal;
|
||||
}
|
||||
}
|
||||
|
||||
void taosSetAllDebugFlag(int32_t flag, bool rewrite) {
|
||||
if (flag <= 0) return;
|
||||
|
||||
taosSetDebugFlag(NULL, "debugFlag", flag, rewrite);
|
||||
taosSetDebugFlag(NULL, "simDebugFlag", flag, rewrite);
|
||||
taosSetDebugFlag(NULL, "tmrDebugFlag", flag, rewrite);
|
||||
taosSetDebugFlag(&uDebugFlag, "uDebugFlag", flag, rewrite);
|
||||
taosSetDebugFlag(&rpcDebugFlag, "rpcDebugFlag", flag, rewrite);
|
||||
taosSetDebugFlag(&jniDebugFlag, "jniDebugFlag", flag, rewrite);
|
||||
|
@ -1340,6 +1341,5 @@ void taosSetAllDebugFlag(int32_t flag, bool rewrite) {
|
|||
taosSetDebugFlag(&idxDebugFlag, "idxDebugFlag", flag, rewrite);
|
||||
taosSetDebugFlag(&tdbDebugFlag, "tdbDebugFlag", flag, rewrite);
|
||||
taosSetDebugFlag(&metaDebugFlag, "metaDebugFlag", flag, rewrite);
|
||||
taosSetDebugFlag(&metaDebugFlag, "tmrDebugFlag", flag, rewrite);
|
||||
uInfo("all debug flag are set to %d", flag);
|
||||
}
|
||||
|
|
|
@ -5424,6 +5424,7 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS
|
|||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||
}
|
||||
if (tEncodeI8(&encoder, pReq->createStb) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
|
@ -5484,6 +5485,7 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea
|
|||
}
|
||||
}
|
||||
}
|
||||
if (tDecodeI8(&decoder, &pReq->createStb) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
|
@ -5627,30 +5629,6 @@ int tDecodeSVCreateStbReq(SDecoder *pCoder, SVCreateStbReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
STSchema *tdGetSTSChemaFromSSChema(SSchema *pSchema, int32_t nCols, int32_t sver) {
|
||||
STSchemaBuilder schemaBuilder = {0};
|
||||
if (tdInitTSchemaBuilder(&schemaBuilder, sver) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nCols; i++) {
|
||||
SSchema *schema = pSchema + i;
|
||||
if (tdAddColToSchema(&schemaBuilder, schema->type, schema->flags, schema->colId, schema->bytes) < 0) {
|
||||
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
STSchema *pNSchema = tdGetSchemaFromBuilder(&schemaBuilder);
|
||||
if (pNSchema == NULL) {
|
||||
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||
return pNSchema;
|
||||
}
|
||||
|
||||
int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
|
@ -5728,6 +5706,25 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tDestroySVCreateTbReq(SVCreateTbReq *pReq, int32_t flags) {
|
||||
if (pReq == NULL) return;
|
||||
|
||||
if (flags & TSDB_MSG_FLG_ENCODE) {
|
||||
// TODO
|
||||
} else if (flags & TSDB_MSG_FLG_DECODE) {
|
||||
if (pReq->comment) {
|
||||
pReq->comment = NULL;
|
||||
taosMemoryFree(pReq->comment);
|
||||
}
|
||||
|
||||
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||
if (pReq->ctb.tagName) taosArrayDestroy(pReq->ctb.tagName);
|
||||
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
||||
if (pReq->ntb.schemaRow.pSchema) taosMemoryFree(pReq->ntb.schemaRow.pSchema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int tEncodeSVCreateTbBatchReq(SEncoder *pCoder, const SVCreateTbBatchReq *pReq) {
|
||||
int32_t nReq = taosArrayGetSize(pReq->pArray);
|
||||
|
||||
|
@ -6719,3 +6716,328 @@ int32_t tDecodeSBatchDeleteReq(SDecoder *pDecoder, SBatchDeleteReq *pReq) {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tEncodeSSubmitTbData(SEncoder *pCoder, const SSubmitTbData *pSubmitTbData) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32v(pCoder, pSubmitTbData->flags) < 0) return -1;
|
||||
|
||||
// auto create table
|
||||
if (pSubmitTbData->flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
|
||||
ASSERT(pSubmitTbData->pCreateTbReq);
|
||||
if (tEncodeSVCreateTbReq(pCoder, pSubmitTbData->pCreateTbReq) < 0) return -1;
|
||||
}
|
||||
|
||||
// submit data
|
||||
if (tEncodeI64(pCoder, pSubmitTbData->suid) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pSubmitTbData->uid) < 0) return -1;
|
||||
if (tEncodeI32v(pCoder, pSubmitTbData->sver) < 0) return -1;
|
||||
|
||||
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
uint64_t nColData = TARRAY_SIZE(pSubmitTbData->aCol);
|
||||
SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
|
||||
|
||||
if (tEncodeU64v(pCoder, nColData) < 0) return -1;
|
||||
|
||||
for (uint64_t i = 0; i < nColData; i++) {
|
||||
pCoder->pos += tPutColData(pCoder->data ? pCoder->data + pCoder->pos : NULL, &aColData[i]);
|
||||
}
|
||||
} else {
|
||||
if (tEncodeU64v(pCoder, TARRAY_SIZE(pSubmitTbData->aRowP)) < 0) return -1;
|
||||
|
||||
SRow **rows = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
|
||||
for (int32_t iRow = 0; iRow < TARRAY_SIZE(pSubmitTbData->aRowP); ++iRow) {
|
||||
if (pCoder->data) memcpy(pCoder->data + pCoder->pos, rows[iRow], rows[iRow]->len);
|
||||
pCoder->pos += rows[iRow]->len;
|
||||
}
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tDecodeSSubmitTbData(SDecoder *pCoder, SSubmitTbData *pSubmitTbData) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (tStartDecode(pCoder) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (tDecodeI32v(pCoder, &pSubmitTbData->flags) < 0) return -1;
|
||||
|
||||
if (pSubmitTbData->flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
|
||||
pSubmitTbData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
|
||||
if (pSubmitTbData->pCreateTbReq == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (tDecodeSVCreateTbReq(pCoder, pSubmitTbData->pCreateTbReq) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
// submit data
|
||||
if (tDecodeI64(pCoder, &pSubmitTbData->suid) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
if (tDecodeI64(pCoder, &pSubmitTbData->uid) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
if (tDecodeI32v(pCoder, &pSubmitTbData->sver) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
uint64_t nColData;
|
||||
|
||||
if (tDecodeU64v(pCoder, &nColData) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pSubmitTbData->aCol = taosArrayInit(nColData, sizeof(SColData));
|
||||
if (pSubmitTbData->aCol == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < nColData; ++i) {
|
||||
pCoder->pos += tGetColData(pCoder->data + pCoder->pos, taosArrayReserve(pSubmitTbData->aCol, 1));
|
||||
}
|
||||
} else {
|
||||
uint64_t nRow;
|
||||
if (tDecodeU64v(pCoder, &nRow) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pSubmitTbData->aRowP = taosArrayInit(nRow, sizeof(SRow *));
|
||||
if (pSubmitTbData->aRowP == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (int32_t iRow = 0; iRow < nRow; ++iRow) {
|
||||
SRow **ppRow = taosArrayReserve(pSubmitTbData->aRowP, 1);
|
||||
|
||||
*ppRow = (SRow *)(pCoder->data + pCoder->pos);
|
||||
pCoder->pos += (*ppRow)->len;
|
||||
}
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
// TODO: clear
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSSubmitReq2(SEncoder *pCoder, const SSubmitReq2 *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeU64v(pCoder, taosArrayGetSize(pReq->aSubmitTbData)) < 0) return -1;
|
||||
for (uint64_t i = 0; i < taosArrayGetSize(pReq->aSubmitTbData); i++) {
|
||||
if (tEncodeSSubmitTbData(pCoder, taosArrayGet(pReq->aSubmitTbData, i)) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSSubmitReq2(SDecoder *pCoder, SSubmitReq2 *pReq) {
|
||||
int32_t code = 0;
|
||||
|
||||
memset(pReq, 0, sizeof(*pReq));
|
||||
|
||||
// decode
|
||||
if (tStartDecode(pCoder) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
uint64_t nSubmitTbData;
|
||||
if (tDecodeU64v(pCoder, &nSubmitTbData) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pReq->aSubmitTbData = taosArrayInit(nSubmitTbData, sizeof(SSubmitTbData));
|
||||
if (pReq->aSubmitTbData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (uint64_t i = 0; i < nSubmitTbData; i++) {
|
||||
if (tDecodeSSubmitTbData(pCoder, taosArrayReserve(pReq->aSubmitTbData, 1)) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
if (pReq->aSubmitTbData) {
|
||||
// todo
|
||||
taosArrayDestroy(pReq->aSubmitTbData);
|
||||
pReq->aSubmitTbData = NULL;
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
void tDestroySSubmitTbData(SSubmitTbData *pTbData, int32_t flag) {
|
||||
if (NULL == pTbData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (flag == TSDB_MSG_FLG_ENCODE) {
|
||||
if (pTbData->pCreateTbReq) {
|
||||
tdDestroySVCreateTbReq(pTbData->pCreateTbReq);
|
||||
taosMemoryFree(pTbData->pCreateTbReq);
|
||||
}
|
||||
|
||||
if (pTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
int32_t nColData = TARRAY_SIZE(pTbData->aCol);
|
||||
SColData *aColData = (SColData *)TARRAY_DATA(pTbData->aCol);
|
||||
|
||||
for (int32_t i = 0; i < nColData; ++i) {
|
||||
tColDataDestroy(&aColData[i]);
|
||||
}
|
||||
taosArrayDestroy(pTbData->aCol);
|
||||
} else {
|
||||
int32_t nRow = TARRAY_SIZE(pTbData->aRowP);
|
||||
SRow **rows = (SRow **)TARRAY_DATA(pTbData->aRowP);
|
||||
|
||||
for (int32_t i = 0; i < nRow; ++i) {
|
||||
tRowDestroy(rows[i]);
|
||||
}
|
||||
taosArrayDestroy(pTbData->aRowP);
|
||||
}
|
||||
} else if (flag == TSDB_MSG_FLG_DECODE) {
|
||||
if (pTbData->pCreateTbReq) {
|
||||
tDestroySVCreateTbReq(pTbData->pCreateTbReq, TSDB_MSG_FLG_DECODE);
|
||||
taosMemoryFree(pTbData->pCreateTbReq);
|
||||
}
|
||||
|
||||
if (pTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
taosArrayDestroy(pTbData->aCol);
|
||||
} else {
|
||||
taosArrayDestroy(pTbData->aRowP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tDestroySSubmitReq2(SSubmitReq2 *pReq, int32_t flag) {
|
||||
if (pReq->aSubmitTbData == NULL) return;
|
||||
|
||||
int32_t nSubmitTbData = TARRAY_SIZE(pReq->aSubmitTbData);
|
||||
SSubmitTbData *aSubmitTbData = (SSubmitTbData *)TARRAY_DATA(pReq->aSubmitTbData);
|
||||
|
||||
for (int32_t i = 0; i < nSubmitTbData; i++) {
|
||||
tDestroySSubmitTbData(&aSubmitTbData[i], flag);
|
||||
}
|
||||
taosArrayDestroy(pReq->aSubmitTbData);
|
||||
}
|
||||
|
||||
int32_t tEncodeSSubmitRsp2(SEncoder *pCoder, const SSubmitRsp2 *pRsp) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32v(pCoder, pRsp->affectedRows) < 0) return -1;
|
||||
|
||||
if (tEncodeU64v(pCoder, taosArrayGetSize(pRsp->aCreateTbRsp)) < 0) return -1;
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pRsp->aCreateTbRsp); ++i) {
|
||||
if (tEncodeSVCreateTbRsp(pCoder, taosArrayGet(pRsp->aCreateTbRsp, i)) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSSubmitRsp2(SDecoder *pCoder, SSubmitRsp2 *pRsp) {
|
||||
int32_t code = 0;
|
||||
|
||||
memset(pRsp, 0, sizeof(SSubmitRsp2));
|
||||
|
||||
// decode
|
||||
if (tStartDecode(pCoder) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (tDecodeI32v(pCoder, &pRsp->affectedRows) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
uint64_t nCreateTbRsp;
|
||||
if (tDecodeU64v(pCoder, &nCreateTbRsp) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (nCreateTbRsp) {
|
||||
pRsp->aCreateTbRsp = taosArrayInit(nCreateTbRsp, sizeof(SVCreateTbRsp));
|
||||
if (pRsp->aCreateTbRsp == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < nCreateTbRsp; ++i) {
|
||||
SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pRsp->aCreateTbRsp, 1);
|
||||
if (tDecodeSVCreateTbRsp(pCoder, pCreateTbRsp) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
if (pRsp->aCreateTbRsp) {
|
||||
taosArrayDestroyEx(pRsp->aCreateTbRsp, NULL /* todo */);
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
void tDestroySSubmitRsp2(SSubmitRsp2 *pRsp, int32_t flag) {
|
||||
if (NULL == pRsp) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (flag & TSDB_MSG_FLG_ENCODE) {
|
||||
if (pRsp->aCreateTbRsp) {
|
||||
int32_t nCreateTbRsp = TARRAY_SIZE(pRsp->aCreateTbRsp);
|
||||
SVCreateTbRsp *aCreateTbRsp = TARRAY_DATA(pRsp->aCreateTbRsp);
|
||||
for (int32_t i = 0; i < nCreateTbRsp; ++i) {
|
||||
if (aCreateTbRsp[i].pMeta) {
|
||||
taosMemoryFree(aCreateTbRsp[i].pMeta);
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(pRsp->aCreateTbRsp);
|
||||
}
|
||||
} else if (flag & TSDB_MSG_FLG_DECODE) {
|
||||
if (pRsp->aCreateTbRsp) {
|
||||
int32_t nCreateTbRsp = TARRAY_SIZE(pRsp->aCreateTbRsp);
|
||||
SVCreateTbRsp *aCreateTbRsp = TARRAY_DATA(pRsp->aCreateTbRsp);
|
||||
for (int32_t i = 0; i < nCreateTbRsp; ++i) {
|
||||
if (aCreateTbRsp[i].pMeta) {
|
||||
taosMemoryFree(aCreateTbRsp[i].pMeta);
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(pRsp->aCreateTbRsp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,8 +298,8 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
}
|
||||
|
||||
static int compareKv(const void* p1, const void* p2) {
|
||||
SSmlKv* kv1 = *(SSmlKv**)p1;
|
||||
SSmlKv* kv2 = *(SSmlKv**)p2;
|
||||
SSmlKv* kv1 = (SSmlKv*)p1;
|
||||
SSmlKv* kv2 = (SSmlKv*)p2;
|
||||
int32_t kvLen1 = kv1->keyLen;
|
||||
int32_t kvLen2 = kv2->keyLen;
|
||||
int32_t res = strncasecmp(kv1->key, kv2->key, TMIN(kvLen1, kvLen2));
|
||||
|
@ -320,7 +320,7 @@ void buildChildTableName(RandTableName* rName) {
|
|||
taosArraySort(rName->tags, compareKv);
|
||||
for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) {
|
||||
taosStringBuilderAppendChar(&sb, ',');
|
||||
SSmlKv* tagKv = taosArrayGetP(rName->tags, j);
|
||||
SSmlKv* tagKv = taosArrayGet(rName->tags, j);
|
||||
taosStringBuilderAppendStringLen(&sb, tagKv->key, tagKv->keyLen);
|
||||
taosStringBuilderAppendChar(&sb, '=');
|
||||
if (IS_VAR_DATA_TYPE(tagKv->type)) {
|
||||
|
|
|
@ -117,7 +117,7 @@ STSchema *genSTSchema(int16_t nCols) {
|
|||
}
|
||||
|
||||
STSchema *pResult = NULL;
|
||||
pResult = tdGetSTSChemaFromSSChema(pSchema, nCols, 1);
|
||||
pResult = tBuildTSchema(pSchema, nCols, 1);
|
||||
|
||||
taosMemoryFree(pSchema);
|
||||
return pResult;
|
||||
|
|
|
@ -268,6 +268,11 @@ int mainWindows(int argc, char **argv) {
|
|||
|
||||
if (dmInit() != 0) {
|
||||
dError("failed to init dnode since %s", terrstr());
|
||||
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
taosConvDestroy();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,20 +26,20 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
typedef struct SVnodeMgmt {
|
||||
SDnodeData *pData;
|
||||
SMsgCb msgCb;
|
||||
const char *path;
|
||||
const char *name;
|
||||
SQWorkerPool queryPool;
|
||||
SQWorkerPool streamPool;
|
||||
SWWorkerPool fetchPool;
|
||||
SSingleWorker mgmtWorker;
|
||||
SHashObj *hash;
|
||||
TdThreadRwlock lock;
|
||||
SVnodesStat state;
|
||||
STfs *pTfs;
|
||||
TdThread thread;
|
||||
bool stop;
|
||||
SDnodeData *pData;
|
||||
SMsgCb msgCb;
|
||||
const char *path;
|
||||
const char *name;
|
||||
SQWorkerPool queryPool;
|
||||
SAutoQWorkerPool streamPool;
|
||||
SWWorkerPool fetchPool;
|
||||
SSingleWorker mgmtWorker;
|
||||
SHashObj *hash;
|
||||
TdThreadRwlock lock;
|
||||
SVnodesStat state;
|
||||
STfs *pTfs;
|
||||
TdThread thread;
|
||||
bool stop;
|
||||
} SVnodeMgmt;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -140,6 +140,12 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
|
|||
|
||||
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
if (pMsg->contLen < sizeof(SMsgHead)) {
|
||||
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
|
||||
pMsg->contLen);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
int32_t code = 0;
|
||||
|
||||
|
@ -233,6 +239,14 @@ int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
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);
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
||||
if (pMsg == NULL) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
|
@ -304,7 +318,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
(void)tMultiWorkerInit(&pVnode->pApplyW, &acfg);
|
||||
|
||||
pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
|
||||
pVnode->pStreamQ = tQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
|
||||
pVnode->pStreamQ = tAutoQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
|
||||
pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue);
|
||||
|
||||
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncCtrlW.queue == NULL ||
|
||||
|
@ -330,7 +344,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
|
||||
void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||
tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
|
||||
tQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
|
||||
tAutoQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
|
||||
tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
|
||||
pVnode->pQueryQ = NULL;
|
||||
pVnode->pStreamQ = NULL;
|
||||
|
@ -345,11 +359,10 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
|||
pQPool->max = tsNumOfVnodeQueryThreads;
|
||||
if (tQWorkerInit(pQPool) != 0) return -1;
|
||||
|
||||
SQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
||||
SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
||||
pStreamPool->name = "vnode-stream";
|
||||
pStreamPool->min = tsNumOfVnodeStreamThreads;
|
||||
pStreamPool->max = tsNumOfVnodeStreamThreads;
|
||||
if (tQWorkerInit(pStreamPool) != 0) return -1;
|
||||
pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
|
||||
if (tAutoQWorkerInit(pStreamPool) != 0) return -1;
|
||||
|
||||
SWWorkerPool *pFPool = &pMgmt->fetchPool;
|
||||
pFPool->name = "vnode-fetch";
|
||||
|
@ -371,7 +384,7 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
|||
|
||||
void vmStopWorker(SVnodeMgmt *pMgmt) {
|
||||
tQWorkerCleanup(&pMgmt->queryPool);
|
||||
tQWorkerCleanup(&pMgmt->streamPool);
|
||||
tAutoQWorkerCleanup(&pMgmt->streamPool);
|
||||
tWWorkerCleanup(&pMgmt->fetchPool);
|
||||
dDebug("vnode workers are closed");
|
||||
}
|
||||
|
|
|
@ -111,12 +111,12 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType));
|
||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||
goto _OVER;
|
||||
} /* else if ((pRpc->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRpc->code == TSDB_CODE_RPC_BROKEN_LINK) &&
|
||||
(!IsReq(pRpc)) && (pRpc->pCont == NULL)) {
|
||||
dGError("msg:%p, type:%s pCont is NULL, err: %s", pRpc, TMSG_INFO(pRpc->msgType), tstrerror(pRpc->code));
|
||||
terrno = pRpc->code;
|
||||
goto _OVER;
|
||||
}*/
|
||||
} else if ((pRpc->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRpc->code == TSDB_CODE_RPC_BROKEN_LINK) &&
|
||||
(!IsReq(pRpc)) && (pRpc->pCont == NULL)) {
|
||||
dGError("msg:%p, type:%s pCont is NULL, err: %s", pRpc, TMSG_INFO(pRpc->msgType), tstrerror(pRpc->code));
|
||||
terrno = pRpc->code;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (pHandle->defaultNtype == NODE_END) {
|
||||
dGError("msg:%p, type:%s not processed since no handle", pRpc, TMSG_INFO(pRpc->msgType));
|
||||
|
@ -248,8 +248,9 @@ static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) { rpcRe
|
|||
|
||||
static bool rpcRfp(int32_t code, tmsg_t msgType) {
|
||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_MNODE_NOT_FOUND ||
|
||||
code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_VND_STOPPED ||
|
||||
code == TSDB_CODE_APP_IS_STARTING || code == TSDB_CODE_APP_IS_STOPPING) {
|
||||
code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED || code == TSDB_CODE_SYN_NOT_LEADER ||
|
||||
code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_VND_STOPPED || code == TSDB_CODE_APP_IS_STARTING ||
|
||||
code == TSDB_CODE_APP_IS_STOPPING) {
|
||||
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH ||
|
||||
msgType == TDMT_SCH_MERGE_FETCH) {
|
||||
return false;
|
||||
|
|
|
@ -193,6 +193,7 @@ typedef struct {
|
|||
int64_t lastAccessTime;
|
||||
int32_t accessTimes;
|
||||
int32_t numOfVnodes;
|
||||
int32_t numOfOtherNodes;
|
||||
int32_t numOfSupportVnodes;
|
||||
float numOfCores;
|
||||
int64_t memTotal;
|
||||
|
|
|
@ -558,6 +558,10 @@ static int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
goto SUBSCRIBE_OVER;
|
||||
}
|
||||
|
||||
if (mndCheckTopicPrivilege(pMnode, pMsg->info.conn.user, MND_OPER_SUBSCRIBE, pTopic) != 0) {
|
||||
goto SUBSCRIBE_OVER;
|
||||
}
|
||||
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
}
|
||||
|
||||
|
|
|
@ -397,8 +397,6 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
|||
bool reboot = (pDnode->rebootTime != statusReq.rebootTime);
|
||||
bool needCheck = !online || dnodeChanged || reboot;
|
||||
|
||||
pDnode->accessTimes++;
|
||||
pDnode->lastAccessTime = curMs;
|
||||
const STraceId *trace = &pReq->info.traceId;
|
||||
mGTrace("dnode:%d, status received, accessTimes:%d check:%d online:%d reboot:%d changed:%d statusSeq:%d", pDnode->id,
|
||||
pDnode->accessTimes, needCheck, online, reboot, dnodeChanged, statusReq.statusSeq);
|
||||
|
@ -534,6 +532,8 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
|||
pReq->info.rsp = pHead;
|
||||
}
|
||||
|
||||
pDnode->accessTimes++;
|
||||
pDnode->lastAccessTime = curMs;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
|
|
@ -637,7 +637,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
|
|||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
// create stb for stream
|
||||
if (mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->info.conn.user) < 0) {
|
||||
if (createStreamReq.createStb == STREAM_CREATE_STABLE_TRUE && mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->info.conn.user) < 0) {
|
||||
mError("trans:%d, failed to create stb for stream %s since %s", pTrans->id, createStreamReq.name, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
goto _OVER;
|
||||
|
|
|
@ -696,14 +696,9 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
sdbRelease(pSdb, pConsumer);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (pTopic->refConsumerCnt != 0) {
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
mError("topic:%s, failed to drop since %s", dropReq.name, terrstr());
|
||||
if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_READ_DB, pTopic->db) != 0) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "drop-topic");
|
||||
if (pTrans == NULL) {
|
||||
|
|
|
@ -957,7 +957,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
for (int32_t i = 0; i < size; ++i) {
|
||||
SRpcHandleInfo *pInfo = taosArrayGet(pTrans->pRpcArray, i);
|
||||
if (pInfo->handle != NULL) {
|
||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED) {
|
||||
code = TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL;
|
||||
}
|
||||
if (code == TSDB_CODE_SYN_TIMEOUT) {
|
||||
|
|
|
@ -425,6 +425,7 @@ void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgOb
|
|||
static bool mndResetDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) {
|
||||
SDnodeObj *pDnode = pObj;
|
||||
pDnode->numOfVnodes = 0;
|
||||
pDnode->numOfOtherNodes = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -447,7 +448,7 @@ static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2
|
|||
pDnode->numOfVnodes, pDnode->numOfSupportVnodes, isMnode, online, pDnode->memAvail, pDnode->memUsed);
|
||||
|
||||
if (isMnode) {
|
||||
pDnode->numOfVnodes++;
|
||||
pDnode->numOfOtherNodes++;
|
||||
}
|
||||
|
||||
if (online && pDnode->numOfSupportVnodes > 0) {
|
||||
|
@ -468,14 +469,25 @@ SArray *mndBuildDnodesArray(SMnode *pMnode, int32_t exceptDnodeId) {
|
|||
|
||||
sdbTraverse(pSdb, SDB_DNODE, mndResetDnodesArrayFp, NULL, NULL, NULL);
|
||||
sdbTraverse(pSdb, SDB_DNODE, mndBuildDnodesArrayFp, pArray, &exceptDnodeId, NULL);
|
||||
|
||||
mDebug("build %d dnodes array", (int32_t)taosArrayGetSize(pArray));
|
||||
for (int32_t i = 0; i < (int32_t)taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mDebug("dnode:%d, vnodes:%d others:%d", pDnode->id, pDnode->numOfVnodes, pDnode->numOfOtherNodes);
|
||||
}
|
||||
return pArray;
|
||||
}
|
||||
|
||||
static int32_t mndCompareDnodeId(int32_t *dnode1Id, int32_t *dnode2Id) { return *dnode1Id >= *dnode2Id ? 1 : 0; }
|
||||
|
||||
static float mndGetDnodeScore(SDnodeObj *pDnode, int32_t additionDnodes, float ratio) {
|
||||
float totalDnodes = pDnode->numOfVnodes + (float)pDnode->numOfOtherNodes * ratio + additionDnodes;
|
||||
return totalDnodes / pDnode->numOfSupportVnodes;
|
||||
}
|
||||
|
||||
static int32_t mndCompareDnodeVnodes(SDnodeObj *pDnode1, SDnodeObj *pDnode2) {
|
||||
float d1Score = (float)pDnode1->numOfVnodes / pDnode1->numOfSupportVnodes;
|
||||
float d2Score = (float)pDnode2->numOfVnodes / pDnode2->numOfSupportVnodes;
|
||||
float d1Score = mndGetDnodeScore(pDnode1, 0, 0.9);
|
||||
float d2Score = mndGetDnodeScore(pDnode2, 0, 0.9);
|
||||
return d1Score >= d2Score ? 1 : 0;
|
||||
}
|
||||
|
||||
|
@ -494,7 +506,12 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup
|
|||
int32_t allocedVnodes = 0;
|
||||
void *pIter = NULL;
|
||||
|
||||
mDebug("start to sort %d dnodes", (int32_t)taosArrayGetSize(pArray));
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < (int32_t)taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mDebug("dnode:%d, score:%f", pDnode->id, mndGetDnodeScore(pDnode, 0, 0.9));
|
||||
}
|
||||
|
||||
int32_t size = taosArrayGetSize(pArray);
|
||||
if (size < pVgroup->replica) {
|
||||
|
@ -875,7 +892,7 @@ static int32_t mndAddVnodeToVgroup(SMnode *pMnode, STrans *pTrans, SVgObj *pVgro
|
|||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mInfo("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes);
|
||||
mInfo("dnode:%d, equivalent vnodes:%d others:%d", pDnode->id, pDnode->numOfVnodes, pDnode->numOfOtherNodes);
|
||||
}
|
||||
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[pVgroup->replica];
|
||||
|
@ -935,7 +952,7 @@ static int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, STrans *pTrans, SVgObj *
|
|||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mInfo("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes);
|
||||
mInfo("dnode:%d, equivalent vnodes:%d others:%d", pDnode->id, pDnode->numOfVnodes, pDnode->numOfOtherNodes);
|
||||
}
|
||||
|
||||
int32_t code = -1;
|
||||
|
@ -1970,16 +1987,16 @@ static int32_t mndBalanceVgroup(SMnode *pMnode, SRpcMsg *pReq, SArray *pArray) {
|
|||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mInfo("dnode:%d, equivalent vnodes:%d support:%d, score:%f", pDnode->id, pDnode->numOfVnodes,
|
||||
pDnode->numOfSupportVnodes, (float)pDnode->numOfVnodes / pDnode->numOfSupportVnodes);
|
||||
mInfo("dnode:%d, equivalent vnodes:%d others:%d support:%d, score:%f", pDnode->id, pDnode->numOfVnodes,
|
||||
pDnode->numOfSupportVnodes, pDnode->numOfOtherNodes, mndGetDnodeScore(pDnode, 0, 1));
|
||||
}
|
||||
|
||||
SDnodeObj *pSrc = taosArrayGet(pArray, taosArrayGetSize(pArray) - 1);
|
||||
SDnodeObj *pDst = taosArrayGet(pArray, 0);
|
||||
|
||||
float srcScore = (float)(pSrc->numOfVnodes - 1) / pSrc->numOfSupportVnodes;
|
||||
float dstScore = (float)(pDst->numOfVnodes + 1) / pDst->numOfSupportVnodes;
|
||||
mInfo("trans:%d, after balance, src dnode:%d score:%f, dst dnode:%d score:%f", pTrans->id, pSrc->id, srcScore,
|
||||
float srcScore = mndGetDnodeScore(pSrc, -1, 1);
|
||||
float dstScore = mndGetDnodeScore(pDst, 1, 1);
|
||||
mInfo("trans:%d, after balance, src dnode:%d score:%f, dst dnode:%d score:%f", pTrans->id, pSrc->id, dstScore,
|
||||
pDst->id, dstScore);
|
||||
|
||||
if (srcScore > dstScore - 0.000001) {
|
||||
|
|
|
@ -222,11 +222,19 @@ typedef struct SSnapContext {
|
|||
} SSnapContext;
|
||||
|
||||
typedef struct STqReader {
|
||||
int64_t ver;
|
||||
const SSubmitReq *pMsg;
|
||||
SSubmitBlk *pBlock;
|
||||
SSubmitMsgIter msgIter;
|
||||
SSubmitBlkIter blkIter;
|
||||
// const SSubmitReq *pMsg;
|
||||
// SSubmitBlk *pBlock;
|
||||
// SSubmitMsgIter msgIter;
|
||||
// SSubmitBlkIter blkIter;
|
||||
|
||||
int64_t ver;
|
||||
SPackedData msg2;
|
||||
|
||||
int8_t setMsg;
|
||||
SSubmitReq2 submit;
|
||||
int32_t nextBlk;
|
||||
|
||||
int64_t lastBlkUid;
|
||||
|
||||
SWalReader *pWalReader;
|
||||
|
||||
|
@ -251,11 +259,14 @@ int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
|
|||
int32_t tqSeekVer(STqReader *pReader, int64_t ver);
|
||||
int32_t tqNextBlock(STqReader *pReader, SFetchRet *ret);
|
||||
|
||||
int32_t tqReaderSetDataMsg(STqReader *pReader, const SSubmitReq *pMsg, int64_t ver);
|
||||
bool tqNextDataBlock(STqReader *pReader);
|
||||
bool tqNextDataBlockFilterOut(STqReader *pReader, SHashObj *filterOutUids);
|
||||
int32_t tqRetrieveDataBlock(SSDataBlock *pBlock, STqReader *pReader);
|
||||
int32_t tqRetrieveTaosxBlock(STqReader *pReader, SArray *blocks, SArray *schemas);
|
||||
int32_t tqReaderSetSubmitReq2(STqReader *pReader, void *msgStr, int32_t msgLen, int64_t ver);
|
||||
// int32_t tqReaderSetDataMsg(STqReader *pReader, const SSubmitReq *pMsg, int64_t ver);
|
||||
bool tqNextDataBlock2(STqReader *pReader);
|
||||
bool tqNextDataBlockFilterOut2(STqReader *pReader, SHashObj *filterOutUids);
|
||||
int32_t tqRetrieveDataBlock2(SSDataBlock *pBlock, STqReader *pReader);
|
||||
int32_t tqRetrieveTaosxBlock2(STqReader *pReader, SArray *blocks, SArray *schemas);
|
||||
// int32_t tqRetrieveDataBlock(SSDataBlock *pBlock, STqReader *pReader);
|
||||
// int32_t tqRetrieveTaosxBlock(STqReader *pReader, SArray *blocks, SArray *schemas);
|
||||
|
||||
int32_t vnodeEnqueueStreamMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
||||
|
||||
|
|
|
@ -154,7 +154,8 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
|
|||
int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum);
|
||||
|
||||
// tqExec
|
||||
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp* pRsp);
|
||||
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxRsp* pRsp);
|
||||
// int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp* pRsp);
|
||||
int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataRsp* pRsp, int32_t numOfCols, int8_t precision);
|
||||
int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp);
|
||||
int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry);
|
||||
|
@ -182,7 +183,8 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore);
|
|||
|
||||
// tqSink
|
||||
// void tqSinkToTableMerge(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
// void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
|
||||
// tqOffset
|
||||
char* tqOffsetBuildFName(const char* path, int32_t fVer);
|
||||
|
|
|
@ -70,6 +70,9 @@ typedef struct SDiskData SDiskData;
|
|||
typedef struct SDiskDataBuilder SDiskDataBuilder;
|
||||
typedef struct SBlkInfo SBlkInfo;
|
||||
|
||||
#define TSDBROW_ROW_FMT ((int8_t)0x0)
|
||||
#define TSDBROW_COL_FMT ((int8_t)0x1)
|
||||
|
||||
#define TSDB_FILE_DLMT ((uint32_t)0xF00AFA0F)
|
||||
#define TSDB_MAX_SUBBLOCKS 8
|
||||
#define TSDB_FHDR_SIZE 512
|
||||
|
@ -102,26 +105,29 @@ static FORCE_INLINE int64_t tsdbLogicToFileSize(int64_t lSize, int32_t szPage) {
|
|||
|
||||
// tsdbUtil.c ==============================================================================================
|
||||
// TSDBROW
|
||||
#define TSDBROW_TS(ROW) (((ROW)->type == 0) ? (ROW)->pTSRow->ts : (ROW)->pBlockData->aTSKEY[(ROW)->iRow])
|
||||
#define TSDBROW_VERSION(ROW) (((ROW)->type == 0) ? (ROW)->version : (ROW)->pBlockData->aVersion[(ROW)->iRow])
|
||||
#define TSDBROW_SVERSION(ROW) TD_ROW_SVER((ROW)->pTSRow)
|
||||
#define TSDBROW_KEY(ROW) ((TSDBKEY){.version = TSDBROW_VERSION(ROW), .ts = TSDBROW_TS(ROW)})
|
||||
#define tsdbRowFromTSRow(VERSION, TSROW) ((TSDBROW){.type = 0, .version = (VERSION), .pTSRow = (TSROW)})
|
||||
#define tsdbRowFromBlockData(BLOCKDATA, IROW) ((TSDBROW){.type = 1, .pBlockData = (BLOCKDATA), .iRow = (IROW)})
|
||||
void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||
// int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow);
|
||||
#define TSDBROW_TS(ROW) (((ROW)->type == TSDBROW_ROW_FMT) ? (ROW)->pTSRow->ts : (ROW)->pBlockData->aTSKEY[(ROW)->iRow])
|
||||
#define TSDBROW_VERSION(ROW) \
|
||||
(((ROW)->type == TSDBROW_ROW_FMT) ? (ROW)->version : (ROW)->pBlockData->aVersion[(ROW)->iRow])
|
||||
#define TSDBROW_SVERSION(ROW) ((ROW)->type == TSDBROW_ROW_FMT ? (ROW)->pTSRow->sver : -1)
|
||||
#define TSDBROW_KEY(ROW) ((TSDBKEY){.version = TSDBROW_VERSION(ROW), .ts = TSDBROW_TS(ROW)})
|
||||
#define tsdbRowFromTSRow(VERSION, TSROW) ((TSDBROW){.type = TSDBROW_ROW_FMT, .version = (VERSION), .pTSRow = (TSROW)})
|
||||
#define tsdbRowFromBlockData(BLOCKDATA, IROW) \
|
||||
((TSDBROW){.type = TSDBROW_COL_FMT, .pBlockData = (BLOCKDATA), .iRow = (IROW)})
|
||||
|
||||
void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||
int32_t tsdbRowCmprFn(const void *p1, const void *p2);
|
||||
// STSDBRowIter
|
||||
void tsdbRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
|
||||
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tsdbRowClose(STSDBRowIter *pIter);
|
||||
SColVal *tsdbRowIterNext(STSDBRowIter *pIter);
|
||||
// SRowMerger
|
||||
int32_t tRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema);
|
||||
int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||
int32_t tsdbRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema);
|
||||
int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||
|
||||
int32_t tRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tRowMergerClear(SRowMerger *pMerger);
|
||||
int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
|
||||
int32_t tRowMergerGetRow(SRowMerger *pMerger, STSRow **ppRow);
|
||||
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tsdbRowMergerClear(SRowMerger *pMerger);
|
||||
int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
|
||||
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow);
|
||||
// TABLEID
|
||||
int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
|
||||
// TSDBKEY
|
||||
|
@ -146,24 +152,22 @@ int32_t tGetBlockIdx(uint8_t *p, void *ph);
|
|||
int32_t tCmprBlockIdx(void const *lhs, void const *rhs);
|
||||
int32_t tCmprBlockL(void const *lhs, void const *rhs);
|
||||
// SBlockData
|
||||
#define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0)
|
||||
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
|
||||
#define tBlockDataFirstKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataFirstRow(PBLOCKDATA))
|
||||
#define tBlockDataLastKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataLastRow(PBLOCKDATA))
|
||||
#define tBlockDataFirstRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, 0)
|
||||
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
|
||||
#define tBlockDataFirstKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataFirstRow(PBLOCKDATA))
|
||||
#define tBlockDataLastKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataLastRow(PBLOCKDATA))
|
||||
#define tBlockDataGetColDataByIdx(PBLOCKDATA, IDX) (&(PBLOCKDATA)->aColData[IDX])
|
||||
|
||||
int32_t tBlockDataCreate(SBlockData *pBlockData);
|
||||
void tBlockDataDestroy(SBlockData *pBlockData, int8_t deepClear);
|
||||
int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, int16_t *aCid, int32_t nCid);
|
||||
void tBlockDataReset(SBlockData *pBlockData);
|
||||
int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid);
|
||||
void tBlockDataClear(SBlockData *pBlockData);
|
||||
SColData *tBlockDataGetColDataByIdx(SBlockData *pBlockData, int32_t idx);
|
||||
void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData);
|
||||
int32_t tBlockDataMerge(SBlockData *pBlockData1, SBlockData *pBlockData2, SBlockData *pBlockData);
|
||||
int32_t tBlockDataAddColData(SBlockData *pBlockData, SColData **ppColData);
|
||||
int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut, int32_t *szOut, uint8_t *aBuf[],
|
||||
int32_t aBufN[]);
|
||||
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]);
|
||||
int32_t tBlockDataCreate(SBlockData *pBlockData);
|
||||
void tBlockDataDestroy(SBlockData *pBlockData);
|
||||
int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, int16_t *aCid, int32_t nCid);
|
||||
void tBlockDataReset(SBlockData *pBlockData);
|
||||
int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid);
|
||||
void tBlockDataClear(SBlockData *pBlockData);
|
||||
void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData);
|
||||
int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut, int32_t *szOut, uint8_t *aBuf[],
|
||||
int32_t aBufN[]);
|
||||
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]);
|
||||
// SDiskDataHdr
|
||||
int32_t tPutDiskDataHdr(uint8_t *p, const SDiskDataHdr *pHdr);
|
||||
int32_t tGetDiskDataHdr(uint8_t *p, void *ph);
|
||||
|
@ -335,10 +339,13 @@ struct SVersionRange {
|
|||
typedef struct SMemSkipListNode SMemSkipListNode;
|
||||
struct SMemSkipListNode {
|
||||
int8_t level;
|
||||
int8_t flag; // TSDBROW_ROW_FMT for row format, TSDBROW_COL_FMT for col format
|
||||
int32_t iRow;
|
||||
int64_t version;
|
||||
STSRow *pTSRow;
|
||||
void *pData;
|
||||
SMemSkipListNode *forwards[0];
|
||||
};
|
||||
|
||||
typedef struct SMemSkipList {
|
||||
int64_t size;
|
||||
uint32_t seed;
|
||||
|
@ -376,11 +383,11 @@ struct SMemTable {
|
|||
};
|
||||
|
||||
struct TSDBROW {
|
||||
int8_t type; // 0 for row from tsRow, 1 for row from block data
|
||||
int8_t type; // TSDBROW_ROW_FMT for row from tsRow, TSDBROW_COL_FMT for row from block data
|
||||
union {
|
||||
struct {
|
||||
int64_t version;
|
||||
STSRow *pTSRow;
|
||||
SRow *pTSRow;
|
||||
};
|
||||
struct {
|
||||
SBlockData *pBlockData;
|
||||
|
@ -466,14 +473,14 @@ struct SSttBlk {
|
|||
// (SBlockData){.suid = suid, .uid = 0}: block data for N child tables int .last file
|
||||
// (SBlockData){.suid = 0, .uid = uid}: block data for 1 normal table int .last/.data file
|
||||
struct SBlockData {
|
||||
int64_t suid; // 0 means normal table block data, otherwise child table block data
|
||||
int64_t uid; // 0 means block data in .last file, otherwise in .data file
|
||||
int32_t nRow; // number of rows
|
||||
int64_t *aUid; // uids of each row, only exist in block data in .last file (uid == 0)
|
||||
int64_t *aVersion; // versions of each row
|
||||
TSKEY *aTSKEY; // timestamp of each row
|
||||
int32_t nColData;
|
||||
SArray *aColData; // SArray<SColData>
|
||||
int64_t suid; // 0 means normal table block data, otherwise child table block data
|
||||
int64_t uid; // 0 means block data in .last file, otherwise in .data file
|
||||
int32_t nRow; // number of rows
|
||||
int64_t *aUid; // uids of each row, only exist in block data in .last file (uid == 0)
|
||||
int64_t *aVersion; // versions of each row
|
||||
TSKEY *aTSKEY; // timestamp of each row
|
||||
int32_t nColData;
|
||||
SColData *aColData;
|
||||
};
|
||||
|
||||
struct TABLEID {
|
||||
|
@ -565,10 +572,14 @@ struct SDFileSet {
|
|||
};
|
||||
|
||||
struct STSDBRowIter {
|
||||
TSDBROW *pRow;
|
||||
STSchema *pTSchema;
|
||||
SColVal colVal;
|
||||
int32_t i;
|
||||
TSDBROW *pRow;
|
||||
union {
|
||||
SRowIter *pIter;
|
||||
struct {
|
||||
int32_t iColData;
|
||||
SColVal cv;
|
||||
};
|
||||
};
|
||||
};
|
||||
struct SRowMerger {
|
||||
STSchema *pTSchema;
|
||||
|
@ -739,8 +750,8 @@ typedef struct {
|
|||
|
||||
int32_t tsdbOpenCache(STsdb *pTsdb);
|
||||
void tsdbCloseCache(STsdb *pTsdb);
|
||||
int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb *pTsdb);
|
||||
int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, STSRow *row, bool dup);
|
||||
int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, TSDBROW *row, STsdb *pTsdb);
|
||||
int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, TSDBROW *row, bool dup);
|
||||
int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *pr, LRUHandle **h);
|
||||
int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *pr, LRUHandle **h);
|
||||
int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h);
|
||||
|
@ -752,6 +763,8 @@ int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
|
|||
void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity);
|
||||
size_t tsdbCacheGetCapacity(SVnode *pVnode);
|
||||
|
||||
// int32_t tsdbCacheLastArray2Row(SArray *pLastArray, STSRow **ppRow, STSchema *pSchema);
|
||||
|
||||
// ========== inline functions ==========
|
||||
static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
|
||||
TSDBKEY *pKey1 = (TSDBKEY *)p1;
|
||||
|
@ -793,8 +806,13 @@ static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
|
|||
}
|
||||
|
||||
pIter->pRow = &pIter->row;
|
||||
pIter->pRow->version = pIter->pNode->version;
|
||||
pIter->pRow->pTSRow = pIter->pNode->pTSRow;
|
||||
if (pIter->pNode->flag == TSDBROW_ROW_FMT) {
|
||||
pIter->row = tsdbRowFromTSRow(pIter->pNode->version, pIter->pNode->pData);
|
||||
} else if (pIter->pNode->flag == TSDBROW_COL_FMT) {
|
||||
pIter->row = tsdbRowFromBlockData(pIter->pNode->pData, pIter->pNode->iRow);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
return pIter->pRow;
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ typedef struct SCommitInfo SCommitInfo;
|
|||
#define VND_INFO_FNAME "vnode.json"
|
||||
|
||||
// vnd.h
|
||||
|
||||
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
|
||||
void* vnodeBufPoolMallocAligned(SVBufPool* pPool, int size);
|
||||
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
|
||||
|
@ -162,10 +163,9 @@ int32_t tsdbCommit(STsdb* pTsdb, SCommitInfo* pInfo);
|
|||
int32_t tsdbFinishCommit(STsdb* pTsdb);
|
||||
int32_t tsdbRollbackCommit(STsdb* pTsdb);
|
||||
int32_t tsdbDoRetention(STsdb* pTsdb, int64_t now);
|
||||
int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg);
|
||||
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp);
|
||||
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock,
|
||||
SSubmitBlkRsp* pRsp);
|
||||
int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq2* pMsg);
|
||||
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq2* pMsg, SSubmitRsp2* pRsp);
|
||||
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitTbData* pSubmitTbData, int32_t* affectedRows);
|
||||
int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
|
||||
int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg);
|
||||
|
||||
|
@ -190,7 +190,7 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t version, char* msg, int32_t msg
|
|||
int32_t tqProcessTaskDropReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg);
|
||||
int32_t tqProcessStreamTaskCheckRsp(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* data, int64_t ver);
|
||||
int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit);
|
||||
int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver);
|
||||
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg);
|
||||
int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec);
|
||||
|
@ -203,9 +203,9 @@ int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, SRpcMsg* pMsg);
|
|||
int32_t tqProcessTaskRecoverFinishRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||
int32_t tqCheckLogInWal(STQ* pTq, int64_t version);
|
||||
|
||||
SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema,
|
||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||
SBatchDeleteReq* pDeleteReq);
|
||||
int32_t tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema,
|
||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||
SBatchDeleteReq* pDeleteReq, void** ppData, int32_t* pLen);
|
||||
|
||||
// sma
|
||||
int32_t smaInit();
|
||||
|
@ -223,7 +223,7 @@ int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg);
|
|||
int32_t tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg);
|
||||
|
||||
int32_t tdProcessRSmaCreate(SSma* pSma, SVCreateStbReq* pReq);
|
||||
int32_t tdProcessRSmaSubmit(SSma* pSma, void* pMsg, int32_t inputType);
|
||||
int32_t tdProcessRSmaSubmit(SSma* pSma, int64_t version, void* pReq, void* pMsg, int32_t len, int32_t inputType);
|
||||
int32_t tdProcessRSmaDrop(SSma* pSma, SVDropStbReq* pReq);
|
||||
int32_t tdFetchTbUidList(SSma* pSma, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
|
||||
int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore, bool isAdd);
|
||||
|
|
|
@ -57,7 +57,6 @@ struct SMetaCache {
|
|||
TdThreadMutex lock;
|
||||
SHashObj* pTableEntry;
|
||||
SLRUCache* pUidResCache;
|
||||
uint64_t keyBuf[3];
|
||||
} sTagFilterResCache;
|
||||
};
|
||||
|
||||
|
@ -211,7 +210,7 @@ _exit:
|
|||
int32_t metaCacheUpsert(SMeta* pMeta, SMetaInfo* pInfo) {
|
||||
int32_t code = 0;
|
||||
|
||||
// ASSERT(metaIsWLocked(pMeta));
|
||||
// meta is wlocked for calling this func.
|
||||
|
||||
// search
|
||||
SMetaCache* pCache = pMeta->pCache;
|
||||
|
@ -222,7 +221,10 @@ int32_t metaCacheUpsert(SMeta* pMeta, SMetaInfo* pInfo) {
|
|||
}
|
||||
|
||||
if (*ppEntry) { // update
|
||||
ASSERT(pInfo->suid == (*ppEntry)->info.suid);
|
||||
if (pInfo->suid != (*ppEntry)->info.suid) {
|
||||
metaError("meta/cache: suid should be same as the one in cache.");
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (pInfo->version > (*ppEntry)->info.version) {
|
||||
(*ppEntry)->info.version = pInfo->version;
|
||||
(*ppEntry)->info.skmVer = pInfo->skmVer;
|
||||
|
@ -341,7 +343,7 @@ _exit:
|
|||
int32_t metaStatsCacheUpsert(SMeta* pMeta, SMetaStbStats* pInfo) {
|
||||
int32_t code = 0;
|
||||
|
||||
// ASSERT(metaIsWLocked(pMeta));
|
||||
// meta is wlocked for calling this func.
|
||||
|
||||
// search
|
||||
SMetaCache* pCache = pMeta->pCache;
|
||||
|
@ -429,20 +431,20 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
|
|||
bool* acquireRes) {
|
||||
// generate the composed key for LRU cache
|
||||
SLRUCache* pCache = pMeta->pCache->sTagFilterResCache.pUidResCache;
|
||||
uint64_t* pBuf = pMeta->pCache->sTagFilterResCache.keyBuf;
|
||||
SHashObj* pTableMap = pMeta->pCache->sTagFilterResCache.pTableEntry;
|
||||
TdThreadMutex* pLock = &pMeta->pCache->sTagFilterResCache.lock;
|
||||
|
||||
uint64_t buf[3] = {0};
|
||||
uint32_t times = 0;
|
||||
|
||||
*acquireRes = 0;
|
||||
pBuf[0] = suid;
|
||||
memcpy(&pBuf[1], pKey, keyLen);
|
||||
buf[0] = suid;
|
||||
memcpy(&buf[1], pKey, keyLen);
|
||||
|
||||
taosThreadMutexLock(pLock);
|
||||
|
||||
int32_t len = keyLen + sizeof(uint64_t);
|
||||
LRUHandle* pHandle = taosLRUCacheLookup(pCache, pBuf, len);
|
||||
LRUHandle* pHandle = taosLRUCacheLookup(pCache, buf, len);
|
||||
if (pHandle == NULL) {
|
||||
taosThreadMutexUnlock(pLock);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -450,7 +452,11 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
|
|||
|
||||
// do some book mark work after acquiring the filter result from cache
|
||||
STagFilterResEntry** pEntry = taosHashGet(pTableMap, &suid, sizeof(uint64_t));
|
||||
ASSERT(pEntry != NULL);
|
||||
if (NULL == pEntry) {
|
||||
metaError("meta/cache: pEntry should not be NULL.");
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
*acquireRes = 1;
|
||||
|
||||
const char* p = taosLRUCacheValue(pCache, pHandle);
|
||||
|
@ -476,10 +482,10 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
|
|||
|
||||
SListNode* pNode = NULL;
|
||||
while ((pNode = tdListNext(&iter)) != NULL) {
|
||||
memcpy(&pBuf[1], pNode->data, keyLen);
|
||||
memcpy(&buf[1], pNode->data, keyLen);
|
||||
|
||||
// check whether it is existed in LRU cache, and remove it from linked list if not.
|
||||
LRUHandle* pRes = taosLRUCacheLookup(pCache, pBuf, len);
|
||||
LRUHandle* pRes = taosLRUCacheLookup(pCache, buf, len);
|
||||
if (pRes == NULL) { // remove the item in the linked list
|
||||
taosArrayPush(pInvalidRes, &pNode);
|
||||
} else {
|
||||
|
@ -495,7 +501,7 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
|
|||
taosMemoryFree(*p1);
|
||||
}
|
||||
|
||||
atomic_store_32(&(*pEntry)->qTimes, 0); // reset the query times
|
||||
atomic_store_32(&(*pEntry)->qTimes, 0); // reset the query times
|
||||
taosArrayDestroy(pInvalidRes);
|
||||
|
||||
taosThreadMutexUnlock(pLock);
|
||||
|
@ -547,14 +553,17 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
|
|||
tdListAppend(&(*pEntry)->list, pKey);
|
||||
}
|
||||
|
||||
uint64_t* pBuf = pMeta->pCache->sTagFilterResCache.keyBuf;
|
||||
pBuf[0] = suid;
|
||||
uint64_t buf[3] = {0};
|
||||
buf[0] = suid;
|
||||
|
||||
memcpy(&pBuf[1], pKey, keyLen);
|
||||
ASSERT(sizeof(uint64_t) + keyLen == 24);
|
||||
memcpy(&buf[1], pKey, keyLen);
|
||||
if (sizeof(uint64_t) + keyLen != 24) {
|
||||
metaError("meta/cache: incorrect keyLen:%" PRId32 " length.", keyLen);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// add to cache.
|
||||
taosLRUCacheInsert(pCache, pBuf, sizeof(uint64_t) + keyLen, pPayload, payloadLen, freePayload, NULL,
|
||||
taosLRUCacheInsert(pCache, buf, sizeof(uint64_t) + keyLen, pPayload, payloadLen, freePayload, NULL,
|
||||
TAOS_LRU_PRIORITY_LOW);
|
||||
|
||||
taosThreadMutexUnlock(pLock);
|
||||
|
|
|
@ -51,7 +51,9 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
|
|||
} else if (pME->type == TSDB_TSMA_TABLE) {
|
||||
if (tEncodeTSma(pCoder, pME->smaEntry.tsma) < 0) return -1;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
metaError("meta/entry: invalide table type: %" PRId8 " encode failed.", pME->type);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
|
@ -99,7 +101,9 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
|
|||
}
|
||||
if (tDecodeTSma(pCoder, pME->smaEntry.tsma, true) < 0) return -1;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
metaError("meta/entry: invalide table type: %" PRId8 " decode failed.", pME->type);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
|
|
|
@ -358,7 +358,10 @@ static int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
|
|||
return -1;
|
||||
}
|
||||
|
||||
ASSERT(pTagIdxKey1->type == pTagIdxKey2->type);
|
||||
if (pTagIdxKey1->type != pTagIdxKey2->type) {
|
||||
metaError("meta/open: incorrect tag idx type.");
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// check NULL, NULL is always the smallest
|
||||
if (pTagIdxKey1->isNull && !pTagIdxKey2->isNull) {
|
||||
|
|
|
@ -611,23 +611,14 @@ tb_uid_t metaStbCursorNext(SMStbCursor *pStbCur) {
|
|||
}
|
||||
|
||||
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock) {
|
||||
// SMetaReader mr = {0};
|
||||
STSchema *pTSchema = NULL;
|
||||
SSchemaWrapper *pSW = NULL;
|
||||
STSchemaBuilder sb = {0};
|
||||
SSchema *pSchema;
|
||||
SSchema *pSchema = NULL;
|
||||
|
||||
pSW = metaGetTableSchema(pMeta, uid, sver, lock);
|
||||
if (!pSW) return NULL;
|
||||
|
||||
tdInitTSchemaBuilder(&sb, pSW->version);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
pSchema = pSW->pSchema + i;
|
||||
tdAddColToSchema(&sb, pSchema->type, pSchema->flags, pSchema->colId, pSchema->bytes);
|
||||
}
|
||||
pTSchema = tdGetSchemaFromBuilder(&sb);
|
||||
|
||||
tdDestroyTSchemaBuilder(&sb);
|
||||
pTSchema = tBuildTSchema(pSW->pSchema, pSW->nCols, pSW->version);
|
||||
|
||||
taosMemoryFree(pSW->pSchema);
|
||||
taosMemoryFree(pSW);
|
||||
|
@ -661,7 +652,11 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
ASSERT(c);
|
||||
if (c == 0) {
|
||||
metaError("meta/query: incorrect c: %" PRId32 ".", c);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (c < 0) {
|
||||
tdbTbcMoveToPrev(pSkmDbC);
|
||||
|
@ -685,7 +680,11 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv
|
|||
}
|
||||
}
|
||||
|
||||
ASSERT(sver > 0);
|
||||
if (sver <= 0) {
|
||||
metaError("meta/query: incorrect sver: %" PRId32 ".", sver);
|
||||
code = TSDB_CODE_FAILED;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
skmDbKey.uid = suid ? suid : uid;
|
||||
skmDbKey.sver = sver;
|
||||
|
@ -708,21 +707,11 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv
|
|||
tdbFree(pData);
|
||||
|
||||
// convert
|
||||
STSchemaBuilder sb = {0};
|
||||
|
||||
tdInitTSchemaBuilder(&sb, pSchemaWrapper->version);
|
||||
for (int i = 0; i < pSchemaWrapper->nCols; i++) {
|
||||
SSchema *pSchema = pSchemaWrapper->pSchema + i;
|
||||
tdAddColToSchema(&sb, pSchema->type, pSchema->flags, pSchema->colId, pSchema->bytes);
|
||||
}
|
||||
|
||||
STSchema *pTSchema = tdGetSchemaFromBuilder(&sb);
|
||||
STSchema *pTSchema = tBuildTSchema(pSchemaWrapper->pSchema, pSchemaWrapper->nCols, pSchemaWrapper->version);
|
||||
if (pTSchema == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
tdDestroyTSchemaBuilder(&sb);
|
||||
|
||||
*ppTSchema = pTSchema;
|
||||
taosMemoryFree(pSchemaWrapper->pSchema);
|
||||
|
||||
|
|
|
@ -100,7 +100,10 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) {
|
|||
break;
|
||||
}
|
||||
|
||||
ASSERT(pData && nData);
|
||||
if (!pData || !nData) {
|
||||
metaError("meta/snap: invalide nData: %" PRId32 " meta snap read failed.", nData);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
*ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + nData);
|
||||
if (*ppData == NULL) {
|
||||
|
@ -113,8 +116,8 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) {
|
|||
pHdr->size = nData;
|
||||
memcpy(pHdr->data, pData, nData);
|
||||
|
||||
metaInfo("vgId:%d, vnode snapshot meta read data, version:%" PRId64 " uid:%" PRId64 " nData:%d",
|
||||
TD_VID(pReader->pMeta->pVnode), key.version, key.uid, nData);
|
||||
metaDebug("vgId:%d, vnode snapshot meta read data, version:%" PRId64 " uid:%" PRId64 " blockLen:%d",
|
||||
TD_VID(pReader->pMeta->pVnode), key.version, key.uid, nData);
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
|
@ -356,7 +359,11 @@ int32_t buildSnapContext(SMeta* pMeta, int64_t snapVersion, int64_t suid, int8_t
|
|||
for (int i = 0; i < taosArrayGetSize(ctx->idList); i++) {
|
||||
int64_t* uid = taosArrayGet(ctx->idList, i);
|
||||
SIdInfo* idData = (SIdInfo*)taosHashGet(ctx->idVersion, uid, sizeof(int64_t));
|
||||
ASSERT(idData);
|
||||
if (!idData) {
|
||||
metaError("meta/snap: null idData");
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
idData->index = i;
|
||||
metaDebug("tmqsnap init idVersion uid:%" PRIi64 " version:%" PRIi64 " index:%d", *uid, idData->version,
|
||||
idData->index);
|
||||
|
@ -473,7 +480,10 @@ int32_t getMetafromSnapShot(SSnapContext* ctx, void** pBuf, int32_t* contLen, in
|
|||
int64_t* uidTmp = taosArrayGet(ctx->idList, ctx->index);
|
||||
ctx->index++;
|
||||
SIdInfo* idInfo = (SIdInfo*)taosHashGet(ctx->idVersion, uidTmp, sizeof(tb_uid_t));
|
||||
ASSERT(idInfo);
|
||||
if (!idInfo) {
|
||||
metaError("meta/snap: null idInfo");
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
*uid = *uidTmp;
|
||||
ret = MoveToPosition(ctx, idInfo->version, *uidTmp);
|
||||
|
@ -507,7 +517,11 @@ int32_t getMetafromSnapShot(SSnapContext* ctx, void** pBuf, int32_t* contLen, in
|
|||
(ctx->subType == TOPIC_SUB_TYPE__TABLE && me.type == TSDB_CHILD_TABLE && me.ctbEntry.suid == ctx->suid)) {
|
||||
STableInfoForChildTable* data =
|
||||
(STableInfoForChildTable*)taosHashGet(ctx->suidInfo, &me.ctbEntry.suid, sizeof(tb_uid_t));
|
||||
ASSERT(data);
|
||||
if (!data) {
|
||||
metaError("meta/snap: null data");
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SVCreateTbReq req = {0};
|
||||
|
||||
req.type = TSDB_CHILD_TABLE;
|
||||
|
@ -528,7 +542,8 @@ int32_t getMetafromSnapShot(SSnapContext* ctx, void** pBuf, int32_t* contLen, in
|
|||
} else {
|
||||
SArray* pTagVals = NULL;
|
||||
if (tTagToValArray((const STag*)p, &pTagVals) != 0) {
|
||||
ASSERT(0);
|
||||
metaError("meta/snap: tag to val array failed.");
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int16_t nCols = taosArrayGetSize(pTagVals);
|
||||
for (int j = 0; j < nCols; ++j) {
|
||||
|
@ -572,7 +587,8 @@ int32_t getMetafromSnapShot(SSnapContext* ctx, void** pBuf, int32_t* contLen, in
|
|||
ret = buildNormalChildTableInfo(&req, pBuf, contLen);
|
||||
*type = TDMT_VND_CREATE_TABLE;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
metaError("meta/snap: invalid topic sub type: %" PRId8 " get meta from snap failed.", ctx->subType);
|
||||
ret = -1;
|
||||
}
|
||||
tDecoderClear(&dc);
|
||||
|
||||
|
@ -593,7 +609,10 @@ SMetaTableInfo getUidfromSnapShot(SSnapContext* ctx) {
|
|||
int64_t* uidTmp = taosArrayGet(ctx->idList, ctx->index);
|
||||
ctx->index++;
|
||||
SIdInfo* idInfo = (SIdInfo*)taosHashGet(ctx->idVersion, uidTmp, sizeof(tb_uid_t));
|
||||
ASSERT(idInfo);
|
||||
if (!idInfo) {
|
||||
metaError("meta/snap: null idInfo");
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t ret = MoveToPosition(ctx, idInfo->version, *uidTmp);
|
||||
if (ret != 0) {
|
||||
|
|
|
@ -46,7 +46,7 @@ static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
|||
pInfo->suid = 0;
|
||||
pInfo->skmVer = pEntry->ntbEntry.schemaRow.version;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
metaError("meta/table: invalide table type: %" PRId8 " get entry info failed.", pEntry->type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,10 +342,18 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
|
||||
tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL);
|
||||
ret = tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = pReq->suid, .version = oversion}), sizeof(STbDbKey), &c);
|
||||
ASSERT(ret == 0 && c == 0);
|
||||
if (!(ret == 0 && c == 0)) {
|
||||
metaError("meta/table: invalide ret: %" PRId32 " or c: %" PRId32 "alter stb failed.", ret, c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
ASSERT(ret == 0);
|
||||
if (ret < 0) {
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
||||
terrno = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
oStbEntry.pBuf = taosMemoryMalloc(nData);
|
||||
memcpy(oStbEntry.pBuf, pData, nData);
|
||||
|
@ -558,7 +566,8 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME) {
|
|||
ctime = pME->ntbEntry.ctime;
|
||||
ttlDays = pME->ntbEntry.ttlDays;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
metaError("meta/table: invalide table type: %" PRId8 " build ttl idx key failed.", pME->type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ttlDays <= 0) return;
|
||||
|
@ -773,7 +782,10 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
|
||||
tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL);
|
||||
tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
||||
ASSERT(c == 0);
|
||||
if (c != 0) {
|
||||
metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
oversion = ((SUidIdxVal *)pData)[0].version;
|
||||
|
@ -783,7 +795,11 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
|
||||
tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL);
|
||||
tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c);
|
||||
ASSERT(c == 0);
|
||||
if (c != 0) {
|
||||
metaError("meta/table: invalide c: %" PRId32 " alt tb column failed.", c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
||||
// get table entry
|
||||
|
@ -792,7 +808,11 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
memcpy(entry.pBuf, pData, nData);
|
||||
tDecoderInit(&dc, entry.pBuf, nData);
|
||||
ret = metaDecodeEntry(&dc, &entry);
|
||||
ASSERT(ret == 0);
|
||||
if (ret != 0) {
|
||||
tDecoderClear(&dc);
|
||||
metaError("meta/table: invalide ret: %" PRId32 " alt tb column failed.", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (entry.type != TSDB_NORMAL_TABLE) {
|
||||
terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
|
||||
|
@ -812,7 +832,11 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
if (iCol >= pSchema->nCols) break;
|
||||
pColumn = &pSchema->pSchema[iCol];
|
||||
|
||||
ASSERT(pAlterTbReq->colName);
|
||||
if (NULL == pAlterTbReq->colName) {
|
||||
metaError("meta/table: null pAlterTbReq->colName");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp(pColumn->name, pAlterTbReq->colName) == 0) break;
|
||||
iCol++;
|
||||
}
|
||||
|
@ -964,7 +988,10 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
|
||||
tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL);
|
||||
tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
||||
ASSERT(c == 0);
|
||||
if (c != 0) {
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
oversion = ((SUidIdxVal *)pData)[0].version;
|
||||
|
@ -977,7 +1004,11 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
/* get ctbEntry */
|
||||
tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL);
|
||||
tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c);
|
||||
ASSERT(c == 0);
|
||||
if (c != 0) {
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
||||
ctbEntry.pBuf = taosMemoryMalloc(nData);
|
||||
|
@ -1075,7 +1106,11 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
metaUpdateTagIdx(pMeta, &ctbEntry);
|
||||
}
|
||||
|
||||
ASSERT(ctbEntry.ctbEntry.pTags);
|
||||
if (NULL == ctbEntry.ctbEntry.pTags) {
|
||||
metaError("meta/table: null tags, update tag val failed.");
|
||||
goto _err;
|
||||
}
|
||||
|
||||
SCtbIdxKey ctbIdxKey = {.suid = ctbEntry.ctbEntry.suid, .uid = uid};
|
||||
tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags,
|
||||
((STag *)(ctbEntry.ctbEntry.pTags))->len, pMeta->txn);
|
||||
|
@ -1130,7 +1165,10 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
|
||||
tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL);
|
||||
tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
||||
ASSERT(c == 0);
|
||||
if (c != 0) {
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
oversion = ((SUidIdxVal *)pData)[0].version;
|
||||
|
@ -1140,7 +1178,11 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
|
||||
tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL);
|
||||
tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c);
|
||||
ASSERT(c == 0);
|
||||
if (c != 0) {
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
|
||||
// get table entry
|
||||
|
@ -1149,7 +1191,11 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
memcpy(entry.pBuf, pData, nData);
|
||||
tDecoderInit(&dc, entry.pBuf, nData);
|
||||
ret = metaDecodeEntry(&dc, &entry);
|
||||
ASSERT(ret == 0);
|
||||
if (ret != 0) {
|
||||
tDecoderClear(&dc);
|
||||
metaError("meta/table: invalide ret: %" PRId32 " alt tb options failed.", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
entry.version = version;
|
||||
metaWLock(pMeta);
|
||||
|
@ -1408,7 +1454,8 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
pSW = &pME->ntbEntry.schemaRow;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
metaError("meta/table: invalide table type: %" PRId8 " save skm db failed.", pME->type);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
skmDbKey.uid = pME->uid;
|
||||
|
|
|
@ -563,8 +563,8 @@ static int32_t tdProcessSubmitReq(STsdb *pTsdb, int64_t version, void *pReq) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
||||
// TODO: spin lock for race condition
|
||||
SSubmitReq2 *pSubmitReq = (SSubmitReq2 *)pReq;
|
||||
// spin lock for race condition during insert data
|
||||
if (tsdbInsertData(pTsdb, version, pSubmitReq, NULL) < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -572,29 +572,19 @@ static int32_t tdProcessSubmitReq(STsdb *pTsdb, int64_t version, void *pReq) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tdFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) {
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
SSubmitBlkIter blkIter = {0};
|
||||
STSRow *row = NULL;
|
||||
static int32_t tdFetchSubmitReqSuids(SSubmitReq2 *pMsg, STbUidStore *pStore) {
|
||||
SArray *pSubmitTbData = pMsg ? pMsg->aSubmitTbData : NULL;
|
||||
int32_t size = taosArrayGetSize(pSubmitTbData);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) {
|
||||
return -1;
|
||||
}
|
||||
while (true) {
|
||||
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) {
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSubmitTbData *pData = TARRAY_GET_ELEM(pSubmitTbData, i);
|
||||
if ((terrno = tdUidStorePut(pStore, pData->suid, NULL)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!pBlock) break;
|
||||
tdUidStorePut(pStore, msgIter.suid, NULL);
|
||||
}
|
||||
|
||||
if (terrno != TSDB_CODE_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -673,11 +663,11 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
|||
smaDebug("result block, uid:%" PRIu64 ", groupid:%" PRIu64 ", rows:%d", output->info.id.uid,
|
||||
output->info.id.groupId, output->info.rows);
|
||||
|
||||
STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb[0] : pSma->pRSmaTsdb[1]);
|
||||
SSubmitReq *pReq = NULL;
|
||||
STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb[0] : pSma->pRSmaTsdb[1]);
|
||||
SSubmitReq2 *pReq = NULL;
|
||||
|
||||
// TODO: the schema update should be handled later(TD-17965)
|
||||
if (buildSubmitReqFromDataBlock(&pReq, output, pTSchema, SMA_VID(pSma), suid) < 0) {
|
||||
if (buildSubmitReqFromDataBlock(&pReq, output, pTSchema, output->info.id.groupId, SMA_VID(pSma), suid) < 0) {
|
||||
smaError("vgId:%d, build submit req for rsma table suid:%" PRIu64 ", uid:%" PRIu64 ", level %" PRIi8
|
||||
" failed since %s",
|
||||
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, terrstr());
|
||||
|
@ -685,19 +675,21 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
|||
}
|
||||
|
||||
if (pReq && tdProcessSubmitReq(sinkTsdb, output->info.version, pReq) < 0) {
|
||||
taosMemoryFreeClear(pReq);
|
||||
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
taosMemoryFree(pReq);
|
||||
smaError("vgId:%d, process submit req for rsma suid:%" PRIu64 ", uid:%" PRIu64 " level %" PRIi8
|
||||
" failed since %s",
|
||||
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, terrstr());
|
||||
goto _err;
|
||||
}
|
||||
|
||||
smaDebug("vgId:%d, process submit req for rsma suid:%" PRIu64 ",uid:%" PRIu64 ", level %" PRIi8 " ver %" PRIi64
|
||||
" len %" PRIu32,
|
||||
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, output->info.version,
|
||||
htonl(pReq->header.contLen));
|
||||
smaDebug("vgId:%d, process submit req for rsma suid:%" PRIu64 ",uid:%" PRIu64 ", level %" PRIi8 " ver %" PRIi64,
|
||||
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, output->info.version);
|
||||
|
||||
taosMemoryFreeClear(pReq);
|
||||
if (pReq) {
|
||||
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
taosMemoryFree(pReq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -715,22 +707,29 @@ _err:
|
|||
* @brief Copy msg to rsmaQueueBuffer for batch process
|
||||
*
|
||||
* @param pSma
|
||||
* @param version
|
||||
* @param pMsg
|
||||
* @param len
|
||||
* @param inputType
|
||||
* @param pInfo
|
||||
* @param suid
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t tdExecuteRSmaImplAsync(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfo *pInfo,
|
||||
tb_uid_t suid) {
|
||||
const SSubmitReq *pReq = (const SSubmitReq *)pMsg;
|
||||
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 size = sizeof(int32_t) + sizeof(int64_t) + len;
|
||||
void *qItem = taosAllocateQitem(size, DEF_QITEM, 0);
|
||||
|
||||
void *qItem = taosAllocateQitem(pReq->header.contLen, DEF_QITEM, 0);
|
||||
if (!qItem) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
memcpy(qItem, pMsg, pReq->header.contLen);
|
||||
void *pItem = qItem;
|
||||
|
||||
*(int32_t *)pItem = len;
|
||||
pItem = POINTER_SHIFT(pItem, sizeof(int32_t));
|
||||
*(int64_t *)pItem = version;
|
||||
memcpy(POINTER_SHIFT(pItem, sizeof(int64_t)), pMsg, len);
|
||||
|
||||
taosWriteQitem(pInfo->queue, qItem);
|
||||
|
||||
|
@ -997,12 +996,14 @@ static FORCE_INLINE void tdReleaseRSmaInfo(SSma *pSma, SRSmaInfo *pInfo) {
|
|||
* @brief async mode
|
||||
*
|
||||
* @param pSma
|
||||
* @param version
|
||||
* @param pMsg
|
||||
* @param inputType
|
||||
* @param suid
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t tdExecuteRSmaAsync(SSma *pSma, const void *pMsg, int32_t inputType, tb_uid_t suid) {
|
||||
static int32_t tdExecuteRSmaAsync(SSma *pSma, int64_t version, const void *pMsg, int32_t len, int32_t inputType,
|
||||
tb_uid_t suid) {
|
||||
SRSmaInfo *pRSmaInfo = tdAcquireRSmaInfoBySuid(pSma, suid);
|
||||
if (!pRSmaInfo) {
|
||||
smaDebug("vgId:%d, execute rsma, no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid);
|
||||
|
@ -1010,7 +1011,7 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, const void *pMsg, int32_t inputTyp
|
|||
}
|
||||
|
||||
if (inputType == STREAM_INPUT__DATA_SUBMIT) {
|
||||
if (tdExecuteRSmaImplAsync(pSma, pMsg, inputType, pRSmaInfo, suid) < 0) {
|
||||
if (tdExecuteRSmaImplAsync(pSma, version, pMsg, len, inputType, pRSmaInfo, suid) < 0) {
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -1036,7 +1037,7 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, const void *pMsg, int32_t inputTyp
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdProcessRSmaSubmit(SSma *pSma, void *pMsg, int32_t inputType) {
|
||||
int32_t tdProcessRSmaSubmit(SSma *pSma, int64_t version, void *pReq, void *pMsg, int32_t len, int32_t inputType) {
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
if (!pEnv) {
|
||||
// only applicable when rsma env exists
|
||||
|
@ -1046,19 +1047,22 @@ int32_t tdProcessRSmaSubmit(SSma *pSma, void *pMsg, int32_t inputType) {
|
|||
STbUidStore uidStore = {0};
|
||||
|
||||
if (inputType == STREAM_INPUT__DATA_SUBMIT) {
|
||||
if (tdFetchSubmitReqSuids(pMsg, &uidStore) < 0) {
|
||||
if (tdFetchSubmitReqSuids(pReq, &uidStore) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit fetch suid since: %s", SMA_VID(pSma), terrstr());
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (uidStore.suid != 0) {
|
||||
if (tdExecuteRSmaAsync(pSma, pMsg, inputType, uidStore.suid) < 0) {
|
||||
if (tdExecuteRSmaAsync(pSma, version, pMsg, len, inputType, uidStore.suid) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit exec 1 since: %s", SMA_VID(pSma), terrstr());
|
||||
goto _err;
|
||||
}
|
||||
|
||||
void *pIter = NULL;
|
||||
while ((pIter = taosHashIterate(uidStore.uidHash, pIter))) {
|
||||
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||
if (tdExecuteRSmaAsync(pSma, pMsg, inputType, *pTbSuid) < 0) {
|
||||
if (tdExecuteRSmaAsync(pSma, version, pMsg, len, inputType, *pTbSuid) < 0) {
|
||||
smaError("vgId:%d, failed to process rsma submit exec 2 since: %s", SMA_VID(pSma), terrstr());
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
|
@ -1068,7 +1072,6 @@ int32_t tdProcessRSmaSubmit(SSma *pSma, void *pMsg, int32_t inputType) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
tdUidStoreDestory(&uidStore);
|
||||
smaError("vgId:%d, failed to process rsma submit since: %s", SMA_VID(pSma), terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
|
@ -1428,7 +1431,8 @@ _end:
|
|||
|
||||
static void tdFreeRSmaSubmitItems(SArray *pItems) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pItems); ++i) {
|
||||
taosFreeQitem(*(void **)taosArrayGet(pItems, i));
|
||||
SPackedData *packData = taosArrayGet(pItems, i);
|
||||
taosFreeQitem(POINTER_SHIFT(packData->msgStr, -sizeof(int32_t) - sizeof(int64_t)));
|
||||
}
|
||||
taosArrayClear(pItems);
|
||||
}
|
||||
|
@ -1497,8 +1501,12 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA
|
|||
void *msg = NULL;
|
||||
taosGetQitem(qall, (void **)&msg);
|
||||
if (msg) {
|
||||
if (!taosArrayPush(pSubmitArr, &msg)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SPackedData packData = {.msgLen = *(int32_t *)msg,
|
||||
.ver = *(int64_t *)POINTER_SHIFT(msg, sizeof(int32_t)),
|
||||
.msgStr = POINTER_SHIFT(msg, sizeof(int32_t) + sizeof(int64_t))};
|
||||
|
||||
if (!taosArrayPush(pSubmitArr, &packData)) {
|
||||
tdFreeRSmaSubmitItems(pSubmitArr);
|
||||
goto _err;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -217,19 +217,18 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
|||
}
|
||||
|
||||
SBatchDeleteReq deleteReq = {0};
|
||||
SSubmitReq *pSubmitReq =
|
||||
tqBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, &pTsmaStat->pTSma->schemaTag, true,
|
||||
pTsmaStat->pTSma->dstTbUid, pTsmaStat->pTSma->dstTbName, &deleteReq);
|
||||
// TODO deleteReq
|
||||
taosArrayDestroy(deleteReq.deleteReqs);
|
||||
|
||||
void *pSubmitReq = NULL;
|
||||
int32_t contLen = 0;
|
||||
|
||||
if (!pSubmitReq) {
|
||||
smaError("vgId:%d, failed to gen submit blk while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
|
||||
if (tqBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, &pTsmaStat->pTSma->schemaTag, true,
|
||||
pTsmaStat->pTSma->dstTbUid, pTsmaStat->pTSma->dstTbName, &deleteReq, &pSubmitReq, &contLen) < 0) {
|
||||
smaError("vgId:%d, failed to gen submit msg while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
|
||||
indexUid, tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
|
||||
// TODO deleteReq
|
||||
taosArrayDestroy(deleteReq.deleteReqs);
|
||||
#if 0
|
||||
if (!strncasecmp("td.tsma.rst.tb", pTsmaStat->pTSma->dstTbName, 14)) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
|
@ -242,7 +241,7 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
|||
SRpcMsg submitReqMsg = {
|
||||
.msgType = TDMT_VND_SUBMIT,
|
||||
.pCont = pSubmitReq,
|
||||
.contLen = ntohl(pSubmitReq->length),
|
||||
.contLen = ntohl(contLen),
|
||||
};
|
||||
|
||||
if (tmsgPutToQueue(&pSma->pVnode->msgCb, WRITE_QUEUE, &submitReqMsg) < 0) {
|
||||
|
|
|
@ -677,9 +677,12 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
req.epoch, TD_VID(pTq->pVnode), fetchVer, pHead->msgType);
|
||||
|
||||
if (pHead->msgType == TDMT_VND_SUBMIT) {
|
||||
SSubmitReq* pCont = (SSubmitReq*)&pHead->body;
|
||||
|
||||
if (tqTaosxScanLog(pTq, pHandle, pCont, &taosxRsp) < 0) {
|
||||
SPackedData submit = {
|
||||
.msgStr = POINTER_SHIFT(pHead->body, sizeof(SMsgHead)),
|
||||
.msgLen = pHead->bodyLen - sizeof(SMsgHead),
|
||||
.ver = pHead->version,
|
||||
};
|
||||
if (tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp) < 0) {
|
||||
}
|
||||
if (taosxRsp.blockNum > 0 /* threshold */) {
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
|
||||
|
@ -731,6 +734,7 @@ int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t version, char* msg, int32_t msgL
|
|||
|
||||
STqHandle* pHandle = taosHashGet(pTq->pHandle, pReq->subKey, strlen(pReq->subKey));
|
||||
if (pHandle) {
|
||||
// walCloseRef(pHandle->pWalReader->pWal, pHandle->pRef->refId);
|
||||
if (pHandle->pRef) {
|
||||
walCloseRef(pTq->pVnode->pWal, pHandle->pRef->refId);
|
||||
}
|
||||
|
@ -954,14 +958,14 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
|
|||
pTask->smaSink.smaSink = smaHandleRes;
|
||||
} else if (pTask->outputType == TASK_OUTPUT__TABLE) {
|
||||
pTask->tbSink.vnode = pTq->pVnode;
|
||||
pTask->tbSink.tbSinkFunc = tqSinkToTablePipeline;
|
||||
pTask->tbSink.tbSinkFunc = tqSinkToTablePipeline2;
|
||||
|
||||
/*A(pTask->tbSink.pSchemaWrapper);*/
|
||||
/*A(pTask->tbSink.pSchemaWrapper->pSchema);*/
|
||||
|
||||
pTask->tbSink.pTSchema =
|
||||
tdGetSTSChemaFromSSChema(pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols, 1);
|
||||
/*A(pTask->tbSink.pTSchema);*/
|
||||
tBuildTSchema(pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols, 1);
|
||||
ASSERT(pTask->tbSink.pTSchema);
|
||||
}
|
||||
|
||||
streamSetupTrigger(pTask);
|
||||
|
@ -1010,6 +1014,7 @@ int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
tqError("unable to encode rsp %d", __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* buf = rpcMallocCont(sizeof(SMsgHead) + len);
|
||||
((SMsgHead*)buf)->vgId = htonl(req.upstreamNodeId);
|
||||
|
||||
|
@ -1334,12 +1339,12 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
||||
void* pIter = NULL;
|
||||
bool failed = false;
|
||||
SStreamDataSubmit* pSubmit = NULL;
|
||||
int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
||||
void* pIter = NULL;
|
||||
bool failed = false;
|
||||
SStreamDataSubmit2* pSubmit = NULL;
|
||||
|
||||
pSubmit = streamDataSubmitNew(pReq);
|
||||
pSubmit = streamDataSubmitNew(submit);
|
||||
if (pSubmit == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("failed to create data submit for stream since out of memory");
|
||||
|
@ -1356,7 +1361,7 @@ int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
|||
continue;
|
||||
}
|
||||
|
||||
tqDebug("data submit enqueue stream task: %d, ver: %" PRId64, pTask->taskId, ver);
|
||||
tqDebug("data submit enqueue stream task: %d, ver: %" PRId64, pTask->taskId, submit.ver);
|
||||
|
||||
if (!failed) {
|
||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) {
|
||||
|
|
|
@ -113,14 +113,8 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (pRsp->withTbName) {
|
||||
if (pRsp->rspOffset.type == TMQ_OFFSET__LOG) {
|
||||
int64_t uid = pExec->pExecReader->msgIter.uid;
|
||||
tqAddTbNameToRsp(pTq, uid, pRsp, 1);
|
||||
} else {
|
||||
pRsp->withTbName = false;
|
||||
}
|
||||
}
|
||||
ASSERT(pRsp->withTbName == false);
|
||||
ASSERT(pRsp->withSchema == false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -157,9 +151,8 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
|||
|
||||
if (pDataBlock != NULL) {
|
||||
if (pRsp->withTbName) {
|
||||
int64_t uid = 0;
|
||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
||||
uid = pExec->pExecReader->msgIter.uid;
|
||||
int64_t uid = pExec->pExecReader->lastBlkUid;
|
||||
if (tqAddTbNameToRsp(pTq, uid, (SMqDataRsp*)pRsp, 1) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -229,7 +222,7 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp* pRsp) {
|
||||
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxRsp* pRsp) {
|
||||
STqExecHandle* pExec = &pHandle->execHandle;
|
||||
/*A(pExec->subType != TOPIC_SUB_TYPE__COLUMN);*/
|
||||
|
||||
|
@ -238,8 +231,9 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
|||
|
||||
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
STqReader* pReader = pExec->pExecReader;
|
||||
tqReaderSetDataMsg(pReader, pReq, 0);
|
||||
while (tqNextDataBlock(pReader)) {
|
||||
/*tqReaderSetDataMsg(pReader, pReq, 0);*/
|
||||
tqReaderSetSubmitReq2(pReader, submit.msgStr, submit.msgLen, submit.ver);
|
||||
while (tqNextDataBlock2(pReader)) {
|
||||
/*SSDataBlock block = {0};*/
|
||||
/*if (tqRetrieveDataBlock(&block, pReader) < 0) {*/
|
||||
/*if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;*/
|
||||
|
@ -247,11 +241,12 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
|||
|
||||
taosArrayClear(pBlocks);
|
||||
taosArrayClear(pSchemas);
|
||||
if (tqRetrieveTaosxBlock(pReader, pBlocks, pSchemas) < 0) {
|
||||
if (tqRetrieveTaosxBlock2(pReader, pBlocks, pSchemas) < 0) {
|
||||
if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
|
||||
}
|
||||
if (pRsp->withTbName) {
|
||||
int64_t uid = pExec->pExecReader->msgIter.uid;
|
||||
/*int64_t uid = pExec->pExecReader->msgIter.uid;*/
|
||||
int64_t uid = pExec->pExecReader->lastBlkUid;
|
||||
if (tqAddTbNameToRsp(pTq, uid, (SMqDataRsp*)pRsp, taosArrayGetSize(pBlocks)) < 0) {
|
||||
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
|
||||
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
|
||||
|
@ -261,7 +256,9 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
|||
}
|
||||
}
|
||||
if (pHandle->fetchMeta) {
|
||||
#if 0
|
||||
SSubmitBlk* pBlk = pReader->pBlock;
|
||||
int64_t uid = pExec->pExecReader->lastBlkUid;
|
||||
int32_t schemaLen = htonl(pBlk->schemaLen);
|
||||
if (schemaLen > 0) {
|
||||
if (pRsp->createTableNum == 0) {
|
||||
|
@ -274,6 +271,7 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
|||
taosArrayPush(pRsp->createTableReq, &createReq);
|
||||
pRsp->createTableNum++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pBlocks); i++) {
|
||||
SSDataBlock* pBlock = taosArrayGet(pBlocks, i);
|
||||
|
@ -287,19 +285,20 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
|||
}
|
||||
} else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
|
||||
STqReader* pReader = pExec->pExecReader;
|
||||
tqReaderSetDataMsg(pReader, pReq, 0);
|
||||
while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
|
||||
/*tqReaderSetDataMsg(pReader, pReq, 0);*/
|
||||
tqReaderSetSubmitReq2(pReader, submit.msgStr, submit.msgLen, submit.ver);
|
||||
while (tqNextDataBlockFilterOut2(pReader, pExec->execDb.pFilterOutTbUid)) {
|
||||
/*SSDataBlock block = {0};*/
|
||||
/*if (tqRetrieveDataBlock(&block, pReader) < 0) {*/
|
||||
/*if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;*/
|
||||
/*}*/
|
||||
taosArrayClear(pBlocks);
|
||||
taosArrayClear(pSchemas);
|
||||
if (tqRetrieveTaosxBlock(pReader, pBlocks, pSchemas) < 0) {
|
||||
if (tqRetrieveTaosxBlock2(pReader, pBlocks, pSchemas) < 0) {
|
||||
if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
|
||||
}
|
||||
if (pRsp->withTbName) {
|
||||
int64_t uid = pExec->pExecReader->msgIter.uid;
|
||||
int64_t uid = pExec->pExecReader->lastBlkUid;
|
||||
if (tqAddTbNameToRsp(pTq, uid, (SMqDataRsp*)pRsp, taosArrayGetSize(pBlocks)) < 0) {
|
||||
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
|
||||
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
|
||||
|
@ -309,6 +308,7 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
|||
}
|
||||
}
|
||||
if (pHandle->fetchMeta) {
|
||||
#if 0
|
||||
SSubmitBlk* pBlk = pReader->pBlock;
|
||||
int32_t schemaLen = htonl(pBlk->schemaLen);
|
||||
if (schemaLen > 0) {
|
||||
|
@ -322,6 +322,7 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
|||
taosArrayPush(pRsp->createTableReq, &createReq);
|
||||
pRsp->createTableNum++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*tqAddBlockDataToRsp(&block, (SMqDataRsp*)pRsp, taosArrayGetSize(block.pDataBlock),*/
|
||||
/*pTq->pVnode->config.tsdbCfg.precision);*/
|
||||
|
|
|
@ -207,7 +207,11 @@ int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_
|
|||
#endif
|
||||
|
||||
int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) {
|
||||
tqDebug("vgId:%d, tq push msg ver %" PRId64 ", type: %s", pTq->pVnode->config.vgId, ver, TMSG_INFO(msgType));
|
||||
void* pReq = POINTER_SHIFT(msg, sizeof(SMsgHead));
|
||||
int32_t len = msgLen - sizeof(SMsgHead);
|
||||
|
||||
tqDebug("vgId:%d, tq push msg ver %" PRId64 ", type: %s, p head %p, p body %p, len %d", pTq->pVnode->config.vgId, ver,
|
||||
TMSG_INFO(msgType), msg, pReq, len);
|
||||
|
||||
if (msgType == TDMT_VND_SUBMIT) {
|
||||
// lock push mgr to avoid potential msg lost
|
||||
|
@ -216,7 +220,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
|
|||
if (taosHashGetSize(pTq->pPushMgr) != 0) {
|
||||
SArray* cachedKeys = taosArrayInit(0, sizeof(void*));
|
||||
SArray* cachedKeyLens = taosArrayInit(0, sizeof(size_t));
|
||||
void* data = taosMemoryMalloc(msgLen);
|
||||
void* data = taosMemoryMalloc(len);
|
||||
if (data == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("failed to copy data for stream since out of memory");
|
||||
|
@ -224,9 +228,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
|
|||
taosArrayDestroy(cachedKeyLens);
|
||||
return -1;
|
||||
}
|
||||
memcpy(data, msg, msgLen);
|
||||
SSubmitReq* pReq = (SSubmitReq*)data;
|
||||
pReq->version = ver;
|
||||
memcpy(data, pReq, len);
|
||||
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
|
@ -250,7 +252,12 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
|
|||
SMqDataRsp* pRsp = &pPushEntry->dataRsp;
|
||||
|
||||
// prepare scan mem data
|
||||
qStreamScanMemData(task, pReq);
|
||||
SPackedData submit = {
|
||||
.msgStr = data,
|
||||
.msgLen = len,
|
||||
.ver = ver,
|
||||
};
|
||||
qStreamSetScanMemData(task, submit);
|
||||
|
||||
// exec
|
||||
while (1) {
|
||||
|
@ -304,17 +311,22 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
|
|||
if (vnodeIsRoleLeader(pTq->pVnode)) {
|
||||
if (taosHashGetSize(pTq->pStreamMeta->pTasks) == 0) return 0;
|
||||
if (msgType == TDMT_VND_SUBMIT) {
|
||||
void* data = taosMemoryMalloc(msgLen);
|
||||
void* data = taosMemoryMalloc(len);
|
||||
if (data == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("failed to copy data for stream since out of memory");
|
||||
return -1;
|
||||
}
|
||||
memcpy(data, msg, msgLen);
|
||||
SSubmitReq* pReq = (SSubmitReq*)data;
|
||||
pReq->version = ver;
|
||||
memcpy(data, pReq, len);
|
||||
SPackedData submit = {
|
||||
.msgStr = data,
|
||||
.msgLen = len,
|
||||
.ver = ver,
|
||||
};
|
||||
|
||||
tqProcessSubmitReq(pTq, data, ver);
|
||||
tqDebug("tq copy write msg %p %d %" PRId64 " from %p", data, len, ver, pReq);
|
||||
|
||||
tqProcessSubmitReq(pTq, submit);
|
||||
}
|
||||
if (msgType == TDMT_VND_DELETE) {
|
||||
tqProcessDelReq(pTq, POINTER_SHIFT(msg, sizeof(SMsgHead)), msgLen - sizeof(SMsgHead), ver);
|
||||
|
|
|
@ -247,7 +247,7 @@ END:
|
|||
}
|
||||
|
||||
STqReader* tqOpenReader(SVnode* pVnode) {
|
||||
STqReader* pReader = taosMemoryMalloc(sizeof(STqReader));
|
||||
STqReader* pReader = taosMemoryCalloc(1, sizeof(STqReader));
|
||||
if (pReader == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ STqReader* tqOpenReader(SVnode* pVnode) {
|
|||
}
|
||||
|
||||
pReader->pVnodeMeta = pVnode->pMeta;
|
||||
pReader->pMsg = NULL;
|
||||
/*pReader->pMsg = NULL;*/
|
||||
pReader->ver = -1;
|
||||
pReader->pColIdList = NULL;
|
||||
pReader->cachedSchemaVer = 0;
|
||||
|
@ -298,7 +298,7 @@ int32_t tqSeekVer(STqReader* pReader, int64_t ver) {
|
|||
}
|
||||
|
||||
int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
||||
bool fromProcessedMsg = pReader->pMsg != NULL;
|
||||
bool fromProcessedMsg = pReader->msg2.msgStr != NULL;
|
||||
|
||||
while (1) {
|
||||
if (!fromProcessedMsg) {
|
||||
|
@ -311,7 +311,9 @@ int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
|||
tqDebug("return offset %" PRId64 ", no more valid", ret->offset.version);
|
||||
return -1;
|
||||
}
|
||||
void* body = pReader->pWalReader->pHead->head.body;
|
||||
void* body = POINTER_SHIFT(pReader->pWalReader->pHead->head.body, sizeof(SMsgHead));
|
||||
int32_t bodyLen = pReader->pWalReader->pHead->head.bodyLen - sizeof(SMsgHead);
|
||||
int64_t ver = pReader->pWalReader->pHead->head.version;
|
||||
#if 0
|
||||
if (pReader->pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
|
||||
// TODO do filter
|
||||
|
@ -320,16 +322,17 @@ int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
|||
return 0;
|
||||
} else {
|
||||
#endif
|
||||
tqReaderSetDataMsg(pReader, body, pReader->pWalReader->pHead->head.version);
|
||||
tqReaderSetSubmitReq2(pReader, body, bodyLen, ver);
|
||||
/*tqReaderSetDataMsg(pReader, body, pReader->pWalReader->pHead->head.version);*/
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
while (tqNextDataBlock(pReader)) {
|
||||
while (tqNextDataBlock2(pReader)) {
|
||||
// TODO mem free
|
||||
memset(&ret->data, 0, sizeof(SSDataBlock));
|
||||
int32_t code = tqRetrieveDataBlock(&ret->data, pReader);
|
||||
int32_t code = tqRetrieveDataBlock2(&ret->data, pReader);
|
||||
if (code != 0 || ret->data.info.rows == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -348,6 +351,7 @@ int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tqReaderSetDataMsg(STqReader* pReader, const SSubmitReq* pMsg, int64_t ver) {
|
||||
pReader->pMsg = pMsg;
|
||||
|
||||
|
@ -362,7 +366,33 @@ int32_t tqReaderSetDataMsg(STqReader* pReader, const SSubmitReq* pMsg, int64_t v
|
|||
memset(&pReader->blkIter, 0, sizeof(SSubmitBlkIter));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqReaderSetSubmitReq2(STqReader* pReader, void* msgStr, int32_t msgLen, int64_t ver) {
|
||||
ASSERT(pReader->msg2.msgStr == NULL);
|
||||
ASSERT(msgStr);
|
||||
ASSERT(msgLen);
|
||||
ASSERT(ver >= 0);
|
||||
pReader->msg2.msgStr = msgStr;
|
||||
pReader->msg2.msgLen = msgLen;
|
||||
pReader->msg2.ver = ver;
|
||||
pReader->ver = ver;
|
||||
|
||||
tqDebug("tq reader set msg %p %d", msgStr, msgLen);
|
||||
|
||||
if (pReader->setMsg == 0) {
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, pReader->msg2.msgStr, pReader->msg2.msgLen);
|
||||
if (tDecodeSSubmitReq2(&decoder, &pReader->submit) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
pReader->setMsg = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool tqNextDataBlock(STqReader* pReader) {
|
||||
if (pReader->pMsg == NULL) return false;
|
||||
while (1) {
|
||||
|
@ -386,6 +416,59 @@ bool tqNextDataBlock(STqReader* pReader) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool tqNextDataBlock2(STqReader* pReader) {
|
||||
if (pReader->msg2.msgStr == NULL) return false;
|
||||
ASSERT(pReader->setMsg == 1);
|
||||
|
||||
tqDebug("tq reader next data block %p, %d %" PRId64 " %d", pReader->msg2.msgStr, pReader->msg2.msgLen,
|
||||
pReader->msg2.ver, pReader->nextBlk);
|
||||
|
||||
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||
while (pReader->nextBlk < blockSz) {
|
||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||
ASSERT(pSubmitTbData->uid);
|
||||
|
||||
if (pReader->tbIdHash == NULL) return true;
|
||||
|
||||
void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
|
||||
if (ret != NULL) {
|
||||
return true;
|
||||
}
|
||||
pReader->nextBlk++;
|
||||
}
|
||||
|
||||
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||
pReader->setMsg = 0;
|
||||
pReader->nextBlk = 0;
|
||||
pReader->msg2.msgStr = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool tqNextDataBlockFilterOut2(STqReader* pReader, SHashObj* filterOutUids) {
|
||||
if (pReader->msg2.msgStr == NULL) return false;
|
||||
ASSERT(pReader->setMsg == 1);
|
||||
|
||||
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||
while (pReader->nextBlk < blockSz) {
|
||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||
if (pReader->tbIdHash == NULL) return true;
|
||||
|
||||
void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
|
||||
if (ret == NULL) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||
pReader->setMsg = 0;
|
||||
pReader->nextBlk = 0;
|
||||
pReader->msg2.msgStr = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrapper* pSrc, char* mask) {
|
||||
int32_t code;
|
||||
|
@ -416,6 +499,7 @@ int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrap
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool tqNextDataBlockFilterOut(STqReader* pHandle, SHashObj* filterOutUids) {
|
||||
while (1) {
|
||||
if (tGetSubmitMsgNext(&pHandle->msgIter, &pHandle->pBlock) < 0) {
|
||||
|
@ -431,6 +515,253 @@ bool tqNextDataBlockFilterOut(STqReader* pHandle, SHashObj* filterOutUids) {
|
|||
return false;
|
||||
}
|
||||
|
||||
int32_t tqScanSubmitSplit(SArray* pBlocks, SArray* schemas, STqReader* pReader) {
|
||||
//
|
||||
int32_t sversion = htonl(pReader->pBlock->sversion);
|
||||
if (pReader->cachedSchemaSuid == 0 || pReader->cachedSchemaVer != sversion ||
|
||||
pReader->cachedSchemaSuid != pReader->msgIter.suid) {
|
||||
taosMemoryFree(pReader->pSchema);
|
||||
pReader->pSchema = metaGetTbTSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, 1);
|
||||
if (pReader->pSchema == NULL) {
|
||||
tqWarn("vgId:%d, cannot found tsschema for table: uid:%" PRId64 " (suid:%" PRId64
|
||||
"), version %d, possibly dropped table",
|
||||
pReader->pWalReader->pWal->cfg.vgId, pReader->msgIter.uid, pReader->msgIter.suid, sversion);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tDeleteSSchemaWrapper(pReader->pSchemaWrapper);
|
||||
pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, 1);
|
||||
if (pReader->pSchemaWrapper == NULL) {
|
||||
tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
|
||||
pReader->pWalReader->pWal->cfg.vgId, pReader->msgIter.uid, pReader->cachedSchemaVer);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
STSchema* pTschema = pReader->pSchema;
|
||||
SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
|
||||
|
||||
int32_t colNumNeed = taosArrayGetSize(pReader->pColIdList);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader) {
|
||||
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||
ASSERT(pReader->nextBlk < blockSz);
|
||||
|
||||
tqDebug("tq reader retrieve data block %p, %d", pReader->msg2.msgStr, pReader->nextBlk);
|
||||
|
||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||
pReader->nextBlk++;
|
||||
|
||||
int32_t sversion = pSubmitTbData->sver;
|
||||
int64_t suid = pSubmitTbData->suid;
|
||||
int64_t uid = pSubmitTbData->uid;
|
||||
pReader->lastBlkUid = uid;
|
||||
|
||||
pBlock->info.id.uid = uid;
|
||||
pBlock->info.version = pReader->msg2.ver;
|
||||
|
||||
if (pReader->cachedSchemaSuid == 0 || pReader->cachedSchemaVer != sversion || pReader->cachedSchemaSuid != suid) {
|
||||
taosMemoryFree(pReader->pSchema);
|
||||
pReader->pSchema = metaGetTbTSchema(pReader->pVnodeMeta, uid, sversion, 1);
|
||||
if (pReader->pSchema == NULL) {
|
||||
tqWarn("vgId:%d, cannot found tsschema for table: uid:%" PRId64 " (suid:%" PRId64
|
||||
"), version %d, possibly dropped table",
|
||||
pReader->pWalReader->pWal->cfg.vgId, uid, suid, sversion);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tDeleteSSchemaWrapper(pReader->pSchemaWrapper);
|
||||
pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1);
|
||||
if (pReader->pSchemaWrapper == NULL) {
|
||||
tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
|
||||
pReader->pWalReader->pWal->cfg.vgId, uid, pReader->cachedSchemaVer);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
STSchema* pTschema = pReader->pSchema;
|
||||
SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
|
||||
|
||||
int32_t colNumNeed = taosArrayGetSize(pReader->pColIdList);
|
||||
|
||||
if (colNumNeed == 0) {
|
||||
int32_t colMeta = 0;
|
||||
while (colMeta < pSchemaWrapper->nCols) {
|
||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||
SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
|
||||
int32_t code = blockDataAppendColInfo(pBlock, &colInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto FAIL;
|
||||
}
|
||||
colMeta++;
|
||||
}
|
||||
} else {
|
||||
if (colNumNeed > pSchemaWrapper->nCols) {
|
||||
colNumNeed = pSchemaWrapper->nCols;
|
||||
}
|
||||
|
||||
int32_t colMeta = 0;
|
||||
int32_t colNeed = 0;
|
||||
while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) {
|
||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||
col_id_t colIdSchema = pColSchema->colId;
|
||||
col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pReader->pColIdList, colNeed);
|
||||
if (colIdSchema < colIdNeed) {
|
||||
colMeta++;
|
||||
} else if (colIdSchema > colIdNeed) {
|
||||
colNeed++;
|
||||
} else {
|
||||
SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
|
||||
int32_t code = blockDataAppendColInfo(pBlock, &colInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto FAIL;
|
||||
}
|
||||
colMeta++;
|
||||
colNeed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t numOfRows = 0;
|
||||
|
||||
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
SArray* pCols = pSubmitTbData->aCol;
|
||||
SColData* pCol = taosArrayGet(pCols, 0);
|
||||
numOfRows = pCol->nVal;
|
||||
} else {
|
||||
SArray* pRows = pSubmitTbData->aRowP;
|
||||
numOfRows = taosArrayGetSize(pRows);
|
||||
}
|
||||
|
||||
if (blockDataEnsureCapacity(pBlock, numOfRows) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
}
|
||||
pBlock->info.rows = numOfRows;
|
||||
|
||||
int32_t colActual = blockDataGetNumOfCols(pBlock);
|
||||
|
||||
// convert and scan one block
|
||||
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
SArray* pCols = pSubmitTbData->aCol;
|
||||
int32_t numOfCols = taosArrayGetSize(pCols);
|
||||
int32_t targetIdx = 0;
|
||||
int32_t sourceIdx = 0;
|
||||
while (targetIdx < colActual) {
|
||||
ASSERT(sourceIdx < numOfCols);
|
||||
|
||||
SColData* pCol = taosArrayGet(pCols, sourceIdx);
|
||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
|
||||
SColVal colVal;
|
||||
|
||||
ASSERT(pCol->nVal == numOfRows);
|
||||
|
||||
if (pCol->cid < pColData->info.colId) {
|
||||
sourceIdx++;
|
||||
} else if (pCol->cid == pColData->info.colId) {
|
||||
for (int32_t i = 0; i < pCol->nVal; i++) {
|
||||
tColDataGetValue(pCol, sourceIdx, &colVal);
|
||||
#if 0
|
||||
void* val = NULL;
|
||||
if (IS_STR_DATA_TYPE(colVal.type)) {
|
||||
val = colVal.value.pData;
|
||||
} else {
|
||||
val = &colVal.value.val;
|
||||
}
|
||||
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
#endif
|
||||
if (IS_STR_DATA_TYPE(colVal.type)) {
|
||||
if (colVal.value.pData != NULL) {
|
||||
char val[65535 + 2];
|
||||
memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
|
||||
varDataSetLen(val, colVal.value.nData);
|
||||
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
} else {
|
||||
colDataAppendNULL(pColData, i);
|
||||
}
|
||||
} else {
|
||||
if (colDataAppend(pColData, i, (void*)&colVal.value.val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceIdx++;
|
||||
targetIdx++;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SArray* pRows = pSubmitTbData->aRowP;
|
||||
|
||||
for (int32_t i = 0; i < numOfRows; i++) {
|
||||
SRow* pRow = taosArrayGetP(pRows, i);
|
||||
int32_t targetIdx = 0;
|
||||
int32_t sourceIdx = 0;
|
||||
|
||||
for (int32_t j = 0; j < colActual; j++) {
|
||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
|
||||
while (1) {
|
||||
ASSERT(sourceIdx < pTschema->numOfCols);
|
||||
|
||||
SColVal colVal;
|
||||
tRowGet(pRow, pTschema, sourceIdx, &colVal);
|
||||
if (colVal.cid < pColData->info.colId) {
|
||||
sourceIdx++;
|
||||
continue;
|
||||
} else if (colVal.cid == pColData->info.colId) {
|
||||
if (IS_STR_DATA_TYPE(colVal.type)) {
|
||||
if (colVal.value.pData != NULL) {
|
||||
char val[65535 + 2];
|
||||
memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
|
||||
varDataSetLen(val, colVal.value.nData);
|
||||
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
} else {
|
||||
colDataAppendNULL(pColData, i);
|
||||
}
|
||||
/*val = colVal.value.pData;*/
|
||||
} else {
|
||||
if (colDataAppend(pColData, i, (void*)&colVal.value.val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
sourceIdx++;
|
||||
targetIdx++;
|
||||
break;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
FAIL:
|
||||
blockDataFreeRes(pBlock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tqRetrieveDataBlock(SSDataBlock* pBlock, STqReader* pReader) {
|
||||
// TODO: cache multiple schema
|
||||
int32_t sversion = htonl(pReader->pBlock->sversion);
|
||||
|
@ -673,6 +1004,18 @@ FAIL:
|
|||
taosMemoryFree(assigned);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schemas) {
|
||||
SSDataBlock block = {0};
|
||||
if (tqRetrieveDataBlock2(&block, pReader) == 0) {
|
||||
taosArrayPush(blocks, &block);
|
||||
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pReader->pSchemaWrapper);
|
||||
taosArrayPush(schemas, &pSW);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void tqReaderSetColIdList(STqReader* pReader, SArray* pColIdList) { pReader->pColIdList = pColIdList; }
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBl
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pTSchema,
|
||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||
SBatchDeleteReq* pDeleteReq) {
|
||||
|
@ -251,8 +252,6 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
|
|||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
|
||||
tqDebug("tq sink, convert block1 %d, rows: %d", i, rows);
|
||||
|
||||
int32_t dataLen = 0;
|
||||
int32_t schemaLen = 0;
|
||||
void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
||||
|
@ -298,6 +297,201 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
|
|||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pTSchema,
|
||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||
SBatchDeleteReq* pDeleteReq, void** ppData, int32_t* pLen) {
|
||||
void* pBuf = NULL;
|
||||
int32_t len = 0;
|
||||
SSubmitReq2* pReq = NULL;
|
||||
SArray* tagArray = NULL;
|
||||
SArray* createTbArray = NULL;
|
||||
SArray* pVals = NULL;
|
||||
|
||||
int32_t sz = taosArrayGetSize(pBlocks);
|
||||
|
||||
if (!(tagArray = taosArrayInit(1, sizeof(STagVal)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(createTbArray = taosArrayInit(sz, POINTER_BYTES))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pReq = taosMemoryCalloc(1, sizeof(SSubmitReq2)))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pReq->aSubmitTbData = taosArrayInit(1, sizeof(SSubmitTbData)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
// create table req
|
||||
if (createTb) {
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
SVCreateTbReq* pCreateTbReq = NULL;
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
taosArrayPush(createTbArray, &pCreateTbReq);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateStbReq)))) {
|
||||
goto _end;
|
||||
};
|
||||
|
||||
// don't move to the end of loop as to destroy in the end of func when error occur
|
||||
taosArrayPush(createTbArray, &pCreateTbReq);
|
||||
|
||||
// set const
|
||||
pCreateTbReq->flags = 0;
|
||||
pCreateTbReq->type = TSDB_CHILD_TABLE;
|
||||
pCreateTbReq->ctb.suid = suid;
|
||||
|
||||
// set super table name
|
||||
SName name = {0};
|
||||
tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
pCreateTbReq->ctb.stbName = strdup((char*)tNameGetTableName(&name)); // strdup(stbFullName);
|
||||
|
||||
// set tag content
|
||||
taosArrayClear(tagArray);
|
||||
STagVal tagVal = {
|
||||
.cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1,
|
||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||
.i64 = (int64_t)pDataBlock->info.id.groupId,
|
||||
};
|
||||
taosArrayPush(tagArray, &tagVal);
|
||||
pCreateTbReq->ctb.tagNum = taosArrayGetSize(tagArray);
|
||||
|
||||
STag* pTag = NULL;
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (pTag == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
pCreateTbReq->ctb.pTag = (uint8_t*)pTag;
|
||||
|
||||
// set tag name
|
||||
SArray* tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
|
||||
char tagNameStr[TSDB_COL_NAME_LEN] = {0};
|
||||
strcpy(tagNameStr, "group_id");
|
||||
taosArrayPush(tagName, tagNameStr);
|
||||
pCreateTbReq->ctb.tagName = tagName;
|
||||
|
||||
// set table name
|
||||
if (pDataBlock->info.parTbName[0]) {
|
||||
pCreateTbReq->name = strdup(pDataBlock->info.parTbName);
|
||||
} else {
|
||||
pCreateTbReq->name = buildCtbNameByGroupId(stbFullName, pDataBlock->info.id.groupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SSubmitTbData req
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
pDeleteReq->suid = suid;
|
||||
pDeleteReq->deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
|
||||
tqBuildDeleteReq(pVnode, stbFullName, pDataBlock, pDeleteReq);
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
|
||||
SSubmitTbData* pTbData = (SSubmitTbData*)taosMemoryCalloc(1, sizeof(SSubmitTbData));
|
||||
if (!pTbData) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pTbData->aRowP = taosArrayInit(rows, sizeof(SRow*)))) {
|
||||
taosMemoryFree(pTbData);
|
||||
goto _end;
|
||||
}
|
||||
pTbData->suid = suid;
|
||||
pTbData->uid = 0; // uid is assigned by vnode
|
||||
pTbData->sver = pTSchema->version;
|
||||
|
||||
if (createTb) {
|
||||
pTbData->pCreateTbReq = taosArrayGetP(createTbArray, i);
|
||||
if (pTbData->pCreateTbReq) pTbData->flags = SUBMIT_REQ_AUTO_CREATE_TABLE;
|
||||
}
|
||||
|
||||
if (!pVals && !(pVals = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)))) {
|
||||
taosArrayDestroy(pTbData->aRowP);
|
||||
taosMemoryFree(pTbData);
|
||||
goto _end;
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
taosArrayClear(pVals);
|
||||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
||||
const STColumn* pCol = &pTSchema->columns[k];
|
||||
SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
if (colDataIsNull_s(pColData, j)) {
|
||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
void* data = colDataGetData(pColData, j);
|
||||
if (IS_STR_DATA_TYPE(pCol->type)) {
|
||||
SValue sv = (SValue){.nData = varDataLen(data), .pData = varDataVal(data)}; // address copy, no value
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
SValue sv;
|
||||
memcpy(&sv.val, data, tDataTypes[pCol->type].bytes);
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
}
|
||||
}
|
||||
}
|
||||
SRow* pRow = NULL;
|
||||
if ((terrno = tRowBuild(pVals, (STSchema*)pTSchema, &pRow)) < 0) {
|
||||
tDestroySSubmitTbData(pTbData, TSDB_MSG_FLG_ENCODE);
|
||||
goto _end;
|
||||
}
|
||||
ASSERT(pRow);
|
||||
taosArrayPush(pTbData->aRowP, &pRow);
|
||||
}
|
||||
|
||||
taosArrayPush(pReq->aSubmitTbData, pTbData);
|
||||
}
|
||||
|
||||
// encode
|
||||
tEncodeSize(tEncodeSSubmitReq2, pReq, len, terrno);
|
||||
if (TSDB_CODE_SUCCESS == terrno) {
|
||||
SEncoder encoder;
|
||||
len += sizeof(SMsgHead);
|
||||
pBuf = rpcMallocCont(len);
|
||||
if (NULL == pBuf) {
|
||||
goto _end;
|
||||
}
|
||||
((SMsgHead*)pBuf)->vgId = htonl(TD_VID(pVnode));
|
||||
((SMsgHead*)pBuf)->contLen = htonl(len);
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len - sizeof(SMsgHead));
|
||||
if (tEncodeSSubmitReq2(&encoder, pReq) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("failed to encode submit req since %s", terrstr());
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
}
|
||||
_end:
|
||||
taosArrayDestroy(tagArray);
|
||||
taosArrayDestroy(pVals);
|
||||
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
|
||||
if (terrno != 0) {
|
||||
rpcFreeCont(pBuf);
|
||||
taosArrayDestroy(pDeleteReq->deleteReqs);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (ppData) *ppData = pBuf;
|
||||
if (pLen) *pLen = len;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
||||
const SArray* pBlocks = (const SArray*)data;
|
||||
|
@ -492,7 +686,7 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d
|
|||
blkHead->uid = 0;
|
||||
blkHead->schemaLen = 0;
|
||||
|
||||
tqDebug("tq sink, convert block2 %d, rows: %d", i, rows);
|
||||
tqDebug("tq sink pipe1, convert block2 %d, rows: %d", i, rows);
|
||||
|
||||
int32_t dataLen = 0;
|
||||
void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
||||
|
@ -521,7 +715,7 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d
|
|||
} else {
|
||||
void* colData = colDataGetData(pColData, j);
|
||||
if (k == 0) {
|
||||
tqDebug("tq sink, row %d ts %" PRId64, j, *(int64_t*)colData);
|
||||
tqDebug("tq sink pipe1, row %d ts %" PRId64, j, *(int64_t*)colData);
|
||||
}
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, colData, true, pColumn->offset, k);
|
||||
}
|
||||
|
@ -550,6 +744,247 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d
|
|||
taosArrayDestroy(tagArray);
|
||||
}
|
||||
|
||||
void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
||||
const SArray* pBlocks = (const SArray*)data;
|
||||
SVnode* pVnode = (SVnode*)vnode;
|
||||
int64_t suid = pTask->tbSink.stbUid;
|
||||
char* stbFullName = pTask->tbSink.stbFullName;
|
||||
STSchema* pTSchema = pTask->tbSink.pTSchema;
|
||||
/*SSchemaWrapper* pSchemaWrapper = pTask->tbSink.pSchemaWrapper;*/
|
||||
|
||||
int32_t blockSz = taosArrayGetSize(pBlocks);
|
||||
|
||||
tqDebug("vgId:%d, task %d write into table, block num: %d", TD_VID(pVnode), pTask->taskId, blockSz);
|
||||
|
||||
void* pBuf = NULL;
|
||||
SArray* tagArray = NULL;
|
||||
SArray* pVals = NULL;
|
||||
|
||||
if (!(tagArray = taosArrayInit(1, sizeof(STagVal)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < blockSz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
SBatchDeleteReq deleteReq = {0};
|
||||
deleteReq.deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
|
||||
deleteReq.suid = suid;
|
||||
tqBuildDeleteReq(pVnode, stbFullName, pDataBlock, &deleteReq);
|
||||
if (taosArrayGetSize(deleteReq.deleteReqs) == 0) {
|
||||
taosArrayDestroy(deleteReq.deleteReqs);
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t len;
|
||||
int32_t code;
|
||||
tEncodeSize(tEncodeSBatchDeleteReq, &deleteReq, len, code);
|
||||
if (code < 0) {
|
||||
//
|
||||
ASSERT(0);
|
||||
}
|
||||
SEncoder encoder;
|
||||
void* serializedDeleteReq = rpcMallocCont(len + sizeof(SMsgHead));
|
||||
void* abuf = POINTER_SHIFT(serializedDeleteReq, sizeof(SMsgHead));
|
||||
tEncoderInit(&encoder, abuf, len);
|
||||
tEncodeSBatchDeleteReq(&encoder, &deleteReq);
|
||||
tEncoderClear(&encoder);
|
||||
taosArrayDestroy(deleteReq.deleteReqs);
|
||||
|
||||
((SMsgHead*)serializedDeleteReq)->vgId = pVnode->config.vgId;
|
||||
|
||||
SRpcMsg msg = {
|
||||
.msgType = TDMT_VND_BATCH_DEL,
|
||||
.pCont = serializedDeleteReq,
|
||||
.contLen = len + sizeof(SMsgHead),
|
||||
};
|
||||
if (tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &msg) != 0) {
|
||||
tqDebug("failed to put delete req into write-queue since %s", terrstr());
|
||||
}
|
||||
} else {
|
||||
SSubmitTbData tbData = {0};
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
tqDebug("tq sink pipe2, convert block1 %d, rows: %d", i, rows);
|
||||
|
||||
if (!(tbData.aRowP = taosArrayInit(rows, sizeof(SRow*)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
tbData.suid = suid;
|
||||
tbData.uid = 0; // uid is assigned by vnode
|
||||
tbData.sver = pTSchema->version;
|
||||
|
||||
char* ctbName = NULL;
|
||||
if (pDataBlock->info.parTbName[0]) {
|
||||
ctbName = strdup(pDataBlock->info.parTbName);
|
||||
} else {
|
||||
ctbName = buildCtbNameByGroupId(stbFullName, pDataBlock->info.id.groupId);
|
||||
}
|
||||
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, pVnode->pMeta, 0);
|
||||
if (metaGetTableEntryByName(&mr, ctbName) < 0) {
|
||||
metaReaderClear(&mr);
|
||||
tqDebug("vgId:%d, stream write into %s, table auto created", TD_VID(pVnode), ctbName);
|
||||
|
||||
SVCreateTbReq* pCreateTbReq = NULL;
|
||||
|
||||
if (!(pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateStbReq)))) {
|
||||
goto _end;
|
||||
};
|
||||
|
||||
// set const
|
||||
pCreateTbReq->flags = 0;
|
||||
pCreateTbReq->type = TSDB_CHILD_TABLE;
|
||||
pCreateTbReq->ctb.suid = suid;
|
||||
|
||||
// set super table name
|
||||
SName name = {0};
|
||||
tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
pCreateTbReq->ctb.stbName = strdup((char*)tNameGetTableName(&name)); // strdup(stbFullName);
|
||||
|
||||
// set tag content
|
||||
taosArrayClear(tagArray);
|
||||
STagVal tagVal = {
|
||||
.cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1,
|
||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||
.i64 = (int64_t)pDataBlock->info.id.groupId,
|
||||
};
|
||||
taosArrayPush(tagArray, &tagVal);
|
||||
pCreateTbReq->ctb.tagNum = taosArrayGetSize(tagArray);
|
||||
|
||||
STag* pTag = NULL;
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (pTag == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
pCreateTbReq->ctb.pTag = (uint8_t*)pTag;
|
||||
|
||||
// set tag name
|
||||
SArray* tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
|
||||
char tagNameStr[TSDB_COL_NAME_LEN] = {0};
|
||||
strcpy(tagNameStr, "group_id");
|
||||
taosArrayPush(tagName, tagNameStr);
|
||||
pCreateTbReq->ctb.tagName = tagName;
|
||||
|
||||
// set table name
|
||||
pCreateTbReq->name = ctbName;
|
||||
ctbName = NULL;
|
||||
|
||||
tbData.pCreateTbReq = pCreateTbReq;
|
||||
tbData.flags = SUBMIT_REQ_AUTO_CREATE_TABLE;
|
||||
} else {
|
||||
if (mr.me.type != TSDB_CHILD_TABLE) {
|
||||
tqError("vgId:%d, failed to write into %s, since table type incorrect, type %d", TD_VID(pVnode), ctbName,
|
||||
mr.me.type);
|
||||
metaReaderClear(&mr);
|
||||
taosMemoryFree(ctbName);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mr.me.ctbEntry.suid != suid) {
|
||||
tqError("vgId:%d, failed to write into %s, since suid mismatch, expect suid: %" PRId64
|
||||
", actual suid %" PRId64 "",
|
||||
TD_VID(pVnode), ctbName, suid, mr.me.ctbEntry.suid);
|
||||
metaReaderClear(&mr);
|
||||
taosMemoryFree(ctbName);
|
||||
}
|
||||
|
||||
tbData.uid = mr.me.uid;
|
||||
metaReaderClear(&mr);
|
||||
taosMemoryFreeClear(ctbName);
|
||||
}
|
||||
|
||||
// rows
|
||||
if (!pVals && !(pVals = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)))) {
|
||||
taosArrayDestroy(tbData.aRowP);
|
||||
goto _end;
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
taosArrayClear(pVals);
|
||||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
||||
const STColumn* pCol = &pTSchema->columns[k];
|
||||
SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
if (k == 0) {
|
||||
void* colData = colDataGetData(pColData, j);
|
||||
tqDebug("tq sink pipe2, row %d, col %d ts %" PRId64, j, k, *(int64_t*)colData);
|
||||
}
|
||||
if (colDataIsNull_s(pColData, j)) {
|
||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
void* colData = colDataGetData(pColData, j);
|
||||
if (IS_STR_DATA_TYPE(pCol->type)) {
|
||||
SValue sv =
|
||||
(SValue){.nData = varDataLen(colData), .pData = varDataVal(colData)}; // address copy, no value
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
SValue sv;
|
||||
memcpy(&sv.val, colData, tDataTypes[pCol->type].bytes);
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
}
|
||||
}
|
||||
}
|
||||
SRow* pRow = NULL;
|
||||
if ((terrno = tRowBuild(pVals, (STSchema*)pTSchema, &pRow)) < 0) {
|
||||
tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
|
||||
goto _end;
|
||||
}
|
||||
ASSERT(pRow);
|
||||
taosArrayPush(tbData.aRowP, &pRow);
|
||||
}
|
||||
|
||||
SSubmitReq2 submitReq = {0};
|
||||
if (!(submitReq.aSubmitTbData = taosArrayInit(1, sizeof(SSubmitTbData)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
taosArrayPush(submitReq.aSubmitTbData, &tbData);
|
||||
|
||||
// encode
|
||||
int32_t len;
|
||||
int32_t code;
|
||||
tEncodeSize(tEncodeSSubmitReq2, &submitReq, len, code);
|
||||
SEncoder encoder;
|
||||
len += sizeof(SMsgHead);
|
||||
pBuf = rpcMallocCont(len);
|
||||
if (NULL == pBuf) {
|
||||
goto _end;
|
||||
}
|
||||
((SMsgHead*)pBuf)->vgId = TD_VID(pVnode);
|
||||
((SMsgHead*)pBuf)->contLen = htonl(len);
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len - sizeof(SMsgHead));
|
||||
if (tEncodeSSubmitReq2(&encoder, &submitReq) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("failed to encode submit req since %s", terrstr());
|
||||
tEncoderClear(&encoder);
|
||||
rpcFreeCont(pBuf);
|
||||
continue;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
tDestroySSubmitReq2(&submitReq, TSDB_MSG_FLG_ENCODE);
|
||||
|
||||
SRpcMsg msg = {
|
||||
.msgType = TDMT_VND_SUBMIT,
|
||||
.pCont = pBuf,
|
||||
.contLen = len,
|
||||
};
|
||||
|
||||
if (tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &msg) != 0) {
|
||||
tqDebug("failed to put into write-queue since %s", terrstr());
|
||||
}
|
||||
}
|
||||
}
|
||||
_end:
|
||||
taosArrayDestroy(tagArray);
|
||||
taosArrayDestroy(pVals);
|
||||
// TODO: change
|
||||
}
|
||||
|
||||
#if 0
|
||||
void tqSinkToTableMerge(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
||||
const SArray* pRes = (const SArray*)data;
|
||||
|
|
|
@ -91,12 +91,10 @@ int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) {
|
|||
}
|
||||
}
|
||||
|
||||
taosLRUCacheRelease(pCache, h, invalidate);
|
||||
if (invalidate) {
|
||||
taosLRUCacheRelease(pCache, h, true);
|
||||
} else {
|
||||
taosLRUCacheRelease(pCache, h, false);
|
||||
taosLRUCacheErase(pCache, key, keyLen);
|
||||
}
|
||||
// void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -124,12 +122,10 @@ int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) {
|
|||
}
|
||||
}
|
||||
|
||||
taosLRUCacheRelease(pCache, h, invalidate);
|
||||
if (invalidate) {
|
||||
taosLRUCacheRelease(pCache, h, true);
|
||||
} else {
|
||||
taosLRUCacheRelease(pCache, h, false);
|
||||
taosLRUCacheErase(pCache, key, keyLen);
|
||||
}
|
||||
// void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -190,7 +186,7 @@ int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, STSRow *row, bool dup) {
|
||||
int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, TSDBROW *row, bool dup) {
|
||||
int32_t code = 0;
|
||||
STSRow *cacheRow = NULL;
|
||||
char key[32] = {0};
|
||||
|
@ -201,13 +197,51 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST
|
|||
LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||
if (h) {
|
||||
STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1);
|
||||
TSKEY keyTs = row->ts;
|
||||
TSKEY keyTs = TSDBROW_TS(row);
|
||||
bool invalidate = false;
|
||||
|
||||
SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h);
|
||||
int16_t nCol = taosArrayGetSize(pLast);
|
||||
int16_t iCol = 0;
|
||||
|
||||
if (nCol <= 0) {
|
||||
nCol = pTSchema->numOfCols;
|
||||
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
SColVal tColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = keyTs});
|
||||
if (taosArrayPush(pLast, &(SLastCol){.ts = keyTs, .colVal = tColVal}) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _invalidate;
|
||||
}
|
||||
|
||||
for (iCol = 1; iCol < nCol; ++iCol) {
|
||||
SColVal colVal = {0};
|
||||
tsdbRowGetColVal(row, pTSchema, iCol, &colVal);
|
||||
|
||||
SLastCol lastCol = {.ts = keyTs, .colVal = colVal};
|
||||
if (IS_VAR_DATA_TYPE(colVal.type) && colVal.value.nData > 0) {
|
||||
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pLast, iCol);
|
||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||
|
||||
lastCol.colVal.value.pData = taosMemoryMalloc(colVal.value.nData);
|
||||
if (lastCol.colVal.value.pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _invalidate;
|
||||
}
|
||||
memcpy(lastCol.colVal.value.pData, colVal.value.pData, colVal.value.nData);
|
||||
}
|
||||
|
||||
if (taosArrayPush(pLast, &lastCol) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _invalidate;
|
||||
}
|
||||
}
|
||||
|
||||
goto _invalidate;
|
||||
}
|
||||
|
||||
SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol);
|
||||
if (keyTs > tTsVal->ts) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
@ -222,7 +256,7 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST
|
|||
SColVal *tColVal = &tTsVal1->colVal;
|
||||
|
||||
SColVal colVal = {0};
|
||||
tTSRowGetVal(row, pTSchema, iCol, &colVal);
|
||||
tsdbRowGetColVal(row, pTSchema, iCol, &colVal);
|
||||
if (!COL_VAL_IS_NONE(&colVal)) {
|
||||
if (keyTs == tTsVal1->ts && !COL_VAL_IS_NONE(tColVal)) {
|
||||
invalidate = true;
|
||||
|
@ -261,7 +295,7 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb *pTsdb) {
|
||||
int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, TSDBROW *row, STsdb *pTsdb) {
|
||||
int32_t code = 0;
|
||||
STSRow *cacheRow = NULL;
|
||||
char key[32] = {0};
|
||||
|
@ -272,13 +306,51 @@ int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb
|
|||
LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||
if (h) {
|
||||
STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1);
|
||||
TSKEY keyTs = row->ts;
|
||||
TSKEY keyTs = TSDBROW_TS(row);
|
||||
bool invalidate = false;
|
||||
|
||||
SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h);
|
||||
int16_t nCol = taosArrayGetSize(pLast);
|
||||
int16_t iCol = 0;
|
||||
|
||||
if (nCol <= 0) {
|
||||
nCol = pTSchema->numOfCols;
|
||||
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
SColVal tColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = keyTs});
|
||||
if (taosArrayPush(pLast, &(SLastCol){.ts = keyTs, .colVal = tColVal}) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _invalidate;
|
||||
}
|
||||
|
||||
for (iCol = 1; iCol < nCol; ++iCol) {
|
||||
SColVal colVal = {0};
|
||||
tsdbRowGetColVal(row, pTSchema, iCol, &colVal);
|
||||
|
||||
SLastCol lastCol = {.ts = keyTs, .colVal = colVal};
|
||||
if (IS_VAR_DATA_TYPE(colVal.type) && colVal.value.nData > 0) {
|
||||
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pLast, iCol);
|
||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||
|
||||
lastCol.colVal.value.pData = taosMemoryMalloc(colVal.value.nData);
|
||||
if (lastCol.colVal.value.pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _invalidate;
|
||||
}
|
||||
memcpy(lastCol.colVal.value.pData, colVal.value.pData, colVal.value.nData);
|
||||
}
|
||||
|
||||
if (taosArrayPush(pLast, &lastCol) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _invalidate;
|
||||
}
|
||||
}
|
||||
|
||||
goto _invalidate;
|
||||
}
|
||||
|
||||
SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol);
|
||||
if (keyTs > tTsVal->ts) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
@ -293,7 +365,7 @@ int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb
|
|||
SColVal *tColVal = &tTsVal1->colVal;
|
||||
|
||||
SColVal colVal = {0};
|
||||
tTSRowGetVal(row, pTSchema, iCol, &colVal);
|
||||
tsdbRowGetColVal(row, pTSchema, iCol, &colVal);
|
||||
if (COL_VAL_IS_VALUE(&colVal)) {
|
||||
if (keyTs == tTsVal1->ts && COL_VAL_IS_VALUE(tColVal)) {
|
||||
invalidate = true;
|
||||
|
@ -617,7 +689,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
|
|||
} else {
|
||||
// tBlockDataDestroy(&state->blockData, 1);
|
||||
if (state->pBlockData) {
|
||||
tBlockDataDestroy(state->pBlockData, 1);
|
||||
tBlockDataDestroy(state->pBlockData);
|
||||
state->pBlockData = NULL;
|
||||
}
|
||||
|
||||
|
@ -685,7 +757,8 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
|
|||
tBlockDataReset(state->pBlockData);
|
||||
|
||||
tMapDataGetItemByIdx(&state->blockMap, state->iBlock, &block, tGetDataBlk);
|
||||
/* code = tsdbReadBlockData(state->pDataFReader, &state->blockIdx, &block, &state->blockData, NULL, NULL); */
|
||||
/* code = tsdbReadBlockData(state->pDataFReader, &state->blockIdx, &block, &state->blockData, NULL, NULL);
|
||||
*/
|
||||
tBlockDataReset(state->pBlockData);
|
||||
TABLEID tid = {.suid = state->suid, .uid = state->uid};
|
||||
code = tBlockDataInit(state->pBlockData, &tid, state->pTSchema, NULL, 0);
|
||||
|
@ -739,7 +812,7 @@ _err:
|
|||
state->aBlockIdx = NULL;
|
||||
}
|
||||
if (state->pBlockData) {
|
||||
tBlockDataDestroy(state->pBlockData, 1);
|
||||
tBlockDataDestroy(state->pBlockData);
|
||||
state->pBlockData = NULL;
|
||||
}
|
||||
|
||||
|
@ -766,7 +839,7 @@ int32_t clearNextRowFromFS(void *iter) {
|
|||
}
|
||||
if (state->pBlockData) {
|
||||
// tBlockDataDestroy(&state->blockData, 1);
|
||||
tBlockDataDestroy(state->pBlockData, 1);
|
||||
tBlockDataDestroy(state->pBlockData);
|
||||
state->pBlockData = NULL;
|
||||
}
|
||||
|
||||
|
@ -1219,12 +1292,12 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, SArray **ppCo
|
|||
|
||||
// build the result ts row here
|
||||
*dup = false;
|
||||
if (taosArrayGetSize(pColArray) != nCol) {
|
||||
*ppColArray = NULL;
|
||||
taosArrayDestroy(pColArray);
|
||||
} else {
|
||||
*ppColArray = pColArray;
|
||||
}
|
||||
// if (taosArrayGetSize(pColArray) != nCol) {
|
||||
//*ppColArray = NULL;
|
||||
// taosArrayDestroy(pColArray);
|
||||
//} else {
|
||||
*ppColArray = pColArray;
|
||||
//}
|
||||
|
||||
nextRowIterClose(&iter);
|
||||
// taosMemoryFreeClear(pTSchema);
|
||||
|
@ -1337,12 +1410,12 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
|
|||
}
|
||||
} while (setNoneCol);
|
||||
|
||||
if (taosArrayGetSize(pColArray) <= 0) {
|
||||
*ppLastArray = NULL;
|
||||
taosArrayDestroy(pColArray);
|
||||
} else {
|
||||
*ppLastArray = pColArray;
|
||||
}
|
||||
// if (taosArrayGetSize(pColArray) <= 0) {
|
||||
//*ppLastArray = NULL;
|
||||
// taosArrayDestroy(pColArray);
|
||||
//} else {
|
||||
*ppLastArray = pColArray;
|
||||
//}
|
||||
|
||||
nextRowIterClose(&iter);
|
||||
// taosMemoryFreeClear(pTSchema);
|
||||
|
@ -1373,8 +1446,8 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *
|
|||
SArray *pArray = NULL;
|
||||
bool dup = false; // which is always false for now
|
||||
code = mergeLastRow(uid, pTsdb, &dup, &pArray, pr);
|
||||
// if table's empty or error, return code of -1
|
||||
if (code < 0 || pArray == NULL) {
|
||||
// if table's empty or error, set handle NULL and return
|
||||
if (code < 0 /* || pArray == NULL*/) {
|
||||
if (!dup && pArray) {
|
||||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
@ -1392,13 +1465,8 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *
|
|||
if (status != TAOS_LRU_STATUS_OK) {
|
||||
code = -1;
|
||||
}
|
||||
|
||||
// taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||
|
||||
// h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||
} // else {
|
||||
}
|
||||
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||
//}
|
||||
}
|
||||
|
||||
*handle = h;
|
||||
|
@ -1422,8 +1490,8 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *pr,
|
|||
if (!h) {
|
||||
SArray *pLastArray = NULL;
|
||||
code = mergeLast(uid, pTsdb, &pLastArray, pr);
|
||||
// if table's empty or error, return code of -1
|
||||
if (code < 0 || pLastArray == NULL) {
|
||||
// if table's empty or error, set handle NULL and return
|
||||
if (code < 0 /* || pLastArray == NULL*/) {
|
||||
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||
|
||||
*handle = NULL;
|
||||
|
@ -1437,13 +1505,8 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *pr,
|
|||
if (status != TAOS_LRU_STATUS_OK) {
|
||||
code = -1;
|
||||
}
|
||||
|
||||
// taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||
|
||||
// h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||
} // else {
|
||||
}
|
||||
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||
//}
|
||||
}
|
||||
|
||||
*handle = h;
|
||||
|
|
|
@ -258,6 +258,10 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
if (h == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (taosArrayGetSize(pRow) <= 0) {
|
||||
tsdbCacheRelease(lruCache, h);
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
for (int32_t k = 0; k < pr->numOfCols; ++k) {
|
||||
|
@ -327,6 +331,10 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
if (h == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (taosArrayGetSize(pRow) <= 0) {
|
||||
tsdbCacheRelease(lruCache, h);
|
||||
continue;
|
||||
}
|
||||
|
||||
saveOneRow(pRow, pResBlock, pr, slotIds, pRes, pr->idstr);
|
||||
// TODO reset the pRes
|
||||
|
|
|
@ -913,24 +913,24 @@ static void tsdbCommitDataEnd(SCommitter *pCommitter) {
|
|||
// reader
|
||||
taosArrayDestroy(pCommitter->dReader.aBlockIdx);
|
||||
tMapDataClear(&pCommitter->dReader.mBlock);
|
||||
tBlockDataDestroy(&pCommitter->dReader.bData, 1);
|
||||
tBlockDataDestroy(&pCommitter->dReader.bData);
|
||||
|
||||
// merger
|
||||
for (int32_t iStt = 0; iStt < TSDB_MAX_STT_TRIGGER; iStt++) {
|
||||
SDataIter *pIter = &pCommitter->aDataIter[iStt];
|
||||
taosArrayDestroy(pIter->aSttBlk);
|
||||
tBlockDataDestroy(&pIter->bData, 1);
|
||||
tBlockDataDestroy(&pIter->bData);
|
||||
}
|
||||
|
||||
// writer
|
||||
taosArrayDestroy(pCommitter->dWriter.aBlockIdx);
|
||||
taosArrayDestroy(pCommitter->dWriter.aSttBlk);
|
||||
tMapDataClear(&pCommitter->dWriter.mBlock);
|
||||
tBlockDataDestroy(&pCommitter->dWriter.bData, 1);
|
||||
tBlockDataDestroy(&pCommitter->dWriter.bData);
|
||||
#if USE_STREAM_COMPRESSION
|
||||
tDiskDataBuilderDestroy(pCommitter->dWriter.pBuilder);
|
||||
#else
|
||||
tBlockDataDestroy(&pCommitter->dWriter.bDatal, 1);
|
||||
tBlockDataDestroy(&pCommitter->dWriter.bDatal);
|
||||
#endif
|
||||
tDestroyTSchema(pCommitter->skmTable.pTSchema);
|
||||
tDestroyTSchema(pCommitter->skmRow.pTSchema);
|
||||
|
@ -1183,7 +1183,6 @@ static int32_t tsdbCommitAheadBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
|
|||
|
||||
tBlockDataClear(pBlockData);
|
||||
while (pRowInfo) {
|
||||
ASSERT(pRowInfo->row.type == 0);
|
||||
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
|
@ -1251,7 +1250,6 @@ static int32_t tsdbCommitMergeBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
|
|||
pRow = NULL;
|
||||
}
|
||||
} else if (c > 0) {
|
||||
ASSERT(pRowInfo->row.type == 0);
|
||||
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
|
@ -1493,7 +1491,7 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) {
|
|||
|
||||
while (pRowInfo) {
|
||||
STSchema *pTSchema = NULL;
|
||||
if (pRowInfo->row.type == 0) {
|
||||
if (pRowInfo->row.type == TSDBROW_ROW_FMT) {
|
||||
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
pTSchema = pCommitter->skmRow.pTSchema;
|
||||
|
@ -1536,7 +1534,7 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) {
|
|||
|
||||
while (pRowInfo) {
|
||||
STSchema *pTSchema = NULL;
|
||||
if (pRowInfo->row.type == 0) {
|
||||
if (pRowInfo->row.type == TSDBROW_ROW_FMT) {
|
||||
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
pTSchema = pCommitter->skmRow.pTSchema;
|
||||
|
|
|
@ -596,7 +596,7 @@ int32_t tDiskDataAddRow(SDiskDataBuilder *pBuilder, TSDBROW *pRow, STSchema *pTS
|
|||
if (pBuilder->bi.maxKey < kRow.ts) pBuilder->bi.maxKey = kRow.ts;
|
||||
|
||||
STSDBRowIter iter = {0};
|
||||
tsdbRowIterInit(&iter, pRow, pTSchema);
|
||||
tsdbRowIterOpen(&iter, pRow, pTSchema);
|
||||
|
||||
SColVal *pColVal = tsdbRowIterNext(&iter);
|
||||
for (int32_t iBuilder = 0; iBuilder < pBuilder->nBuilder; iBuilder++) {
|
||||
|
|
|
@ -28,8 +28,10 @@
|
|||
|
||||
static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags);
|
||||
static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData);
|
||||
static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||
SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkRsp *pRsp);
|
||||
static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||
SSubmitTbData *pSubmitTbData, int32_t *affectedRows);
|
||||
static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||
SSubmitTbData *pSubmitTbData, int32_t *affectedRows);
|
||||
|
||||
int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) {
|
||||
int32_t code = 0;
|
||||
|
@ -95,14 +97,14 @@ STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t
|
|||
return pTbData;
|
||||
}
|
||||
|
||||
int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock,
|
||||
SSubmitBlkRsp *pRsp) {
|
||||
int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitTbData *pSubmitTbData, int32_t *affectedRows) {
|
||||
int32_t code = 0;
|
||||
SMemTable *pMemTable = pTsdb->mem;
|
||||
STbData *pTbData = NULL;
|
||||
tb_uid_t suid = pMsgIter->suid;
|
||||
tb_uid_t uid = pMsgIter->uid;
|
||||
tb_uid_t suid = pSubmitTbData->suid;
|
||||
tb_uid_t uid = pSubmitTbData->uid;
|
||||
|
||||
#if 0
|
||||
SMetaInfo info;
|
||||
code = metaGetInfo(pTsdb->pVnode->pMeta, uid, &info, NULL);
|
||||
if (code) {
|
||||
|
@ -116,14 +118,15 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgI
|
|||
if (info.suid) {
|
||||
metaGetInfo(pTsdb->pVnode->pMeta, info.suid, &info, NULL);
|
||||
}
|
||||
if (pMsgIter->sversion != info.skmVer) {
|
||||
if (pSubmitTbData->sver != info.skmVer) {
|
||||
tsdbError("vgId:%d, req sver:%d, skmVer:%d suid:%" PRId64 " uid:%" PRId64, TD_VID(pTsdb->pVnode),
|
||||
pMsgIter->sversion, info.skmVer, suid, uid);
|
||||
pSubmitTbData->sver, info.skmVer, suid, uid);
|
||||
code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
pRsp->sver = info.skmVer;
|
||||
if (pRsp) pRsp->sver = info.skmVer;
|
||||
#endif
|
||||
|
||||
// create/get STbData to op
|
||||
code = tsdbGetOrCreateTbData(pMemTable, suid, uid, &pTbData);
|
||||
|
@ -132,10 +135,12 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgI
|
|||
}
|
||||
|
||||
// do insert impl
|
||||
code = tsdbInsertTableDataImpl(pMemTable, pTbData, version, pMsgIter, pBlock, pRsp);
|
||||
if (code) {
|
||||
goto _err;
|
||||
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
code = tsdbInsertColDataToTable(pMemTable, pTbData, version, pSubmitTbData, affectedRows);
|
||||
} else {
|
||||
code = tsdbInsertRowDataToTable(pMemTable, pTbData, version, pSubmitTbData, affectedRows);
|
||||
}
|
||||
if (code) goto _err;
|
||||
|
||||
return code;
|
||||
|
||||
|
@ -242,7 +247,6 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDa
|
|||
pIter->pTbData = pTbData;
|
||||
pIter->backward = backward;
|
||||
pIter->pRow = NULL;
|
||||
pIter->row.type = 0;
|
||||
if (pFrom == NULL) {
|
||||
// create from head or tail
|
||||
if (backward) {
|
||||
|
@ -410,8 +414,13 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
|||
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
||||
pn = SL_NODE_BACKWARD(px, iLevel);
|
||||
while (pn != pTbData->sl.pHead) {
|
||||
tKey.version = pn->version;
|
||||
tKey.ts = pn->pTSRow->ts;
|
||||
if (pn->flag == TSDBROW_ROW_FMT) {
|
||||
tKey.version = pn->version;
|
||||
tKey.ts = ((SRow *)pn->pData)->ts;
|
||||
} else if (pn->flag == TSDBROW_COL_FMT) {
|
||||
tKey.version = ((SBlockData *)pn->pData)->aVersion[pn->iRow];
|
||||
tKey.ts = ((SBlockData *)pn->pData)->aTSKEY[pn->iRow];
|
||||
}
|
||||
|
||||
int32_t c = tsdbKeyCmprFn(&tKey, pKey);
|
||||
if (c <= 0) {
|
||||
|
@ -440,8 +449,13 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
|||
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
||||
pn = SL_NODE_FORWARD(px, iLevel);
|
||||
while (pn != pTbData->sl.pTail) {
|
||||
tKey.version = pn->version;
|
||||
tKey.ts = pn->pTSRow->ts;
|
||||
if (pn->flag == TSDBROW_ROW_FMT) {
|
||||
tKey.version = pn->version;
|
||||
tKey.ts = ((SRow *)pn->pData)->ts;
|
||||
} else if (pn->flag == TSDBROW_COL_FMT) {
|
||||
tKey.version = ((SBlockData *)pn->pData)->aVersion[pn->iRow];
|
||||
tKey.ts = ((SBlockData *)pn->pData)->aTSKEY[pn->iRow];
|
||||
}
|
||||
|
||||
int32_t c = tsdbKeyCmprFn(&tKey, pKey);
|
||||
if (c >= 0) {
|
||||
|
@ -468,29 +482,39 @@ static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
|
|||
|
||||
return level;
|
||||
}
|
||||
static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListNode **pos, int64_t version,
|
||||
STSRow *pRow, int8_t forward) {
|
||||
static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListNode **pos, TSDBROW *pRow,
|
||||
int8_t forward) {
|
||||
int32_t code = 0;
|
||||
int8_t level;
|
||||
SMemSkipListNode *pNode;
|
||||
SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse;
|
||||
|
||||
ASSERT(pPool != NULL);
|
||||
|
||||
// node
|
||||
level = tsdbMemSkipListRandLevel(&pTbData->sl);
|
||||
ASSERT(pPool != NULL);
|
||||
pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level));
|
||||
if (pNode == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
pNode->level = level;
|
||||
pNode->version = version;
|
||||
pNode->pTSRow = vnodeBufPoolMalloc(pPool, pRow->len);
|
||||
if (NULL == pNode->pTSRow) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
pNode->flag = pRow->type;
|
||||
|
||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||
pNode->version = pRow->version;
|
||||
pNode->pData = vnodeBufPoolMalloc(pPool, pRow->pTSRow->len);
|
||||
if (NULL == pNode->pData) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
memcpy(pNode->pData, pRow->pTSRow, pRow->pTSRow->len);
|
||||
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||
pNode->iRow = pRow->iRow;
|
||||
pNode->pData = pRow->pBlockData;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
memcpy(pNode->pTSRow, pRow, pRow->len);
|
||||
|
||||
for (int8_t iLevel = level - 1; iLevel >= 0; iLevel--) {
|
||||
SMemSkipListNode *pn = pos[iLevel];
|
||||
|
@ -537,69 +561,166 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||
SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkRsp *pRsp) {
|
||||
int32_t code = 0;
|
||||
SSubmitBlkIter blkIter = {0};
|
||||
TSDBKEY key = {.version = version};
|
||||
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
||||
TSDBROW row = tsdbRowFromTSRow(version, NULL);
|
||||
int32_t nRow = 0;
|
||||
STSRow *pLastRow = NULL;
|
||||
static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||
SSubmitTbData *pSubmitTbData, int32_t *affectedRows) {
|
||||
int32_t code = 0;
|
||||
|
||||
tInitSubmitBlkIter(pMsgIter, pBlock, &blkIter);
|
||||
SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse;
|
||||
int32_t nColData = TARRAY_SIZE(pSubmitTbData->aCol);
|
||||
SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
|
||||
|
||||
// backward put first data
|
||||
row.pTSRow = tGetSubmitBlkNext(&blkIter);
|
||||
if (row.pTSRow == NULL) return code;
|
||||
ASSERT(aColData[0].cid == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
ASSERT(aColData[0].type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
ASSERT(aColData[0].flag == HAS_VALUE);
|
||||
|
||||
key.ts = row.pTSRow->ts;
|
||||
nRow++;
|
||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
|
||||
code = tbDataDoPut(pMemTable, pTbData, pos, version, row.pTSRow, 0);
|
||||
if (code) {
|
||||
goto _err;
|
||||
// copy and construct block data
|
||||
SBlockData *pBlockData = vnodeBufPoolMalloc(pPool, sizeof(*pBlockData));
|
||||
if (pBlockData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pBlockData->suid = pTbData->suid;
|
||||
pBlockData->uid = pTbData->uid;
|
||||
pBlockData->nRow = aColData[0].nVal;
|
||||
pBlockData->aUid = NULL;
|
||||
pBlockData->aVersion = vnodeBufPoolMalloc(pPool, aColData[0].nData);
|
||||
if (pBlockData->aVersion == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
for (int32_t i = 0; i < pBlockData->nRow; i++) { // todo: here can be optimized
|
||||
pBlockData->aVersion[i] = version;
|
||||
}
|
||||
|
||||
pBlockData->aTSKEY = vnodeBufPoolMalloc(pPool, aColData[0].nData);
|
||||
if (pBlockData->aTSKEY == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
memcpy(pBlockData->aTSKEY, aColData[0].pData, aColData[0].nData);
|
||||
|
||||
pBlockData->nColData = nColData - 1;
|
||||
pBlockData->aColData = vnodeBufPoolMalloc(pPool, sizeof(SColData) * pBlockData->nColData);
|
||||
if (pBlockData->aColData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; ++iColData) {
|
||||
code = tColDataCopy(&aColData[iColData + 1], &pBlockData->aColData[iColData], (xMallocFn)vnodeBufPoolMalloc, pPool);
|
||||
if (code) goto _exit;
|
||||
}
|
||||
|
||||
// loop to add each row to the skiplist
|
||||
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
||||
TSDBROW tRow = tsdbRowFromBlockData(pBlockData, 0);
|
||||
TSDBKEY key = {.version = version, .ts = pBlockData->aTSKEY[0]};
|
||||
TSDBROW lRow; // last row
|
||||
|
||||
// first row
|
||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
|
||||
if ((code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 0))) goto _exit;
|
||||
pTbData->minKey = TMIN(pTbData->minKey, key.ts);
|
||||
lRow = tRow;
|
||||
|
||||
pLastRow = row.pTSRow;
|
||||
|
||||
// forward put rest data
|
||||
row.pTSRow = tGetSubmitBlkNext(&blkIter);
|
||||
if (row.pTSRow) {
|
||||
// remain row
|
||||
++tRow.iRow;
|
||||
if (tRow.iRow < pBlockData->nRow) {
|
||||
for (int8_t iLevel = pos[0]->level; iLevel < pTbData->sl.maxLevel; iLevel++) {
|
||||
pos[iLevel] = SL_NODE_BACKWARD(pos[iLevel], iLevel);
|
||||
}
|
||||
do {
|
||||
key.ts = row.pTSRow->ts;
|
||||
nRow++;
|
||||
|
||||
while (tRow.iRow < pBlockData->nRow) {
|
||||
key.ts = pBlockData->aTSKEY[tRow.iRow];
|
||||
|
||||
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
||||
}
|
||||
code = tbDataDoPut(pMemTable, pTbData, pos, version, row.pTSRow, 1);
|
||||
if (code) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
pLastRow = row.pTSRow;
|
||||
if ((code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 1))) goto _exit;
|
||||
lRow = tRow;
|
||||
|
||||
row.pTSRow = tGetSubmitBlkNext(&blkIter);
|
||||
} while (row.pTSRow);
|
||||
++tRow.iRow;
|
||||
}
|
||||
}
|
||||
|
||||
if (key.ts >= pTbData->maxKey) {
|
||||
if (key.ts > pTbData->maxKey) {
|
||||
pTbData->maxKey = key.ts;
|
||||
}
|
||||
pTbData->maxKey = key.ts;
|
||||
|
||||
if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config) && pLastRow != NULL) {
|
||||
tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, pLastRow, true);
|
||||
if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config)) {
|
||||
tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, &lRow, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CACHE_LAST(pMemTable->pTsdb->pVnode->config)) {
|
||||
tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, pLastRow, pMemTable->pTsdb);
|
||||
tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, &lRow, pMemTable->pTsdb);
|
||||
}
|
||||
|
||||
// SMemTable
|
||||
pMemTable->minKey = TMIN(pMemTable->minKey, pTbData->minKey);
|
||||
pMemTable->maxKey = TMAX(pMemTable->maxKey, pTbData->maxKey);
|
||||
pMemTable->nRow += pBlockData->nRow;
|
||||
|
||||
if (affectedRows) *affectedRows = pBlockData->nRow;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||
SSubmitTbData *pSubmitTbData, int32_t *affectedRows) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t nRow = TARRAY_SIZE(pSubmitTbData->aRowP);
|
||||
SRow **aRow = (SRow **)TARRAY_DATA(pSubmitTbData->aRowP);
|
||||
TSDBKEY key = {.version = version};
|
||||
SMemSkipListNode *pos[SL_MAX_LEVEL];
|
||||
TSDBROW tRow = {.type = TSDBROW_ROW_FMT, .version = version};
|
||||
int32_t iRow = 0;
|
||||
TSDBROW lRow;
|
||||
|
||||
// backward put first data
|
||||
tRow.pTSRow = aRow[iRow++];
|
||||
key.ts = tRow.pTSRow->ts;
|
||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
|
||||
code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 0);
|
||||
if (code) goto _exit;
|
||||
lRow = tRow;
|
||||
|
||||
pTbData->minKey = TMIN(pTbData->minKey, key.ts);
|
||||
|
||||
// forward put rest data
|
||||
if (iRow < nRow) {
|
||||
for (int8_t iLevel = pos[0]->level; iLevel < pTbData->sl.maxLevel; iLevel++) {
|
||||
pos[iLevel] = SL_NODE_BACKWARD(pos[iLevel], iLevel);
|
||||
}
|
||||
|
||||
while (iRow < nRow) {
|
||||
tRow.pTSRow = aRow[iRow];
|
||||
key.ts = tRow.pTSRow->ts;
|
||||
|
||||
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
||||
}
|
||||
|
||||
code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 1);
|
||||
if (code) goto _exit;
|
||||
|
||||
lRow = tRow;
|
||||
|
||||
iRow++;
|
||||
}
|
||||
}
|
||||
|
||||
if (key.ts >= pTbData->maxKey) {
|
||||
pTbData->maxKey = key.ts;
|
||||
|
||||
if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config)) {
|
||||
tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, &lRow, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CACHE_LAST(pMemTable->pTsdb->pVnode->config)) {
|
||||
tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, &lRow, pMemTable->pTsdb);
|
||||
}
|
||||
|
||||
// SMemTable
|
||||
|
@ -607,12 +728,9 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
|
|||
pMemTable->maxKey = TMAX(pMemTable->maxKey, pTbData->maxKey);
|
||||
pMemTable->nRow += nRow;
|
||||
|
||||
pRsp->numOfRows = nRow;
|
||||
pRsp->affectedRows = nRow;
|
||||
if (affectedRows) *affectedRows = nRow;
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,8 +89,8 @@ void *destroyLastBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo) {
|
|||
pLoadInfo[i].blockIndex[0] = -1;
|
||||
pLoadInfo[i].blockIndex[1] = -1;
|
||||
|
||||
tBlockDataDestroy(&pLoadInfo[i].blockData[0], true);
|
||||
tBlockDataDestroy(&pLoadInfo[i].blockData[1], true);
|
||||
tBlockDataDestroy(&pLoadInfo[i].blockData[0]);
|
||||
tBlockDataDestroy(&pLoadInfo[i].blockData[1]);
|
||||
|
||||
taosArrayDestroy(pLoadInfo[i].aSttBlk);
|
||||
}
|
||||
|
@ -567,7 +567,6 @@ int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFRead
|
|||
|
||||
pMTree->pLoadInfo = pBlockLoadInfo;
|
||||
pMTree->destroyLoadInfo = destroyLoadInfo;
|
||||
ASSERT(pMTree->pLoadInfo != NULL);
|
||||
|
||||
for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) { // open all last file
|
||||
struct SLDataIter *pIter = NULL;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -538,7 +538,7 @@ _exit:
|
|||
if (pReader) {
|
||||
taosArrayDestroy(pReader->aDelData);
|
||||
taosArrayDestroy(pReader->aDelIdx);
|
||||
tBlockDataDestroy(&pReader->bData, 1);
|
||||
tBlockDataDestroy(&pReader->bData);
|
||||
tsdbFSDestroy(&pReader->fs);
|
||||
taosMemoryFree(pReader);
|
||||
}
|
||||
|
@ -565,10 +565,10 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader) {
|
|||
taosArrayDestroy(pIter->aSttBlk);
|
||||
}
|
||||
|
||||
tBlockDataDestroy(&pIter->bData, 1);
|
||||
tBlockDataDestroy(&pIter->bData);
|
||||
}
|
||||
|
||||
tBlockDataDestroy(&pReader->bData, 1);
|
||||
tBlockDataDestroy(&pReader->bData);
|
||||
tDestroyTSchema(pReader->skmTable.pTSchema);
|
||||
|
||||
// del
|
||||
|
@ -1359,13 +1359,13 @@ _exit:
|
|||
if (pWriter->aDelIdxW) taosArrayDestroy(pWriter->aDelIdxW);
|
||||
if (pWriter->aDelData) taosArrayDestroy(pWriter->aDelData);
|
||||
if (pWriter->aDelIdxR) taosArrayDestroy(pWriter->aDelIdxR);
|
||||
tBlockDataDestroy(&pWriter->dWriter.sData, 1);
|
||||
tBlockDataDestroy(&pWriter->dWriter.bData, 1);
|
||||
tBlockDataDestroy(&pWriter->dWriter.sData);
|
||||
tBlockDataDestroy(&pWriter->dWriter.bData);
|
||||
if (pWriter->dWriter.aSttBlk) taosArrayDestroy(pWriter->dWriter.aSttBlk);
|
||||
if (pWriter->dWriter.aBlockIdx) taosArrayDestroy(pWriter->dWriter.aBlockIdx);
|
||||
tBlockDataDestroy(&pWriter->dReader.bData, 1);
|
||||
tBlockDataDestroy(&pWriter->dReader.bData);
|
||||
if (pWriter->dReader.aBlockIdx) taosArrayDestroy(pWriter->dReader.aBlockIdx);
|
||||
tBlockDataDestroy(&pWriter->bData, 1);
|
||||
tBlockDataDestroy(&pWriter->bData);
|
||||
tsdbFSDestroy(&pWriter->fs);
|
||||
taosMemoryFree(pWriter);
|
||||
}
|
||||
|
@ -1425,18 +1425,18 @@ int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback) {
|
|||
// SNAP_DATA_TSDB
|
||||
|
||||
// Writer
|
||||
tBlockDataDestroy(&pWriter->dWriter.sData, 1);
|
||||
tBlockDataDestroy(&pWriter->dWriter.bData, 1);
|
||||
tBlockDataDestroy(&pWriter->dWriter.sData);
|
||||
tBlockDataDestroy(&pWriter->dWriter.bData);
|
||||
taosArrayDestroy(pWriter->dWriter.aSttBlk);
|
||||
tMapDataClear(&pWriter->dWriter.mDataBlk);
|
||||
taosArrayDestroy(pWriter->dWriter.aBlockIdx);
|
||||
|
||||
// Reader
|
||||
tBlockDataDestroy(&pWriter->dReader.bData, 1);
|
||||
tBlockDataDestroy(&pWriter->dReader.bData);
|
||||
tMapDataClear(&pWriter->dReader.mDataBlk);
|
||||
taosArrayDestroy(pWriter->dReader.aBlockIdx);
|
||||
|
||||
tBlockDataDestroy(&pWriter->bData, 1);
|
||||
tBlockDataDestroy(&pWriter->bData);
|
||||
tDestroyTSchema(pWriter->skmTable.pTSchema);
|
||||
|
||||
for (int32_t iBuf = 0; iBuf < sizeof(pWriter->aBuf) / sizeof(uint8_t*); iBuf++) {
|
||||
|
|
|
@ -23,7 +23,7 @@ void tMapDataReset(SMapData *pMapData) {
|
|||
}
|
||||
|
||||
void tMapDataClear(SMapData *pMapData) {
|
||||
tFree((uint8_t *)pMapData->aOffset);
|
||||
tFree(pMapData->aOffset);
|
||||
tFree(pMapData->pData);
|
||||
pMapData->pData = NULL;
|
||||
pMapData->aOffset = NULL;
|
||||
|
@ -572,9 +572,9 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *
|
|||
|
||||
ASSERT(iCol > 0);
|
||||
|
||||
if (pRow->type == 0) {
|
||||
tTSRowGetVal(pRow->pTSRow, pTSchema, iCol, pColVal);
|
||||
} else if (pRow->type == 1) {
|
||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||
tRowGet(pRow->pTSRow, pTSchema, iCol, pColVal);
|
||||
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||
SColData *pColData;
|
||||
|
||||
tBlockDataGetColData(pRow->pBlockData, pTColumn->colId, &pColData);
|
||||
|
@ -589,60 +589,61 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *
|
|||
}
|
||||
}
|
||||
|
||||
// int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow) {
|
||||
// int32_t n = 0;
|
||||
|
||||
// n += tPutI64(p, pRow->version);
|
||||
// if (p) memcpy(p + n, pRow->pTSRow, pRow->pTSRow->len);
|
||||
// n += pRow->pTSRow->len;
|
||||
|
||||
// return n;
|
||||
// }
|
||||
|
||||
int32_t tsdbRowCmprFn(const void *p1, const void *p2) {
|
||||
return tsdbKeyCmprFn(&TSDBROW_KEY((TSDBROW *)p1), &TSDBROW_KEY((TSDBROW *)p2));
|
||||
}
|
||||
|
||||
// STSDBRowIter ======================================================
|
||||
void tsdbRowIterInit(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
|
||||
pIter->pRow = pRow;
|
||||
if (pRow->type == 0) {
|
||||
ASSERT(pTSchema);
|
||||
pIter->pTSchema = pTSchema;
|
||||
pIter->i = 1;
|
||||
} else if (pRow->type == 1) {
|
||||
pIter->pTSchema = NULL;
|
||||
pIter->i = 0;
|
||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||
code = tRowIterOpen(pRow->pTSRow, pTSchema, &pIter->pIter);
|
||||
if (code) goto _exit;
|
||||
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||
pIter->iColData = 0;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
void tsdbRowClose(STSDBRowIter *pIter) {
|
||||
if (pIter->pRow->type == TSDBROW_ROW_FMT) {
|
||||
tRowIterClose(&pIter->pIter);
|
||||
}
|
||||
}
|
||||
|
||||
SColVal *tsdbRowIterNext(STSDBRowIter *pIter) {
|
||||
if (pIter->pRow->type == 0) {
|
||||
if (pIter->i < pIter->pTSchema->numOfCols) {
|
||||
tTSRowGetVal(pIter->pRow->pTSRow, pIter->pTSchema, pIter->i, &pIter->colVal);
|
||||
pIter->i++;
|
||||
if (pIter->pRow->type == TSDBROW_ROW_FMT) {
|
||||
return tRowIterNext(pIter->pIter);
|
||||
} else if (pIter->pRow->type == TSDBROW_COL_FMT) {
|
||||
if (pIter->iColData == 0) {
|
||||
pIter->cv = COL_VAL_VALUE(PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP,
|
||||
(SValue){.val = pIter->pRow->pBlockData->aTSKEY[pIter->pRow->iRow]});
|
||||
++pIter->iColData;
|
||||
return &pIter->cv;
|
||||
}
|
||||
|
||||
return &pIter->colVal;
|
||||
if (pIter->iColData < pIter->pRow->pBlockData->nColData) {
|
||||
tColDataGetValue(&pIter->pRow->pBlockData->aColData[pIter->iColData], pIter->pRow->iRow, &pIter->cv);
|
||||
++pIter->iColData;
|
||||
return &pIter->cv;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (pIter->i < pIter->pRow->pBlockData->nColData) {
|
||||
SColData *pColData = tBlockDataGetColDataByIdx(pIter->pRow->pBlockData, pIter->i);
|
||||
|
||||
tColDataGetValue(pColData, pIter->pRow->iRow, &pIter->colVal);
|
||||
pIter->i++;
|
||||
|
||||
return &pIter->colVal;
|
||||
}
|
||||
ASSERT(0);
|
||||
return NULL; // suppress error report by compiler
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// SRowMerger ======================================================
|
||||
|
||||
int32_t tRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t tsdbRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||
SColVal *pColVal = &(SColVal){0};
|
||||
|
@ -697,7 +698,7 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||
SColVal *pColVal = &(SColVal){0};
|
||||
|
@ -736,7 +737,7 @@ int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||
SColVal *pColVal = &(SColVal){0};
|
||||
|
@ -775,9 +776,9 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
void tRowMergerClear(SRowMerger *pMerger) { taosArrayDestroy(pMerger->pArray); }
|
||||
void tsdbRowMergerClear(SRowMerger *pMerger) { taosArrayDestroy(pMerger->pArray); }
|
||||
|
||||
int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
||||
int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
||||
int32_t code = 0;
|
||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||
SColVal *pColVal = &(SColVal){0};
|
||||
|
@ -807,12 +808,8 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tRowMergerGetRow(SRowMerger *pMerger, STSRow **ppRow) {
|
||||
int32_t code = 0;
|
||||
|
||||
code = tdSTSRowNew(pMerger->pArray, pMerger->pTSchema, ppRow);
|
||||
|
||||
return code;
|
||||
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow) {
|
||||
return tRowBuild(pMerger->pArray, pMerger->pTSchema, ppRow);
|
||||
}
|
||||
|
||||
// delete skyline ======================================================
|
||||
|
@ -931,27 +928,49 @@ int32_t tBlockDataCreate(SBlockData *pBlockData) {
|
|||
pBlockData->aVersion = NULL;
|
||||
pBlockData->aTSKEY = NULL;
|
||||
pBlockData->nColData = 0;
|
||||
pBlockData->aColData = taosArrayInit(0, sizeof(SColData));
|
||||
if (pBlockData->aColData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
pBlockData->aColData = NULL;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
void tBlockDataDestroy(SBlockData *pBlockData, int8_t deepClear) {
|
||||
tFree((uint8_t *)pBlockData->aUid);
|
||||
tFree((uint8_t *)pBlockData->aVersion);
|
||||
tFree((uint8_t *)pBlockData->aTSKEY);
|
||||
taosArrayDestroyEx(pBlockData->aColData, deepClear ? tColDataDestroy : NULL);
|
||||
pBlockData->aUid = NULL;
|
||||
pBlockData->aVersion = NULL;
|
||||
pBlockData->aTSKEY = NULL;
|
||||
pBlockData->aColData = NULL;
|
||||
void tBlockDataDestroy(SBlockData *pBlockData) {
|
||||
tFree(pBlockData->aUid);
|
||||
tFree(pBlockData->aVersion);
|
||||
tFree(pBlockData->aTSKEY);
|
||||
|
||||
for (int32_t i = 0; i < pBlockData->nColData; i++) {
|
||||
tColDataDestroy(&pBlockData->aColData[i]);
|
||||
}
|
||||
|
||||
if (pBlockData->aColData) {
|
||||
taosMemoryFree(pBlockData->aColData);
|
||||
pBlockData->aColData = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t tBlockDataAdjustColData(SBlockData *pBlockData, int32_t nColData) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (pBlockData->nColData > nColData) {
|
||||
for (int32_t i = nColData; i < pBlockData->nColData; i++) {
|
||||
tColDataDestroy(&pBlockData->aColData[i]);
|
||||
}
|
||||
} else if (pBlockData->nColData < nColData) {
|
||||
SColData *aColData = taosMemoryRealloc(pBlockData->aColData, sizeof(SBlockData) * nColData);
|
||||
if (aColData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pBlockData->aColData = aColData;
|
||||
memset(&pBlockData->aColData[pBlockData->nColData], 0, sizeof(SBlockData) * (nColData - pBlockData->nColData));
|
||||
}
|
||||
pBlockData->nColData = nColData;
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, int16_t *aCid, int32_t nCid) {
|
||||
int32_t code = 0;
|
||||
|
||||
|
@ -961,37 +980,35 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema,
|
|||
pBlockData->uid = pId->uid;
|
||||
pBlockData->nRow = 0;
|
||||
|
||||
pBlockData->nColData = 0;
|
||||
if (aCid) {
|
||||
code = tBlockDataAdjustColData(pBlockData, nCid);
|
||||
if (code) goto _exit;
|
||||
|
||||
int32_t iColumn = 1;
|
||||
STColumn *pTColumn = &pTSchema->columns[iColumn];
|
||||
for (int32_t iCid = 0; iCid < nCid; iCid++) {
|
||||
while (pTColumn && pTColumn->colId < aCid[iCid]) {
|
||||
ASSERT(pTColumn);
|
||||
while (pTColumn->colId < aCid[iCid]) {
|
||||
iColumn++;
|
||||
pTColumn = (iColumn < pTSchema->numOfCols) ? &pTSchema->columns[iColumn] : NULL;
|
||||
ASSERT(iColumn < pTSchema->numOfCols);
|
||||
pTColumn = &pTSchema->columns[iColumn];
|
||||
}
|
||||
|
||||
if (pTColumn == NULL) {
|
||||
break;
|
||||
} else if (pTColumn->colId == aCid[iCid]) {
|
||||
SColData *pColData;
|
||||
code = tBlockDataAddColData(pBlockData, &pColData);
|
||||
if (code) goto _exit;
|
||||
tColDataInit(pColData, pTColumn->colId, pTColumn->type, (pTColumn->flags & COL_SMA_ON) ? 1 : 0);
|
||||
ASSERT(pTColumn->colId == aCid[iCid]);
|
||||
tColDataInit(&pBlockData->aColData[iCid], pTColumn->colId, pTColumn->type,
|
||||
(pTColumn->flags & COL_SMA_ON) ? 1 : 0);
|
||||
|
||||
iColumn++;
|
||||
pTColumn = (iColumn < pTSchema->numOfCols) ? &pTSchema->columns[iColumn] : NULL;
|
||||
}
|
||||
iColumn++;
|
||||
pTColumn = (iColumn < pTSchema->numOfCols) ? &pTSchema->columns[iColumn] : NULL;
|
||||
}
|
||||
} else {
|
||||
for (int32_t iColumn = 1; iColumn < pTSchema->numOfCols; iColumn++) {
|
||||
STColumn *pTColumn = &pTSchema->columns[iColumn];
|
||||
code = tBlockDataAdjustColData(pBlockData, pTSchema->numOfCols - 1);
|
||||
if (code) goto _exit;
|
||||
|
||||
SColData *pColData;
|
||||
code = tBlockDataAddColData(pBlockData, &pColData);
|
||||
if (code) goto _exit;
|
||||
|
||||
tColDataInit(pColData, pTColumn->colId, pTColumn->type, (pTColumn->flags & COL_SMA_ON) ? 1 : 0);
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||
STColumn *pTColumn = &pTSchema->columns[iColData + 1];
|
||||
tColDataInit(&pBlockData->aColData[iColData], pTColumn->colId, pTColumn->type,
|
||||
(pTColumn->flags & COL_SMA_ON) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1002,8 +1019,6 @@ _exit:
|
|||
void tBlockDataReset(SBlockData *pBlockData) {
|
||||
pBlockData->suid = 0;
|
||||
pBlockData->uid = 0;
|
||||
pBlockData->nRow = 0;
|
||||
pBlockData->nColData = 0;
|
||||
}
|
||||
|
||||
void tBlockDataClear(SBlockData *pBlockData) {
|
||||
|
@ -1011,49 +1026,22 @@ void tBlockDataClear(SBlockData *pBlockData) {
|
|||
|
||||
pBlockData->nRow = 0;
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||
SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData);
|
||||
tColDataClear(pColData);
|
||||
tColDataClear(tBlockDataGetColDataByIdx(pBlockData, iColData));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tBlockDataAddColData(SBlockData *pBlockData, SColData **ppColData) {
|
||||
int32_t code = 0;
|
||||
SColData *pColData = NULL;
|
||||
|
||||
if (pBlockData->nColData >= taosArrayGetSize(pBlockData->aColData)) {
|
||||
if (taosArrayPush(pBlockData->aColData, &((SColData){0})) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
pColData = (SColData *)taosArrayGet(pBlockData->aColData, pBlockData->nColData);
|
||||
|
||||
pBlockData->nColData++;
|
||||
|
||||
*ppColData = pColData;
|
||||
return code;
|
||||
|
||||
_err:
|
||||
*ppColData = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tBlockDataAppendBlockRow(SBlockData *pBlockData, SBlockData *pBlockDataFrom, int32_t iRow) {
|
||||
int32_t code = 0;
|
||||
|
||||
SColVal cv = {0};
|
||||
int32_t iColDataFrom = 0;
|
||||
SColData *pColDataFrom =
|
||||
(iColDataFrom < pBlockDataFrom->nColData) ? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom] : NULL;
|
||||
SColData *pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData) ? &pBlockDataFrom->aColData[iColDataFrom] : NULL;
|
||||
|
||||
for (int32_t iColDataTo = 0; iColDataTo < pBlockData->nColData; iColDataTo++) {
|
||||
SColData *pColDataTo = &((SColData *)pBlockData->aColData->pData)[iColDataTo];
|
||||
SColData *pColDataTo = &pBlockData->aColData[iColDataTo];
|
||||
|
||||
while (pColDataFrom && pColDataFrom->cid < pColDataTo->cid) {
|
||||
iColDataFrom++;
|
||||
pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData)
|
||||
? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom]
|
||||
: NULL;
|
||||
pColDataFrom = (++iColDataFrom < pBlockDataFrom->nColData) ? &pBlockDataFrom->aColData[iColDataFrom] : NULL;
|
||||
}
|
||||
|
||||
if (pColDataFrom == NULL || pColDataFrom->cid > pColDataTo->cid) {
|
||||
|
@ -1065,157 +1053,7 @@ static int32_t tBlockDataAppendBlockRow(SBlockData *pBlockData, SBlockData *pBlo
|
|||
code = tColDataAppendValue(pColDataTo, &cv);
|
||||
if (code) goto _exit;
|
||||
|
||||
iColDataFrom++;
|
||||
pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData)
|
||||
? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom]
|
||||
: NULL;
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tBlockDataAppendTPRow(SBlockData *pBlockData, STSRow *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t iTColumn = 1;
|
||||
STColumn *pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
void *pBitmap = pRow->statis ? tdGetBitmapAddrTp(pRow, pTSchema->flen) : NULL;
|
||||
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||
SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData];
|
||||
|
||||
while (pTColumn && pTColumn->colId < pColData->cid) {
|
||||
iTColumn++;
|
||||
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
}
|
||||
|
||||
if (pTColumn == NULL || pTColumn->colId > pColData->cid) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
ASSERT(pTColumn->type == pColData->type);
|
||||
|
||||
SColVal cv = {.cid = pTColumn->colId, .type = pTColumn->type};
|
||||
|
||||
if (pRow->statis) {
|
||||
TDRowValT vt = TD_VTYPE_MAX;
|
||||
tdGetBitmapValTypeII(pBitmap, iTColumn - 1, &vt);
|
||||
|
||||
if (vt == TD_VTYPE_NORM) {
|
||||
cv.flag = CV_FLAG_VALUE;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
void *pData = (char *)pRow + *(int32_t *)(pRow->data + pTColumn->offset);
|
||||
cv.value.nData = varDataLen(pData);
|
||||
cv.value.pData = varDataVal(pData);
|
||||
} else {
|
||||
memcpy(&cv.value.val, pRow->data + pTColumn->offset, pTColumn->bytes);
|
||||
}
|
||||
|
||||
code = tColDataAppendValue(pColData, &cv);
|
||||
if (code) goto _exit;
|
||||
} else if (vt == TD_VTYPE_NONE) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else if (vt == TD_VTYPE_NULL) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NULL(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
} else {
|
||||
cv.flag = CV_FLAG_VALUE;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
void *pData = (char *)pRow + *(int32_t *)(pRow->data + pTColumn->offset);
|
||||
cv.value.nData = varDataLen(pData);
|
||||
cv.value.pData = varDataVal(pData);
|
||||
} else {
|
||||
memcpy(&cv.value.val, pRow->data + pTColumn->offset, pTColumn->bytes);
|
||||
}
|
||||
|
||||
code = tColDataAppendValue(pColData, &cv);
|
||||
if (code) goto _exit;
|
||||
}
|
||||
|
||||
iTColumn++;
|
||||
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tBlockDataAppendKVRow(SBlockData *pBlockData, STSRow *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
|
||||
col_id_t kvIter = 0;
|
||||
col_id_t nKvCols = tdRowGetNCols(pRow) - 1;
|
||||
void *pColIdx = TD_ROW_COL_IDX(pRow);
|
||||
void *pBitmap = tdGetBitmapAddrKv(pRow, tdRowGetNCols(pRow));
|
||||
int32_t iTColumn = 1;
|
||||
STColumn *pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||
SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData];
|
||||
|
||||
while (pTColumn && pTColumn->colId < pColData->cid) {
|
||||
iTColumn++;
|
||||
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
}
|
||||
|
||||
if (pTColumn == NULL || pTColumn->colId > pColData->cid) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
ASSERT(pTColumn->type == pColData->type);
|
||||
|
||||
SColVal cv = {.cid = pTColumn->colId, .type = pTColumn->type};
|
||||
TDRowValT vt = TD_VTYPE_NONE; // default is NONE
|
||||
SKvRowIdx *pKvIdx = NULL;
|
||||
|
||||
while (kvIter < nKvCols) {
|
||||
pKvIdx = (SKvRowIdx *)POINTER_SHIFT(pColIdx, kvIter * sizeof(SKvRowIdx));
|
||||
if (pKvIdx->colId == pTColumn->colId) {
|
||||
tdGetBitmapValTypeII(pBitmap, kvIter, &vt);
|
||||
++kvIter;
|
||||
break;
|
||||
} else if (pKvIdx->colId > pTColumn->colId) {
|
||||
vt = TD_VTYPE_NONE;
|
||||
break;
|
||||
} else {
|
||||
++kvIter;
|
||||
}
|
||||
}
|
||||
|
||||
if (vt == TD_VTYPE_NORM) {
|
||||
cv.flag = CV_FLAG_VALUE;
|
||||
|
||||
void *pData = POINTER_SHIFT(pRow, pKvIdx->offset);
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
cv.value.nData = varDataLen(pData);
|
||||
cv.value.pData = varDataVal(pData);
|
||||
} else {
|
||||
memcpy(&cv.value.val, pData, pTColumn->bytes);
|
||||
}
|
||||
|
||||
code = tColDataAppendValue(pColData, &cv);
|
||||
if (code) goto _exit;
|
||||
} else if (vt == TD_VTYPE_NONE) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else if (vt == TD_VTYPE_NULL) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NULL(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
iTColumn++;
|
||||
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
pColDataFrom = (++iColDataFrom < pBlockDataFrom->nColData) ? &pBlockDataFrom->aColData[iColDataFrom] : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1245,19 +1083,14 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
|
|||
pBlockData->aTSKEY[pBlockData->nRow] = TSDBROW_TS(pRow);
|
||||
|
||||
SColVal cv = {0};
|
||||
if (pRow->type == 0) {
|
||||
if (TD_IS_TP_ROW(pRow->pTSRow)) {
|
||||
code = tBlockDataAppendTPRow(pBlockData, pRow->pTSRow, pTSchema);
|
||||
if (code) goto _err;
|
||||
} else if (TD_IS_KV_ROW(pRow->pTSRow)) {
|
||||
code = tBlockDataAppendKVRow(pBlockData, pRow->pTSRow, pTSchema);
|
||||
if (code) goto _err;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
} else {
|
||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||
code = tRowAppendToColData(pRow->pTSRow, pTSchema, pBlockData->aColData, pBlockData->nColData);
|
||||
if (code) goto _err;
|
||||
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||
code = tBlockDataAppendBlockRow(pBlockData, pRow->pBlockData, pRow->iRow);
|
||||
if (code) goto _err;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
pBlockData->nRow++;
|
||||
|
||||
|
@ -1267,133 +1100,13 @@ _err:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tBlockDataCorrectSchema(SBlockData *pBlockData, SBlockData *pBlockDataFrom) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t iColData = 0;
|
||||
for (int32_t iColDataFrom = 0; iColDataFrom < pBlockDataFrom->nColData; iColDataFrom++) {
|
||||
SColData *pColDataFrom = tBlockDataGetColDataByIdx(pBlockDataFrom, iColDataFrom);
|
||||
|
||||
while (true) {
|
||||
SColData *pColData;
|
||||
if (iColData < pBlockData->nColData) {
|
||||
pColData = tBlockDataGetColDataByIdx(pBlockData, iColData);
|
||||
} else {
|
||||
pColData = NULL;
|
||||
}
|
||||
|
||||
if (pColData == NULL || pColData->cid > pColDataFrom->cid) {
|
||||
code = tBlockDataAddColData(pBlockData, &pColData);
|
||||
if (code) goto _exit;
|
||||
|
||||
tColDataInit(pColData, pColDataFrom->cid, pColDataFrom->type, pColDataFrom->smaOn);
|
||||
for (int32_t iRow = 0; iRow < pBlockData->nRow; iRow++) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
}
|
||||
|
||||
iColData++;
|
||||
break;
|
||||
} else if (pColData->cid == pColDataFrom->cid) {
|
||||
iColData++;
|
||||
break;
|
||||
} else {
|
||||
iColData++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tBlockDataMerge(SBlockData *pBlockData1, SBlockData *pBlockData2, SBlockData *pBlockData) {
|
||||
int32_t code = 0;
|
||||
|
||||
ASSERT(pBlockData->suid == pBlockData1->suid);
|
||||
ASSERT(pBlockData->uid == pBlockData1->uid);
|
||||
ASSERT(pBlockData1->nRow > 0);
|
||||
ASSERT(pBlockData2->nRow > 0);
|
||||
|
||||
tBlockDataClear(pBlockData);
|
||||
|
||||
TSDBROW row1 = tsdbRowFromBlockData(pBlockData1, 0);
|
||||
TSDBROW row2 = tsdbRowFromBlockData(pBlockData2, 0);
|
||||
TSDBROW *pRow1 = &row1;
|
||||
TSDBROW *pRow2 = &row2;
|
||||
|
||||
while (pRow1 && pRow2) {
|
||||
int32_t c = tsdbRowCmprFn(pRow1, pRow2);
|
||||
|
||||
if (c < 0) {
|
||||
code = tBlockDataAppendRow(pBlockData, pRow1, NULL,
|
||||
pBlockData1->uid ? pBlockData1->uid : pBlockData1->aUid[pRow1->iRow]);
|
||||
if (code) goto _exit;
|
||||
|
||||
pRow1->iRow++;
|
||||
if (pRow1->iRow < pBlockData1->nRow) {
|
||||
*pRow1 = tsdbRowFromBlockData(pBlockData1, pRow1->iRow);
|
||||
} else {
|
||||
pRow1 = NULL;
|
||||
}
|
||||
} else if (c > 0) {
|
||||
code = tBlockDataAppendRow(pBlockData, pRow2, NULL,
|
||||
pBlockData2->uid ? pBlockData2->uid : pBlockData2->aUid[pRow2->iRow]);
|
||||
if (code) goto _exit;
|
||||
|
||||
pRow2->iRow++;
|
||||
if (pRow2->iRow < pBlockData2->nRow) {
|
||||
*pRow2 = tsdbRowFromBlockData(pBlockData2, pRow2->iRow);
|
||||
} else {
|
||||
pRow2 = NULL;
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
while (pRow1) {
|
||||
code = tBlockDataAppendRow(pBlockData, pRow1, NULL,
|
||||
pBlockData1->uid ? pBlockData1->uid : pBlockData1->aUid[pRow1->iRow]);
|
||||
if (code) goto _exit;
|
||||
|
||||
pRow1->iRow++;
|
||||
if (pRow1->iRow < pBlockData1->nRow) {
|
||||
*pRow1 = tsdbRowFromBlockData(pBlockData1, pRow1->iRow);
|
||||
} else {
|
||||
pRow1 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
while (pRow2) {
|
||||
code = tBlockDataAppendRow(pBlockData, pRow2, NULL,
|
||||
pBlockData2->uid ? pBlockData2->uid : pBlockData2->aUid[pRow2->iRow]);
|
||||
if (code) goto _exit;
|
||||
|
||||
pRow2->iRow++;
|
||||
if (pRow2->iRow < pBlockData2->nRow) {
|
||||
*pRow2 = tsdbRowFromBlockData(pBlockData2, pRow2->iRow);
|
||||
} else {
|
||||
pRow2 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
SColData *tBlockDataGetColDataByIdx(SBlockData *pBlockData, int32_t idx) {
|
||||
ASSERT(idx >= 0 && idx < pBlockData->nColData);
|
||||
return (SColData *)taosArrayGet(pBlockData->aColData, idx);
|
||||
}
|
||||
|
||||
void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData) {
|
||||
ASSERT(cid != PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
int32_t lidx = 0;
|
||||
int32_t ridx = pBlockData->nColData - 1;
|
||||
|
||||
while (lidx <= ridx) {
|
||||
int32_t midx = (lidx + ridx) / 2;
|
||||
int32_t midx = (lidx + ridx) >> 1;
|
||||
SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, midx);
|
||||
int32_t c = (pColData->cid == cid) ? 0 : ((pColData->cid > cid) ? 1 : -1);
|
||||
|
||||
|
@ -1540,15 +1253,25 @@ int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uin
|
|||
// loop to decode each column data
|
||||
if (hdr.szBlkCol == 0) goto _exit;
|
||||
|
||||
int32_t nColData = 0;
|
||||
int32_t nt = 0;
|
||||
while (nt < hdr.szBlkCol) {
|
||||
SBlockCol blockCol = {0};
|
||||
nt += tGetBlockCol(pIn + n + nt, &blockCol);
|
||||
ASSERT(nt <= hdr.szBlkCol);
|
||||
++nColData;
|
||||
}
|
||||
ASSERT(nt == hdr.szBlkCol);
|
||||
|
||||
SColData *pColData;
|
||||
code = tBlockDataAddColData(pBlockData, &pColData);
|
||||
if (code) goto _exit;
|
||||
code = tBlockDataAdjustColData(pBlockData, nColData);
|
||||
if (code) goto _exit;
|
||||
|
||||
nt = 0;
|
||||
int32_t iColData = 0;
|
||||
while (nt < hdr.szBlkCol) {
|
||||
SBlockCol blockCol = {0};
|
||||
nt += tGetBlockCol(pIn + n + nt, &blockCol);
|
||||
|
||||
SColData *pColData = &pBlockData->aColData[iColData++];
|
||||
|
||||
tColDataInit(pColData, blockCol.cid, blockCol.type, blockCol.smaOn);
|
||||
if (blockCol.flag == HAS_NULL) {
|
||||
|
|
|
@ -26,14 +26,17 @@ static int64_t tsMaxKeyByPrecision[] = {31556995200000L, 31556995200000000L, 921
|
|||
|
||||
// static int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg);
|
||||
|
||||
int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp *pRsp) {
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
int32_t affectedrows = 0;
|
||||
int32_t numOfRows = 0;
|
||||
int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq2 *pMsg, SSubmitRsp2 *pRsp) {
|
||||
int32_t arrSize = 0;
|
||||
int32_t affectedrows = 0;
|
||||
int32_t numOfRows = 0;
|
||||
|
||||
ASSERT(pTsdb->mem != NULL);
|
||||
|
||||
if (pMsg) {
|
||||
arrSize = taosArrayGetSize(pMsg->aSubmitTbData);
|
||||
}
|
||||
|
||||
// scan and convert
|
||||
if (tsdbScanAndConvertSubmitMsg(pTsdb, pMsg) < 0) {
|
||||
if (terrno != TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||
|
@ -43,18 +46,10 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp *
|
|||
}
|
||||
|
||||
// loop to insert
|
||||
if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) {
|
||||
return -1;
|
||||
}
|
||||
while (true) {
|
||||
SSubmitBlkRsp r = {0};
|
||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
||||
if (pBlock == NULL) break;
|
||||
if ((terrno = tsdbInsertTableData(pTsdb, version, &msgIter, pBlock, &r)) < 0) {
|
||||
for (int32_t i = 0; i < arrSize; ++i) {
|
||||
if ((terrno = tsdbInsertTableData(pTsdb, version, taosArrayGet(pMsg->aSubmitTbData, i), &affectedrows)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
numOfRows += msgIter.numOfRows;
|
||||
}
|
||||
|
||||
if (pRsp != NULL) {
|
||||
|
@ -82,9 +77,8 @@ static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, STable *pTable, STSRow *
|
|||
}
|
||||
#endif
|
||||
|
||||
static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, tb_uid_t uid, STSRow *row, TSKEY minKey, TSKEY maxKey,
|
||||
static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, tb_uid_t uid, TSKEY rowKey, TSKEY minKey, TSKEY maxKey,
|
||||
TSKEY now) {
|
||||
TSKEY rowKey = TD_ROW_KEY(row);
|
||||
if (rowKey < minKey || rowKey > maxKey) {
|
||||
tsdbError("vgId:%d, table uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
|
||||
" maxKey %" PRId64 " row key %" PRId64,
|
||||
|
@ -96,6 +90,7 @@ static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, tb_uid_t uid, STSRow *ro
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
||||
ASSERT(pMsg != NULL);
|
||||
// STsdbMeta * pMeta = pTsdb->tsdbMeta;
|
||||
|
@ -163,6 +158,46 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq2 *pMsg) {
|
||||
ASSERT(pMsg != NULL);
|
||||
STsdbKeepCfg *pCfg = &pTsdb->keepCfg;
|
||||
TSKEY now = taosGetTimestamp(pCfg->precision);
|
||||
TSKEY minKey = now - tsTickPerMin[pCfg->precision] * pCfg->keep2;
|
||||
TSKEY maxKey = tsMaxKeyByPrecision[pCfg->precision];
|
||||
int32_t size = taosArrayGetSize(pMsg->aSubmitTbData);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSubmitTbData *pData = TARRAY_GET_ELEM(pMsg->aSubmitTbData, i);
|
||||
if (pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
uint64_t nColData = TARRAY_SIZE(pData->aCol);
|
||||
SColData *aColData = (SColData *)TARRAY_DATA(pData->aCol);
|
||||
if (nColData > 0) {
|
||||
int32_t nRows = aColData[0].nVal;
|
||||
TSKEY *aKey = (TSKEY *)aColData[0].pData;
|
||||
for (int32_t r = 0; r < nRows; ++r) {
|
||||
if (tsdbCheckRowRange(pTsdb, pData->uid, aKey[r], minKey, maxKey, now) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int32_t nRows = taosArrayGetSize(pData->aRowP);
|
||||
for (int32_t r = 0; r < nRows; ++r) {
|
||||
SRow *pRow = (SRow *)taosArrayGetP(pData->aRowP, r);
|
||||
if (tsdbCheckRowRange(pTsdb, pData->uid, pRow->ts, minKey, maxKey, now) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
||||
return 0;
|
||||
}
|
|
@ -123,6 +123,7 @@ void vnodeBufPoolReset(SVBufPool *pPool) {
|
|||
pPool->ptr = pPool->node.data;
|
||||
}
|
||||
|
||||
|
||||
void *vnodeBufPoolMallocAligned(SVBufPool *pPool, int size) {
|
||||
SVBufPoolNode *pNode;
|
||||
void *p = NULL;
|
||||
|
|
|
@ -184,18 +184,51 @@ _err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int32_t vnodePrepareCommit(SVnode *pVnode) {
|
||||
static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
tsem_wait(&pVnode->canCommit);
|
||||
|
||||
pVnode->state.commitTerm = pVnode->state.applyTerm;
|
||||
|
||||
pInfo->info.config = pVnode->config;
|
||||
pInfo->info.state.committed = pVnode->state.applied;
|
||||
pInfo->info.state.commitTerm = pVnode->state.applyTerm;
|
||||
pInfo->info.state.commitID = pVnode->state.commitID;
|
||||
pInfo->pVnode = pVnode;
|
||||
pInfo->txn = metaGetTxn(pVnode->pMeta);
|
||||
|
||||
// save info
|
||||
if (pVnode->pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||
}
|
||||
if (vnodeSaveInfo(dir, &pInfo->info) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
tsdbPrepareCommit(pVnode->pTsdb);
|
||||
|
||||
metaPrepareAsyncCommit(pVnode->pMeta);
|
||||
|
||||
code = smaPrepareAsyncCommit(pVnode->pSma);
|
||||
if (code) goto _exit;
|
||||
|
||||
_exit:
|
||||
vnodeBufPoolUnRef(pVnode->inUse);
|
||||
pVnode->inUse = NULL;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
vError("vgId:%d, %s failed at line %d since %s, commit id:%" PRId64, TD_VID(pVnode), __func__, lino,
|
||||
tstrerror(code), pVnode->state.commitID);
|
||||
} else {
|
||||
vDebug("vgId:%d, %s done", TD_VID(pVnode), __func__);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -217,33 +250,32 @@ _exit:
|
|||
int vnodeAsyncCommit(SVnode *pVnode) {
|
||||
int32_t code = 0;
|
||||
|
||||
// prepare to commit
|
||||
code = vnodePrepareCommit(pVnode);
|
||||
if (code) goto _exit;
|
||||
|
||||
// schedule the task
|
||||
pVnode->state.commitTerm = pVnode->state.applyTerm;
|
||||
|
||||
SCommitInfo *pInfo = (SCommitInfo *)taosMemoryCalloc(1, sizeof(*pInfo));
|
||||
if (NULL == pInfo) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
pInfo->info.config = pVnode->config;
|
||||
pInfo->info.state.committed = pVnode->state.applied;
|
||||
pInfo->info.state.commitTerm = pVnode->state.applyTerm;
|
||||
pInfo->info.state.commitID = pVnode->state.commitID;
|
||||
pInfo->pVnode = pVnode;
|
||||
pInfo->txn = metaGetTxn(pVnode->pMeta);
|
||||
|
||||
// prepare to commit
|
||||
code = vnodePrepareCommit(pVnode, pInfo);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
// schedule the task
|
||||
code = vnodeScheduleTask(vnodeCommitTask, pInfo);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
if (NULL != pInfo) {
|
||||
taosMemoryFree(pInfo);
|
||||
}
|
||||
tsem_post(&pVnode->canCommit);
|
||||
vError("vgId:%d, %s failed since %s, commit id:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code),
|
||||
pVnode->state.commitID);
|
||||
} else {
|
||||
vDebug("vgId:%d, %s done", TD_VID(pVnode), __func__);
|
||||
vInfo("vgId:%d, vnode async commit done, commitId:%" PRId64 " term:%" PRId64 " applied:%" PRId64, TD_VID(pVnode),
|
||||
pVnode->state.commitID, pVnode->state.applyTerm, pVnode->state.applied);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -262,7 +294,7 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) {
|
|||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
SVnode *pVnode = pInfo->pVnode;
|
||||
|
||||
vInfo("vgId:%d, start to commit, commit ID:%" PRId64 " version:%" PRId64 " term: %" PRId64, TD_VID(pVnode),
|
||||
vInfo("vgId:%d, start to commit, commitId:%" PRId64 " version:%" PRId64 " term: %" PRId64, TD_VID(pVnode),
|
||||
pVnode->state.commitID, pVnode->state.applied, pVnode->state.applyTerm);
|
||||
|
||||
// persist wal before starting
|
||||
|
@ -271,16 +303,11 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// save info
|
||||
if (pVnode->pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||
}
|
||||
if (vnodeSaveInfo(dir, &pInfo->info) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
// walBeginSnapshot(pVnode->pWal, pVnode->state.applied);
|
||||
syncBeginSnapshot(pVnode->sync, pVnode->state.applied);
|
||||
|
|
|
@ -257,8 +257,8 @@ _exit:
|
|||
pReader->index++;
|
||||
*nData = sizeof(SSnapDataHdr) + pHdr->size;
|
||||
pHdr->index = pReader->index;
|
||||
vInfo("vgId:%d, vnode snapshot read data,index:%" PRId64 " type:%d nData:%d ", TD_VID(pReader->pVnode),
|
||||
pReader->index, pHdr->type, *nData);
|
||||
vDebug("vgId:%d, vnode snapshot read data, index:%" PRId64 " type:%d blockLen:%d ", TD_VID(pReader->pVnode),
|
||||
pReader->index, pHdr->type, *nData);
|
||||
} else {
|
||||
vInfo("vgId:%d, vnode snapshot read data end, index:%" PRId64, TD_VID(pReader->pVnode), pReader->index);
|
||||
}
|
||||
|
@ -423,8 +423,8 @@ int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) {
|
|||
ASSERT(pHdr->index == pWriter->index + 1);
|
||||
pWriter->index = pHdr->index;
|
||||
|
||||
vInfo("vgId:%d, vnode snapshot write data, index:%" PRId64 " type:%d nData:%d", TD_VID(pVnode), pHdr->index,
|
||||
pHdr->type, nData);
|
||||
vDebug("vgId:%d, vnode snapshot write data, index:%" PRId64 " type:%d blockLen:%d", TD_VID(pVnode), pHdr->index,
|
||||
pHdr->type, nData);
|
||||
|
||||
switch (pHdr->type) {
|
||||
case SNAP_DATA_CFG: {
|
||||
|
|
|
@ -77,52 +77,72 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
tDecoderClear(&dc);
|
||||
} break;
|
||||
case TDMT_VND_SUBMIT: {
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pMsg->pCont;
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
int64_t ctime = taosGetTimestampMs();
|
||||
tb_uid_t uid;
|
||||
int64_t ctime = taosGetTimestampMs();
|
||||
|
||||
if (tInitSubmitMsgIter(pSubmitReq, &msgIter) < 0) {
|
||||
code = terrno;
|
||||
tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
|
||||
tStartDecode(&dc);
|
||||
|
||||
uint64_t nSubmitTbData;
|
||||
if (tDecodeU64v(&dc, &nSubmitTbData) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
||||
if (pBlock == NULL) break;
|
||||
for (int32_t i = 0; i < nSubmitTbData; i++) {
|
||||
if (tStartDecode(&dc) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (msgIter.schemaLen > 0) {
|
||||
char *name = NULL;
|
||||
int32_t flags;
|
||||
if (tDecodeI32v(&dc, &flags) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
tDecoderInit(&dc, pBlock->data, msgIter.schemaLen);
|
||||
if (flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
|
||||
// SVCreateTbReq
|
||||
if (tStartDecode(&dc) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (tDecodeI32v(&dc, NULL) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
if (tDecodeCStr(&dc, &name) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
uid = metaGetTableEntryUidByName(pVnode->pMeta, name);
|
||||
char *name = NULL;
|
||||
if (tDecodeCStr(&dc, &name) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
int64_t uid = metaGetTableEntryUidByName(pVnode->pMeta, name);
|
||||
if (uid == 0) {
|
||||
uid = tGenIdPI64();
|
||||
}
|
||||
|
||||
*(int64_t *)(dc.data + dc.pos) = uid;
|
||||
*(int64_t *)(dc.data + dc.pos + 8) = ctime;
|
||||
pBlock->uid = htobe64(uid);
|
||||
|
||||
tEndDecode(&dc);
|
||||
tDecoderClear(&dc);
|
||||
|
||||
// SSubmitTbData
|
||||
int64_t suid;
|
||||
if (tDecodeI64(&dc, &suid) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
*(int64_t *)(dc.data + dc.pos) = uid;
|
||||
}
|
||||
|
||||
tEndDecode(&dc);
|
||||
}
|
||||
|
||||
tEndDecode(&dc);
|
||||
tDecoderClear(&dc);
|
||||
} break;
|
||||
case TDMT_VND_DELETE: {
|
||||
int32_t size;
|
||||
|
@ -197,7 +217,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
|||
|
||||
if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
|
||||
|
||||
if (pMsg->msgType == TDMT_VND_STREAM_RECOVER_BLOCKING_STAGE) {
|
||||
if (pMsg->msgType == TDMT_VND_STREAM_RECOVER_BLOCKING_STAGE || pMsg->msgType == TDMT_STREAM_TASK_CHECK_RSP) {
|
||||
if (tqCheckLogInWal(pVnode->pTq, version)) return 0;
|
||||
}
|
||||
|
||||
|
@ -236,7 +256,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
|||
break;
|
||||
/* TSDB */
|
||||
case TDMT_VND_SUBMIT:
|
||||
if (vnodeProcessSubmitReq(pVnode, version, pMsg->pCont, pMsg->contLen, pRsp) < 0) goto _err;
|
||||
if (vnodeProcessSubmitReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
break;
|
||||
case TDMT_VND_DELETE:
|
||||
if (vnodeProcessDeleteReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
|
@ -855,57 +875,198 @@ static int32_t vnodeDebugPrintSingleSubmitMsg(SMeta *pMeta, SSubmitBlk *pBlock,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t vnodeDebugPrintSubmitMsg(SVnode *pVnode, SSubmitReq *pMsg, const char *tags) {
|
||||
ASSERT(pMsg != NULL);
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
SMeta *pMeta = pVnode->pMeta;
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
#if 1
|
||||
int32_t code = 0;
|
||||
terrno = 0;
|
||||
|
||||
if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) return -1;
|
||||
while (true) {
|
||||
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
|
||||
if (pBlock == NULL) break;
|
||||
SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
|
||||
SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
|
||||
SArray *newTbUids = NULL;
|
||||
int32_t ret;
|
||||
SEncoder ec = {0};
|
||||
|
||||
vnodeDebugPrintSingleSubmitMsg(pMeta, pBlock, &msgIter, tags);
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
|
||||
// decode
|
||||
SDecoder dc = {0};
|
||||
tDecoderInit(&dc, pReq, len);
|
||||
if (tDecodeSSubmitReq2(&dc, pSubmitReq) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
tDecoderClear(&dc);
|
||||
|
||||
// check
|
||||
code = tsdbScanAndConvertSubmitMsg(pVnode->pTsdb, pSubmitReq);
|
||||
if (code) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
|
||||
SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
|
||||
|
||||
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
||||
SSubmitRsp submitRsp = {0};
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
SVCreateTbReq createTbReq = {0};
|
||||
SDecoder decoder = {0};
|
||||
int32_t nRows = 0;
|
||||
int32_t tsize, ret;
|
||||
SEncoder encoder = {0};
|
||||
SArray *newTbUids = NULL;
|
||||
SVStatis statis = {0};
|
||||
bool tbCreated = false;
|
||||
if (pSubmitTbData->pCreateTbReq) {
|
||||
pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;
|
||||
} else {
|
||||
SMetaInfo info = {0};
|
||||
|
||||
code = metaGetInfo(pVnode->pMeta, pSubmitTbData->uid, &info, NULL);
|
||||
if (code) {
|
||||
code = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), pSubmitTbData->uid);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (info.suid != pSubmitTbData->suid) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (info.suid) {
|
||||
metaGetInfo(pVnode->pMeta, info.suid, &info, NULL);
|
||||
}
|
||||
|
||||
if (pSubmitTbData->sver != info.skmVer) {
|
||||
code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
int32_t nColData = TARRAY_SIZE(pSubmitTbData->aCol);
|
||||
SColData *aColData = (SColData *)TARRAY_DATA(pSubmitTbData->aCol);
|
||||
|
||||
if (nColData <= 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (aColData[0].cid != PRIMARYKEY_TIMESTAMP_COL_ID || aColData[0].type != TSDB_DATA_TYPE_TIMESTAMP ||
|
||||
aColData[0].nVal <= 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (int32_t i = 1; i < nColData; i++) {
|
||||
if (aColData[i].nVal != aColData[0].nVal) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, submit block size %d", TD_VID(pVnode), (int32_t)taosArrayGetSize(pSubmitReq->aSubmitTbData));
|
||||
|
||||
// loop to handle
|
||||
for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
|
||||
SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
|
||||
|
||||
// create table
|
||||
if (pSubmitTbData->pCreateTbReq) {
|
||||
// check (TODO: move check to create table)
|
||||
code = grantCheck(TSDB_GRANT_TIMESERIES);
|
||||
if (code) goto _exit;
|
||||
|
||||
code = grantCheck(TSDB_GRANT_TABLE);
|
||||
if (code) goto _exit;
|
||||
|
||||
// alloc if need
|
||||
if (pSubmitRsp->aCreateTbRsp == NULL &&
|
||||
(pSubmitRsp->aCreateTbRsp = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(SVCreateTbRsp))) ==
|
||||
NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
SVCreateTbRsp *pCreateTbRsp = taosArrayReserve(pSubmitRsp->aCreateTbRsp, 1);
|
||||
|
||||
// create table
|
||||
if (metaCreateTable(pVnode->pMeta, version, pSubmitTbData->pCreateTbReq, &pCreateTbRsp->pMeta) ==
|
||||
0) { // create table success
|
||||
|
||||
if (newTbUids == NULL &&
|
||||
(newTbUids = taosArrayInit(TARRAY_SIZE(pSubmitReq->aSubmitTbData), sizeof(int64_t))) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
taosArrayPush(newTbUids, &pSubmitTbData->uid);
|
||||
|
||||
if (pCreateTbRsp->pMeta) {
|
||||
vnodeUpdateMetaRsp(pVnode, pCreateTbRsp->pMeta);
|
||||
}
|
||||
} else { // create table failed
|
||||
if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// insert data
|
||||
int32_t affectedRows;
|
||||
code = tsdbInsertTableData(pVnode->pTsdb, version, pSubmitTbData, &affectedRows);
|
||||
if (code) goto _exit;
|
||||
|
||||
pSubmitRsp->affectedRows += affectedRows;
|
||||
}
|
||||
|
||||
// update table uid list
|
||||
if (taosArrayGetSize(newTbUids) > 0) {
|
||||
vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
|
||||
(int32_t)taosArrayGetSize(newTbUids));
|
||||
tqUpdateTbUidList(pVnode->pTq, newTbUids, true);
|
||||
}
|
||||
|
||||
_exit:
|
||||
// message
|
||||
pRsp->code = code;
|
||||
tEncodeSize(tEncodeSSubmitRsp2, pSubmitRsp, pRsp->contLen, ret);
|
||||
pRsp->pCont = rpcMallocCont(pRsp->contLen);
|
||||
tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
|
||||
tEncodeSSubmitRsp2(&ec, pSubmitRsp);
|
||||
tEncoderClear(&ec);
|
||||
|
||||
// update statistics
|
||||
atomic_add_fetch_64(&pVnode->statis.nInsert, pSubmitRsp->affectedRows);
|
||||
atomic_add_fetch_64(&pVnode->statis.nInsertSuccess, pSubmitRsp->affectedRows);
|
||||
atomic_add_fetch_64(&pVnode->statis.nBatchInsert, 1);
|
||||
if (code == 0) {
|
||||
atomic_add_fetch_64(&pVnode->statis.nBatchInsertSuccess, 1);
|
||||
tdProcessRSmaSubmit(pVnode->pSma, version, pSubmitReq, pReq, len, STREAM_INPUT__DATA_SUBMIT);
|
||||
}
|
||||
|
||||
// clear
|
||||
taosArrayDestroy(newTbUids);
|
||||
tDestroySSubmitReq2(pSubmitReq, TSDB_MSG_FLG_DECODE);
|
||||
tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
|
||||
|
||||
if (code) terrno = code;
|
||||
|
||||
return code;
|
||||
|
||||
#else
|
||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
||||
SSubmitRsp submitRsp = {0};
|
||||
int32_t nRows = 0;
|
||||
int32_t tsize, ret;
|
||||
SEncoder encoder = {0};
|
||||
SArray *newTbUids = NULL;
|
||||
SVStatis statis = {0};
|
||||
bool tbCreated = false;
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
pRsp->code = 0;
|
||||
pSubmitReq->version = version;
|
||||
statis.nBatchInsert = 1;
|
||||
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
vnodeDebugPrintSubmitMsg(pVnode, pReq, __func__);
|
||||
#endif
|
||||
|
||||
if (tsdbScanAndConvertSubmitMsg(pVnode->pTsdb, pSubmitReq) < 0) {
|
||||
pRsp->code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
// handle the request
|
||||
if (tInitSubmitMsgIter(pSubmitReq, &msgIter) < 0) {
|
||||
pRsp->code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
submitRsp.pArray = taosArrayInit(msgIter.numOfBlocks, sizeof(SSubmitBlkRsp));
|
||||
newTbUids = taosArrayInit(msgIter.numOfBlocks, sizeof(int64_t));
|
||||
if (!submitRsp.pArray || !newTbUids) {
|
||||
|
@ -922,42 +1083,42 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq
|
|||
|
||||
// create table for auto create table mode
|
||||
if (msgIter.schemaLen > 0) {
|
||||
tDecoderInit(&decoder, pBlock->data, msgIter.schemaLen);
|
||||
if (tDecodeSVCreateTbReq(&decoder, &createTbReq) < 0) {
|
||||
pRsp->code = TSDB_CODE_INVALID_MSG;
|
||||
tDecoderClear(&decoder);
|
||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
goto _exit;
|
||||
}
|
||||
// tDecoderInit(&decoder, pBlock->data, msgIter.schemaLen);
|
||||
// if (tDecodeSVCreateTbReq(&decoder, &createTbReq) < 0) {
|
||||
// pRsp->code = TSDB_CODE_INVALID_MSG;
|
||||
// tDecoderClear(&decoder);
|
||||
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
// goto _exit;
|
||||
// }
|
||||
|
||||
if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0) {
|
||||
pRsp->code = terrno;
|
||||
tDecoderClear(&decoder);
|
||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
goto _exit;
|
||||
}
|
||||
// if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0) {
|
||||
// pRsp->code = terrno;
|
||||
// tDecoderClear(&decoder);
|
||||
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
// goto _exit;
|
||||
// }
|
||||
|
||||
if ((terrno = grantCheck(TSDB_GRANT_TABLE)) < 0) {
|
||||
pRsp->code = terrno;
|
||||
tDecoderClear(&decoder);
|
||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
goto _exit;
|
||||
}
|
||||
// if ((terrno = grantCheck(TSDB_GRANT_TABLE)) < 0) {
|
||||
// pRsp->code = terrno;
|
||||
// tDecoderClear(&decoder);
|
||||
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
// goto _exit;
|
||||
// }
|
||||
|
||||
if (metaCreateTable(pVnode->pMeta, version, &createTbReq, &submitBlkRsp.pMeta) < 0) {
|
||||
if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
|
||||
submitBlkRsp.code = terrno;
|
||||
pRsp->code = terrno;
|
||||
tDecoderClear(&decoder);
|
||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
goto _exit;
|
||||
}
|
||||
// if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
|
||||
// submitBlkRsp.code = terrno;
|
||||
// pRsp->code = terrno;
|
||||
// tDecoderClear(&decoder);
|
||||
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
// goto _exit;
|
||||
// }
|
||||
} else {
|
||||
if (NULL != submitBlkRsp.pMeta) {
|
||||
vnodeUpdateMetaRsp(pVnode, submitBlkRsp.pMeta);
|
||||
}
|
||||
|
||||
taosArrayPush(newTbUids, &createTbReq.uid);
|
||||
// taosArrayPush(newTbUids, &createTbReq.uid);
|
||||
|
||||
submitBlkRsp.uid = createTbReq.uid;
|
||||
submitBlkRsp.tblFName = taosMemoryMalloc(strlen(pVnode->config.dbname) + strlen(createTbReq.name) + 2);
|
||||
|
@ -965,18 +1126,15 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq
|
|||
tbCreated = true;
|
||||
}
|
||||
|
||||
msgIter.uid = createTbReq.uid;
|
||||
if (createTbReq.type == TSDB_CHILD_TABLE) {
|
||||
msgIter.suid = createTbReq.ctb.suid;
|
||||
} else {
|
||||
msgIter.suid = 0;
|
||||
}
|
||||
// msgIter.uid = createTbReq.uid;
|
||||
// if (createTbReq.type == TSDB_CHILD_TABLE) {
|
||||
// msgIter.suid = createTbReq.ctb.suid;
|
||||
// } else {
|
||||
// msgIter.suid = 0;
|
||||
// }
|
||||
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
vnodeDebugPrintSingleSubmitMsg(pVnode->pMeta, pBlock, &msgIter, "real uid");
|
||||
#endif
|
||||
tDecoderClear(&decoder);
|
||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
// tDecoderClear(&decoder);
|
||||
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||
}
|
||||
|
||||
if (tsdbInsertTableData(pVnode->pTsdb, version, &msgIter, pBlock, &submitBlkRsp) < 0) {
|
||||
|
@ -990,21 +1148,21 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq
|
|||
}
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(newTbUids) > 0) {
|
||||
vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
|
||||
(int32_t)taosArrayGetSize(newTbUids));
|
||||
}
|
||||
// if (taosArrayGetSize(newTbUids) > 0) {
|
||||
// vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
|
||||
// (int32_t)taosArrayGetSize(newTbUids));
|
||||
// }
|
||||
|
||||
tqUpdateTbUidList(pVnode->pTq, newTbUids, true);
|
||||
// tqUpdateTbUidList(pVnode->pTq, newTbUids, true);
|
||||
|
||||
_exit:
|
||||
taosArrayDestroy(newTbUids);
|
||||
tEncodeSize(tEncodeSSubmitRsp, &submitRsp, tsize, ret);
|
||||
pRsp->pCont = rpcMallocCont(tsize);
|
||||
pRsp->contLen = tsize;
|
||||
tEncoderInit(&encoder, pRsp->pCont, tsize);
|
||||
tEncodeSSubmitRsp(&encoder, &submitRsp);
|
||||
tEncoderClear(&encoder);
|
||||
// tEncodeSize(tEncodeSSubmitRsp, &submitRsp, tsize, ret);
|
||||
// pRsp->pCont = rpcMallocCont(tsize);
|
||||
// pRsp->contLen = tsize;
|
||||
// tEncoderInit(&encoder, pRsp->pCont, tsize);
|
||||
// tEncodeSSubmitRsp(&encoder, &submitRsp);
|
||||
// tEncoderClear(&encoder);
|
||||
|
||||
taosArrayDestroyEx(submitRsp.pArray, tFreeSSubmitBlkRsp);
|
||||
|
||||
|
@ -1025,6 +1183,8 @@ _exit:
|
|||
|
||||
vDebug("vgId:%d, submit success, index:%" PRId64, pVnode->config.vgId, version);
|
||||
return 0;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue