diff --git a/cmake/cmake.version b/cmake/cmake.version
index 05094f10cc..1a83126cd7 100644
--- a/cmake/cmake.version
+++ b/cmake/cmake.version
@@ -2,7 +2,7 @@
IF (DEFINED VERNUMBER)
SET(TD_VER_NUMBER ${VERNUMBER})
ELSE ()
- SET(TD_VER_NUMBER "3.0.1.4")
+ SET(TD_VER_NUMBER "3.0.1.5")
ENDIF ()
IF (DEFINED VERCOMPATIBLE)
diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in
index ea4d48a2b1..c19928c7a9 100644
--- a/cmake/taostools_CMakeLists.txt.in
+++ b/cmake/taostools_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taos-tools
ExternalProject_Add(taos-tools
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
- GIT_TAG c64858f
+ GIT_TAG cc973e0
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
diff --git a/docs/en/12-taos-sql/10-function.md b/docs/en/12-taos-sql/10-function.md
index 2b39c4b9e5..6145d8c00c 100644
--- a/docs/en/12-taos-sql/10-function.md
+++ b/docs/en/12-taos-sql/10-function.md
@@ -863,6 +863,7 @@ INTERP(expr)
- `INTERP` is used to get the value that matches the specified time slice from a column. If no such value exists an interpolation value will be returned based on `FILL` parameter.
- The input data of `INTERP` is the value of the specified column and a `where` clause can be used to filter the original data. If no `where` condition is specified then all original data is the input.
+- `INTERP` must be used along with `RANGE`, `EVERY`, `FILL` keywords.
- The output time range of `INTERP` is specified by `RANGE(timestamp1,timestamp2)` parameter, with timestamp1<=timestamp2. timestamp1 is the starting point of the output time range and must be specified. timestamp2 is the ending point of the output time range and must be specified.
- The number of rows in the result set of `INTERP` is determined by the parameter `EVERY`. Starting from timestamp1, one interpolation is performed for every time interval specified `EVERY` parameter. The parameter `EVERY` must be an integer, with no quotes, with a time unit of: b(nanosecond), u(microsecond), a(millisecond)), s(second), m(minute), h(hour), d(day), or w(week). For example, `EVERY(500a)` will interpolate every 500 milliseconds.
- Interpolation is performed based on `FILL` parameter.
@@ -945,7 +946,7 @@ MIN(expr)
MODE(expr)
```
-**Description**:The value which has the highest frequency of occurrence. NULL is returned if there are multiple values which have highest frequency of occurrence.
+**Description**:The value which has the highest frequency of occurrence. One random value is returned if there are multiple values which have highest frequency of occurrence.
**Return value type**: Same as the input data
diff --git a/docs/en/14-reference/03-connector/05-go.mdx b/docs/en/14-reference/03-connector/05-go.mdx
index f00e635af9..a33b302a92 100644
--- a/docs/en/14-reference/03-connector/05-go.mdx
+++ b/docs/en/14-reference/03-connector/05-go.mdx
@@ -7,7 +7,6 @@ title: TDengine Go Connector
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
-import Preparition from "./_preparation.mdx"
import GoInsert from "../../07-develop/03-insert-data/_go_sql.mdx"
import GoInfluxLine from "../../07-develop/03-insert-data/_go_line.mdx"
import GoOpenTSDBTelnet from "../../07-develop/03-insert-data/_go_opts_telnet.mdx"
@@ -176,6 +175,37 @@ func main() {
}
```
+
+
+_taosRestful_ implements Go's `database/sql/driver` interface via `http client`. You can use the [`database/sql`](https://golang.org/pkg/database/sql/) interface by simply introducing the driver (driver-go minimum version 3.0.2).
+
+Use `taosWS` as `driverName` and use a correct [DSN](#DSN) as `dataSourceName` with the following parameters supported by the DSN.
+
+* `writeTimeout` The timeout to send data via WebSocket.
+* `readTimeout` The timeout to receive response data via WebSocket.
+
+For example:
+
+```go
+package main
+
+import (
+ "database/sql"
+ "fmt"
+
+ _ "github.com/taosdata/driver-go/v3/taosWS"
+)
+
+func main() {
+ var taosUri = "root:taosdata@ws(localhost:6041)/"
+ taos, err := sql.Open("taosWS", taosUri)
+ if err != nil {
+ fmt.Println("failed to connect TDengine, err:", err)
+ return
+ }
+}
+```
+
## Usage examples
@@ -331,7 +361,7 @@ Creates consumer group.
* `func (c *Consumer) Subscribe(topics []string) error`
-Subscribes to a topic.
+Subscribes to topics.
* `func (c *Consumer) Poll(timeout time.Duration) (*Result, error)`
@@ -409,6 +439,30 @@ Close consumer.
Closes the parameter binding.
+### Subscribe via WebSocket
+
+* `func NewConsumer(config *Config) (*Consumer, error)`
+
+ Creates consumer group.
+
+* `func (c *Consumer) Subscribe(topic []string) error`
+
+ Subscribes to topics.
+
+* `func (c *Consumer) Poll(timeout time.Duration) (*Result, error)`
+
+ Polling information.
+
+* `func (c *Consumer) Commit(messageID uint64) error`
+
+ Commit information.
+
+* `func (c *Consumer) Close() error`
+
+ Close consumer.
+
+For a complete example see [GitHub sample file](https://github.com/taosdata/driver-go/blob/3.0/examples/tmqoverws/main.go)
+
## API Reference
Full API see [driver-go documentation](https://pkg.go.dev/github.com/taosdata/driver-go/v3)
diff --git a/docs/en/14-reference/03-connector/_macos_install.mdx b/docs/en/14-reference/03-connector/_macos_install.mdx
index 8813d65869..effabbbebe 100644
--- a/docs/en/14-reference/03-connector/_macos_install.mdx
+++ b/docs/en/14-reference/03-connector/_macos_install.mdx
@@ -2,7 +2,7 @@ import PkgListV3 from "/components/PkgListV3";
1. Download the client installation package
-
+
[All Downloads](../../releases/tdengine)
diff --git a/docs/en/28-releases/01-tdengine.md b/docs/en/28-releases/01-tdengine.md
index 808a21474e..14096bd400 100644
--- a/docs/en/28-releases/01-tdengine.md
+++ b/docs/en/28-releases/01-tdengine.md
@@ -6,6 +6,10 @@ description: TDengine release history, Release Notes and download links.
import Release from "/components/ReleaseV3";
+## 3.0.1.5
+
+
+
## 3.0.1.4
diff --git a/docs/en/28-releases/02-tools.md b/docs/en/28-releases/02-tools.md
index 5d6693ae73..a7446be4e3 100644
--- a/docs/en/28-releases/02-tools.md
+++ b/docs/en/28-releases/02-tools.md
@@ -6,6 +6,10 @@ description: taosTools release history, Release Notes, download links.
import Release from "/components/ReleaseV3";
+## 2.2.6
+
+
+
## 2.2.4
diff --git a/docs/zh/07-develop/07-tmq.mdx b/docs/zh/07-develop/07-tmq.mdx
index d9a35ab4eb..1f5a089aaa 100644
--- a/docs/zh/07-develop/07-tmq.mdx
+++ b/docs/zh/07-develop/07-tmq.mdx
@@ -247,7 +247,7 @@ CREATE TOPIC topic_name as subquery
- 该类型 TOPIC 一旦创建则订阅数据的结构确定。
- 被订阅或用于计算的列或标签不可被删除(`ALTER table DROP`)、修改(`ALTER table MODIFY`)。
-- 若发生表结构变更,新增的列不出现在结果中,若发生列删除则会报错。
+- 若发生表结构变更,新增的列不出现在结果中。
### 超级表订阅
@@ -269,10 +269,10 @@ CREATE TOPIC topic_name AS STABLE stb_name
语法:
```sql
-CREATE TOPIC topic_name [WITH META] AS DATABASE db_name;
+CREATE TOPIC topic_name AS DATABASE db_name;
```
-通过该语句可创建一个包含数据库所有表数据的订阅,`WITH META` 可选择将数据库结构变动信息加入到订阅消息流,TMQ 将消费当前数据库下所有表结构的变动,包括超级表的创建与删除,列添加、删除或修改,子表的创建、删除及 TAG 变动信息等等。消费者可通过 API 来判断具体的消息类型。这一点也是与 Kafka 不同的地方。
+通过该语句可创建一个包含数据库所有表数据的订阅
## 创建消费者 *consumer*
@@ -282,16 +282,16 @@ CREATE TOPIC topic_name [WITH META] AS DATABASE db_name;
| :----------------------------: | :-----: | -------------------------------------------------------- | ------------------------------------------- |
| `td.connect.ip` | string | 用于创建连接,同 `taos_connect` | |
| `td.connect.user` | string | 用于创建连接,同 `taos_connect` | |
-| `td.connect.pass` | string | 用于创建连接,同 `taos_connect` |
-| `td.connect.port` | integer | 用于创建连接,同 `taos_connect` |
+| `td.connect.pass` | string | 用于创建连接,同 `taos_connect` | |
+| `td.connect.port` | integer | 用于创建连接,同 `taos_connect` | |
| `group.id` | string | 消费组 ID,同一消费组共享消费进度 | **必填项**。最大长度:192。 |
| `client.id` | string | 客户端 ID | 最大长度:192。 |
-| `auto.offset.reset` | enum | 消费组订阅的初始位置 | 可选:`earliest`, `latest`, `none`(default) |
-| `enable.auto.commit` | boolean | 启用自动提交 | 合法值:`true`, `false`。 |
-| `auto.commit.interval.ms` | integer | 以毫秒为单位的自动提交时间间隔 |
-| `enable.heartbeat.background` | boolean | 启用后台心跳,启用后即使长时间不 poll 消息也不会造成离线 | |
-| `experimental.snapshot.enable` | boolean | 从 WAL 开始消费,还是从 TSBS 开始消费 | |
-| `msg.with.table.name` | boolean | 是否允许从消息中解析表名 |
+| `auto.offset.reset` | enum | 消费组订阅的初始位置 | 可选:`earliest`(default), `latest`, `none` |
+| `enable.auto.commit` | boolean | 是否启用消费位点自动提交 | 合法值:`true`, `false`。 |
+| `auto.commit.interval.ms` | integer | 以毫秒为单位的消费记录自动提交消费位点时间间 | 默认 5000 m |
+| `enable.heartbeat.background` | boolean | 启用后台心跳,启用后即使长时间不 poll 消息也不会造成离线 | 默认开启 |
+| `experimental.snapshot.enable` | boolean | 是否允许从 TSDB 消费数据 | 实验功能,默认关闭 |
+| `msg.with.table.name` | boolean | 是否允许从消息中解析表名, 不适用于列订阅(列订阅时可将 tbname 作为列写入 subquery 语句) | |
对于不同编程语言,其设置方式如下:
@@ -420,7 +420,18 @@ let mut consumer = tmq.build()?;
-Python 使用以下配置项创建一个 Consumer 实例。
+Python 语言下引入 `taos` 库的 `TaosConsumer` 类,创建一个 Consumer 示例:
+
+```python
+from taos.tmq import TaosConsumer
+
+# Syntax: `consumer = TaosConsumer(*topics, **args)`
+#
+# Example:
+consumer = TaosConsumer('topic1', 'topic2', td_connect_ip = "127.0.0.1", group_id = "local")
+```
+
+其中,元组类型参数被视为 *Topics*,字典类型参数用于以下订阅配置设置:
| 参数名称 | 类型 | 参数说明 | 备注 |
| :----------------------------: | :----: | -------------------------------------------------------- | ------------------------------------------- |
@@ -430,13 +441,13 @@ Python 使用以下配置项创建一个 Consumer 实例。
| `td_connect_port` | string | 用于创建连接,同 `taos_connect` | |
| `group_id` | string | 消费组 ID,同一消费组共享消费进度 | **必填项**。最大长度:192。 |
| `client_id` | string | 客户端 ID | 最大长度:192。 |
-| `auto_offset_reset` | string | 消费组订阅的初始位置 | 可选:`earliest`, `latest`, `none`(default) |
-| `enable_auto_commit` | string | 启用自动提交 | 合法值:`true`, `false`。 |
-| `auto_commit_interval_ms` | string | 以毫秒为单位的自动提交时间间隔 | |
+| `auto_offset_reset` | string | 消费组订阅的初始位置 | 可选:`earliest`(default), `latest`, `none` |
+| `enable_auto_commit` | string | 启用自动提交 | 合法值:`true`, `false`,默认为 true |
+| `auto_commit_interval_ms` | string | 以毫秒为单位的自动提交时间间隔 | 默认值:5000 ms |
| `enable_heartbeat_background` | string | 启用后台心跳,启用后即使长时间不 poll 消息也不会造成离线 | 合法值:`true`, `false` |
-| `experimental_snapshot_enable` | string | 从 WAL 开始消费,还是从 TSBS 开始消费 | 合法值:`true`, `false` |
-| `msg_with_table_name` | string | 是否允许从消息中解析表名 | 合法值:`true`, `false` |
-| `timeout` | int | 消费者拉去的超时时间 | |
+| `experimental_snapshot_enable` | string | 是否允许从 TSDB 消费数据 | 合法值:`true`, `false` |
+| `msg_with_table_name` | string | 是否允许从消息中解析表名,不适用于列订阅 | 合法值:`true`, `false` |
+| `timeout` | int | 消费者拉取数据的超时时间 | |
diff --git a/docs/zh/08-connector/20-go.mdx b/docs/zh/08-connector/20-go.mdx
index 515d1b030b..7a6058db3c 100644
--- a/docs/zh/08-connector/20-go.mdx
+++ b/docs/zh/08-connector/20-go.mdx
@@ -177,6 +177,37 @@ func main() {
}
```
+
+
+_taosWS_ 通过 `WebSocket` 实现了 Go 的 `database/sql/driver` 接口。只需要引入驱动(driver-go 最低版本 3.0.2)就可以使用[`database/sql`](https://golang.org/pkg/database/sql/)的接口。
+
+使用 `taosWS` 作为 `driverName` 并且使用一个正确的 [DSN](#DSN) 作为 `dataSourceName`,DSN 支持的参数:
+
+* `writeTimeout` 通过 WebSocket 发送数据的超时时间。
+* `readTimeout` 通过 WebSocket 接收响应数据的超时时间。
+
+示例:
+
+```go
+package main
+
+import (
+ "database/sql"
+ "fmt"
+
+ _ "github.com/taosdata/driver-go/v3/taosWS"
+)
+
+func main() {
+ var taosUri = "root:taosdata@ws(localhost:6041)/"
+ taos, err := sql.Open("taosWS", taosUri)
+ if err != nil {
+ fmt.Println("failed to connect TDengine, err:", err)
+ return
+ }
+}
+```
+
## 使用示例
@@ -410,6 +441,30 @@ func main() {
结束参数绑定。
+### 通过 WebSocket 订阅
+
+* `func NewConsumer(config *Config) (*Consumer, error)`
+
+ 创建消费者。
+
+* `func (c *Consumer) Subscribe(topic []string) error`
+
+ 订阅主题。
+
+* `func (c *Consumer) Poll(timeout time.Duration) (*Result, error)`
+
+ 轮询消息。
+
+* `func (c *Consumer) Commit(messageID uint64) error`
+
+ 提交消息。
+
+* `func (c *Consumer) Close() error`
+
+ 关闭消费者。
+
+完整订阅示例参见 [GitHub 示例文件](https://github.com/taosdata/driver-go/blob/3.0/examples/tmqoverws/main.go)
+
## API 参考
全部 API 见 [driver-go 文档](https://pkg.go.dev/github.com/taosdata/driver-go/v3)
diff --git a/docs/zh/08-connector/_macos_install.mdx b/docs/zh/08-connector/_macos_install.mdx
index 4925ffabcd..081134dfee 100644
--- a/docs/zh/08-connector/_macos_install.mdx
+++ b/docs/zh/08-connector/_macos_install.mdx
@@ -2,7 +2,7 @@ import PkgListV3 from "/components/PkgListV3";
1. 下载客户端安装包
-
+
[所有下载](../../releases/tdengine)
diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md
index 9346c3f763..68c7fe6f30 100644
--- a/docs/zh/12-taos-sql/10-function.md
+++ b/docs/zh/12-taos-sql/10-function.md
@@ -864,8 +864,9 @@ INTERP(expr)
- INTERP 用于在指定时间断面获取指定列的记录值,如果该时间断面不存在符合条件的行数据,那么会根据 FILL 参数的设定进行插值。
- INTERP 的输入数据为指定列的数据,可以通过条件语句(where 子句)来对原始列数据进行过滤,如果没有指定过滤条件则输入为全部数据。
+- INTERP 需要同时与 RANGE,EVERY 和 FILL 关键字一起使用。
- INTERP 的输出时间范围根据 RANGE(timestamp1,timestamp2)字段来指定,需满足 timestamp1<=timestamp2。其中 timestamp1(必选值)为输出时间范围的起始值,即如果 timestamp1 时刻符合插值条件则 timestamp1 为输出的第一条记录,timestamp2(必选值)为输出时间范围的结束值,即输出的最后一条记录的 timestamp 不能大于 timestamp2。
-- INTERP 根据 EVERY 字段来确定输出时间范围内的结果条数,即从 timestamp1 开始每隔固定长度的时间(EVERY 值)进行插值。如果没有指定 EVERY,则默认窗口大小为无穷大,即从 timestamp1 开始只有一个窗口。
+- INTERP 根据 EVERY 字段来确定输出时间范围内的结果条数,即从 timestamp1 开始每隔固定长度的时间(EVERY 值)进行插值。
- INTERP 根据 FILL 字段来决定在每个符合输出条件的时刻如何进行插值。
- INTERP 只能在一个时间序列内进行插值,因此当作用于超级表时必须跟 partition by tbname 一起使用。
- INTERP 可以与伪列 _irowts 一起使用,返回插值点所对应的时间戳(3.0.1.4版本以后支持)。
@@ -946,7 +947,7 @@ MIN(expr)
MODE(expr)
```
-**功能说明**:返回出现频率最高的值,若存在多个频率相同的最高值,输出NULL。
+**功能说明**:返回出现频率最高的值,若存在多个频率相同的最高值,则随机输出其中某个值。
**返回数据类型**:与输入数据类型一致。
diff --git a/docs/zh/21-tdinternal/01-arch.md b/docs/zh/21-tdinternal/01-arch.md
index 782e4bcdd8..6150f2e757 100644
--- a/docs/zh/21-tdinternal/01-arch.md
+++ b/docs/zh/21-tdinternal/01-arch.md
@@ -240,7 +240,7 @@ dataDir /mnt/data6 2 0
## 数据查询
-TDengine 提供了多种多样针对表和超级表的查询处理功能,除了常规的聚合查询之外,还提供针对时序数据的窗口查询、统计聚合等功能。TDengine 的查询处理需要客户端、vnode、qnode、mnode 节点协同完成,一个复杂的超级表聚合查询可能需要多个 vnode 和 qnode 节点公共分担查询和计算任务。
+TDengine 提供了多种多样针对表和超级表的查询处理功能,除了常规的聚合查询之外,还提供针对时序数据的窗口查询、统计聚合等功能。TDengine 的查询处理需要客户端、vnode、qnode、mnode 节点协同完成,一个复杂的超级表聚合查询可能需要多个 vnode 和 qnode 节点共同分担查询和计算任务。
### 查询基本流程
diff --git a/docs/zh/28-releases/01-tdengine.md b/docs/zh/28-releases/01-tdengine.md
index 59e0d0f761..a5b3534250 100644
--- a/docs/zh/28-releases/01-tdengine.md
+++ b/docs/zh/28-releases/01-tdengine.md
@@ -6,6 +6,10 @@ description: TDengine 发布历史、Release Notes 及下载链接
import Release from "/components/ReleaseV3";
+## 3.0.1.5
+
+
+
## 3.0.1.4
diff --git a/docs/zh/28-releases/02-tools.md b/docs/zh/28-releases/02-tools.md
index 83ccdec387..e86481435c 100644
--- a/docs/zh/28-releases/02-tools.md
+++ b/docs/zh/28-releases/02-tools.md
@@ -6,6 +6,10 @@ description: taosTools 的发布历史、Release Notes 和下载链接
import Release from "/components/ReleaseV3";
+## 2.2.6
+
+
+
## 2.2.4
diff --git a/include/common/systable.h b/include/common/systable.h
index 102465c8c2..8b29525db3 100644
--- a/include/common/systable.h
+++ b/include/common/systable.h
@@ -27,7 +27,7 @@ extern "C" {
#define TSDB_INS_TABLE_MNODES "ins_mnodes"
#define TSDB_INS_TABLE_MODULES "ins_modules"
#define TSDB_INS_TABLE_QNODES "ins_qnodes"
-#define TSDB_INS_TABLE_BNODES "ins_bnodes"
+#define TSDB_INS_TABLE_BNODES "ins_bnodes" // no longer used
#define TSDB_INS_TABLE_SNODES "ins_snodes"
#define TSDB_INS_TABLE_CLUSTER "ins_cluster"
#define TSDB_INS_TABLE_DATABASES "ins_databases"
diff --git a/include/common/tcommon.h b/include/common/tcommon.h
index eaddf4e983..bb2519bea3 100644
--- a/include/common/tcommon.h
+++ b/include/common/tcommon.h
@@ -44,12 +44,17 @@ enum {
)
// clang-format on
-typedef struct {
+typedef struct SWinKey {
uint64_t groupId;
TSKEY ts;
} SWinKey;
-static inline int sWinKeyCmprImpl(const void* pKey1, const void* pKey2) {
+typedef struct SSessionKey {
+ STimeWindow win;
+ uint64_t groupId;
+} SSessionKey;
+
+static inline int winKeyCmprImpl(const void* pKey1, const void* pKey2) {
SWinKey* pWin1 = (SWinKey*)pKey1;
SWinKey* pWin2 = (SWinKey*)pKey2;
@@ -69,7 +74,7 @@ static inline int sWinKeyCmprImpl(const void* pKey1, const void* pKey2) {
}
static inline int winKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
- return sWinKeyCmprImpl(pKey1, pKey2);
+ return winKeyCmprImpl(pKey1, pKey2);
}
typedef struct {
diff --git a/include/common/tglobal.h b/include/common/tglobal.h
index fd0521af3b..4a2e14eb78 100644
--- a/include/common/tglobal.h
+++ b/include/common/tglobal.h
@@ -45,15 +45,6 @@ extern bool tsPrintAuth;
extern int64_t tsTickPerMin[3];
extern int32_t tsCountAlwaysReturnValue;
-// multi-process
-extern int32_t tsMultiProcess;
-extern int32_t tsMnodeShmSize;
-extern int32_t tsVnodeShmSize;
-extern int32_t tsQnodeShmSize;
-extern int32_t tsSnodeShmSize;
-extern int32_t tsBnodeShmSize;
-extern int32_t tsNumOfShmThreads;
-
// queue & threads
extern int32_t tsNumOfRpcThreads;
extern int32_t tsNumOfCommitThreads;
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index 0febcdbba7..6317d423f3 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -95,7 +95,7 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_MODULE,
TSDB_MGMT_TABLE_QNODE,
TSDB_MGMT_TABLE_SNODE,
- TSDB_MGMT_TABLE_BNODE,
+ TSDB_MGMT_TABLE_BNODE, // no longer used
TSDB_MGMT_TABLE_CLUSTER,
TSDB_MGMT_TABLE_DB,
TSDB_MGMT_TABLE_FUNC,
@@ -343,6 +343,8 @@ typedef struct {
} SSchemaWrapper;
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
+ if (pSchemaWrapper->pSchema == NULL) return NULL;
+
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
if (pSW == NULL) return pSW;
pSW->nCols = pSchemaWrapper->nCols;
@@ -352,6 +354,7 @@ static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* p
taosMemoryFree(pSW);
return NULL;
}
+
memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
return pSW;
}
@@ -1486,11 +1489,10 @@ int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq
typedef struct {
int32_t dnodeId;
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
- SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq, SMCreateBnodeReq, SMDropBnodeReq,
- SDCreateBnodeReq, SDDropBnodeReq;
+ SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
-int32_t tSerializeSCreateDropMQSBNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
-int32_t tDeserializeSCreateDropMQSBNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
+int32_t tSerializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
+int32_t tDeserializeSCreateDropMQSNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
typedef struct {
int8_t replica;
diff --git a/include/common/tmsgcb.h b/include/common/tmsgcb.h
index c13c50e161..b5b997dac0 100644
--- a/include/common/tmsgcb.h
+++ b/include/common/tmsgcb.h
@@ -34,6 +34,7 @@ typedef enum {
WRITE_QUEUE,
APPLY_QUEUE,
SYNC_QUEUE,
+ SYNC_CTRL_QUEUE,
STREAM_QUEUE,
QUEUE_MAX,
} EQueueType;
diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h
index 3f917ff0d1..7b4e930485 100644
--- a/include/common/tmsgdef.h
+++ b/include/common/tmsgdef.h
@@ -74,8 +74,8 @@ enum {
TD_DEF_MSG_TYPE(TDMT_DND_DROP_QNODE, "dnode-drop-qnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_SNODE, "dnode-create-snode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_DROP_SNODE, "dnode-drop-snode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_CREATE_BNODE, "dnode-create-bnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_DND_DROP_BNODE, "dnode-drop-bnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_DND_CREATE_BNODE, "dnode-create-bnode", NULL, NULL) // no longer used
+ TD_DEF_MSG_TYPE(TDMT_DND_DROP_BNODE, "dnode-drop-bnode", NULL, NULL) // no longer used
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_VNODE, "create-vnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_DROP_VNODE, "drop-vnode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_DND_SERVER_STATUS, "server-status", NULL, NULL)
@@ -107,9 +107,9 @@ enum {
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SNODE, "create-snode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_SNODE, "alter-snode", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_DROP_SNODE, "drop-snode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_CREATE_BNODE, "create-bnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_ALTER_BNODE, "alter-bnode", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MND_DROP_BNODE, "drop-bnode", NULL, NULL)
+ TD_DEF_MSG_TYPE(TDMT_MND_CREATE_BNODE, "create-bnode", NULL, NULL) // no longer used
+ TD_DEF_MSG_TYPE(TDMT_MND_ALTER_BNODE, "alter-bnode", NULL, NULL) // no longer used
+ TD_DEF_MSG_TYPE(TDMT_MND_DROP_BNODE, "drop-bnode", NULL, NULL) // no longer used
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DB, "create-db", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_DROP_DB, "drop-db", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MND_USE_DB, "use-db", NULL, NULL)
@@ -239,14 +239,6 @@ enum {
TD_DEF_MSG_TYPE(TDMT_STREAM_MAX_MSG, "stream-max", NULL, NULL)
TD_NEW_MSG_SEG(TDMT_MON_MSG)
- TD_DEF_MSG_TYPE(TDMT_MON_MM_INFO, "monitor-minfo", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MON_VM_INFO, "monitor-vinfo", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MON_QM_INFO, "monitor-qinfo", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MON_SM_INFO, "monitor-sinfo", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MON_BM_INFO, "monitor-binfo", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MON_VM_LOAD, "monitor-vload", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MON_MM_LOAD, "monitor-mload", NULL, NULL)
- TD_DEF_MSG_TYPE(TDMT_MON_QM_LOAD, "monitor-qload", NULL, NULL)
TD_DEF_MSG_TYPE(TDMT_MON_MAX_MSG, "monitor-max", NULL, NULL)
TD_NEW_MSG_SEG(TDMT_SYNC_MSG)
diff --git a/include/common/trow.h b/include/common/trow.h
index 3680a82594..8b0349c99b 100644
--- a/include/common/trow.h
+++ b/include/common/trow.h
@@ -30,7 +30,7 @@
extern "C" {
#endif
-typedef struct {
+typedef struct STSRow {
TSKEY ts;
union {
uint32_t info;
diff --git a/include/dnode/bnode/bnode.h b/include/dnode/bnode/bnode.h
deleted file mode 100644
index d5958d432b..0000000000
--- a/include/dnode/bnode/bnode.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef _TD_BNODE_H_
-#define _TD_BNODE_H_
-
-#include "tmsgcb.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* ------------------------ TYPES EXPOSED ------------------------ */
-typedef struct SBnode SBnode;
-
-typedef struct {
-#ifdef WINDOWS
- size_t avoidCompilationErrors;
-#endif
-} SBnodeLoad;
-
-typedef struct {
- SMsgCb msgCb;
-} SBnodeOpt;
-
-/* ------------------------ SBnode ------------------------ */
-/**
- * @brief Start one Bnode in Dnode.
- *
- * @param path Path of the bnode.
- * @param pOption Option of the bnode.
- * @return SBnode* The bnode object.
- */
-SBnode *bndOpen(const char *path, const SBnodeOpt *pOption);
-
-/**
- * @brief Stop Bnode in Dnode.
- *
- * @param pBnode The bnode object to close.
- */
-void bndClose(SBnode *pBnode);
-
-/**
- * @brief Get the statistical information of Bnode
- *
- * @param pBnode The bnode object.
- * @param pLoad Statistics of the bnode.
- * @return int32_t 0 for success, -1 for failure.
- */
-int32_t bndGetLoad(SBnode *pBnode, SBnodeLoad *pLoad);
-
-/**
- * @brief Process a query message.
- *
- * @param pBnode The bnode object.
- * @param pMsgs The array of SRpcMsg
- * @return int32_t 0 for success, -1 for failure
- */
-int32_t bndProcessWMsgs(SBnode *pBnode, SArray *pMsgs);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_BNODE_H_*/
\ No newline at end of file
diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h
index fe1692c50f..82823e3f57 100644
--- a/include/dnode/mgmt/dnode.h
+++ b/include/dnode/mgmt/dnode.h
@@ -25,10 +25,9 @@ extern "C" {
/**
* @brief Initialize the dnode
*
- * @param rtype for internal debug usage, default is 0
* @return int32_t 0 for success and -1 for failure
*/
-int32_t dmInit(int8_t rtype);
+int32_t dmInit();
/**
* @brief Cleanup the dnode
diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h
index 30254d61a9..12e465e0f8 100644
--- a/include/libs/monitor/monitor.h
+++ b/include/libs/monitor/monitor.h
@@ -80,7 +80,6 @@ typedef struct {
int8_t has_mnode;
int8_t has_qnode;
int8_t has_snode;
- int8_t has_bnode;
SMonDiskDesc logdir;
SMonDiskDesc tempdir;
} SMonDnodeInfo;
diff --git a/include/libs/stream/streamState.h b/include/libs/stream/streamState.h
index 9445a0baa5..ec68e8ed71 100644
--- a/include/libs/stream/streamState.h
+++ b/include/libs/stream/streamState.h
@@ -25,6 +25,8 @@ extern "C" {
typedef struct SStreamTask SStreamTask;
+typedef bool (*state_key_cmpr_fn)(void* pKey1, void* pKey2);
+
// incremental state storage
typedef struct {
SStreamTask* pOwner;
@@ -32,6 +34,7 @@ typedef struct {
TTB* pStateDb;
TTB* pFuncStateDb;
TTB* pFillStateDb; // todo refactor
+ TTB* pSessionStateDb;
TXN txn;
int32_t number;
} SStreamState;
@@ -57,6 +60,19 @@ int32_t streamStateDel(SStreamState* pState, const SWinKey* key);
int32_t streamStateClear(SStreamState* pState);
void streamStateSetNumber(SStreamState* pState, int32_t number);
+int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen);
+int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, const void* value, int32_t vLen);
+int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen);
+int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key);
+int32_t streamStateSessionClear(SStreamState* pState);
+int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, const void** pVal, int32_t* pVLen);
+int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
+ state_key_cmpr_fn fn, void** pVal, int32_t* pVLen);
+
+SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key);
+SStreamStateCur* streamStateSessionSeekKeyPrev(SStreamState* pState, const SSessionKey* key);
+SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKey* key);
+
int32_t streamStateFillPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
int32_t streamStateFillGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
int32_t streamStateFillDel(SStreamState* pState, const SWinKey* key);
diff --git a/include/libs/sync/syncTools.h b/include/libs/sync/syncTools.h
index de2271554d..b2c743831a 100644
--- a/include/libs/sync/syncTools.h
+++ b/include/libs/sync/syncTools.h
@@ -695,6 +695,9 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie
int32_t syncNodeOnSnapshotSendCb(SSyncNode* ths, SyncSnapshotSend* pMsg);
int32_t syncNodeOnSnapshotRspCb(SSyncNode* ths, SyncSnapshotRsp* pMsg);
+int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg);
+int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg);
+
// -----------------------------------------
typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg);
typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg);
diff --git a/include/os/os.h b/include/os/os.h
index 28a3ebee81..e780611c41 100644
--- a/include/os/os.h
+++ b/include/os/os.h
@@ -94,10 +94,8 @@ extern "C" {
#include "osLz4.h"
#include "osMath.h"
#include "osMemory.h"
-#include "osProc.h"
#include "osRand.h"
#include "osSemaphore.h"
-#include "osShm.h"
#include "osSignal.h"
#include "osSleep.h"
#include "osSocket.h"
diff --git a/include/os/osEnv.h b/include/os/osEnv.h
index d4e94d6173..c1fdc9e404 100644
--- a/include/os/osEnv.h
+++ b/include/os/osEnv.h
@@ -60,6 +60,7 @@ bool osTempSpaceSufficient();
void osSetTimezone(const char *timezone);
void osSetSystemLocale(const char *inLocale, const char *inCharSet);
+void osSetProcPath(int32_t argc, char **argv);
#ifdef __cplusplus
}
diff --git a/include/os/osProc.h b/include/os/osProc.h
deleted file mode 100644
index f09b695ef4..0000000000
--- a/include/os/osProc.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef _TD_OS_PROC_H_
-#define _TD_OS_PROC_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t taosNewProc(char **args);
-void taosWaitProc(int32_t pid);
-void taosKillProc(int32_t pid);
-bool taosProcExist(int32_t pid);
-void taosSetProcName(int32_t argc, char **argv, const char *name);
-void taosSetProcPath(int32_t argc, char **argv);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_OS_PROC_H_*/
diff --git a/include/os/osShm.h b/include/os/osShm.h
deleted file mode 100644
index 87efb1ab16..0000000000
--- a/include/os/osShm.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef _TD_OS_SHM_H_
-#define _TD_OS_SHM_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- int32_t id;
- int32_t size;
- void *ptr;
-} SShm;
-
-int32_t taosCreateShm(SShm *pShm, int32_t key, int32_t shmsize);
-void taosDropShm(SShm *pShm);
-int32_t taosAttachShm(SShm *pShm);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_OS_SHM_H_*/
diff --git a/include/util/tdef.h b/include/util/tdef.h
index d9bb558b74..bb7f908ad4 100644
--- a/include/util/tdef.h
+++ b/include/util/tdef.h
@@ -483,7 +483,6 @@ enum {
#define QNODE_HANDLE -1
#define SNODE_HANDLE -2
#define VNODE_HANDLE -3
-#define BNODE_HANDLE -4
#define CLIENT_HANDLE -5
#define TSDB_CONFIG_OPTION_LEN 32
@@ -498,6 +497,7 @@ enum {
#define MAX_NUM_STR_SIZE 40
#define MAX_META_MSG_IN_BATCH 1048576
+#define MAX_META_BATCH_RSP_SIZE (1 * 1048576 * 1024)
#ifdef __cplusplus
}
diff --git a/include/util/tutil.h b/include/util/tutil.h
index 2a3f0dcb02..de96300155 100644
--- a/include/util/tutil.h
+++ b/include/util/tutil.h
@@ -83,6 +83,12 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
}
}
+#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \
+ if (CODE) { \
+ LINO = __LINE__; \
+ goto LABEL; \
+ }
+
#ifdef __cplusplus
}
#endif
diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c
index df717bda23..7b9009c34b 100644
--- a/source/client/src/clientImpl.c
+++ b/source/client/src/clientImpl.c
@@ -186,8 +186,8 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param,
STscObj* pTscObj = (*pRequest)->pTscObj;
if (taosHashPut(pTscObj->pRequests, &(*pRequest)->self, sizeof((*pRequest)->self), &(*pRequest)->self,
sizeof((*pRequest)->self))) {
- tscError("%" PRIx64 " failed to add to request container, reqId:0x%" PRIu64 ", conn:%" PRIx64 ", %s", (*pRequest)->self,
- (*pRequest)->requestId, pTscObj->id, sql);
+ tscError("%" PRIx64 " failed to add to request container, reqId:0x%" PRIu64 ", conn:%" PRIx64 ", %s",
+ (*pRequest)->self, (*pRequest)->requestId, pTscObj->id, sql);
taosMemoryFree(param);
destroyRequest(*pRequest);
@@ -199,9 +199,8 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param,
if (tsQueryUseNodeAllocator && !qIsInsertValuesSql((*pRequest)->sqlstr, (*pRequest)->sqlLen)) {
if (TSDB_CODE_SUCCESS !=
nodesCreateAllocator((*pRequest)->requestId, tsQueryNodeChunkSize, &((*pRequest)->allocatorRefId))) {
- tscError("%d failed to create node allocator, reqId:0x%" PRIx64 ", conn:%d, %s", (*pRequest)->self,
- (*pRequest)->requestId, pTscObj->id, sql);
-
+ tscError("%" PRId64 " failed to create node allocator, reqId:0x%" PRIx64 ", conn:%" PRId64 ", %s",
+ (*pRequest)->self, (*pRequest)->requestId, pTscObj->id, sql);
destroyRequest(*pRequest);
*pRequest = NULL;
return TSDB_CODE_TSC_OUT_OF_MEMORY;
@@ -955,7 +954,12 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue
switch (pQuery->execMode) {
case QUERY_EXEC_MODE_LOCAL:
if (!pRequest->validateOnly) {
- code = execLocalCmd(pRequest, pQuery);
+ if (NULL == pQuery->pRoot) {
+ terrno = TSDB_CODE_INVALID_PARA;
+ code = terrno;
+ } else {
+ code = execLocalCmd(pRequest, pQuery);
+ }
}
break;
case QUERY_EXEC_MODE_RPC:
@@ -997,7 +1001,7 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue
handleQueryExecRsp(pRequest);
- if (NULL != pRequest && TSDB_CODE_SUCCESS != code) {
+ if (TSDB_CODE_SUCCESS != code) {
pRequest->code = terrno;
}
@@ -1035,39 +1039,39 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
SSqlCallbackWrapper* pWrapper) {
pRequest->type = pQuery->msgType;
- SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad));
+ SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad));
SPlanContext cxt = {.queryId = pRequest->requestId,
- .acctId = pRequest->pTscObj->acctId,
- .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
- .pAstRoot = pQuery->pRoot,
- .showRewrite = pQuery->showRewrite,
- .pMsg = pRequest->msgBuf,
- .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
- .pUser = pRequest->pTscObj->user,
- .sysInfo = pRequest->pTscObj->sysInfo,
- .allocatorId = pRequest->allocatorRefId};
+ .acctId = pRequest->pTscObj->acctId,
+ .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
+ .pAstRoot = pQuery->pRoot,
+ .showRewrite = pQuery->showRewrite,
+ .pMsg = pRequest->msgBuf,
+ .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
+ .pUser = pRequest->pTscObj->user,
+ .sysInfo = pRequest->pTscObj->sysInfo,
+ .allocatorId = pRequest->allocatorRefId};
- SAppInstInfo* pAppInfo = getAppInfo(pRequest);
- SQueryPlan* pDag = NULL;
+ SAppInstInfo* pAppInfo = getAppInfo(pRequest);
+ SQueryPlan* pDag = NULL;
int64_t st = taosGetTimestampUs();
int32_t code = qCreateQueryPlan(&cxt, &pDag, pMnodeList);
- if (code) {
- tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code),
- pRequest->requestId);
- } else {
- pRequest->body.subplanNum = pDag->numOfSubplans;
- }
+ if (code) {
+ tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code),
+ pRequest->requestId);
+ } else {
+ pRequest->body.subplanNum = pDag->numOfSubplans;
+ }
- pRequest->metric.planEnd = taosGetTimestampUs();
+ pRequest->metric.planEnd = taosGetTimestampUs();
if (code == TSDB_CODE_SUCCESS) {
tscDebug("0x%" PRIx64 " create query plan success, elapsed time:%.2f ms, 0x%" PRIx64, pRequest->self,
- (pRequest->metric.planEnd - st)/1000.0, pRequest->requestId);
+ (pRequest->metric.planEnd - st) / 1000.0, pRequest->requestId);
}
- if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) {
- SArray* pNodeList = NULL;
- buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta);
+ if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) {
+ SArray* pNodeList = NULL;
+ buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta);
SRequestConnInfo conn = {.pTrans = getAppInfo(pRequest)->pTransporter,
.requestId = pRequest->requestId,
@@ -2254,7 +2258,10 @@ void syncQueryFn(void* param, void* res, int32_t code) {
void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly) {
if (sql == NULL || NULL == fp) {
terrno = TSDB_CODE_INVALID_PARA;
- fp(param, NULL, terrno);
+ if (fp) {
+ fp(param, NULL, terrno);
+ }
+
return;
}
diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c
index 6126817ece..286fb85373 100644
--- a/source/client/src/clientMain.c
+++ b/source/client/src/clientMain.c
@@ -944,7 +944,6 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
if (pResultInfo->completed) {
// it is a local executed query, no need to do async fetch
if (QUERY_EXEC_MODE_LOCAL == pRequest->body.execMode) {
- ASSERT(pResultInfo->numOfRows >= 0);
if (pResultInfo->localResultFetched) {
pResultInfo->numOfRows = 0;
pResultInfo->current = 0;
diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c
index 8680f93f8c..945562ef36 100644
--- a/source/client/src/clientMsgHandler.c
+++ b/source/client/src/clientMsgHandler.c
@@ -292,8 +292,10 @@ int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp);
struct SCatalog* pCatalog = NULL;
- catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
- catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
+ int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
+ if (TSDB_CODE_SUCCESS == code) {
+ catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
+ }
}
taosMemoryFree(pMsg->pData);
@@ -397,6 +399,7 @@ static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) {
size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
*pRsp = taosMemoryCalloc(1, rspSize);
if (NULL == *pRsp) {
+ blockDataDestroy(pBlock);
return TSDB_CODE_OUT_OF_MEMORY;
}
diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c
index f2739c9ab8..2c48eae59f 100644
--- a/source/client/src/clientSml.c
+++ b/source/client/src/clientSml.c
@@ -1372,8 +1372,14 @@ static int32_t smlKvTimeArrayCompare(const void *key1, const void *key2) {
static int32_t smlKvTimeHashCompare(const void *key1, const void *key2) {
SHashObj *s1 = *(SHashObj **)key1;
SHashObj *s2 = *(SHashObj **)key2;
- SSmlKv *kv1 = *(SSmlKv **)taosHashGet(s1, TS, TS_LEN);
- SSmlKv *kv2 = *(SSmlKv **)taosHashGet(s2, TS, TS_LEN);
+ SSmlKv **kv1pp = (SSmlKv **)taosHashGet(s1, TS, TS_LEN);
+ SSmlKv **kv2pp = (SSmlKv **)taosHashGet(s2, TS, TS_LEN);
+ if(!kv1pp || !kv2pp){
+ uError("smlKvTimeHashCompare kv is null");
+ return -1;
+ }
+ SSmlKv *kv1 = *kv1pp;
+ SSmlKv *kv2 = *kv2pp;
if(!kv1 || kv1->type != TSDB_DATA_TYPE_TIMESTAMP){
uError("smlKvTimeHashCompare kv1");
return -1;
diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c
index bf3fd00f14..81d0d616c9 100644
--- a/source/client/src/clientStmt.c
+++ b/source/client/src/clientStmt.c
@@ -152,7 +152,7 @@ int32_t stmtUpdateBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags,
pStmt->bInfo.tbType = pTableMeta->tableType;
pStmt->bInfo.boundTags = tags;
pStmt->bInfo.tagsCached = false;
- strcpy(pStmt->bInfo.stbFName, sTableName);
+ tstrncpy(pStmt->bInfo.stbFName, sTableName, sizeof(pStmt->bInfo.stbFName));
return TSDB_CODE_SUCCESS;
}
diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c
index 838b851d6d..0bc33739c6 100644
--- a/source/client/src/clientTmq.c
+++ b/source/client/src/clientTmq.c
@@ -210,6 +210,8 @@ typedef struct {
typedef struct {
SMqCommitCbParamSet* params;
STqOffset* pOffset;
+ /*char topicName[TSDB_TOPIC_FNAME_LEN];*/
+ /*int32_t vgId;*/
} SMqCommitCbParam;
tmq_conf_t* tmq_conf_new() {
@@ -407,6 +409,14 @@ int32_t tmqCommitDone(SMqCommitCbParamSet* pParamSet) {
return 0;
}
+static void tmqCommitRspCountDown(SMqCommitCbParamSet* pParamSet) {
+ int32_t waitingRspNum = atomic_sub_fetch_32(&pParamSet->waitingRspNum, 1);
+ ASSERT(waitingRspNum >= 0);
+ if (waitingRspNum == 0) {
+ tmqCommitDone(pParamSet);
+ }
+}
+
int32_t tmqCommitCb(void* param, SDataBuf* pBuf, int32_t code) {
SMqCommitCbParam* pParam = (SMqCommitCbParam*)param;
SMqCommitCbParamSet* pParamSet = (SMqCommitCbParamSet*)pParam->params;
@@ -420,18 +430,13 @@ int32_t tmqCommitCb(void* param, SDataBuf* pBuf, int32_t code) {
#endif
taosMemoryFree(pParam->pOffset);
- if (pBuf->pData) taosMemoryFree(pBuf->pData);
+ taosMemoryFree(pBuf->pData);
/*tscDebug("receive offset commit cb of %s on vgId:%d, offset is %" PRId64, pParam->pOffset->subKey, pParam->->vgId,
* pOffset->version);*/
- // count down waiting rsp
- int32_t waitingRspNum = atomic_sub_fetch_32(&pParamSet->waitingRspNum, 1);
- ASSERT(waitingRspNum >= 0);
+ tmqCommitRspCountDown(pParamSet);
- if (waitingRspNum == 0) {
- tmqCommitDone(pParamSet);
- }
return 0;
}
@@ -591,14 +596,10 @@ FAIL:
return 0;
}
-int32_t tmqCommitInner(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_t async, tmq_commit_cb* userCb,
- void* userParam) {
+static int32_t tmqCommitConsumerImpl(tmq_t* tmq, int8_t automatic, int8_t async, tmq_commit_cb* userCb,
+ void* userParam) {
int32_t code = -1;
- if (msg != NULL) {
- return tmqCommitMsgImpl(tmq, msg, async, userCb, userParam);
- }
-
SMqCommitCbParamSet* pParamSet = taosMemoryCalloc(1, sizeof(SMqCommitCbParamSet));
if (pParamSet == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
@@ -646,33 +647,37 @@ int32_t tmqCommitInner(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_t
}
}
+ // no request is sent
if (pParamSet->totalRspNum == 0) {
tsem_destroy(&pParamSet->rspSem);
taosMemoryFree(pParamSet);
return 0;
}
- int32_t waitingRspNum = atomic_sub_fetch_32(&pParamSet->waitingRspNum, 1);
- ASSERT(waitingRspNum >= 0);
- if (waitingRspNum == 0) {
- tmqCommitDone(pParamSet);
- }
+ // count down since waiting rsp num init as 1
+ tmqCommitRspCountDown(pParamSet);
if (!async) {
tsem_wait(&pParamSet->rspSem);
code = pParamSet->rspErr;
tsem_destroy(&pParamSet->rspSem);
taosMemoryFree(pParamSet);
- }
-
#if 0
- if (!async) {
taosArrayDestroyP(pParamSet->successfulOffsets, taosMemoryFree);
taosArrayDestroyP(pParamSet->failedOffsets, taosMemoryFree);
- }
#endif
+ }
- return 0;
+ return code;
+}
+
+int32_t tmqCommitInner(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_t async, tmq_commit_cb* userCb,
+ void* userParam) {
+ if (msg) {
+ return tmqCommitMsgImpl(tmq, msg, async, userCb, userParam);
+ } else {
+ return tmqCommitConsumerImpl(tmq, automatic, async, userCb, userParam);
+ }
}
void tmqAssignAskEpTask(void* param, void* tmrId) {
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index a45f7b2913..28a4732abd 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -62,12 +62,6 @@ static const SSysDbTableSchema snodesSchema[] = {
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true},
};
-static const SSysDbTableSchema bnodesSchema[] = {
- {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
- {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
- {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true},
-};
-
static const SSysDbTableSchema clusterSchema[] = {
{.name = "id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
{.name = "name", .bytes = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
@@ -277,7 +271,6 @@ static const SSysTableMeta infosMeta[] = {
{TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema), true},
{TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema), true},
// {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)},
- // {TSDB_INS_TABLE_BNODES, bnodesSchema, tListLen(bnodesSchema)},
{TSDB_INS_TABLE_CLUSTER, clusterSchema, tListLen(clusterSchema), true},
{TSDB_INS_TABLE_DATABASES, userDBSchema, tListLen(userDBSchema), false},
{TSDB_INS_TABLE_FUNCTIONS, userFuncSchema, tListLen(userFuncSchema), false},
diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c
index 1028a899b6..62706db980 100644
--- a/source/common/src/tdatablock.c
+++ b/source/common/src/tdatablock.c
@@ -1892,12 +1892,13 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
for (int32_t k = 0; k < colNum; k++) {
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k);
- void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
if (colDataIsNull(pColInfoData, rows, j, NULL) || !pColInfoData->pData) {
len += snprintf(dumpBuf + len, size - len, " %15s |", "NULL");
if (len >= size - 1) return dumpBuf;
continue;
}
+
+ void* var = colDataGetData(pColInfoData, j);
switch (pColInfoData->info.type) {
case TSDB_DATA_TYPE_TIMESTAMP:
memset(pBuf, 0, sizeof(pBuf));
@@ -1926,8 +1927,8 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
if (len >= size - 1) return dumpBuf;
break;
case TSDB_DATA_TYPE_DOUBLE:
- len += snprintf(dumpBuf + len, size - len, " %15lf |", *(double*)var);
- if (len >= size - 1) return dumpBuf;
+ // len += snprintf(dumpBuf + len, size - len, " %15lf |", *(double*)var);
+ // if (len >= size - 1) return dumpBuf;
break;
case TSDB_DATA_TYPE_BOOL:
len += snprintf(dumpBuf + len, size - len, " %15d |", *(bool*)var);
diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c
index 56daa4075a..3edeeee49a 100644
--- a/source/common/src/tglobal.c
+++ b/source/common/src/tglobal.c
@@ -40,15 +40,6 @@ int32_t tsMaxShellConns = 50000;
int32_t tsShellActivityTimer = 3; // second
bool tsPrintAuth = false;
-// multi process
-int32_t tsMultiProcess = 0;
-int32_t tsMnodeShmSize = TSDB_MAX_MSG_SIZE * 2 + 1024;
-int32_t tsVnodeShmSize = TSDB_MAX_MSG_SIZE * 10 + 1024;
-int32_t tsQnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024;
-int32_t tsSnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024;
-int32_t tsBnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024;
-int32_t tsNumOfShmThreads = 1;
-
// queue & threads
int32_t tsNumOfRpcThreads = 1;
int32_t tsNumOfCommitThreads = 2;
@@ -353,14 +344,6 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1;
if (cfgAddInt32(pCfg, "queryRspPolicy", tsQueryRspPolicy, 0, 1, 0) != 0) return -1;
- if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1;
- if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
- if (cfgAddInt32(pCfg, "vnodeShmSize", tsVnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
- if (cfgAddInt32(pCfg, "qnodeShmSize", tsQnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
- if (cfgAddInt32(pCfg, "snodeShmSize", tsSnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
- if (cfgAddInt32(pCfg, "bnodeShmSize", tsBnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
- if (cfgAddInt32(pCfg, "numOfShmThreads", tsNumOfShmThreads, 1, 1024, 0) != 0) return -1;
-
tsNumOfRpcThreads = tsNumOfCores / 2;
tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 1, 4);
if (cfgAddInt32(pCfg, "numOfRpcThreads", tsNumOfRpcThreads, 1, 1024, 0) != 0) return -1;
@@ -700,15 +683,6 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsQueryBufferSize = cfgGetItem(pCfg, "queryBufferSize")->i32;
tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval;
-#if !defined(WINDOWS) && !defined(DARWIN)
- tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval;
-#endif
- tsMnodeShmSize = cfgGetItem(pCfg, "mnodeShmSize")->i32;
- tsVnodeShmSize = cfgGetItem(pCfg, "vnodeShmSize")->i32;
- tsQnodeShmSize = cfgGetItem(pCfg, "qnodeShmSize")->i32;
- tsSnodeShmSize = cfgGetItem(pCfg, "snodeShmSize")->i32;
- tsBnodeShmSize = cfgGetItem(pCfg, "bnodeShmSize")->i32;
-
tsNumOfRpcThreads = cfgGetItem(pCfg, "numOfRpcThreads")->i32;
tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32;
tsNumOfMnodeReadThreads = cfgGetItem(pCfg, "numOfMnodeReadThreads")->i32;
@@ -780,12 +754,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
}
break;
}
- case 'b': {
- if (strcasecmp("bnodeShmSize", name) == 0) {
- tsBnodeShmSize = cfgGetItem(pCfg, "bnodeShmSize")->i32;
- }
- break;
- }
case 'c': {
if (strcasecmp("charset", name) == 0) {
const char *locale = cfgGetItem(pCfg, "locale")->str;
@@ -912,12 +880,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
}
break;
}
- case 'n': {
- if (strcasecmp("mnodeShmSize", name) == 0) {
- tsMnodeShmSize = cfgGetItem(pCfg, "mnodeShmSize")->i32;
- }
- break;
- }
case 'o': {
if (strcasecmp("monitor", name) == 0) {
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
@@ -941,11 +903,7 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
break;
}
case 'u': {
- if (strcasecmp("multiProcess", name) == 0) {
-#if !defined(WINDOWS) && !defined(DARWIN)
- tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval;
-#endif
- } else if (strcasecmp("udfDebugFlag", name) == 0) {
+ if (strcasecmp("udfDebugFlag", name) == 0) {
udfDebugFlag = cfgGetItem(pCfg, "udfDebugFlag")->i32;
}
break;
@@ -1008,8 +966,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
if (tsQueryBufferSize >= 0) {
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
}
- } else if (strcasecmp("qnodeShmSize", name) == 0) {
- tsQnodeShmSize = cfgGetItem(pCfg, "qnodeShmSize")->i32;
} else if (strcasecmp("qDebugFlag", name) == 0) {
qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32;
} else if (strcasecmp("queryPlannerTrace", name) == 0) {
@@ -1050,8 +1006,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
tsNumOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32;
} else if (strcasecmp("statusInterval", name) == 0) {
tsStatusInterval = cfgGetItem(pCfg, "statusInterval")->i32;
- } else if (strcasecmp("snodeShmSize", name) == 0) {
- tsSnodeShmSize = cfgGetItem(pCfg, "snodeShmSize")->i32;
} else if (strcasecmp("serverPort", name) == 0) {
tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN);
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
@@ -1119,9 +1073,7 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
break;
}
case 'v': {
- if (strcasecmp("vnodeShmSize", name) == 0) {
- tsVnodeShmSize = cfgGetItem(pCfg, "vnodeShmSize")->i32;
- } else if (strcasecmp("vDebugFlag", name) == 0) {
+ if (strcasecmp("vDebugFlag", name) == 0) {
vDebugFlag = cfgGetItem(pCfg, "vDebugFlag")->i32;
}
break;
@@ -1244,6 +1196,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile
if (cfgLoadFromArray(tsCfg, pArgs) != 0) {
uError("failed to load cfg from array since %s", terrstr());
cfgCleanup(tsCfg);
+ tsCfg = NULL;
return -1;
}
diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c
index a3135c1f55..c6d3513280 100644
--- a/source/common/src/tmsg.c
+++ b/source/common/src/tmsg.c
@@ -1448,7 +1448,7 @@ void tFreeSGetUserAuthRsp(SGetUserAuthRsp *pRsp) {
taosHashCleanup(pRsp->writeDbs);
}
-int32_t tSerializeSCreateDropMQSBNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
+int32_t tSerializeSCreateDropMQSNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
SEncoder encoder = {0};
tEncoderInit(&encoder, buf, bufLen);
@@ -1461,7 +1461,7 @@ int32_t tSerializeSCreateDropMQSBNodeReq(void *buf, int32_t bufLen, SMCreateQnod
return tlen;
}
-int32_t tDeserializeSCreateDropMQSBNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
+int32_t tDeserializeSCreateDropMQSNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
SDecoder decoder = {0};
tDecoderInit(&decoder, buf, bufLen);
diff --git a/source/dnode/CMakeLists.txt b/source/dnode/CMakeLists.txt
index 87e4c5fc46..035cea2dc4 100644
--- a/source/dnode/CMakeLists.txt
+++ b/source/dnode/CMakeLists.txt
@@ -2,5 +2,4 @@ add_subdirectory(mnode)
add_subdirectory(vnode)
add_subdirectory(qnode)
add_subdirectory(snode)
-add_subdirectory(bnode)
add_subdirectory(mgmt)
\ No newline at end of file
diff --git a/source/dnode/bnode/CMakeLists.txt b/source/dnode/bnode/CMakeLists.txt
deleted file mode 100644
index 77f4d15ad2..0000000000
--- a/source/dnode/bnode/CMakeLists.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-aux_source_directory(src BNODE_SRC)
-add_library(bnode STATIC ${BNODE_SRC})
-target_include_directories(
- bnode
- PUBLIC "${TD_SOURCE_DIR}/include/dnode/bnode"
- private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
-)
-target_link_libraries(
- bnode
- PRIVATE transport
- PRIVATE os
- PRIVATE common
- PRIVATE util
-)
\ No newline at end of file
diff --git a/source/dnode/bnode/inc/bndInt.h b/source/dnode/bnode/inc/bndInt.h
deleted file mode 100644
index e611d230a3..0000000000
--- a/source/dnode/bnode/inc/bndInt.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef _TD_BNODE_INT_H_
-#define _TD_BNODE_INT_H_
-
-#include "os.h"
-
-#include "tarray.h"
-#include "tlog.h"
-#include "tmsg.h"
-#include "trpc.h"
-
-#include "bnode.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct SBnode {
- SMsgCb msgCb;
-} SBnode;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_BNODE_INT_H_*/
\ No newline at end of file
diff --git a/source/dnode/bnode/src/bnode.c b/source/dnode/bnode/src/bnode.c
deleted file mode 100644
index b9c41ebf43..0000000000
--- a/source/dnode/bnode/src/bnode.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#include "bndInt.h"
-
-SBnode *bndOpen(const char *path, const SBnodeOpt *pOption) {
- SBnode *pBnode = taosMemoryCalloc(1, sizeof(SBnode));
- pBnode->msgCb = pOption->msgCb;
- return pBnode;
-}
-
-void bndClose(SBnode *pBnode) { taosMemoryFree(pBnode); }
-
-int32_t bndGetLoad(SBnode *pBnode, SBnodeLoad *pLoad) { return 0; }
-
-int32_t bndProcessWMsgs(SBnode *pBnode, SArray *pMsgs) { return 0; }
diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt
index 581686ba90..423028b167 100644
--- a/source/dnode/mgmt/CMakeLists.txt
+++ b/source/dnode/mgmt/CMakeLists.txt
@@ -1,6 +1,5 @@
add_subdirectory(node_mgmt)
add_subdirectory(node_util)
-add_subdirectory(mgmt_bnode)
add_subdirectory(mgmt_mnode)
add_subdirectory(mgmt_qnode)
add_subdirectory(mgmt_snode)
diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c
index acc3fc5658..188677656a 100644
--- a/source/dnode/mgmt/exe/dmMain.c
+++ b/source/dnode/mgmt/exe/dmMain.c
@@ -25,7 +25,6 @@
#define DM_SDB_INFO "Dump sdb info."
#define DM_ENV_CMD "The env cmd variable string to use when configuring the server, such as: -e 'TAOS_FQDN=td1'."
#define DM_ENV_FILE "The env variable file path to use when configuring the server, default is './.env', .env text can be 'TAOS_FQDN=td1'."
-#define DM_NODE_TYPE "Startup type of the node, default is 0."
#define DM_MACHINE_CODE "Get machine code."
#define DM_VERSION "Print program version."
#define DM_EMAIL ""
@@ -44,7 +43,6 @@ static struct {
char apolloUrl[PATH_MAX];
const char **envCmd;
SArray *pArgs; // SConfigPair
- EDndNodeType ntype;
} global = {0};
static void dmStopDnode(int signum, void *info, void *ctx) { dmStop(); }
@@ -59,13 +57,6 @@ static void dmSetSignalHandle() {
taosSetSignal(SIGTSTP, dmStopDnode);
taosSetSignal(SIGQUIT, dmStopDnode);
#endif
-
- if (!tsMultiProcess) {
- } else if (global.ntype == DNODE || global.ntype == NODE_END) {
- taosIgnSignal(SIGCHLD);
- } else {
- taosKillChildOnParentStopped();
- }
}
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
@@ -91,12 +82,6 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
global.dumpSdb = true;
} else if (strcmp(argv[i], "-E") == 0) {
tstrncpy(global.envFile, argv[++i], PATH_MAX);
- } else if (strcmp(argv[i], "-n") == 0) {
- global.ntype = atoi(argv[++i]);
- if (global.ntype <= DNODE || global.ntype > NODE_END) {
- printf("'-n' range is [1 - %d], default is 0\n", NODE_END - 1);
- return -1;
- }
} else if (strcmp(argv[i], "-k") == 0) {
global.generateGrant = true;
} else if (strcmp(argv[i], "-C") == 0) {
@@ -142,7 +127,6 @@ static void dmPrintHelp() {
printf("%s%s%s%s\n", indent, "-C,", indent, DM_DMP_CFG);
printf("%s%s%s%s\n", indent, "-e,", indent, DM_ENV_CMD);
printf("%s%s%s%s\n", indent, "-E,", indent, DM_ENV_FILE);
- printf("%s%s%s%s\n", indent, "-n,", indent, DM_NODE_TYPE);
printf("%s%s%s%s\n", indent, "-k,", indent, DM_MACHINE_CODE);
printf("%s%s%s%s\n", indent, "-V,", indent, DM_VERSION);
@@ -155,17 +139,7 @@ static void dmDumpCfg() {
}
static int32_t dmInitLog() {
- char logName[12] = {0};
- snprintf(logName, sizeof(logName), "%slog", dmNodeLogName(global.ntype));
- return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0);
-}
-
-static void dmSetProcInfo(int32_t argc, char **argv) {
- taosSetProcPath(argc, argv);
- if (global.ntype != DNODE && global.ntype != NODE_END) {
- const char *name = dmNodeProcName(global.ntype);
- taosSetProcName(argc, argv, name);
- }
+ return taosCreateLog("taosdlog", 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0);
}
static void taosCleanupArgs() {
@@ -234,6 +208,7 @@ int mainWindows(int argc, char **argv) {
taosCleanupCfg();
taosCloseLog();
taosCleanupArgs();
+ taosConvDestroy();
return 0;
}
@@ -242,13 +217,14 @@ int mainWindows(int argc, char **argv) {
taosCleanupCfg();
taosCloseLog();
taosCleanupArgs();
+ taosConvDestroy();
return 0;
}
- dmSetProcInfo(argc, (char **)argv);
+ osSetProcPath(argc, (char **)argv);
taosCleanupArgs();
- if (dmInit(global.ntype) != 0) {
+ if (dmInit() != 0) {
dError("failed to init dnode since %s", terrstr());
return -1;
}
diff --git a/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt
deleted file mode 100644
index 0a6cf52fb8..0000000000
--- a/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-aux_source_directory(src MGMT_BNODE)
-add_library(mgmt_bnode STATIC ${MGMT_BNODE})
-target_include_directories(
- mgmt_bnode
- PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
-)
-target_link_libraries(
- mgmt_bnode node_util
-)
\ No newline at end of file
diff --git a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h
deleted file mode 100644
index c05ad46189..0000000000
--- a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef _TD_DND_BNODE_INT_H_
-#define _TD_DND_BNODE_INT_H_
-
-#include "dmUtil.h"
-
-#include "bnode.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct SBnodeMgmt {
- SDnodeData *pData;
- SBnode *pBnode;
- SMsgCb msgCb;
- const char *path;
- const char *name;
- SMultiWorker writeWorker;
- SSingleWorker monitorWorker;
-} SBnodeMgmt;
-
-// bmHandle.c
-SArray *bmGetMsgHandles();
-int32_t bmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
-int32_t bmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
-int32_t bmProcessGetMonBmInfoReq(SBnodeMgmt *pMgmt, SRpcMsg *pMsg);
-
-// bmWorker.c
-int32_t bmStartWorker(SBnodeMgmt *pMgmt);
-void bmStopWorker(SBnodeMgmt *pMgmt);
-int32_t bmPutNodeMsgToWriteQueue(SBnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t bmPutNodeMsgToMonitorQueue(SBnodeMgmt *pMgmt, SRpcMsg *pMsg);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_DND_BNODE_INT_H_*/
\ No newline at end of file
diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c
deleted file mode 100644
index 9ec445c69c..0000000000
--- a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#define _DEFAULT_SOURCE
-#include "bmInt.h"
-
-void bmGetMonitorInfo(SBnodeMgmt *pMgmt, SMonBmInfo *bmInfo) {}
-
-int32_t bmProcessGetMonBmInfoReq(SBnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SMonBmInfo bmInfo = {0};
- bmGetMonitorInfo(pMgmt, &bmInfo);
- dmGetMonitorSystemInfo(&bmInfo.sys);
- monGetLogs(&bmInfo.log);
-
- int32_t rspLen = tSerializeSMonBmInfo(NULL, 0, &bmInfo);
- if (rspLen < 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- void *pRsp = rpcMallocCont(rspLen);
- if (pRsp == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- tSerializeSMonBmInfo(pRsp, rspLen, &bmInfo);
- pMsg->info.rsp = pRsp;
- pMsg->info.rspLen = rspLen;
- tFreeSMonBmInfo(&bmInfo);
- return 0;
-}
-
-int32_t bmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
- SDCreateBnodeReq createReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
- terrno = TSDB_CODE_INVALID_OPTION;
- dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pInput->pData->dnodeId);
- return -1;
- }
-
- bool deployed = true;
- if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
- dError("failed to write bnode file since %s", terrstr());
- return -1;
- }
-
- return 0;
-}
-
-int32_t bmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
- SDDropBnodeReq dropReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
- terrno = TSDB_CODE_INVALID_OPTION;
- dError("failed to drop bnode since %s", terrstr());
- return -1;
- }
-
- bool deployed = false;
- if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
- dError("failed to write bnode file since %s", terrstr());
- return -1;
- }
-
- return 0;
-}
-
-SArray *bmGetMsgHandles() {
- int32_t code = -1;
- SArray *pArray = taosArrayInit(2, sizeof(SMgmtHandle));
- if (pArray == NULL) goto _OVER;
-
- if (dmSetMgmtHandle(pArray, TDMT_MON_BM_INFO, bmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
-
- code = 0;
-_OVER:
- if (code != 0) {
- taosArrayDestroy(pArray);
- return NULL;
- } else {
- return pArray;
- }
-}
diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c
deleted file mode 100644
index 2c5d23cae9..0000000000
--- a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#define _DEFAULT_SOURCE
-#include "bmInt.h"
-
-static int32_t bmRequire(const SMgmtInputOpt *pInput, bool *required) {
- return dmReadFile(pInput->path, pInput->name, required);
-}
-
-static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { pOption->msgCb = pMgmt->msgCb; }
-
-static void bmClose(SBnodeMgmt *pMgmt) {
- if (pMgmt->pBnode != NULL) {
- bmStopWorker(pMgmt);
- bndClose(pMgmt->pBnode);
- pMgmt->pBnode = NULL;
- }
-
- taosMemoryFree(pMgmt);
-}
-
-int32_t bmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
- SBnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SBnodeMgmt));
- if (pMgmt == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- pMgmt->pData = pInput->pData;
- pMgmt->path = pInput->path;
- pMgmt->name = pInput->name;
- pMgmt->msgCb = pInput->msgCb;
- pMgmt->msgCb.mgmt = pMgmt;
-
- SBnodeOpt option = {0};
- bmInitOption(pMgmt, &option);
- pMgmt->pBnode = bndOpen(pMgmt->path, &option);
- if (pMgmt->pBnode == NULL) {
- dError("failed to open bnode since %s", terrstr());
- bmClose(pMgmt);
- return -1;
- }
- tmsgReportStartup("bnode-impl", "initialized");
-
- if (bmStartWorker(pMgmt) != 0) {
- dError("failed to start bnode worker since %s", terrstr());
- bmClose(pMgmt);
- return -1;
- }
- tmsgReportStartup("bnode-worker", "initialized");
-
- pOutput->pMgmt = pMgmt;
- return 0;
-}
-
-SMgmtFunc bmGetMgmtFunc() {
- SMgmtFunc mgmtFunc = {0};
- mgmtFunc.openFp = bmOpen;
- mgmtFunc.closeFp = (NodeCloseFp)bmClose;
- mgmtFunc.createFp = (NodeCreateFp)bmProcessCreateReq;
- mgmtFunc.dropFp = (NodeDropFp)bmProcessDropReq;
- mgmtFunc.requiredFp = bmRequire;
- mgmtFunc.getHandlesFp = bmGetMsgHandles;
-
- return mgmtFunc;
-}
diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c b/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c
deleted file mode 100644
index 08c9edd854..0000000000
--- a/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#define _DEFAULT_SOURCE
-#include "bmInt.h"
-
-static void bmSendErrorRsp(SRpcMsg *pMsg, int32_t code) {
- SRpcMsg rsp = {.code = code, .info = pMsg->info};
- tmsgSendRsp(&rsp);
-
- dTrace("msg:%p, is freed", pMsg);
- rpcFreeCont(pMsg->pCont);
- taosFreeQitem(pMsg);
-}
-
-static void bmSendErrorRsps(STaosQall *qall, int32_t numOfMsgs, int32_t code) {
- for (int32_t i = 0; i < numOfMsgs; ++i) {
- SRpcMsg *pMsg = NULL;
- taosGetQitem(qall, (void **)&pMsg);
- if (pMsg != NULL) {
- bmSendErrorRsp(pMsg, code);
- }
- }
-}
-
-static inline void bmSendRsp(SRpcMsg *pMsg, int32_t code) {
- SRpcMsg rsp = {
- .code = code,
- .pCont = pMsg->info.rsp,
- .contLen = pMsg->info.rspLen,
- .info = pMsg->info,
- };
- tmsgSendRsp(&rsp);
-}
-
-static void bmProcessMonitorQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
- SBnodeMgmt *pMgmt = pInfo->ahandle;
- int32_t code = -1;
- dTrace("msg:%p, get from bnode-monitor queue", pMsg);
-
- if (pMsg->msgType == TDMT_MON_BM_INFO) {
- code = bmProcessGetMonBmInfoReq(pMgmt, pMsg);
- } else {
- terrno = TSDB_CODE_MSG_NOT_PROCESSED;
- }
-
- if (IsReq(pMsg)) {
- if (code != 0 && terrno != 0) code = terrno;
- bmSendRsp(pMsg, code);
- }
-
- dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
- rpcFreeCont(pMsg->pCont);
- taosFreeQitem(pMsg);
-}
-
-static void bmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
- SBnodeMgmt *pMgmt = pInfo->ahandle;
-
- SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *));
- if (pArray == NULL) {
- bmSendErrorRsps(qall, numOfMsgs, TSDB_CODE_OUT_OF_MEMORY);
- return;
- }
-
- for (int32_t i = 0; i < numOfMsgs; ++i) {
- SRpcMsg *pMsg = NULL;
- taosGetQitem(qall, (void **)&pMsg);
- if (pMsg != NULL) {
- dTrace("msg:%p, get from bnode-write queue", pMsg);
- if (taosArrayPush(pArray, &pMsg) == NULL) {
- bmSendErrorRsp(pMsg, TSDB_CODE_OUT_OF_MEMORY);
- }
- }
- }
-
- bndProcessWMsgs(pMgmt->pBnode, pArray);
-
- for (size_t i = 0; i < numOfMsgs; i++) {
- SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
- if (pMsg != NULL) {
- dTrace("msg:%p, is freed", pMsg);
- rpcFreeCont(pMsg->pCont);
- taosFreeQitem(pMsg);
- }
- }
- taosArrayDestroy(pArray);
-}
-
-int32_t bmPutNodeMsgToWriteQueue(SBnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SMultiWorker *pWorker = &pMgmt->writeWorker;
-
- dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name);
- taosWriteQitem(pWorker->queue, pMsg);
- return 0;
-}
-
-int32_t bmPutNodeMsgToMonitorQueue(SBnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SSingleWorker *pWorker = &pMgmt->monitorWorker;
-
- dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name);
- taosWriteQitem(pWorker->queue, pMsg);
- return 0;
-}
-
-int32_t bmStartWorker(SBnodeMgmt *pMgmt) {
- SMultiWorkerCfg cfg = {
- .max = 1,
- .name = "bnode-write",
- .fp = (FItems)bmProcessWriteQueue,
- .param = pMgmt,
- };
- if (tMultiWorkerInit(&pMgmt->writeWorker, &cfg) != 0) {
- dError("failed to start bnode-write worker since %s", terrstr());
- return -1;
- }
-
- SSingleWorkerCfg mCfg = {
- .min = 1,
- .max = 1,
- .name = "bnode-monitor",
- .fp = (FItem)bmProcessMonitorQueue,
- .param = pMgmt,
- };
- if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) {
- dError("failed to start bnode-monitor worker since %s", terrstr());
- return -1;
- }
-
- dDebug("bnode workers are initialized");
- return 0;
-}
-
-void bmStopWorker(SBnodeMgmt *pMgmt) {
- tSingleWorkerCleanup(&pMgmt->monitorWorker);
- tMultiWorkerCleanup(&pMgmt->writeWorker);
- dDebug("bnode workers are closed");
-}
diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
index dd98816161..782c828bb2 100644
--- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
+++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c
@@ -326,8 +326,6 @@ SArray *dmGetMsgHandles() {
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_QNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_SNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_BNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_BNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_SERVER_STATUS, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_SYSTABLE_RETRIEVE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c
index e7ccce1c8b..ca8a434d05 100644
--- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c
+++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c
@@ -132,12 +132,6 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
case TDMT_DND_DROP_SNODE:
code = (*pMgmt->processDropNodeFp)(SNODE, pMsg);
break;
- case TDMT_DND_CREATE_BNODE:
- code = (*pMgmt->processCreateNodeFp)(BNODE, pMsg);
- break;
- case TDMT_DND_DROP_BNODE:
- code = (*pMgmt->processDropNodeFp)(BNODE, pMsg);
- break;
case TDMT_DND_SERVER_STATUS:
code = dmProcessServerRunStatus(pMgmt, pMsg);
break;
diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h
index 17cbde437b..6d06535447 100644
--- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h
+++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h
@@ -34,7 +34,6 @@ typedef struct SMnodeMgmt {
SSingleWorker readWorker;
SSingleWorker writeWorker;
SSingleWorker syncWorker;
- SSingleWorker monitorWorker;
bool stopped;
int32_t refCount;
TdThreadRwlock lock;
@@ -48,8 +47,6 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption);
SArray *mmGetMsgHandles();
int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
-int32_t mmProcessGetMonitorInfoReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t mmProcessGetLoadsReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
// mmWorker.c
int32_t mmStartWorker(SMnodeMgmt *pMgmt);
@@ -59,7 +56,6 @@ int32_t mmPutMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t mmPutMsgToFetchQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t mmPutMsgToMonitorQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc);
#ifdef __cplusplus
diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
index fc45dbf15f..7fb700e776 100644
--- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
+++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
@@ -20,58 +20,11 @@ void mmGetMonitorInfo(SMnodeMgmt *pMgmt, SMonMmInfo *pInfo) {
mndGetMonitorInfo(pMgmt->pMnode, &pInfo->cluster, &pInfo->vgroup, &pInfo->stb, &pInfo->grant);
}
-int32_t mmProcessGetMonitorInfoReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SMonMmInfo mmInfo = {0};
- mmGetMonitorInfo(pMgmt, &mmInfo);
- dmGetMonitorSystemInfo(&mmInfo.sys);
- monGetLogs(&mmInfo.log);
-
- int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo);
- if (rspLen < 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- void *pRsp = rpcMallocCont(rspLen);
- if (pRsp == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo);
- pMsg->info.rsp = pRsp;
- pMsg->info.rspLen = rspLen;
- tFreeSMonMmInfo(&mmInfo);
- return 0;
-}
-
void mmGetMnodeLoads(SMnodeMgmt *pMgmt, SMonMloadInfo *pInfo) {
pInfo->isMnode = 1;
mndGetLoad(pMgmt->pMnode, &pInfo->load);
}
-int32_t mmProcessGetLoadsReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SMonMloadInfo mloads = {0};
- mmGetMnodeLoads(pMgmt, &mloads);
-
- int32_t rspLen = tSerializeSMonMloadInfo(NULL, 0, &mloads);
- if (rspLen < 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- void *pRsp = rpcMallocCont(rspLen);
- if (pRsp == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- tSerializeSMonMloadInfo(pRsp, rspLen, &mloads);
- pMsg->info.rsp = pRsp;
- pMsg->info.rspLen = rspLen;
- return 0;
-}
-
int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
const STraceId *trace = &pMsg->info.traceId;
SDCreateMnodeReq createReq = {0};
@@ -105,7 +58,7 @@ int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
const STraceId *trace = &pMsg->info.traceId;
SDDropMnodeReq dropReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
@@ -136,8 +89,6 @@ SArray *mmGetMsgHandles() {
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_QNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_SNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_SNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_BNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_BNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
@@ -163,8 +114,6 @@ SArray *mmGetMsgHandles() {
if (dmSetMgmtHandle(pArray, TDMT_MND_DNODE_LIST, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_SNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_SNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_BNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_BNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_MND_USE_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
@@ -234,9 +183,6 @@ SArray *mmGetMsgHandles() {
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_HASHRANGE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MON_MM_INFO, mmPutMsgToMonitorQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MON_MM_LOAD, mmPutMsgToMonitorQueue, 0) == NULL) goto _OVER;
-
if (dmSetMgmtHandle(pArray, TDMT_SYNC_TIMEOUT, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c
index 849d3ef390..16e6f67409 100644
--- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c
+++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c
@@ -46,22 +46,12 @@ static inline void mmSendRsp(SRpcMsg *pMsg, int32_t code) {
static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
SMnodeMgmt *pMgmt = pInfo->ahandle;
- int32_t code = -1;
+ pMsg->info.node = pMgmt->pMnode;
const STraceId *trace = &pMsg->info.traceId;
dGTrace("msg:%p, get from mnode queue", pMsg);
- switch (pMsg->msgType) {
- case TDMT_MON_MM_INFO:
- code = mmProcessGetMonitorInfoReq(pMgmt, pMsg);
- break;
- case TDMT_MON_MM_LOAD:
- code = mmProcessGetLoadsReq(pMgmt, pMsg);
- break;
- default:
- pMsg->info.node = pMgmt->pMnode;
- code = mndProcessRpcMsg(pMsg);
- }
+ int32_t code = mndProcessRpcMsg(pMsg);
if (IsReq(pMsg) && pMsg->info.handle != NULL && code != TSDB_CODE_ACTION_IN_PROGRESS) {
if (code != 0 && terrno != 0) code = terrno;
@@ -136,10 +126,6 @@ int32_t mmPutMsgToFetchQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
return mmPutMsgToWorker(pMgmt, &pMgmt->fetchWorker, pMsg);
}
-int32_t mmPutMsgToMonitorQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return mmPutMsgToWorker(pMgmt, &pMgmt->monitorWorker, pMsg);
-}
-
int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
SSingleWorker *pWorker = NULL;
switch (qtype) {
@@ -237,18 +223,6 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
return -1;
}
- SSingleWorkerCfg mCfg = {
- .min = 1,
- .max = 1,
- .name = "mnode-monitor",
- .fp = (FItem)mmProcessRpcMsg,
- .param = pMgmt,
- };
- if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) {
- dError("failed to start mnode mnode-monitor worker since %s", terrstr());
- return -1;
- }
-
dDebug("mnode workers are initialized");
return 0;
}
@@ -256,7 +230,6 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
void mmStopWorker(SMnodeMgmt *pMgmt) {
while (pMgmt->refCount > 0) taosMsleep(10);
- tSingleWorkerCleanup(&pMgmt->monitorWorker);
tSingleWorkerCleanup(&pMgmt->queryWorker);
tSingleWorkerCleanup(&pMgmt->fetchWorker);
tSingleWorkerCleanup(&pMgmt->readWorker);
diff --git a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h
index 56bf56f25e..c6c239bdcc 100644
--- a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h
+++ b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h
@@ -32,14 +32,12 @@ typedef struct SQnodeMgmt {
const char *name;
SSingleWorker queryWorker;
SSingleWorker fetchWorker;
- SSingleWorker monitorWorker;
} SQnodeMgmt;
// qmHandle.c
SArray *qmGetMsgHandles();
int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
-int32_t qmProcessGetMonitorInfoReq(SQnodeMgmt *pMgmt, SRpcMsg *pMsg);
// qmWorker.c
int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pMsg);
@@ -49,7 +47,6 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt);
void qmStopWorker(SQnodeMgmt *pMgmt);
int32_t qmPutNodeMsgToQueryQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t qmPutNodeMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t qmPutNodeMsgToMonitorQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg);
diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c
index 6382152cd1..5017ad7b74 100644
--- a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c
+++ b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c
@@ -29,34 +29,9 @@ void qmGetQnodeLoads(SQnodeMgmt *pMgmt, SQnodeLoad *pInfo) {
pInfo->dnodeId = pMgmt->pData->dnodeId;
}
-int32_t qmProcessGetMonitorInfoReq(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SMonQmInfo qmInfo = {0};
- qmGetMonitorInfo(pMgmt, &qmInfo);
- dmGetMonitorSystemInfo(&qmInfo.sys);
- monGetLogs(&qmInfo.log);
-
- int32_t rspLen = tSerializeSMonQmInfo(NULL, 0, &qmInfo);
- if (rspLen < 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- void *pRsp = rpcMallocCont(rspLen);
- if (pRsp == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- tSerializeSMonQmInfo(pRsp, rspLen, &qmInfo);
- pMsg->info.rsp = pRsp;
- pMsg->info.rspLen = rspLen;
- tFreeSMonQmInfo(&qmInfo);
- return 0;
-}
-
int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
SDCreateQnodeReq createReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
@@ -78,7 +53,7 @@ int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
SDDropQnodeReq dropReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
@@ -103,8 +78,6 @@ SArray *qmGetMsgHandles() {
SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
if (pArray == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MON_QM_INFO, qmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
-
// Requests handled by VNODE
if (dmSetMgmtHandle(pArray, TDMT_SCH_QUERY, qmPutNodeMsgToQueryQueue, 1) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_SCH_MERGE_QUERY, qmPutNodeMsgToQueryQueue, 1) == NULL) goto _OVER;
diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c
index 66386b0ee0..edbe9882a4 100644
--- a/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c
+++ b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c
@@ -28,18 +28,9 @@ static inline void qmSendRsp(SRpcMsg *pMsg, int32_t code) {
static void qmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
SQnodeMgmt *pMgmt = pInfo->ahandle;
- int32_t code = -1;
dTrace("msg:%p, get from qnode queue", pMsg);
- switch (pMsg->msgType) {
- case TDMT_MON_QM_INFO:
- code = qmProcessGetMonitorInfoReq(pMgmt, pMsg);
- break;
- default:
- code = qndProcessQueryMsg(pMgmt->pQnode, pInfo->timestamp, pMsg);
- break;
- }
-
+ int32_t code = qndProcessQueryMsg(pMgmt->pQnode, pInfo->timestamp, pMsg);
if (IsReq(pMsg) && code != TSDB_CODE_ACTION_IN_PROGRESS) {
if (code != 0 && terrno != 0) code = terrno;
qmSendRsp(pMsg, code);
@@ -66,10 +57,6 @@ int32_t qmPutNodeMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
return qmPutNodeMsgToWorker(&pMgmt->fetchWorker, pMsg);
}
-int32_t qmPutNodeMsgToMonitorQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- return qmPutNodeMsgToWorker(&pMgmt->monitorWorker, pMsg);
-}
-
int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM);
if (pMsg == NULL) return -1;
@@ -136,24 +123,11 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
return -1;
}
- SSingleWorkerCfg mCfg = {
- .min = 1,
- .max = 1,
- .name = "qnode-monitor",
- .fp = (FItem)qmProcessQueue,
- .param = pMgmt,
- };
- if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) {
- dError("failed to start qnode-monitor worker since %s", terrstr());
- return -1;
- }
-
dDebug("qnode workers are initialized");
return 0;
}
void qmStopWorker(SQnodeMgmt *pMgmt) {
- tSingleWorkerCleanup(&pMgmt->monitorWorker);
tSingleWorkerCleanup(&pMgmt->queryWorker);
tSingleWorkerCleanup(&pMgmt->fetchWorker);
dDebug("qnode workers are closed");
diff --git a/source/dnode/mgmt/mgmt_snode/inc/smInt.h b/source/dnode/mgmt/mgmt_snode/inc/smInt.h
index fbf63dda43..4efe1c997b 100644
--- a/source/dnode/mgmt/mgmt_snode/inc/smInt.h
+++ b/source/dnode/mgmt/mgmt_snode/inc/smInt.h
@@ -33,14 +33,12 @@ typedef struct SSnodeMgmt {
int8_t uniqueWorkerInUse;
SArray *uniqueWorkers; // SArray
SSingleWorker sharedWorker;
- SSingleWorker monitorWorker;
} SSnodeMgmt;
// smHandle.c
SArray *smGetMsgHandles();
int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
-int32_t smProcessGetMonitorInfoReq(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
// smWorker.c
int32_t smStartWorker(SSnodeMgmt *pMgmt);
@@ -49,7 +47,6 @@ int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t smPutNodeMsgToUniqueQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t smPutNodeMsgToSharedQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t smPutNodeMsgToExecQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t smPutNodeMsgToMonitorQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg);
#ifdef __cplusplus
}
diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c
index 7cb41ca77c..65c96767ab 100644
--- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c
+++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c
@@ -18,34 +18,9 @@
void smGetMonitorInfo(SSnodeMgmt *pMgmt, SMonSmInfo *smInfo) {}
-int32_t smProcessGetMonitorInfoReq(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SMonSmInfo smInfo = {0};
- smGetMonitorInfo(pMgmt, &smInfo);
- dmGetMonitorSystemInfo(&smInfo.sys);
- monGetLogs(&smInfo.log);
-
- int32_t rspLen = tSerializeSMonSmInfo(NULL, 0, &smInfo);
- if (rspLen < 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- void *pRsp = rpcMallocCont(rspLen);
- if (pRsp == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- tSerializeSMonSmInfo(pRsp, rspLen, &smInfo);
- pMsg->info.rsp = pRsp;
- pMsg->info.rspLen = rspLen;
- tFreeSMonSmInfo(&smInfo);
- return 0;
-}
-
int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
SDCreateSnodeReq createReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
@@ -67,7 +42,7 @@ int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
SDDropSnodeReq dropReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
@@ -92,8 +67,6 @@ SArray *smGetMsgHandles() {
SArray *pArray = taosArrayInit(4, sizeof(SMgmtHandle));
if (pArray == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MON_SM_INFO, smPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER;
-
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER;
diff --git a/source/dnode/mgmt/mgmt_snode/src/smWorker.c b/source/dnode/mgmt/mgmt_snode/src/smWorker.c
index 19c1b9b5c7..ad56d57f69 100644
--- a/source/dnode/mgmt/mgmt_snode/src/smWorker.c
+++ b/source/dnode/mgmt/mgmt_snode/src/smWorker.c
@@ -26,27 +26,6 @@ static inline void smSendRsp(SRpcMsg *pMsg, int32_t code) {
tmsgSendRsp(&rsp);
}
-static void smProcessMonitorQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
- SSnodeMgmt *pMgmt = pInfo->ahandle;
- int32_t code = -1;
- dTrace("msg:%p, get from snode-monitor queue", pMsg);
-
- if (pMsg->msgType == TDMT_MON_SM_INFO) {
- code = smProcessGetMonitorInfoReq(pMgmt, pMsg);
- } else {
- terrno = TSDB_CODE_MSG_NOT_PROCESSED;
- }
-
- if (IsReq(pMsg)) {
- if (code != 0 && terrno != 0) code = terrno;
- smSendRsp(pMsg, code);
- }
-
- dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
- rpcFreeCont(pMsg->pCont);
- taosFreeQitem(pMsg);
-}
-
static void smProcessUniqueQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
SSnodeMgmt *pMgmt = pInfo->ahandle;
@@ -123,24 +102,11 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
return -1;
}
- SSingleWorkerCfg mCfg = {
- .min = 1,
- .max = 1,
- .name = "snode-monitor",
- .fp = (FItem)smProcessMonitorQueue,
- .param = pMgmt,
- };
- if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) {
- dError("failed to start snode-monitor worker since %s", terrstr());
- return -1;
- }
-
dDebug("snode workers are initialized");
return 0;
}
void smStopWorker(SSnodeMgmt *pMgmt) {
- tSingleWorkerCleanup(&pMgmt->monitorWorker);
for (int32_t i = 0; i < taosArrayGetSize(pMgmt->uniqueWorkers); i++) {
SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, i);
tMultiWorkerCleanup(pWorker);
@@ -175,14 +141,6 @@ int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
return 0;
}
-int32_t smPutNodeMsgToMonitorQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SSingleWorker *pWorker = &pMgmt->monitorWorker;
-
- dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
- taosWriteQitem(pWorker->queue, pMsg);
- return 0;
-}
-
int32_t smPutNodeMsgToUniqueQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
int32_t index = smGetSWIdFromMsg(pMsg);
SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, index);
diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h
index 30f5483198..1bd68e6d41 100644
--- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h
+++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h
@@ -34,10 +34,10 @@ typedef struct SVnodeMgmt {
SQWorkerPool streamPool;
SWWorkerPool fetchPool;
SWWorkerPool syncPool;
+ SWWorkerPool syncCtrlPool;
SWWorkerPool writePool;
SWWorkerPool applyPool;
SSingleWorker mgmtWorker;
- SSingleWorker monitorWorker;
SHashObj *hash;
TdThreadRwlock lock;
SVnodesStat state;
@@ -60,6 +60,7 @@ typedef struct {
SVnode *pImpl;
STaosQueue *pWriteQ;
STaosQueue *pSyncQ;
+ STaosQueue *pSyncCtrlQ;
STaosQueue *pApplyQ;
STaosQueue *pQueryQ;
STaosQueue *pStreamQ;
@@ -87,8 +88,6 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode);
SArray *vmGetMsgHandles();
int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmProcessGetMonitorInfoReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmProcessGetLoadsReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
// vmFile.c
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
@@ -106,12 +105,12 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc);
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
+int32_t vmPutMsgToSyncCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
-int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
#ifdef __cplusplus
}
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
index 0e53b7ca80..c92b6c4c4d 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
@@ -83,54 +83,6 @@ void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) {
taosArrayDestroy(pVloads);
}
-int32_t vmProcessGetMonitorInfoReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SMonVmInfo vmInfo = {0};
- vmGetMonitorInfo(pMgmt, &vmInfo);
- dmGetMonitorSystemInfo(&vmInfo.sys);
- monGetLogs(&vmInfo.log);
-
- int32_t rspLen = tSerializeSMonVmInfo(NULL, 0, &vmInfo);
- if (rspLen < 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- void *pRsp = rpcMallocCont(rspLen);
- if (pRsp == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- tSerializeSMonVmInfo(pRsp, rspLen, &vmInfo);
- pMsg->info.rsp = pRsp;
- pMsg->info.rspLen = rspLen;
- tFreeSMonVmInfo(&vmInfo);
- return 0;
-}
-
-int32_t vmProcessGetLoadsReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- SMonVloadInfo vloads = {0};
- vmGetVnodeLoads(pMgmt, &vloads, false);
-
- int32_t rspLen = tSerializeSMonVloadInfo(NULL, 0, &vloads);
- if (rspLen < 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- return -1;
- }
-
- void *pRsp = rpcMallocCont(rspLen);
- if (pRsp == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- tSerializeSMonVloadInfo(pRsp, rspLen, &vloads);
- pMsg->info.rsp = pRsp;
- pMsg->info.rspLen = rspLen;
- tFreeSMonVloadInfo(&vloads);
- return 0;
-}
-
static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
memcpy(pCfg, &vnodeCfgDefault, sizeof(SVnodeCfg));
@@ -348,9 +300,6 @@ SArray *vmGetMsgHandles() {
SArray *pArray = taosArrayInit(32, sizeof(SMgmtHandle));
if (pArray == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MON_VM_INFO, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER;
- if (dmSetMgmtHandle(pArray, TDMT_MON_VM_LOAD, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER;
-
if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_SCH_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_SCH_MERGE_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
@@ -422,6 +371,8 @@ SArray *vmGetMsgHandles() {
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_VNODE_STANDBY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER;
+ if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER;
code = 0;
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
index bcc2e358d6..f825407b45 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
@@ -217,17 +217,80 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) {
}
}
+static void *vmCloseVnodeInThread(void *param) {
+ SVnodeThread *pThread = param;
+ SVnodeMgmt *pMgmt = pThread->pMgmt;
+
+ dInfo("thread:%d, start to close %d vnodes", pThread->threadIndex, pThread->vnodeNum);
+ setThreadName("close-vnodes");
+
+ for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
+ SVnodeObj *pVnode = pThread->ppVnodes[v];
+
+ char stepDesc[TSDB_STEP_DESC_LEN] = {0};
+ snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to close, %d of %d have been closed", pVnode->vgId,
+ pMgmt->state.openVnodes, pMgmt->state.totalVnodes);
+ tmsgReportStartup("vnode-close", stepDesc);
+
+ vmCloseVnode(pMgmt, pVnode);
+ }
+
+ dInfo("thread:%d, numOfVnodes:%d is closed", pThread->threadIndex, pThread->vnodeNum);
+ return NULL;
+}
+
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
dInfo("start to close all vnodes");
int32_t numOfVnodes = 0;
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
- for (int32_t i = 0; i < numOfVnodes; ++i) {
- if (ppVnodes == NULL || ppVnodes[i] == NULL) continue;
- vmCloseVnode(pMgmt, ppVnodes[i]);
+ int32_t threadNum = tsNumOfCores / 2;
+ if (threadNum < 1) threadNum = 1;
+ int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
+
+ SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
+ for (int32_t t = 0; t < threadNum; ++t) {
+ threads[t].threadIndex = t;
+ threads[t].pMgmt = pMgmt;
+ threads[t].ppVnodes = taosMemoryCalloc(vnodesPerThread, sizeof(SVnode *));
}
+ for (int32_t v = 0; v < numOfVnodes; ++v) {
+ int32_t t = v % threadNum;
+ SVnodeThread *pThread = &threads[t];
+ if (pThread->ppVnodes != NULL && ppVnodes != NULL) {
+ pThread->ppVnodes[pThread->vnodeNum++] = ppVnodes[v];
+ }
+ }
+
+ pMgmt->state.openVnodes = 0;
+ dInfo("close %d vnodes with %d threads", numOfVnodes, threadNum);
+
+ for (int32_t t = 0; t < threadNum; ++t) {
+ SVnodeThread *pThread = &threads[t];
+ if (pThread->vnodeNum == 0) continue;
+
+ TdThreadAttr thAttr;
+ taosThreadAttrInit(&thAttr);
+ taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
+ if (taosThreadCreate(&pThread->thread, &thAttr, vmCloseVnodeInThread, pThread) != 0) {
+ dError("thread:%d, failed to create thread to close vnode since %s", pThread->threadIndex, strerror(errno));
+ }
+
+ taosThreadAttrDestroy(&thAttr);
+ }
+
+ for (int32_t t = 0; t < threadNum; ++t) {
+ SVnodeThread *pThread = &threads[t];
+ if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) {
+ taosThreadJoin(pThread->thread, NULL);
+ taosThreadClear(&pThread->thread);
+ }
+ taosMemoryFree(pThread->ppVnodes);
+ }
+ taosMemoryFree(threads);
+
if (ppVnodes != NULL) {
taosMemoryFree(ppVnodes);
}
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
index d7df30bc75..fd1dbe00ce 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
@@ -34,12 +34,6 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
dGTrace("msg:%p, get from vnode-mgmt queue", pMsg);
switch (pMsg->msgType) {
- case TDMT_MON_VM_INFO:
- code = vmProcessGetMonitorInfoReq(pMgmt, pMsg);
- break;
- case TDMT_MON_VM_LOAD:
- code = vmProcessGetLoadsReq(pMgmt, pMsg);
- break;
case TDMT_DND_CREATE_VNODE:
code = vmProcessCreateVnodeReq(pMgmt, pMsg);
break;
@@ -136,6 +130,22 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
}
}
+static void vmProcessSyncCtrlQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
+ SVnodeObj *pVnode = pInfo->ahandle;
+ SRpcMsg *pMsg = NULL;
+
+ for (int32_t i = 0; i < numOfMsgs; ++i) {
+ if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
+ const STraceId *trace = &pMsg->info.traceId;
+ dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
+
+ int32_t code = vnodeProcessSyncCtrlMsg(pVnode->pImpl, pMsg, NULL); // no response here
+ dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
+ rpcFreeCont(pMsg->pCont);
+ taosFreeQitem(pMsg);
+ }
+}
+
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
const STraceId *trace = &pMsg->info.traceId;
SMsgHead *pHead = pMsg->pCont;
@@ -203,6 +213,10 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pSyncQ, pMsg);
break;
+ case SYNC_CTRL_QUEUE:
+ dGTrace("vgId:%d, msg:%p put into vnode-sync-ctrl queue", pVnode->vgId, pMsg);
+ taosWriteQitem(pVnode->pSyncCtrlQ, pMsg);
+ break;
case APPLY_QUEUE:
dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
taosWriteQitem(pVnode->pApplyQ, pMsg);
@@ -219,6 +233,10 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
+int32_t vmPutMsgToSyncCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
+ return vmPutMsgToQueue(pMgmt, pMsg, SYNC_CTRL_QUEUE);
+}
+
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, QUERY_QUEUE); }
@@ -234,13 +252,6 @@ int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
return 0;
}
-int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
- const STraceId *trace = &pMsg->info.traceId;
- dGTrace("msg:%p, put into vnode-monitor queue", pMsg);
- taosWriteQitem(pMgmt->monitorWorker.queue, pMsg);
- return 0;
-}
-
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM);
if (pMsg == NULL) {
@@ -301,6 +312,7 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode->pImpl, (FItems)vnodeProposeWriteMsg);
pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue);
+ pVnode->pSyncCtrlQ = tWWorkerAllocQueue(&pMgmt->syncCtrlPool, pVnode, (FItems)vmProcessSyncCtrlQueue);
pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyWriteMsg);
pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
pVnode->pStreamQ = tQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
@@ -325,6 +337,7 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
tWWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ);
tWWorkerFreeQueue(&pMgmt->applyPool, pVnode->pApplyQ);
tWWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ);
+ tWWorkerFreeQueue(&pMgmt->syncCtrlPool, pVnode->pSyncCtrlQ);
tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
tQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ);
tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
@@ -370,6 +383,11 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
pSPool->max = tsNumOfVnodeSyncThreads;
if (tWWorkerInit(pSPool) != 0) return -1;
+ SWWorkerPool *pSCPool = &pMgmt->syncCtrlPool;
+ pSCPool->name = "vnode-sync-ctrl";
+ pSCPool->max = tsNumOfVnodeSyncThreads;
+ if (tWWorkerInit(pSCPool) != 0) return -1;
+
SSingleWorkerCfg mgmtCfg = {
.min = 1,
.max = 1,
@@ -379,25 +397,16 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
};
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) return -1;
- SSingleWorkerCfg monitorCfg = {
- .min = 1,
- .max = 1,
- .name = "vnode-monitor",
- .fp = (FItem)vmProcessMgmtQueue,
- .param = pMgmt,
- };
- if (tSingleWorkerInit(&pMgmt->monitorWorker, &monitorCfg) != 0) return -1;
-
dDebug("vnode workers are initialized");
return 0;
}
void vmStopWorker(SVnodeMgmt *pMgmt) {
- tSingleWorkerCleanup(&pMgmt->monitorWorker);
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
tWWorkerCleanup(&pMgmt->writePool);
tWWorkerCleanup(&pMgmt->applyPool);
tWWorkerCleanup(&pMgmt->syncPool);
+ tWWorkerCleanup(&pMgmt->syncCtrlPool);
tQWorkerCleanup(&pMgmt->queryPool);
tQWorkerCleanup(&pMgmt->streamPool);
tWWorkerCleanup(&pMgmt->fetchPool);
diff --git a/source/dnode/mgmt/node_mgmt/CMakeLists.txt b/source/dnode/mgmt/node_mgmt/CMakeLists.txt
index 98027d80d4..f1be20289a 100644
--- a/source/dnode/mgmt/node_mgmt/CMakeLists.txt
+++ b/source/dnode/mgmt/node_mgmt/CMakeLists.txt
@@ -1,7 +1,7 @@
aux_source_directory(src IMPLEMENT_SRC)
add_library(dnode STATIC ${IMPLEMENT_SRC})
target_link_libraries(
- dnode mgmt_bnode mgmt_mnode mgmt_qnode mgmt_snode mgmt_vnode mgmt_dnode
+ dnode mgmt_mnode mgmt_qnode mgmt_snode mgmt_vnode mgmt_dnode
)
target_include_directories(
dnode
diff --git a/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h b/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h
index adde055796..7e85e6b722 100644
--- a/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h
+++ b/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h
@@ -25,44 +25,6 @@
extern "C" {
#endif
-typedef struct SMgmtWrapper SMgmtWrapper;
-
-#define SINGLE_PROC 0
-#define CHILD_PROC 1
-#define PARENT_PROC 2
-#define TEST_PROC 3
-#define OnlyInSingleProc(wrapper) ((wrapper)->proc.ptype == SINGLE_PROC)
-#define OnlyInChildProc(wrapper) ((wrapper)->proc.ptype == CHILD_PROC)
-#define OnlyInParentProc(wrapper) ((wrapper)->proc.ptype == PARENT_PROC)
-#define InChildProc(wrapper) ((wrapper)->proc.ptype & CHILD_PROC)
-#define InParentProc(wrapper) ((wrapper)->proc.ptype & PARENT_PROC)
-
-typedef struct {
- int32_t head;
- int32_t tail;
- int32_t total;
- int32_t avail;
- int32_t items;
- char name[8];
- TdThreadMutex mutex;
- tsem_t sem;
- char pBuffer[];
-} SProcQueue;
-
-typedef struct {
- SMgmtWrapper *wrapper;
- const char *name;
- SHashObj *hash;
- SProcQueue *pqueue;
- SProcQueue *cqueue;
- TdThread pthread;
- TdThread cthread;
- SShm shm;
- int32_t pid;
- EDndProcType ptype;
- bool stop;
-} SProc;
-
typedef struct SMgmtWrapper {
SMgmtFunc func;
struct SDnode *pDnode;
@@ -74,7 +36,6 @@ typedef struct SMgmtWrapper {
EDndNodeType ntype;
bool deployed;
bool required;
- SProc proc;
NodeMsgFp msgFps[TDMT_MAX];
} SMgmtWrapper;
@@ -111,8 +72,6 @@ typedef struct SUdfdData {
typedef struct SDnode {
int8_t once;
bool stop;
- EDndProcType ptype;
- EDndNodeType rtype;
EDndRunStatus status;
SStartupInfo startup;
SDnodeTrans trans;
@@ -128,7 +87,7 @@ SDnode *dmInstance();
void dmReportStartup(const char *pName, const char *pDesc);
// dmMgmt.c
-int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype);
+int32_t dmInitDnode(SDnode *pDnode);
void dmCleanupDnode(SDnode *pDnode);
SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
@@ -145,16 +104,6 @@ void dmStopNode(SMgmtWrapper *pWrapper);
void dmCloseNode(SMgmtWrapper *pWrapper);
int32_t dmRunDnode(SDnode *pDnode);
-// dmProc.c
-int32_t dmInitProc(struct SMgmtWrapper *pWrapper);
-void dmCleanupProc(struct SMgmtWrapper *pWrapper);
-int32_t dmRunProc(SProc *proc);
-void dmStopProc(SProc *proc);
-void dmRemoveProcRpcHandle(SProc *proc, void *handle);
-void dmCloseProcRpcHandles(SProc *proc);
-int32_t dmPutToProcCQueue(SProc *proc, SRpcMsg *pMsg, EProcFuncType ftype);
-void dmPutToProcPQueue(SProc *proc, SRpcMsg *pMsg, EProcFuncType ftype);
-
// dmTransport.c
int32_t dmInitServer(SDnode *pDnode);
void dmCleanupServer(SDnode *pDnode);
diff --git a/source/dnode/mgmt/node_mgmt/inc/dmNodes.h b/source/dnode/mgmt/node_mgmt/inc/dmNodes.h
index d3f1044f88..5f36309038 100644
--- a/source/dnode/mgmt/node_mgmt/inc/dmNodes.h
+++ b/source/dnode/mgmt/node_mgmt/inc/dmNodes.h
@@ -23,7 +23,6 @@ extern "C" {
#endif
SMgmtFunc dmGetMgmtFunc();
-SMgmtFunc bmGetMgmtFunc();
SMgmtFunc qmGetMgmtFunc();
SMgmtFunc smGetMgmtFunc();
SMgmtFunc vmGetMgmtFunc();
diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c
index 5a7f149bc6..a222ad3f7d 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c
@@ -53,13 +53,19 @@ static bool dmCheckDiskSpace() {
osUpdate();
// sufficiency
if (!osDataSpaceSufficient()) {
- dWarn("free data disk size: %f GB, not sufficient, expected %f GB at least", (double)tsDataSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsDataSpace.reserved / 1024.0 / 1024.0 / 1024.0);
+ dWarn("free data disk size: %f GB, not sufficient, expected %f GB at least",
+ (double)tsDataSpace.size.avail / 1024.0 / 1024.0 / 1024.0,
+ (double)tsDataSpace.reserved / 1024.0 / 1024.0 / 1024.0);
}
if (!osLogSpaceSufficient()) {
- dWarn("free log disk size: %f GB, not sufficient, expected %f GB at least", (double)tsLogSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsLogSpace.reserved / 1024.0 / 1024.0 / 1024.0);
+ dWarn("free log disk size: %f GB, not sufficient, expected %f GB at least",
+ (double)tsLogSpace.size.avail / 1024.0 / 1024.0 / 1024.0,
+ (double)tsLogSpace.reserved / 1024.0 / 1024.0 / 1024.0);
}
if (!osTempSpaceSufficient()) {
- dWarn("free temp disk size: %f GB, not sufficient, expected %f GB at least", (double)tsTempSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsTempSpace.reserved / 1024.0 / 1024.0 / 1024.0);
+ dWarn("free temp disk size: %f GB, not sufficient, expected %f GB at least",
+ (double)tsTempSpace.size.avail / 1024.0 / 1024.0 / 1024.0,
+ (double)tsTempSpace.reserved / 1024.0 / 1024.0 / 1024.0);
}
// availability
bool ret = true;
@@ -82,7 +88,7 @@ static bool dmCheckDiskSpace() {
}
static bool dmCheckDataDirVersion() {
- char checkDataDirJsonFileName[PATH_MAX];
+ char checkDataDirJsonFileName[PATH_MAX] = {0};
snprintf(checkDataDirJsonFileName, PATH_MAX, "%s/dnode/dnodeCfg.json", tsDataDir);
if (taosCheckExistFile(checkDataDirJsonFileName)) {
dError("The default data directory %s contains old data of tdengine 2.x, please clear it before running!",
@@ -92,14 +98,14 @@ static bool dmCheckDataDirVersion() {
return true;
}
-int32_t dmInit(int8_t rtype) {
+int32_t dmInit() {
dInfo("start to init dnode env");
if (!dmCheckDataDirVersion()) return -1;
if (!dmCheckDiskSpace()) return -1;
if (dmCheckRepeatInit(dmInstance()) != 0) return -1;
if (dmInitSystem() != 0) return -1;
if (dmInitMonitor() != 0) return -1;
- if (dmInitDnode(dmInstance(), rtype) != 0) return -1;
+ if (dmInitDnode(dmInstance()) != 0) return -1;
dInfo("dnode env is initialized");
return 0;
@@ -126,8 +132,8 @@ void dmCleanup() {
taosStopCacheRefreshWorker();
dInfo("dnode env is cleaned up");
- taosCloseLog();
taosCleanupCfg();
+ taosCloseLog();
}
void dmStop() {
@@ -174,7 +180,6 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
}
pWrapper->deployed = true;
pWrapper->required = true;
- pWrapper->proc.ptype = pDnode->ptype;
}
taosThreadMutexUnlock(&pDnode->mutex);
diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c
index 2e149be3b6..2c9020b668 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c
@@ -26,47 +26,14 @@ static bool dmRequireNode(SDnode *pDnode, SMgmtWrapper *pWrapper) {
int32_t code = (*pWrapper->func.requiredFp)(&input, &required);
if (!required) {
dDebug("node:%s, does not require startup", pWrapper->name);
- }
-
- if (pWrapper->ntype == DNODE) {
- if (pDnode->rtype != DNODE && pDnode->rtype != NODE_END) {
- required = false;
- dDebug("node:%s, does not require startup in child process", pWrapper->name);
- }
} else {
- if (OnlyInChildProc(pWrapper)) {
- if (pWrapper->ntype != pDnode->rtype) {
- dDebug("node:%s, does not require startup in child process", pWrapper->name);
- required = false;
- }
- }
- }
-
- if (required) {
dDebug("node:%s, required to startup", pWrapper->name);
}
return required;
}
-static int32_t dmInitVars(SDnode *pDnode, EDndNodeType rtype) {
- pDnode->rtype = rtype;
-
- if (tsMultiProcess == 0) {
- pDnode->ptype = DND_PROC_SINGLE;
- dInfo("dnode will run in single-process mode");
- } else if (tsMultiProcess > 1) {
- pDnode->ptype = DND_PROC_TEST;
- dInfo("dnode will run in multi-process test mode");
- } else if (pDnode->rtype == DNODE || pDnode->rtype == NODE_END) {
- pDnode->ptype = DND_PROC_PARENT;
- dInfo("dnode will run in parent-process mode");
- } else {
- pDnode->ptype = DND_PROC_CHILD;
- SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->rtype];
- dInfo("dnode will run in child-process mode, node:%s", dmNodeName(pDnode->rtype));
- }
-
+static int32_t dmInitVars(SDnode *pDnode) {
SDnodeData *pData = &pDnode->data;
pData->dnodeId = 0;
pData->clusterId = 0;
@@ -127,12 +94,12 @@ static void dmClearVars(SDnode *pDnode) {
memset(&pDnode->mutex, 0, sizeof(pDnode->mutex));
}
-int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) {
+int32_t dmInitDnode(SDnode *pDnode) {
dDebug("start to create dnode");
int32_t code = -1;
char path[PATH_MAX + 100] = {0};
- if (dmInitVars(pDnode, rtype) != 0) {
+ if (dmInitVars(pDnode) != 0) {
goto _OVER;
}
@@ -141,20 +108,12 @@ int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) {
pDnode->wrappers[VNODE].func = vmGetMgmtFunc();
pDnode->wrappers[QNODE].func = qmGetMgmtFunc();
pDnode->wrappers[SNODE].func = smGetMgmtFunc();
- pDnode->wrappers[BNODE].func = bmGetMgmtFunc();
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
pWrapper->pDnode = pDnode;
pWrapper->name = dmNodeName(ntype);
pWrapper->ntype = ntype;
- pWrapper->proc.wrapper = pWrapper;
- pWrapper->proc.shm.id = -1;
- pWrapper->proc.pid = -1;
- pWrapper->proc.ptype = pDnode->ptype;
- if (ntype == DNODE) {
- pWrapper->proc.ptype = DND_PROC_SINGLE;
- }
taosThreadRwlockInit(&pWrapper->lock, NULL);
snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name);
@@ -165,11 +124,6 @@ int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) {
}
pWrapper->required = dmRequireNode(pDnode, pWrapper);
-
- if (ntype != DNODE && dmReadShmFile(pWrapper->path, pWrapper->name, pDnode->rtype, &pWrapper->proc.shm) != 0) {
- dError("node:%s, failed to read shm file since %s", pWrapper->name, terrstr());
- goto _OVER;
- }
}
if (dmInitMsgHandle(pDnode) != 0) {
@@ -177,16 +131,14 @@ int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) {
goto _OVER;
}
- if (pDnode->ptype == SINGLE_PROC || (pDnode->ptype & PARENT_PROC)) {
- pDnode->lockfile = dmCheckRunning(tsDataDir);
- if (pDnode->lockfile == NULL) {
- goto _OVER;
- }
+ pDnode->lockfile = dmCheckRunning(tsDataDir);
+ if (pDnode->lockfile == NULL) {
+ goto _OVER;
+ }
- if (dmInitServer(pDnode) != 0) {
- dError("failed to init transport since %s", terrstr());
- goto _OVER;
- }
+ if (dmInitServer(pDnode) != 0) {
+ dError("failed to init transport since %s", terrstr());
+ goto _OVER;
}
if (dmInitClient(pDnode) != 0) {
@@ -249,7 +201,7 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
int32_t code = 0;
taosThreadRwlockRdlock(&pWrapper->lock);
- if (pWrapper->deployed || (InParentProc(pWrapper) && pWrapper->required)) {
+ if (pWrapper->deployed) {
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
// dTrace("node:%s, is marked, ref:%d", pWrapper->name, refCount);
} else {
diff --git a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c
index 1c71fe5e1f..4ab56ed682 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c
@@ -17,18 +17,6 @@
#include "dmMgmt.h"
#include "dmNodes.h"
-#define dmSendLocalRecv(pDnode, mtype, func, pInfo) \
- SRpcMsg rsp = {0}; \
- SRpcMsg req = {.msgType = mtype}; \
- SEpSet epset = {.inUse = 0, .numOfEps = 1}; \
- tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); \
- epset.eps[0].port = tsServerPort; \
- rpcSendRecv(pDnode->trans.clientRpc, &epset, &req, &rsp); \
- if (rsp.code == 0 && rsp.contLen > 0) { \
- func(rsp.pCont, rsp.contLen, pInfo); \
- } \
- rpcFreeCont(rsp.pCont);
-
static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) {
pInfo->protocol = 1;
pInfo->dnode_id = pDnode->data.dnodeId;
@@ -41,7 +29,6 @@ static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
pInfo->has_mnode = pDnode->wrappers[MNODE].required;
pInfo->has_qnode = pDnode->wrappers[QNODE].required;
pInfo->has_snode = pDnode->wrappers[SNODE].required;
- pInfo->has_bnode = pDnode->wrappers[BNODE].required;
tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name));
pInfo->logdir.size = tsLogSpace.size;
tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name));
@@ -60,9 +47,7 @@ static void dmGetMmMonitorInfo(SDnode *pDnode) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[MNODE];
if (dmMarkWrapper(pWrapper) == 0) {
SMonMmInfo mmInfo = {0};
- if (tsMultiProcess) {
- dmSendLocalRecv(pDnode, TDMT_MON_MM_INFO, tDeserializeSMonMmInfo, &mmInfo);
- } else if (pWrapper->pMgmt != NULL) {
+ if (pWrapper->pMgmt != NULL) {
mmGetMonitorInfo(pWrapper->pMgmt, &mmInfo);
}
dmReleaseWrapper(pWrapper);
@@ -75,9 +60,7 @@ static void dmGetVmMonitorInfo(SDnode *pDnode) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[VNODE];
if (dmMarkWrapper(pWrapper) == 0) {
SMonVmInfo vmInfo = {0};
- if (tsMultiProcess) {
- dmSendLocalRecv(pDnode, TDMT_MON_VM_INFO, tDeserializeSMonVmInfo, &vmInfo);
- } else if (pWrapper->pMgmt != NULL) {
+ if (pWrapper->pMgmt != NULL) {
vmGetMonitorInfo(pWrapper->pMgmt, &vmInfo);
}
dmReleaseWrapper(pWrapper);
@@ -90,9 +73,7 @@ static void dmGetQmMonitorInfo(SDnode *pDnode) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[QNODE];
if (dmMarkWrapper(pWrapper) == 0) {
SMonQmInfo qmInfo = {0};
- if (tsMultiProcess) {
- dmSendLocalRecv(pDnode, TDMT_MON_QM_INFO, tDeserializeSMonQmInfo, &qmInfo);
- } else if (pWrapper->pMgmt != NULL) {
+ if (pWrapper->pMgmt != NULL) {
qmGetMonitorInfo(pWrapper->pMgmt, &qmInfo);
}
dmReleaseWrapper(pWrapper);
@@ -105,9 +86,7 @@ static void dmGetSmMonitorInfo(SDnode *pDnode) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[SNODE];
if (dmMarkWrapper(pWrapper) == 0) {
SMonSmInfo smInfo = {0};
- if (tsMultiProcess) {
- dmSendLocalRecv(pDnode, TDMT_MON_SM_INFO, tDeserializeSMonSmInfo, &smInfo);
- } else if (pWrapper->pMgmt != NULL) {
+ if (pWrapper->pMgmt != NULL) {
smGetMonitorInfo(pWrapper->pMgmt, &smInfo);
}
dmReleaseWrapper(pWrapper);
@@ -116,21 +95,6 @@ static void dmGetSmMonitorInfo(SDnode *pDnode) {
}
}
-static void dmGetBmMonitorInfo(SDnode *pDnode) {
- SMgmtWrapper *pWrapper = &pDnode->wrappers[BNODE];
- if (dmMarkWrapper(pWrapper) == 0) {
- SMonBmInfo bmInfo = {0};
- if (tsMultiProcess) {
- dmSendLocalRecv(pDnode, TDMT_MON_BM_INFO, tDeserializeSMonBmInfo, &bmInfo);
- } else if (pWrapper->pMgmt != NULL) {
- bmGetMonitorInfo(pWrapper->pMgmt, &bmInfo);
- }
- dmReleaseWrapper(pWrapper);
- monSetBmInfo(&bmInfo);
- tFreeSMonBmInfo(&bmInfo);
- }
-}
-
void dmSendMonitorReport() {
if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return;
dTrace("send monitor report to %s:%u", tsMonitorFqdn, tsMonitorPort);
@@ -141,7 +105,6 @@ void dmSendMonitorReport() {
dmGetVmMonitorInfo(pDnode);
dmGetQmMonitorInfo(pDnode);
dmGetSmMonitorInfo(pDnode);
- dmGetBmMonitorInfo(pDnode);
monSendReport();
}
@@ -149,9 +112,7 @@ void dmGetVnodeLoads(SMonVloadInfo *pInfo) {
SDnode *pDnode = dmInstance();
SMgmtWrapper *pWrapper = &pDnode->wrappers[VNODE];
if (dmMarkWrapper(pWrapper) == 0) {
- if (tsMultiProcess) {
- dmSendLocalRecv(pDnode, TDMT_MON_VM_LOAD, tDeserializeSMonVloadInfo, pInfo);
- } else if (pWrapper->pMgmt != NULL) {
+ if (pWrapper->pMgmt != NULL) {
vmGetVnodeLoads(pWrapper->pMgmt, pInfo, false);
}
dmReleaseWrapper(pWrapper);
@@ -162,9 +123,7 @@ void dmGetMnodeLoads(SMonMloadInfo *pInfo) {
SDnode *pDnode = dmInstance();
SMgmtWrapper *pWrapper = &pDnode->wrappers[MNODE];
if (dmMarkWrapper(pWrapper) == 0) {
- if (tsMultiProcess) {
- dmSendLocalRecv(pDnode, TDMT_MON_MM_LOAD, tDeserializeSMonMloadInfo, pInfo);
- } else if (pWrapper->pMgmt != NULL) {
+ if (pWrapper->pMgmt != NULL) {
mmGetMnodeLoads(pWrapper->pMgmt, pInfo);
}
dmReleaseWrapper(pWrapper);
@@ -175,9 +134,7 @@ void dmGetQnodeLoads(SQnodeLoad *pInfo) {
SDnode *pDnode = dmInstance();
SMgmtWrapper *pWrapper = &pDnode->wrappers[QNODE];
if (dmMarkWrapper(pWrapper) == 0) {
- if (tsMultiProcess) {
- dmSendLocalRecv(pDnode, TDMT_MON_QM_LOAD, tDeserializeSQnodeLoad, pInfo);
- } else if (pWrapper->pMgmt != NULL) {
+ if (pWrapper->pMgmt != NULL) {
qmGetQnodeLoads(pWrapper->pMgmt, pInfo);
}
dmReleaseWrapper(pWrapper);
diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c
index 99ffd73a7a..6893e486bb 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c
@@ -16,55 +16,6 @@
#define _DEFAULT_SOURCE
#include "dmMgmt.h"
-static int32_t dmCreateShm(SMgmtWrapper *pWrapper) {
- int32_t shmsize = tsMnodeShmSize;
- if (pWrapper->ntype == VNODE) {
- shmsize = tsVnodeShmSize;
- } else if (pWrapper->ntype == QNODE) {
- shmsize = tsQnodeShmSize;
- } else if (pWrapper->ntype == SNODE) {
- shmsize = tsSnodeShmSize;
- } else if (pWrapper->ntype == MNODE) {
- shmsize = tsMnodeShmSize;
- } else if (pWrapper->ntype == BNODE) {
- shmsize = tsBnodeShmSize;
- } else {
- return -1;
- }
-
- if (taosCreateShm(&pWrapper->proc.shm, pWrapper->ntype, shmsize) != 0) {
- terrno = TAOS_SYSTEM_ERROR(terrno);
- dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
- return -1;
- }
-
- dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->proc.shm.id, shmsize);
- return 0;
-}
-
-static int32_t dmNewProc(SMgmtWrapper *pWrapper, EDndNodeType ntype) {
- char tstr[8] = {0};
- char *args[6] = {0};
- snprintf(tstr, sizeof(tstr), "%d", ntype);
- args[1] = "-c";
- args[2] = configDir;
- args[3] = "-n";
- args[4] = tstr;
- args[5] = NULL;
-
- int32_t pid = taosNewProc(args);
- if (pid <= 0) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr());
- return -1;
- }
-
- taosIgnSignal(SIGCHLD);
- pWrapper->proc.pid = pid;
- dInfo("node:%s, continue running in new pid:%d", pWrapper->name, pid);
- return 0;
-}
-
int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
SDnode *pDnode = pWrapper->pDnode;
@@ -77,64 +28,14 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
SMgmtOutputOpt output = {0};
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
- if (pWrapper->ntype == DNODE || InChildProc(pWrapper)) {
- tmsgSetDefault(&input.msgCb);
- }
-
- if (OnlyInSingleProc(pWrapper)) {
- dInfo("node:%s, start to open", pWrapper->name);
- if ((*pWrapper->func.openFp)(&input, &output) != 0) {
- dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
- return -1;
- }
- dInfo("node:%s, has been opened", pWrapper->name);
- pWrapper->deployed = true;
- }
-
- if (InParentProc(pWrapper)) {
- dDebug("node:%s, start to open", pWrapper->name);
- if (dmCreateShm(pWrapper) != 0) {
- return -1;
- }
- if (dmWriteShmFile(pWrapper->path, pWrapper->name, &pWrapper->proc.shm) != 0) {
- return -1;
- }
-
- if (OnlyInParentProc(pWrapper)) {
- if (dmInitProc(pWrapper) != 0) {
- dError("node:%s, failed to init proc since %s", pWrapper->name, terrstr());
- return -1;
- }
- if (pDnode->rtype == NODE_END) {
- dInfo("node:%s, should be started manually in child process", pWrapper->name);
- } else {
- if (dmNewProc(pWrapper, pWrapper->ntype) != 0) {
- return -1;
- }
- }
- if (dmRunProc(&pWrapper->proc) != 0) {
- dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
- return -1;
- }
- }
- dDebug("node:%s, has been opened in parent process", pWrapper->name);
- }
-
- if (InChildProc(pWrapper)) {
- dDebug("node:%s, start to open", pWrapper->name);
- if ((*pWrapper->func.openFp)(&input, &output) != 0) {
- dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
- return -1;
- }
- if (dmInitProc(pWrapper) != 0) {
- return -1;
- }
- if (dmRunProc(&pWrapper->proc) != 0) {
- return -1;
- }
- dDebug("node:%s, has been opened in child process", pWrapper->name);
- pWrapper->deployed = true;
+ dInfo("node:%s, start to open", pWrapper->name);
+ tmsgSetDefault(&input.msgCb);
+ if ((*pWrapper->func.openFp)(&input, &output) != 0) {
+ dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
+ return -1;
}
+ dInfo("node:%s, has been opened", pWrapper->name);
+ pWrapper->deployed = true;
if (output.pMgmt != NULL) {
pWrapper->pMgmt = output.pMgmt;
@@ -145,7 +46,6 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
}
int32_t dmStartNode(SMgmtWrapper *pWrapper) {
- if (OnlyInParentProc(pWrapper)) return 0;
if (pWrapper->func.startFp != NULL) {
dDebug("node:%s, start to start", pWrapper->name);
if ((*pWrapper->func.startFp)(pWrapper->pMgmt) != 0) {
@@ -175,17 +75,6 @@ void dmCloseNode(SMgmtWrapper *pWrapper) {
taosMsleep(10);
}
- if (OnlyInParentProc(pWrapper)) {
- int32_t pid = pWrapper->proc.pid;
- if (pid > 0 && taosProcExist(pid)) {
- dInfo("node:%s, send kill signal to the child pid:%d", pWrapper->name, pid);
- taosKillProc(pid);
- dInfo("node:%s, wait for child pid:%d to stop", pWrapper->name, pid);
- taosWaitProc(pid);
- dInfo("node:%s, child pid:%d is stopped", pWrapper->name, pid);
- }
- }
-
taosThreadRwlockWrlock(&pWrapper->lock);
if (pWrapper->pMgmt != NULL) {
(*pWrapper->func.closeFp)(pWrapper->pMgmt);
@@ -193,10 +82,6 @@ void dmCloseNode(SMgmtWrapper *pWrapper) {
}
taosThreadRwlockUnlock(&pWrapper->lock);
- if (!OnlyInSingleProc(pWrapper)) {
- dmCleanupProc(pWrapper);
- }
-
dInfo("node:%s, has been closed", pWrapper->name);
}
@@ -243,29 +128,8 @@ static void dmCloseNodes(SDnode *pDnode) {
}
}
-static void dmWatchNodes(SDnode *pDnode) {
- if (pDnode->ptype != PARENT_PROC) return;
- if (pDnode->rtype == NODE_END) return;
-
- taosThreadMutexLock(&pDnode->mutex);
- for (EDndNodeType ntype = DNODE + 1; ntype < NODE_END; ++ntype) {
- SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
- SProc *proc = &pWrapper->proc;
-
- if (!pWrapper->required) continue;
- if (!OnlyInParentProc(pWrapper)) continue;
-
- if (proc->pid <= 0 || !taosProcExist(proc->pid)) {
- dError("node:%s, pid:%d is killed and needs to restart", pWrapper->name, proc->pid);
- dmCloseProcRpcHandles(&pWrapper->proc);
- dmNewProc(pWrapper, ntype);
- }
- }
- taosThreadMutexUnlock(&pDnode->mutex);
-}
-
int32_t dmRunDnode(SDnode *pDnode) {
- int count = 0;
+ int32_t count = 0;
if (dmOpenNodes(pDnode) != 0) {
dError("failed to open nodes since %s", terrstr());
return -1;
@@ -275,6 +139,7 @@ int32_t dmRunDnode(SDnode *pDnode) {
dError("failed to start nodes since %s", terrstr());
return -1;
}
+
while (1) {
if (pDnode->stop) {
dInfo("TDengine is about to stop");
@@ -284,8 +149,8 @@ int32_t dmRunDnode(SDnode *pDnode) {
return 0;
}
- dmWatchNodes(pDnode);
if (count == 0) osUpdate();
+
count %= 10;
count++;
taosMsleep(100);
diff --git a/source/dnode/mgmt/node_mgmt/src/dmProc.c b/source/dnode/mgmt/node_mgmt/src/dmProc.c
deleted file mode 100644
index dc07455e6b..0000000000
--- a/source/dnode/mgmt/node_mgmt/src/dmProc.c
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#define _DEFAULT_SOURCE
-#include "dmMgmt.h"
-
-static inline int32_t CEIL8(int32_t v) { return ceil((float)(v) / 8) * 8; }
-
-static int32_t dmInitProcMutex(SProcQueue *queue) {
- TdThreadMutexAttr mattr = {0};
-
- if (taosThreadMutexAttrInit(&mattr) != 0) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to init mutex while init attr since %s", queue->name, terrstr());
- return -1;
- }
-
- if (taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) {
- taosThreadMutexAttrDestroy(&mattr);
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to init mutex while set shared since %s", queue->name, terrstr());
- return -1;
- }
-
- if (taosThreadMutexInit(&queue->mutex, &mattr) != 0) {
- taosThreadMutexAttrDestroy(&mattr);
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to init mutex since %s", queue->name, terrstr());
- return -1;
- }
-
- taosThreadMutexAttrDestroy(&mattr);
- return 0;
-}
-
-static int32_t dmInitProcSem(SProcQueue *queue) {
- if (tsem_init(&queue->sem, 1, 0) != 0) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to init sem since %s", queue->name, terrstr());
- return -1;
- }
-
- return 0;
-}
-
-static SProcQueue *dmInitProcQueue(SProc *proc, char *ptr, int32_t size) {
- SProcQueue *queue = (SProcQueue *)(ptr);
-
- int32_t bufSize = size - CEIL8(sizeof(SProcQueue));
- if (bufSize <= 1024) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return NULL;
- }
-
- if (proc->ptype & DND_PROC_PARENT) {
- memset(ptr, 0, sizeof(SProcQueue));
- if (dmInitProcMutex(queue) != 0) {
- return NULL;
- }
-
- if (dmInitProcSem(queue) != 0) {
- return NULL;
- }
-
- tstrncpy(queue->name, proc->name, sizeof(queue->name));
-
- taosThreadMutexLock(&queue->mutex);
- // queue->head = 0;
- // queue->tail = 0;
- queue->total = bufSize;
- queue->avail = bufSize;
- // queue->items = 0;
- taosThreadMutexUnlock(&queue->mutex);
- }
-
- return queue;
-}
-
-static void dmCleanupProcQueue(SProcQueue *queue) {}
-
-static inline int32_t dmPushToProcQueue(SProc *proc, SProcQueue *queue, SRpcMsg *pMsg, EProcFuncType ftype) {
- const void *pHead = pMsg;
- const void *pBody = pMsg->pCont;
- const int16_t rawHeadLen = sizeof(SRpcMsg);
- const int32_t rawBodyLen = pMsg->contLen;
- const int16_t headLen = CEIL8(rawHeadLen);
- const int32_t bodyLen = CEIL8(rawBodyLen);
- const int32_t fullLen = headLen + bodyLen + 8;
- const int64_t handle = (int64_t)pMsg->info.handle;
-
- if (fullLen > queue->total) {
- terrno = TSDB_CODE_OUT_OF_RANGE;
- return -1;
- }
-
- taosThreadMutexLock(&queue->mutex);
- if (fullLen > queue->avail) {
- taosThreadMutexUnlock(&queue->mutex);
- terrno = TSDB_CODE_OUT_OF_SHM_MEM;
- return -1;
- }
-
- if (ftype == DND_FUNC_REQ && IsReq(pMsg) && pMsg->code == 0 && handle != 0 && pMsg->info.noResp == 0) {
- if (taosHashPut(proc->hash, &handle, sizeof(int64_t), &pMsg->info, sizeof(SRpcConnInfo)) != 0) {
- taosThreadMutexUnlock(&queue->mutex);
- return -1;
- }
- }
-
- const int32_t pos = queue->tail;
- if (queue->tail < queue->total) {
- *(int16_t *)(queue->pBuffer + queue->tail) = rawHeadLen;
- *(int8_t *)(queue->pBuffer + queue->tail + 2) = (int8_t)ftype;
- *(int32_t *)(queue->pBuffer + queue->tail + 4) = rawBodyLen;
- } else {
- *(int16_t *)(queue->pBuffer) = rawHeadLen;
- *(int8_t *)(queue->pBuffer + 2) = (int8_t)ftype;
- *(int32_t *)(queue->pBuffer + 4) = rawBodyLen;
- }
-
- if (queue->tail < queue->head) {
- memcpy(queue->pBuffer + queue->tail + 8, pHead, rawHeadLen);
- if (rawBodyLen > 0) memcpy(queue->pBuffer + queue->tail + 8 + headLen, pBody, rawBodyLen);
- queue->tail = queue->tail + 8 + headLen + bodyLen;
- } else {
- int32_t remain = queue->total - queue->tail;
- if (remain == 0) {
- memcpy(queue->pBuffer + 8, pHead, rawHeadLen);
- if (rawBodyLen > 0) memcpy(queue->pBuffer + 8 + headLen, pBody, rawBodyLen);
- queue->tail = 8 + headLen + bodyLen;
- } else if (remain == 8) {
- memcpy(queue->pBuffer, pHead, rawHeadLen);
- if (rawBodyLen > 0) memcpy(queue->pBuffer + headLen, pBody, rawBodyLen);
- queue->tail = headLen + bodyLen;
- } else if (remain < 8 + headLen) {
- memcpy(queue->pBuffer + queue->tail + 8, pHead, remain - 8);
- memcpy(queue->pBuffer, (char *)pHead + remain - 8, rawHeadLen - (remain - 8));
- if (rawBodyLen > 0) memcpy(queue->pBuffer + headLen - (remain - 8), pBody, rawBodyLen);
- queue->tail = headLen - (remain - 8) + bodyLen;
- } else if (remain < 8 + headLen + bodyLen) {
- memcpy(queue->pBuffer + queue->tail + 8, pHead, rawHeadLen);
- if (rawBodyLen > 0) memcpy(queue->pBuffer + queue->tail + 8 + headLen, pBody, remain - 8 - headLen);
- if (rawBodyLen > 0)
- memcpy(queue->pBuffer, (char *)pBody + remain - 8 - headLen, rawBodyLen - (remain - 8 - headLen));
- queue->tail = bodyLen - (remain - 8 - headLen);
- } else {
- memcpy(queue->pBuffer + queue->tail + 8, pHead, rawHeadLen);
- if (rawBodyLen > 0) memcpy(queue->pBuffer + queue->tail + headLen + 8, pBody, rawBodyLen);
- queue->tail = queue->tail + headLen + bodyLen + 8;
- }
- }
-
- queue->avail -= fullLen;
- queue->items++;
- taosThreadMutexUnlock(&queue->mutex);
- tsem_post(&queue->sem);
-
- dTrace("node:%s, push %s msg:%p type:%d handle:%p len:%d code:0x%x, pos:%d remain:%d", queue->name, dmFuncStr(ftype),
- pMsg, pMsg->msgType, pMsg->info.handle, pMsg->contLen, pMsg->code, pos, queue->items);
- return 0;
-}
-
-static inline int32_t dmPopFromProcQueue(SProcQueue *queue, SRpcMsg **ppMsg, EProcFuncType *pFuncType) {
- tsem_wait(&queue->sem);
-
- taosThreadMutexLock(&queue->mutex);
- if (queue->total - queue->avail <= 0) {
- taosThreadMutexUnlock(&queue->mutex);
- terrno = TSDB_CODE_OUT_OF_SHM_MEM;
- return 0;
- }
-
- int16_t rawHeadLen = 0;
- int8_t ftype = 0;
- int32_t rawBodyLen = 0;
- if (queue->head < queue->total) {
- rawHeadLen = *(int16_t *)(queue->pBuffer + queue->head);
- ftype = *(int8_t *)(queue->pBuffer + queue->head + 2);
- rawBodyLen = *(int32_t *)(queue->pBuffer + queue->head + 4);
- } else {
- rawHeadLen = *(int16_t *)(queue->pBuffer);
- ftype = *(int8_t *)(queue->pBuffer + 2);
- rawBodyLen = *(int32_t *)(queue->pBuffer + 4);
- }
- int16_t headLen = CEIL8(rawHeadLen);
- int32_t bodyLen = CEIL8(rawBodyLen);
-
- void *pHead = taosAllocateQitem(headLen, DEF_QITEM);
- void *pBody = NULL;
- if (bodyLen > 0) pBody = rpcMallocCont(bodyLen);
- if (pHead == NULL || (bodyLen > 0 && pBody == NULL)) {
- taosThreadMutexUnlock(&queue->mutex);
- tsem_post(&queue->sem);
- taosFreeQitem(pHead);
- rpcFreeCont(pBody);
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- const int32_t pos = queue->head;
- if (queue->head < queue->tail) {
- memcpy(pHead, queue->pBuffer + queue->head + 8, headLen);
- if (bodyLen > 0) memcpy(pBody, queue->pBuffer + queue->head + 8 + headLen, bodyLen);
- queue->head = queue->head + 8 + headLen + bodyLen;
- } else {
- int32_t remain = queue->total - queue->head;
- if (remain == 0) {
- memcpy(pHead, queue->pBuffer + 8, headLen);
- if (bodyLen > 0) memcpy(pBody, queue->pBuffer + 8 + headLen, bodyLen);
- queue->head = 8 + headLen + bodyLen;
- } else if (remain == 8) {
- memcpy(pHead, queue->pBuffer, headLen);
- if (bodyLen > 0) memcpy(pBody, queue->pBuffer + headLen, bodyLen);
- queue->head = headLen + bodyLen;
- } else if (remain < 8 + headLen) {
- memcpy(pHead, queue->pBuffer + queue->head + 8, remain - 8);
- memcpy((char *)pHead + remain - 8, queue->pBuffer, headLen - (remain - 8));
- if (bodyLen > 0) memcpy(pBody, queue->pBuffer + headLen - (remain - 8), bodyLen);
- queue->head = headLen - (remain - 8) + bodyLen;
- } else if (remain < 8 + headLen + bodyLen) {
- memcpy(pHead, queue->pBuffer + queue->head + 8, headLen);
- if (bodyLen > 0) memcpy(pBody, queue->pBuffer + queue->head + 8 + headLen, remain - 8 - headLen);
- if (bodyLen > 0) memcpy((char *)pBody + remain - 8 - headLen, queue->pBuffer, bodyLen - (remain - 8 - headLen));
- queue->head = bodyLen - (remain - 8 - headLen);
- } else {
- memcpy(pHead, queue->pBuffer + queue->head + 8, headLen);
- if (bodyLen > 0) memcpy(pBody, queue->pBuffer + queue->head + headLen + 8, bodyLen);
- queue->head = queue->head + headLen + bodyLen + 8;
- }
- }
-
- queue->avail = queue->avail + headLen + bodyLen + 8;
- queue->items--;
- taosThreadMutexUnlock(&queue->mutex);
-
- *ppMsg = pHead;
- (*ppMsg)->pCont = pBody;
- *pFuncType = (EProcFuncType)ftype;
-
- dTrace("node:%s, pop %s msg:%p type:%d handle:%p len:%d code:0x%x, pos:%d remain:%d", queue->name, dmFuncStr(ftype),
- (*ppMsg), (*ppMsg)->msgType, (*ppMsg)->info.handle, (*ppMsg)->contLen, (*ppMsg)->code, pos, queue->items);
- return 1;
-}
-
-int32_t dmInitProc(struct SMgmtWrapper *pWrapper) {
- SProc *proc = &pWrapper->proc;
- if (proc->name != NULL) return 0;
-
- proc->wrapper = pWrapper;
- proc->name = pWrapper->name;
-
- SShm *shm = &proc->shm;
- int32_t cstart = 0;
- int32_t csize = CEIL8(shm->size / 2);
- int32_t pstart = csize;
- int32_t psize = CEIL8(shm->size - pstart);
- if (pstart + psize > shm->size) {
- psize -= 8;
- }
-
- proc->hash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
- proc->cqueue = dmInitProcQueue(proc, (char *)shm->ptr + cstart, csize);
- proc->pqueue = dmInitProcQueue(proc, (char *)shm->ptr + pstart, psize);
- if (proc->cqueue == NULL || proc->pqueue == NULL || proc->hash == NULL) {
- dmCleanupProcQueue(proc->cqueue);
- dmCleanupProcQueue(proc->pqueue);
- taosHashCleanup(proc->hash);
- return -1;
- }
-
- dDebug("node:%s, proc is initialized, cqueue:%p pqueue:%p", proc->name, proc->cqueue, proc->pqueue);
- return 0;
-}
-
-static void *dmConsumChildQueue(void *param) {
- SProc *proc = param;
- SMgmtWrapper *pWrapper = proc->wrapper;
- SProcQueue *queue = proc->cqueue;
- int32_t numOfMsgs = 0;
- int32_t code = 0;
- EProcFuncType ftype = DND_FUNC_REQ;
- SRpcMsg *pMsg = NULL;
-
- dDebug("node:%s, start to consume from cqueue", proc->name);
- do {
- numOfMsgs = dmPopFromProcQueue(queue, &pMsg, &ftype);
- if (numOfMsgs == 0) {
- dDebug("node:%s, get no msg from cqueue and exit thread", proc->name);
- break;
- }
-
- if (numOfMsgs < 0) {
- dError("node:%s, get no msg from cqueue since %s", proc->name, terrstr());
- taosMsleep(1);
- continue;
- }
-
- if (ftype != DND_FUNC_REQ) {
- dError("node:%s, invalid ftype:%d from cqueue", proc->name, ftype);
- rpcFreeCont(pMsg->pCont);
- taosFreeQitem(pMsg);
- continue;
- }
-
- code = dmProcessNodeMsg(pWrapper, pMsg);
- if (code != 0) {
- dError("node:%s, failed to process msg:%p since %s, put into pqueue", proc->name, pMsg, terrstr());
- SRpcMsg rsp = {.code = (terrno != 0 ? terrno : code), .info = pMsg->info};
- dmPutToProcPQueue(proc, &rsp, DND_FUNC_RSP);
- rpcFreeCont(pMsg->pCont);
- taosFreeQitem(pMsg);
- }
- } while (1);
-
- return NULL;
-}
-
-static void *dmConsumParentQueue(void *param) {
- SProc *proc = param;
- SMgmtWrapper *pWrapper = proc->wrapper;
- SProcQueue *queue = proc->pqueue;
- int32_t numOfMsgs = 0;
- int32_t code = 0;
- EProcFuncType ftype = DND_FUNC_REQ;
- SRpcMsg *pMsg = NULL;
-
- dDebug("node:%s, start to consume from pqueue", proc->name);
- do {
- numOfMsgs = dmPopFromProcQueue(queue, &pMsg, &ftype);
- if (numOfMsgs == 0) {
- dDebug("node:%s, get no msg from pqueue and exit thread", proc->name);
- break;
- }
-
- if (numOfMsgs < 0) {
- dError("node:%s, get no msg from pqueue since %s", proc->name, terrstr());
- taosMsleep(1);
- continue;
- }
-
- if (ftype == DND_FUNC_RSP) {
- dmRemoveProcRpcHandle(proc, pMsg->info.handle);
- rpcSendResponse(pMsg);
- } else if (ftype == DND_FUNC_REGIST) {
- rpcRegisterBrokenLinkArg(pMsg);
- } else if (ftype == DND_FUNC_RELEASE) {
- dmRemoveProcRpcHandle(proc, pMsg->info.handle);
- rpcReleaseHandle(&pMsg->info, TAOS_CONN_SERVER);
- } else {
- dError("node:%s, invalid ftype:%d from pqueue", proc->name, ftype);
- rpcFreeCont(pMsg->pCont);
- }
-
- taosFreeQitem(pMsg);
- } while (1);
-
- return NULL;
-}
-
-int32_t dmRunProc(SProc *proc) {
- TdThreadAttr thAttr = {0};
- taosThreadAttrInit(&thAttr);
- taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
-
- if (proc->ptype & DND_PROC_PARENT) {
- if (taosThreadCreate(&proc->pthread, &thAttr, dmConsumParentQueue, proc) != 0) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to create pthread since %s", proc->name, terrstr());
- return -1;
- }
- dDebug("node:%s, thread:%" PRId64 " is created to consume pqueue", proc->name, proc->pthread);
- }
-
- if (proc->ptype & DND_PROC_CHILD) {
- if (taosThreadCreate(&proc->cthread, &thAttr, dmConsumChildQueue, proc) != 0) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to create cthread since %s", proc->name, terrstr());
- return -1;
- }
- dDebug("node:%s, thread:%" PRId64 " is created to consume cqueue", proc->name, proc->cthread);
- }
-
- taosThreadAttrDestroy(&thAttr);
- return 0;
-}
-
-void dmStopProc(SProc *proc) {
- proc->stop = true;
- if (taosCheckPthreadValid(proc->pthread)) {
- dDebug("node:%s, start to join pthread:%" PRId64, proc->name, proc->pthread);
- tsem_post(&proc->pqueue->sem);
- taosThreadJoin(proc->pthread, NULL);
- taosThreadClear(&proc->pthread);
- }
-
- if (taosCheckPthreadValid(proc->cthread)) {
- dDebug("node:%s, start to join cthread:%" PRId64, proc->name, proc->cthread);
- tsem_post(&proc->cqueue->sem);
- taosThreadJoin(proc->cthread, NULL);
- taosThreadClear(&proc->cthread);
- }
-}
-
-void dmCleanupProc(struct SMgmtWrapper *pWrapper) {
- SProc *proc = &pWrapper->proc;
- if (proc->name == NULL) return;
-
- dDebug("node:%s, start to cleanup proc", pWrapper->name);
- dmStopProc(proc);
- dmCleanupProcQueue(proc->cqueue);
- dmCleanupProcQueue(proc->pqueue);
- taosHashCleanup(proc->hash);
- proc->hash = NULL;
- dDebug("node:%s, proc is cleaned up", pWrapper->name);
-}
-
-void dmRemoveProcRpcHandle(SProc *proc, void *handle) {
- int64_t h = (int64_t)handle;
- taosThreadMutexLock(&proc->cqueue->mutex);
- taosHashRemove(proc->hash, &h, sizeof(int64_t));
- taosThreadMutexUnlock(&proc->cqueue->mutex);
-}
-
-void dmCloseProcRpcHandles(SProc *proc) {
- taosThreadMutexLock(&proc->cqueue->mutex);
- SRpcHandleInfo *pInfo = taosHashIterate(proc->hash, NULL);
- while (pInfo != NULL) {
- dError("node:%s, the child process dies and send an offline rsp to handle:%p", proc->name, pInfo->handle);
- SRpcMsg rpcMsg = {.code = TSDB_CODE_NODE_OFFLINE, .info = *pInfo};
- rpcSendResponse(&rpcMsg);
- pInfo = taosHashIterate(proc->hash, pInfo);
- }
- taosHashClear(proc->hash);
- taosThreadMutexUnlock(&proc->cqueue->mutex);
-}
-
-void dmPutToProcPQueue(SProc *proc, SRpcMsg *pMsg, EProcFuncType ftype) {
- int32_t retry = 0;
- while (1) {
- if (dmPushToProcQueue(proc, proc->pqueue, pMsg, ftype) == 0) {
- break;
- }
-
- if (terrno != TSDB_CODE_OUT_OF_SHM_MEM) {
- pMsg->code = terrno;
- if (pMsg->contLen > 0) {
- rpcFreeCont(pMsg->pCont);
- pMsg->pCont = NULL;
- pMsg->contLen = 0;
- }
- dError("node:%s, failed to push %s msg:%p type:%d handle:%p then discard data and return error", proc->name,
- dmFuncStr(ftype), pMsg, pMsg->msgType, pMsg->info.handle);
- } else {
- dError("node:%s, failed to push %s msg:%p type:%d handle:%p len:%d since %s, retry:%d", proc->name,
- dmFuncStr(ftype), pMsg, pMsg->msgType, pMsg->info.handle, pMsg->contLen, terrstr(), retry);
- retry++;
- taosMsleep(retry);
- }
- }
-
- rpcFreeCont(pMsg->pCont);
- pMsg->pCont = NULL;
- pMsg->contLen = 0;
-}
-
-int32_t dmPutToProcCQueue(SProc *proc, SRpcMsg *pMsg, EProcFuncType ftype) {
- int32_t code = dmPushToProcQueue(proc, proc->cqueue, pMsg, ftype);
- if (code == 0) {
- dTrace("msg:%p, is freed after push to cqueue", pMsg);
- rpcFreeCont(pMsg->pCont);
- taosFreeQitem(pMsg);
- }
- return code;
-}
diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c
index 542baaec09..7ad24be258 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c
@@ -17,14 +17,7 @@
#include "dmMgmt.h"
#include "qworker.h"
-static inline void dmSendRsp(SRpcMsg *pMsg) {
- SMgmtWrapper *pWrapper = pMsg->info.wrapper;
- if (InChildProc(pWrapper)) {
- dmPutToProcPQueue(&pWrapper->proc, pMsg, DND_FUNC_RSP);
- } else {
- rpcSendResponse(pMsg);
- }
-}
+static inline void dmSendRsp(SRpcMsg *pMsg) { rpcSendResponse(pMsg); }
static inline void dmBuildMnodeRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) {
SEpSet epSet = {0};
@@ -157,11 +150,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
dGTrace("msg:%p, is created, type:%s handle:%p", pMsg, TMSG_INFO(pRpc->msgType), pMsg->info.handle);
- if (InParentProc(pWrapper)) {
- code = dmPutToProcCQueue(&pWrapper->proc, pMsg, DND_FUNC_REQ);
- } else {
- code = dmProcessNodeMsg(pWrapper, pMsg);
- }
+ code = dmProcessNodeMsg(pWrapper, pMsg);
_OVER:
if (code != 0) {
@@ -233,24 +222,9 @@ static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
}
}
-static inline void dmRegisterBrokenLinkArg(SRpcMsg *pMsg) {
- SMgmtWrapper *pWrapper = pMsg->info.wrapper;
- if (InChildProc(pWrapper)) {
- dmPutToProcPQueue(&pWrapper->proc, pMsg, DND_FUNC_REGIST);
- } else {
- rpcRegisterBrokenLinkArg(pMsg);
- }
-}
+static inline void dmRegisterBrokenLinkArg(SRpcMsg *pMsg) { rpcRegisterBrokenLinkArg(pMsg); }
-static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) {
- SMgmtWrapper *pWrapper = pHandle->wrapper;
- if (InChildProc(pWrapper)) {
- SRpcMsg msg = {.code = type, .info = *pHandle};
- dmPutToProcPQueue(&pWrapper->proc, &msg, DND_FUNC_RELEASE);
- } else {
- rpcReleaseHandle(pHandle, type);
- }
-}
+static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) { rpcReleaseHandle(pHandle, type); }
static bool rpcRfp(int32_t code, tmsg_t msgType) {
if (code == TSDB_CODE_RPC_REDIRECT || code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_NODE_NOT_DEPLOYED ||
diff --git a/source/dnode/mgmt/node_util/CMakeLists.txt b/source/dnode/mgmt/node_util/CMakeLists.txt
index 5d879fdbcf..5c670cbdd3 100644
--- a/source/dnode/mgmt/node_util/CMakeLists.txt
+++ b/source/dnode/mgmt/node_util/CMakeLists.txt
@@ -6,5 +6,5 @@ target_include_directories(
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
target_link_libraries(
- node_util cjson mnode vnode qnode snode bnode wal sync taos_static tfs monitor
+ node_util cjson mnode vnode qnode snode wal sync taos_static tfs monitor
)
\ No newline at end of file
diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h
index f599de384c..8719e988e7 100644
--- a/source/dnode/mgmt/node_util/inc/dmUtil.h
+++ b/source/dnode/mgmt/node_util/inc/dmUtil.h
@@ -68,8 +68,7 @@ typedef enum {
VNODE = 2,
QNODE = 3,
SNODE = 4,
- BNODE = 5,
- NODE_END = 6,
+ NODE_END = 5,
} EDndNodeType;
typedef enum {
@@ -84,20 +83,6 @@ typedef enum {
DND_ENV_CLEANUP,
} EDndEnvStatus;
-typedef enum {
- DND_PROC_SINGLE,
- DND_PROC_CHILD,
- DND_PROC_PARENT,
- DND_PROC_TEST,
-} EDndProcType;
-
-typedef enum {
- DND_FUNC_REQ = 1,
- DND_FUNC_RSP = 2,
- DND_FUNC_REGIST = 3,
- DND_FUNC_RELEASE = 4,
-} EProcFuncType;
-
typedef int32_t (*ProcessCreateNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
typedef int32_t (*ProcessDropNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
typedef void (*SendMonitorReportFp)();
@@ -166,11 +151,7 @@ typedef struct {
// dmUtil.c
const char *dmStatStr(EDndRunStatus stype);
-const char *dmNodeLogName(EDndNodeType ntype);
-const char *dmNodeProcName(EDndNodeType ntype);
const char *dmNodeName(EDndNodeType ntype);
-const char *dmProcStr(EDndProcType ptype);
-const char *dmFuncStr(EProcFuncType etype);
void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId);
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
@@ -178,8 +159,6 @@ void dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
TdFilePtr dmCheckRunning(const char *dataDir);
-int32_t dmReadShmFile(const char *path, const char *name, EDndNodeType runType, SShm *pShm);
-int32_t dmWriteShmFile(const char *path, const char *name, const SShm *pShm);
// dmEps.c
int32_t dmReadEps(SDnodeData *pData);
diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c
index 9ec17a18b5..d387fe4a3f 100644
--- a/source/dnode/mgmt/node_util/src/dmFile.c
+++ b/source/dnode/mgmt/node_util/src/dmFile.c
@@ -148,114 +148,3 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
dDebug("lock file:%s to prevent repeated starts", filepath);
return pFile;
}
-
-int32_t dmReadShmFile(const char *path, const char *name, EDndNodeType runType, SShm *pShm) {
- int32_t code = -1;
- char content[MAXLEN + 1] = {0};
- char file[PATH_MAX] = {0};
- cJSON *root = NULL;
- TdFilePtr pFile = NULL;
-
- snprintf(file, sizeof(file), "%s%sshmfile", path, TD_DIRSEP);
- pFile = taosOpenFile(file, TD_FILE_READ);
- if (pFile == NULL) {
- code = 0;
- goto _OVER;
- }
-
- if (taosReadFile(pFile, content, MAXLEN) > 0) {
- root = cJSON_Parse(content);
- if (root == NULL) {
- terrno = TSDB_CODE_INVALID_JSON_FORMAT;
- dError("node:%s, failed to read %s since invalid json format", name, file);
- goto _OVER;
- }
-
- cJSON *shmid = cJSON_GetObjectItem(root, "shmid");
- if (shmid && shmid->type == cJSON_Number) {
- pShm->id = shmid->valueint;
- }
-
- cJSON *shmsize = cJSON_GetObjectItem(root, "shmsize");
- if (shmsize && shmsize->type == cJSON_Number) {
- pShm->size = shmsize->valueint;
- }
- }
-
- if (!tsMultiProcess || runType == DNODE || runType == NODE_END) {
- if (pShm->id >= 0) {
- dDebug("node:%s, shmid:%d, is closed, size:%d", name, pShm->id, pShm->size);
- taosDropShm(pShm);
- }
- } else {
- if (taosAttachShm(pShm) != 0) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("shmid:%d, failed to attach shm since %s", pShm->id, terrstr());
- goto _OVER;
- }
- dInfo("node:%s, shmid:%d is attached, size:%d", name, pShm->id, pShm->size);
- }
-
- dDebug("node:%s, successed to load %s", name, file);
- code = 0;
-
-_OVER:
- if (root != NULL) cJSON_Delete(root);
- if (pFile != NULL) taosCloseFile(&pFile);
-
- return code;
-}
-
-int32_t dmWriteShmFile(const char *path, const char *name, const SShm *pShm) {
- int32_t code = -1;
- int32_t len = 0;
- char content[MAXLEN + 1] = {0};
- char file[PATH_MAX] = {0};
- char realfile[PATH_MAX] = {0};
- TdFilePtr pFile = NULL;
-
- snprintf(file, sizeof(file), "%s%sshmfile.bak", path, TD_DIRSEP);
- snprintf(realfile, sizeof(realfile), "%s%sshmfile", path, TD_DIRSEP);
-
- pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
- if (pFile == NULL) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to open file:%s since %s", name, file, terrstr());
- goto _OVER;
- }
-
- len += snprintf(content + len, MAXLEN - len, "{\n");
- len += snprintf(content + len, MAXLEN - len, " \"shmid\":%d,\n", pShm->id);
- len += snprintf(content + len, MAXLEN - len, " \"shmsize\":%d\n", pShm->size);
- len += snprintf(content + len, MAXLEN - len, "}\n");
-
- if (taosWriteFile(pFile, content, len) != len) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to write file:%s since %s", name, file, terrstr());
- goto _OVER;
- }
-
- if (taosFsyncFile(pFile) != 0) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to fsync file:%s since %s", name, file, terrstr());
- goto _OVER;
- }
-
- taosCloseFile(&pFile);
-
- if (taosRenameFile(file, realfile) != 0) {
- terrno = TAOS_SYSTEM_ERROR(errno);
- dError("node:%s, failed to rename %s to %s since %s", name, file, realfile, terrstr());
- return -1;
- }
-
- dInfo("node:%s, successed to write %s", name, realfile);
- code = 0;
-
-_OVER:
- if (pFile != NULL) {
- taosCloseFile(&pFile);
- }
-
- return code;
-}
diff --git a/source/dnode/mgmt/node_util/src/dmUtil.c b/source/dnode/mgmt/node_util/src/dmUtil.c
index 832e15a1e0..80bb8debd2 100644
--- a/source/dnode/mgmt/node_util/src/dmUtil.c
+++ b/source/dnode/mgmt/node_util/src/dmUtil.c
@@ -29,40 +29,6 @@ const char *dmStatStr(EDndRunStatus stype) {
}
}
-const char *dmNodeLogName(EDndNodeType ntype) {
- switch (ntype) {
- case VNODE:
- return "vnode";
- case QNODE:
- return "qnode";
- case SNODE:
- return "snode";
- case MNODE:
- return "mnode";
- case BNODE:
- return "bnode";
- default:
- return "taosd";
- }
-}
-
-const char *dmNodeProcName(EDndNodeType ntype) {
- switch (ntype) {
- case VNODE:
- return "taosv";
- case QNODE:
- return "taosq";
- case SNODE:
- return "taoss";
- case MNODE:
- return "taosm";
- case BNODE:
- return "taosb";
- default:
- return "taosd";
- }
-}
-
const char *dmNodeName(EDndNodeType ntype) {
switch (ntype) {
case VNODE:
@@ -73,43 +39,11 @@ const char *dmNodeName(EDndNodeType ntype) {
return "snode";
case MNODE:
return "mnode";
- case BNODE:
- return "bnode";
default:
return "dnode";
}
}
-const char *dmProcStr(EDndProcType etype) {
- switch (etype) {
- case DND_PROC_SINGLE:
- return "start";
- case DND_PROC_CHILD:
- return "stop";
- case DND_PROC_PARENT:
- return "child";
- case DND_PROC_TEST:
- return "test";
- default:
- return "UNKNOWN";
- }
-}
-
-const char *dmFuncStr(EProcFuncType etype) {
- switch (etype) {
- case DND_FUNC_REQ:
- return "req";
- case DND_FUNC_RSP:
- return "rsp";
- case DND_FUNC_REGIST:
- return "regist";
- case DND_FUNC_RELEASE:
- return "release";
- default:
- return "UNKNOWN";
- }
-}
-
void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId) {
SMgmtHandle handle = {
.msgType = msgType,
diff --git a/source/dnode/mgmt/test/CMakeLists.txt b/source/dnode/mgmt/test/CMakeLists.txt
index 6b1919bf18..6709a2aa5e 100644
--- a/source/dnode/mgmt/test/CMakeLists.txt
+++ b/source/dnode/mgmt/test/CMakeLists.txt
@@ -1,7 +1,6 @@
if(${BUILD_TEST})
enable_testing()
add_subdirectory(qnode)
- add_subdirectory(bnode)
add_subdirectory(snode)
#add_subdirectory(mnode)
add_subdirectory(vnode)
diff --git a/source/dnode/mgmt/test/bnode/CMakeLists.txt b/source/dnode/mgmt/test/bnode/CMakeLists.txt
deleted file mode 100644
index 7108d3adb9..0000000000
--- a/source/dnode/mgmt/test/bnode/CMakeLists.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-aux_source_directory(. DND_BNODE_TEST_SRC)
-add_executable(dbnodeTest ${DND_BNODE_TEST_SRC})
-target_link_libraries(
- dbnodeTest sut
-)
-
-add_test(
- NAME dbnodeTest
- COMMAND dbnodeTest
-)
diff --git a/source/dnode/mgmt/test/bnode/dbnode.cpp b/source/dnode/mgmt/test/bnode/dbnode.cpp
deleted file mode 100644
index 24d8c594ce..0000000000
--- a/source/dnode/mgmt/test/bnode/dbnode.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- * @file dbnode.cpp
- * @author slguan (slguan@taosdata.com)
- * @brief DNODE module bnode tests
- * @version 1.0
- * @date 2022-01-05
- *
- * @copyright Copyright (c) 2022
- *
- */
-
-#include "sut.h"
-
-class DndTestBnode : public ::testing::Test {
- protected:
- static void SetUpTestSuite() {
- test.Init(TD_TMP_DIR_PATH "dbnodeTest", 9112);
- taosMsleep(1100);
- }
- static void TearDownTestSuite() { test.Cleanup(); }
- static Testbase test;
-
- public:
- void SetUp() override {}
- void TearDown() override {}
-};
-
-Testbase DndTestBnode::test;
-
-TEST_F(DndTestBnode, 01_Create_Bnode) {
- {
- SDCreateBnodeReq createReq = {0};
- createReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
- }
-
- {
- SDCreateBnodeReq createReq = {0};
- createReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, 0);
- }
-
- {
- SDCreateBnodeReq createReq = {0};
- createReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
- }
-
- // test.Restart();
-
- {
- SDCreateBnodeReq createReq = {0};
- createReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
- }
-}
-
-TEST_F(DndTestBnode, 02_Drop_Bnode) {
- {
- SDDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
- }
-
- {
- SDDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, 0);
- }
-
- {
- SDDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED);
- }
-
- // test.Restart();
-
- {
- SDDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED);
- }
-
- {
- SDCreateBnodeReq createReq = {0};
- createReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, 0);
- }
-}
diff --git a/source/dnode/mgmt/test/mnode/dmnode.cpp b/source/dnode/mgmt/test/mnode/dmnode.cpp
index 857f58befc..7b7eb97216 100644
--- a/source/dnode/mgmt/test/mnode/dmnode.cpp
+++ b/source/dnode/mgmt/test/mnode/dmnode.cpp
@@ -139,9 +139,9 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) {
SDDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -152,9 +152,9 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) {
SDDropMnodeReq dropReq = {0};
dropReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -165,9 +165,9 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) {
SDDropMnodeReq dropReq = {0};
dropReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
diff --git a/source/dnode/mgmt/test/qnode/dqnode.cpp b/source/dnode/mgmt/test/qnode/dqnode.cpp
index ef51be47a6..a2c6a2c28c 100644
--- a/source/dnode/mgmt/test/qnode/dqnode.cpp
+++ b/source/dnode/mgmt/test/qnode/dqnode.cpp
@@ -30,9 +30,9 @@ TEST_F(DndTestQnode, 01_Create_Qnode) {
SDCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -43,9 +43,9 @@ TEST_F(DndTestQnode, 01_Create_Qnode) {
SDCreateQnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -56,9 +56,9 @@ TEST_F(DndTestQnode, 01_Create_Qnode) {
SDCreateQnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -71,9 +71,9 @@ TEST_F(DndTestQnode, 01_Create_Qnode) {
SDCreateQnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -87,9 +87,9 @@ TEST_F(DndTestQnode, 02_Drop_Qnode) {
SDDropQnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -101,9 +101,9 @@ TEST_F(DndTestQnode, 02_Drop_Qnode) {
SDDropQnodeReq dropReq = {0};
dropReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -114,9 +114,9 @@ TEST_F(DndTestQnode, 02_Drop_Qnode) {
SDDropQnodeReq dropReq = {0};
dropReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -129,9 +129,9 @@ TEST_F(DndTestQnode, 02_Drop_Qnode) {
SDDropQnodeReq dropReq = {0};
dropReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -142,9 +142,9 @@ TEST_F(DndTestQnode, 02_Drop_Qnode) {
SDCreateQnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
diff --git a/source/dnode/mgmt/test/snode/dsnode.cpp b/source/dnode/mgmt/test/snode/dsnode.cpp
index 9ae0fbdc54..e3ad65d831 100644
--- a/source/dnode/mgmt/test/snode/dsnode.cpp
+++ b/source/dnode/mgmt/test/snode/dsnode.cpp
@@ -30,9 +30,9 @@ TEST_F(DndTestSnode, 01_Create_Snode) {
SDCreateSnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -43,9 +43,9 @@ TEST_F(DndTestSnode, 01_Create_Snode) {
SDCreateSnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -56,9 +56,9 @@ TEST_F(DndTestSnode, 01_Create_Snode) {
SDCreateSnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -71,9 +71,9 @@ TEST_F(DndTestSnode, 01_Create_Snode) {
SDCreateSnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -87,9 +87,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) {
SDDropSnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -101,9 +101,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) {
SDDropSnodeReq dropReq = {0};
dropReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -114,9 +114,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) {
SDDropSnodeReq dropReq = {0};
dropReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -129,9 +129,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) {
SDDropSnodeReq dropReq = {0};
dropReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -142,9 +142,9 @@ TEST_F(DndTestSnode, 01_Drop_Snode) {
SDCreateSnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp
index de35b06b05..98c59a1614 100644
--- a/source/dnode/mgmt/test/sut/src/server.cpp
+++ b/source/dnode/mgmt/test/sut/src/server.cpp
@@ -16,7 +16,7 @@
#include "sut.h"
void* serverLoop(void* param) {
- dmInit(0);
+ dmInit();
dmRun();
dmCleanup();
return NULL;
diff --git a/source/dnode/mnode/impl/inc/mndBnode.h b/source/dnode/mnode/impl/inc/mndBnode.h
deleted file mode 100644
index cefc0b1859..0000000000
--- a/source/dnode/mnode/impl/inc/mndBnode.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef _TD_MND_BNODE_H_
-#define _TD_MND_BNODE_H_
-
-#include "mndInt.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int32_t mndInitBnode(SMnode *pMnode);
-void mndCleanupBnode(SMnode *pMnode);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_TD_MND_BNODE_H_*/
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index 9cc920de04..48eea7daea 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -43,8 +43,6 @@ typedef enum {
MND_OPER_CREATE_USER,
MND_OPER_DROP_USER,
MND_OPER_ALTER_USER,
- MND_OPER_CREATE_BNODE,
- MND_OPER_DROP_BNODE,
MND_OPER_CREATE_DNODE,
MND_OPER_DROP_DNODE,
MND_OPER_CONFIG_DNODE,
@@ -226,13 +224,6 @@ typedef struct {
SDnodeObj* pDnode;
} SSnodeObj;
-typedef struct {
- int32_t id;
- int64_t createdTime;
- int64_t updateTime;
- SDnodeObj* pDnode;
-} SBnodeObj;
-
typedef struct {
int32_t maxUsers;
int32_t maxDbs;
diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c
deleted file mode 100644
index 06209d89c7..0000000000
--- a/source/dnode/mnode/impl/src/mndBnode.c
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#define _DEFAULT_SOURCE
-#include "mndBnode.h"
-#include "mndDnode.h"
-#include "mndPrivilege.h"
-#include "mndShow.h"
-#include "mndTrans.h"
-#include "mndUser.h"
-
-#define BNODE_VER_NUMBER 1
-#define BNODE_RESERVE_SIZE 64
-
-static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj);
-static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw);
-static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj);
-static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew);
-static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj);
-static int32_t mndProcessCreateBnodeReq(SRpcMsg *pReq);
-static int32_t mndProcessDropBnodeReq(SRpcMsg *pReq);
-static int32_t mndRetrieveBnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
-static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter);
-
-int32_t mndInitBnode(SMnode *pMnode) {
- SSdbTable table = {
- .sdbType = SDB_BNODE,
- .keyType = SDB_KEY_INT32,
- .encodeFp = (SdbEncodeFp)mndBnodeActionEncode,
- .decodeFp = (SdbDecodeFp)mndBnodeActionDecode,
- .insertFp = (SdbInsertFp)mndBnodeActionInsert,
- .updateFp = (SdbUpdateFp)mndBnodeActionUpdate,
- .deleteFp = (SdbDeleteFp)mndBnodeActionDelete,
- };
-
- mndSetMsgHandle(pMnode, TDMT_MND_CREATE_BNODE, mndProcessCreateBnodeReq);
- mndSetMsgHandle(pMnode, TDMT_MND_DROP_BNODE, mndProcessDropBnodeReq);
- mndSetMsgHandle(pMnode, TDMT_DND_CREATE_BNODE_RSP, mndTransProcessRsp);
- mndSetMsgHandle(pMnode, TDMT_DND_DROP_BNODE_RSP, mndTransProcessRsp);
-
- mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndRetrieveBnodes);
- mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndCancelGetNextBnode);
-
- return sdbSetTable(pMnode->pSdb, table);
-}
-
-void mndCleanupBnode(SMnode *pMnode) {}
-
-static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t bnodeId) {
- SBnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_BNODE, &bnodeId);
- if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
- terrno = TSDB_CODE_MND_BNODE_NOT_EXIST;
- }
- return pObj;
-}
-
-static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) {
- SSdb *pSdb = pMnode->pSdb;
- sdbRelease(pSdb, pObj);
-}
-
-static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
-
- SSdbRaw *pRaw = sdbAllocRaw(SDB_BNODE, BNODE_VER_NUMBER, sizeof(SBnodeObj) + BNODE_RESERVE_SIZE);
- if (pRaw == NULL) goto _OVER;
-
- int32_t dataPos = 0;
- SDB_SET_INT32(pRaw, dataPos, pObj->id, _OVER)
- SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, _OVER)
- SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, _OVER)
- SDB_SET_RESERVE(pRaw, dataPos, BNODE_RESERVE_SIZE, _OVER)
-
- terrno = 0;
-
-_OVER:
- if (terrno != 0) {
- mError("bnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr());
- sdbFreeRaw(pRaw);
- return NULL;
- }
-
- mTrace("bnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj);
- return pRaw;
-}
-
-static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
-
- int8_t sver = 0;
- if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
-
- if (sver != BNODE_VER_NUMBER) {
- terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
- goto _OVER;
- }
-
- SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj));
- if (pRow == NULL) goto _OVER;
-
- SBnodeObj *pObj = sdbGetRowObj(pRow);
- if (pObj == NULL) goto _OVER;
-
- int32_t dataPos = 0;
- SDB_GET_INT32(pRaw, dataPos, &pObj->id, _OVER)
- SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, _OVER)
- SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, _OVER)
- SDB_GET_RESERVE(pRaw, dataPos, BNODE_RESERVE_SIZE, _OVER)
-
- terrno = 0;
-
-_OVER:
- if (terrno != 0) {
- mError("bnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr());
- taosMemoryFreeClear(pRow);
- return NULL;
- }
-
- mTrace("bnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj);
- return pRow;
-}
-
-static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) {
- mTrace("bnode:%d, perform insert action, row:%p", pObj->id, pObj);
- pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
- if (pObj->pDnode == NULL) {
- terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
- mError("bnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
- return -1;
- }
-
- return 0;
-}
-
-static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) {
- mTrace("bnode:%d, perform delete action, row:%p", pObj->id, pObj);
- if (pObj->pDnode != NULL) {
- sdbRelease(pSdb, pObj->pDnode);
- pObj->pDnode = NULL;
- }
-
- return 0;
-}
-
-static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew) {
- mTrace("bnode:%d, perform update action, old row:%p new row:%p", pOld->id, pOld, pNew);
- pOld->updateTime = pNew->updateTime;
- return 0;
-}
-
-static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) {
- SSdbRaw *pRedoRaw = mndBnodeActionEncode(pObj);
- if (pRedoRaw == NULL) return -1;
- if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
- if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
- return 0;
-}
-
-static int32_t mndSetCreateBnodeUndoLogs(STrans *pTrans, SBnodeObj *pObj) {
- SSdbRaw *pUndoRaw = mndBnodeActionEncode(pObj);
- if (pUndoRaw == NULL) return -1;
- if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
- if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
- return 0;
-}
-
-static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
- SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj);
- if (pCommitRaw == NULL) return -1;
- if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
- if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
- return 0;
-}
-
-static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
- SDCreateBnodeReq createReq = {0};
- createReq.dnodeId = pDnode->id;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void *pReq = taosMemoryMalloc(contLen);
- if (pReq == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- STransAction action = {0};
- action.epSet = mndGetDnodeEpset(pDnode);
- action.pCont = pReq;
- action.contLen = contLen;
- action.msgType = TDMT_DND_CREATE_BNODE;
- action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
-
- if (mndTransAppendRedoAction(pTrans, &action) != 0) {
- taosMemoryFree(pReq);
- return -1;
- }
-
- return 0;
-}
-
-static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
- SDDropBnodeReq dropReq = {0};
- dropReq.dnodeId = pDnode->id;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void *pReq = taosMemoryMalloc(contLen);
- if (pReq == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- STransAction action = {0};
- action.epSet = mndGetDnodeEpset(pDnode);
- action.pCont = pReq;
- action.contLen = contLen;
- action.msgType = TDMT_DND_DROP_BNODE;
- action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
-
- if (mndTransAppendUndoAction(pTrans, &action) != 0) {
- taosMemoryFree(pReq);
- return -1;
- }
-
- return 0;
-}
-
-static int32_t mndCreateBnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) {
- int32_t code = -1;
-
- SBnodeObj bnodeObj = {0};
- bnodeObj.id = pDnode->id;
- bnodeObj.createdTime = taosGetTimestampMs();
- bnodeObj.updateTime = bnodeObj.createdTime;
-
- STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-bnode");
- if (pTrans == NULL) goto _OVER;
-
- mInfo("trans:%d, used to create bnode:%d", pTrans->id, pCreate->dnodeId);
- if (mndSetCreateBnodeRedoLogs(pTrans, &bnodeObj) != 0) goto _OVER;
- if (mndSetCreateBnodeUndoLogs(pTrans, &bnodeObj) != 0) goto _OVER;
- if (mndSetCreateBnodeCommitLogs(pTrans, &bnodeObj) != 0) goto _OVER;
- if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &bnodeObj) != 0) goto _OVER;
- if (mndSetCreateBnodeUndoActions(pTrans, pDnode, &bnodeObj) != 0) goto _OVER;
- if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
-
- code = 0;
-
-_OVER:
- mndTransDrop(pTrans);
- return code;
-}
-
-static int32_t mndProcessCreateBnodeReq(SRpcMsg *pReq) {
- SMnode *pMnode = pReq->info.node;
- int32_t code = -1;
- SBnodeObj *pObj = NULL;
- SDnodeObj *pDnode = NULL;
- SMCreateBnodeReq createReq = {0};
-
- if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- goto _OVER;
- }
-
- mInfo("bnode:%d, start to create", createReq.dnodeId);
- if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_BNODE) != 0) {
- goto _OVER;
- }
-
- pObj = mndAcquireBnode(pMnode, createReq.dnodeId);
- if (pObj != NULL) {
- terrno = TSDB_CODE_MND_BNODE_ALREADY_EXIST;
- goto _OVER;
- } else if (terrno != TSDB_CODE_MND_BNODE_NOT_EXIST) {
- goto _OVER;
- }
-
- pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
- if (pDnode == NULL) {
- terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
- goto _OVER;
- }
-
- code = mndCreateBnode(pMnode, pReq, pDnode, &createReq);
- if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
-
-_OVER:
- if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
- mError("bnode:%d, failed to create since %s", createReq.dnodeId, terrstr());
- }
-
- mndReleaseBnode(pMnode, pObj);
- mndReleaseDnode(pMnode, pDnode);
- return code;
-}
-
-static int32_t mndSetDropBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) {
- SSdbRaw *pRedoRaw = mndBnodeActionEncode(pObj);
- if (pRedoRaw == NULL) return -1;
- if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
- if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
- return 0;
-}
-
-static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
- SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj);
- if (pCommitRaw == NULL) return -1;
- if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
- if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
- return 0;
-}
-
-static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
- SDDropBnodeReq dropReq = {0};
- dropReq.dnodeId = pDnode->id;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void *pReq = taosMemoryMalloc(contLen);
- if (pReq == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- STransAction action = {0};
- action.epSet = mndGetDnodeEpset(pDnode);
- action.pCont = pReq;
- action.contLen = contLen;
- action.msgType = TDMT_DND_DROP_BNODE;
- action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
-
- if (mndTransAppendRedoAction(pTrans, &action) != 0) {
- taosMemoryFree(pReq);
- return -1;
- }
-
- return 0;
-}
-
-static int32_t mndDropBnode(SMnode *pMnode, SRpcMsg *pReq, SBnodeObj *pObj) {
- int32_t code = -1;
-
- STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-bnode");
- if (pTrans == NULL) goto _OVER;
-
- mInfo("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id);
- if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) goto _OVER;
- if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) goto _OVER;
- if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto _OVER;
- if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
-
- code = 0;
-
-_OVER:
- mndTransDrop(pTrans);
- return code;
-}
-
-static int32_t mndProcessDropBnodeReq(SRpcMsg *pReq) {
- SMnode *pMnode = pReq->info.node;
- int32_t code = -1;
- SBnodeObj *pObj = NULL;
- SMDropBnodeReq dropReq = {0};
-
- if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- goto _OVER;
- }
-
- mInfo("bnode:%d, start to drop", dropReq.dnodeId);
- if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_BNODE) != 0) {
- goto _OVER;
- }
-
- if (dropReq.dnodeId <= 0) {
- terrno = TSDB_CODE_INVALID_MSG;
- goto _OVER;
- }
-
- pObj = mndAcquireBnode(pMnode, dropReq.dnodeId);
- if (pObj == NULL) {
- goto _OVER;
- }
-
- code = mndDropBnode(pMnode, pReq, pObj);
- if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
-
-_OVER:
- if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
- mError("bnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
- }
-
- mndReleaseBnode(pMnode, pObj);
- return code;
-}
-
-static int32_t mndRetrieveBnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
- SMnode *pMnode = pReq->info.node;
- SSdb *pSdb = pMnode->pSdb;
- int32_t numOfRows = 0;
- int32_t cols = 0;
- SBnodeObj *pObj = NULL;
-
- while (numOfRows < rows) {
- pShow->pIter = sdbFetch(pSdb, SDB_BNODE, pShow->pIter, (void **)&pObj);
- if (pShow->pIter == NULL) break;
-
- cols = 0;
- SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false);
-
- char buf[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
- STR_WITH_MAXSIZE_TO_VARSTR(buf, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
-
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- colDataAppend(pColInfo, numOfRows, buf, false);
-
- pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
- colDataAppend(pColInfo, numOfRows, (const char *)&pObj->createdTime, false);
-
- numOfRows++;
- sdbRelease(pSdb, pObj);
- }
-
- pShow->numOfRows += numOfRows;
-
- return numOfRows;
-}
-
-static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter) {
- SSdb *pSdb = pMnode->pSdb;
- sdbCancelFetch(pSdb, pIter);
-}
diff --git a/source/dnode/mnode/impl/src/mndDump.c b/source/dnode/mnode/impl/src/mndDump.c
index c1c7581a7e..7d0f5742f8 100644
--- a/source/dnode/mnode/impl/src/mndDump.c
+++ b/source/dnode/mnode/impl/src/mndDump.c
@@ -447,10 +447,6 @@ void dumpDnode(SSdb *pSdb, SJson *json) {
}
}
-void dumpBnode(SSdb *pSdb, SJson *json) {
- // not implemented yet
-}
-
void dumpSnode(SSdb *pSdb, SJson *json) {
void *pIter = NULL;
SJson *items = tjsonAddArrayToObject(json, "snodes");
@@ -616,7 +612,6 @@ void mndDumpSdb() {
dumpAuth(pSdb, json);
dumpUser(pSdb, json);
dumpDnode(pSdb, json);
- dumpBnode(pSdb, json);
dumpSnode(pSdb, json);
dumpQnode(pSdb, json);
dumpMnode(pSdb, json);
diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c
index 8314601df3..4eb2e2978b 100644
--- a/source/dnode/mnode/impl/src/mndMain.c
+++ b/source/dnode/mnode/impl/src/mndMain.c
@@ -15,7 +15,6 @@
#define _DEFAULT_SOURCE
#include "mndAcct.h"
-#include "mndBnode.h"
#include "mndCluster.h"
#include "mndConsumer.h"
#include "mndDb.h"
@@ -296,7 +295,6 @@ static int32_t mndInitSteps(SMnode *pMnode) {
if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1;
if (mndAllocStep(pMnode, "mnode-qnode", mndInitQnode, mndCleanupQnode) != 0) return -1;
if (mndAllocStep(pMnode, "mnode-snode", mndInitSnode, mndCleanupSnode) != 0) return -1;
- if (mndAllocStep(pMnode, "mnode-bnode", mndInitBnode, mndCleanupBnode) != 0) return -1;
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
if (mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant) != 0) return -1;
diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c
index f25d436aee..f6ea81c565 100644
--- a/source/dnode/mnode/impl/src/mndMnode.c
+++ b/source/dnode/mnode/impl/src/mndMnode.c
@@ -324,9 +324,9 @@ static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pA
}
static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDropReq, SEpSet *pDroprEpSet) {
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, pDropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, pDropReq);
void *pReq = taosMemoryMalloc(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, pDropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq);
STransAction action = {
.epSet = *pDroprEpSet,
@@ -410,7 +410,7 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
SDnodeObj *pDnode = NULL;
SMCreateMnodeReq createReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
}
@@ -533,7 +533,7 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
SMnodeObj *pObj = NULL;
SMDropMnodeReq dropReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
}
@@ -745,6 +745,7 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
mInfo("vgId:1, mnode sync not reconfig since readyMnodes:%d updatingMnodes:%d", readyMnodes, updatingMnodes);
return;
}
+ // ASSERT(0);
if (cfg.myIndex == -1) {
#if 1
diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c
index d48a446e20..70f9b35312 100644
--- a/source/dnode/mnode/impl/src/mndQnode.c
+++ b/source/dnode/mnode/impl/src/mndQnode.c
@@ -190,13 +190,13 @@ static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S
SDCreateQnodeReq createReq = {0};
createReq.dnodeId = pDnode->id;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
STransAction action = {0};
action.epSet = mndGetDnodeEpset(pDnode);
@@ -217,13 +217,13 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
SDDropQnodeReq dropReq = {0};
dropReq.dnodeId = pDnode->id;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
STransAction action = {0};
action.epSet = mndGetDnodeEpset(pDnode);
@@ -273,7 +273,7 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
SDnodeObj *pDnode = NULL;
SMCreateQnodeReq createReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
}
@@ -330,13 +330,13 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn
SDDropQnodeReq dropReq = {0};
dropReq.dnodeId = pDnode->id;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
STransAction action = {0};
action.epSet = mndGetDnodeEpset(pDnode);
@@ -384,7 +384,7 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
SQnodeObj *pObj = NULL;
SMDropQnodeReq dropReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
}
diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c
index 2e01fadbae..3e4c8005b4 100644
--- a/source/dnode/mnode/impl/src/mndQuery.c
+++ b/source/dnode/mnode/impl/src/mndQuery.c
@@ -90,14 +90,39 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
}
for (int32_t i = 0; i < msgNum; ++i) {
+ if (offset >= pMsg->contLen) {
+ mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
+ terrno = TSDB_CODE_MSG_NOT_PROCESSED;
+ taosArrayDestroy(batchRsp);
+ return -1;
+ }
+
req.msgIdx = ntohl(*(int32_t *)((char *)pMsg->pCont + offset));
offset += sizeof(req.msgIdx);
+ if (offset >= pMsg->contLen) {
+ mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
+ terrno = TSDB_CODE_MSG_NOT_PROCESSED;
+ taosArrayDestroy(batchRsp);
+ return -1;
+ }
req.msgType = ntohl(*(int32_t *)((char *)pMsg->pCont + offset));
offset += sizeof(req.msgType);
+ if (offset >= pMsg->contLen) {
+ mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
+ terrno = TSDB_CODE_MSG_NOT_PROCESSED;
+ taosArrayDestroy(batchRsp);
+ return -1;
+ }
req.msgLen = ntohl(*(int32_t *)((char *)pMsg->pCont + offset));
offset += sizeof(req.msgLen);
+ if (offset >= pMsg->contLen) {
+ mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
+ terrno = TSDB_CODE_MSG_NOT_PROCESSED;
+ taosArrayDestroy(batchRsp);
+ return -1;
+ }
req.msg = (char *)pMsg->pCont + offset;
offset += req.msgLen;
diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c
index 5a998dfe98..8b4cacf8d6 100644
--- a/source/dnode/mnode/impl/src/mndShow.c
+++ b/source/dnode/mnode/impl/src/mndShow.c
@@ -60,8 +60,6 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
type = TSDB_MGMT_TABLE_MODULE;
} else if (strncasecmp(name, TSDB_INS_TABLE_QNODES, len) == 0) {
type = TSDB_MGMT_TABLE_QNODE;
- } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, len) == 0) {
- type = TSDB_MGMT_TABLE_BNODE;
} else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
type = TSDB_MGMT_TABLE_SNODE;
} else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c
index 916e8d0c44..8127d5912e 100644
--- a/source/dnode/mnode/impl/src/mndSnode.c
+++ b/source/dnode/mnode/impl/src/mndSnode.c
@@ -195,13 +195,13 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S
SDCreateSnodeReq createReq = {0};
createReq.dnodeId = pDnode->id;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
STransAction action = {0};
action.epSet = mndGetDnodeEpset(pDnode);
@@ -222,13 +222,13 @@ static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
SDDropSnodeReq dropReq = {0};
dropReq.dnodeId = pDnode->id;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
STransAction action = {0};
action.epSet = mndGetDnodeEpset(pDnode);
@@ -282,7 +282,7 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) {
SDnodeObj *pDnode = NULL;
SMCreateSnodeReq createReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
}
@@ -341,13 +341,13 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn
SDDropSnodeReq dropReq = {0};
dropReq.dnodeId = pDnode->id;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
STransAction action = {0};
action.epSet = mndGetDnodeEpset(pDnode);
@@ -398,7 +398,7 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) {
SSnodeObj *pObj = NULL;
SMDropSnodeReq dropReq = {0};
- if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
+ if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto _OVER;
}
diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c
index 10cfb0a660..4b1906ba70 100644
--- a/source/dnode/mnode/impl/src/mndStb.c
+++ b/source/dnode/mnode/impl/src/mndStb.c
@@ -2553,12 +2553,17 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
char rollup[160 + VARSTR_HEADER_SIZE] = {0};
int32_t rollupNum = (int32_t)taosArrayGetSize(pStb->pFuncs);
+ char *sep = ", ";
+ int32_t sepLen = strlen(sep);
+ int32_t rollupLen = sizeof(rollup) - VARSTR_HEADER_SIZE - 2;
for (int32_t i = 0; i < rollupNum; ++i) {
char *funcName = taosArrayGet(pStb->pFuncs, i);
if (i) {
- strcat(varDataVal(rollup), ", ");
+ strncat(varDataVal(rollup), sep, rollupLen);
+ rollupLen -= sepLen;
}
- strcat(varDataVal(rollup), funcName);
+ strncat(varDataVal(rollup), funcName, rollupLen);
+ rollupLen -= strlen(funcName);
}
varDataSetLen(rollup, strlen(varDataVal(rollup)));
diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c
index 866a3fa8b9..ac95dd2795 100644
--- a/source/dnode/mnode/impl/src/mndSync.c
+++ b/source/dnode/mnode/impl/src/mndSync.c
@@ -293,6 +293,14 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
if (code == 0) {
tsem_wait(&pMgmt->syncSem);
+ } else if (code > 0) {
+ mInfo("trans:%d, confirm at once since replica is 1, continue execute", transId);
+ taosWLockLatch(&pMgmt->lock);
+ pMgmt->transId = 0;
+ taosWUnLockLatch(&pMgmt->lock);
+ sdbWriteWithoutFree(pMnode->pSdb, pRaw);
+ sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID);
+ code = 0;
} else if (code == -1 && terrno == TSDB_CODE_SYN_NOT_LEADER) {
terrno = TSDB_CODE_APP_NOT_READY;
} else if (code == -1 && terrno == TSDB_CODE_SYN_INTERNAL_ERROR) {
diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt
index 3b1ca0999c..7db8485561 100644
--- a/source/dnode/mnode/impl/test/CMakeLists.txt
+++ b/source/dnode/mnode/impl/test/CMakeLists.txt
@@ -1,7 +1,6 @@
enable_testing()
add_subdirectory(acct)
-add_subdirectory(bnode)
add_subdirectory(db)
#add_subdirectory(dnode)
add_subdirectory(func)
diff --git a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt
deleted file mode 100644
index 2dd7b9ef78..0000000000
--- a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-# aux_source_directory(. MNODE_BNODE_TEST_SRC)
-# add_executable(mbnodeTest ${MNODE_BNODE_TEST_SRC})
-# target_link_libraries(
-# mbnodeTest
-# PUBLIC sut
-# )
-
-# add_test(
-# NAME mbnodeTest
-# COMMAND mbnodeTest
-# )
diff --git a/source/dnode/mnode/impl/test/bnode/mbnode.cpp b/source/dnode/mnode/impl/test/bnode/mbnode.cpp
deleted file mode 100644
index c93e2142d0..0000000000
--- a/source/dnode/mnode/impl/test/bnode/mbnode.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-/**
- * @file bnode.cpp
- * @author slguan (slguan@taosdata.com)
- * @brief MNODE module bnode tests
- * @version 1.0
- * @date 2022-01-05
- *
- * @copyright Copyright (c) 2022
- *
- */
-
-#include "sut.h"
-
-class MndTestBnode : public ::testing::Test {
- public:
- void SetUp() override {}
- void TearDown() override {}
-
- public:
- static void SetUpTestSuite() {
- test.Init(TD_TMP_DIR_PATH "mnode_test_bnode1", 9018);
- const char* fqdn = "localhost";
- const char* firstEp = "localhost:9018";
-
- server2.Start(TD_TMP_DIR_PATH "mnode_test_bnode2", 9019);
- taosMsleep(300);
- }
-
- static void TearDownTestSuite() {
- server2.Stop();
- test.Cleanup();
- }
-
- static Testbase test;
- static TestServer server2;
-};
-
-Testbase MndTestBnode::test;
-TestServer MndTestBnode::server2;
-
-TEST_F(MndTestBnode, 01_Show_Bnode) {
- test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", "");
- EXPECT_EQ(test.GetShowRows(), 0);
-}
-
-TEST_F(MndTestBnode, 02_Create_Bnode) {
- {
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
- }
-
- {
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, 0);
-
- test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", "");
- EXPECT_EQ(test.GetShowRows(), 1);
- }
-
- {
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 1;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_MND_BNODE_ALREADY_EXIST);
- }
-}
-
-TEST_F(MndTestBnode, 03_Drop_Bnode) {
- {
- SCreateDnodeReq createReq = {0};
- strcpy(createReq.fqdn, "localhost");
- createReq.port = 9019;
-
- int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, 0);
-
- taosMsleep(1300);
- test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", "");
- EXPECT_EQ(test.GetShowRows(), 2);
- }
-
- {
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, 0);
-
- test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", "");
- EXPECT_EQ(test.GetShowRows(), 2);
- }
-
- {
- SMDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, 0);
-
- test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", "");
- EXPECT_EQ(test.GetShowRows(), 1);
- }
-
- {
- SMDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_MND_BNODE_NOT_EXIST);
- }
-}
-
-TEST_F(MndTestBnode, 03_Create_Bnode_Rollback) {
- {
- // send message first, then dnode2 crash, result is returned, and rollback is started
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- server2.Stop();
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
- }
-
- {
- // continue send message, bnode is creating
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
- }
-
- {
- // continue send message, bnode is creating
- SMDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
- }
-
- {
- // server start, wait until the rollback finished
- server2.DoStart();
- taosMsleep(1000);
-
- int32_t retry = 0;
- int32_t retryMax = 20;
-
- for (retry = 0; retry < retryMax; retry++) {
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- if (pRsp->code == 0) break;
- taosMsleep(1000);
- }
-
- ASSERT_NE(retry, retryMax);
- }
-}
-
-TEST_F(MndTestBnode, 04_Drop_Bnode_Rollback) {
- {
- // send message first, then dnode2 crash, result is returned, and rollback is started
- SMDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- server2.Stop();
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
- }
-
- {
- // continue send message, bnode is dropping
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
- }
-
- {
- // continue send message, bnode is dropping
- SMDropBnodeReq dropReq = {0};
- dropReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
- }
-
- {
- // server start, wait until the rollback finished
- server2.DoStart();
- taosMsleep(1000);
-
- int32_t retry = 0;
- int32_t retryMax = 20;
-
- for (retry = 0; retry < retryMax; retry++) {
- SMCreateBnodeReq createReq = {0};
- createReq.dnodeId = 2;
-
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
- void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
-
- SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
- ASSERT_NE(pRsp, nullptr);
- if (pRsp->code == 0) break;
- taosMsleep(1000);
- }
-
- ASSERT_NE(retry, retryMax);
- }
-}
diff --git a/source/dnode/mnode/impl/test/mnode/mnode.cpp b/source/dnode/mnode/impl/test/mnode/mnode.cpp
index 1ed613c723..1f6dbd6dca 100644
--- a/source/dnode/mnode/impl/test/mnode/mnode.cpp
+++ b/source/dnode/mnode/impl/test/mnode/mnode.cpp
@@ -48,9 +48,9 @@ TEST_F(MndTestMnode, 02_Create_Mnode_Invalid_Id) {
SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -63,9 +63,9 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Invalid_Id) {
SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -98,9 +98,9 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -115,9 +115,9 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -132,9 +132,9 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -148,9 +148,9 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
server2.Stop();
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
@@ -163,9 +163,9 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -177,9 +177,9 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -198,9 +198,9 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -218,9 +218,9 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
server2.Stop();
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
@@ -233,9 +233,9 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -247,9 +247,9 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -268,9 +268,9 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp
index 57b38e55c1..a3bcb7654e 100644
--- a/source/dnode/mnode/impl/test/qnode/qnode.cpp
+++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp
@@ -48,9 +48,9 @@ TEST_F(MndTestQnode, 02_Create_Qnode) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -61,9 +61,9 @@ TEST_F(MndTestQnode, 02_Create_Qnode) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -77,9 +77,9 @@ TEST_F(MndTestQnode, 02_Create_Qnode) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -110,9 +110,9 @@ TEST_F(MndTestQnode, 03_Drop_Qnode) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -126,9 +126,9 @@ TEST_F(MndTestQnode, 03_Drop_Qnode) {
SMDropQnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -142,9 +142,9 @@ TEST_F(MndTestQnode, 03_Drop_Qnode) {
SMDropQnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -158,9 +158,9 @@ TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
server2.Stop();
taosMsleep(1000);
@@ -176,9 +176,9 @@ TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -190,9 +190,9 @@ TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) {
SMDropQnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -212,9 +212,9 @@ TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -231,9 +231,9 @@ TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) {
SMDropQnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
server2.Stop();
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
@@ -246,9 +246,9 @@ TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
@@ -259,9 +259,9 @@ TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) {
SMDropQnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -280,9 +280,9 @@ TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
if (pRsp->code == 0) break;
diff --git a/source/dnode/mnode/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp
index 1828fbd570..ac48eee4d0 100644
--- a/source/dnode/mnode/impl/test/snode/snode.cpp
+++ b/source/dnode/mnode/impl/test/snode/snode.cpp
@@ -48,9 +48,9 @@ TEST_F(MndTestSnode, 02_Create_Snode) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -61,9 +61,9 @@ TEST_F(MndTestSnode, 02_Create_Snode) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -77,9 +77,9 @@ TEST_F(MndTestSnode, 02_Create_Snode) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -110,9 +110,9 @@ TEST_F(MndTestSnode, 03_Drop_Snode) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -126,9 +126,9 @@ TEST_F(MndTestSnode, 03_Drop_Snode) {
SMDropSnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -142,9 +142,9 @@ TEST_F(MndTestSnode, 03_Drop_Snode) {
SMDropSnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -158,9 +158,9 @@ TEST_F(MndTestSnode, 03_Create_Snode_Rollback) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
server2.Stop();
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
@@ -173,9 +173,9 @@ TEST_F(MndTestSnode, 03_Create_Snode_Rollback) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -187,9 +187,9 @@ TEST_F(MndTestSnode, 03_Create_Snode_Rollback) {
SMDropSnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -208,9 +208,9 @@ TEST_F(MndTestSnode, 03_Create_Snode_Rollback) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -228,9 +228,9 @@ TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) {
SMDropSnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
server2.Stop();
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
@@ -243,9 +243,9 @@ TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -257,9 +257,9 @@ TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) {
SMDropSnodeReq dropReq = {0};
dropReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -278,9 +278,9 @@ TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) {
SMCreateSnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
diff --git a/source/dnode/mnode/impl/test/trans/trans1.cpp b/source/dnode/mnode/impl/test/trans/trans1.cpp
index 5a470fc900..92a442aa5e 100644
--- a/source/dnode/mnode/impl/test/trans/trans1.cpp
+++ b/source/dnode/mnode/impl/test/trans/trans1.cpp
@@ -112,9 +112,9 @@ TEST_F(MndTestTrans1, 02_Create_Qnode1_Crash) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -129,9 +129,9 @@ TEST_F(MndTestTrans1, 02_Create_Qnode1_Crash) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 1;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -165,9 +165,9 @@ TEST_F(MndTestTrans1, 03_Create_Qnode2_Crash) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
server2.Stop();
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
@@ -209,9 +209,9 @@ TEST_F(MndTestTrans1, 03_Create_Qnode2_Crash) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
@@ -232,9 +232,9 @@ TEST_F(MndTestTrans1, 03_Create_Qnode2_Crash) {
SMCreateQnodeReq createReq = {0};
createReq.dnodeId = 2;
- int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
+ int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
- tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
+ tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h
index a2373a55ce..d4db4709ca 100644
--- a/source/dnode/mnode/sdb/inc/sdb.h
+++ b/source/dnode/mnode/sdb/inc/sdb.h
@@ -132,7 +132,6 @@ typedef enum {
SDB_MNODE = 2,
SDB_QNODE = 3,
SDB_SNODE = 4,
- SDB_BNODE = 5,
SDB_DNODE = 6,
SDB_USER = 7,
SDB_AUTH = 8,
diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c
index 85e937fcc3..6c00a654e9 100644
--- a/source/dnode/mnode/sdb/src/sdbHash.c
+++ b/source/dnode/mnode/sdb/src/sdbHash.c
@@ -30,8 +30,6 @@ const char *sdbTableName(ESdbType type) {
return "qnode";
case SDB_SNODE:
return "snode";
- case SDB_BNODE:
- return "bnode";
case SDB_DNODE:
return "dnode";
case SDB_USER:
diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h
index 54d5d9eec2..96ba9a0602 100644
--- a/source/dnode/vnode/inc/vnode.h
+++ b/source/dnode/vnode/inc/vnode.h
@@ -82,6 +82,7 @@ int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp);
int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
+int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h
index 69e6cdce9f..7f418439a8 100644
--- a/source/dnode/vnode/src/inc/tq.h
+++ b/source/dnode/vnode/src/inc/tq.h
@@ -149,7 +149,7 @@ int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle);
int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle);
// tqRead
-int32_t tqScan(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* offset);
+int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* offset);
int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset);
int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum);
@@ -181,8 +181,8 @@ int32_t tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey)
int32_t tqOffsetCommitFile(STqOffsetStore* pStore);
// tqSink
-void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
-void tqTableSink1(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);
// tqOffset
char* tqOffsetBuildFName(const char* path, int32_t ver);
diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h
index bf110f1ae3..cb877e3b2d 100644
--- a/source/dnode/vnode/src/inc/tsdb.h
+++ b/source/dnode/vnode/src/inc/tsdb.h
@@ -32,12 +32,6 @@ extern "C" {
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSD ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
-#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \
- if (CODE) { \
- LINO = __LINE__; \
- goto LABEL; \
- }
-
typedef struct TSDBROW TSDBROW;
typedef struct TABLEID TABLEID;
typedef struct TSDBKEY TSDBKEY;
@@ -247,18 +241,17 @@ void tsdbSmaFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSmaFile *pSmaF, ch
// SDelFile
void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]);
// tsdbFS.c ==============================================================================================
-int32_t tsdbFSOpen(STsdb *pTsdb);
+int32_t tsdbFSOpen(STsdb *pTsdb, int8_t rollback);
int32_t tsdbFSClose(STsdb *pTsdb);
int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS);
void tsdbFSDestroy(STsdbFS *pFS);
int32_t tDFileSetCmprFn(const void *p1, const void *p2);
-int32_t tsdbFSCommit1(STsdb *pTsdb, STsdbFS *pFS);
-int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFS);
+int32_t tsdbFSCommit(STsdb *pTsdb);
+int32_t tsdbFSRollback(STsdb *pTsdb);
+int32_t tsdbFSPrepareCommit(STsdb *pTsdb, STsdbFS *pFS);
int32_t tsdbFSRef(STsdb *pTsdb, STsdbFS *pFS);
void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS);
-int32_t tsdbFSRollback(STsdbFS *pFS);
-
int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet);
int32_t tsdbFSUpsertDelFile(STsdbFS *pFS, SDelFile *pDelFile);
// tsdbReaderWriter.c ==============================================================================================
diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h
index aca99ecd2f..988ecc5dd3 100644
--- a/source/dnode/vnode/src/inc/vnd.h
+++ b/source/dnode/vnode/src/inc/vnd.h
@@ -87,11 +87,13 @@ int32_t vnodeGetBatchMeta(SVnode* pVnode, SRpcMsg* pMsg);
int32_t vnodeBegin(SVnode* pVnode);
int32_t vnodeShouldCommit(SVnode* pVnode);
int32_t vnodeCommit(SVnode* pVnode);
+void vnodeRollback(SVnode* pVnode);
int32_t vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
int32_t vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
int32_t vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo);
int32_t vnodeSyncCommit(SVnode* pVnode);
int32_t vnodeAsyncCommit(SVnode* pVnode);
+bool vnodeShouldRollback(SVnode* pVnode);
// vnodeSync.c
int32_t vnodeSyncOpen(SVnode* pVnode, char* path);
diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h
index 712f8bd15b..42ab0c2a37 100644
--- a/source/dnode/vnode/src/inc/vnodeInt.h
+++ b/source/dnode/vnode/src/inc/vnodeInt.h
@@ -97,10 +97,11 @@ typedef struct SMCtbCursor SMCtbCursor;
typedef struct SMStbCursor SMStbCursor;
typedef struct STbUidStore STbUidStore;
-int metaOpen(SVnode* pVnode, SMeta** ppMeta);
+int metaOpen(SVnode* pVnode, SMeta** ppMeta, int8_t rollback);
int metaClose(SMeta* pMeta);
int metaBegin(SMeta* pMeta, int8_t fromSys);
int metaCommit(SMeta* pMeta);
+int metaFinishCommit(SMeta* pMeta);
int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq, SArray* tbUidList);
@@ -149,10 +150,12 @@ typedef struct {
int32_t metaGetStbStats(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo);
// tsdb
-int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg);
+int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg, int8_t rollback);
int tsdbClose(STsdb** pTsdb);
int32_t tsdbBegin(STsdb* pTsdb);
int32_t tsdbCommit(STsdb* pTsdb);
+int32_t tsdbFinishCommit(STsdb* pTsdb);
+int32_t tsdbRollbackCommit(STsdb* pTsdb);
int32_t tsdbDoRetention(STsdb* pTsdb, int64_t now);
int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg);
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp);
@@ -200,15 +203,15 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
// sma
int32_t smaInit();
void smaCleanUp();
-int32_t smaOpen(SVnode* pVnode);
+int32_t smaOpen(SVnode* pVnode, int8_t rollback);
int32_t smaClose(SSma* pSma);
int32_t smaBegin(SSma* pSma);
int32_t smaSyncPreCommit(SSma* pSma);
int32_t smaSyncCommit(SSma* pSma);
int32_t smaSyncPostCommit(SSma* pSma);
-int32_t smaAsyncPreCommit(SSma* pSma);
-int32_t smaAsyncCommit(SSma* pSma);
-int32_t smaAsyncPostCommit(SSma* pSma);
+int32_t smaPreCommit(SSma* pSma);
+int32_t smaCommit(SSma* pSma);
+int32_t smaPostCommit(SSma* pSma);
int32_t smaDoRetention(SSma* pSma, int64_t now);
int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg);
diff --git a/source/dnode/vnode/src/meta/metaCommit.c b/source/dnode/vnode/src/meta/metaCommit.c
index 85ed40970c..01ad833d20 100644
--- a/source/dnode/vnode/src/meta/metaCommit.c
+++ b/source/dnode/vnode/src/meta/metaCommit.c
@@ -34,6 +34,7 @@ int metaBegin(SMeta *pMeta, int8_t fromSys) {
// commit the meta txn
int metaCommit(SMeta *pMeta) { return tdbCommit(pMeta->pEnv, &pMeta->txn); }
+int metaFinishCommit(SMeta *pMeta) { return tdbPostCommit(pMeta->pEnv, &pMeta->txn); }
// abort the meta txn
int metaAbort(SMeta *pMeta) { return tdbAbort(pMeta->pEnv, &pMeta->txn); }
diff --git a/source/dnode/vnode/src/meta/metaEntry.c b/source/dnode/vnode/src/meta/metaEntry.c
index b7bdadec03..72f7365a1e 100644
--- a/source/dnode/vnode/src/meta/metaEntry.c
+++ b/source/dnode/vnode/src/meta/metaEntry.c
@@ -21,7 +21,7 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
if (tEncodeI64(pCoder, pME->version) < 0) return -1;
if (tEncodeI8(pCoder, pME->type) < 0) return -1;
if (tEncodeI64(pCoder, pME->uid) < 0) return -1;
- if (tEncodeCStr(pCoder, pME->name) < 0) return -1;
+ if (pME->name == NULL || tEncodeCStr(pCoder, pME->name) < 0) return -1;
if (pME->type == TSDB_SUPER_TABLE) {
if (tEncodeI8(pCoder, pME->flags) < 0) return -1; // TODO: need refactor?
diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c
index 515fd31e9d..2198033db9 100644
--- a/source/dnode/vnode/src/meta/metaOpen.c
+++ b/source/dnode/vnode/src/meta/metaOpen.c
@@ -27,7 +27,7 @@ static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int k
static int32_t metaInitLock(SMeta *pMeta) { return taosThreadRwlockInit(&pMeta->lock, NULL); }
static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); }
-int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
+int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
SMeta *pMeta = NULL;
int ret;
int slen;
@@ -60,49 +60,49 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
taosMkDir(pMeta->path);
// open env
- ret = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv);
+ ret = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv, rollback);
if (ret < 0) {
metaError("vgId:%d, failed to open meta env since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pTbDb
- ret = tdbTbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb);
+ ret = tdbTbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pSkmDb
- ret = tdbTbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb);
+ ret = tdbTbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta schema db since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pUidIdx
- ret = tdbTbOpen("uid.idx", sizeof(tb_uid_t), sizeof(SUidIdxVal), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx);
+ ret = tdbTbOpen("uid.idx", sizeof(tb_uid_t), sizeof(SUidIdxVal), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pNameIdx
- ret = tdbTbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx);
+ ret = tdbTbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta name index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pCtbIdx
- ret = tdbTbOpen("ctb.idx", sizeof(SCtbIdxKey), -1, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx);
+ ret = tdbTbOpen("ctb.idx", sizeof(SCtbIdxKey), -1, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta child table index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pSuidIdx
- ret = tdbTbOpen("suid.idx", sizeof(tb_uid_t), 0, uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pSuidIdx);
+ ret = tdbTbOpen("suid.idx", sizeof(tb_uid_t), 0, uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pSuidIdx, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta super table index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
@@ -119,27 +119,27 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
goto _err;
}
- ret = tdbTbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx);
+ ret = tdbTbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pTtlIdx
- ret = tdbTbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx);
+ ret = tdbTbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open pSmaIdx
- ret = tdbTbOpen("sma.idx", sizeof(SSmaIdxKey), 0, smaIdxKeyCmpr, pMeta->pEnv, &pMeta->pSmaIdx);
+ ret = tdbTbOpen("sma.idx", sizeof(SSmaIdxKey), 0, smaIdxKeyCmpr, pMeta->pEnv, &pMeta->pSmaIdx, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta sma index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
- ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb);
+ ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb, 0);
if (ret < 0) {
metaError("vgId:%d, failed to open meta stream task index since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c
index a40bbd7d87..5c5b49ece5 100644
--- a/source/dnode/vnode/src/meta/metaSnapshot.c
+++ b/source/dnode/vnode/src/meta/metaSnapshot.c
@@ -165,6 +165,8 @@ int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback) {
} else {
code = metaCommit(pWriter->pMeta);
if (code) goto _err;
+ code = metaFinishCommit(pWriter->pMeta);
+ if (code) goto _err;
}
taosMemoryFree(pWriter);
*ppWriter = NULL;
diff --git a/source/dnode/vnode/src/sma/smaCommit.c b/source/dnode/vnode/src/sma/smaCommit.c
index 6168a00815..3dce724de7 100644
--- a/source/dnode/vnode/src/sma/smaCommit.c
+++ b/source/dnode/vnode/src/sma/smaCommit.c
@@ -54,28 +54,28 @@ int32_t smaSyncPostCommit(SSma *pSma) { return tdProcessRSmaSyncPostCommitImpl(p
#endif
/**
- * @brief Only applicable to Rollup SMA
+ * @brief async commit, only applicable to Rollup SMA
*
* @param pSma
* @return int32_t
*/
-int32_t smaAsyncPreCommit(SSma *pSma) { return tdProcessRSmaAsyncPreCommitImpl(pSma); }
+int32_t smaPreCommit(SSma *pSma) { return tdProcessRSmaAsyncPreCommitImpl(pSma); }
/**
- * @brief Only applicable to Rollup SMA
+ * @brief async commit, only applicable to Rollup SMA
*
* @param pSma
* @return int32_t
*/
-int32_t smaAsyncCommit(SSma *pSma) { return tdProcessRSmaAsyncCommitImpl(pSma); }
+int32_t smaCommit(SSma *pSma) { return tdProcessRSmaAsyncCommitImpl(pSma); }
/**
- * @brief Only applicable to Rollup SMA
+ * @brief async commit, only applicable to Rollup SMA
*
* @param pSma
* @return int32_t
*/
-int32_t smaAsyncPostCommit(SSma *pSma) { return tdProcessRSmaAsyncPostCommitImpl(pSma); }
+int32_t smaPostCommit(SSma *pSma) { return tdProcessRSmaAsyncPostCommitImpl(pSma); }
/**
* @brief set rsma trigger stat active
@@ -366,9 +366,11 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
* @return int32_t
*/
static int32_t tdProcessRSmaAsyncCommitImpl(SSma *pSma) {
+ int32_t code = 0;
+ SVnode *pVnode = pSma->pVnode;
SSmaEnv *pSmaEnv = SMA_RSMA_ENV(pSma);
if (!pSmaEnv) {
- return TSDB_CODE_SUCCESS;
+ goto _exit;
}
#if 0
SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pSmaEnv);
@@ -378,8 +380,21 @@ static int32_t tdProcessRSmaAsyncCommitImpl(SSma *pSma) {
return TSDB_CODE_FAILED;
}
#endif
-
- return TSDB_CODE_SUCCESS;
+ if ((code = tsdbCommit(VND_RSMA0(pVnode))) < 0) {
+ smaError("vgId:%d, failed to commit tsdb rsma0 since %s", TD_VID(pVnode), tstrerror(code));
+ goto _exit;
+ }
+ if ((code = tsdbCommit(VND_RSMA1(pVnode))) < 0) {
+ smaError("vgId:%d, failed to commit tsdb rsma1 since %s", TD_VID(pVnode), tstrerror(code));
+ goto _exit;
+ }
+ if ((code = tsdbCommit(VND_RSMA2(pVnode))) < 0) {
+ smaError("vgId:%d, failed to commit tsdb rsma2 since %s", TD_VID(pVnode), tstrerror(code));
+ goto _exit;
+ }
+_exit:
+ terrno = code;
+ return code;
}
/**
diff --git a/source/dnode/vnode/src/sma/smaOpen.c b/source/dnode/vnode/src/sma/smaOpen.c
index ef0d51f0eb..850e4c5697 100644
--- a/source/dnode/vnode/src/sma/smaOpen.c
+++ b/source/dnode/vnode/src/sma/smaOpen.c
@@ -29,19 +29,19 @@ static int32_t rsmaRestore(SSma *pSma);
pKeepCfg->days = smaEvalDays(v, pCfg->retentions, l, pCfg->precision, pCfg->days); \
} while (0)
-#define SMA_OPEN_RSMA_IMPL(v, l) \
- do { \
- SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \
- if (!RETENTION_VALID(r)) { \
- if (l == 0) { \
- goto _err; \
- } \
- break; \
- } \
- smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \
- if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg) < 0) { \
- goto _err; \
- } \
+#define SMA_OPEN_RSMA_IMPL(v, l) \
+ do { \
+ SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \
+ if (!RETENTION_VALID(r)) { \
+ if (l == 0) { \
+ goto _err; \
+ } \
+ break; \
+ } \
+ smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \
+ if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg, rollback) < 0) { \
+ goto _err; \
+ } \
} while (0)
/**
@@ -119,7 +119,7 @@ int smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int ty
return 0;
}
-int32_t smaOpen(SVnode *pVnode) {
+int32_t smaOpen(SVnode *pVnode, int8_t rollback) {
STsdbCfg *pCfg = &pVnode->config.tsdbCfg;
ASSERT(!pVnode->pSma);
diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c
index 5e1cc15063..6d71496008 100644
--- a/source/dnode/vnode/src/tq/tq.c
+++ b/source/dnode/vnode/src/tq/tq.c
@@ -595,7 +595,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
tqInitTaosxRsp(&taosxRsp, pReq);
if (fetchOffsetNew.type != TMQ_OFFSET__LOG) {
- tqScan(pTq, pHandle, &taosxRsp, &metaRsp, &fetchOffsetNew);
+ tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, &fetchOffsetNew);
if (metaRsp.metaRspLen > 0) {
if (tqSendMetaPollRsp(pTq, pMsg, pReq, &metaRsp) < 0) {
@@ -924,7 +924,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask) {
pTask->smaSink.smaSink = smaHandleRes;
} else if (pTask->outputType == TASK_OUTPUT__TABLE) {
pTask->tbSink.vnode = pTq->pVnode;
- pTask->tbSink.tbSinkFunc = tqTableSink1;
+ pTask->tbSink.tbSinkFunc = tqSinkToTablePipeline;
ASSERT(pTask->tbSink.pSchemaWrapper);
ASSERT(pTask->tbSink.pSchemaWrapper->pSchema);
diff --git a/source/dnode/vnode/src/tq/tqExec.c b/source/dnode/vnode/src/tq/tqExec.c
index 58d051bec1..305ee82982 100644
--- a/source/dnode/vnode/src/tq/tqExec.c
+++ b/source/dnode/vnode/src/tq/tqExec.c
@@ -123,7 +123,7 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
return 0;
}
-int32_t tqScan(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* pOffset) {
+int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* pOffset) {
const STqExecHandle* pExec = &pHandle->execHandle;
qTaskInfo_t task = pExec->task;
diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c
index 8e4bc34e0c..7e3ba57dea 100644
--- a/source/dnode/vnode/src/tq/tqMeta.c
+++ b/source/dnode/vnode/src/tq/tqMeta.c
@@ -70,17 +70,17 @@ int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) {
}
int32_t tqMetaOpen(STQ* pTq) {
- if (tdbOpen(pTq->path, 16 * 1024, 1, &pTq->pMetaDB) < 0) {
+ if (tdbOpen(pTq->path, 16 * 1024, 1, &pTq->pMetaDB, 0) < 0) {
ASSERT(0);
return -1;
}
- if (tdbTbOpen("tq.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pExecStore) < 0) {
+ if (tdbTbOpen("tq.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pExecStore, 0) < 0) {
ASSERT(0);
return -1;
}
- if (tdbTbOpen("tq.check.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pCheckStore) < 0) {
+ if (tdbTbOpen("tq.check.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pCheckStore, 0) < 0) {
ASSERT(0);
return -1;
}
diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c
index ab195b1eb3..79d7e27642 100644
--- a/source/dnode/vnode/src/tq/tqSink.c
+++ b/source/dnode/vnode/src/tq/tqSink.c
@@ -284,7 +284,7 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
return ret;
}
-void tqTableSink1(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;
SVnode* pVnode = (SVnode*)vnode;
int64_t suid = pTask->tbSink.stbUid;
@@ -528,7 +528,7 @@ void tqTableSink1(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
taosArrayDestroy(tagArray);
}
-void tqTableSink(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;
SVnode* pVnode = (SVnode*)vnode;
SBatchDeleteReq deleteReq = {0};
diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c
index a4d993bc6c..460ef611a3 100644
--- a/source/dnode/vnode/src/tsdb/tsdbCommit.c
+++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c
@@ -1041,38 +1041,20 @@ _exit:
static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno) {
int32_t code = 0;
int32_t lino = 0;
+ STsdb *pTsdb = pCommitter->pTsdb;
- STsdb *pTsdb = pCommitter->pTsdb;
- SMemTable *pMemTable = pTsdb->imem;
-
- ASSERT(eno == 0 &&
- "tsdbCommit failure"
- "Restart taosd");
-
- code = tsdbFSCommit1(pTsdb, &pCommitter->fs);
- TSDB_CHECK_CODE(code, lino, _exit);
-
- // lock
- taosThreadRwlockWrlock(&pTsdb->rwLock);
-
- // commit or rollback
- code = tsdbFSCommit2(pTsdb, &pCommitter->fs);
- if (code) {
- taosThreadRwlockUnlock(&pTsdb->rwLock);
+ if (eno) {
+ code = eno;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ } else {
+ code = tsdbFSPrepareCommit(pCommitter->pTsdb, &pCommitter->fs);
TSDB_CHECK_CODE(code, lino, _exit);
}
- pTsdb->imem = NULL;
-
- // unlock
- taosThreadRwlockUnlock(&pTsdb->rwLock);
-
- tsdbUnrefMemTable(pMemTable);
+_exit:
tsdbFSDestroy(&pCommitter->fs);
taosArrayDestroy(pCommitter->aTbDataP);
-
-_exit:
- if (code) {
+ if (code || eno) {
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
} else {
tsdbInfo("vgId:%d tsdb end commit", TD_VID(pTsdb->pVnode));
@@ -1646,3 +1628,50 @@ _exit:
}
return code;
}
+
+int32_t tsdbFinishCommit(STsdb *pTsdb) {
+ int32_t code = 0;
+ int32_t lino = 0;
+ SMemTable *pMemTable = pTsdb->imem;
+
+ // lock
+ taosThreadRwlockWrlock(&pTsdb->rwLock);
+
+ code = tsdbFSCommit(pTsdb);
+ if (code) {
+ taosThreadRwlockUnlock(&pTsdb->rwLock);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ pTsdb->imem = NULL;
+
+ // unlock
+ taosThreadRwlockUnlock(&pTsdb->rwLock);
+ if (pMemTable) {
+ tsdbUnrefMemTable(pMemTable);
+ }
+
+_exit:
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
+ } else {
+ tsdbInfo("vgId:%d tsdb finish commit", TD_VID(pTsdb->pVnode));
+ }
+ return code;
+}
+
+int32_t tsdbRollbackCommit(STsdb *pTsdb) {
+ int32_t code = 0;
+ int32_t lino = 0;
+
+ code = tsdbFSRollback(pTsdb);
+ TSDB_CHECK_CODE(code, lino, _exit);
+
+_exit:
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
+ } else {
+ tsdbInfo("vgId:%d tsdb rollback commit", TD_VID(pTsdb->pVnode));
+ }
+ return code;
+}
\ No newline at end of file
diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c
index 6fd5629592..c63247c21a 100644
--- a/source/dnode/vnode/src/tsdb/tsdbFS.c
+++ b/source/dnode/vnode/src/tsdb/tsdbFS.c
@@ -16,7 +16,7 @@
#include "tsdb.h"
// =================================================================================================
-static int32_t tsdbEncodeFS(uint8_t *p, STsdbFS *pFS) {
+static int32_t tsdbFSToBinary(uint8_t *p, STsdbFS *pFS) {
int32_t n = 0;
int8_t hasDel = pFS->pDelFile ? 1 : 0;
uint32_t nSet = taosArrayGetSize(pFS->aDFileSet);
@@ -39,214 +39,112 @@ static int32_t tsdbEncodeFS(uint8_t *p, STsdbFS *pFS) {
return n;
}
-static int32_t tsdbGnrtCurrent(STsdb *pTsdb, STsdbFS *pFS, char *fname) {
- int32_t code = 0;
- int64_t n;
- int64_t size;
- uint8_t *pData = NULL;
- TdFilePtr pFD = NULL;
+static int32_t tsdbBinaryToFS(uint8_t *pData, int64_t nData, STsdbFS *pFS) {
+ int32_t code = 0;
+ int32_t n = 0;
- // to binary
- size = tsdbEncodeFS(NULL, pFS) + sizeof(TSCKSUM);
- pData = taosMemoryMalloc(size);
+ // version
+ n += tGetI8(pData + n, NULL);
+
+ // SDelFile
+ int8_t hasDel = 0;
+ n += tGetI8(pData + n, &hasDel);
+ if (hasDel) {
+ pFS->pDelFile = (SDelFile *)taosMemoryCalloc(1, sizeof(SDelFile));
+ if (pFS->pDelFile == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
+
+ n += tGetDelFile(pData + n, pFS->pDelFile);
+ pFS->pDelFile->nRef = 1;
+ } else {
+ pFS->pDelFile = NULL;
+ }
+
+ // aDFileSet
+ taosArrayClear(pFS->aDFileSet);
+ uint32_t nSet = 0;
+ n += tGetU32v(pData + n, &nSet);
+ for (uint32_t iSet = 0; iSet < nSet; iSet++) {
+ SDFileSet fSet = {0};
+
+ int32_t nt = tGetDFileSet(pData + n, &fSet);
+ if (nt < 0) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
+
+ n += nt;
+ if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
+ }
+
+ ASSERT(n + sizeof(TSCKSUM) == nData);
+
+_exit:
+ return code;
+}
+
+static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) {
+ int32_t code = 0;
+ int32_t lino = 0;
+
+ // encode to binary
+ int32_t size = tsdbFSToBinary(NULL, pFS) + sizeof(TSCKSUM);
+ uint8_t *pData = taosMemoryMalloc(size);
if (pData == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
- n = tsdbEncodeFS(pData, pFS);
- ASSERT(n + sizeof(TSCKSUM) == size);
+ tsdbFSToBinary(pData, pFS);
taosCalcChecksumAppend(0, pData, size);
- // create and write
- pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
+ // save to file
+ TdFilePtr pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
if (pFD == NULL) {
code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
- n = taosWriteFile(pFD, pData, size);
+ int64_t n = taosWriteFile(pFD, pData, size);
if (n < 0) {
code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
+ taosCloseFile(&pFD);
+ TSDB_CHECK_CODE(code, lino, _exit);
}
if (taosFsyncFile(pFD) < 0) {
code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
+ taosCloseFile(&pFD);
+ TSDB_CHECK_CODE(code, lino, _exit);
}
taosCloseFile(&pFD);
+_exit:
if (pData) taosMemoryFree(pData);
- return code;
-
-_err:
- tsdbError("vgId:%d, tsdb gnrt current failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
- if (pData) taosMemoryFree(pData);
+ if (code) {
+ tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname);
+ }
return code;
}
-// static int32_t tsdbApplyDFileSetChange(STsdbFS *pFS, SDFileSet *pFrom, SDFileSet *pTo) {
-// int32_t code = 0;
-// char fname[TSDB_FILENAME_LEN];
+int32_t tsdbFSCreate(STsdbFS *pFS) {
+ int32_t code = 0;
-// if (pFrom && pTo) {
-// bool isSameDisk = (pFrom->diskId.level == pTo->diskId.level) && (pFrom->diskId.id == pTo->diskId.id);
+ pFS->pDelFile = NULL;
+ pFS->aDFileSet = taosArrayInit(0, sizeof(SDFileSet));
+ if (pFS->aDFileSet == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
-// // head
-// if (isSameDisk && pFrom->pHeadF->commitID == pTo->pHeadF->commitID) {
-// ASSERT(pFrom->pHeadF->size == pTo->pHeadF->size);
-// ASSERT(pFrom->pHeadF->offset == pTo->pHeadF->offset);
-// } else {
-// tsdbHeadFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pHeadF, fname);
-// taosRemoveFile(fname);
-// }
-
-// // data
-// if (isSameDisk && pFrom->pDataF->commitID == pTo->pDataF->commitID) {
-// if (pFrom->pDataF->size > pTo->pDataF->size) {
-// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_DATA_FILE);
-// if (code) goto _err;
-// }
-// } else {
-// tsdbDataFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pDataF, fname);
-// taosRemoveFile(fname);
-// }
-
-// // stt
-// if (isSameDisk && pFrom->pLastF->commitID == pTo->pLastF->commitID) {
-// if (pFrom->pLastF->size > pTo->pLastF->size) {
-// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_LAST_FILE);
-// if (code) goto _err;
-// }
-// } else {
-// tsdbLastFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pLastF, fname);
-// taosRemoveFile(fname);
-// }
-
-// // sma
-// if (isSameDisk && pFrom->pSmaF->commitID == pTo->pSmaF->commitID) {
-// if (pFrom->pSmaF->size > pTo->pSmaF->size) {
-// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_SMA_FILE);
-// if (code) goto _err;
-// }
-// } else {
-// tsdbSmaFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pSmaF, fname);
-// taosRemoveFile(fname);
-// }
-// } else if (pFrom) {
-// // head
-// tsdbHeadFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pHeadF, fname);
-// taosRemoveFile(fname);
-
-// // data
-// tsdbDataFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pDataF, fname);
-// taosRemoveFile(fname);
-
-// // stt
-// tsdbLastFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pLastF, fname);
-// taosRemoveFile(fname);
-
-// // fsm
-// tsdbSmaFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pSmaF, fname);
-// taosRemoveFile(fname);
-// }
-
-// return code;
-
-// _err:
-// tsdbError("vgId:%d, tsdb apply disk file set change failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code));
-// return code;
-// }
-
-// static int32_t tsdbApplyDelFileChange(STsdbFS *pFS, SDelFile *pFrom, SDelFile *pTo) {
-// int32_t code = 0;
-// char fname[TSDB_FILENAME_LEN];
-
-// if (pFrom && pTo) {
-// if (!tsdbDelFileIsSame(pFrom, pTo)) {
-// tsdbDelFileName(pFS->pTsdb, pFrom, fname);
-// if (taosRemoveFile(fname) < 0) {
-// code = TAOS_SYSTEM_ERROR(errno);
-// goto _err;
-// }
-// }
-// } else if (pFrom) {
-// tsdbDelFileName(pFS->pTsdb, pFrom, fname);
-// if (taosRemoveFile(fname) < 0) {
-// code = TAOS_SYSTEM_ERROR(errno);
-// goto _err;
-// }
-// } else {
-// // do nothing
-// }
-
-// return code;
-
-// _err:
-// tsdbError("vgId:%d, tsdb apply del file change failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code));
-// return code;
-// }
-
-// static int32_t tsdbFSApplyDiskChange(STsdbFS *pFS, STsdbFSState *pFrom, STsdbFSState *pTo) {
-// int32_t code = 0;
-// int32_t iFrom = 0;
-// int32_t nFrom = taosArrayGetSize(pFrom->aDFileSet);
-// int32_t iTo = 0;
-// int32_t nTo = taosArrayGetSize(pTo->aDFileSet);
-// SDFileSet *pDFileSetFrom;
-// SDFileSet *pDFileSetTo;
-
-// // SDelFile
-// code = tsdbApplyDelFileChange(pFS, pFrom->pDelFile, pTo->pDelFile);
-// if (code) goto _err;
-
-// // SDFileSet
-// while (iFrom < nFrom && iTo < nTo) {
-// pDFileSetFrom = (SDFileSet *)taosArrayGet(pFrom->aDFileSet, iFrom);
-// pDFileSetTo = (SDFileSet *)taosArrayGet(pTo->aDFileSet, iTo);
-
-// if (pDFileSetFrom->fid == pDFileSetTo->fid) {
-// code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, pDFileSetTo);
-// if (code) goto _err;
-
-// iFrom++;
-// iTo++;
-// } else if (pDFileSetFrom->fid < pDFileSetTo->fid) {
-// code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, NULL);
-// if (code) goto _err;
-
-// iFrom++;
-// } else {
-// iTo++;
-// }
-// }
-
-// while (iFrom < nFrom) {
-// pDFileSetFrom = (SDFileSet *)taosArrayGet(pFrom->aDFileSet, iFrom);
-// code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, NULL);
-// if (code) goto _err;
-
-// iFrom++;
-// }
-
-// #if 0
-// // do noting
-// while (iTo < nTo) {
-// pDFileSetTo = (SDFileSet *)taosArrayGetP(pTo->aDFileSet, iTo);
-// code = tsdbApplyDFileSetChange(pFS, NULL, pDFileSetTo);
-// if (code) goto _err;
-
-// iTo++;
-// }
-// #endif
-
-// return code;
-
-// _err:
-// tsdbError("vgId:%d, tsdb fs apply disk change failed sicne %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code));
-// return code;
-// }
+_exit:
+ return code;
+}
void tsdbFSDestroy(STsdbFS *pFS) {
if (pFS->pDelFile) {
@@ -268,76 +166,81 @@ void tsdbFSDestroy(STsdbFS *pFS) {
static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
int32_t code = 0;
- int64_t size;
- char fname[TSDB_FILENAME_LEN];
+ int32_t lino = 0;
+ int64_t size = 0;
+ char fname[TSDB_FILENAME_LEN] = {0};
// SDelFile
if (pTsdb->fs.pDelFile) {
tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname);
if (taosStatFile(fname, &size, NULL)) {
code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
if (size != tsdbLogicToFileSize(pTsdb->fs.pDelFile->size, pTsdb->pVnode->config.tsdbPageSize)) {
code = TSDB_CODE_FILE_CORRUPTED;
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
}
// SArray
+ int32_t fid = 0;
for (int32_t iSet = 0; iSet < taosArrayGetSize(pTsdb->fs.aDFileSet); iSet++) {
SDFileSet *pSet = (SDFileSet *)taosArrayGet(pTsdb->fs.aDFileSet, iSet);
+ fid = pSet->fid;
// head =========
tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname);
if (taosStatFile(fname, &size, NULL)) {
code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
if (size != tsdbLogicToFileSize(pSet->pHeadF->size, pTsdb->pVnode->config.tsdbPageSize)) {
code = TSDB_CODE_FILE_CORRUPTED;
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
// data =========
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
if (taosStatFile(fname, &size, NULL)) {
code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
if (size < tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) {
code = TSDB_CODE_FILE_CORRUPTED;
- goto _err;
- } else if (size > tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) {
- code = tsdbDFileRollback(pTsdb, pSet, TSDB_DATA_FILE);
- if (code) goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
+ // else if (size > tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) {
+ // code = tsdbDFileRollback(pTsdb, pSet, TSDB_DATA_FILE);
+ // TSDB_CHECK_CODE(code, lino, _exit);
+ // }
// sma =============
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
if (taosStatFile(fname, &size, NULL)) {
code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
if (size < tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) {
code = TSDB_CODE_FILE_CORRUPTED;
- goto _err;
- } else if (size > tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) {
- code = tsdbDFileRollback(pTsdb, pSet, TSDB_SMA_FILE);
- if (code) goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
+ // else if (size > tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) {
+ // code = tsdbDFileRollback(pTsdb, pSet, TSDB_SMA_FILE);
+ // TSDB_CHECK_CODE(code, lino, _exit);
+ // }
// stt ===========
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
if (taosStatFile(fname, &size, NULL)) {
code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
if (size != tsdbLogicToFileSize(pSet->aSttF[iStt]->size, pTsdb->pVnode->config.tsdbPageSize)) {
code = TSDB_CODE_FILE_CORRUPTED;
- goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
}
}
@@ -346,10 +249,11 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// remove those invalid files (todo)
}
- return code;
-
-_err:
- tsdbError("vgId:%d, tsdb scan and try fix fs failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
+_exit:
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s, fid:%d", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code),
+ fid);
+ }
return code;
}
@@ -363,141 +267,531 @@ int32_t tDFileSetCmprFn(const void *p1, const void *p2) {
return 0;
}
-static int32_t tsdbRecoverFS(STsdb *pTsdb, uint8_t *pData, int64_t nData) {
- int32_t code = 0;
- int8_t hasDel;
- uint32_t nSet;
- int32_t n = 0;
+static void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) {
+ SVnode *pVnode = pTsdb->pVnode;
+ if (pVnode->pTfs) {
+ if (current) {
+ snprintf(current, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP,
+ pTsdb->path, TD_DIRSEP);
+ }
+ if (current_t) {
+ snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT.t", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP,
+ pTsdb->path, TD_DIRSEP);
+ }
+ } else {
+ if (current) {
+ snprintf(current, TSDB_FILENAME_LEN - 1, "%s%sCURRENT", pTsdb->path, TD_DIRSEP);
+ }
+ if (current_t) {
+ snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%sCURRENT.t", pTsdb->path, TD_DIRSEP);
+ }
+ }
+}
- // version
- n += tGetI8(pData + n, NULL);
+static int32_t tsdbLoadFSFromFile(const char *fname, STsdbFS *pFS) {
+ int32_t code = 0;
+ int32_t lino = 0;
+ uint8_t *pData = NULL;
+
+ // load binary
+ TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ);
+ if (pFD == NULL) {
+ code = terrno;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ int64_t size;
+ if (taosFStatFile(pFD, &size, NULL) < 0) {
+ code = TAOS_SYSTEM_ERROR(errno);
+ taosCloseFile(&pFD);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ pData = taosMemoryMalloc(size);
+ if (pData == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ taosCloseFile(&pFD);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ if (taosReadFile(pFD, pData, size) < 0) {
+ code = TAOS_SYSTEM_ERROR(errno);
+ taosCloseFile(&pFD);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ if (!taosCheckChecksumWhole(pData, size)) {
+ code = TSDB_CODE_FILE_CORRUPTED;
+ taosCloseFile(&pFD);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ taosCloseFile(&pFD);
+
+ // decode binary
+ code = tsdbBinaryToFS(pData, size, pFS);
+ TSDB_CHECK_CODE(code, lino, _exit);
+
+_exit:
+ if (pData) taosMemoryFree(pData);
+ if (code) {
+ tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname);
+ }
+ return code;
+}
+
+static int32_t tsdbRemoveFileSet(STsdb *pTsdb, SDFileSet *pSet) {
+ int32_t code = 0;
+ char fname[TSDB_FILENAME_LEN] = {0};
+
+ int32_t nRef = atomic_sub_fetch_32(&pSet->pHeadF->nRef, 1);
+ if (nRef == 0) {
+ tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pSet->pHeadF);
+ }
+
+ nRef = atomic_sub_fetch_32(&pSet->pDataF->nRef, 1);
+ if (nRef == 0) {
+ tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pSet->pDataF);
+ }
+
+ nRef = atomic_sub_fetch_32(&pSet->pSmaF->nRef, 1);
+ if (nRef == 0) {
+ tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pSet->pSmaF);
+ }
+
+ for (int8_t iStt = 0; iStt < pSet->nSttF; iStt++) {
+ nRef = atomic_sub_fetch_32(&pSet->aSttF[iStt]->nRef, 1);
+ if (nRef == 0) {
+ tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pSet->aSttF[iStt]);
+ }
+ }
+
+_exit:
+ return code;
+}
+
+static int32_t tsdbNewFileSet(STsdb *pTsdb, SDFileSet *pSetTo, SDFileSet *pSetFrom) {
+ int32_t code = 0;
+ int32_t lino = 0;
+
+ *pSetTo = (SDFileSet){.diskId = pSetFrom->diskId, .fid = pSetFrom->fid, .nSttF = 0};
+
+ // head
+ pSetTo->pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
+ if (pSetTo->pHeadF == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetTo->pHeadF = *pSetFrom->pHeadF;
+ pSetTo->pHeadF->nRef = 1;
+
+ // data
+ pSetTo->pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile));
+ if (pSetTo->pDataF == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetTo->pDataF = *pSetFrom->pDataF;
+ pSetTo->pDataF->nRef = 1;
+
+ // sma
+ pSetTo->pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
+ if (pSetTo->pSmaF == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetTo->pSmaF = *pSetFrom->pSmaF;
+ pSetTo->pSmaF->nRef = 1;
+
+ // stt
+ for (int32_t iStt = 0; iStt < pSetFrom->nSttF; iStt++) {
+ pSetTo->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
+ if (pSetTo->aSttF[iStt] == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ pSetTo->nSttF++;
+ *pSetTo->aSttF[iStt] = *pSetFrom->aSttF[iStt];
+ pSetTo->aSttF[iStt]->nRef = 1;
+ }
+
+_exit:
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
+ }
+ return code;
+}
+
+static int32_t tsdbMergeFileSet(STsdb *pTsdb, SDFileSet *pSetOld, SDFileSet *pSetNew) {
+ int32_t code = 0;
+ int32_t lino = 0;
+ int32_t nRef = 0;
+ bool sameDisk = ((pSetOld->diskId.level == pSetNew->diskId.level) && (pSetOld->diskId.id == pSetNew->diskId.id));
+ char fname[TSDB_FILENAME_LEN] = {0};
+
+ // head
+ SHeadFile *pHeadF = pSetOld->pHeadF;
+ if ((!sameDisk) || (pHeadF->commitID != pSetNew->pHeadF->commitID)) {
+ pSetOld->pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
+ if (pSetOld->pHeadF == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetOld->pHeadF = *pSetNew->pHeadF;
+ pSetOld->pHeadF->nRef = 1;
+
+ nRef = atomic_sub_fetch_32(&pHeadF->nRef, 1);
+ if (nRef == 0) {
+ tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pHeadF, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pHeadF);
+ }
+ } else {
+ nRef = pHeadF->nRef;
+ *pHeadF = *pSetNew->pHeadF;
+ pHeadF->nRef = nRef;
+ }
+
+ // data
+ SDataFile *pDataF = pSetOld->pDataF;
+ if ((!sameDisk) || (pDataF->commitID != pSetNew->pDataF->commitID)) {
+ pSetOld->pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile));
+ if (pSetOld->pDataF == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetOld->pDataF = *pSetNew->pDataF;
+ pSetOld->pDataF->nRef = 1;
+
+ nRef = atomic_sub_fetch_32(&pDataF->nRef, 1);
+ if (nRef == 0) {
+ tsdbDataFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pDataF, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pDataF);
+ }
+ } else {
+ nRef = pDataF->nRef;
+ *pDataF = *pSetNew->pDataF;
+ pDataF->nRef = nRef;
+ }
+
+ // sma
+ SSmaFile *pSmaF = pSetOld->pSmaF;
+ if ((!sameDisk) || (pSmaF->commitID != pSetNew->pSmaF->commitID)) {
+ pSetOld->pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
+ if (pSetOld->pSmaF == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetOld->pSmaF = *pSetNew->pSmaF;
+ pSetOld->pSmaF->nRef = 1;
+
+ nRef = atomic_sub_fetch_32(&pSmaF->nRef, 1);
+ if (nRef == 0) {
+ tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSmaF, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pSmaF);
+ }
+ } else {
+ nRef = pSmaF->nRef;
+ *pSmaF = *pSetNew->pSmaF;
+ pSmaF->nRef = nRef;
+ }
+
+ // stt
+ if (sameDisk) {
+ if (pSetNew->nSttF > pSetOld->nSttF) {
+ ASSERT(pSetNew->nSttF == pSetOld->nSttF + 1);
+ pSetOld->aSttF[pSetOld->nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
+ if (pSetOld->aSttF[pSetOld->nSttF] == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetOld->aSttF[pSetOld->nSttF] = *pSetNew->aSttF[pSetOld->nSttF];
+ pSetOld->aSttF[pSetOld->nSttF]->nRef = 1;
+ pSetOld->nSttF++;
+ } else if (pSetNew->nSttF < pSetOld->nSttF) {
+ ASSERT(pSetNew->nSttF == 1);
+ for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
+ SSttFile *pSttFile = pSetOld->aSttF[iStt];
+ nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
+ if (nRef == 0) {
+ tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pSttFile);
+ }
+ pSetOld->aSttF[iStt] = NULL;
+ }
+
+ pSetOld->nSttF = 1;
+ pSetOld->aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
+ if (pSetOld->aSttF[0] == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetOld->aSttF[0] = *pSetNew->aSttF[0];
+ pSetOld->aSttF[0]->nRef = 1;
+ } else {
+ for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
+ if (pSetOld->aSttF[iStt]->commitID != pSetNew->aSttF[iStt]->commitID) {
+ SSttFile *pSttFile = pSetOld->aSttF[iStt];
+ nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
+ if (nRef == 0) {
+ tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pSttFile);
+ }
+
+ pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
+ if (pSetOld->aSttF[iStt] == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ *pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt];
+ pSetOld->aSttF[iStt]->nRef = 1;
+ } else {
+ ASSERT(pSetOld->aSttF[iStt]->size == pSetOld->aSttF[iStt]->size);
+ ASSERT(pSetOld->aSttF[iStt]->offset == pSetOld->aSttF[iStt]->offset);
+ }
+ }
+ }
+ } else {
+ for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
+ SSttFile *pSttFile = pSetOld->aSttF[iStt];
+ nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
+ if (nRef == 0) {
+ tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pSttFile);
+ }
+ }
+
+ pSetOld->nSttF = 0;
+ for (int32_t iStt = 0; iStt < pSetNew->nSttF; iStt++) {
+ pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
+ if (pSetOld->aSttF[iStt] == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ *pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt];
+ pSetOld->aSttF[iStt]->nRef = 1;
+
+ pSetOld->nSttF++;
+ }
+ }
+
+ if (!sameDisk) {
+ pSetOld->diskId = pSetNew->diskId;
+ }
+
+_exit:
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
+ }
+ return code;
+}
+
+static int32_t tsdbFSApplyChange(STsdb *pTsdb, STsdbFS *pFS) {
+ int32_t code = 0;
+ int32_t lino = 0;
+
+ int32_t nRef = 0;
+ char fname[TSDB_FILENAME_LEN] = {0};
// SDelFile
- n += tGetI8(pData + n, &hasDel);
- if (hasDel) {
- pTsdb->fs.pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile));
- if (pTsdb->fs.pDelFile == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
+ if (pFS->pDelFile) {
+ SDelFile *pDelFile = pTsdb->fs.pDelFile;
- pTsdb->fs.pDelFile->nRef = 1;
- n += tGetDelFile(pData + n, pTsdb->fs.pDelFile);
+ if (pDelFile == NULL || (pDelFile->commitID != pFS->pDelFile->commitID)) {
+ pTsdb->fs.pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile));
+ if (pTsdb->fs.pDelFile == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ *pTsdb->fs.pDelFile = *pFS->pDelFile;
+ pTsdb->fs.pDelFile->nRef = 1;
+
+ if (pDelFile) {
+ nRef = atomic_sub_fetch_32(&pDelFile->nRef, 1);
+ if (nRef == 0) {
+ tsdbDelFileName(pTsdb, pDelFile, fname);
+ (void)taosRemoveFile(fname);
+ taosMemoryFree(pDelFile);
+ }
+ }
+ }
} else {
- pTsdb->fs.pDelFile = NULL;
+ ASSERT(pTsdb->fs.pDelFile == NULL);
}
- // SArray
- taosArrayClear(pTsdb->fs.aDFileSet);
- n += tGetU32v(pData + n, &nSet);
- for (uint32_t iSet = 0; iSet < nSet; iSet++) {
+ // aDFileSet
+ int32_t iOld = 0;
+ int32_t iNew = 0;
+ while (true) {
+ int32_t nOld = taosArrayGetSize(pTsdb->fs.aDFileSet);
+ int32_t nNew = taosArrayGetSize(pFS->aDFileSet);
SDFileSet fSet = {0};
+ int8_t sameDisk = 0;
- int32_t nt = tGetDFileSet(pData + n, &fSet);
- if (nt < 0) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
+ if (iOld >= nOld && iNew >= nNew) break;
- n += nt;
+ SDFileSet *pSetOld = (iOld < nOld) ? taosArrayGet(pTsdb->fs.aDFileSet, iOld) : NULL;
+ SDFileSet *pSetNew = (iNew < nNew) ? taosArrayGet(pFS->aDFileSet, iNew) : NULL;
- if (taosArrayPush(pTsdb->fs.aDFileSet, &fSet) == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
+ if (pSetOld && pSetNew) {
+ if (pSetOld->fid == pSetNew->fid) {
+ code = tsdbMergeFileSet(pTsdb, pSetOld, pSetNew);
+ TSDB_CHECK_CODE(code, lino, _exit);
+
+ iOld++;
+ iNew++;
+ } else if (pSetOld->fid < pSetNew->fid) {
+ code = tsdbRemoveFileSet(pTsdb, pSetOld);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ taosArrayRemove(pTsdb->fs.aDFileSet, iOld);
+ } else {
+ code = tsdbNewFileSet(pTsdb, &fSet, pSetNew);
+ TSDB_CHECK_CODE(code, lino, _exit)
+
+ if (taosArrayInsert(pTsdb->fs.aDFileSet, iOld, &fSet) == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ iOld++;
+ iNew++;
+ }
+ } else if (pSetOld) {
+ code = tsdbRemoveFileSet(pTsdb, pSetOld);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ taosArrayRemove(pTsdb->fs.aDFileSet, iOld);
+ } else {
+ code = tsdbNewFileSet(pTsdb, &fSet, pSetNew);
+ TSDB_CHECK_CODE(code, lino, _exit)
+
+ if (taosArrayInsert(pTsdb->fs.aDFileSet, iOld, &fSet) == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ iOld++;
+ iNew++;
}
}
- ASSERT(n + sizeof(TSCKSUM) == nData);
- return code;
-
-_err:
+_exit:
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
+ }
return code;
}
// EXPOSED APIS ====================================================================================
-int32_t tsdbFSOpen(STsdb *pTsdb) {
+int32_t tsdbFSCommit(STsdb *pTsdb) {
int32_t code = 0;
+ int32_t lino = 0;
+ STsdbFS fs = {0};
+
+ char current[TSDB_FILENAME_LEN] = {0};
+ char current_t[TSDB_FILENAME_LEN] = {0};
+ tsdbGetCurrentFName(pTsdb, current, current_t);
+
+ if (!taosCheckExistFile(current_t)) goto _exit;
+
+ // rename the file
+ if (taosRenameFile(current_t, current) < 0) {
+ code = TAOS_SYSTEM_ERROR(errno);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ // Load the new FS
+ code = tsdbFSCreate(&fs);
+ TSDB_CHECK_CODE(code, lino, _exit);
+
+ code = tsdbLoadFSFromFile(current, &fs);
+ TSDB_CHECK_CODE(code, lino, _exit);
+
+ // apply file change
+ code = tsdbFSApplyChange(pTsdb, &fs);
+ TSDB_CHECK_CODE(code, lino, _exit);
+
+_exit:
+ tsdbFSDestroy(&fs);
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
+ }
+ return code;
+}
+
+int32_t tsdbFSRollback(STsdb *pTsdb) {
+ int32_t code = 0;
+ int32_t lino = 0;
+
+ char current_t[TSDB_FILENAME_LEN] = {0};
+ tsdbGetCurrentFName(pTsdb, NULL, current_t);
+ (void)taosRemoveFile(current_t);
+
+_exit:
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(errno));
+ }
+ return code;
+}
+
+int32_t tsdbFSOpen(STsdb *pTsdb, int8_t rollback) {
+ int32_t code = 0;
+ int32_t lino = 0;
SVnode *pVnode = pTsdb->pVnode;
// open handle
- pTsdb->fs.pDelFile = NULL;
- pTsdb->fs.aDFileSet = taosArrayInit(0, sizeof(SDFileSet));
- if (pTsdb->fs.aDFileSet == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
+ code = tsdbFSCreate(&pTsdb->fs);
+ TSDB_CHECK_CODE(code, lino, _exit);
- // load fs or keep empty
- char fname[TSDB_FILENAME_LEN];
+ // open impl
+ char current[TSDB_FILENAME_LEN] = {0};
+ char current_t[TSDB_FILENAME_LEN] = {0};
+ tsdbGetCurrentFName(pTsdb, current, current_t);
- if (pVnode->pTfs) {
- snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP,
- pTsdb->path, TD_DIRSEP);
+ if (taosCheckExistFile(current)) {
+ code = tsdbLoadFSFromFile(current, &pTsdb->fs);
+ TSDB_CHECK_CODE(code, lino, _exit);
+
+ if (taosCheckExistFile(current_t)) {
+ if (rollback) {
+ code = tsdbFSRollback(pTsdb);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ } else {
+ code = tsdbFSCommit(pTsdb);
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+ }
} else {
- snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%sCURRENT", pTsdb->path, TD_DIRSEP);
- }
-
- if (!taosCheckExistFile(fname)) {
// empty one
- code = tsdbGnrtCurrent(pTsdb, &pTsdb->fs, fname);
- if (code) goto _err;
- } else {
- // read
- TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ);
- if (pFD == NULL) {
- code = TAOS_SYSTEM_ERROR(errno);
- goto _err;
- }
+ code = tsdbSaveFSToFile(&pTsdb->fs, current);
+ TSDB_CHECK_CODE(code, lino, _exit);
- int64_t size;
- if (taosFStatFile(pFD, &size, NULL) < 0) {
- code = TAOS_SYSTEM_ERROR(errno);
- taosCloseFile(&pFD);
- goto _err;
- }
-
- uint8_t *pData = taosMemoryMalloc(size);
- if (pData == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- taosCloseFile(&pFD);
- goto _err;
- }
-
- int64_t n = taosReadFile(pFD, pData, size);
- if (n < 0) {
- code = TAOS_SYSTEM_ERROR(errno);
- taosMemoryFree(pData);
- taosCloseFile(&pFD);
- goto _err;
- }
-
- if (!taosCheckChecksumWhole(pData, size)) {
- code = TSDB_CODE_FILE_CORRUPTED;
- taosMemoryFree(pData);
- taosCloseFile(&pFD);
- goto _err;
- }
-
- taosCloseFile(&pFD);
-
- // recover fs
- code = tsdbRecoverFS(pTsdb, pData, size);
- if (code) {
- taosMemoryFree(pData);
- goto _err;
- }
-
- taosMemoryFree(pData);
+ ASSERT(!rollback);
}
// scan and fix FS
code = tsdbScanAndTryFixFS(pTsdb);
- if (code) goto _err;
+ TSDB_CHECK_CODE(code, lino, _exit);
- return code;
-
-_err:
- tsdbError("vgId:%d, tsdb fs open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
+_exit:
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
+ }
return code;
}
@@ -538,19 +832,24 @@ int32_t tsdbFSClose(STsdb *pTsdb) {
int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
int32_t code = 0;
+ int32_t lino = 0;
pFS->pDelFile = NULL;
- pFS->aDFileSet = taosArrayInit(taosArrayGetSize(pTsdb->fs.aDFileSet), sizeof(SDFileSet));
- if (pFS->aDFileSet == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _exit;
+ if (pFS->aDFileSet) {
+ taosArrayClear(pFS->aDFileSet);
+ } else {
+ pFS->aDFileSet = taosArrayInit(taosArrayGetSize(pTsdb->fs.aDFileSet), sizeof(SDFileSet));
+ if (pFS->aDFileSet == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
}
if (pTsdb->fs.pDelFile) {
pFS->pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile));
if (pFS->pDelFile == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
- goto _exit;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
*pFS->pDelFile = *pTsdb->fs.pDelFile;
@@ -564,7 +863,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
if (fSet.pHeadF == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
- goto _exit;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
*fSet.pHeadF = *pSet->pHeadF;
@@ -572,7 +871,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
fSet.pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile));
if (fSet.pDataF == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
- goto _exit;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
*fSet.pDataF = *pSet->pDataF;
@@ -580,7 +879,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
if (fSet.pSmaF == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
- goto _exit;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
*fSet.pSmaF = *pSet->pSmaF;
@@ -589,26 +888,21 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
fSet.aSttF[fSet.nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
if (fSet.aSttF[fSet.nSttF] == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
- goto _exit;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
*fSet.aSttF[fSet.nSttF] = *pSet->aSttF[fSet.nSttF];
}
if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
- goto _exit;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
}
_exit:
- return code;
-}
-
-int32_t tsdbFSRollback(STsdbFS *pFS) {
- int32_t code = 0;
-
- ASSERT(0);
-
+ if (code) {
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
+ }
return code;
}
@@ -714,336 +1008,21 @@ _exit:
return code;
}
-int32_t tsdbFSCommit1(STsdb *pTsdb, STsdbFS *pFSNew) {
+int32_t tsdbFSPrepareCommit(STsdb *pTsdb, STsdbFS *pFSNew) {
int32_t code = 0;
+ int32_t lino = 0;
char tfname[TSDB_FILENAME_LEN];
- char fname[TSDB_FILENAME_LEN];
- snprintf(tfname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT.t", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP,
- pTsdb->path, TD_DIRSEP);
- snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP,
- pTsdb->path, TD_DIRSEP);
+ tsdbGetCurrentFName(pTsdb, NULL, tfname);
// gnrt CURRENT.t
- code = tsdbGnrtCurrent(pTsdb, pFSNew, tfname);
- if (code) goto _err;
+ code = tsdbSaveFSToFile(pFSNew, tfname);
+ TSDB_CHECK_CODE(code, lino, _exit);
- // rename
- code = taosRenameFile(tfname, fname);
+_exit:
if (code) {
- code = TAOS_SYSTEM_ERROR(code);
- goto _err;
+ tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
}
-
- return code;
-
-_err:
- tsdbError("vgId:%d, tsdb fs commit phase 1 failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
- return code;
-}
-
-int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
- int32_t code = 0;
- int32_t nRef;
- char fname[TSDB_FILENAME_LEN];
-
- // del
- if (pFSNew->pDelFile) {
- SDelFile *pDelFile = pTsdb->fs.pDelFile;
-
- if (pDelFile == NULL || (pDelFile->commitID != pFSNew->pDelFile->commitID)) {
- pTsdb->fs.pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile));
- if (pTsdb->fs.pDelFile == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
-
- *pTsdb->fs.pDelFile = *pFSNew->pDelFile;
- pTsdb->fs.pDelFile->nRef = 1;
-
- if (pDelFile) {
- nRef = atomic_sub_fetch_32(&pDelFile->nRef, 1);
- if (nRef == 0) {
- tsdbDelFileName(pTsdb, pDelFile, fname);
- taosRemoveFile(fname);
- taosMemoryFree(pDelFile);
- }
- }
- }
- } else {
- ASSERT(pTsdb->fs.pDelFile == NULL);
- }
-
- // data
- int32_t iOld = 0;
- int32_t iNew = 0;
- while (true) {
- int32_t nOld = taosArrayGetSize(pTsdb->fs.aDFileSet);
- int32_t nNew = taosArrayGetSize(pFSNew->aDFileSet);
- SDFileSet fSet;
- int8_t sameDisk;
-
- if (iOld >= nOld && iNew >= nNew) break;
-
- SDFileSet *pSetOld = (iOld < nOld) ? taosArrayGet(pTsdb->fs.aDFileSet, iOld) : NULL;
- SDFileSet *pSetNew = (iNew < nNew) ? taosArrayGet(pFSNew->aDFileSet, iNew) : NULL;
-
- if (pSetOld && pSetNew) {
- if (pSetOld->fid == pSetNew->fid) {
- goto _merge_old_and_new;
- } else if (pSetOld->fid < pSetNew->fid) {
- goto _remove_old;
- } else {
- goto _add_new;
- }
- } else if (pSetOld) {
- goto _remove_old;
- } else {
- goto _add_new;
- }
-
- _merge_old_and_new:
- sameDisk = ((pSetOld->diskId.level == pSetNew->diskId.level) && (pSetOld->diskId.id == pSetNew->diskId.id));
-
- // head
- fSet.pHeadF = pSetOld->pHeadF;
- if ((!sameDisk) || (pSetOld->pHeadF->commitID != pSetNew->pHeadF->commitID)) {
- pSetOld->pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
- if (pSetOld->pHeadF == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *pSetOld->pHeadF = *pSetNew->pHeadF;
- pSetOld->pHeadF->nRef = 1;
-
- nRef = atomic_sub_fetch_32(&fSet.pHeadF->nRef, 1);
- if (nRef == 0) {
- tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pHeadF, fname);
- (void)taosRemoveFile(fname);
- taosMemoryFree(fSet.pHeadF);
- }
- } else {
- ASSERT(fSet.pHeadF->size == pSetNew->pHeadF->size);
- ASSERT(fSet.pHeadF->offset == pSetNew->pHeadF->offset);
- }
-
- // data
- fSet.pDataF = pSetOld->pDataF;
- if ((!sameDisk) || (pSetOld->pDataF->commitID != pSetNew->pDataF->commitID)) {
- pSetOld->pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile));
- if (pSetOld->pDataF == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *pSetOld->pDataF = *pSetNew->pDataF;
- pSetOld->pDataF->nRef = 1;
-
- nRef = atomic_sub_fetch_32(&fSet.pDataF->nRef, 1);
- if (nRef == 0) {
- tsdbDataFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pDataF, fname);
- taosRemoveFile(fname);
- taosMemoryFree(fSet.pDataF);
- }
- } else {
- ASSERT(pSetOld->pDataF->size <= pSetNew->pDataF->size);
- pSetOld->pDataF->size = pSetNew->pDataF->size;
- }
-
- // sma
- fSet.pSmaF = pSetOld->pSmaF;
- if ((!sameDisk) || (pSetOld->pSmaF->commitID != pSetNew->pSmaF->commitID)) {
- pSetOld->pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
- if (pSetOld->pSmaF == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *pSetOld->pSmaF = *pSetNew->pSmaF;
- pSetOld->pSmaF->nRef = 1;
-
- nRef = atomic_sub_fetch_32(&fSet.pSmaF->nRef, 1);
- if (nRef == 0) {
- tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pSmaF, fname);
- (void)taosRemoveFile(fname);
- taosMemoryFree(fSet.pSmaF);
- }
- } else {
- ASSERT(pSetOld->pSmaF->size <= pSetNew->pSmaF->size);
- pSetOld->pSmaF->size = pSetNew->pSmaF->size;
- }
-
- // stt
- if (sameDisk) {
- if (pSetNew->nSttF > pSetOld->nSttF) {
- ASSERT(pSetNew->nSttF == pSetOld->nSttF + 1);
- pSetOld->aSttF[pSetOld->nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
- if (pSetOld->aSttF[pSetOld->nSttF] == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *pSetOld->aSttF[pSetOld->nSttF] = *pSetNew->aSttF[pSetOld->nSttF];
- pSetOld->aSttF[pSetOld->nSttF]->nRef = 1;
- pSetOld->nSttF++;
- } else if (pSetNew->nSttF < pSetOld->nSttF) {
- ASSERT(pSetNew->nSttF == 1);
- for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
- SSttFile *pSttFile = pSetOld->aSttF[iStt];
- nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
- if (nRef == 0) {
- tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
- taosRemoveFile(fname);
- taosMemoryFree(pSttFile);
- }
- pSetOld->aSttF[iStt] = NULL;
- }
-
- pSetOld->nSttF = 1;
- pSetOld->aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
- if (pSetOld->aSttF[0] == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *pSetOld->aSttF[0] = *pSetNew->aSttF[0];
- pSetOld->aSttF[0]->nRef = 1;
- } else {
- for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
- if (pSetOld->aSttF[iStt]->commitID != pSetNew->aSttF[iStt]->commitID) {
- SSttFile *pSttFile = pSetOld->aSttF[iStt];
- nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
- if (nRef == 0) {
- tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
- taosRemoveFile(fname);
- taosMemoryFree(pSttFile);
- }
-
- pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
- if (pSetOld->aSttF[iStt] == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt];
- pSetOld->aSttF[iStt]->nRef = 1;
- } else {
- ASSERT(pSetOld->aSttF[iStt]->size == pSetOld->aSttF[iStt]->size);
- ASSERT(pSetOld->aSttF[iStt]->offset == pSetOld->aSttF[iStt]->offset);
- }
- }
- }
- } else {
- ASSERT(pSetOld->nSttF == pSetNew->nSttF);
- for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
- SSttFile *pSttFile = pSetOld->aSttF[iStt];
- nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
- if (nRef == 0) {
- tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
- taosRemoveFile(fname);
- taosMemoryFree(pSttFile);
- }
-
- pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
- if (pSetOld->aSttF[iStt] == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt];
- pSetOld->aSttF[iStt]->nRef = 1;
- }
- }
-
- if (!sameDisk) {
- pSetOld->diskId = pSetNew->diskId;
- }
-
- iOld++;
- iNew++;
- continue;
-
- _remove_old:
- nRef = atomic_sub_fetch_32(&pSetOld->pHeadF->nRef, 1);
- if (nRef == 0) {
- tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pHeadF, fname);
- (void)taosRemoveFile(fname);
- taosMemoryFree(pSetOld->pHeadF);
- }
-
- nRef = atomic_sub_fetch_32(&pSetOld->pDataF->nRef, 1);
- if (nRef == 0) {
- tsdbDataFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pDataF, fname);
- taosRemoveFile(fname);
- taosMemoryFree(pSetOld->pDataF);
- }
-
- nRef = atomic_sub_fetch_32(&pSetOld->pSmaF->nRef, 1);
- if (nRef == 0) {
- tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pSmaF, fname);
- taosRemoveFile(fname);
- taosMemoryFree(pSetOld->pSmaF);
- }
-
- for (int8_t iStt = 0; iStt < pSetOld->nSttF; iStt++) {
- nRef = atomic_sub_fetch_32(&pSetOld->aSttF[iStt]->nRef, 1);
- if (nRef == 0) {
- tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->aSttF[iStt], fname);
- taosRemoveFile(fname);
- taosMemoryFree(pSetOld->aSttF[iStt]);
- }
- }
-
- taosArrayRemove(pTsdb->fs.aDFileSet, iOld);
- continue;
-
- _add_new:
- fSet = (SDFileSet){.diskId = pSetNew->diskId, .fid = pSetNew->fid, .nSttF = 1};
-
- // head
- fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile));
- if (fSet.pHeadF == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *fSet.pHeadF = *pSetNew->pHeadF;
- fSet.pHeadF->nRef = 1;
-
- // data
- fSet.pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile));
- if (fSet.pDataF == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *fSet.pDataF = *pSetNew->pDataF;
- fSet.pDataF->nRef = 1;
-
- // sma
- fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile));
- if (fSet.pSmaF == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *fSet.pSmaF = *pSetNew->pSmaF;
- fSet.pSmaF->nRef = 1;
-
- // stt
- ASSERT(pSetNew->nSttF == 1);
- fSet.aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile));
- if (fSet.aSttF[0] == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- *fSet.aSttF[0] = *pSetNew->aSttF[0];
- fSet.aSttF[0]->nRef = 1;
-
- if (taosArrayInsert(pTsdb->fs.aDFileSet, iOld, &fSet) == NULL) {
- code = TSDB_CODE_OUT_OF_MEMORY;
- goto _err;
- }
- iOld++;
- iNew++;
- continue;
- }
-
- return code;
-
-_err:
- tsdbError("vgId:%d, tsdb fs commit phase 2 failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
return code;
}
@@ -1123,7 +1102,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
ASSERT(nRef >= 0);
if (nRef == 0) {
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
- taosRemoveFile(fname);
+ (void)taosRemoveFile(fname);
taosMemoryFree(pSet->pDataF);
}
@@ -1132,7 +1111,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
ASSERT(nRef >= 0);
if (nRef == 0) {
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
- taosRemoveFile(fname);
+ (void)taosRemoveFile(fname);
taosMemoryFree(pSet->pSmaF);
}
@@ -1142,7 +1121,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
ASSERT(nRef >= 0);
if (nRef == 0) {
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
- taosRemoveFile(fname);
+ (void)taosRemoveFile(fname);
taosMemoryFree(pSet->aSttF[iStt]);
/* code */
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c
index 5197823490..efc74b68ba 100644
--- a/source/dnode/vnode/src/tsdb/tsdbOpen.c
+++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c
@@ -33,7 +33,7 @@ int32_t tsdbSetKeepCfg(STsdb *pTsdb, STsdbCfg *pCfg) {
* @param dir
* @return int
*/
-int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKeepCfg) {
+int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKeepCfg, int8_t rollback) {
STsdb *pTsdb = NULL;
int slen = 0;
@@ -66,7 +66,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
}
// open tsdb
- if (tsdbFSOpen(pTsdb) < 0) {
+ if (tsdbFSOpen(pTsdb, rollback) < 0) {
goto _err;
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
index 84b3afe72c..71024408c1 100644
--- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
@@ -1334,8 +1334,8 @@ int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb
_exit:
if (code) {
if (pDelFWriter) {
- taosMemoryFree(pDelFWriter);
tsdbCloseFile(&pDelFWriter->pWriteH);
+ taosMemoryFree(pDelFWriter);
}
*ppWriter = NULL;
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(errno));
diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c
index 2c68c57176..259c30d591 100644
--- a/source/dnode/vnode/src/tsdb/tsdbRetention.c
+++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c
@@ -86,12 +86,12 @@ int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) {
}
// do change fs
- code = tsdbFSCommit1(pTsdb, &fs);
+ code = tsdbFSPrepareCommit(pTsdb, &fs);
if (code) goto _err;
taosThreadRwlockWrlock(&pTsdb->rwLock);
- code = tsdbFSCommit2(pTsdb, &fs);
+ code = tsdbFSCommit(pTsdb);
if (code) {
taosThreadRwlockUnlock(&pTsdb->rwLock);
goto _err;
diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c
index 74c704598d..f9d9349a1c 100644
--- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c
+++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c
@@ -517,8 +517,8 @@ int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type
_exit:
if (code) {
- tsdbError("vgId:%d %s failed at line %d since %s, TSDB path: %s", TD_VID(pTsdb->pVnode), lino, tstrerror(code),
- pTsdb->path);
+ tsdbError("vgId:%d %s failed at line %d since %s, TSDB path: %s", TD_VID(pTsdb->pVnode), __func__, lino,
+ tstrerror(code), pTsdb->path);
*ppReader = NULL;
if (pReader) {
@@ -1380,13 +1380,13 @@ int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback) {
code = tsdbSnapWriteDelEnd(pWriter);
if (code) goto _err;
- code = tsdbFSCommit1(pWriter->pTsdb, &pWriter->fs);
+ code = tsdbFSPrepareCommit(pWriter->pTsdb, &pWriter->fs);
if (code) goto _err;
// lock
taosThreadRwlockWrlock(&pTsdb->rwLock);
- code = tsdbFSCommit2(pWriter->pTsdb, &pWriter->fs);
+ code = tsdbFSCommit(pWriter->pTsdb);
if (code) {
taosThreadRwlockUnlock(&pTsdb->rwLock);
goto _err;
diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c
index 07c4c32955..24b678b5eb 100644
--- a/source/dnode/vnode/src/vnd/vnodeCommit.c
+++ b/source/dnode/vnode/src/vnd/vnodeCommit.c
@@ -20,8 +20,6 @@
static int vnodeEncodeInfo(const SVnodeInfo *pInfo, char **ppData);
static int vnodeDecodeInfo(uint8_t *pData, SVnodeInfo *pInfo);
-static int vnodeStartCommit(SVnode *pVnode);
-static int vnodeEndCommit(SVnode *pVnode);
static int vnodeCommitImpl(void *arg);
static void vnodeWaitCommit(SVnode *pVnode);
@@ -215,6 +213,8 @@ int vnodeSyncCommit(SVnode *pVnode) {
}
int vnodeCommit(SVnode *pVnode) {
+ int32_t code = 0;
+ int32_t lino = 0;
SVnodeInfo info = {0};
char dir[TSDB_FILENAME_LEN];
@@ -234,15 +234,13 @@ int vnodeCommit(SVnode *pVnode) {
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
}
if (vnodeSaveInfo(dir, &info) < 0) {
- vError("vgId:%d, failed to save vnode info since %s", TD_VID(pVnode), tstrerror(terrno));
- return -1;
+ code = terrno;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
walBeginSnapshot(pVnode->pWal, pVnode->state.applied);
- // preCommit
- // smaSyncPreCommit(pVnode->pSma);
- if(smaAsyncPreCommit(pVnode->pSma) < 0){
- vError("vgId:%d, failed to async pre-commit sma since %s", TD_VID(pVnode), tstrerror(terrno));
+ if (smaPreCommit(pVnode->pSma) < 0) {
+ vError("vgId:%d, failed to pre-commit sma since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
@@ -251,64 +249,73 @@ int vnodeCommit(SVnode *pVnode) {
// commit each sub-system
if (metaCommit(pVnode->pMeta) < 0) {
- vError("vgId:%d, failed to commit meta since %s", TD_VID(pVnode), tstrerror(terrno));
- return -1;
+ code = TSDB_CODE_FAILED;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
if (VND_IS_RSMA(pVnode)) {
- if (smaAsyncCommit(pVnode->pSma) < 0) {
- vError("vgId:%d, failed to async commit sma since %s", TD_VID(pVnode), tstrerror(terrno));
- return -1;
- }
-
- if (tsdbCommit(VND_RSMA0(pVnode)) < 0) {
- vError("vgId:%d, failed to commit tsdb rsma0 since %s", TD_VID(pVnode), tstrerror(terrno));
- return -1;
- }
- if (tsdbCommit(VND_RSMA1(pVnode)) < 0) {
- vError("vgId:%d, failed to commit tsdb rsma1 since %s", TD_VID(pVnode), tstrerror(terrno));
- return -1;
- }
- if (tsdbCommit(VND_RSMA2(pVnode)) < 0) {
- vError("vgId:%d, failed to commit tsdb rsma2 since %s", TD_VID(pVnode), tstrerror(terrno));
+ if (smaCommit(pVnode->pSma) < 0) {
+ vError("vgId:%d, failed to commit sma since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
} else {
- if (tsdbCommit(pVnode->pTsdb) < 0) {
- vError("vgId:%d, failed to commit tsdb since %s", TD_VID(pVnode), tstrerror(terrno));
- return -1;
- }
+ code = tsdbCommit(pVnode->pTsdb);
+ TSDB_CHECK_CODE(code, lino, _exit);
}
if (tqCommit(pVnode->pTq) < 0) {
- vError("vgId:%d, failed to commit tq since %s", TD_VID(pVnode), tstrerror(terrno));
- return -1;
+ code = TSDB_CODE_FAILED;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
- // walCommit (TODO)
// commit info
if (vnodeCommitInfo(dir, &info) < 0) {
- vError("vgId:%d, failed to commit vnode info since %s", TD_VID(pVnode), tstrerror(terrno));
- return -1;
+ code = terrno;
+ TSDB_CHECK_CODE(code, lino, _exit);
+ }
+
+ tsdbFinishCommit(pVnode->pTsdb);
+
+ if (metaFinishCommit(pVnode->pMeta) < 0) {
+ code = terrno;
+ TSDB_CHECK_CODE(code, lino, _exit);
}
pVnode->state.committed = info.state.committed;
- // postCommit
- // smaSyncPostCommit(pVnode->pSma);
- if (smaAsyncPostCommit(pVnode->pSma) < 0) {
- vError("vgId:%d, failed to async post-commit sma since %s", TD_VID(pVnode), tstrerror(terrno));
+ if (smaPostCommit(pVnode->pSma) < 0) {
+ vError("vgId:%d, failed to post-commit sma since %s", TD_VID(pVnode), tstrerror(terrno));
return -1;
}
// apply the commit (TODO)
walEndSnapshot(pVnode->pWal);
- vInfo("vgId:%d, commit end", TD_VID(pVnode));
-
+_exit:
+ if (code) {
+ vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
+ } else {
+ vInfo("vgId:%d, commit end", TD_VID(pVnode));
+ }
return 0;
}
+bool vnodeShouldRollback(SVnode *pVnode) {
+ char tFName[TSDB_FILENAME_LEN] = {0};
+ snprintf(tFName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP,
+ VND_INFO_FNAME_TMP);
+
+ return taosCheckExistFile(tFName);
+}
+
+void vnodeRollback(SVnode *pVnode) {
+ char tFName[TSDB_FILENAME_LEN] = {0};
+ snprintf(tFName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP,
+ VND_INFO_FNAME_TMP);
+
+ (void)taosRemoveFile(tFName);
+}
+
static int vnodeCommitImpl(void *arg) {
SVnode *pVnode = (SVnode *)arg;
@@ -321,16 +328,6 @@ static int vnodeCommitImpl(void *arg) {
return 0;
}
-static int vnodeStartCommit(SVnode *pVnode) {
- // TODO
- return 0;
-}
-
-static int vnodeEndCommit(SVnode *pVnode) {
- // TODO
- return 0;
-}
-
static FORCE_INLINE void vnodeWaitCommit(SVnode *pVnode) { tsem_wait(&pVnode->canCommit); }
static int vnodeEncodeState(const void *pObj, SJson *pJson) {
diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c
index 001bb5f7f2..3dbd93bb27 100644
--- a/source/dnode/vnode/src/vnd/vnodeOpen.c
+++ b/source/dnode/vnode/src/vnd/vnodeOpen.c
@@ -110,6 +110,8 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
taosThreadMutexInit(&pVnode->mutex, NULL);
taosThreadCondInit(&pVnode->poolNotEmpty, NULL);
+ int8_t rollback = vnodeShouldRollback(pVnode);
+
// open buffer pool
if (vnodeOpenBufPool(pVnode) < 0) {
vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
@@ -117,19 +119,19 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
}
// open meta
- if (metaOpen(pVnode, &pVnode->pMeta) < 0) {
+ if (metaOpen(pVnode, &pVnode->pMeta, rollback) < 0) {
vError("vgId:%d, failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open tsdb
- if (!VND_IS_RSMA(pVnode) && tsdbOpen(pVnode, &VND_TSDB(pVnode), VNODE_TSDB_DIR, NULL) < 0) {
+ if (!VND_IS_RSMA(pVnode) && tsdbOpen(pVnode, &VND_TSDB(pVnode), VNODE_TSDB_DIR, NULL, rollback) < 0) {
vError("vgId:%d, failed to open vnode tsdb since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
// open sma
- if (smaOpen(pVnode)) {
+ if (smaOpen(pVnode, rollback)) {
vError("vgId:%d, failed to open vnode sma since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
@@ -153,14 +155,12 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
goto _err;
}
-#if !VNODE_AS_LIB
// open query
if (vnodeQueryOpen(pVnode)) {
vError("vgId:%d, failed to open vnode query since %s", TD_VID(pVnode), tstrerror(terrno));
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
}
-#endif
// vnode begin
if (vnodeBegin(pVnode) < 0) {
@@ -169,13 +169,15 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
goto _err;
}
-#if !VNODE_AS_LIB
// open sync
if (vnodeSyncOpen(pVnode, dir)) {
vError("vgId:%d, failed to open sync since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}
-#endif
+
+ if (rollback) {
+ vnodeRollback(pVnode);
+ }
return pVnode;
diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c
index 8c1f858cbb..64df3aa1eb 100644
--- a/source/dnode/vnode/src/vnd/vnodeQuery.c
+++ b/source/dnode/vnode/src/vnd/vnodeQuery.c
@@ -330,6 +330,11 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
rspSize += sizeof(int32_t);
offset = 0;
+ if (rspSize > MAX_META_BATCH_RSP_SIZE) {
+ code = TSDB_CODE_INVALID_MSG_LEN;
+ goto _exit;
+ }
+
pRsp = rpcMallocCont(rspSize);
if (pRsp == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c
index d0a00a8b6d..4dbefd659c 100644
--- a/source/dnode/vnode/src/vnd/vnodeSvr.c
+++ b/source/dnode/vnode/src/vnd/vnodeSvr.c
@@ -53,7 +53,10 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
for (int32_t iReq = 0; iReq < nReqs; iReq++) {
tb_uid_t uid = tGenIdPI64();
char *name = NULL;
- tStartDecode(&dc);
+ if (tStartDecode(&dc) < 0) {
+ code = TSDB_CODE_INVALID_MSG;
+ goto _err;
+ }
if (tDecodeI32v(&dc, NULL) < 0) {
code = TSDB_CODE_INVALID_MSG;
diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c
index ab7fb001f0..44eee79574 100644
--- a/source/dnode/vnode/src/vnd/vnodeSync.c
+++ b/source/dnode/vnode/src/vnd/vnodeSync.c
@@ -323,6 +323,49 @@ void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
}
}
+int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
+ int32_t code = 0;
+ const STraceId *trace = &pMsg->info.traceId;
+
+ if (!syncEnvIsStart()) {
+ vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId);
+ terrno = TSDB_CODE_APP_ERROR;
+ return -1;
+ }
+
+ SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync);
+ if (pSyncNode == NULL) {
+ vGError("vgId:%d, msg:%p failed to process since invalid sync node", pVnode->config.vgId);
+ terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
+ return -1;
+ }
+
+ vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
+
+ if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) {
+ SyncHeartbeat *pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg);
+ code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg);
+ syncHeartbeatDestroy(pSyncMsg);
+
+ } else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) {
+ SyncHeartbeatReply *pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg);
+ code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg);
+ syncHeartbeatReplyDestroy(pSyncMsg);
+
+ } else {
+ vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg->msgType);
+ code = -1;
+ }
+
+ vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType),
+ code);
+ syncNodeRelease(pSyncNode);
+ if (code != 0 && terrno == 0) {
+ terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
+ }
+ return code;
+}
+
int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
int32_t code = 0;
const STraceId *trace = &pMsg->info.traceId;
diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h
index fe71987103..0786321686 100644
--- a/source/libs/catalog/inc/catalogInt.h
+++ b/source/libs/catalog/inc/catalogInt.h
@@ -505,6 +505,7 @@ typedef struct SCtgOperation {
#define CTG_FLAG_UNKNOWN_STB 0x4
#define CTG_FLAG_SYS_DB 0x8
#define CTG_FLAG_FORCE_UPDATE 0x10
+#define CTG_FLAG_ONLY_CACHE 0x20
#define CTG_FLAG_SET(_flag, _v) ((_flag) |= (_v))
@@ -783,7 +784,7 @@ void ctgFreeQNode(SCtgQNode* node);
void ctgClearHandle(SCatalog* pCtg);
void ctgFreeTbCacheImpl(SCtgTbCache* pCache);
int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName);
-int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup);
+int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists);
SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch);
extern SCatalogMgmt gCtgMgmt;
diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c
index b960103d94..5997f63a16 100644
--- a/source/libs/catalog/src/catalog.c
+++ b/source/libs/catalog/src/catalog.c
@@ -23,12 +23,21 @@
SCatalogMgmt gCtgMgmt = {0};
int32_t ctgGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SCtgDBCache** dbCache,
- SDBVgInfo** pInfo) {
+ SDBVgInfo** pInfo, bool* exists) {
int32_t code = 0;
CTG_ERR_RET(ctgAcquireVgInfoFromCache(pCtg, dbFName, dbCache));
if (*dbCache) {
+ if (exists) {
+ *exists = true;
+ }
+
+ return TSDB_CODE_SUCCESS;
+ }
+
+ if (exists) {
+ *exists = false;
return TSDB_CODE_SUCCESS;
}
@@ -94,7 +103,7 @@ int32_t ctgRefreshTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx*
int32_t code = 0;
if (!CTG_FLAG_IS_SYS_DB(ctx->flag)) {
- CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, ctx->pName, &vgroupInfo));
+ CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, ctx->pName, &vgroupInfo, NULL));
}
STableMetaOutput moutput = {0};
@@ -194,7 +203,7 @@ int32_t ctgGetTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx
STableMetaOutput* output = NULL;
CTG_ERR_RET(ctgGetTbMetaFromCache(pCtg, pConn, ctx, pTableMeta));
- if (*pTableMeta) {
+ if (*pTableMeta || (ctx->flag & CTG_FLAG_ONLY_CACHE)) {
goto _return;
}
@@ -302,9 +311,11 @@ int32_t ctgUpdateTbMeta(SCatalog* pCtg, STableMetaRsp* rspMsg, bool syncOp) {
_return:
- taosMemoryFreeClear(output->tbMeta);
- taosMemoryFreeClear(output);
-
+ if (output) {
+ taosMemoryFreeClear(output->tbMeta);
+ taosMemoryFreeClear(output);
+ }
+
CTG_RET(code);
}
@@ -413,7 +424,7 @@ int32_t ctgGetTbCfg(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName,
CTG_ERR_RET(ctgGetTableCfgFromMnode(pCtg, pConn, pTableName, pCfg, NULL));
} else {
SVgroupInfo vgroupInfo = {0};
- CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, pTableName, &vgroupInfo));
+ CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, pTableName, &vgroupInfo, NULL));
CTG_ERR_RET(ctgGetTableCfgFromVnode(pCtg, pConn, pTableName, &vgroupInfo, pCfg, NULL));
}
@@ -439,7 +450,7 @@ int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTabl
tNameGetFullDbName(pTableName, db);
SHashObj* vgHash = NULL;
- CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo));
+ CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo, NULL));
if (dbCache) {
vgHash = dbCache->vgCache.vgInfo->vgHash;
@@ -499,7 +510,7 @@ _return:
CTG_RET(code);
}
-int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup) {
+int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists) {
if (IS_SYS_DBNAME(pTableName->dbname)) {
ctgError("no valid vgInfo for db, dbname:%s", pTableName->dbname);
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
@@ -511,8 +522,13 @@ int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName*
tNameGetFullDbName(pTableName, db);
SDBVgInfo* vgInfo = NULL;
- CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo));
+ CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo, exists));
+ if (exists && false == *exists) {
+ ctgDebug("db %s vgInfo not in cache", pTableName->dbname);
+ return TSDB_CODE_SUCCESS;
+ }
+
CTG_ERR_JRET(ctgGetVgInfoFromHashValue(pCtg, vgInfo ? vgInfo : dbCache->vgCache.vgInfo, pTableName, pVgroup));
_return:
@@ -735,7 +751,7 @@ int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char*
SArray* vgList = NULL;
SHashObj* vgHash = NULL;
SDBVgInfo* vgInfo = NULL;
- CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, dbFName, &dbCache, &vgInfo));
+ CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, dbFName, &dbCache, &vgInfo, NULL));
if (dbCache) {
vgHash = dbCache->vgCache.vgInfo->vgHash;
} else {
@@ -878,6 +894,17 @@ int32_t catalogGetTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName
CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta));
}
+int32_t catalogGetCachedTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableMeta** pTableMeta) {
+ CTG_API_ENTER();
+
+ SCtgTbMetaCtx ctx = {0};
+ ctx.pName = (SName*)pTableName;
+ ctx.flag = CTG_FLAG_UNKNOWN_STB | CTG_FLAG_ONLY_CACHE;
+
+ CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta));
+}
+
+
int32_t catalogGetSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName,
STableMeta** pTableMeta) {
CTG_API_ENTER();
@@ -889,6 +916,18 @@ int32_t catalogGetSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SNam
CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta));
}
+int32_t catalogGetCachedSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName,
+ STableMeta** pTableMeta) {
+ CTG_API_ENTER();
+
+ SCtgTbMetaCtx ctx = {0};
+ ctx.pName = (SName*)pTableName;
+ ctx.flag = CTG_FLAG_STB | CTG_FLAG_ONLY_CACHE;
+
+ CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta));
+}
+
+
int32_t catalogUpdateTableMeta(SCatalog* pCtg, STableMetaRsp* pMsg) {
CTG_API_ENTER();
@@ -1007,7 +1046,14 @@ int32_t catalogGetTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const
SVgroupInfo* pVgroup) {
CTG_API_ENTER();
- CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup));
+ CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup, NULL));
+}
+
+int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName,
+ SVgroupInfo* pVgroup, bool* exists) {
+ CTG_API_ENTER();
+
+ CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup, exists));
}
int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, SMetaData* pRsp) {
diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c
index 1d2e3640a1..93d36bc4b3 100644
--- a/source/libs/catalog/src/ctgAsync.c
+++ b/source/libs/catalog/src/ctgAsync.c
@@ -252,7 +252,7 @@ int32_t ctgInitGetIndexTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
SCtgIndexCtx* ctx = task.taskCtx;
- strcpy(ctx->indexFName, name);
+ tstrncpy(ctx->indexFName, name, sizeof(ctx->indexFName));
taosArrayPush(pJob->pTasks, &task);
@@ -277,7 +277,7 @@ int32_t ctgInitGetUdfTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
SCtgUdfCtx* ctx = task.taskCtx;
- strcpy(ctx->udfName, name);
+ tstrncpy(ctx->udfName, name, sizeof(ctx->udfName));
taosArrayPush(pJob->pTasks, &task);
diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c
index b3588898e4..1a7a0057ba 100644
--- a/source/libs/catalog/src/ctgCache.c
+++ b/source/libs/catalog/src/ctgCache.c
@@ -660,7 +660,7 @@ int32_t ctgDropDbCacheEnqueue(SCatalog *pCtg, const char *dbFName, int64_t dbId)
}
msg->pCtg = pCtg;
- strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
+ tstrncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
msg->dbId = dbId;
op->data = msg;
@@ -693,7 +693,7 @@ int32_t ctgDropDbVgroupEnqueue(SCatalog *pCtg, const char *dbFName, bool syncOp)
}
msg->pCtg = pCtg;
- strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
+ tstrncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
op->data = msg;
@@ -721,8 +721,8 @@ int32_t ctgDropStbMetaEnqueue(SCatalog *pCtg, const char *dbFName, int64_t dbId,
}
msg->pCtg = pCtg;
- strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
- strncpy(msg->stbName, stbName, sizeof(msg->stbName));
+ tstrncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
+ tstrncpy(msg->stbName, stbName, sizeof(msg->stbName));
msg->dbId = dbId;
msg->suid = suid;
@@ -751,8 +751,8 @@ int32_t ctgDropTbMetaEnqueue(SCatalog *pCtg, const char *dbFName, int64_t dbId,
}
msg->pCtg = pCtg;
- strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
- strncpy(msg->tbName, tbName, sizeof(msg->tbName));
+ tstrncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
+ tstrncpy(msg->tbName, tbName, sizeof(msg->tbName));
msg->dbId = dbId;
op->data = msg;
@@ -785,7 +785,7 @@ int32_t ctgUpdateVgroupEnqueue(SCatalog *pCtg, const char *dbFName, int64_t dbId
dbFName = p + 1;
}
- strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
+ tstrncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
msg->pCtg = pCtg;
msg->dbId = dbId;
msg->dbInfo = dbInfo;
@@ -817,7 +817,8 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog *pCtg, STableMetaOutput *output, bool sy
char *p = strchr(output->dbFName, '.');
if (p && IS_SYS_DBNAME(p + 1)) {
- memmove(output->dbFName, p + 1, strlen(p + 1));
+ int32_t len = strlen(p + 1);
+ memmove(output->dbFName, p + 1, len >= TSDB_DB_FNAME_LEN ? TSDB_DB_FNAME_LEN - 1 : len);
}
msg->pCtg = pCtg;
@@ -852,7 +853,7 @@ int32_t ctgUpdateVgEpsetEnqueue(SCatalog *pCtg, char *dbFName, int32_t vgId, SEp
}
msg->pCtg = pCtg;
- strcpy(msg->dbFName, dbFName);
+ tstrncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
msg->vgId = vgId;
msg->epSet = *pEpSet;
@@ -1215,7 +1216,7 @@ int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
CTG_CACHE_STAT_INC(numOfDb, 1);
SDbVgVersion vgVersion = {.dbId = newDBCache.dbId, .vgVersion = -1};
- strncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName));
+ tstrncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName));
ctgDebug("db added to cache, dbFName:%s, dbId:0x%" PRIx64, dbFName, dbId);
@@ -1331,8 +1332,8 @@ int32_t ctgUpdateRentStbVersion(SCatalog *pCtg, char *dbFName, char *tbName, uin
metaRent.smaVer = pCache->pIndex->version;
}
- strcpy(metaRent.dbFName, dbFName);
- strcpy(metaRent.stbName, tbName);
+ tstrncpy(metaRent.dbFName, dbFName, sizeof(metaRent.dbFName));
+ tstrncpy(metaRent.stbName, tbName, sizeof(metaRent.stbName));
CTG_ERR_RET(ctgMetaRentUpdate(&pCtg->stbRent, &metaRent, metaRent.suid, sizeof(SSTableVersion),
ctgStbVersionSortCompare, ctgStbVersionSearchCompare));
@@ -1418,8 +1419,10 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
ctgDebug("stb 0x%" PRIx64 " updated to cache, dbFName:%s, tbName:%s, tbType:%d", meta->suid, dbFName, tbName,
meta->tableType);
- CTG_ERR_RET(ctgUpdateRentStbVersion(pCtg, dbFName, tbName, dbId, meta->suid, pCache));
-
+ if (pCache) {
+ CTG_ERR_RET(ctgUpdateRentStbVersion(pCtg, dbFName, tbName, dbId, meta->suid, pCache));
+ }
+
return TSDB_CODE_SUCCESS;
}
@@ -1590,7 +1593,7 @@ int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
dbCache = NULL;
- strncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName));
+ tstrncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName));
CTG_ERR_JRET(ctgMetaRentUpdate(&msg->pCtg->dbRent, &vgVersion, vgVersion.dbId, sizeof(SDbVgVersion),
ctgDbVgVersionSortCompare, ctgDbVgVersionSearchCompare));
@@ -1680,9 +1683,9 @@ int32_t ctgOpUpdateTbMeta(SCtgCacheOperation *operation) {
if (CTG_IS_META_TABLE(pMeta->metaType) || CTG_IS_META_BOTH(pMeta->metaType)) {
int32_t metaSize = CTG_META_SIZE(pMeta->tbMeta);
- CTG_ERR_JRET(
- ctgWriteTbMetaToCache(pCtg, dbCache, pMeta->dbFName, pMeta->dbId, pMeta->tbName, pMeta->tbMeta, metaSize));
+ code = ctgWriteTbMetaToCache(pCtg, dbCache, pMeta->dbFName, pMeta->dbId, pMeta->tbName, pMeta->tbMeta, metaSize);
pMeta->tbMeta = NULL;
+ CTG_ERR_JRET(code);
}
if (CTG_IS_META_CTABLE(pMeta->metaType) || CTG_IS_META_BOTH(pMeta->metaType)) {
@@ -1697,10 +1700,8 @@ int32_t ctgOpUpdateTbMeta(SCtgCacheOperation *operation) {
_return:
- if (pMeta) {
- taosMemoryFreeClear(pMeta->tbMeta);
- taosMemoryFreeClear(pMeta);
- }
+ taosMemoryFreeClear(pMeta->tbMeta);
+ taosMemoryFreeClear(pMeta);
taosMemoryFreeClear(msg);
diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c
index c32adb17ae..7e16fa5c80 100644
--- a/source/libs/command/src/command.c
+++ b/source/libs/command/src/command.c
@@ -361,7 +361,12 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
SArray* pTagVals = NULL;
STag* pTag = (STag*)pCfg->pTags;
- if (pCfg->pTags && tTagIsJson(pTag)) {
+ if (NULL == pCfg->pTags || pCfg->numOfTags <= 0) {
+ qError("tag missed in table cfg, pointer:%p, numOfTags:%d", pCfg->pTags, pCfg->numOfTags);
+ return TSDB_CODE_APP_ERROR;
+ }
+
+ if (tTagIsJson(pTag)) {
char* pJson = parseTagDatatoJson(pTag);
if (pJson) {
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s", pJson);
diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h
index fc996a6003..1aa3d55efc 100644
--- a/source/libs/executor/inc/executorimpl.h
+++ b/source/libs/executor/inc/executorimpl.h
@@ -53,6 +53,11 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
#define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData ? 1 : 0)
+#define IS_VALID_SESSION_WIN(winInfo) ((winInfo).sessionWin.win.skey > 0)
+#define SET_SESSION_WIN_INVALID(winInfo) ((winInfo).sessionWin.win.skey = INT64_MIN)
+#define IS_INVALID_SESSION_WIN_KEY(winKey) ((winKey).win.skey <= 0)
+#define SET_SESSION_WIN_KEY_INVALID(pWinKey) ((pWinKey)->win.skey = INT64_MIN)
+
enum {
// when this task starts to execute, this status will set
TASK_NOT_COMPLETED = 0x1u,
@@ -434,15 +439,15 @@ typedef struct SCatchSupporter {
} SCatchSupporter;
typedef struct SStreamAggSupporter {
- SHashObj* pResultRows;
- SArray* pCurWins;
- int32_t valueSize;
- int32_t keySize;
- char* pKeyBuf; // window key buffer
- SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file
- int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
- int32_t currentPageId; // buffer page that is active
- SSDataBlock* pScanBlock;
+ int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
+ SSDataBlock* pScanBlock;
+ SStreamState* pState;
+ int64_t gap; // stream session window gap
+ SqlFunctionCtx* pDummyCtx; // for combine
+ SSHashObj* pResultRows;
+ int32_t stateKeySize;
+ int16_t stateKeyType;
+ SDiskbasedBuf* pResultBuf;
} SStreamAggSupporter;
typedef struct SWindowSupporter {
@@ -736,42 +741,54 @@ typedef struct SSessionAggOperatorInfo {
} SSessionAggOperatorInfo;
typedef struct SResultWindowInfo {
- SResultRowPosition pos;
- STimeWindow win;
- uint64_t groupId;
+ void* pOutputBuf;
+ SSessionKey sessionWin;
bool isOutput;
- bool isClosed;
} SResultWindowInfo;
typedef struct SStateWindowInfo {
SResultWindowInfo winInfo;
- SStateKeys stateKey;
+ SStateKeys* pStateKey;
} SStateWindowInfo;
typedef struct SStreamSessionAggOperatorInfo {
SOptrBasicInfo binfo;
SStreamAggSupporter streamAggSup;
- SExprSupp scalarSupp; // supporter for perform scalar function
+ SExprSupp scalarSupp; // supporter for perform scalar function
SGroupResInfo groupResInfo;
- int64_t gap; // session window gap
int32_t primaryTsIndex; // primary timestamp slot id
int32_t endTsIndex; // window end timestamp slot id
int32_t order; // current SSDataBlock scan order
STimeWindowAggSupp twAggSup;
- SSDataBlock* pWinBlock; // window result
- SqlFunctionCtx* pDummyCtx; // for combine
- SSDataBlock* pDelRes; // delete result
- SSDataBlock* pUpdateRes; // update window
+ SSDataBlock* pWinBlock; // window result
+ SSDataBlock* pDelRes; // delete result
+ SSDataBlock* pUpdateRes; // update window
bool returnUpdate;
- SHashObj* pStDeleted;
+ SSHashObj* pStDeleted;
void* pDelIterator;
- SArray* pChildren; // cache for children's result; final stream operator
- SPhysiNode* pPhyNode; // create new child
+ SArray* pChildren; // cache for children's result; final stream operator
+ SPhysiNode* pPhyNode; // create new child
bool isFinal;
bool ignoreExpiredData;
SHashObj* pGroupIdTbNameMap;
} SStreamSessionAggOperatorInfo;
+typedef struct SStreamStateAggOperatorInfo {
+ SOptrBasicInfo binfo;
+ SStreamAggSupporter streamAggSup;
+ SExprSupp scalarSupp; // supporter for perform scalar function
+ SGroupResInfo groupResInfo;
+ int32_t primaryTsIndex; // primary timestamp slot id
+ STimeWindowAggSupp twAggSup;
+ SColumn stateCol;
+ SSDataBlock* pDelRes;
+ SSHashObj* pSeDeleted;
+ void* pDelIterator;
+ SArray* pChildren; // cache for children's result;
+ bool ignoreExpiredData;
+ SHashObj* pGroupIdTbNameMap;
+} SStreamStateAggOperatorInfo;
+
typedef struct SStreamPartitionOperatorInfo {
SOptrBasicInfo binfo;
SPartitionBySupporter partitionSup;
@@ -834,24 +851,6 @@ typedef struct SStateWindowOperatorInfo {
const SNode* pCondition;
} SStateWindowOperatorInfo;
-typedef struct SStreamStateAggOperatorInfo {
- SOptrBasicInfo binfo;
- SStreamAggSupporter streamAggSup;
- SExprSupp scalarSupp; // supporter for perform scalar function
- SGroupResInfo groupResInfo;
- int32_t primaryTsIndex; // primary timestamp slot id
- int32_t order; // current SSDataBlock scan order
- STimeWindowAggSupp twAggSup;
- SColumn stateCol;
- SqlFunctionCtx* pDummyCtx; // for combine
- SSDataBlock* pDelRes;
- SHashObj* pSeDeleted;
- void* pDelIterator;
- SArray* pChildren; // cache for children's result;
- bool ignoreExpiredData;
- SHashObj* pGroupIdTbNameMap;
-} SStreamStateAggOperatorInfo;
-
typedef struct SSortOperatorInfo {
SOptrBasicInfo binfo;
uint32_t sortBufSize; // max buffer size for in-memory sort
@@ -1064,13 +1063,8 @@ STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowI
int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimaryColumn, int32_t startPos, TSKEY ekey,
__block_search_fn_t searchFn, STableQueryInfo* item, int32_t order);
int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
-int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx, int32_t numOfOutput,
- int32_t size);
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize);
-SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId,
- int64_t gap, int32_t* pIndex);
-SResultWindowInfo* getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId,
- int64_t gap, int32_t* pIndex);
+void getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId, SSessionKey* pKey);
bool isInTimeWindow(STimeWindow* pWin, TSKEY ts, int64_t gap);
bool functionNeedToExecute(SqlFunctionCtx* pCtx);
bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup);
@@ -1100,6 +1094,9 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput);
int32_t buildDataBlockFromGroupRes(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock, SExprSupp* pSup,
SGroupResInfo* pGroupResInfo);
+int32_t saveSessionDiscBuf(SStreamState* pState, SSessionKey* key, void* buf, int32_t size);
+int32_t buildSessionResultDataBlock(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock,
+ SExprSupp* pSup, SGroupResInfo* pGroupResInfo);
int32_t setOutputBuf(SStreamState* pState, STimeWindow* win, SResultRow** pResult, int64_t tableGroupId, SqlFunctionCtx* pCtx,
int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup);
int32_t releaseOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResult);
diff --git a/source/libs/executor/src/dataDeleter.c b/source/libs/executor/src/dataDeleter.c
index 55978855d1..a462d9d61d 100644
--- a/source/libs/executor/src/dataDeleter.c
+++ b/source/libs/executor/src/dataDeleter.c
@@ -150,9 +150,15 @@ static int32_t getStatus(SDataDeleterHandle* pDeleter) {
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle;
SDataDeleterBuf* pBuf = taosAllocateQitem(sizeof(SDataDeleterBuf), DEF_QITEM);
- if (NULL == pBuf || !allocBuf(pDeleter, pInput, pBuf)) {
+ if (NULL == pBuf) {
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
+
+ if (!allocBuf(pDeleter, pInput, pBuf)) {
+ taosFreeQitem(pBuf);
+ return TSDB_CODE_QRY_OUT_OF_MEMORY;
+ }
+
toDataCacheEntry(pDeleter, pInput, pBuf);
taosWriteQitem(pDeleter->pDataBlocks, pBuf);
*pContinue = (DS_BUF_LOW == updateStatus(pDeleter) ? true : false);
@@ -177,6 +183,7 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE
SDataDeleterBuf* pBuf = NULL;
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
+ ASSERT(NULL != pBuf);
memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf));
taosFreeQitem(pBuf);
diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c
index 0b5c8372f1..ffdcf48d48 100644
--- a/source/libs/executor/src/dataDispatcher.c
+++ b/source/libs/executor/src/dataDispatcher.c
@@ -143,9 +143,15 @@ static int32_t getStatus(SDataDispatchHandle* pDispatcher) {
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
SDataDispatchBuf* pBuf = taosAllocateQitem(sizeof(SDataDispatchBuf), DEF_QITEM);
- if (NULL == pBuf || !allocBuf(pDispatcher, pInput, pBuf)) {
+ if (NULL == pBuf) {
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
+
+ if (!allocBuf(pDispatcher, pInput, pBuf)) {
+ taosFreeQitem(pBuf);
+ return TSDB_CODE_QRY_OUT_OF_MEMORY;
+ }
+
toDataCacheEntry(pDispatcher, pInput, pBuf);
taosWriteQitem(pDispatcher->pDataBlocks, pBuf);
*pContinue = (DS_BUF_LOW == updateStatus(pDispatcher) ? true : false);
diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c
index 4c4ba59fa9..d996634d8e 100644
--- a/source/libs/executor/src/dataInserter.c
+++ b/source/libs/executor/src/dataInserter.c
@@ -323,7 +323,8 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat
int32_t code =
tsdbGetTableSchema(inserter->pParam->readHandle->vnode, pInserterNode->tableId, &inserter->pSchema, &suid);
if (code) {
- destroyDataSinker((SDataSinkHandle*)pInserterNode);
+ destroyDataSinker((SDataSinkHandle*)inserter);
+ taosMemoryFree(inserter);
return code;
}
diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c
index a7e98527f4..ea91cc06c8 100644
--- a/source/libs/executor/src/executorimpl.c
+++ b/source/libs/executor/src/executorimpl.c
@@ -569,6 +569,7 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc
}
pResult->info.groupId = pSrcBlock->info.groupId;
+ memcpy(pResult->info.parTbName, pSrcBlock->info.parTbName, TSDB_TABLE_NAME_LEN);
// if the source equals to the destination, it is to create a new column as the result of scalar
// function or some operators.
@@ -4192,42 +4193,6 @@ int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SArray* pExecInf
return TSDB_CODE_SUCCESS;
}
-int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx, int32_t numOfOutput,
- int32_t size) {
- pSup->currentPageId = -1;
- pSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
- pSup->keySize = sizeof(int64_t) + sizeof(TSKEY);
- pSup->pKeyBuf = taosMemoryCalloc(1, pSup->keySize);
- _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
- pSup->pResultRows = taosHashInit(1024, hashFn, false, HASH_NO_LOCK);
- if (pSup->pKeyBuf == NULL || pSup->pResultRows == NULL) {
- return TSDB_CODE_OUT_OF_MEMORY;
- }
- pSup->valueSize = size;
-
- pSup->pScanBlock = createSpecialDataBlock(STREAM_CLEAR);
- int32_t pageSize = 4096;
- while (pageSize < pSup->resultRowSize * 4) {
- pageSize <<= 1u;
- }
- // at least four pages need to be in buffer
- int32_t bufSize = 4096 * 256;
- if (bufSize <= pageSize) {
- bufSize = pageSize * 4;
- }
- if (!osTempSpaceAvailable()) {
- terrno = TSDB_CODE_NO_AVAIL_DISK;
- qError("Init stream agg supporter failed since %s", terrstr(terrno));
- return terrno;
- }
- int32_t code = createDiskbasedBuf(&pSup->pResultBuf, pageSize, bufSize, pKey, tsTempDir);
- for (int32_t i = 0; i < numOfOutput; ++i) {
- pCtx[i].saveHandle.pBuf = pSup->pResultBuf;
- }
-
- return code;
-}
-
int32_t setOutputBuf(SStreamState* pState, STimeWindow* win, SResultRow** pResult, int64_t tableGroupId,
SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup) {
SWinKey key = {
@@ -4237,7 +4202,6 @@ int32_t setOutputBuf(SStreamState* pState, STimeWindow* win, SResultRow** pResul
char* value = NULL;
int32_t size = pAggSup->resultRowSize;
- tSimpleHashPut(pAggSup->pResultRowHashTable, &key, sizeof(SWinKey), NULL, 0);
if (streamStateAddIfNotExist(pState, &key, (void**)&value, &size) < 0) {
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
@@ -4342,3 +4306,108 @@ int32_t buildDataBlockFromGroupRes(SOperatorInfo* pOperator, SStreamState* pStat
blockDataUpdateTsWindow(pBlock, 0);
return TSDB_CODE_SUCCESS;
}
+
+int32_t saveSessionDiscBuf(SStreamState* pState, SSessionKey* key, void* buf, int32_t size) {
+ streamStateSessionPut(pState, key, (const void*)buf, size);
+ releaseOutputBuf(pState, NULL, (SResultRow*)buf);
+ return TSDB_CODE_SUCCESS;
+}
+
+int32_t buildSessionResultDataBlock(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock,
+ SExprSupp* pSup, SGroupResInfo* pGroupResInfo) {
+ SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
+ SExprInfo* pExprInfo = pSup->pExprInfo;
+ int32_t numOfExprs = pSup->numOfExprs;
+ int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
+ SqlFunctionCtx* pCtx = pSup->pCtx;
+
+ int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
+
+ for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
+ SSessionKey* pKey = taosArrayGet(pGroupResInfo->pRows, i);
+ int32_t size = 0;
+ void* pVal = NULL;
+ int32_t code = streamStateSessionGet(pState, pKey, &pVal, &size);
+ ASSERT(code == 0);
+ SResultRow* pRow = (SResultRow*)pVal;
+ doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
+ // no results, continue to check the next one
+ if (pRow->numOfRows == 0) {
+ pGroupResInfo->index += 1;
+ releaseOutputBuf(pState, NULL, pRow);
+ continue;
+ }
+
+ if (pBlock->info.groupId == 0) {
+ pBlock->info.groupId = pKey->groupId;
+
+ if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) {
+ SStreamStateAggOperatorInfo* pInfo = pOperator->info;
+
+ char* tbname = taosHashGet(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t));
+ if (tbname != NULL) {
+ memcpy(pBlock->info.parTbName, tbname, TSDB_TABLE_NAME_LEN);
+ } else {
+ pBlock->info.parTbName[0] = 0;
+ }
+ } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION ||
+ pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
+ pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
+ SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
+
+ char* tbname = taosHashGet(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t));
+ if (tbname != NULL) {
+ memcpy(pBlock->info.parTbName, tbname, TSDB_TABLE_NAME_LEN);
+ } else {
+ pBlock->info.parTbName[0] = 0;
+ }
+ } else {
+ ASSERT(0);
+ }
+
+ } else {
+ // current value belongs to different group, it can't be packed into one datablock
+ if (pBlock->info.groupId != pKey->groupId) {
+ releaseOutputBuf(pState, NULL, pRow);
+ break;
+ }
+ }
+
+ if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
+ ASSERT(pBlock->info.rows > 0);
+ releaseOutputBuf(pState, NULL, pRow);
+ break;
+ }
+
+ pGroupResInfo->index += 1;
+
+ for (int32_t j = 0; j < numOfExprs; ++j) {
+ int32_t slotId = pExprInfo[j].base.resSchema.slotId;
+
+ pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
+ if (pCtx[j].fpSet.finalize) {
+ int32_t code1 = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
+ if (TAOS_FAILED(code1)) {
+ qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code1));
+ T_LONG_JMP(pTaskInfo->env, code1);
+ }
+ } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
+ // do nothing, todo refactor
+ } else {
+ // expand the result into multiple rows. E.g., _wstart, top(k, 20)
+ // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
+ SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
+ char* in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
+ for (int32_t k = 0; k < pRow->numOfRows; ++k) {
+ colDataAppend(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
+ }
+ }
+ }
+
+ pBlock->info.rows += pRow->numOfRows;
+ // saveSessionDiscBuf(pState, pKey, pVal, size);
+ releaseOutputBuf(pState, NULL, pRow);
+ }
+ blockDataUpdateTsWindow(pBlock, 0);
+ return TSDB_CODE_SUCCESS;
+}
diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c
index 8e1858d8c0..7385e9bb92 100644
--- a/source/libs/executor/src/scanoperator.c
+++ b/source/libs/executor/src/scanoperator.c
@@ -1190,23 +1190,22 @@ static int32_t generateSessionScanRange(SStreamScanInfo* pInfo, SSDataBlock* pSr
SColumnInfoData* pDestGpCol = taosArrayGet(pDestBlock->pDataBlock, GROUPID_COLUMN_INDEX);
SColumnInfoData* pDestCalStartTsCol = taosArrayGet(pDestBlock->pDataBlock, CALCULATE_START_TS_COLUMN_INDEX);
SColumnInfoData* pDestCalEndTsCol = taosArrayGet(pDestBlock->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX);
- int32_t dummy = 0;
int64_t version = pSrcBlock->info.version - 1;
for (int32_t i = 0; i < pSrcBlock->info.rows; i++) {
uint64_t groupId = getGroupIdByData(pInfo, uidCol[i], startData[i], version);
// gap must be 0.
- SResultWindowInfo* pStartWin =
- getCurSessionWindow(pInfo->windowSup.pStreamAggSup, startData[i], endData[i], groupId, 0, &dummy);
- if (!pStartWin) {
+ SSessionKey startWin = {0};
+ getCurSessionWindow(pInfo->windowSup.pStreamAggSup, startData[i], endData[i], groupId, &startWin);
+ if (IS_INVALID_SESSION_WIN_KEY(startWin)) {
// window has been closed.
continue;
}
- SResultWindowInfo* pEndWin =
- getCurSessionWindow(pInfo->windowSup.pStreamAggSup, endData[i], endData[i], groupId, 0, &dummy);
- ASSERT(pEndWin);
- TSKEY ts = INT64_MIN;
- colDataAppend(pDestStartCol, i, (const char*)&pStartWin->win.skey, false);
- colDataAppend(pDestEndCol, i, (const char*)&pEndWin->win.ekey, false);
+ SSessionKey endWin = {0};
+ getCurSessionWindow(pInfo->windowSup.pStreamAggSup, endData[i], endData[i], groupId, &endWin);
+ ASSERT(!IS_INVALID_SESSION_WIN_KEY(endWin));
+ colDataAppend(pDestStartCol, i, (const char*)&startWin.win.skey, false);
+ colDataAppend(pDestEndCol, i, (const char*)&endWin.win.ekey, false);
+
colDataAppendNULL(pDestUidCol, i);
colDataAppend(pDestGpCol, i, (const char*)&groupId, false);
colDataAppendNULL(pDestCalStartTsCol, i);
diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c
index 8b716531e5..599e46c5fc 100644
--- a/source/libs/executor/src/tfill.c
+++ b/source/libs/executor/src/tfill.c
@@ -693,7 +693,7 @@ void* destroyStreamFillSupporter(SStreamFillSupporter* pFillSup) {
pFillSup->pAllColInfo = destroyFillColumnInfo(pFillSup->pAllColInfo, pFillSup->numOfFillCols, pFillSup->numOfAllCols);
tSimpleHashCleanup(pFillSup->pResMap);
pFillSup->pResMap = NULL;
- streamStateReleaseBuf(NULL, NULL, pFillSup->cur.pRowVal);
+ releaseOutputBuf(NULL, NULL, (SResultRow*)pFillSup->cur.pRowVal);
pFillSup->cur.pRowVal = NULL;
taosMemoryFree(pFillSup);
@@ -736,7 +736,7 @@ static void resetFillWindow(SResultRowData* pRowData) {
void resetPrevAndNextWindow(SStreamFillSupporter* pFillSup, SStreamState* pState) {
resetFillWindow(&pFillSup->prev);
- streamStateReleaseBuf(NULL, NULL, pFillSup->cur.pRowVal);
+ releaseOutputBuf(NULL, NULL, (SResultRow*)pFillSup->cur.pRowVal);
resetFillWindow(&pFillSup->cur);
resetFillWindow(&pFillSup->next);
resetFillWindow(&pFillSup->nextNext);
@@ -1492,6 +1492,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
case STREAM_NORMAL:
case STREAM_INVALID: {
doApplyStreamScalarCalculation(pOperator, pBlock, pInfo->pSrcBlock);
+ memcpy(pInfo->pSrcBlock->info.parTbName, pBlock->info.parTbName, TSDB_TABLE_NAME_LEN);
pInfo->srcRowIndex = 0;
} break;
default:
@@ -1502,6 +1503,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
doStreamFillImpl(pOperator);
doFilter(pInfo->pCondition, pInfo->pRes, pInfo->pColMatchColInfo, NULL);
+ memcpy(pInfo->pRes->info.parTbName, pInfo->pSrcBlock->info.parTbName, TSDB_TABLE_NAME_LEN);
pOperator->resultInfo.totalRows += pInfo->pRes->info.rows;
if (pInfo->pRes->info.rows > 0) {
break;
diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c
index 1f2b394b9c..add5f44847 100644
--- a/source/libs/executor/src/timewindowoperator.c
+++ b/source/libs/executor/src/timewindowoperator.c
@@ -38,8 +38,6 @@ typedef struct SOpenWindowInfo {
uint64_t groupId;
} SOpenWindowInfo;
-static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator);
-
static int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo);
static SResultRowPosition addToOpenWindowList(SResultRowInfo* pResultRowInfo, const SResultRow* pResult,
@@ -828,31 +826,9 @@ int32_t compareResKey(void* pKey, void* data, int32_t index) {
return -1;
}
-static int32_t saveResult(int64_t ts, int32_t pageId, int32_t offset, uint64_t groupId, SArray* pUpdated) {
- int32_t size = taosArrayGetSize(pUpdated);
- SWinKey data = {.ts = ts, .groupId = groupId};
- int32_t index = binarySearchCom(pUpdated, size, &data, TSDB_ORDER_DESC, compareResKey);
- if (index == -1) {
- index = 0;
- } else {
- if (compareResKey(&data, pUpdated, index) > 0) {
- index++;
- } else {
- return TSDB_CODE_SUCCESS;
- }
- }
-
- SResKeyPos* newPos = taosMemoryMalloc(sizeof(SResKeyPos) + sizeof(uint64_t));
- if (newPos == NULL) {
- return TSDB_CODE_OUT_OF_MEMORY;
- }
- newPos->groupId = groupId;
- newPos->pos = (SResultRowPosition){.pageId = pageId, .offset = offset};
- *(int64_t*)newPos->key = ts;
- if (taosArrayInsert(pUpdated, index, &newPos) == NULL) {
- return TSDB_CODE_OUT_OF_MEMORY;
- }
- return TSDB_CODE_SUCCESS;
+static int32_t saveResult(SResultWindowInfo winInfo, SSHashObj* pStUpdated) {
+ winInfo.sessionWin.win.ekey = winInfo.sessionWin.win.skey;
+ return tSimpleHashPut(pStUpdated, &winInfo.sessionWin, sizeof(SSessionKey), &winInfo, sizeof(SResultWindowInfo));
}
static int32_t saveWinResult(int64_t ts, int32_t pageId, int32_t offset, uint64_t groupId, SHashObj* pUpdatedMap) {
@@ -874,10 +850,6 @@ static int32_t saveWinResultInfo(TSKEY ts, uint64_t groupId, SHashObj* pUpdatedM
return saveWinResult(ts, -1, -1, groupId, pUpdatedMap);
}
-static int32_t saveResultRow(SResultRow* result, uint64_t groupId, SArray* pUpdated) {
- return saveResult(result->win.skey, result->pageId, result->offset, groupId, pUpdated);
-}
-
static void removeResults(SArray* pWins, SHashObj* pUpdatedMap) {
int32_t size = taosArrayGetSize(pWins);
for (int32_t i = 0; i < size; i++) {
@@ -915,8 +887,8 @@ int32_t compareWinRes(void* pKey, void* data, int32_t index) {
}
static void removeDeleteResults(SHashObj* pUpdatedMap, SArray* pDelWins) {
- taosArraySort(pDelWins, sWinKeyCmprImpl);
- taosArrayRemoveDuplicate(pDelWins, sWinKeyCmprImpl, NULL);
+ taosArraySort(pDelWins, winKeyCmprImpl);
+ taosArrayRemoveDuplicate(pDelWins, winKeyCmprImpl, NULL);
int32_t delSize = taosArrayGetSize(pDelWins);
if (taosHashGetSize(pUpdatedMap) == 0 || delSize == 0) {
return;
@@ -1385,19 +1357,6 @@ static void doClearWindowImpl(SResultRowPosition* p1, SDiskbasedBuf* pResultBuf,
releaseBufPage(pResultBuf, bufPage);
}
-static bool doClearWindow(SAggSupporter* pAggSup, SExprSupp* pSup, char* pData, int16_t bytes, uint64_t groupId,
- int32_t numOfOutput) {
- SET_RES_WINDOW_KEY(pAggSup->keyBuf, pData, bytes, groupId);
- SResultRowPosition* p1 =
- (SResultRowPosition*)tSimpleHashGet(pAggSup->pResultRowHashTable, pAggSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
- if (!p1) {
- // window has been closed
- return false;
- }
- doClearWindowImpl(p1, pAggSup->pResultBuf, pSup, numOfOutput);
- return true;
-}
-
static bool doDeleteWindow(SOperatorInfo* pOperator, TSKEY ts, uint64_t groupId) {
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
SWinKey key = {.ts = ts, .groupId = groupId};
@@ -1455,73 +1414,6 @@ static void doDeleteWindows(SOperatorInfo* pOperator, SInterval* pInterval, SSDa
}
}
-bool doDeleteIntervalWindow(SAggSupporter* pAggSup, TSKEY ts, uint64_t groupId) {
- size_t bytes = sizeof(TSKEY);
- SET_RES_WINDOW_KEY(pAggSup->keyBuf, &ts, bytes, groupId);
- SResultRowPosition* p1 =
- (SResultRowPosition*)tSimpleHashGet(pAggSup->pResultRowHashTable, pAggSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
- if (!p1) {
- // window has been closed
- return false;
- }
- tSimpleHashRemove(pAggSup->pResultRowHashTable, pAggSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
- return true;
-}
-
-static void doDeleteSpecifyIntervalWindow(SAggSupporter* pAggSup, STimeWindowAggSupp* pTwSup, SSDataBlock* pBlock,
- SArray* pDelWins, SInterval* pInterval, SHashObj* pUpdatedMap) {
- SColumnInfoData* pStartCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
- TSKEY* tsStarts = (TSKEY*)pStartCol->pData;
- SColumnInfoData* pEndCol = taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX);
- TSKEY* tsEnds = (TSKEY*)pEndCol->pData;
- SColumnInfoData* pGroupCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
- uint64_t* groupIds = (uint64_t*)pGroupCol->pData;
- int64_t numOfWin = tSimpleHashGetSize(pAggSup->pResultRowHashTable);
- for (int32_t i = 0; i < pBlock->info.rows; i++) {
- TSKEY startTs = TMAX(tsStarts[i], pTwSup->minTs);
- TSKEY endTs = TMIN(tsEnds[i], pTwSup->maxTs);
- SResultRowInfo dumyInfo = {0};
- dumyInfo.cur.pageId = -1;
- STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, startTs, pInterval, TSDB_ORDER_ASC);
- do {
- doDeleteIntervalWindow(pAggSup, win.skey, groupIds[i]);
- SWinKey winRes = {.ts = win.skey, .groupId = groupIds[i]};
- if (pDelWins) {
- taosArrayPush(pDelWins, &winRes);
- }
- if (pUpdatedMap) {
- taosHashRemove(pUpdatedMap, &winRes, sizeof(SWinKey));
- }
- getNextTimeWindow(pInterval, pInterval->precision, TSDB_ORDER_ASC, &win);
- } while (win.skey <= endTs);
- }
-}
-
-static void doClearWindows(SAggSupporter* pAggSup, SExprSupp* pSup1, SInterval* pInterval, int32_t numOfOutput,
- SSDataBlock* pBlock, SArray* pUpWins) {
- SColumnInfoData* pStartTsCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
- TSKEY* startTsCols = (TSKEY*)pStartTsCol->pData;
- SColumnInfoData* pEndTsCol = taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX);
- TSKEY* endTsCols = (TSKEY*)pEndTsCol->pData;
- SColumnInfoData* pGpCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
- uint64_t* pGpDatas = (uint64_t*)pGpCol->pData;
- for (int32_t i = 0; i < pBlock->info.rows; i++) {
- SResultRowInfo dumyInfo = {0};
- dumyInfo.cur.pageId = -1;
-
- STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, startTsCols[i], pInterval, TSDB_ORDER_ASC);
- while (win.ekey <= endTsCols[i]) {
- uint64_t winGpId = pGpDatas[i];
- bool res = doClearWindow(pAggSup, pSup1, (char*)&win.skey, sizeof(TSKEY), winGpId, numOfOutput);
- if (pUpWins && res) {
- SWinKey winRes = {.ts = win.skey, .groupId = winGpId};
- taosArrayPush(pUpWins, &winRes);
- }
- getNextTimeWindow(pInterval, pInterval->precision, TSDB_ORDER_ASC, &win);
- }
- }
-}
-
static int32_t getAllIntervalWindow(SSHashObj* pHashMap, SHashObj* resWins) {
void* pIte = NULL;
size_t keyLen = 0;
@@ -2923,11 +2815,12 @@ bool hasIntervalWindow(SStreamState* pState, SWinKey* pKey) {
return TSDB_CODE_SUCCESS == streamStateGet(pState, pKey, NULL, 0);
}
-static void rebuildIntervalWindow(SOperatorInfo* pOperator, SExprSupp* pSup, SArray* pWinArray, SHashObj* pUpdatedMap) {
+static void rebuildIntervalWindow(SOperatorInfo* pOperator, SArray* pWinArray, SHashObj* pUpdatedMap) {
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
int32_t size = taosArrayGetSize(pWinArray);
int32_t numOfOutput = pOperator->exprSupp.numOfExprs;
+ SExprSupp* pSup = &pOperator->exprSupp;
if (!pInfo->pChildren) {
return;
}
@@ -2935,8 +2828,7 @@ static void rebuildIntervalWindow(SOperatorInfo* pOperator, SExprSupp* pSup, SAr
SWinKey* pWinRes = taosArrayGet(pWinArray, i);
SResultRow* pCurResult = NULL;
STimeWindow parentWin = getFinalTimeWindow(pWinRes->ts, &pInfo->interval);
- if (isDeletedStreamWindow(&parentWin, pWinRes->groupId, pInfo->pState, &pInfo->twAggSup) &&
- isCloseWindow(&parentWin, &pInfo->twAggSup)) {
+ if (isDeletedStreamWindow(&parentWin, pWinRes->groupId, pInfo->pState, &pInfo->twAggSup)) {
continue;
}
@@ -3223,6 +3115,14 @@ static void doStreamIntervalAggImpl(SOperatorInfo* pOperatorInfo, SSDataBlock* p
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdatedMap) {
saveWinResultInfo(pResult->win.skey, groupId, pUpdatedMap);
}
+
+ if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) {
+ SWinKey key = {
+ .ts = pResult->win.skey,
+ .groupId = groupId,
+ };
+ tSimpleHashPut(pInfo->aggSup.pResultRowHashTable, &key, sizeof(SWinKey), NULL, 0);
+ }
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true);
doApplyFunctions(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows,
pSDataBlock->info.rows, numOfOutput);
@@ -3338,7 +3238,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
SStreamIntervalOperatorInfo* pChildInfo = pChildOp->info;
SExprSupp* pChildSup = &pChildOp->exprSupp;
doDeleteWindows(pChildOp, &pChildInfo->interval, pBlock, NULL, NULL);
- rebuildIntervalWindow(pOperator, pSup, delWins, pUpdatedMap);
+ rebuildIntervalWindow(pOperator, delWins, pUpdatedMap);
addRetriveWindow(delWins, pInfo);
taosArrayAddAll(pInfo->pDelWins, delWins);
taosArrayDestroy(delWins);
@@ -3564,42 +3464,18 @@ _error:
}
void destroyStreamAggSupporter(SStreamAggSupporter* pSup) {
- taosMemoryFreeClear(pSup->pKeyBuf);
- void** pIte = NULL;
- while ((pIte = taosHashIterate(pSup->pResultRows, pIte)) != NULL) {
- SArray* pWins = (SArray*)(*pIte);
- taosArrayDestroy(pWins);
- }
- taosHashCleanup(pSup->pResultRows);
- destroyDiskbasedBuf(pSup->pResultBuf);
- blockDataDestroy(pSup->pScanBlock);
-}
-
-void destroyStateWinInfo(void* ptr) {
- if (ptr == NULL) {
- return;
- }
- SStateWindowInfo* pWin = (SStateWindowInfo*)ptr;
- taosMemoryFreeClear(pWin->stateKey.pData);
-}
-
-void destroyStateStreamAggSupporter(SStreamAggSupporter* pSup) {
- taosMemoryFreeClear(pSup->pKeyBuf);
- void** pIte = NULL;
- while ((pIte = taosHashIterate(pSup->pResultRows, pIte)) != NULL) {
- SArray* pWins = (SArray*)(*pIte);
- taosArrayDestroyEx(pWins, (FDelete)destroyStateWinInfo);
- }
- taosHashCleanup(pSup->pResultRows);
+ tSimpleHashCleanup(pSup->pResultRows);
destroyDiskbasedBuf(pSup->pResultBuf);
blockDataDestroy(pSup->pScanBlock);
+ taosMemoryFreeClear(pSup->pState);
+ taosMemoryFreeClear(pSup->pDummyCtx);
}
void destroyStreamSessionAggOperatorInfo(void* param) {
SStreamSessionAggOperatorInfo* pInfo = (SStreamSessionAggOperatorInfo*)param;
cleanupBasicInfo(&pInfo->binfo);
destroyStreamAggSupporter(&pInfo->streamAggSup);
- cleanupGroupResInfo(&pInfo->groupResInfo);
+
if (pInfo->pChildren != NULL) {
int32_t size = taosArrayGetSize(pInfo->pChildren);
for (int32_t i = 0; i < size; i++) {
@@ -3613,8 +3489,7 @@ void destroyStreamSessionAggOperatorInfo(void* param) {
blockDataDestroy(pInfo->pDelRes);
blockDataDestroy(pInfo->pWinBlock);
blockDataDestroy(pInfo->pUpdateRes);
- destroySqlFunctionCtx(pInfo->pDummyCtx, 0);
- taosHashCleanup(pInfo->pStDeleted);
+ tSimpleHashCleanup(pInfo->pStDeleted);
taosHashCleanup(pInfo->pGroupIdTbNameMap);
taosMemoryFreeClear(param);
@@ -3643,129 +3518,62 @@ void initDummyFunction(SqlFunctionCtx* pDummy, SqlFunctionCtx* pCtx, int32_t num
}
}
-void initDownStream(SOperatorInfo* downstream, SStreamAggSupporter* pAggSup, int64_t gap, int64_t waterMark,
- uint16_t type, int32_t tsColIndex) {
+void initDownStream(SOperatorInfo* downstream, SStreamAggSupporter* pAggSup, int64_t waterMark, uint16_t type,
+ int32_t tsColIndex) {
if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION) {
SStreamPartitionOperatorInfo* pScanInfo = downstream->info;
pScanInfo->tsColIndex = tsColIndex;
}
if (downstream->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
- initDownStream(downstream->pDownstream[0], pAggSup, gap, waterMark, type, tsColIndex);
+ initDownStream(downstream->pDownstream[0], pAggSup, waterMark, type, tsColIndex);
return;
}
SStreamScanInfo* pScanInfo = downstream->info;
- pScanInfo->windowSup = (SWindowSupporter){.pStreamAggSup = pAggSup, .gap = gap, .parentType = type};
+ pScanInfo->windowSup = (SWindowSupporter){.pStreamAggSup = pAggSup, .gap = pAggSup->gap, .parentType = type};
pScanInfo->pUpdateInfo = updateInfoInit(60000, TSDB_TIME_PRECISION_MILLI, waterMark);
}
-int32_t initSessionAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx,
- int32_t numOfOutput) {
- return initStreamAggSupporter(pSup, pKey, pCtx, numOfOutput, sizeof(SResultWindowInfo));
-}
-
-SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode,
- SExecTaskInfo* pTaskInfo) {
- SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
- int32_t numOfCols = 0;
- int32_t code = TSDB_CODE_OUT_OF_MEMORY;
-
- SStreamSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamSessionAggOperatorInfo));
- SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
- if (pInfo == NULL || pOperator == NULL) {
- goto _error;
+int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, int64_t gap,
+ SStreamState* pState, int32_t keySize, int16_t keyType) {
+ pSup->resultRowSize = keySize + getResultRowSize(pCtx, numOfOutput);
+ pSup->pScanBlock = createSpecialDataBlock(STREAM_CLEAR);
+ pSup->gap = gap;
+ pSup->stateKeySize = keySize;
+ pSup->stateKeyType = keyType;
+ pSup->pDummyCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx));
+ if (pSup->pDummyCtx == NULL) {
+ return TSDB_CODE_OUT_OF_MEMORY;
}
- pOperator->pTaskInfo = pTaskInfo;
+ initDummyFunction(pSup->pDummyCtx, pCtx, numOfOutput);
+ pSup->pState = taosMemoryCalloc(1, sizeof(SStreamState));
+ *(pSup->pState) = *pState;
+ streamStateSetNumber(pSup->pState, -1);
- initResultSizeInfo(&pOperator->resultInfo, 4096);
- if (pSessionNode->window.pExprs != NULL) {
- int32_t numOfScalar = 0;
- SExprInfo* pScalarExprInfo = createExprInfo(pSessionNode->window.pExprs, NULL, &numOfScalar);
- code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar);
- if (code != TSDB_CODE_SUCCESS) {
- goto _error;
- }
- }
-
- SExprSupp* pSup = &pOperator->exprSupp;
-
- SExprInfo* pExprInfo = createExprInfo(pSessionNode->window.pFuncs, NULL, &numOfCols);
- SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
- code = initBasicInfoEx(&pInfo->binfo, pSup, pExprInfo, numOfCols, pResBlock);
- if (code != TSDB_CODE_SUCCESS) {
- goto _error;
- }
-
- code = initSessionAggSupporter(&pInfo->streamAggSup, "StreamSessionAggOperatorInfo", pSup->pCtx, numOfCols);
- if (code != TSDB_CODE_SUCCESS) {
- goto _error;
- }
-
- pInfo->pDummyCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfCols, sizeof(SqlFunctionCtx));
- if (pInfo->pDummyCtx == NULL) {
- goto _error;
- }
-
- initDummyFunction(pInfo->pDummyCtx, pSup->pCtx, numOfCols);
- pInfo->twAggSup = (STimeWindowAggSupp){
- .waterMark = pSessionNode->window.watermark,
- .calTrigger = pSessionNode->window.triggerType,
- .maxTs = INT64_MIN,
- .minTs = INT64_MAX,
- };
-
- initResultRowInfo(&pInfo->binfo.resultRowInfo);
- initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
-
- pInfo->primaryTsIndex = ((SColumnNode*)pSessionNode->window.pTspk)->slotId;
- if (pSessionNode->window.pTsEnd) {
- pInfo->endTsIndex = ((SColumnNode*)pSessionNode->window.pTsEnd)->slotId;
- }
- pInfo->gap = pSessionNode->gap;
- pInfo->binfo.pRes = pResBlock;
- pInfo->order = TSDB_ORDER_ASC;
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
- pInfo->pStDeleted = taosHashInit(64, hashFn, true, HASH_NO_LOCK);
- pInfo->pDelIterator = NULL;
- pInfo->pDelRes = createSpecialDataBlock(STREAM_DELETE_RESULT);
- pInfo->pChildren = NULL;
- pInfo->isFinal = false;
- pInfo->pPhyNode = pPhyNode;
- pInfo->ignoreExpiredData = pSessionNode->window.igExpired;
+ pSup->pResultRows = tSimpleHashInit(32, hashFn);
- pInfo->pGroupIdTbNameMap =
- taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_NO_LOCK);
-
- pOperator->name = "StreamSessionWindowAggOperator";
- pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION;
- pOperator->blocking = true;
- pOperator->status = OP_NOT_OPENED;
- pOperator->info = pInfo;
- pOperator->fpSet =
- createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo,
- aggEncodeResultRow, aggDecodeResultRow, NULL);
- if (downstream) {
- initDownStream(downstream, &pInfo->streamAggSup, pInfo->gap, pInfo->twAggSup.waterMark, pOperator->operatorType,
- pInfo->primaryTsIndex);
- code = appendDownstream(pOperator, &downstream, 1);
+ int32_t pageSize = 4096;
+ while (pageSize < pSup->resultRowSize * 4) {
+ pageSize <<= 1u;
}
- return pOperator;
-
-_error:
- if (pInfo != NULL) {
- destroyStreamSessionAggOperatorInfo(pInfo);
+ // at least four pages need to be in buffer
+ int32_t bufSize = 4096 * 256;
+ if (bufSize <= pageSize) {
+ bufSize = pageSize * 4;
+ }
+ if (!osTempSpaceAvailable()) {
+ terrno = TSDB_CODE_NO_AVAIL_DISK;
+ qError("Init stream agg supporter failed since %s", terrstr(terrno));
+ return terrno;
+ }
+ int32_t code = createDiskbasedBuf(&pSup->pResultBuf, pageSize, bufSize, "function", tsTempDir);
+ for (int32_t i = 0; i < numOfOutput; ++i) {
+ pCtx[i].saveHandle.pBuf = pSup->pResultBuf;
}
- taosMemoryFreeClear(pOperator);
- pTaskInfo->code = code;
- return NULL;
-}
-
-int64_t getSessionWindowEndkey(void* data, int32_t index) {
- SArray* pWinInfos = (SArray*)data;
- SResultWindowInfo* pWin = taosArrayGet(pWinInfos, index);
- return pWin->win.ekey;
+ return TSDB_CODE_SUCCESS;
}
bool isInTimeWindow(STimeWindow* pWin, TSKEY ts, int64_t gap) {
@@ -3775,305 +3583,243 @@ bool isInTimeWindow(STimeWindow* pWin, TSKEY ts, int64_t gap) {
return false;
}
-bool isInWindow(SResultWindowInfo* pWinInfo, TSKEY ts, int64_t gap) { return isInTimeWindow(&pWinInfo->win, ts, gap); }
-
-static SResultWindowInfo* insertNewSessionWindow(SArray* pWinInfos, TSKEY startTs, TSKEY endTs, int32_t index) {
- SResultWindowInfo win = {
- .pos.offset = -1, .pos.pageId = -1, .win.skey = startTs, .win.ekey = endTs, .isOutput = false};
- return taosArrayInsert(pWinInfos, index, &win);
+bool isInWindow(SResultWindowInfo* pWinInfo, TSKEY ts, int64_t gap) {
+ return isInTimeWindow(&pWinInfo->sessionWin.win, ts, gap);
}
-static SResultWindowInfo* addNewSessionWindow(SArray* pWinInfos, TSKEY startTs, TSKEY endTs) {
- SResultWindowInfo win = {
- .pos.offset = -1, .pos.pageId = -1, .win.skey = startTs, .win.ekey = endTs, .isOutput = false};
- return taosArrayPush(pWinInfos, &win);
+void getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId,
+ SSessionKey* pKey) {
+ pKey->win.skey = startTs;
+ pKey->win.ekey = endTs;
+ pKey->groupId = groupId;
+ SStreamStateCur* pCur = streamStateSessionGetCur(pAggSup->pState, pKey);
+ int32_t code = streamStateSessionGetKVByCur(pCur, pKey, NULL, 0);
+ streamStateFreeCur(pCur);
+ if (code != TSDB_CODE_SUCCESS) {
+ SET_SESSION_WIN_KEY_INVALID(pKey);
+ }
}
-SArray* getWinInfos(SStreamAggSupporter* pAggSup, uint64_t groupId) {
- void** ite = taosHashGet(pAggSup->pResultRows, &groupId, sizeof(uint64_t));
- SArray* pWinInfos = NULL;
- if (ite == NULL) {
- pWinInfos = taosArrayInit(1024, pAggSup->valueSize);
- taosHashPut(pAggSup->pResultRows, &groupId, sizeof(uint64_t), &pWinInfos, sizeof(void*));
+bool isInvalidSessionWin(SResultWindowInfo* pWinInfo) { return pWinInfo->sessionWin.win.skey == 0; }
+
+void setSessionOutputBuf(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId,
+ SResultWindowInfo* pCurWin) {
+ pCurWin->sessionWin.groupId = groupId;
+ pCurWin->sessionWin.win.skey = startTs - pAggSup->gap;
+ pCurWin->sessionWin.win.ekey = endTs + pAggSup->gap;
+ int32_t size = pAggSup->resultRowSize;
+ int32_t code = streamStateSessionAddIfNotExist(pAggSup->pState, &pCurWin->sessionWin, &pCurWin->pOutputBuf, &size);
+ if (code == TSDB_CODE_SUCCESS) {
+ pCurWin->isOutput = true;
} else {
- pWinInfos = *ite;
+ pCurWin->sessionWin.win.skey = startTs;
+ pCurWin->sessionWin.win.ekey = endTs;
}
- return pWinInfos;
}
-// don't add new window
-SResultWindowInfo* getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId,
- int64_t gap, int32_t* pIndex) {
- STimeWindow searchWin = {.skey = startTs, .ekey = endTs};
- SArray* pWinInfos = getWinInfos(pAggSup, groupId);
- pAggSup->pCurWins = pWinInfos;
-
- int32_t size = taosArrayGetSize(pWinInfos);
- if (size == 0) {
- return NULL;
+int32_t getSessionWinBuf(SStreamAggSupporter* pAggSup, SStreamStateCur* pCur, SResultWindowInfo* pWinInfo) {
+ int32_t size = 0;
+ int32_t code = streamStateSessionGetKVByCur(pCur, &pWinInfo->sessionWin, (const void**)&pWinInfo->pOutputBuf, &size);
+ if (code != TSDB_CODE_SUCCESS) {
+ return code;
}
- // find the first position which is smaller than the key
- int32_t index = binarySearch(pWinInfos, size, startTs, TSDB_ORDER_DESC, getSessionWindowEndkey);
- SResultWindowInfo* pWin = NULL;
- if (index >= 0) {
- pWin = taosArrayGet(pWinInfos, index);
- if (isInWindow(pWin, startTs, gap) || isInTimeWindow(&searchWin, pWin->win.skey, gap)) {
- *pIndex = index;
- return pWin;
- }
- }
-
- if (index + 1 < size) {
- pWin = taosArrayGet(pWinInfos, index + 1);
- if (isInWindow(pWin, startTs, gap) || isInTimeWindow(&searchWin, pWin->win.skey, gap)) {
- *pIndex = index + 1;
- return pWin;
- } else if (endTs != INT64_MIN && isInWindow(pWin, endTs, gap)) {
- *pIndex = index + 1;
- return pWin;
- }
- }
-
- return NULL;
+ streamStateCurNext(pAggSup->pState, pCur);
+ return TSDB_CODE_SUCCESS;
+}
+void saveDeleteInfo(SArray* pWins, SSessionKey key) {
+ // key.win.ekey = key.win.skey;
+ taosArrayPush(pWins, &key);
}
-SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId,
- int64_t gap, int32_t* pIndex) {
- SArray* pWinInfos = getWinInfos(pAggSup, groupId);
- pAggSup->pCurWins = pWinInfos;
+void saveDeleteRes(SSHashObj* pStDelete, SSessionKey key) {
+ key.win.ekey = key.win.skey;
+ tSimpleHashPut(pStDelete, &key, sizeof(SSessionKey), NULL, 0);
+}
- int32_t size = taosArrayGetSize(pWinInfos);
- if (size == 0) {
- *pIndex = 0;
- return addNewSessionWindow(pWinInfos, startTs, endTs);
- }
- // find the first position which is smaller than the key
- int32_t index = binarySearch(pWinInfos, size, startTs, TSDB_ORDER_DESC, getSessionWindowEndkey);
- SResultWindowInfo* pWin = NULL;
- if (index >= 0) {
- pWin = taosArrayGet(pWinInfos, index);
- if (isInWindow(pWin, startTs, gap)) {
- *pIndex = index;
- return pWin;
- }
- }
+static void removeSessionResult(SSHashObj* pHashMap, SSHashObj* pResMap, SSessionKey key) {
+ key.win.ekey = key.win.skey;
+ tSimpleHashRemove(pHashMap, &key, sizeof(SSessionKey));
+ tSimpleHashRemove(pResMap, &key, sizeof(SSessionKey));
+}
- if (index + 1 < size) {
- pWin = taosArrayGet(pWinInfos, index + 1);
- if (isInWindow(pWin, startTs, gap)) {
- *pIndex = index + 1;
- return pWin;
- } else if (endTs != INT64_MIN && isInWindow(pWin, endTs, gap)) {
- *pIndex = index;
- return pWin;
- }
+static void removeSessionResults(SSHashObj* pHashMap, SArray* pWins) {
+ if (tSimpleHashGetSize(pHashMap) == 0) {
+ return;
}
-
- if (index == size - 1) {
- *pIndex = taosArrayGetSize(pWinInfos);
- return addNewSessionWindow(pWinInfos, startTs, endTs);
+ int32_t size = taosArrayGetSize(pWins);
+ for (int32_t i = 0; i < size; i++) {
+ SSessionKey* pWin = taosArrayGet(pWins, i);
+ if (!pWin) continue;
+ SSessionKey key = *pWin;
+ key.win.ekey = key.win.skey;
+ tSimpleHashRemove(pHashMap, &key, sizeof(SSessionKey));
}
- *pIndex = index + 1;
- return insertNewSessionWindow(pWinInfos, startTs, endTs, index + 1);
}
int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pStartTs, TSKEY* pEndTs, uint64_t groupId,
- int32_t rows, int32_t start, int64_t gap, SHashObj* pStDeleted) {
+ int32_t rows, int32_t start, int64_t gap, SSHashObj* pResultRows, SSHashObj* pStUpdated,
+ SSHashObj* pStDeleted) {
for (int32_t i = start; i < rows; ++i) {
if (!isInWindow(pWinInfo, pStartTs[i], gap) && (!pEndTs || !isInWindow(pWinInfo, pEndTs[i], gap))) {
return i - start;
}
- if (pWinInfo->win.skey > pStartTs[i]) {
+ if (pWinInfo->sessionWin.win.skey > pStartTs[i]) {
if (pStDeleted && pWinInfo->isOutput) {
- SWinKey res = {.ts = pWinInfo->win.skey, .groupId = groupId};
- taosHashPut(pStDeleted, &res, sizeof(SWinKey), &res, sizeof(SWinKey));
- pWinInfo->isOutput = false;
+ saveDeleteRes(pStDeleted, pWinInfo->sessionWin);
}
- pWinInfo->win.skey = pStartTs[i];
+ removeSessionResult(pStUpdated, pResultRows, pWinInfo->sessionWin);
+ pWinInfo->sessionWin.win.skey = pStartTs[i];
}
- pWinInfo->win.ekey = TMAX(pWinInfo->win.ekey, pStartTs[i]);
+ pWinInfo->sessionWin.win.ekey = TMAX(pWinInfo->sessionWin.win.ekey, pStartTs[i]);
if (pEndTs) {
- pWinInfo->win.ekey = TMAX(pWinInfo->win.ekey, pEndTs[i]);
+ pWinInfo->sessionWin.win.ekey = TMAX(pWinInfo->sessionWin.win.ekey, pEndTs[i]);
}
}
return rows - start;
}
-static int32_t setWindowOutputBuf(SResultWindowInfo* pWinInfo, SResultRow** pResult, SqlFunctionCtx* pCtx,
- uint64_t groupId, int32_t numOfOutput, int32_t* rowEntryInfoOffset,
- SStreamAggSupporter* pAggSup, SExecTaskInfo* pTaskInfo) {
- assert(pWinInfo->win.skey <= pWinInfo->win.ekey);
- // too many time window in query
- int32_t size = taosArrayGetSize(pAggSup->pCurWins);
- if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH && size > MAX_INTERVAL_TIME_WINDOW) {
- T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW);
- }
-
- if (pWinInfo->pos.pageId == -1) {
- *pResult = getNewResultRow(pAggSup->pResultBuf, &pAggSup->currentPageId, pAggSup->resultRowSize);
- if (*pResult == NULL) {
- return TSDB_CODE_OUT_OF_MEMORY;
- }
-
- // add a new result set for a new group
- pWinInfo->pos.pageId = (*pResult)->pageId;
- pWinInfo->pos.offset = (*pResult)->offset;
- } else {
- *pResult = getResultRowByPos(pAggSup->pResultBuf, &pWinInfo->pos, true);
- if (!(*pResult)) {
- qError("getResultRowByPos return NULL, TID:%s", GET_TASKID(pTaskInfo));
- return TSDB_CODE_FAILED;
- }
- }
-
+static int32_t initSessionOutputBuf(SResultWindowInfo* pWinInfo, SResultRow** pResult, SqlFunctionCtx* pCtx,
+ int32_t numOfOutput, int32_t* rowEntryInfoOffset) {
+ ASSERT(pWinInfo->sessionWin.win.skey <= pWinInfo->sessionWin.win.ekey);
+ *pResult = (SResultRow*)pWinInfo->pOutputBuf;
// set time window for current result
- (*pResult)->win = pWinInfo->win;
+ (*pResult)->win = pWinInfo->sessionWin.win;
setResultRowInitCtx(*pResult, pCtx, numOfOutput, rowEntryInfoOffset);
return TSDB_CODE_SUCCESS;
}
-static int32_t doOneWindowAggImpl(int32_t tsColId, SOptrBasicInfo* pBinfo, SStreamAggSupporter* pAggSup,
- SColumnInfoData* pTimeWindowData, SSDataBlock* pSDataBlock,
- SResultWindowInfo* pCurWin, SResultRow** pResult, int32_t startIndex, int32_t winRows,
- int32_t numOutput, SOperatorInfo* pOperator) {
+static int32_t doOneWindowAggImpl(SColumnInfoData* pTimeWindowData, SResultWindowInfo* pCurWin, SResultRow** pResult,
+ int32_t startIndex, int32_t winRows, int32_t rows, int32_t numOutput,
+ SOperatorInfo* pOperator) {
SExprSupp* pSup = &pOperator->exprSupp;
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
-
- SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, tsColId);
- TSKEY* tsCols = (int64_t*)pColDataInfo->pData;
- int32_t code = setWindowOutputBuf(pCurWin, pResult, pSup->pCtx, pSDataBlock->info.groupId, numOutput,
- pSup->rowEntryInfoOffset, pAggSup, pTaskInfo);
+ int32_t code = initSessionOutputBuf(pCurWin, pResult, pSup->pCtx, numOutput, pSup->rowEntryInfoOffset);
if (code != TSDB_CODE_SUCCESS || (*pResult) == NULL) {
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
- updateTimeWindowInfo(pTimeWindowData, &pCurWin->win, false);
- doApplyFunctions(pTaskInfo, pSup->pCtx, pTimeWindowData, startIndex, winRows, pSDataBlock->info.rows, numOutput);
- SFilePage* bufPage = getBufPage(pAggSup->pResultBuf, pCurWin->pos.pageId);
- setBufPageDirty(bufPage, true);
- releaseBufPage(pAggSup->pResultBuf, bufPage);
+ updateTimeWindowInfo(pTimeWindowData, &pCurWin->sessionWin.win, false);
+ doApplyFunctions(pTaskInfo, pSup->pCtx, pTimeWindowData, startIndex, winRows, rows, numOutput);
return TSDB_CODE_SUCCESS;
}
-static int32_t doOneWindowAgg(SStreamSessionAggOperatorInfo* pInfo, SSDataBlock* pSDataBlock,
- SResultWindowInfo* pCurWin, SResultRow** pResult, int32_t startIndex, int32_t winRows,
- int32_t numOutput, SOperatorInfo* pOperator) {
- return doOneWindowAggImpl(pInfo->primaryTsIndex, &pInfo->binfo, &pInfo->streamAggSup, &pInfo->twAggSup.timeWindowData,
- pSDataBlock, pCurWin, pResult, startIndex, winRows, numOutput, pOperator);
+static bool doDeleteSessionWindow(SStreamAggSupporter* pAggSup, SSessionKey* pKey) {
+ streamStateSessionDel(pAggSup->pState, pKey);
+ tSimpleHashRemove(pAggSup->pResultRows, pKey, sizeof(SSessionKey));
+ return true;
}
-static int32_t doOneStateWindowAgg(SStreamStateAggOperatorInfo* pInfo, SSDataBlock* pSDataBlock,
- SResultWindowInfo* pCurWin, SResultRow** pResult, int32_t startIndex,
- int32_t winRows, int32_t numOutput, SOperatorInfo* pOperator) {
- return doOneWindowAggImpl(pInfo->primaryTsIndex, &pInfo->binfo, &pInfo->streamAggSup, &pInfo->twAggSup.timeWindowData,
- pSDataBlock, pCurWin, pResult, startIndex, winRows, numOutput, pOperator);
-}
-
-int32_t getNumCompactWindow(SArray* pWinInfos, int32_t startIndex, int64_t gap) {
- SResultWindowInfo* pCurWin = taosArrayGet(pWinInfos, startIndex);
- int32_t size = taosArrayGetSize(pWinInfos);
- // Just look for the window behind StartIndex
- for (int32_t i = startIndex + 1; i < size; i++) {
- SResultWindowInfo* pWinInfo = taosArrayGet(pWinInfos, i);
- if (!isInWindow(pCurWin, pWinInfo->win.skey, gap)) {
- return i - startIndex - 1;
- }
+static int32_t setSessionWinOutputInfo(SSHashObj* pStUpdated, SResultWindowInfo* pWinInfo) {
+ void* pVal = tSimpleHashGet(pStUpdated, &pWinInfo->sessionWin, sizeof(SSessionKey));
+ if (pVal) {
+ SResultWindowInfo* pWin = pVal;
+ pWinInfo->isOutput = pWin->isOutput;
}
-
- return size - startIndex - 1;
+ return TSDB_CODE_SUCCESS;
}
-void compactTimeWindow(SStreamSessionAggOperatorInfo* pInfo, int32_t startIndex, int32_t num, uint64_t groupId,
- int32_t numOfOutput, SHashObj* pStUpdated, SHashObj* pStDeleted, SOperatorInfo* pOperator) {
- SExprSupp* pSup = &pOperator->exprSupp;
- SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
-
- SResultWindowInfo* pCurWin = taosArrayGet(pInfo->streamAggSup.pCurWins, startIndex);
- SResultRow* pCurResult = NULL;
- setWindowOutputBuf(pCurWin, &pCurResult, pSup->pCtx, groupId, numOfOutput, pSup->rowEntryInfoOffset,
- &pInfo->streamAggSup, pTaskInfo);
- num += startIndex + 1;
- ASSERT(num <= taosArrayGetSize(pInfo->streamAggSup.pCurWins));
- // Just look for the window behind StartIndex
- for (int32_t i = startIndex + 1; i < num; i++) {
- SResultWindowInfo* pWinInfo = taosArrayGet(pInfo->streamAggSup.pCurWins, i);
- SResultRow* pWinResult = NULL;
- setWindowOutputBuf(pWinInfo, &pWinResult, pInfo->pDummyCtx, groupId, numOfOutput, pSup->rowEntryInfoOffset,
- &pInfo->streamAggSup, pTaskInfo);
- pCurWin->win.ekey = TMAX(pCurWin->win.ekey, pWinInfo->win.ekey);
- updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pCurWin->win, true);
- compactFunctions(pSup->pCtx, pInfo->pDummyCtx, numOfOutput, pTaskInfo, &pInfo->twAggSup.timeWindowData);
- taosHashRemove(pStUpdated, &pWinInfo->pos, sizeof(SResultRowPosition));
- if (pWinInfo->isOutput && pStDeleted) {
- SWinKey res = {.ts = pWinInfo->win.skey, .groupId = groupId};
- taosHashPut(pStDeleted, &res, sizeof(SWinKey), &res, sizeof(SWinKey));
- pWinInfo->isOutput = false;
- }
- taosArrayRemove(pInfo->streamAggSup.pCurWins, i);
- SFilePage* tmpPage = getBufPage(pInfo->streamAggSup.pResultBuf, pWinInfo->pos.pageId);
- releaseBufPage(pInfo->streamAggSup.pResultBuf, tmpPage);
+SStreamStateCur* getNextSessionWinInfo(SStreamAggSupporter* pAggSup, SSHashObj* pStUpdated, SResultWindowInfo* pCurWin,
+ SResultWindowInfo* pNextWin) {
+ SStreamStateCur* pCur = streamStateSessionSeekKeyNext(pAggSup->pState, &pCurWin->sessionWin);
+ pNextWin->isOutput = true;
+ setSessionWinOutputInfo(pStUpdated, pNextWin);
+ int32_t size = 0;
+ pNextWin->sessionWin = pCurWin->sessionWin;
+ int32_t code = streamStateSessionGetKVByCur(pCur, &pNextWin->sessionWin, (const void**)&pNextWin->pOutputBuf, &size);
+ if (code != TSDB_CODE_SUCCESS) {
+ SET_SESSION_WIN_INVALID(*pNextWin);
}
- SFilePage* bufPage = getBufPage(pInfo->streamAggSup.pResultBuf, pCurWin->pos.pageId);
- ASSERT(num > 0);
- setBufPageDirty(bufPage, true);
- releaseBufPage(pInfo->streamAggSup.pResultBuf, bufPage);
+ return pCur;
}
-static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, SHashObj* pStUpdated,
- SHashObj* pStDeleted, bool hasEndTs) {
+static void compactSessionWindow(SOperatorInfo* pOperator, SResultWindowInfo* pCurWin, SSHashObj* pStUpdated,
+ SSHashObj* pStDeleted) {
+ SExprSupp* pSup = &pOperator->exprSupp;
+ SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
+ SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
+ SResultRow* pCurResult = NULL;
+ int32_t numOfOutput = pOperator->exprSupp.numOfExprs;
+ SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
+ initSessionOutputBuf(pCurWin, &pCurResult, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset);
+ // Just look for the window behind StartIndex
+ while (1) {
+ SResultWindowInfo winInfo = {0};
+ SStreamStateCur* pCur = getNextSessionWinInfo(pAggSup, pStUpdated, pCurWin, &winInfo);
+ if (!IS_VALID_SESSION_WIN(winInfo) || !isInWindow(pCurWin, winInfo.sessionWin.win.skey, pAggSup->gap)) {
+ streamStateFreeCur(pCur);
+ break;
+ }
+ SResultRow* pWinResult = NULL;
+ initSessionOutputBuf(&winInfo, &pWinResult, pAggSup->pDummyCtx, numOfOutput, pSup->rowEntryInfoOffset);
+ pCurWin->sessionWin.win.ekey = TMAX(pCurWin->sessionWin.win.ekey, winInfo.sessionWin.win.ekey);
+ updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pCurWin->sessionWin.win, true);
+ compactFunctions(pSup->pCtx, pAggSup->pDummyCtx, numOfOutput, pTaskInfo, &pInfo->twAggSup.timeWindowData);
+ tSimpleHashRemove(pStUpdated, &winInfo.sessionWin, sizeof(SSessionKey));
+ if (winInfo.isOutput && pStDeleted) {
+ saveDeleteRes(pStDeleted, winInfo.sessionWin);
+ }
+ removeSessionResult(pStUpdated, pAggSup->pResultRows, winInfo.sessionWin);
+ doDeleteSessionWindow(pAggSup, &winInfo.sessionWin);
+ streamStateFreeCur(pCur);
+ }
+}
+
+int32_t saveSessionOutputBuf(SStreamAggSupporter* pAggSup, SResultWindowInfo* pWinInfo) {
+ saveSessionDiscBuf(pAggSup->pState, &pWinInfo->sessionWin, pWinInfo->pOutputBuf, pAggSup->resultRowSize);
+ return TSDB_CODE_SUCCESS;
+}
+
+static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, SSHashObj* pStUpdated,
+ SSHashObj* pStDeleted, bool hasEndTs) {
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
- bool masterScan = true;
int32_t numOfOutput = pOperator->exprSupp.numOfExprs;
uint64_t groupId = pSDataBlock->info.groupId;
- int64_t gap = pInfo->gap;
int64_t code = TSDB_CODE_SUCCESS;
+ SResultRow* pResult = NULL;
+ int32_t rows = pSDataBlock->info.rows;
+ int32_t winRows = 0;
- int32_t step = 1;
- bool ascScan = true;
- TSKEY* startTsCols = NULL;
- TSKEY* endTsCols = NULL;
- SResultRow* pResult = NULL;
- int32_t winRows = 0;
-
- ASSERT(pSDataBlock->pDataBlock);
SColumnInfoData* pStartTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
- startTsCols = (int64_t*)pStartTsCol->pData;
+ TSKEY* startTsCols = (int64_t*)pStartTsCol->pData;
SColumnInfoData* pEndTsCol = NULL;
if (hasEndTs) {
pEndTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->endTsIndex);
} else {
pEndTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
}
- endTsCols = (int64_t*)pEndTsCol->pData;
+ TSKEY* endTsCols = (int64_t*)pEndTsCol->pData;
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
- for (int32_t i = 0; i < pSDataBlock->info.rows;) {
+ for (int32_t i = 0; i < rows;) {
if (pInfo->ignoreExpiredData && isOverdue(endTsCols[i], &pInfo->twAggSup)) {
i++;
continue;
}
- int32_t winIndex = 0;
- SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, startTsCols[i], endTsCols[i], groupId, gap, &winIndex);
- winRows = updateSessionWindowInfo(pCurWin, startTsCols, endTsCols, groupId, pSDataBlock->info.rows, i, pInfo->gap,
- pStDeleted);
- code = doOneWindowAgg(pInfo, pSDataBlock, pCurWin, &pResult, i, winRows, numOfOutput, pOperator);
+ SResultWindowInfo winInfo = {0};
+ setSessionOutputBuf(pAggSup, startTsCols[i], endTsCols[i], groupId, &winInfo);
+ setSessionWinOutputInfo(pStUpdated, &winInfo);
+ winRows = updateSessionWindowInfo(&winInfo, startTsCols, endTsCols, groupId, rows, i, pAggSup->gap,
+ pAggSup->pResultRows, pStUpdated, pStDeleted);
+ code = doOneWindowAggImpl(&pInfo->twAggSup.timeWindowData, &winInfo, &pResult, i, winRows, rows, numOfOutput,
+ pOperator);
if (code != TSDB_CODE_SUCCESS || pResult == NULL) {
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
}
+ compactSessionWindow(pOperator, &winInfo, pStUpdated, pStDeleted);
+ saveSessionOutputBuf(pAggSup, &winInfo);
- int32_t winNum = getNumCompactWindow(pAggSup->pCurWins, winIndex, gap);
- if (winNum > 0) {
- compactTimeWindow(pInfo, winIndex, winNum, groupId, numOfOutput, pStUpdated, pStDeleted, pOperator);
- }
- pCurWin->isClosed = false;
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pStUpdated) {
- SWinKey value = {.ts = pCurWin->win.skey, .groupId = groupId};
- code = taosHashPut(pStUpdated, &pCurWin->pos, sizeof(SResultRowPosition), &value, sizeof(SWinKey));
+ code = saveResult(winInfo, pStUpdated);
if (code != TSDB_CODE_SUCCESS) {
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
}
- pCurWin->isOutput = true;
}
+ if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) {
+ SSessionKey key = winInfo.sessionWin;
+ key.win.ekey = key.win.skey;
+ tSimpleHashPut(pAggSup->pResultRows, &key, sizeof(SSessionKey), &winInfo, sizeof(SResultWindowInfo));
+ }
+
i += winRows;
}
}
@@ -4087,8 +3833,7 @@ void deleteWindow(SArray* pWinInfos, int32_t index, FDelete fp) {
taosArrayRemove(pWinInfos, index);
}
-static void doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, int64_t gap, SArray* result,
- FDelete fp) {
+static void doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, SArray* result) {
SColumnInfoData* pStartTsCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
TSKEY* startDatas = (TSKEY*)pStartTsCol->pData;
SColumnInfoData* pEndTsCol = taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX);
@@ -4096,85 +3841,70 @@ static void doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBloc
SColumnInfoData* pGroupCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
uint64_t* gpDatas = (uint64_t*)pGroupCol->pData;
for (int32_t i = 0; i < pBlock->info.rows; i++) {
- int32_t winIndex = 0;
- SResultWindowInfo* pCurWin = getCurSessionWindow(pAggSup, startDatas[i], endDatas[i], gpDatas[i], gap, &winIndex);
- if (!pCurWin) {
- continue;
- }
-
- do {
- SResultWindowInfo delWin = *pCurWin;
- deleteWindow(pAggSup->pCurWins, winIndex, fp);
- if (result) {
- delWin.groupId = gpDatas[i];
- taosArrayPush(result, &delWin);
- }
- if (winIndex >= taosArrayGetSize(pAggSup->pCurWins)) {
+ while (1) {
+ SSessionKey curWin = {0};
+ getCurSessionWindow(pAggSup, startDatas[i], endDatas[i], gpDatas[i], &curWin);
+ if (IS_INVALID_SESSION_WIN_KEY(curWin)) {
break;
}
- pCurWin = taosArrayGet(pAggSup->pCurWins, winIndex);
- } while (pCurWin->win.skey <= endDatas[i]);
- }
-}
-
-static void doClearSessionWindows(SStreamAggSupporter* pAggSup, SExprSupp* pSup, SSDataBlock* pBlock, int32_t tsIndex,
- int32_t numOfOutput, int64_t gap, SArray* result) {
- SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, tsIndex);
- TSKEY* tsCols = (TSKEY*)pColDataInfo->pData;
- SColumnInfoData* pGpDataInfo = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
- uint64_t* gpCols = (uint64_t*)pGpDataInfo->pData;
- int32_t step = 0;
- for (int32_t i = 0; i < pBlock->info.rows; i += step) {
- int32_t winIndex = 0;
- SResultWindowInfo* pCurWin = getCurSessionWindow(pAggSup, tsCols[i], INT64_MIN, gpCols[i], gap, &winIndex);
- if (!pCurWin || pCurWin->pos.pageId == -1) {
- // window has been closed.
- step = 1;
- continue;
- }
- step = updateSessionWindowInfo(pCurWin, tsCols, NULL, 0, pBlock->info.rows, i, gap, NULL);
- ASSERT(isInWindow(pCurWin, tsCols[i], gap));
- doClearWindowImpl(&pCurWin->pos, pAggSup->pResultBuf, pSup, numOfOutput);
- if (result) {
- pCurWin->groupId = gpCols[i];
- taosArrayPush(result, pCurWin);
+ doDeleteSessionWindow(pAggSup, &curWin);
+ if (result) {
+ saveDeleteInfo(result, curWin);
+ }
}
}
}
-static int32_t copyUpdateResult(SHashObj* pStUpdated, SArray* pUpdated) {
- void* pData = NULL;
- size_t keyLen = 0;
- while ((pData = taosHashIterate(pStUpdated, pData)) != NULL) {
- void* key = taosHashGetKey(pData, &keyLen);
- ASSERT(keyLen == sizeof(SResultRowPosition));
- SResKeyPos* pos = taosMemoryMalloc(sizeof(SResKeyPos) + sizeof(uint64_t));
- if (pos == NULL) {
- return TSDB_CODE_QRY_OUT_OF_MEMORY;
- }
- pos->groupId = ((SWinKey*)pData)->groupId;
- pos->pos = *(SResultRowPosition*)key;
- *(int64_t*)pos->key = ((SWinKey*)pData)->ts;
- taosArrayPush(pUpdated, &pos);
+static inline int32_t sessionKeyCompareAsc(const void* pKey1, const void* pKey2) {
+ SSessionKey* pWin1 = (SSessionKey*)pKey1;
+ SSessionKey* pWin2 = (SSessionKey*)pKey2;
+
+ if (pWin1->groupId > pWin2->groupId) {
+ return 1;
+ } else if (pWin1->groupId < pWin2->groupId) {
+ return -1;
}
- taosArraySort(pUpdated, resultrowComparAsc);
+
+ if (pWin1->win.skey > pWin2->win.skey) {
+ return 1;
+ } else if (pWin1->win.skey < pWin2->win.skey) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static int32_t copyUpdateResult(SSHashObj* pStUpdated, SArray* pUpdated) {
+ void* pIte = NULL;
+ size_t keyLen = 0;
+ int32_t iter = 0;
+ while ((pIte = tSimpleHashIterate(pStUpdated, pIte, &iter)) != NULL) {
+ void* key = tSimpleHashGetKey(pIte, &keyLen);
+ ASSERT(keyLen == sizeof(SSessionKey));
+ taosArrayPush(pUpdated, key);
+ }
+ taosArraySort(pUpdated, sessionKeyCompareAsc);
return TSDB_CODE_SUCCESS;
}
-void doBuildDeleteDataBlock(SHashObj* pStDeleted, SSDataBlock* pBlock, void** Ite) {
+void doBuildDeleteDataBlock(SSHashObj* pStDeleted, SSDataBlock* pBlock, void** Ite) {
blockDataCleanup(pBlock);
- int32_t size = taosHashGetSize(pStDeleted);
+ int32_t size = tSimpleHashGetSize(pStDeleted);
if (size == 0) {
return;
}
blockDataEnsureCapacity(pBlock, size);
- size_t keyLen = 0;
- while (((*Ite) = taosHashIterate(pStDeleted, *Ite)) != NULL) {
- SWinKey* res = *Ite;
+ size_t keyLen = 0;
+ int32_t iter = 0;
+ while (((*Ite) = tSimpleHashIterate(pStDeleted, *Ite, &iter)) != NULL) {
+ if (pBlock->info.rows + 1 > pBlock->info.capacity) {
+ break;
+ }
+ SSessionKey* res = tSimpleHashGetKey(*Ite, &keyLen);
SColumnInfoData* pStartTsCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
- colDataAppend(pStartTsCol, pBlock->info.rows, (const char*)&res->ts, false);
+ colDataAppend(pStartTsCol, pBlock->info.rows, (const char*)&res->win.skey, false);
SColumnInfoData* pEndTsCol = taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX);
- colDataAppend(pEndTsCol, pBlock->info.rows, (const char*)&res->ts, false);
+ colDataAppend(pEndTsCol, pBlock->info.rows, (const char*)&res->win.skey, false);
SColumnInfoData* pUidCol = taosArrayGet(pBlock->pDataBlock, UID_COLUMN_INDEX);
colDataAppendNULL(pUidCol, pBlock->info.rows);
SColumnInfoData* pGpCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
@@ -4184,167 +3914,137 @@ void doBuildDeleteDataBlock(SHashObj* pStDeleted, SSDataBlock* pBlock, void** It
SColumnInfoData* pCalEdCol = taosArrayGet(pBlock->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX);
colDataAppendNULL(pCalEdCol, pBlock->info.rows);
pBlock->info.rows += 1;
- if (pBlock->info.rows + 1 >= pBlock->info.capacity) {
- break;
- }
}
if ((*Ite) == NULL) {
- taosHashClear(pStDeleted);
+ tSimpleHashClear(pStDeleted);
}
}
-static void rebuildTimeWindow(SStreamSessionAggOperatorInfo* pInfo, SArray* pWinArray, int32_t numOfOutput,
- SOperatorInfo* pOperator, SHashObj* pStUpdated) {
- SExprSupp* pSup = &pOperator->exprSupp;
- SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
- int32_t size = taosArrayGetSize(pWinArray);
+static void rebuildSessionWindow(SOperatorInfo* pOperator, SArray* pWinArray, SSHashObj* pStUpdated) {
+ SExprSupp* pSup = &pOperator->exprSupp;
+ SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
+ int32_t size = taosArrayGetSize(pWinArray);
+ SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
+ SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
+ int32_t numOfOutput = pSup->numOfExprs;
+ int32_t numOfChildren = taosArrayGetSize(pInfo->pChildren);
ASSERT(pInfo->pChildren);
for (int32_t i = 0; i < size; i++) {
- SResultWindowInfo* pParentWin = taosArrayGet(pWinArray, i);
- uint64_t groupId = pParentWin->groupId;
- int32_t numOfChildren = taosArrayGetSize(pInfo->pChildren);
+ SSessionKey* pWinKey = taosArrayGet(pWinArray, i);
+ int32_t num = 0;
+ SResultWindowInfo parentWin = {0};
for (int32_t j = 0; j < numOfChildren; j++) {
SOperatorInfo* pChild = taosArrayGetP(pInfo->pChildren, j);
SStreamSessionAggOperatorInfo* pChInfo = pChild->info;
- SArray* pChWins = getWinInfos(&pChInfo->streamAggSup, groupId);
- int32_t chWinSize = taosArrayGetSize(pChWins);
- int32_t index = binarySearch(pChWins, chWinSize, pParentWin->win.skey, TSDB_ORDER_DESC, getSessionWindowEndkey);
- if (index < 0) {
- index = 0;
- }
- for (int32_t k = index; k < chWinSize; k++) {
- SResultWindowInfo* pChWin = taosArrayGet(pChWins, k);
- if (pParentWin->win.skey <= pChWin->win.skey && pChWin->win.ekey <= pParentWin->win.ekey) {
- int32_t winIndex = 0;
- SResultWindowInfo* pNewParWin =
- getSessionTimeWindow(&pInfo->streamAggSup, pChWin->win.skey, pChWin->win.ekey, groupId, 0, &winIndex);
- SResultRow* pPareResult = NULL;
- setWindowOutputBuf(pNewParWin, &pPareResult, pSup->pCtx, groupId, numOfOutput, pSup->rowEntryInfoOffset,
- &pInfo->streamAggSup, pTaskInfo);
- SResultRow* pChResult = NULL;
- setWindowOutputBuf(pChWin, &pChResult, pChild->exprSupp.pCtx, groupId, numOfOutput,
- pChild->exprSupp.rowEntryInfoOffset, &pChInfo->streamAggSup, pTaskInfo);
- updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pNewParWin->win, true);
- compactFunctions(pSup->pCtx, pChild->exprSupp.pCtx, numOfOutput, pTaskInfo, &pInfo->twAggSup.timeWindowData);
-
- int32_t winNum = getNumCompactWindow(pInfo->streamAggSup.pCurWins, winIndex, pInfo->gap);
- if (winNum > 0) {
- compactTimeWindow(pInfo, winIndex, winNum, groupId, numOfOutput, pStUpdated, NULL, pOperator);
+ SStreamAggSupporter* pChAggSup = &pChInfo->streamAggSup;
+ SStreamStateCur* pCur = streamStateSessionGetCur(pChAggSup->pState, pWinKey);
+ SResultRow* pResult = NULL;
+ SResultRow* pChResult = NULL;
+ while (1) {
+ SResultWindowInfo childWin = {0};
+ childWin.sessionWin = *pWinKey;
+ int32_t code = getSessionWinBuf(pChAggSup, pCur, &childWin);
+ if (code == TSDB_CODE_SUCCESS && pWinKey->win.skey <= childWin.sessionWin.win.skey &&
+ childWin.sessionWin.win.ekey <= pWinKey->win.ekey) {
+ if (num == 0) {
+ setSessionOutputBuf(pAggSup, pWinKey->win.skey, pWinKey->win.ekey, pWinKey->groupId, &parentWin);
+ code = initSessionOutputBuf(&parentWin, &pResult, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset);
+ if (code != TSDB_CODE_SUCCESS || pResult == NULL) {
+ break;
+ }
}
-
- SFilePage* bufPage = getBufPage(pChInfo->streamAggSup.pResultBuf, pChWin->pos.pageId);
- releaseBufPage(pChInfo->streamAggSup.pResultBuf, bufPage);
-
- bufPage = getBufPage(pInfo->streamAggSup.pResultBuf, pNewParWin->pos.pageId);
- setBufPageDirty(bufPage, true);
- releaseBufPage(pInfo->streamAggSup.pResultBuf, bufPage);
- SWinKey value = {.ts = pNewParWin->win.skey, .groupId = groupId};
- taosHashPut(pStUpdated, &pNewParWin->pos, sizeof(SResultRowPosition), &value, sizeof(SWinKey));
- } else if (!pChWin->isClosed) {
+ num++;
+ updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &parentWin.sessionWin.win, true);
+ initSessionOutputBuf(&childWin, &pChResult, pChild->exprSupp.pCtx, numOfOutput,
+ pChild->exprSupp.rowEntryInfoOffset);
+ compactFunctions(pSup->pCtx, pChild->exprSupp.pCtx, numOfOutput, pTaskInfo, &pInfo->twAggSup.timeWindowData);
+ compactSessionWindow(pOperator, &parentWin, pStUpdated, NULL);
+ saveResult(parentWin, pStUpdated);
+ } else {
break;
}
}
+ streamStateFreeCur(pCur);
+ }
+ if (num > 0) {
+ saveSessionOutputBuf(pAggSup, &parentWin);
}
}
}
-typedef SResultWindowInfo* (*__get_win_info_)(void*);
-SResultWindowInfo* getResWinForSession(void* pData) { return (SResultWindowInfo*)pData; }
-SResultWindowInfo* getResWinForState(void* pData) { return &((SStateWindowInfo*)pData)->winInfo; }
-
-int32_t closeSessionWindow(SHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SArray* pClosed, __get_win_info_ fn,
- bool delete, FDelete fp) {
- // Todo(liuyao) save window to tdb
- void** pIte = NULL;
- size_t keyLen = 0;
- while ((pIte = taosHashIterate(pHashMap, pIte)) != NULL) {
- uint64_t* pGroupId = taosHashGetKey(pIte, &keyLen);
- SArray* pWins = (SArray*)(*pIte);
- int32_t size = taosArrayGetSize(pWins);
- for (int32_t i = 0; i < size; i++) {
- void* pWin = taosArrayGet(pWins, i);
- SResultWindowInfo* pSeWin = fn(pWin);
- if (isCloseWindow(&pSeWin->win, pTwSup)) {
- if (!pSeWin->isClosed) {
- pSeWin->isClosed = true;
- if (pTwSup->calTrigger == STREAM_TRIGGER_WINDOW_CLOSE && pClosed) {
- int32_t code = saveResult(pSeWin->win.skey, pSeWin->pos.pageId, pSeWin->pos.offset, *pGroupId, pClosed);
- if (code != TSDB_CODE_SUCCESS) {
- return code;
- }
- pSeWin->isOutput = true;
- }
- if (delete) {
- deleteWindow(pWins, i, fp);
- i--;
- size = taosArrayGetSize(pWins);
- }
+int32_t closeSessionWindow(SSHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SSHashObj* pClosed) {
+ void* pIte = NULL;
+ size_t keyLen = 0;
+ int32_t iter = 0;
+ while ((pIte = tSimpleHashIterate(pHashMap, pIte, &iter)) != NULL) {
+ SResultWindowInfo* pWinInfo = pIte;
+ if (isCloseWindow(&pWinInfo->sessionWin.win, pTwSup)) {
+ if (pTwSup->calTrigger == STREAM_TRIGGER_WINDOW_CLOSE && pClosed) {
+ int32_t code = saveResult(*pWinInfo, pClosed);
+ if (code != TSDB_CODE_SUCCESS) {
+ return code;
}
- continue;
}
- break;
+ tSimpleHashIterateRemove(pHashMap, &pWinInfo->sessionWin, sizeof(SSessionKey), &pIte, &iter);
}
}
return TSDB_CODE_SUCCESS;
}
-static void closeChildSessionWindow(SArray* pChildren, TSKEY maxTs, bool delete, FDelete fp) {
+static void closeChildSessionWindow(SArray* pChildren, TSKEY maxTs) {
int32_t size = taosArrayGetSize(pChildren);
for (int32_t i = 0; i < size; i++) {
SOperatorInfo* pChildOp = taosArrayGetP(pChildren, i);
SStreamSessionAggOperatorInfo* pChInfo = pChildOp->info;
pChInfo->twAggSup.maxTs = TMAX(pChInfo->twAggSup.maxTs, maxTs);
- closeSessionWindow(pChInfo->streamAggSup.pResultRows, &pChInfo->twAggSup, NULL, getResWinForSession, delete, fp);
+ closeSessionWindow(pChInfo->streamAggSup.pResultRows, &pChInfo->twAggSup, NULL);
}
}
-int32_t getAllSessionWindow(SHashObj* pHashMap, SArray* pClosed, __get_win_info_ fn) {
- void** pIte = NULL;
- while ((pIte = taosHashIterate(pHashMap, pIte)) != NULL) {
- SArray* pWins = (SArray*)(*pIte);
- int32_t size = taosArrayGetSize(pWins);
- for (int32_t i = 0; i < size; i++) {
- void* pWin = taosArrayGet(pWins, i);
- SResultWindowInfo* pSeWin = fn(pWin);
- if (!pSeWin->isClosed) {
- int32_t code = saveResult(pSeWin->win.skey, pSeWin->pos.pageId, pSeWin->pos.offset, 0, pClosed);
- pSeWin->isOutput = true;
- }
- }
+int32_t getAllSessionWindow(SSHashObj* pHashMap, SSHashObj* pStUpdated) {
+ void* pIte = NULL;
+ int32_t iter = 0;
+ while ((pIte = tSimpleHashIterate(pHashMap, pIte, &iter)) != NULL) {
+ SResultWindowInfo* pWinInfo = *(void**)pIte;
+ saveResult(*pWinInfo, pStUpdated);
}
return TSDB_CODE_SUCCESS;
}
-static void copyDeleteWindowInfo(SArray* pResWins, SHashObj* pStDeleted) {
+static void copyDeleteWindowInfo(SArray* pResWins, SSHashObj* pStDeleted) {
int32_t size = taosArrayGetSize(pResWins);
for (int32_t i = 0; i < size; i++) {
- SResultWindowInfo* pWinInfo = taosArrayGet(pResWins, i);
- SWinKey res = {.ts = pWinInfo->win.skey, .groupId = pWinInfo->groupId};
- taosHashPut(pStDeleted, &res, sizeof(SWinKey), &res, sizeof(SWinKey));
+ SSessionKey* pWinKey = taosArrayGet(pResWins, i);
+ if (!pWinKey) continue;
+ SSessionKey winInfo = *pWinKey;
+ winInfo.win.ekey = winInfo.win.skey;
+ tSimpleHashPut(pStDeleted, &winInfo, sizeof(SSessionKey), NULL, 0);
}
}
-static void removeSessionResults(SHashObj* pHashMap, SArray* pWins) {
- int32_t size = taosArrayGetSize(pWins);
- for (int32_t i = 0; i < size; i++) {
- SResultWindowInfo* pWin = taosArrayGet(pWins, i);
- taosHashRemove(pHashMap, &pWin->pos, sizeof(SResultRowPosition));
- }
+void initGroupResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList) {
+ pGroupResInfo->pRows = pArrayList;
+ pGroupResInfo->index = 0;
+ ASSERT(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
}
-static void removeSessionDeleteResults(SArray* update, SHashObj* pStDeleted) {
- int32_t size = taosHashGetSize(pStDeleted);
- if (size == 0) {
+void doBuildSessionResult(SOperatorInfo* pOperator, SStreamState* pState, SGroupResInfo* pGroupResInfo,
+ SSDataBlock* pBlock) {
+ SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
+ // set output datablock version
+ pBlock->info.version = pTaskInfo->version;
+
+ blockDataCleanup(pBlock);
+ if (!hasRemainResults(pGroupResInfo)) {
+ taosArrayDestroy(pGroupResInfo->pRows);
+ pGroupResInfo->pRows = NULL;
return;
}
- int32_t num = taosArrayGetSize(update);
- for (int32_t i = 0; i < num; i++) {
- SResKeyPos* pos = taosArrayGetP(update, i);
- SWinKey winKey = {.ts = *(int64_t*)pos->key, .groupId = pos->groupId};
- taosHashRemove(pStDeleted, &winKey, sizeof(SWinKey));
- }
+ // clear the existed group id
+ pBlock->info.groupId = 0;
+ buildSessionResultDataBlock(pOperator, pState, pBlock, &pOperator->exprSupp, pGroupResInfo);
}
static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
@@ -4352,6 +4052,7 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
SOptrBasicInfo* pBInfo = &pInfo->binfo;
TSKEY maxTs = INT64_MIN;
+ SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
if (pOperator->status == OP_EXEC_DONE) {
return NULL;
} else if (pOperator->status == OP_RES_TO_RETURN) {
@@ -4360,18 +4061,20 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
printDataBlock(pInfo->pDelRes, IS_FINAL_OP(pInfo) ? "final session" : "single session");
return pInfo->pDelRes;
}
- doBuildStreamResBlock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
- if (pBInfo->pRes->info.rows == 0 || !hasRemainResults(&pInfo->groupResInfo)) {
- doSetOperatorCompleted(pOperator);
+ doBuildSessionResult(pOperator, pAggSup->pState, &pInfo->groupResInfo, pBInfo->pRes);
+ if (pBInfo->pRes->info.rows > 0) {
+ printDataBlock(pBInfo->pRes, IS_FINAL_OP(pInfo) ? "final session" : "single session");
+ return pBInfo->pRes;
}
- printDataBlock(pBInfo->pRes, IS_FINAL_OP(pInfo) ? "final session" : "single session");
- return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes;
+
+ doSetOperatorCompleted(pOperator);
+ return NULL;
}
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
- SHashObj* pStUpdated = taosHashInit(64, hashFn, true, HASH_NO_LOCK);
+ SSHashObj* pStUpdated = tSimpleHashInit(64, hashFn);
SOperatorInfo* downstream = pOperator->pDownstream[0];
- SArray* pUpdated = taosArrayInit(16, POINTER_BYTES); // SResKeyPos
+ SArray* pUpdated = taosArrayInit(16, sizeof(SSessionKey)); // SResKeyPos
while (1) {
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
if (pBlock == NULL) {
@@ -4385,38 +4088,31 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
/*printf("\n\n put tbname %s\n\n", pBlock->info.parTbName);*/
}
- if (pBlock->info.type == STREAM_CLEAR) {
- SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo));
- doClearSessionWindows(&pInfo->streamAggSup, &pOperator->exprSupp, pBlock, START_TS_COLUMN_INDEX,
- pOperator->exprSupp.numOfExprs, 0, pWins);
- if (IS_FINAL_OP(pInfo)) {
- int32_t childIndex = getChildIndex(pBlock);
- SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex);
- SStreamSessionAggOperatorInfo* pChildInfo = pChildOp->info;
- doClearSessionWindows(&pChildInfo->streamAggSup, &pChildOp->exprSupp, pBlock, START_TS_COLUMN_INDEX,
- pChildOp->exprSupp.numOfExprs, 0, NULL);
- rebuildTimeWindow(pInfo, pWins, pOperator->exprSupp.numOfExprs, pOperator, pStUpdated);
- }
- taosArrayDestroy(pWins);
- continue;
- } else if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT) {
- SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo));
+ if (pBlock->info.parTbName[0]) {
+ taosHashPut(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t), &pBlock->info.parTbName,
+ TSDB_TABLE_NAME_LEN);
+ /*printf("\n\n put tbname %s\n\n", pBlock->info.parTbName);*/
+ }
+
+ if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT ||
+ pBlock->info.type == STREAM_CLEAR) {
+ SArray* pWins = taosArrayInit(16, sizeof(SSessionKey));
// gap must be 0
- doDeleteTimeWindows(&pInfo->streamAggSup, pBlock, 0, pWins, NULL);
+ doDeleteTimeWindows(pAggSup, pBlock, pWins);
+ removeSessionResults(pStUpdated, pWins);
if (IS_FINAL_OP(pInfo)) {
int32_t childIndex = getChildIndex(pBlock);
SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex);
SStreamSessionAggOperatorInfo* pChildInfo = pChildOp->info;
// gap must be 0
- doDeleteTimeWindows(&pChildInfo->streamAggSup, pBlock, 0, NULL, NULL);
- rebuildTimeWindow(pInfo, pWins, pOperator->exprSupp.numOfExprs, pOperator, pStUpdated);
+ doDeleteTimeWindows(&pChildInfo->streamAggSup, pBlock, NULL);
+ rebuildSessionWindow(pOperator, pWins, pStUpdated);
}
copyDeleteWindowInfo(pWins, pInfo->pStDeleted);
- removeSessionResults(pStUpdated, pWins);
taosArrayDestroy(pWins);
continue;
} else if (pBlock->info.type == STREAM_GET_ALL) {
- getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForSession);
+ getAllSessionWindow(pAggSup->pResultRows, pStUpdated);
continue;
}
@@ -4424,7 +4120,6 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
SExprSupp* pExprSup = &pInfo->scalarSupp;
projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL);
}
- // the pDataBlock are always the same one, no need to call this again
setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true);
doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted, IS_FINAL_OP(pInfo));
if (IS_FINAL_OP(pInfo)) {
@@ -4451,39 +4146,121 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
// restore the value
pOperator->status = OP_RES_TO_RETURN;
- closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated, getResWinForSession,
- pInfo->ignoreExpiredData, NULL);
- closeChildSessionWindow(pInfo->pChildren, pInfo->twAggSup.maxTs, pInfo->ignoreExpiredData, NULL);
+ closeSessionWindow(pAggSup->pResultRows, &pInfo->twAggSup, pStUpdated);
+ closeChildSessionWindow(pInfo->pChildren, pInfo->twAggSup.maxTs);
copyUpdateResult(pStUpdated, pUpdated);
- removeSessionDeleteResults(pUpdated, pInfo->pStDeleted);
- taosHashCleanup(pStUpdated);
-
- finalizeUpdatedResult(pSup->numOfExprs, pInfo->streamAggSup.pResultBuf, pUpdated, pSup->rowEntryInfoOffset);
- initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
+ removeSessionResults(pInfo->pStDeleted, pUpdated);
+ tSimpleHashCleanup(pStUpdated);
+ initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
+
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
if (pInfo->pDelRes->info.rows > 0) {
printDataBlock(pInfo->pDelRes, IS_FINAL_OP(pInfo) ? "final session" : "single session");
return pInfo->pDelRes;
}
- doBuildStreamResBlock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
- printDataBlock(pBInfo->pRes, IS_FINAL_OP(pInfo) ? "final session" : "single session");
- return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes;
+
+ doBuildSessionResult(pOperator, pAggSup->pState, &pInfo->groupResInfo, pBInfo->pRes);
+ if (pBInfo->pRes->info.rows > 0) {
+ printDataBlock(pBInfo->pRes, IS_FINAL_OP(pInfo) ? "final session" : "single session");
+ return pBInfo->pRes;
+ }
+
+ doSetOperatorCompleted(pOperator);
+ return NULL;
+}
+
+SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode,
+ SExecTaskInfo* pTaskInfo) {
+ SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
+ int32_t numOfCols = 0;
+ int32_t code = TSDB_CODE_OUT_OF_MEMORY;
+ SStreamSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamSessionAggOperatorInfo));
+ SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
+ if (pInfo == NULL || pOperator == NULL) {
+ goto _error;
+ }
+
+ pOperator->pTaskInfo = pTaskInfo;
+
+ initResultSizeInfo(&pOperator->resultInfo, 4096);
+ if (pSessionNode->window.pExprs != NULL) {
+ int32_t numOfScalar = 0;
+ SExprInfo* pScalarExprInfo = createExprInfo(pSessionNode->window.pExprs, NULL, &numOfScalar);
+ code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar);
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
+ }
+ }
+ SExprSupp* pSup = &pOperator->exprSupp;
+
+ SExprInfo* pExprInfo = createExprInfo(pSessionNode->window.pFuncs, NULL, &numOfCols);
+ SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
+ code = initBasicInfoEx(&pInfo->binfo, pSup, pExprInfo, numOfCols, pResBlock);
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
+ }
+
+ code = initStreamAggSupporter(&pInfo->streamAggSup, pSup->pCtx, numOfCols, pSessionNode->gap,
+ pTaskInfo->streamInfo.pState, 0, 0);
+ if (code != TSDB_CODE_SUCCESS) {
+ goto _error;
+ }
+
+ pInfo->twAggSup = (STimeWindowAggSupp){
+ .waterMark = pSessionNode->window.watermark,
+ .calTrigger = pSessionNode->window.triggerType,
+ .maxTs = INT64_MIN,
+ .minTs = INT64_MAX,
+ };
+
+ initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
+
+ pInfo->primaryTsIndex = ((SColumnNode*)pSessionNode->window.pTspk)->slotId;
+ if (pSessionNode->window.pTsEnd) {
+ pInfo->endTsIndex = ((SColumnNode*)pSessionNode->window.pTsEnd)->slotId;
+ }
+ pInfo->binfo.pRes = pResBlock;
+ pInfo->order = TSDB_ORDER_ASC;
+ _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
+ pInfo->pStDeleted = tSimpleHashInit(64, hashFn);
+ pInfo->pDelIterator = NULL;
+ pInfo->pDelRes = createSpecialDataBlock(STREAM_DELETE_RESULT);
+ pInfo->pChildren = NULL;
+ pInfo->isFinal = false;
+ pInfo->pPhyNode = pPhyNode;
+ pInfo->ignoreExpiredData = pSessionNode->window.igExpired;
+ pInfo->pGroupIdTbNameMap =
+ taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_NO_LOCK);
+
+ pOperator->name = "StreamSessionWindowAggOperator";
+ pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION;
+ pOperator->blocking = true;
+ pOperator->status = OP_NOT_OPENED;
+ pOperator->info = pInfo;
+ pOperator->fpSet =
+ createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo,
+ aggEncodeResultRow, aggDecodeResultRow, NULL);
+ if (downstream) {
+ initDownStream(downstream, &pInfo->streamAggSup, pInfo->twAggSup.waterMark, pOperator->operatorType,
+ pInfo->primaryTsIndex);
+ code = appendDownstream(pOperator, &downstream, 1);
+ }
+ return pOperator;
+
+_error:
+ if (pInfo != NULL) {
+ destroyStreamSessionAggOperatorInfo(pInfo);
+ }
+
+ taosMemoryFreeClear(pOperator);
+ pTaskInfo->code = code;
+ return NULL;
}
static void clearStreamSessionOperator(SStreamSessionAggOperatorInfo* pInfo) {
- void** pIte = NULL;
- while ((pIte = taosHashIterate(pInfo->streamAggSup.pResultRows, pIte)) != NULL) {
- SArray* pWins = (SArray*)(*pIte);
- int32_t size = taosArrayGetSize(pWins);
- for (int32_t i = 0; i < size; i++) {
- SResultWindowInfo* pWin = (SResultWindowInfo*)taosArrayGet(pWins, i);
- pWin->pos.pageId = -1;
- pWin->pos.offset = -1;
- }
- }
- clearDiskbasedBuf(pInfo->streamAggSup.pResultBuf);
- pInfo->streamAggSup.currentPageId = -1;
+ tSimpleHashClear(pInfo->streamAggSup.pResultRows);
+ streamStateSessionClear(pInfo->streamAggSup.pState);
}
static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) {
@@ -4491,13 +4268,14 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) {
SOptrBasicInfo* pBInfo = &pInfo->binfo;
TSKEY maxTs = INT64_MIN;
SExprSupp* pSup = &pOperator->exprSupp;
+ SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
if (pOperator->status == OP_EXEC_DONE) {
return NULL;
}
{
- doBuildStreamResBlock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
+ doBuildSessionResult(pOperator, pAggSup->pState, &pInfo->groupResInfo, pBInfo->pRes);
if (pBInfo->pRes->info.rows > 0) {
printDataBlock(pBInfo->pRes, "semi session");
return pBInfo->pRes;
@@ -4505,30 +4283,23 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) {
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
if (pInfo->pDelRes->info.rows > 0) {
- printDataBlock(pInfo->pDelRes, "semi session");
+ printDataBlock(pInfo->pDelRes, "semi session delete");
return pInfo->pDelRes;
}
- if (pInfo->pUpdateRes->info.rows > 0 && pInfo->returnUpdate) {
- pInfo->returnUpdate = false;
- // process the rest of the data
- printDataBlock(pInfo->pUpdateRes, "semi session");
- return pInfo->pUpdateRes;
- }
-
if (pOperator->status == OP_RES_TO_RETURN) {
clearFunctionContext(&pOperator->exprSupp);
// semi interval operator clear disk buffer
clearStreamSessionOperator(pInfo);
- pOperator->status = OP_EXEC_DONE;
+ doSetOperatorCompleted(pOperator);
return NULL;
}
}
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
- SHashObj* pStUpdated = taosHashInit(64, hashFn, true, HASH_NO_LOCK);
+ SSHashObj* pStUpdated = tSimpleHashInit(64, hashFn);
SOperatorInfo* downstream = pOperator->pDownstream[0];
- SArray* pUpdated = taosArrayInit(16, POINTER_BYTES);
+ SArray* pUpdated = taosArrayInit(16, sizeof(SSessionKey));
while (1) {
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
if (pBlock == NULL) {
@@ -4544,24 +4315,17 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) {
/*printf("\n\n put tbname %s\n\n", pBlock->info.parTbName);*/
}
- if (pBlock->info.type == STREAM_CLEAR) {
- SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo));
- doClearSessionWindows(&pInfo->streamAggSup, pSup, pBlock, START_TS_COLUMN_INDEX, pSup->numOfExprs, 0, pWins);
- removeSessionResults(pStUpdated, pWins);
- taosArrayDestroy(pWins);
- copyDataBlock(pInfo->pUpdateRes, pBlock);
- pInfo->returnUpdate = true;
- break;
- } else if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT) {
+ if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT ||
+ pBlock->info.type == STREAM_CLEAR) {
// gap must be 0
SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo));
- doDeleteTimeWindows(&pInfo->streamAggSup, pBlock, 0, pWins, NULL);
- copyDeleteWindowInfo(pWins, pInfo->pStDeleted);
+ doDeleteTimeWindows(&pInfo->streamAggSup, pBlock, pWins);
removeSessionResults(pStUpdated, pWins);
+ copyDeleteWindowInfo(pWins, pInfo->pStDeleted);
taosArrayDestroy(pWins);
break;
} else if (pBlock->info.type == STREAM_GET_ALL) {
- getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForSession);
+ getAllSessionWindow(pInfo->streamAggSup.pResultRows, pStUpdated);
continue;
}
@@ -4579,15 +4343,13 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) {
pBInfo->pRes->info.watermark = pInfo->twAggSup.maxTs;
copyUpdateResult(pStUpdated, pUpdated);
- removeSessionDeleteResults(pUpdated, pInfo->pStDeleted);
- taosHashCleanup(pStUpdated);
+ removeSessionResults(pInfo->pStDeleted, pUpdated);
+ tSimpleHashCleanup(pStUpdated);
- finalizeUpdatedResult(pOperator->exprSupp.numOfExprs, pInfo->streamAggSup.pResultBuf, pUpdated,
- pSup->rowEntryInfoOffset);
- initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
+ initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity);
- doBuildStreamResBlock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
+ doBuildSessionResult(pOperator, pAggSup->pState, &pInfo->groupResInfo, pBInfo->pRes);
if (pBInfo->pRes->info.rows > 0) {
printDataBlock(pBInfo->pRes, "semi session");
return pBInfo->pRes;
@@ -4595,18 +4357,14 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) {
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
if (pInfo->pDelRes->info.rows > 0) {
- printDataBlock(pInfo->pDelRes, "semi session");
+ printDataBlock(pInfo->pDelRes, "semi session delete");
return pInfo->pDelRes;
}
- if (pInfo->pUpdateRes->info.rows > 0 && pInfo->returnUpdate) {
- pInfo->returnUpdate = false;
- // process the rest of the data
- printDataBlock(pInfo->pUpdateRes, "semi session");
- return pInfo->pUpdateRes;
- }
-
- pOperator->status = OP_EXEC_DONE;
+ clearFunctionContext(&pOperator->exprSupp);
+ // semi interval operator clear disk buffer
+ clearStreamSessionOperator(pInfo);
+ doSetOperatorCompleted(pOperator);
return NULL;
}
@@ -4639,11 +4397,14 @@ SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream
if (numOfChild > 0) {
pInfo->pChildren = taosArrayInit(numOfChild, sizeof(void*));
for (int32_t i = 0; i < numOfChild; i++) {
- SOperatorInfo* pChild = createStreamFinalSessionAggOperatorInfo(NULL, pPhyNode, pTaskInfo, 0);
- if (pChild == NULL) {
+ SOperatorInfo* pChildOp = createStreamFinalSessionAggOperatorInfo(NULL, pPhyNode, pTaskInfo, 0);
+ if (pChildOp == NULL) {
goto _error;
}
- taosArrayPush(pInfo->pChildren, &pChild);
+ SStreamSessionAggOperatorInfo* pChInfo = pChildOp->info;
+ pChInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
+ streamStateSetNumber(pChInfo->streamAggSup.pState, i);
+ taosArrayPush(pInfo->pChildren, &pChildOp);
}
}
return pOperator;
@@ -4652,7 +4413,6 @@ _error:
if (pInfo != NULL) {
destroyStreamSessionAggOperatorInfo(pInfo);
}
-
taosMemoryFreeClear(pOperator);
pTaskInfo->code = code;
return NULL;
@@ -4661,7 +4421,7 @@ _error:
void destroyStreamStateOperatorInfo(void* param) {
SStreamStateAggOperatorInfo* pInfo = (SStreamStateAggOperatorInfo*)param;
cleanupBasicInfo(&pInfo->binfo);
- destroyStateStreamAggSupporter(&pInfo->streamAggSup);
+ destroyStreamAggSupporter(&pInfo->streamAggSup);
cleanupGroupResInfo(&pInfo->groupResInfo);
if (pInfo->pChildren != NULL) {
int32_t size = taosArrayGetSize(pInfo->pChildren);
@@ -4674,151 +4434,75 @@ void destroyStreamStateOperatorInfo(void* param) {
}
colDataDestroy(&pInfo->twAggSup.timeWindowData);
blockDataDestroy(pInfo->pDelRes);
- taosHashCleanup(pInfo->pSeDeleted);
+ tSimpleHashCleanup(pInfo->pSeDeleted);
taosHashCleanup(pInfo->pGroupIdTbNameMap);
- destroySqlFunctionCtx(pInfo->pDummyCtx, 0);
-
taosMemoryFreeClear(param);
}
-int64_t getStateWinTsKey(void* data, int32_t index) {
- SStateWindowInfo* pStateWin = taosArrayGet(data, index);
- return pStateWin->winInfo.win.ekey;
-}
-
-SStateWindowInfo* addNewStateWindow(SArray* pWinInfos, TSKEY ts, char* pKeyData, SColumn* pCol) {
- SStateWindowInfo win = {
- .stateKey.bytes = pCol->bytes,
- .stateKey.type = pCol->type,
- .stateKey.pData = taosMemoryCalloc(1, pCol->bytes),
- .winInfo.pos.offset = -1,
- .winInfo.pos.pageId = -1,
- .winInfo.win.skey = ts,
- .winInfo.win.ekey = ts,
- .winInfo.isOutput = false,
- .winInfo.isClosed = false,
- };
- if (IS_VAR_DATA_TYPE(win.stateKey.type)) {
- varDataCopy(win.stateKey.pData, pKeyData);
- } else {
- memcpy(win.stateKey.pData, pKeyData, win.stateKey.bytes);
- }
- return taosArrayPush(pWinInfos, &win);
-}
-
-SStateWindowInfo* insertNewStateWindow(SArray* pWinInfos, TSKEY ts, char* pKeyData, int32_t index, SColumn* pCol) {
- SStateWindowInfo win = {
- .stateKey.bytes = pCol->bytes,
- .stateKey.type = pCol->type,
- .stateKey.pData = taosMemoryCalloc(1, pCol->bytes),
- .winInfo.pos.offset = -1,
- .winInfo.pos.pageId = -1,
- .winInfo.win.skey = ts,
- .winInfo.win.ekey = ts,
- .winInfo.isOutput = false,
- .winInfo.isClosed = false,
- };
- if (IS_VAR_DATA_TYPE(win.stateKey.type)) {
- varDataCopy(win.stateKey.pData, pKeyData);
- } else {
- memcpy(win.stateKey.pData, pKeyData, win.stateKey.bytes);
- }
- return taosArrayInsert(pWinInfos, index, &win);
-}
-
bool isTsInWindow(SStateWindowInfo* pWin, TSKEY ts) {
- if (pWin->winInfo.win.skey <= ts && ts <= pWin->winInfo.win.ekey) {
+ if (pWin->winInfo.sessionWin.win.skey <= ts && ts <= pWin->winInfo.sessionWin.win.ekey) {
return true;
}
return false;
}
bool isEqualStateKey(SStateWindowInfo* pWin, char* pKeyData) {
- return pKeyData && compareVal(pKeyData, &pWin->stateKey);
+ return pKeyData && compareVal(pKeyData, pWin->pStateKey);
}
-SStateWindowInfo* getStateWindowByTs(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t groupId, int32_t* pIndex) {
- SArray* pWinInfos = getWinInfos(pAggSup, groupId);
- pAggSup->pCurWins = pWinInfos;
- int32_t size = taosArrayGetSize(pWinInfos);
- int32_t index = binarySearch(pWinInfos, size, ts, TSDB_ORDER_DESC, getStateWinTsKey);
- SStateWindowInfo* pWin = NULL;
- if (index >= 0) {
- pWin = taosArrayGet(pWinInfos, index);
- if (isTsInWindow(pWin, ts)) {
- *pIndex = index;
- return pWin;
- }
- }
-
- if (index + 1 < size) {
- pWin = taosArrayGet(pWinInfos, index + 1);
- if (isTsInWindow(pWin, ts)) {
- *pIndex = index + 1;
- return pWin;
- }
- }
- *pIndex = 0;
- return NULL;
+bool compareStateKey(void* data, void* key) {
+ SStateKeys* stateKey = (SStateKeys*)key;
+ stateKey->pData = (char*)key + sizeof(SStateKeys);
+ return compareVal(data, stateKey);
}
-SStateWindowInfo* getStateWindow(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t groupId, char* pKeyData,
- SColumn* pCol, int32_t* pIndex) {
- SArray* pWinInfos = getWinInfos(pAggSup, groupId);
- pAggSup->pCurWins = pWinInfos;
- int32_t size = taosArrayGetSize(pWinInfos);
- if (size == 0) {
- *pIndex = 0;
- return addNewStateWindow(pWinInfos, ts, pKeyData, pCol);
- }
- int32_t index = binarySearch(pWinInfos, size, ts, TSDB_ORDER_DESC, getStateWinTsKey);
- SStateWindowInfo* pWin = NULL;
- if (index >= 0) {
- pWin = taosArrayGet(pWinInfos, index);
- if (isTsInWindow(pWin, ts)) {
- *pIndex = index;
- return pWin;
+void setStateOutputBuf(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t groupId, char* pKeyData,
+ SStateWindowInfo* pCurWin, SStateWindowInfo* pNextWin) {
+ int32_t size = pAggSup->resultRowSize;
+ pCurWin->winInfo.sessionWin.groupId = groupId;
+ pCurWin->winInfo.sessionWin.win.skey = ts;
+ pCurWin->winInfo.sessionWin.win.ekey = ts;
+ int32_t code =
+ streamStateStateAddIfNotExist(pAggSup->pState, &pCurWin->winInfo.sessionWin, pKeyData, pAggSup->stateKeySize,
+ compareStateKey, &pCurWin->winInfo.pOutputBuf, &size);
+ pCurWin->pStateKey =
+ (SStateKeys*)((char*)pCurWin->winInfo.pOutputBuf + (pAggSup->resultRowSize - pAggSup->stateKeySize));
+ pCurWin->pStateKey->bytes = pAggSup->stateKeySize - sizeof(SStateKeys);
+ pCurWin->pStateKey->type = pAggSup->stateKeyType;
+ pCurWin->pStateKey->pData = (char*)pCurWin->pStateKey + sizeof(SStateKeys);
+ pCurWin->pStateKey->isNull = false;
+
+ if (code == TSDB_CODE_SUCCESS) {
+ pCurWin->winInfo.isOutput = true;
+ } else {
+ if (IS_VAR_DATA_TYPE(pAggSup->stateKeyType)) {
+ varDataCopy(pCurWin->pStateKey->pData, pKeyData);
+ } else {
+ memcpy(pCurWin->pStateKey->pData, pKeyData, pCurWin->pStateKey->bytes);
}
}
- if (index + 1 < size) {
- pWin = taosArrayGet(pWinInfos, index + 1);
- if (isTsInWindow(pWin, ts) || isEqualStateKey(pWin, pKeyData)) {
- *pIndex = index + 1;
- return pWin;
- }
+ pNextWin->winInfo.sessionWin = pCurWin->winInfo.sessionWin;
+ pNextWin->winInfo.pOutputBuf = NULL;
+ SStreamStateCur* pCur = streamStateSessionSeekKeyNext(pAggSup->pState, &pCurWin->winInfo.sessionWin);
+ code = streamStateSessionGetKVByCur(pCur, &pNextWin->winInfo.sessionWin, NULL, 0);
+ if (code != TSDB_CODE_SUCCESS) {
+ SET_SESSION_WIN_INVALID(pNextWin->winInfo);
}
-
- if (index >= 0) {
- pWin = taosArrayGet(pWinInfos, index);
- if (isEqualStateKey(pWin, pKeyData)) {
- *pIndex = index;
- return pWin;
- }
- }
-
- if (index == size - 1) {
- *pIndex = taosArrayGetSize(pWinInfos);
- return addNewStateWindow(pWinInfos, ts, pKeyData, pCol);
- }
- *pIndex = index + 1;
- return insertNewStateWindow(pWinInfos, ts, pKeyData, index + 1, pCol);
+ streamStateFreeCur(pCur);
}
-int32_t updateStateWindowInfo(SArray* pWinInfos, int32_t winIndex, TSKEY* pTs, uint64_t groupId,
+int32_t updateStateWindowInfo(SStateWindowInfo* pWinInfo, SStateWindowInfo* pNextWin, TSKEY* pTs, uint64_t groupId,
SColumnInfoData* pKeyCol, int32_t rows, int32_t start, bool* allEqual,
- SHashObj* pSeDeleted) {
+ SSHashObj* pResultRows, SSHashObj* pSeUpdated, SSHashObj* pSeDeleted) {
*allEqual = true;
- SStateWindowInfo* pWinInfo = taosArrayGet(pWinInfos, winIndex);
for (int32_t i = start; i < rows; ++i) {
char* pKeyData = colDataGetData(pKeyCol, i);
if (!isTsInWindow(pWinInfo, pTs[i])) {
if (isEqualStateKey(pWinInfo, pKeyData)) {
- int32_t size = taosArrayGetSize(pWinInfos);
- if (winIndex + 1 < size) {
- SStateWindowInfo* pNextWin = taosArrayGet(pWinInfos, winIndex + 1);
+ if (IS_VALID_SESSION_WIN(pNextWin->winInfo)) {
// ts belongs to the next window
- if (pTs[i] >= pNextWin->winInfo.win.skey) {
+ if (pTs[i] >= pNextWin->winInfo.sessionWin.win.skey) {
return i - start;
}
}
@@ -4826,15 +4510,15 @@ int32_t updateStateWindowInfo(SArray* pWinInfos, int32_t winIndex, TSKEY* pTs, u
return i - start;
}
}
- if (pWinInfo->winInfo.win.skey > pTs[i]) {
+
+ if (pWinInfo->winInfo.sessionWin.win.skey > pTs[i]) {
if (pSeDeleted && pWinInfo->winInfo.isOutput) {
- SWinKey res = {.ts = pWinInfo->winInfo.win.skey, .groupId = groupId};
- taosHashPut(pSeDeleted, &res, sizeof(SWinKey), &res, sizeof(SWinKey));
- pWinInfo->winInfo.isOutput = false;
+ saveDeleteRes(pSeDeleted, pWinInfo->winInfo.sessionWin);
}
- pWinInfo->winInfo.win.skey = pTs[i];
+ removeSessionResult(pSeUpdated, pResultRows, pWinInfo->winInfo.sessionWin);
+ pWinInfo->winInfo.sessionWin.win.skey = pTs[i];
}
- pWinInfo->winInfo.win.ekey = TMAX(pWinInfo->winInfo.win.ekey, pTs[i]);
+ pWinInfo->winInfo.sessionWin.win.ekey = TMAX(pWinInfo->winInfo.sessionWin.win.ekey, pTs[i]);
if (!isEqualStateKey(pWinInfo, pKeyData)) {
*allEqual = false;
}
@@ -4842,36 +4526,13 @@ int32_t updateStateWindowInfo(SArray* pWinInfos, int32_t winIndex, TSKEY* pTs, u
return rows - start;
}
-static void doClearStateWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, SHashObj* pSeUpdated,
- SHashObj* pSeDeleted) {
- SColumnInfoData* pTsColInfo = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
- SColumnInfoData* pGroupColInfo = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
- TSKEY* tsCol = (TSKEY*)pTsColInfo->pData;
- bool allEqual = false;
- int32_t step = 1;
- uint64_t* gpCol = (uint64_t*)pGroupColInfo->pData;
- for (int32_t i = 0; i < pBlock->info.rows; i += step) {
- int32_t winIndex = 0;
- SStateWindowInfo* pCurWin = getStateWindowByTs(pAggSup, tsCol[i], gpCol[i], &winIndex);
- if (!pCurWin) {
- continue;
- }
- updateSessionWindowInfo(&pCurWin->winInfo, tsCol, NULL, 0, pBlock->info.rows, i, 0, NULL);
- taosHashRemove(pSeUpdated, &pCurWin->winInfo.pos, sizeof(SResultRowPosition));
- deleteWindow(pAggSup->pCurWins, winIndex, destroyStateWinInfo);
- }
-}
-
-static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, SHashObj* pSeUpdated,
- SHashObj* pStDeleted) {
+static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, SSHashObj* pSeUpdated,
+ SSHashObj* pStDeleted) {
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
SStreamStateAggOperatorInfo* pInfo = pOperator->info;
- bool masterScan = true;
int32_t numOfOutput = pOperator->exprSupp.numOfExprs;
int64_t groupId = pSDataBlock->info.groupId;
int64_t code = TSDB_CODE_SUCCESS;
- int32_t step = 1;
- bool ascScan = true;
TSKEY* tsCols = NULL;
SResultRow* pResult = NULL;
int32_t winRows = 0;
@@ -4883,39 +4544,44 @@ static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl
}
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
- blockDataEnsureCapacity(pAggSup->pScanBlock, pSDataBlock->info.rows);
+ int32_t rows = pSDataBlock->info.rows;
+ blockDataEnsureCapacity(pAggSup->pScanBlock, rows);
SColumnInfoData* pKeyColInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->stateCol.slotId);
- for (int32_t i = 0; i < pSDataBlock->info.rows; i += winRows) {
+ for (int32_t i = 0; i < rows; i += winRows) {
if (pInfo->ignoreExpiredData && isOverdue(tsCols[i], &pInfo->twAggSup)) {
i++;
continue;
}
- char* pKeyData = colDataGetData(pKeyColInfo, i);
- int32_t winIndex = 0;
- bool allEqual = true;
- SStateWindowInfo* pCurWin = getStateWindow(pAggSup, tsCols[i], groupId, pKeyData, &pInfo->stateCol, &winIndex);
- winRows = updateStateWindowInfo(pAggSup->pCurWins, winIndex, tsCols, groupId, pKeyColInfo, pSDataBlock->info.rows,
- i, &allEqual, pStDeleted);
+ char* pKeyData = colDataGetData(pKeyColInfo, i);
+ int32_t winIndex = 0;
+ bool allEqual = true;
+ SStateWindowInfo curWin = {0};
+ SStateWindowInfo nextWin = {0};
+ setStateOutputBuf(pAggSup, tsCols[i], groupId, pKeyData, &curWin, &nextWin);
+ setSessionWinOutputInfo(pSeUpdated, &curWin.winInfo);
+ winRows = updateStateWindowInfo(&curWin, &nextWin, tsCols, groupId, pKeyColInfo, rows, i, &allEqual,
+ pAggSup->pResultRows, pSeUpdated, pStDeleted);
if (!allEqual) {
uint64_t uid = 0;
- appendOneRowToStreamSpecialBlock(pAggSup->pScanBlock, &pCurWin->winInfo.win.skey, &pCurWin->winInfo.win.ekey,
- &uid, &groupId, NULL);
- taosHashRemove(pSeUpdated, &pCurWin->winInfo.pos, sizeof(SResultRowPosition));
- deleteWindow(pAggSup->pCurWins, winIndex, destroyStateWinInfo);
+ appendOneRowToStreamSpecialBlock(pAggSup->pScanBlock, &curWin.winInfo.sessionWin.win.skey,
+ &curWin.winInfo.sessionWin.win.ekey, &uid, &groupId, NULL);
+ tSimpleHashRemove(pSeUpdated, &curWin.winInfo.sessionWin, sizeof(SSessionKey));
+ doDeleteSessionWindow(pAggSup, &curWin.winInfo.sessionWin);
+ releaseOutputBuf(pAggSup->pState, NULL, (SResultRow*)curWin.winInfo.pOutputBuf);
continue;
}
- code = doOneStateWindowAgg(pInfo, pSDataBlock, &pCurWin->winInfo, &pResult, i, winRows, numOfOutput, pOperator);
+ code = doOneWindowAggImpl(&pInfo->twAggSup.timeWindowData, &curWin.winInfo, &pResult, i, winRows, rows, numOfOutput,
+ pOperator);
if (code != TSDB_CODE_SUCCESS || pResult == NULL) {
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
}
- pCurWin->winInfo.isClosed = false;
+ saveSessionOutputBuf(pAggSup, &curWin.winInfo);
+
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) {
- SWinKey value = {.ts = pCurWin->winInfo.win.skey, .groupId = groupId};
- code = taosHashPut(pSeUpdated, &pCurWin->winInfo.pos, sizeof(SResultRowPosition), &value, sizeof(SWinKey));
+ code = saveResult(curWin.winInfo, pSeUpdated);
if (code != TSDB_CODE_SUCCESS) {
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
}
- pCurWin->winInfo.isOutput = true;
}
}
}
@@ -4932,21 +4598,24 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
if (pOperator->status == OP_RES_TO_RETURN) {
doBuildDeleteDataBlock(pInfo->pSeDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
if (pInfo->pDelRes->info.rows > 0) {
- printDataBlock(pInfo->pDelRes, "single state");
+ printDataBlock(pInfo->pDelRes, "single state delete");
return pInfo->pDelRes;
}
- doBuildStreamResBlock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
- if (pBInfo->pRes->info.rows == 0 || !hasRemainResults(&pInfo->groupResInfo)) {
- doSetOperatorCompleted(pOperator);
+
+ doBuildSessionResult(pOperator, pInfo->streamAggSup.pState, &pInfo->groupResInfo, pBInfo->pRes);
+ if (pBInfo->pRes->info.rows > 0) {
+ printDataBlock(pBInfo->pRes, "single state");
+ return pBInfo->pRes;
}
- printDataBlock(pBInfo->pRes, "single state");
- return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes;
+
+ doSetOperatorCompleted(pOperator);
+ return NULL;
}
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
- SHashObj* pSeUpdated = taosHashInit(64, hashFn, true, HASH_NO_LOCK);
+ SSHashObj* pSeUpdated = tSimpleHashInit(64, hashFn);
SOperatorInfo* downstream = pOperator->pDownstream[0];
- SArray* pUpdated = taosArrayInit(16, POINTER_BYTES);
+ SArray* pUpdated = taosArrayInit(16, sizeof(SSessionKey));
while (1) {
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
if (pBlock == NULL) {
@@ -4954,18 +4623,22 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
}
printDataBlock(pBlock, "single state recv");
- if (pBlock->info.type == STREAM_CLEAR) {
- doClearStateWindows(&pInfo->streamAggSup, pBlock, pSeUpdated, pInfo->pSeDeleted);
- continue;
- } else if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT) {
- SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo));
- doDeleteTimeWindows(&pInfo->streamAggSup, pBlock, 0, pWins, destroyStateWinInfo);
- copyDeleteWindowInfo(pWins, pInfo->pSeDeleted);
+ if (pBlock->info.parTbName[0]) {
+ taosHashPut(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t), &pBlock->info.parTbName,
+ TSDB_TABLE_NAME_LEN);
+ /*printf("\n\n put tbname %s\n\n", pBlock->info.parTbName);*/
+ }
+
+ if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT ||
+ pBlock->info.type == STREAM_CLEAR) {
+ SArray* pWins = taosArrayInit(16, sizeof(SSessionKey));
+ doDeleteTimeWindows(&pInfo->streamAggSup, pBlock, pWins);
removeSessionResults(pSeUpdated, pWins);
+ copyDeleteWindowInfo(pWins, pInfo->pSeDeleted);
taosArrayDestroy(pWins);
continue;
} else if (pBlock->info.type == STREAM_GET_ALL) {
- getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForState);
+ getAllSessionWindow(pInfo->streamAggSup.pResultRows, pSeUpdated);
continue;
}
@@ -4982,28 +4655,27 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
// restore the value
pOperator->status = OP_RES_TO_RETURN;
- closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated, getResWinForState,
- pInfo->ignoreExpiredData, destroyStateWinInfo);
- // closeChildSessionWindow(pInfo->pChildren, pInfo->twAggSup.maxTs, pInfo->ignoreExpiredData, destroyStateWinInfo);
+ closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pSeUpdated);
copyUpdateResult(pSeUpdated, pUpdated);
- taosHashCleanup(pSeUpdated);
+ removeSessionResults(pInfo->pSeDeleted, pUpdated);
+ tSimpleHashCleanup(pSeUpdated);
- finalizeUpdatedResult(pOperator->exprSupp.numOfExprs, pInfo->streamAggSup.pResultBuf, pUpdated,
- pSup->rowEntryInfoOffset);
- initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
+ initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
+
doBuildDeleteDataBlock(pInfo->pSeDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
if (pInfo->pDelRes->info.rows > 0) {
- printDataBlock(pInfo->pDelRes, "single state");
+ printDataBlock(pInfo->pDelRes, "single state delete");
return pInfo->pDelRes;
}
- doBuildStreamResBlock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf);
- printDataBlock(pBInfo->pRes, "single state");
- return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes;
-}
-int32_t initStateAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx, int32_t numOfOutput) {
- return initStreamAggSupporter(pSup, pKey, pCtx, numOfOutput, sizeof(SStateWindowInfo));
+ doBuildSessionResult(pOperator, pInfo->streamAggSup.pState, &pInfo->groupResInfo, pBInfo->pRes);
+ if (pBInfo->pRes->info.rows > 0) {
+ printDataBlock(pBInfo->pRes, "single state");
+ return pBInfo->pRes;
+ }
+ doSetOperatorCompleted(pOperator);
+ return NULL;
}
SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode,
@@ -5020,11 +4692,6 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys
goto _error;
}
- SExprSupp* pSup = &pOperator->exprSupp;
-
- int32_t numOfCols = 0;
- SExprInfo* pExprInfo = createExprInfo(pStateNode->window.pFuncs, NULL, &numOfCols);
-
pInfo->stateCol = extractColumnFromColumnNode(pColNode);
initResultSizeInfo(&pOperator->resultInfo, 4096);
if (pStateNode->window.pExprs != NULL) {
@@ -5036,7 +4703,6 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys
}
}
- initResultRowInfo(&pInfo->binfo.resultRowInfo);
pInfo->twAggSup = (STimeWindowAggSupp){
.waterMark = pStateNode->window.watermark,
.calTrigger = pStateNode->window.triggerType,
@@ -5045,27 +4711,25 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys
};
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
+ SExprSupp* pSup = &pOperator->exprSupp;
+ int32_t numOfCols = 0;
+ SExprInfo* pExprInfo = createExprInfo(pStateNode->window.pFuncs, NULL, &numOfCols);
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
code = initBasicInfoEx(&pInfo->binfo, pSup, pExprInfo, numOfCols, pResBlock);
if (code != TSDB_CODE_SUCCESS) {
goto _error;
}
-
- code = initStateAggSupporter(&pInfo->streamAggSup, "StreamStateAggOperatorInfo", pSup->pCtx, numOfCols);
+ int32_t keySize = sizeof(SStateKeys) + pColNode->node.resType.bytes;
+ int16_t type = pColNode->node.resType.type;
+ code = initStreamAggSupporter(&pInfo->streamAggSup, pSup->pCtx, numOfCols, 0, pTaskInfo->streamInfo.pState, keySize,
+ type);
if (code != TSDB_CODE_SUCCESS) {
goto _error;
}
- pInfo->pDummyCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfCols, sizeof(SqlFunctionCtx));
- if (pInfo->pDummyCtx == NULL) {
- goto _error;
- }
-
- initDummyFunction(pInfo->pDummyCtx, pSup->pCtx, numOfCols);
pInfo->primaryTsIndex = tsSlotId;
- pInfo->order = TSDB_ORDER_ASC;
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
- pInfo->pSeDeleted = taosHashInit(64, hashFn, true, HASH_NO_LOCK);
+ pInfo->pSeDeleted = tSimpleHashInit(64, hashFn);
pInfo->pDelIterator = NULL;
pInfo->pDelRes = createSpecialDataBlock(STREAM_DELETE_RESULT);
pInfo->pChildren = NULL;
@@ -5082,7 +4746,7 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys
pOperator->info = pInfo;
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamStateAgg, NULL, NULL,
destroyStreamStateOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
- initDownStream(downstream, &pInfo->streamAggSup, 0, pInfo->twAggSup.waterMark, pOperator->operatorType,
+ initDownStream(downstream, &pInfo->streamAggSup, pInfo->twAggSup.waterMark, pOperator->operatorType,
pInfo->primaryTsIndex);
code = appendDownstream(pOperator, &downstream, 1);
if (code != TSDB_CODE_SUCCESS) {
@@ -5619,8 +5283,8 @@ SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMerge
goto _error;
}
- int32_t num = 0;
- SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &num);
+ int32_t num = 0;
+ SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &num);
SInterval interval = {.interval = pIntervalPhyNode->interval,
.sliding = pIntervalPhyNode->sliding,
diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h
index b5b7453e7a..dfdf03a5a8 100644
--- a/source/libs/function/inc/builtinsimpl.h
+++ b/source/libs/function/inc/builtinsimpl.h
@@ -118,6 +118,7 @@ int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pB
int32_t firstCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t lastCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t getFirstLastInfoSize(int32_t resBytes);
+EFuncDataRequired firstDynDataReq(void* pRes, STimeWindow* pTimeWindow);
EFuncDataRequired lastDynDataReq(void* pRes, STimeWindow* pTimeWindow);
int32_t lastRowFunction(SqlFunctionCtx* pCtx);
diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c
index 2308aaf214..49facfdd14 100644
--- a/source/libs/function/src/builtins.c
+++ b/source/libs/function/src/builtins.c
@@ -2431,6 +2431,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.type = FUNCTION_TYPE_FIRST,
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC,
.translateFunc = translateFirstLast,
+ .dynDataRequiredFunc = firstDynDataReq,
.getEnvFunc = getFirstLastFuncEnv,
.initFunc = functionSetup,
.processFunc = firstFunction,
@@ -2445,6 +2446,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.type = FUNCTION_TYPE_FIRST_PARTIAL,
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC,
.translateFunc = translateFirstLastPartial,
+ .dynDataRequiredFunc = firstDynDataReq,
.getEnvFunc = getFirstLastFuncEnv,
.initFunc = functionSetup,
.processFunc = firstFunction,
diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c
index 7077a9b780..874822106e 100644
--- a/source/libs/function/src/builtinsimpl.c
+++ b/source/libs/function/src/builtinsimpl.c
@@ -2527,6 +2527,8 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
int32_t start = pInput->startRowIndex;
if (pInfo->algo == APERCT_ALGO_TDIGEST) {
+ buildTDigestInfo(pInfo);
+ tdigestAutoFill(pInfo->pTDigest, COMPRESSION);
for (int32_t i = start; i < pInput->numOfRows + start; ++i) {
if (colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
@@ -2540,12 +2542,11 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
tdigestAdd(pInfo->pTDigest, v, w);
}
} else {
- qDebug("%s before add %d elements into histogram, total:%d, numOfEntry:%d, pHisto:%p, elems: %p", __FUNCTION__,
- numOfElems, pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto, pInfo->pHisto->elems);
-
// might be a race condition here that pHisto can be overwritten or setup function
// has not been called, need to relink the buffer pHisto points to.
buildHistogramInfo(pInfo);
+ qDebug("%s before add %d elements into histogram, total:%d, numOfEntry:%d, pHisto:%p, elems: %p", __FUNCTION__,
+ numOfElems, pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto, pInfo->pHisto->elems);
for (int32_t i = start; i < pInput->numOfRows + start; ++i) {
if (colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
@@ -2579,8 +2580,9 @@ static void apercentileTransferInfo(SAPercentileInfo* pInput, SAPercentileInfo*
buildTDigestInfo(pOutput);
TDigest* pTDigest = pOutput->pTDigest;
+ tdigestAutoFill(pTDigest, COMPRESSION);
- if (pTDigest->num_centroids <= 0) {
+ if (pTDigest->num_centroids <= 0 && pTDigest->num_buffered_pts == 0) {
memcpy(pTDigest, pInput->pTDigest, (size_t)TDIGEST_SIZE(COMPRESSION));
tdigestAutoFill(pTDigest, COMPRESSION);
} else {
@@ -2652,6 +2654,7 @@ int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
if (pInfo->algo == APERCT_ALGO_TDIGEST) {
buildTDigestInfo(pInfo);
+ tdigestAutoFill(pInfo->pTDigest, COMPRESSION);
if (pInfo->pTDigest->size > 0) {
pInfo->result = tdigestQuantile(pInfo->pTDigest, pInfo->percent / 100);
} else { // no need to free
@@ -2717,6 +2720,22 @@ int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx)
return TSDB_CODE_SUCCESS;
}
+EFuncDataRequired firstDynDataReq(void* pRes, STimeWindow* pTimeWindow) {
+ SResultRowEntryInfo* pEntry = (SResultRowEntryInfo*)pRes;
+
+ // not initialized yet, data is required
+ if (pEntry == NULL) {
+ return FUNC_DATA_REQUIRED_DATA_LOAD;
+ }
+
+ SFirstLastRes* pResult = GET_ROWCELL_INTERBUF(pEntry);
+ if (pResult->hasResult && pResult->ts <= pTimeWindow->skey) {
+ return FUNC_DATA_REQUIRED_NOT_LOAD;
+ } else {
+ return FUNC_DATA_REQUIRED_DATA_LOAD;
+ }
+}
+
EFuncDataRequired lastDynDataReq(void* pRes, STimeWindow* pTimeWindow) {
SResultRowEntryInfo* pEntry = (SResultRowEntryInfo*)pRes;
@@ -5356,16 +5375,14 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t maxCount = 0;
for (int32_t i = 0; i < pInfo->numOfPoints; ++i) {
SModeItem* pItem = (SModeItem*)(pInfo->pItems + i * (sizeof(SModeItem) + pInfo->colBytes));
- if (pItem->count > maxCount) {
+ if (pItem->count >= maxCount) {
maxCount = pItem->count;
resIndex = i;
- } else if (pItem->count == maxCount) {
- resIndex = -1;
}
}
SModeItem* pResItem = (SModeItem*)(pInfo->pItems + resIndex * (sizeof(SModeItem) + pInfo->colBytes));
- colDataAppend(pCol, currentRow, pResItem->data, (resIndex == -1) ? true : false);
+ colDataAppend(pCol, currentRow, pResItem->data, (maxCount == 0) ? true : false);
return pResInfo->numOfRes;
}
diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c
index eab5a33450..890a59e4be 100644
--- a/source/libs/monitor/src/monMain.c
+++ b/source/libs/monitor/src/monMain.c
@@ -401,7 +401,6 @@ static void monGenDnodeJson(SMonInfo *pMonitor) {
tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode);
tjsonAddDoubleToObject(pJson, "has_qnode", pInfo->has_qnode);
tjsonAddDoubleToObject(pJson, "has_snode", pInfo->has_snode);
- tjsonAddDoubleToObject(pJson, "has_bnode", pInfo->has_bnode);
}
static void monGenDiskJson(SMonInfo *pMonitor) {
diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c
index 9e89955ae5..04e6bcff43 100644
--- a/source/libs/nodes/src/nodesMsgFuncs.c
+++ b/source/libs/nodes/src/nodesMsgFuncs.c
@@ -84,13 +84,12 @@ static void endTlvEncode(STlvEncoder* pEncoder, char** pMsg, int32_t* pLen) {
*pMsg = pEncoder->pBuf;
pEncoder->pBuf = NULL;
*pLen = pEncoder->offset;
- // nodesWarn("encode tlv count = %d, tl size = %d", pEncoder->tlvCount, sizeof(STlv) * pEncoder->tlvCount);
}
static int32_t tlvEncodeImpl(STlvEncoder* pEncoder, int16_t type, const void* pValue, int32_t len) {
int32_t tlvLen = sizeof(STlv) + len;
if (pEncoder->offset + tlvLen > pEncoder->allocSize) {
- pEncoder->allocSize = TMAX(pEncoder->allocSize * 2, pEncoder->allocSize + pEncoder->offset + tlvLen);
+ pEncoder->allocSize = TMAX(pEncoder->allocSize * 2, pEncoder->allocSize + tlvLen);
void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize);
if (NULL == pNewBuf) {
return TSDB_CODE_OUT_OF_MEMORY;
@@ -241,6 +240,15 @@ static int32_t tlvEncodeObj(STlvEncoder* pEncoder, int16_t type, FToMsg func, co
return TSDB_CODE_SUCCESS;
}
+ if (pEncoder->offset + sizeof(STlv) > pEncoder->allocSize) {
+ pEncoder->allocSize = TMAX(pEncoder->allocSize * 2, pEncoder->allocSize + sizeof(STlv));
+ void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize);
+ if (NULL == pNewBuf) {
+ return TSDB_CODE_OUT_OF_MEMORY;
+ }
+ pEncoder->pBuf = pNewBuf;
+ }
+
int32_t start = pEncoder->offset;
pEncoder->offset += sizeof(STlv);
int32_t code = func(pObj, pEncoder);
@@ -307,7 +315,7 @@ static int32_t tlvDecodeImpl(STlv* pTlv, void* pValue, int32_t len) {
}
static int32_t tlvDecodeValueImpl(STlvDecoder* pDecoder, void* pValue, int32_t len) {
- if (pDecoder->offset + len > pDecoder->bufSize) {
+ if (len > pDecoder->bufSize - pDecoder->offset) {
return TSDB_CODE_FAILED;
}
memcpy(pValue, pDecoder->pBuf + pDecoder->offset, len);
@@ -911,6 +919,10 @@ static int32_t msgToDatum(STlv* pTlv, void* pObj) {
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_VARCHAR:
case TSDB_DATA_TYPE_VARBINARY: {
+ if (pTlv->len > pNode->node.resType.bytes + VARSTR_HEADER_SIZE) {
+ code = TSDB_CODE_FAILED;
+ break;
+ }
pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + VARSTR_HEADER_SIZE + 1);
if (NULL == pNode->datum.p) {
code = TSDB_CODE_OUT_OF_MEMORY;
diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c
index bc0c4d42bb..e647438800 100644
--- a/source/libs/nodes/src/nodesUtilFuncs.c
+++ b/source/libs/nodes/src/nodesUtilFuncs.c
@@ -190,14 +190,23 @@ int32_t nodesReleaseAllocator(int64_t allocatorId) {
return TSDB_CODE_SUCCESS;
}
- if (NULL == g_pNodeAllocator) {
+ SNodeAllocator* pAllocator = taosAcquireRef(g_allocatorReqRefPool, allocatorId);
+ if (NULL == pAllocator) {
+ return terrno;
+ }
+
+ int32_t code = taosThreadMutexTryLock(&pAllocator->mutex);
+ if (EBUSY != code) {
nodesError("allocator id %" PRIx64
" release failed: The nodesReleaseAllocator function needs to be called after the nodesAcquireAllocator "
"function is called!",
allocatorId);
+ if (0 == code) {
+ taosThreadMutexUnlock(&pAllocator->mutex);
+ }
return TSDB_CODE_FAILED;
}
- SNodeAllocator* pAllocator = g_pNodeAllocator;
+
g_pNodeAllocator = NULL;
taosThreadMutexUnlock(&pAllocator->mutex);
return taosReleaseRef(g_allocatorReqRefPool, allocatorId);
@@ -1826,7 +1835,7 @@ static EDealRes collectFuncs(SNode* pNode, void* pContext) {
if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId) &&
!(((SExprNode*)pNode)->orderAlias)) {
SExprNode* pExpr = (SExprNode*)pNode;
- if (NULL == taosHashGet(pCxt->pFuncsSet, &pExpr, POINTER_BYTES)) {
+ if (NULL == taosHashGet(pCxt->pFuncsSet, &pExpr, sizeof(SExprNode*))) {
pCxt->errCode = nodesListStrictAppend(pCxt->pFuncs, nodesCloneNode(pNode));
taosHashPut(pCxt->pFuncsSet, &pExpr, POINTER_BYTES, &pExpr, POINTER_BYTES);
}
diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c
index f59a6c7f9b..65cc44b1e9 100644
--- a/source/libs/parser/src/parInsert.c
+++ b/source/libs/parser/src/parInsert.c
@@ -1365,8 +1365,12 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, TdFilePtr fp, STableDataB
strtolower(pLine, pLine);
char* pRawSql = pCxt->pSql;
pCxt->pSql = pLine;
- bool gotRow = false;
- CHECK_CODE(parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, tmpTokenBuf));
+ bool gotRow = false;
+ int32_t code = parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, tmpTokenBuf);
+ if (TSDB_CODE_SUCCESS != code) {
+ pCxt->pSql = pRawSql;
+ return code;
+ }
if (gotRow) {
pDataBlock->size += extendedRowSize; // len;
(*numOfRows)++;
diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c
index 09e40cad60..954c1b332a 100644
--- a/source/libs/parser/src/parInsertData.c
+++ b/source/libs/parser/src/parInsertData.c
@@ -222,6 +222,21 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq)
return code;
}
+static void destroyDataBlock(STableDataBlocks* pDataBlock) {
+ if (pDataBlock == NULL) {
+ return;
+ }
+
+ taosMemoryFreeClear(pDataBlock->pData);
+ // if (!pDataBlock->cloned) {
+ // free the refcount for metermeta
+ taosMemoryFreeClear(pDataBlock->pTableMeta);
+
+ destroyBoundColumnInfo(&pDataBlock->boundColumnInfo);
+ // }
+ taosMemoryFreeClear(pDataBlock);
+}
+
int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32_t size, int32_t startOffset,
int32_t rowSize, STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList,
SVCreateTbReq* pCreateTbReq) {
@@ -240,11 +255,13 @@ int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32
if (NULL != pCreateTbReq && NULL != pCreateTbReq->ctb.pTag) {
ret = buildCreateTbMsg(*dataBlocks, pCreateTbReq);
if (ret != TSDB_CODE_SUCCESS) {
+ destroyDataBlock(*dataBlocks);
return ret;
}
}
- taosHashPut(pHashList, id, idLen, dataBlocks, POINTER_BYTES);
+ // converting to 'const char*' is to handle coverity scan errors
+ taosHashPut(pHashList, (const char*)id, idLen, (const char*)dataBlocks, POINTER_BYTES);
if (pBlockList) {
taosArrayPush(pBlockList, dataBlocks);
}
@@ -266,21 +283,6 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) {
return result;
}
-static void destroyDataBlock(STableDataBlocks* pDataBlock) {
- if (pDataBlock == NULL) {
- return;
- }
-
- taosMemoryFreeClear(pDataBlock->pData);
- // if (!pDataBlock->cloned) {
- // free the refcount for metermeta
- taosMemoryFreeClear(pDataBlock->pTableMeta);
-
- destroyBoundColumnInfo(&pDataBlock->boundColumnInfo);
- // }
- taosMemoryFreeClear(pDataBlock);
-}
-
void destroyBlockArrayList(SArray* pDataBlockList) {
if (pDataBlockList == NULL) {
return;
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index a8bc8689d0..5a05440c73 100644
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -5166,7 +5166,7 @@ static int16_t getCreateComponentNodeMsgType(ENodeType type) {
static int32_t translateCreateComponentNode(STranslateContext* pCxt, SCreateComponentNodeStmt* pStmt) {
SMCreateQnodeReq createReq = {.dnodeId = pStmt->dnodeId};
return buildCmdMsg(pCxt, getCreateComponentNodeMsgType(nodeType(pStmt)),
- (FSerializeFunc)tSerializeSCreateDropMQSBNodeReq, &createReq);
+ (FSerializeFunc)tSerializeSCreateDropMQSNodeReq, &createReq);
}
static int16_t getDropComponentNodeMsgType(ENodeType type) {
@@ -5188,7 +5188,7 @@ static int16_t getDropComponentNodeMsgType(ENodeType type) {
static int32_t translateDropComponentNode(STranslateContext* pCxt, SDropComponentNodeStmt* pStmt) {
SDDropQnodeReq dropReq = {.dnodeId = pStmt->dnodeId};
return buildCmdMsg(pCxt, getDropComponentNodeMsgType(nodeType(pStmt)),
- (FSerializeFunc)tSerializeSCreateDropMQSBNodeReq, &dropReq);
+ (FSerializeFunc)tSerializeSCreateDropMQSNodeReq, &dropReq);
}
static int32_t checkTopicQuery(STranslateContext* pCxt, SSelectStmt* pSelect) {
diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c
index 95eb094edb..d98d513d5d 100644
--- a/source/libs/parser/src/parUtil.c
+++ b/source/libs/parser/src/parUtil.c
@@ -248,8 +248,12 @@ int32_t getNumOfTags(const STableMeta* pTableMeta) { return getTableInfo(pTableM
STableComInfo getTableInfo(const STableMeta* pTableMeta) { return pTableMeta->tableInfo; }
STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
- size_t size = TABLE_META_SIZE(pTableMeta);
+ int32_t numOfFields = TABLE_TOTAL_COL_NUM(pTableMeta);
+ if (numOfFields > TSDB_MAX_COLUMNS || numOfFields < TSDB_MIN_COLUMNS) {
+ return NULL;
+ }
+ size_t size = sizeof(STableMeta) + numOfFields * sizeof(SSchema);
STableMeta* p = taosMemoryMalloc(size);
memcpy(p, pTableMeta, size);
return p;
diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp
index a9360f796c..a40d0f81fc 100644
--- a/source/libs/parser/test/mockCatalog.cpp
+++ b/source/libs/parser/test/mockCatalog.cpp
@@ -32,23 +32,29 @@
namespace {
void generateInformationSchema(MockCatalogService* mcs) {
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODES, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODES, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("id", TSDB_DATA_TYPE_INT)
.addColumn("endpoint", TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MNODES, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MNODES, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("id", TSDB_DATA_TYPE_INT)
.addColumn("endpoint", TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MODULES, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MODULES, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("id", TSDB_DATA_TYPE_INT)
.addColumn("endpoint", TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_QNODES, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_QNODES, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("id", TSDB_DATA_TYPE_INT)
.addColumn("endpoint", TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DATABASES, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DATABASES, TSDB_SYSTEM_TABLE, 2)
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
+ .addColumn("create_time", TSDB_DATA_TYPE_TIMESTAMP)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_FUNCTIONS, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_FUNCTIONS, TSDB_SYSTEM_TABLE, 2)
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN)
+ .addColumn("aggregate", TSDB_DATA_TYPE_INT)
.done();
mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_INDEXES, TSDB_SYSTEM_TABLE, 3)
.addColumn("index_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN)
@@ -63,22 +69,28 @@ void generateInformationSchema(MockCatalogService* mcs) {
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
.addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TABLE_DISTRIBUTED, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TABLE_DISTRIBUTED, TSDB_SYSTEM_TABLE, 2)
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
+ .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USERS, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USERS, TSDB_SYSTEM_TABLE, 2)
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN)
+ .addColumn("super", TSDB_DATA_TYPE_TINYINT)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("vgroup_id", TSDB_DATA_TYPE_INT)
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_OPTION_LEN)
+ .addColumn("value", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_VALUE_LEN)
+ .done();
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODE_VARIABLES, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("dnode_id", TSDB_DATA_TYPE_INT)
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_OPTION_LEN)
.done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODE_VARIABLES, TSDB_SYSTEM_TABLE, 1)
- .addColumn("dnode_id", TSDB_DATA_TYPE_INT)
- .done();
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CLUSTER, TSDB_SYSTEM_TABLE, 1)
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CLUSTER, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("id", TSDB_DATA_TYPE_BIGINT)
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN)
.done();
mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VNODES, TSDB_SYSTEM_TABLE, 2)
@@ -92,30 +104,22 @@ void generateInformationSchema(MockCatalogService* mcs) {
}
void generatePerformanceSchema(MockCatalogService* mcs) {
- {
- ITableBuilder& builder =
- mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_TRANS, TSDB_SYSTEM_TABLE, 1)
- .addColumn("id", TSDB_DATA_TYPE_INT);
- builder.done();
- }
- {
- ITableBuilder& builder =
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STREAMS, TSDB_SYSTEM_TABLE, 1)
- .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
- builder.done();
- }
- {
- ITableBuilder& builder =
- mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONSUMERS, TSDB_SYSTEM_TABLE, 1)
- .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
- builder.done();
- }
- {
- ITableBuilder& builder =
- mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SUBSCRIPTIONS, TSDB_SYSTEM_TABLE, 1)
- .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
- builder.done();
- }
+ mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_TRANS, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("id", TSDB_DATA_TYPE_INT)
+ .addColumn("create_time", TSDB_DATA_TYPE_TIMESTAMP)
+ .done();
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STREAMS, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN)
+ .addColumn("create_time", TSDB_DATA_TYPE_TIMESTAMP)
+ .done();
+ mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONSUMERS, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("consumer_id", TSDB_DATA_TYPE_BIGINT)
+ .addColumn("consumer_group", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN)
+ .done();
+ mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SUBSCRIPTIONS, TSDB_SYSTEM_TABLE, 2)
+ .addColumn("vgroup_id", TSDB_DATA_TYPE_INT)
+ .addColumn("consumer_id", TSDB_DATA_TYPE_BIGINT)
+ .done();
}
/*
diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp
index 121bbaa733..3ea6ae3db4 100644
--- a/source/libs/parser/test/parInitialCTest.cpp
+++ b/source/libs/parser/test/parInitialCTest.cpp
@@ -27,25 +27,6 @@ TEST_F(ParserInitialCTest, createAccount) {
run("CREATE ACCOUNT ac_wxy PASS '123456'", TSDB_CODE_PAR_EXPRIE_STATEMENT, PARSER_STAGE_PARSE);
}
-TEST_F(ParserInitialCTest, createBnode) {
- useDb("root", "test");
-
- SMCreateQnodeReq expect = {0};
-
- auto setCreateQnodeReq = [&](int32_t dnodeId) { expect.dnodeId = dnodeId; };
-
- setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
- ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_CREATE_BNODE_STMT);
- SMCreateQnodeReq req = {0};
- ASSERT_TRUE(TSDB_CODE_SUCCESS ==
- tDeserializeSCreateDropMQSBNodeReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));
- ASSERT_EQ(req.dnodeId, expect.dnodeId);
- });
-
- setCreateQnodeReq(1);
- run("CREATE BNODE ON DNODE 1");
-}
-
/*
* CREATE DATABASE [IF NOT EXISTS] db_name [database_options]
*
diff --git a/source/libs/parser/test/parInitialDTest.cpp b/source/libs/parser/test/parInitialDTest.cpp
index 870afa694a..c7865f3da3 100644
--- a/source/libs/parser/test/parInitialDTest.cpp
+++ b/source/libs/parser/test/parInitialDTest.cpp
@@ -52,12 +52,6 @@ TEST_F(ParserInitialDTest, describe) {
// todo describe
// todo DROP account
-TEST_F(ParserInitialDTest, dropBnode) {
- useDb("root", "test");
-
- run("DROP BNODE ON DNODE 1");
-}
-
// DROP CONSUMER GROUP [ IF EXISTS ] cgroup_name ON topic_name
TEST_F(ParserInitialDTest, dropConsumerGroup) {
useDb("root", "test");
diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c
index a917397d02..23f177ffe2 100644
--- a/source/libs/qcom/src/queryUtil.c
+++ b/source/libs/qcom/src/queryUtil.c
@@ -357,8 +357,7 @@ char* parseTagDatatoJson(void* p) {
for (int j = 0; j < nCols; ++j) {
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
// json key encode by binary
- memset(tagJsonKey, 0, sizeof(tagJsonKey));
- memcpy(tagJsonKey, pTagVal->pKey, strlen(pTagVal->pKey));
+ tstrncpy(tagJsonKey, pTagVal->pKey, sizeof(tagJsonKey));
// json value
char type = pTagVal->type;
if (type == TSDB_DATA_TYPE_NULL) {
@@ -424,13 +423,14 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
return TSDB_CODE_SUCCESS;
}
- if ((pSrc->tableInfo.numOfColumns + pSrc->tableInfo.numOfTags) > TSDB_MAX_COL_TAG_NUM) {
+ int32_t numOfField = pSrc->tableInfo.numOfColumns + pSrc->tableInfo.numOfTags;
+ if (numOfField > TSDB_MAX_COL_TAG_NUM || numOfField < TSDB_MIN_COLUMNS) {
*pDst = NULL;
qError("too many column and tag num:%d,%d", pSrc->tableInfo.numOfColumns, pSrc->tableInfo.numOfTags);
return TSDB_CODE_INVALID_PARA;
}
- int32_t metaSize = sizeof(STableMeta) + (pSrc->tableInfo.numOfColumns + pSrc->tableInfo.numOfTags) * sizeof(SSchema);
+ int32_t metaSize = sizeof(STableMeta) + numOfField * sizeof(SSchema);
*pDst = taosMemoryMalloc(metaSize);
if (NULL == *pDst) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c
index a6f26088de..fadd07a9f3 100644
--- a/source/libs/qcom/src/querymsg.c
+++ b/source/libs/qcom/src/querymsg.c
@@ -173,7 +173,7 @@ int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t
}
SDbCfgReq dbCfgReq = {0};
- strcpy(dbCfgReq.db, input);
+ strncpy(dbCfgReq.db, input, sizeof(dbCfgReq.db) - 1);
int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq);
void *pBuf = (*mallcFp)(bufLen);
@@ -191,7 +191,7 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t
}
SUserIndexReq indexReq = {0};
- strcpy(indexReq.indexFName, input);
+ strncpy(indexReq.indexFName, input, sizeof(indexReq.indexFName) - 1);
int32_t bufLen = tSerializeSUserIndexReq(NULL, 0, &indexReq);
void *pBuf = (*mallcFp)(bufLen);
@@ -233,7 +233,7 @@ int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32
}
SGetUserAuthReq req = {0};
- strncpy(req.user, input, sizeof(req.user));
+ strncpy(req.user, input, sizeof(req.user) - 1);
int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req);
void *pBuf = (*mallcFp)(bufLen);
@@ -251,7 +251,7 @@ int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_
}
STableIndexReq indexReq = {0};
- strcpy(indexReq.tbFName, input);
+ strncpy(indexReq.tbFName, input, sizeof(indexReq.tbFName) - 1);
int32_t bufLen = tSerializeSTableIndexReq(NULL, 0, &indexReq);
void *pBuf = (*mallcFp)(bufLen);
@@ -271,8 +271,8 @@ int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t
SBuildTableInput *pInput = input;
STableCfgReq cfgReq = {0};
cfgReq.header.vgId = pInput->vgId;
- strncpy(cfgReq.dbFName, pInput->dbFName, sizeof(cfgReq.dbFName));
- strncpy(cfgReq.tbName, pInput->tbName, sizeof(cfgReq.tbName));
+ strncpy(cfgReq.dbFName, pInput->dbFName, sizeof(cfgReq.dbFName) - 1);
+ strncpy(cfgReq.tbName, pInput->tbName, sizeof(cfgReq.tbName) - 1);
int32_t bufLen = tSerializeSTableCfgReq(NULL, 0, &cfgReq);
void *pBuf = (*mallcFp)(bufLen);
diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c
index 3038b87930..e9ded9b269 100644
--- a/source/libs/qworker/src/qwUtil.c
+++ b/source/libs/qworker/src/qwUtil.c
@@ -412,7 +412,7 @@ void qwSetHbParam(int64_t refId, SQWHbParam **pParam) {
while (true) {
paramIdx = atomic_load_32(&gQwMgmt.paramIdx);
if (paramIdx == tListLen(gQwMgmt.param)) {
- newParamIdx = 0;
+ newParamIdx = 1;
} else {
newParamIdx = paramIdx + 1;
}
@@ -422,6 +422,10 @@ void qwSetHbParam(int64_t refId, SQWHbParam **pParam) {
}
}
+ if (paramIdx == tListLen(gQwMgmt.param)) {
+ paramIdx = 0;
+ }
+
gQwMgmt.param[paramIdx].qwrId = gQwMgmt.qwRef;
gQwMgmt.param[paramIdx].refId = refId;
diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c
index 0ff40f3b9a..3df16563e2 100644
--- a/source/libs/qworker/src/qworker.c
+++ b/source/libs/qworker/src/qworker.c
@@ -398,7 +398,6 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu
if (QW_EVENT_PROCESSED(ctx, QW_EVENT_DROP)) {
QW_TASK_ELOG("task already dropped at wrong phase %s", qwPhaseStr(phase));
QW_ERR_JRET(TSDB_CODE_QRY_TASK_STATUS_ERROR);
- break;
}
if (QW_EVENT_RECEIVED(ctx, QW_EVENT_DROP)) {
diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c
index c641b88152..b585373b0a 100644
--- a/source/libs/scheduler/src/schTask.c
+++ b/source/libs/scheduler/src/schTask.c
@@ -430,7 +430,8 @@ int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf *pData, int32
if (SCH_IS_DATA_BIND_TASK(pTask)) {
if (NULL == pData->pEpSet) {
SCH_TASK_ELOG("no epset updated while got error %s", tstrerror(rspCode));
- SCH_ERR_JRET(rspCode);
+ code = rspCode;
+ goto _return;
}
}
diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c
index 5ad5aa549d..149b1a8447 100644
--- a/source/libs/stream/src/streamExec.c
+++ b/source/libs/stream/src/streamExec.c
@@ -137,6 +137,8 @@ int32_t streamPipelineExec(SStreamTask* pTask, int32_t batchNum, bool dispatch)
if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
streamDispatch(pTask);
}
+ } else {
+ taosArrayDestroyEx(pRes, (FDelete)blockDataFreeRes);
}
}
diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c
index 53e49a6ba5..02b74c260b 100644
--- a/source/libs/stream/src/streamMeta.c
+++ b/source/libs/stream/src/streamMeta.c
@@ -27,7 +27,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
char* streamPath = taosMemoryCalloc(1, len);
sprintf(streamPath, "%s/%s", path, "stream");
pMeta->path = strdup(streamPath);
- if (tdbOpen(pMeta->path, 16 * 1024, 1, &pMeta->db) < 0) {
+ if (tdbOpen(pMeta->path, 16 * 1024, 1, &pMeta->db, 0) < 0) {
taosMemoryFree(streamPath);
goto _err;
}
@@ -36,11 +36,11 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
taosMulModeMkDir(streamPath, 0755);
taosMemoryFree(streamPath);
- if (tdbTbOpen("task.db", sizeof(int32_t), -1, NULL, pMeta->db, &pMeta->pTaskDb) < 0) {
+ if (tdbTbOpen("task.db", sizeof(int32_t), -1, NULL, pMeta->db, &pMeta->pTaskDb, 0) < 0) {
goto _err;
}
- if (tdbTbOpen("checkpoint.db", sizeof(int32_t), -1, NULL, pMeta->db, &pMeta->pCheckpointDb) < 0) {
+ if (tdbTbOpen("checkpoint.db", sizeof(int32_t), -1, NULL, pMeta->db, &pMeta->pCheckpointDb, 0) < 0) {
goto _err;
}
@@ -262,12 +262,14 @@ int32_t streamLoadTasks(SStreamMeta* pMeta) {
if (pMeta->expandFunc(pMeta->ahandle, pTask) < 0) {
tdbFree(pKey);
tdbFree(pVal);
+ tdbTbcClose(pCur);
return -1;
}
if (taosHashPut(pMeta->pTasks, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void*)) < 0) {
tdbFree(pKey);
tdbFree(pVal);
+ tdbTbcClose(pCur);
return -1;
}
}
diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c
index c0ed135d74..c3c58e125a 100644
--- a/source/libs/stream/src/streamState.c
+++ b/source/libs/stream/src/streamState.c
@@ -24,6 +24,40 @@ typedef struct SStateKey {
int64_t opNum;
} SStateKey;
+typedef struct SStateSessionKey {
+ SSessionKey key;
+ int64_t opNum;
+} SStateSessionKey;
+
+static inline int sessionKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2) {
+ if (pWin1->groupId > pWin2->groupId) {
+ return 1;
+ } else if (pWin1->groupId < pWin2->groupId) {
+ return -1;
+ }
+
+ if (pWin1->win.skey > pWin2->win.ekey) {
+ return 1;
+ } else if (pWin1->win.ekey < pWin2->win.skey) {
+ return -1;
+ }
+
+ return 0;
+}
+
+static inline int stateSessionKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
+ SStateSessionKey* pWin1 = (SStateSessionKey*)pKey1;
+ SStateSessionKey* pWin2 = (SStateSessionKey*)pKey2;
+
+ if (pWin1->opNum > pWin2->opNum) {
+ return 1;
+ } else if (pWin1->opNum < pWin2->opNum) {
+ return -1;
+ }
+
+ return sessionKeyCmpr(&pWin1->key, &pWin2->key);
+}
+
static inline int stateKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
SStateKey* pWin1 = (SStateKey*)pKey1;
SStateKey* pWin2 = (SStateKey*)pKey2;
@@ -65,21 +99,26 @@ SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath, int
memset(statePath, 0, 300);
tstrncpy(statePath, path, 300);
}
- if (tdbOpen(statePath, szPage, pages, &pState->db) < 0) {
+ if (tdbOpen(statePath, szPage, pages, &pState->db, 0) < 0) {
goto _err;
}
// open state storage backend
- if (tdbTbOpen("state.db", sizeof(SStateKey), -1, stateKeyCmpr, pState->db, &pState->pStateDb) < 0) {
+ if (tdbTbOpen("state.db", sizeof(SStateKey), -1, stateKeyCmpr, pState->db, &pState->pStateDb, 0) < 0) {
goto _err;
}
// todo refactor
- if (tdbTbOpen("fill.state.db", sizeof(SWinKey), -1, winKeyCmpr, pState->db, &pState->pFillStateDb) < 0) {
+ if (tdbTbOpen("fill.state.db", sizeof(SWinKey), -1, winKeyCmpr, pState->db, &pState->pFillStateDb, 0) < 0) {
goto _err;
}
- if (tdbTbOpen("func.state.db", sizeof(STupleKey), -1, STupleKeyCmpr, pState->db, &pState->pFuncStateDb) < 0) {
+ if (tdbTbOpen("session.state.db", sizeof(SStateSessionKey), -1, stateSessionKeyCmpr, pState->db,
+ &pState->pSessionStateDb, 0) < 0) {
+ goto _err;
+ }
+
+ if (tdbTbOpen("func.state.db", sizeof(STupleKey), -1, STupleKeyCmpr, pState->db, &pState->pFuncStateDb, 0) < 0) {
goto _err;
}
@@ -95,6 +134,7 @@ _err:
tdbTbClose(pState->pStateDb);
tdbTbClose(pState->pFuncStateDb);
tdbTbClose(pState->pFillStateDb);
+ tdbTbClose(pState->pSessionStateDb);
tdbClose(pState->db);
taosMemoryFree(pState);
return NULL;
@@ -105,6 +145,7 @@ void streamStateClose(SStreamState* pState) {
tdbTbClose(pState->pStateDb);
tdbTbClose(pState->pFuncStateDb);
tdbTbClose(pState->pFillStateDb);
+ tdbTbClose(pState->pSessionStateDb);
tdbClose(pState->db);
taosMemoryFree(pState);
@@ -241,11 +282,11 @@ SStreamStateCur* streamStateGetCur(SStreamState* pState, const SWinKey* key) {
if (pCur == NULL) return NULL;
tdbTbcOpen(pState->pStateDb, &pCur->pCur, NULL);
- int32_t c;
+ int32_t c = 0;
SStateKey sKey = {.key = *key, .opNum = pState->number};
tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateKey), &c);
if (c != 0) {
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
pCur->number = pState->number;
@@ -257,7 +298,7 @@ SStreamStateCur* streamStateFillGetCur(SStreamState* pState, const SWinKey* key)
if (pCur == NULL) return NULL;
tdbTbcOpen(pState->pFillStateDb, &pCur->pCur, NULL);
- int32_t c;
+ int32_t c = 0;
tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c);
if (c != 0) {
streamStateFreeCur(pCur);
@@ -348,21 +389,21 @@ SStreamStateCur* streamStateSeekKeyNext(SStreamState* pState, const SWinKey* key
}
pCur->number = pState->number;
if (tdbTbcOpen(pState->pStateDb, &pCur->pCur, NULL) < 0) {
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
SStateKey sKey = {.key = *key, .opNum = pState->number};
- int32_t c;
+ int32_t c = 0;
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateKey), &c) < 0) {
tdbTbcClose(pCur->pCur);
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
if (c > 0) return pCur;
if (tdbTbcMoveToNext(pCur->pCur) < 0) {
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
@@ -375,20 +416,20 @@ SStreamStateCur* streamStateFillSeekKeyNext(SStreamState* pState, const SWinKey*
return NULL;
}
if (tdbTbcOpen(pState->pFillStateDb, &pCur->pCur, NULL) < 0) {
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
- int32_t c;
+ int32_t c = 0;
if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) {
tdbTbcClose(pCur->pCur);
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
if (c > 0) return pCur;
if (tdbTbcMoveToNext(pCur->pCur) < 0) {
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
@@ -401,20 +442,20 @@ SStreamStateCur* streamStateFillSeekKeyPrev(SStreamState* pState, const SWinKey*
return NULL;
}
if (tdbTbcOpen(pState->pFillStateDb, &pCur->pCur, NULL) < 0) {
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
- int32_t c;
+ int32_t c = 0;
if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) {
tdbTbcClose(pCur->pCur);
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
if (c < 0) return pCur;
if (tdbTbcMoveToPrev(pCur->pCur) < 0) {
- taosMemoryFree(pCur);
+ streamStateFreeCur(pCur);
return NULL;
}
@@ -445,3 +486,229 @@ void streamStateFreeCur(SStreamStateCur* pCur) {
}
void streamFreeVal(void* val) { tdbFree(val); }
+
+int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, const void* value, int32_t vLen) {
+ SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
+ return tdbTbUpsert(pState->pSessionStateDb, &sKey, sizeof(SStateSessionKey), value, vLen, &pState->txn);
+}
+
+SStreamStateCur* streamStateSessionGetRanomCur(SStreamState* pState, const SSessionKey* key) {
+ SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur));
+ if (pCur == NULL) return NULL;
+ tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL);
+
+ int32_t c = 0;
+ SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
+ tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c);
+ if (c != 0) {
+ streamStateFreeCur(pCur);
+ return NULL;
+ }
+ pCur->number = pState->number;
+ return pCur;
+}
+
+int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen) {
+ SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key);
+ void* tmp = NULL;
+ if (streamStateSessionGetKVByCur(pCur, key, (const void**)&tmp, pVLen) == 0) {
+ *pVal = tdbRealloc(NULL, *pVLen);
+ memcpy(*pVal, tmp, *pVLen);
+ streamStateFreeCur(pCur);
+ return 0;
+ }
+ streamStateFreeCur(pCur);
+ return -1;
+}
+
+int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key) {
+ SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
+ return tdbTbDelete(pState->pSessionStateDb, &sKey, sizeof(SStateSessionKey), &pState->txn);
+}
+
+SStreamStateCur* streamStateSessionSeekKeyPrev(SStreamState* pState, const SSessionKey* key) {
+ SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur));
+ if (pCur == NULL) {
+ return NULL;
+ }
+ pCur->number = pState->number;
+ if (tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL) < 0) {
+ streamStateFreeCur(pCur);
+ return NULL;
+ }
+
+ SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
+ int32_t c = 0;
+ if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) {
+ tdbTbcClose(pCur->pCur);
+ streamStateFreeCur(pCur);
+ return NULL;
+ }
+ if (c > 0) return pCur;
+
+ if (tdbTbcMoveToPrev(pCur->pCur) < 0) {
+ streamStateFreeCur(pCur);
+ return NULL;
+ }
+
+ return pCur;
+}
+
+SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key) {
+ SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur));
+ if (pCur == NULL) {
+ return NULL;
+ }
+ pCur->number = pState->number;
+ if (tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL) < 0) {
+ streamStateFreeCur(pCur);
+ return NULL;
+ }
+
+ SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
+ int32_t c = 0;
+ if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) {
+ tdbTbcClose(pCur->pCur);
+ streamStateFreeCur(pCur);
+ return NULL;
+ }
+ if (c > 0) return pCur;
+
+ if (tdbTbcMoveToNext(pCur->pCur) < 0) {
+ streamStateFreeCur(pCur);
+ return NULL;
+ }
+
+ return pCur;
+}
+
+int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, const void** pVal, int32_t* pVLen) {
+ if (!pCur) {
+ return -1;
+ }
+ const SStateSessionKey* pKTmp = NULL;
+ int32_t kLen;
+ if (tdbTbcGet(pCur->pCur, (const void**)&pKTmp, &kLen, pVal, pVLen) < 0) {
+ return -1;
+ }
+ if (pKTmp->opNum != pCur->number) {
+ return -1;
+ }
+ if (pKey->groupId != 0 && pKey->groupId != pKTmp->key.groupId) {
+ return -1;
+ }
+ *pKey = pKTmp->key;
+ return 0;
+}
+
+int32_t streamStateSessionClear(SStreamState* pState) {
+ SSessionKey key = {.win.skey = 0, .win.ekey = 0, .groupId = 0};
+ streamStateSessionPut(pState, &key, NULL, 0);
+ SStreamStateCur* pCur = streamStateSessionSeekKeyNext(pState, &key);
+ while (1) {
+ SSessionKey delKey = {0};
+ void* buf = NULL;
+ int32_t size = 0;
+ int32_t code = streamStateSessionGetKVByCur(pCur, &delKey, buf, &size);
+ if (code == 0) {
+ memset(buf, 0, size);
+ streamStateSessionPut(pState, &delKey, buf, size);
+ } else {
+ break;
+ }
+ streamStateCurNext(pState, pCur);
+ }
+ streamStateFreeCur(pCur);
+ streamStateSessionDel(pState, &key);
+ return 0;
+}
+
+SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKey* key) {
+ SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key);
+ SSessionKey resKey = *key;
+ while (1) {
+ streamStateCurPrev(pState, pCur);
+ SSessionKey tmpKey = *key;
+ int32_t code = streamStateSessionGetKVByCur(pCur, &tmpKey, NULL, 0);
+ if (code == TSDB_CODE_SUCCESS && sessionKeyCmpr(key, &tmpKey) == 0) {
+ resKey = tmpKey;
+ } else {
+ break;
+ }
+ }
+ streamStateFreeCur(pCur);
+ return streamStateSessionGetRanomCur(pState, &resKey);
+}
+
+int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen) {
+ // todo refactor
+ SStreamStateCur* pCur = streamStateSessionGetCur(pState, key);
+ int32_t size = *pVLen;
+ void* tmp = NULL;
+ *pVal = tdbRealloc(NULL, size);
+ memset(*pVal, 0, size);
+ if (streamStateSessionGetKVByCur(pCur, key, (const void**)&tmp, pVLen) == 0) {
+ memcpy(*pVal, tmp, *pVLen);
+ streamStateFreeCur(pCur);
+ return 0;
+ }
+ streamStateFreeCur(pCur);
+ return 1;
+}
+
+int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
+ state_key_cmpr_fn fn, void** pVal, int32_t* pVLen) {
+ // todo refactor
+ int32_t res = TSDB_CODE_SUCCESS;
+ SSessionKey tmpKey = *key;
+ int32_t valSize = *pVLen;
+ void* tmp = tdbRealloc(NULL, valSize);
+ if (!tmp) {
+ return -1;
+ }
+
+ SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key);
+ int32_t code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen);
+ if (code == TSDB_CODE_SUCCESS) {
+ memcpy(tmp, *pVal, valSize);
+ *pVal = tmp;
+ streamStateFreeCur(pCur);
+ return res;
+ }
+ streamStateFreeCur(pCur);
+
+ streamStateSessionPut(pState, key, NULL, 0);
+ pCur = streamStateSessionGetRanomCur(pState, key);
+ streamStateCurPrev(pState, pCur);
+ code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen);
+ if (code == TSDB_CODE_SUCCESS) {
+ void* stateKey = (char*)(*pVal) + (valSize - keyDataLen);
+ if (fn(pKeyData, stateKey) == true) {
+ memcpy(tmp, *pVal, valSize);
+ goto _end;
+ }
+ }
+
+ streamStateFreeCur(pCur);
+ *key = tmpKey;
+ pCur = streamStateSessionSeekKeyNext(pState, key);
+ code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen);
+ if (code == TSDB_CODE_SUCCESS) {
+ void* stateKey = (char*)(*pVal) + (valSize - keyDataLen);
+ if (fn(pKeyData, stateKey) == true) {
+ memcpy(tmp, *pVal, valSize);
+ goto _end;
+ }
+ }
+
+ *key = tmpKey;
+ res = 1;
+ memset(tmp, 0, valSize);
+
+_end:
+
+ *pVal = tmp;
+ streamStateSessionDel(pState, &tmpKey);
+ streamStateFreeCur(pCur);
+ return res;
+}
diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c
index ce5917de29..5304938195 100644
--- a/source/libs/stream/src/streamTask.c
+++ b/source/libs/stream/src/streamTask.c
@@ -119,7 +119,10 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
for (int32_t i = 0; i < epSz; i++) {
SStreamChildEpInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamChildEpInfo));
if (pInfo == NULL) return -1;
- if (tDecodeStreamEpInfo(pDecoder, pInfo) < 0) return -1;
+ if (tDecodeStreamEpInfo(pDecoder, pInfo) < 0) {
+ taosMemoryFreeClear(pInfo);
+ return -1;
+ }
taosArrayPush(pTask->childEpInfo, &pInfo);
}
diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h
index 101e99afea..4e2a8647b2 100644
--- a/source/libs/sync/inc/syncInt.h
+++ b/source/libs/sync/inc/syncInt.h
@@ -287,6 +287,12 @@ void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s);
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s);
+void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s);
+void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s);
+
+void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
+void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
+
// for debug --------------
void syncNodePrint(SSyncNode* pObj);
void syncNodePrint2(char* s, SSyncNode* pObj);
diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c
index 83bd7a5f38..8ccfce603d 100644
--- a/source/libs/sync/src/syncMain.c
+++ b/source/libs/sync/src/syncMain.c
@@ -2282,7 +2282,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
- //ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted));
+ // ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted));
syncNodeBecomeLeader(pSyncNode, "candidate to leader");
syncNodeLog2("==state change syncNodeCandidate2Leader==", pSyncNode);
@@ -2676,7 +2676,7 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
if (ths->state == TAOS_SYNC_STATE_LEADER) {
int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
if (code != 0) {
- sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno));
+ sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno));
return -1;
}
syncNodeReplicate(ths, false);
@@ -2726,6 +2726,55 @@ int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) {
return ret;
}
+int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
+ syncLogRecvHeartbeat(ths, pMsg, "");
+
+ SyncHeartbeatReply* pMsgReply = syncHeartbeatReplyBuild(ths->vgId);
+ pMsgReply->destId = pMsg->srcId;
+ pMsgReply->srcId = ths->myRaftId;
+ pMsgReply->term = ths->pRaftStore->currentTerm;
+ pMsgReply->privateTerm = 8864; // magic number
+
+ SRpcMsg rpcMsg;
+ syncHeartbeatReply2RpcMsg(pMsgReply, &rpcMsg);
+
+ if (pMsg->term >= ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) {
+ syncNodeBecomeFollower(ths, "become follower by hb");
+ }
+
+ if (pMsg->term == ths->pRaftStore->currentTerm) {
+ // sInfo("vgId:%d, heartbeat reset timer", ths->vgId);
+ syncNodeResetElectTimer(ths);
+
+#if 0
+ if (ths->state == TAOS_SYNC_STATE_FOLLOWER) {
+ syncNodeFollowerCommit(ths, pMsg->commitIndex);
+ }
+#endif
+ }
+
+ /*
+ // htonl
+ SMsgHead* pHead = rpcMsg.pCont;
+ pHead->contLen = htonl(pHead->contLen);
+ pHead->vgId = htonl(pHead->vgId);
+ */
+
+ // reply
+ syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
+
+ return 0;
+}
+
+int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg) {
+ syncLogRecvHeartbeatReply(ths, pMsg, "");
+
+ // update last reply time, make decision whether the other node is alive or not
+ syncIndexMgrSetRecvTime(ths->pMatchIndex, &(pMsg->destId), pMsg->startTime);
+
+ return 0;
+}
+
// TLA+ Spec
// ClientRequest(i, v) ==
// /\ state[i] = Leader
@@ -2754,7 +2803,7 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
if (code != 0) {
// del resp mgr, call FpCommitCb
- sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno));
+ sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno));
return -1;
}
@@ -3032,7 +3081,8 @@ static int32_t syncNodeProposeConfigChangeFinish(SSyncNode* ths, SyncReconfigFin
}
bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg) {
- return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType) && ths->vgId != 1);
+ return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType));
+ // return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType) && ths->vgId != 1);
}
int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag) {
@@ -3072,9 +3122,9 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
} else {
code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, i, &pEntry);
if (code != 0) {
- sError("vgId:%d, failed to get log entry since %s. index:%lld", ths->vgId, tstrerror(terrno), i);
- return -1;
- }
+ sError("vgId:%d, failed to get log entry since %s. index:%lld", ths->vgId, tstrerror(terrno), i);
+ return -1;
+ }
ASSERT(pEntry != NULL);
}
@@ -3084,7 +3134,8 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
// user commit
if ((ths->pFsm->FpCommitCb != NULL) && syncUtilUserCommit(pEntry->originalRpcType)) {
bool internalExecute = true;
- if ((ths->replicaNum == 1) && ths->restoreFinish && ths->vgId != 1) {
+ if ((ths->replicaNum == 1) && ths->restoreFinish) {
+ // if ((ths->replicaNum == 1) && ths->restoreFinish && ths->vgId != 1) {
internalExecute = false;
}
@@ -3335,3 +3386,45 @@ void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
syncNodeEventLog(pSyncNode, logBuf);
}
+
+void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) {
+ char host[64];
+ uint16_t port;
+ syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
+ char logBuf[256];
+ snprintf(logBuf, sizeof(logBuf),
+ "send sync-heartbeat from %s:%d {term:%" PRIu64 ", cmt:%" PRIu64 ", pterm:%" PRIu64 "}, %s", host, port,
+ pMsg->term, pMsg->commitIndex, pMsg->privateTerm, s);
+ syncNodeEventLog(pSyncNode, logBuf);
+}
+
+void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) {
+ char host[64];
+ uint16_t port;
+ syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
+ char logBuf[256];
+ snprintf(logBuf, sizeof(logBuf),
+ "recv sync-heartbeat from %s:%d {term:%" PRIu64 ", cmt:%" PRIu64 ", pterm:%" PRIu64 "}, %s", host, port,
+ pMsg->term, pMsg->commitIndex, pMsg->privateTerm, s);
+ syncNodeEventLog(pSyncNode, logBuf);
+}
+
+void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
+ char host[64];
+ uint16_t port;
+ syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
+ char logBuf[256];
+ snprintf(logBuf, sizeof(logBuf), "send sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s",
+ host, port, pMsg->term, pMsg->privateTerm, s);
+ syncNodeEventLog(pSyncNode, logBuf);
+}
+
+void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
+ char host[64];
+ uint16_t port;
+ syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
+ char logBuf[256];
+ snprintf(logBuf, sizeof(logBuf), "recv sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s",
+ host, port, pMsg->term, pMsg->privateTerm, s);
+ syncNodeEventLog(pSyncNode, logBuf);
+}
\ No newline at end of file
diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h
index c90d4e3c03..3d92d164b4 100644
--- a/source/libs/tdb/inc/tdb.h
+++ b/source/libs/tdb/inc/tdb.h
@@ -31,15 +31,17 @@ typedef struct STBC TBC;
typedef struct STxn TXN;
// TDB
-int32_t tdbOpen(const char *dbname, int szPage, int pages, TDB **ppDb);
+int32_t tdbOpen(const char *dbname, int szPage, int pages, TDB **ppDb, int8_t rollback);
int32_t tdbClose(TDB *pDb);
int32_t tdbBegin(TDB *pDb, TXN *pTxn);
int32_t tdbCommit(TDB *pDb, TXN *pTxn);
+int32_t tdbPostCommit(TDB *pDb, TXN *pTxn);
int32_t tdbAbort(TDB *pDb, TXN *pTxn);
int32_t tdbAlter(TDB *pDb, int pages);
// TTB
-int32_t tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb);
+int32_t tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb,
+ int8_t rollback);
int32_t tdbTbClose(TTB *pTb);
int32_t tdbTbDrop(TTB *pTb);
int32_t tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn);
diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c
index 8f11fb88a2..ba0b3dbcf8 100644
--- a/source/libs/tdb/src/db/tdbBtree.c
+++ b/source/libs/tdb/src/db/tdbBtree.c
@@ -1094,6 +1094,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
// fetch next ofp, a new ofp and make it dirty
ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt);
if (ret < 0) {
+ tdbFree(pBuf);
return -1;
}
}
@@ -1135,6 +1136,11 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
memcpy(pBuf, ((SCell *)pVal) + vLen - nLeft, bytes);
memcpy(pBuf + bytes, &pgno, sizeof(pgno));
+ if (ofp == NULL) {
+ tdbFree(pBuf);
+ return -1;
+ }
+
ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0);
if (ret < 0) {
tdbFree(pBuf);
diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c
index a2803d3ecf..1e2b059adb 100644
--- a/source/libs/tdb/src/db/tdbDb.c
+++ b/source/libs/tdb/src/db/tdbDb.c
@@ -15,7 +15,7 @@
#include "tdbInt.h"
-int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb) {
+int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, int8_t rollback) {
TDB *pDb;
int dsize;
int zsize;
@@ -66,7 +66,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb) {
#ifdef USE_MAINDB
// open main db
- ret = tdbTbOpen(TDB_MAINDB_NAME, -1, sizeof(SBtInfo), NULL, pDb, &pDb->pMainDb);
+ ret = tdbTbOpen(TDB_MAINDB_NAME, -1, sizeof(SBtInfo), NULL, pDb, &pDb->pMainDb, rollback);
if (ret < 0) {
return -1;
}
@@ -106,7 +106,8 @@ int32_t tdbBegin(TDB *pDb, TXN *pTxn) {
for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) {
ret = tdbPagerBegin(pPager, pTxn);
if (ret < 0) {
- tdbError("failed to begin pager since %s. dbName:%s, txnId:%ld", tstrerror(terrno), pDb->dbName, pTxn->txnId);
+ tdbError("failed to begin pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName,
+ pTxn->txnId);
return -1;
}
}
@@ -121,7 +122,23 @@ int32_t tdbCommit(TDB *pDb, TXN *pTxn) {
for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) {
ret = tdbPagerCommit(pPager, pTxn);
if (ret < 0) {
- tdbError("failed to commit pager since %s. dbName:%s, txnId:%ld", tstrerror(terrno), pDb->dbName, pTxn->txnId);
+ tdbError("failed to commit pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName,
+ pTxn->txnId);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int32_t tdbPostCommit(TDB *pDb, TXN *pTxn) {
+ SPager *pPager;
+ int ret;
+
+ for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) {
+ ret = tdbPagerPostCommit(pPager, pTxn);
+ if (ret < 0) {
+ tdbError("failed to commit pager since %s. dbName:%s, txnId:%d", tstrerror(terrno), pDb->dbName, pTxn->txnId);
return -1;
}
}
@@ -136,7 +153,8 @@ int32_t tdbAbort(TDB *pDb, TXN *pTxn) {
for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) {
ret = tdbPagerAbort(pPager, pTxn);
if (ret < 0) {
- tdbError("failed to abort pager since %s. dbName:%s, txnId:%ld", tstrerror(terrno), pDb->dbName, pTxn->txnId);
+ tdbError("failed to abort pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName,
+ pTxn->txnId);
return -1;
}
}
diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c
index 732a57639f..667cd706c5 100644
--- a/source/libs/tdb/src/db/tdbPCache.c
+++ b/source/libs/tdb/src/db/tdbPCache.c
@@ -105,7 +105,7 @@ static int tdbPCacheAlterImpl(SPCache *pCache, int32_t nPage) {
for (int32_t iPage = pCache->nPages; iPage < nPage; iPage++) {
if (tdbPageCreate(pCache->szPage, &aPage[iPage], tdbDefaultMalloc, NULL) < 0) {
// TODO: handle error
- tdbOsFree(pCache->aPage);
+ tdbOsFree(aPage);
return -1;
}
diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c
index 90332617cd..7c8ab16ec7 100644
--- a/source/libs/tdb/src/db/tdbPager.c
+++ b/source/libs/tdb/src/db/tdbPager.c
@@ -305,6 +305,18 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
return 0;
}
+int tdbPagerPostCommit(SPager *pPager, TXN *pTxn) {
+ if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) {
+ tdbError("failed to remove file due to %s. file:%s", strerror(errno), pPager->jFileName);
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ return -1;
+ }
+
+ pPager->inTran = 0;
+
+ return 0;
+}
+
// recovery dirty pages
int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
SPage *pPage;
@@ -563,7 +575,7 @@ static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) {
offset = (i64)pPage->pageSize * (TDB_PAGE_PGNO(pPage) - 1);
if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) {
- tdbError("failed to lseek due to %s. file:%s, offset:%ld", strerror(errno), pPager->dbFileName, offset);
+ tdbError("failed to lseek due to %s. file:%s, offset:%" PRId64, strerror(errno), pPager->dbFileName, offset);
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
@@ -618,7 +630,7 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
i64 offset = pPager->pageSize * (pgno - 1);
if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) {
- tdbError("failed to lseek fd due to %s. file:%s, offset:%ld", strerror(errno), pPager->dbFileName, offset);
+ tdbError("failed to lseek fd due to %s. file:%s, offset:%" PRId64, strerror(errno), pPager->dbFileName, offset);
terrno = TAOS_SYSTEM_ERROR(errno);
tdbOsFree(pageBuf);
return -1;
@@ -657,3 +669,13 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
return 0;
}
+
+int tdbPagerRollback(SPager *pPager) {
+ if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) {
+ tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), pPager->jFileName);
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/source/libs/tdb/src/db/tdbTable.c b/source/libs/tdb/src/db/tdbTable.c
index 008907ca77..73cc34a86f 100644
--- a/source/libs/tdb/src/db/tdbTable.c
+++ b/source/libs/tdb/src/db/tdbTable.c
@@ -24,7 +24,8 @@ struct STBC {
SBTC btc;
};
-int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb) {
+int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb,
+ int8_t rollback) {
TTB *pTb;
SPager *pPager;
int ret;
@@ -110,10 +111,14 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
return -1;
}
- ret = tdbPagerRestore(pPager, pTb->pBt);
- if (ret < 0) {
- tdbOsFree(pTb);
- return -1;
+ if (rollback) {
+ tdbPagerRollback(pPager);
+ } else {
+ ret = tdbPagerRestore(pPager, pTb->pBt);
+ if (ret < 0) {
+ tdbOsFree(pTb);
+ return -1;
+ }
}
*ppTb = pTb;
diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h
index 68434a4319..b45747c972 100644
--- a/source/libs/tdb/src/inc/tdbInt.h
+++ b/source/libs/tdb/src/inc/tdbInt.h
@@ -190,12 +190,14 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt);
int tdbPagerWrite(SPager *pPager, SPage *pPage);
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
int tdbPagerCommit(SPager *pPager, TXN *pTxn);
+int tdbPagerPostCommit(SPager *pPager, TXN *pTxn);
int tdbPagerAbort(SPager *pPager, TXN *pTxn);
int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg,
TXN *pTxn);
void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn);
int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno);
int tdbPagerRestore(SPager *pPager, SBTree *pBt);
+int tdbPagerRollback(SPager *pPager);
// tdbPCache.c ====================================
#define TDB_PCACHE_PAGE \
diff --git a/source/libs/tdb/test/tdbExOVFLTest.cpp b/source/libs/tdb/test/tdbExOVFLTest.cpp
index d98c271edb..6ead7c0dd6 100644
--- a/source/libs/tdb/test/tdbExOVFLTest.cpp
+++ b/source/libs/tdb/test/tdbExOVFLTest.cpp
@@ -140,7 +140,7 @@ static void generateBigVal(char *val, int valLen) {
static TDB *openEnv(char const *envName, int const pageSize, int const pageNum) {
TDB *pEnv = NULL;
- int ret = tdbOpen(envName, pageSize, pageNum, &pEnv);
+ int ret = tdbOpen(envName, pageSize, pageNum, &pEnv, 0);
if (ret) {
pEnv = NULL;
}
@@ -162,8 +162,8 @@ static void insertOfp(void) {
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
- // ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb);
- ret = tdbTbOpen("ofp_insert.db", 12, -1, compFunc, pEnv, &pDb);
+ // ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
+ ret = tdbTbOpen("ofp_insert.db", 12, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// open the pool
@@ -211,8 +211,8 @@ TEST(TdbOVFLPagesTest, TbGetTest) {
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
- // int ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb);
- int ret = tdbTbOpen("ofp_insert.db", 12, -1, compFunc, pEnv, &pDb);
+ // int ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
+ int ret = tdbTbOpen("ofp_insert.db", 12, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// generate value payload
@@ -253,7 +253,7 @@ TEST(TdbOVFLPagesTest, TbDeleteTest) {
// open db
TTB *pDb = NULL;
tdb_cmpr_fn_t compFunc = tKeyCmpr;
- ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb);
+ ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
// open the pool
@@ -354,12 +354,12 @@ TEST(tdb_test, simple_insert1) {
taosRemoveDir("tdb");
// Open Env
- ret = tdbOpen("tdb", pageSize, 64, &pEnv);
+ ret = tdbOpen("tdb", pageSize, 64, &pEnv, 0);
GTEST_ASSERT_EQ(ret, 0);
// Create a database
compFunc = tKeyCmpr;
- ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb);
+ ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
{
diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp
index 6070052127..f3a301cf5b 100644
--- a/source/libs/tdb/test/tdbTest.cpp
+++ b/source/libs/tdb/test/tdbTest.cpp
@@ -130,12 +130,12 @@ TEST(tdb_test, DISABLED_simple_insert1) {
taosRemoveDir("tdb");
// Open Env
- ret = tdbOpen("tdb", 4096, 64, &pEnv);
+ ret = tdbOpen("tdb", 4096, 64, &pEnv, 0);
GTEST_ASSERT_EQ(ret, 0);
// Create a database
compFunc = tKeyCmpr;
- ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb);
+ ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
{
@@ -250,12 +250,12 @@ TEST(tdb_test, DISABLED_simple_insert2) {
taosRemoveDir("tdb");
// Open Env
- ret = tdbOpen("tdb", 1024, 10, &pEnv);
+ ret = tdbOpen("tdb", 1024, 10, &pEnv, 0);
GTEST_ASSERT_EQ(ret, 0);
// Create a database
compFunc = tDefaultKeyCmpr;
- ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb);
+ ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
{
@@ -346,11 +346,11 @@ TEST(tdb_test, DISABLED_simple_delete1) {
pPool = openPool();
// open env
- ret = tdbOpen("tdb", 1024, 256, &pEnv);
+ ret = tdbOpen("tdb", 1024, 256, &pEnv, 0);
GTEST_ASSERT_EQ(ret, 0);
// open database
- ret = tdbTbOpen("db.db", -1, -1, tKeyCmpr, pEnv, &pDb);
+ ret = tdbTbOpen("db.db", -1, -1, tKeyCmpr, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
tdbTxnOpen(&txn, 0, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
@@ -435,11 +435,11 @@ TEST(tdb_test, DISABLED_simple_upsert1) {
taosRemoveDir("tdb");
// open env
- ret = tdbOpen("tdb", 4096, 64, &pEnv);
+ ret = tdbOpen("tdb", 4096, 64, &pEnv, 0);
GTEST_ASSERT_EQ(ret, 0);
// open database
- ret = tdbTbOpen("db.db", -1, -1, NULL, pEnv, &pDb);
+ ret = tdbTbOpen("db.db", -1, -1, NULL, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
pPool = openPool();
@@ -497,12 +497,12 @@ TEST(tdb_test, multi_thread_query) {
taosRemoveDir("tdb");
// Open Env
- ret = tdbOpen("tdb", 4096, 10, &pEnv);
+ ret = tdbOpen("tdb", 4096, 10, &pEnv, 0);
GTEST_ASSERT_EQ(ret, 0);
// Create a database
compFunc = tKeyCmpr;
- ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb);
+ ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
char key[64];
@@ -614,10 +614,10 @@ TEST(tdb_test, DISABLED_multi_thread1) {
taosRemoveDir("tdb");
// Open Env
- ret = tdbOpen("tdb", 512, 1, &pDb);
+ ret = tdbOpen("tdb", 512, 1, &pDb, 0);
GTEST_ASSERT_EQ(ret, 0);
- ret = tdbTbOpen("db.db", -1, -1, NULL, pDb, &pTb);
+ ret = tdbTbOpen("db.db", -1, -1, NULL, pDb, &pTb, 0);
GTEST_ASSERT_EQ(ret, 0);
auto insert = [](TDB *pDb, TTB *pTb, int nData, int *stop, std::shared_timed_mutex *mu) {
@@ -726,4 +726,4 @@ TEST(tdb_test, DISABLED_multi_thread1) {
ret = tdbClose(pDb);
GTEST_ASSERT_EQ(ret, 0);
#endif
-}
\ No newline at end of file
+}
diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c
index 616ab7875d..ac1881fc6d 100644
--- a/source/os/src/osEnv.c
+++ b/source/os/src/osEnv.c
@@ -105,3 +105,5 @@ void osSetSystemLocale(const char *inLocale, const char *inCharSet) {
memcpy(tsLocale, inLocale, strlen(inLocale) + 1);
memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1);
}
+
+void osSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; }
diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c
index d332d913ca..be862308f1 100644
--- a/source/os/src/osFile.c
+++ b/source/os/src/osFile.c
@@ -343,6 +343,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
TdFilePtr pFile = (TdFilePtr)taosMemoryMalloc(sizeof(TdFile));
if (pFile == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
if (fd >= 0) close(fd);
if (fp != NULL) fclose(fp);
return NULL;
diff --git a/source/os/src/osProc.c b/source/os/src/osProc.c
deleted file mode 100644
index f060ab48c9..0000000000
--- a/source/os/src/osProc.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#define ALLOW_FORBID_FUNC
-#define _DEFAULT_SOURCE
-#include "os.h"
-
-int32_t taosNewProc(char **args) {
-#ifdef WINDOWS
- assert(0);
- return 0;
-#else
- int32_t pid = fork();
- if (pid == 0) {
- args[0] = tsProcPath;
- // close(STDIN_FILENO);
- // close(STDOUT_FILENO);
- // close(STDERR_FILENO);
- return execvp(tsProcPath, args);
- } else {
- return pid;
- }
-#endif
-}
-
-void taosWaitProc(int32_t pid) {
-#ifdef WINDOWS
- assert(0);
-#else
- int32_t status = -1;
- waitpid(pid, &status, 0);
-#endif
-}
-
-void taosKillProc(int32_t pid) {
-#ifdef WINDOWS
- assert(0);
-#else
- kill(pid, SIGINT);
-#endif
-}
-
-bool taosProcExist(int32_t pid) {
-#ifdef WINDOWS
- assert(0);
- return false;
-#else
- int32_t p = getpgid(pid);
- return p >= 0;
-#endif
-}
-
-// the length of the new name must be less than the original name to take effect
-void taosSetProcName(int32_t argc, char **argv, const char *name) {
- setThreadName(name);
-
- for (int32_t i = 0; i < argc; ++i) {
- int32_t len = strlen(argv[i]);
- for (int32_t j = 0; j < len; ++j) {
- argv[i][j] = 0;
- }
- if (i == 0) {
- tstrncpy(argv[0], name, len + 1);
- }
- }
-}
-
-void taosSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; }
diff --git a/source/os/src/osShm.c b/source/os/src/osShm.c
deleted file mode 100644
index cb09e2fb38..0000000000
--- a/source/os/src/osShm.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#define ALLOW_FORBID_FUNC
-#define _DEFAULT_SOURCE
-#include "os.h"
-
-#define MAX_SHMIDS 6
-
-static int32_t shmids[MAX_SHMIDS] = {0};
-
-static void taosDeleteCreatedShms() {
-#if defined(WINDOWS)
- assert(0);
-#else
- for (int32_t i = 0; i < MAX_SHMIDS; ++i) {
- int32_t shmid = shmids[i] - 1;
- if (shmid >= 0) {
- shmctl(shmid, IPC_RMID, NULL);
- }
- }
-#endif
-}
-
-int32_t taosCreateShm(SShm* pShm, int32_t key, int32_t shmsize) {
-#if defined(WINDOWS)
- assert(0);
-#else
- pShm->id = -1;
-
-#if 1
- key_t __shkey = IPC_PRIVATE;
- int32_t __shmflag = IPC_CREAT | IPC_EXCL | 0600;
-#else
- key_t __shkey = 0X95270000 + key;
- int32_t __shmflag = IPC_CREAT | 0600;
-#endif
-
- int32_t shmid = shmget(__shkey, shmsize, __shmflag);
- if (shmid < 0) {
- return -1;
- }
-
- void* shmptr = shmat(shmid, NULL, 0);
- if (shmptr == NULL) {
- return -1;
- }
-
- pShm->id = shmid;
- pShm->size = shmsize;
- pShm->ptr = shmptr;
-
-#if 0
- if (key >= 0 && key < MAX_SHMIDS) {
- shmids[key] = pShm->id + 1;
- }
- atexit(taosDeleteCreatedShms);
-#else
- shmctl(pShm->id, IPC_RMID, NULL);
-#endif
-
-#endif
- return 0;
-}
-
-void taosDropShm(SShm* pShm) {
-#if defined(WINDOWS)
- assert(0);
-#else
- if (pShm->id >= 0) {
- if (pShm->ptr != NULL) {
- shmdt(pShm->ptr);
- }
- shmctl(pShm->id, IPC_RMID, NULL);
- }
- pShm->id = -1;
- pShm->size = 0;
- pShm->ptr = NULL;
-#endif
-}
-
-int32_t taosAttachShm(SShm* pShm) {
-#if defined(WINDOWS)
- assert(0);
-#else
- errno = 0;
-
- void* ptr = shmat(pShm->id, NULL, 0);
- if (errno == 0) {
- pShm->ptr = ptr;
- }
-#endif
- return errno;
-}
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index 9a117c6eb4..37f9734eab 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -238,8 +238,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_QNODE_ALREADY_EXIST, "Qnode already exists"
TAOS_DEFINE_ERROR(TSDB_CODE_MND_QNODE_NOT_EXIST, "Qnode not there")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SNODE_ALREADY_EXIST, "Snode already exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SNODE_NOT_EXIST, "Snode not there")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_BNODE_ALREADY_EXIST, "Bnode already exists")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_BNODE_NOT_EXIST, "Bnode not there")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_FEW_MNODES, "The replica of mnode cannot less than 1")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_MNODES, "The replica of mnode cannot exceed 3")
diff --git a/source/util/src/tsched.c b/source/util/src/tsched.c
index f524680331..467f26b362 100644
--- a/source/util/src/tsched.c
+++ b/source/util/src/tsched.c
@@ -26,19 +26,25 @@ static void *taosProcessSchedQueue(void *param);
static void taosDumpSchedulerStatus(void *qhandle, void *tmrId);
void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *label, SSchedQueue *pSched) {
+ bool schedMalloced = false;
+
if (NULL == pSched) {
pSched = (SSchedQueue *)taosMemoryCalloc(sizeof(SSchedQueue), 1);
if (pSched == NULL) {
uError("%s: no enough memory for pSched", label);
return NULL;
}
+
+ schedMalloced = true;
}
pSched->queue = (SSchedMsg *)taosMemoryCalloc(sizeof(SSchedMsg), queueSize);
if (pSched->queue == NULL) {
uError("%s: no enough memory for queue", label);
taosCleanUpScheduler(pSched);
- taosMemoryFree(pSched);
+ if (schedMalloced) {
+ taosMemoryFree(pSched);
+ }
return NULL;
}
@@ -46,6 +52,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
if (pSched->qthread == NULL) {
uError("%s: no enough memory for qthread", label);
taosCleanUpScheduler(pSched);
+ if (schedMalloced) {
+ taosMemoryFree(pSched);
+ }
return NULL;
}
@@ -58,18 +67,27 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
if (taosThreadMutexInit(&pSched->queueMutex, NULL) < 0) {
uError("init %s:queueMutex failed(%s)", label, strerror(errno));
taosCleanUpScheduler(pSched);
+ if (schedMalloced) {
+ taosMemoryFree(pSched);
+ }
return NULL;
}
if (tsem_init(&pSched->emptySem, 0, (uint32_t)pSched->queueSize) != 0) {
uError("init %s:empty semaphore failed(%s)", label, strerror(errno));
taosCleanUpScheduler(pSched);
+ if (schedMalloced) {
+ taosMemoryFree(pSched);
+ }
return NULL;
}
if (tsem_init(&pSched->fullSem, 0, 0) != 0) {
uError("init %s:full semaphore failed(%s)", label, strerror(errno));
taosCleanUpScheduler(pSched);
+ if (schedMalloced) {
+ taosMemoryFree(pSched);
+ }
return NULL;
}
@@ -83,6 +101,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
if (code != 0) {
uError("%s: failed to create rpc thread(%s)", label, strerror(errno));
taosCleanUpScheduler(pSched);
+ if (schedMalloced) {
+ taosMemoryFree(pSched);
+ }
return NULL;
}
++pSched->numOfThreads;
diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt
index 6e42ef7e75..2e307771b7 100644
--- a/source/util/test/CMakeLists.txt
+++ b/source/util/test/CMakeLists.txt
@@ -45,14 +45,6 @@ INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
# add_executable(encodeTest "encodeTest.cpp")
# target_link_libraries(encodeTest os util gtest gtest_main)
-# queueTest
-# add_executable(procTest "procTest.cpp")
-# target_link_libraries(procTest os util transport sut gtest_main)
-# add_test(
-# NAME procTest
-# COMMAND procTest
-# )
-
# cfgTest
add_executable(cfgTest "cfgTest.cpp")
target_link_libraries(cfgTest os util gtest_main)
diff --git a/source/util/test/procTest.cpp b/source/util/test/procTest.cpp
deleted file mode 100644
index 53d3fa2c4b..0000000000
--- a/source/util/test/procTest.cpp
+++ /dev/null
@@ -1,264 +0,0 @@
-/**
- * @file queue.cpp
- * @author slguan (slguan@taosdata.com)
- * @brief UTIL module queue tests
- * @version 1.0
- * @date 2022-01-27
- *
- * @copyright Copyright (c) 2022
- *
- */
-#if 0
-#include
-#include "tlog.h"
-#include "tprocess.h"
-#include "tqueue.h"
-
-typedef struct STestMsg {
- uint16_t msgType;
- void *pCont;
- int contLen;
- int32_t code;
- void *handle; // rpc handle returned to app
- void *ahandle; // app handle set by client
- int noResp; // has response or not(default 0, 0: resp, 1: no resp);
- int persistHandle; // persist handle or not
-} STestMsg;
-
-class UtilTesProc : public ::testing::Test {
- public:
- void SetUp() override {
- shm.id = -1;
- for (int32_t i = 0; i < 4000; ++i) {
- body[i] = i % 26 + 'a';
- }
- head.pCont = body;
- head.code = 1;
- head.msgType = 2;
- head.noResp = 3;
- head.persistHandle = 4;
-
- taosRemoveDir(TD_TMP_DIR_PATH "td");
- taosMkDir(TD_TMP_DIR_PATH "td");
- tstrncpy(tsLogDir, TD_TMP_DIR_PATH "td", PATH_MAX);
- if (taosInitLog("taosdlog", 1) != 0) {
- printf("failed to init log file\n");
- }
- }
- void TearDown() override { taosDropShm(&shm); }
-
- public:
- static STestMsg head;
- static char body[4000];
- static SShm shm;
- static void SetUpTestSuite() {}
- static void TearDownTestSuite() {}
-};
-
-SShm UtilTesProc::shm;
-char UtilTesProc::body[4000];
-STestMsg UtilTesProc::head;
-
-TEST_F(UtilTesProc, 00_Init_Cleanup) {
- ASSERT_EQ(taosCreateShm(&shm, 1234, 1024 * 1024 * 2), 0);
-
- shm.size = 1023;
- SProcCfg cfg = {(ProcConsumeFp)NULL,
- (ProcMallocFp)taosAllocateQitem,
- (ProcFreeFp)taosFreeQitem,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryMalloc,
- (ProcConsumeFp)NULL,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryMalloc,
- shm,
- &shm,
- "1234"};
- SProc *proc = dmInitProc(&cfg);
- ASSERT_EQ(proc, nullptr);
-
- shm.size = 2468;
- cfg.shm = shm;
- proc = dmInitProc(&cfg);
- ASSERT_NE(proc, nullptr);
-
- ASSERT_EQ(dmRunProc(proc), 0);
- dmCleanupProc(proc);
- taosDropShm(&shm);
-}
-
-void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) {
- STestMsg msg;
- memcpy(&msg, pHead, headLen);
- char body[2000] = {0};
- memcpy(body, pBody, bodyLen);
-
- uDebug("====> parent:%" PRId64 " ftype:%d, headLen:%d bodyLen:%d head:%d:%d:%d:%d body:%s <====", (int64_t)parent,
- ftype, headLen, bodyLen, msg.code, msg.msgType, msg.noResp, msg.persistHandle, body);
- taosMemoryFree(pBody);
- taosFreeQitem(pHead);
-}
-
-TEST_F(UtilTesProc, 01_Push_Pop_Child) {
- shm.size = 3000;
- ASSERT_EQ(taosCreateShm(&shm, 1235, shm.size), 0);
- SProcCfg cfg = {(ProcConsumeFp)ConsumeChild1,
- (ProcMallocFp)taosAllocateQitem,
- (ProcFreeFp)taosFreeQitem,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- (ProcConsumeFp)NULL,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- shm,
- (void *)((int64_t)1235),
- "1235_c"};
- SProc *cproc = dmInitProc(&cfg);
- ASSERT_NE(cproc, nullptr);
-
- ASSERT_NE(dmPutToProcCQueue(cproc, &head, 0, body, 0, 0, 0, DND_FUNC_RSP), 0);
- ASSERT_NE(dmPutToProcCQueue(cproc, &head, 0, body, 0, 0, 0, DND_FUNC_REGIST), 0);
- ASSERT_NE(dmPutToProcCQueue(cproc, &head, 0, body, 0, 0, 0, DND_FUNC_RELEASE), 0);
- ASSERT_NE(dmPutToProcCQueue(cproc, NULL, 12, body, 0, 0, 0, DND_FUNC_REQ), 0);
- ASSERT_NE(dmPutToProcCQueue(cproc, &head, 0, body, 0, 0, 0, DND_FUNC_REQ), 0);
- ASSERT_NE(dmPutToProcCQueue(cproc, &head, shm.size, body, 0, 0, 0, DND_FUNC_REQ), 0);
- ASSERT_NE(dmPutToProcCQueue(cproc, &head, sizeof(STestMsg), body, shm.size, 0, 0, DND_FUNC_REQ), 0);
-
- for (int32_t j = 0; j < 1000; j++) {
- int32_t i = 0;
- for (i = 0; i < 20; ++i) {
- ASSERT_EQ(dmPutToProcCQueue(cproc, &head, sizeof(STestMsg), body, i, 0, 0, DND_FUNC_REQ), 0);
- }
- ASSERT_NE(dmPutToProcCQueue(cproc, &head, sizeof(STestMsg), body, i, 0, 0, DND_FUNC_REQ), 0);
-
- cfg.isChild = true;
- cfg.name = "1235_p";
- SProc *pproc = dmInitProc(&cfg);
- ASSERT_NE(pproc, nullptr);
- dmRunProc(pproc);
- dmCleanupProc(pproc);
- }
-
- dmCleanupProc(cproc);
- taosDropShm(&shm);
-}
-
-void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) {
- STestMsg msg;
- memcpy(&msg, pHead, headLen);
- char body[2000] = {0};
- memcpy(body, pBody, bodyLen);
-
- uDebug("----> parent:%" PRId64 " ftype:%d, headLen:%d bodyLen:%d head:%d:%d:%d:%d body:%s <----", (int64_t)parent,
- ftype, headLen, bodyLen, msg.code, msg.msgType, msg.noResp, msg.persistHandle, body);
- taosMemoryFree(pBody);
- taosMemoryFree(pHead);
-}
-
-TEST_F(UtilTesProc, 02_Push_Pop_Parent) {
- shm.size = 3000;
- ASSERT_EQ(taosCreateShm(&shm, 1236, shm.size), 0);
- SProcCfg cfg = {(ProcConsumeFp)NULL,
- (ProcMallocFp)taosAllocateQitem,
- (ProcFreeFp)taosFreeQitem,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- (ProcConsumeFp)ConsumeParent1,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- shm,
- (void *)((int64_t)1236),
- "1236_c"};
- SProc *cproc = dmInitProc(&cfg);
- ASSERT_NE(cproc, nullptr);
-
- cfg.name = "1236_p";
- cfg.isChild = true;
- SProc *pproc = dmInitProc(&cfg);
- ASSERT_NE(pproc, nullptr);
-
- for (int32_t j = 0; j < 1000; j++) {
- int32_t i = 0;
- for (i = 0; i < 20; ++i) {
- dmPutToProcPQueue(pproc, &head, sizeof(STestMsg), body, i, DND_FUNC_REQ);
- }
-
- dmRunProc(cproc);
- dmStopProc(cproc);
- }
-
- dmCleanupProc(pproc);
- dmCleanupProc(cproc);
- taosDropShm(&shm);
-}
-
-void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) {
- STestMsg msg;
- memcpy(&msg, pHead, headLen);
- char body[2000] = {0};
- memcpy(body, pBody, bodyLen);
-
- uDebug("====> parent:%" PRId64 " ftype:%d, headLen:%d bodyLen:%d handle:%" PRId64 " body:%s <====", (int64_t)parent,
- ftype, headLen, bodyLen, (int64_t)msg.handle, body);
- taosMemoryFree(pBody);
- taosFreeQitem(pHead);
-}
-
-void processHandle(void *handle) { uDebug("----> remove handle:%" PRId64 " <----", (int64_t)handle); }
-
-TEST_F(UtilTesProc, 03_Handle) {
- // uDebugFlag = 207;
- shm.size = 3000;
- ASSERT_EQ(taosCreateShm(&shm, 1237, shm.size), 0);
- SProcCfg cfg = {(ProcConsumeFp)ConsumeChild3,
- (ProcMallocFp)taosAllocateQitem,
- (ProcFreeFp)taosFreeQitem,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- (ProcConsumeFp)NULL,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- (ProcMallocFp)taosMemoryMalloc,
- (ProcFreeFp)taosMemoryFree,
- shm,
- (void *)((int64_t)1235),
- "1237_p"};
- SProc *cproc = dmInitProc(&cfg);
- ASSERT_NE(cproc, nullptr);
-
- for (int32_t j = 0; j < 1; j++) {
- int32_t i = 0;
- for (i = 0; i < 20; ++i) {
- head.handle = (void *)((int64_t)i);
- ASSERT_EQ(dmPutToProcCQueue(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), i, DND_FUNC_REQ), 0);
- }
-
- cfg.isChild = true;
- cfg.name = "child_queue";
- SProc *pproc = dmInitProc(&cfg);
- ASSERT_NE(pproc, nullptr);
- dmRunProc(pproc);
- dmCleanupProc(pproc);
-
- int64_t ref = 0;
-
- ref = dmRemoveProcRpcHandle(cproc, (void *)((int64_t)3));
- EXPECT_EQ(ref, 3);
- ref = dmRemoveProcRpcHandle(cproc, (void *)((int64_t)5));
- EXPECT_EQ(ref, 5);
- ref = dmRemoveProcRpcHandle(cproc, (void *)((int64_t)6));
- EXPECT_EQ(ref, 6);
- dmCloseProcRpcHandles(cproc, processHandle);
- }
-
- dmCleanupProc(cproc);
- taosDropShm(&shm);
-}
-
-#endif
\ No newline at end of file
diff --git a/tests/parallel_test/run_case.sh b/tests/parallel_test/run_case.sh
index 58dcb87345..e0b905375a 100755
--- a/tests/parallel_test/run_case.sh
+++ b/tests/parallel_test/run_case.sh
@@ -67,9 +67,13 @@ mkdir -p /var/lib/taos
cd $CONTAINER_TESTDIR/tests/$exec_dir
ulimit -c unlimited
+md5sum /usr/lib/libtaos.so.1
+md5sum /home/TDinternal/debug/build/lib/libtaos.so
$TIMEOUT_CMD $cmd
RET=$?
echo "cmd exit code: $RET"
+md5sum /usr/lib/libtaos.so.1
+md5sum /home/TDinternal/debug/build/lib/libtaos.so
if [ $RET -ne 0 ]; then
pwd
diff --git a/tests/parallel_test/run_container.sh b/tests/parallel_test/run_container.sh
index 0de777e6f1..47a918f8d1 100755
--- a/tests/parallel_test/run_container.sh
+++ b/tests/parallel_test/run_container.sh
@@ -68,12 +68,16 @@ if [ $ent -ne 0 ]; then
CONTAINER_TESTDIR=/home/TDinternal/community
SIM_DIR=/home/TDinternal/sim
REP_MOUNT_PARAM="$INTERNAL_REPDIR:/home/TDinternal"
+ REP_MOUNT_LIB="$INTERNAL_REPDIR/debug/build/lib:/home/TDinternal/debug/build/lib:ro"
+
else
# community edition
REPDIR=$WORKDIR/TDengine
CONTAINER_TESTDIR=/home/TDengine
SIM_DIR=/home/TDengine/sim
REP_MOUNT_PARAM="$REPDIR:/home/TDengine"
+ REP_MOUNT_LIB="$REPDIR/debug/build/lib:/home/TDengine/debug/build/lib:ro"
+
fi
ulimit -c unlimited
@@ -103,6 +107,7 @@ coredump_dir=`cat /proc/sys/kernel/core_pattern | xargs dirname`
docker run \
-v $REP_MOUNT_PARAM \
+ -v $REP_MOUNT_LIB \
-v $MOUNT_DIR \
-v ${SOURCEDIR}:/usr/local/src/ \
-v "$TMP_DIR/thread_volume/$thread_no/sim:${SIM_DIR}" \
diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh
index 5f497a248f..606afe164b 100755
--- a/tests/script/sh/deploy.sh
+++ b/tests/script/sh/deploy.sh
@@ -9,7 +9,6 @@ UNAME_BIN=`which uname`
OS_TYPE=`$UNAME_BIN`
NODE_NAME=
NODE=
-MULTIPROCESS=0
while getopts "n:i:m" arg
do
case $arg in
@@ -19,9 +18,6 @@ do
i)
NODE=$OPTARG
;;
- m)
- MULTIPROCESS=1
- ;;
?)
echo "unkonw argument"
;;
@@ -148,5 +144,4 @@ echo "numOfLogLines 20000000" >> $TAOS_CFG
echo "asyncLog 0" >> $TAOS_CFG
echo "locale en_US.UTF-8" >> $TAOS_CFG
echo "telemetryReporting 0" >> $TAOS_CFG
-echo "multiProcess ${MULTIPROCESS}" >> $TAOS_CFG
echo " " >> $TAOS_CFG
diff --git a/tests/script/test.sh b/tests/script/test.sh
index 0ffe8cf8f1..1530567987 100755
--- a/tests/script/test.sh
+++ b/tests/script/test.sh
@@ -15,7 +15,6 @@ VALGRIND=0
UNIQUE=0
UNAME_BIN=`which uname`
OS_TYPE=`$UNAME_BIN`
-MULTIPROCESS=0
while getopts "f:avum" arg
do
case $arg in
@@ -28,9 +27,6 @@ do
u)
UNIQUE=1
;;
- m)
- MULTIPROCESS=1
- ;;
?)
echo "unknow argument"
;;
@@ -126,22 +122,12 @@ ulimit -c unlimited
if [ -n "$FILE_NAME" ]; then
echo "------------------------------------------------------------------------"
if [ $VALGRIND -eq 1 ]; then
- if [[ $MULTIPROCESS -eq 1 ]];then
- FLAG="-m -v"
- else
- FLAG="-v"
- fi
-
+ FLAG="-v"
echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --child-silent-after-fork=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tsim.log $PROGRAM -c $CFG_DIR -f $FILE_NAME $FLAG
valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --child-silent-after-fork=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tsim.log $PROGRAM -c $CFG_DIR -f $FILE_NAME $FLAG
else
- if [[ $MULTIPROCESS -eq 1 ]];then
- echo "ExcuteCmd(multiprocess):" $PROGRAM -m -c $CFG_DIR -f $FILE_NAME
- $PROGRAM -m -c $CFG_DIR -f $FILE_NAME
- else
- echo "ExcuteCmd(singleprocess):" $PROGRAM -c $CFG_DIR -f $FILE_NAME
- $PROGRAM -c $CFG_DIR -f $FILE_NAME
- fi
+ echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME
+ $PROGRAM -c $CFG_DIR -f $FILE_NAME
fi
else
echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim
diff --git a/tests/script/tmp/monitor.sim b/tests/script/tmp/monitor.sim
index b410e1b6ad..1734b9a1a7 100644
--- a/tests/script/tmp/monitor.sim
+++ b/tests/script/tmp/monitor.sim
@@ -23,5 +23,4 @@ sql create table db.stb (ts timestamp, c1 int, c2 binary(4)) tags(t1 int, t2 bin
print =============== create drop qnode 1
sql create qnode on dnode 1
#sql create snode on dnode 1
-#sql create bnode on dnode 1
diff --git a/tests/script/tsim/bnode/basic1.sim b/tests/script/tsim/bnode/basic1.sim
deleted file mode 100644
index 0a20001636..0000000000
--- a/tests/script/tsim/bnode/basic1.sim
+++ /dev/null
@@ -1,135 +0,0 @@
-system sh/stop_dnodes.sh
-system sh/deploy.sh -n dnode1 -i 1
-system sh/deploy.sh -n dnode2 -i 2
-system sh/exec.sh -n dnode1 -s start
-system sh/exec.sh -n dnode2 -s start
-sql connect
-
-print =============== select * from information_schema.ins_dnodes
-sql select * from information_schema.ins_dnodes;
-if $rows != 1 then
- return -1
-endi
-
-if $data00 != 1 then
- return -1
-endi
-
-sql select * from information_schema.ins_mnodes;
-if $rows != 1 then
- return -1
-endi
-
-if $data00 != 1 then
- return -1
-endi
-
-if $data02 != leader then
- return -1
-endi
-
-print =============== create dnodes
-sql create dnode $hostname port 7200
-sleep 2000
-
-sql select * from information_schema.ins_dnodes;
-if $rows != 2 then
- return -1
-endi
-
-if $data00 != 1 then
- return -1
-endi
-
-if $data10 != 2 then
- return -1
-endi
-
-print $data02
-if $data02 != 0 then
- return -1
-endi
-
-if $data12 != 0 then
- return -1
-endi
-
-if $data04 != ready then
- return -1
-endi
-
-if $data14 != ready then
- return -1
-endi
-
-sql select * from information_schema.ins_mnodes;
-if $rows != 1 then
- return -1
-endi
-
-if $data00 != 1 then
- return -1
-endi
-
-if $data02 != leader then
- return -1
-endi
-
-#print =============== create drop bnode 1
-#sql create bnode on dnode 1
-#sql show bnodes
-#if $rows != 1 then
-# return -1
-#endi
-#if $data00 != 1 then
-# return -1
-#endi
-#sql_error create bnode on dnode 1
-#
-#sql drop bnode on dnode 1
-#sql show bnodes
-#if $rows != 0 then
-# return -1
-#endi
-#sql_error drop bnode on dnode 1
-#
-#print =============== create drop bnode 2
-#sql create bnode on dnode 2
-#sql show bnodes
-#if $rows != 1 then
-# return -1
-#endi
-#if $data00 != 2 then
-# return -1
-#endi
-#sql_error create bnode on dnode 2
-#
-#sql drop bnode on dnode 2
-#sql show bnodes
-#if $rows != 0 then
-# return -1
-#endi
-#sql_error drop bnode on dnode 2
-#
-#print =============== create drop bnodes
-#sql create bnode on dnode 1
-#sql create bnode on dnode 2
-#sql show bnodes
-#if $rows != 2 then
-# return -1
-#endi
-
-#print =============== restart
-#system sh/exec.sh -n dnode1 -s stop -x SIGINT
-#system sh/exec.sh -n dnode2 -s stop -x SIGINT
-#system sh/exec.sh -n dnode1 -s start
-#system sh/exec.sh -n dnode2 -s start
-#
-#sleep 2000
-#sql show bnodes
-#if $rows != 2 then
-# return -1
-#endi
-
-system sh/exec.sh -n dnode1 -s stop -x SIGINT
-system sh/exec.sh -n dnode2 -s stop -x SIGINT
diff --git a/tests/script/tsim/parser/like.sim b/tests/script/tsim/parser/like.sim
index 40dcec4080..5cac026b57 100644
--- a/tests/script/tsim/parser/like.sim
+++ b/tests/script/tsim/parser/like.sim
@@ -17,9 +17,9 @@ sql create table $table1 (ts timestamp, b binary(20))
sql create table $table2 (ts timestamp, b binary(20))
sql insert into $table1 values(now, "table_name")
-sql insert into $table1 values(now-1m, "tablexname")
+sql insert into $table1 values(now-3m, "tablexname")
sql insert into $table1 values(now-2m, "tablexxx")
-sql insert into $table1 values(now-2m, "table")
+sql insert into $table1 values(now-1m, "table")
sql select b from $table1
if $rows != 4 then
diff --git a/tests/script/tsim/sma/tsmaCreateInsertQuery.sim b/tests/script/tsim/sma/tsmaCreateInsertQuery.sim
index 2ff01263a4..7aef9e0f86 100644
--- a/tests/script/tsim/sma/tsmaCreateInsertQuery.sim
+++ b/tests/script/tsim/sma/tsmaCreateInsertQuery.sim
@@ -5,7 +5,7 @@ sleep 50
sql connect
print =============== create database
-sql create database d1 vgroups 1
+sql create database d1 keep 36500d vgroups 1
sql use d1
print =============== create super table, include column type for count/sum/min/max/first
@@ -25,8 +25,8 @@ if $rows != 1 then
endi
print =============== insert data, mode1: one row one table in sql
-sql insert into ct1 values(now+0s, 10, 2.0, 3.0)
-sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3)
+sql insert into ct1 values('2022-10-19 09:55:45.682', 10, 2.0, 3.0)
+sql insert into ct1 values('2022-10-19 09:55:46.682', 11, 2.1, 3.1)('2022-10-19 09:55:47.682', -12, -2.2, -3.2)('2022-10-19 09:55:48.682', -13, -2.3, -3.3)
print =============== create sma index from super table
@@ -34,7 +34,7 @@ sql create sma index sma_index_name1 on stb function(max(c1),max(c2),min(c1)) in
print $data00 $data01 $data02 $data03
print =============== trigger stream to execute sma aggr task and insert sma data into sma store
-sql insert into ct1 values(now+5s, 20, 20.0, 30.0)
+sql insert into ct1 values('2022-10-19 09:55:50.682', 20, 20.0, 30.0)
#===================================================================
print =============== show streams ================================
diff --git a/tests/script/tsim/stream/session0.sim b/tests/script/tsim/stream/session0.sim
index 3e0af354d8..afae8ef5da 100644
--- a/tests/script/tsim/stream/session0.sim
+++ b/tests/script/tsim/stream/session0.sim
@@ -216,12 +216,12 @@ if $data02 != 3.274823935 then
goto loop2
endi
-if $data03 != 1.800000000 then
+if $data03 != 1.500000000 then
print ======$data03
return -1
endi
-if $data04 != 3.350000000 then
+if $data04 != 3.500000000 then
print ======$data04
return -1
endi
diff --git a/tests/script/tsim/stream/session1.sim b/tests/script/tsim/stream/session1.sim
index ab173c5929..ee6eefde26 100644
--- a/tests/script/tsim/stream/session1.sim
+++ b/tests/script/tsim/stream/session1.sim
@@ -5,15 +5,15 @@ sleep 50
sql connect
print =============== create database
-sql create database test vgroups 1
-sql select * from information_schema.ins_databases
+sql create database test vgroups 1;
+sql select * from information_schema.ins_databases;
if $rows != 3 then
return -1
endi
print $data00 $data01 $data02
-sql use test
+sql use test;
sql create table t1(ts timestamp, a int, b int , c int, d double,id int);
diff --git a/tests/script/tsim/stream/state0.sim b/tests/script/tsim/stream/state0.sim
index 877a2877b9..60a50f9560 100644
--- a/tests/script/tsim/stream/state0.sim
+++ b/tests/script/tsim/stream/state0.sim
@@ -349,7 +349,7 @@ endi
if $rows != 3 then
print ====loop4=rows=$rows
-# goto loop4
+ goto loop4
endi
# row 0
diff --git a/tests/script/tsim/stream/triggerSession0.sim b/tests/script/tsim/stream/triggerSession0.sim
index 2ea689ef78..1bef439884 100644
--- a/tests/script/tsim/stream/triggerSession0.sim
+++ b/tests/script/tsim/stream/triggerSession0.sim
@@ -13,7 +13,7 @@ endi
print $data00 $data01 $data02
-sql use test
+sql use test;
sql create table t2(ts timestamp, a int, b int , c int, d double);
sql create stream streams2 trigger window_close into streamt2 as select _wstart, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5 from t2 session(ts, 10s);
@@ -58,16 +58,11 @@ endi
sql insert into t2 values(1648791233002,1,2,3,1.0);
sleep 300
sql select * from streamt2;
-if $rows != 1 then
+if $rows != 0 then
print ======$rows
return -1
endi
-if $data01 != 6 then
- print ======$data01
- return -1
-endi
-
sql insert into t2 values(1648791253003,1,2,3,1.0);
sleep 300
sql select * from streamt2;
diff --git a/tests/script/tsim/testsuit.sim b/tests/script/tsim/testsuit.sim
index 89a4babb0b..ad8d70b089 100644
--- a/tests/script/tsim/testsuit.sim
+++ b/tests/script/tsim/testsuit.sim
@@ -128,5 +128,4 @@ run tsim/sync/threeReplica1VgElectWihtInsert.sim
run tsim/sma/tsmaCreateInsertQuery.sim
run tsim/sma/rsmaCreateInsertQuery.sim
run tsim/valgrind/basic.sim
-run tsim/valgrind/checkError.sim
-run tsim/bnode/basic1.sim
\ No newline at end of file
+run tsim/valgrind/checkError.sim
\ No newline at end of file
diff --git a/tests/script/tsim/user/privilege_sysinfo.sim b/tests/script/tsim/user/privilege_sysinfo.sim
index 86f95755d0..1614c3be55 100644
--- a/tests/script/tsim/user/privilege_sysinfo.sim
+++ b/tests/script/tsim/user/privilege_sysinfo.sim
@@ -110,7 +110,6 @@ sql_error show dnodes
sql_error show snodes
sql_error show qnodes
sql_error show mnodes
-sql_error show bnodes
sql_error show db.vgroups
sql_error show db.stables
sql_error show db.tables
diff --git a/tests/system-test/0-others/taosdMonitor.py b/tests/system-test/0-others/taosdMonitor.py
index c713e9fd14..1d733191b7 100644
--- a/tests/system-test/0-others/taosdMonitor.py
+++ b/tests/system-test/0-others/taosdMonitor.py
@@ -125,7 +125,7 @@ class RequestHandlerImpl(http.server.BaseHTTPRequestHandler):
dnode_infos = ['uptime', 'cpu_engine', 'cpu_system', 'cpu_cores', 'mem_engine', 'mem_system', 'mem_total', 'disk_engine',
'disk_used', 'disk_total', 'net_in', 'net_out', 'io_read', 'io_write', 'io_read_disk', 'io_write_disk', 'req_select',
'req_select_rate', 'req_insert', 'req_insert_success', 'req_insert_rate', 'req_insert_batch', 'req_insert_batch_success',
- 'req_insert_batch_rate', 'errors', 'vnodes_num', 'masters', 'has_mnode', 'has_qnode', 'has_snode', 'has_bnode']
+ 'req_insert_batch_rate', 'errors', 'vnodes_num', 'masters', 'has_mnode', 'has_qnode', 'has_snode']
for elem in dnode_infos:
if elem not in infoDict["dnode_info"] or infoDict["dnode_info"][elem] < 0:
tdLog.exit(f"{elem} is null!")
diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh
old mode 100755
new mode 100644
index 7831e86f76..7b1a1eb32c
--- a/tests/system-test/fulltest.sh
+++ b/tests/system-test/fulltest.sh
@@ -251,6 +251,7 @@ python3 ./test.py -f 0-others/compatibility.py
# # python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5
# python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3
+
# python3 ./test.py -f 6-cluster/5dnode3mnodeRecreateMnode.py -N 5 -M 3
# python3 ./test.py -f 6-cluster/5dnode3mnodeStopFollowerLeader.py -N 5 -M 3
# python3 ./test.py -f 6-cluster/5dnode3mnodeStop2Follower.py -N 5 -M 3
diff --git a/tools/shell/src/shellCommand.c b/tools/shell/src/shellCommand.c
index 0b26d685fd..c34b22b691 100644
--- a/tools/shell/src/shellCommand.c
+++ b/tools/shell/src/shellCommand.c
@@ -101,11 +101,8 @@ void shellInsertChar(SShellCmd *cmd, char *c, int32_t size) {
/* update the values */
cmd->commandSize += size;
cmd->cursorOffset += size;
- for (int i = 0; i < size; i++) {
- taosMbToWchar(&wc, c + i, size);
- cmd->screenOffset += taosWcharWidth(wc);
- cmd->endOffset += taosWcharWidth(wc);
- }
+ cmd->screenOffset += taosWcharWidth(wc);
+ cmd->endOffset += taosWcharWidth(wc);
#ifdef WINDOWS
#else
shellShowOnScreen(cmd);
diff --git a/utils/test/c/sml_test.c b/utils/test/c/sml_test.c
index f7fd59cd7b..ab520e6638 100644
--- a/utils/test/c/sml_test.c
+++ b/utils/test/c/sml_test.c
@@ -102,27 +102,8 @@ int smlProcess_json1_Test() {
taos_free_result(pRes);
const char *sql[] = {
- "["
- " {"
- " \"metric\": \"sys.cpu.nice\","
- " \"timestamp\": 0,"
- " \"value\": 18,"
- " \"tags\": {"
- " \"host\": \"web01\","
- " \"id\": \"t1\","
- " \"dc\": \"lga\""
- " }"
- " },"
- " {"
- " \"metric\": \"sys.cpu.nice\","
- " \"timestamp\": 1662344042,"
- " \"value\": 9,"
- " \"tags\": {"
- " \"host\": \"web02\","
- " \"dc\": \"lga\""
- " }"
- " }"
- "]",};
+ "[{\"metric\":\"sys.cpu.nice\",\"timestamp\":0,\"value\":18,\"tags\":{\"host\":\"web01\",\"id\":\"t1\",\"dc\":\"lga\"}},{\"metric\":\"sys.cpu.nice\",\"timestamp\":1662344042,\"value\":9,\"tags\":{\"host\":\"web02\",\"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));
@@ -143,28 +124,8 @@ int smlProcess_json2_Test() {
taos_free_result(pRes);
const char *sql[] = {
- "{"
- " \"metric\": \"meter_current0\","
- " \"timestamp\": {"
- " \"value\" : 1662344042,"
- " \"type\" : \"s\""
- " },"
- " \"value\": {"
- " \"value\" : 10.3,"
- " \"type\" : \"i64\""
- " },"
- " \"tags\": {"
- " \"groupid\": { "
- " \"value\" : 2,"
- " \"type\" : \"bigint\""
- " },"
- " \"location\": { "
- " \"value\" : \"北京\","
- " \"type\" : \"binary\""
- " },"
- " \"id\": \"d1001\""
- " }"
- "}",};
+ "{\"metric\":\"meter_current0\",\"timestamp\":{\"value\":1662344042,\"type\":\"s\"},\"value\":{\"value\":10.3,\"type\":\"i64\"},\"tags\":{\"groupid\":{\"value\":2,\"type\":\"bigint\"},\"location\":{\"value\":\"北京\",\"type\":\"binary\"},\"id\":\"d1001\"}}"
+ };
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));
@@ -185,56 +146,7 @@ int smlProcess_json3_Test() {
taos_free_result(pRes);
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\":\"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\"}}"};
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));
@@ -255,47 +167,8 @@ int smlProcess_json4_Test() {
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\""
- " }"
- "}",};
+ "{\"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,
TSDB_SML_TIMESTAMP_NANO_SECONDS);
printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
diff --git a/utils/test/c/tmqDemo.c b/utils/test/c/tmqDemo.c
index 784b45c92b..d105b50579 100644
--- a/utils/test/c/tmqDemo.c
+++ b/utils/test/c/tmqDemo.c
@@ -130,15 +130,15 @@ void parseArgument(int32_t argc, char* argv[]) {
printHelp();
exit(0);
} else if (strcmp(argv[i], "-d") == 0) {
- strcpy(g_stConfInfo.dbName, argv[++i]);
+ tstrncpy(g_stConfInfo.dbName, argv[++i], sizeof(g_stConfInfo.dbName));
} else if (strcmp(argv[i], "-c") == 0) {
- strcpy(configDir, argv[++i]);
+ tstrncpy(configDir, argv[++i], PATH_MAX);
} else if (strcmp(argv[i], "-s") == 0) {
- strcpy(g_stConfInfo.stbName, argv[++i]);
+ tstrncpy(g_stConfInfo.stbName, argv[++i], sizeof(g_stConfInfo.stbName));
} else if (strcmp(argv[i], "-w") == 0) {
- strcpy(g_stConfInfo.vnodeWalPath, argv[++i]);
+ tstrncpy(g_stConfInfo.vnodeWalPath, argv[++i], sizeof(g_stConfInfo.vnodeWalPath));
} else if (strcmp(argv[i], "-f") == 0) {
- strcpy(g_stConfInfo.resultFileName, argv[++i]);
+ tstrncpy(g_stConfInfo.resultFileName, argv[++i], sizeof(g_stConfInfo.resultFileName));
} else if (strcmp(argv[i], "-t") == 0) {
g_stConfInfo.numOfThreads = atoi(argv[++i]);
} else if (strcmp(argv[i], "-n") == 0) {
diff --git a/utils/test/c/tmqSim.c b/utils/test/c/tmqSim.c
index d36fe0855a..25e83363ee 100644
--- a/utils/test/c/tmqSim.c
+++ b/utils/test/c/tmqSim.c
@@ -949,7 +949,7 @@ void parseConsumeInfo() {
token = strtok(g_stConfInfo.stThreads[i].topicString, delim);
while (token != NULL) {
// printf("%s\n", token );
- strcpy(g_stConfInfo.stThreads[i].topics[g_stConfInfo.stThreads[i].numOfTopic], token);
+ tstrncpy(g_stConfInfo.stThreads[i].topics[g_stConfInfo.stThreads[i].numOfTopic], token, sizeof(g_stConfInfo.stThreads[i].topics[g_stConfInfo.stThreads[i].numOfTopic]));
ltrim(g_stConfInfo.stThreads[i].topics[g_stConfInfo.stThreads[i].numOfTopic]);
// printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]);
g_stConfInfo.stThreads[i].numOfTopic++;
diff --git a/utils/tsim/inc/simInt.h b/utils/tsim/inc/simInt.h
index f9e96fc67b..9438e11fbd 100644
--- a/utils/tsim/inc/simInt.h
+++ b/utils/tsim/inc/simInt.h
@@ -155,7 +155,6 @@ extern int32_t simScriptSucced;
extern int32_t simDebugFlag;
extern char simScriptDir[];
extern bool abortExecution;
-extern bool useMultiProcess;
extern bool useValgrind;
SScript *simParseScript(char *fileName);
diff --git a/utils/tsim/src/simExe.c b/utils/tsim/src/simExe.c
index 4fe5fdf672..7c7afeefc3 100644
--- a/utils/tsim/src/simExe.c
+++ b/utils/tsim/src/simExe.c
@@ -37,6 +37,7 @@ void simLogSql(char *sql, bool useSharp) {
taosFsyncFile(pFile);
}
+#if 0
char *simParseArbitratorName(char *varName) {
static char hostName[140];
#ifdef WINDOWS
@@ -47,6 +48,7 @@ char *simParseArbitratorName(char *varName) {
#endif
return hostName;
}
+#endif
char *simParseHostName(char *varName) {
static char hostName[140];
@@ -102,9 +104,11 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return simParseHostName(varName);
}
+#if 0
if (strncmp(varName, "arbitrator", 10) == 0) {
return simParseArbitratorName(varName);
}
+#endif
if (strncmp(varName, "error", varLen) == 0) return script->error;
@@ -438,10 +442,6 @@ bool simExecuteSystemCmd(SScript *script, char *option) {
simReplaceStr(buf, ".sh", ".bat");
#endif
- if (useMultiProcess) {
- simReplaceStr(buf, "deploy.sh", "deploy.sh -m");
- }
-
if (useValgrind) {
replaced = simReplaceStr(buf, "exec.sh", "exec.sh -v");
}
@@ -883,6 +883,7 @@ bool simExecuteSqlSlowCmd(SScript *script, char *rest) {
return simExecuteSqlImpCmd(script, rest, isSlow);
}
+#if 0
bool simExecuteRestfulCmd(SScript *script, char *rest) {
TdFilePtr pFile = NULL;
char filename[256];
@@ -924,6 +925,7 @@ bool simExecuteRestfulCmd(SScript *script, char *rest) {
return simExecuteSystemCmd(script, cmd);
}
+#endif
bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
char buf[3000];
@@ -981,6 +983,7 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return false;
}
+#if 0
bool simExecuteLineInsertCmd(SScript *script, char *rest) {
char buf[TSDB_MAX_BINARY_LEN] = {0};
@@ -1037,3 +1040,4 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) {
return true;
}
}
+#endif
\ No newline at end of file
diff --git a/utils/tsim/src/simMain.c b/utils/tsim/src/simMain.c
index e58a22cf68..cd4a5117b2 100644
--- a/utils/tsim/src/simMain.c
+++ b/utils/tsim/src/simMain.c
@@ -18,7 +18,6 @@
bool simExecSuccess = false;
bool abortExecution = false;
-bool useMultiProcess = false;
bool useValgrind = false;
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
@@ -34,8 +33,6 @@ int32_t main(int32_t argc, char *argv[]) {
tstrncpy(configDir, argv[++i], 128);
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
tstrncpy(scriptFile, argv[++i], MAX_FILE_NAME_LEN);
- } else if (strcmp(argv[i], "-m") == 0) {
- useMultiProcess = true;
} else if (strcmp(argv[i], "-v") == 0) {
useValgrind = true;
} else {
diff --git a/utils/tsim/src/simParse.c b/utils/tsim/src/simParse.c
index 14be10bc8a..ae523edfc4 100644
--- a/utils/tsim/src/simParse.c
+++ b/utils/tsim/src/simParse.c
@@ -501,6 +501,7 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return true;
}
+#if 0
bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char *token;
int32_t tokenLen;
@@ -647,6 +648,7 @@ bool simParseContinueCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
numOfLines++;
return true;
}
+#endif
bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen;
@@ -715,6 +717,7 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return true;
}
+#if 0
bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
simParseSqlCmd(rest, pCmd, lineNum);
cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW;
@@ -726,6 +729,7 @@ bool simParseRestfulCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
cmdLine[numOfLines - 1].cmdno = SIM_CMD_RESTFUL;
return true;
}
+#endif
bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen;
@@ -838,6 +842,7 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return true;
}
+#if 0
bool simParseLineInsertCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen;
@@ -869,6 +874,7 @@ bool simParseLineInsertErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
numOfLines++;
return true;
}
+#endif
void simInitsimCmdList() {
int32_t cmdno;
@@ -930,6 +936,7 @@ void simInitsimCmdList() {
simCmdList[cmdno].executeCmd = NULL;
simAddCmdIntoHash(&(simCmdList[cmdno]));
+#if 0
cmdno = SIM_CMD_SWITCH;
simCmdList[cmdno].cmdno = cmdno;
strcpy(simCmdList[cmdno].name, "switch");
@@ -977,6 +984,7 @@ void simInitsimCmdList() {
simCmdList[cmdno].parseCmd = simParseEndsCmd;
simCmdList[cmdno].executeCmd = NULL;
simAddCmdIntoHash(&(simCmdList[cmdno]));
+#endif
cmdno = SIM_CMD_SLEEP;
simCmdList[cmdno].cmdno = cmdno;
@@ -1050,6 +1058,7 @@ void simInitsimCmdList() {
simCmdList[cmdno].executeCmd = simExecuteSqlErrorCmd;
simAddCmdIntoHash(&(simCmdList[cmdno]));
+#if 0
cmdno = SIM_CMD_SQL_SLOW;
simCmdList[cmdno].cmdno = cmdno;
strcpy(simCmdList[cmdno].name, "sql_slow");
@@ -1065,6 +1074,7 @@ void simInitsimCmdList() {
simCmdList[cmdno].parseCmd = simParseRestfulCmd;
simCmdList[cmdno].executeCmd = simExecuteRestfulCmd;
simAddCmdIntoHash(&(simCmdList[cmdno]));
+#endif
/* test is only an internal command */
cmdno = SIM_CMD_TEST;
@@ -1082,6 +1092,7 @@ void simInitsimCmdList() {
simCmdList[cmdno].executeCmd = simExecuteReturnCmd;
simAddCmdIntoHash(&(simCmdList[cmdno]));
+#if 0
cmdno = SIM_CMD_LINE_INSERT;
simCmdList[cmdno].cmdno = cmdno;
strcpy(simCmdList[cmdno].name, "line_insert");
@@ -1097,4 +1108,5 @@ void simInitsimCmdList() {
simCmdList[cmdno].parseCmd = simParseLineInsertErrorCmd;
simCmdList[cmdno].executeCmd = simExecuteLineInsertErrorCmd;
simAddCmdIntoHash(&(simCmdList[cmdno]));
+#endif
}