Merge remote-tracking branch 'origin/3.0' into enh/3.0_planner_optimize
This commit is contained in:
commit
01b90f45eb
|
|
@ -141,12 +141,12 @@ ELSE ()
|
||||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
IF ("${SIMD_SUPPORT}" MATCHES "true")
|
||||||
IF (COMPILER_SUPPORT_FMA)
|
IF (COMPILER_SUPPORT_FMA)
|
||||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma")
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma")
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
IF ("${SIMD_SUPPORT}" MATCHES "true")
|
|
||||||
IF (COMPILER_SUPPORT_AVX)
|
IF (COMPILER_SUPPORT_AVX)
|
||||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ IF (TD_LINUX)
|
||||||
ELSEIF (TD_WINDOWS)
|
ELSEIF (TD_WINDOWS)
|
||||||
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.bat")
|
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 "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)
|
ELSEIF (TD_DARWIN)
|
||||||
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.sh")
|
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.sh")
|
||||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# taosadapter
|
# taosadapter
|
||||||
ExternalProject_Add(taosadapter
|
ExternalProject_Add(taosadapter
|
||||||
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
||||||
GIT_TAG f0c1753
|
GIT_TAG 5662a6d
|
||||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
||||||
BINARY_DIR ""
|
BINARY_DIR ""
|
||||||
#BUILD_IN_SOURCE TRUE
|
#BUILD_IN_SOURCE TRUE
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ database_option: {
|
||||||
| WAL_LEVEL {1 | 2}
|
| WAL_LEVEL {1 | 2}
|
||||||
| VGROUPS value
|
| VGROUPS value
|
||||||
| SINGLE_STABLE {0 | 1}
|
| SINGLE_STABLE {0 | 1}
|
||||||
|
| TABLE_PREFIX value
|
||||||
|
| TABLE_SUFFIX value
|
||||||
| WAL_RETENTION_PERIOD value
|
| WAL_RETENTION_PERIOD value
|
||||||
| WAL_ROLL_PERIOD value
|
| WAL_ROLL_PERIOD value
|
||||||
| WAL_RETENTION_SIZE value
|
| WAL_RETENTION_SIZE value
|
||||||
|
|
@ -67,6 +69,8 @@ database_option: {
|
||||||
- SINGLE_STABLE: specifies whether the database can contain more than one supertable.
|
- SINGLE_STABLE: specifies whether the database can contain more than one supertable.
|
||||||
- 0: The database can contain multiple supertables.
|
- 0: The database can contain multiple supertables.
|
||||||
- 1: The database can contain only one supertable.
|
- 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_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_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.
|
- 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.
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ taosAdapter provides the following features.
|
||||||
- Seamless connection to collectd
|
- Seamless connection to collectd
|
||||||
- Seamless connection to StatsD
|
- Seamless connection to StatsD
|
||||||
- Supports Prometheus remote_read and remote_write
|
- Supports Prometheus remote_read and remote_write
|
||||||
|
- Get table's VGroup ID
|
||||||
|
|
||||||
## taosAdapter architecture diagram
|
## 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.
|
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
|
- 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.
|
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
|
## Interfaces
|
||||||
|
|
||||||
|
|
@ -199,7 +201,7 @@ Support InfluxDB query parameters as follows.
|
||||||
- `precision` The time precision used by TDengine
|
- `precision` The time precision used by TDengine
|
||||||
- `u` TDengine user name
|
- `u` TDengine user name
|
||||||
- `p` TDengine password
|
- `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.
|
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"
|
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 />
|
<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
|
## 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.
|
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.
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ database_option: {
|
||||||
| WAL_LEVEL {1 | 2}
|
| WAL_LEVEL {1 | 2}
|
||||||
| VGROUPS value
|
| VGROUPS value
|
||||||
| SINGLE_STABLE {0 | 1}
|
| SINGLE_STABLE {0 | 1}
|
||||||
|
| TABLE_PREFIX value
|
||||||
|
| TABLE_SUFFIX value
|
||||||
| WAL_RETENTION_PERIOD value
|
| WAL_RETENTION_PERIOD value
|
||||||
| WAL_ROLL_PERIOD value
|
| WAL_ROLL_PERIOD value
|
||||||
| WAL_RETENTION_SIZE value
|
| WAL_RETENTION_SIZE value
|
||||||
|
|
@ -67,6 +69,8 @@ database_option: {
|
||||||
- SINGLE_STABLE:表示此数据库中是否只可以创建一个超级表,用于超级表列非常多的情况。
|
- SINGLE_STABLE:表示此数据库中是否只可以创建一个超级表,用于超级表列非常多的情况。
|
||||||
- 0:表示可以创建多张超级表。
|
- 0:表示可以创建多张超级表。
|
||||||
- 1:表示只可以创建一张超级表。
|
- 1:表示只可以创建一张超级表。
|
||||||
|
- TABLE_PREFIX:内部存储引擎根据表名分配存储该表数据的 VNODE 时要忽略的前缀的长度。
|
||||||
|
- TABLE_SUFFIX:内部存储引擎根据表名分配存储该表数据的 VNODE 时要忽略的后缀的长度。
|
||||||
- WAL_RETENTION_PERIOD:wal 文件的额外保留策略,用于数据订阅。wal 的保存时长,单位为 s。单副本默认为 0,即落盘后立即删除。-1 表示不删除。多副本默认为 4 天。
|
- WAL_RETENTION_PERIOD:wal 文件的额外保留策略,用于数据订阅。wal 的保存时长,单位为 s。单副本默认为 0,即落盘后立即删除。-1 表示不删除。多副本默认为 4 天。
|
||||||
- WAL_RETENTION_SIZE:wal 文件的额外保留策略,用于数据订阅。wal 的保存的最大上限,单位为 KB。单副本默认为 0,即落盘后立即删除。多副本默认为-1,表示不删除。
|
- WAL_RETENTION_SIZE:wal 文件的额外保留策略,用于数据订阅。wal 的保存的最大上限,单位为 KB。单副本默认为 0,即落盘后立即删除。多副本默认为-1,表示不删除。
|
||||||
- WAL_ROLL_PERIOD:wal 文件切换时长,单位为 s。当 wal 文件创建并写入后,经过该时间,会自动创建一个新的 wal 文件。单副本默认为 0,即仅在落盘时创建新文件。多副本默认为 1 天。
|
- WAL_ROLL_PERIOD:wal 文件切换时长,单位为 s。当 wal 文件创建并写入后,经过该时间,会自动创建一个新的 wal 文件。单副本默认为 0,即仅在落盘时创建新文件。多副本默认为 1 天。
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ taosAdapter 提供以下功能:
|
||||||
- 无缝连接到 collectd
|
- 无缝连接到 collectd
|
||||||
- 无缝连接到 StatsD
|
- 无缝连接到 StatsD
|
||||||
- 支持 Prometheus remote_read 和 remote_write
|
- 支持 Prometheus remote_read 和 remote_write
|
||||||
|
- 获取 table 所在的虚拟节点组(VGroup)的 VGroup ID
|
||||||
|
|
||||||
## taosAdapter 架构图
|
## taosAdapter 架构图
|
||||||
|
|
||||||
|
|
@ -178,6 +179,7 @@ AllowWebSockets
|
||||||
node_export 是一个机器指标的导出器。请访问 [https://github.com/prometheus/node_exporter](https://github.com/prometheus/node_exporter) 了解更多信息。
|
node_export 是一个机器指标的导出器。请访问 [https://github.com/prometheus/node_exporter](https://github.com/prometheus/node_exporter) 了解更多信息。
|
||||||
- 支持 Prometheus remote_read 和 remote_write
|
- 支持 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) 了解更多信息。
|
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 />
|
<Prometheus />
|
||||||
|
|
||||||
|
### 获取 table 的 VGroup ID
|
||||||
|
|
||||||
|
可以访问 http 接口 `http://<fqdn>:6041/rest/vgid?db=<db>&table=<table>` 获取 table 的 VGroup ID。关于虚拟节点组(VGroup)的更多信息,请访问[整体架构文档](/tdinternal/arch/#主要逻辑单元) 。
|
||||||
|
|
||||||
## 内存使用优化方法
|
## 内存使用优化方法
|
||||||
|
|
||||||
taosAdapter 将监测自身运行过程中内存使用率并通过两个阈值进行调节。有效值范围为 -1 到 100 的整数,单位为系统物理内存的百分比。
|
taosAdapter 将监测自身运行过程中内存使用率并通过两个阈值进行调节。有效值范围为 -1 到 100 的整数,单位为系统物理内存的百分比。
|
||||||
|
|
@ -282,7 +288,7 @@ http 返回内容:
|
||||||
|
|
||||||
## taosAdapter 监控指标
|
## taosAdapter 监控指标
|
||||||
|
|
||||||
taosAdapter 采集 http 相关指标、cpu 百分比和内存百分比。
|
taosAdapter 采集 http 相关指标、CPU 百分比和内存百分比。
|
||||||
|
|
||||||
### http 接口
|
### http 接口
|
||||||
|
|
||||||
|
|
@ -294,13 +300,13 @@ http://<fqdn>:6041/metrics
|
||||||
|
|
||||||
### 写入 TDengine
|
### 写入 TDengine
|
||||||
|
|
||||||
taosAdapter 支持将 http 监控、cpu 百分比和内存百分比写入 TDengine。
|
taosAdapter 支持将 http 监控、CPU 百分比和内存百分比写入 TDengine。
|
||||||
|
|
||||||
有关配置参数
|
有关配置参数
|
||||||
|
|
||||||
| **配置项** | **描述** | **默认值** |
|
| **配置项** | **描述** | **默认值** |
|
||||||
|-------------------------|--------------------------------------------|----------|
|
|-------------------------|--------------------------------------------|----------|
|
||||||
| monitor.collectDuration | cpu 和内存采集间隔 | 3s |
|
| monitor.collectDuration | CPU 和内存采集间隔 | 3s |
|
||||||
| monitor.identity | 当前taosadapter 的标识符如果不设置将使用 'hostname:port' | |
|
| monitor.identity | 当前taosadapter 的标识符如果不设置将使用 'hostname:port' | |
|
||||||
| monitor.incgroup | 是否是 cgroup 中运行(容器中运行设置为 true) | false |
|
| monitor.incgroup | 是否是 cgroup 中运行(容器中运行设置为 true) | false |
|
||||||
| monitor.writeToTD | 是否写入到 TDengine | false |
|
| monitor.writeToTD | 是否写入到 TDengine | false |
|
||||||
|
|
|
||||||
|
|
@ -341,7 +341,7 @@ typedef struct SExprInfo {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* key;
|
const char* key;
|
||||||
int32_t keyLen;
|
size_t keyLen;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
union {
|
union {
|
||||||
const char* value;
|
const char* value;
|
||||||
|
|
@ -350,7 +350,7 @@ typedef struct {
|
||||||
double d;
|
double d;
|
||||||
float f;
|
float f;
|
||||||
};
|
};
|
||||||
int32_t length;
|
size_t length;
|
||||||
} SSmlKv;
|
} SSmlKv;
|
||||||
|
|
||||||
#define QUERY_ASC_FORWARD_STEP 1
|
#define QUERY_ASC_FORWARD_STEP 1
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@ void blockDebugShowDataBlocks(const SArray* dataBlocks, const char* flag);
|
||||||
// for debug
|
// for debug
|
||||||
char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** dumpBuf);
|
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);
|
tb_uid_t suid);
|
||||||
|
|
||||||
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId);
|
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId);
|
||||||
|
|
|
||||||
|
|
@ -44,18 +44,38 @@ typedef struct SColData SColData;
|
||||||
#define HAS_VALUE ((uint8_t)0x4)
|
#define HAS_VALUE ((uint8_t)0x4)
|
||||||
|
|
||||||
// bitmap ================================
|
// bitmap ================================
|
||||||
const static uint8_t BIT2_MAP[4][4] = {{0b00000000, 0b00000001, 0b00000010, 0},
|
const static uint8_t BIT1_MAP[8] = {0b11111110, 0b11111101, 0b11111011, 0b11110111,
|
||||||
{0b00000000, 0b00000100, 0b00001000, 2},
|
0b11101111, 0b11011111, 0b10111111, 0b01111111};
|
||||||
{0b00000000, 0b00010000, 0b00100000, 4},
|
|
||||||
{0b00000000, 0b01000000, 0b10000000, 6}};
|
|
||||||
|
|
||||||
#define N1(n) ((((uint8_t)1) << (n)) - 1)
|
const static uint8_t BIT2_MAP[4] = {0b11111100, 0b11110011, 0b11001111, 0b00111111};
|
||||||
#define BIT1_SIZE(n) ((((n)-1) >> 3) + 1)
|
|
||||||
#define BIT2_SIZE(n) ((((n)-1) >> 2) + 1)
|
#define ONE ((uint8_t)1)
|
||||||
#define SET_BIT1(p, i, v) ((p)[(i) >> 3] = (p)[(i) >> 3] & N1((i)&7) | (((uint8_t)(v)) << ((i)&7)))
|
#define THREE ((uint8_t)3)
|
||||||
#define GET_BIT1(p, i) (((p)[(i) >> 3] >> ((i)&7)) & ((uint8_t)1))
|
#define DIV_8(i) ((i) >> 3)
|
||||||
#define SET_BIT2(p, i, v) ((p)[(i) >> 2] = (p)[(i) >> 2] & N1(BIT2_MAP[(i)&3][3]) | BIT2_MAP[(i)&3][(v)])
|
#define MOD_8(i) ((i)&7)
|
||||||
#define GET_BIT2(p, i) (((p)[(i) >> 2] >> BIT2_MAP[(i)&3][3]) & ((uint8_t)3))
|
#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 ================================
|
// SBuffer ================================
|
||||||
struct 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 tBufferPut(SBuffer *pBuffer, const void *pData, int64_t nData);
|
||||||
int32_t tBufferReserve(SBuffer *pBuffer, int64_t nData, void **ppData);
|
int32_t tBufferReserve(SBuffer *pBuffer, int64_t nData, void **ppData);
|
||||||
|
|
||||||
// STSchema ================================
|
|
||||||
void tDestroyTSchema(STSchema *pTSchema);
|
|
||||||
|
|
||||||
// SColVal ================================
|
// SColVal ================================
|
||||||
#define CV_FLAG_VALUE ((int8_t)0x0)
|
#define CV_FLAG_VALUE ((int8_t)0x0)
|
||||||
#define CV_FLAG_NONE ((int8_t)0x1)
|
#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)
|
#define COL_VAL_IS_VALUE(CV) ((CV)->flag == CV_FLAG_VALUE)
|
||||||
|
|
||||||
// SRow ================================
|
// 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 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 ================================
|
// SRowIter ================================
|
||||||
int32_t tRowIterOpen(SRow *pRow, STSchema *pTSchema, SRowIter **ppIter);
|
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);
|
int32_t parseJsontoTagData(const char *json, SArray *pTagVals, STag **ppTag, void *pMsgBuf);
|
||||||
|
|
||||||
// SColData ================================
|
// SColData ================================
|
||||||
|
typedef void *(*xMallocFn)(void *, int32_t);
|
||||||
void tColDataDestroy(void *ph);
|
void tColDataDestroy(void *ph);
|
||||||
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn);
|
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn);
|
||||||
void tColDataClear(SColData *pColData);
|
void tColDataClear(SColData *pColData);
|
||||||
|
void tColDataDeepClear(SColData *pColData);
|
||||||
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
|
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
|
||||||
void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal);
|
void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal);
|
||||||
uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal);
|
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);
|
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 ================================
|
||||||
struct STColumn {
|
struct STColumn {
|
||||||
col_id_t colId;
|
col_id_t colId;
|
||||||
|
|
@ -225,23 +259,9 @@ struct STag {
|
||||||
memcpy(varDataVal(x), (str), (_size)); \
|
memcpy(varDataVal(x), (str), (_size)); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
// ----------------- SCHEMA BUILDER DEFINITION
|
// STSchema ================================
|
||||||
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 *tBuildTSchema(SSchema *aSchema, int32_t numOfCols, int32_t version);
|
STSchema *tBuildTSchema(SSchema *aSchema, int32_t numOfCols, int32_t version);
|
||||||
|
void tDestroyTSchema(STSchema *pTSchema);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -482,8 +482,6 @@ static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaW
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STSchema* tdGetSTSChemaFromSSChema(SSchema* pSchema, int32_t nCols, int32_t sver);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[TSDB_TABLE_FNAME_LEN];
|
char name[TSDB_TABLE_FNAME_LEN];
|
||||||
int8_t igExists;
|
int8_t igExists;
|
||||||
|
|
@ -1734,6 +1732,8 @@ typedef struct {
|
||||||
int32_t execId;
|
int32_t execId;
|
||||||
} STaskDropReq;
|
} 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 tSerializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
|
||||||
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
|
int32_t tDeserializeSTaskDropReq(void* buf, int32_t bufLen, STaskDropReq* pReq);
|
||||||
|
|
||||||
|
|
@ -2083,8 +2083,13 @@ typedef struct SVCreateTbReq {
|
||||||
|
|
||||||
int tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
|
int tEncodeSVCreateTbReq(SEncoder* pCoder, const SVCreateTbReq* pReq);
|
||||||
int tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
|
int tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq);
|
||||||
|
void tDestroySVCreateTbReq(SVCreateTbReq* pReq, int32_t flags);
|
||||||
|
|
||||||
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
|
static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) {
|
||||||
|
if (NULL == req) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
taosMemoryFreeClear(req->name);
|
taosMemoryFreeClear(req->name);
|
||||||
taosMemoryFreeClear(req->comment);
|
taosMemoryFreeClear(req->comment);
|
||||||
if (req->type == TSDB_CHILD_TABLE) {
|
if (req->type == TSDB_CHILD_TABLE) {
|
||||||
|
|
@ -3232,6 +3237,57 @@ int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||||
int32_t tDeserializeSMqAskEpReq(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 tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||||
int32_t tDeserializeSMqHbReq(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)
|
#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 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);
|
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 qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver);
|
||||||
int32_t qStreamRecoverFinish(qTaskInfo_t tinfo);
|
int32_t qStreamRecoverFinish(qTaskInfo_t tinfo);
|
||||||
int32_t qStreamRestoreParam(qTaskInfo_t tinfo);
|
int32_t qStreamRestoreParam(qTaskInfo_t tinfo);
|
||||||
|
bool qStreamRecoverScanFinished(qTaskInfo_t tinfo);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,8 @@ typedef struct SVgDataBlocks {
|
||||||
void* pData; // SSubmitReq + SSubmitBlk + ...
|
void* pData; // SSubmitReq + SSubmitBlk + ...
|
||||||
} SVgDataBlocks;
|
} SVgDataBlocks;
|
||||||
|
|
||||||
typedef void (*FFreeDataBlockHash)(SHashObj*);
|
typedef void (*FFreeTableBlockHash)(SHashObj*);
|
||||||
typedef void (*FFreeDataBlockArray)(SArray*);
|
typedef void (*FFreeVgourpBlockArray)(SArray*);
|
||||||
|
|
||||||
typedef struct SVnodeModifyOpStmt {
|
typedef struct SVnodeModifyOpStmt {
|
||||||
ENodeType nodeType;
|
ENodeType nodeType;
|
||||||
|
|
@ -377,15 +377,15 @@ typedef struct SVnodeModifyOpStmt {
|
||||||
const char* pBoundCols;
|
const char* pBoundCols;
|
||||||
struct STableMeta* pTableMeta;
|
struct STableMeta* pTableMeta;
|
||||||
SHashObj* pVgroupsHashObj;
|
SHashObj* pVgroupsHashObj;
|
||||||
SHashObj* pTableBlockHashObj;
|
SHashObj* pTableBlockHashObj; // SHashObj<tuid, STableDataCxt*>
|
||||||
SHashObj* pSubTableHashObj;
|
SHashObj* pSubTableHashObj;
|
||||||
SHashObj* pTableNameHashObj;
|
SHashObj* pTableNameHashObj;
|
||||||
SHashObj* pDbFNameHashObj;
|
SHashObj* pDbFNameHashObj;
|
||||||
SArray* pVgDataBlocks;
|
SArray* pVgDataBlocks; // SArray<SVgroupDataCxt*>
|
||||||
SVCreateTbReq createTblReq;
|
SVCreateTbReq* pCreateTblReq;
|
||||||
TdFilePtr fp;
|
TdFilePtr fp;
|
||||||
FFreeDataBlockHash freeHashFunc;
|
FFreeTableBlockHash freeHashFunc;
|
||||||
FFreeDataBlockArray freeArrayFunc;
|
FFreeVgourpBlockArray freeArrayFunc;
|
||||||
bool usingTableProcessing;
|
bool usingTableProcessing;
|
||||||
bool fileProcessing;
|
bool fileProcessing;
|
||||||
} SVnodeModifyOpStmt;
|
} SVnodeModifyOpStmt;
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ typedef struct SParseContext {
|
||||||
bool isSuperUser;
|
bool isSuperUser;
|
||||||
bool enableSysInfo;
|
bool enableSysInfo;
|
||||||
bool async;
|
bool async;
|
||||||
int8_t schemalessType;
|
|
||||||
const char* svrVer;
|
const char* svrVer;
|
||||||
bool nodeOffline;
|
bool nodeOffline;
|
||||||
SArray* pTableMetaPos; // sql table pos => catalog data pos
|
SArray* pTableMetaPos; // sql table pos => catalog data pos
|
||||||
|
|
@ -85,12 +84,12 @@ int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
|
||||||
void qCleanupKeywordsTable();
|
void qCleanupKeywordsTable();
|
||||||
|
|
||||||
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
|
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
|
||||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf);
|
int32_t qResetStmtDataBlock(STableDataCxt* block, bool keepBuf);
|
||||||
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc);
|
int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset);
|
||||||
void qFreeStmtDataBlock(void* pDataBlock);
|
int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, bool rebuildCreateTb);
|
||||||
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid, int32_t vgId);
|
void qDestroyStmtDataBlock(STableDataCxt* pBlock);
|
||||||
void qDestroyStmtDataBlock(void* pBlock);
|
STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock);
|
||||||
STableMeta* qGetTableMetaInDataBlock(void* pDataBlock);
|
int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData **pData);
|
||||||
|
|
||||||
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx);
|
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx);
|
||||||
int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery);
|
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 qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
|
||||||
int32_t msgBufLen);
|
int32_t msgBufLen);
|
||||||
|
|
||||||
void* smlInitHandle(SQuery* pQuery);
|
void qDestroyBoundColInfo(void* pInfo);
|
||||||
void smlDestroyHandle(void* pHandle);
|
|
||||||
int32_t smlBindData(void* handle, SArray* tags, SArray* colsSchema, SArray* cols, bool format, STableMeta* pTableMeta,
|
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);
|
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);
|
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
|
||||||
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
|
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,23 @@ typedef struct STargetInfo {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
} STargetInfo;
|
} 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_send_cb_fn_t)(void* param, SDataBuf* pMsg, int32_t code);
|
||||||
typedef int32_t (*__async_exec_fn_t)(void* param);
|
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);
|
char* parseTagDatatoJson(void* p);
|
||||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
||||||
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
||||||
|
int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst);
|
||||||
void freeVgInfo(SDBVgInfo* vgInfo);
|
void freeVgInfo(SDBVgInfo* vgInfo);
|
||||||
|
|
||||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen,
|
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen,
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ typedef struct {
|
||||||
int8_t type;
|
int8_t type;
|
||||||
} SStreamQueueItem;
|
} SStreamQueueItem;
|
||||||
|
|
||||||
|
#if 0
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t type;
|
int8_t type;
|
||||||
int64_t ver;
|
int64_t ver;
|
||||||
|
|
@ -116,6 +117,21 @@ typedef struct {
|
||||||
SArray* dataRefs; // SArray<int32_t*>
|
SArray* dataRefs; // SArray<int32_t*>
|
||||||
SArray* reqs; // SArray<SSubmitReq*>
|
SArray* reqs; // SArray<SSubmitReq*>
|
||||||
} SStreamMergedSubmit;
|
} 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 {
|
typedef struct {
|
||||||
int8_t type;
|
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 {
|
typedef struct {
|
||||||
char* qmsg;
|
char* qmsg;
|
||||||
|
|
@ -355,14 +371,15 @@ void tFreeSStreamTask(SStreamTask* pTask);
|
||||||
|
|
||||||
static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem* pItem) {
|
static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem* pItem) {
|
||||||
if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
SStreamDataSubmit* pSubmitClone = streamSubmitRefClone((SStreamDataSubmit*)pItem);
|
SStreamDataSubmit2* pSubmitClone = streamSubmitRefClone((SStreamDataSubmit2*)pItem);
|
||||||
if (pSubmitClone == NULL) {
|
if (pSubmitClone == NULL) {
|
||||||
qDebug("task %d %p submit enqueue failed since out of memory", pTask->taskId, pTask);
|
qDebug("task %d %p submit enqueue failed since out of memory", pTask->taskId, pTask);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||||
return -1;
|
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);
|
taosWriteQitem(pTask->inputQueue->queue, pSubmitClone);
|
||||||
// qStreamInput(pTask->exec.executor, pSubmitClone);
|
// qStreamInput(pTask->exec.executor, pSubmitClone);
|
||||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE ||
|
} 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);
|
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 {
|
typedef struct {
|
||||||
SMsgHead head;
|
SMsgHead head;
|
||||||
int64_t streamId;
|
int64_t streamId;
|
||||||
|
|
@ -584,6 +586,7 @@ int32_t streamProcessRetrieveRsp(SStreamTask* pTask, SStreamRetrieveRsp* pRsp);
|
||||||
|
|
||||||
int32_t streamTryExec(SStreamTask* pTask);
|
int32_t streamTryExec(SStreamTask* pTask);
|
||||||
int32_t streamSchedExec(SStreamTask* pTask);
|
int32_t streamSchedExec(SStreamTask* pTask);
|
||||||
|
int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBlock* pBlock);
|
||||||
|
|
||||||
int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz);
|
int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,11 +52,13 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void tFree(uint8_t *pBuf) {
|
#define tFree(BUF) \
|
||||||
if (pBuf) {
|
do { \
|
||||||
taosMemoryFree(pBuf - sizeof(int64_t));
|
if (BUF) { \
|
||||||
}
|
taosMemoryFree((uint8_t *)(BUF) - sizeof(int64_t)); \
|
||||||
}
|
(BUF) = NULL; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_TSC_QUERY_KILLED TAOS_DEF_ERROR_CODE(0, 0X022D)
|
#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_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_NOT_STABLE_ERROR TAOS_DEF_ERROR_CODE(0, 0X022F)
|
||||||
|
#define TSDB_CODE_TSC_STMT_CACHE_ERROR TAOS_DEF_ERROR_CODE(0, 0X0230)
|
||||||
|
|
||||||
// mnode-common
|
// mnode-common
|
||||||
// #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) // 2.x
|
// #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) // 2.x
|
||||||
|
|
|
||||||
|
|
@ -22,19 +22,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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_MIN_SIZE 8
|
||||||
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
|
#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)
|
#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
|
||||||
|
|
@ -46,6 +33,9 @@ typedef struct SArray {
|
||||||
void* pData;
|
void* pData;
|
||||||
} SArray;
|
} SArray;
|
||||||
|
|
||||||
|
#define TARRAY_SIZE(array) ((array)->size)
|
||||||
|
#define TARRAY_DATA(array) ((array)->pData)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param size
|
* @param size
|
||||||
|
|
@ -194,6 +184,13 @@ void taosArrayPopTailBatch(SArray* pArray, size_t cnt);
|
||||||
*/
|
*/
|
||||||
void taosArrayRemove(SArray* pArray, size_t index);
|
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
|
* copy the whole array from source to destination
|
||||||
* @param pDst
|
* @param pDst
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,7 @@ typedef enum ELogicConditionType {
|
||||||
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
#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_TOPIC_NAME_LEN 193 // it is a null-terminated string
|
||||||
#define TSDB_CGROUP_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_NAME_LEN 65
|
||||||
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ static int32_t tEncodeI64v(SEncoder* pCoder, int64_t val);
|
||||||
static int32_t tEncodeFloat(SEncoder* pCoder, float val);
|
static int32_t tEncodeFloat(SEncoder* pCoder, float val);
|
||||||
static int32_t tEncodeDouble(SEncoder* pCoder, double 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 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 tEncodeCStrWithLen(SEncoder* pCoder, const char* val, uint32_t len);
|
||||||
static int32_t tEncodeCStr(SEncoder* pCoder, const char* val);
|
static int32_t tEncodeCStr(SEncoder* pCoder, const char* val);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ set binary_dir=%3
|
||||||
set binary_dir=%binary_dir:/=\\%
|
set binary_dir=%binary_dir:/=\\%
|
||||||
set osType=%4
|
set osType=%4
|
||||||
set verNumber=%5
|
set verNumber=%5
|
||||||
|
set Enterprise=%6
|
||||||
set target_dir=C:\\TDengine
|
set target_dir=C:\\TDengine
|
||||||
|
|
||||||
if not exist %target_dir% (
|
if not exist %target_dir% (
|
||||||
|
|
@ -57,6 +58,32 @@ if exist %binary_dir%\\build\\lib\\taosws.dll (
|
||||||
if exist %binary_dir%\\build\\bin\\taosdump.exe (
|
if exist %binary_dir%\\build\\bin\\taosdump.exe (
|
||||||
copy %binary_dir%\\build\\bin\\taosdump.exe %target_dir% > nul
|
copy %binary_dir%\\build\\bin\\taosdump.exe %target_dir% > nul
|
||||||
)
|
)
|
||||||
|
if %Enterprise% (
|
||||||
|
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\\taosd.exe %target_dir% > nul
|
||||||
copy %binary_dir%\\build\\bin\\udfd.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
|
# install_dir has been distinguishes cluster from edege, so comments this code
|
||||||
pkg_name=${install_dir}-${osType}-${cpuType}
|
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
|
# if [ "$verMode" == "cluster" ]; then
|
||||||
# pkg_name=${install_dir}-${osType}-${cpuType}
|
# pkg_name=${install_dir}-${osType}-${cpuType}
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,6 @@ typedef struct STscObj {
|
||||||
int32_t numOfReqs; // number of sqlObj bound to this connection
|
int32_t numOfReqs; // number of sqlObj bound to this connection
|
||||||
SAppInstInfo* pAppInfo;
|
SAppInstInfo* pAppInfo;
|
||||||
SHashObj* pRequests;
|
SHashObj* pRequests;
|
||||||
int8_t schemalessType; // todo remove it, this attribute should be move to request
|
|
||||||
} STscObj;
|
} STscObj;
|
||||||
|
|
||||||
typedef struct SResultColumn {
|
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 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 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 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
|
// clang-format on
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#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
|
#endif
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
|
|
||||||
typedef void STableDataBlocks;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STMT_TYPE_INSERT = 1,
|
STMT_TYPE_INSERT = 1,
|
||||||
STMT_TYPE_MULTI_INSERT,
|
STMT_TYPE_MULTI_INSERT,
|
||||||
|
|
@ -43,7 +41,7 @@ typedef enum {
|
||||||
} STMT_STATUS;
|
} STMT_STATUS;
|
||||||
|
|
||||||
typedef struct SStmtTableCache {
|
typedef struct SStmtTableCache {
|
||||||
STableDataBlocks *pDataBlock;
|
STableDataCxt *pDataCtx;
|
||||||
void *boundTags;
|
void *boundTags;
|
||||||
} SStmtTableCache;
|
} SStmtTableCache;
|
||||||
|
|
||||||
|
|
@ -74,7 +72,8 @@ typedef struct SStmtExecInfo {
|
||||||
int32_t affectedRows;
|
int32_t affectedRows;
|
||||||
SRequestObj *pRequest;
|
SRequestObj *pRequest;
|
||||||
SHashObj *pBlockHash;
|
SHashObj *pBlockHash;
|
||||||
bool autoCreateTbl;
|
STableDataCxt *pCurrBlock;
|
||||||
|
SSubmitTbData *pCurrTbData;
|
||||||
} SStmtExecInfo;
|
} SStmtExecInfo;
|
||||||
|
|
||||||
typedef struct SStmtSQLInfo {
|
typedef struct SStmtSQLInfo {
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,19 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
||||||
"current:%d, app current:%d",
|
"current:%d, app current:%d",
|
||||||
pRequest->self, pTscObj->id, pRequest->requestId, duration / 1000.0, num, currentInst);
|
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) {
|
if (QUERY_NODE_VNODE_MODIFY_STMT == pRequest->stmtType) {
|
||||||
// tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64
|
// tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64
|
||||||
// "us, exec:%" PRId64 "us",
|
// "us, exec:%" PRId64 "us",
|
||||||
// duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart,
|
// duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart,
|
||||||
// pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd -
|
// pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd -
|
||||||
// pRequest->metric.ctgEnd, pRequest->metric.execEnd - pRequest->metric.semanticEnd);
|
// pRequest->metric.ctgEnd, pRequest->metric.execEnd - pRequest->metric.semanticEnd);
|
||||||
atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
|
// atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
|
||||||
} else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) {
|
} else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) {
|
||||||
// tscPerf("select duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64
|
// tscPerf("select duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64
|
||||||
// "us, planner:%" PRId64 "us, exec:%" PRId64 "us, reqId:0x%" PRIx64,
|
// "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);
|
taosThreadMutexInit(&pObj->mutex, NULL);
|
||||||
pObj->id = taosAddRef(clientConnRefPool, pObj);
|
pObj->id = taosAddRef(clientConnRefPool, pObj);
|
||||||
pObj->schemalessType = 1;
|
|
||||||
|
|
||||||
atomic_add_fetch_64(&pObj->pAppInfo->numOfConns, 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,
|
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||||
.pStmtCb = pStmtCb,
|
.pStmtCb = pStmtCb,
|
||||||
.pUser = pTscObj->user,
|
.pUser = pTscObj->user,
|
||||||
.schemalessType = pTscObj->schemalessType,
|
|
||||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||||
.enableSysInfo = pTscObj->sysInfo,
|
.enableSysInfo = pTscObj->sysInfo,
|
||||||
.svrVer = pTscObj->sVer,
|
.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 handleSubmitExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet* epset) {
|
||||||
int32_t code = 0;
|
|
||||||
SArray* pArray = NULL;
|
SArray* pArray = NULL;
|
||||||
SSubmitRsp* pRsp = (SSubmitRsp*)res;
|
SSubmitRsp2* pRsp = (SSubmitRsp2*)res;
|
||||||
if (pRsp->nBlocks <= 0) {
|
if (NULL == pRsp->aCreateTbRsp) {
|
||||||
taosMemoryFreeClear(pRsp->pBlocks);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
pArray = taosArrayInit(pRsp->nBlocks, sizeof(STbSVersion));
|
int32_t tbNum = taosArrayGetSize(pRsp->aCreateTbRsp);
|
||||||
if (NULL == pArray) {
|
for (int32_t i = 0; i < tbNum; ++i) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
SVCreateTbRsp* pTbRsp = (SVCreateTbRsp*)taosArrayGet(pRsp->aCreateTbRsp, i);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
if (pTbRsp->pMeta) {
|
||||||
|
handleCreateTbExecRes(pTbRsp->pMeta, pCatalog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < pRsp->nBlocks; ++i) {
|
return TSDB_CODE_SUCCESS;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet* epset) {
|
int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet* epset) {
|
||||||
|
|
|
||||||
|
|
@ -866,7 +866,6 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
||||||
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||||
.pStmtCb = NULL,
|
.pStmtCb = NULL,
|
||||||
.pUser = pTscObj->user,
|
.pUser = pTscObj->user,
|
||||||
.schemalessType = pTscObj->schemalessType,
|
|
||||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||||
.enableSysInfo = pTscObj->sysInfo,
|
.enableSysInfo = pTscObj->sysInfo,
|
||||||
.async = true,
|
.async = true,
|
||||||
|
|
|
||||||
|
|
@ -1240,22 +1240,12 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
|
||||||
return code;
|
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 taos_write_raw_block_with_fields(TAOS* taos, int rows, char* pData, const char* tbname, TAOS_FIELD* fields,
|
||||||
int numFields) {
|
int numFields) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
STableMeta* pTableMeta = NULL;
|
STableMeta* pTableMeta = NULL;
|
||||||
SQuery* pQuery = NULL;
|
SQuery* pQuery = NULL;
|
||||||
SSubmitReq* subReq = NULL;
|
SHashObj* pVgHash = NULL;
|
||||||
|
|
||||||
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
|
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
|
||||||
if (!pRequest) {
|
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);
|
uError("WriteRaw:catalogGetTableMeta failed. table name: %s", tbname);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
|
pQuery = smlInitHandle();
|
||||||
uint64_t uid = pTableMeta->uid;
|
if (pQuery == NULL) {
|
||||||
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");
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||||
pQuery->haveResultSet = false;
|
taosHashPut(pVgHash, (const char*)&vgData.vgId, sizeof(vgData.vgId), (char*)&vgData, sizeof(vgData));
|
||||||
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);
|
|
||||||
|
|
||||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
code = rawBlockBindData(pQuery, pTableMeta, pData, NULL, fields, numFields);
|
||||||
if (NULL == dst) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
uError("WriteRaw:rawBlockBindData failed");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
dst->vg = vgData;
|
|
||||||
dst->numOfTables = subReq->numOfBlocks;
|
code = smlBuildOutput(pQuery, pVgHash);
|
||||||
dst->size = subReq->length;
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
dst->pData = (char*)subReq;
|
uError("smlBuildOutput failed");
|
||||||
subReq->header.vgId = htonl(dst->vg.vgId);
|
return code;
|
||||||
subReq->version = htonl(1);
|
}
|
||||||
subReq->header.contLen = htonl(subReq->length);
|
|
||||||
subReq->length = htonl(subReq->length);
|
|
||||||
subReq->numOfBlocks = htonl(subReq->numOfBlocks);
|
|
||||||
subReq = NULL; // no need free
|
|
||||||
taosArrayPush(nodeStmt->pDataBlocks, &dst);
|
|
||||||
|
|
||||||
launchQueryImpl(pRequest, pQuery, true, NULL);
|
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||||
code = pRequest->code;
|
code = pRequest->code;
|
||||||
|
|
@ -1450,7 +1316,8 @@ int taos_write_raw_block_with_fields(TAOS* taos, int rows, char* pData, const ch
|
||||||
end:
|
end:
|
||||||
taosMemoryFreeClear(pTableMeta);
|
taosMemoryFreeClear(pTableMeta);
|
||||||
qDestroyQuery(pQuery);
|
qDestroyQuery(pQuery);
|
||||||
taosMemoryFree(subReq);
|
destroyRequest(pRequest);
|
||||||
|
taosHashCleanup(pVgHash);
|
||||||
return code;
|
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;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
STableMeta* pTableMeta = NULL;
|
STableMeta* pTableMeta = NULL;
|
||||||
SQuery* pQuery = NULL;
|
SQuery* pQuery = NULL;
|
||||||
SSubmitReq* subReq = NULL;
|
SHashObj* pVgHash = NULL;
|
||||||
|
|
||||||
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
|
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
|
||||||
if (!pRequest) {
|
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);
|
uError("WriteRaw:catalogGetTableMeta failed. table name: %s", tbname);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
|
pQuery = smlInitHandle();
|
||||||
uint64_t uid = pTableMeta->uid;
|
if (pQuery == NULL) {
|
||||||
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");
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
SVnodeModifyOpStmt* nodeStmt = (SVnodeModifyOpStmt*)(pQuery->pRoot);
|
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||||
nodeStmt->pDataBlocks = taosArrayInit(1, POINTER_BYTES);
|
taosHashPut(pVgHash, (const char*)&vgData.vgId, sizeof(vgData.vgId), (char*)&vgData, sizeof(vgData));
|
||||||
|
|
||||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
code = rawBlockBindData(pQuery, pTableMeta, pData, NULL, NULL, 0);
|
||||||
if (NULL == dst) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
uError("WriteRaw:rawBlockBindData failed");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
dst->vg = vgData;
|
|
||||||
dst->numOfTables = subReq->numOfBlocks;
|
code = smlBuildOutput(pQuery, pVgHash);
|
||||||
dst->size = subReq->length;
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
dst->pData = (char*)subReq;
|
uError("smlBuildOutput failed");
|
||||||
subReq->header.vgId = htonl(dst->vg.vgId);
|
return code;
|
||||||
subReq->version = htonl(1);
|
}
|
||||||
subReq->header.contLen = htonl(subReq->length);
|
|
||||||
subReq->length = htonl(subReq->length);
|
|
||||||
subReq->numOfBlocks = htonl(subReq->numOfBlocks);
|
|
||||||
subReq = NULL; // no need free
|
|
||||||
taosArrayPush(nodeStmt->pDataBlocks, &dst);
|
|
||||||
|
|
||||||
launchQueryImpl(pRequest, pQuery, true, NULL);
|
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||||
code = pRequest->code;
|
code = pRequest->code;
|
||||||
|
|
@ -1642,7 +1396,8 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname)
|
||||||
end:
|
end:
|
||||||
taosMemoryFreeClear(pTableMeta);
|
taosMemoryFreeClear(pTableMeta);
|
||||||
qDestroyQuery(pQuery);
|
qDestroyQuery(pQuery);
|
||||||
taosMemoryFree(subReq);
|
destroyRequest(pRequest);
|
||||||
|
taosHashCleanup(pVgHash);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1679,8 +1434,6 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
|
||||||
taosHashSetFreeFp(pVgHash, destroyVgHash);
|
|
||||||
struct SCatalog* pCatalog = NULL;
|
struct SCatalog* pCatalog = NULL;
|
||||||
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
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.requestObjRefId = pRequest->self;
|
||||||
conn.mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
|
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);
|
uDebug("raw data block num:%d\n", rspObj.rsp.blockNum);
|
||||||
while (++rspObj.resIter < rspObj.rsp.blockNum) {
|
while (++rspObj.resIter < rspObj.rsp.blockNum) {
|
||||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(rspObj.rsp.blockData, rspObj.resIter);
|
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);
|
uError("WriteRaw:no schema, iter:%d", rspObj.resIter);
|
||||||
goto end;
|
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);
|
const char* tbName = (const char*)taosArrayGetP(rspObj.rsp.blockTbName, rspObj.resIter);
|
||||||
if (!tbName) {
|
if (!tbName) {
|
||||||
|
|
@ -1722,13 +1473,6 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
||||||
strcpy(pName.dbname, pRequest->pDb);
|
strcpy(pName.dbname, pRequest->pDb);
|
||||||
strcpy(pName.tname, tbName);
|
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);
|
code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
|
||||||
if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
|
if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
|
||||||
uError("WriteRaw:catalogGetTableMeta table not exist. table name: %s", tbName);
|
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;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t fLen = 0;
|
SVgroupInfo vg;
|
||||||
int32_t rowSize = 0;
|
code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &vg);
|
||||||
int16_t nVar = 0;
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
|
uError("WriteRaw:catalogGetTableHashVgroup failed. table name: %s", tbName);
|
||||||
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;
|
goto end;
|
||||||
}
|
}
|
||||||
vgData.data = tmp;
|
|
||||||
((VgData*)hData)->data = tmp;
|
void* hData = taosHashGet(pVgHash, &vg.vgId, sizeof(vg.vgId));
|
||||||
subReq = (SSubmitReq*)(vgData.data);
|
if (hData == NULL) {
|
||||||
blk = POINTER_SHIFT(vgData.data, subReq->length);
|
taosHashPut(pVgHash, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg));
|
||||||
} else {
|
}
|
||||||
int32_t totalLen = sizeof(SSubmitReq) + submitLen;
|
|
||||||
void* tmp = taosMemoryCalloc(1, totalLen);
|
code = rawBlockBindData(pQuery, pTableMeta, pRetrieve->data, NULL, NULL, 0);
|
||||||
if (tmp == NULL) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
uError("WriteRaw:rawBlockBindData failed");
|
||||||
goto end;
|
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
|
code = smlBuildOutput(pQuery, pVgHash);
|
||||||
// ASSERT(pSW->nCols == pTableMeta->tableInfo.numOfColumns);
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
|
uError("smlBuildOutput failed");
|
||||||
uint64_t uid = pTableMeta->uid;
|
return code;
|
||||||
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;
|
|
||||||
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);
|
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||||
|
|
@ -1905,8 +1514,6 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
||||||
|
|
||||||
end:
|
end:
|
||||||
tDeleteSMqDataRsp(&rspObj.rsp);
|
tDeleteSMqDataRsp(&rspObj.rsp);
|
||||||
rspObj.resInfo.pRspMsg = NULL;
|
|
||||||
doFreeReqResultInfo(&rspObj.resInfo);
|
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
qDestroyQuery(pQuery);
|
qDestroyQuery(pQuery);
|
||||||
destroyRequest(pRequest);
|
destroyRequest(pRequest);
|
||||||
|
|
@ -1948,8 +1555,6 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
|
||||||
taosHashSetFreeFp(pVgHash, destroyVgHash);
|
|
||||||
struct SCatalog* pCatalog = NULL;
|
struct SCatalog* pCatalog = NULL;
|
||||||
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
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.requestObjRefId = pRequest->self;
|
||||||
conn.mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
|
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);
|
uDebug("raw data block num:%d\n", rspObj.rsp.blockNum);
|
||||||
while (++rspObj.resIter < rspObj.rsp.blockNum) {
|
while (++rspObj.resIter < rspObj.rsp.blockNum) {
|
||||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(rspObj.rsp.blockData, rspObj.resIter);
|
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);
|
uError("WriteRaw:no schema, iter:%d", rspObj.resIter);
|
||||||
goto end;
|
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);
|
const char* tbName = (const char*)taosArrayGetP(rspObj.rsp.blockTbName, rspObj.resIter);
|
||||||
if (!tbName) {
|
if (!tbName) {
|
||||||
|
|
@ -1991,44 +1595,28 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
||||||
strcpy(pName.dbname, pRequest->pDb);
|
strcpy(pName.dbname, pRequest->pDb);
|
||||||
strcpy(pName.tname, tbName);
|
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
|
// find schema data info
|
||||||
int32_t schemaLen = 0;
|
SVCreateTbReq pCreateReq = {0};
|
||||||
void* schemaData = NULL;
|
|
||||||
for (int j = 0; j < rspObj.rsp.createTableNum; j++) {
|
for (int j = 0; j < rspObj.rsp.createTableNum; j++) {
|
||||||
void** dataTmp = taosArrayGet(rspObj.rsp.createTableReq, j);
|
void** dataTmp = taosArrayGet(rspObj.rsp.createTableReq, j);
|
||||||
int32_t* lenTmp = taosArrayGet(rspObj.rsp.createTableLen, j);
|
int32_t* lenTmp = taosArrayGet(rspObj.rsp.createTableLen, j);
|
||||||
|
|
||||||
SDecoder decoderTmp = {0};
|
SDecoder decoderTmp = {0};
|
||||||
SVCreateTbReq pCreateReq = {0};
|
|
||||||
|
|
||||||
tDecoderInit(&decoderTmp, *dataTmp, *lenTmp);
|
tDecoderInit(&decoderTmp, *dataTmp, *lenTmp);
|
||||||
|
memset(&pCreateReq, 0, sizeof(SVCreateTbReq));
|
||||||
if (tDecodeSVCreateTbReq(&decoderTmp, &pCreateReq) < 0) {
|
if (tDecodeSVCreateTbReq(&decoderTmp, &pCreateReq) < 0) {
|
||||||
tDecoderClear(&decoderTmp);
|
tDecoderClear(&decoderTmp);
|
||||||
taosMemoryFreeClear(pCreateReq.comment);
|
|
||||||
taosArrayDestroy(pCreateReq.ctb.tagName);
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pCreateReq.type == TSDB_CHILD_TABLE);
|
ASSERT(pCreateReq.type == TSDB_CHILD_TABLE);
|
||||||
if (strcmp(tbName, pCreateReq.name) == 0) {
|
if (strcmp(tbName, pCreateReq.name) == 0) {
|
||||||
schemaLen = *lenTmp;
|
|
||||||
schemaData = *dataTmp;
|
|
||||||
strcpy(pName.tname, pCreateReq.ctb.stbName);
|
strcpy(pName.tname, pCreateReq.ctb.stbName);
|
||||||
tDecoderClear(&decoderTmp);
|
tDecoderClear(&decoderTmp);
|
||||||
taosMemoryFreeClear(pCreateReq.comment);
|
|
||||||
taosArrayDestroy(pCreateReq.ctb.tagName);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tDecoderClear(&decoderTmp);
|
tDecoderClear(&decoderTmp);
|
||||||
taosMemoryFreeClear(pCreateReq.comment);
|
|
||||||
taosArrayDestroy(pCreateReq.ctb.tagName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
|
code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
|
||||||
|
|
@ -2042,167 +1630,23 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t fLen = 0;
|
SVgroupInfo vg;
|
||||||
int32_t rowSize = 0;
|
code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &vg);
|
||||||
int16_t nVar = 0;
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
|
uError("WriteRaw:catalogGetTableHashVgroup failed. table name: %s", tbName);
|
||||||
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;
|
goto end;
|
||||||
}
|
}
|
||||||
vgData.data = tmp;
|
|
||||||
((VgData*)hData)->data = tmp;
|
void* hData = taosHashGet(pVgHash, &vg.vgId, sizeof(vg.vgId));
|
||||||
subReq = (SSubmitReq*)(vgData.data);
|
if (hData == NULL) {
|
||||||
blk = POINTER_SHIFT(vgData.data, subReq->length);
|
taosHashPut(pVgHash, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg));
|
||||||
} else {
|
}
|
||||||
int32_t totalLen = sizeof(SSubmitReq) + submitLen;
|
|
||||||
void* tmp = taosMemoryCalloc(1, totalLen);
|
code = rawBlockBindData(pQuery, pTableMeta, pRetrieve->data, &pCreateReq, NULL, 0);
|
||||||
if (tmp == NULL) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
uError("WriteRaw:rawBlockBindData failed");
|
||||||
goto end;
|
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;
|
|
||||||
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);
|
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||||
|
|
@ -2210,8 +1654,6 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
||||||
|
|
||||||
end:
|
end:
|
||||||
tDeleteSTaosxRsp(&rspObj.rsp);
|
tDeleteSTaosxRsp(&rspObj.rsp);
|
||||||
rspObj.resInfo.pRspMsg = NULL;
|
|
||||||
doFreeReqResultInfo(&rspObj.resInfo);
|
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
qDestroyQuery(pQuery);
|
qDestroyQuery(pQuery);
|
||||||
destroyRequest(pRequest);
|
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,7 +152,8 @@ int32_t stmtRestoreQueryFields(STscStmt* pStmt) {
|
||||||
return TSDB_CODE_SUCCESS;
|
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;
|
STscStmt* pStmt = (STscStmt*)stmt;
|
||||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||||
tNameExtractFullName(tbName, tbFName);
|
tNameExtractFullName(tbName, tbFName);
|
||||||
|
|
@ -171,12 +172,11 @@ int32_t stmtUpdateBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags,
|
||||||
return TSDB_CODE_SUCCESS;
|
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;
|
STscStmt* pStmt = (STscStmt*)stmt;
|
||||||
|
|
||||||
pStmt->sql.pVgHash = pVgHash;
|
pStmt->sql.pVgHash = pVgHash;
|
||||||
pStmt->exec.pBlockHash = pBlockHash;
|
pStmt->exec.pBlockHash = pBlockHash;
|
||||||
pStmt->exec.autoCreateTbl = autoCreateTbl;
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +186,7 @@ int32_t stmtUpdateInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags, SNam
|
||||||
STscStmt* pStmt = (STscStmt*)stmt;
|
STscStmt* pStmt = (STscStmt*)stmt;
|
||||||
|
|
||||||
STMT_ERR_RET(stmtUpdateBindInfo(stmt, pTableMeta, tags, tbName, sTableName, autoCreateTbl));
|
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;
|
pStmt->sql.autoCreateTbl = autoCreateTbl;
|
||||||
|
|
||||||
|
|
@ -214,16 +214,16 @@ int32_t stmtCacheBlock(STscStmt* pStmt) {
|
||||||
return TSDB_CODE_SUCCESS;
|
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) {
|
if (!pSrc) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
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 = {
|
SStmtTableCache cache = {
|
||||||
.pDataBlock = pDst,
|
.pDataCtx = pDst,
|
||||||
.boundTags = pStmt->bInfo.boundTags,
|
.boundTags = pStmt->bInfo.boundTags,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -241,6 +241,8 @@ int32_t stmtCacheBlock(STscStmt* pStmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t stmtParseSql(STscStmt* pStmt) {
|
int32_t stmtParseSql(STscStmt* pStmt) {
|
||||||
|
pStmt->exec.pCurrBlock = NULL;
|
||||||
|
|
||||||
SStmtCallback stmtCb = {
|
SStmtCallback stmtCb = {
|
||||||
.pStmt = pStmt,
|
.pStmt = pStmt,
|
||||||
.getTbNameFn = stmtGetTbName,
|
.getTbNameFn = stmtGetTbName,
|
||||||
|
|
@ -273,7 +275,7 @@ int32_t stmtCleanBindInfo(STscStmt* pStmt) {
|
||||||
pStmt->bInfo.tbName[0] = 0;
|
pStmt->bInfo.tbName[0] = 0;
|
||||||
pStmt->bInfo.tbFName[0] = 0;
|
pStmt->bInfo.tbFName[0] = 0;
|
||||||
if (!pStmt->bInfo.tagsCached) {
|
if (!pStmt->bInfo.tagsCached) {
|
||||||
destroyBoundColumnInfo(pStmt->bInfo.boundTags);
|
qDestroyBoundColInfo(pStmt->bInfo.boundTags);
|
||||||
taosMemoryFreeClear(pStmt->bInfo.boundTags);
|
taosMemoryFreeClear(pStmt->bInfo.boundTags);
|
||||||
}
|
}
|
||||||
memset(pStmt->bInfo.stbFName, 0, TSDB_TABLE_FNAME_LEN);
|
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;
|
size_t keyLen = 0;
|
||||||
void* pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
|
void* pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
STableDataBlocks* pBlocks = *(STableDataBlocks**)pIter;
|
STableDataCxt* pBlocks = *(STableDataCxt**)pIter;
|
||||||
char* key = taosHashGetKey(pIter, &keyLen);
|
char* key = taosHashGetKey(pIter, &keyLen);
|
||||||
STableMeta* pMeta = qGetTableMetaInDataBlock(pBlocks);
|
STableMeta* pMeta = qGetTableMetaInDataBlock(pBlocks);
|
||||||
|
|
||||||
if (keepTable && (strlen(pStmt->bInfo.tbFName) == keyLen) && strncmp(pStmt->bInfo.tbFName, key, keyLen) == 0) {
|
if (keepTable && pBlocks == pStmt->exec.pCurrBlock) {
|
||||||
STMT_ERR_RET(qResetStmtDataBlock(pBlocks, true));
|
ASSERT(NULL == pBlocks->pData);
|
||||||
|
TSWAP(pBlocks->pData, pStmt->exec.pCurrTbData);
|
||||||
|
STMT_ERR_RET(qResetStmtDataBlock(pBlocks, false));
|
||||||
|
|
||||||
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STMT_TYPE_MULTI_INSERT == pStmt->sql.type) {
|
|
||||||
qFreeStmtDataBlock(pBlocks);
|
|
||||||
} else {
|
|
||||||
qDestroyStmtDataBlock(pBlocks);
|
qDestroyStmtDataBlock(pBlocks);
|
||||||
}
|
|
||||||
taosHashRemove(pStmt->exec.pBlockHash, key, keyLen);
|
taosHashRemove(pStmt->exec.pBlockHash, key, keyLen);
|
||||||
|
|
||||||
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
pStmt->exec.autoCreateTbl = false;
|
|
||||||
|
|
||||||
if (keepTable) {
|
if (keepTable) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -319,6 +317,9 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool deepClean) {
|
||||||
taosHashCleanup(pStmt->exec.pBlockHash);
|
taosHashCleanup(pStmt->exec.pBlockHash);
|
||||||
pStmt->exec.pBlockHash = NULL;
|
pStmt->exec.pBlockHash = NULL;
|
||||||
|
|
||||||
|
tDestroySSubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
|
||||||
|
taosMemoryFreeClear(pStmt->exec.pCurrTbData);
|
||||||
|
|
||||||
STMT_ERR_RET(stmtCleanBindInfo(pStmt));
|
STMT_ERR_RET(stmtCleanBindInfo(pStmt));
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
@ -337,8 +338,8 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
SStmtTableCache* pCache = (SStmtTableCache*)pIter;
|
SStmtTableCache* pCache = (SStmtTableCache*)pIter;
|
||||||
|
|
||||||
qDestroyStmtDataBlock(pCache->pDataBlock);
|
qDestroyStmtDataBlock(pCache->pDataCtx);
|
||||||
destroyBoundColumnInfo(pCache->boundTags);
|
qDestroyBoundColInfo(pCache->boundTags);
|
||||||
taosMemoryFreeClear(pCache->boundTags);
|
taosMemoryFreeClear(pCache->boundTags);
|
||||||
|
|
||||||
pIter = taosHashIterate(pStmt->sql.pTableCache, pIter);
|
pIter = taosHashIterate(pStmt->sql.pTableCache, pIter);
|
||||||
|
|
@ -354,7 +355,8 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
||||||
return TSDB_CODE_SUCCESS;
|
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);
|
SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp);
|
||||||
SVgroupInfo vgInfo = {0};
|
SVgroupInfo vgInfo = {0};
|
||||||
SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter,
|
SRequestConnInfo conn = {.pTrans = pStmt->taos->pAppInfo->pTransporter,
|
||||||
|
|
@ -366,7 +368,9 @@ int32_t stmtRebuildDataBlock(STscStmt* pStmt, STableDataBlocks* pDataBlock, STab
|
||||||
STMT_ERR_RET(
|
STMT_ERR_RET(
|
||||||
taosHashPut(pStmt->sql.pVgHash, (const char*)&vgInfo.vgId, sizeof(vgInfo.vgId), (char*)&vgInfo, sizeof(vgInfo)));
|
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;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -375,12 +379,13 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
||||||
pStmt->bInfo.needParse = true;
|
pStmt->bInfo.needParse = true;
|
||||||
pStmt->bInfo.inExecCache = false;
|
pStmt->bInfo.inExecCache = false;
|
||||||
|
|
||||||
STableDataBlocks* pBlockInExec =
|
STableDataCxt** pCxtInExec = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||||
taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
if (pCxtInExec) {
|
||||||
if (pBlockInExec) {
|
|
||||||
pStmt->bInfo.needParse = false;
|
pStmt->bInfo.needParse = false;
|
||||||
pStmt->bInfo.inExecCache = true;
|
pStmt->bInfo.inExecCache = true;
|
||||||
|
|
||||||
|
pStmt->exec.pCurrBlock = *pCxtInExec;
|
||||||
|
|
||||||
if (pStmt->sql.autoCreateTbl) {
|
if (pStmt->sql.autoCreateTbl) {
|
||||||
tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName);
|
tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName);
|
||||||
return TSDB_CODE_SUCCESS;
|
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));
|
SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pStmt->bInfo.tbSuid, sizeof(pStmt->bInfo.tbSuid));
|
||||||
if (pCache) {
|
if (pCache) {
|
||||||
pStmt->bInfo.needParse = false;
|
pStmt->bInfo.needParse = false;
|
||||||
pStmt->exec.autoCreateTbl = true;
|
|
||||||
|
|
||||||
pStmt->bInfo.tbUid = 0;
|
pStmt->bInfo.tbUid = 0;
|
||||||
|
|
||||||
STableDataBlocks* pNewBlock = NULL;
|
STableDataCxt* pNewBlock = NULL;
|
||||||
STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataBlock, &pNewBlock, 0));
|
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,
|
if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock,
|
||||||
POINTER_BYTES)) {
|
POINTER_BYTES)) {
|
||||||
STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
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);
|
tscDebug("reuse stmt block for tb %s in sqlBlock, suid:0x%" PRIx64, pStmt->bInfo.tbFName, pStmt->bInfo.tbSuid);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
@ -489,14 +494,16 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
||||||
pStmt->bInfo.boundTags = pCache->boundTags;
|
pStmt->bInfo.boundTags = pCache->boundTags;
|
||||||
pStmt->bInfo.tagsCached = true;
|
pStmt->bInfo.tagsCached = true;
|
||||||
|
|
||||||
STableDataBlocks* pNewBlock = NULL;
|
STableDataCxt* pNewBlock = NULL;
|
||||||
STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataBlock, &pNewBlock, uid));
|
STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataCtx, &pNewBlock, uid, suid));
|
||||||
|
|
||||||
if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock,
|
if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock,
|
||||||
POINTER_BYTES)) {
|
POINTER_BYTES)) {
|
||||||
STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pStmt->exec.pCurrBlock = pNewBlock;
|
||||||
|
|
||||||
tscDebug("tb %s in sqlBlock list, set to current", pStmt->bInfo.tbFName);
|
tscDebug("tb %s in sqlBlock list, set to current", pStmt->bInfo.tbFName);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
@ -614,8 +621,8 @@ int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks** pDataBlock =
|
STableDataCxt** pDataBlock =
|
||||||
(STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||||
if (NULL == pDataBlock) {
|
if (NULL == pDataBlock) {
|
||||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
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->bInfo.sname.tname, tags, pStmt->exec.pRequest->msgBuf,
|
||||||
pStmt->exec.pRequest->msgBufLen));
|
pStmt->exec.pRequest->msgBufLen));
|
||||||
|
|
||||||
pStmt->exec.autoCreateTbl = true;
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
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);
|
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks** pDataBlock =
|
STableDataCxt** pDataBlock =
|
||||||
(STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||||
if (NULL == pDataBlock) {
|
if (NULL == pDataBlock) {
|
||||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
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);
|
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks** pDataBlock =
|
STableDataCxt** pDataBlock =
|
||||||
(STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
||||||
if (NULL == pDataBlock) {
|
if (NULL == pDataBlock) {
|
||||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
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;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks** pDataBlock =
|
STableDataCxt** pDataBlock = NULL;
|
||||||
(STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));
|
|
||||||
|
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) {
|
if (NULL == pDataBlock) {
|
||||||
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName);
|
||||||
STMT_ERR_RET(TSDB_CODE_APP_ERROR);
|
STMT_ERR_RET(TSDB_CODE_TSC_STMT_CACHE_ERROR);
|
||||||
|
}
|
||||||
|
pStmt->exec.pCurrBlock = *pDataBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colIdx < 0) {
|
if (colIdx < 0) {
|
||||||
|
|
@ -779,9 +791,9 @@ int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t finalCode = 0;
|
int32_t finalCode = 0;
|
||||||
size_t keyLen = 0;
|
size_t keyLen = 0;
|
||||||
STableDataBlocks** pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
|
void* pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
STableDataBlocks* pBlock = *pIter;
|
STableDataCxt* pBlock = *(STableDataCxt**)pIter;
|
||||||
char* key = taosHashGetKey(pIter, &keyLen);
|
char* key = taosHashGetKey(pIter, &keyLen);
|
||||||
|
|
||||||
STableMeta* pMeta = qGetTableMetaInDataBlock(pBlock);
|
STableMeta* pMeta = qGetTableMetaInDataBlock(pBlock);
|
||||||
|
|
@ -861,7 +873,6 @@ int stmtExec(TAOS_STMT* stmt) {
|
||||||
STscStmt* pStmt = (STscStmt*)stmt;
|
STscStmt* pStmt = (STscStmt*)stmt;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSubmitRsp* pRsp = NULL;
|
SSubmitRsp* pRsp = NULL;
|
||||||
bool autoCreateTbl = pStmt->exec.autoCreateTbl;
|
|
||||||
|
|
||||||
STMT_DLOG_E("start to exec");
|
STMT_DLOG_E("start to exec");
|
||||||
|
|
||||||
|
|
@ -870,8 +881,13 @@ int stmtExec(TAOS_STMT* stmt) {
|
||||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||||
launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL);
|
launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL);
|
||||||
} else {
|
} 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));
|
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)) {
|
if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) {
|
||||||
|
|
@ -894,15 +910,6 @@ _return:
|
||||||
|
|
||||||
stmtCleanExecInfo(pStmt, (code ? false : true), false);
|
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);
|
tFreeSSubmitRsp(pRsp);
|
||||||
|
|
||||||
++pStmt->sql.runTimes;
|
++pStmt->sql.runTimes;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -19,7 +19,7 @@
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
|
|
||||||
#define MALLOC_ALIGN_BYTES 256
|
#define MALLOC_ALIGN_BYTES 32
|
||||||
|
|
||||||
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) {
|
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) {
|
||||||
ASSERT(pColumnInfoData != NULL);
|
ASSERT(pColumnInfoData != NULL);
|
||||||
|
|
@ -38,7 +38,8 @@ int32_t colDataGetFullLength(const SColumnInfoData* pColumnInfoData, int32_t num
|
||||||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||||
return pColumnInfoData->varmeta.length + sizeof(int32_t) * numOfRows;
|
return pColumnInfoData->varmeta.length + sizeof(int32_t) * numOfRows;
|
||||||
} else {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1167,8 +1168,11 @@ void blockDataEmpty(SSDataBlock* pDataBlock) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo temporarily disable it
|
// 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);
|
ASSERT(numOfRows > 0);
|
||||||
|
|
||||||
if (numOfRows <= pBlockInfo->capacity) {
|
if (numOfRows <= pBlockInfo->capacity) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -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
|
"===stream===%s|block type %d|child id %d|group id:%" PRIu64 "|uid:%" PRId64
|
||||||
"|rows:%d|version:%" PRIu64 "|cal start:%" PRIu64 "|cal end:%" PRIu64 "\n",
|
"|rows:%d|version:%" PRIu64 "|cal start:%" PRIu64 "|cal end:%" PRIu64 "\n",
|
||||||
flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.id.groupId,
|
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;
|
if (len >= size - 1) return dumpBuf;
|
||||||
|
|
||||||
for (int32_t j = 0; j < rows; j++) {
|
for (int32_t j = 0; j < rows; j++) {
|
||||||
|
|
@ -2055,6 +2060,7 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
|
||||||
* @param suid
|
* @param suid
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#if 0
|
||||||
int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataBlock, STSchema* pTSchema, int32_t vgId,
|
int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataBlock, STSchema* pTSchema, int32_t vgId,
|
||||||
tb_uid_t suid) {
|
tb_uid_t suid) {
|
||||||
int32_t bufSize = sizeof(SSubmitReq);
|
int32_t bufSize = sizeof(SSubmitReq);
|
||||||
|
|
@ -2220,32 +2226,186 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
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) {
|
char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) {
|
||||||
ASSERT(stbFullName[0] != 0);
|
ASSERT(stbFullName[0] != 0);
|
||||||
SArray* tags = taosArrayInit(0, sizeof(void*));
|
SArray* tags = taosArrayInit(0, sizeof(SSmlKv));
|
||||||
if (tags == NULL) {
|
if (tags == NULL) {
|
||||||
return 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);
|
void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
|
||||||
if (cname == NULL) {
|
if (cname == NULL) {
|
||||||
taosArrayDestroy(tags);
|
taosArrayDestroy(tags);
|
||||||
taosMemoryFree(pTag);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTag->key = "group_id";
|
SSmlKv pTag = {.key = "group_id",
|
||||||
pTag->keyLen = strlen(pTag->key);
|
.keyLen = sizeof("group_id") - 1,
|
||||||
pTag->type = TSDB_DATA_TYPE_UBIGINT;
|
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||||
pTag->u = groupId;
|
.u = groupId,
|
||||||
pTag->length = sizeof(uint64_t);
|
.length = sizeof(uint64_t)};
|
||||||
taosArrayPush(tags, &pTag);
|
taosArrayPush(tags, &pTag);
|
||||||
|
|
||||||
RandTableName rname = {
|
RandTableName rname = {
|
||||||
|
|
@ -2257,7 +2417,6 @@ char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) {
|
||||||
|
|
||||||
buildChildTableName(&rname);
|
buildChildTableName(&rname);
|
||||||
|
|
||||||
taosMemoryFree(pTag);
|
|
||||||
taosArrayDestroy(tags);
|
taosArrayDestroy(tags);
|
||||||
|
|
||||||
ASSERT(rname.ctbShortName && rname.ctbShortName[0]);
|
ASSERT(rname.ctbShortName && rname.ctbShortName[0]);
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -5627,30 +5627,6 @@ int tDecodeSVCreateStbReq(SDecoder *pCoder, SVCreateStbReq *pReq) {
|
||||||
return 0;
|
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) {
|
int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) {
|
||||||
if (tStartEncode(pCoder) < 0) return -1;
|
if (tStartEncode(pCoder) < 0) return -1;
|
||||||
|
|
||||||
|
|
@ -5728,6 +5704,25 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
|
||||||
return 0;
|
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) {
|
int tEncodeSVCreateTbBatchReq(SEncoder *pCoder, const SVCreateTbBatchReq *pReq) {
|
||||||
int32_t nReq = taosArrayGetSize(pReq->pArray);
|
int32_t nReq = taosArrayGetSize(pReq->pArray);
|
||||||
|
|
||||||
|
|
@ -6719,3 +6714,328 @@ int32_t tDecodeSBatchDeleteReq(SDecoder *pDecoder, SBatchDeleteReq *pReq) {
|
||||||
}
|
}
|
||||||
return 0;
|
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) {
|
static int compareKv(const void* p1, const void* p2) {
|
||||||
SSmlKv* kv1 = *(SSmlKv**)p1;
|
SSmlKv* kv1 = (SSmlKv*)p1;
|
||||||
SSmlKv* kv2 = *(SSmlKv**)p2;
|
SSmlKv* kv2 = (SSmlKv*)p2;
|
||||||
int32_t kvLen1 = kv1->keyLen;
|
int32_t kvLen1 = kv1->keyLen;
|
||||||
int32_t kvLen2 = kv2->keyLen;
|
int32_t kvLen2 = kv2->keyLen;
|
||||||
int32_t res = strncasecmp(kv1->key, kv2->key, TMIN(kvLen1, kvLen2));
|
int32_t res = strncasecmp(kv1->key, kv2->key, TMIN(kvLen1, kvLen2));
|
||||||
|
|
@ -320,7 +320,7 @@ void buildChildTableName(RandTableName* rName) {
|
||||||
taosArraySort(rName->tags, compareKv);
|
taosArraySort(rName->tags, compareKv);
|
||||||
for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) {
|
for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) {
|
||||||
taosStringBuilderAppendChar(&sb, ',');
|
taosStringBuilderAppendChar(&sb, ',');
|
||||||
SSmlKv* tagKv = taosArrayGetP(rName->tags, j);
|
SSmlKv* tagKv = taosArrayGet(rName->tags, j);
|
||||||
taosStringBuilderAppendStringLen(&sb, tagKv->key, tagKv->keyLen);
|
taosStringBuilderAppendStringLen(&sb, tagKv->key, tagKv->keyLen);
|
||||||
taosStringBuilderAppendChar(&sb, '=');
|
taosStringBuilderAppendChar(&sb, '=');
|
||||||
if (IS_VAR_DATA_TYPE(tagKv->type)) {
|
if (IS_VAR_DATA_TYPE(tagKv->type)) {
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ STSchema *genSTSchema(int16_t nCols) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STSchema *pResult = NULL;
|
STSchema *pResult = NULL;
|
||||||
pResult = tdGetSTSChemaFromSSChema(pSchema, nCols, 1);
|
pResult = tBuildTSchema(pSchema, nCols, 1);
|
||||||
|
|
||||||
taosMemoryFree(pSchema);
|
taosMemoryFree(pSchema);
|
||||||
return pResult;
|
return pResult;
|
||||||
|
|
|
||||||
|
|
@ -558,6 +558,10 @@ static int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
||||||
goto SUBSCRIBE_OVER;
|
goto SUBSCRIBE_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mndCheckTopicPrivilege(pMnode, pMsg->info.conn.user, MND_OPER_SUBSCRIBE, pTopic) != 0) {
|
||||||
|
goto SUBSCRIBE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
mndReleaseTopic(pMnode, pTopic);
|
mndReleaseTopic(pMnode, pTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -696,14 +696,9 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||||
sdbRelease(pSdb, pConsumer);
|
sdbRelease(pSdb, pConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_READ_DB, pTopic->db) != 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());
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "drop-topic");
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "drop-topic");
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
|
|
|
||||||
|
|
@ -222,11 +222,19 @@ typedef struct SSnapContext {
|
||||||
} SSnapContext;
|
} SSnapContext;
|
||||||
|
|
||||||
typedef struct STqReader {
|
typedef struct STqReader {
|
||||||
|
// const SSubmitReq *pMsg;
|
||||||
|
// SSubmitBlk *pBlock;
|
||||||
|
// SSubmitMsgIter msgIter;
|
||||||
|
// SSubmitBlkIter blkIter;
|
||||||
|
|
||||||
int64_t ver;
|
int64_t ver;
|
||||||
const SSubmitReq *pMsg;
|
SPackedData msg2;
|
||||||
SSubmitBlk *pBlock;
|
|
||||||
SSubmitMsgIter msgIter;
|
int8_t setMsg;
|
||||||
SSubmitBlkIter blkIter;
|
SSubmitReq2 submit;
|
||||||
|
int32_t nextBlk;
|
||||||
|
|
||||||
|
int64_t lastBlkUid;
|
||||||
|
|
||||||
SWalReader *pWalReader;
|
SWalReader *pWalReader;
|
||||||
|
|
||||||
|
|
@ -251,11 +259,14 @@ int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
|
||||||
int32_t tqSeekVer(STqReader *pReader, int64_t ver);
|
int32_t tqSeekVer(STqReader *pReader, int64_t ver);
|
||||||
int32_t tqNextBlock(STqReader *pReader, SFetchRet *ret);
|
int32_t tqNextBlock(STqReader *pReader, SFetchRet *ret);
|
||||||
|
|
||||||
int32_t tqReaderSetDataMsg(STqReader *pReader, const SSubmitReq *pMsg, int64_t ver);
|
int32_t tqReaderSetSubmitReq2(STqReader *pReader, void *msgStr, int32_t msgLen, int64_t ver);
|
||||||
bool tqNextDataBlock(STqReader *pReader);
|
// int32_t tqReaderSetDataMsg(STqReader *pReader, const SSubmitReq *pMsg, int64_t ver);
|
||||||
bool tqNextDataBlockFilterOut(STqReader *pReader, SHashObj *filterOutUids);
|
bool tqNextDataBlock2(STqReader *pReader);
|
||||||
int32_t tqRetrieveDataBlock(SSDataBlock *pBlock, STqReader *pReader);
|
bool tqNextDataBlockFilterOut2(STqReader *pReader, SHashObj *filterOutUids);
|
||||||
int32_t tqRetrieveTaosxBlock(STqReader *pReader, SArray *blocks, SArray *schemas);
|
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);
|
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);
|
int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum);
|
||||||
|
|
||||||
// tqExec
|
// 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 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 tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp);
|
||||||
int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry);
|
int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry);
|
||||||
|
|
@ -182,7 +183,8 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore);
|
||||||
|
|
||||||
// tqSink
|
// tqSink
|
||||||
// void tqSinkToTableMerge(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
// 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
|
// tqOffset
|
||||||
char* tqOffsetBuildFName(const char* path, int32_t fVer);
|
char* tqOffsetBuildFName(const char* path, int32_t fVer);
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,9 @@ typedef struct SDiskData SDiskData;
|
||||||
typedef struct SDiskDataBuilder SDiskDataBuilder;
|
typedef struct SDiskDataBuilder SDiskDataBuilder;
|
||||||
typedef struct SBlkInfo SBlkInfo;
|
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_FILE_DLMT ((uint32_t)0xF00AFA0F)
|
||||||
#define TSDB_MAX_SUBBLOCKS 8
|
#define TSDB_MAX_SUBBLOCKS 8
|
||||||
#define TSDB_FHDR_SIZE 512
|
#define TSDB_FHDR_SIZE 512
|
||||||
|
|
@ -102,26 +105,29 @@ static FORCE_INLINE int64_t tsdbLogicToFileSize(int64_t lSize, int32_t szPage) {
|
||||||
|
|
||||||
// tsdbUtil.c ==============================================================================================
|
// tsdbUtil.c ==============================================================================================
|
||||||
// TSDBROW
|
// TSDBROW
|
||||||
#define TSDBROW_TS(ROW) (((ROW)->type == 0) ? (ROW)->pTSRow->ts : (ROW)->pBlockData->aTSKEY[(ROW)->iRow])
|
#define TSDBROW_TS(ROW) (((ROW)->type == TSDBROW_ROW_FMT) ? (ROW)->pTSRow->ts : (ROW)->pBlockData->aTSKEY[(ROW)->iRow])
|
||||||
#define TSDBROW_VERSION(ROW) (((ROW)->type == 0) ? (ROW)->version : (ROW)->pBlockData->aVersion[(ROW)->iRow])
|
#define TSDBROW_VERSION(ROW) \
|
||||||
#define TSDBROW_SVERSION(ROW) TD_ROW_SVER((ROW)->pTSRow)
|
(((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 TSDBROW_KEY(ROW) ((TSDBKEY){.version = TSDBROW_VERSION(ROW), .ts = TSDBROW_TS(ROW)})
|
||||||
#define tsdbRowFromTSRow(VERSION, TSROW) ((TSDBROW){.type = 0, .version = (VERSION), .pTSRow = (TSROW)})
|
#define tsdbRowFromTSRow(VERSION, TSROW) ((TSDBROW){.type = TSDBROW_ROW_FMT, .version = (VERSION), .pTSRow = (TSROW)})
|
||||||
#define tsdbRowFromBlockData(BLOCKDATA, IROW) ((TSDBROW){.type = 1, .pBlockData = (BLOCKDATA), .iRow = (IROW)})
|
#define tsdbRowFromBlockData(BLOCKDATA, IROW) \
|
||||||
|
((TSDBROW){.type = TSDBROW_COL_FMT, .pBlockData = (BLOCKDATA), .iRow = (IROW)})
|
||||||
|
|
||||||
void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
|
||||||
// int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow);
|
|
||||||
int32_t tsdbRowCmprFn(const void *p1, const void *p2);
|
int32_t tsdbRowCmprFn(const void *p1, const void *p2);
|
||||||
// STSDBRowIter
|
// 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);
|
SColVal *tsdbRowIterNext(STSDBRowIter *pIter);
|
||||||
// SRowMerger
|
// 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 tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||||
|
|
||||||
int32_t tRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||||
void tRowMergerClear(SRowMerger *pMerger);
|
void tsdbRowMergerClear(SRowMerger *pMerger);
|
||||||
int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
|
int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
|
||||||
int32_t tRowMergerGetRow(SRowMerger *pMerger, STSRow **ppRow);
|
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow);
|
||||||
// TABLEID
|
// TABLEID
|
||||||
int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
|
int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
|
||||||
// TSDBKEY
|
// TSDBKEY
|
||||||
|
|
@ -150,17 +156,15 @@ int32_t tCmprBlockL(void const *lhs, void const *rhs);
|
||||||
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
|
#define tBlockDataLastRow(PBLOCKDATA) tsdbRowFromBlockData(PBLOCKDATA, (PBLOCKDATA)->nRow - 1)
|
||||||
#define tBlockDataFirstKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataFirstRow(PBLOCKDATA))
|
#define tBlockDataFirstKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataFirstRow(PBLOCKDATA))
|
||||||
#define tBlockDataLastKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataLastRow(PBLOCKDATA))
|
#define tBlockDataLastKey(PBLOCKDATA) TSDBROW_KEY(&tBlockDataLastRow(PBLOCKDATA))
|
||||||
|
#define tBlockDataGetColDataByIdx(PBLOCKDATA, IDX) (&(PBLOCKDATA)->aColData[IDX])
|
||||||
|
|
||||||
int32_t tBlockDataCreate(SBlockData *pBlockData);
|
int32_t tBlockDataCreate(SBlockData *pBlockData);
|
||||||
void tBlockDataDestroy(SBlockData *pBlockData, int8_t deepClear);
|
void tBlockDataDestroy(SBlockData *pBlockData);
|
||||||
int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, int16_t *aCid, int32_t nCid);
|
int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, int16_t *aCid, int32_t nCid);
|
||||||
void tBlockDataReset(SBlockData *pBlockData);
|
void tBlockDataReset(SBlockData *pBlockData);
|
||||||
int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid);
|
int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid);
|
||||||
void tBlockDataClear(SBlockData *pBlockData);
|
void tBlockDataClear(SBlockData *pBlockData);
|
||||||
SColData *tBlockDataGetColDataByIdx(SBlockData *pBlockData, int32_t idx);
|
|
||||||
void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData);
|
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 tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut, int32_t *szOut, uint8_t *aBuf[],
|
||||||
int32_t aBufN[]);
|
int32_t aBufN[]);
|
||||||
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]);
|
int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]);
|
||||||
|
|
@ -335,10 +339,13 @@ struct SVersionRange {
|
||||||
typedef struct SMemSkipListNode SMemSkipListNode;
|
typedef struct SMemSkipListNode SMemSkipListNode;
|
||||||
struct SMemSkipListNode {
|
struct SMemSkipListNode {
|
||||||
int8_t level;
|
int8_t level;
|
||||||
|
int8_t flag; // TSDBROW_ROW_FMT for row format, TSDBROW_COL_FMT for col format
|
||||||
|
int32_t iRow;
|
||||||
int64_t version;
|
int64_t version;
|
||||||
STSRow *pTSRow;
|
void *pData;
|
||||||
SMemSkipListNode *forwards[0];
|
SMemSkipListNode *forwards[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SMemSkipList {
|
typedef struct SMemSkipList {
|
||||||
int64_t size;
|
int64_t size;
|
||||||
uint32_t seed;
|
uint32_t seed;
|
||||||
|
|
@ -376,11 +383,11 @@ struct SMemTable {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TSDBROW {
|
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 {
|
union {
|
||||||
struct {
|
struct {
|
||||||
int64_t version;
|
int64_t version;
|
||||||
STSRow *pTSRow;
|
SRow *pTSRow;
|
||||||
};
|
};
|
||||||
struct {
|
struct {
|
||||||
SBlockData *pBlockData;
|
SBlockData *pBlockData;
|
||||||
|
|
@ -473,7 +480,7 @@ struct SBlockData {
|
||||||
int64_t *aVersion; // versions of each row
|
int64_t *aVersion; // versions of each row
|
||||||
TSKEY *aTSKEY; // timestamp of each row
|
TSKEY *aTSKEY; // timestamp of each row
|
||||||
int32_t nColData;
|
int32_t nColData;
|
||||||
SArray *aColData; // SArray<SColData>
|
SColData *aColData;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TABLEID {
|
struct TABLEID {
|
||||||
|
|
@ -566,9 +573,13 @@ struct SDFileSet {
|
||||||
|
|
||||||
struct STSDBRowIter {
|
struct STSDBRowIter {
|
||||||
TSDBROW *pRow;
|
TSDBROW *pRow;
|
||||||
STSchema *pTSchema;
|
union {
|
||||||
SColVal colVal;
|
SRowIter *pIter;
|
||||||
int32_t i;
|
struct {
|
||||||
|
int32_t iColData;
|
||||||
|
SColVal cv;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
struct SRowMerger {
|
struct SRowMerger {
|
||||||
STSchema *pTSchema;
|
STSchema *pTSchema;
|
||||||
|
|
@ -739,8 +750,8 @@ typedef struct {
|
||||||
|
|
||||||
int32_t tsdbOpenCache(STsdb *pTsdb);
|
int32_t tsdbOpenCache(STsdb *pTsdb);
|
||||||
void tsdbCloseCache(STsdb *pTsdb);
|
void tsdbCloseCache(STsdb *pTsdb);
|
||||||
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 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 tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *pr, LRUHandle **h);
|
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 tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *pr, LRUHandle **h);
|
||||||
int32_t tsdbCacheRelease(SLRUCache *pCache, 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);
|
void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity);
|
||||||
size_t tsdbCacheGetCapacity(SVnode *pVnode);
|
size_t tsdbCacheGetCapacity(SVnode *pVnode);
|
||||||
|
|
||||||
|
// int32_t tsdbCacheLastArray2Row(SArray *pLastArray, STSRow **ppRow, STSchema *pSchema);
|
||||||
|
|
||||||
// ========== inline functions ==========
|
// ========== inline functions ==========
|
||||||
static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
|
static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
|
||||||
TSDBKEY *pKey1 = (TSDBKEY *)p1;
|
TSDBKEY *pKey1 = (TSDBKEY *)p1;
|
||||||
|
|
@ -793,8 +806,13 @@ static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pIter->pRow = &pIter->row;
|
pIter->pRow = &pIter->row;
|
||||||
pIter->pRow->version = pIter->pNode->version;
|
if (pIter->pNode->flag == TSDBROW_ROW_FMT) {
|
||||||
pIter->pRow->pTSRow = pIter->pNode->pTSRow;
|
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;
|
return pIter->pRow;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ typedef struct SCommitInfo SCommitInfo;
|
||||||
#define VND_INFO_FNAME "vnode.json"
|
#define VND_INFO_FNAME "vnode.json"
|
||||||
|
|
||||||
// vnd.h
|
// vnd.h
|
||||||
|
|
||||||
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
|
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
|
||||||
void* vnodeBufPoolMallocAligned(SVBufPool* pPool, int size);
|
void* vnodeBufPoolMallocAligned(SVBufPool* pPool, int size);
|
||||||
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
|
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
|
||||||
|
|
@ -162,10 +163,9 @@ int32_t tsdbCommit(STsdb* pTsdb, SCommitInfo* pInfo);
|
||||||
int32_t tsdbFinishCommit(STsdb* pTsdb);
|
int32_t tsdbFinishCommit(STsdb* pTsdb);
|
||||||
int32_t tsdbRollbackCommit(STsdb* pTsdb);
|
int32_t tsdbRollbackCommit(STsdb* pTsdb);
|
||||||
int32_t tsdbDoRetention(STsdb* pTsdb, int64_t now);
|
int32_t tsdbDoRetention(STsdb* pTsdb, int64_t now);
|
||||||
int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg);
|
int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq2* pMsg);
|
||||||
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp);
|
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq2* pMsg, SSubmitRsp2* pRsp);
|
||||||
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock,
|
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitTbData* pSubmitTbData, int32_t* affectedRows);
|
||||||
SSubmitBlkRsp* pRsp);
|
|
||||||
int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
|
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);
|
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 tqProcessTaskDropReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg);
|
int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg);
|
||||||
int32_t tqProcessStreamTaskCheckRsp(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
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 tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver);
|
||||||
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg);
|
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg);
|
||||||
int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec);
|
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 tqProcessTaskRecoverFinishRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||||
int32_t tqCheckLogInWal(STQ* pTq, int64_t version);
|
int32_t tqCheckLogInWal(STQ* pTq, int64_t version);
|
||||||
|
|
||||||
SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema,
|
int32_t tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema,
|
||||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||||
SBatchDeleteReq* pDeleteReq);
|
SBatchDeleteReq* pDeleteReq, void** ppData, int32_t* pLen);
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
int32_t smaInit();
|
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 tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg);
|
||||||
|
|
||||||
int32_t tdProcessRSmaCreate(SSma* pSma, SVCreateStbReq* pReq);
|
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 tdProcessRSmaDrop(SSma* pSma, SVDropStbReq* pReq);
|
||||||
int32_t tdFetchTbUidList(SSma* pSma, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
|
int32_t tdFetchTbUidList(SSma* pSma, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
|
||||||
int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore, bool isAdd);
|
int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore, bool isAdd);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags) {
|
||||||
memset(pReader, 0, sizeof(*pReader));
|
memset(pReader, 0, sizeof(*pReader));
|
||||||
pReader->flags = flags;
|
pReader->flags = flags;
|
||||||
pReader->pMeta = pMeta;
|
pReader->pMeta = pMeta;
|
||||||
if (!(flags & META_READER_NOLOCK)) {
|
if (pReader->pMeta && !(flags & META_READER_NOLOCK)) {
|
||||||
metaRLock(pMeta);
|
metaRLock(pMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -239,7 +239,6 @@ int metaGetTableSzNameByUid(void *meta, uint64_t uid, char *tbName) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid) {
|
int metaGetTableUidByName(void *meta, char *tbName, uint64_t *uid) {
|
||||||
int code = 0;
|
int code = 0;
|
||||||
SMetaReader mr = {0};
|
SMetaReader mr = {0};
|
||||||
|
|
@ -612,23 +611,14 @@ tb_uid_t metaStbCursorNext(SMStbCursor *pStbCur) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock) {
|
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock) {
|
||||||
// SMetaReader mr = {0};
|
|
||||||
STSchema *pTSchema = NULL;
|
STSchema *pTSchema = NULL;
|
||||||
SSchemaWrapper *pSW = NULL;
|
SSchemaWrapper *pSW = NULL;
|
||||||
STSchemaBuilder sb = {0};
|
SSchema *pSchema = NULL;
|
||||||
SSchema *pSchema;
|
|
||||||
|
|
||||||
pSW = metaGetTableSchema(pMeta, uid, sver, lock);
|
pSW = metaGetTableSchema(pMeta, uid, sver, lock);
|
||||||
if (!pSW) return NULL;
|
if (!pSW) return NULL;
|
||||||
|
|
||||||
tdInitTSchemaBuilder(&sb, pSW->version);
|
pTSchema = tBuildTSchema(pSW->pSchema, pSW->nCols, 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);
|
|
||||||
|
|
||||||
taosMemoryFree(pSW->pSchema);
|
taosMemoryFree(pSW->pSchema);
|
||||||
taosMemoryFree(pSW);
|
taosMemoryFree(pSW);
|
||||||
|
|
@ -709,21 +699,11 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv
|
||||||
tdbFree(pData);
|
tdbFree(pData);
|
||||||
|
|
||||||
// convert
|
// convert
|
||||||
STSchemaBuilder sb = {0};
|
STSchema *pTSchema = tBuildTSchema(pSchemaWrapper->pSchema, pSchemaWrapper->nCols, pSchemaWrapper->version);
|
||||||
|
|
||||||
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);
|
|
||||||
if (pTSchema == NULL) {
|
if (pTSchema == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
tdDestroyTSchemaBuilder(&sb);
|
|
||||||
|
|
||||||
*ppTSchema = pTSchema;
|
*ppTSchema = pTSchema;
|
||||||
taosMemoryFree(pSchemaWrapper->pSchema);
|
taosMemoryFree(pSchemaWrapper->pSchema);
|
||||||
|
|
||||||
|
|
@ -756,9 +736,7 @@ int64_t metaGetTimeSeriesNum(SMeta *pMeta) {
|
||||||
return pMeta->pVnode->config.vndStats.numOfTimeSeries + pMeta->pVnode->config.vndStats.numOfNTimeSeries;
|
return pMeta->pVnode->config.vndStats.numOfTimeSeries + pMeta->pVnode->config.vndStats.numOfNTimeSeries;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t metaGetNtbNum(SMeta *pMeta) {
|
int64_t metaGetNtbNum(SMeta *pMeta) { return pMeta->pVnode->config.vndStats.numOfNTables; }
|
||||||
return pMeta->pVnode->config.vndStats.numOfNTables;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMeta *pMeta;
|
SMeta *pMeta;
|
||||||
|
|
|
||||||
|
|
@ -565,8 +565,8 @@ static int32_t tdProcessSubmitReq(STsdb *pTsdb, int64_t version, void *pReq) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
SSubmitReq2 *pSubmitReq = (SSubmitReq2 *)pReq;
|
||||||
// TODO: spin lock for race condition
|
// spin lock for race condition during insert data
|
||||||
if (tsdbInsertData(pTsdb, version, pSubmitReq, NULL) < 0) {
|
if (tsdbInsertData(pTsdb, version, pSubmitReq, NULL) < 0) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
@ -574,29 +574,19 @@ static int32_t tdProcessSubmitReq(STsdb *pTsdb, int64_t version, void *pReq) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tdFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) {
|
static int32_t tdFetchSubmitReqSuids(SSubmitReq2 *pMsg, STbUidStore *pStore) {
|
||||||
SSubmitMsgIter msgIter = {0};
|
SArray *pSubmitTbData = pMsg ? pMsg->aSubmitTbData : NULL;
|
||||||
SSubmitBlk *pBlock = NULL;
|
int32_t size = taosArrayGetSize(pSubmitTbData);
|
||||||
SSubmitBlkIter blkIter = {0};
|
|
||||||
STSRow *row = NULL;
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_SUCCESS;
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
if (tInitSubmitMsgIter(pMsg, &msgIter) < 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;
|
return -1;
|
||||||
}
|
}
|
||||||
while (true) {
|
|
||||||
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pBlock) break;
|
|
||||||
tdUidStorePut(pStore, msgIter.suid, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (terrno != TSDB_CODE_SUCCESS) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -676,10 +666,10 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
||||||
output->info.id.groupId, output->info.rows);
|
output->info.id.groupId, output->info.rows);
|
||||||
|
|
||||||
STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb[0] : pSma->pRSmaTsdb[1]);
|
STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb[0] : pSma->pRSmaTsdb[1]);
|
||||||
SSubmitReq *pReq = NULL;
|
SSubmitReq2 *pReq = NULL;
|
||||||
|
|
||||||
// TODO: the schema update should be handled later(TD-17965)
|
// 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
|
smaError("vgId:%d, build submit req for rsma table suid:%" PRIu64 ", uid:%" PRIu64 ", level %" PRIi8
|
||||||
" failed since %s",
|
" failed since %s",
|
||||||
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, terrstr());
|
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, terrstr());
|
||||||
|
|
@ -687,19 +677,21 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReq && tdProcessSubmitReq(sinkTsdb, output->info.version, pReq) < 0) {
|
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
|
smaError("vgId:%d, process submit req for rsma suid:%" PRIu64 ", uid:%" PRIu64 " level %" PRIi8
|
||||||
" failed since %s",
|
" failed since %s",
|
||||||
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, terrstr());
|
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, terrstr());
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
smaDebug("vgId:%d, process submit req for rsma suid:%" PRIu64 ",uid:%" PRIu64 ", level %" PRIi8 " ver %" PRIi64
|
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);
|
||||||
SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, output->info.version,
|
|
||||||
htonl(pReq->header.contLen));
|
|
||||||
|
|
||||||
taosMemoryFreeClear(pReq);
|
if (pReq) {
|
||||||
|
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||||
|
taosMemoryFree(pReq);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -717,22 +709,29 @@ _err:
|
||||||
* @brief Copy msg to rsmaQueueBuffer for batch process
|
* @brief Copy msg to rsmaQueueBuffer for batch process
|
||||||
*
|
*
|
||||||
* @param pSma
|
* @param pSma
|
||||||
|
* @param version
|
||||||
* @param pMsg
|
* @param pMsg
|
||||||
|
* @param len
|
||||||
* @param inputType
|
* @param inputType
|
||||||
* @param pInfo
|
* @param pInfo
|
||||||
* @param suid
|
* @param suid
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
static int32_t tdExecuteRSmaImplAsync(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfo *pInfo,
|
static int32_t tdExecuteRSmaImplAsync(SSma *pSma, int64_t version, const void *pMsg, int32_t len, int32_t inputType,
|
||||||
tb_uid_t suid) {
|
SRSmaInfo *pInfo, tb_uid_t suid) {
|
||||||
const SSubmitReq *pReq = (const SSubmitReq *)pMsg;
|
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) {
|
if (!qItem) {
|
||||||
return TSDB_CODE_FAILED;
|
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);
|
taosWriteQitem(pInfo->queue, qItem);
|
||||||
|
|
||||||
|
|
@ -981,12 +980,14 @@ static FORCE_INLINE void tdReleaseRSmaInfo(SSma *pSma, SRSmaInfo *pInfo) {
|
||||||
* @brief async mode
|
* @brief async mode
|
||||||
*
|
*
|
||||||
* @param pSma
|
* @param pSma
|
||||||
|
* @param version
|
||||||
* @param pMsg
|
* @param pMsg
|
||||||
* @param inputType
|
* @param inputType
|
||||||
* @param suid
|
* @param suid
|
||||||
* @return int32_t
|
* @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);
|
SRSmaInfo *pRSmaInfo = tdAcquireRSmaInfoBySuid(pSma, suid);
|
||||||
if (!pRSmaInfo) {
|
if (!pRSmaInfo) {
|
||||||
smaDebug("vgId:%d, execute rsma, no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid);
|
smaDebug("vgId:%d, execute rsma, no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid);
|
||||||
|
|
@ -994,7 +995,7 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, const void *pMsg, int32_t inputTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputType == STREAM_INPUT__DATA_SUBMIT) {
|
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);
|
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
@ -1016,7 +1017,7 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, const void *pMsg, int32_t inputTyp
|
||||||
return TSDB_CODE_SUCCESS;
|
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);
|
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||||
if (!pEnv) {
|
if (!pEnv) {
|
||||||
// only applicable when rsma env exists
|
// only applicable when rsma env exists
|
||||||
|
|
@ -1026,19 +1027,22 @@ int32_t tdProcessRSmaSubmit(SSma *pSma, void *pMsg, int32_t inputType) {
|
||||||
STbUidStore uidStore = {0};
|
STbUidStore uidStore = {0};
|
||||||
|
|
||||||
if (inputType == STREAM_INPUT__DATA_SUBMIT) {
|
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;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uidStore.suid != 0) {
|
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;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
while ((pIter = taosHashIterate(uidStore.uidHash, pIter))) {
|
while ((pIter = taosHashIterate(uidStore.uidHash, pIter))) {
|
||||||
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
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;
|
goto _err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1048,7 +1052,6 @@ int32_t tdProcessRSmaSubmit(SSma *pSma, void *pMsg, int32_t inputType) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
_err:
|
_err:
|
||||||
tdUidStoreDestory(&uidStore);
|
tdUidStoreDestory(&uidStore);
|
||||||
smaError("vgId:%d, failed to process rsma submit since: %s", SMA_VID(pSma), terrstr());
|
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1403,7 +1406,8 @@ _end:
|
||||||
|
|
||||||
static void tdFreeRSmaSubmitItems(SArray *pItems) {
|
static void tdFreeRSmaSubmitItems(SArray *pItems) {
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pItems); ++i) {
|
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);
|
taosArrayClear(pItems);
|
||||||
}
|
}
|
||||||
|
|
@ -1472,8 +1476,12 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA
|
||||||
void *msg = NULL;
|
void *msg = NULL;
|
||||||
taosGetQitem(qall, (void **)&msg);
|
taosGetQitem(qall, (void **)&msg);
|
||||||
if (msg) {
|
if (msg) {
|
||||||
if (!taosArrayPush(pSubmitArr, &msg)) {
|
SPackedData packData = {.msgLen = *(int32_t *)msg,
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
.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;
|
goto _err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1529,7 +1537,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pSubmitArr =
|
if (!(pSubmitArr =
|
||||||
taosArrayInit(TMIN(RSMA_SUBMIT_BATCH_SIZE, atomic_load_64(&pRSmaStat->nBufItems)), POINTER_BYTES))) {
|
taosArrayInit(TMIN(RSMA_SUBMIT_BATCH_SIZE, atomic_load_64(&pRSmaStat->nBufItems)), sizeof(SPackedData)))) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -217,19 +217,18 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
SBatchDeleteReq deleteReq = {0};
|
SBatchDeleteReq deleteReq = {0};
|
||||||
SSubmitReq *pSubmitReq =
|
void *pSubmitReq = NULL;
|
||||||
tqBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, &pTsmaStat->pTSma->schemaTag, true,
|
int32_t contLen = 0;
|
||||||
pTsmaStat->pTSma->dstTbUid, pTsmaStat->pTSma->dstTbName, &deleteReq);
|
|
||||||
// TODO deleteReq
|
|
||||||
taosArrayDestroy(deleteReq.deleteReqs);
|
|
||||||
|
|
||||||
|
if (tqBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, &pTsmaStat->pTSma->schemaTag, true,
|
||||||
if (!pSubmitReq) {
|
pTsmaStat->pTSma->dstTbUid, pTsmaStat->pTSma->dstTbName, &deleteReq, &pSubmitReq, &contLen) < 0) {
|
||||||
smaError("vgId:%d, failed to gen submit blk while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
|
smaError("vgId:%d, failed to gen submit msg while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
|
||||||
indexUid, tstrerror(terrno));
|
indexUid, tstrerror(terrno));
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO deleteReq
|
||||||
|
taosArrayDestroy(deleteReq.deleteReqs);
|
||||||
#if 0
|
#if 0
|
||||||
if (!strncasecmp("td.tsma.rst.tb", pTsmaStat->pTSma->dstTbName, 14)) {
|
if (!strncasecmp("td.tsma.rst.tb", pTsmaStat->pTSma->dstTbName, 14)) {
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
|
|
@ -242,7 +241,7 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
||||||
SRpcMsg submitReqMsg = {
|
SRpcMsg submitReqMsg = {
|
||||||
.msgType = TDMT_VND_SUBMIT,
|
.msgType = TDMT_VND_SUBMIT,
|
||||||
.pCont = pSubmitReq,
|
.pCont = pSubmitReq,
|
||||||
.contLen = ntohl(pSubmitReq->length),
|
.contLen = ntohl(contLen),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tmsgPutToQueue(&pSma->pVnode->msgCb, WRITE_QUEUE, &submitReqMsg) < 0) {
|
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);
|
req.epoch, TD_VID(pTq->pVnode), fetchVer, pHead->msgType);
|
||||||
|
|
||||||
if (pHead->msgType == TDMT_VND_SUBMIT) {
|
if (pHead->msgType == TDMT_VND_SUBMIT) {
|
||||||
SSubmitReq* pCont = (SSubmitReq*)&pHead->body;
|
SPackedData submit = {
|
||||||
|
.msgStr = POINTER_SHIFT(pHead->body, sizeof(SMsgHead)),
|
||||||
if (tqTaosxScanLog(pTq, pHandle, pCont, &taosxRsp) < 0) {
|
.msgLen = pHead->bodyLen - sizeof(SMsgHead),
|
||||||
|
.ver = pHead->version,
|
||||||
|
};
|
||||||
|
if (tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp) < 0) {
|
||||||
}
|
}
|
||||||
if (taosxRsp.blockNum > 0 /* threshold */) {
|
if (taosxRsp.blockNum > 0 /* threshold */) {
|
||||||
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
|
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));
|
STqHandle* pHandle = taosHashGet(pTq->pHandle, pReq->subKey, strlen(pReq->subKey));
|
||||||
if (pHandle) {
|
if (pHandle) {
|
||||||
|
// walCloseRef(pHandle->pWalReader->pWal, pHandle->pRef->refId);
|
||||||
if (pHandle->pRef) {
|
if (pHandle->pRef) {
|
||||||
walCloseRef(pTq->pVnode->pWal, pHandle->pRef->refId);
|
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;
|
pTask->smaSink.smaSink = smaHandleRes;
|
||||||
} else if (pTask->outputType == TASK_OUTPUT__TABLE) {
|
} else if (pTask->outputType == TASK_OUTPUT__TABLE) {
|
||||||
pTask->tbSink.vnode = pTq->pVnode;
|
pTask->tbSink.vnode = pTq->pVnode;
|
||||||
pTask->tbSink.tbSinkFunc = tqSinkToTablePipeline;
|
pTask->tbSink.tbSinkFunc = tqSinkToTablePipeline2;
|
||||||
|
|
||||||
/*A(pTask->tbSink.pSchemaWrapper);*/
|
/*A(pTask->tbSink.pSchemaWrapper);*/
|
||||||
/*A(pTask->tbSink.pSchemaWrapper->pSchema);*/
|
/*A(pTask->tbSink.pSchemaWrapper->pSchema);*/
|
||||||
|
|
||||||
pTask->tbSink.pTSchema =
|
pTask->tbSink.pTSchema =
|
||||||
tdGetSTSChemaFromSSChema(pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols, 1);
|
tBuildTSchema(pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols, 1);
|
||||||
/*A(pTask->tbSink.pTSchema);*/
|
ASSERT(pTask->tbSink.pTSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
streamSetupTrigger(pTask);
|
streamSetupTrigger(pTask);
|
||||||
|
|
@ -1334,12 +1338,12 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
||||||
void* pIter = NULL;
|
void* pIter = NULL;
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
SStreamDataSubmit* pSubmit = NULL;
|
SStreamDataSubmit2* pSubmit = NULL;
|
||||||
|
|
||||||
pSubmit = streamDataSubmitNew(pReq);
|
pSubmit = streamDataSubmitNew(submit);
|
||||||
if (pSubmit == NULL) {
|
if (pSubmit == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tqError("failed to create data submit for stream since out of memory");
|
tqError("failed to create data submit for stream since out of memory");
|
||||||
|
|
@ -1356,7 +1360,7 @@ int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
||||||
continue;
|
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 (!failed) {
|
||||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) {
|
if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) {
|
||||||
|
|
|
||||||
|
|
@ -113,14 +113,8 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRsp->withTbName) {
|
ASSERT(pRsp->withTbName == false);
|
||||||
if (pRsp->rspOffset.type == TMQ_OFFSET__LOG) {
|
ASSERT(pRsp->withSchema == false);
|
||||||
int64_t uid = pExec->pExecReader->msgIter.uid;
|
|
||||||
tqAddTbNameToRsp(pTq, uid, pRsp, 1);
|
|
||||||
} else {
|
|
||||||
pRsp->withTbName = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -157,9 +151,8 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
||||||
|
|
||||||
if (pDataBlock != NULL) {
|
if (pDataBlock != NULL) {
|
||||||
if (pRsp->withTbName) {
|
if (pRsp->withTbName) {
|
||||||
int64_t uid = 0;
|
|
||||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
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) {
|
if (tqAddTbNameToRsp(pTq, uid, (SMqDataRsp*)pRsp, 1) < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -229,7 +222,7 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
||||||
return 0;
|
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;
|
STqExecHandle* pExec = &pHandle->execHandle;
|
||||||
/*A(pExec->subType != TOPIC_SUB_TYPE__COLUMN);*/
|
/*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) {
|
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
STqReader* pReader = pExec->pExecReader;
|
STqReader* pReader = pExec->pExecReader;
|
||||||
tqReaderSetDataMsg(pReader, pReq, 0);
|
/*tqReaderSetDataMsg(pReader, pReq, 0);*/
|
||||||
while (tqNextDataBlock(pReader)) {
|
tqReaderSetSubmitReq2(pReader, submit.msgStr, submit.msgLen, submit.ver);
|
||||||
|
while (tqNextDataBlock2(pReader)) {
|
||||||
/*SSDataBlock block = {0};*/
|
/*SSDataBlock block = {0};*/
|
||||||
/*if (tqRetrieveDataBlock(&block, pReader) < 0) {*/
|
/*if (tqRetrieveDataBlock(&block, pReader) < 0) {*/
|
||||||
/*if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;*/
|
/*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(pBlocks);
|
||||||
taosArrayClear(pSchemas);
|
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 (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
|
||||||
}
|
}
|
||||||
if (pRsp->withTbName) {
|
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) {
|
if (tqAddTbNameToRsp(pTq, uid, (SMqDataRsp*)pRsp, taosArrayGetSize(pBlocks)) < 0) {
|
||||||
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
|
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
|
||||||
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
|
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
|
||||||
|
|
@ -261,7 +256,9 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pHandle->fetchMeta) {
|
if (pHandle->fetchMeta) {
|
||||||
|
#if 0
|
||||||
SSubmitBlk* pBlk = pReader->pBlock;
|
SSubmitBlk* pBlk = pReader->pBlock;
|
||||||
|
int64_t uid = pExec->pExecReader->lastBlkUid;
|
||||||
int32_t schemaLen = htonl(pBlk->schemaLen);
|
int32_t schemaLen = htonl(pBlk->schemaLen);
|
||||||
if (schemaLen > 0) {
|
if (schemaLen > 0) {
|
||||||
if (pRsp->createTableNum == 0) {
|
if (pRsp->createTableNum == 0) {
|
||||||
|
|
@ -274,6 +271,7 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
||||||
taosArrayPush(pRsp->createTableReq, &createReq);
|
taosArrayPush(pRsp->createTableReq, &createReq);
|
||||||
pRsp->createTableNum++;
|
pRsp->createTableNum++;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pBlocks); i++) {
|
for (int32_t i = 0; i < taosArrayGetSize(pBlocks); i++) {
|
||||||
SSDataBlock* pBlock = taosArrayGet(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) {
|
} else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
|
||||||
STqReader* pReader = pExec->pExecReader;
|
STqReader* pReader = pExec->pExecReader;
|
||||||
tqReaderSetDataMsg(pReader, pReq, 0);
|
/*tqReaderSetDataMsg(pReader, pReq, 0);*/
|
||||||
while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
|
tqReaderSetSubmitReq2(pReader, submit.msgStr, submit.msgLen, submit.ver);
|
||||||
|
while (tqNextDataBlockFilterOut2(pReader, pExec->execDb.pFilterOutTbUid)) {
|
||||||
/*SSDataBlock block = {0};*/
|
/*SSDataBlock block = {0};*/
|
||||||
/*if (tqRetrieveDataBlock(&block, pReader) < 0) {*/
|
/*if (tqRetrieveDataBlock(&block, pReader) < 0) {*/
|
||||||
/*if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;*/
|
/*if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;*/
|
||||||
/*}*/
|
/*}*/
|
||||||
taosArrayClear(pBlocks);
|
taosArrayClear(pBlocks);
|
||||||
taosArrayClear(pSchemas);
|
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 (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
|
||||||
}
|
}
|
||||||
if (pRsp->withTbName) {
|
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) {
|
if (tqAddTbNameToRsp(pTq, uid, (SMqDataRsp*)pRsp, taosArrayGetSize(pBlocks)) < 0) {
|
||||||
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
|
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
|
||||||
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
|
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
|
||||||
|
|
@ -309,6 +308,7 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pHandle->fetchMeta) {
|
if (pHandle->fetchMeta) {
|
||||||
|
#if 0
|
||||||
SSubmitBlk* pBlk = pReader->pBlock;
|
SSubmitBlk* pBlk = pReader->pBlock;
|
||||||
int32_t schemaLen = htonl(pBlk->schemaLen);
|
int32_t schemaLen = htonl(pBlk->schemaLen);
|
||||||
if (schemaLen > 0) {
|
if (schemaLen > 0) {
|
||||||
|
|
@ -322,6 +322,7 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
|
||||||
taosArrayPush(pRsp->createTableReq, &createReq);
|
taosArrayPush(pRsp->createTableReq, &createReq);
|
||||||
pRsp->createTableNum++;
|
pRsp->createTableNum++;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
/*tqAddBlockDataToRsp(&block, (SMqDataRsp*)pRsp, taosArrayGetSize(block.pDataBlock),*/
|
/*tqAddBlockDataToRsp(&block, (SMqDataRsp*)pRsp, taosArrayGetSize(block.pDataBlock),*/
|
||||||
/*pTq->pVnode->config.tsdbCfg.precision);*/
|
/*pTq->pVnode->config.tsdbCfg.precision);*/
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,11 @@ int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) {
|
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) {
|
if (msgType == TDMT_VND_SUBMIT) {
|
||||||
// lock push mgr to avoid potential msg lost
|
// 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) {
|
if (taosHashGetSize(pTq->pPushMgr) != 0) {
|
||||||
SArray* cachedKeys = taosArrayInit(0, sizeof(void*));
|
SArray* cachedKeys = taosArrayInit(0, sizeof(void*));
|
||||||
SArray* cachedKeyLens = taosArrayInit(0, sizeof(size_t));
|
SArray* cachedKeyLens = taosArrayInit(0, sizeof(size_t));
|
||||||
void* data = taosMemoryMalloc(msgLen);
|
void* data = taosMemoryMalloc(len);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tqError("failed to copy data for stream since 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);
|
taosArrayDestroy(cachedKeyLens);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(data, msg, msgLen);
|
memcpy(data, pReq, len);
|
||||||
SSubmitReq* pReq = (SSubmitReq*)data;
|
|
||||||
pReq->version = ver;
|
|
||||||
|
|
||||||
void* pIter = NULL;
|
void* pIter = NULL;
|
||||||
while (1) {
|
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;
|
SMqDataRsp* pRsp = &pPushEntry->dataRsp;
|
||||||
|
|
||||||
// prepare scan mem data
|
// prepare scan mem data
|
||||||
qStreamScanMemData(task, pReq);
|
SPackedData submit = {
|
||||||
|
.msgStr = data,
|
||||||
|
.msgLen = len,
|
||||||
|
.ver = ver,
|
||||||
|
};
|
||||||
|
qStreamSetScanMemData(task, submit);
|
||||||
|
|
||||||
// exec
|
// exec
|
||||||
while (1) {
|
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 (vnodeIsRoleLeader(pTq->pVnode)) {
|
||||||
if (taosHashGetSize(pTq->pStreamMeta->pTasks) == 0) return 0;
|
if (taosHashGetSize(pTq->pStreamMeta->pTasks) == 0) return 0;
|
||||||
if (msgType == TDMT_VND_SUBMIT) {
|
if (msgType == TDMT_VND_SUBMIT) {
|
||||||
void* data = taosMemoryMalloc(msgLen);
|
void* data = taosMemoryMalloc(len);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tqError("failed to copy data for stream since out of memory");
|
tqError("failed to copy data for stream since out of memory");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(data, msg, msgLen);
|
memcpy(data, pReq, len);
|
||||||
SSubmitReq* pReq = (SSubmitReq*)data;
|
SPackedData submit = {
|
||||||
pReq->version = ver;
|
.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) {
|
if (msgType == TDMT_VND_DELETE) {
|
||||||
tqProcessDelReq(pTq, POINTER_SHIFT(msg, sizeof(SMsgHead)), msgLen - sizeof(SMsgHead), ver);
|
tqProcessDelReq(pTq, POINTER_SHIFT(msg, sizeof(SMsgHead)), msgLen - sizeof(SMsgHead), ver);
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ END:
|
||||||
}
|
}
|
||||||
|
|
||||||
STqReader* tqOpenReader(SVnode* pVnode) {
|
STqReader* tqOpenReader(SVnode* pVnode) {
|
||||||
STqReader* pReader = taosMemoryMalloc(sizeof(STqReader));
|
STqReader* pReader = taosMemoryCalloc(1, sizeof(STqReader));
|
||||||
if (pReader == NULL) {
|
if (pReader == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -259,7 +259,7 @@ STqReader* tqOpenReader(SVnode* pVnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pReader->pVnodeMeta = pVnode->pMeta;
|
pReader->pVnodeMeta = pVnode->pMeta;
|
||||||
pReader->pMsg = NULL;
|
/*pReader->pMsg = NULL;*/
|
||||||
pReader->ver = -1;
|
pReader->ver = -1;
|
||||||
pReader->pColIdList = NULL;
|
pReader->pColIdList = NULL;
|
||||||
pReader->cachedSchemaVer = 0;
|
pReader->cachedSchemaVer = 0;
|
||||||
|
|
@ -298,7 +298,7 @@ int32_t tqSeekVer(STqReader* pReader, int64_t ver) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
||||||
bool fromProcessedMsg = pReader->pMsg != NULL;
|
bool fromProcessedMsg = pReader->msg2.msgStr != NULL;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!fromProcessedMsg) {
|
if (!fromProcessedMsg) {
|
||||||
|
|
@ -311,7 +311,9 @@ int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
||||||
tqDebug("return offset %" PRId64 ", no more valid", ret->offset.version);
|
tqDebug("return offset %" PRId64 ", no more valid", ret->offset.version);
|
||||||
return -1;
|
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 0
|
||||||
if (pReader->pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
|
if (pReader->pWalReader->pHead->head.msgType != TDMT_VND_SUBMIT) {
|
||||||
// TODO do filter
|
// TODO do filter
|
||||||
|
|
@ -320,16 +322,17 @@ int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
tqReaderSetDataMsg(pReader, body, pReader->pWalReader->pHead->head.version);
|
tqReaderSetSubmitReq2(pReader, body, bodyLen, ver);
|
||||||
|
/*tqReaderSetDataMsg(pReader, body, pReader->pWalReader->pHead->head.version);*/
|
||||||
#if 0
|
#if 0
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
while (tqNextDataBlock(pReader)) {
|
while (tqNextDataBlock2(pReader)) {
|
||||||
// TODO mem free
|
// TODO mem free
|
||||||
memset(&ret->data, 0, sizeof(SSDataBlock));
|
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) {
|
if (code != 0 || ret->data.info.rows == 0) {
|
||||||
continue;
|
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) {
|
int32_t tqReaderSetDataMsg(STqReader* pReader, const SSubmitReq* pMsg, int64_t ver) {
|
||||||
pReader->pMsg = pMsg;
|
pReader->pMsg = pMsg;
|
||||||
|
|
||||||
|
|
@ -362,7 +366,33 @@ int32_t tqReaderSetDataMsg(STqReader* pReader, const SSubmitReq* pMsg, int64_t v
|
||||||
memset(&pReader->blkIter, 0, sizeof(SSubmitBlkIter));
|
memset(&pReader->blkIter, 0, sizeof(SSubmitBlkIter));
|
||||||
return 0;
|
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) {
|
bool tqNextDataBlock(STqReader* pReader) {
|
||||||
if (pReader->pMsg == NULL) return false;
|
if (pReader->pMsg == NULL) return false;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
@ -386,6 +416,59 @@ bool tqNextDataBlock(STqReader* pReader) {
|
||||||
}
|
}
|
||||||
return false;
|
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 tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrapper* pSrc, char* mask) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
|
@ -416,6 +499,7 @@ int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrap
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
bool tqNextDataBlockFilterOut(STqReader* pHandle, SHashObj* filterOutUids) {
|
bool tqNextDataBlockFilterOut(STqReader* pHandle, SHashObj* filterOutUids) {
|
||||||
while (1) {
|
while (1) {
|
||||||
if (tGetSubmitMsgNext(&pHandle->msgIter, &pHandle->pBlock) < 0) {
|
if (tGetSubmitMsgNext(&pHandle->msgIter, &pHandle->pBlock) < 0) {
|
||||||
|
|
@ -431,6 +515,253 @@ bool tqNextDataBlockFilterOut(STqReader* pHandle, SHashObj* filterOutUids) {
|
||||||
return false;
|
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) {
|
int32_t tqRetrieveDataBlock(SSDataBlock* pBlock, STqReader* pReader) {
|
||||||
// TODO: cache multiple schema
|
// TODO: cache multiple schema
|
||||||
int32_t sversion = htonl(pReader->pBlock->sversion);
|
int32_t sversion = htonl(pReader->pBlock->sversion);
|
||||||
|
|
@ -673,6 +1004,18 @@ FAIL:
|
||||||
taosMemoryFree(assigned);
|
taosMemoryFree(assigned);
|
||||||
return -1;
|
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; }
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pTSchema,
|
SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pTSchema,
|
||||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||||
SBatchDeleteReq* pDeleteReq) {
|
SBatchDeleteReq* pDeleteReq) {
|
||||||
|
|
@ -251,8 +252,6 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
|
||||||
|
|
||||||
int32_t rows = pDataBlock->info.rows;
|
int32_t rows = pDataBlock->info.rows;
|
||||||
|
|
||||||
tqDebug("tq sink, convert block1 %d, rows: %d", i, rows);
|
|
||||||
|
|
||||||
int32_t dataLen = 0;
|
int32_t dataLen = 0;
|
||||||
int32_t schemaLen = 0;
|
int32_t schemaLen = 0;
|
||||||
void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
||||||
|
|
@ -298,6 +297,201 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
|
||||||
|
|
||||||
return ret;
|
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) {
|
void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
||||||
const SArray* pBlocks = (const SArray*)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->uid = 0;
|
||||||
blkHead->schemaLen = 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;
|
int32_t dataLen = 0;
|
||||||
void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
||||||
|
|
@ -521,7 +715,7 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d
|
||||||
} else {
|
} else {
|
||||||
void* colData = colDataGetData(pColData, j);
|
void* colData = colDataGetData(pColData, j);
|
||||||
if (k == 0) {
|
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);
|
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);
|
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
|
#if 0
|
||||||
void tqSinkToTableMerge(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
void tqSinkToTableMerge(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
||||||
const SArray* pRes = (const SArray*)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) {
|
if (invalidate) {
|
||||||
taosLRUCacheRelease(pCache, h, true);
|
taosLRUCacheErase(pCache, key, keyLen);
|
||||||
} else {
|
|
||||||
taosLRUCacheRelease(pCache, h, false);
|
|
||||||
}
|
}
|
||||||
// void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
@ -124,12 +122,10 @@ int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosLRUCacheRelease(pCache, h, invalidate);
|
||||||
if (invalidate) {
|
if (invalidate) {
|
||||||
taosLRUCacheRelease(pCache, h, true);
|
taosLRUCacheErase(pCache, key, keyLen);
|
||||||
} else {
|
|
||||||
taosLRUCacheRelease(pCache, h, false);
|
|
||||||
}
|
}
|
||||||
// void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
@ -190,7 +186,7 @@ int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) {
|
||||||
return code;
|
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;
|
int32_t code = 0;
|
||||||
STSRow *cacheRow = NULL;
|
STSRow *cacheRow = NULL;
|
||||||
char key[32] = {0};
|
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);
|
LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||||
if (h) {
|
if (h) {
|
||||||
STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1);
|
STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1);
|
||||||
TSKEY keyTs = row->ts;
|
TSKEY keyTs = TSDBROW_TS(row);
|
||||||
bool invalidate = false;
|
bool invalidate = false;
|
||||||
|
|
||||||
SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h);
|
SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h);
|
||||||
int16_t nCol = taosArrayGetSize(pLast);
|
int16_t nCol = taosArrayGetSize(pLast);
|
||||||
int16_t iCol = 0;
|
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);
|
SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol);
|
||||||
if (keyTs > tTsVal->ts) {
|
if (keyTs > tTsVal->ts) {
|
||||||
STColumn *pTColumn = &pTSchema->columns[0];
|
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 *tColVal = &tTsVal1->colVal;
|
||||||
|
|
||||||
SColVal colVal = {0};
|
SColVal colVal = {0};
|
||||||
tTSRowGetVal(row, pTSchema, iCol, &colVal);
|
tsdbRowGetColVal(row, pTSchema, iCol, &colVal);
|
||||||
if (!COL_VAL_IS_NONE(&colVal)) {
|
if (!COL_VAL_IS_NONE(&colVal)) {
|
||||||
if (keyTs == tTsVal1->ts && !COL_VAL_IS_NONE(tColVal)) {
|
if (keyTs == tTsVal1->ts && !COL_VAL_IS_NONE(tColVal)) {
|
||||||
invalidate = true;
|
invalidate = true;
|
||||||
|
|
@ -261,7 +295,7 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST
|
||||||
return code;
|
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;
|
int32_t code = 0;
|
||||||
STSRow *cacheRow = NULL;
|
STSRow *cacheRow = NULL;
|
||||||
char key[32] = {0};
|
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);
|
LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen);
|
||||||
if (h) {
|
if (h) {
|
||||||
STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1);
|
STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1);
|
||||||
TSKEY keyTs = row->ts;
|
TSKEY keyTs = TSDBROW_TS(row);
|
||||||
bool invalidate = false;
|
bool invalidate = false;
|
||||||
|
|
||||||
SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h);
|
SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h);
|
||||||
int16_t nCol = taosArrayGetSize(pLast);
|
int16_t nCol = taosArrayGetSize(pLast);
|
||||||
int16_t iCol = 0;
|
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);
|
SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol);
|
||||||
if (keyTs > tTsVal->ts) {
|
if (keyTs > tTsVal->ts) {
|
||||||
STColumn *pTColumn = &pTSchema->columns[0];
|
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 *tColVal = &tTsVal1->colVal;
|
||||||
|
|
||||||
SColVal colVal = {0};
|
SColVal colVal = {0};
|
||||||
tTSRowGetVal(row, pTSchema, iCol, &colVal);
|
tsdbRowGetColVal(row, pTSchema, iCol, &colVal);
|
||||||
if (COL_VAL_IS_VALUE(&colVal)) {
|
if (COL_VAL_IS_VALUE(&colVal)) {
|
||||||
if (keyTs == tTsVal1->ts && COL_VAL_IS_VALUE(tColVal)) {
|
if (keyTs == tTsVal1->ts && COL_VAL_IS_VALUE(tColVal)) {
|
||||||
invalidate = true;
|
invalidate = true;
|
||||||
|
|
@ -617,7 +689,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
|
||||||
} else {
|
} else {
|
||||||
// tBlockDataDestroy(&state->blockData, 1);
|
// tBlockDataDestroy(&state->blockData, 1);
|
||||||
if (state->pBlockData) {
|
if (state->pBlockData) {
|
||||||
tBlockDataDestroy(state->pBlockData, 1);
|
tBlockDataDestroy(state->pBlockData);
|
||||||
state->pBlockData = NULL;
|
state->pBlockData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -685,7 +757,8 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
|
||||||
tBlockDataReset(state->pBlockData);
|
tBlockDataReset(state->pBlockData);
|
||||||
|
|
||||||
tMapDataGetItemByIdx(&state->blockMap, state->iBlock, &block, tGetDataBlk);
|
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);
|
tBlockDataReset(state->pBlockData);
|
||||||
TABLEID tid = {.suid = state->suid, .uid = state->uid};
|
TABLEID tid = {.suid = state->suid, .uid = state->uid};
|
||||||
code = tBlockDataInit(state->pBlockData, &tid, state->pTSchema, NULL, 0);
|
code = tBlockDataInit(state->pBlockData, &tid, state->pTSchema, NULL, 0);
|
||||||
|
|
@ -739,7 +812,7 @@ _err:
|
||||||
state->aBlockIdx = NULL;
|
state->aBlockIdx = NULL;
|
||||||
}
|
}
|
||||||
if (state->pBlockData) {
|
if (state->pBlockData) {
|
||||||
tBlockDataDestroy(state->pBlockData, 1);
|
tBlockDataDestroy(state->pBlockData);
|
||||||
state->pBlockData = NULL;
|
state->pBlockData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -766,7 +839,7 @@ int32_t clearNextRowFromFS(void *iter) {
|
||||||
}
|
}
|
||||||
if (state->pBlockData) {
|
if (state->pBlockData) {
|
||||||
// tBlockDataDestroy(&state->blockData, 1);
|
// tBlockDataDestroy(&state->blockData, 1);
|
||||||
tBlockDataDestroy(state->pBlockData, 1);
|
tBlockDataDestroy(state->pBlockData);
|
||||||
state->pBlockData = NULL;
|
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
|
// build the result ts row here
|
||||||
*dup = false;
|
*dup = false;
|
||||||
if (taosArrayGetSize(pColArray) != nCol) {
|
// if (taosArrayGetSize(pColArray) != nCol) {
|
||||||
*ppColArray = NULL;
|
//*ppColArray = NULL;
|
||||||
taosArrayDestroy(pColArray);
|
// taosArrayDestroy(pColArray);
|
||||||
} else {
|
//} else {
|
||||||
*ppColArray = pColArray;
|
*ppColArray = pColArray;
|
||||||
}
|
//}
|
||||||
|
|
||||||
nextRowIterClose(&iter);
|
nextRowIterClose(&iter);
|
||||||
// taosMemoryFreeClear(pTSchema);
|
// taosMemoryFreeClear(pTSchema);
|
||||||
|
|
@ -1337,12 +1410,12 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
|
||||||
}
|
}
|
||||||
} while (setNoneCol);
|
} while (setNoneCol);
|
||||||
|
|
||||||
if (taosArrayGetSize(pColArray) <= 0) {
|
// if (taosArrayGetSize(pColArray) <= 0) {
|
||||||
*ppLastArray = NULL;
|
//*ppLastArray = NULL;
|
||||||
taosArrayDestroy(pColArray);
|
// taosArrayDestroy(pColArray);
|
||||||
} else {
|
//} else {
|
||||||
*ppLastArray = pColArray;
|
*ppLastArray = pColArray;
|
||||||
}
|
//}
|
||||||
|
|
||||||
nextRowIterClose(&iter);
|
nextRowIterClose(&iter);
|
||||||
// taosMemoryFreeClear(pTSchema);
|
// taosMemoryFreeClear(pTSchema);
|
||||||
|
|
@ -1373,8 +1446,8 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *
|
||||||
SArray *pArray = NULL;
|
SArray *pArray = NULL;
|
||||||
bool dup = false; // which is always false for now
|
bool dup = false; // which is always false for now
|
||||||
code = mergeLastRow(uid, pTsdb, &dup, &pArray, pr);
|
code = mergeLastRow(uid, pTsdb, &dup, &pArray, pr);
|
||||||
// if table's empty or error, return code of -1
|
// if table's empty or error, set handle NULL and return
|
||||||
if (code < 0 || pArray == NULL) {
|
if (code < 0 /* || pArray == NULL*/) {
|
||||||
if (!dup && pArray) {
|
if (!dup && pArray) {
|
||||||
taosArrayDestroy(pArray);
|
taosArrayDestroy(pArray);
|
||||||
}
|
}
|
||||||
|
|
@ -1392,13 +1465,8 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *
|
||||||
if (status != TAOS_LRU_STATUS_OK) {
|
if (status != TAOS_LRU_STATUS_OK) {
|
||||||
code = -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// taosThreadMutexUnlock(&pTsdb->lruMutex);
|
|
||||||
|
|
||||||
// h = taosLRUCacheLookup(pCache, key, keyLen);
|
|
||||||
} // else {
|
|
||||||
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*handle = h;
|
*handle = h;
|
||||||
|
|
@ -1422,8 +1490,8 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *pr,
|
||||||
if (!h) {
|
if (!h) {
|
||||||
SArray *pLastArray = NULL;
|
SArray *pLastArray = NULL;
|
||||||
code = mergeLast(uid, pTsdb, &pLastArray, pr);
|
code = mergeLast(uid, pTsdb, &pLastArray, pr);
|
||||||
// if table's empty or error, return code of -1
|
// if table's empty or error, set handle NULL and return
|
||||||
if (code < 0 || pLastArray == NULL) {
|
if (code < 0 /* || pLastArray == NULL*/) {
|
||||||
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
*handle = NULL;
|
*handle = NULL;
|
||||||
|
|
@ -1437,13 +1505,8 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, SCacheRowsReader *pr,
|
||||||
if (status != TAOS_LRU_STATUS_OK) {
|
if (status != TAOS_LRU_STATUS_OK) {
|
||||||
code = -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// taosThreadMutexUnlock(&pTsdb->lruMutex);
|
|
||||||
|
|
||||||
// h = taosLRUCacheLookup(pCache, key, keyLen);
|
|
||||||
} // else {
|
|
||||||
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*handle = h;
|
*handle = h;
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,10 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
||||||
if (h == NULL) {
|
if (h == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (taosArrayGetSize(pRow) <= 0) {
|
||||||
|
tsdbCacheRelease(lruCache, h);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
for (int32_t k = 0; k < pr->numOfCols; ++k) {
|
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) {
|
if (h == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (taosArrayGetSize(pRow) <= 0) {
|
||||||
|
tsdbCacheRelease(lruCache, h);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
saveOneRow(pRow, pResBlock, pr, slotIds, pRes, pr->idstr);
|
saveOneRow(pRow, pResBlock, pr, slotIds, pRes, pr->idstr);
|
||||||
// TODO reset the pRes
|
// TODO reset the pRes
|
||||||
|
|
|
||||||
|
|
@ -913,24 +913,24 @@ static void tsdbCommitDataEnd(SCommitter *pCommitter) {
|
||||||
// reader
|
// reader
|
||||||
taosArrayDestroy(pCommitter->dReader.aBlockIdx);
|
taosArrayDestroy(pCommitter->dReader.aBlockIdx);
|
||||||
tMapDataClear(&pCommitter->dReader.mBlock);
|
tMapDataClear(&pCommitter->dReader.mBlock);
|
||||||
tBlockDataDestroy(&pCommitter->dReader.bData, 1);
|
tBlockDataDestroy(&pCommitter->dReader.bData);
|
||||||
|
|
||||||
// merger
|
// merger
|
||||||
for (int32_t iStt = 0; iStt < TSDB_MAX_STT_TRIGGER; iStt++) {
|
for (int32_t iStt = 0; iStt < TSDB_MAX_STT_TRIGGER; iStt++) {
|
||||||
SDataIter *pIter = &pCommitter->aDataIter[iStt];
|
SDataIter *pIter = &pCommitter->aDataIter[iStt];
|
||||||
taosArrayDestroy(pIter->aSttBlk);
|
taosArrayDestroy(pIter->aSttBlk);
|
||||||
tBlockDataDestroy(&pIter->bData, 1);
|
tBlockDataDestroy(&pIter->bData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// writer
|
// writer
|
||||||
taosArrayDestroy(pCommitter->dWriter.aBlockIdx);
|
taosArrayDestroy(pCommitter->dWriter.aBlockIdx);
|
||||||
taosArrayDestroy(pCommitter->dWriter.aSttBlk);
|
taosArrayDestroy(pCommitter->dWriter.aSttBlk);
|
||||||
tMapDataClear(&pCommitter->dWriter.mBlock);
|
tMapDataClear(&pCommitter->dWriter.mBlock);
|
||||||
tBlockDataDestroy(&pCommitter->dWriter.bData, 1);
|
tBlockDataDestroy(&pCommitter->dWriter.bData);
|
||||||
#if USE_STREAM_COMPRESSION
|
#if USE_STREAM_COMPRESSION
|
||||||
tDiskDataBuilderDestroy(pCommitter->dWriter.pBuilder);
|
tDiskDataBuilderDestroy(pCommitter->dWriter.pBuilder);
|
||||||
#else
|
#else
|
||||||
tBlockDataDestroy(&pCommitter->dWriter.bDatal, 1);
|
tBlockDataDestroy(&pCommitter->dWriter.bDatal);
|
||||||
#endif
|
#endif
|
||||||
tDestroyTSchema(pCommitter->skmTable.pTSchema);
|
tDestroyTSchema(pCommitter->skmTable.pTSchema);
|
||||||
tDestroyTSchema(pCommitter->skmRow.pTSchema);
|
tDestroyTSchema(pCommitter->skmRow.pTSchema);
|
||||||
|
|
@ -1183,7 +1183,6 @@ static int32_t tsdbCommitAheadBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
|
||||||
|
|
||||||
tBlockDataClear(pBlockData);
|
tBlockDataClear(pBlockData);
|
||||||
while (pRowInfo) {
|
while (pRowInfo) {
|
||||||
ASSERT(pRowInfo->row.type == 0);
|
|
||||||
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
|
|
@ -1251,7 +1250,6 @@ static int32_t tsdbCommitMergeBlock(SCommitter *pCommitter, SDataBlk *pDataBlk)
|
||||||
pRow = NULL;
|
pRow = NULL;
|
||||||
}
|
}
|
||||||
} else if (c > 0) {
|
} else if (c > 0) {
|
||||||
ASSERT(pRowInfo->row.type == 0);
|
|
||||||
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
|
|
@ -1493,7 +1491,7 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) {
|
||||||
|
|
||||||
while (pRowInfo) {
|
while (pRowInfo) {
|
||||||
STSchema *pTSchema = NULL;
|
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));
|
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
pTSchema = pCommitter->skmRow.pTSchema;
|
pTSchema = pCommitter->skmRow.pTSchema;
|
||||||
|
|
@ -1536,7 +1534,7 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) {
|
||||||
|
|
||||||
while (pRowInfo) {
|
while (pRowInfo) {
|
||||||
STSchema *pTSchema = NULL;
|
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));
|
code = tsdbCommitterUpdateRowSchema(pCommitter, id.suid, id.uid, TSDBROW_SVERSION(&pRowInfo->row));
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
pTSchema = pCommitter->skmRow.pTSchema;
|
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;
|
if (pBuilder->bi.maxKey < kRow.ts) pBuilder->bi.maxKey = kRow.ts;
|
||||||
|
|
||||||
STSDBRowIter iter = {0};
|
STSDBRowIter iter = {0};
|
||||||
tsdbRowIterInit(&iter, pRow, pTSchema);
|
tsdbRowIterOpen(&iter, pRow, pTSchema);
|
||||||
|
|
||||||
SColVal *pColVal = tsdbRowIterNext(&iter);
|
SColVal *pColVal = tsdbRowIterNext(&iter);
|
||||||
for (int32_t iBuilder = 0; iBuilder < pBuilder->nBuilder; iBuilder++) {
|
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 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 tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData);
|
||||||
static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||||
SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkRsp *pRsp);
|
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 tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
@ -95,14 +97,14 @@ STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t
|
||||||
return pTbData;
|
return pTbData;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock,
|
int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitTbData *pSubmitTbData, int32_t *affectedRows) {
|
||||||
SSubmitBlkRsp *pRsp) {
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SMemTable *pMemTable = pTsdb->mem;
|
SMemTable *pMemTable = pTsdb->mem;
|
||||||
STbData *pTbData = NULL;
|
STbData *pTbData = NULL;
|
||||||
tb_uid_t suid = pMsgIter->suid;
|
tb_uid_t suid = pSubmitTbData->suid;
|
||||||
tb_uid_t uid = pMsgIter->uid;
|
tb_uid_t uid = pSubmitTbData->uid;
|
||||||
|
|
||||||
|
#if 0
|
||||||
SMetaInfo info;
|
SMetaInfo info;
|
||||||
code = metaGetInfo(pTsdb->pVnode->pMeta, uid, &info, NULL);
|
code = metaGetInfo(pTsdb->pVnode->pMeta, uid, &info, NULL);
|
||||||
if (code) {
|
if (code) {
|
||||||
|
|
@ -116,14 +118,15 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgI
|
||||||
if (info.suid) {
|
if (info.suid) {
|
||||||
metaGetInfo(pTsdb->pVnode->pMeta, info.suid, &info, NULL);
|
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),
|
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;
|
code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRsp->sver = info.skmVer;
|
if (pRsp) pRsp->sver = info.skmVer;
|
||||||
|
#endif
|
||||||
|
|
||||||
// create/get STbData to op
|
// create/get STbData to op
|
||||||
code = tsdbGetOrCreateTbData(pMemTable, suid, uid, &pTbData);
|
code = tsdbGetOrCreateTbData(pMemTable, suid, uid, &pTbData);
|
||||||
|
|
@ -132,10 +135,12 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgI
|
||||||
}
|
}
|
||||||
|
|
||||||
// do insert impl
|
// do insert impl
|
||||||
code = tsdbInsertTableDataImpl(pMemTable, pTbData, version, pMsgIter, pBlock, pRsp);
|
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||||
if (code) {
|
code = tsdbInsertColDataToTable(pMemTable, pTbData, version, pSubmitTbData, affectedRows);
|
||||||
goto _err;
|
} else {
|
||||||
|
code = tsdbInsertRowDataToTable(pMemTable, pTbData, version, pSubmitTbData, affectedRows);
|
||||||
}
|
}
|
||||||
|
if (code) goto _err;
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
|
|
@ -242,7 +247,6 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDa
|
||||||
pIter->pTbData = pTbData;
|
pIter->pTbData = pTbData;
|
||||||
pIter->backward = backward;
|
pIter->backward = backward;
|
||||||
pIter->pRow = NULL;
|
pIter->pRow = NULL;
|
||||||
pIter->row.type = 0;
|
|
||||||
if (pFrom == NULL) {
|
if (pFrom == NULL) {
|
||||||
// create from head or tail
|
// create from head or tail
|
||||||
if (backward) {
|
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--) {
|
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
||||||
pn = SL_NODE_BACKWARD(px, iLevel);
|
pn = SL_NODE_BACKWARD(px, iLevel);
|
||||||
while (pn != pTbData->sl.pHead) {
|
while (pn != pTbData->sl.pHead) {
|
||||||
|
if (pn->flag == TSDBROW_ROW_FMT) {
|
||||||
tKey.version = pn->version;
|
tKey.version = pn->version;
|
||||||
tKey.ts = pn->pTSRow->ts;
|
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);
|
int32_t c = tsdbKeyCmprFn(&tKey, pKey);
|
||||||
if (c <= 0) {
|
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--) {
|
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
||||||
pn = SL_NODE_FORWARD(px, iLevel);
|
pn = SL_NODE_FORWARD(px, iLevel);
|
||||||
while (pn != pTbData->sl.pTail) {
|
while (pn != pTbData->sl.pTail) {
|
||||||
|
if (pn->flag == TSDBROW_ROW_FMT) {
|
||||||
tKey.version = pn->version;
|
tKey.version = pn->version;
|
||||||
tKey.ts = pn->pTSRow->ts;
|
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);
|
int32_t c = tsdbKeyCmprFn(&tKey, pKey);
|
||||||
if (c >= 0) {
|
if (c >= 0) {
|
||||||
|
|
@ -468,29 +482,39 @@ static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
|
||||||
|
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListNode **pos, int64_t version,
|
static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListNode **pos, TSDBROW *pRow,
|
||||||
STSRow *pRow, int8_t forward) {
|
int8_t forward) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int8_t level;
|
int8_t level;
|
||||||
SMemSkipListNode *pNode;
|
SMemSkipListNode *pNode;
|
||||||
SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse;
|
SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse;
|
||||||
|
|
||||||
|
ASSERT(pPool != NULL);
|
||||||
|
|
||||||
// node
|
// node
|
||||||
level = tsdbMemSkipListRandLevel(&pTbData->sl);
|
level = tsdbMemSkipListRandLevel(&pTbData->sl);
|
||||||
ASSERT(pPool != NULL);
|
|
||||||
pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level));
|
pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level));
|
||||||
if (pNode == NULL) {
|
if (pNode == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
pNode->level = level;
|
pNode->level = level;
|
||||||
pNode->version = version;
|
pNode->flag = pRow->type;
|
||||||
pNode->pTSRow = vnodeBufPoolMalloc(pPool, pRow->len);
|
|
||||||
if (NULL == pNode->pTSRow) {
|
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;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
memcpy(pNode->pTSRow, pRow, pRow->len);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
for (int8_t iLevel = level - 1; iLevel >= 0; iLevel--) {
|
for (int8_t iLevel = level - 1; iLevel >= 0; iLevel--) {
|
||||||
SMemSkipListNode *pn = pos[iLevel];
|
SMemSkipListNode *pn = pos[iLevel];
|
||||||
|
|
@ -537,69 +561,166 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData, int64_t version,
|
||||||
SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkRsp *pRsp) {
|
SSubmitTbData *pSubmitTbData, int32_t *affectedRows) {
|
||||||
int32_t code = 0;
|
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;
|
|
||||||
|
|
||||||
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
|
ASSERT(aColData[0].cid == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||||
row.pTSRow = tGetSubmitBlkNext(&blkIter);
|
ASSERT(aColData[0].type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||||
if (row.pTSRow == NULL) return code;
|
ASSERT(aColData[0].flag == HAS_VALUE);
|
||||||
|
|
||||||
key.ts = row.pTSRow->ts;
|
// copy and construct block data
|
||||||
nRow++;
|
SBlockData *pBlockData = vnodeBufPoolMalloc(pPool, sizeof(*pBlockData));
|
||||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
|
if (pBlockData == NULL) {
|
||||||
code = tbDataDoPut(pMemTable, pTbData, pos, version, row.pTSRow, 0);
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
if (code) {
|
goto _exit;
|
||||||
goto _err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
pTbData->minKey = TMIN(pTbData->minKey, key.ts);
|
||||||
|
lRow = tRow;
|
||||||
|
|
||||||
pLastRow = row.pTSRow;
|
// remain row
|
||||||
|
++tRow.iRow;
|
||||||
// forward put rest data
|
if (tRow.iRow < pBlockData->nRow) {
|
||||||
row.pTSRow = tGetSubmitBlkNext(&blkIter);
|
|
||||||
if (row.pTSRow) {
|
|
||||||
for (int8_t iLevel = pos[0]->level; iLevel < pTbData->sl.maxLevel; iLevel++) {
|
for (int8_t iLevel = pos[0]->level; iLevel < pTbData->sl.maxLevel; iLevel++) {
|
||||||
pos[iLevel] = SL_NODE_BACKWARD(pos[iLevel], iLevel);
|
pos[iLevel] = SL_NODE_BACKWARD(pos[iLevel], iLevel);
|
||||||
}
|
}
|
||||||
do {
|
|
||||||
key.ts = row.pTSRow->ts;
|
while (tRow.iRow < pBlockData->nRow) {
|
||||||
nRow++;
|
key.ts = pBlockData->aTSKEY[tRow.iRow];
|
||||||
|
|
||||||
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
||||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
||||||
}
|
}
|
||||||
code = tbDataDoPut(pMemTable, pTbData, pos, version, row.pTSRow, 1);
|
|
||||||
if (code) {
|
if ((code = tbDataDoPut(pMemTable, pTbData, pos, &tRow, 1))) goto _exit;
|
||||||
goto _err;
|
lRow = tRow;
|
||||||
|
|
||||||
|
++tRow.iRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
pLastRow = row.pTSRow;
|
|
||||||
|
|
||||||
row.pTSRow = tGetSubmitBlkNext(&blkIter);
|
|
||||||
} while (row.pTSRow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.ts >= pTbData->maxKey) {
|
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) {
|
if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config)) {
|
||||||
tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, pLastRow, true);
|
tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, &lRow, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CACHE_LAST(pMemTable->pTsdb->pVnode->config)) {
|
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
|
// SMemTable
|
||||||
|
|
@ -607,12 +728,9 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
|
||||||
pMemTable->maxKey = TMAX(pMemTable->maxKey, pTbData->maxKey);
|
pMemTable->maxKey = TMAX(pMemTable->maxKey, pTbData->maxKey);
|
||||||
pMemTable->nRow += nRow;
|
pMemTable->nRow += nRow;
|
||||||
|
|
||||||
pRsp->numOfRows = nRow;
|
if (affectedRows) *affectedRows = nRow;
|
||||||
pRsp->affectedRows = nRow;
|
|
||||||
|
|
||||||
return code;
|
_exit:
|
||||||
|
|
||||||
_err:
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,8 @@ void *destroyLastBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo) {
|
||||||
pLoadInfo[i].blockIndex[0] = -1;
|
pLoadInfo[i].blockIndex[0] = -1;
|
||||||
pLoadInfo[i].blockIndex[1] = -1;
|
pLoadInfo[i].blockIndex[1] = -1;
|
||||||
|
|
||||||
tBlockDataDestroy(&pLoadInfo[i].blockData[0], true);
|
tBlockDataDestroy(&pLoadInfo[i].blockData[0]);
|
||||||
tBlockDataDestroy(&pLoadInfo[i].blockData[1], true);
|
tBlockDataDestroy(&pLoadInfo[i].blockData[1]);
|
||||||
|
|
||||||
taosArrayDestroy(pLoadInfo[i].aSttBlk);
|
taosArrayDestroy(pLoadInfo[i].aSttBlk);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -189,8 +189,8 @@ static int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STabl
|
||||||
SRowMerger* pMerger, SVersionRange* pVerRange);
|
SRowMerger* pMerger, SVersionRange* pVerRange);
|
||||||
static int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, SRowMerger* pMerger,
|
static int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, SRowMerger* pMerger,
|
||||||
STsdbReader* pReader);
|
STsdbReader* pReader);
|
||||||
static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow,
|
static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pTSRow,
|
||||||
STableBlockScanInfo* pScanInfo);
|
STableBlockScanInfo* pInfo);
|
||||||
static int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData,
|
static int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData,
|
||||||
int32_t rowIndex);
|
int32_t rowIndex);
|
||||||
static void setComposedBlockFlag(STsdbReader* pReader, bool composed);
|
static void setComposedBlockFlag(STsdbReader* pReader, bool composed);
|
||||||
|
|
@ -198,9 +198,9 @@ static bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY*
|
||||||
SVersionRange* pVerRange);
|
SVersionRange* pVerRange);
|
||||||
|
|
||||||
static int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDelList,
|
static int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDelList,
|
||||||
STSRow** pTSRow, STsdbReader* pReader, bool* freeTSRow);
|
TSDBROW* pTSRow, STsdbReader* pReader, bool* freeTSRow);
|
||||||
static int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo,
|
static int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo,
|
||||||
STsdbReader* pReader, STSRow** pTSRow);
|
STsdbReader* pReader, SRow** pTSRow);
|
||||||
static int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBlockScanInfo, int64_t key,
|
static int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBlockScanInfo, int64_t key,
|
||||||
STsdbReader* pReader);
|
STsdbReader* pReader);
|
||||||
|
|
||||||
|
|
@ -218,7 +218,8 @@ static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBl
|
||||||
|
|
||||||
static bool outOfTimeWindow(int64_t ts, STimeWindow* pWindow) { return (ts > pWindow->ekey) || (ts < pWindow->skey); }
|
static bool outOfTimeWindow(int64_t ts, STimeWindow* pWindow) { return (ts > pWindow->ekey) || (ts < pWindow->skey); }
|
||||||
|
|
||||||
static int32_t setColumnIdSlotList(SBlockLoadSuppInfo* pSupInfo, SColumnInfo* pCols, const int32_t* pSlotIdList, int32_t numOfCols) {
|
static int32_t setColumnIdSlotList(SBlockLoadSuppInfo* pSupInfo, SColumnInfo* pCols, const int32_t* pSlotIdList,
|
||||||
|
int32_t numOfCols) {
|
||||||
pSupInfo->smaValid = true;
|
pSupInfo->smaValid = true;
|
||||||
pSupInfo->numOfCols = numOfCols;
|
pSupInfo->numOfCols = numOfCols;
|
||||||
pSupInfo->colId = taosMemoryMalloc(numOfCols * (sizeof(int16_t) * 2 + POINTER_BYTES));
|
pSupInfo->colId = taosMemoryMalloc(numOfCols * (sizeof(int16_t) * 2 + POINTER_BYTES));
|
||||||
|
|
@ -309,7 +310,8 @@ static void* getPosInBlockInfoBuf(SBlockInfoBuf* pBuf, int32_t index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: speedup the whole processing by preparing the buffer for STableBlockScanInfo in batch model
|
// NOTE: speedup the whole processing by preparing the buffer for STableBlockScanInfo in batch model
|
||||||
static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, const STableKeyInfo* idList, int32_t numOfTables) {
|
static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, const STableKeyInfo* idList,
|
||||||
|
int32_t numOfTables) {
|
||||||
// allocate buffer in order to load data blocks from file
|
// allocate buffer in order to load data blocks from file
|
||||||
// todo use simple hash instead, optimize the memory consumption
|
// todo use simple hash instead, optimize the memory consumption
|
||||||
SHashObj* pTableMap =
|
SHashObj* pTableMap =
|
||||||
|
|
@ -761,7 +763,6 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
|
||||||
numOfTables, pBlockNum->numOfBlocks, numOfQTable, pBlockNum->numOfLastFiles, sizeInDisk / 1000.0, el,
|
numOfTables, pBlockNum->numOfBlocks, numOfQTable, pBlockNum->numOfLastFiles, sizeInDisk / 1000.0, el,
|
||||||
pReader->idStr);
|
pReader->idStr);
|
||||||
|
|
||||||
|
|
||||||
pReader->cost.numOfBlocks += total;
|
pReader->cost.numOfBlocks += total;
|
||||||
pReader->cost.headFileLoadTime += el;
|
pReader->cost.headFileLoadTime += el;
|
||||||
|
|
||||||
|
|
@ -984,8 +985,7 @@ static void copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDB_DATA_TYPE_DOUBLE:
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
case TSDB_DATA_TYPE_BIGINT:
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
case TSDB_DATA_TYPE_UBIGINT:
|
case TSDB_DATA_TYPE_UBIGINT: {
|
||||||
{
|
|
||||||
int32_t mid = dumpedRows >> 1u;
|
int32_t mid = dumpedRows >> 1u;
|
||||||
int64_t* pts = (int64_t*)pColData->pData;
|
int64_t* pts = (int64_t*)pColData->pData;
|
||||||
for (int32_t j = 0; j < mid; ++j) {
|
for (int32_t j = 0; j < mid; ++j) {
|
||||||
|
|
@ -1157,6 +1157,8 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn
|
||||||
setBlockAllDumped(pDumpInfo, ts, pReader->order);
|
setBlockAllDumped(pDumpInfo, ts, pReader->order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pBlockScanInfo->lastKey = pDumpInfo->lastKey;
|
||||||
|
|
||||||
double elapsedTime = (taosGetTimestampUs() - st) / 1000.0;
|
double elapsedTime = (taosGetTimestampUs() - st) / 1000.0;
|
||||||
pReader->cost.blockLoadTime += elapsedTime;
|
pReader->cost.blockLoadTime += elapsedTime;
|
||||||
|
|
||||||
|
|
@ -1741,7 +1743,7 @@ static FORCE_INLINE STSchema* doGetSchemaForTSRow(int32_t sversion, STsdbReader*
|
||||||
static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, TSDBROW* pRow,
|
static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, TSDBROW* pRow,
|
||||||
SIterInfo* pIter, int64_t key, SLastBlockReader* pLastBlockReader) {
|
SIterInfo* pIter, int64_t key, SLastBlockReader* pLastBlockReader) {
|
||||||
SRowMerger merge = {0};
|
SRowMerger merge = {0};
|
||||||
STSRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
SBlockData* pBlockData = &pReader->status.fileBlockData;
|
SBlockData* pBlockData = &pReader->status.fileBlockData;
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
|
|
||||||
|
|
@ -1789,7 +1791,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (pReader->order == TSDB_ORDER_ASC) {
|
if (pReader->order == TSDB_ORDER_ASC) {
|
||||||
if (minKey == key) {
|
if (minKey == key) {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1799,10 +1801,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == tsLast) {
|
if (minKey == tsLast) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
if (init) {
|
if (init) {
|
||||||
tRowMerge(&merge, &fRow1);
|
tsdbRowMerge(&merge, &fRow1);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1812,11 +1814,11 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.ts) {
|
||||||
if (init) {
|
if (init) {
|
||||||
tRowMerge(&merge, pRow);
|
tsdbRowMerge(&merge, pRow);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
int32_t code = tRowMergerInit(&merge, pRow, pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1830,7 +1832,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.ts) {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
int32_t code = tRowMergerInit(&merge, pRow, pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1844,10 +1846,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == tsLast) {
|
if (minKey == tsLast) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
if (init) {
|
if (init) {
|
||||||
tRowMerge(&merge, &fRow1);
|
tsdbRowMerge(&merge, &fRow1);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1857,10 +1859,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
if (minKey == key) {
|
if (minKey == key) {
|
||||||
if (init) {
|
if (init) {
|
||||||
tRowMerge(&merge, &fRow);
|
tsdbRowMerge(&merge, &fRow);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1869,7 +1871,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = tRowMergerGetRow(&merge, &pTSRow);
|
int32_t code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1877,7 +1879,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
||||||
|
|
||||||
taosMemoryFree(pTSRow);
|
taosMemoryFree(pTSRow);
|
||||||
tRowMergerClear(&merge);
|
tsdbRowMergerClear(&merge);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1887,7 +1889,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
int64_t tsLastBlock = getCurrentKeyInLastBlock(pLastBlockReader);
|
int64_t tsLastBlock = getCurrentKeyInLastBlock(pLastBlockReader);
|
||||||
|
|
||||||
STSRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
SRowMerger merge = {0};
|
SRowMerger merge = {0};
|
||||||
TSDBROW fRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
tsdbTrace("fRow ptr:%p, %d, uid:%" PRIu64 ", %s", fRow.pBlockData, fRow.iRow, pLastBlockReader->uid, pReader->idStr);
|
tsdbTrace("fRow ptr:%p, %d, uid:%" PRIu64 ", %s", fRow.pBlockData, fRow.iRow, pLastBlockReader->uid, pReader->idStr);
|
||||||
|
|
@ -1898,16 +1900,16 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
pBlockScanInfo->lastKey = tsLastBlock;
|
pBlockScanInfo->lastKey = tsLastBlock;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
tRowMerge(&merge, &fRow1);
|
tsdbRowMerge(&merge, &fRow1);
|
||||||
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange);
|
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange);
|
||||||
|
|
||||||
code = tRowMergerGetRow(&merge, &pTSRow);
|
code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1915,10 +1917,10 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
||||||
|
|
||||||
taosMemoryFree(pTSRow);
|
taosMemoryFree(pTSRow);
|
||||||
tRowMergerClear(&merge);
|
tsdbRowMergerClear(&merge);
|
||||||
}
|
}
|
||||||
} else { // not merge block data
|
} else { // not merge block data
|
||||||
int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1931,7 +1933,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tRowMergerGetRow(&merge, &pTSRow);
|
code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1939,7 +1941,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
||||||
|
|
||||||
taosMemoryFree(pTSRow);
|
taosMemoryFree(pTSRow);
|
||||||
tRowMergerClear(&merge);
|
tsdbRowMergerClear(&merge);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
@ -1964,10 +1966,10 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
||||||
if (key < ts) { // imem, mem are all empty, file blocks (data blocks and last block) exist
|
if (key < ts) { // imem, mem are all empty, file blocks (data blocks and last block) exist
|
||||||
return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, key, pReader);
|
return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, key, pReader);
|
||||||
} else if (key == ts) {
|
} else if (key == ts) {
|
||||||
STSRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
SRowMerger merge = {0};
|
SRowMerger merge = {0};
|
||||||
|
|
||||||
int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1975,11 +1977,11 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
||||||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||||
|
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
tRowMerge(&merge, &fRow1);
|
tsdbRowMerge(&merge, &fRow1);
|
||||||
|
|
||||||
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, &merge, &pReader->verRange);
|
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, &merge, &pReader->verRange);
|
||||||
|
|
||||||
code = tRowMergerGetRow(&merge, &pTSRow);
|
code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1987,7 +1989,7 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
||||||
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
||||||
|
|
||||||
taosMemoryFree(pTSRow);
|
taosMemoryFree(pTSRow);
|
||||||
tRowMergerClear(&merge);
|
tsdbRowMergerClear(&merge);
|
||||||
return code;
|
return code;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
|
@ -2004,7 +2006,7 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
||||||
static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData,
|
static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData,
|
||||||
SLastBlockReader* pLastBlockReader) {
|
SLastBlockReader* pLastBlockReader) {
|
||||||
SRowMerger merge = {0};
|
SRowMerger merge = {0};
|
||||||
STSRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
SArray* pDelList = pBlockScanInfo->delSkyline;
|
SArray* pDelList = pBlockScanInfo->delSkyline;
|
||||||
|
|
@ -2068,7 +2070,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == key) {
|
if (minKey == key) {
|
||||||
init = true;
|
init = true;
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||||
code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2079,10 +2081,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == tsLast) {
|
if (minKey == tsLast) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
if (init) {
|
if (init) {
|
||||||
tRowMerge(&merge, &fRow1);
|
tsdbRowMerge(&merge, &fRow1);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
code = tRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2093,7 +2095,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
if (minKey == ik.ts) {
|
if (minKey == ik.ts) {
|
||||||
if (init) {
|
if (init) {
|
||||||
tRowMerge(&merge, piRow);
|
tsdbRowMerge(&merge, piRow);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||||
|
|
@ -2101,7 +2103,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tRowMergerInit(&merge, piRow, pSchema);
|
code = tsdbRowMergerInit(&merge, piRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2120,10 +2122,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tRowMerge(&merge, pRow);
|
tsdbRowMerge(&merge, pRow);
|
||||||
} else {
|
} else {
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
code = tRowMergerInit(&merge, pRow, pSchema);
|
code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2138,7 +2140,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.ts) {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
code = tRowMergerInit(&merge, pRow, pSchema);
|
code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2152,11 +2154,11 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
if (minKey == ik.ts) {
|
if (minKey == ik.ts) {
|
||||||
if (init) {
|
if (init) {
|
||||||
tRowMerge(&merge, piRow);
|
tsdbRowMerge(&merge, piRow);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||||
code = tRowMergerInit(&merge, piRow, pSchema);
|
code = tsdbRowMergerInit(&merge, piRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2171,10 +2173,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == tsLast) {
|
if (minKey == tsLast) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
if (init) {
|
if (init) {
|
||||||
tRowMerge(&merge, &fRow1);
|
tsdbRowMerge(&merge, &fRow1);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
code = tRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2185,7 +2187,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == key) {
|
if (minKey == key) {
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||||
if (!init) {
|
if (!init) {
|
||||||
code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2193,7 +2195,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (merge.pTSchema == NULL) {
|
if (merge.pTSchema == NULL) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
tRowMerge(&merge, &fRow);
|
tsdbRowMerge(&merge, &fRow);
|
||||||
}
|
}
|
||||||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||||
}
|
}
|
||||||
|
|
@ -2203,7 +2205,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tRowMergerGetRow(&merge, &pTSRow);
|
code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2211,7 +2213,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
||||||
|
|
||||||
taosMemoryFree(pTSRow);
|
taosMemoryFree(pTSRow);
|
||||||
tRowMergerClear(&merge);
|
tsdbRowMergerClear(&merge);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2365,16 +2367,16 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc
|
||||||
} else {
|
} else {
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||||
|
|
||||||
STSRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
SRowMerger merge = {0};
|
SRowMerger merge = {0};
|
||||||
|
|
||||||
int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||||
code = tRowMergerGetRow(&merge, &pTSRow);
|
code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -2382,7 +2384,7 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc
|
||||||
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
|
||||||
|
|
||||||
taosMemoryFree(pTSRow);
|
taosMemoryFree(pTSRow);
|
||||||
tRowMergerClear(&merge);
|
tsdbRowMergerClear(&merge);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2507,7 +2509,7 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
||||||
while (1) {
|
while (1) {
|
||||||
bool hasBlockData = false;
|
bool hasBlockData = false;
|
||||||
{
|
{
|
||||||
while (pBlockData->nRow > 0) { // find the first qualified row in data block
|
while (pBlockData->nRow > 0 && pBlockData->uid == pBlockScanInfo->uid) { // find the first qualified row in data block
|
||||||
if (isValidFileBlockRow(pBlockData, pDumpInfo, pBlockScanInfo, pReader)) {
|
if (isValidFileBlockRow(pBlockData, pDumpInfo, pBlockScanInfo, pReader)) {
|
||||||
hasBlockData = true;
|
hasBlockData = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -2691,7 +2693,6 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum) {
|
||||||
taosArrayDestroy(pIndexList);
|
taosArrayDestroy(pIndexList);
|
||||||
|
|
||||||
if (pReader->pReadSnap != NULL) {
|
if (pReader->pReadSnap != NULL) {
|
||||||
|
|
||||||
SDelFile* pDelFile = pReader->pReadSnap->fs.pDelFile;
|
SDelFile* pDelFile = pReader->pReadSnap->fs.pDelFile;
|
||||||
if (pReader->pDelFReader == NULL && pDelFile != NULL) {
|
if (pReader->pDelFReader == NULL && pDelFile != NULL) {
|
||||||
int32_t code = tsdbDelFReaderOpen(&pReader->pDelFReader, pDelFile, pReader->pTsdb);
|
int32_t code = tsdbDelFReaderOpen(&pReader->pDelFReader, pDelFile, pReader->pTsdb);
|
||||||
|
|
@ -3042,7 +3043,12 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) {
|
||||||
} else {
|
} else {
|
||||||
if (pReader->status.pCurrentFileset->nSttF > 0) {
|
if (pReader->status.pCurrentFileset->nSttF > 0) {
|
||||||
// data blocks in current file are exhausted, let's try the next file now
|
// data blocks in current file are exhausted, let's try the next file now
|
||||||
tBlockDataReset(&pReader->status.fileBlockData);
|
SBlockData* pBlockData = &pReader->status.fileBlockData;
|
||||||
|
if (pBlockData->uid != 0) {
|
||||||
|
tBlockDataClear(pBlockData);
|
||||||
|
}
|
||||||
|
|
||||||
|
tBlockDataReset(pBlockData);
|
||||||
resetDataBlockIterator(pBlockIter, pReader->order);
|
resetDataBlockIterator(pBlockIter, pReader->order);
|
||||||
goto _begin;
|
goto _begin;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -3240,7 +3246,8 @@ TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* p
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBROW* pRow = tsdbTbDataIterGet(pIter->iter);
|
TSDBROW* pRow = tsdbTbDataIterGet(pIter->iter);
|
||||||
TSDBKEY key = {.ts = pRow->pTSRow->ts, .version = pRow->version};
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
|
|
||||||
if (outOfTimeWindow(key.ts, &pReader->window)) {
|
if (outOfTimeWindow(key.ts, &pReader->window)) {
|
||||||
pIter->hasVal = false;
|
pIter->hasVal = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -3293,12 +3300,16 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDe
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
STSchema* pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, uid);
|
STSchema* pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, uid);
|
||||||
if (pTSchema == NULL) {
|
if (pTSchema == NULL) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
tRowMergerAdd(pMerger, pRow, pTSchema);
|
tsdbRowMergerAdd(pMerger, pRow, pTSchema);
|
||||||
|
} else { // column format
|
||||||
|
tsdbRowMerge(pMerger, pRow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
@ -3313,7 +3324,7 @@ static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowInd
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, rowIndex);
|
||||||
tRowMerge(pMerger, &fRow);
|
tsdbRowMerge(pMerger, &fRow);
|
||||||
rowIndex += step;
|
rowIndex += step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3369,6 +3380,11 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc
|
||||||
|
|
||||||
SFileDataBlockInfo* pFileBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter);
|
SFileDataBlockInfo* pFileBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter);
|
||||||
SDataBlk* pCurrentBlock = getCurrentBlock(&pReader->status.blockIter);
|
SDataBlk* pCurrentBlock = getCurrentBlock(&pReader->status.blockIter);
|
||||||
|
if (pFileBlockInfo == NULL) {
|
||||||
|
st = CHECK_FILEBLOCK_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
checkForNeighborFileBlock(pReader, pScanInfo, pCurrentBlock, pFileBlockInfo, pMerger, key, &st);
|
checkForNeighborFileBlock(pReader, pScanInfo, pCurrentBlock, pFileBlockInfo, pMerger, key, &st);
|
||||||
if (st == CHECK_FILEBLOCK_QUIT) {
|
if (st == CHECK_FILEBLOCK_QUIT) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -3385,7 +3401,7 @@ int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockSc
|
||||||
int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader);
|
int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader);
|
||||||
if (next1 == ts) {
|
if (next1 == ts) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
tRowMerge(pMerger, &fRow1);
|
tsdbRowMerge(pMerger, &fRow1);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -3394,7 +3410,7 @@ int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockSc
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDelList, STSRow** pTSRow,
|
int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDelList, TSDBROW* pResRow,
|
||||||
STsdbReader* pReader, bool* freeTSRow) {
|
STsdbReader* pReader, bool* freeTSRow) {
|
||||||
TSDBROW* pNextRow = NULL;
|
TSDBROW* pNextRow = NULL;
|
||||||
TSDBROW current = *pRow;
|
TSDBROW current = *pRow;
|
||||||
|
|
@ -3403,19 +3419,19 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
pIter->hasVal = tsdbTbDataIterNext(pIter->iter);
|
pIter->hasVal = tsdbTbDataIterNext(pIter->iter);
|
||||||
|
|
||||||
if (!pIter->hasVal) {
|
if (!pIter->hasVal) {
|
||||||
*pTSRow = current.pTSRow;
|
*pResRow = *pRow;
|
||||||
*freeTSRow = false;
|
*freeTSRow = false;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else { // has next point in mem/imem
|
} else { // has next point in mem/imem
|
||||||
pNextRow = getValidMemRow(pIter, pDelList, pReader);
|
pNextRow = getValidMemRow(pIter, pDelList, pReader);
|
||||||
if (pNextRow == NULL) {
|
if (pNextRow == NULL) {
|
||||||
*pTSRow = current.pTSRow;
|
*pResRow = current;
|
||||||
*freeTSRow = false;
|
*freeTSRow = false;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current.pTSRow->ts != pNextRow->pTSRow->ts) {
|
if (TSDBROW_TS(¤t) != TSDBROW_TS(pNextRow)) {
|
||||||
*pTSRow = current.pTSRow;
|
*pResRow = current;
|
||||||
*freeTSRow = false;
|
*freeTSRow = false;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -3423,9 +3439,12 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
}
|
}
|
||||||
|
|
||||||
SRowMerger merge = {0};
|
SRowMerger merge = {0};
|
||||||
|
|
||||||
// get the correct schema for data in memory
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
// start to merge duplicated rows
|
||||||
|
if (current.type == TSDBROW_ROW_FMT) {
|
||||||
|
// get the correct schema for data in memory
|
||||||
STSchema* pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(¤t), pReader, uid);
|
STSchema* pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(¤t), pReader, uid);
|
||||||
if (pTSchema == NULL) {
|
if (pTSchema == NULL) {
|
||||||
return terrno;
|
return terrno;
|
||||||
|
|
@ -3435,7 +3454,7 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
pReader->pSchema = pTSchema;
|
pReader->pSchema = pTSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = tRowMergerInit2(&merge, pReader->pSchema, ¤t, pTSchema);
|
code = tsdbRowMergerInit2(&merge, pReader->pSchema, ¤t, pTSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -3445,25 +3464,35 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
tRowMergerAdd(&merge, pNextRow, pTSchema1);
|
tsdbRowMergerAdd(&merge, pNextRow, pTSchema1);
|
||||||
|
} else { // let's merge rows in file block
|
||||||
code = doMergeRowsInBuf(pIter, uid, current.pTSRow->ts, pDelList, &merge, pReader);
|
code = tsdbRowMergerInit(&merge, ¤t, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tRowMergerGetRow(&merge, pTSRow);
|
tsdbRowMerge(&merge, pNextRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, &merge, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tRowMergerClear(&merge);
|
code = tsdbRowMergerGetRow(&merge, &pResRow->pTSRow);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
pResRow->type = TSDBROW_ROW_FMT;
|
||||||
|
tsdbRowMergerClear(&merge);
|
||||||
*freeTSRow = true;
|
*freeTSRow = true;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader,
|
int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader,
|
||||||
STSRow** pTSRow) {
|
SRow** pTSRow) {
|
||||||
SRowMerger merge = {0};
|
SRowMerger merge = {0};
|
||||||
|
|
||||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
TSDBKEY k = TSDBROW_KEY(pRow);
|
||||||
|
|
@ -3472,7 +3501,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
if (ASCENDING_TRAVERSE(pReader->order)) { // ascending order imem --> mem
|
if (ASCENDING_TRAVERSE(pReader->order)) { // ascending order imem --> mem
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
|
|
||||||
int32_t code = tRowMergerInit(&merge, piRow, pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, piRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -3483,7 +3512,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tRowMerge(&merge, pRow);
|
tsdbRowMerge(&merge, pRow);
|
||||||
code =
|
code =
|
||||||
doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge, pReader);
|
doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge, pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
|
@ -3493,7 +3522,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
} else {
|
} else {
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
|
|
||||||
int32_t code = tRowMergerInit(&merge, pRow, pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
|
if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -3504,7 +3533,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tRowMerge(&merge, piRow);
|
tsdbRowMerge(&merge, piRow);
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
|
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
|
||||||
pReader);
|
pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
|
@ -3512,13 +3541,12 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = tRowMergerGetRow(&merge, pTSRow);
|
int32_t code = tsdbRowMergerGetRow(&merge, pTSRow);
|
||||||
tRowMergerClear(&merge);
|
tsdbRowMergerClear(&merge);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, STSRow** pTSRow, int64_t endKey,
|
int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, TSDBROW* pResRow, int64_t endKey,
|
||||||
bool* freeTSRow) {
|
bool* freeTSRow) {
|
||||||
TSDBROW* pRow = getValidMemRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader);
|
TSDBROW* pRow = getValidMemRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader);
|
||||||
TSDBROW* piRow = getValidMemRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader);
|
TSDBROW* piRow = getValidMemRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader);
|
||||||
|
|
@ -3548,13 +3576,14 @@ int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pR
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (ik.ts != k.ts) {
|
if (ik.ts != k.ts) {
|
||||||
if (((ik.ts < k.ts) && asc) || ((ik.ts > k.ts) && (!asc))) { // ik.ts < k.ts
|
if (((ik.ts < k.ts) && asc) || ((ik.ts > k.ts) && (!asc))) { // ik.ts < k.ts
|
||||||
code = doMergeMemTableMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, pTSRow, pReader, freeTSRow);
|
code = doMergeMemTableMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, pResRow, pReader, freeTSRow);
|
||||||
} else if (((k.ts < ik.ts) && asc) || ((k.ts > ik.ts) && (!asc))) {
|
} else if (((k.ts < ik.ts) && asc) || ((k.ts > ik.ts) && (!asc))) {
|
||||||
code = doMergeMemTableMultiRows(pRow, uid, &pBlockScanInfo->iter, pDelList, pTSRow, pReader, freeTSRow);
|
code = doMergeMemTableMultiRows(pRow, uid, &pBlockScanInfo->iter, pDelList, pResRow, pReader, freeTSRow);
|
||||||
}
|
}
|
||||||
} else { // ik.ts == k.ts
|
} else { // ik.ts == k.ts
|
||||||
*freeTSRow = true;
|
*freeTSRow = true;
|
||||||
code = doMergeMemIMemRows(pRow, piRow, pBlockScanInfo, pReader, pTSRow);
|
pResRow->type = TSDBROW_ROW_FMT;
|
||||||
|
code = doMergeMemIMemRows(pRow, piRow, pBlockScanInfo, pReader, &pResRow->pTSRow);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -3564,22 +3593,23 @@ int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pR
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockScanInfo->iter.hasVal && pRow != NULL) {
|
if (pBlockScanInfo->iter.hasVal && pRow != NULL) {
|
||||||
return doMergeMemTableMultiRows(pRow, pBlockScanInfo->uid, &pBlockScanInfo->iter, pDelList, pTSRow, pReader,
|
return doMergeMemTableMultiRows(pRow, pBlockScanInfo->uid, &pBlockScanInfo->iter, pDelList, pResRow, pReader,
|
||||||
freeTSRow);
|
freeTSRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pBlockScanInfo->iiter.hasVal && piRow != NULL) {
|
if (pBlockScanInfo->iiter.hasVal && piRow != NULL) {
|
||||||
return doMergeMemTableMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, pTSRow, pReader, freeTSRow);
|
return doMergeMemTableMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, pResRow, pReader, freeTSRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow,
|
int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pTSRow, STableBlockScanInfo* pScanInfo) {
|
||||||
STableBlockScanInfo* pScanInfo) {
|
|
||||||
int32_t outputRowIndex = pBlock->info.rows;
|
int32_t outputRowIndex = pBlock->info.rows;
|
||||||
int64_t uid = pScanInfo->uid;
|
int64_t uid = pScanInfo->uid;
|
||||||
|
|
||||||
|
int32_t numOfCols = (int32_t)taosArrayGetSize(pBlock->pDataBlock);
|
||||||
|
|
||||||
SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo;
|
SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(pTSRow->sver, pReader, uid);
|
STSchema* pSchema = doGetSchemaForTSRow(pTSRow->sver, pReader, uid);
|
||||||
|
|
||||||
|
|
@ -3598,7 +3628,7 @@ int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow*
|
||||||
if (colId == pSchema->columns[j].colId) {
|
if (colId == pSchema->columns[j].colId) {
|
||||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pSupInfo->slotId[i]);
|
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pSupInfo->slotId[i]);
|
||||||
|
|
||||||
tTSRowGetVal(pTSRow, pSchema, j, &colVal);
|
tRowGet(pTSRow, pSchema, j, &colVal);
|
||||||
doCopyColVal(pColInfoData, outputRowIndex, i, &colVal, pSupInfo);
|
doCopyColVal(pColInfoData, outputRowIndex, i, &colVal, pSupInfo);
|
||||||
i += 1;
|
i += 1;
|
||||||
j += 1;
|
j += 1;
|
||||||
|
|
@ -3677,17 +3707,22 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e
|
||||||
SSDataBlock* pBlock = pReader->pResBlock;
|
SSDataBlock* pBlock = pReader->pResBlock;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
STSRow* pTSRow = NULL;
|
// SRow* pTSRow = NULL;
|
||||||
|
TSDBROW row = {.type = -1};
|
||||||
bool freeTSRow = false;
|
bool freeTSRow = false;
|
||||||
tsdbGetNextRowInMem(pBlockScanInfo, pReader, &pTSRow, endKey, &freeTSRow);
|
tsdbGetNextRowInMem(pBlockScanInfo, pReader, &row, endKey, &freeTSRow);
|
||||||
if (pTSRow == NULL) {
|
if (row.type == -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
doAppendRowFromTSRow(pBlock, pReader, pTSRow, pBlockScanInfo);
|
if (row.type == TSDBROW_ROW_FMT) {
|
||||||
|
doAppendRowFromTSRow(pBlock, pReader, row.pTSRow, pBlockScanInfo);
|
||||||
|
|
||||||
if (freeTSRow) {
|
if (freeTSRow) {
|
||||||
taosMemoryFree(pTSRow);
|
taosMemoryFree(row.pTSRow);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
doAppendRowFromFileBlock(pBlock, pReader, row.pBlockData, row.iRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
// no data in buffer, return immediately
|
// no data in buffer, return immediately
|
||||||
|
|
@ -3934,7 +3969,7 @@ void tsdbReaderClose(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(pSupInfo->colId);
|
taosMemoryFree(pSupInfo->colId);
|
||||||
tBlockDataDestroy(&pReader->status.fileBlockData, true);
|
tBlockDataDestroy(&pReader->status.fileBlockData);
|
||||||
cleanupDataBlockIterator(&pReader->status.blockIter);
|
cleanupDataBlockIterator(&pReader->status.blockIter);
|
||||||
|
|
||||||
size_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
|
size_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
|
||||||
|
|
@ -4087,9 +4122,7 @@ void tsdbRetrieveDataBlockInfo(const STsdbReader* pReader, int32_t* rows, uint64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void doFillNullColSMA(SBlockLoadSuppInfo* pSup, int32_t numOfRows, int32_t numOfCols, SColumnDataAgg* pTsAgg) {
|
||||||
static void doFillNullColSMA(SBlockLoadSuppInfo* pSup, int32_t numOfRows, int32_t numOfCols,
|
|
||||||
SColumnDataAgg* pTsAgg) {
|
|
||||||
// do fill all null column value SMA info
|
// do fill all null column value SMA info
|
||||||
int32_t i = 0, j = 0;
|
int32_t i = 0, j = 0;
|
||||||
int32_t size = (int32_t)taosArrayGetSize(pSup->pColAgg);
|
int32_t size = (int32_t)taosArrayGetSize(pSup->pColAgg);
|
||||||
|
|
@ -4187,8 +4220,15 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
|
||||||
} else if (pAgg->colId < pSup->colId[j]) {
|
} else if (pAgg->colId < pSup->colId[j]) {
|
||||||
i += 1;
|
i += 1;
|
||||||
} else if (pSup->colId[j] < pAgg->colId) {
|
} else if (pSup->colId[j] < pAgg->colId) {
|
||||||
ASSERT(pSup->colId[j] == PRIMARYKEY_TIMESTAMP_COL_ID);
|
if (pSup->colId[j] == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||||
pResBlock->pBlockAgg[pSup->slotId[j]] = &pSup->tsColAgg;
|
pResBlock->pBlockAgg[pSup->slotId[j]] = &pSup->tsColAgg;
|
||||||
|
} else {
|
||||||
|
// all date in this block are null
|
||||||
|
SColumnDataAgg nullColAgg = {.colId = pSup->colId[j], .numOfNull = pBlock->nRow};
|
||||||
|
taosArrayPush(pSup->pColAgg, &nullColAgg);
|
||||||
|
|
||||||
|
pResBlock->pBlockAgg[pSup->slotId[j]] = taosArrayGetLast(pSup->pColAgg);
|
||||||
|
}
|
||||||
j += 1;
|
j += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4219,7 +4259,7 @@ static SSDataBlock* doRetrieveDataBlock(STsdbReader* pReader) {
|
||||||
|
|
||||||
int32_t code = doLoadFileBlockData(pReader, &pStatus->blockIter, &pStatus->fileBlockData, pBlockScanInfo->uid);
|
int32_t code = doLoadFileBlockData(pReader, &pStatus->blockIter, &pStatus->fileBlockData, pBlockScanInfo->uid);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
tBlockDataDestroy(&pStatus->fileBlockData, 1);
|
tBlockDataDestroy(&pStatus->fileBlockData);
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -538,7 +538,7 @@ _exit:
|
||||||
if (pReader) {
|
if (pReader) {
|
||||||
taosArrayDestroy(pReader->aDelData);
|
taosArrayDestroy(pReader->aDelData);
|
||||||
taosArrayDestroy(pReader->aDelIdx);
|
taosArrayDestroy(pReader->aDelIdx);
|
||||||
tBlockDataDestroy(&pReader->bData, 1);
|
tBlockDataDestroy(&pReader->bData);
|
||||||
tsdbFSDestroy(&pReader->fs);
|
tsdbFSDestroy(&pReader->fs);
|
||||||
taosMemoryFree(pReader);
|
taosMemoryFree(pReader);
|
||||||
}
|
}
|
||||||
|
|
@ -565,10 +565,10 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader) {
|
||||||
taosArrayDestroy(pIter->aSttBlk);
|
taosArrayDestroy(pIter->aSttBlk);
|
||||||
}
|
}
|
||||||
|
|
||||||
tBlockDataDestroy(&pIter->bData, 1);
|
tBlockDataDestroy(&pIter->bData);
|
||||||
}
|
}
|
||||||
|
|
||||||
tBlockDataDestroy(&pReader->bData, 1);
|
tBlockDataDestroy(&pReader->bData);
|
||||||
tDestroyTSchema(pReader->skmTable.pTSchema);
|
tDestroyTSchema(pReader->skmTable.pTSchema);
|
||||||
|
|
||||||
// del
|
// del
|
||||||
|
|
@ -1359,13 +1359,13 @@ _exit:
|
||||||
if (pWriter->aDelIdxW) taosArrayDestroy(pWriter->aDelIdxW);
|
if (pWriter->aDelIdxW) taosArrayDestroy(pWriter->aDelIdxW);
|
||||||
if (pWriter->aDelData) taosArrayDestroy(pWriter->aDelData);
|
if (pWriter->aDelData) taosArrayDestroy(pWriter->aDelData);
|
||||||
if (pWriter->aDelIdxR) taosArrayDestroy(pWriter->aDelIdxR);
|
if (pWriter->aDelIdxR) taosArrayDestroy(pWriter->aDelIdxR);
|
||||||
tBlockDataDestroy(&pWriter->dWriter.sData, 1);
|
tBlockDataDestroy(&pWriter->dWriter.sData);
|
||||||
tBlockDataDestroy(&pWriter->dWriter.bData, 1);
|
tBlockDataDestroy(&pWriter->dWriter.bData);
|
||||||
if (pWriter->dWriter.aSttBlk) taosArrayDestroy(pWriter->dWriter.aSttBlk);
|
if (pWriter->dWriter.aSttBlk) taosArrayDestroy(pWriter->dWriter.aSttBlk);
|
||||||
if (pWriter->dWriter.aBlockIdx) taosArrayDestroy(pWriter->dWriter.aBlockIdx);
|
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);
|
if (pWriter->dReader.aBlockIdx) taosArrayDestroy(pWriter->dReader.aBlockIdx);
|
||||||
tBlockDataDestroy(&pWriter->bData, 1);
|
tBlockDataDestroy(&pWriter->bData);
|
||||||
tsdbFSDestroy(&pWriter->fs);
|
tsdbFSDestroy(&pWriter->fs);
|
||||||
taosMemoryFree(pWriter);
|
taosMemoryFree(pWriter);
|
||||||
}
|
}
|
||||||
|
|
@ -1425,18 +1425,18 @@ int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback) {
|
||||||
// SNAP_DATA_TSDB
|
// SNAP_DATA_TSDB
|
||||||
|
|
||||||
// Writer
|
// Writer
|
||||||
tBlockDataDestroy(&pWriter->dWriter.sData, 1);
|
tBlockDataDestroy(&pWriter->dWriter.sData);
|
||||||
tBlockDataDestroy(&pWriter->dWriter.bData, 1);
|
tBlockDataDestroy(&pWriter->dWriter.bData);
|
||||||
taosArrayDestroy(pWriter->dWriter.aSttBlk);
|
taosArrayDestroy(pWriter->dWriter.aSttBlk);
|
||||||
tMapDataClear(&pWriter->dWriter.mDataBlk);
|
tMapDataClear(&pWriter->dWriter.mDataBlk);
|
||||||
taosArrayDestroy(pWriter->dWriter.aBlockIdx);
|
taosArrayDestroy(pWriter->dWriter.aBlockIdx);
|
||||||
|
|
||||||
// Reader
|
// Reader
|
||||||
tBlockDataDestroy(&pWriter->dReader.bData, 1);
|
tBlockDataDestroy(&pWriter->dReader.bData);
|
||||||
tMapDataClear(&pWriter->dReader.mDataBlk);
|
tMapDataClear(&pWriter->dReader.mDataBlk);
|
||||||
taosArrayDestroy(pWriter->dReader.aBlockIdx);
|
taosArrayDestroy(pWriter->dReader.aBlockIdx);
|
||||||
|
|
||||||
tBlockDataDestroy(&pWriter->bData, 1);
|
tBlockDataDestroy(&pWriter->bData);
|
||||||
tDestroyTSchema(pWriter->skmTable.pTSchema);
|
tDestroyTSchema(pWriter->skmTable.pTSchema);
|
||||||
|
|
||||||
for (int32_t iBuf = 0; iBuf < sizeof(pWriter->aBuf) / sizeof(uint8_t*); iBuf++) {
|
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) {
|
void tMapDataClear(SMapData *pMapData) {
|
||||||
tFree((uint8_t *)pMapData->aOffset);
|
tFree(pMapData->aOffset);
|
||||||
tFree(pMapData->pData);
|
tFree(pMapData->pData);
|
||||||
pMapData->pData = NULL;
|
pMapData->pData = NULL;
|
||||||
pMapData->aOffset = NULL;
|
pMapData->aOffset = NULL;
|
||||||
|
|
@ -572,9 +572,9 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *
|
||||||
|
|
||||||
ASSERT(iCol > 0);
|
ASSERT(iCol > 0);
|
||||||
|
|
||||||
if (pRow->type == 0) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
tTSRowGetVal(pRow->pTSRow, pTSchema, iCol, pColVal);
|
tRowGet(pRow->pTSRow, pTSchema, iCol, pColVal);
|
||||||
} else if (pRow->type == 1) {
|
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||||
SColData *pColData;
|
SColData *pColData;
|
||||||
|
|
||||||
tBlockDataGetColData(pRow->pBlockData, pTColumn->colId, &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) {
|
int32_t tsdbRowCmprFn(const void *p1, const void *p2) {
|
||||||
return tsdbKeyCmprFn(&TSDBROW_KEY((TSDBROW *)p1), &TSDBROW_KEY((TSDBROW *)p2));
|
return tsdbKeyCmprFn(&TSDBROW_KEY((TSDBROW *)p1), &TSDBROW_KEY((TSDBROW *)p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// STSDBRowIter ======================================================
|
// 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;
|
pIter->pRow = pRow;
|
||||||
if (pRow->type == 0) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
ASSERT(pTSchema);
|
code = tRowIterOpen(pRow->pTSRow, pTSchema, &pIter->pIter);
|
||||||
pIter->pTSchema = pTSchema;
|
if (code) goto _exit;
|
||||||
pIter->i = 1;
|
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||||
} else if (pRow->type == 1) {
|
pIter->iColData = 0;
|
||||||
pIter->pTSchema = NULL;
|
|
||||||
pIter->i = 0;
|
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tsdbRowClose(STSDBRowIter *pIter) {
|
||||||
|
if (pIter->pRow->type == TSDBROW_ROW_FMT) {
|
||||||
|
tRowIterClose(&pIter->pIter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SColVal *tsdbRowIterNext(STSDBRowIter *pIter) {
|
SColVal *tsdbRowIterNext(STSDBRowIter *pIter) {
|
||||||
if (pIter->pRow->type == 0) {
|
if (pIter->pRow->type == TSDBROW_ROW_FMT) {
|
||||||
if (pIter->i < pIter->pTSchema->numOfCols) {
|
return tRowIterNext(pIter->pIter);
|
||||||
tTSRowGetVal(pIter->pRow->pTSRow, pIter->pTSchema, pIter->i, &pIter->colVal);
|
} else if (pIter->pRow->type == TSDBROW_COL_FMT) {
|
||||||
pIter->i++;
|
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 {
|
} else {
|
||||||
if (pIter->i < pIter->pRow->pBlockData->nColData) {
|
ASSERT(0);
|
||||||
SColData *pColData = tBlockDataGetColDataByIdx(pIter->pRow->pBlockData, pIter->i);
|
return NULL; // suppress error report by compiler
|
||||||
|
|
||||||
tColDataGetValue(pColData, pIter->pRow->iRow, &pIter->colVal);
|
|
||||||
pIter->i++;
|
|
||||||
|
|
||||||
return &pIter->colVal;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SRowMerger ======================================================
|
// 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;
|
int32_t code = 0;
|
||||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
SColVal *pColVal = &(SColVal){0};
|
SColVal *pColVal = &(SColVal){0};
|
||||||
|
|
@ -697,7 +698,7 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
SColVal *pColVal = &(SColVal){0};
|
SColVal *pColVal = &(SColVal){0};
|
||||||
|
|
@ -736,7 +737,7 @@ int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
SColVal *pColVal = &(SColVal){0};
|
SColVal *pColVal = &(SColVal){0};
|
||||||
|
|
@ -775,9 +776,9 @@ _exit:
|
||||||
return code;
|
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;
|
int32_t code = 0;
|
||||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
SColVal *pColVal = &(SColVal){0};
|
SColVal *pColVal = &(SColVal){0};
|
||||||
|
|
@ -807,12 +808,8 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tRowMergerGetRow(SRowMerger *pMerger, STSRow **ppRow) {
|
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow) {
|
||||||
int32_t code = 0;
|
return tRowBuild(pMerger->pArray, pMerger->pTSchema, ppRow);
|
||||||
|
|
||||||
code = tdSTSRowNew(pMerger->pArray, pMerger->pTSchema, ppRow);
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete skyline ======================================================
|
// delete skyline ======================================================
|
||||||
|
|
@ -931,27 +928,49 @@ int32_t tBlockDataCreate(SBlockData *pBlockData) {
|
||||||
pBlockData->aVersion = NULL;
|
pBlockData->aVersion = NULL;
|
||||||
pBlockData->aTSKEY = NULL;
|
pBlockData->aTSKEY = NULL;
|
||||||
pBlockData->nColData = 0;
|
pBlockData->nColData = 0;
|
||||||
pBlockData->aColData = taosArrayInit(0, sizeof(SColData));
|
pBlockData->aColData = NULL;
|
||||||
if (pBlockData->aColData == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tBlockDataDestroy(SBlockData *pBlockData, int8_t deepClear) {
|
void tBlockDataDestroy(SBlockData *pBlockData) {
|
||||||
tFree((uint8_t *)pBlockData->aUid);
|
tFree(pBlockData->aUid);
|
||||||
tFree((uint8_t *)pBlockData->aVersion);
|
tFree(pBlockData->aVersion);
|
||||||
tFree((uint8_t *)pBlockData->aTSKEY);
|
tFree(pBlockData->aTSKEY);
|
||||||
taosArrayDestroyEx(pBlockData->aColData, deepClear ? tColDataDestroy : NULL);
|
|
||||||
pBlockData->aUid = NULL;
|
for (int32_t i = 0; i < pBlockData->nColData; i++) {
|
||||||
pBlockData->aVersion = NULL;
|
tColDataDestroy(&pBlockData->aColData[i]);
|
||||||
pBlockData->aTSKEY = NULL;
|
|
||||||
pBlockData->aColData = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, int16_t *aCid, int32_t nCid) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
|
|
@ -961,37 +980,35 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema,
|
||||||
pBlockData->uid = pId->uid;
|
pBlockData->uid = pId->uid;
|
||||||
pBlockData->nRow = 0;
|
pBlockData->nRow = 0;
|
||||||
|
|
||||||
pBlockData->nColData = 0;
|
|
||||||
if (aCid) {
|
if (aCid) {
|
||||||
|
code = tBlockDataAdjustColData(pBlockData, nCid);
|
||||||
|
if (code) goto _exit;
|
||||||
|
|
||||||
int32_t iColumn = 1;
|
int32_t iColumn = 1;
|
||||||
STColumn *pTColumn = &pTSchema->columns[iColumn];
|
STColumn *pTColumn = &pTSchema->columns[iColumn];
|
||||||
for (int32_t iCid = 0; iCid < nCid; iCid++) {
|
for (int32_t iCid = 0; iCid < nCid; iCid++) {
|
||||||
while (pTColumn && pTColumn->colId < aCid[iCid]) {
|
ASSERT(pTColumn);
|
||||||
|
while (pTColumn->colId < aCid[iCid]) {
|
||||||
iColumn++;
|
iColumn++;
|
||||||
pTColumn = (iColumn < pTSchema->numOfCols) ? &pTSchema->columns[iColumn] : NULL;
|
ASSERT(iColumn < pTSchema->numOfCols);
|
||||||
|
pTColumn = &pTSchema->columns[iColumn];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTColumn == NULL) {
|
ASSERT(pTColumn->colId == aCid[iCid]);
|
||||||
break;
|
tColDataInit(&pBlockData->aColData[iCid], pTColumn->colId, pTColumn->type,
|
||||||
} else if (pTColumn->colId == aCid[iCid]) {
|
(pTColumn->flags & COL_SMA_ON) ? 1 : 0);
|
||||||
SColData *pColData;
|
|
||||||
code = tBlockDataAddColData(pBlockData, &pColData);
|
|
||||||
if (code) goto _exit;
|
|
||||||
tColDataInit(pColData, pTColumn->colId, pTColumn->type, (pTColumn->flags & COL_SMA_ON) ? 1 : 0);
|
|
||||||
|
|
||||||
iColumn++;
|
iColumn++;
|
||||||
pTColumn = (iColumn < pTSchema->numOfCols) ? &pTSchema->columns[iColumn] : NULL;
|
pTColumn = (iColumn < pTSchema->numOfCols) ? &pTSchema->columns[iColumn] : NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (int32_t iColumn = 1; iColumn < pTSchema->numOfCols; iColumn++) {
|
code = tBlockDataAdjustColData(pBlockData, pTSchema->numOfCols - 1);
|
||||||
STColumn *pTColumn = &pTSchema->columns[iColumn];
|
|
||||||
|
|
||||||
SColData *pColData;
|
|
||||||
code = tBlockDataAddColData(pBlockData, &pColData);
|
|
||||||
if (code) goto _exit;
|
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) {
|
void tBlockDataReset(SBlockData *pBlockData) {
|
||||||
pBlockData->suid = 0;
|
pBlockData->suid = 0;
|
||||||
pBlockData->uid = 0;
|
pBlockData->uid = 0;
|
||||||
pBlockData->nRow = 0;
|
|
||||||
pBlockData->nColData = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tBlockDataClear(SBlockData *pBlockData) {
|
void tBlockDataClear(SBlockData *pBlockData) {
|
||||||
|
|
@ -1011,49 +1026,22 @@ void tBlockDataClear(SBlockData *pBlockData) {
|
||||||
|
|
||||||
pBlockData->nRow = 0;
|
pBlockData->nRow = 0;
|
||||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||||
SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData);
|
tColDataClear(tBlockDataGetColDataByIdx(pBlockData, iColData));
|
||||||
tColDataClear(pColData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
static int32_t tBlockDataAppendBlockRow(SBlockData *pBlockData, SBlockData *pBlockDataFrom, int32_t iRow) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
SColVal cv = {0};
|
SColVal cv = {0};
|
||||||
int32_t iColDataFrom = 0;
|
int32_t iColDataFrom = 0;
|
||||||
SColData *pColDataFrom =
|
SColData *pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData) ? &pBlockDataFrom->aColData[iColDataFrom] : NULL;
|
||||||
(iColDataFrom < pBlockDataFrom->nColData) ? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom] : NULL;
|
|
||||||
|
|
||||||
for (int32_t iColDataTo = 0; iColDataTo < pBlockData->nColData; iColDataTo++) {
|
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) {
|
while (pColDataFrom && pColDataFrom->cid < pColDataTo->cid) {
|
||||||
iColDataFrom++;
|
pColDataFrom = (++iColDataFrom < pBlockDataFrom->nColData) ? &pBlockDataFrom->aColData[iColDataFrom] : NULL;
|
||||||
pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData)
|
|
||||||
? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom]
|
|
||||||
: NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pColDataFrom == NULL || pColDataFrom->cid > pColDataTo->cid) {
|
if (pColDataFrom == NULL || pColDataFrom->cid > pColDataTo->cid) {
|
||||||
|
|
@ -1065,157 +1053,7 @@ static int32_t tBlockDataAppendBlockRow(SBlockData *pBlockData, SBlockData *pBlo
|
||||||
code = tColDataAppendValue(pColDataTo, &cv);
|
code = tColDataAppendValue(pColDataTo, &cv);
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
|
|
||||||
iColDataFrom++;
|
pColDataFrom = (++iColDataFrom < pBlockDataFrom->nColData) ? &pBlockDataFrom->aColData[iColDataFrom] : NULL;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1245,20 +1083,15 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
|
||||||
pBlockData->aTSKEY[pBlockData->nRow] = TSDBROW_TS(pRow);
|
pBlockData->aTSKEY[pBlockData->nRow] = TSDBROW_TS(pRow);
|
||||||
|
|
||||||
SColVal cv = {0};
|
SColVal cv = {0};
|
||||||
if (pRow->type == 0) {
|
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||||
if (TD_IS_TP_ROW(pRow->pTSRow)) {
|
code = tRowAppendToColData(pRow->pTSRow, pTSchema, pBlockData->aColData, pBlockData->nColData);
|
||||||
code = tBlockDataAppendTPRow(pBlockData, pRow->pTSRow, pTSchema);
|
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
} else if (TD_IS_KV_ROW(pRow->pTSRow)) {
|
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||||
code = tBlockDataAppendKVRow(pBlockData, pRow->pTSRow, pTSchema);
|
code = tBlockDataAppendBlockRow(pBlockData, pRow->pBlockData, pRow->iRow);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
code = tBlockDataAppendBlockRow(pBlockData, pRow->pBlockData, pRow->iRow);
|
|
||||||
if (code) goto _err;
|
|
||||||
}
|
|
||||||
pBlockData->nRow++;
|
pBlockData->nRow++;
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
@ -1267,133 +1100,13 @@ _err:
|
||||||
return code;
|
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) {
|
void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData) {
|
||||||
ASSERT(cid != PRIMARYKEY_TIMESTAMP_COL_ID);
|
ASSERT(cid != PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||||
int32_t lidx = 0;
|
int32_t lidx = 0;
|
||||||
int32_t ridx = pBlockData->nColData - 1;
|
int32_t ridx = pBlockData->nColData - 1;
|
||||||
|
|
||||||
while (lidx <= ridx) {
|
while (lidx <= ridx) {
|
||||||
int32_t midx = (lidx + ridx) / 2;
|
int32_t midx = (lidx + ridx) >> 1;
|
||||||
SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, midx);
|
SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, midx);
|
||||||
int32_t c = (pColData->cid == cid) ? 0 : ((pColData->cid > cid) ? 1 : -1);
|
int32_t c = (pColData->cid == cid) ? 0 : ((pColData->cid > cid) ? 1 : -1);
|
||||||
|
|
||||||
|
|
@ -1540,16 +1253,26 @@ int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uin
|
||||||
// loop to decode each column data
|
// loop to decode each column data
|
||||||
if (hdr.szBlkCol == 0) goto _exit;
|
if (hdr.szBlkCol == 0) goto _exit;
|
||||||
|
|
||||||
|
int32_t nColData = 0;
|
||||||
int32_t nt = 0;
|
int32_t nt = 0;
|
||||||
while (nt < hdr.szBlkCol) {
|
while (nt < hdr.szBlkCol) {
|
||||||
SBlockCol blockCol = {0};
|
SBlockCol blockCol = {0};
|
||||||
nt += tGetBlockCol(pIn + n + nt, &blockCol);
|
nt += tGetBlockCol(pIn + n + nt, &blockCol);
|
||||||
ASSERT(nt <= hdr.szBlkCol);
|
++nColData;
|
||||||
|
}
|
||||||
|
ASSERT(nt == hdr.szBlkCol);
|
||||||
|
|
||||||
SColData *pColData;
|
code = tBlockDataAdjustColData(pBlockData, nColData);
|
||||||
code = tBlockDataAddColData(pBlockData, &pColData);
|
|
||||||
if (code) goto _exit;
|
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);
|
tColDataInit(pColData, blockCol.cid, blockCol.type, blockCol.smaOn);
|
||||||
if (blockCol.flag == HAS_NULL) {
|
if (blockCol.flag == HAS_NULL) {
|
||||||
for (int32_t iRow = 0; iRow < hdr.nRow; iRow++) {
|
for (int32_t iRow = 0; iRow < hdr.nRow; iRow++) {
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,17 @@ static int64_t tsMaxKeyByPrecision[] = {31556995200000L, 31556995200000000L, 921
|
||||||
|
|
||||||
// static int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg);
|
// static int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg);
|
||||||
|
|
||||||
int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp *pRsp) {
|
int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq2 *pMsg, SSubmitRsp2 *pRsp) {
|
||||||
SSubmitMsgIter msgIter = {0};
|
int32_t arrSize = 0;
|
||||||
SSubmitBlk *pBlock = NULL;
|
|
||||||
int32_t affectedrows = 0;
|
int32_t affectedrows = 0;
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
|
|
||||||
ASSERT(pTsdb->mem != NULL);
|
ASSERT(pTsdb->mem != NULL);
|
||||||
|
|
||||||
|
if (pMsg) {
|
||||||
|
arrSize = taosArrayGetSize(pMsg->aSubmitTbData);
|
||||||
|
}
|
||||||
|
|
||||||
// scan and convert
|
// scan and convert
|
||||||
if (tsdbScanAndConvertSubmitMsg(pTsdb, pMsg) < 0) {
|
if (tsdbScanAndConvertSubmitMsg(pTsdb, pMsg) < 0) {
|
||||||
if (terrno != TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
if (terrno != TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||||
|
|
@ -43,18 +46,10 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp *
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop to insert
|
// loop to insert
|
||||||
if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) {
|
for (int32_t i = 0; i < arrSize; ++i) {
|
||||||
|
if ((terrno = tsdbInsertTableData(pTsdb, version, taosArrayGet(pMsg->aSubmitTbData, i), &affectedrows)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (true) {
|
|
||||||
SSubmitBlkRsp r = {0};
|
|
||||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
|
||||||
if (pBlock == NULL) break;
|
|
||||||
if ((terrno = tsdbInsertTableData(pTsdb, version, &msgIter, pBlock, &r)) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfRows += msgIter.numOfRows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRsp != NULL) {
|
if (pRsp != NULL) {
|
||||||
|
|
@ -82,9 +77,8 @@ static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, STable *pTable, STSRow *
|
||||||
}
|
}
|
||||||
#endif
|
#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 now) {
|
||||||
TSKEY rowKey = TD_ROW_KEY(row);
|
|
||||||
if (rowKey < minKey || rowKey > maxKey) {
|
if (rowKey < minKey || rowKey > maxKey) {
|
||||||
tsdbError("vgId:%d, table uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
|
tsdbError("vgId:%d, table uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
|
||||||
" maxKey %" PRId64 " row key %" 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
||||||
ASSERT(pMsg != NULL);
|
ASSERT(pMsg != NULL);
|
||||||
// STsdbMeta * pMeta = pTsdb->tsdbMeta;
|
// STsdbMeta * pMeta = pTsdb->tsdbMeta;
|
||||||
|
|
@ -166,3 +161,43 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
||||||
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
||||||
return 0;
|
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;
|
pPool->ptr = pPool->node.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *vnodeBufPoolMallocAligned(SVBufPool *pPool, int size) {
|
void *vnodeBufPoolMallocAligned(SVBufPool *pPool, int size) {
|
||||||
SVBufPoolNode *pNode;
|
SVBufPoolNode *pNode;
|
||||||
void *p = NULL;
|
void *p = NULL;
|
||||||
|
|
|
||||||
|
|
@ -77,52 +77,72 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
} break;
|
} break;
|
||||||
case TDMT_VND_SUBMIT: {
|
case TDMT_VND_SUBMIT: {
|
||||||
SSubmitMsgIter msgIter = {0};
|
|
||||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pMsg->pCont;
|
|
||||||
SSubmitBlk *pBlock = NULL;
|
|
||||||
int64_t ctime = taosGetTimestampMs();
|
int64_t ctime = taosGetTimestampMs();
|
||||||
tb_uid_t uid;
|
|
||||||
|
|
||||||
if (tInitSubmitMsgIter(pSubmitReq, &msgIter) < 0) {
|
tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
|
||||||
code = terrno;
|
tStartDecode(&dc);
|
||||||
|
|
||||||
|
uint64_t nSubmitTbData;
|
||||||
|
if (tDecodeU64v(&dc, &nSubmitTbData) < 0) {
|
||||||
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (int32_t i = 0; i < nSubmitTbData; i++) {
|
||||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
|
||||||
if (pBlock == NULL) break;
|
|
||||||
|
|
||||||
if (msgIter.schemaLen > 0) {
|
|
||||||
char *name = NULL;
|
|
||||||
|
|
||||||
tDecoderInit(&dc, pBlock->data, msgIter.schemaLen);
|
|
||||||
if (tStartDecode(&dc) < 0) {
|
if (tStartDecode(&dc) < 0) {
|
||||||
code = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return code;
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t flags;
|
||||||
|
if (tDecodeI32v(&dc, &flags) < 0) {
|
||||||
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
|
||||||
|
// SVCreateTbReq
|
||||||
|
if (tStartDecode(&dc) < 0) {
|
||||||
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tDecodeI32v(&dc, NULL) < 0) {
|
if (tDecodeI32v(&dc, NULL) < 0) {
|
||||||
code = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return code;
|
goto _err;
|
||||||
}
|
|
||||||
if (tDecodeCStr(&dc, &name) < 0) {
|
|
||||||
code = TSDB_CODE_INVALID_MSG;
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (uid == 0) {
|
||||||
uid = tGenIdPI64();
|
uid = tGenIdPI64();
|
||||||
}
|
}
|
||||||
|
|
||||||
*(int64_t *)(dc.data + dc.pos) = uid;
|
*(int64_t *)(dc.data + dc.pos) = uid;
|
||||||
*(int64_t *)(dc.data + dc.pos + 8) = ctime;
|
*(int64_t *)(dc.data + dc.pos + 8) = ctime;
|
||||||
pBlock->uid = htobe64(uid);
|
|
||||||
|
tEndDecode(&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);
|
tEndDecode(&dc);
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TDMT_VND_DELETE: {
|
case TDMT_VND_DELETE: {
|
||||||
int32_t size;
|
int32_t size;
|
||||||
|
|
@ -236,7 +256,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
break;
|
break;
|
||||||
/* TSDB */
|
/* TSDB */
|
||||||
case TDMT_VND_SUBMIT:
|
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;
|
break;
|
||||||
case TDMT_VND_DELETE:
|
case TDMT_VND_DELETE:
|
||||||
if (vnodeProcessDeleteReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
if (vnodeProcessDeleteReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||||
|
|
@ -855,30 +875,181 @@ static int32_t vnodeDebugPrintSingleSubmitMsg(SMeta *pMeta, SSubmitBlk *pBlock,
|
||||||
return TSDB_CODE_SUCCESS;
|
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;
|
|
||||||
|
|
||||||
if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) return -1;
|
|
||||||
while (true) {
|
|
||||||
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
|
|
||||||
if (pBlock == NULL) break;
|
|
||||||
|
|
||||||
vnodeDebugPrintSingleSubmitMsg(pMeta, pBlock, &msgIter, tags);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||||
|
#if 1
|
||||||
|
int32_t code = 0;
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
SSubmitReq2 *pSubmitReq = &(SSubmitReq2){0};
|
||||||
|
SSubmitRsp2 *pSubmitRsp = &(SSubmitRsp2){0};
|
||||||
|
SArray *newTbUids = NULL;
|
||||||
|
int32_t ret;
|
||||||
|
SEncoder ec = {0};
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < TARRAY_SIZE(pSubmitReq->aSubmitTbData); ++i) {
|
||||||
|
SSubmitTbData *pSubmitTbData = taosArrayGet(pSubmitReq->aSubmitTbData, i);
|
||||||
|
|
||||||
|
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;
|
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
||||||
SSubmitRsp submitRsp = {0};
|
SSubmitRsp submitRsp = {0};
|
||||||
SSubmitMsgIter msgIter = {0};
|
|
||||||
SSubmitBlk *pBlock = NULL;
|
|
||||||
SVCreateTbReq createTbReq = {0};
|
|
||||||
SDecoder decoder = {0};
|
|
||||||
int32_t nRows = 0;
|
int32_t nRows = 0;
|
||||||
int32_t tsize, ret;
|
int32_t tsize, ret;
|
||||||
SEncoder encoder = {0};
|
SEncoder encoder = {0};
|
||||||
|
|
@ -891,21 +1062,11 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq
|
||||||
pSubmitReq->version = version;
|
pSubmitReq->version = version;
|
||||||
statis.nBatchInsert = 1;
|
statis.nBatchInsert = 1;
|
||||||
|
|
||||||
#ifdef TD_DEBUG_PRINT_ROW
|
|
||||||
vnodeDebugPrintSubmitMsg(pVnode, pReq, __func__);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (tsdbScanAndConvertSubmitMsg(pVnode->pTsdb, pSubmitReq) < 0) {
|
if (tsdbScanAndConvertSubmitMsg(pVnode->pTsdb, pSubmitReq) < 0) {
|
||||||
pRsp->code = terrno;
|
pRsp->code = terrno;
|
||||||
goto _exit;
|
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));
|
submitRsp.pArray = taosArrayInit(msgIter.numOfBlocks, sizeof(SSubmitBlkRsp));
|
||||||
newTbUids = taosArrayInit(msgIter.numOfBlocks, sizeof(int64_t));
|
newTbUids = taosArrayInit(msgIter.numOfBlocks, sizeof(int64_t));
|
||||||
if (!submitRsp.pArray || !newTbUids) {
|
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
|
// create table for auto create table mode
|
||||||
if (msgIter.schemaLen > 0) {
|
if (msgIter.schemaLen > 0) {
|
||||||
tDecoderInit(&decoder, pBlock->data, msgIter.schemaLen);
|
// tDecoderInit(&decoder, pBlock->data, msgIter.schemaLen);
|
||||||
if (tDecodeSVCreateTbReq(&decoder, &createTbReq) < 0) {
|
// if (tDecodeSVCreateTbReq(&decoder, &createTbReq) < 0) {
|
||||||
pRsp->code = TSDB_CODE_INVALID_MSG;
|
// pRsp->code = TSDB_CODE_INVALID_MSG;
|
||||||
tDecoderClear(&decoder);
|
// tDecoderClear(&decoder);
|
||||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||||
goto _exit;
|
// goto _exit;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0) {
|
// if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0) {
|
||||||
pRsp->code = terrno;
|
// pRsp->code = terrno;
|
||||||
tDecoderClear(&decoder);
|
// tDecoderClear(&decoder);
|
||||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||||
goto _exit;
|
// goto _exit;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if ((terrno = grantCheck(TSDB_GRANT_TABLE)) < 0) {
|
// if ((terrno = grantCheck(TSDB_GRANT_TABLE)) < 0) {
|
||||||
pRsp->code = terrno;
|
// pRsp->code = terrno;
|
||||||
tDecoderClear(&decoder);
|
// tDecoderClear(&decoder);
|
||||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||||
goto _exit;
|
// goto _exit;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (metaCreateTable(pVnode->pMeta, version, &createTbReq, &submitBlkRsp.pMeta) < 0) {
|
if (metaCreateTable(pVnode->pMeta, version, &createTbReq, &submitBlkRsp.pMeta) < 0) {
|
||||||
if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
|
// if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
|
||||||
submitBlkRsp.code = terrno;
|
// submitBlkRsp.code = terrno;
|
||||||
pRsp->code = terrno;
|
// pRsp->code = terrno;
|
||||||
tDecoderClear(&decoder);
|
// tDecoderClear(&decoder);
|
||||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||||
goto _exit;
|
// goto _exit;
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
if (NULL != submitBlkRsp.pMeta) {
|
if (NULL != submitBlkRsp.pMeta) {
|
||||||
vnodeUpdateMetaRsp(pVnode, submitBlkRsp.pMeta);
|
vnodeUpdateMetaRsp(pVnode, submitBlkRsp.pMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(newTbUids, &createTbReq.uid);
|
// taosArrayPush(newTbUids, &createTbReq.uid);
|
||||||
|
|
||||||
submitBlkRsp.uid = createTbReq.uid;
|
submitBlkRsp.uid = createTbReq.uid;
|
||||||
submitBlkRsp.tblFName = taosMemoryMalloc(strlen(pVnode->config.dbname) + strlen(createTbReq.name) + 2);
|
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;
|
tbCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgIter.uid = createTbReq.uid;
|
// msgIter.uid = createTbReq.uid;
|
||||||
if (createTbReq.type == TSDB_CHILD_TABLE) {
|
// if (createTbReq.type == TSDB_CHILD_TABLE) {
|
||||||
msgIter.suid = createTbReq.ctb.suid;
|
// msgIter.suid = createTbReq.ctb.suid;
|
||||||
} else {
|
// } else {
|
||||||
msgIter.suid = 0;
|
// msgIter.suid = 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
#ifdef TD_DEBUG_PRINT_ROW
|
// tDecoderClear(&decoder);
|
||||||
vnodeDebugPrintSingleSubmitMsg(pVnode->pMeta, pBlock, &msgIter, "real uid");
|
// taosArrayDestroy(createTbReq.ctb.tagName);
|
||||||
#endif
|
|
||||||
tDecoderClear(&decoder);
|
|
||||||
taosArrayDestroy(createTbReq.ctb.tagName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsdbInsertTableData(pVnode->pTsdb, version, &msgIter, pBlock, &submitBlkRsp) < 0) {
|
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) {
|
// if (taosArrayGetSize(newTbUids) > 0) {
|
||||||
vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
|
// vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode),
|
||||||
(int32_t)taosArrayGetSize(newTbUids));
|
// (int32_t)taosArrayGetSize(newTbUids));
|
||||||
}
|
// }
|
||||||
|
|
||||||
tqUpdateTbUidList(pVnode->pTq, newTbUids, true);
|
// tqUpdateTbUidList(pVnode->pTq, newTbUids, true);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
taosArrayDestroy(newTbUids);
|
taosArrayDestroy(newTbUids);
|
||||||
tEncodeSize(tEncodeSSubmitRsp, &submitRsp, tsize, ret);
|
// tEncodeSize(tEncodeSSubmitRsp, &submitRsp, tsize, ret);
|
||||||
pRsp->pCont = rpcMallocCont(tsize);
|
// pRsp->pCont = rpcMallocCont(tsize);
|
||||||
pRsp->contLen = tsize;
|
// pRsp->contLen = tsize;
|
||||||
tEncoderInit(&encoder, pRsp->pCont, tsize);
|
// tEncoderInit(&encoder, pRsp->pCont, tsize);
|
||||||
tEncodeSSubmitRsp(&encoder, &submitRsp);
|
// tEncodeSSubmitRsp(&encoder, &submitRsp);
|
||||||
tEncoderClear(&encoder);
|
// tEncoderClear(&encoder);
|
||||||
|
|
||||||
taosArrayDestroyEx(submitRsp.pArray, tFreeSSubmitBlkRsp);
|
taosArrayDestroyEx(submitRsp.pArray, tFreeSSubmitBlkRsp);
|
||||||
|
|
||||||
|
|
@ -1025,6 +1183,8 @@ _exit:
|
||||||
|
|
||||||
vDebug("vgId:%d, submit success, index:%" PRId64, pVnode->config.vgId, version);
|
vDebug("vgId:%d, submit success, index:%" PRId64, pVnode->config.vgId, version);
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||||
|
|
|
||||||
|
|
@ -131,11 +131,14 @@ typedef struct {
|
||||||
SMqMetaRsp metaRsp; // for tmq fetching meta
|
SMqMetaRsp metaRsp; // for tmq fetching meta
|
||||||
int8_t returned;
|
int8_t returned;
|
||||||
int64_t snapshotVer;
|
int64_t snapshotVer;
|
||||||
const SSubmitReq* pReq;
|
// const SSubmitReq* pReq;
|
||||||
|
|
||||||
|
SPackedData submit;
|
||||||
|
|
||||||
SSchemaWrapper* schema;
|
SSchemaWrapper* schema;
|
||||||
char tbName[TSDB_TABLE_NAME_LEN];
|
char tbName[TSDB_TABLE_NAME_LEN];
|
||||||
int8_t recoverStep;
|
int8_t recoverStep;
|
||||||
|
int8_t recoverScanFinished;
|
||||||
SQueryTableDataCond tableCond;
|
SQueryTableDataCond tableCond;
|
||||||
int64_t fillHistoryVer1;
|
int64_t fillHistoryVer1;
|
||||||
int64_t fillHistoryVer2;
|
int64_t fillHistoryVer2;
|
||||||
|
|
@ -354,6 +357,7 @@ typedef struct STableMergeScanInfo {
|
||||||
SLimitInfo limitInfo;
|
SLimitInfo limitInfo;
|
||||||
int64_t numOfRows;
|
int64_t numOfRows;
|
||||||
SScanInfo scanInfo;
|
SScanInfo scanInfo;
|
||||||
|
int32_t scanTimes;
|
||||||
SSDataBlock* pResBlock;
|
SSDataBlock* pResBlock;
|
||||||
SSampleExecInfo sample; // sample execution info
|
SSampleExecInfo sample; // sample execution info
|
||||||
SSortExecInfo sortExecInfo;
|
SSortExecInfo sortExecInfo;
|
||||||
|
|
@ -468,6 +472,11 @@ typedef struct SStreamScanInfo {
|
||||||
SNodeList* pGroupTags;
|
SNodeList* pGroupTags;
|
||||||
SNode* pTagCond;
|
SNode* pTagCond;
|
||||||
SNode* pTagIndexCond;
|
SNode* pTagIndexCond;
|
||||||
|
|
||||||
|
// recover
|
||||||
|
int32_t blockRecoverContiCnt;
|
||||||
|
int32_t blockRecoverTotCnt;
|
||||||
|
|
||||||
} SStreamScanInfo;
|
} SStreamScanInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ extern SDataSinkStat gDataSinkStat;
|
||||||
typedef struct SSubmitRes {
|
typedef struct SSubmitRes {
|
||||||
int64_t affectedRows;
|
int64_t affectedRows;
|
||||||
int32_t code;
|
int32_t code;
|
||||||
SSubmitRsp* pRsp;
|
SSubmitRsp2* pRsp;
|
||||||
} SSubmitRes;
|
} SSubmitRes;
|
||||||
|
|
||||||
typedef struct SDataInserterHandle {
|
typedef struct SDataInserterHandle {
|
||||||
|
|
@ -58,22 +58,25 @@ int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
pInserter->submitRes.code = code;
|
pInserter->submitRes.code = code;
|
||||||
|
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
pInserter->submitRes.pRsp = taosMemoryCalloc(1, sizeof(SSubmitRsp));
|
pInserter->submitRes.pRsp = taosMemoryCalloc(1, sizeof(SSubmitRsp2));
|
||||||
SDecoder coder = {0};
|
SDecoder coder = {0};
|
||||||
tDecoderInit(&coder, pMsg->pData, pMsg->len);
|
tDecoderInit(&coder, pMsg->pData, pMsg->len);
|
||||||
code = tDecodeSSubmitRsp(&coder, pInserter->submitRes.pRsp);
|
code = tDecodeSSubmitRsp2(&coder, pInserter->submitRes.pRsp);
|
||||||
if (code) {
|
if (code) {
|
||||||
tFreeSSubmitRsp(pInserter->submitRes.pRsp);
|
taosMemoryFree(pInserter->submitRes.pRsp);
|
||||||
pInserter->submitRes.code = code;
|
pInserter->submitRes.code = code;
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInserter->submitRes.pRsp->nBlocks > 0) {
|
if (pInserter->submitRes.pRsp->affectedRows > 0) {
|
||||||
for (int32_t i = 0; i < pInserter->submitRes.pRsp->nBlocks; ++i) {
|
SArray* pCreateTbList = pInserter->submitRes.pRsp->aCreateTbRsp;
|
||||||
SSubmitBlkRsp* blk = pInserter->submitRes.pRsp->pBlocks + i;
|
int32_t numOfTables = taosArrayGetSize(pCreateTbList);
|
||||||
if (TSDB_CODE_SUCCESS != blk->code) {
|
|
||||||
code = blk->code;
|
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||||
tFreeSSubmitRsp(pInserter->submitRes.pRsp);
|
SVCreateTbRsp* pRsp = taosArrayGet(pCreateTbList, i);
|
||||||
|
if (TSDB_CODE_SUCCESS != pRsp->code) {
|
||||||
|
code = pRsp->code;
|
||||||
|
taosMemoryFree(pInserter->submitRes.pRsp);
|
||||||
pInserter->submitRes.code = code;
|
pInserter->submitRes.code = code;
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
@ -83,20 +86,17 @@ int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
pInserter->submitRes.affectedRows += pInserter->submitRes.pRsp->affectedRows;
|
pInserter->submitRes.affectedRows += pInserter->submitRes.pRsp->affectedRows;
|
||||||
qDebug("submit rsp received, affectedRows:%d, total:%"PRId64, pInserter->submitRes.pRsp->affectedRows,
|
qDebug("submit rsp received, affectedRows:%d, total:%"PRId64, pInserter->submitRes.pRsp->affectedRows,
|
||||||
pInserter->submitRes.affectedRows);
|
pInserter->submitRes.affectedRows);
|
||||||
|
tDecoderClear(&coder);
|
||||||
tFreeSSubmitRsp(pInserter->submitRes.pRsp);
|
taosMemoryFree(pInserter->submitRes.pRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
tsem_post(&pInserter->ready);
|
tsem_post(&pInserter->ready);
|
||||||
|
|
||||||
taosMemoryFree(pMsg->pData);
|
taosMemoryFree(pMsg->pData);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, SSubmitReq* pMsg, void* pTransporter, SEpSet* pEpset) {
|
static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, void* pMsg, int32_t msgLen, void* pTransporter, SEpSet* pEpset) {
|
||||||
// send the fetch remote task result reques
|
// send the fetch remote task result reques
|
||||||
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||||
if (NULL == pMsgSendInfo) {
|
if (NULL == pMsgSendInfo) {
|
||||||
|
|
@ -111,7 +111,7 @@ static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, SSubmitReq* pMs
|
||||||
pMsgSendInfo->param = pParam;
|
pMsgSendInfo->param = pParam;
|
||||||
pMsgSendInfo->paramFreeFp = taosMemoryFree;
|
pMsgSendInfo->paramFreeFp = taosMemoryFree;
|
||||||
pMsgSendInfo->msgInfo.pData = pMsg;
|
pMsgSendInfo->msgInfo.pData = pMsg;
|
||||||
pMsgSendInfo->msgInfo.len = ntohl(pMsg->length);
|
pMsgSendInfo->msgInfo.len = msgLen;
|
||||||
pMsgSendInfo->msgType = TDMT_VND_SUBMIT;
|
pMsgSendInfo->msgType = TDMT_VND_SUBMIT;
|
||||||
pMsgSendInfo->fp = inserterCallback;
|
pMsgSendInfo->fp = inserterCallback;
|
||||||
|
|
||||||
|
|
@ -119,65 +119,85 @@ static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, SSubmitReq* pMs
|
||||||
return asyncSendMsgToServer(pTransporter, pEpset, &transporterId, pMsgSendInfo);
|
return asyncSendMsgToServer(pTransporter, pEpset, &transporterId, pMsgSendInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) {
|
static int32_t submitReqToMsg(int32_t vgId, SSubmitReq2* pReq, void** pData, int32_t* pLen) {
|
||||||
const SArray* pBlocks = pInserter->pDataBlocks;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
const STSchema* pTSchema = pInserter->pSchema;
|
int32_t len = 0;
|
||||||
int64_t uid = pInserter->pNode->tableId;
|
void* pBuf = NULL;
|
||||||
int64_t suid = pInserter->pNode->stableId;
|
tEncodeSize(tEncodeSSubmitReq2, pReq, len, code);
|
||||||
int32_t vgId = pInserter->pNode->vgId;
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
bool fullCol = (pInserter->pNode->pCols->length == pTSchema->numOfCols);
|
SEncoder encoder;
|
||||||
|
len += sizeof(SMsgHead);
|
||||||
SSubmitReq* ret = NULL;
|
pBuf = taosMemoryMalloc(len);
|
||||||
int32_t sz = taosArrayGetSize(pBlocks);
|
if (NULL == pBuf) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
// cal size
|
}
|
||||||
int32_t cap = sizeof(SSubmitReq);
|
((SMsgHead*)pBuf)->vgId = htonl(vgId);
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
((SMsgHead*)pBuf)->contLen = htonl(len);
|
||||||
SSDataBlock* pDataBlock = taosArrayGetP(pBlocks, i);
|
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len - sizeof(SMsgHead));
|
||||||
int32_t rows = pDataBlock->info.rows;
|
code = tEncodeSSubmitReq2(&encoder, pReq);
|
||||||
// TODO min
|
tEncoderClear(&encoder);
|
||||||
int32_t rowSize = pDataBlock->info.rowSize;
|
|
||||||
int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);
|
|
||||||
|
|
||||||
cap += sizeof(SSubmitBlk) + rows * maxLen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign data
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
// TODO
|
*pData = pBuf;
|
||||||
ret = taosMemoryCalloc(1, cap);
|
*pLen = len;
|
||||||
ret->header.vgId = htonl(vgId);
|
} else {
|
||||||
ret->version = htonl(pTSchema->version);
|
taosMemoryFree(pBuf);
|
||||||
ret->length = sizeof(SSubmitReq);
|
}
|
||||||
ret->numOfBlocks = htonl(sz);
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
SSubmitBlk* blkHead = POINTER_SHIFT(ret, sizeof(SSubmitReq));
|
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
|
||||||
SSDataBlock* pDataBlock = taosArrayGetP(pBlocks, i);
|
|
||||||
|
|
||||||
blkHead->sversion = htonl(pTSchema->version);
|
int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** ppReq, const SSDataBlock* pDataBlock, const STSchema* pTSchema,
|
||||||
// TODO
|
int64_t uid, int32_t vgId, tb_uid_t suid) {
|
||||||
blkHead->suid = htobe64(suid);
|
SSubmitReq2* pReq = *ppReq;
|
||||||
blkHead->uid = htobe64(uid);
|
SArray* pVals = NULL;
|
||||||
blkHead->schemaLen = htonl(0);
|
int32_t numOfBlks = 0;
|
||||||
|
bool fullCol = (pInserter->pNode->pCols->length == pTSchema->numOfCols);
|
||||||
|
|
||||||
|
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)))) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock);
|
||||||
|
int32_t rows = pDataBlock->info.rows;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t rows = 0;
|
|
||||||
int32_t dataLen = 0;
|
|
||||||
STSRow* rowData = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
|
||||||
int64_t lastTs = TSKEY_MIN;
|
int64_t lastTs = TSKEY_MIN;
|
||||||
bool ignoreRow = false;
|
bool ignoreRow = false;
|
||||||
for (int32_t j = 0; j < pDataBlock->info.rows; j++) {
|
bool disorderTs = false;
|
||||||
SRowBuilder rb = {0};
|
|
||||||
tdSRowInit(&rb, pTSchema->version);
|
|
||||||
tdSRowSetTpInfo(&rb, pTSchema->numOfCols, pTSchema->flen);
|
|
||||||
tdSRowResetBuf(&rb, rowData);
|
|
||||||
|
|
||||||
ignoreRow = false;
|
for (int32_t j = 0; j < rows; ++j) { // iterate by row
|
||||||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
taosArrayClear(pVals);
|
||||||
const STColumn* pColumn = &pTSchema->columns[k];
|
|
||||||
SColumnInfoData* pColData = NULL;
|
int32_t offset = 0;
|
||||||
|
for (int32_t k = 0; k < pTSchema->numOfCols; ++k) { // iterate by column
|
||||||
int16_t colIdx = k;
|
int16_t colIdx = k;
|
||||||
|
const STColumn* pCol = &pTSchema->columns[k];
|
||||||
if (!fullCol) {
|
if (!fullCol) {
|
||||||
int16_t* slotId = taosHashGet(pInserter->pCols, &pColumn->colId, sizeof(pColumn->colId));
|
int16_t* slotId = taosHashGet(pInserter->pCols, &pCol->colId, sizeof(pCol->colId));
|
||||||
if (NULL == slotId) {
|
if (NULL == slotId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -185,74 +205,147 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) {
|
||||||
colIdx = *slotId;
|
colIdx = *slotId;
|
||||||
}
|
}
|
||||||
|
|
||||||
pColData = taosArrayGet(pDataBlock->pDataBlock, colIdx);
|
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, colIdx);
|
||||||
if (pColData->info.type != pColumn->type) {
|
void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||||
qError("col type mis-match, schema type:%d, type in block:%d", pColumn->type, pColData->info.type);
|
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
|
||||||
return TSDB_CODE_APP_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (colDataIsNull_s(pColData, j)) {
|
switch (pColInfoData->info.type) {
|
||||||
if (0 == k && TSDB_DATA_TYPE_TIMESTAMP == pColumn->type) {
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
ignoreRow = true;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_VARBINARY:
|
||||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, pColumn->offset, k);
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
} else {
|
case TSDB_DATA_TYPE_BLOB:
|
||||||
void* data = colDataGetData(pColData, j);
|
case TSDB_DATA_TYPE_JSON:
|
||||||
if (0 == k && TSDB_DATA_TYPE_TIMESTAMP == pColumn->type) {
|
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||||
if (*(int64_t*)data == lastTs) {
|
uError("the column type %" PRIi16 " is defined but not implemented yet", pColInfoData->info.type);
|
||||||
ignoreRow = true;
|
ASSERT(0);
|
||||||
break;
|
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 {
|
} else {
|
||||||
lastTs = *(int64_t*)data;
|
if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId) {
|
||||||
|
if (*(int64_t*)var == lastTs) {
|
||||||
|
ignoreRow = true;
|
||||||
|
} else if (*(int64_t*)var < lastTs) {
|
||||||
|
disorderTs = true;
|
||||||
|
} else {
|
||||||
|
lastTs = *(int64_t*)var;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k);
|
|
||||||
|
SValue sv;
|
||||||
|
memcpy(&sv.val, var, tDataTypes[pCol->type].bytes);
|
||||||
|
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||||
|
taosArrayPush(pVals, &cv);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
uError("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type);
|
||||||
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
if (!fullCol) {
|
break;
|
||||||
rb.hasNone = true;
|
|
||||||
}
|
}
|
||||||
tdSRowEnd(&rb);
|
|
||||||
|
|
||||||
if (ignoreRow) {
|
if (ignoreRow) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ignoreRow) {
|
||||||
|
ignoreRow = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rows++;
|
SRow* pRow = NULL;
|
||||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
if ((terrno = tRowBuild(pVals, pTSchema, &pRow)) < 0) {
|
||||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
|
||||||
dataLen += rowLen;
|
goto _end;
|
||||||
|
}
|
||||||
|
taosArrayPush(tbData.aRowP, &pRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
blkHead->dataLen = htonl(dataLen);
|
if (disorderTs) {
|
||||||
blkHead->numOfRows = htonl(rows);
|
tRowSort(tbData.aRowP);
|
||||||
|
if ((terrno = tRowMerge(tbData.aRowP, (STSchema*)pTSchema, 0)) != 0) {
|
||||||
ret->length += sizeof(SSubmitBlk) + dataLen;
|
goto _end;
|
||||||
blkHead = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk) + dataLen);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->length = htonl(ret->length);
|
taosArrayPush(pReq->aSubmitTbData, &tbData);
|
||||||
|
|
||||||
*pReq = ret;
|
|
||||||
|
|
||||||
|
_end:
|
||||||
|
taosArrayDestroy(pVals);
|
||||||
|
if (terrno != 0) {
|
||||||
|
*ppReq = NULL;
|
||||||
|
if (pReq) {
|
||||||
|
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||||
|
taosMemoryFree(pReq);
|
||||||
|
}
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
*ppReq = pReq;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t dataBlocksToSubmitReq(SDataInserterHandle* pInserter, void** pMsg, int32_t* msgLen) {
|
||||||
|
const SArray* pBlocks = pInserter->pDataBlocks;
|
||||||
|
const STSchema* pTSchema = pInserter->pSchema;
|
||||||
|
int64_t uid = pInserter->pNode->tableId;
|
||||||
|
int64_t suid = pInserter->pNode->stableId;
|
||||||
|
int32_t vgId = pInserter->pNode->vgId;
|
||||||
|
int32_t sz = taosArrayGetSize(pBlocks);
|
||||||
|
int32_t code = 0;
|
||||||
|
SSubmitReq2 *pReq = NULL;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < sz; i++) {
|
||||||
|
SSDataBlock* pDataBlock = taosArrayGetP(pBlocks, i);
|
||||||
|
|
||||||
|
code = buildSubmitReqFromBlock(pInserter, &pReq, pDataBlock, pTSchema, uid, vgId, suid);
|
||||||
|
if (code) {
|
||||||
|
if (pReq) {
|
||||||
|
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||||
|
taosMemoryFree(pReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
code = submitReqToMsg(vgId, pReq, pMsg, msgLen);
|
||||||
|
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||||
|
taosMemoryFree(pReq);
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
|
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
|
||||||
SDataInserterHandle* pInserter = (SDataInserterHandle*)pHandle;
|
SDataInserterHandle* pInserter = (SDataInserterHandle*)pHandle;
|
||||||
taosArrayPush(pInserter->pDataBlocks, &pInput->pData);
|
taosArrayPush(pInserter->pDataBlocks, &pInput->pData);
|
||||||
SSubmitReq* pMsg = NULL;
|
void* pMsg = NULL;
|
||||||
int32_t code = dataBlockToSubmit(pInserter, &pMsg);
|
int32_t msgLen = 0;
|
||||||
|
int32_t code = dataBlocksToSubmitReq(pInserter, &pMsg, &msgLen);
|
||||||
if (code) {
|
if (code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayClear(pInserter->pDataBlocks);
|
taosArrayClear(pInserter->pDataBlocks);
|
||||||
|
|
||||||
code = sendSubmitRequest(pInserter, pMsg, pInserter->pParam->readHandle->pMsgCb->clientRpc, &pInserter->pNode->epSet);
|
code = sendSubmitRequest(pInserter, pMsg, msgLen, pInserter->pParam->readHandle->pMsgCb->clientRpc, &pInserter->pNode->epSet);
|
||||||
if (code) {
|
if (code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOf
|
||||||
|
|
||||||
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
for (int32_t i = 0; i < numOfBlocks; i++) {
|
for (int32_t i = 0; i < numOfBlocks; i++) {
|
||||||
SSubmitReq* pReq = *(void**)POINTER_SHIFT(input, i * sizeof(void*));
|
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
||||||
taosArrayPush(pInfo->pBlockLists, &pReq);
|
taosArrayPush(pInfo->pBlockLists, pReq);
|
||||||
}
|
}
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||||
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
|
|
@ -61,7 +61,10 @@ static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOf
|
||||||
} else if (type == STREAM_INPUT__DATA_BLOCK) {
|
} else if (type == STREAM_INPUT__DATA_BLOCK) {
|
||||||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||||
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
||||||
taosArrayPush(pInfo->pBlockLists, &pDataBlock);
|
SPackedData tmp = {
|
||||||
|
.pDataBlock = pDataBlock,
|
||||||
|
};
|
||||||
|
taosArrayPush(pInfo->pBlockLists, &tmp);
|
||||||
}
|
}
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
@ -115,18 +118,21 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
|
||||||
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
// ASSERT(numOfBlocks > 1);
|
// ASSERT(numOfBlocks > 1);
|
||||||
for (int32_t i = 0; i < numOfBlocks; i++) {
|
for (int32_t i = 0; i < numOfBlocks; i++) {
|
||||||
SSubmitReq* pReq = *(void**)POINTER_SHIFT(input, i * sizeof(void*));
|
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
||||||
taosArrayPush(pInfo->pBlockLists, &pReq);
|
taosArrayPush(pInfo->pBlockLists, pReq);
|
||||||
}
|
}
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||||
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
ASSERT(numOfBlocks == 1);
|
ASSERT(numOfBlocks == 1);
|
||||||
taosArrayPush(pInfo->pBlockLists, &input);
|
taosArrayPush(pInfo->pBlockLists, input);
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
|
||||||
} else if (type == STREAM_INPUT__DATA_BLOCK) {
|
} else if (type == STREAM_INPUT__DATA_BLOCK) {
|
||||||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||||
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
|
||||||
taosArrayPush(pInfo->pBlockLists, &pDataBlock);
|
SPackedData tmp = {
|
||||||
|
.pDataBlock = pDataBlock,
|
||||||
|
};
|
||||||
|
taosArrayPush(pInfo->pBlockLists, &tmp);
|
||||||
}
|
}
|
||||||
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -937,6 +943,11 @@ int32_t qStreamRestoreParam(qTaskInfo_t tinfo) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool qStreamRecoverScanFinished(qTaskInfo_t tinfo) {
|
||||||
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
|
return pTaskInfo->streamInfo.recoverScanFinished;
|
||||||
|
}
|
||||||
|
|
||||||
void* qExtractReaderFromStreamScanner(void* scanner) {
|
void* qExtractReaderFromStreamScanner(void* scanner) {
|
||||||
SStreamScanInfo* pInfo = scanner;
|
SStreamScanInfo* pInfo = scanner;
|
||||||
return (void*)pInfo->tqReader;
|
return (void*)pInfo->tqReader;
|
||||||
|
|
@ -1002,11 +1013,22 @@ int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* s
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qStreamScanMemData(qTaskInfo_t tinfo, const SSubmitReq* pReq) {
|
#if 0
|
||||||
|
int32_t qStreamScanMemData(qTaskInfo_t tinfo, const SSubmitReq* pReq, int64_t scanVer) {
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
|
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
|
||||||
ASSERT(pTaskInfo->streamInfo.pReq == NULL);
|
ASSERT(pTaskInfo->streamInfo.pReq == NULL);
|
||||||
pTaskInfo->streamInfo.pReq = pReq;
|
pTaskInfo->streamInfo.pReq = pReq;
|
||||||
|
pTaskInfo->streamInfo.scanVer = scanVer;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit) {
|
||||||
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
|
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
|
||||||
|
ASSERT(pTaskInfo->streamInfo.submit.msgStr == NULL);
|
||||||
|
pTaskInfo->streamInfo.submit = submit;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
||||||
blockDataCleanup(pFinalRes);
|
blockDataCleanup(pFinalRes);
|
||||||
|
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
if (pTaskInfo->streamInfo.pReq) {
|
if (pTaskInfo->streamInfo.submit.msgStr) {
|
||||||
pOperator->status = OP_OPENED;
|
pOperator->status = OP_OPENED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1560,14 +1560,18 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
qDebug("queue scan called");
|
qDebug("queue scan called");
|
||||||
|
|
||||||
if (pTaskInfo->streamInfo.pReq != NULL) {
|
if (pTaskInfo->streamInfo.submit.msgStr != NULL) {
|
||||||
if (pInfo->tqReader->pMsg == NULL) {
|
if (pInfo->tqReader->msg2.msgStr == NULL) {
|
||||||
pInfo->tqReader->pMsg = pTaskInfo->streamInfo.pReq;
|
/*pInfo->tqReader->pMsg = pTaskInfo->streamInfo.pReq;*/
|
||||||
const SSubmitReq* pSubmit = pInfo->tqReader->pMsg;
|
|
||||||
if (tqReaderSetDataMsg(pInfo->tqReader, pSubmit, 0) < 0) {
|
/*const SSubmitReq* pSubmit = pInfo->tqReader->pMsg;*/
|
||||||
qError("submit msg messed up when initing stream submit block %p", pSubmit);
|
/*if (tqReaderSetDataMsg(pInfo->tqReader, pSubmit, 0) < 0) {*/
|
||||||
pInfo->tqReader->pMsg = NULL;
|
/*void* msgStr = pTaskInfo->streamInfo.*/
|
||||||
pTaskInfo->streamInfo.pReq = NULL;
|
SPackedData submit = pTaskInfo->streamInfo.submit;
|
||||||
|
if (tqReaderSetSubmitReq2(pInfo->tqReader, submit.msgStr, submit.msgLen, submit.ver) < 0) {
|
||||||
|
qError("submit msg messed up when initing stream submit block %p", submit.msgStr);
|
||||||
|
pInfo->tqReader->msg2 = (SPackedData){0};
|
||||||
|
pInfo->tqReader->setMsg = 0;
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1575,10 +1579,10 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
||||||
blockDataCleanup(pInfo->pRes);
|
blockDataCleanup(pInfo->pRes);
|
||||||
SDataBlockInfo* pBlockInfo = &pInfo->pRes->info;
|
SDataBlockInfo* pBlockInfo = &pInfo->pRes->info;
|
||||||
|
|
||||||
while (tqNextDataBlock(pInfo->tqReader)) {
|
while (tqNextDataBlock2(pInfo->tqReader)) {
|
||||||
SSDataBlock block = {0};
|
SSDataBlock block = {0};
|
||||||
|
|
||||||
int32_t code = tqRetrieveDataBlock(&block, pInfo->tqReader);
|
int32_t code = tqRetrieveDataBlock2(&block, pInfo->tqReader);
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS || block.info.rows == 0) {
|
if (code != TSDB_CODE_SUCCESS || block.info.rows == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1591,8 +1595,9 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->tqReader->pMsg = NULL;
|
pInfo->tqReader->msg2 = (SPackedData){0};
|
||||||
pTaskInfo->streamInfo.pReq = NULL;
|
pInfo->tqReader->setMsg = 0;
|
||||||
|
pTaskInfo->streamInfo.submit = (SPackedData){0};
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1785,11 +1790,18 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
||||||
pTSInfo->scanTimes = 0;
|
pTSInfo->scanTimes = 0;
|
||||||
pTSInfo->currentGroupId = -1;
|
pTSInfo->currentGroupId = -1;
|
||||||
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__SCAN;
|
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__SCAN;
|
||||||
|
pTaskInfo->streamInfo.recoverScanFinished = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__SCAN) {
|
if (pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__SCAN) {
|
||||||
|
if (pInfo->blockRecoverContiCnt > 100) {
|
||||||
|
pInfo->blockRecoverTotCnt += pInfo->blockRecoverContiCnt;
|
||||||
|
pInfo->blockRecoverContiCnt = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
SSDataBlock* pBlock = doTableScan(pInfo->pTableScanOp);
|
SSDataBlock* pBlock = doTableScan(pInfo->pTableScanOp);
|
||||||
if (pBlock != NULL) {
|
if (pBlock != NULL) {
|
||||||
|
pInfo->blockRecoverContiCnt++;
|
||||||
calBlockTbName(pInfo, pBlock);
|
calBlockTbName(pInfo, pBlock);
|
||||||
if (pInfo->pUpdateInfo) {
|
if (pInfo->pUpdateInfo) {
|
||||||
TSKEY maxTs = updateInfoFillBlockData(pInfo->pUpdateInfo, pBlock, pInfo->primaryTsIndex);
|
TSKEY maxTs = updateInfoFillBlockData(pInfo->pUpdateInfo, pBlock, pInfo->primaryTsIndex);
|
||||||
|
|
@ -1807,6 +1819,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
||||||
pTSInfo->base.cond.startVersion = -1;
|
pTSInfo->base.cond.startVersion = -1;
|
||||||
pTSInfo->base.cond.endVersion = -1;
|
pTSInfo->base.cond.endVersion = -1;
|
||||||
|
|
||||||
|
pTaskInfo->streamInfo.recoverScanFinished = true;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1821,7 +1834,8 @@ FETCH_NEXT_BLOCK:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t current = pInfo->validBlockIndex++;
|
int32_t current = pInfo->validBlockIndex++;
|
||||||
SSDataBlock* pBlock = taosArrayGetP(pInfo->pBlockLists, current);
|
SPackedData* pPacked = taosArrayGet(pInfo->pBlockLists, current);
|
||||||
|
SSDataBlock* pBlock = pPacked->pDataBlock;
|
||||||
if (pBlock->info.id.groupId && pBlock->info.parTbName[0]) {
|
if (pBlock->info.id.groupId && pBlock->info.parTbName[0]) {
|
||||||
streamStatePutParName(pTaskInfo->streamInfo.pState, pBlock->info.id.groupId, pBlock->info.parTbName);
|
streamStatePutParName(pTaskInfo->streamInfo.pState, pBlock->info.id.groupId, pBlock->info.parTbName);
|
||||||
}
|
}
|
||||||
|
|
@ -1951,7 +1965,7 @@ FETCH_NEXT_BLOCK:
|
||||||
|
|
||||||
NEXT_SUBMIT_BLK:
|
NEXT_SUBMIT_BLK:
|
||||||
while (1) {
|
while (1) {
|
||||||
if (pInfo->tqReader->pMsg == NULL) {
|
if (pInfo->tqReader->msg2.msgStr == NULL) {
|
||||||
if (pInfo->validBlockIndex >= totBlockNum) {
|
if (pInfo->validBlockIndex >= totBlockNum) {
|
||||||
updateInfoDestoryColseWinSBF(pInfo->pUpdateInfo);
|
updateInfoDestoryColseWinSBF(pInfo->pUpdateInfo);
|
||||||
doClearBufferedBlocks(pInfo);
|
doClearBufferedBlocks(pInfo);
|
||||||
|
|
@ -1960,21 +1974,21 @@ FETCH_NEXT_BLOCK:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t current = pInfo->validBlockIndex++;
|
int32_t current = pInfo->validBlockIndex++;
|
||||||
SSubmitReq* pSubmit = taosArrayGetP(pInfo->pBlockLists, current);
|
SPackedData* pSubmit = taosArrayGet(pInfo->pBlockLists, current);
|
||||||
if (tqReaderSetDataMsg(pInfo->tqReader, pSubmit, 0) < 0) {
|
/*if (tqReaderSetDataMsg(pInfo->tqReader, pSubmit, 0) < 0) {*/
|
||||||
|
if (tqReaderSetSubmitReq2(pInfo->tqReader, pSubmit->msgStr, pSubmit->msgLen, pSubmit->ver) < 0) {
|
||||||
qError("submit msg messed up when initing stream submit block %p, current %d, total %d", pSubmit, current,
|
qError("submit msg messed up when initing stream submit block %p, current %d, total %d", pSubmit, current,
|
||||||
totBlockNum);
|
totBlockNum);
|
||||||
pInfo->tqReader->pMsg = NULL;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDataCleanup(pInfo->pRes);
|
blockDataCleanup(pInfo->pRes);
|
||||||
|
|
||||||
while (tqNextDataBlock(pInfo->tqReader)) {
|
while (tqNextDataBlock2(pInfo->tqReader)) {
|
||||||
SSDataBlock block = {0};
|
SSDataBlock block = {0};
|
||||||
|
|
||||||
int32_t code = tqRetrieveDataBlock(&block, pInfo->tqReader);
|
int32_t code = tqRetrieveDataBlock2(&block, pInfo->tqReader);
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS || block.info.rows == 0) {
|
if (code != TSDB_CODE_SUCCESS || block.info.rows == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -2016,7 +2030,6 @@ FETCH_NEXT_BLOCK:
|
||||||
if (pBlockInfo->rows > 0 || pInfo->pUpdateDataRes->info.rows > 0) {
|
if (pBlockInfo->rows > 0 || pInfo->pUpdateDataRes->info.rows > 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
pInfo->tqReader->pMsg = NULL;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*blockDataCleanup(pInfo->pRes);*/
|
/*blockDataCleanup(pInfo->pRes);*/
|
||||||
|
|
@ -2297,7 +2310,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->pBlockLists = taosArrayInit(4, POINTER_BYTES);
|
pInfo->pBlockLists = taosArrayInit(4, sizeof(SPackedData));
|
||||||
if (pInfo->pBlockLists == NULL) {
|
if (pInfo->pBlockLists == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _error;
|
goto _error;
|
||||||
|
|
|
||||||
|
|
@ -832,7 +832,8 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
if (pStmt->freeArrayFunc) {
|
if (pStmt->freeArrayFunc) {
|
||||||
pStmt->freeArrayFunc(pStmt->pVgDataBlocks);
|
pStmt->freeArrayFunc(pStmt->pVgDataBlocks);
|
||||||
}
|
}
|
||||||
tdDestroySVCreateTbReq(&pStmt->createTblReq);
|
tdDestroySVCreateTbReq(pStmt->pCreateTblReq);
|
||||||
|
taosMemoryFreeClear(pStmt->pCreateTblReq);
|
||||||
taosCloseFile(&pStmt->fp);
|
taosCloseFile(&pStmt->fp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
struct SToken;
|
struct SToken;
|
||||||
|
|
||||||
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
|
||||||
|
|
||||||
#define NEXT_TOKEN(pSql, sToken) \
|
#define NEXT_TOKEN(pSql, sToken) \
|
||||||
do { \
|
do { \
|
||||||
int32_t index = 0; \
|
int32_t index = 0; \
|
||||||
|
|
@ -37,6 +35,8 @@ struct SToken;
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
||||||
|
|
||||||
typedef enum EOrderStatus {
|
typedef enum EOrderStatus {
|
||||||
ORDER_STATUS_UNKNOWN = 0,
|
ORDER_STATUS_UNKNOWN = 0,
|
||||||
ORDER_STATUS_ORDERED = 1,
|
ORDER_STATUS_ORDERED = 1,
|
||||||
|
|
@ -133,7 +133,7 @@ int32_t insMergeTableDataBlocks(SHashObj *pHashObj, SArray **pVgDataBlocks);
|
||||||
int32_t insBuildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq);
|
int32_t insBuildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq);
|
||||||
int32_t insAllocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize);
|
int32_t insAllocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize);
|
||||||
int32_t insCreateSName(SName *pName, struct SToken *pTableName, int32_t acctId, const char *dbName, SMsgBuf *pMsgBuf);
|
int32_t insCreateSName(SName *pName, struct SToken *pTableName, int32_t acctId, const char *dbName, SMsgBuf *pMsgBuf);
|
||||||
int32_t insFindCol(struct SToken *pColname, int32_t start, int32_t end, SSchema *pSchema);
|
int16_t insFindCol(struct SToken *pColname, int16_t start, int16_t end, SSchema *pSchema);
|
||||||
void insBuildCreateTbReq(SVCreateTbReq *pTbReq, const char *tname, STag *pTag, int64_t suid, const char *sname,
|
void insBuildCreateTbReq(SVCreateTbReq *pTbReq, const char *tname, STag *pTag, int64_t suid, const char *sname,
|
||||||
SArray *tagName, uint8_t tagNum, int32_t ttl);
|
SArray *tagName, uint8_t tagNum, int32_t ttl);
|
||||||
int32_t insMemRowAppend(SMsgBuf *pMsgBuf, const void *value, int32_t len, void *param);
|
int32_t insMemRowAppend(SMsgBuf *pMsgBuf, const void *value, int32_t len, void *param);
|
||||||
|
|
@ -141,4 +141,22 @@ int32_t insCheckTimestamp(STableDataBlocks *pDataBlocks, const char *start);
|
||||||
int32_t insBuildOutput(SHashObj *pVgroupsHashObj, SArray *pVgDataBlocks, SArray **pDataBlocks);
|
int32_t insBuildOutput(SHashObj *pVgroupsHashObj, SArray *pVgDataBlocks, SArray **pDataBlocks);
|
||||||
void insDestroyDataBlock(STableDataBlocks *pDataBlock);
|
void insDestroyDataBlock(STableDataBlocks *pDataBlock);
|
||||||
|
|
||||||
|
typedef struct SVgroupDataCxt {
|
||||||
|
int32_t vgId;
|
||||||
|
SSubmitReq2 *pData;
|
||||||
|
} SVgroupDataCxt;
|
||||||
|
|
||||||
|
int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo *pInfo);
|
||||||
|
void insCheckTableDataOrder(STableDataCxt *pTableCxt, TSKEY tsKey);
|
||||||
|
int32_t insGetTableDataCxt(SHashObj *pHash, void *id, int32_t idLen, STableMeta *pTableMeta,
|
||||||
|
SVCreateTbReq **pCreateTbReq, STableDataCxt **pTableCxt, bool colMode);
|
||||||
|
int32_t initTableColSubmitData(STableDataCxt* pTableCxt);
|
||||||
|
int32_t insMergeTableDataCxt(SHashObj *pTableHash, SArray **pVgDataBlocks);
|
||||||
|
int32_t insBuildVgDataBlocks(SHashObj *pVgroupsHashObj, SArray *pVgDataBlocks, SArray **pDataBlocks);
|
||||||
|
void insDestroyTableDataCxtHashMap(SHashObj *pTableCxtHash);
|
||||||
|
void insDestroyVgroupDataCxt(SVgroupDataCxt *pVgCxt);
|
||||||
|
void insDestroyVgroupDataCxtList(SArray *pVgCxtList);
|
||||||
|
void insDestroyVgroupDataCxtHashMap(SHashObj *pVgCxtHash);
|
||||||
|
void insDestroyTableDataCxt(STableDataCxt* pTableCxt);
|
||||||
|
void destroyBoundColInfo(SBoundColInfo* pInfo);
|
||||||
#endif // TDENGINE_PAR_INSERT_UTIL_H
|
#endif // TDENGINE_PAR_INSERT_UTIL_H
|
||||||
|
|
|
||||||
|
|
@ -45,95 +45,46 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char*
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct SmlExecTableHandle {
|
static int32_t smlBoundColumnData(SArray* cols, SBoundColInfo* pBoundInfo, SSchema* pSchema, bool isTag) {
|
||||||
SParsedDataColInfo tags; // each table
|
bool* pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool));
|
||||||
SVCreateTbReq createTblReq; // each table
|
if (NULL == pUseCols) {
|
||||||
} SmlExecTableHandle;
|
|
||||||
|
|
||||||
typedef struct SmlExecHandle {
|
|
||||||
SHashObj* pBlockHash;
|
|
||||||
SmlExecTableHandle tableExecHandle;
|
|
||||||
SQuery* pQuery;
|
|
||||||
} SSmlExecHandle;
|
|
||||||
|
|
||||||
static void smlDestroyTableHandle(void* pHandle) {
|
|
||||||
SmlExecTableHandle* handle = (SmlExecTableHandle*)pHandle;
|
|
||||||
destroyBoundColumnInfo(&handle->tags);
|
|
||||||
tdDestroySVCreateTbReq(&handle->createTblReq);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t smlBoundColumnData(SArray* cols, SParsedDataColInfo* pColList, SSchema* pSchema, bool isTag) {
|
|
||||||
col_id_t nCols = pColList->numOfCols;
|
|
||||||
|
|
||||||
pColList->numOfBound = 0;
|
|
||||||
pColList->boundNullLen = 0;
|
|
||||||
memset(pColList->boundColumns, 0, sizeof(col_id_t) * nCols);
|
|
||||||
for (col_id_t i = 0; i < nCols; ++i) {
|
|
||||||
pColList->cols[i].valStat = VAL_STAT_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isOrdered = true;
|
|
||||||
col_id_t lastColIdx = -1; // last column found
|
|
||||||
for (int i = 0; i < taosArrayGetSize(cols); ++i) {
|
|
||||||
SSmlKv* kv = taosArrayGetP(cols, i);
|
|
||||||
SToken sToken = {.n = kv->keyLen, .z = (char*)kv->key};
|
|
||||||
col_id_t t = lastColIdx + 1;
|
|
||||||
col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, nCols, pSchema));
|
|
||||||
uDebug("SML, index:%d, t:%d, ncols:%d", index, t, nCols);
|
|
||||||
if (index < 0 && t > 0) {
|
|
||||||
index = insFindCol(&sToken, 0, t, pSchema);
|
|
||||||
isOrdered = false;
|
|
||||||
}
|
|
||||||
if (index < 0) {
|
|
||||||
uError("smlBoundColumnData. index:%d", index);
|
|
||||||
return TSDB_CODE_SML_INVALID_DATA;
|
|
||||||
}
|
|
||||||
if (pColList->cols[index].valStat == VAL_STAT_HAS) {
|
|
||||||
uError("smlBoundColumnData. already set. index:%d", index);
|
|
||||||
return TSDB_CODE_SML_INVALID_DATA;
|
|
||||||
}
|
|
||||||
lastColIdx = index;
|
|
||||||
pColList->cols[index].valStat = VAL_STAT_HAS;
|
|
||||||
pColList->boundColumns[pColList->numOfBound] = index;
|
|
||||||
++pColList->numOfBound;
|
|
||||||
switch (pSchema[t].type) {
|
|
||||||
case TSDB_DATA_TYPE_BINARY:
|
|
||||||
pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
|
||||||
pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
pColList->boundNullLen += TYPE_BYTES[pSchema[t].type];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pColList->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED;
|
|
||||||
|
|
||||||
if (!isOrdered) {
|
|
||||||
pColList->colIdxInfo = taosMemoryCalloc(pColList->numOfBound, sizeof(SBoundIdxInfo));
|
|
||||||
if (NULL == pColList->colIdxInfo) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
SBoundIdxInfo* pColIdx = pColList->colIdxInfo;
|
|
||||||
for (col_id_t i = 0; i < pColList->numOfBound; ++i) {
|
pBoundInfo->numOfBound = 0;
|
||||||
pColIdx[i].schemaColIdx = pColList->boundColumns[i];
|
int16_t lastColIdx = -1; // last column found
|
||||||
pColIdx[i].boundIdx = i;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
}
|
|
||||||
taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insSchemaIdxCompar);
|
for (int i = 0; i < taosArrayGetSize(cols); ++i) {
|
||||||
for (col_id_t i = 0; i < pColList->numOfBound; ++i) {
|
SSmlKv* kv = taosArrayGet(cols, i);
|
||||||
pColIdx[i].finalIdx = i;
|
SToken sToken = {.n = kv->keyLen, .z = (char*)kv->key};
|
||||||
}
|
col_id_t t = lastColIdx + 1;
|
||||||
taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insBoundIdxCompar);
|
col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, pBoundInfo->numOfCols, pSchema));
|
||||||
|
uDebug("SML, index:%d, t:%d, ncols:%d", index, t, pBoundInfo->numOfCols);
|
||||||
|
if (index < 0 && t > 0) {
|
||||||
|
index = insFindCol(&sToken, 0, t, pSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pColList->numOfCols > pColList->numOfBound) {
|
if (index < 0) {
|
||||||
memset(&pColList->boundColumns[pColList->numOfBound], 0,
|
uError("smlBoundColumnData. index:%d", index);
|
||||||
sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound));
|
code = TSDB_CODE_SML_INVALID_DATA;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (pUseCols[index]) {
|
||||||
|
uError("smlBoundColumnData. already set. index:%d", index);
|
||||||
|
code = TSDB_CODE_SML_INVALID_DATA;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
lastColIdx = index;
|
||||||
|
pUseCols[index] = true;
|
||||||
|
pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
|
||||||
|
++pBoundInfo->numOfBound;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
end:
|
||||||
|
taosMemoryFree(pUseCols);
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -146,7 +97,7 @@ static int32_t smlBoundColumnData(SArray* cols, SParsedDataColInfo* pColList, SS
|
||||||
* @param msg
|
* @param msg
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
static int32_t smlBuildTagRow(SArray* cols, SParsedDataColInfo* tags, SSchema* pSchema, STag** ppTag, SArray** tagName,
|
static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchema, STag** ppTag, SArray** tagName,
|
||||||
SMsgBuf* msg) {
|
SMsgBuf* msg) {
|
||||||
SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
|
SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
|
||||||
if (!pTagArray) {
|
if (!pTagArray) {
|
||||||
|
|
@ -159,8 +110,8 @@ static int32_t smlBuildTagRow(SArray* cols, SParsedDataColInfo* tags, SSchema* p
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
for (int i = 0; i < tags->numOfBound; ++i) {
|
for (int i = 0; i < tags->numOfBound; ++i) {
|
||||||
SSchema* pTagSchema = &pSchema[tags->boundColumns[i]];
|
SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
|
||||||
SSmlKv* kv = taosArrayGetP(cols, i);
|
SSmlKv* kv = taosArrayGet(cols, i);
|
||||||
|
|
||||||
taosArrayPush(*tagName, pTagSchema->name);
|
taosArrayPush(*tagName, pTagSchema->name);
|
||||||
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
||||||
|
|
@ -207,153 +158,237 @@ end:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smlBindData(void* handle, SArray* tags, SArray* colsSchema, SArray* cols, bool format, STableMeta* pTableMeta,
|
STableDataCxt* smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta) {
|
||||||
char* tableName, const char* sTableName, int32_t sTableNameLen, int32_t ttl, char* msgBuf, int16_t msgBufLen) {
|
STableDataCxt* pTableCxt = NULL;
|
||||||
|
SVCreateTbReq* pCreateTbReq = NULL;
|
||||||
|
int ret = insGetTableDataCxt(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid,
|
||||||
|
sizeof(pTableMeta->uid), pTableMeta, &pCreateTbReq, &pTableCxt, false);
|
||||||
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = initTableColSubmitData(pTableCxt);
|
||||||
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return pTableCxt;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t smlBuildRow(STableDataCxt* pTableCxt) {
|
||||||
|
SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
|
||||||
|
int ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow);
|
||||||
|
if (TSDB_CODE_SUCCESS != ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
insCheckTableDataOrder(pTableCxt, TD_ROW_KEY(*pRow));
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* data, int32_t index) {
|
||||||
|
int ret = TSDB_CODE_SUCCESS;
|
||||||
|
SSchema* pColSchema = schema + index;
|
||||||
|
SColVal* pVal = taosArrayGet(pTableCxt->pValues, index);
|
||||||
|
SSmlKv* kv = (SSmlKv*)data;
|
||||||
|
if (kv->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
int32_t len = 0;
|
||||||
|
char* pUcs4 = taosMemoryCalloc(1, pColSchema->bytes - VARSTR_HEADER_SIZE);
|
||||||
|
if (NULL == pUcs4) {
|
||||||
|
ret = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) {
|
||||||
|
if (errno == E2BIG) {
|
||||||
|
ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
ret = TSDB_CODE_TSC_INVALID_VALUE;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
pVal->value.pData = pUcs4;
|
||||||
|
pVal->value.nData = len;
|
||||||
|
} else if (kv->type == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
pVal->value.nData = kv->length;
|
||||||
|
pVal->value.pData = (uint8_t*)kv->value;
|
||||||
|
} else {
|
||||||
|
memcpy(&pVal->value.val, &(kv->value), kv->length);
|
||||||
|
}
|
||||||
|
pVal->flag = CV_FLAG_VALUE;
|
||||||
|
|
||||||
|
end:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t smlBindData(SQuery* query, 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) {
|
||||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||||
|
|
||||||
SSmlExecHandle* smlHandle = (SSmlExecHandle*)handle;
|
|
||||||
smlDestroyTableHandle(&smlHandle->tableExecHandle); // free for each table
|
|
||||||
SSchema* pTagsSchema = getTableTagSchema(pTableMeta);
|
SSchema* pTagsSchema = getTableTagSchema(pTableMeta);
|
||||||
insSetBoundColumnInfo(&smlHandle->tableExecHandle.tags, pTagsSchema, getNumOfTags(pTableMeta));
|
SBoundColInfo bindTags = {0};
|
||||||
int ret = smlBoundColumnData(tags, &smlHandle->tableExecHandle.tags, pTagsSchema, true);
|
SVCreateTbReq* pCreateTblReq = NULL;
|
||||||
|
SArray* tagName = NULL;
|
||||||
|
|
||||||
|
insInitBoundColsInfo(getNumOfTags(pTableMeta), &bindTags);
|
||||||
|
int ret = smlBoundColumnData(tags, &bindTags, pTagsSchema, true);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
buildInvalidOperationMsg(&pBuf, "bound tags error");
|
buildInvalidOperationMsg(&pBuf, "bound tags error");
|
||||||
return ret;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
STag* pTag = NULL;
|
STag* pTag = NULL;
|
||||||
SArray* tagName = NULL;
|
|
||||||
ret = smlBuildTagRow(tags, &smlHandle->tableExecHandle.tags, pTagsSchema, &pTag, &tagName, &pBuf);
|
ret = smlBuildTagRow(tags, &bindTags, pTagsSchema, &pTag, &tagName, &pBuf);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
taosArrayDestroy(tagName);
|
goto end;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
insBuildCreateTbReq(&smlHandle->tableExecHandle.createTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName,
|
pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
|
||||||
pTableMeta->tableInfo.numOfTags, ttl);
|
if (NULL == pCreateTblReq) {
|
||||||
taosArrayDestroy(tagName);
|
ret = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
insBuildCreateTbReq(pCreateTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName, pTableMeta->tableInfo.numOfTags,
|
||||||
|
ttl);
|
||||||
|
|
||||||
smlHandle->tableExecHandle.createTblReq.ctb.stbName = taosMemoryMalloc(sTableNameLen + 1);
|
pCreateTblReq->ctb.stbName = taosMemoryCalloc(1, sTableNameLen + 1);
|
||||||
memcpy(smlHandle->tableExecHandle.createTblReq.ctb.stbName, sTableName, sTableNameLen);
|
memcpy(pCreateTblReq->ctb.stbName, sTableName, sTableNameLen);
|
||||||
smlHandle->tableExecHandle.createTblReq.ctb.stbName[sTableNameLen] = 0;
|
|
||||||
|
|
||||||
STableDataBlocks* pDataBlock = NULL;
|
if (dataFormat) {
|
||||||
ret = insGetDataBlockFromList(smlHandle->pBlockHash, &pTableMeta->uid, sizeof(pTableMeta->uid),
|
STableDataCxt** pTableCxt = (STableDataCxt**)taosHashGet(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj,
|
||||||
TSDB_DEFAULT_PAYLOAD_SIZE, sizeof(SSubmitBlk), getTableInfo(pTableMeta).rowSize,
|
&pTableMeta->uid, sizeof(pTableMeta->uid));
|
||||||
pTableMeta, &pDataBlock, NULL, &smlHandle->tableExecHandle.createTblReq);
|
if (NULL == pTableCxt) {
|
||||||
|
ret = buildInvalidOperationMsg(&pBuf, "dataformat true. get tableDataCtx error");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
(*pTableCxt)->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
|
||||||
|
(*pTableCxt)->pData->pCreateTbReq = pCreateTblReq;
|
||||||
|
(*pTableCxt)->pMeta->uid = pTableMeta->uid;
|
||||||
|
(*pTableCxt)->pMeta->vgId = pTableMeta->vgId;
|
||||||
|
pCreateTblReq = NULL;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
STableDataCxt* pTableCxt = NULL;
|
||||||
|
ret = insGetTableDataCxt(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid,
|
||||||
|
sizeof(pTableMeta->uid), pTableMeta, &pCreateTblReq, &pTableCxt, false);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
buildInvalidOperationMsg(&pBuf, "create data block error");
|
buildInvalidOperationMsg(&pBuf, "insGetTableDataCxt error");
|
||||||
return ret;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* pSchema = getTableColumnSchema(pTableMeta);
|
SSchema* pSchema = getTableColumnSchema(pTableMeta);
|
||||||
|
ret = smlBoundColumnData(colsSchema, &pTableCxt->boundColsInfo, pSchema, false);
|
||||||
ret = smlBoundColumnData(colsSchema, &pDataBlock->boundColumnInfo, pSchema, false);
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
buildInvalidOperationMsg(&pBuf, "bound cols error");
|
buildInvalidOperationMsg(&pBuf, "bound cols error");
|
||||||
return ret;
|
goto end;
|
||||||
}
|
}
|
||||||
int32_t extendedRowSize = insGetExtendedRowSize(pDataBlock);
|
|
||||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
|
||||||
SRowBuilder* pBuilder = &pDataBlock->rowBuilder;
|
|
||||||
SMemParam param = {.rb = pBuilder};
|
|
||||||
|
|
||||||
insInitRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo);
|
ret = initTableColSubmitData(pTableCxt);
|
||||||
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
|
buildInvalidOperationMsg(&pBuf, "initTableColSubmitData error");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t rowNum = taosArrayGetSize(cols);
|
int32_t rowNum = taosArrayGetSize(cols);
|
||||||
if (rowNum <= 0) {
|
if (rowNum <= 0) {
|
||||||
return buildInvalidOperationMsg(&pBuf, "cols size <= 0");
|
ret = buildInvalidOperationMsg(&pBuf, "cols size <= 0");
|
||||||
}
|
goto end;
|
||||||
ret = insAllocateMemForSize(pDataBlock, extendedRowSize * rowNum);
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
|
||||||
buildInvalidOperationMsg(&pBuf, "allocate memory error");
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t r = 0; r < rowNum; ++r) {
|
for (int32_t r = 0; r < rowNum; ++r) {
|
||||||
STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size); // skip the SSubmitBlk header
|
|
||||||
tdSRowResetBuf(pBuilder, row);
|
|
||||||
void* rowData = taosArrayGetP(cols, r);
|
void* rowData = taosArrayGetP(cols, r);
|
||||||
size_t rowDataSize = 0;
|
|
||||||
if (format) {
|
|
||||||
rowDataSize = taosArrayGetSize(rowData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. set the parsed value from sql string
|
// 1. set the parsed value from sql string
|
||||||
for (int c = 0, j = 0; c < spd->numOfBound; ++c) {
|
for (int c = 0; c < pTableCxt->boundColsInfo.numOfBound; ++c) {
|
||||||
SSchema* pColSchema = &pSchema[spd->boundColumns[c]];
|
SSchema* pColSchema = &pSchema[pTableCxt->boundColsInfo.pColIndex[c]];
|
||||||
|
SColVal* pVal = taosArrayGet(pTableCxt->pValues, pTableCxt->boundColsInfo.pColIndex[c]);
|
||||||
param.schema = pColSchema;
|
|
||||||
insGetSTSRowAppendInfo(pBuilder->rowType, spd, c, ¶m.toffset, ¶m.colIdx);
|
|
||||||
|
|
||||||
SSmlKv* kv = NULL;
|
|
||||||
if (format) {
|
|
||||||
if (j < rowDataSize) {
|
|
||||||
kv = taosArrayGetP(rowData, j);
|
|
||||||
if (rowDataSize != spd->numOfBound && j != 0 &&
|
|
||||||
(kv->keyLen != strlen(pColSchema->name) || strncmp(kv->key, pColSchema->name, kv->keyLen) != 0)) {
|
|
||||||
kv = NULL;
|
|
||||||
} else {
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
|
void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
|
||||||
if (p) kv = *p;
|
if (p == NULL) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
SSmlKv* kv = *(SSmlKv**)p;
|
||||||
|
|
||||||
if (kv) {
|
|
||||||
int32_t colLen = kv->length;
|
|
||||||
if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
|
if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
uDebug("SML:data before:%" PRId64 ", precision:%d", kv->i, pTableMeta->tableInfo.precision);
|
|
||||||
kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
|
kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
|
||||||
uDebug("SML:data after:%" PRId64 ", precision:%d", kv->i, pTableMeta->tableInfo.precision);
|
|
||||||
}
|
}
|
||||||
|
if (kv->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
if (IS_VAR_DATA_TYPE(kv->type)) {
|
int32_t len = 0;
|
||||||
insMemRowAppend(&pBuf, kv->value, colLen, ¶m);
|
char* pUcs4 = taosMemoryCalloc(1, pColSchema->bytes - VARSTR_HEADER_SIZE);
|
||||||
|
if (NULL == pUcs4) {
|
||||||
|
ret = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) {
|
||||||
|
if (errno == E2BIG) {
|
||||||
|
buildInvalidOperationMsg(&pBuf, "value too long");
|
||||||
|
ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
ret = buildInvalidOperationMsg(&pBuf, strerror(errno));
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
pVal->value.pData = pUcs4;
|
||||||
|
pVal->value.nData = len;
|
||||||
|
} else if (kv->type == TSDB_DATA_TYPE_BINARY) {
|
||||||
|
pVal->value.nData = kv->length;
|
||||||
|
pVal->value.pData = (uint8_t*)kv->value;
|
||||||
} else {
|
} else {
|
||||||
insMemRowAppend(&pBuf, &(kv->value), colLen, ¶m);
|
memcpy(&pVal->value.val, &(kv->value), kv->length);
|
||||||
}
|
}
|
||||||
} else {
|
pVal->flag = CV_FLAG_VALUE;
|
||||||
pBuilder->hasNone = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) {
|
SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
|
||||||
TSKEY tsKey = TD_ROW_KEY(row);
|
ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow);
|
||||||
insCheckTimestamp(pDataBlock, (const char*)&tsKey);
|
if (TSDB_CODE_SUCCESS != ret) {
|
||||||
|
buildInvalidOperationMsg(&pBuf, "tRowBuild error");
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
insCheckTableDataOrder(pTableCxt, TD_ROW_KEY(*pRow));
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the null value for the columns that do not assign values
|
end:
|
||||||
if ((spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) {
|
destroyBoundColInfo(&bindTags);
|
||||||
pBuilder->hasNone = true;
|
taosMemoryFree(pCreateTblReq);
|
||||||
|
taosArrayDestroy(tagName);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
tdSRowEnd(pBuilder);
|
SQuery* smlInitHandle() {
|
||||||
pDataBlock->size += extendedRowSize;
|
SQuery* pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||||
|
if (NULL == pQuery) {
|
||||||
|
uError("create pQuery error");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||||
|
pQuery->haveResultSet = false;
|
||||||
|
pQuery->msgType = TDMT_VND_SUBMIT;
|
||||||
|
SVnodeModifyOpStmt* stmt = (SVnodeModifyOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIFY_STMT);
|
||||||
|
if (NULL == stmt) {
|
||||||
|
uError("create SVnodeModifyOpStmt error");
|
||||||
|
qDestroyQuery(pQuery);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
stmt->pTableBlockHashObj = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||||
|
stmt->freeHashFunc = insDestroyTableDataCxtHashMap;
|
||||||
|
stmt->freeArrayFunc = insDestroyVgroupDataCxtList;
|
||||||
|
|
||||||
|
pQuery->pRoot = (SNode*)stmt;
|
||||||
|
return pQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData);
|
int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash) {
|
||||||
return insSetBlockInfo(pBlocks, pDataBlock, rowNum, &pBuf);
|
SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)(handle)->pRoot;
|
||||||
|
// merge according to vgId
|
||||||
|
int32_t code = insMergeTableDataCxt(pStmt->pTableBlockHashObj, &pStmt->pVgDataBlocks);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
uError("insMergeTableDataCxt failed");
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
code = insBuildVgDataBlocks(pVgHash, pStmt->pVgDataBlocks, &pStmt->pDataBlocks);
|
||||||
void* smlInitHandle(SQuery* pQuery) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
SSmlExecHandle* handle = taosMemoryCalloc(1, sizeof(SSmlExecHandle));
|
uError("insBuildVgDataBlocks failed");
|
||||||
if (!handle) return NULL;
|
return code;
|
||||||
handle->pBlockHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
|
||||||
handle->pQuery = pQuery;
|
|
||||||
|
|
||||||
return handle;
|
|
||||||
}
|
}
|
||||||
|
return code;
|
||||||
void smlDestroyHandle(void* pHandle) {
|
|
||||||
if (!pHandle) return;
|
|
||||||
SSmlExecHandle* handle = (SSmlExecHandle*)pHandle;
|
|
||||||
insDestroyBlockHashmap(handle->pBlockHash);
|
|
||||||
smlDestroyTableHandle(&handle->tableExecHandle);
|
|
||||||
taosMemoryFree(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t smlBuildOutput(void* handle, SHashObj* pVgHash) {
|
|
||||||
SSmlExecHandle* smlHandle = (SSmlExecHandle*)handle;
|
|
||||||
return qBuildStmtOutput(smlHandle->pQuery, pVgHash, smlHandle->pBlockHash);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ typedef struct SInsertParseContext {
|
||||||
SParseContext* pComCxt;
|
SParseContext* pComCxt;
|
||||||
SMsgBuf msg;
|
SMsgBuf msg;
|
||||||
char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW];
|
char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW];
|
||||||
SParsedDataColInfo tags; // for stmt
|
SBoundColInfo tags; // for stmt
|
||||||
bool missCache;
|
bool missCache;
|
||||||
bool usingDuplicateTable;
|
bool usingDuplicateTable;
|
||||||
bool forceUpdate;
|
bool forceUpdate;
|
||||||
|
|
@ -173,21 +173,19 @@ static int32_t parseDuplicateUsingClause(SInsertParseContext* pCxt, SVnodeModify
|
||||||
}
|
}
|
||||||
|
|
||||||
// pStmt->pSql -> field1_name, ...)
|
// pStmt->pSql -> field1_name, ...)
|
||||||
static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, bool isTags,
|
static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, bool isTags, SSchema* pSchema,
|
||||||
SParsedDataColInfo* pColList, SSchema* pSchema) {
|
SBoundColInfo* pBoundInfo) {
|
||||||
col_id_t nCols = pColList->numOfCols;
|
bool* pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool));
|
||||||
|
if (NULL == pUseCols) {
|
||||||
pColList->numOfBound = 0;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pColList->boundNullLen = 0;
|
|
||||||
memset(pColList->boundColumns, 0, sizeof(col_id_t) * nCols);
|
|
||||||
for (col_id_t i = 0; i < nCols; ++i) {
|
|
||||||
pColList->cols[i].valStat = VAL_STAT_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pBoundInfo->numOfBound = 0;
|
||||||
|
|
||||||
|
int16_t lastColIdx = -1; // last column found
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
while (TSDB_CODE_SUCCESS == code) {
|
||||||
SToken token;
|
SToken token;
|
||||||
bool isOrdered = true;
|
|
||||||
col_id_t lastColIdx = -1; // last column found
|
|
||||||
while (1) {
|
|
||||||
NEXT_TOKEN(*pSql, token);
|
NEXT_TOKEN(*pSql, token);
|
||||||
|
|
||||||
if (TK_NK_RP == token.type) {
|
if (TK_NK_RP == token.type) {
|
||||||
|
|
@ -199,64 +197,30 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, b
|
||||||
token.z = tmpTokenBuf;
|
token.z = tmpTokenBuf;
|
||||||
token.n = strdequote(token.z);
|
token.n = strdequote(token.z);
|
||||||
|
|
||||||
col_id_t t = lastColIdx + 1;
|
int16_t t = lastColIdx + 1;
|
||||||
col_id_t index = insFindCol(&token, t, nCols, pSchema);
|
int16_t index = insFindCol(&token, t, pBoundInfo->numOfCols, pSchema);
|
||||||
if (index < 0 && t > 0) {
|
if (index < 0 && t > 0) {
|
||||||
index = insFindCol(&token, 0, t, pSchema);
|
index = insFindCol(&token, 0, t, pSchema);
|
||||||
isOrdered = false;
|
|
||||||
}
|
}
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMN, token.z);
|
code = generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMN, token.z);
|
||||||
}
|
} else if (pUseCols[index]) {
|
||||||
if (pColList->cols[index].valStat == VAL_STAT_HAS) {
|
code = buildSyntaxErrMsg(&pCxt->msg, "duplicated column name", token.z);
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "duplicated column name", token.z);
|
} else {
|
||||||
}
|
|
||||||
lastColIdx = index;
|
lastColIdx = index;
|
||||||
pColList->cols[index].valStat = VAL_STAT_HAS;
|
pUseCols[index] = true;
|
||||||
pColList->boundColumns[pColList->numOfBound] = index;
|
pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
|
||||||
++pColList->numOfBound;
|
++pBoundInfo->numOfBound;
|
||||||
switch (pSchema[t].type) {
|
|
||||||
case TSDB_DATA_TYPE_BINARY:
|
|
||||||
pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
|
||||||
pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
pColList->boundNullLen += TYPE_BYTES[pSchema[t].type];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isTags && pColList->cols[0].valStat == VAL_STAT_NONE) {
|
if (TSDB_CODE_SUCCESS == code && !isTags && !pUseCols[0]) {
|
||||||
return buildInvalidOperationMsg(&pCxt->msg, "primary timestamp column can not be null");
|
code = buildInvalidOperationMsg(&pCxt->msg, "primary timestamp column can not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
pColList->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED;
|
taosMemoryFree(pUseCols);
|
||||||
|
|
||||||
if (!isOrdered) {
|
return code;
|
||||||
pColList->colIdxInfo = taosMemoryCalloc(pColList->numOfBound, sizeof(SBoundIdxInfo));
|
|
||||||
if (NULL == pColList->colIdxInfo) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
SBoundIdxInfo* pColIdx = pColList->colIdxInfo;
|
|
||||||
for (col_id_t i = 0; i < pColList->numOfBound; ++i) {
|
|
||||||
pColIdx[i].schemaColIdx = pColList->boundColumns[i];
|
|
||||||
pColIdx[i].boundIdx = i;
|
|
||||||
}
|
|
||||||
taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insSchemaIdxCompar);
|
|
||||||
for (col_id_t i = 0; i < pColList->numOfBound; ++i) {
|
|
||||||
pColIdx[i].finalIdx = i;
|
|
||||||
}
|
|
||||||
taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insBoundIdxCompar);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pColList->numOfCols > pColList->numOfBound) {
|
|
||||||
memset(&pColList->boundColumns[pColList->numOfBound], 0,
|
|
||||||
sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound));
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parseTime(const char** end, SToken* pToken, int16_t timePrec, int64_t* time, SMsgBuf* pMsgBuf) {
|
static int parseTime(const char** end, SToken* pToken, int16_t timePrec, int64_t* time, SMsgBuf* pMsgBuf) {
|
||||||
|
|
@ -519,8 +483,7 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema,
|
||||||
// input pStmt->pSql: [(tag1_name, ...)] TAGS (tag1_value, ...) ...
|
// input pStmt->pSql: [(tag1_name, ...)] TAGS (tag1_value, ...) ...
|
||||||
// output pStmt->pSql: TAGS (tag1_value, ...) ...
|
// output pStmt->pSql: TAGS (tag1_value, ...) ...
|
||||||
static int32_t parseBoundTagsClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
static int32_t parseBoundTagsClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||||
SSchema* pTagsSchema = getTableTagSchema(pStmt->pTableMeta);
|
insInitBoundColsInfo(getNumOfTags(pStmt->pTableMeta), &pCxt->tags);
|
||||||
insSetBoundColumnInfo(&pCxt->tags, pTagsSchema, getNumOfTags(pStmt->pTableMeta));
|
|
||||||
|
|
||||||
SToken token;
|
SToken token;
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
|
|
@ -530,7 +493,7 @@ static int32_t parseBoundTagsClause(SInsertParseContext* pCxt, SVnodeModifyOpStm
|
||||||
}
|
}
|
||||||
|
|
||||||
pStmt->pSql += index;
|
pStmt->pSql += index;
|
||||||
return parseBoundColumns(pCxt, &pStmt->pSql, true, &pCxt->tags, pTagsSchema);
|
return parseBoundColumns(pCxt, &pStmt->pSql, true, getTableTagSchema(pStmt->pTableMeta), &pCxt->tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseTagValue(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SSchema* pTagSchema, SToken* pToken,
|
static int32_t parseTagValue(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SSchema* pTagSchema, SToken* pToken,
|
||||||
|
|
@ -561,10 +524,15 @@ static int32_t parseTagValue(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStm
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buildCreateTbReq(SVnodeModifyOpStmt* pStmt, STag* pTag, SArray* pTagName) {
|
static int32_t buildCreateTbReq(SVnodeModifyOpStmt* pStmt, STag* pTag, SArray* pTagName) {
|
||||||
insBuildCreateTbReq(&pStmt->createTblReq, pStmt->targetTableName.tname, pTag, pStmt->pTableMeta->suid,
|
pStmt->pCreateTblReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
|
||||||
|
if (NULL == pStmt->pCreateTblReq) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
insBuildCreateTbReq(pStmt->pCreateTblReq, pStmt->targetTableName.tname, pTag, pStmt->pTableMeta->suid,
|
||||||
pStmt->usingTableName.tname, pTagName, pStmt->pTableMeta->tableInfo.numOfTags,
|
pStmt->usingTableName.tname, pTagName, pStmt->pTableMeta->tableInfo.numOfTags,
|
||||||
TSDB_DEFAULT_TABLE_TTL);
|
TSDB_DEFAULT_TABLE_TTL);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf) {
|
static int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf) {
|
||||||
|
|
@ -618,7 +586,7 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i]];
|
SSchema* pTagSchema = &pSchema[pCxt->tags.pColIndex[i]];
|
||||||
isJson = pTagSchema->type == TSDB_DATA_TYPE_JSON;
|
isJson = pTagSchema->type == TSDB_DATA_TYPE_JSON;
|
||||||
code = checkAndTrimValue(&token, pCxt->tmpTokenBuf, &pCxt->msg);
|
code = checkAndTrimValue(&token, pCxt->tmpTokenBuf, &pCxt->msg);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
|
@ -631,7 +599,7 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && !isParseBindParam) {
|
if (TSDB_CODE_SUCCESS == code && !isParseBindParam) {
|
||||||
buildCreateTbReq(pStmt, pTag, pTagName);
|
code = buildCreateTbReq(pStmt, pTag, pTagName);
|
||||||
pTag = NULL;
|
pTag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -699,8 +667,8 @@ static int32_t parseTableOptions(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
|
||||||
if (TK_NK_INTEGER != token.type) {
|
if (TK_NK_INTEGER != token.type) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "Invalid option ttl", token.z);
|
return buildSyntaxErrMsg(&pCxt->msg, "Invalid option ttl", token.z);
|
||||||
}
|
}
|
||||||
pStmt->createTblReq.ttl = taosStr2Int32(token.z, NULL, 10);
|
pStmt->pCreateTblReq->ttl = taosStr2Int32(token.z, NULL, 10);
|
||||||
if (pStmt->createTblReq.ttl < 0) {
|
if (pStmt->pCreateTblReq->ttl < 0) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "Invalid option ttl", token.z);
|
return buildSyntaxErrMsg(&pCxt->msg, "Invalid option ttl", token.z);
|
||||||
}
|
}
|
||||||
} else if (TK_COMMENT == token.type) {
|
} else if (TK_COMMENT == token.type) {
|
||||||
|
|
@ -713,11 +681,11 @@ static int32_t parseTableOptions(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "comment too long", token.z);
|
return buildSyntaxErrMsg(&pCxt->msg, "comment too long", token.z);
|
||||||
}
|
}
|
||||||
int32_t len = trimString(token.z, token.n, pCxt->tmpTokenBuf, TSDB_TB_COMMENT_LEN);
|
int32_t len = trimString(token.z, token.n, pCxt->tmpTokenBuf, TSDB_TB_COMMENT_LEN);
|
||||||
pStmt->createTblReq.comment = strndup(pCxt->tmpTokenBuf, len);
|
pStmt->pCreateTblReq->comment = strndup(pCxt->tmpTokenBuf, len);
|
||||||
if (NULL == pStmt->createTblReq.comment) {
|
if (NULL == pStmt->pCreateTblReq->comment) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pStmt->createTblReq.commentLen = len;
|
pStmt->pCreateTblReq->commentLen = len;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -975,26 +943,22 @@ static int32_t preParseBoundColumnsClause(SInsertParseContext* pCxt, SVnodeModif
|
||||||
return skipParentheses(pCxt, &pStmt->pSql);
|
return skipParentheses(pCxt, &pStmt->pSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t getTableDataBlocks(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataBlocks** pDataBuf) {
|
static int32_t getTableDataCxt(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataCxt** pTableCxt) {
|
||||||
if (pCxt->pComCxt->async) {
|
if (pCxt->pComCxt->async) {
|
||||||
uint64_t uid = pStmt->pTableMeta->uid;
|
return insGetTableDataCxt(pStmt->pTableBlockHashObj, &pStmt->pTableMeta->uid, sizeof(pStmt->pTableMeta->uid),
|
||||||
|
pStmt->pTableMeta, &pStmt->pCreateTblReq, pTableCxt, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||||
|
tNameExtractFullName(&pStmt->targetTableName, tbFName);
|
||||||
if (pStmt->usingTableProcessing) {
|
if (pStmt->usingTableProcessing) {
|
||||||
pStmt->pTableMeta->uid = 0;
|
pStmt->pTableMeta->uid = 0;
|
||||||
}
|
}
|
||||||
|
return insGetTableDataCxt(pStmt->pTableBlockHashObj, tbFName, strlen(tbFName), pStmt->pTableMeta,
|
||||||
return insGetDataBlockFromList(
|
&pStmt->pCreateTblReq, pTableCxt, NULL != pCxt->pComCxt->pStmtCb);
|
||||||
pStmt->pTableBlockHashObj, &uid, sizeof(pStmt->pTableMeta->uid), TSDB_DEFAULT_PAYLOAD_SIZE, sizeof(SSubmitBlk),
|
|
||||||
getTableInfo(pStmt->pTableMeta).rowSize, pStmt->pTableMeta, pDataBuf, NULL, &pStmt->createTblReq);
|
|
||||||
}
|
|
||||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
|
||||||
tNameExtractFullName(&pStmt->targetTableName, tbFName);
|
|
||||||
return insGetDataBlockFromList(pStmt->pTableBlockHashObj, tbFName, strlen(tbFName), TSDB_DEFAULT_PAYLOAD_SIZE,
|
|
||||||
sizeof(SSubmitBlk), getTableInfo(pStmt->pTableMeta).rowSize, pStmt->pTableMeta,
|
|
||||||
pDataBuf, NULL, &pStmt->createTblReq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseBoundColumnsClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt,
|
static int32_t parseBoundColumnsClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataCxt* pTableCxt) {
|
||||||
STableDataBlocks* pDataBuf) {
|
|
||||||
SToken token;
|
SToken token;
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
NEXT_TOKEN_KEEP_SQL(pStmt->pSql, token, index);
|
NEXT_TOKEN_KEEP_SQL(pStmt->pSql, token, index);
|
||||||
|
|
@ -1004,13 +968,30 @@ static int32_t parseBoundColumnsClause(SInsertParseContext* pCxt, SVnodeModifyOp
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", token.z);
|
return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", token.z);
|
||||||
}
|
}
|
||||||
// pStmt->pSql -> field1_name, ...)
|
// pStmt->pSql -> field1_name, ...)
|
||||||
return parseBoundColumns(pCxt, &pStmt->pSql, false, &pDataBuf->boundColumnInfo,
|
return parseBoundColumns(pCxt, &pStmt->pSql, false, getTableColumnSchema(pStmt->pTableMeta),
|
||||||
getTableColumnSchema(pStmt->pTableMeta));
|
&pTableCxt->boundColsInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != pStmt->pBoundCols) {
|
if (NULL != pStmt->pBoundCols) {
|
||||||
return parseBoundColumns(pCxt, &pStmt->pBoundCols, false, &pDataBuf->boundColumnInfo,
|
return parseBoundColumns(pCxt, &pStmt->pBoundCols, false, getTableColumnSchema(pStmt->pTableMeta),
|
||||||
getTableColumnSchema(pStmt->pTableMeta));
|
&pTableCxt->boundColsInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t initTableColSubmitData(STableDataCxt* pTableCxt) {
|
||||||
|
if (0 == (pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT)) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pTableCxt->boundColsInfo.numOfBound; ++i) {
|
||||||
|
SSchema* pSchema = &pTableCxt->pMeta->schema[pTableCxt->boundColsInfo.pColIndex[i]];
|
||||||
|
SColData* pCol = taosArrayReserve(pTableCxt->pData->aCol, 1);
|
||||||
|
if (NULL == pCol) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
tColDataInit(pCol, pSchema->colId, pSchema->type, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
@ -1021,13 +1002,16 @@ static int32_t parseBoundColumnsClause(SInsertParseContext* pCxt, SVnodeModifyOp
|
||||||
// 2. VALUES ... | FILE ...
|
// 2. VALUES ... | FILE ...
|
||||||
// output pStmt->pSql: VALUES ... | FILE ...
|
// output pStmt->pSql: VALUES ... | FILE ...
|
||||||
static int32_t parseSchemaClauseBottom(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt,
|
static int32_t parseSchemaClauseBottom(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt,
|
||||||
STableDataBlocks** pDataBuf) {
|
STableDataCxt** pTableCxt) {
|
||||||
int32_t code = parseUsingClauseBottom(pCxt, pStmt);
|
int32_t code = parseUsingClauseBottom(pCxt, pStmt);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = getTableDataBlocks(pCxt, pStmt, pDataBuf);
|
code = getTableDataCxt(pCxt, pStmt, pTableCxt);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = parseBoundColumnsClause(pCxt, pStmt, *pDataBuf);
|
code = parseBoundColumnsClause(pCxt, pStmt, *pTableCxt);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = initTableColSubmitData(*pTableCxt);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -1050,108 +1034,88 @@ static int32_t parseSchemaClauseTop(SInsertParseContext* pCxt, SVnodeModifyOpStm
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, SToken* pToken, SSchema* pSchema,
|
static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, SToken* pToken, SSchema* pSchema,
|
||||||
int16_t timePrec, _row_append_fn_t func, void* param) {
|
int16_t timePrec, SColVal* pVal) {
|
||||||
int64_t iv;
|
|
||||||
uint64_t uv;
|
|
||||||
char* endptr = NULL;
|
|
||||||
|
|
||||||
switch (pSchema->type) {
|
switch (pSchema->type) {
|
||||||
case TSDB_DATA_TYPE_BOOL: {
|
case TSDB_DATA_TYPE_BOOL: {
|
||||||
if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) {
|
if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) {
|
||||||
if (strncmp(pToken->z, "true", pToken->n) == 0) {
|
if (strncmp(pToken->z, "true", pToken->n) == 0) {
|
||||||
return func(&pCxt->msg, &TRUE_VALUE, pSchema->bytes, param);
|
pVal->value.val = TRUE_VALUE;
|
||||||
} else if (strncmp(pToken->z, "false", pToken->n) == 0) {
|
} else if (strncmp(pToken->z, "false", pToken->n) == 0) {
|
||||||
return func(&pCxt->msg, &FALSE_VALUE, pSchema->bytes, param);
|
pVal->value.val = FALSE_VALUE;
|
||||||
} else {
|
} else {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z);
|
||||||
}
|
}
|
||||||
} else if (pToken->type == TK_NK_INTEGER) {
|
} else if (pToken->type == TK_NK_INTEGER) {
|
||||||
return func(&pCxt->msg, ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE),
|
pVal->value.val = ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? FALSE_VALUE : TRUE_VALUE);
|
||||||
pSchema->bytes, param);
|
|
||||||
} else if (pToken->type == TK_NK_FLOAT) {
|
} else if (pToken->type == TK_NK_FLOAT) {
|
||||||
return func(&pCxt->msg, ((taosStr2Double(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes,
|
pVal->value.val = ((taosStr2Double(pToken->z, NULL) == 0) ? FALSE_VALUE : TRUE_VALUE);
|
||||||
param);
|
|
||||||
} else {
|
} else {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_TINYINT: {
|
case TSDB_DATA_TYPE_TINYINT: {
|
||||||
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) {
|
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid tinyint data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid tinyint data", pToken->z);
|
||||||
} else if (!IS_VALID_TINYINT(iv)) {
|
} else if (!IS_VALID_TINYINT(pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "tinyint data overflow", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "tinyint data overflow", pToken->z);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
uint8_t tmpVal = (uint8_t)iv;
|
|
||||||
return func(&pCxt->msg, &tmpVal, pSchema->bytes, param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_UTINYINT: {
|
case TSDB_DATA_TYPE_UTINYINT: {
|
||||||
if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) {
|
if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned tinyint data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned tinyint data", pToken->z);
|
||||||
} else if (uv > UINT8_MAX) {
|
} else if (pVal->value.val > UINT8_MAX) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "unsigned tinyint data overflow", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "unsigned tinyint data overflow", pToken->z);
|
||||||
}
|
}
|
||||||
uint8_t tmpVal = (uint8_t)uv;
|
break;
|
||||||
return func(&pCxt->msg, &tmpVal, pSchema->bytes, param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_SMALLINT: {
|
case TSDB_DATA_TYPE_SMALLINT: {
|
||||||
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) {
|
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid smallint data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid smallint data", pToken->z);
|
||||||
} else if (!IS_VALID_SMALLINT(iv)) {
|
} else if (!IS_VALID_SMALLINT(pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "smallint data overflow", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "smallint data overflow", pToken->z);
|
||||||
}
|
}
|
||||||
int16_t tmpVal = (int16_t)iv;
|
break;
|
||||||
return func(&pCxt->msg, &tmpVal, pSchema->bytes, param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_USMALLINT: {
|
case TSDB_DATA_TYPE_USMALLINT: {
|
||||||
if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) {
|
if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned smallint data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned smallint data", pToken->z);
|
||||||
} else if (uv > UINT16_MAX) {
|
} else if (pVal->value.val > UINT16_MAX) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "unsigned smallint data overflow", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "unsigned smallint data overflow", pToken->z);
|
||||||
}
|
}
|
||||||
uint16_t tmpVal = (uint16_t)uv;
|
break;
|
||||||
return func(&pCxt->msg, &tmpVal, pSchema->bytes, param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_INT: {
|
case TSDB_DATA_TYPE_INT: {
|
||||||
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) {
|
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid int data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid int data", pToken->z);
|
||||||
} else if (!IS_VALID_INT(iv)) {
|
} else if (!IS_VALID_INT(pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "int data overflow", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "int data overflow", pToken->z);
|
||||||
}
|
}
|
||||||
int32_t tmpVal = (int32_t)iv;
|
break;
|
||||||
return func(&pCxt->msg, &tmpVal, pSchema->bytes, param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_UINT: {
|
case TSDB_DATA_TYPE_UINT: {
|
||||||
if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) {
|
if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned int data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned int data", pToken->z);
|
||||||
} else if (uv > UINT32_MAX) {
|
} else if (pVal->value.val > UINT32_MAX) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "unsigned int data overflow", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "unsigned int data overflow", pToken->z);
|
||||||
}
|
}
|
||||||
uint32_t tmpVal = (uint32_t)uv;
|
break;
|
||||||
return func(&pCxt->msg, &tmpVal, pSchema->bytes, param);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_BIGINT: {
|
case TSDB_DATA_TYPE_BIGINT: {
|
||||||
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) {
|
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid bigint data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid bigint data", pToken->z);
|
||||||
}
|
}
|
||||||
return func(&pCxt->msg, &iv, pSchema->bytes, param);
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_UBIGINT: {
|
case TSDB_DATA_TYPE_UBIGINT: {
|
||||||
if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) {
|
if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &pVal->value.val)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned bigint data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned bigint data", pToken->z);
|
||||||
}
|
}
|
||||||
return func(&pCxt->msg, &uv, pSchema->bytes, param);
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_FLOAT: {
|
case TSDB_DATA_TYPE_FLOAT: {
|
||||||
|
char* endptr = NULL;
|
||||||
double dv;
|
double dv;
|
||||||
if (TK_NK_ILLEGAL == toDouble(pToken, &dv, &endptr)) {
|
if (TK_NK_ILLEGAL == toDouble(pToken, &dv, &endptr)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z);
|
||||||
|
|
@ -1160,11 +1124,12 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
|
||||||
isnan(dv)) {
|
isnan(dv)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z);
|
||||||
}
|
}
|
||||||
float tmpVal = (float)dv;
|
float f = dv;
|
||||||
return func(&pCxt->msg, &tmpVal, pSchema->bytes, param);
|
memcpy(&pVal->value.val, &f, sizeof(f));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_DOUBLE: {
|
case TSDB_DATA_TYPE_DOUBLE: {
|
||||||
|
char* endptr = NULL;
|
||||||
double dv;
|
double dv;
|
||||||
if (TK_NK_ILLEGAL == toDouble(pToken, &dv, &endptr)) {
|
if (TK_NK_ILLEGAL == toDouble(pToken, &dv, &endptr)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z);
|
||||||
|
|
@ -1172,49 +1137,76 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
|
||||||
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) {
|
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z);
|
||||||
}
|
}
|
||||||
return func(&pCxt->msg, &dv, pSchema->bytes, param);
|
pVal->value.val = *(int64_t*)&dv;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_BINARY: {
|
case TSDB_DATA_TYPE_BINARY: {
|
||||||
// Too long values will raise the invalid sql error message
|
// Too long values will raise the invalid sql error message
|
||||||
if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) {
|
if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
||||||
}
|
}
|
||||||
|
pVal->value.pData = taosMemoryMalloc(pToken->n);
|
||||||
return func(&pCxt->msg, pToken->z, pToken->n, param);
|
if (NULL == pVal->value.pData) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
memcpy(pVal->value.pData, pToken->z, pToken->n);
|
||||||
|
pVal->value.nData = pToken->n;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_NCHAR: {
|
case TSDB_DATA_TYPE_NCHAR: {
|
||||||
return func(&pCxt->msg, pToken->z, pToken->n, param);
|
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
||||||
|
int32_t len = 0;
|
||||||
|
char* pUcs4 = taosMemoryCalloc(1, pSchema->bytes - VARSTR_HEADER_SIZE);
|
||||||
|
if (NULL == pUcs4) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, pSchema->bytes - VARSTR_HEADER_SIZE, &len)) {
|
||||||
|
if (errno == E2BIG) {
|
||||||
|
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
||||||
|
}
|
||||||
|
char buf[512] = {0};
|
||||||
|
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
||||||
|
return buildSyntaxErrMsg(&pCxt->msg, buf, pToken->z);
|
||||||
|
}
|
||||||
|
pVal->value.pData = pUcs4;
|
||||||
|
pVal->value.nData = len;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case TSDB_DATA_TYPE_JSON: {
|
case TSDB_DATA_TYPE_JSON: {
|
||||||
if (pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
if (pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "json string too long than 4095", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "json string too long than 4095", pToken->z);
|
||||||
}
|
}
|
||||||
return func(&pCxt->msg, pToken->z, pToken->n, param);
|
pVal->value.pData = taosMemoryMalloc(pToken->n);
|
||||||
|
if (NULL == pVal->value.pData) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
memcpy(pVal->value.pData, pToken->z, pToken->n);
|
||||||
|
pVal->value.nData = pToken->n;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||||
int64_t tmpVal;
|
if (parseTime(pSql, pToken, timePrec, &pVal->value.val, &pCxt->msg) != TSDB_CODE_SUCCESS) {
|
||||||
if (parseTime(pSql, pToken, timePrec, &tmpVal, &pCxt->msg) != TSDB_CODE_SUCCESS) {
|
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid timestamp", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "invalid timestamp", pToken->z);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
return func(&pCxt->msg, &tmpVal, pSchema->bytes, param);
|
|
||||||
}
|
}
|
||||||
}
|
default:
|
||||||
|
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pVal->flag = CV_FLAG_VALUE;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t parseValueToken(SInsertParseContext* pCxt, const char** pSql, SToken* pToken, SSchema* pSchema,
|
static int32_t parseValueToken(SInsertParseContext* pCxt, const char** pSql, SToken* pToken, SSchema* pSchema,
|
||||||
int16_t timePrec, _row_append_fn_t func, void* param) {
|
int16_t timePrec, SColVal* pVal) {
|
||||||
int32_t code = checkAndTrimValue(pToken, pCxt->tmpTokenBuf, &pCxt->msg);
|
int32_t code = checkAndTrimValue(pToken, pCxt->tmpTokenBuf, &pCxt->msg);
|
||||||
if (TSDB_CODE_SUCCESS == code && isNullValue(pSchema->type, pToken)) {
|
if (TSDB_CODE_SUCCESS == code && isNullValue(pSchema->type, pToken)) {
|
||||||
if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) {
|
if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "primary timestamp should not be null", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "primary timestamp should not be null", pToken->z);
|
||||||
}
|
}
|
||||||
|
pVal->flag = CV_FLAG_NULL;
|
||||||
return func(&pCxt->msg, NULL, 0, param);
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) {
|
if (TSDB_CODE_SUCCESS == code && IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) {
|
||||||
|
|
@ -1222,26 +1214,34 @@ static int32_t parseValueToken(SInsertParseContext* pCxt, const char** pSql, STo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = parseValueTokenImpl(pCxt, pSql, pToken, pSchema, timePrec, func, param);
|
code = parseValueTokenImpl(pCxt, pSql, pToken, pSchema, timePrec, pVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parseOneRow(SInsertParseContext* pCxt, const char** pSql, STableDataBlocks* pDataBuf, bool* pGotRow,
|
static void clearColValArray(SArray* pCols) {
|
||||||
SToken* pToken) {
|
int32_t num = taosArrayGetSize(pCols);
|
||||||
SRowBuilder* pBuilder = &pDataBuf->rowBuilder;
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
STSRow* row = (STSRow*)(pDataBuf->pData + pDataBuf->size); // skip the SSubmitBlk header
|
SColVal* pCol = taosArrayGet(pCols, i);
|
||||||
SParsedDataColInfo* pCols = &pDataBuf->boundColumnInfo;
|
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||||
bool isParseBindParam = false;
|
taosMemoryFreeClear(pCol->value.pData);
|
||||||
SSchema* pSchemas = getTableColumnSchema(pDataBuf->pTableMeta);
|
}
|
||||||
SMemParam param = {.rb = pBuilder};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32_t code = tdSRowResetBuf(pBuilder, row);
|
static int parseOneRow(SInsertParseContext* pCxt, const char** pSql, STableDataCxt* pTableCxt, bool* pGotRow,
|
||||||
|
SToken* pToken) {
|
||||||
|
SBoundColInfo* pCols = &pTableCxt->boundColsInfo;
|
||||||
|
bool isParseBindParam = false;
|
||||||
|
SSchema* pSchemas = getTableColumnSchema(pTableCxt->pMeta);
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
// 1. set the parsed value from sql string
|
// 1. set the parsed value from sql string
|
||||||
for (int i = 0; i < pCols->numOfBound && TSDB_CODE_SUCCESS == code; ++i) {
|
for (int i = 0; i < pCols->numOfBound && TSDB_CODE_SUCCESS == code; ++i) {
|
||||||
NEXT_TOKEN_WITH_PREV(*pSql, *pToken);
|
NEXT_TOKEN_WITH_PREV(*pSql, *pToken);
|
||||||
SSchema* pSchema = &pSchemas[pCols->boundColumns[i]];
|
SSchema* pSchema = &pSchemas[pCols->pColIndex[i]];
|
||||||
|
SColVal* pVal = taosArrayGet(pTableCxt->pValues, pCols->pColIndex[i]);
|
||||||
|
|
||||||
if (pToken->type == TK_NK_QUESTION) {
|
if (pToken->type == TK_NK_QUESTION) {
|
||||||
isParseBindParam = true;
|
isParseBindParam = true;
|
||||||
|
|
@ -1260,10 +1260,7 @@ static int parseOneRow(SInsertParseContext* pCxt, const char** pSql, STableDataB
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
param.schema = pSchema;
|
code = parseValueToken(pCxt, pSql, pToken, pSchema, getTableInfo(pTableCxt->pMeta).precision, pVal);
|
||||||
insGetSTSRowAppendInfo(pBuilder->rowType, pCols, i, ¶m.toffset, ¶m.colIdx);
|
|
||||||
code = parseValueToken(pCxt, pSql, pToken, pSchema, getTableInfo(pDataBuf->pTableMeta).precision, insMemRowAppend,
|
|
||||||
¶m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && i < pCols->numOfBound - 1) {
|
if (TSDB_CODE_SUCCESS == code && i < pCols->numOfBound - 1) {
|
||||||
|
|
@ -1274,65 +1271,28 @@ static int parseOneRow(SInsertParseContext* pCxt, const char** pSql, STableDataB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code && !isParseBindParam) {
|
||||||
|
SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1);
|
||||||
|
code = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
TSKEY tsKey = TD_ROW_KEY(row);
|
insCheckTableDataOrder(pTableCxt, TD_ROW_KEY(*pRow));
|
||||||
code = insCheckTimestamp(pDataBuf, (const char*)&tsKey);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && !isParseBindParam) {
|
if (TSDB_CODE_SUCCESS == code && !isParseBindParam) {
|
||||||
// set the null value for the columns that do not assign values
|
|
||||||
if ((pCols->numOfBound < pCols->numOfCols) && TD_IS_TP_ROW(row)) {
|
|
||||||
pBuilder->hasNone = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
tdSRowEnd(pBuilder);
|
|
||||||
|
|
||||||
*pGotRow = true;
|
*pGotRow = true;
|
||||||
|
|
||||||
#ifdef TD_DEBUG_PRINT_ROW
|
|
||||||
STSchema* pSTSchema = tdGetSTSChemaFromSSChema(schema, spd->numOfCols, 1);
|
|
||||||
tdSRowPrint(row, pSTSchema, __func__);
|
|
||||||
taosMemoryFree(pSTSchema);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearColValArray(pTableCxt->pValues);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t allocateMemIfNeed(STableDataBlocks* pDataBlock, int32_t rowSize, int32_t* numOfRows) {
|
|
||||||
size_t remain = pDataBlock->nAllocSize - pDataBlock->size;
|
|
||||||
const int factor = 5;
|
|
||||||
uint32_t nAllocSizeOld = pDataBlock->nAllocSize;
|
|
||||||
|
|
||||||
// expand the allocated size
|
|
||||||
if (remain < rowSize * factor) {
|
|
||||||
while (remain < rowSize * factor) {
|
|
||||||
pDataBlock->nAllocSize = (uint32_t)(pDataBlock->nAllocSize * 1.5);
|
|
||||||
remain = pDataBlock->nAllocSize - pDataBlock->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize);
|
|
||||||
if (tmp != NULL) {
|
|
||||||
pDataBlock->pData = tmp;
|
|
||||||
memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size);
|
|
||||||
} else {
|
|
||||||
// do nothing, if allocate more memory failed
|
|
||||||
pDataBlock->nAllocSize = nAllocSizeOld;
|
|
||||||
*numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize;
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
|
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
|
||||||
static int32_t parseValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataBlocks* pDataBuf,
|
static int32_t parseValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataCxt* pTableCxt,
|
||||||
int32_t maxRows, int32_t* pNumOfRows, SToken* pToken) {
|
int32_t* pNumOfRows, SToken* pToken) {
|
||||||
int32_t code = insInitRowBuilder(&pDataBuf->rowBuilder, pDataBuf->pTableMeta->sversion, &pDataBuf->boundColumnInfo);
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
int32_t extendedRowSize = insGetExtendedRowSize(pDataBuf);
|
|
||||||
(*pNumOfRows) = 0;
|
(*pNumOfRows) = 0;
|
||||||
while (TSDB_CODE_SUCCESS == code) {
|
while (TSDB_CODE_SUCCESS == code) {
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
|
|
@ -1342,13 +1302,9 @@ static int32_t parseValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt,
|
||||||
}
|
}
|
||||||
pStmt->pSql += index;
|
pStmt->pSql += index;
|
||||||
|
|
||||||
if ((*pNumOfRows) >= maxRows || pDataBuf->size + extendedRowSize >= pDataBuf->nAllocSize) {
|
|
||||||
code = allocateMemIfNeed(pDataBuf, extendedRowSize, &maxRows);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool gotRow = false;
|
bool gotRow = false;
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = parseOneRow(pCxt, &pStmt->pSql, pDataBuf, &gotRow, pToken);
|
code = parseOneRow(pCxt, &pStmt->pSql, pTableCxt, &gotRow, pToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
|
@ -1361,7 +1317,6 @@ static int32_t parseValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && gotRow) {
|
if (TSDB_CODE_SUCCESS == code && gotRow) {
|
||||||
pDataBuf->size += extendedRowSize;
|
|
||||||
(*pNumOfRows)++;
|
(*pNumOfRows)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1374,19 +1329,11 @@ static int32_t parseValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// VALUES (field1_value, ...) [(field1_value2, ...) ...]
|
// VALUES (field1_value, ...) [(field1_value2, ...) ...]
|
||||||
static int32_t parseValuesClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataBlocks* pDataBuf,
|
static int32_t parseValuesClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataCxt* pTableCxt,
|
||||||
SToken* pToken) {
|
SToken* pToken) {
|
||||||
int32_t maxNumOfRows = 0;
|
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
int32_t code = allocateMemIfNeed(pDataBuf, insGetExtendedRowSize(pDataBuf), &maxNumOfRows);
|
int32_t code = parseValues(pCxt, pStmt, pTableCxt, &numOfRows, pToken);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = parseValues(pCxt, pStmt, pDataBuf, maxNumOfRows, &numOfRows, pToken);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
|
||||||
code = insSetBlockInfo((SSubmitBlk*)(pDataBuf->pData), pDataBuf, numOfRows, &pCxt->msg);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
|
||||||
pDataBuf->numOfTables = 1;
|
|
||||||
pStmt->totalRowsNum += numOfRows;
|
pStmt->totalRowsNum += numOfRows;
|
||||||
pStmt->totalTbNum += 1;
|
pStmt->totalTbNum += 1;
|
||||||
TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_INSERT);
|
TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_INSERT);
|
||||||
|
|
@ -1394,11 +1341,9 @@ static int32_t parseValuesClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataBlocks* pDataBuf,
|
static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataCxt* pTableCxt,
|
||||||
int maxRows, int32_t* pNumOfRows) {
|
int32_t* pNumOfRows) {
|
||||||
int32_t code = insInitRowBuilder(&pDataBuf->rowBuilder, pDataBuf->pTableMeta->sversion, &pDataBuf->boundColumnInfo);
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
int32_t extendedRowSize = insGetExtendedRowSize(pDataBuf);
|
|
||||||
(*pNumOfRows) = 0;
|
(*pNumOfRows) = 0;
|
||||||
char* pLine = NULL;
|
char* pLine = NULL;
|
||||||
int64_t readLen = 0;
|
int64_t readLen = 0;
|
||||||
|
|
@ -1414,16 +1359,13 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*pNumOfRows) >= maxRows || pDataBuf->size + extendedRowSize >= pDataBuf->nAllocSize) {
|
|
||||||
code = allocateMemIfNeed(pDataBuf, extendedRowSize, &maxRows);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool gotRow = false;
|
bool gotRow = false;
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
SToken token;
|
SToken token;
|
||||||
strtolower(pLine, pLine);
|
strtolower(pLine, pLine);
|
||||||
const char* pRow = pLine;
|
const char* pRow = pLine;
|
||||||
code = parseOneRow(pCxt, (const char**)&pRow, pDataBuf, &gotRow, &token);
|
|
||||||
|
code = parseOneRow(pCxt, (const char**)&pRow, pTableCxt, &gotRow, &token);
|
||||||
if (code && firstLine) {
|
if (code && firstLine) {
|
||||||
firstLine = false;
|
firstLine = false;
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
@ -1432,11 +1374,10 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && gotRow) {
|
if (TSDB_CODE_SUCCESS == code && gotRow) {
|
||||||
pDataBuf->size += extendedRowSize;
|
|
||||||
(*pNumOfRows)++;
|
(*pNumOfRows)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && pDataBuf->nAllocSize > tsMaxMemUsedByInsert * 1024 * 1024) {
|
if (TSDB_CODE_SUCCESS == code && (*pNumOfRows) > tsMaxMemUsedByInsert * 1024 * 1024) {
|
||||||
pStmt->fileProcessing = true;
|
pStmt->fileProcessing = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1452,18 +1393,10 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataBlocks* pDataBuf) {
|
static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataCxt* pTableCxt) {
|
||||||
int32_t maxNumOfRows = 0;
|
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
int32_t code = allocateMemIfNeed(pDataBuf, insGetExtendedRowSize(pDataBuf), &maxNumOfRows);
|
int32_t code = parseCsvFile(pCxt, pStmt, pTableCxt, &numOfRows);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = parseCsvFile(pCxt, pStmt, pDataBuf, maxNumOfRows, &numOfRows);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
|
||||||
code = insSetBlockInfo((SSubmitBlk*)(pDataBuf->pData), pDataBuf, numOfRows, &pCxt->msg);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
|
||||||
pDataBuf->numOfTables = 1;
|
|
||||||
pStmt->totalRowsNum += numOfRows;
|
pStmt->totalRowsNum += numOfRows;
|
||||||
pStmt->totalTbNum += 1;
|
pStmt->totalTbNum += 1;
|
||||||
TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_FILE_INSERT);
|
TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_FILE_INSERT);
|
||||||
|
|
@ -1477,7 +1410,7 @@ static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifyOpSt
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseDataFromFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SToken* pFilePath,
|
static int32_t parseDataFromFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SToken* pFilePath,
|
||||||
STableDataBlocks* pDataBuf) {
|
STableDataCxt* pTableCxt) {
|
||||||
char filePathStr[TSDB_FILENAME_LEN] = {0};
|
char filePathStr[TSDB_FILENAME_LEN] = {0};
|
||||||
if (TK_NK_STRING == pFilePath->type) {
|
if (TK_NK_STRING == pFilePath->type) {
|
||||||
trimString(pFilePath->z, pFilePath->n, filePathStr, sizeof(filePathStr));
|
trimString(pFilePath->z, pFilePath->n, filePathStr, sizeof(filePathStr));
|
||||||
|
|
@ -1489,10 +1422,10 @@ static int32_t parseDataFromFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseDataFromFileImpl(pCxt, pStmt, pDataBuf);
|
return parseDataFromFileImpl(pCxt, pStmt, pTableCxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseFileClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataBlocks* pDataBuf,
|
static int32_t parseFileClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataCxt* pTableCxt,
|
||||||
SToken* pToken) {
|
SToken* pToken) {
|
||||||
if (tsUseAdapter) {
|
if (tsUseAdapter) {
|
||||||
return buildInvalidOperationMsg(&pCxt->msg, "proxy mode does not support csv loading");
|
return buildInvalidOperationMsg(&pCxt->msg, "proxy mode does not support csv loading");
|
||||||
|
|
@ -1502,18 +1435,18 @@ static int32_t parseFileClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pS
|
||||||
if (0 == pToken->n || (TK_NK_STRING != pToken->type && TK_NK_ID != pToken->type)) {
|
if (0 == pToken->n || (TK_NK_STRING != pToken->type && TK_NK_ID != pToken->type)) {
|
||||||
return buildSyntaxErrMsg(&pCxt->msg, "file path is required following keyword FILE", pToken->z);
|
return buildSyntaxErrMsg(&pCxt->msg, "file path is required following keyword FILE", pToken->z);
|
||||||
}
|
}
|
||||||
return parseDataFromFile(pCxt, pStmt, pToken, pDataBuf);
|
return parseDataFromFile(pCxt, pStmt, pToken, pTableCxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path
|
// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path
|
||||||
static int32_t parseDataClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataBlocks* pDataBuf) {
|
static int32_t parseDataClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, STableDataCxt* pTableCxt) {
|
||||||
SToken token;
|
SToken token;
|
||||||
NEXT_TOKEN(pStmt->pSql, token);
|
NEXT_TOKEN(pStmt->pSql, token);
|
||||||
switch (token.type) {
|
switch (token.type) {
|
||||||
case TK_VALUES:
|
case TK_VALUES:
|
||||||
return parseValuesClause(pCxt, pStmt, pDataBuf, &token);
|
return parseValuesClause(pCxt, pStmt, pTableCxt, &token);
|
||||||
case TK_FILE:
|
case TK_FILE:
|
||||||
return parseFileClause(pCxt, pStmt, pDataBuf, &token);
|
return parseFileClause(pCxt, pStmt, pTableCxt, &token);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1524,18 +1457,19 @@ static int32_t parseDataClause(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pS
|
||||||
// 1. [(tag1_name, ...)] ...
|
// 1. [(tag1_name, ...)] ...
|
||||||
// 2. VALUES ... | FILE ...
|
// 2. VALUES ... | FILE ...
|
||||||
static int32_t parseInsertTableClauseBottom(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
static int32_t parseInsertTableClauseBottom(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||||
STableDataBlocks* pDataBuf = NULL;
|
STableDataCxt* pTableCxt = NULL;
|
||||||
int32_t code = parseSchemaClauseBottom(pCxt, pStmt, &pDataBuf);
|
int32_t code = parseSchemaClauseBottom(pCxt, pStmt, &pTableCxt);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = parseDataClause(pCxt, pStmt, pDataBuf);
|
code = parseDataClause(pCxt, pStmt, pTableCxt);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resetEnvPreTable(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
static void resetEnvPreTable(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||||
destroyBoundColumnInfo(&pCxt->tags);
|
destroyBoundColInfo(&pCxt->tags);
|
||||||
taosMemoryFreeClear(pStmt->pTableMeta);
|
taosMemoryFreeClear(pStmt->pTableMeta);
|
||||||
tdDestroySVCreateTbReq(&pStmt->createTblReq);
|
tdDestroySVCreateTbReq(pStmt->pCreateTblReq);
|
||||||
|
taosMemoryFreeClear(pStmt->pCreateTblReq);
|
||||||
pCxt->missCache = false;
|
pCxt->missCache = false;
|
||||||
pCxt->usingDuplicateTable = false;
|
pCxt->usingDuplicateTable = false;
|
||||||
pStmt->pBoundCols = NULL;
|
pStmt->pBoundCols = NULL;
|
||||||
|
|
@ -1616,13 +1550,11 @@ static int32_t parseInsertBodyBottom(SInsertParseContext* pCxt, SVnodeModifyOpSt
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge according to vgId
|
// merge according to vgId
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = insMergeTableDataCxt(pStmt->pTableBlockHashObj, &pStmt->pVgDataBlocks);
|
||||||
if (taosHashGetSize(pStmt->pTableBlockHashObj) > 0) {
|
|
||||||
code = insMergeTableDataBlocks(pStmt->pTableBlockHashObj, &pStmt->pVgDataBlocks);
|
|
||||||
}
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = insBuildOutput(pStmt->pVgroupsHashObj, pStmt->pVgDataBlocks, &pStmt->pDataBlocks);
|
code = insBuildVgDataBlocks(pStmt->pVgroupsHashObj, pStmt->pVgDataBlocks, &pStmt->pDataBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1663,8 +1595,8 @@ static int32_t createVnodeModifOpStmt(SInsertParseContext* pCxt, bool reentry, S
|
||||||
TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT);
|
TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT);
|
||||||
}
|
}
|
||||||
pStmt->pSql = pCxt->pComCxt->pSql;
|
pStmt->pSql = pCxt->pComCxt->pSql;
|
||||||
pStmt->freeHashFunc = insDestroyBlockHashmap;
|
pStmt->freeHashFunc = insDestroyTableDataCxtHashMap;
|
||||||
pStmt->freeArrayFunc = insDestroyBlockArrayList;
|
pStmt->freeArrayFunc = insDestroyVgroupDataCxtList;
|
||||||
|
|
||||||
if (!reentry) {
|
if (!reentry) {
|
||||||
pStmt->pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
pStmt->pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||||
|
|
@ -1878,10 +1810,10 @@ static int32_t parseInsertSqlFromStart(SInsertParseContext* pCxt, SVnodeModifyOp
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t parseInsertSqlFromCsv(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
static int32_t parseInsertSqlFromCsv(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||||
STableDataBlocks* pDataBuf = NULL;
|
STableDataCxt* pTableCxt = NULL;
|
||||||
int32_t code = getTableDataBlocks(pCxt, pStmt, &pDataBuf);
|
int32_t code = getTableDataCxt(pCxt, pStmt, &pTableCxt);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = parseDataFromFileImpl(pCxt, pStmt, pDataBuf);
|
code = parseDataFromFileImpl(pCxt, pStmt, pTableCxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
|
@ -2005,6 +1937,6 @@ int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatal
|
||||||
QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) {
|
QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) {
|
||||||
code = setRefreshMate(*pQuery);
|
code = setRefreshMate(*pQuery);
|
||||||
}
|
}
|
||||||
destroyBoundColumnInfo(&context.tags);
|
destroyBoundColInfo(&context.tags);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,26 +29,53 @@ typedef struct SKvParam {
|
||||||
char buf[TSDB_MAX_TAGS_LEN];
|
char buf[TSDB_MAX_TAGS_LEN];
|
||||||
} SKvParam;
|
} SKvParam;
|
||||||
|
|
||||||
|
int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData) {
|
||||||
|
*pData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
|
||||||
|
if (NULL == *pData) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSubmitTbData* pNew = *pData;
|
||||||
|
|
||||||
|
*pNew = *pDataBlock->pData;
|
||||||
|
|
||||||
|
cloneSVreateTbReq(pDataBlock->pData->pCreateTbReq, &pNew->pCreateTbReq);
|
||||||
|
pNew->aCol = taosArrayDup(pDataBlock->pData->aCol, NULL);
|
||||||
|
|
||||||
|
int32_t colNum = taosArrayGetSize(pNew->aCol);
|
||||||
|
for (int32_t i = 0; i < colNum; ++i) {
|
||||||
|
SColData* pCol = (SColData*)taosArrayGet(pNew->aCol, i);
|
||||||
|
tColDataDeepClear(pCol);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) {
|
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SArray* pVgDataBlocks = NULL;
|
SArray* pVgDataBlocks = NULL;
|
||||||
|
SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)pQuery->pRoot;
|
||||||
|
|
||||||
// merge according to vgId
|
// merge according to vgId
|
||||||
if (taosHashGetSize(pBlockHash) > 0) {
|
if (taosHashGetSize(pBlockHash) > 0) {
|
||||||
code = insMergeTableDataBlocks(pBlockHash, &pVgDataBlocks);
|
code = insMergeTableDataCxt(pBlockHash, &pVgDataBlocks);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = insBuildOutput(pVgHash, pVgDataBlocks, &((SVnodeModifyOpStmt*)pQuery->pRoot)->pDataBlocks);
|
code = insBuildVgDataBlocks(pVgHash, pVgDataBlocks, &pStmt->pDataBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pStmt->freeArrayFunc) {
|
||||||
|
pStmt->freeArrayFunc(pVgDataBlocks);
|
||||||
}
|
}
|
||||||
insDestroyBlockArrayList(pVgDataBlocks);
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
|
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
|
||||||
TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen) {
|
TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
SBoundColInfo* tags = (SBoundColInfo*)boundTags;
|
||||||
if (NULL == tags) {
|
if (NULL == tags) {
|
||||||
return TSDB_CODE_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +91,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta);
|
SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta);
|
||||||
|
|
||||||
bool isJson = false;
|
bool isJson = false;
|
||||||
STag* pTag = NULL;
|
STag* pTag = NULL;
|
||||||
|
|
@ -74,7 +101,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* pTagSchema = &pSchema[tags->boundColumns[c]];
|
SSchema* pTagSchema = &pSchema[tags->pColIndex[c]];
|
||||||
int32_t colLen = pTagSchema->bytes;
|
int32_t colLen = pTagSchema->bytes;
|
||||||
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
|
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
|
||||||
colLen = bind[c].length[0];
|
colLen = bind[c].length[0];
|
||||||
|
|
@ -136,11 +163,16 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
SVCreateTbReq tbReq = {0};
|
if (NULL == pDataBlock->pData->pCreateTbReq) {
|
||||||
insBuildCreateTbReq(&tbReq, tName, pTag, suid, sTableName, tagName, pDataBlock->pTableMeta->tableInfo.numOfTags,
|
pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
|
||||||
TSDB_DEFAULT_TABLE_TTL);
|
if (NULL == pDataBlock->pData->pCreateTbReq) {
|
||||||
code = insBuildCreateTbMsg(pDataBlock, &tbReq);
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tdDestroySVCreateTbReq(&tbReq);
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
insBuildCreateTbReq(pDataBlock->pData->pCreateTbReq, tName, pTag, suid, sTableName, tagName,
|
||||||
|
pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
|
for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
|
||||||
|
|
@ -155,199 +187,178 @@ end:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t convertStmtNcharCol(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_MULTI_BIND* src, TAOS_MULTI_BIND* dst) {
|
||||||
|
int32_t output = 0;
|
||||||
|
int32_t newBuflen = (pSchema->bytes - VARSTR_HEADER_SIZE) * src->num;
|
||||||
|
if (dst->buffer_length < newBuflen) {
|
||||||
|
dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen);
|
||||||
|
if (NULL == dst->buffer) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL == dst->length) {
|
||||||
|
dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num);
|
||||||
|
if (NULL == dst->buffer) {
|
||||||
|
taosMemoryFreeClear(dst->buffer);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dst->buffer_length = pSchema->bytes - VARSTR_HEADER_SIZE;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < src->num; ++i) {
|
||||||
|
if (src->is_null && src->is_null[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i],
|
||||||
|
(TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {
|
||||||
|
if (errno == E2BIG) {
|
||||||
|
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
|
||||||
|
}
|
||||||
|
char buf[512] = {0};
|
||||||
|
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
||||||
|
return buildSyntaxErrMsg(pMsgBuf, buf, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
dst->length[i] = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
dst->buffer_type = src->buffer_type;
|
||||||
|
dst->is_null = src->is_null;
|
||||||
|
dst->num = src->num;
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t qBindStmtColsValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen) {
|
int32_t qBindStmtColsValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta);
|
||||||
int32_t extendedRowSize = insGetExtendedRowSize(pDataBlock);
|
SBoundColInfo* boundInfo = &pDataBlock->boundColsInfo;
|
||||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
|
||||||
SRowBuilder* pBuilder = &pDataBlock->rowBuilder;
|
|
||||||
SMemParam param = {.rb = pBuilder};
|
|
||||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||||
int32_t rowNum = bind->num;
|
int32_t rowNum = bind->num;
|
||||||
|
TAOS_MULTI_BIND ncharBind = {0};
|
||||||
|
TAOS_MULTI_BIND* pBind = NULL;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
CHECK_CODE(
|
for (int c = 0; c < boundInfo->numOfBound; ++c) {
|
||||||
insInitRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo));
|
SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]];
|
||||||
|
SColData* pCol = taosArrayGet(pDataBlock->pData->aCol, c);
|
||||||
CHECK_CODE(insAllocateMemForSize(pDataBlock, extendedRowSize * bind->num));
|
|
||||||
|
|
||||||
for (int32_t r = 0; r < bind->num; ++r) {
|
|
||||||
STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size); // skip the SSubmitBlk header
|
|
||||||
tdSRowResetBuf(pBuilder, row);
|
|
||||||
|
|
||||||
for (int c = 0; c < spd->numOfBound; ++c) {
|
|
||||||
SSchema* pColSchema = &pSchema[spd->boundColumns[c]];
|
|
||||||
|
|
||||||
if (bind[c].num != rowNum) {
|
if (bind[c].num != rowNum) {
|
||||||
return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
|
code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
|
||||||
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
param.schema = pColSchema;
|
|
||||||
insGetSTSRowAppendInfo(pBuilder->rowType, spd, c, ¶m.toffset, ¶m.colIdx);
|
|
||||||
|
|
||||||
if (bind[c].is_null && bind[c].is_null[r]) {
|
|
||||||
if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
|
||||||
return buildInvalidOperationMsg(&pBuf, "primary timestamp should not be NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_CODE(insMemRowAppend(&pBuf, NULL, 0, ¶m));
|
|
||||||
} else {
|
|
||||||
if (bind[c].buffer_type != pColSchema->type) {
|
if (bind[c].buffer_type != pColSchema->type) {
|
||||||
return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
|
code = buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
|
||||||
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t colLen = pColSchema->bytes;
|
if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
|
||||||
if (IS_VAR_DATA_TYPE(pColSchema->type)) {
|
code = convertStmtNcharCol(&pBuf, pColSchema, bind + c, &ncharBind);
|
||||||
colLen = bind[c].length[r];
|
if (code) {
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
pBind = &ncharBind;
|
||||||
|
} else {
|
||||||
|
pBind = bind + c;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_CODE(insMemRowAppend(&pBuf, (char*)bind[c].buffer + bind[c].buffer_length * r, colLen, ¶m));
|
tColDataAddValueByBind(pCol, pBind);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) {
|
qDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);
|
||||||
TSKEY tsKey = TD_ROW_KEY(row);
|
|
||||||
insCheckTimestamp(pDataBlock, (const char*)&tsKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// set the null value for the columns that do not assign values
|
|
||||||
if ((spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) {
|
|
||||||
pBuilder->hasNone = true;
|
|
||||||
}
|
|
||||||
tdSRowEnd(pBuilder);
|
|
||||||
#ifdef TD_DEBUG_PRINT_ROW
|
|
||||||
STSchema* pSTSchema = tdGetSTSChemaFromSSChema(pSchema, spd->numOfCols, 1);
|
|
||||||
tdSRowPrint(row, pSTSchema, __func__);
|
|
||||||
taosMemoryFree(pSTSchema);
|
|
||||||
#endif
|
|
||||||
pDataBlock->size += extendedRowSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData);
|
_return:
|
||||||
return insSetBlockInfo(pBlocks, pDataBlock, bind->num, &pBuf);
|
|
||||||
|
taosMemoryFree(ncharBind.buffer);
|
||||||
|
taosMemoryFree(ncharBind.length);
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx,
|
int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx,
|
||||||
int32_t rowNum) {
|
int32_t rowNum) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta);
|
||||||
int32_t extendedRowSize = insGetExtendedRowSize(pDataBlock);
|
SBoundColInfo* boundInfo = &pDataBlock->boundColsInfo;
|
||||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
|
||||||
SRowBuilder* pBuilder = &pDataBlock->rowBuilder;
|
|
||||||
SMemParam param = {.rb = pBuilder};
|
|
||||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||||
bool rowStart = (0 == colIdx);
|
SSchema* pColSchema = &pSchema[boundInfo->pColIndex[colIdx]];
|
||||||
bool rowEnd = ((colIdx + 1) == spd->numOfBound);
|
SColData* pCol = taosArrayGet(pDataBlock->pData->aCol, colIdx);
|
||||||
|
TAOS_MULTI_BIND ncharBind = {0};
|
||||||
if (rowStart) {
|
TAOS_MULTI_BIND* pBind = NULL;
|
||||||
CHECK_CODE(
|
int32_t code = 0;
|
||||||
insInitRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo));
|
|
||||||
CHECK_CODE(insAllocateMemForSize(pDataBlock, extendedRowSize * bind->num));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t r = 0; r < bind->num; ++r) {
|
|
||||||
STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size + extendedRowSize * r); // skip the SSubmitBlk header
|
|
||||||
if (rowStart) {
|
|
||||||
tdSRowResetBuf(pBuilder, row);
|
|
||||||
} else {
|
|
||||||
tdSRowGetBuf(pBuilder, row);
|
|
||||||
}
|
|
||||||
|
|
||||||
SSchema* pColSchema = &pSchema[spd->boundColumns[colIdx]];
|
|
||||||
|
|
||||||
if (bind->num != rowNum) {
|
if (bind->num != rowNum) {
|
||||||
return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
|
return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
|
||||||
}
|
}
|
||||||
|
|
||||||
param.schema = pColSchema;
|
|
||||||
insGetSTSRowAppendInfo(pBuilder->rowType, spd, colIdx, ¶m.toffset, ¶m.colIdx);
|
|
||||||
|
|
||||||
if (bind->is_null && bind->is_null[r]) {
|
|
||||||
if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
|
||||||
return buildInvalidOperationMsg(&pBuf, "primary timestamp should not be NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK_CODE(insMemRowAppend(&pBuf, NULL, 0, ¶m));
|
|
||||||
} else {
|
|
||||||
if (bind->buffer_type != pColSchema->type) {
|
if (bind->buffer_type != pColSchema->type) {
|
||||||
return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
|
return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t colLen = pColSchema->bytes;
|
if (TSDB_DATA_TYPE_NCHAR == pColSchema->type) {
|
||||||
if (IS_VAR_DATA_TYPE(pColSchema->type)) {
|
code = convertStmtNcharCol(&pBuf, pColSchema, bind, &ncharBind);
|
||||||
colLen = bind->length[r];
|
if (code) {
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
pBind = &ncharBind;
|
||||||
|
} else {
|
||||||
|
pBind = bind;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_CODE(insMemRowAppend(&pBuf, (char*)bind->buffer + bind->buffer_length * r, colLen, ¶m));
|
tColDataAddValueByBind(pCol, pBind);
|
||||||
|
|
||||||
|
qDebug("stmt col %d bind %d rows data", colIdx, rowNum);
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
taosMemoryFree(ncharBind.buffer);
|
||||||
|
taosMemoryFree(ncharBind.length);
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) {
|
int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSchema, int32_t* fieldNum,
|
||||||
TSKEY tsKey = TD_ROW_KEY(row);
|
TAOS_FIELD_E** fields, uint8_t timePrec) {
|
||||||
insCheckTimestamp(pDataBlock, (const char*)&tsKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the null value for the columns that do not assign values
|
|
||||||
if (rowEnd && (spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) {
|
|
||||||
pBuilder->hasNone = true;
|
|
||||||
}
|
|
||||||
if (rowEnd) {
|
|
||||||
tdSRowEnd(pBuilder);
|
|
||||||
}
|
|
||||||
#ifdef TD_DEBUG_PRINT_ROW
|
|
||||||
if (rowEnd) {
|
|
||||||
STSchema* pSTSchema = tdGetSTSChemaFromSSChema(pSchema, spd->numOfCols, 1);
|
|
||||||
tdSRowPrint(row, pSTSchema, __func__);
|
|
||||||
taosMemoryFree(pSTSchema);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rowEnd) {
|
|
||||||
pDataBlock->size += extendedRowSize * bind->num;
|
|
||||||
|
|
||||||
SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData);
|
|
||||||
CHECK_CODE(insSetBlockInfo(pBlocks, pDataBlock, bind->num, &pBuf));
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t buildBoundFields(SParsedDataColInfo* boundInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD_E** fields,
|
|
||||||
uint8_t timePrec) {
|
|
||||||
if (fields) {
|
if (fields) {
|
||||||
*fields = taosMemoryCalloc(boundInfo->numOfBound, sizeof(TAOS_FIELD));
|
*fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_E));
|
||||||
if (NULL == *fields) {
|
if (NULL == *fields) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* schema = &pSchema[boundInfo->boundColumns[0]];
|
SSchema* schema = &pSchema[boundColumns[0]];
|
||||||
if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
|
if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
|
||||||
(*fields)[0].precision = timePrec;
|
(*fields)[0].precision = timePrec;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < boundInfo->numOfBound; ++i) {
|
for (int32_t i = 0; i < numOfBound; ++i) {
|
||||||
schema = &pSchema[boundInfo->boundColumns[i]];
|
schema = &pSchema[boundColumns[i]];
|
||||||
strcpy((*fields)[i].name, schema->name);
|
strcpy((*fields)[i].name, schema->name);
|
||||||
(*fields)[i].type = schema->type;
|
(*fields)[i].type = schema->type;
|
||||||
(*fields)[i].bytes = schema->bytes;
|
(*fields)[i].bytes = schema->bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*fieldNum = boundInfo->numOfBound;
|
*fieldNum = numOfBound;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields) {
|
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
SBoundColInfo* tags = (SBoundColInfo*)boundTags;
|
||||||
if (NULL == tags) {
|
if (NULL == tags) {
|
||||||
return TSDB_CODE_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDataBlock->pTableMeta->tableType != TSDB_SUPER_TABLE && pDataBlock->pTableMeta->tableType != TSDB_CHILD_TABLE) {
|
if (pDataBlock->pMeta->tableType != TSDB_SUPER_TABLE && pDataBlock->pMeta->tableType != TSDB_CHILD_TABLE) {
|
||||||
return TSDB_CODE_TSC_STMT_API_ERROR;
|
return TSDB_CODE_TSC_STMT_API_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta);
|
SSchema* pSchema = getTableTagSchema(pDataBlock->pMeta);
|
||||||
if (tags->numOfBound <= 0) {
|
if (tags->numOfBound <= 0) {
|
||||||
*fieldNum = 0;
|
*fieldNum = 0;
|
||||||
*fields = NULL;
|
*fields = NULL;
|
||||||
|
|
@ -355,15 +366,15 @@ int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TA
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_CODE(buildBoundFields(tags, pSchema, fieldNum, fields, 0));
|
CHECK_CODE(buildBoundFields(tags->numOfBound, tags->pColIndex, pSchema, fieldNum, fields, 0));
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fields) {
|
int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fields) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta);
|
||||||
if (pDataBlock->boundColumnInfo.numOfBound <= 0) {
|
if (pDataBlock->boundColsInfo.numOfBound <= 0) {
|
||||||
*fieldNum = 0;
|
*fieldNum = 0;
|
||||||
if (fields) {
|
if (fields) {
|
||||||
*fields = NULL;
|
*fields = NULL;
|
||||||
|
|
@ -372,107 +383,125 @@ int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fiel
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_CODE(buildBoundFields(&pDataBlock->boundColumnInfo, pSchema, fieldNum, fields,
|
CHECK_CODE(buildBoundFields(pDataBlock->boundColsInfo.numOfBound, pDataBlock->boundColsInfo.pColIndex, pSchema,
|
||||||
pDataBlock->pTableMeta->tableInfo.precision));
|
fieldNum, fields, pDataBlock->pMeta->tableInfo.precision));
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
int32_t qResetStmtDataBlock(STableDataCxt* block, bool deepClear) {
|
||||||
STableDataBlocks* pBlock = (STableDataBlocks*)block;
|
STableDataCxt* pBlock = (STableDataCxt*)block;
|
||||||
|
int32_t colNum = taosArrayGetSize(pBlock->pData->aCol);
|
||||||
|
|
||||||
if (keepBuf) {
|
for (int32_t i = 0; i < colNum; ++i) {
|
||||||
taosMemoryFreeClear(pBlock->pData);
|
SColData* pCol = (SColData*)taosArrayGet(pBlock->pData->aCol, i);
|
||||||
pBlock->pData = taosMemoryMalloc(TSDB_PAYLOAD_SIZE);
|
if (deepClear) {
|
||||||
if (NULL == pBlock->pData) {
|
tColDataDeepClear(pCol);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
memset(pBlock->pData, 0, sizeof(SSubmitBlk));
|
|
||||||
} else {
|
} else {
|
||||||
pBlock->pData = NULL;
|
tColDataClear(pCol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlock->ordered = true;
|
|
||||||
pBlock->prevTS = INT64_MIN;
|
|
||||||
pBlock->size = sizeof(SSubmitBlk);
|
|
||||||
pBlock->tsSource = -1;
|
|
||||||
pBlock->numOfTables = 1;
|
|
||||||
pBlock->nAllocSize = TSDB_PAYLOAD_SIZE;
|
|
||||||
pBlock->headerSize = pBlock->size;
|
|
||||||
pBlock->createTbReqLen = 0;
|
|
||||||
|
|
||||||
memset(&pBlock->rowBuilder, 0, sizeof(pBlock->rowBuilder));
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) {
|
int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset) {
|
||||||
*pDst = taosMemoryMalloc(sizeof(STableDataBlocks));
|
int32_t code = 0;
|
||||||
|
|
||||||
|
*pDst = taosMemoryCalloc(1, sizeof(STableDataCxt));
|
||||||
if (NULL == *pDst) {
|
if (NULL == *pDst) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(*pDst, pSrc, sizeof(STableDataBlocks));
|
STableDataCxt* pNewCxt = (STableDataCxt*)*pDst;
|
||||||
((STableDataBlocks*)(*pDst))->cloned = true;
|
STableDataCxt* pCxt = (STableDataCxt*)pSrc;
|
||||||
|
pNewCxt->pSchema = NULL;
|
||||||
|
pNewCxt->pValues = NULL;
|
||||||
|
|
||||||
STableDataBlocks* pBlock = (STableDataBlocks*)(*pDst);
|
if (pCxt->pMeta) {
|
||||||
if (pBlock->pTableMeta) {
|
void* pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pCxt->pMeta));
|
||||||
void* pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pBlock->pTableMeta));
|
|
||||||
if (NULL == pNewMeta) {
|
if (NULL == pNewMeta) {
|
||||||
taosMemoryFreeClear(*pDst);
|
insDestroyTableDataCxt(*pDst);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
memcpy(pNewMeta, pBlock->pTableMeta, TABLE_META_SIZE(pBlock->pTableMeta));
|
memcpy(pNewMeta, pCxt->pMeta, TABLE_META_SIZE(pCxt->pMeta));
|
||||||
pBlock->pTableMeta = pNewMeta;
|
pNewCxt->pMeta = pNewMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
return qResetStmtDataBlock(*pDst, false);
|
memcpy(&pNewCxt->boundColsInfo, &pCxt->boundColsInfo, sizeof(pCxt->boundColsInfo));
|
||||||
|
pNewCxt->boundColsInfo.pColIndex = NULL;
|
||||||
|
|
||||||
|
if (pCxt->boundColsInfo.pColIndex) {
|
||||||
|
void* pNewColIdx = taosMemoryMalloc(pCxt->boundColsInfo.numOfBound * sizeof(*pCxt->boundColsInfo.pColIndex));
|
||||||
|
if (NULL == pNewColIdx) {
|
||||||
|
insDestroyTableDataCxt(*pDst);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
memcpy(pNewColIdx, pCxt->boundColsInfo.pColIndex,
|
||||||
|
pCxt->boundColsInfo.numOfBound * sizeof(*pCxt->boundColsInfo.pColIndex));
|
||||||
|
pNewCxt->boundColsInfo.pColIndex = pNewColIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid, int32_t vgId) {
|
if (pCxt->pData) {
|
||||||
int32_t code = qCloneStmtDataBlock(pDst, pSrc);
|
SSubmitTbData* pNewTb = (SSubmitTbData*)taosMemoryMalloc(sizeof(SSubmitTbData));
|
||||||
|
if (NULL == pNewTb) {
|
||||||
|
insDestroyTableDataCxt(*pDst);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pNewTb, pCxt->pData, sizeof(*pCxt->pData));
|
||||||
|
pNewTb->pCreateTbReq = NULL;
|
||||||
|
|
||||||
|
pNewTb->aCol = taosArrayDup(pCxt->pData->aCol, NULL);
|
||||||
|
if (NULL == pNewTb) {
|
||||||
|
insDestroyTableDataCxt(*pDst);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
pNewCxt->pData = pNewTb;
|
||||||
|
|
||||||
|
if (reset) {
|
||||||
|
code = qResetStmtDataBlock(*pDst, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId,
|
||||||
|
bool rebuildCreateTb) {
|
||||||
|
int32_t code = qCloneStmtDataBlock(pDst, pSrc, false);
|
||||||
if (code) {
|
if (code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks* pBlock = (STableDataBlocks*)*pDst;
|
STableDataCxt* pBlock = (STableDataCxt*)*pDst;
|
||||||
pBlock->pData = taosMemoryMalloc(pBlock->nAllocSize);
|
if (pBlock->pMeta) {
|
||||||
if (NULL == pBlock->pData) {
|
pBlock->pMeta->uid = uid;
|
||||||
qFreeStmtDataBlock(pBlock);
|
pBlock->pMeta->vgId = vgId;
|
||||||
|
pBlock->pMeta->suid = suid;
|
||||||
|
}
|
||||||
|
|
||||||
|
pBlock->pData->suid = suid;
|
||||||
|
pBlock->pData->uid = uid;
|
||||||
|
|
||||||
|
if (rebuildCreateTb && NULL == pBlock->pData->pCreateTbReq) {
|
||||||
|
pBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
|
||||||
|
if (NULL == pBlock->pData->pCreateTbReq) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlock->vgId = vgId;
|
|
||||||
|
|
||||||
if (pBlock->pTableMeta) {
|
|
||||||
pBlock->pTableMeta->uid = uid;
|
|
||||||
pBlock->pTableMeta->vgId = vgId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(pBlock->pData, 0, sizeof(SSubmitBlk));
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMeta* qGetTableMetaInDataBlock(void* pDataBlock) { return ((STableDataBlocks*)pDataBlock)->pTableMeta; }
|
STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock) { return ((STableDataCxt*)pDataBlock)->pMeta; }
|
||||||
|
|
||||||
void qFreeStmtDataBlock(void* pDataBlock) {
|
void qDestroyStmtDataBlock(STableDataCxt* pBlock) {
|
||||||
if (pDataBlock == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
taosMemoryFreeClear(((STableDataBlocks*)pDataBlock)->pTableMeta);
|
|
||||||
taosMemoryFreeClear(((STableDataBlocks*)pDataBlock)->pData);
|
|
||||||
taosMemoryFreeClear(pDataBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void qDestroyStmtDataBlock(void* pBlock) {
|
|
||||||
if (pBlock == NULL) {
|
if (pBlock == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||||
|
insDestroyTableDataCxt(pDataBlock);
|
||||||
pDataBlock->cloned = false;
|
|
||||||
insDestroyDataBlock(pDataBlock);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
#include "parUtil.h"
|
#include "parUtil.h"
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
#include "tRealloc.h"
|
#include "tRealloc.h"
|
||||||
|
#include "tdatablock.h"
|
||||||
|
|
||||||
typedef struct SBlockKeyTuple {
|
typedef struct SBlockKeyTuple {
|
||||||
TSKEY skey;
|
TSKEY skey;
|
||||||
|
|
@ -194,7 +195,17 @@ void destroyBoundColumnInfo(void* pBoundInfo) {
|
||||||
taosMemoryFreeClear(pColList->colIdxInfo);
|
taosMemoryFreeClear(pColList->colIdxInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, STableMeta* pTableMeta,
|
void qDestroyBoundColInfo(void* pInfo) {
|
||||||
|
if (NULL == pInfo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SBoundColInfo* pBoundInfo = (SBoundColInfo*)pInfo;
|
||||||
|
|
||||||
|
taosMemoryFreeClear(pBoundInfo->pColIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t createTableDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, STableMeta* pTableMeta,
|
||||||
STableDataBlocks** dataBlocks) {
|
STableDataBlocks** dataBlocks) {
|
||||||
STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks));
|
STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks));
|
||||||
if (dataBuf == NULL) {
|
if (dataBuf == NULL) {
|
||||||
|
|
@ -285,7 +296,7 @@ int32_t insGetDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, in
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*dataBlocks == NULL) {
|
if (*dataBlocks == NULL) {
|
||||||
int32_t ret = createDataBlock((size_t)size, rowSize, startOffset, pTableMeta, dataBlocks);
|
int32_t ret = createTableDataBlock((size_t)size, rowSize, startOffset, pTableMeta, dataBlocks);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -329,8 +340,8 @@ void insDestroyBlockHashmap(SHashObj* pDataBlockHash) {
|
||||||
|
|
||||||
void** p1 = taosHashIterate(pDataBlockHash, NULL);
|
void** p1 = taosHashIterate(pDataBlockHash, NULL);
|
||||||
while (p1) {
|
while (p1) {
|
||||||
STableDataBlocks* pBlocks = *p1;
|
SBoundColInfo* pBlocks = *p1;
|
||||||
insDestroyDataBlock(pBlocks);
|
destroyBoundColInfo(pBlocks);
|
||||||
|
|
||||||
p1 = taosHashIterate(pDataBlockHash, p1);
|
p1 = taosHashIterate(pDataBlockHash, p1);
|
||||||
}
|
}
|
||||||
|
|
@ -458,7 +469,7 @@ static int32_t tdBlockRowMerge(STableMeta* pTableMeta, SBlockKeyTuple* pEndKeyTp
|
||||||
|
|
||||||
if (!(*pBlkRowMerger)->pSchema) {
|
if (!(*pBlkRowMerger)->pSchema) {
|
||||||
(*pBlkRowMerger)->pSchema =
|
(*pBlkRowMerger)->pSchema =
|
||||||
tdGetSTSChemaFromSSChema(pTableMeta->schema, pTableMeta->tableInfo.numOfColumns, pTableMeta->sversion);
|
tBuildTSchema(pTableMeta->schema, pTableMeta->tableInfo.numOfColumns, pTableMeta->sversion);
|
||||||
|
|
||||||
if (!(*pBlkRowMerger)->pSchema) {
|
if (!(*pBlkRowMerger)->pSchema) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
@ -839,7 +850,7 @@ int32_t insCreateSName(SName* pName, SToken* pTableName, int32_t acctId, const c
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t insFindCol(SToken* pColname, int32_t start, int32_t end, SSchema* pSchema) {
|
int16_t insFindCol(SToken* pColname, int16_t start, int16_t end, SSchema* pSchema) {
|
||||||
while (start < end) {
|
while (start < end) {
|
||||||
if (strlen(pSchema[start].name) == pColname->n && strncmp(pColname->z, pSchema[start].name, pColname->n) == 0) {
|
if (strlen(pSchema[start].name) == pColname->n && strncmp(pColname->z, pSchema[start].name, pColname->n) == 0) {
|
||||||
return start;
|
return start;
|
||||||
|
|
@ -955,3 +966,536 @@ int32_t insBuildOutput(SHashObj* pVgroupsHashObj, SArray* pVgDataBlocks, SArray*
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void initBoundCols(int32_t ncols, int16_t* pBoundCols) {
|
||||||
|
for (int32_t i = 0; i < ncols; ++i) {
|
||||||
|
pBoundCols[i] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initColValues(STableMeta* pTableMeta, SArray* pValues) {
|
||||||
|
SSchema* pSchemas = getTableColumnSchema(pTableMeta);
|
||||||
|
for (int32_t i = 0; i < pTableMeta->tableInfo.numOfColumns; ++i) {
|
||||||
|
SColVal val = COL_VAL_NONE(pSchemas[i].colId, pSchemas[i].type);
|
||||||
|
taosArrayPush(pValues, &val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo* pInfo) {
|
||||||
|
pInfo->numOfCols = numOfBound;
|
||||||
|
pInfo->numOfBound = numOfBound;
|
||||||
|
pInfo->pColIndex = taosMemoryCalloc(numOfBound, sizeof(int16_t));
|
||||||
|
if (NULL == pInfo->pColIndex) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
initBoundCols(numOfBound, pInfo->pColIndex);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void insCheckTableDataOrder(STableDataCxt* pTableCxt, TSKEY tsKey) {
|
||||||
|
// once the data block is disordered, we do NOT keep last timestamp any more
|
||||||
|
if (!pTableCxt->ordered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsKey < pTableCxt->lastTs) {
|
||||||
|
pTableCxt->ordered = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsKey == pTableCxt->lastTs) {
|
||||||
|
pTableCxt->duplicateTs = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pTableCxt->lastTs = tsKey;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyBoundColInfo(SBoundColInfo* pInfo) { taosMemoryFreeClear(pInfo->pColIndex); }
|
||||||
|
|
||||||
|
static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreateTbReq, STableDataCxt** pOutput,
|
||||||
|
bool colMode) {
|
||||||
|
STableDataCxt* pTableCxt = taosMemoryCalloc(1, sizeof(STableDataCxt));
|
||||||
|
if (NULL == pTableCxt) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
pTableCxt->lastTs = 0;
|
||||||
|
pTableCxt->ordered = true;
|
||||||
|
pTableCxt->duplicateTs = false;
|
||||||
|
|
||||||
|
pTableCxt->pMeta = tableMetaDup(pTableMeta);
|
||||||
|
if (NULL == pTableCxt->pMeta) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
pTableCxt->pSchema =
|
||||||
|
tBuildTSchema(getTableColumnSchema(pTableMeta), pTableMeta->tableInfo.numOfColumns, pTableMeta->sversion);
|
||||||
|
if (NULL == pTableCxt->pSchema) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = insInitBoundColsInfo(pTableMeta->tableInfo.numOfColumns, &pTableCxt->boundColsInfo);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
pTableCxt->pValues = taosArrayInit(pTableMeta->tableInfo.numOfColumns, sizeof(SColVal));
|
||||||
|
if (NULL == pTableCxt->pValues) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
initColValues(pTableMeta, pTableCxt->pValues);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
pTableCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
|
||||||
|
if (NULL == pTableCxt->pData) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
pTableCxt->pData->flags = NULL != *pCreateTbReq ? SUBMIT_REQ_AUTO_CREATE_TABLE : 0;
|
||||||
|
pTableCxt->pData->flags |= colMode ? SUBMIT_REQ_COLUMN_DATA_FORMAT : 0;
|
||||||
|
pTableCxt->pData->suid = pTableMeta->suid;
|
||||||
|
pTableCxt->pData->uid = pTableMeta->uid;
|
||||||
|
pTableCxt->pData->sver = pTableMeta->sversion;
|
||||||
|
pTableCxt->pData->pCreateTbReq = *pCreateTbReq;
|
||||||
|
*pCreateTbReq = NULL;
|
||||||
|
if (pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||||
|
pTableCxt->pData->aCol = taosArrayInit(128, sizeof(SColData));
|
||||||
|
if (NULL == pTableCxt->pData->aCol) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pTableCxt->pData->aRowP = taosArrayInit(128, POINTER_BYTES);
|
||||||
|
if (NULL == pTableCxt->pData->aRowP) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pOutput = pTableCxt;
|
||||||
|
qDebug("tableDataCxt created, uid:%" PRId64 ", vgId:%d", pTableMeta->uid, pTableMeta->vgId);
|
||||||
|
} else {
|
||||||
|
taosMemoryFree(pTableCxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void resetColValues(SArray* pValues) {
|
||||||
|
int32_t num = taosArrayGetSize(pValues);
|
||||||
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
|
SColVal* pVal = taosArrayGet(pValues, i);
|
||||||
|
pVal->flag = CV_FLAG_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t insGetTableDataCxt(SHashObj* pHash, void* id, int32_t idLen, STableMeta* pTableMeta,
|
||||||
|
SVCreateTbReq** pCreateTbReq, STableDataCxt** pTableCxt, bool colMode) {
|
||||||
|
STableDataCxt** tmp = (STableDataCxt**)taosHashGet(pHash, id, idLen);
|
||||||
|
if (NULL != tmp) {
|
||||||
|
*pTableCxt = *tmp;
|
||||||
|
resetColValues((*pTableCxt)->pValues);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
int32_t code = createTableDataCxt(pTableMeta, pCreateTbReq, pTableCxt, colMode);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = taosHashPut(pHash, id, idLen, pTableCxt, POINTER_BYTES);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroyColVal(void* p) {
|
||||||
|
SColVal* pVal = p;
|
||||||
|
if (TSDB_DATA_TYPE_NCHAR == pVal->type) {
|
||||||
|
taosMemoryFree(pVal->value.pData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void insDestroyTableDataCxt(STableDataCxt* pTableCxt) {
|
||||||
|
if (NULL == pTableCxt) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMemoryFreeClear(pTableCxt->pMeta);
|
||||||
|
tDestroyTSchema(pTableCxt->pSchema);
|
||||||
|
destroyBoundColInfo(&pTableCxt->boundColsInfo);
|
||||||
|
taosArrayDestroyEx(pTableCxt->pValues, destroyColVal);
|
||||||
|
if (pTableCxt->pData) {
|
||||||
|
tDestroySSubmitTbData(pTableCxt->pData, TSDB_MSG_FLG_ENCODE);
|
||||||
|
taosMemoryFree(pTableCxt->pData);
|
||||||
|
}
|
||||||
|
taosMemoryFree(pTableCxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void insDestroyVgroupDataCxt(SVgroupDataCxt* pVgCxt) {
|
||||||
|
if (NULL == pVgCxt) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tDestroySSubmitReq2(pVgCxt->pData, TSDB_MSG_FLG_ENCODE);
|
||||||
|
taosMemoryFree(pVgCxt->pData);
|
||||||
|
taosMemoryFree(pVgCxt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void insDestroyVgroupDataCxtList(SArray* pVgCxtList) {
|
||||||
|
if (NULL == pVgCxtList) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = taosArrayGetSize(pVgCxtList);
|
||||||
|
for (int32_t i = 0; i < size; i++) {
|
||||||
|
void* p = taosArrayGetP(pVgCxtList, i);
|
||||||
|
insDestroyVgroupDataCxt(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(pVgCxtList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void insDestroyVgroupDataCxtHashMap(SHashObj* pVgCxtHash) {
|
||||||
|
if (NULL == pVgCxtHash) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void** p = taosHashIterate(pVgCxtHash, NULL);
|
||||||
|
while (p) {
|
||||||
|
insDestroyVgroupDataCxt(*(SVgroupDataCxt**)p);
|
||||||
|
|
||||||
|
p = taosHashIterate(pVgCxtHash, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosHashCleanup(pVgCxtHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void insDestroyTableDataCxtHashMap(SHashObj* pTableCxtHash) {
|
||||||
|
if (NULL == pTableCxtHash) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void** p = taosHashIterate(pTableCxtHash, NULL);
|
||||||
|
while (p) {
|
||||||
|
insDestroyTableDataCxt(*(STableDataCxt**)p);
|
||||||
|
|
||||||
|
p = taosHashIterate(pTableCxtHash, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosHashCleanup(pTableCxtHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t fillVgroupDataCxt(STableDataCxt* pTableCxt, SVgroupDataCxt* pVgCxt) {
|
||||||
|
if (NULL == pVgCxt->pData->aSubmitTbData) {
|
||||||
|
pVgCxt->pData->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData));
|
||||||
|
if (NULL == pVgCxt->pData->aSubmitTbData) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosArrayPush(pVgCxt->pData->aSubmitTbData, pTableCxt->pData);
|
||||||
|
taosMemoryFreeClear(pTableCxt->pData);
|
||||||
|
|
||||||
|
qDebug("add tableDataCxt uid:%" PRId64 " to vgId:%d", pTableCxt->pMeta->uid, pVgCxt->vgId);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t createVgroupDataCxt(STableDataCxt* pTableCxt, SHashObj* pVgroupHash, SArray* pVgroupList,
|
||||||
|
SVgroupDataCxt** pOutput) {
|
||||||
|
SVgroupDataCxt* pVgCxt = taosMemoryCalloc(1, sizeof(SVgroupDataCxt));
|
||||||
|
if (NULL == pVgCxt) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pVgCxt->pData = taosMemoryCalloc(1, sizeof(SSubmitReq2));
|
||||||
|
if (NULL == pVgCxt->pData) {
|
||||||
|
insDestroyVgroupDataCxt(pVgCxt);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
pVgCxt->vgId = pTableCxt->pMeta->vgId;
|
||||||
|
int32_t code = taosHashPut(pVgroupHash, &pVgCxt->vgId, sizeof(pVgCxt->vgId), &pVgCxt, POINTER_BYTES);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
taosArrayPush(pVgroupList, &pVgCxt);
|
||||||
|
*pOutput = pVgCxt;
|
||||||
|
} else {
|
||||||
|
insDestroyVgroupDataCxt(pVgCxt);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int insColDataComp(const void* lp, const void* rp) {
|
||||||
|
SColData* pLeft = (SColData*)lp;
|
||||||
|
SColData* pRight = (SColData*)rp;
|
||||||
|
if (pLeft->cid < pRight->cid) {
|
||||||
|
return -1;
|
||||||
|
} else if (pLeft->cid > pRight->cid) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t insMergeTableDataCxt(SHashObj* pTableHash, SArray** pVgDataBlocks) {
|
||||||
|
SHashObj* pVgroupHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false);
|
||||||
|
SArray* pVgroupList = taosArrayInit(8, POINTER_BYTES);
|
||||||
|
if (NULL == pVgroupHash || NULL == pVgroupList) {
|
||||||
|
taosHashCleanup(pVgroupHash);
|
||||||
|
taosArrayDestroy(pVgroupList);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
bool colFormat = false;
|
||||||
|
|
||||||
|
void* p = taosHashIterate(pTableHash, NULL);
|
||||||
|
if (p) {
|
||||||
|
STableDataCxt* pTableCxt = *(STableDataCxt**)p;
|
||||||
|
colFormat = (0 != (pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (TSDB_CODE_SUCCESS == code && NULL != p) {
|
||||||
|
STableDataCxt* pTableCxt = *(STableDataCxt**)p;
|
||||||
|
if (colFormat) {
|
||||||
|
SColData* pCol = taosArrayGet(pTableCxt->pData->aCol, 0);
|
||||||
|
if (pCol->nVal <= 0) {
|
||||||
|
p = taosHashIterate(pTableHash, p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pTableCxt->pData->pCreateTbReq) {
|
||||||
|
pTableCxt->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArraySort(pTableCxt->pData->aCol, insColDataComp);
|
||||||
|
|
||||||
|
tColDataSortMerge(pTableCxt->pData->aCol);
|
||||||
|
} else {
|
||||||
|
if (!pTableCxt->ordered) {
|
||||||
|
tRowSort(pTableCxt->pData->aRowP);
|
||||||
|
}
|
||||||
|
if (!pTableCxt->ordered || pTableCxt->duplicateTs) {
|
||||||
|
code = tRowMerge(pTableCxt->pData->aRowP, pTableCxt->pSchema, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
SVgroupDataCxt* pVgCxt = NULL;
|
||||||
|
int32_t vgId = pTableCxt->pMeta->vgId;
|
||||||
|
void** p = taosHashGet(pVgroupHash, &vgId, sizeof(vgId));
|
||||||
|
if (NULL == p) {
|
||||||
|
code = createVgroupDataCxt(pTableCxt, pVgroupHash, pVgroupList, &pVgCxt);
|
||||||
|
} else {
|
||||||
|
pVgCxt = *(SVgroupDataCxt**)p;
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = fillVgroupDataCxt(pTableCxt, pVgCxt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
p = taosHashIterate(pTableHash, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taosHashCleanup(pVgroupHash);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pVgDataBlocks = pVgroupList;
|
||||||
|
} else {
|
||||||
|
insDestroyVgroupDataCxtList(pVgroupList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t buildSubmitReq(int32_t vgId, SSubmitReq2* pReq, void** pData, uint32_t* pLen) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
uint32_t len = 0;
|
||||||
|
void* pBuf = NULL;
|
||||||
|
tEncodeSize(tEncodeSSubmitReq2, pReq, len, code);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
SEncoder encoder;
|
||||||
|
len += sizeof(SMsgHead);
|
||||||
|
pBuf = taosMemoryMalloc(len);
|
||||||
|
if (NULL == pBuf) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
((SMsgHead*)pBuf)->vgId = htonl(vgId);
|
||||||
|
((SMsgHead*)pBuf)->contLen = htonl(len);
|
||||||
|
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len - sizeof(SMsgHead));
|
||||||
|
code = tEncodeSSubmitReq2(&encoder, pReq);
|
||||||
|
tEncoderClear(&encoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pData = pBuf;
|
||||||
|
*pLen = len;
|
||||||
|
} else {
|
||||||
|
taosMemoryFree(pBuf);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroyVgDataBlocks(void* p) {
|
||||||
|
SVgDataBlocks* pVg = p;
|
||||||
|
taosMemoryFree(pVg->pData);
|
||||||
|
taosMemoryFree(pVg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t insBuildVgDataBlocks(SHashObj* pVgroupsHashObj, SArray* pVgDataCxtList, SArray** pVgDataBlocks) {
|
||||||
|
size_t numOfVg = taosArrayGetSize(pVgDataCxtList);
|
||||||
|
SArray* pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES);
|
||||||
|
if (NULL == pDataBlocks) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
for (size_t i = 0; TSDB_CODE_SUCCESS == code && i < numOfVg; ++i) {
|
||||||
|
SVgroupDataCxt* src = taosArrayGetP(pVgDataCxtList, i);
|
||||||
|
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
||||||
|
if (NULL == dst) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
dst->numOfTables = taosArrayGetSize(src->pData->aSubmitTbData);
|
||||||
|
code = taosHashGetDup(pVgroupsHashObj, (const char*)&src->vgId, sizeof(src->vgId), &dst->vg);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = buildSubmitReq(src->vgId, src->pData, &dst->pData, &dst->size);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = (NULL == taosArrayPush(pDataBlocks, &dst) ? TSDB_CODE_OUT_OF_MEMORY : TSDB_CODE_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pVgDataBlocks = pDataBlocks;
|
||||||
|
} else {
|
||||||
|
taosArrayDestroyP(pDataBlocks, destroyVgDataBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bindFileds(SBoundColInfo* pBoundInfo, SSchema* pSchema, TAOS_FIELD* fields, int numFields) {
|
||||||
|
bool* pUseCols = taosMemoryCalloc(pBoundInfo->numOfCols, sizeof(bool));
|
||||||
|
if (NULL == pUseCols) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
pBoundInfo->numOfBound = 0;
|
||||||
|
|
||||||
|
int16_t lastColIdx = -1; // last column found
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
for (int i = 0; i < numFields; i++) {
|
||||||
|
SToken token;
|
||||||
|
token.z = fields[i].name;
|
||||||
|
token.n = strlen(fields[i].name);
|
||||||
|
|
||||||
|
int16_t t = lastColIdx + 1;
|
||||||
|
int16_t index = insFindCol(&token, t, pBoundInfo->numOfCols, pSchema);
|
||||||
|
if (index < 0 && t > 0) {
|
||||||
|
index = insFindCol(&token, 0, t, pSchema);
|
||||||
|
}
|
||||||
|
if (index < 0) {
|
||||||
|
uError("can not find column name:%s", token.z);
|
||||||
|
code = TSDB_CODE_PAR_INVALID_COLUMN;
|
||||||
|
break;
|
||||||
|
} else if (pUseCols[index]) {
|
||||||
|
code = TSDB_CODE_PAR_INVALID_COLUMN;
|
||||||
|
uError("duplicated column name:%s", token.z);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
lastColIdx = index;
|
||||||
|
pUseCols[index] = true;
|
||||||
|
pBoundInfo->pColIndex[pBoundInfo->numOfBound] = index;
|
||||||
|
++pBoundInfo->numOfBound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code && !pUseCols[0]) {
|
||||||
|
uError("primary timestamp column can not be null:");
|
||||||
|
code = TSDB_CODE_PAR_INVALID_COLUMN;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMemoryFree(pUseCols);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rawBlockBindData(SQuery* query, STableMeta* pTableMeta, void* data, SVCreateTbReq* pCreateTb, TAOS_FIELD* tFields,
|
||||||
|
int numFields) {
|
||||||
|
STableDataCxt* pTableCxt = NULL;
|
||||||
|
int ret = insGetTableDataCxt(((SVnodeModifyOpStmt*)(query->pRoot))->pTableBlockHashObj, &pTableMeta->uid,
|
||||||
|
sizeof(pTableMeta->uid), pTableMeta, &pCreateTb, &pTableCxt, true);
|
||||||
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
|
uError("insGetTableDataCxt error");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (tFields != NULL) {
|
||||||
|
ret = bindFileds(&pTableCxt->boundColsInfo, getTableColumnSchema(pTableMeta), tFields, numFields);
|
||||||
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
|
uError("bindFileds error");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// no need to bind, because select * get all fields
|
||||||
|
ret = initTableColSubmitData(pTableCxt);
|
||||||
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
|
uError("initTableColSubmitData error");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* p = (char*)data;
|
||||||
|
// | version | total length | total rows | total columns | flag seg| block group id | column schema | each column
|
||||||
|
// length |
|
||||||
|
p += sizeof(int32_t);
|
||||||
|
p += sizeof(int32_t);
|
||||||
|
|
||||||
|
int32_t numOfRows = *(int32_t*)p;
|
||||||
|
p += sizeof(int32_t);
|
||||||
|
|
||||||
|
int32_t numOfCols = *(int32_t*)p;
|
||||||
|
p += sizeof(int32_t);
|
||||||
|
|
||||||
|
p += sizeof(int32_t);
|
||||||
|
p += sizeof(uint64_t);
|
||||||
|
|
||||||
|
int8_t* fields = p;
|
||||||
|
p += numOfCols * (sizeof(int8_t) + sizeof(int32_t));
|
||||||
|
|
||||||
|
int32_t* colLength = (int32_t*)p;
|
||||||
|
p += sizeof(int32_t) * numOfCols;
|
||||||
|
|
||||||
|
char* pStart = p;
|
||||||
|
|
||||||
|
SSchema* pSchema = getTableColumnSchema(pTableCxt->pMeta);
|
||||||
|
SBoundColInfo* boundInfo = &pTableCxt->boundColsInfo;
|
||||||
|
|
||||||
|
if (boundInfo->numOfBound != numOfCols) {
|
||||||
|
uError("boundInfo->numOfBound:%d != numOfCols:%d", boundInfo->numOfBound, numOfCols);
|
||||||
|
ret = TSDB_CODE_INVALID_PARA;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
for (int c = 0; c < boundInfo->numOfBound; ++c) {
|
||||||
|
SSchema* pColSchema = &pSchema[boundInfo->pColIndex[c]];
|
||||||
|
SColData* pCol = taosArrayGet(pTableCxt->pData->aCol, c);
|
||||||
|
|
||||||
|
if (*fields != pColSchema->type && *(int32_t*)(fields + sizeof(int8_t)) != pColSchema->bytes) {
|
||||||
|
uError("type or bytes not equal");
|
||||||
|
ret = TSDB_CODE_INVALID_PARA;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
colLength[c] = htonl(colLength[c]);
|
||||||
|
int8_t* offset = pStart;
|
||||||
|
if (IS_VAR_DATA_TYPE(pColSchema->type)) {
|
||||||
|
pStart += numOfRows * sizeof(int32_t);
|
||||||
|
} else {
|
||||||
|
pStart += BitmapLen(numOfRows);
|
||||||
|
}
|
||||||
|
char* pData = pStart;
|
||||||
|
|
||||||
|
tColDataAddValueByDataBlock(pCol, pColSchema->type, pColSchema->bytes, numOfRows, offset, pData);
|
||||||
|
fields += sizeof(int8_t) + sizeof(int32_t);
|
||||||
|
pStart += colLength[c];
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
@ -243,7 +243,8 @@ void destroyQueryExecRes(SExecResult* pRes) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TDMT_VND_SUBMIT: {
|
case TDMT_VND_SUBMIT: {
|
||||||
tFreeSSubmitRsp((SSubmitRsp*)pRes->res);
|
tDestroySSubmitRsp2((SSubmitRsp2*)pRes->res, TSDB_MSG_FLG_DECODE);
|
||||||
|
taosMemoryFreeClear(pRes->res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TDMT_SCH_QUERY:
|
case TDMT_SCH_QUERY:
|
||||||
|
|
@ -447,7 +448,6 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void freeVgInfo(SDBVgInfo* vgInfo) {
|
void freeVgInfo(SDBVgInfo* vgInfo) {
|
||||||
if (NULL == vgInfo) {
|
if (NULL == vgInfo) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -459,7 +459,6 @@ void freeVgInfo(SDBVgInfo* vgInfo) {
|
||||||
taosMemoryFreeClear(vgInfo);
|
taosMemoryFreeClear(vgInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) {
|
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) {
|
||||||
if (NULL == pSrc) {
|
if (NULL == pSrc) {
|
||||||
*pDst = NULL;
|
*pDst = NULL;
|
||||||
|
|
@ -498,3 +497,53 @@ int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) {
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst) {
|
||||||
|
if (NULL == pSrc) {
|
||||||
|
*pDst = NULL;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pDst = taosMemoryCalloc(1, sizeof(SVCreateTbReq));
|
||||||
|
if (NULL == *pDst) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*pDst)->flags = pSrc->flags;
|
||||||
|
if (pSrc->name) {
|
||||||
|
(*pDst)->name = strdup(pSrc->name);
|
||||||
|
}
|
||||||
|
(*pDst)->uid = pSrc->uid;
|
||||||
|
(*pDst)->ctime = pSrc->ctime;
|
||||||
|
(*pDst)->ttl = pSrc->ttl;
|
||||||
|
(*pDst)->commentLen = pSrc->commentLen;
|
||||||
|
if (pSrc->comment) {
|
||||||
|
(*pDst)->comment = strdup(pSrc->comment);
|
||||||
|
}
|
||||||
|
(*pDst)->type = pSrc->type;
|
||||||
|
|
||||||
|
if (pSrc->type == TSDB_CHILD_TABLE) {
|
||||||
|
if (pSrc->ctb.stbName) {
|
||||||
|
(*pDst)->ctb.stbName = strdup(pSrc->ctb.stbName);
|
||||||
|
}
|
||||||
|
(*pDst)->ctb.tagNum = pSrc->ctb.tagNum;
|
||||||
|
(*pDst)->ctb.suid = pSrc->ctb.suid;
|
||||||
|
if (pSrc->ctb.tagName) {
|
||||||
|
(*pDst)->ctb.tagName = taosArrayDup(pSrc->ctb.tagName, NULL);
|
||||||
|
}
|
||||||
|
STag* pTag = (STag*)pSrc->ctb.pTag;
|
||||||
|
if (pTag) {
|
||||||
|
(*pDst)->ctb.pTag = taosMemoryMalloc(pTag->len);
|
||||||
|
memcpy((*pDst)->ctb.pTag, pTag, pTag->len);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(*pDst)->ntb.schemaRow.nCols = pSrc->ntb.schemaRow.nCols;
|
||||||
|
(*pDst)->ntb.schemaRow.version = pSrc->ntb.schemaRow.nCols;
|
||||||
|
if (pSrc->ntb.schemaRow.nCols > 0 && pSrc->ntb.schemaRow.pSchema) {
|
||||||
|
(*pDst)->ntb.schemaRow.pSchema = taosMemoryMalloc(pSrc->ntb.schemaRow.nCols * sizeof(SSchema));
|
||||||
|
memcpy((*pDst)->ntb.schemaRow.pSchema, pSrc->ntb.schemaRow.pSchema, pSrc->ntb.schemaRow.nCols * sizeof(SSchema));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -261,39 +261,33 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
SDecoder coder = {0};
|
SDecoder coder = {0};
|
||||||
SSubmitRsp *rsp = taosMemoryMalloc(sizeof(*rsp));
|
SSubmitRsp2 *rsp = taosMemoryMalloc(sizeof(*rsp));
|
||||||
tDecoderInit(&coder, msg, msgSize);
|
tDecoderInit(&coder, msg, msgSize);
|
||||||
code = tDecodeSSubmitRsp(&coder, rsp);
|
code = tDecodeSSubmitRsp2(&coder, rsp);
|
||||||
|
tDecoderClear(&coder);
|
||||||
if (code) {
|
if (code) {
|
||||||
SCH_TASK_ELOG("decode submitRsp failed, code:%d", code);
|
SCH_TASK_ELOG("tDecodeSSubmitRsp2 failed, code:%d", code);
|
||||||
tFreeSSubmitRsp(rsp);
|
tDestroySSubmitRsp2(rsp, TSDB_MSG_FLG_DECODE);
|
||||||
|
taosMemoryFree(rsp);
|
||||||
SCH_ERR_JRET(code);
|
SCH_ERR_JRET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rsp->nBlocks > 0) {
|
|
||||||
for (int32_t i = 0; i < rsp->nBlocks; ++i) {
|
|
||||||
SSubmitBlkRsp *blk = rsp->pBlocks + i;
|
|
||||||
if (TSDB_CODE_SUCCESS != blk->code) {
|
|
||||||
code = blk->code;
|
|
||||||
tFreeSSubmitRsp(rsp);
|
|
||||||
SCH_ERR_JRET(code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
atomic_add_fetch_64(&pJob->resNumOfRows, rsp->affectedRows);
|
atomic_add_fetch_64(&pJob->resNumOfRows, rsp->affectedRows);
|
||||||
SCH_TASK_DLOG("submit succeed, affectedRows:%d, blocks:%d", rsp->affectedRows, rsp->nBlocks);
|
|
||||||
|
|
||||||
|
int32_t createTbRspNum = taosArrayGetSize(rsp->aCreateTbRsp);
|
||||||
|
SCH_TASK_DLOG("submit succeed, affectedRows:%d, createTbRspNum:%d", rsp->affectedRows, createTbRspNum);
|
||||||
|
|
||||||
|
if (rsp->aCreateTbRsp && taosArrayGetSize(rsp->aCreateTbRsp) > 0) {
|
||||||
SCH_LOCK(SCH_WRITE, &pJob->resLock);
|
SCH_LOCK(SCH_WRITE, &pJob->resLock);
|
||||||
if (pJob->execRes.res) {
|
if (pJob->execRes.res) {
|
||||||
SSubmitRsp *sum = pJob->execRes.res;
|
SSubmitRsp2 *sum = pJob->execRes.res;
|
||||||
sum->affectedRows += rsp->affectedRows;
|
sum->affectedRows += rsp->affectedRows;
|
||||||
sum->nBlocks += rsp->nBlocks;
|
if (sum->aCreateTbRsp) {
|
||||||
if (rsp->nBlocks > 0 && rsp->pBlocks) {
|
taosArrayAddAll(sum->aCreateTbRsp, rsp->aCreateTbRsp);
|
||||||
sum->pBlocks = taosMemoryRealloc(sum->pBlocks, sum->nBlocks * sizeof(*sum->pBlocks));
|
taosArrayDestroy(rsp->aCreateTbRsp);
|
||||||
memcpy(sum->pBlocks + sum->nBlocks - rsp->nBlocks, rsp->pBlocks, rsp->nBlocks * sizeof(*sum->pBlocks));
|
} else {
|
||||||
|
TSWAP(sum->aCreateTbRsp, rsp->aCreateTbRsp);
|
||||||
}
|
}
|
||||||
taosMemoryFree(rsp->pBlocks);
|
|
||||||
taosMemoryFree(rsp);
|
taosMemoryFree(rsp);
|
||||||
} else {
|
} else {
|
||||||
pJob->execRes.res = rsp;
|
pJob->execRes.res = rsp;
|
||||||
|
|
@ -301,6 +295,17 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa
|
||||||
}
|
}
|
||||||
pJob->execRes.numOfBytes += pTask->msgLen;
|
pJob->execRes.numOfBytes += pTask->msgLen;
|
||||||
SCH_UNLOCK(SCH_WRITE, &pJob->resLock);
|
SCH_UNLOCK(SCH_WRITE, &pJob->resLock);
|
||||||
|
} else {
|
||||||
|
SCH_LOCK(SCH_WRITE, &pJob->resLock);
|
||||||
|
pJob->execRes.numOfBytes += pTask->msgLen;
|
||||||
|
if (NULL == pJob->execRes.res) {
|
||||||
|
TSWAP(pJob->execRes.res, rsp);
|
||||||
|
pJob->execRes.msgType = TDMT_VND_SUBMIT;
|
||||||
|
}
|
||||||
|
SCH_UNLOCK(SCH_WRITE, &pJob->resLock);
|
||||||
|
tDestroySSubmitRsp2(rsp, TSDB_MSG_FLG_DECODE);
|
||||||
|
taosMemoryFree(rsp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFreeClear(msg);
|
taosMemoryFreeClear(msg);
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,23 @@ int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq,
|
||||||
return status == TASK_INPUT_STATUS__NORMAL ? 0 : -1;
|
return status == TASK_INPUT_STATUS__NORMAL ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
ASSERT(pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH);
|
||||||
|
taosWriteQitem(pTask->outputQueue->queue, pBlock);
|
||||||
|
streamDispatch(pTask);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp, bool exec) {
|
int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp, bool exec) {
|
||||||
qDebug("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId,
|
qDebug("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId,
|
||||||
pReq->upstreamTaskId);
|
pReq->upstreamTaskId);
|
||||||
|
|
@ -199,9 +216,9 @@ int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, S
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
|
/*if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {*/
|
||||||
streamDispatch(pTask);
|
/*streamDispatch(pTask);*/
|
||||||
}
|
/*}*/
|
||||||
} else {
|
} else {
|
||||||
streamSchedExec(pTask);
|
streamSchedExec(pTask);
|
||||||
}
|
}
|
||||||
|
|
@ -237,9 +254,9 @@ int32_t streamProcessRunReq(SStreamTask* pTask) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
|
/*if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {*/
|
||||||
streamDispatch(pTask);
|
/*streamDispatch(pTask);*/
|
||||||
}
|
/*}*/
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,13 @@ int32_t streamRetrieveReqToData(const SStreamRetrieveReq* pReq, SStreamDataBlock
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq) {
|
SStreamDataSubmit2* streamDataSubmitNew(SPackedData submit) {
|
||||||
SStreamDataSubmit* pDataSubmit = (SStreamDataSubmit*)taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM, 0);
|
SStreamDataSubmit2* pDataSubmit = (SStreamDataSubmit2*)taosAllocateQitem(sizeof(SStreamDataSubmit2), DEF_QITEM, 0);
|
||||||
|
|
||||||
if (pDataSubmit == NULL) return NULL;
|
if (pDataSubmit == NULL) return NULL;
|
||||||
pDataSubmit->dataRef = (int32_t*)taosMemoryMalloc(sizeof(int32_t));
|
pDataSubmit->dataRef = (int32_t*)taosMemoryMalloc(sizeof(int32_t));
|
||||||
if (pDataSubmit->dataRef == NULL) goto FAIL;
|
if (pDataSubmit->dataRef == NULL) goto FAIL;
|
||||||
pDataSubmit->data = pReq;
|
pDataSubmit->submit = submit;
|
||||||
*pDataSubmit->dataRef = 1;
|
*pDataSubmit->dataRef = 1;
|
||||||
pDataSubmit->type = STREAM_INPUT__DATA_SUBMIT;
|
pDataSubmit->type = STREAM_INPUT__DATA_SUBMIT;
|
||||||
return pDataSubmit;
|
return pDataSubmit;
|
||||||
|
|
@ -80,47 +81,49 @@ FAIL:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SStreamMergedSubmit* streamMergedSubmitNew() {
|
SStreamMergedSubmit2* streamMergedSubmitNew() {
|
||||||
SStreamMergedSubmit* pMerged = (SStreamMergedSubmit*)taosAllocateQitem(sizeof(SStreamMergedSubmit), DEF_QITEM, 0);
|
SStreamMergedSubmit2* pMerged = (SStreamMergedSubmit2*)taosAllocateQitem(sizeof(SStreamMergedSubmit2), DEF_QITEM, 0);
|
||||||
|
|
||||||
if (pMerged == NULL) return NULL;
|
if (pMerged == NULL) return NULL;
|
||||||
pMerged->reqs = taosArrayInit(0, sizeof(void*));
|
pMerged->submits = taosArrayInit(0, sizeof(SPackedData));
|
||||||
pMerged->dataRefs = taosArrayInit(0, sizeof(void*));
|
pMerged->dataRefs = taosArrayInit(0, sizeof(void*));
|
||||||
if (pMerged->dataRefs == NULL || pMerged->reqs == NULL) goto FAIL;
|
if (pMerged->dataRefs == NULL || pMerged->submits == NULL) goto FAIL;
|
||||||
pMerged->type = STREAM_INPUT__MERGED_SUBMIT;
|
pMerged->type = STREAM_INPUT__MERGED_SUBMIT;
|
||||||
return pMerged;
|
return pMerged;
|
||||||
FAIL:
|
FAIL:
|
||||||
if (pMerged->reqs) taosArrayDestroy(pMerged->reqs);
|
if (pMerged->submits) taosArrayDestroy(pMerged->submits);
|
||||||
if (pMerged->dataRefs) taosArrayDestroy(pMerged->dataRefs);
|
if (pMerged->dataRefs) taosArrayDestroy(pMerged->dataRefs);
|
||||||
taosFreeQitem(pMerged);
|
taosFreeQitem(pMerged);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamMergeSubmit(SStreamMergedSubmit* pMerged, SStreamDataSubmit* pSubmit) {
|
int32_t streamMergeSubmit(SStreamMergedSubmit2* pMerged, SStreamDataSubmit2* pSubmit) {
|
||||||
taosArrayPush(pMerged->dataRefs, &pSubmit->dataRef);
|
taosArrayPush(pMerged->dataRefs, &pSubmit->dataRef);
|
||||||
taosArrayPush(pMerged->reqs, &pSubmit->data);
|
taosArrayPush(pMerged->submits, &pSubmit->submit);
|
||||||
pMerged->ver = pSubmit->ver;
|
pMerged->ver = pSubmit->ver;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void streamDataSubmitRefInc(SStreamDataSubmit* pDataSubmit) {
|
static FORCE_INLINE void streamDataSubmitRefInc(SStreamDataSubmit2* pDataSubmit) {
|
||||||
atomic_add_fetch_32(pDataSubmit->dataRef, 1);
|
atomic_add_fetch_32(pDataSubmit->dataRef, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit) {
|
SStreamDataSubmit2* streamSubmitRefClone(SStreamDataSubmit2* pSubmit) {
|
||||||
SStreamDataSubmit* pSubmitClone = taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM, 0);
|
SStreamDataSubmit2* pSubmitClone = taosAllocateQitem(sizeof(SStreamDataSubmit2), DEF_QITEM, 0);
|
||||||
|
|
||||||
if (pSubmitClone == NULL) {
|
if (pSubmitClone == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
streamDataSubmitRefInc(pSubmit);
|
streamDataSubmitRefInc(pSubmit);
|
||||||
memcpy(pSubmitClone, pSubmit, sizeof(SStreamDataSubmit));
|
memcpy(pSubmitClone, pSubmit, sizeof(SStreamDataSubmit2));
|
||||||
return pSubmitClone;
|
return pSubmitClone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit) {
|
void streamDataSubmitRefDec(SStreamDataSubmit2* pDataSubmit) {
|
||||||
int32_t ref = atomic_sub_fetch_32(pDataSubmit->dataRef, 1);
|
int32_t ref = atomic_sub_fetch_32(pDataSubmit->dataRef, 1);
|
||||||
ASSERT(ref >= 0);
|
ASSERT(ref >= 0);
|
||||||
if (ref == 0) {
|
if (ref == 0) {
|
||||||
taosMemoryFree(pDataSubmit->data);
|
taosMemoryFree(pDataSubmit->submit.msgStr);
|
||||||
taosMemoryFree(pDataSubmit->dataRef);
|
taosMemoryFree(pDataSubmit->dataRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -135,16 +138,16 @@ SStreamQueueItem* streamMergeQueueItem(SStreamQueueItem* dst, SStreamQueueItem*
|
||||||
taosFreeQitem(elem);
|
taosFreeQitem(elem);
|
||||||
return dst;
|
return dst;
|
||||||
} else if (dst->type == STREAM_INPUT__MERGED_SUBMIT && elem->type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (dst->type == STREAM_INPUT__MERGED_SUBMIT && elem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
SStreamMergedSubmit* pMerged = (SStreamMergedSubmit*)dst;
|
SStreamMergedSubmit2* pMerged = (SStreamMergedSubmit2*)dst;
|
||||||
SStreamDataSubmit* pBlockSrc = (SStreamDataSubmit*)elem;
|
SStreamDataSubmit2* pBlockSrc = (SStreamDataSubmit2*)elem;
|
||||||
streamMergeSubmit(pMerged, pBlockSrc);
|
streamMergeSubmit(pMerged, pBlockSrc);
|
||||||
taosFreeQitem(elem);
|
taosFreeQitem(elem);
|
||||||
return dst;
|
return dst;
|
||||||
} else if (dst->type == STREAM_INPUT__DATA_SUBMIT && elem->type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (dst->type == STREAM_INPUT__DATA_SUBMIT && elem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
SStreamMergedSubmit* pMerged = streamMergedSubmitNew();
|
SStreamMergedSubmit2* pMerged = streamMergedSubmitNew();
|
||||||
ASSERT(pMerged);
|
ASSERT(pMerged);
|
||||||
streamMergeSubmit(pMerged, (SStreamDataSubmit*)dst);
|
streamMergeSubmit(pMerged, (SStreamDataSubmit2*)dst);
|
||||||
streamMergeSubmit(pMerged, (SStreamDataSubmit*)elem);
|
streamMergeSubmit(pMerged, (SStreamDataSubmit2*)elem);
|
||||||
taosFreeQitem(dst);
|
taosFreeQitem(dst);
|
||||||
taosFreeQitem(elem);
|
taosFreeQitem(elem);
|
||||||
return (SStreamQueueItem*)pMerged;
|
return (SStreamQueueItem*)pMerged;
|
||||||
|
|
@ -162,22 +165,22 @@ void streamFreeQitem(SStreamQueueItem* data) {
|
||||||
taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)blockDataFreeRes);
|
taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)blockDataFreeRes);
|
||||||
taosFreeQitem(data);
|
taosFreeQitem(data);
|
||||||
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
streamDataSubmitRefDec((SStreamDataSubmit*)data);
|
streamDataSubmitRefDec((SStreamDataSubmit2*)data);
|
||||||
taosFreeQitem(data);
|
taosFreeQitem(data);
|
||||||
} else if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
} else if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
SStreamMergedSubmit* pMerge = (SStreamMergedSubmit*)data;
|
SStreamMergedSubmit2* pMerge = (SStreamMergedSubmit2*)data;
|
||||||
int32_t sz = taosArrayGetSize(pMerge->reqs);
|
int32_t sz = taosArrayGetSize(pMerge->submits);
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
for (int32_t i = 0; i < sz; i++) {
|
||||||
int32_t* pRef = taosArrayGetP(pMerge->dataRefs, i);
|
int32_t* pRef = taosArrayGetP(pMerge->dataRefs, i);
|
||||||
int32_t ref = atomic_sub_fetch_32(pRef, 1);
|
int32_t ref = atomic_sub_fetch_32(pRef, 1);
|
||||||
ASSERT(ref >= 0);
|
ASSERT(ref >= 0);
|
||||||
if (ref == 0) {
|
if (ref == 0) {
|
||||||
void* dataStr = taosArrayGetP(pMerge->reqs, i);
|
SPackedData* pSubmit = (SPackedData*)taosArrayGet(pMerge->submits, i);
|
||||||
taosMemoryFree(dataStr);
|
taosMemoryFree(pSubmit->msgStr);
|
||||||
taosMemoryFree(pRef);
|
taosMemoryFree(pRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
taosArrayDestroy(pMerge->reqs);
|
taosArrayDestroy(pMerge->submits);
|
||||||
taosArrayDestroy(pMerge->dataRefs);
|
taosArrayDestroy(pMerge->dataRefs);
|
||||||
taosFreeQitem(pMerge);
|
taosFreeQitem(pMerge);
|
||||||
} else if (type == STREAM_INPUT__REF_DATA_BLOCK) {
|
} else if (type == STREAM_INPUT__REF_DATA_BLOCK) {
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,18 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray*
|
||||||
qSetMultiStreamInput(exec, pTrigger->pBlock, 1, STREAM_INPUT__DATA_BLOCK);
|
qSetMultiStreamInput(exec, pTrigger->pBlock, 1, STREAM_INPUT__DATA_BLOCK);
|
||||||
} else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
ASSERT(pTask->taskLevel == TASK_LEVEL__SOURCE);
|
ASSERT(pTask->taskLevel == TASK_LEVEL__SOURCE);
|
||||||
const SStreamDataSubmit* pSubmit = (const SStreamDataSubmit*)data;
|
const SStreamDataSubmit2* pSubmit = (const SStreamDataSubmit2*)data;
|
||||||
qDebug("task %d %p set submit input %p %p %d 1", pTask->taskId, pTask, pSubmit, pSubmit->data, *pSubmit->dataRef);
|
qDebug("task %d %p set submit input %p %p %d %" PRId64, pTask->taskId, pTask, pSubmit, pSubmit->submit.msgStr,
|
||||||
qSetMultiStreamInput(exec, pSubmit->data, 1, STREAM_INPUT__DATA_SUBMIT);
|
pSubmit->submit.msgLen, pSubmit->submit.ver);
|
||||||
|
qSetMultiStreamInput(exec, &pSubmit->submit, 1, STREAM_INPUT__DATA_SUBMIT);
|
||||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) {
|
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) {
|
||||||
const SStreamDataBlock* pBlock = (const SStreamDataBlock*)data;
|
const SStreamDataBlock* pBlock = (const SStreamDataBlock*)data;
|
||||||
SArray* blocks = pBlock->blocks;
|
SArray* blocks = pBlock->blocks;
|
||||||
qDebug("task %d %p set ssdata input", pTask->taskId, pTask);
|
qDebug("task %d %p set ssdata input", pTask->taskId, pTask);
|
||||||
qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__DATA_BLOCK);
|
qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__DATA_BLOCK);
|
||||||
} else if (pItem->type == STREAM_INPUT__MERGED_SUBMIT) {
|
} else if (pItem->type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
const SStreamMergedSubmit* pMerged = (const SStreamMergedSubmit*)data;
|
const SStreamMergedSubmit2* pMerged = (const SStreamMergedSubmit2*)data;
|
||||||
SArray* blocks = pMerged->reqs;
|
SArray* blocks = pMerged->submits;
|
||||||
qDebug("task %d %p set submit input (merged), batch num: %d", pTask->taskId, pTask, (int32_t)blocks->size);
|
qDebug("task %d %p set submit input (merged), batch num: %d", pTask->taskId, pTask, (int32_t)blocks->size);
|
||||||
qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__MERGED_SUBMIT);
|
qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__MERGED_SUBMIT);
|
||||||
} else if (pItem->type == STREAM_INPUT__REF_DATA_BLOCK) {
|
} else if (pItem->type == STREAM_INPUT__REF_DATA_BLOCK) {
|
||||||
|
|
@ -112,7 +113,11 @@ int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz) {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
if (output == NULL) {
|
if (output == NULL) {
|
||||||
|
if (qStreamRecoverScanFinished(exec)) {
|
||||||
finished = true;
|
finished = true;
|
||||||
|
} else {
|
||||||
|
qSetStreamOpOpen(exec);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,11 +255,11 @@ int32_t streamExecForAll(SStreamTask* pTask) {
|
||||||
qRes->blocks = pRes;
|
qRes->blocks = pRes;
|
||||||
|
|
||||||
if (((SStreamQueueItem*)input)->type == STREAM_INPUT__DATA_SUBMIT) {
|
if (((SStreamQueueItem*)input)->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)input;
|
SStreamDataSubmit2* pSubmit = (SStreamDataSubmit2*)input;
|
||||||
qRes->childId = pTask->selfChildId;
|
qRes->childId = pTask->selfChildId;
|
||||||
qRes->sourceVer = pSubmit->ver;
|
qRes->sourceVer = pSubmit->ver;
|
||||||
} else if (((SStreamQueueItem*)input)->type == STREAM_INPUT__MERGED_SUBMIT) {
|
} else if (((SStreamQueueItem*)input)->type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
SStreamMergedSubmit* pMerged = (SStreamMergedSubmit*)input;
|
SStreamMergedSubmit2* pMerged = (SStreamMergedSubmit2*)input;
|
||||||
qRes->childId = pTask->selfChildId;
|
qRes->childId = pTask->selfChildId;
|
||||||
qRes->sourceVer = pMerged->ver;
|
qRes->sourceVer = pMerged->ver;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -267,54 +267,55 @@ static int32_t walFetchHeadNew(SWalReader *pRead, int64_t fetchVer) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t walFetchBodyNew(SWalReader *pRead) {
|
static int32_t walFetchBodyNew(SWalReader *pReader) {
|
||||||
SWalCont *pReadHead = &pRead->pHead->head;
|
SWalCont *pReadHead = &pReader->pHead->head;
|
||||||
int64_t ver = pReadHead->version;
|
int64_t ver = pReadHead->version;
|
||||||
|
|
||||||
wDebug("vgId:%d, wal starts to fetch body, index:%" PRId64, pRead->pWal->cfg.vgId, ver);
|
wDebug("vgId:%d, wal starts to fetch body, ver:%" PRId64 " ,len:%d", pReader->pWal->cfg.vgId, ver,
|
||||||
|
pReadHead->bodyLen);
|
||||||
|
|
||||||
if (pRead->capacity < pReadHead->bodyLen) {
|
if (pReader->capacity < pReadHead->bodyLen) {
|
||||||
SWalCkHead *ptr = (SWalCkHead *)taosMemoryRealloc(pRead->pHead, sizeof(SWalCkHead) + pReadHead->bodyLen);
|
SWalCkHead *ptr = (SWalCkHead *)taosMemoryRealloc(pReader->pHead, sizeof(SWalCkHead) + pReadHead->bodyLen);
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pRead->pHead = ptr;
|
pReader->pHead = ptr;
|
||||||
pReadHead = &pRead->pHead->head;
|
pReadHead = &pReader->pHead->head;
|
||||||
pRead->capacity = pReadHead->bodyLen;
|
pReader->capacity = pReadHead->bodyLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReadHead->bodyLen != taosReadFile(pRead->pLogFile, pReadHead->body, pReadHead->bodyLen)) {
|
if (pReadHead->bodyLen != taosReadFile(pReader->pLogFile, pReadHead->body, pReadHead->bodyLen)) {
|
||||||
if (pReadHead->bodyLen < 0) {
|
if (pReadHead->bodyLen < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since %s",
|
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since %s",
|
||||||
pRead->pWal->cfg.vgId, pRead->pHead->head.version, ver, tstrerror(terrno));
|
pReader->pWal->cfg.vgId, pReader->pHead->head.version, ver, tstrerror(terrno));
|
||||||
} else {
|
} else {
|
||||||
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since file corrupted",
|
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since file corrupted",
|
||||||
pRead->pWal->cfg.vgId, pRead->pHead->head.version, ver);
|
pReader->pWal->cfg.vgId, pReader->pHead->head.version, ver);
|
||||||
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||||
}
|
}
|
||||||
pRead->curInvalid = 1;
|
pReader->curInvalid = 1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReadHead->version != ver) {
|
if (pReadHead->version != ver) {
|
||||||
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64, pRead->pWal->cfg.vgId,
|
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64, pReader->pWal->cfg.vgId,
|
||||||
pRead->pHead->head.version, ver);
|
pReader->pHead->head.version, ver);
|
||||||
pRead->curInvalid = 1;
|
pReader->curInvalid = 1;
|
||||||
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (walValidBodyCksum(pRead->pHead) != 0) {
|
if (walValidBodyCksum(pReader->pHead) != 0) {
|
||||||
wError("vgId:%d, wal fetch body error:%" PRId64 ", since body checksum not passed", pRead->pWal->cfg.vgId, ver);
|
wError("vgId:%d, wal fetch body error:%" PRId64 ", since body checksum not passed", pReader->pWal->cfg.vgId, ver);
|
||||||
pRead->curInvalid = 1;
|
pReader->curInvalid = 1;
|
||||||
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wDebug("vgId:%d, index:%" PRId64 " is fetched, cursor advance", pRead->pWal->cfg.vgId, ver);
|
wDebug("vgId:%d, index:%" PRId64 " is fetched, cursor advance", pReader->pWal->cfg.vgId, ver);
|
||||||
pRead->curVersion = ver + 1;
|
pReader->curVersion = ver + 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#define ALLOW_FORBID_FUNC
|
#define ALLOW_FORBID_FUNC
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
void swapStr(char* j, char* J, int width) {
|
void swapStr(char* j, char* J, int width) {
|
||||||
|
|
@ -33,16 +34,5 @@ void swapStr(char* j, char* J, int width) {
|
||||||
|
|
||||||
// todo refactor: 1) move away; 2) use merge sort instead; 3) qsort is not a stable sort actually.
|
// todo refactor: 1) move away; 2) use merge sort instead; 3) qsort is not a stable sort actually.
|
||||||
void taosSort(void* arr, int64_t sz, int64_t width, __compar_fn_t compar) {
|
void taosSort(void* arr, int64_t sz, int64_t width, __compar_fn_t compar) {
|
||||||
#ifdef WINDOWS
|
|
||||||
int64_t i, j;
|
|
||||||
for (i = 0; i < sz - 1; i++) {
|
|
||||||
for (j = 0; j < sz - 1 - i; j++) {
|
|
||||||
if (compar((char*)arr + j * width, (char*)arr + (j + 1) * width) > 0.00) {
|
|
||||||
swapStr((char*)arr + j * width, (char*)arr + (j + 1) * width, width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
qsort(arr, sz, width, compar);
|
qsort(arr, sz, width, compar);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,8 @@ void* taosArrayReserve(SArray* pArray, int32_t num) {
|
||||||
void* dst = TARRAY_GET_ELEM(pArray, pArray->size);
|
void* dst = TARRAY_GET_ELEM(pArray, pArray->size);
|
||||||
pArray->size += num;
|
pArray->size += num;
|
||||||
|
|
||||||
|
memset(dst, 0, num * pArray->elemSize);
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +228,7 @@ size_t taosArrayGetSize(const SArray* pArray) {
|
||||||
if (pArray == NULL) {
|
if (pArray == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return pArray->size;
|
return TARRAY_SIZE(pArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosArraySetSize(SArray* pArray, size_t size) {
|
void taosArraySetSize(SArray* pArray, size_t size) {
|
||||||
|
|
@ -295,6 +297,20 @@ void taosArrayRemove(SArray* pArray, size_t index) {
|
||||||
pArray->size -= 1;
|
pArray->size -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void taosArrayRemoveBatch(SArray* pArray, size_t index, size_t num, FDelete fp) {
|
||||||
|
ASSERT(index + num <= pArray->size);
|
||||||
|
|
||||||
|
if (fp) {
|
||||||
|
for (int32_t i = 0; i < num; i++) {
|
||||||
|
fp(taosArrayGet(pArray, index + i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memmove((char*)pArray->pData + index * pArray->elemSize, (char*)pArray->pData + (index + num) * pArray->elemSize,
|
||||||
|
(pArray->size - index - num) * pArray->elemSize);
|
||||||
|
pArray->size -= num;
|
||||||
|
}
|
||||||
|
|
||||||
SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize) {
|
SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize) {
|
||||||
assert(src != NULL && elemSize > 0);
|
assert(src != NULL && elemSize > 0);
|
||||||
SArray* pDst = taosArrayInit(size, elemSize);
|
SArray* pDst = taosArrayInit(size, elemSize);
|
||||||
|
|
|
||||||
|
|
@ -1120,7 +1120,7 @@ int32_t WCSPatternMatch(const TdUcs4 *patterStr, const TdUcs4 *str, size_t size,
|
||||||
return TSDB_PATTERN_NOMATCH;
|
return TSDB_PATTERN_NOMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (str[j] == 0 || j >= size) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH;
|
return (j >= size || str[j] == 0) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight) { return compareStrRegexComp(pLeft, pRight); }
|
int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight) { return compareStrRegexComp(pLeft, pRight); }
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_CLAUSE_ERROR, "not supported stmt cl
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_KILLED, "Query killed")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_KILLED, "Query killed")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_EXEC_NODE, "No available execution node in current query policy configuration")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_EXEC_NODE, "No available execution node in current query policy configuration")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NOT_STABLE_ERROR, "Table is not a super table")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NOT_STABLE_ERROR, "Table is not a super table")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_CACHE_ERROR, "Stmt cache error")
|
||||||
|
|
||||||
// mnode-common
|
// mnode-common
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_RIGHTS, "Insufficient privilege for operation")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_RIGHTS, "Insufficient privilege for operation")
|
||||||
|
|
|
||||||
|
|
@ -733,7 +733,7 @@
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/stbTagFilter-1ctb.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/stbTagFilter-1ctb.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dataFromTsdbNWal.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dataFromTsdbNWal.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dataFromTsdbNWal-multiCtb.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dataFromTsdbNWal-multiCtb.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_taosx.py
|
#,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_taosx.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/stbTagFilter-multiCtb.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/stbTagFilter-multiCtb.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TD-19201.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TD-19201.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqSubscribeStb-r3.py -N 5
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqSubscribeStb-r3.py -N 5
|
||||||
|
|
@ -1037,7 +1037,7 @@
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TD-20582.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TD-20582.py
|
||||||
|
|
||||||
#develop test
|
#develop test
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/auto_create_table_json.py
|
#,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/auto_create_table_json.py
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/custom_col_tag.py
|
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/custom_col_tag.py
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/default_json.py
|
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/default_json.py
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/demo.py
|
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/demo.py
|
||||||
|
|
@ -1046,7 +1046,7 @@
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/json_tag.py
|
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/json_tag.py
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/query_json.py
|
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/query_json.py
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/sample_csv_json.py
|
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/sample_csv_json.py
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/sml_json_alltypes.py
|
#,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/sml_json_alltypes.py
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestQueryWithJson.py -R
|
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestQueryWithJson.py -R
|
||||||
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/telnet_tcp.py -R
|
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/telnet_tcp.py -R
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -232,8 +232,8 @@ CaseCtrl gCaseCtrl = {
|
||||||
.printCreateTblSql = true,
|
.printCreateTblSql = true,
|
||||||
.printQuerySql = true,
|
.printQuerySql = true,
|
||||||
.printStmtSql = true,
|
.printStmtSql = true,
|
||||||
.printVerbose = false,
|
.printVerbose = true,
|
||||||
.printRes = false,
|
.printRes = true,
|
||||||
.autoCreateTbl = false,
|
.autoCreateTbl = false,
|
||||||
.numericParam = false,
|
.numericParam = false,
|
||||||
.rowNum = 0,
|
.rowNum = 0,
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ from util.dnodes import *
|
||||||
from util.dnodes import TDDnodes
|
from util.dnodes import TDDnodes
|
||||||
from util.dnodes import TDDnode
|
from util.dnodes import TDDnode
|
||||||
from util.cluster import *
|
from util.cluster import *
|
||||||
|
import subprocess
|
||||||
|
|
||||||
BASEVERSION = "3.0.1.8"
|
BASEVERSION = "3.0.1.8"
|
||||||
class TDTestCase:
|
class TDTestCase:
|
||||||
|
|
@ -27,6 +28,19 @@ class TDTestCase:
|
||||||
tdLog.debug(f"start to excute {__file__}")
|
tdLog.debug(f"start to excute {__file__}")
|
||||||
tdSql.init(conn.cursor())
|
tdSql.init(conn.cursor())
|
||||||
|
|
||||||
|
def checkProcessPid(self,processName):
|
||||||
|
i=0
|
||||||
|
while i<60:
|
||||||
|
print(f"wait stop {processName}")
|
||||||
|
processPid = subprocess.getstatusoutput(f'ps aux|grep {processName} |grep -v "grep"|awk \'{{print $2}}\'')[1]
|
||||||
|
print(f"times:{i},{processName}-pid:{processPid}")
|
||||||
|
if(processPid == ""):
|
||||||
|
break
|
||||||
|
i += 1
|
||||||
|
sleep(1)
|
||||||
|
else:
|
||||||
|
print(f'this processName is not stoped in 60s')
|
||||||
|
|
||||||
|
|
||||||
def getBuildPath(self):
|
def getBuildPath(self):
|
||||||
selfPath = os.path.dirname(os.path.realpath(__file__))
|
selfPath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
@ -115,15 +129,15 @@ class TDTestCase:
|
||||||
# tdsqlF.query(f"select count(*) from {stb}")
|
# tdsqlF.query(f"select count(*) from {stb}")
|
||||||
# tdsqlF.checkData(0,0,tableNumbers*recordNumbers1)
|
# tdsqlF.checkData(0,0,tableNumbers*recordNumbers1)
|
||||||
os.system("pkill taosd")
|
os.system("pkill taosd")
|
||||||
sleep(2)
|
self.checkProcessPid("taosd")
|
||||||
|
|
||||||
print(f"start taosd: nohup taosd -c {cPath} & ")
|
print(f"start taosd: nohup taosd -c {cPath} & ")
|
||||||
os.system(f" nohup taosd -c {cPath} & " )
|
os.system(f" nohup taosd -c {cPath} & " )
|
||||||
sleep(10)
|
sleep(10)
|
||||||
tdLog.info(" LD_LIBRARY_PATH=/usr/lib taosBenchmark -f 0-others/compa4096.json -y ")
|
tdLog.info(" LD_LIBRARY_PATH=/usr/lib taosBenchmark -f 0-others/compa4096.json -y ")
|
||||||
os.system("LD_LIBRARY_PATH=/usr/lib taosBenchmark -f 0-others/compa4096.json -y")
|
os.system("LD_LIBRARY_PATH=/usr/lib taosBenchmark -f 0-others/compa4096.json -y")
|
||||||
os.system("pkill -9 taosd")
|
os.system("pkill taosd") # make sure all the data are saved in disk.
|
||||||
|
self.checkProcessPid("taosd")
|
||||||
|
|
||||||
|
|
||||||
tdLog.printNoPrefix("==========step2:update new version ")
|
tdLog.printNoPrefix("==========step2:update new version ")
|
||||||
|
|
|
||||||
|
|
@ -1719,6 +1719,7 @@ class TDTestCase:
|
||||||
print(err.errno)
|
print(err.errno)
|
||||||
|
|
||||||
def runAll(self):
|
def runAll(self):
|
||||||
|
"""
|
||||||
for value_type in ["obj", "default"]:
|
for value_type in ["obj", "default"]:
|
||||||
self.initCheckCase(value_type)
|
self.initCheckCase(value_type)
|
||||||
self.symbolsCheckCase(value_type)
|
self.symbolsCheckCase(value_type)
|
||||||
|
|
@ -1771,7 +1772,7 @@ class TDTestCase:
|
||||||
# self.sStbStbDdataDtsMtInsertMultiThreadCheckCase()
|
# self.sStbStbDdataDtsMtInsertMultiThreadCheckCase()
|
||||||
# self.sStbDtbDdataDtsMtInsertMultiThreadCheckCase()
|
# self.sStbDtbDdataDtsMtInsertMultiThreadCheckCase()
|
||||||
# self.lengthIcreaseCrashCheckCase()
|
# self.lengthIcreaseCrashCheckCase()
|
||||||
|
"""
|
||||||
def run(self):
|
def run(self):
|
||||||
print("running {}".format(__file__))
|
print("running {}".format(__file__))
|
||||||
self.createDb()
|
self.createDb()
|
||||||
|
|
|
||||||
|
|
@ -1416,8 +1416,8 @@ class TDTestCase:
|
||||||
self.symbolsCheckCase()
|
self.symbolsCheckCase()
|
||||||
self.tsCheckCase()
|
self.tsCheckCase()
|
||||||
self.openTstbTelnetTsCheckCase()
|
self.openTstbTelnetTsCheckCase()
|
||||||
self.idSeqCheckCase()
|
#self.idSeqCheckCase()
|
||||||
self.idLetterCheckCase()
|
#self.idLetterCheckCase()
|
||||||
self.noIdCheckCase()
|
self.noIdCheckCase()
|
||||||
self.maxColTagCheckCase()
|
self.maxColTagCheckCase()
|
||||||
self.stbTbNameCheckCase()
|
self.stbTbNameCheckCase()
|
||||||
|
|
@ -1450,7 +1450,7 @@ class TDTestCase:
|
||||||
self.spellCheckCase()
|
self.spellCheckCase()
|
||||||
self.pointTransCheckCase()
|
self.pointTransCheckCase()
|
||||||
self.defaultTypeCheckCase()
|
self.defaultTypeCheckCase()
|
||||||
self.tbnameTagsColsNameCheckCase()
|
#self.tbnameTagsColsNameCheckCase()
|
||||||
# # # MultiThreads
|
# # # MultiThreads
|
||||||
# self.stbInsertMultiThreadCheckCase()
|
# self.stbInsertMultiThreadCheckCase()
|
||||||
# self.sStbStbDdataInsertMultiThreadCheckCase()
|
# self.sStbStbDdataInsertMultiThreadCheckCase()
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class TDTestCase:
|
||||||
def init(self, conn, logSql, replicaVar=1):
|
def init(self, conn, logSql, replicaVar=1):
|
||||||
self.replicaVar = int(replicaVar)
|
self.replicaVar = int(replicaVar)
|
||||||
tdLog.debug(f"start to excute {__file__}")
|
tdLog.debug(f"start to excute {__file__}")
|
||||||
tdSql.init(conn.cursor())
|
tdSql.init(conn.cursor(), True)
|
||||||
#tdSql.init(conn.cursor(), logSql) # output sql.txt file
|
#tdSql.init(conn.cursor(), logSql) # output sql.txt file
|
||||||
|
|
||||||
def checkFileContent(self, dbname="sml_db"):
|
def checkFileContent(self, dbname="sml_db"):
|
||||||
|
|
@ -76,13 +76,14 @@ class TDTestCase:
|
||||||
tdSql.query(f"select * from {dbname}.`sys.cpu.nice` order by _ts")
|
tdSql.query(f"select * from {dbname}.`sys.cpu.nice` order by _ts")
|
||||||
tdSql.checkRows(2)
|
tdSql.checkRows(2)
|
||||||
tdSql.checkData(0, 1, 9.000000000)
|
tdSql.checkData(0, 1, 9.000000000)
|
||||||
tdSql.checkData(0, 2, "lga")
|
tdSql.checkData(0, 2, "web02")
|
||||||
tdSql.checkData(0, 3, "web02")
|
tdSql.checkData(0, 3, None)
|
||||||
tdSql.checkData(0, 4, None)
|
tdSql.checkData(0, 4, "lga")
|
||||||
|
|
||||||
tdSql.checkData(1, 1, 18.000000000)
|
tdSql.checkData(1, 1, 18.000000000)
|
||||||
tdSql.checkData(1, 2, "lga")
|
tdSql.checkData(1, 2, "web01")
|
||||||
tdSql.checkData(1, 3, "web01")
|
tdSql.checkData(1, 3, "t1")
|
||||||
tdSql.checkData(1, 4, "t1")
|
tdSql.checkData(0, 4, "lga")
|
||||||
|
|
||||||
tdSql.query(f"select * from {dbname}.macylr")
|
tdSql.query(f"select * from {dbname}.macylr")
|
||||||
tdSql.checkRows(2)
|
tdSql.checkRows(2)
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,11 @@ class TDTestCase:
|
||||||
|
|
||||||
def checkData(self):
|
def checkData(self):
|
||||||
tdSql.execute('use db_taosx')
|
tdSql.execute('use db_taosx')
|
||||||
|
tdSql.query("select * from tb1")
|
||||||
|
tdSql.checkRows(1)
|
||||||
|
tdSql.checkData(0, 1, 0)
|
||||||
|
tdSql.checkData(0, 2, 1)
|
||||||
|
|
||||||
tdSql.query("select * from ct3 order by c1 desc")
|
tdSql.query("select * from ct3 order by c1 desc")
|
||||||
tdSql.checkRows(2)
|
tdSql.checkRows(2)
|
||||||
tdSql.checkData(0, 1, 51)
|
tdSql.checkData(0, 1, 51)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/bin/bash
|
||||||
|
ulimit -c unlimited
|
||||||
|
#======================p1-insert===============
|
||||||
|
|
||||||
|
python3 ./test.py -f 0-others/taosShell.py
|
||||||
|
python3 ./test.py -f 0-others/taosShellError.py
|
||||||
|
python3 ./test.py -f 0-others/taosShellNetChk.py
|
||||||
|
python3 ./test.py -f 1-insert/alter_database.py
|
||||||
|
python3 ./test.py -f 1-insert/influxdb_line_taosc_insert.py
|
||||||
|
python3 ./test.py -f 1-insert/opentsdb_telnet_line_taosc_insert.py
|
||||||
|
python3 ./test.py -f 1-insert/opentsdb_json_taosc_insert.py
|
||||||
|
python3 ./test.py -f 1-insert/test_stmt_muti_insert_query.py
|
||||||
|
python3 ./test.py -f 1-insert/test_stmt_set_tbname_tag.py
|
||||||
|
python3 ./test.py -f 1-insert/alter_stable.py
|
||||||
|
python3 ./test.py -f 1-insert/alter_table.py
|
||||||
|
python3 ./test.py -f 1-insert/boundary.py
|
||||||
|
python3 ./test.py -f 2-query/top.py
|
||||||
|
python3 ./test.py -f 2-query/top.py -R
|
||||||
|
python3 ./test.py -f 2-query/tsbsQuery.py
|
||||||
|
python3 ./test.py -f 2-query/tsbsQuery.py -R
|
||||||
|
python3 ./test.py -f 2-query/ttl_comment.py
|
||||||
|
python3 ./test.py -f 2-query/ttl_comment.py -R
|
||||||
|
python3 ./test.py -f 2-query/twa.py
|
||||||
|
python3 ./test.py -f 2-query/twa.py -R
|
||||||
|
python3 ./test.py -f 2-query/union.py
|
||||||
|
python3 ./test.py -f 2-query/union.py -R
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode1mnode.py
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -N 5 -M 3
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -N 5 -M 3 -i False
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode3mnodeStop2Follower.py -N 5 -M 3
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode3mnodeStop2Follower.py -N 5 -M 3 -i False
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode3mnodeStopLoop.py -N 5 -M 3
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py -N 6 -M 3
|
||||||
|
python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py -N 6 -M 3 -n 3
|
||||||
|
python3 ./test.py -f 7-tmq/subscribeStb4.py
|
||||||
|
python3 ./test.py -f 7-tmq/db.py
|
||||||
|
python3 ./test.py -f 7-tmq/tmqError.py
|
||||||
|
python3 ./test.py -f 7-tmq/schema.py
|
||||||
|
python3 ./test.py -f 7-tmq/stbFilter.py
|
||||||
|
python3 ./test.py -f 7-tmq/tmqCheckData.py
|
||||||
|
python3 ./test.py -f 7-tmq/tmqCheckData1.py
|
||||||
|
python3 ./test.py -f 7-tmq/tmqConsumerGroup.py
|
||||||
|
python3 ./test.py -f 7-tmq/tmqShow.py
|
||||||
|
python3 ./test.py -f 7-tmq/tmqAlterSchema.
|
||||||
|
python3 ./test.py -f 99-TDcase/TD-20582.py
|
||||||
|
|
@ -78,11 +78,20 @@ int smlProcess_telnet_Test() {
|
||||||
pRes = taos_query(taos, "use sml_db");
|
pRes = taos_query(taos, "use sml_db");
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
const char *sql[] = {"sys.if.bytes.out 1479496100 1.3E0 host=web01 interface=eth0",
|
char *sql[4] = {0};
|
||||||
|
sql[0] = taosMemoryCalloc(1, 128);
|
||||||
|
sql[1] = taosMemoryCalloc(1, 128);
|
||||||
|
sql[2] = taosMemoryCalloc(1, 128);
|
||||||
|
sql[3] = taosMemoryCalloc(1, 128);
|
||||||
|
const char *sql1[] = {"sys.if.bytes.out 1479496100 1.3E0 host=web01 interface=eth0",
|
||||||
"sys.if.bytes.out 1479496101 1.3E1 interface=eth0 host=web01 ",
|
"sys.if.bytes.out 1479496101 1.3E1 interface=eth0 host=web01 ",
|
||||||
"sys.if.bytes.out 1479496102 1.3E3 network=tcp",
|
"sys.if.bytes.out 1479496102 1.3E3 network=tcp",
|
||||||
" sys.procs.running 1479496100 42 host=web01 "};
|
" sys.procs.running 1479496100 42 host=web01 "};
|
||||||
|
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
strncpy(sql[i], sql1[i], 128);
|
||||||
|
}
|
||||||
|
|
||||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_TELNET_PROTOCOL,
|
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_TELNET_PROTOCOL,
|
||||||
TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||||
printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
|
printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
|
||||||
|
|
@ -147,28 +156,7 @@ int smlProcess_json3_Test() {
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
const char *sql[] = {
|
const char *sql[] = {
|
||||||
"{\"metric\":\"meter_current1\",\"timestamp\":{\"value\":1662344042,\"type\":\"s\"},\"value\":{\"value\":10.3,\"type\":\"i64\"},\"tags\":{\"t1\":{\"value\":2,\"type\":\"bigint\"},\"t2\":{\"value\":2,\"type\":\"int\"},\"t3\":{\"value\":2,\"type\":\"i16\"},\"t4\":{\"value\":2,\"type\":\"i8\"},\"t5\":{\"value\":2,\"type\":\"f32\"},\"t6\":{\"value\":2,\"type\":\"double\"},\"t7\":{\"value\":\"8323\",\"type\":\"binary\"},\"t8\":{\"value\":\"北京\",\"type\":\"nchar\"},\"t9\":{\"value\":true,\"type\":\"bool\"},\"id\":\"d1001\"}}"};
|
"[{\"metric\":\"sys.cpu.nice\",\"timestamp\":0,\"value\":\"18\",\"tags\":{\"host\":\"web01\",\"id\":\"t1\",\"dc\":\"lga\"}}]"
|
||||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL,
|
|
||||||
TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
|
||||||
printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
|
|
||||||
int code = taos_errno(pRes);
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(taos);
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int smlProcess_json4_Test() {
|
|
||||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
|
|
||||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
pRes = taos_query(taos, "use sml_db");
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
const char *sql[] = {
|
|
||||||
"{\"metric\":\"meter_current2\",\"timestamp\":{\"value\":1662344042000,\"type\":\"ms\"},\"value\":\"ni\",\"tags\":{\"t1\":{\"value\":20,\"type\":\"i64\"},\"t2\":{\"value\":25,\"type\":\"i32\"},\"t3\":{\"value\":2,\"type\":\"smallint\"},\"t4\":{\"value\":2,\"type\":\"tinyint\"},\"t5\":{\"value\":2,\"type\":\"float\"},\"t6\":{\"value\":0.2,\"type\":\"f64\"},\"t7\":\"nsj\",\"t8\":{\"value\":\"北京\",\"type\":\"nchar\"},\"t9\":false,\"id\":\"d1001\"}}"
|
|
||||||
};
|
};
|
||||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL,
|
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL,
|
||||||
TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||||
|
|
@ -677,52 +665,6 @@ int sml_oom_Test() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sml_16368_Test() {
|
|
||||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
|
|
||||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
pRes = taos_query(taos, "use sml_db");
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
const char *sql[] = {
|
|
||||||
"[{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833639000, \"type\": \"us\"}, \"value\": 1, "
|
|
||||||
"\"tags\": {\"t1\": 3, \"t2\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t3\", \"type\": "
|
|
||||||
"\"binary\"}}},"
|
|
||||||
"{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833739000, \"type\": \"us\"}, \"value\": 2, "
|
|
||||||
"\"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, "
|
|
||||||
"\"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},"
|
|
||||||
"{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006833639100, \"type\": \"us\"}, \"value\": 3, "
|
|
||||||
"\"tags\": {\"t2\": {\"value\": 5, \"type\": \"double\"}, \"t3\": {\"value\": \"ste\", \"type\": \"nchar\"}}},"
|
|
||||||
"{\"metric\": \"stf567890\", \"timestamp\": {\"value\": 1626006833639200, \"type\": \"us\"}, \"value\": 4, "
|
|
||||||
"\"tags\": {\"t1\": {\"value\": 4, \"type\": \"bigint\"}, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, "
|
|
||||||
"\"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}},"
|
|
||||||
"{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833639300, \"type\": \"us\"}, \"value\": "
|
|
||||||
"{\"value\": 5, \"type\": \"double\"}, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t2\": 5.0, "
|
|
||||||
"\"t3\": {\"value\": \"t4\", \"type\": \"binary\"}}},"
|
|
||||||
"{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006833639400, \"type\": \"us\"}, \"value\": "
|
|
||||||
"{\"value\": 6, \"type\": \"double\"}, \"tags\": {\"t2\": 5.0, \"t3\": {\"value\": \"ste2\", \"type\": "
|
|
||||||
"\"nchar\"}}},"
|
|
||||||
"{\"metric\": \"stb_name\", \"timestamp\": {\"value\": 1626006834639400, \"type\": \"us\"}, \"value\": "
|
|
||||||
"{\"value\": 7, \"type\": \"double\"}, \"tags\": {\"t2\": {\"value\": 5.0, \"type\": \"double\"}, \"t3\": "
|
|
||||||
"{\"value\": \"ste2\", \"type\": \"nchar\"}}},"
|
|
||||||
"{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833839006, \"type\": \"us\"}, \"value\": "
|
|
||||||
"{\"value\": 8, \"type\": \"double\"}, \"tags\": {\"t1\": {\"value\": 4, \"type\": \"double\"}, \"t3\": "
|
|
||||||
"{\"value\": \"t4\", \"type\": \"binary\"}, \"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, "
|
|
||||||
"\"type\": \"double\"}}},"
|
|
||||||
"{\"metric\": \"st123456\", \"timestamp\": {\"value\": 1626006833939007, \"type\": \"us\"}, \"value\": "
|
|
||||||
"{\"value\": 9, \"type\": \"double\"}, \"tags\": {\"t1\": 4, \"t3\": {\"value\": \"t4\", \"type\": \"binary\"}, "
|
|
||||||
"\"t2\": {\"value\": 5, \"type\": \"double\"}, \"t4\": {\"value\": 5, \"type\": \"double\"}}}]"};
|
|
||||||
pRes = taos_schemaless_insert(taos, (char **)sql, 0, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_MICRO_SECONDS);
|
|
||||||
printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
|
|
||||||
int code = taos_errno(pRes);
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(taos);
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sml_dup_time_Test() {
|
int sml_dup_time_Test() {
|
||||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
|
||||||
|
|
@ -762,214 +704,6 @@ int sml_dup_time_Test() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sml_16960_Test() {
|
|
||||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
|
|
||||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
pRes = taos_query(taos, "use sml_db");
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
const char *sql[] = {
|
|
||||||
"["
|
|
||||||
"{"
|
|
||||||
"\"timestamp\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 1664418955000, \"type\": \"ms\" }"
|
|
||||||
","
|
|
||||||
"\"value\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 830525384, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"tags\": {"
|
|
||||||
"\"id\": \"stb00_0\","
|
|
||||||
"\"t0\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 83972721, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t1\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 539147525, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t2\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 618258572, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t3\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -10536201, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t4\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 349227409, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t5\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 249347042, \"type\": \"int\" }"
|
|
||||||
"},"
|
|
||||||
"\"metric\": \"stb0\""
|
|
||||||
"},"
|
|
||||||
"{"
|
|
||||||
"\"timestamp\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 1664418955001, \"type\": \"ms\" }"
|
|
||||||
","
|
|
||||||
"\"value\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -588348364, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"tags\": {"
|
|
||||||
"\"id\": \"stb00_0\","
|
|
||||||
"\"t0\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 83972721, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t1\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 539147525, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t2\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 618258572, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t3\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -10536201, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t4\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 349227409, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t5\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 249347042, \"type\": \"int\" }"
|
|
||||||
"},"
|
|
||||||
"\"metric\": \"stb0\""
|
|
||||||
"},"
|
|
||||||
"{"
|
|
||||||
"\"timestamp\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 1664418955002, \"type\": \"ms\" }"
|
|
||||||
","
|
|
||||||
"\"value\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -370310823, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"tags\": {"
|
|
||||||
"\"id\": \"stb00_0\","
|
|
||||||
"\"t0\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 83972721, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t1\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 539147525, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t2\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 618258572, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t3\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -10536201, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t4\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 349227409, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t5\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 249347042, \"type\": \"int\" }"
|
|
||||||
"},"
|
|
||||||
"\"metric\": \"stb0\""
|
|
||||||
"},"
|
|
||||||
"{"
|
|
||||||
"\"timestamp\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 1664418955003, \"type\": \"ms\" }"
|
|
||||||
","
|
|
||||||
"\"value\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -811250191, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"tags\": {"
|
|
||||||
"\"id\": \"stb00_0\","
|
|
||||||
"\"t0\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 83972721, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t1\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 539147525, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t2\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 618258572, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t3\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -10536201, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t4\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 349227409, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t5\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 249347042, \"type\": \"int\" }"
|
|
||||||
"},"
|
|
||||||
"\"metric\": \"stb0\""
|
|
||||||
"},"
|
|
||||||
"{"
|
|
||||||
"\"timestamp\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 1664418955004, \"type\": \"ms\" }"
|
|
||||||
","
|
|
||||||
"\"value\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -330340558, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"tags\": {"
|
|
||||||
"\"id\": \"stb00_0\","
|
|
||||||
"\"t0\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 83972721, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t1\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 539147525, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t2\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 618258572, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t3\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": -10536201, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t4\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 349227409, \"type\": \"int\" }"
|
|
||||||
","
|
|
||||||
"\"t5\":"
|
|
||||||
""
|
|
||||||
"{ \"value\": 249347042, \"type\": \"int\" }"
|
|
||||||
"},"
|
|
||||||
"\"metric\": \"stb0\""
|
|
||||||
"}"
|
|
||||||
"]"};
|
|
||||||
|
|
||||||
pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_JSON_PROTOCOL,
|
|
||||||
TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
|
||||||
printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
|
|
||||||
int code = taos_errno(pRes);
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(taos);
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sml_add_tag_col_Test() {
|
int sml_add_tag_col_Test() {
|
||||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
|
||||||
|
|
@ -1004,10 +738,10 @@ int sml_add_tag_col_Test() {
|
||||||
int smlProcess_18784_Test() {
|
int smlProcess_18784_Test() {
|
||||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
|
||||||
TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1");
|
TAOS_RES *pRes = taos_query(taos, "create database if not exists db_18784 schemaless 1");
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(taos, "use sml_db");
|
pRes = taos_query(taos, "use db_18784");
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
const char *sql[] = {
|
const char *sql[] = {
|
||||||
|
|
@ -1018,7 +752,7 @@ int smlProcess_18784_Test() {
|
||||||
printf("%s result:%s, rows:%d\n", __FUNCTION__, taos_errstr(pRes), taos_affected_rows(pRes));
|
printf("%s result:%s, rows:%d\n", __FUNCTION__, taos_errstr(pRes), taos_affected_rows(pRes));
|
||||||
int code = taos_errno(pRes);
|
int code = taos_errno(pRes);
|
||||||
ASSERT(!code);
|
ASSERT(!code);
|
||||||
ASSERT(taos_affected_rows(pRes) == 2);
|
ASSERT(taos_affected_rows(pRes) == 1);
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(taos, "select * from disk");
|
pRes = taos_query(taos, "select * from disk");
|
||||||
|
|
@ -1092,9 +826,10 @@ int sml_ts2164_Test() {
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
const char *sql[] = {
|
const char *sql[] = {
|
||||||
|
// "meters,location=la,groupid=ca current=11.8,voltage=221,phase=0.27",
|
||||||
|
"meters,location=la,groupid=ca current=11.8,voltage=221",
|
||||||
"meters,location=la,groupid=ca current=11.8,voltage=221,phase=0.27",
|
"meters,location=la,groupid=ca current=11.8,voltage=221,phase=0.27",
|
||||||
"meters,location=la,groupid=ca current=11.8,voltage=221,phase=0.27",
|
// "meters,location=la,groupid=cb current=11.8,voltage=221,phase=0.27",
|
||||||
"meters,location=la,groupid=cb current=11.8,voltage=221,phase=0.27",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pRes = taos_query(taos, "use line_test");
|
pRes = taos_query(taos, "use line_test");
|
||||||
|
|
@ -1119,6 +854,9 @@ int sml_ttl_Test() {
|
||||||
const char *sql[] = {
|
const char *sql[] = {
|
||||||
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=\"2022-02-0210:22:22\" 1626006833739000000",
|
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=\"2022-02-0210:22:22\" 1626006833739000000",
|
||||||
};
|
};
|
||||||
|
const char *sql1[] = {
|
||||||
|
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=\"2022-02-0210:22:22\" 1626006833339000000",
|
||||||
|
};
|
||||||
|
|
||||||
pRes = taos_query(taos, "use sml_db");
|
pRes = taos_query(taos, "use sml_db");
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
@ -1128,6 +866,11 @@ int sml_ttl_Test() {
|
||||||
printf("%s result1:%s\n", __FUNCTION__, taos_errstr(pRes));
|
printf("%s result1:%s\n", __FUNCTION__, taos_errstr(pRes));
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
|
pRes = taos_schemaless_insert_ttl(taos, (char **)sql1, sizeof(sql1) / sizeof(sql1[0]), TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS, 20);
|
||||||
|
|
||||||
|
printf("%s result1:%s\n", __FUNCTION__, taos_errstr(pRes));
|
||||||
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(taos, "select `ttl` from information_schema.ins_tables where table_name='t_be97833a0e1f523fcdaeb6291d6fdf27'");
|
pRes = taos_query(taos, "select `ttl` from information_schema.ins_tables where table_name='t_be97833a0e1f523fcdaeb6291d6fdf27'");
|
||||||
printf("%s result2:%s\n", __FUNCTION__, taos_errstr(pRes));
|
printf("%s result2:%s\n", __FUNCTION__, taos_errstr(pRes));
|
||||||
TAOS_ROW row = taos_fetch_row(pRes);
|
TAOS_ROW row = taos_fetch_row(pRes);
|
||||||
|
|
@ -1141,7 +884,46 @@ int sml_ttl_Test() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//char *str[] ={
|
||||||
|
// "",
|
||||||
|
// "f64",
|
||||||
|
// "F64",
|
||||||
|
// "f32",
|
||||||
|
// "F32",
|
||||||
|
// "i",
|
||||||
|
// "I",
|
||||||
|
// "i64",
|
||||||
|
// "I64",
|
||||||
|
// "u",
|
||||||
|
// "U",
|
||||||
|
// "u64",
|
||||||
|
// "U64",
|
||||||
|
// "i32",
|
||||||
|
// "I32",
|
||||||
|
// "u32",
|
||||||
|
// "U32",
|
||||||
|
// "i16",
|
||||||
|
// "I16",
|
||||||
|
// "u16",
|
||||||
|
// "U16",
|
||||||
|
// "i8",
|
||||||
|
// "I8",
|
||||||
|
// "u8",
|
||||||
|
// "U8",
|
||||||
|
//};
|
||||||
|
//uint8_t smlCalTypeSum(char* endptr, int32_t left){
|
||||||
|
// uint8_t sum = 0;
|
||||||
|
// for(int i = 0; i < left; i++){
|
||||||
|
// sum += endptr[i];
|
||||||
|
// }
|
||||||
|
// return sum;
|
||||||
|
//}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
// for(int i = 0; i < sizeof(str)/sizeof(str[0]); i++){
|
||||||
|
// printf("str:%s \t %d\n", str[i], smlCalTypeSum(str[i], strlen(str[i])));
|
||||||
|
// }
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
ret = sml_ttl_Test();
|
ret = sml_ttl_Test();
|
||||||
ASSERT(!ret);
|
ASSERT(!ret);
|
||||||
|
|
@ -1154,11 +936,9 @@ int main(int argc, char *argv[]) {
|
||||||
ret = smlProcess_json1_Test();
|
ret = smlProcess_json1_Test();
|
||||||
ASSERT(!ret);
|
ASSERT(!ret);
|
||||||
ret = smlProcess_json2_Test();
|
ret = smlProcess_json2_Test();
|
||||||
ASSERT(!ret);
|
ASSERT(ret);
|
||||||
ret = smlProcess_json3_Test();
|
ret = smlProcess_json3_Test();
|
||||||
ASSERT(!ret);
|
ASSERT(ret);
|
||||||
ret = smlProcess_json4_Test();
|
|
||||||
ASSERT(!ret);
|
|
||||||
ret = sml_TD15662_Test();
|
ret = sml_TD15662_Test();
|
||||||
ASSERT(!ret);
|
ASSERT(!ret);
|
||||||
ret = sml_TD15742_Test();
|
ret = sml_TD15742_Test();
|
||||||
|
|
@ -1167,12 +947,8 @@ int main(int argc, char *argv[]) {
|
||||||
ASSERT(!ret);
|
ASSERT(!ret);
|
||||||
ret = sml_oom_Test();
|
ret = sml_oom_Test();
|
||||||
ASSERT(!ret);
|
ASSERT(!ret);
|
||||||
ret = sml_16368_Test();
|
|
||||||
ASSERT(!ret);
|
|
||||||
ret = sml_dup_time_Test();
|
ret = sml_dup_time_Test();
|
||||||
ASSERT(!ret);
|
ASSERT(!ret);
|
||||||
ret = sml_16960_Test();
|
|
||||||
ASSERT(!ret);
|
|
||||||
ret = sml_add_tag_col_Test();
|
ret = sml_add_tag_col_Test();
|
||||||
ASSERT(!ret);
|
ASSERT(!ret);
|
||||||
ret = smlProcess_18784_Test();
|
ret = smlProcess_18784_Test();
|
||||||
|
|
|
||||||
|
|
@ -78,28 +78,27 @@ static void msg_process(TAOS_RES* msg) {
|
||||||
int buildDatabase(TAOS* pConn, TAOS_RES* pRes){
|
int buildDatabase(TAOS* pConn, TAOS_RES* pRes){
|
||||||
|
|
||||||
/* test for TD-20612 start*/
|
/* test for TD-20612 start*/
|
||||||
// pRes = taos_query(pConn,"create table tb1 (ts timestamp, c1 int, c2 int)");
|
pRes = taos_query(pConn,"create table tb1 (ts timestamp, c1 int, c2 int)");
|
||||||
// if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
// printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||||
// return -1;
|
return -1;
|
||||||
// }
|
}
|
||||||
// taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
//
|
|
||||||
// pRes = taos_query(pConn,"insert into tb1 (ts, c1) values(1669092069069, 0)");
|
pRes = taos_query(pConn,"insert into tb1 (ts, c1) values(1669092069069, 0)");
|
||||||
// if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
// printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||||
// return -1;
|
return -1;
|
||||||
// }
|
}
|
||||||
// taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
//
|
|
||||||
// pRes = taos_query(pConn,"insert into tb1 (ts, c2) values(1669092069069, 1)");
|
pRes = taos_query(pConn,"insert into tb1 (ts, c2) values(1669092069069, 1)");
|
||||||
// if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
// printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||||
// return -1;
|
return -1;
|
||||||
// }
|
}
|
||||||
// taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
//
|
|
||||||
// return 0;
|
|
||||||
/* test for TD-20612 end*/
|
/* test for TD-20612 end*/
|
||||||
|
|
||||||
pRes = taos_query(pConn,
|
pRes = taos_query(pConn,
|
||||||
|
|
@ -614,6 +613,7 @@ void initLogFile() {
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
char *result[] = {
|
char *result[] = {
|
||||||
|
"{\"type\":\"create\",\"tableType\":\"normal\",\"tableName\":\"tb1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":4}],\"tags\":[]}",
|
||||||
"{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"st1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":64},{\"name\":\"c4\",\"type\":5}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1},{\"name\":\"t2\",\"type\":8,\"length\":64}]}",
|
"{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"st1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":64},{\"name\":\"c4\",\"type\":5}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1},{\"name\":\"t2\",\"type\":8,\"length\":64}]}",
|
||||||
"{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct0\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
|
"{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct0\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
|
||||||
"{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct1\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}],\"createList\":[]}",
|
"{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct1\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}],\"createList\":[]}",
|
||||||
|
|
@ -652,6 +652,7 @@ void initLogFile() {
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
char *result[] = {
|
char *result[] = {
|
||||||
|
"{\"type\":\"create\",\"tableType\":\"normal\",\"tableName\":\"tb1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":4}],\"tags\":[]}",
|
||||||
"{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"st1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
|
"{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"st1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
|
||||||
"{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct0\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
|
"{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct0\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
|
||||||
"{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct1\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}],\"createList\":[]}",
|
"{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct1\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}],\"createList\":[]}",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue