Merge branch '3.0' into feature/stream
This commit is contained in:
commit
8ca5f0bd9c
|
@ -2,7 +2,7 @@
|
|||
# taos-tools
|
||||
ExternalProject_Add(taos-tools
|
||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||
GIT_TAG 7321fbb
|
||||
GIT_TAG 719fc88
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -270,7 +270,7 @@ if(${JEMALLOC_ENABLED})
|
|||
PREFIX "jemalloc"
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jemalloc
|
||||
BUILD_IN_SOURCE 1
|
||||
CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ --disable-initial-exec-tls
|
||||
CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ --disable-initial-exec-tls
|
||||
BUILD_COMMAND ${MAKE}
|
||||
)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/build/include)
|
||||
|
|
|
@ -201,7 +201,7 @@ The configuration parameters in the URL are as follows:
|
|||
- httpConnectTimeout: REST connection timeout in milliseconds, the default value is 5000 ms.
|
||||
- httpSocketTimeout: socket timeout in milliseconds, the default value is 5000 ms. It only takes effect when batchfetch is false.
|
||||
- messageWaitTimeout: message transmission timeout in milliseconds, the default value is 3000 ms. It only takes effect when batchfetch is true.
|
||||
- useSSL: connecting Securely Using SSL. true: using SSL conneciton, false: not using SSL connection.
|
||||
- useSSL: connecting Securely Using SSL. true: using SSL connection, false: not using SSL connection.
|
||||
|
||||
**Note**: Some configuration items (e.g., locale, timezone) do not work in the REST connection.
|
||||
|
||||
|
@ -268,7 +268,7 @@ The configuration parameters in properties are as follows.
|
|||
- TSDBDriver.HTTP_CONNECT_TIMEOUT: REST connection timeout in milliseconds, the default value is 5000 ms. It only takes effect when using JDBC REST connection.
|
||||
- TSDBDriver.HTTP_SOCKET_TIMEOUT: socket timeout in milliseconds, the default value is 5000 ms. It only takes effect when using JDBC REST connection and batchfetch is false.
|
||||
- TSDBDriver.PROPERTY_KEY_MESSAGE_WAIT_TIMEOUT: message transmission timeout in milliseconds, the default value is 3000 ms. It only takes effect when using JDBC REST connection and batchfetch is true.
|
||||
- TSDBDriver.PROPERTY_KEY_USE_SSL: connecting Securely Using SSL. true: using SSL conneciton, false: not using SSL connection. It only takes effect when using JDBC REST connection.
|
||||
- TSDBDriver.PROPERTY_KEY_USE_SSL: connecting Securely Using SSL. true: using SSL connection, false: not using SSL connection. It only takes effect when using JDBC REST connection.
|
||||
For JDBC native connections, you can specify other parameters, such as log level, SQL length, etc., by specifying URL and Properties. For more detailed configuration, please refer to [Client Configuration](/reference/config/#Client-Only).
|
||||
|
||||
### Priority of configuration parameters
|
||||
|
@ -824,7 +824,7 @@ Example usage is as follows.
|
|||
//query or insert
|
||||
// ...
|
||||
|
||||
connection.close(); // put back to conneciton pool
|
||||
connection.close(); // put back to connection pool
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -856,7 +856,7 @@ public static void main(String[] args) throws Exception {
|
|||
//query or insert
|
||||
// ...
|
||||
|
||||
connection.close(); // put back to conneciton pool
|
||||
connection.close(); // put back to connection pool
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -878,7 +878,9 @@ The source code of the sample application is under `TDengine/examples/JDBC`:
|
|||
|
||||
| taos-jdbcdriver version | major changes |
|
||||
| :---------------------: | :--------------------------------------------: |
|
||||
| 3.0.1 - 3.0.2 | fix the resultSet data is parsed incorrectly sometimes. 3.0.1 is compiled on JDK 11, you are advised to use 3.0.2 in the JDK 8 environment |
|
||||
| 3.0.0 | Support for TDengine 3.0 |
|
||||
| 2.0.41 | fix decode method of username and password in REST connection |
|
||||
| 2.0.39 - 2.0.40 | Add REST connection/request timeout parameters |
|
||||
| 2.0.38 | JDBC REST connections add bulk pull function |
|
||||
| 2.0.37 | Support json tags |
|
||||
|
@ -910,6 +912,12 @@ The source code of the sample application is under `TDengine/examples/JDBC`:
|
|||
|
||||
**Solution**: Use taos-jdbcdriver 2.* with your TDengine 2.* deployment.
|
||||
|
||||
5. java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer; ... taos-jdbcdriver-3.0.1.jar
|
||||
|
||||
**Cause**:taos-jdbcdriver 3.0.1 is compiled on JDK 11.
|
||||
|
||||
**Solution**: Use taos-jdbcdriver 3.0.2.
|
||||
|
||||
For additional troubleshooting, see [FAQ](../../../train-faq/faq).
|
||||
|
||||
## API Reference
|
||||
|
|
|
@ -36,10 +36,10 @@ int main() {
|
|||
executeSQL(taos, "CREATE DATABASE power");
|
||||
executeSQL(taos, "USE power");
|
||||
executeSQL(taos, "CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
|
||||
executeSQL(taos, "INSERT INTO d1001 USING meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)"
|
||||
"d1002 USING meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)"
|
||||
"d1003 USING meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)"
|
||||
"d1004 USING meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)");
|
||||
executeSQL(taos, "INSERT INTO d1001 USING meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)"
|
||||
"d1002 USING meters TAGS('California.SanFrancisco', 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)"
|
||||
"d1003 USING meters TAGS('California.LosAngeles', 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)"
|
||||
"d1004 USING meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)");
|
||||
taos_close(taos);
|
||||
taos_cleanup();
|
||||
}
|
||||
|
@ -48,4 +48,4 @@ int main() {
|
|||
// affected rows 0
|
||||
// affected rows 0
|
||||
// affected rows 0
|
||||
// affected rows 8
|
||||
// affected rows 8
|
||||
|
|
|
@ -68,38 +68,39 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Java 对
|
|||
### 安装连接器
|
||||
|
||||
<Tabs defaultValue="maven">
|
||||
<TabItem value="maven" label="使用 Maven 安装">
|
||||
<TabItem value="maven" label="使用 Maven 安装">
|
||||
|
||||
目前 taos-jdbcdriver 已经发布到 [Sonatype Repository](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver) 仓库,且各大仓库都已同步。
|
||||
目前 taos-jdbcdriver 已经发布到 [Sonatype Repository](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
仓库,且各大仓库都已同步。
|
||||
|
||||
- [sonatype](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
- [mvnrepository](https://mvnrepository.com/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
- [maven.aliyun](https://maven.aliyun.com/mvn/search)
|
||||
- [sonatype](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
- [mvnrepository](https://mvnrepository.com/artifact/com.taosdata.jdbc/taos-jdbcdriver)
|
||||
- [maven.aliyun](https://maven.aliyun.com/mvn/search)
|
||||
|
||||
Maven 项目中,在 pom.xml 中添加以下依赖:
|
||||
Maven 项目中,在 pom.xml 中添加以下依赖:
|
||||
|
||||
```xml-dtd
|
||||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
```
|
||||
```xml-dtd
|
||||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="source" label="使用源码编译安装">
|
||||
</TabItem>
|
||||
<TabItem value="source" label="使用源码编译安装">
|
||||
|
||||
可以通过下载 TDengine 的源码,自己编译最新版本的 Java connector
|
||||
可以通过下载 TDengine 的源码,自己编译最新版本的 Java connector
|
||||
|
||||
```shell
|
||||
git clone https://github.com/taosdata/taos-connector-jdbc.git
|
||||
cd taos-connector-jdbc
|
||||
mvn clean install -Dmaven.test.skip=true
|
||||
```
|
||||
```shell
|
||||
git clone https://github.com/taosdata/taos-connector-jdbc.git
|
||||
cd taos-connector-jdbc
|
||||
mvn clean install -Dmaven.test.skip=true
|
||||
```
|
||||
|
||||
编译后,在 target 目录下会产生 taos-jdbcdriver-3.0.*-dist.jar 的 jar 包,并自动将编译的 jar 文件放在本地的 Maven 仓库中。
|
||||
编译后,在 target 目录下会产生 taos-jdbcdriver-3.0.*-dist.jar 的 jar 包,并自动将编译的 jar 文件放在本地的 Maven 仓库中。
|
||||
|
||||
</TabItem>
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## 建立连接
|
||||
|
@ -110,116 +111,125 @@ TDengine 的 JDBC URL 规范格式为:
|
|||
对于建立连接,原生连接与 REST 连接有细微不同。
|
||||
|
||||
<Tabs defaultValue="rest">
|
||||
<TabItem value="native" label="原生连接">
|
||||
<TabItem value="native" label="原生连接">
|
||||
|
||||
```java
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata";
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl);
|
||||
```
|
||||
```java
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata";
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl);
|
||||
```
|
||||
|
||||
以上示例,使用了 JDBC 原生连接的 TSDBDriver,建立了到 hostname 为 taosdemo.com,端口为 6030(TDengine 的默认端口),数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
|
||||
以上示例,使用了 JDBC 原生连接的 TSDBDriver,建立了到 hostname 为 taosdemo.com,端口为 6030(TDengine 的默认端口),数据库名为 test 的连接。这个 URL
|
||||
中指定用户名(user)为 root,密码(password)为 taosdata。
|
||||
|
||||
**注意**:使用 JDBC 原生连接,taos-jdbcdriver 需要依赖客户端驱动(Linux 下是 libtaos.so;Windows 下是 taos.dll;macOS 下是 libtaos.dylib)。
|
||||
**注意**:使用 JDBC 原生连接,taos-jdbcdriver 需要依赖客户端驱动(Linux 下是 libtaos.so;Windows 下是 taos.dll;macOS 下是 libtaos.dylib)。
|
||||
|
||||
url 中的配置参数如下:
|
||||
url 中的配置参数如下:
|
||||
|
||||
- user:登录 TDengine 用户名,默认值 'root'。
|
||||
- password:用户登录密码,默认值 'taosdata'。
|
||||
- cfgdir:客户端配置文件目录路径,Linux OS 上默认值 `/etc/taos`,Windows OS 上默认值 `C:/TDengine/cfg`。
|
||||
- charset:客户端使用的字符集,默认值为系统字符集。
|
||||
- locale:客户端语言环境,默认值系统当前 locale。
|
||||
- timezone:客户端使用的时区,默认值为系统当前时区。
|
||||
- batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:true。开启批量拉取同时获取一批数据在查询数据量较大时批量拉取可以有效的提升查询性能。
|
||||
- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败将继续执行下面的 SQL。false:不再执行失败 SQL 后的任何语句。默认值为:false。
|
||||
- user:登录 TDengine 用户名,默认值 'root'。
|
||||
- password:用户登录密码,默认值 'taosdata'。
|
||||
- cfgdir:客户端配置文件目录路径,Linux OS 上默认值 `/etc/taos`,Windows OS 上默认值 `C:/TDengine/cfg`。
|
||||
- charset:客户端使用的字符集,默认值为系统字符集。
|
||||
- locale:客户端语言环境,默认值系统当前 locale。
|
||||
- timezone:客户端使用的时区,默认值为系统当前时区。
|
||||
- batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:true。开启批量拉取同时获取一批数据在查询数据量较大时批量拉取可以有效的提升查询性能。
|
||||
- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败将继续执行下面的 SQL。false:不再执行失败 SQL
|
||||
后的任何语句。默认值为:false。
|
||||
|
||||
JDBC 原生连接的使用请参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1955.html)。
|
||||
JDBC 原生连接的使用请参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1955.html)。
|
||||
|
||||
**使用 TDengine 客户端驱动配置文件建立连接 **
|
||||
**使用 TDengine 客户端驱动配置文件建立连接 **
|
||||
|
||||
当使用 JDBC 原生连接连接 TDengine 集群时,可以使用 TDengine 客户端驱动配置文件,在配置文件中指定集群的 firstEp、secondEp 等参数。如下所示:
|
||||
当使用 JDBC 原生连接连接 TDengine 集群时,可以使用 TDengine 客户端驱动配置文件,在配置文件中指定集群的 firstEp、secondEp 等参数。如下所示:
|
||||
|
||||
1. 在 Java 应用中不指定 hostname 和 port
|
||||
1. 在 Java 应用中不指定 hostname 和 port
|
||||
|
||||
```java
|
||||
public Connection getConn() throws Exception{
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
String jdbcUrl = "jdbc:TAOS://:/test?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||
return conn;
|
||||
}
|
||||
```
|
||||
```java
|
||||
public Connection getConn() throws Exception{
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
String jdbcUrl = "jdbc:TAOS://:/test?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||
return conn;
|
||||
}
|
||||
```
|
||||
|
||||
2. 在配置文件中指定 firstEp 和 secondEp
|
||||
2. 在配置文件中指定 firstEp 和 secondEp
|
||||
|
||||
```shell
|
||||
# first fully qualified domain name (FQDN) for TDengine system
|
||||
firstEp cluster_node1:6030
|
||||
```shell
|
||||
# first fully qualified domain name (FQDN) for TDengine system
|
||||
firstEp cluster_node1:6030
|
||||
|
||||
# second fully qualified domain name (FQDN) for TDengine system, for cluster only
|
||||
secondEp cluster_node2:6030
|
||||
# second fully qualified domain name (FQDN) for TDengine system, for cluster only
|
||||
secondEp cluster_node2:6030
|
||||
|
||||
# default system charset
|
||||
# charset UTF-8
|
||||
# default system charset
|
||||
# charset UTF-8
|
||||
|
||||
# system locale
|
||||
# locale en_US.UTF-8
|
||||
```
|
||||
# system locale
|
||||
# locale en_US.UTF-8
|
||||
```
|
||||
|
||||
以上示例,jdbc 会使用客户端的配置文件,建立到 hostname 为 cluster_node1、端口为 6030、数据库名为 test 的连接。当集群中 firstEp 节点失效时,JDBC 会尝试使用 secondEp 连接集群。
|
||||
以上示例,jdbc 会使用客户端的配置文件,建立到 hostname 为 cluster_node1、端口为 6030、数据库名为 test 的连接。当集群中 firstEp 节点失效时,JDBC 会尝试使用 secondEp
|
||||
连接集群。
|
||||
|
||||
TDengine 中,只要保证 firstEp 和 secondEp 中一个节点有效,就可以正常建立到集群的连接。
|
||||
TDengine 中,只要保证 firstEp 和 secondEp 中一个节点有效,就可以正常建立到集群的连接。
|
||||
|
||||
> **注意**:这里的配置文件指的是调用 JDBC Connector 的应用程序所在机器上的配置文件,Linux OS 上默认值 /etc/taos/taos.cfg ,Windows OS 上默认值 C://TDengine/cfg/taos.cfg。
|
||||
> **注意**:这里的配置文件指的是调用 JDBC Connector 的应用程序所在机器上的配置文件,Linux OS 上默认值 /etc/taos/taos.cfg ,Windows OS 上默认值
|
||||
C://TDengine/cfg/taos.cfg。
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="rest" label="REST 连接">
|
||||
</TabItem>
|
||||
<TabItem value="rest" label="REST 连接">
|
||||
|
||||
```java
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl);
|
||||
```
|
||||
```java
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl);
|
||||
```
|
||||
|
||||
以上示例,使用了 JDBC REST 连接的 RestfulDriver,建立了到 hostname 为 taosdemo.com,端口为 6041,数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
|
||||
以上示例,使用了 JDBC REST 连接的 RestfulDriver,建立了到 hostname 为 taosdemo.com,端口为 6041,数据库名为 test 的连接。这个 URL 中指定用户名(user)为
|
||||
root,密码(password)为 taosdata。
|
||||
|
||||
使用 JDBC REST 连接,不需要依赖客户端驱动。与 JDBC 原生连接相比,仅需要:
|
||||
使用 JDBC REST 连接,不需要依赖客户端驱动。与 JDBC 原生连接相比,仅需要:
|
||||
|
||||
1. driverClass 指定为“com.taosdata.jdbc.rs.RestfulDriver”;
|
||||
2. jdbcUrl 以“jdbc:TAOS-RS://”开头;
|
||||
3. 使用 6041 作为连接端口。
|
||||
1. driverClass 指定为“com.taosdata.jdbc.rs.RestfulDriver”;
|
||||
2. jdbcUrl 以“jdbc:TAOS-RS://”开头;
|
||||
3. 使用 6041 作为连接端口。
|
||||
|
||||
url 中的配置参数如下:
|
||||
url 中的配置参数如下:
|
||||
|
||||
- user:登录 TDengine 用户名,默认值 'root'。
|
||||
- password:用户登录密码,默认值 'taosdata'。
|
||||
- batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。逐行拉取结果集使用 HTTP 方式进行数据传输。JDBC REST 连接支持批量拉取数据功能。taos-jdbcdriver 与 TDengine 之间通过 WebSocket 连接进行数据传输。相较于 HTTP,WebSocket 可以使 JDBC REST 连接支持大数据量查询,并提升查询性能。
|
||||
- charset: 当开启批量拉取数据时,指定解析字符串数据的字符集。
|
||||
- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败,继续执行下面的 SQL 了。false:不再执行失败 SQL 后的任何语句。默认值为:false。
|
||||
- httpConnectTimeout: 连接超时时间,单位 ms, 默认值为 5000。
|
||||
- httpSocketTimeout: socket 超时时间,单位 ms,默认值为 5000。仅在 batchfetch 设置为 false 时生效。
|
||||
- messageWaitTimeout: 消息超时时间, 单位 ms, 默认值为 3000。 仅在 batchfetch 设置为 true 时生效。
|
||||
- useSSL: 连接中是否使用 SSL。
|
||||
- user:登录 TDengine 用户名,默认值 'root'。
|
||||
- password:用户登录密码,默认值 'taosdata'。
|
||||
- batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。逐行拉取结果集使用 HTTP 方式进行数据传输。JDBC REST
|
||||
连接支持批量拉取数据功能。taos-jdbcdriver 与 TDengine 之间通过 WebSocket 连接进行数据传输。相较于 HTTP,WebSocket 可以使 JDBC REST 连接支持大数据量查询,并提升查询性能。
|
||||
- charset: 当开启批量拉取数据时,指定解析字符串数据的字符集。
|
||||
- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败,继续执行下面的 SQL 了。false:不再执行失败 SQL
|
||||
后的任何语句。默认值为:false。
|
||||
- httpConnectTimeout: 连接超时时间,单位 ms, 默认值为 5000。
|
||||
- httpSocketTimeout: socket 超时时间,单位 ms,默认值为 5000。仅在 batchfetch 设置为 false 时生效。
|
||||
- messageWaitTimeout: 消息超时时间, 单位 ms, 默认值为 3000。 仅在 batchfetch 设置为 true 时生效。
|
||||
- useSSL: 连接中是否使用 SSL。
|
||||
|
||||
**注意**:部分配置项(比如:locale、timezone)在 REST 连接中不生效。
|
||||
**注意**:部分配置项(比如:locale、timezone)在 REST 连接中不生效。
|
||||
|
||||
:::note
|
||||
:::note
|
||||
|
||||
- 与原生连接方式不同,REST 接口是无状态的。在使用 JDBC REST 连接时,需要在 SQL 中指定表、超级表的数据库名称。例如:
|
||||
- 与原生连接方式不同,REST 接口是无状态的。在使用 JDBC REST 连接时,需要在 SQL 中指定表、超级表的数据库名称。例如:
|
||||
|
||||
```sql
|
||||
INSERT INTO test.t1 USING test.weather (ts, temperature) TAGS('California.SanFrancisco') VALUES(now, 24.6);
|
||||
```
|
||||
```sql
|
||||
INSERT INTO test.t1 USING test.weather (ts, temperature) TAGS('California.SanFrancisco') VALUES(now, 24.6);
|
||||
```
|
||||
|
||||
- 如果在 url 中指定了 dbname,那么,JDBC REST 连接会默认使用/rest/sql/dbname 作为 restful 请求的 url,在 SQL 中不需要指定 dbname。例如:url 为 jdbc:TAOS-RS://127.0.0.1:6041/test,那么,可以执行 sql:insert into t1 using weather(ts, temperature) tags('California.SanFrancisco') values(now, 24.6);
|
||||
- 如果在 url 中指定了 dbname,那么,JDBC REST 连接会默认使用/rest/sql/dbname 作为 restful 请求的 url,在 SQL 中不需要指定 dbname。例如:url 为
|
||||
jdbc:TAOS-RS://127.0.0.1:6041/test,那么,可以执行 sql:insert into t1 using weather(ts, temperature)
|
||||
tags('California.SanFrancisco') values(now, 24.6);
|
||||
|
||||
:::
|
||||
:::
|
||||
|
||||
</TabItem>
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### 指定 URL 和 Properties 获取连接
|
||||
|
@ -271,7 +281,7 @@ properties 中的配置参数如下:
|
|||
- TSDBDriver.HTTP_SOCKET_TIMEOUT: socket 超时时间,单位 ms,默认值为 5000。仅在 REST 连接且 batchfetch 设置为 false 时生效。
|
||||
- TSDBDriver.PROPERTY_KEY_MESSAGE_WAIT_TIMEOUT: 消息超时时间, 单位 ms, 默认值为 3000。 仅在 REST 连接且 batchfetch 设置为 true 时生效。
|
||||
- TSDBDriver.PROPERTY_KEY_USE_SSL: 连接中是否使用 SSL。仅在 REST 连接时生效。
|
||||
此外对 JDBC 原生连接,通过指定 URL 和 Properties 还可以指定其他参数,比如日志级别、SQL 长度等。更多详细配置请参考[客户端配置](/reference/config/#仅客户端适用)。
|
||||
此外对 JDBC 原生连接,通过指定 URL 和 Properties 还可以指定其他参数,比如日志级别、SQL 长度等。更多详细配置请参考[客户端配置](/reference/config/#仅客户端适用)。
|
||||
|
||||
### 配置参数的优先级
|
||||
|
||||
|
@ -826,7 +836,7 @@ public abstract class ConsumerLoop {
|
|||
//query or insert
|
||||
// ...
|
||||
|
||||
connection.close(); // put back to conneciton pool
|
||||
connection.close(); // put back to connection pool
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -858,7 +868,7 @@ public static void main(String[] args) throws Exception {
|
|||
//query or insert
|
||||
// ...
|
||||
|
||||
connection.close(); // put back to conneciton pool
|
||||
connection.close(); // put back to connection pool
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -880,7 +890,9 @@ public static void main(String[] args) throws Exception {
|
|||
|
||||
| taos-jdbcdriver 版本 | 主要变化 |
|
||||
| :------------------: | :----------------------------: |
|
||||
| 3.0.1 - 3.0.2 | 修复一些情况下结果集数据解析错误的问题。3.0.1 在 JDK 11 环境编译,JDK 8 环境下建议使用 3.0.2 版本 |
|
||||
| 3.0.0 | 支持 TDengine 3.0 |
|
||||
| 2.0.41 | 修正 REST 连接中用户名和密码转码方式 |
|
||||
| 2.0.39 - 2.0.40 | 增加 REST 连接/请求 超时设置 |
|
||||
| 2.0.38 | JDBC REST 连接增加批量拉取功能 |
|
||||
| 2.0.37 | 增加对 json tag 支持 |
|
||||
|
@ -890,27 +902,33 @@ public static void main(String[] args) throws Exception {
|
|||
|
||||
1. 使用 Statement 的 `addBatch()` 和 `executeBatch()` 来执行“批量写入/更新”,为什么没有带来性能上的提升?
|
||||
|
||||
**原因**:TDengine 的 JDBC 实现中,通过 `addBatch` 方法提交的 SQL 语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。
|
||||
**原因**:TDengine 的 JDBC 实现中,通过 `addBatch` 方法提交的 SQL 语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。
|
||||
|
||||
**解决方法**:1. 在一条 insert 语句中拼接多个 values 值;2. 使用多线程的方式并发插入;3. 使用参数绑定的写入方式
|
||||
**解决方法**:1. 在一条 insert 语句中拼接多个 values 值;2. 使用多线程的方式并发插入;3. 使用参数绑定的写入方式
|
||||
|
||||
2. java.lang.UnsatisfiedLinkError: no taos in java.library.path
|
||||
|
||||
**原因**:程序没有找到依赖的本地函数库 taos。
|
||||
**原因**:程序没有找到依赖的本地函数库 taos。
|
||||
|
||||
**解决方法**:Windows 下可以将 C:\TDengine\driver\taos.dll 拷贝到 C:\Windows\System32\ 目录下,Linux 下将建立如下软链 `ln -s /usr/local/taos/driver/libtaos.so.x.x.x.x /usr/lib/libtaos.so` 即可,macOS 下需要建立软链 `ln -s /usr/local/lib/libtaos.dylib`。
|
||||
**解决方法**:Windows 下可以将 C:\TDengine\driver\taos.dll 拷贝到 C:\Windows\System32\ 目录下,Linux 下将建立如下软链 `ln -s /usr/local/taos/driver/libtaos.so.x.x.x.x /usr/lib/libtaos.so` 即可,macOS 下需要建立软链 `ln -s /usr/local/lib/libtaos.dylib`。
|
||||
|
||||
3. java.lang.UnsatisfiedLinkError: taos.dll Can't load AMD 64 bit on a IA 32-bit platform
|
||||
|
||||
**原因**:目前 TDengine 只支持 64 位 JDK。
|
||||
**原因**:目前 TDengine 只支持 64 位 JDK。
|
||||
|
||||
**解决方法**:重新安装 64 位 JDK。
|
||||
**解决方法**:重新安装 64 位 JDK。
|
||||
|
||||
4. java.lang.NoSuchMethodError: setByteArray
|
||||
|
||||
**原因**:taos-jdbcdriver 3.* 版本仅支持 TDengine 3.0 及以上版本。
|
||||
**原因**:taos-jdbcdriver 3.* 版本仅支持 TDengine 3.0 及以上版本。
|
||||
|
||||
**解决方法**: 使用 taos-jdbcdriver 2.* 版本连接 TDengine 2.* 版本。
|
||||
**解决方法**: 使用 taos-jdbcdriver 2.* 版本连接 TDengine 2.* 版本。
|
||||
|
||||
5. java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer; ... taos-jdbcdriver-3.0.1.jar
|
||||
|
||||
**原因**:taos-jdbcdriver 3.0.1 版本需要在 JDK 11+ 环境使用。
|
||||
|
||||
**解决方法**: 更换 taos-jdbcdriver 3.0.2 版本。
|
||||
|
||||
其它问题请参考 [FAQ](../../../train-faq/faq)
|
||||
|
||||
|
|
|
@ -164,14 +164,6 @@ typedef enum EStreamType {
|
|||
STREAM_FILL_OVER,
|
||||
} EStreamType;
|
||||
|
||||
typedef struct {
|
||||
SArray* pGroupList;
|
||||
SArray* pTableList;
|
||||
SHashObj* map; // speedup acquire the tableQueryInfo by table uid
|
||||
bool needSortTableByGroupId;
|
||||
uint64_t suid;
|
||||
} STableListInfo;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct SColumnDataAgg {
|
||||
int16_t colId;
|
||||
|
|
|
@ -119,6 +119,7 @@ extern SDiskCfg tsDiskCfg[];
|
|||
// udf
|
||||
extern bool tsStartUdfd;
|
||||
extern char tsUdfdResFuncs[];
|
||||
extern char tsUdfdLdLibPath[];
|
||||
|
||||
// schemaless
|
||||
extern char tsSmlChildTableName[];
|
||||
|
|
|
@ -1479,6 +1479,7 @@ typedef struct {
|
|||
int32_t dnodeId;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
int32_t port;
|
||||
int8_t force;
|
||||
} SDropDnodeReq;
|
||||
|
||||
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
|
||||
|
|
|
@ -267,6 +267,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_SYNC_SET_VNODE_STANDBY, "set-vnode-standby", NULL, NULL) // no longer used
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT, "sync-heartbeat", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT_REPLY, "sync-heartbeat-reply", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_LOCAL_CMD, "sync-local-cmd", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_MAX_MSG, "sync-max", NULL, NULL)
|
||||
|
||||
#if defined(TD_MSG_NUMBER_)
|
||||
|
|
|
@ -66,280 +66,281 @@
|
|||
#define TK_PORT 48
|
||||
#define TK_DNODES 49
|
||||
#define TK_NK_IPTOKEN 50
|
||||
#define TK_LOCAL 51
|
||||
#define TK_QNODE 52
|
||||
#define TK_BNODE 53
|
||||
#define TK_SNODE 54
|
||||
#define TK_MNODE 55
|
||||
#define TK_DATABASE 56
|
||||
#define TK_USE 57
|
||||
#define TK_FLUSH 58
|
||||
#define TK_TRIM 59
|
||||
#define TK_IF 60
|
||||
#define TK_NOT 61
|
||||
#define TK_EXISTS 62
|
||||
#define TK_BUFFER 63
|
||||
#define TK_CACHEMODEL 64
|
||||
#define TK_CACHESIZE 65
|
||||
#define TK_COMP 66
|
||||
#define TK_DURATION 67
|
||||
#define TK_NK_VARIABLE 68
|
||||
#define TK_MAXROWS 69
|
||||
#define TK_MINROWS 70
|
||||
#define TK_KEEP 71
|
||||
#define TK_PAGES 72
|
||||
#define TK_PAGESIZE 73
|
||||
#define TK_TSDB_PAGESIZE 74
|
||||
#define TK_PRECISION 75
|
||||
#define TK_REPLICA 76
|
||||
#define TK_STRICT 77
|
||||
#define TK_VGROUPS 78
|
||||
#define TK_SINGLE_STABLE 79
|
||||
#define TK_RETENTIONS 80
|
||||
#define TK_SCHEMALESS 81
|
||||
#define TK_WAL_LEVEL 82
|
||||
#define TK_WAL_FSYNC_PERIOD 83
|
||||
#define TK_WAL_RETENTION_PERIOD 84
|
||||
#define TK_WAL_RETENTION_SIZE 85
|
||||
#define TK_WAL_ROLL_PERIOD 86
|
||||
#define TK_WAL_SEGMENT_SIZE 87
|
||||
#define TK_STT_TRIGGER 88
|
||||
#define TK_TABLE_PREFIX 89
|
||||
#define TK_TABLE_SUFFIX 90
|
||||
#define TK_NK_COLON 91
|
||||
#define TK_MAX_SPEED 92
|
||||
#define TK_TABLE 93
|
||||
#define TK_NK_LP 94
|
||||
#define TK_NK_RP 95
|
||||
#define TK_STABLE 96
|
||||
#define TK_ADD 97
|
||||
#define TK_COLUMN 98
|
||||
#define TK_MODIFY 99
|
||||
#define TK_RENAME 100
|
||||
#define TK_TAG 101
|
||||
#define TK_SET 102
|
||||
#define TK_NK_EQ 103
|
||||
#define TK_USING 104
|
||||
#define TK_TAGS 105
|
||||
#define TK_COMMENT 106
|
||||
#define TK_BOOL 107
|
||||
#define TK_TINYINT 108
|
||||
#define TK_SMALLINT 109
|
||||
#define TK_INT 110
|
||||
#define TK_INTEGER 111
|
||||
#define TK_BIGINT 112
|
||||
#define TK_FLOAT 113
|
||||
#define TK_DOUBLE 114
|
||||
#define TK_BINARY 115
|
||||
#define TK_TIMESTAMP 116
|
||||
#define TK_NCHAR 117
|
||||
#define TK_UNSIGNED 118
|
||||
#define TK_JSON 119
|
||||
#define TK_VARCHAR 120
|
||||
#define TK_MEDIUMBLOB 121
|
||||
#define TK_BLOB 122
|
||||
#define TK_VARBINARY 123
|
||||
#define TK_DECIMAL 124
|
||||
#define TK_MAX_DELAY 125
|
||||
#define TK_WATERMARK 126
|
||||
#define TK_ROLLUP 127
|
||||
#define TK_TTL 128
|
||||
#define TK_SMA 129
|
||||
#define TK_FIRST 130
|
||||
#define TK_LAST 131
|
||||
#define TK_SHOW 132
|
||||
#define TK_DATABASES 133
|
||||
#define TK_TABLES 134
|
||||
#define TK_STABLES 135
|
||||
#define TK_MNODES 136
|
||||
#define TK_QNODES 137
|
||||
#define TK_FUNCTIONS 138
|
||||
#define TK_INDEXES 139
|
||||
#define TK_ACCOUNTS 140
|
||||
#define TK_APPS 141
|
||||
#define TK_CONNECTIONS 142
|
||||
#define TK_LICENCES 143
|
||||
#define TK_GRANTS 144
|
||||
#define TK_QUERIES 145
|
||||
#define TK_SCORES 146
|
||||
#define TK_TOPICS 147
|
||||
#define TK_VARIABLES 148
|
||||
#define TK_CLUSTER 149
|
||||
#define TK_BNODES 150
|
||||
#define TK_SNODES 151
|
||||
#define TK_TRANSACTIONS 152
|
||||
#define TK_DISTRIBUTED 153
|
||||
#define TK_CONSUMERS 154
|
||||
#define TK_SUBSCRIPTIONS 155
|
||||
#define TK_VNODES 156
|
||||
#define TK_LIKE 157
|
||||
#define TK_INDEX 158
|
||||
#define TK_FUNCTION 159
|
||||
#define TK_INTERVAL 160
|
||||
#define TK_TOPIC 161
|
||||
#define TK_AS 162
|
||||
#define TK_WITH 163
|
||||
#define TK_META 164
|
||||
#define TK_CONSUMER 165
|
||||
#define TK_GROUP 166
|
||||
#define TK_DESC 167
|
||||
#define TK_DESCRIBE 168
|
||||
#define TK_RESET 169
|
||||
#define TK_QUERY 170
|
||||
#define TK_CACHE 171
|
||||
#define TK_EXPLAIN 172
|
||||
#define TK_ANALYZE 173
|
||||
#define TK_VERBOSE 174
|
||||
#define TK_NK_BOOL 175
|
||||
#define TK_RATIO 176
|
||||
#define TK_NK_FLOAT 177
|
||||
#define TK_OUTPUTTYPE 178
|
||||
#define TK_AGGREGATE 179
|
||||
#define TK_BUFSIZE 180
|
||||
#define TK_STREAM 181
|
||||
#define TK_INTO 182
|
||||
#define TK_TRIGGER 183
|
||||
#define TK_AT_ONCE 184
|
||||
#define TK_WINDOW_CLOSE 185
|
||||
#define TK_IGNORE 186
|
||||
#define TK_EXPIRED 187
|
||||
#define TK_FILL_HISTORY 188
|
||||
#define TK_SUBTABLE 189
|
||||
#define TK_KILL 190
|
||||
#define TK_CONNECTION 191
|
||||
#define TK_TRANSACTION 192
|
||||
#define TK_BALANCE 193
|
||||
#define TK_VGROUP 194
|
||||
#define TK_MERGE 195
|
||||
#define TK_REDISTRIBUTE 196
|
||||
#define TK_SPLIT 197
|
||||
#define TK_DELETE 198
|
||||
#define TK_INSERT 199
|
||||
#define TK_NULL 200
|
||||
#define TK_NK_QUESTION 201
|
||||
#define TK_NK_ARROW 202
|
||||
#define TK_ROWTS 203
|
||||
#define TK_TBNAME 204
|
||||
#define TK_QSTART 205
|
||||
#define TK_QEND 206
|
||||
#define TK_QDURATION 207
|
||||
#define TK_WSTART 208
|
||||
#define TK_WEND 209
|
||||
#define TK_WDURATION 210
|
||||
#define TK_IROWTS 211
|
||||
#define TK_QTAGS 212
|
||||
#define TK_CAST 213
|
||||
#define TK_NOW 214
|
||||
#define TK_TODAY 215
|
||||
#define TK_TIMEZONE 216
|
||||
#define TK_CLIENT_VERSION 217
|
||||
#define TK_SERVER_VERSION 218
|
||||
#define TK_SERVER_STATUS 219
|
||||
#define TK_CURRENT_USER 220
|
||||
#define TK_COUNT 221
|
||||
#define TK_LAST_ROW 222
|
||||
#define TK_CASE 223
|
||||
#define TK_END 224
|
||||
#define TK_WHEN 225
|
||||
#define TK_THEN 226
|
||||
#define TK_ELSE 227
|
||||
#define TK_BETWEEN 228
|
||||
#define TK_IS 229
|
||||
#define TK_NK_LT 230
|
||||
#define TK_NK_GT 231
|
||||
#define TK_NK_LE 232
|
||||
#define TK_NK_GE 233
|
||||
#define TK_NK_NE 234
|
||||
#define TK_MATCH 235
|
||||
#define TK_NMATCH 236
|
||||
#define TK_CONTAINS 237
|
||||
#define TK_IN 238
|
||||
#define TK_JOIN 239
|
||||
#define TK_INNER 240
|
||||
#define TK_SELECT 241
|
||||
#define TK_DISTINCT 242
|
||||
#define TK_WHERE 243
|
||||
#define TK_PARTITION 244
|
||||
#define TK_BY 245
|
||||
#define TK_SESSION 246
|
||||
#define TK_STATE_WINDOW 247
|
||||
#define TK_SLIDING 248
|
||||
#define TK_FILL 249
|
||||
#define TK_VALUE 250
|
||||
#define TK_NONE 251
|
||||
#define TK_PREV 252
|
||||
#define TK_LINEAR 253
|
||||
#define TK_NEXT 254
|
||||
#define TK_HAVING 255
|
||||
#define TK_RANGE 256
|
||||
#define TK_EVERY 257
|
||||
#define TK_ORDER 258
|
||||
#define TK_SLIMIT 259
|
||||
#define TK_SOFFSET 260
|
||||
#define TK_LIMIT 261
|
||||
#define TK_OFFSET 262
|
||||
#define TK_ASC 263
|
||||
#define TK_NULLS 264
|
||||
#define TK_ABORT 265
|
||||
#define TK_AFTER 266
|
||||
#define TK_ATTACH 267
|
||||
#define TK_BEFORE 268
|
||||
#define TK_BEGIN 269
|
||||
#define TK_BITAND 270
|
||||
#define TK_BITNOT 271
|
||||
#define TK_BITOR 272
|
||||
#define TK_BLOCKS 273
|
||||
#define TK_CHANGE 274
|
||||
#define TK_COMMA 275
|
||||
#define TK_COMPACT 276
|
||||
#define TK_CONCAT 277
|
||||
#define TK_CONFLICT 278
|
||||
#define TK_COPY 279
|
||||
#define TK_DEFERRED 280
|
||||
#define TK_DELIMITERS 281
|
||||
#define TK_DETACH 282
|
||||
#define TK_DIVIDE 283
|
||||
#define TK_DOT 284
|
||||
#define TK_EACH 285
|
||||
#define TK_FAIL 286
|
||||
#define TK_FILE 287
|
||||
#define TK_FOR 288
|
||||
#define TK_GLOB 289
|
||||
#define TK_ID 290
|
||||
#define TK_IMMEDIATE 291
|
||||
#define TK_IMPORT 292
|
||||
#define TK_INITIALLY 293
|
||||
#define TK_INSTEAD 294
|
||||
#define TK_ISNULL 295
|
||||
#define TK_KEY 296
|
||||
#define TK_MODULES 297
|
||||
#define TK_NK_BITNOT 298
|
||||
#define TK_NK_SEMI 299
|
||||
#define TK_NOTNULL 300
|
||||
#define TK_OF 301
|
||||
#define TK_PLUS 302
|
||||
#define TK_PRIVILEGE 303
|
||||
#define TK_RAISE 304
|
||||
#define TK_REPLACE 305
|
||||
#define TK_RESTRICT 306
|
||||
#define TK_ROW 307
|
||||
#define TK_SEMI 308
|
||||
#define TK_STAR 309
|
||||
#define TK_STATEMENT 310
|
||||
#define TK_STRING 311
|
||||
#define TK_TIMES 312
|
||||
#define TK_UPDATE 313
|
||||
#define TK_VALUES 314
|
||||
#define TK_VARIABLE 315
|
||||
#define TK_VIEW 316
|
||||
#define TK_WAL 317
|
||||
#define TK_FORCE 51
|
||||
#define TK_LOCAL 52
|
||||
#define TK_QNODE 53
|
||||
#define TK_BNODE 54
|
||||
#define TK_SNODE 55
|
||||
#define TK_MNODE 56
|
||||
#define TK_DATABASE 57
|
||||
#define TK_USE 58
|
||||
#define TK_FLUSH 59
|
||||
#define TK_TRIM 60
|
||||
#define TK_IF 61
|
||||
#define TK_NOT 62
|
||||
#define TK_EXISTS 63
|
||||
#define TK_BUFFER 64
|
||||
#define TK_CACHEMODEL 65
|
||||
#define TK_CACHESIZE 66
|
||||
#define TK_COMP 67
|
||||
#define TK_DURATION 68
|
||||
#define TK_NK_VARIABLE 69
|
||||
#define TK_MAXROWS 70
|
||||
#define TK_MINROWS 71
|
||||
#define TK_KEEP 72
|
||||
#define TK_PAGES 73
|
||||
#define TK_PAGESIZE 74
|
||||
#define TK_TSDB_PAGESIZE 75
|
||||
#define TK_PRECISION 76
|
||||
#define TK_REPLICA 77
|
||||
#define TK_STRICT 78
|
||||
#define TK_VGROUPS 79
|
||||
#define TK_SINGLE_STABLE 80
|
||||
#define TK_RETENTIONS 81
|
||||
#define TK_SCHEMALESS 82
|
||||
#define TK_WAL_LEVEL 83
|
||||
#define TK_WAL_FSYNC_PERIOD 84
|
||||
#define TK_WAL_RETENTION_PERIOD 85
|
||||
#define TK_WAL_RETENTION_SIZE 86
|
||||
#define TK_WAL_ROLL_PERIOD 87
|
||||
#define TK_WAL_SEGMENT_SIZE 88
|
||||
#define TK_STT_TRIGGER 89
|
||||
#define TK_TABLE_PREFIX 90
|
||||
#define TK_TABLE_SUFFIX 91
|
||||
#define TK_NK_COLON 92
|
||||
#define TK_MAX_SPEED 93
|
||||
#define TK_TABLE 94
|
||||
#define TK_NK_LP 95
|
||||
#define TK_NK_RP 96
|
||||
#define TK_STABLE 97
|
||||
#define TK_ADD 98
|
||||
#define TK_COLUMN 99
|
||||
#define TK_MODIFY 100
|
||||
#define TK_RENAME 101
|
||||
#define TK_TAG 102
|
||||
#define TK_SET 103
|
||||
#define TK_NK_EQ 104
|
||||
#define TK_USING 105
|
||||
#define TK_TAGS 106
|
||||
#define TK_COMMENT 107
|
||||
#define TK_BOOL 108
|
||||
#define TK_TINYINT 109
|
||||
#define TK_SMALLINT 110
|
||||
#define TK_INT 111
|
||||
#define TK_INTEGER 112
|
||||
#define TK_BIGINT 113
|
||||
#define TK_FLOAT 114
|
||||
#define TK_DOUBLE 115
|
||||
#define TK_BINARY 116
|
||||
#define TK_TIMESTAMP 117
|
||||
#define TK_NCHAR 118
|
||||
#define TK_UNSIGNED 119
|
||||
#define TK_JSON 120
|
||||
#define TK_VARCHAR 121
|
||||
#define TK_MEDIUMBLOB 122
|
||||
#define TK_BLOB 123
|
||||
#define TK_VARBINARY 124
|
||||
#define TK_DECIMAL 125
|
||||
#define TK_MAX_DELAY 126
|
||||
#define TK_WATERMARK 127
|
||||
#define TK_ROLLUP 128
|
||||
#define TK_TTL 129
|
||||
#define TK_SMA 130
|
||||
#define TK_FIRST 131
|
||||
#define TK_LAST 132
|
||||
#define TK_SHOW 133
|
||||
#define TK_DATABASES 134
|
||||
#define TK_TABLES 135
|
||||
#define TK_STABLES 136
|
||||
#define TK_MNODES 137
|
||||
#define TK_QNODES 138
|
||||
#define TK_FUNCTIONS 139
|
||||
#define TK_INDEXES 140
|
||||
#define TK_ACCOUNTS 141
|
||||
#define TK_APPS 142
|
||||
#define TK_CONNECTIONS 143
|
||||
#define TK_LICENCES 144
|
||||
#define TK_GRANTS 145
|
||||
#define TK_QUERIES 146
|
||||
#define TK_SCORES 147
|
||||
#define TK_TOPICS 148
|
||||
#define TK_VARIABLES 149
|
||||
#define TK_CLUSTER 150
|
||||
#define TK_BNODES 151
|
||||
#define TK_SNODES 152
|
||||
#define TK_TRANSACTIONS 153
|
||||
#define TK_DISTRIBUTED 154
|
||||
#define TK_CONSUMERS 155
|
||||
#define TK_SUBSCRIPTIONS 156
|
||||
#define TK_VNODES 157
|
||||
#define TK_LIKE 158
|
||||
#define TK_INDEX 159
|
||||
#define TK_FUNCTION 160
|
||||
#define TK_INTERVAL 161
|
||||
#define TK_TOPIC 162
|
||||
#define TK_AS 163
|
||||
#define TK_WITH 164
|
||||
#define TK_META 165
|
||||
#define TK_CONSUMER 166
|
||||
#define TK_GROUP 167
|
||||
#define TK_DESC 168
|
||||
#define TK_DESCRIBE 169
|
||||
#define TK_RESET 170
|
||||
#define TK_QUERY 171
|
||||
#define TK_CACHE 172
|
||||
#define TK_EXPLAIN 173
|
||||
#define TK_ANALYZE 174
|
||||
#define TK_VERBOSE 175
|
||||
#define TK_NK_BOOL 176
|
||||
#define TK_RATIO 177
|
||||
#define TK_NK_FLOAT 178
|
||||
#define TK_OUTPUTTYPE 179
|
||||
#define TK_AGGREGATE 180
|
||||
#define TK_BUFSIZE 181
|
||||
#define TK_STREAM 182
|
||||
#define TK_INTO 183
|
||||
#define TK_TRIGGER 184
|
||||
#define TK_AT_ONCE 185
|
||||
#define TK_WINDOW_CLOSE 186
|
||||
#define TK_IGNORE 187
|
||||
#define TK_EXPIRED 188
|
||||
#define TK_FILL_HISTORY 189
|
||||
#define TK_SUBTABLE 190
|
||||
#define TK_KILL 191
|
||||
#define TK_CONNECTION 192
|
||||
#define TK_TRANSACTION 193
|
||||
#define TK_BALANCE 194
|
||||
#define TK_VGROUP 195
|
||||
#define TK_MERGE 196
|
||||
#define TK_REDISTRIBUTE 197
|
||||
#define TK_SPLIT 198
|
||||
#define TK_DELETE 199
|
||||
#define TK_INSERT 200
|
||||
#define TK_NULL 201
|
||||
#define TK_NK_QUESTION 202
|
||||
#define TK_NK_ARROW 203
|
||||
#define TK_ROWTS 204
|
||||
#define TK_TBNAME 205
|
||||
#define TK_QSTART 206
|
||||
#define TK_QEND 207
|
||||
#define TK_QDURATION 208
|
||||
#define TK_WSTART 209
|
||||
#define TK_WEND 210
|
||||
#define TK_WDURATION 211
|
||||
#define TK_IROWTS 212
|
||||
#define TK_QTAGS 213
|
||||
#define TK_CAST 214
|
||||
#define TK_NOW 215
|
||||
#define TK_TODAY 216
|
||||
#define TK_TIMEZONE 217
|
||||
#define TK_CLIENT_VERSION 218
|
||||
#define TK_SERVER_VERSION 219
|
||||
#define TK_SERVER_STATUS 220
|
||||
#define TK_CURRENT_USER 221
|
||||
#define TK_COUNT 222
|
||||
#define TK_LAST_ROW 223
|
||||
#define TK_CASE 224
|
||||
#define TK_END 225
|
||||
#define TK_WHEN 226
|
||||
#define TK_THEN 227
|
||||
#define TK_ELSE 228
|
||||
#define TK_BETWEEN 229
|
||||
#define TK_IS 230
|
||||
#define TK_NK_LT 231
|
||||
#define TK_NK_GT 232
|
||||
#define TK_NK_LE 233
|
||||
#define TK_NK_GE 234
|
||||
#define TK_NK_NE 235
|
||||
#define TK_MATCH 236
|
||||
#define TK_NMATCH 237
|
||||
#define TK_CONTAINS 238
|
||||
#define TK_IN 239
|
||||
#define TK_JOIN 240
|
||||
#define TK_INNER 241
|
||||
#define TK_SELECT 242
|
||||
#define TK_DISTINCT 243
|
||||
#define TK_WHERE 244
|
||||
#define TK_PARTITION 245
|
||||
#define TK_BY 246
|
||||
#define TK_SESSION 247
|
||||
#define TK_STATE_WINDOW 248
|
||||
#define TK_SLIDING 249
|
||||
#define TK_FILL 250
|
||||
#define TK_VALUE 251
|
||||
#define TK_NONE 252
|
||||
#define TK_PREV 253
|
||||
#define TK_LINEAR 254
|
||||
#define TK_NEXT 255
|
||||
#define TK_HAVING 256
|
||||
#define TK_RANGE 257
|
||||
#define TK_EVERY 258
|
||||
#define TK_ORDER 259
|
||||
#define TK_SLIMIT 260
|
||||
#define TK_SOFFSET 261
|
||||
#define TK_LIMIT 262
|
||||
#define TK_OFFSET 263
|
||||
#define TK_ASC 264
|
||||
#define TK_NULLS 265
|
||||
#define TK_ABORT 266
|
||||
#define TK_AFTER 267
|
||||
#define TK_ATTACH 268
|
||||
#define TK_BEFORE 269
|
||||
#define TK_BEGIN 270
|
||||
#define TK_BITAND 271
|
||||
#define TK_BITNOT 272
|
||||
#define TK_BITOR 273
|
||||
#define TK_BLOCKS 274
|
||||
#define TK_CHANGE 275
|
||||
#define TK_COMMA 276
|
||||
#define TK_COMPACT 277
|
||||
#define TK_CONCAT 278
|
||||
#define TK_CONFLICT 279
|
||||
#define TK_COPY 280
|
||||
#define TK_DEFERRED 281
|
||||
#define TK_DELIMITERS 282
|
||||
#define TK_DETACH 283
|
||||
#define TK_DIVIDE 284
|
||||
#define TK_DOT 285
|
||||
#define TK_EACH 286
|
||||
#define TK_FAIL 287
|
||||
#define TK_FILE 288
|
||||
#define TK_FOR 289
|
||||
#define TK_GLOB 290
|
||||
#define TK_ID 291
|
||||
#define TK_IMMEDIATE 292
|
||||
#define TK_IMPORT 293
|
||||
#define TK_INITIALLY 294
|
||||
#define TK_INSTEAD 295
|
||||
#define TK_ISNULL 296
|
||||
#define TK_KEY 297
|
||||
#define TK_MODULES 298
|
||||
#define TK_NK_BITNOT 299
|
||||
#define TK_NK_SEMI 300
|
||||
#define TK_NOTNULL 301
|
||||
#define TK_OF 302
|
||||
#define TK_PLUS 303
|
||||
#define TK_PRIVILEGE 304
|
||||
#define TK_RAISE 305
|
||||
#define TK_REPLACE 306
|
||||
#define TK_RESTRICT 307
|
||||
#define TK_ROW 308
|
||||
#define TK_SEMI 309
|
||||
#define TK_STAR 310
|
||||
#define TK_STATEMENT 311
|
||||
#define TK_STRING 312
|
||||
#define TK_TIMES 313
|
||||
#define TK_UPDATE 314
|
||||
#define TK_VALUES 315
|
||||
#define TK_VARIABLE 316
|
||||
#define TK_VIEW 317
|
||||
#define TK_WAL 318
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
#define TK_NK_ILLEGAL 302
|
||||
#define TK_NK_HEX 303 // hex number 0x123
|
||||
#define TK_NK_OCT 304 // oct number
|
||||
#define TK_NK_BIN 305 // bin format data 0b111
|
||||
#define TK_NK_SPACE 600
|
||||
#define TK_NK_COMMENT 601
|
||||
#define TK_NK_ILLEGAL 602
|
||||
#define TK_NK_HEX 603 // hex number 0x123
|
||||
#define TK_NK_OCT 604 // oct number
|
||||
#define TK_NK_BIN 605 // bin format data 0b111
|
||||
|
||||
#define TK_NK_NIL 65535
|
||||
|
||||
|
|
|
@ -235,6 +235,7 @@ typedef struct SDropDnodeStmt {
|
|||
int32_t dnodeId;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
int32_t port;
|
||||
bool force;
|
||||
} SDropDnodeStmt;
|
||||
|
||||
typedef struct SAlterDnodeStmt {
|
||||
|
|
|
@ -200,10 +200,10 @@ typedef struct SSyncInfo {
|
|||
|
||||
int32_t syncInit();
|
||||
void syncCleanUp();
|
||||
bool syncIsInit();
|
||||
int64_t syncOpen(SSyncInfo* pSyncInfo);
|
||||
void syncStart(int64_t rid);
|
||||
void syncStop(int64_t rid);
|
||||
int32_t syncSetStandby(int64_t rid);
|
||||
ESyncState syncGetMyRole(int64_t rid);
|
||||
bool syncIsReady(int64_t rid);
|
||||
const char* syncGetMyRoleStr(int64_t rid);
|
||||
|
@ -216,7 +216,6 @@ void syncGetEpSet(int64_t rid, SEpSet* pEpSet);
|
|||
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet);
|
||||
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak);
|
||||
// int32_t syncProposeBatch(int64_t rid, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize);
|
||||
bool syncEnvIsStart();
|
||||
const char* syncStr(ESyncState state);
|
||||
bool syncIsRestoreFinish(int64_t rid);
|
||||
int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot);
|
||||
|
@ -232,6 +231,11 @@ int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader);
|
|||
int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex);
|
||||
int32_t syncEndSnapshot(int64_t rid);
|
||||
|
||||
int32_t syncStepDown(int64_t rid, SyncTerm newTerm);
|
||||
|
||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
||||
void syncNodeRelease(SSyncNode* pNode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -28,10 +28,6 @@ typedef struct SRaftId {
|
|||
SyncGroupId vgId;
|
||||
} SRaftId;
|
||||
|
||||
// ------------------ control -------------------
|
||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
||||
void syncNodeRelease(SSyncNode* pNode);
|
||||
|
||||
int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg);
|
||||
int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo);
|
||||
void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb);
|
||||
|
@ -678,24 +674,64 @@ void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg);
|
|||
void syncReconfigFinishLog(const SyncReconfigFinish* pMsg);
|
||||
void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg);
|
||||
|
||||
// on message ----------------------
|
||||
int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg);
|
||||
int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg);
|
||||
// ---------------------------------------------
|
||||
|
||||
typedef enum {
|
||||
SYNC_LOCAL_CMD_STEP_DOWN = 100,
|
||||
} ESyncLocalCmd;
|
||||
|
||||
const char* syncLocalCmdGetStr(int32_t cmd);
|
||||
|
||||
typedef struct SyncLocalCmd {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
int32_t cmd;
|
||||
SyncTerm sdNewTerm; // step down new term
|
||||
|
||||
} SyncLocalCmd;
|
||||
|
||||
SyncLocalCmd* syncLocalCmdBuild(int32_t vgId);
|
||||
void syncLocalCmdDestroy(SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg);
|
||||
char* syncLocalCmdSerialize2(const SyncLocalCmd* pMsg, uint32_t* len);
|
||||
SyncLocalCmd* syncLocalCmdDeserialize2(const char* buf, uint32_t len);
|
||||
void syncLocalCmd2RpcMsg(const SyncLocalCmd* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncLocalCmdFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLocalCmd* pMsg);
|
||||
SyncLocalCmd* syncLocalCmdFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg);
|
||||
char* syncLocalCmd2Str(const SyncLocalCmd* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncLocalCmdPrint(const SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdLog(const SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdLog2(char* s, const SyncLocalCmd* pMsg);
|
||||
|
||||
// on message ----------------------
|
||||
int32_t syncNodeOnPing(SSyncNode* ths, SyncPing* pMsg);
|
||||
int32_t syncNodeOnPingReply(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg);
|
||||
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg);
|
||||
int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex);
|
||||
int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnSnapshot(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
||||
int32_t syncNodeOnSnapshotReply(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||
|
||||
int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg);
|
||||
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex);
|
||||
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg);
|
||||
int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg);
|
||||
|
||||
// -----------------------------------------
|
||||
typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg);
|
||||
typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
|
|
|
@ -36,6 +36,7 @@ void *taosMemoryStrDup(const char *ptr);
|
|||
void taosMemoryFree(void *ptr);
|
||||
int64_t taosMemorySize(void *ptr);
|
||||
void taosPrintBackTrace();
|
||||
void taosMemoryTrim(int32_t size);
|
||||
|
||||
#define taosMemoryFreeClear(ptr) \
|
||||
do { \
|
||||
|
|
|
@ -360,7 +360,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_DEFAULT_DB_SCHEMALESS TSDB_DB_SCHEMALESS_OFF
|
||||
#define TSDB_MIN_STT_TRIGGER 1
|
||||
#define TSDB_MAX_STT_TRIGGER 16
|
||||
#define TSDB_DEFAULT_SST_TRIGGER 8
|
||||
#define TSDB_DEFAULT_SST_TRIGGER 1
|
||||
#define TSDB_MIN_HASH_PREFIX 0
|
||||
#define TSDB_MAX_HASH_PREFIX 128
|
||||
#define TSDB_DEFAULT_HASH_PREFIX 0
|
||||
|
|
|
@ -25,7 +25,8 @@ extern "C" {
|
|||
|
||||
// open a reference set, max is the mod used by hash, fp is the pointer to free resource function
|
||||
// return rsetId which will be used by other APIs. On error, -1 is returned, and terrno is set appropriately
|
||||
int32_t taosOpenRef(int32_t max, void (*fp)(void *));
|
||||
typedef void (*RefFp)(void *);
|
||||
int32_t taosOpenRef(int32_t max, RefFp fp);
|
||||
|
||||
// close the reference set, refId is the return value by taosOpenRef
|
||||
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
||||
|
|
|
@ -163,7 +163,8 @@ int32_t tsTtlUnit = 86400;
|
|||
int32_t tsTtlPushInterval = 86400;
|
||||
int32_t tsGrantHBInterval = 60;
|
||||
int32_t tsUptimeInterval = 300; // seconds
|
||||
char tsUdfdResFuncs[1024] = ""; // udfd resident funcs that teardown when udfd exits
|
||||
char tsUdfdResFuncs[512] = ""; // udfd resident funcs that teardown when udfd exits
|
||||
char tsUdfdLdLibPath[512] = "";
|
||||
|
||||
#ifndef _STORAGE
|
||||
int32_t taosSetTfsCfg(SConfig *pCfg) {
|
||||
|
@ -424,6 +425,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
|
||||
if (cfgAddBool(pCfg, "udf", tsStartUdfd, 0) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "udfdResFuncs", tsUdfdResFuncs, 0) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "udfdLdLibPath", tsUdfdLdLibPath, 0) != 0) return -1;
|
||||
GRANT_CFG_ADD;
|
||||
return 0;
|
||||
}
|
||||
|
@ -722,7 +724,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
|
||||
tsStartUdfd = cfgGetItem(pCfg, "udf")->bval;
|
||||
tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs));
|
||||
|
||||
tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath));
|
||||
if (tsQueryBufferSize >= 0) {
|
||||
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
|
||||
}
|
||||
|
|
|
@ -1485,6 +1485,7 @@ int32_t tSerializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq)
|
|||
if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->fqdn) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->port) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->force) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -1500,6 +1501,7 @@ int32_t tDeserializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq
|
|||
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->fqdn) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->port) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->force) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
|
|
@ -73,7 +73,13 @@ void tdSCellValPrint(SCellVal *pVal, int8_t colType) {
|
|||
} else if (tdValTypeIsNone(pVal->valType)) {
|
||||
printf("NONE ");
|
||||
return;
|
||||
}
|
||||
if(!pVal->val) {
|
||||
ASSERT(0);
|
||||
printf("BadVal ");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (colType) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
printf("%s ", (*(int8_t *)pVal->val) == 0 ? "false" : "true");
|
||||
|
@ -678,6 +684,10 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp
|
|||
}
|
||||
// TS KEY is stored in STSRow.ts and not included in STSRow.data field.
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
if (!val) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
TD_ROW_KEY(pRow) = *(TSKEY *)val;
|
||||
// The primary TS key is Norm all the time, thus its valType is not stored in bitmap.
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -20,7 +20,7 @@ static void *dmStatusThreadFp(void *param) {
|
|||
SDnodeMgmt *pMgmt = param;
|
||||
int64_t lastTime = taosGetTimestampMs();
|
||||
setThreadName("dnode-status");
|
||||
|
||||
|
||||
while (1) {
|
||||
taosMsleep(200);
|
||||
if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
|
||||
|
@ -28,6 +28,7 @@ static void *dmStatusThreadFp(void *param) {
|
|||
int64_t curTime = taosGetTimestampMs();
|
||||
float interval = (curTime - lastTime) / 1000.0f;
|
||||
if (interval >= tsStatusInterval) {
|
||||
taosMemoryTrim(0);
|
||||
dmSendStatusReq(pMgmt);
|
||||
lastTime = curTime;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId);
|
|||
void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj);
|
||||
bool mndIsMnode(SMnode *pMnode, int32_t dnodeId);
|
||||
void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet);
|
||||
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj);
|
||||
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj, bool force);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ void mndCleanupQnode(SMnode *pMnode);
|
|||
SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId);
|
||||
void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj);
|
||||
int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit);
|
||||
int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj);
|
||||
int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj, bool force);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ void mndCleanupSnode(SMnode *pMnode);
|
|||
SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t qnodeId);
|
||||
void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj);
|
||||
SEpSet mndAcquireEpFromSnode(SMnode *pMnode, const SSnodeObj *pSnode);
|
||||
int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj);
|
||||
int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj, bool force);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -42,8 +42,7 @@ int32_t mndAddCreateVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *p
|
|||
int32_t mndAddAlterVnodeConfirmAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup);
|
||||
int32_t mndAddAlterVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType);
|
||||
int32_t mndAddDropVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool isRedo);
|
||||
int32_t mndSetMoveVgroupInfoToTrans(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vn, SArray *pArray);
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnodeId);
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnodeId, bool force);
|
||||
int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pVgroup,
|
||||
SArray *pArray);
|
||||
|
||||
|
|
|
@ -670,7 +670,7 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMnodeObj *pMObj, SQnodeObj *pQObj,
|
||||
SSnodeObj *pSObj, int32_t numOfVnodes) {
|
||||
SSnodeObj *pSObj, int32_t numOfVnodes, bool force) {
|
||||
int32_t code = -1;
|
||||
SSdbRaw *pRaw = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
|
@ -678,7 +678,7 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM
|
|||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "drop-dnode");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to drop dnode:%d", pTrans->id, pDnode->id);
|
||||
mInfo("trans:%d, used to drop dnode:%d, force:%d", pTrans->id, pDnode->id, force);
|
||||
|
||||
pRaw = mndDnodeActionEncode(pDnode);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
@ -694,22 +694,22 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM
|
|||
|
||||
if (pMObj != NULL) {
|
||||
mInfo("trans:%d, mnode on dnode:%d will be dropped", pTrans->id, pDnode->id);
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj) != 0) goto _OVER;
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj, force) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (pQObj != NULL) {
|
||||
mInfo("trans:%d, qnode on dnode:%d will be dropped", pTrans->id, pDnode->id);
|
||||
if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pQObj) != 0) goto _OVER;
|
||||
if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pQObj, force) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (pSObj != NULL) {
|
||||
mInfo("trans:%d, snode on dnode:%d will be dropped", pTrans->id, pDnode->id);
|
||||
if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pSObj) != 0) goto _OVER;
|
||||
if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pSObj, force) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (numOfVnodes > 0) {
|
||||
mInfo("trans:%d, %d vnodes on dnode:%d will be dropped", pTrans->id, numOfVnodes, pDnode->id);
|
||||
if (mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id) != 0) goto _OVER;
|
||||
if (mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id, force) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
@ -767,16 +767,16 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
int32_t numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id);
|
||||
if (numOfVnodes > 0 || pMObj != NULL) {
|
||||
if ((numOfVnodes > 0 || pMObj != NULL || pSObj != NULL || pQObj != NULL) && !dropReq.force) {
|
||||
if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
mError("dnode:%d, failed to drop since %s, has_mnode:%d numOfVnodes:%d", pDnode->id, terrstr(), pMObj != NULL,
|
||||
numOfVnodes);
|
||||
mError("dnode:%d, failed to drop since %s, vnodes:%d mnode:%d qnode:%d snode:%d", pDnode->id, terrstr(),
|
||||
numOfVnodes, pMObj != NULL, pQObj != NULL, pSObj != NULL);
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes);
|
||||
code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes, dropReq.force);
|
||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
_OVER:
|
||||
|
|
|
@ -481,7 +481,7 @@ int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg) {
|
|||
|
||||
mInfo("vgId:%d, process sync ctrl msg", 1);
|
||||
|
||||
if (!syncEnvIsStart()) {
|
||||
if (!syncIsInit()) {
|
||||
mError("failed to process sync msg:%p type:%s since syncEnv stop", pMsg, TMSG_INFO(pMsg->msgType));
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
|
@ -518,7 +518,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
|||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
int32_t code = 0;
|
||||
|
||||
if (!syncEnvIsStart()) {
|
||||
if (!syncIsInit()) {
|
||||
mError("failed to process sync msg:%p type:%s since syncEnv stop", pMsg, TMSG_INFO(pMsg->msgType));
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
|
@ -538,12 +538,12 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
|||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
||||
code = syncNodeOnPing(pSyncNode, pSyncMsg);
|
||||
syncPingDestroy(pSyncMsg);
|
||||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
||||
code = syncNodeOnPingReply(pSyncNode, pSyncMsg);
|
||||
syncPingReplyDestroy(pSyncMsg);
|
||||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||
|
@ -581,10 +581,10 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
|||
code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg);
|
||||
syncSnapshotRspDestroy(pSyncMsg);
|
||||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) {
|
||||
code = syncSetStandby(pMgmt->sync);
|
||||
SRpcMsg rsp = {.code = code, .info = pMsg->info};
|
||||
tmsgSendRsp(&rsp);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_LOCAL_CMD) {
|
||||
SyncLocalCmd *pSyncMsg = syncLocalCmdFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnLocalCmd(pSyncNode, pSyncMsg);
|
||||
syncLocalCmdDestroy(pSyncMsg);
|
||||
|
||||
} else {
|
||||
mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||
|
|
|
@ -472,7 +472,8 @@ static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeO
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||
static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj,
|
||||
bool force) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
|
@ -485,12 +486,21 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
|
||||
int32_t totalMnodes = sdbGetSize(pSdb, SDB_MNODE);
|
||||
if (totalMnodes == 2) {
|
||||
if (force) {
|
||||
mError("cant't force drop dnode, since a mnode on it and replica is 2");
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
mInfo("vgId:1, has %d mnodes, exec redo log first", totalMnodes);
|
||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1;
|
||||
if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1;
|
||||
if (!force) {
|
||||
if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1;
|
||||
}
|
||||
} else if (totalMnodes == 3) {
|
||||
mInfo("vgId:1, has %d mnodes, exec redo action first", totalMnodes);
|
||||
if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1;
|
||||
if (!force) {
|
||||
if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1;
|
||||
}
|
||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1;
|
||||
} else {
|
||||
return -1;
|
||||
|
@ -499,9 +509,9 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj, bool force) {
|
||||
if (pObj == NULL) return 0;
|
||||
if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) return -1;
|
||||
if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj, force) != 0) return -1;
|
||||
if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -515,7 +525,7 @@ static int32_t mndDropMnode(SMnode *pMnode, SRpcMsg *pReq, SMnodeObj *pObj) {
|
|||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
||||
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER;
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
@ -743,7 +753,7 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
|
|||
mInfo("vgId:1, mnode sync not reconfig since readyMnodes:%d updatingMnodes:%d", readyMnodes, updatingMnodes);
|
||||
return;
|
||||
}
|
||||
// ASSERT(0);
|
||||
// ASSERT(0);
|
||||
|
||||
if (cfg.myIndex == -1) {
|
||||
#if 1
|
||||
|
|
|
@ -353,11 +353,13 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj) {
|
||||
int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj, bool force) {
|
||||
if (pObj == NULL) return 0;
|
||||
if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) return -1;
|
||||
if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) return -1;
|
||||
if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1;
|
||||
if (!force) {
|
||||
if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -368,7 +370,7 @@ static int32_t mndDropQnode(SMnode *pMnode, SRpcMsg *pReq, SQnodeObj *pObj) {
|
|||
if (pTrans == NULL) goto _OVER;
|
||||
|
||||
mInfo("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id);
|
||||
if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER;
|
||||
if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
|
|
@ -360,11 +360,13 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj) {
|
||||
int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj, bool force) {
|
||||
if (pObj == NULL) return 0;
|
||||
if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) return -1;
|
||||
if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) return -1;
|
||||
if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1;
|
||||
if (!force) {
|
||||
if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -375,7 +377,7 @@ static int32_t mndDropSnode(SMnode *pMnode, SRpcMsg *pReq, SSnodeObj *pObj) {
|
|||
if (pTrans == NULL) goto _OVER;
|
||||
|
||||
mInfo("trans:%d, used to drop snode:%d", pTrans->id, pObj->id);
|
||||
if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER;
|
||||
if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
@ -386,9 +388,9 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
int32_t code = -1;
|
||||
SSnodeObj *pObj = NULL;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
int32_t code = -1;
|
||||
SSnodeObj *pObj = NULL;
|
||||
SMDropSnodeReq dropReq = {0};
|
||||
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
|
|
|
@ -2029,7 +2029,7 @@ static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_DROP_STB;
|
||||
action.acceptableCode = TSDB_CODE_VND_TB_NOT_EXIST;
|
||||
action.acceptableCode = TSDB_CODE_TDB_STB_NOT_EXIST;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
|
|
|
@ -17,11 +17,44 @@
|
|||
#include "mndSync.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
static int32_t mndSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
|
||||
if (msgcb == NULL || msgcb->putToQueueFp == NULL) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = tmsgPutToQueue(msgcb, SYNC_CTRL_QUEUE, pMsg);
|
||||
if (code != 0) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
|
||||
if (msgcb == NULL || msgcb->putToQueueFp == NULL) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg);
|
||||
if (code != 0) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
@ -212,7 +245,7 @@ int32_t mndInitSync(SMnode *pMnode) {
|
|||
.msgcb = NULL,
|
||||
.FpSendMsg = mndSyncSendMsg,
|
||||
.FpEqMsg = mndSyncEqMsg,
|
||||
.FpEqCtrlMsg = NULL,
|
||||
.FpEqCtrlMsg = mndSyncEqCtrlMsg,
|
||||
};
|
||||
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP);
|
||||
|
|
|
@ -1071,7 +1071,7 @@ int32_t mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
|
|||
}
|
||||
|
||||
int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vnIndex,
|
||||
SArray *pArray) {
|
||||
SArray *pArray, bool force) {
|
||||
SVgObj newVg = {0};
|
||||
memcpy(&newVg, pVgroup, sizeof(SVgObj));
|
||||
|
||||
|
@ -1080,24 +1080,45 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
|
|||
mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId);
|
||||
}
|
||||
|
||||
mInfo("vgId:%d, will add 1 vnodes", pVgroup->vgId);
|
||||
if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[newVg.replica - 1]) != 0) return -1;
|
||||
for (int32_t i = 0; i < newVg.replica - 1; ++i) {
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1;
|
||||
}
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
||||
if (!force) {
|
||||
mInfo("vgId:%d, will add 1 vnode", pVgroup->vgId);
|
||||
if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[newVg.replica - 1]) != 0) return -1;
|
||||
for (int32_t i = 0; i < newVg.replica - 1; ++i) {
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1;
|
||||
}
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
||||
|
||||
mInfo("vgId:%d, will remove 1 vnodes", pVgroup->vgId);
|
||||
newVg.replica--;
|
||||
SVnodeGid del = newVg.vnodeGid[vnIndex];
|
||||
newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica];
|
||||
memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid));
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1;
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1;
|
||||
mInfo("vgId:%d, will remove 1 vnode", pVgroup->vgId);
|
||||
newVg.replica--;
|
||||
SVnodeGid del = newVg.vnodeGid[vnIndex];
|
||||
newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica];
|
||||
memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid));
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1;
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1;
|
||||
}
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
||||
} else {
|
||||
mInfo("vgId:%d, will add 1 vnode and force remove 1 vnode", pVgroup->vgId);
|
||||
if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1;
|
||||
newVg.replica--;
|
||||
SVnodeGid del = newVg.vnodeGid[vnIndex];
|
||||
newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica];
|
||||
memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid));
|
||||
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[vnIndex]) != 0) return -1;
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
if (i != vnIndex) {
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1;
|
||||
}
|
||||
}
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
||||
|
||||
if (newVg.replica == 1) {
|
||||
mInfo("vgId:%d, all data is dropped since replica=1", pVgroup->vgId);
|
||||
}
|
||||
}
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
||||
|
||||
{
|
||||
SSdbRaw *pRaw = mndVgroupActionEncode(&newVg);
|
||||
|
@ -1120,7 +1141,7 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t delDnodeId) {
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t delDnodeId, bool force) {
|
||||
int32_t code = 0;
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, delDnodeId);
|
||||
if (pArray == NULL) return -1;
|
||||
|
@ -1141,9 +1162,9 @@ int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t del
|
|||
|
||||
code = 0;
|
||||
if (vnIndex != -1) {
|
||||
mInfo("vgId:%d, vnode:%d will be removed from dnode:%d", pVgroup->vgId, vnIndex, delDnodeId);
|
||||
mInfo("vgId:%d, vnode:%d will be removed from dnode:%d, force:%d", pVgroup->vgId, vnIndex, delDnodeId, force);
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
||||
code = mndSetMoveVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, vnIndex, pArray);
|
||||
code = mndSetMoveVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, vnIndex, pArray, force);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
}
|
||||
|
||||
|
|
|
@ -152,26 +152,25 @@ typedef struct STsdbReader STsdbReader;
|
|||
#define CACHESCAN_RETRIEVE_LAST_ROW 0x4
|
||||
#define CACHESCAN_RETRIEVE_LAST 0x8
|
||||
|
||||
int32_t tsdbSetTableId(STsdbReader *pReader, int64_t uid);
|
||||
int32_t tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, SArray *pTableList, STsdbReader **ppReader,
|
||||
const char *idstr);
|
||||
int32_t tsdbSetTableList(STsdbReader *pReader, const void *pTableList, int32_t num);
|
||||
int32_t tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, void *pTableList, int32_t numOfTables,
|
||||
STsdbReader **ppReader, const char *idstr);
|
||||
|
||||
void tsdbReaderClose(STsdbReader *pReader);
|
||||
bool tsdbNextDataBlock(STsdbReader *pReader);
|
||||
bool tsdbTableNextDataBlock(STsdbReader *pReader, int64_t uid);
|
||||
bool tsdbTableNextDataBlock(STsdbReader *pReader, uint64_t uid);
|
||||
void tsdbRetrieveDataBlockInfo(STsdbReader *pReader, SDataBlockInfo *pDataBlockInfo);
|
||||
int32_t tsdbRetrieveDatablockSMA(STsdbReader *pReader, SColumnDataAgg ***pBlockStatis, bool *allHave);
|
||||
SArray *tsdbRetrieveDataBlock(STsdbReader *pTsdbReadHandle, SArray *pColumnIdList);
|
||||
int32_t tsdbReaderReset(STsdbReader *pReader, SQueryTableDataCond *pCond);
|
||||
int32_t tsdbGetFileBlocksDistInfo(STsdbReader *pReader, STableBlockDistInfo *pTableBlockInfo);
|
||||
int64_t tsdbGetNumOfRowsInMemTable(STsdbReader *pHandle);
|
||||
bool tsdbIsAscendingOrder(STsdbReader *pReader);
|
||||
void *tsdbGetIdx(SMeta *pMeta);
|
||||
void *tsdbGetIvtIdx(SMeta *pMeta);
|
||||
uint64_t getReaderMaxVersion(STsdbReader *pReader);
|
||||
|
||||
int32_t tsdbCacherowsReaderOpen(void *pVnode, int32_t type, SArray *pTableIdList, int32_t numOfCols, uint64_t suid,
|
||||
void **pReader);
|
||||
int32_t tsdbCacherowsReaderOpen(void *pVnode, int32_t type, void *pTableIdList, int32_t numOfTables, int32_t numOfCols,
|
||||
uint64_t suid, void **pReader);
|
||||
int32_t tsdbRetrieveCacheRows(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds, SArray *pTableUids);
|
||||
void *tsdbCacherowsReaderClose(void *pReader);
|
||||
int32_t tsdbGetTableSchema(SVnode *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid);
|
||||
|
|
|
@ -716,7 +716,9 @@ typedef struct SCacheRowsReader {
|
|||
int32_t numOfCols;
|
||||
int32_t type;
|
||||
int32_t tableIndex; // currently returned result tables
|
||||
SArray *pTableList; // table id list
|
||||
|
||||
STableKeyInfo *pTableList; // table id list
|
||||
int32_t numOfTables;
|
||||
SSttBlockLoadInfo *pLoadInfo;
|
||||
STsdbReadSnap *pReadSnap;
|
||||
SDataFReader *pDataFReader;
|
||||
|
|
|
@ -162,10 +162,7 @@ int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSub
|
|||
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock,
|
||||
SSubmitBlkRsp* pRsp);
|
||||
int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
|
||||
STsdbReader tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
||||
void* pMemRef);
|
||||
int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg);
|
||||
int32_t tsdbGetStbIdList(SMeta* pMeta, int64_t suid, SArray* list);
|
||||
|
||||
// tq
|
||||
int tqInit();
|
||||
|
|
|
@ -701,25 +701,28 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
|
|||
#endif
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pResList); ++i) {
|
||||
SSDataBlock *output = taosArrayGetP(pResList, i);
|
||||
smaDebug("result block, uid:%"PRIu64", groupid:%"PRIu64", rows:%d", output->info.uid, output->info.groupId,
|
||||
output->info.rows);
|
||||
|
||||
STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb[0] : pSma->pRSmaTsdb[1]);
|
||||
SSubmitReq *pReq = NULL;
|
||||
|
||||
// TODO: the schema update should be handled later(TD-17965)
|
||||
if (buildSubmitReqFromDataBlock(&pReq, output, pTSchema, SMA_VID(pSma), suid) < 0) {
|
||||
smaError("vgId:%d, build submit req for rsma table %" PRIi64 " level %" PRIi8 " failed since %s", SMA_VID(pSma),
|
||||
suid, pItem->level, terrstr());
|
||||
smaError("vgId:%d, build submit req for rsma table suid:%" PRIu64 ", uid:%"PRIu64", level %" PRIi8 " failed since %s", SMA_VID(pSma),
|
||||
suid, output->info.groupId, pItem->level, terrstr());
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (pReq && tdProcessSubmitReq(sinkTsdb, output->info.version, pReq) < 0) {
|
||||
taosMemoryFreeClear(pReq);
|
||||
smaError("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " failed since %s",
|
||||
SMA_VID(pSma), suid, pItem->level, terrstr());
|
||||
smaError("vgId:%d, process submit req for rsma suid:%"PRIu64", uid:%" PRIu64 " level %" PRIi8 " failed since %s",
|
||||
SMA_VID(pSma), suid, output->info.groupId, pItem->level, terrstr());
|
||||
goto _err;
|
||||
}
|
||||
|
||||
smaDebug("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " ver %" PRIi64 " len %" PRIu32,
|
||||
SMA_VID(pSma), suid, pItem->level, output->info.version, htonl(pReq->header.contLen));
|
||||
smaDebug("vgId:%d, process submit req for rsma suid:%" PRIu64 ",uid:%"PRIu64", level %" PRIi8 " ver %" PRIi64 " len %" PRIu32,
|
||||
SMA_VID(pSma), suid, output->info.groupId, pItem->level, output->info.version, htonl(pReq->header.contLen));
|
||||
|
||||
taosMemoryFreeClear(pReq);
|
||||
}
|
||||
|
|
|
@ -97,10 +97,9 @@ static void saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pRea
|
|||
}
|
||||
}
|
||||
|
||||
int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t numOfCols, uint64_t suid,
|
||||
void** pReader) {
|
||||
int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList, int32_t numOfTables, int32_t numOfCols,
|
||||
uint64_t suid, void** pReader) {
|
||||
*pReader = NULL;
|
||||
|
||||
SCacheRowsReader* p = taosMemoryCalloc(1, sizeof(SCacheRowsReader));
|
||||
if (p == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -111,14 +110,15 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList
|
|||
p->numOfCols = numOfCols;
|
||||
p->suid = suid;
|
||||
|
||||
if (taosArrayGetSize(pTableIdList) == 0) {
|
||||
if (numOfTables == 0) {
|
||||
*pReader = p;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pTableIdList, 0);
|
||||
STableKeyInfo* pKeyInfo = &((STableKeyInfo*)pTableIdList)[0];
|
||||
p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, pKeyInfo->uid, -1, 1);
|
||||
p->pTableList = pTableIdList;
|
||||
p->numOfTables = numOfTables;
|
||||
|
||||
p->transferBuf = taosMemoryCalloc(p->pSchema->numOfCols, POINTER_BYTES);
|
||||
if (p->transferBuf == NULL) {
|
||||
|
@ -205,7 +205,6 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
SLRUCache* lruCache = pr->pVnode->pTsdb->lruCache;
|
||||
LRUHandle* h = NULL;
|
||||
SArray* pRow = NULL;
|
||||
size_t numOfTables = taosArrayGetSize(pr->pTableList);
|
||||
bool hasRes = false;
|
||||
SArray* pLastCols = NULL;
|
||||
|
||||
|
@ -243,8 +242,8 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
|
||||
// retrieve the only one last row of all tables in the uid list.
|
||||
if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_SINGLE)) {
|
||||
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i);
|
||||
for (int32_t i = 0; i < pr->numOfTables; ++i) {
|
||||
STableKeyInfo* pKeyInfo = &pr->pTableList[i];
|
||||
|
||||
code = doExtractCacheRow(pr, lruCache, pKeyInfo->uid, &pRow, &h);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -308,8 +307,8 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
}
|
||||
|
||||
} else if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_ALL)) {
|
||||
for (int32_t i = pr->tableIndex; i < numOfTables; ++i) {
|
||||
STableKeyInfo* pKeyInfo = (STableKeyInfo*)taosArrayGet(pr->pTableList, i);
|
||||
for (int32_t i = pr->tableIndex; i < pr->numOfTables; ++i) {
|
||||
STableKeyInfo* pKeyInfo = &pr->pTableList[i];
|
||||
code = doExtractCacheRow(pr, lruCache, pKeyInfo->uid, &pRow, &h);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
|
@ -334,7 +333,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
code = TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
_end:
|
||||
_end:
|
||||
tsdbDataFReaderClose(&pr->pDataFReaderLast);
|
||||
tsdbDataFReaderClose(&pr->pDataFReader);
|
||||
|
||||
|
|
|
@ -270,24 +270,27 @@ static void resetDataBlockScanInfo(SHashObj* pTableMap, int64_t ts) {
|
|||
}
|
||||
}
|
||||
|
||||
static void clearBlockScanInfo(STableBlockScanInfo* p) {
|
||||
p->iterInit = false;
|
||||
p->iiter.hasVal = false;
|
||||
|
||||
if (p->iter.iter != NULL) {
|
||||
p->iter.iter = tsdbTbDataIterDestroy(p->iter.iter);
|
||||
}
|
||||
|
||||
if (p->iiter.iter != NULL) {
|
||||
p->iiter.iter = tsdbTbDataIterDestroy(p->iiter.iter);
|
||||
}
|
||||
|
||||
p->delSkyline = taosArrayDestroy(p->delSkyline);
|
||||
p->pBlockList = taosArrayDestroy(p->pBlockList);
|
||||
tMapDataClear(&p->mapData);
|
||||
}
|
||||
|
||||
static void destroyBlockScanInfo(SHashObj* pTableMap) {
|
||||
STableBlockScanInfo* p = NULL;
|
||||
|
||||
while ((p = taosHashIterate(pTableMap, p)) != NULL) {
|
||||
p->iterInit = false;
|
||||
p->iiter.hasVal = false;
|
||||
|
||||
if (p->iter.iter != NULL) {
|
||||
p->iter.iter = tsdbTbDataIterDestroy(p->iter.iter);
|
||||
}
|
||||
|
||||
if (p->iiter.iter != NULL) {
|
||||
p->iiter.iter = tsdbTbDataIterDestroy(p->iiter.iter);
|
||||
}
|
||||
|
||||
p->delSkyline = taosArrayDestroy(p->delSkyline);
|
||||
p->pBlockList = taosArrayDestroy(p->pBlockList);
|
||||
tMapDataClear(&p->mapData);
|
||||
clearBlockScanInfo(p);
|
||||
}
|
||||
|
||||
taosHashCleanup(pTableMap);
|
||||
|
@ -951,7 +954,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn
|
|||
|
||||
int32_t unDumpedRows = asc ? pBlock->nRow - pDumpInfo->rowIndex : pDumpInfo->rowIndex + 1;
|
||||
tsdbDebug("%p copy file block to sdatablock, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
|
||||
", rows:%d, remain:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s",
|
||||
", rows:%d, remain:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s",
|
||||
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, remain,
|
||||
unDumpedRows, pBlock->minVer, pBlock->maxVer, elapsedTime, pReader->idStr);
|
||||
|
||||
|
@ -978,7 +981,7 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
|
|||
code = tsdbReadDataBlock(pReader->pFileReader, pBlock, pBlockData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tsdbError("%p error occurs in loading file block, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64
|
||||
", rows:%d, code:%s %s",
|
||||
", rows:%d, code:%s %s",
|
||||
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, pBlock->nRow,
|
||||
tstrerror(code), pReader->idStr);
|
||||
return code;
|
||||
|
@ -987,7 +990,7 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
|
|||
double elapsedTime = (taosGetTimestampUs() - st) / 1000.0;
|
||||
|
||||
tsdbDebug("%p load file block into buffer, global index:%d, index in table block list:%d, brange:%" PRId64 "-%" PRId64
|
||||
", rows:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s",
|
||||
", rows:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s",
|
||||
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, pBlock->nRow,
|
||||
pBlock->minVer, pBlock->maxVer, elapsedTime, pReader->idStr);
|
||||
|
||||
|
@ -1438,7 +1441,7 @@ static int32_t buildDataBlockFromBuf(STsdbReader* pReader, STableBlockScanInfo*
|
|||
|
||||
double elapsedTime = (taosGetTimestampUs() - st) / 1000.0;
|
||||
tsdbDebug("%p build data block from cache completed, elapsed time:%.2f ms, numOfRows:%d, brange:%" PRId64
|
||||
" - %" PRId64 " %s",
|
||||
" - %" PRId64 " %s",
|
||||
pReader, elapsedTime, pBlock->info.rows, pBlock->info.window.skey, pBlock->info.window.ekey,
|
||||
pReader->idStr);
|
||||
|
||||
|
@ -1864,7 +1867,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == key) {
|
||||
init = true;
|
||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||
int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -1878,7 +1881,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
tRowMerge(&merge, &fRow1);
|
||||
} else {
|
||||
init = true;
|
||||
int32_t code = tRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||
code = tRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2304,7 +2307,7 @@ _end:
|
|||
|
||||
if (pResBlock->info.rows > 0) {
|
||||
tsdbDebug("%p uid:%" PRIu64 ", composed data block created, brange:%" PRIu64 "-%" PRIu64
|
||||
" rows:%d, elapsed time:%.2f ms %s",
|
||||
" rows:%d, elapsed time:%.2f ms %s",
|
||||
pReader, pResBlock->info.uid, pResBlock->info.window.skey, pResBlock->info.window.ekey,
|
||||
pResBlock->info.rows, el, pReader->idStr);
|
||||
}
|
||||
|
@ -2811,8 +2814,8 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* ret
|
|||
int8_t precision = pVnode->config.tsdbCfg.precision;
|
||||
int64_t now = taosGetTimestamp(precision);
|
||||
int64_t offset = tsQueryRsmaTolerance * ((precision == TSDB_TIME_PRECISION_MILLI) ? 1L
|
||||
: (precision == TSDB_TIME_PRECISION_MICRO) ? 1000L
|
||||
: 1000000L);
|
||||
: (precision == TSDB_TIME_PRECISION_MICRO) ? 1000L
|
||||
: 1000000L);
|
||||
|
||||
for (int8_t i = 0; i < TSDB_RETENTION_MAX; ++i) {
|
||||
SRetention* pRetention = retentions + level;
|
||||
|
@ -3452,13 +3455,23 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// todo refactor, use arraylist instead
|
||||
int32_t tsdbSetTableId(STsdbReader* pReader, int64_t uid) {
|
||||
// TODO refactor: with createDataBlockScanInfo
|
||||
int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t num) {
|
||||
ASSERT(pReader != NULL);
|
||||
|
||||
STableBlockScanInfo* p = NULL;
|
||||
while ((p = taosHashIterate(pReader->status.pTableMap, p)) != NULL) {
|
||||
clearBlockScanInfo(p);
|
||||
}
|
||||
|
||||
taosHashClear(pReader->status.pTableMap);
|
||||
|
||||
STableBlockScanInfo info = {.lastKey = 0, .uid = uid};
|
||||
taosHashPut(pReader->status.pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info));
|
||||
STableKeyInfo* pList = (STableKeyInfo*) pTableList;
|
||||
for(int32_t i = 0; i < num; ++i) {
|
||||
STableBlockScanInfo info = {.lastKey = 0, .uid = pList[i].uid};
|
||||
taosHashPut(pReader->status.pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info));
|
||||
}
|
||||
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -3483,6 +3496,7 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) {
|
|||
|
||||
initFilesetIterator(&pReader->status.fileIter, pReader->pReadSnap->fs.aDFileSet, pReader);
|
||||
resetDataBlockIterator(&pReader->status.blockIter, pReader->order);
|
||||
// resetDataBlockScanInfo(pReader->status.pTableMap, pReader->window.skey);
|
||||
|
||||
// no data in files, let's try buffer in memory
|
||||
if (pReader->status.fileIter.numOfFiles == 0) {
|
||||
|
@ -3494,8 +3508,8 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) {
|
|||
}
|
||||
|
||||
// ====================================== EXPOSED APIs ======================================
|
||||
int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTableList, STsdbReader** ppReader,
|
||||
const char* idstr) {
|
||||
int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, void* pTableList, int32_t numOfTables,
|
||||
STsdbReader** ppReader, const char* idstr) {
|
||||
STimeWindow window = pCond->twindows;
|
||||
if (pCond->type == TIMEWINDOW_RANGE_EXTERNAL) {
|
||||
pCond->twindows.skey += 1;
|
||||
|
@ -3554,8 +3568,8 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl
|
|||
if (pReader->pSchema == NULL) {
|
||||
tsdbError("failed to get table schema, suid:%" PRIu64 ", ver:-1, %s", pReader->suid, pReader->idStr);
|
||||
}
|
||||
} else if (taosArrayGetSize(pTableList) > 0) {
|
||||
STableKeyInfo* pKey = taosArrayGet(pTableList, 0);
|
||||
} else if (numOfTables > 0) {
|
||||
STableKeyInfo* pKey = pTableList;
|
||||
pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, pKey->uid, -1, 1);
|
||||
if (pReader->pSchema == NULL) {
|
||||
tsdbError("failed to get table schema, uid:%" PRIu64 ", ver:-1, %s", pKey->uid, pReader->idStr);
|
||||
|
@ -3564,8 +3578,7 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl
|
|||
|
||||
STsdbReader* p = pReader->innerReader[0] != NULL ? pReader->innerReader[0] : pReader;
|
||||
|
||||
int32_t numOfTables = taosArrayGetSize(pTableList);
|
||||
pReader->status.pTableMap = createDataBlockScanInfo(p, pTableList->pData, numOfTables);
|
||||
pReader->status.pTableMap = createDataBlockScanInfo(p, pTableList, numOfTables);
|
||||
if (pReader->status.pTableMap == NULL) {
|
||||
tsdbReaderClose(pReader);
|
||||
*ppReader = NULL;
|
||||
|
@ -3606,23 +3619,13 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl
|
|||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = doOpenReaderImpl(pNextReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = doOpenReaderImpl(pReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tsdbDebug("%p total numOfTable:%d in this query %s", pReader, numOfTables, pReader->idStr);
|
||||
return code;
|
||||
|
||||
_err:
|
||||
_err:
|
||||
tsdbError("failed to create data reader, code:%s %s", tstrerror(code), idstr);
|
||||
return code;
|
||||
}
|
||||
|
@ -3746,15 +3749,21 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
|||
|
||||
if (pReader->innerReader[0] != NULL && pReader->step == 0) {
|
||||
bool ret = doTsdbNextDataBlock(pReader->innerReader[0]);
|
||||
resetDataBlockScanInfo(pReader->innerReader[0]->status.pTableMap, pReader->innerReader[0]->window.ekey);
|
||||
pReader->step = EXTERNAL_ROWS_PREV;
|
||||
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (pReader->step == EXTERNAL_ROWS_PREV) {
|
||||
// prepare for the main scan
|
||||
int32_t code = doOpenReaderImpl(pReader);
|
||||
resetDataBlockScanInfo(pReader->status.pTableMap, pReader->innerReader[0]->window.ekey);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pReader->step = EXTERNAL_ROWS_MAIN;
|
||||
}
|
||||
|
||||
|
@ -3764,7 +3773,13 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
|||
}
|
||||
|
||||
if (pReader->innerReader[1] != NULL && pReader->step == EXTERNAL_ROWS_MAIN) {
|
||||
// prepare for the next row scan
|
||||
int32_t code = doOpenReaderImpl(pReader->innerReader[1]);
|
||||
resetDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->window.ekey);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
bool ret1 = doTsdbNextDataBlock(pReader->innerReader[1]);
|
||||
pReader->step = EXTERNAL_ROWS_NEXT;
|
||||
if (ret1) {
|
||||
|
@ -3775,7 +3790,7 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool tsdbTableNextDataBlock(STsdbReader* pReader, int64_t uid) {
|
||||
bool tsdbTableNextDataBlock(STsdbReader* pReader, uint64_t uid) {
|
||||
STableBlockScanInfo* pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &uid, sizeof(uid));
|
||||
if (pBlockScanInfo == NULL) { // no data block for the table of given uid
|
||||
return false;
|
||||
|
@ -3964,7 +3979,7 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
|
|||
}
|
||||
|
||||
tsdbDebug("%p reset reader, suid:%" PRIu64 ", numOfTables:%d, skey:%" PRId64 ", query range:%" PRId64 " - %" PRId64
|
||||
" in query %s",
|
||||
" in query %s",
|
||||
pReader, pReader->suid, numOfTables, pCond->twindows.skey, pReader->window.skey, pReader->window.ekey,
|
||||
pReader->idStr);
|
||||
|
||||
|
@ -4155,7 +4170,7 @@ int32_t tsdbTakeReadSnap(STsdb* pTsdb, STsdbReadSnap** ppSnap, const char* idStr
|
|||
}
|
||||
|
||||
tsdbTrace("vgId:%d, take read snapshot, %s", TD_VID(pTsdb->pVnode), idStr);
|
||||
_exit:
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -4174,4 +4189,3 @@ void tsdbUntakeReadSnap(STsdb* pTsdb, STsdbReadSnap* pSnap, const char* idStr) {
|
|||
}
|
||||
tsdbTrace("vgId:%d, untake read snapshot, %s", TD_VID(pTsdb->pVnode), idStr);
|
||||
}
|
||||
bool tsdbIsAscendingOrder(STsdbReader* pReader) { return ASCENDING_TRAVERSE(pReader->order); }
|
||||
|
|
|
@ -289,7 +289,8 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
|||
break;
|
||||
}
|
||||
|
||||
vTrace("vgId:%d, process %s request success, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version);
|
||||
vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code,
|
||||
version);
|
||||
|
||||
walApplyVer(pVnode->pWal, version);
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
int32_t code = 0;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
|
||||
if (!syncEnvIsStart()) {
|
||||
if (!syncIsInit()) {
|
||||
vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId, pMsg);
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return -1;
|
||||
|
@ -277,7 +277,7 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
int32_t code = 0;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
|
||||
if (!syncEnvIsStart()) {
|
||||
if (!syncIsInit()) {
|
||||
vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId, pMsg);
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return -1;
|
||||
|
@ -301,13 +301,13 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
||||
ASSERT(pSyncMsg != NULL);
|
||||
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
||||
code = syncNodeOnPing(pSyncNode, pSyncMsg);
|
||||
syncPingDestroy(pSyncMsg);
|
||||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
||||
ASSERT(pSyncMsg != NULL);
|
||||
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
||||
code = syncNodeOnPingReply(pSyncNode, pSyncMsg);
|
||||
syncPingReplyDestroy(pSyncMsg);
|
||||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||
|
@ -350,6 +350,11 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg);
|
||||
syncSnapshotRspDestroy(pSyncMsg);
|
||||
|
||||
} else if (pMsg->msgType == TDMT_SYNC_LOCAL_CMD) {
|
||||
SyncLocalCmd *pSyncMsg = syncLocalCmdFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnLocalCmd(pSyncNode, pSyncMsg);
|
||||
syncLocalCmdDestroy(pSyncMsg);
|
||||
|
||||
} else {
|
||||
vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType);
|
||||
code = -1;
|
||||
|
@ -365,7 +370,13 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
}
|
||||
|
||||
static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
if (msgcb == NULL) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (msgcb == NULL || msgcb->putToQueueFp == NULL) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -378,7 +389,13 @@ static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
if (msgcb == NULL) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (msgcb == NULL || msgcb->putToQueueFp == NULL) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1114,6 +1114,7 @@ int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn,
|
|||
CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup, exists));
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, SMetaData* pRsp) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
|
@ -1176,6 +1177,7 @@ _return:
|
|||
|
||||
CTG_API_LEAVE(code);
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, catalogCallback fp,
|
||||
void* param, int64_t* jobId) {
|
||||
|
|
|
@ -63,6 +63,7 @@ enum {
|
|||
CTGT_RSP_QNODELIST,
|
||||
CTGT_RSP_UDF,
|
||||
CTGT_RSP_SVRVER,
|
||||
CTGT_RSP_DNODElIST,
|
||||
CTGT_RSP_TBMETA_NOT_EXIST,
|
||||
};
|
||||
|
||||
|
@ -702,6 +703,30 @@ void ctgTestRspSvrVer(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRs
|
|||
pRsp->pCont = pReq;
|
||||
}
|
||||
|
||||
void ctgTestRspDndeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
SDnodeListRsp dRsp = {0};
|
||||
dRsp.dnodeList = taosArrayInit(1, sizeof(SEpSet));
|
||||
SEpSet epSet = {0};
|
||||
epSet.numOfEps = 1;
|
||||
tstrncpy(epSet.eps[0].fqdn, "localhost", TSDB_FQDN_LEN);
|
||||
epSet.eps[0].port = 6030;
|
||||
|
||||
(void)taosArrayPush(dRsp.dnodeList, &epSet);
|
||||
|
||||
int32_t rspLen = tSerializeSDnodeListRsp(NULL, 0, &dRsp);
|
||||
void *pReq = rpcMallocCont(rspLen);
|
||||
tSerializeSDnodeListRsp(pReq, rspLen, &dRsp);
|
||||
|
||||
pRsp->code = 0;
|
||||
pRsp->contLen = rspLen;
|
||||
pRsp->pCont = pReq;
|
||||
|
||||
tFreeSDnodeListRsp(&dRsp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
switch (pMsg->msgType) {
|
||||
|
@ -727,6 +752,9 @@ void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp)
|
|||
case TDMT_MND_SERVER_VERSION:
|
||||
ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_MND_DNODE_LIST:
|
||||
ctgTestRspDndeList(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -779,6 +807,9 @@ void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp
|
|||
case CTGT_RSP_SVRVER:
|
||||
ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case CTGT_RSP_DNODElIST:
|
||||
ctgTestRspDndeList(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
default:
|
||||
ctgTestRspAuto(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
|
@ -2948,6 +2979,69 @@ TEST(apiTest, catalogGetServerVersion_test) {
|
|||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(apiTest, catalogUpdateTableIndex_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_SVRVER;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
STableIndexRsp rsp = {0};
|
||||
strcpy(rsp.dbFName, ctgTestDbname);
|
||||
strcpy(rsp.tbName, ctgTestSTablename);
|
||||
rsp.suid = ctgTestSuid;
|
||||
rsp.version = 1;
|
||||
code = catalogUpdateTableIndex(pCtg, &rsp);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
TEST(apiTest, catalogGetDnodeList_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
||||
memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
|
||||
ctgTestRspIdx = 0;
|
||||
ctgTestRspFunc[0] = CTGT_RSP_DNODElIST;
|
||||
|
||||
ctgTestSetRspByIdx();
|
||||
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
int32_t code = catalogInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SArray* pList = NULL;
|
||||
code = catalogGetDnodeList(pCtg, mockPointer, &pList);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(pList), 1);
|
||||
|
||||
taosArrayDestroy(pList);
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
#include "tpagedbuf.h"
|
||||
#include "tsimplehash.h"
|
||||
#include "vnode.h"
|
||||
#include "executor.h"
|
||||
|
||||
#define T_LONG_JMP(_obj, _c) \
|
||||
do { \
|
||||
ASSERT((_c) != -1); \
|
||||
longjmp((_obj), (_c)); \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#define SET_RES_WINDOW_KEY(_k, _ori, _len, _uid) \
|
||||
do { \
|
||||
|
@ -95,8 +96,24 @@ typedef struct SColMatchInfo {
|
|||
int32_t matchType; // determinate the source according to col id or slot id
|
||||
} SColMatchInfo;
|
||||
|
||||
typedef struct STableListInfo STableListInfo;
|
||||
struct SqlFunctionCtx;
|
||||
|
||||
int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle,
|
||||
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, const char* id);
|
||||
|
||||
STableListInfo* tableListCreate();
|
||||
void* tableListDestroy(STableListInfo* pTableListInfo);
|
||||
void tableListClear(STableListInfo* pTableListInfo);
|
||||
int32_t tableListGetOutputGroups(const STableListInfo* pTableList);
|
||||
bool oneTableForEachGroup(const STableListInfo* pTableList);
|
||||
uint64_t getTableGroupId(const STableListInfo* pTableList, uint64_t tableUid);
|
||||
int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid);
|
||||
int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalIndex, STableKeyInfo** pKeyInfo, int32_t* num);
|
||||
uint64_t tableListGetSize(const STableListInfo* pTableList);
|
||||
uint64_t tableListGetSuid(const STableListInfo* pTableList);
|
||||
STableKeyInfo* tableListGetInfo(const STableListInfo* pTableList, int32_t index);
|
||||
|
||||
size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
void initResultRowInfo(SResultRowInfo* pResultRowInfo);
|
||||
void closeResultRow(SResultRow* pResultRow);
|
||||
|
@ -109,6 +126,7 @@ static FORCE_INLINE SResultRow* getResultRowByPos(SDiskbasedBuf* pBuf, SResultRo
|
|||
if (forUpdate) {
|
||||
setBufPageDirty(bufPage, true);
|
||||
}
|
||||
|
||||
SResultRow* pRow = (SResultRow*)((char*)bufPage + pos->offset);
|
||||
return pRow;
|
||||
}
|
||||
|
@ -124,10 +142,7 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo);
|
|||
SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode);
|
||||
|
||||
EDealRes doTranslateTagExpr(SNode** pNode, void* pContext);
|
||||
int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, SNode* pTagIndexCond,
|
||||
STableListInfo* pListInfo);
|
||||
int32_t getGroupIdFromTagsVal(void* pMeta, uint64_t uid, SNodeList* pGroupNode, char* keyBuf, uint64_t* pGroupId);
|
||||
int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableListInfo* pTableListInfo);
|
||||
size_t getTableTagsBufLen(const SNodeList* pGroups);
|
||||
|
||||
SArray* createSortInfo(SNodeList* pNodeList);
|
||||
|
@ -150,9 +165,7 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi
|
|||
void cleanupQueryTableDataCond(SQueryTableDataCond* pCond);
|
||||
|
||||
int32_t convertFillType(int32_t mode);
|
||||
|
||||
int32_t resultrowComparAsc(const void* p1, const void* p2);
|
||||
|
||||
int32_t isQualifiedTable(STableKeyInfo* info, SNode* pTagCond, void* metaHandle, bool* pQualified);
|
||||
|
||||
#endif // TDENGINE_QUERYUTIL_H
|
||||
|
|
|
@ -179,7 +179,7 @@ typedef struct SExecTaskInfo {
|
|||
int64_t version; // used for stream to record wal version
|
||||
SStreamTaskInfo streamInfo;
|
||||
SSchemaInfo schemaInfo;
|
||||
STableListInfo tableqinfoList; // this is a table list
|
||||
STableListInfo* pTableInfoList; // this is a table list
|
||||
const char* sql; // query sql string
|
||||
jmp_buf env; // jump to this position when error happens.
|
||||
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||
|
@ -552,7 +552,7 @@ typedef struct SSysTableScanInfo {
|
|||
|
||||
typedef struct SBlockDistInfo {
|
||||
SSDataBlock* pResBlock;
|
||||
void* pHandle;
|
||||
STsdbReader* pHandle;
|
||||
SReadHandle readHandle;
|
||||
uint64_t uid; // table uid
|
||||
} SBlockDistInfo;
|
||||
|
@ -967,8 +967,8 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
|||
SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPhysiNode* pSessionNode,
|
||||
SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid,
|
||||
SBlockDistScanPhysiNode* pBlockScanNode, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanPhysiNode* pBlockScanNode,
|
||||
SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SNode* pTagCond,
|
||||
SExecTaskInfo* pTaskInfo);
|
||||
|
@ -1062,10 +1062,6 @@ uint64_t calGroupIdByData(SPartitionBySupporter* pParSup, SExprSupp* pExprSup, S
|
|||
int32_t finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
|
||||
SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle,
|
||||
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond,
|
||||
const char* idstr);
|
||||
|
||||
SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSortPhysiNode* pSortPhyNode,
|
||||
SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, STableListInfo* pTableListInfo,
|
||||
|
@ -1074,7 +1070,6 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
|||
void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_t tsColIndex);
|
||||
|
||||
bool groupbyTbname(SNodeList* pGroupList);
|
||||
int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* groupKey);
|
||||
void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
int32_t buildDataBlockFromGroupRes(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock, SExprSupp* pSup,
|
||||
SGroupResInfo* pGroupResInfo);
|
||||
|
|
|
@ -48,6 +48,10 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
int32_t numOfCols = 0;
|
||||
code =
|
||||
extractColMatchInfo(pScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
removeRedundantTsCol(pScanNode, &pInfo->matchInfo);
|
||||
|
||||
code = extractCacheScanSlotId(pInfo->matchInfo.pList, pTaskInfo, &pInfo->pSlotIds);
|
||||
|
@ -55,18 +59,23 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
goto _error;
|
||||
}
|
||||
|
||||
STableListInfo* pTableList = &pTaskInfo->tableqinfoList;
|
||||
STableListInfo* pTableList = pTaskInfo->pTableInfoList;
|
||||
|
||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||
blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||
pInfo->pUidList = taosArrayInit(4, sizeof(int64_t));
|
||||
|
||||
// partition by tbname
|
||||
if (taosArrayGetSize(pTableList->pGroupList) == taosArrayGetSize(pTableList->pTableList)) {
|
||||
// partition by tbname, todo opt perf
|
||||
if (oneTableForEachGroup(pTableList) || (tableListGetSize(pTableList) == 1)) {
|
||||
pInfo->retrieveType =
|
||||
CACHESCAN_RETRIEVE_TYPE_ALL | (pScanNode->ignoreNull ? CACHESCAN_RETRIEVE_LAST : CACHESCAN_RETRIEVE_LAST_ROW);
|
||||
code = tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pTableList->pTableList,
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), pTableList->suid, &pInfo->pLastrowReader);
|
||||
|
||||
STableKeyInfo* pList = tableListGetInfo(pTableList, 0);
|
||||
|
||||
size_t num = tableListGetSize(pTableList);
|
||||
uint64_t suid = tableListGetSuid(pTableList);
|
||||
code = tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pList, num,
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), suid, &pInfo->pLastrowReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -98,7 +107,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
pOperator->cost.openCost = 0;
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
_error:
|
||||
pTaskInfo->code = code;
|
||||
destroyLastrowScanOperator(pInfo);
|
||||
taosMemoryFree(pOperator);
|
||||
|
@ -112,8 +121,10 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
|
||||
SLastrowScanInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
STableListInfo* pTableList = &pTaskInfo->tableqinfoList;
|
||||
int32_t size = taosArrayGetSize(pTableList->pTableList);
|
||||
STableListInfo* pTableList = pTaskInfo->pTableInfoList;
|
||||
|
||||
uint64_t suid = tableListGetSuid(pTableList);
|
||||
int32_t size = tableListGetSize(pTableList);
|
||||
if (size == 0) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
|
@ -167,16 +178,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pTableList->map != NULL) {
|
||||
int64_t* groupId = taosHashGet(pTableList->map, &pInfo->pRes->info.uid, sizeof(int64_t));
|
||||
if (groupId != NULL) {
|
||||
pInfo->pRes->info.groupId = *groupId;
|
||||
}
|
||||
} else {
|
||||
ASSERT(taosArrayGetSize(pTableList->pTableList) == 1);
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, 0);
|
||||
pInfo->pRes->info.groupId = pKeyInfo->groupId;
|
||||
}
|
||||
pInfo->pRes->info.groupId = getTableGroupId(pTableList, pInfo->pRes->info.uid);
|
||||
|
||||
pInfo->indexOfBufferedRes += 1;
|
||||
return pInfo->pRes;
|
||||
|
@ -185,18 +187,24 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
return NULL;
|
||||
}
|
||||
} else {
|
||||
size_t totalGroups = taosArrayGetSize(pTableList->pGroupList);
|
||||
size_t totalGroups = tableListGetOutputGroups(pTableList);
|
||||
|
||||
while (pInfo->currentGroupIndex < totalGroups) {
|
||||
SArray* pGroupTableList = taosArrayGetP(pTableList->pGroupList, pInfo->currentGroupIndex);
|
||||
STableKeyInfo* pList = NULL;
|
||||
int32_t num = 0;
|
||||
|
||||
tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pGroupTableList,
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), pTableList->suid, &pInfo->pLastrowReader);
|
||||
int32_t code = tableListGetGroupList(pTableList, pInfo->currentGroupIndex, &pList, &num);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pList, num,
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), suid, &pInfo->pLastrowReader);
|
||||
taosArrayClear(pInfo->pUidList);
|
||||
|
||||
int32_t code = tsdbRetrieveCacheRows(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pInfo->pUidList);
|
||||
code = tsdbRetrieveCacheRows(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pInfo->pUidList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, code);
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
pInfo->currentGroupIndex += 1;
|
||||
|
@ -206,7 +214,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
if (pInfo->pseudoExprSup.numOfExprs > 0) {
|
||||
SExprSupp* pSup = &pInfo->pseudoExprSup;
|
||||
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pGroupTableList, 0);
|
||||
STableKeyInfo* pKeyInfo = &((STableKeyInfo*)pTableList)[0];
|
||||
pInfo->pRes->info.groupId = pKeyInfo->groupId;
|
||||
|
||||
if (taosArrayGetSize(pInfo->pUidList) > 0) {
|
||||
|
|
|
@ -26,9 +26,31 @@
|
|||
#include "executorimpl.h"
|
||||
#include "tcompression.h"
|
||||
|
||||
static int32_t removeInvalidTable(SArray* list, SHashObj* tags);
|
||||
// If the numOfOutputGroups is 1, the data blocks that belongs to different groups will be provided randomly
|
||||
// The numOfOutputGroups is specified by physical plan. and will not be affect by numOfGroups
|
||||
struct STableListInfo {
|
||||
bool oneTableForEachGroup;
|
||||
int32_t numOfOuputGroups; // the data block will be generated one by one
|
||||
int32_t* groupOffset; // keep the offset value for each group in the tableList
|
||||
SArray* pTableList;
|
||||
SHashObj* map; // speedup acquire the tableQueryInfo by table uid
|
||||
uint64_t suid;
|
||||
};
|
||||
|
||||
typedef struct tagFilterAssist {
|
||||
SHashObj* colHash;
|
||||
int32_t index;
|
||||
SArray* cInfoList;
|
||||
} tagFilterAssist;
|
||||
|
||||
static int32_t removeInvalidTable(SArray* uids, SHashObj* tags);
|
||||
static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond, SHashObj* tags);
|
||||
static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond);
|
||||
static int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond,
|
||||
SNode* pTagIndexCond, STableListInfo* pListInfo);
|
||||
|
||||
static int64_t getLimit(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->limit; }
|
||||
static int64_t getOffset(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->offset; }
|
||||
|
||||
void initResultRowInfo(SResultRowInfo* pResultRowInfo) {
|
||||
pResultRowInfo->size = 0;
|
||||
|
@ -301,12 +323,6 @@ int32_t isQualifiedTable(STableKeyInfo* info, SNode* pTagCond, void* metaHandle,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
typedef struct tagFilterAssist {
|
||||
SHashObj* colHash;
|
||||
int32_t index;
|
||||
SArray* cInfoList;
|
||||
} tagFilterAssist;
|
||||
|
||||
static EDealRes getColumn(SNode** pNode, void* pContext) {
|
||||
SColumnNode* pSColumnNode = NULL;
|
||||
if (QUERY_NODE_COLUMN == nodeType((*pNode))) {
|
||||
|
@ -482,6 +498,7 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pResBlock->info.rows = rows;
|
||||
|
||||
// int64_t st1 = taosGetTimestampUs();
|
||||
|
@ -544,6 +561,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
||||
ctx.index = 0;
|
||||
ctx.cInfoList = taosArrayInit(4, sizeof(SColumnInfo));
|
||||
if (ctx.cInfoList == NULL) {
|
||||
|
@ -606,6 +624,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis
|
|||
} else {
|
||||
void* tag = taosHashGet(tags, uid, sizeof(int64_t));
|
||||
ASSERT(tag);
|
||||
|
||||
STagVal tagVal = {0};
|
||||
tagVal.cid = pColInfo->info.colId;
|
||||
const char* p = metaGetTableTagVal(tag, pColInfo->info.type, &tagVal);
|
||||
|
@ -636,6 +655,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pResBlock->info.rows = rows;
|
||||
|
||||
// int64_t st1 = taosGetTimestampUs();
|
||||
|
@ -661,10 +681,12 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (nodeType(pNode) == QUERY_NODE_COLUMN) {
|
||||
SColumnNode* pSColumnNode = (SColumnNode*)pNode;
|
||||
SColumnInfoData* pColInfo = (SColumnInfoData*)taosArrayGet(pResBlock->pDataBlock, pSColumnNode->slotId);
|
||||
|
@ -674,10 +696,12 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis
|
|||
} else {
|
||||
code = scalarCalculate(pNode, pBlockList, &output);
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
releaseColInfoData(output.columnData);
|
||||
goto end;
|
||||
}
|
||||
|
||||
taosArrayPush(groupData, &output.columnData);
|
||||
}
|
||||
|
||||
|
@ -696,6 +720,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows; i++) {
|
||||
STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i);
|
||||
|
||||
|
@ -733,7 +758,6 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis
|
|||
|
||||
int32_t len = (int32_t)(pStart - (char*)keyBuf);
|
||||
info->groupId = calcGroupId(keyBuf, len);
|
||||
taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), &info->groupId, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
// int64_t st2 = taosGetTimestampUs();
|
||||
|
@ -759,6 +783,7 @@ static int tableUidCompare(const void* a, const void* b) {
|
|||
}
|
||||
return u1 < u2 ? -1 : 1;
|
||||
}
|
||||
|
||||
static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* cond, SHashObj* tags) {
|
||||
int32_t ret = -1;
|
||||
if (nodeType(cond) == QUERY_NODE_OPERATOR) {
|
||||
|
@ -813,42 +838,91 @@ static int32_t removeInvalidTable(SArray* uids, SHashObj* tags) {
|
|||
taosArrayPush(validUid, uid);
|
||||
}
|
||||
}
|
||||
|
||||
taosArraySwap(uids, validUid);
|
||||
taosArrayDestroy(validUid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t nameComparFn(const void* p1, const void* p2) {
|
||||
const char* pName1 = *(const char**)p1;
|
||||
const char* pName2 = *(const char**)p2;
|
||||
|
||||
int32_t ret = strcmp(pName1, pName2);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return (ret > 0) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
static SArray* getTableNameList(const SNodeListNode* pList) {
|
||||
int32_t len = LIST_LENGTH(pList->pNodeList);
|
||||
SListCell* cell = pList->pNodeList->pHead;
|
||||
|
||||
SArray* pTbList = taosArrayInit(len, POINTER_BYTES);
|
||||
for (int i = 0; i < pList->pNodeList->length; i++) {
|
||||
SValueNode* valueNode = (SValueNode*)cell->pNode;
|
||||
if (!IS_VAR_DATA_TYPE(valueNode->node.resType.type)) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
taosArrayDestroy(pTbList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* name = varDataVal(valueNode->datum.p);
|
||||
taosArrayPush(pTbList, &name);
|
||||
cell = cell->pNext;
|
||||
}
|
||||
|
||||
size_t numOfTables = taosArrayGetSize(pTbList);
|
||||
|
||||
// order the name
|
||||
taosArraySort(pTbList, nameComparFn);
|
||||
|
||||
// remove the duplicates
|
||||
SArray* pNewList = taosArrayInit(taosArrayGetSize(pTbList), sizeof(void*));
|
||||
taosArrayPush(pNewList, taosArrayGet(pTbList, 0));
|
||||
|
||||
for (int32_t i = 1; i < numOfTables; ++i) {
|
||||
char** name = taosArrayGetLast(pNewList);
|
||||
char** nameInOldList = taosArrayGet(pTbList, i);
|
||||
if (strcmp(*name, *nameInOldList) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
taosArrayPush(pNewList, nameInOldList);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pTbList);
|
||||
return pNewList;
|
||||
}
|
||||
|
||||
static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond) {
|
||||
if (nodeType(pTagCond) != QUERY_NODE_OPERATOR) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SOperatorNode* pNode = (SOperatorNode*)pTagCond;
|
||||
if (pNode->opType != OP_TYPE_IN) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((pNode->pLeft != NULL && nodeType(pNode->pLeft) == QUERY_NODE_COLUMN &&
|
||||
((SColumnNode*)pNode->pLeft)->colType == COLUMN_TYPE_TBNAME) &&
|
||||
(pNode->pRight != NULL && nodeType(pNode->pRight) == QUERY_NODE_NODE_LIST)) {
|
||||
SNodeListNode* pList = (SNodeListNode*)pNode->pRight;
|
||||
|
||||
int32_t len = LIST_LENGTH(pList->pNodeList);
|
||||
if (len <= 0) return -1;
|
||||
|
||||
SListCell* cell = pList->pNodeList->pHead;
|
||||
|
||||
SArray* pTbList = taosArrayInit(len, sizeof(void*));
|
||||
for (int i = 0; i < pList->pNodeList->length; i++) {
|
||||
SValueNode* valueNode = (SValueNode*)cell->pNode;
|
||||
if (!IS_VAR_DATA_TYPE(valueNode->node.resType.type)) {
|
||||
taosArrayDestroy(pTbList);
|
||||
return -1;
|
||||
}
|
||||
char* name = varDataVal(valueNode->datum.p);
|
||||
taosArrayPush(pTbList, &name);
|
||||
cell = cell->pNext;
|
||||
if (len <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < taosArrayGetSize(pTbList); i++) {
|
||||
char* name = taosArrayGetP(pTbList, i);
|
||||
SArray* pTbList = getTableNameList(pList);
|
||||
int32_t numOfTables = taosArrayGetSize(pTbList);
|
||||
|
||||
for (int i = 0; i < numOfTables; i++) {
|
||||
char* name = taosArrayGetP(pTbList, i);
|
||||
|
||||
uint64_t uid = 0;
|
||||
if (metaGetTableUidByName(metaHandle, name, &uid) == 0) {
|
||||
ETableType tbType = TSDB_TABLE_MAX;
|
||||
|
@ -863,20 +937,18 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray*
|
|||
terrno = 0;
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(pTbList);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, SNode* pTagIndexCond,
|
||||
STableListInfo* pListInfo) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
pListInfo->pTableList = taosArrayInit(8, sizeof(STableKeyInfo));
|
||||
if (pListInfo->pTableList == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
uint64_t tableUid = pScanNode->uid;
|
||||
pListInfo->suid = pScanNode->suid;
|
||||
SArray* res = taosArrayInit(8, sizeof(uint64_t));
|
||||
|
@ -936,24 +1008,17 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode,
|
|||
size_t numOfTables = taosArrayGetSize(res);
|
||||
for (int i = 0; i < numOfTables; i++) {
|
||||
STableKeyInfo info = {.uid = *(uint64_t*)taosArrayGet(res, i), .groupId = 0};
|
||||
void* p = taosArrayPush(pListInfo->pTableList, &info);
|
||||
|
||||
void* p = taosArrayPush(pListInfo->pTableList, &info);
|
||||
if (p == NULL) {
|
||||
taosArrayDestroy(res);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
qDebug("tagfilter get uid:%" PRId64 "", info.uid);
|
||||
qDebug("tagfilter get uid:%" PRIu64 "", info.uid);
|
||||
}
|
||||
|
||||
taosArrayDestroy(res);
|
||||
|
||||
pListInfo->pGroupList = taosArrayInit(4, POINTER_BYTES);
|
||||
if (pListInfo->pGroupList == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// put into list as default group, remove it if grouping sorting is required later
|
||||
taosArrayPush(pListInfo->pGroupList, &pListInfo->pTableList);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1068,7 +1133,7 @@ SArray* extractPartitionColInfo(SNodeList* pNodeList) {
|
|||
|
||||
int32_t extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols,
|
||||
int32_t type, SColMatchInfo* pMatchInfo) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
int32_t code = 0;
|
||||
|
||||
pMatchInfo->matchType = type;
|
||||
|
@ -1411,10 +1476,10 @@ void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray
|
|||
while (i < numOfSrcCols && j < taosArrayGetSize(pColMatchInfo)) {
|
||||
SColumnInfoData* p = taosArrayGet(pCols, i);
|
||||
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, j);
|
||||
/* if (!outputEveryColumn && pmInfo->reserved) {
|
||||
j++;
|
||||
continue;
|
||||
}*/
|
||||
/* if (!outputEveryColumn && pmInfo->reserved) {
|
||||
j++;
|
||||
continue;
|
||||
}*/
|
||||
|
||||
if (p->info.colId == pmInfo->colId) {
|
||||
SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, pmInfo->dstSlotId);
|
||||
|
@ -1592,9 +1657,6 @@ bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo) {
|
|||
pLimitInfo->slimit.offset != -1);
|
||||
}
|
||||
|
||||
static int64_t getLimit(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->limit; }
|
||||
static int64_t getOffset(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->offset; }
|
||||
|
||||
void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLimitInfo) {
|
||||
SLimit limit = {.limit = getLimit(pLimit), .offset = getOffset(pLimit)};
|
||||
SLimit slimit = {.limit = getLimit(pSLimit), .offset = getOffset(pSLimit)};
|
||||
|
@ -1604,3 +1666,253 @@ void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLimit
|
|||
pLimitInfo->remainOffset = limit.offset;
|
||||
pLimitInfo->remainGroupOffset = slimit.offset;
|
||||
}
|
||||
|
||||
uint64_t tableListGetSize(const STableListInfo* pTableList) {
|
||||
ASSERT(taosArrayGetSize(pTableList->pTableList) == taosHashGetSize(pTableList->map));
|
||||
return taosArrayGetSize(pTableList->pTableList);
|
||||
}
|
||||
|
||||
uint64_t tableListGetSuid(const STableListInfo* pTableList) {
|
||||
return pTableList->suid;
|
||||
}
|
||||
|
||||
STableKeyInfo* tableListGetInfo(const STableListInfo* pTableList, int32_t index) {
|
||||
if (taosArrayGetSize(pTableList->pTableList) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return taosArrayGet(pTableList->pTableList, index);
|
||||
}
|
||||
|
||||
uint64_t getTableGroupId(const STableListInfo* pTableList, uint64_t tableUid) {
|
||||
int32_t* slot = taosHashGet(pTableList->map, &tableUid, sizeof(tableUid));
|
||||
ASSERT(pTableList->map != NULL && slot != NULL);
|
||||
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, *slot);
|
||||
ASSERT(pKeyInfo->uid == tableUid);
|
||||
|
||||
return pKeyInfo->groupId;
|
||||
}
|
||||
|
||||
// TODO handle the group offset info, fix it, the rule of group output will be broken by this function
|
||||
int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid) {
|
||||
if (pTableList->map == NULL) {
|
||||
ASSERT(taosArrayGetSize(pTableList->pTableList) == 0);
|
||||
pTableList->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
}
|
||||
|
||||
STableKeyInfo keyInfo = {.uid = uid, .groupId = gid};
|
||||
taosArrayPush(pTableList->pTableList, &keyInfo);
|
||||
|
||||
int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1;
|
||||
taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot));
|
||||
|
||||
qDebug("uid:%" PRIu64 ", groupId:%" PRIu64 " added into table list, slot:%d, total:%d", uid, gid, slot, slot + 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalGroupIndex, STableKeyInfo** pKeyInfo,
|
||||
int32_t* size) {
|
||||
int32_t total = tableListGetOutputGroups(pTableList);
|
||||
if (ordinalGroupIndex < 0 || ordinalGroupIndex >= total) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
// here handle two special cases:
|
||||
// 1. only one group exists, and 2. one table exists for each group.
|
||||
if (total == 1) {
|
||||
*size = tableListGetSize(pTableList);
|
||||
*pKeyInfo = (*size == 0)? NULL:taosArrayGet(pTableList->pTableList, 0);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else if (total == tableListGetSize(pTableList)) {
|
||||
*size = 1;
|
||||
*pKeyInfo = taosArrayGet(pTableList->pTableList, ordinalGroupIndex);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t offset = pTableList->groupOffset[ordinalGroupIndex];
|
||||
if (ordinalGroupIndex < total - 1) {
|
||||
*size = pTableList->groupOffset[offset + 1] - pTableList->groupOffset[offset];
|
||||
} else {
|
||||
*size = total - pTableList->groupOffset[offset] - 1;
|
||||
}
|
||||
|
||||
*pKeyInfo = taosArrayGet(pTableList->pTableList, offset);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tableListGetOutputGroups(const STableListInfo* pTableList) { return pTableList->numOfOuputGroups; }
|
||||
|
||||
bool oneTableForEachGroup(const STableListInfo* pTableList) { return pTableList->oneTableForEachGroup; }
|
||||
|
||||
STableListInfo* tableListCreate() {
|
||||
STableListInfo* pListInfo = taosMemoryCalloc(1, sizeof(STableListInfo));
|
||||
if (pListInfo == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pListInfo->pTableList = taosArrayInit(4, sizeof(STableKeyInfo));
|
||||
if (pListInfo->pTableList == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pListInfo->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
if (pListInfo->map == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pListInfo->numOfOuputGroups = 1;
|
||||
return pListInfo;
|
||||
|
||||
_error:
|
||||
tableListDestroy(pListInfo);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* tableListDestroy(STableListInfo* pTableListInfo) {
|
||||
if (pTableListInfo == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTableListInfo->pTableList = taosArrayDestroy(pTableListInfo->pTableList);
|
||||
taosMemoryFreeClear(pTableListInfo->groupOffset);
|
||||
|
||||
taosHashCleanup(pTableListInfo->map);
|
||||
|
||||
pTableListInfo->pTableList = NULL;
|
||||
pTableListInfo->map = NULL;
|
||||
taosMemoryFree(pTableListInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tableListClear(STableListInfo* pTableListInfo) {
|
||||
if (pTableListInfo == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosArrayClear(pTableListInfo->pTableList);
|
||||
taosHashClear(pTableListInfo->map);
|
||||
taosMemoryFree(pTableListInfo->groupOffset);
|
||||
pTableListInfo->numOfOuputGroups = 1;
|
||||
pTableListInfo->oneTableForEachGroup = false;
|
||||
}
|
||||
|
||||
static int32_t orderbyGroupIdComparFn(const void* p1, const void* p2) {
|
||||
STableKeyInfo* pInfo1 = (STableKeyInfo*) p1;
|
||||
STableKeyInfo* pInfo2 = (STableKeyInfo*) p2;
|
||||
|
||||
if (pInfo1->groupId == pInfo2->groupId) {
|
||||
return 0;
|
||||
} else {
|
||||
return pInfo1->groupId < pInfo2->groupId? -1:1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t sortTableGroup(STableListInfo* pTableListInfo) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
taosArraySort(pTableListInfo->pTableList, orderbyGroupIdComparFn);
|
||||
int32_t size = taosArrayGetSize(pTableListInfo->pTableList);
|
||||
|
||||
SArray* pList = taosArrayInit(4, sizeof(int32_t));
|
||||
|
||||
STableKeyInfo* pInfo = taosArrayGet(pTableListInfo->pTableList, 0);
|
||||
uint64_t gid = pInfo->groupId;
|
||||
|
||||
int32_t start = 0;
|
||||
taosArrayPush(pList, &start);
|
||||
|
||||
for(int32_t i = 1; i < size; ++i) {
|
||||
pInfo = taosArrayGet(pTableListInfo->pTableList, i);
|
||||
if (pInfo->groupId != gid) {
|
||||
taosArrayPush(pList, &i);
|
||||
gid = pInfo->groupId;
|
||||
}
|
||||
}
|
||||
|
||||
pTableListInfo->numOfOuputGroups = taosArrayGetSize(pList);
|
||||
pTableListInfo->groupOffset = taosMemoryMalloc(sizeof(int32_t) * pTableListInfo->numOfOuputGroups);
|
||||
memcpy(pTableListInfo->groupOffset, taosArrayGet(pList, 0), sizeof(int32_t) * pTableListInfo->numOfOuputGroups);
|
||||
taosArrayDestroy(pList);
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t buildGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* group, bool groupSort) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
ASSERT(pTableListInfo->map != NULL);
|
||||
|
||||
bool groupByTbname = groupbyTbname(group);
|
||||
size_t numOfTables = taosArrayGetSize(pTableListInfo->pTableList);
|
||||
if (group == NULL || groupByTbname) {
|
||||
for (int32_t i = 0; i < numOfTables; i++) {
|
||||
STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i);
|
||||
info->groupId = groupByTbname? info->uid:0;
|
||||
}
|
||||
|
||||
pTableListInfo->oneTableForEachGroup = groupByTbname;
|
||||
|
||||
if (groupSort && groupByTbname) {
|
||||
taosArraySort(pTableListInfo->pTableList, orderbyGroupIdComparFn);
|
||||
pTableListInfo->numOfOuputGroups = numOfTables;
|
||||
} else {
|
||||
pTableListInfo->numOfOuputGroups = 1;
|
||||
}
|
||||
} else {
|
||||
code = getColInfoResultForGroupby(pHandle->meta, group, pTableListInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (groupSort) {
|
||||
code = sortTableGroup(pTableListInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// add all table entry in the hash map
|
||||
size_t size = taosArrayGetSize(pTableListInfo->pTableList);
|
||||
for(int32_t i = 0; i < size; ++i) {
|
||||
STableKeyInfo* p = taosArrayGet(pTableListInfo->pTableList, i);
|
||||
taosHashPut(pTableListInfo->map, &p->uid, sizeof(uint64_t), &i, sizeof(int32_t));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle,
|
||||
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond,
|
||||
const char* idStr) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
if (pHandle == NULL) {
|
||||
qError("invalid handle, in creating operator tree, %s", idStr);
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
int32_t code = getTableList(pHandle->meta, pHandle->vnode, pScanNode, pTagCond, pTagIndexCond, pTableListInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("failed to getTableList, code: %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
ASSERT(pTableListInfo->numOfOuputGroups == 1);
|
||||
|
||||
int64_t st1 = taosGetTimestampUs();
|
||||
qDebug("generate queried table list completed, elapsed time:%.2f ms %s", (st1 - st) / 1000.0, idStr);
|
||||
|
||||
if (taosArrayGetSize(pTableListInfo->pTableList) == 0) {
|
||||
qDebug("no table qualified for query, %s" PRIx64, idStr);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
code = buildGroupIdMapForAllTables(pTableListInfo, pHandle, pGroupTags, groupSort);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t st2 = taosGetTimestampUs();
|
||||
qDebug("generate group id map completed, elapsed time:%.2f ms %s", (st2 - st1) / 1000.0, idStr);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -322,16 +322,11 @@ static SArray* filterUnqualifiedTables(const SStreamScanInfo* pScanInfo, const S
|
|||
|
||||
int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
STableListInfo* pListInfo = &pTaskInfo->tableqinfoList;
|
||||
|
||||
if (isAdd) {
|
||||
qDebug("add %d tables id into query list, %s", (int32_t)taosArrayGetSize(tableIdList), pTaskInfo->id.str);
|
||||
}
|
||||
|
||||
if (pListInfo->map == NULL) {
|
||||
pListInfo->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
}
|
||||
|
||||
// traverse to the stream scanner node to add this table id
|
||||
SOperatorInfo* pInfo = pTaskInfo->pRoot;
|
||||
while (pInfo->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
|
@ -342,8 +337,10 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
|
|||
SStreamScanInfo* pScanInfo = pInfo->info;
|
||||
if (isAdd) { // add new table id
|
||||
SArray* qa = filterUnqualifiedTables(pScanInfo, tableIdList, GET_TASKID(pTaskInfo));
|
||||
int32_t numOfQualifiedTables = taosArrayGetSize(qa);
|
||||
|
||||
qDebug(" %d qualified child tables added into stream scanner", numOfQualifiedTables);
|
||||
|
||||
qDebug(" %d qualified child tables added into stream scanner", (int32_t)taosArrayGetSize(qa));
|
||||
code = tqReaderAddTbUidList(pScanInfo->tqReader, qa);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(qa);
|
||||
|
@ -363,7 +360,9 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
|
|||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(qa); ++i) {
|
||||
STableListInfo* pTableListInfo = pTaskInfo->pTableInfoList;
|
||||
|
||||
for (int32_t i = 0; i < numOfQualifiedTables; ++i) {
|
||||
uint64_t* uid = taosArrayGet(qa, i);
|
||||
STableKeyInfo keyInfo = {.uid = *uid, .groupId = 0};
|
||||
|
||||
|
@ -393,8 +392,8 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
|
|||
|
||||
if (!exists) {
|
||||
#endif
|
||||
taosArrayPush(pTaskInfo->tableqinfoList.pTableList, &keyInfo);
|
||||
taosHashPut(pTaskInfo->tableqinfoList.map, uid, sizeof(*uid), &keyInfo.groupId, sizeof(keyInfo.groupId));
|
||||
|
||||
tableListAddTableInfo(pTableListInfo, keyInfo.uid, keyInfo.groupId);
|
||||
}
|
||||
|
||||
if (keyBuf != NULL) {
|
||||
|
@ -474,7 +473,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
|||
|
||||
qDebug("subplan task create completed, TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, pSubplan->id.queryId);
|
||||
|
||||
_error:
|
||||
_error:
|
||||
// if failed to add ref for all tables in this query, abort current query
|
||||
return code;
|
||||
}
|
||||
|
@ -993,8 +992,8 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
int64_t ts = pOffset->ts;
|
||||
|
||||
if (uid == 0) {
|
||||
if (taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList) != 0) {
|
||||
STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, 0);
|
||||
if (tableListGetSize(pTaskInfo->pTableInfoList) != 0) {
|
||||
STableKeyInfo* pTableInfo = tableListGetInfo(pTaskInfo->pTableInfoList, 0);
|
||||
uid = pTableInfo->uid;
|
||||
ts = INT64_MIN;
|
||||
} else {
|
||||
|
@ -1005,7 +1004,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
/*if (pTaskInfo->streamInfo.lastStatus.type != TMQ_OFFSET__SNAPSHOT_DATA ||*/
|
||||
/*pTaskInfo->streamInfo.lastStatus.uid != uid || pTaskInfo->streamInfo.lastStatus.ts != ts) {*/
|
||||
STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info;
|
||||
int32_t tableSz = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList);
|
||||
int32_t numOfTables = tableListGetSize(pTaskInfo->pTableInfoList);
|
||||
|
||||
#ifndef NDEBUG
|
||||
qDebug("switch to next table %" PRId64 " (cursor %d), %" PRId64 " rows returned", uid,
|
||||
|
@ -1014,8 +1013,8 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
#endif
|
||||
|
||||
bool found = false;
|
||||
for (int32_t i = 0; i < tableSz; i++) {
|
||||
STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, i);
|
||||
for (int32_t i = 0; i < numOfTables; i++) {
|
||||
STableKeyInfo* pTableInfo = tableListGetInfo(pTaskInfo->pTableInfoList, i);
|
||||
if (pTableInfo->uid == uid) {
|
||||
found = true;
|
||||
pTableScanInfo->currentTable = i;
|
||||
|
@ -1027,14 +1026,17 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
ASSERT(found);
|
||||
|
||||
if (pTableScanInfo->dataReader == NULL) {
|
||||
if (tsdbReaderOpen(pTableScanInfo->readHandle.vnode, &pTableScanInfo->cond,
|
||||
pTaskInfo->tableqinfoList.pTableList, &pTableScanInfo->dataReader, NULL) < 0 ||
|
||||
pTableScanInfo->dataReader == NULL) {
|
||||
STableKeyInfo* pList = tableListGetInfo(pTaskInfo->pTableInfoList, 0);
|
||||
int32_t num = tableListGetSize(pTaskInfo->pTableInfoList);
|
||||
|
||||
if (tsdbReaderOpen(pTableScanInfo->readHandle.vnode, &pTableScanInfo->cond, pList, num,
|
||||
&pTableScanInfo->dataReader, NULL) < 0 || pTableScanInfo->dataReader == NULL) {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
tsdbSetTableId(pTableScanInfo->dataReader, uid);
|
||||
STableKeyInfo tki = {.uid = uid};
|
||||
tsdbSetTableList(pTableScanInfo->dataReader, &tki, 1);
|
||||
int64_t oldSkey = pTableScanInfo->cond.twindows.skey;
|
||||
pTableScanInfo->cond.twindows.skey = ts + 1;
|
||||
tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond);
|
||||
|
@ -1042,7 +1044,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
pTableScanInfo->scanTimes = 0;
|
||||
|
||||
qDebug("tsdb reader offset seek to uid %" PRId64 " ts %" PRId64 ", table cur set to %d , all table num %d", uid,
|
||||
ts, pTableScanInfo->currentTable, tableSz);
|
||||
ts, pTableScanInfo->currentTable, numOfTables);
|
||||
/*}*/
|
||||
} else {
|
||||
ASSERT(0);
|
||||
|
@ -1058,16 +1060,28 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
SMetaTableInfo mtInfo = getUidfromSnapShot(sContext);
|
||||
tsdbReaderClose(pInfo->dataReader);
|
||||
pInfo->dataReader = NULL;
|
||||
|
||||
cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
|
||||
taosArrayDestroy(pTaskInfo->tableqinfoList.pTableList);
|
||||
if (mtInfo.uid == 0) return 0; // no data
|
||||
tableListClear(pTaskInfo->pTableInfoList);
|
||||
|
||||
if (mtInfo.uid == 0) {
|
||||
return 0; // no data
|
||||
}
|
||||
|
||||
initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
|
||||
pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts;
|
||||
pTaskInfo->tableqinfoList.pTableList = taosArrayInit(1, sizeof(STableKeyInfo));
|
||||
taosArrayPush(pTaskInfo->tableqinfoList.pTableList, &(STableKeyInfo){.uid = mtInfo.uid, .groupId = 0});
|
||||
tsdbReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pTaskInfo->tableqinfoList.pTableList,
|
||||
&pInfo->dataReader, NULL);
|
||||
|
||||
if (pTaskInfo->pTableInfoList == NULL) {
|
||||
pTaskInfo->pTableInfoList = tableListCreate();
|
||||
}
|
||||
|
||||
tableListAddTableInfo(pTaskInfo->pTableInfoList, mtInfo.uid, 0);
|
||||
|
||||
STableKeyInfo* pList = tableListGetInfo(pTaskInfo->pTableInfoList, 0);
|
||||
int32_t size = tableListGetSize(pTaskInfo->pTableInfoList);
|
||||
ASSERT(size == 1);
|
||||
|
||||
tsdbReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size, &pInfo->dataReader, NULL);
|
||||
|
||||
cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
|
||||
strcpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName);
|
||||
|
|
|
@ -494,7 +494,7 @@ static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int
|
|||
// todo: refactor this
|
||||
if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == pOneExpr->base.numOfParams - 1)) {
|
||||
pInput->pPTS = pInput->pData[j]; // in case of merge function, this is not always the ts column data.
|
||||
// ASSERT(pInput->pPTS->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
// ASSERT(pInput->pPTS->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
}
|
||||
ASSERT(pInput->pData[j] != NULL);
|
||||
} else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
|
||||
|
@ -815,7 +815,7 @@ bool isTaskKilled(SExecTaskInfo* pTaskInfo) {
|
|||
// abort current query execution.
|
||||
if (pTaskInfo->owner != 0 &&
|
||||
((taosGetTimestampSec() - pTaskInfo->cost.start / 1000) > 10 * getMaximumIdleDurationSec())
|
||||
/*(!needBuildResAfterQueryComplete(pTaskInfo))*/) {
|
||||
/*(!needBuildResAfterQueryComplete(pTaskInfo))*/) {
|
||||
assert(pTaskInfo->cost.start != 0);
|
||||
// qDebug("QInfo:%" PRIu64 " retrieve not arrive beyond %d ms, abort current query execution, start:%" PRId64
|
||||
// ", current:%d", pQInfo->qId, 1, pQInfo->startExecTs, taosGetTimestampSec());
|
||||
|
@ -1739,8 +1739,6 @@ int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void doDestroyTableList(STableListInfo* pTableqinfoList);
|
||||
|
||||
typedef struct SFetchRspHandleWrapper {
|
||||
uint32_t exchangeId;
|
||||
int32_t sourceIndex;
|
||||
|
@ -1965,7 +1963,7 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn
|
|||
SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo;
|
||||
if (pRsp->numOfRows == 0) {
|
||||
qDebug("%s vgId:%d, taskId:0x%" PRIx64 " execId:%d index:%d completed, rowsOfSource:%" PRIu64
|
||||
", totalRows:%" PRIu64 ", completed:%d try next %d/%" PRIzu,
|
||||
", totalRows:%" PRIu64 ", completed:%d try next %d/%" PRIzu,
|
||||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, i, pDataInfo->totalRows,
|
||||
pExchangeInfo->loadInfo.totalRows, completed + 1, i + 1, totalSources);
|
||||
pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED;
|
||||
|
@ -1992,10 +1990,10 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn
|
|||
|
||||
if (pRsp->completed == 1) {
|
||||
qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64
|
||||
" execId:%d"
|
||||
" index:%d completed, blocks:%d, numOfRows:%d, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64
|
||||
", total:%.2f Kb,"
|
||||
" completed:%d try next %d/%" PRIzu,
|
||||
" execId:%d"
|
||||
" index:%d completed, blocks:%d, numOfRows:%d, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64
|
||||
", total:%.2f Kb,"
|
||||
" completed:%d try next %d/%" PRIzu,
|
||||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, i, pRsp->numOfBlocks,
|
||||
pRsp->numOfRows, pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0,
|
||||
completed + 1, i + 1, totalSources);
|
||||
|
@ -2003,7 +2001,7 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn
|
|||
pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED;
|
||||
} else {
|
||||
qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64
|
||||
" execId:%d blocks:%d, numOfRows:%d, totalRows:%" PRIu64 ", total:%.2f Kb",
|
||||
" execId:%d blocks:%d, numOfRows:%d, totalRows:%" PRIu64 ", total:%.2f Kb",
|
||||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRsp->numOfBlocks,
|
||||
pRsp->numOfRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0);
|
||||
}
|
||||
|
@ -2030,7 +2028,7 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn
|
|||
sched_yield();
|
||||
}
|
||||
|
||||
_error:
|
||||
_error:
|
||||
pTaskInfo->code = code;
|
||||
}
|
||||
|
||||
|
@ -2091,7 +2089,7 @@ static int32_t seqLoadRemoteData(SOperatorInfo* pOperator) {
|
|||
SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo;
|
||||
if (pRsp->numOfRows == 0) {
|
||||
qDebug("%s vgId:%d, taskID:0x%" PRIx64 " execId:%d %d of total completed, rowsOfSource:%" PRIu64
|
||||
", totalRows:%" PRIu64 " try next",
|
||||
", totalRows:%" PRIu64 " try next",
|
||||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pExchangeInfo->current + 1,
|
||||
pDataInfo->totalRows, pLoadInfo->totalRows);
|
||||
|
||||
|
@ -2108,7 +2106,7 @@ static int32_t seqLoadRemoteData(SOperatorInfo* pOperator) {
|
|||
|
||||
if (pRsp->completed == 1) {
|
||||
qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%d, rowsOfSource:%" PRIu64
|
||||
", totalRows:%" PRIu64 ", totalBytes:%" PRIu64 " try next %d/%" PRIzu,
|
||||
", totalRows:%" PRIu64 ", totalBytes:%" PRIu64 " try next %d/%" PRIzu,
|
||||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRetrieveRsp->numOfRows,
|
||||
pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize, pExchangeInfo->current + 1,
|
||||
totalSources);
|
||||
|
@ -2117,7 +2115,7 @@ static int32_t seqLoadRemoteData(SOperatorInfo* pOperator) {
|
|||
pExchangeInfo->current += 1;
|
||||
} else {
|
||||
qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%d, totalRows:%" PRIu64
|
||||
", totalBytes:%" PRIu64,
|
||||
", totalBytes:%" PRIu64,
|
||||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRetrieveRsp->numOfRows,
|
||||
pLoadInfo->totalRows, pLoadInfo->totalSize);
|
||||
}
|
||||
|
@ -2305,7 +2303,7 @@ SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode
|
|||
createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL, destroyExchangeOperatorInfo, NULL);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
_error:
|
||||
if (pInfo != NULL) {
|
||||
doDestroyExchangeOperatorInfo(pInfo);
|
||||
}
|
||||
|
@ -3042,7 +3040,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiN
|
|||
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
_error:
|
||||
if (pInfo != NULL) {
|
||||
destroyAggOperatorInfo(pInfo);
|
||||
}
|
||||
|
@ -3052,7 +3050,7 @@ _error:
|
|||
}
|
||||
|
||||
taosMemoryFreeClear(pOperator);
|
||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pTaskInfo->code = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -3212,8 +3210,8 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
|||
|
||||
SInterval* pInterval =
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == downstream->operatorType
|
||||
? &((SMergeAlignedIntervalAggOperatorInfo*)downstream->info)->intervalAggOperatorInfo->interval
|
||||
: &((SIntervalAggOperatorInfo*)downstream->info)->interval;
|
||||
? &((SMergeAlignedIntervalAggOperatorInfo*)downstream->info)->intervalAggOperatorInfo->interval
|
||||
: &((SIntervalAggOperatorInfo*)downstream->info)->interval;
|
||||
|
||||
int32_t order = (pPhyFillNode->inputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC;
|
||||
int32_t type = convertFillType(pPhyFillNode->mode);
|
||||
|
@ -3258,7 +3256,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
|||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
_error:
|
||||
if (pInfo != NULL) {
|
||||
destroyFillOperatorInfo(pInfo);
|
||||
}
|
||||
|
@ -3275,6 +3273,7 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT
|
|||
pTaskInfo->cost.created = taosGetTimestampMs();
|
||||
pTaskInfo->id.queryId = queryId;
|
||||
pTaskInfo->execModel = model;
|
||||
pTaskInfo->pTableInfoList = tableListCreate();
|
||||
|
||||
char* p = taosMemoryCalloc(1, 128);
|
||||
snprintf(p, 128, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId);
|
||||
|
@ -3366,64 +3365,6 @@ static void cleanupTableSchemaInfo(SSchemaInfo* pSchemaInfo) {
|
|||
|
||||
static void cleanupStreamInfo(SStreamTaskInfo* pStreamInfo) { tDeleteSSchemaWrapper(pStreamInfo->schema); }
|
||||
|
||||
static int32_t sortTableGroup(STableListInfo* pTableListInfo) {
|
||||
taosArrayClear(pTableListInfo->pGroupList);
|
||||
SArray* sortSupport = taosArrayInit(16, sizeof(uint64_t));
|
||||
if (sortSupport == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTableListInfo->pTableList); i++) {
|
||||
STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i);
|
||||
uint64_t* groupId = taosHashGet(pTableListInfo->map, &info->uid, sizeof(uint64_t));
|
||||
|
||||
int32_t index = taosArraySearchIdx(sortSupport, groupId, compareUint64Val, TD_EQ);
|
||||
if (index == -1) {
|
||||
void* p = taosArraySearch(sortSupport, groupId, compareUint64Val, TD_GT);
|
||||
SArray* tGroup = taosArrayInit(8, sizeof(STableKeyInfo));
|
||||
if (tGroup == NULL) {
|
||||
taosArrayDestroy(sortSupport);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (taosArrayPush(tGroup, info) == NULL) {
|
||||
qError("taos push info array error");
|
||||
taosArrayDestroy(sortSupport);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
if (p == NULL) {
|
||||
if (taosArrayPush(sortSupport, groupId) == NULL) {
|
||||
qError("taos push support array error");
|
||||
taosArrayDestroy(sortSupport);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
if (taosArrayPush(pTableListInfo->pGroupList, &tGroup) == NULL) {
|
||||
qError("taos push group array error");
|
||||
taosArrayDestroy(sortSupport);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
} else {
|
||||
int32_t pos = TARRAY_ELEM_IDX(sortSupport, p);
|
||||
if (taosArrayInsert(sortSupport, pos, groupId) == NULL) {
|
||||
qError("taos insert support array error");
|
||||
taosArrayDestroy(sortSupport);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
if (taosArrayInsert(pTableListInfo->pGroupList, pos, &tGroup) == NULL) {
|
||||
qError("taos insert group array error");
|
||||
taosArrayDestroy(sortSupport);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SArray* tGroup = (SArray*)taosArrayGetP(pTableListInfo->pGroupList, index);
|
||||
if (taosArrayPush(tGroup, info) == NULL) {
|
||||
qError("taos push uid array error");
|
||||
taosArrayDestroy(sortSupport);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(sortSupport);
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool groupbyTbname(SNodeList* pGroupList) {
|
||||
bool bytbname = false;
|
||||
if (LIST_LENGTH(pGroupList) == 1) {
|
||||
|
@ -3437,80 +3378,29 @@ bool groupbyTbname(SNodeList* pGroupList) {
|
|||
return bytbname;
|
||||
}
|
||||
|
||||
int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* group) {
|
||||
if (group == NULL) {
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pTableListInfo->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
if (pTableListInfo->map == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
bool assignUid = groupbyTbname(group);
|
||||
|
||||
size_t numOfTables = taosArrayGetSize(pTableListInfo->pTableList);
|
||||
|
||||
if (assignUid) {
|
||||
for (int32_t i = 0; i < numOfTables; i++) {
|
||||
STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i);
|
||||
info->groupId = info->uid;
|
||||
taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), &info->groupId, sizeof(uint64_t));
|
||||
}
|
||||
} else {
|
||||
int32_t code = getColInfoResultForGroupby(pHandle->meta, group, pTableListInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTableListInfo->needSortTableByGroupId) {
|
||||
return sortTableGroup(pTableListInfo);
|
||||
}
|
||||
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t initTableblockDistQueryCond(uint64_t uid, SQueryTableDataCond* pCond) {
|
||||
memset(pCond, 0, sizeof(SQueryTableDataCond));
|
||||
|
||||
pCond->order = TSDB_ORDER_ASC;
|
||||
pCond->numOfCols = 1;
|
||||
pCond->colList = taosMemoryCalloc(1, sizeof(SColumnInfo));
|
||||
if (pCond->colList == NULL) {
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pCond->colList->colId = 1;
|
||||
pCond->colList->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pCond->colList->bytes = sizeof(TSKEY);
|
||||
|
||||
pCond->twindows = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX};
|
||||
pCond->suid = uid;
|
||||
pCond->type = TIMEWINDOW_RANGE_CONTAINED;
|
||||
pCond->startVersion = -1;
|
||||
pCond->endVersion = -1;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle,
|
||||
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond,
|
||||
const char* pUser) {
|
||||
SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond,
|
||||
SNode* pTagIndexCond, const char* pUser) {
|
||||
int32_t type = nodeType(pPhyNode);
|
||||
STableListInfo* pTableListInfo = pTaskInfo->pTableInfoList;
|
||||
const char* idstr = GET_TASKID(pTaskInfo);
|
||||
|
||||
if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
|
||||
SOperatorInfo* pOperator = NULL;
|
||||
if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) {
|
||||
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
||||
|
||||
// NOTE: this is an patch to fix the physical plan
|
||||
// TODO remove it later
|
||||
if (pTableScanNode->scan.node.pLimit != NULL) {
|
||||
pTableScanNode->groupSort = true;
|
||||
}
|
||||
|
||||
int32_t code =
|
||||
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle,
|
||||
pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
||||
pTableListInfo, pTagCond, pTagIndexCond, idstr);
|
||||
if (code) {
|
||||
pTaskInfo->code = code;
|
||||
qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), GET_TASKID(pTaskInfo));
|
||||
qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -3526,8 +3416,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
} else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
|
||||
STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
|
||||
int32_t code =
|
||||
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle,
|
||||
pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
||||
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, /*pTableScanNode->groupSort*/true, pHandle,
|
||||
pTableListInfo, pTagCond, pTagIndexCond, idstr);
|
||||
if (code) {
|
||||
pTaskInfo->code = code;
|
||||
qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
|
||||
|
@ -3552,7 +3442,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
if (pHandle->vnode) {
|
||||
int32_t code =
|
||||
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
|
||||
pHandle, pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
||||
pHandle, pTableListInfo, pTagCond, pTagIndexCond, idstr);
|
||||
if (code) {
|
||||
pTaskInfo->code = code;
|
||||
qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
|
||||
|
@ -3560,10 +3450,12 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
int32_t sz = taosArrayGetSize(pTableListInfo->pTableList);
|
||||
int32_t sz = tableListGetSize(pTableListInfo);
|
||||
qDebug("create stream task, total:%d", sz);
|
||||
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pTableListInfo->pTableList, i);
|
||||
qDebug("creating stream task: add table %" PRId64, pKeyInfo->uid);
|
||||
STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i);
|
||||
qDebug("add table uid:%" PRIu64", gid:%"PRIu64, pKeyInfo->uid, pKeyInfo->groupId);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -3575,7 +3467,9 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
pOperator = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pUser, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
|
||||
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
|
||||
int32_t code = getTableList(pHandle->meta, pHandle->vnode, pScanPhyNode, pTagCond, pTagIndexCond, pTableListInfo);
|
||||
|
||||
int32_t code = createScanTableListInfo(pScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond,
|
||||
pTagIndexCond, idstr);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
qError("failed to getTableList, code: %s", tstrerror(code));
|
||||
|
@ -3585,35 +3479,30 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
pOperator = createTagScanOperatorInfo(pHandle, pScanPhyNode, pTableListInfo, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) {
|
||||
SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*)pPhyNode;
|
||||
pTableListInfo->pTableList = taosArrayInit(4, sizeof(STableKeyInfo));
|
||||
|
||||
if (pBlockNode->tableType == TSDB_SUPER_TABLE) {
|
||||
int32_t code = vnodeGetAllTableList(pHandle->vnode, pBlockNode->uid, pTableListInfo->pTableList);
|
||||
SArray* pList = taosArrayInit(4, sizeof(STableKeyInfo));
|
||||
int32_t code = vnodeGetAllTableList(pHandle->vnode, pBlockNode->uid, pList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = terrno;
|
||||
return NULL;
|
||||
}
|
||||
} else { // Create one table group.
|
||||
STableKeyInfo info = {.uid = pBlockNode->uid, .groupId = 0};
|
||||
taosArrayPush(pTableListInfo->pTableList, &info);
|
||||
|
||||
for(int32_t i = 0; i < tableListGetSize(pTableListInfo); ++i) {
|
||||
STableKeyInfo* p = taosArrayGet(pList, i);
|
||||
tableListAddTableInfo(pTableListInfo, p->uid, 0);
|
||||
}
|
||||
taosArrayDestroy(pList);
|
||||
} else { // Create group with only one table
|
||||
tableListAddTableInfo(pTableListInfo, pBlockNode->uid, 0);
|
||||
}
|
||||
|
||||
SQueryTableDataCond cond = {0};
|
||||
int32_t code = initTableblockDistQueryCond(pBlockNode->suid, &cond);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STsdbReader* pReader = NULL;
|
||||
tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo->pTableList, &pReader, "");
|
||||
cleanupQueryTableDataCond(&cond);
|
||||
|
||||
pOperator = createDataBlockInfoScanOperator(pReader, pHandle, cond.suid, pBlockNode, pTaskInfo);
|
||||
pOperator = createDataBlockInfoScanOperator(pHandle, pBlockNode, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN == type) {
|
||||
SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode;
|
||||
|
||||
int32_t code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo,
|
||||
pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo));
|
||||
pTagCond, pTagIndexCond, idstr);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
return NULL;
|
||||
|
@ -3639,17 +3528,19 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
return pOperator;
|
||||
}
|
||||
|
||||
size_t size = LIST_LENGTH(pPhyNode->pChildren);
|
||||
size_t size = LIST_LENGTH(pPhyNode->pChildren);
|
||||
SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES);
|
||||
if (ops == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i);
|
||||
ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, pTableListInfo, pTagCond, pTagIndexCond, pUser);
|
||||
ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, pTagCond, pTagIndexCond, pUser);
|
||||
if (ops[i] == NULL) {
|
||||
taosMemoryFree(ops);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ops[i]->resultDataBlockId = pChildNode->pOutputDataBlockDesc->dataBlockId;
|
||||
}
|
||||
|
||||
SOperatorInfo* pOptr = NULL;
|
||||
|
@ -3848,7 +3739,7 @@ int32_t encodeOperator(SOperatorInfo* ops, char** result, int32_t* length, int32
|
|||
*length = *(int32_t*)(*result);
|
||||
}
|
||||
|
||||
_downstream:
|
||||
_downstream:
|
||||
for (int32_t i = 0; i < ops->numOfDownstream; ++i) {
|
||||
code = encodeOperator(ops->pDownstream[i], result, length, nOptrWithVal);
|
||||
if (code != TDB_CODE_SUCCESS) {
|
||||
|
@ -3914,15 +3805,18 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, qTaskInfo_t* pT
|
|||
if (NULL == pDeleterParam) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int32_t tbNum = taosArrayGetSize(pTask->tableqinfoList.pTableList);
|
||||
pDeleterParam->suid = pTask->tableqinfoList.suid;
|
||||
int32_t tbNum = tableListGetSize(pTask->pTableInfoList);
|
||||
pDeleterParam->suid = tableListGetSuid(pTask->pTableInfoList);
|
||||
|
||||
// TODO extract uid list
|
||||
pDeleterParam->pUidList = taosArrayInit(tbNum, sizeof(uint64_t));
|
||||
if (NULL == pDeleterParam->pUidList) {
|
||||
taosMemoryFree(pDeleterParam);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
STableKeyInfo* pTable = taosArrayGet(pTask->tableqinfoList.pTableList, i);
|
||||
STableKeyInfo* pTable = tableListGetInfo(pTask->pTableInfoList, i);
|
||||
taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
|
||||
}
|
||||
|
||||
|
@ -3958,8 +3852,8 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
|
|||
sql = NULL;
|
||||
|
||||
(*pTaskInfo)->pSubplan = pPlan;
|
||||
(*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, &(*pTaskInfo)->tableqinfoList,
|
||||
pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
|
||||
(*pTaskInfo)->pRoot =
|
||||
createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
|
||||
|
||||
if (NULL == (*pTaskInfo)->pRoot) {
|
||||
code = (*pTaskInfo)->code;
|
||||
|
@ -3968,35 +3862,17 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
|
|||
|
||||
return code;
|
||||
|
||||
_complete:
|
||||
_complete:
|
||||
taosMemoryFree(sql);
|
||||
doDestroyTask(*pTaskInfo);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
void doDestroyTableList(STableListInfo* pTableqinfoList) {
|
||||
taosArrayDestroy(pTableqinfoList->pTableList);
|
||||
taosHashCleanup(pTableqinfoList->map);
|
||||
if (pTableqinfoList->needSortTableByGroupId) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTableqinfoList->pGroupList); i++) {
|
||||
SArray* tmp = taosArrayGetP(pTableqinfoList->pGroupList, i);
|
||||
if (tmp == pTableqinfoList->pTableList) {
|
||||
continue;
|
||||
}
|
||||
taosArrayDestroy(tmp);
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(pTableqinfoList->pGroupList);
|
||||
|
||||
pTableqinfoList->pTableList = NULL;
|
||||
pTableqinfoList->map = NULL;
|
||||
}
|
||||
|
||||
void doDestroyTask(SExecTaskInfo* pTaskInfo) {
|
||||
qDebug("%s execTask is freed", GET_TASKID(pTaskInfo));
|
||||
|
||||
doDestroyTableList(&pTaskInfo->tableqinfoList);
|
||||
pTaskInfo->pTableInfoList = tableListDestroy(pTaskInfo->pTableInfoList);
|
||||
destroyOperatorInfo(pTaskInfo->pRoot);
|
||||
cleanupTableSchemaInfo(&pTaskInfo->schemaInfo);
|
||||
cleanupStreamInfo(&pTaskInfo->streamInfo);
|
||||
|
@ -4125,8 +4001,8 @@ int32_t buildDataBlockFromGroupRes(SOperatorInfo* pOperator, SStreamState* pStat
|
|||
int32_t size = 0;
|
||||
void* pVal = NULL;
|
||||
SWinKey key = {
|
||||
.ts = *(TSKEY*)pPos->key,
|
||||
.groupId = pPos->groupId,
|
||||
.ts = *(TSKEY*)pPos->key,
|
||||
.groupId = pPos->groupId,
|
||||
};
|
||||
int32_t code = streamStateGet(pState, &key, &pVal, &size);
|
||||
ASSERT(code == 0);
|
||||
|
|
|
@ -62,7 +62,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char**
|
|||
|
||||
int32_t numOfGroupCols = taosArrayGetSize(pGroupColList);
|
||||
for (int32_t i = 0; i < numOfGroupCols; ++i) {
|
||||
SColumn* pCol = (SColumn*) taosArrayGet(pGroupColList, i);
|
||||
SColumn* pCol = (SColumn*)taosArrayGet(pGroupColList, i);
|
||||
(*keyLen) += pCol->bytes; // actual data + null_flag
|
||||
|
||||
SGroupKeys key = {0};
|
||||
|
@ -397,7 +397,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
|||
return buildGroupResultDataBlock(pOperator);
|
||||
}
|
||||
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode *pAggNode, SExecTaskInfo* pTaskInfo) {
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo) {
|
||||
SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
|
@ -442,8 +442,8 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashGroupbyAggregate, NULL, NULL,
|
||||
destroyGroupOperatorInfo, NULL);
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, hashGroupbyAggregate, NULL, NULL, destroyGroupOperatorInfo, NULL);
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -765,7 +765,6 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
|||
goto _error;
|
||||
}
|
||||
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
SExprInfo* pExprInfo = createExprInfo(pPartNode->pTargets, NULL, &numOfCols);
|
||||
pInfo->pGroupCols = extractPartitionColInfo(pPartNode->pPartitionKeys);
|
||||
|
@ -819,8 +818,8 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashPartition, NULL, NULL, destroyPartitionOperatorInfo,
|
||||
NULL);
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, hashPartition, NULL, NULL, destroyPartitionOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
@ -965,6 +964,7 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) {
|
|||
case STREAM_DELETE_DATA: {
|
||||
copyDataBlock(pInfo->pDelRes, pBlock);
|
||||
pInfo->pDelRes->info.type = STREAM_DELETE_RESULT;
|
||||
printDataBlock(pInfo->pDelRes, "stream partitionby delete");
|
||||
return pInfo->pDelRes;
|
||||
} break;
|
||||
default:
|
||||
|
@ -1014,6 +1014,9 @@ void initParDownStream(SOperatorInfo* downstream, SPartitionBySupporter* pParSup
|
|||
SStreamScanInfo* pScanInfo = downstream->info;
|
||||
pScanInfo->partitionSup = *pParSup;
|
||||
pScanInfo->pPartScalarSup = pExpr;
|
||||
if (!pScanInfo->pUpdateInfo) {
|
||||
pScanInfo->pUpdateInfo = updateInfoInit(60000, TSDB_TIME_PRECISION_MILLI, 0);
|
||||
}
|
||||
}
|
||||
|
||||
SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStreamPartitionPhysiNode* pPartNode,
|
||||
|
@ -1108,7 +1111,6 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
SArray* extractColumnInfo(SNodeList* pNodeList) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn));
|
||||
|
|
|
@ -378,8 +378,6 @@ void applyLimitOffset(SLimitInfo* pLimitInfo, SSDataBlock* pBlock, SExecTaskInfo
|
|||
|
||||
blockDataKeepFirstNRows(pBlock, keep);
|
||||
qDebug("output limit %" PRId64 " has reached, %s", pLimit->limit, GET_TASKID(pTaskInfo));
|
||||
|
||||
// setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
}
|
||||
}
|
||||
|
@ -624,12 +622,9 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
|||
binfo.capacity = binfo.rows;
|
||||
blockDataEnsureCapacity(pBlock, binfo.rows);
|
||||
pBlock->info = binfo;
|
||||
ASSERT(binfo.uid != 0);
|
||||
|
||||
uint64_t* groupId = taosHashGet(pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t));
|
||||
if (groupId) {
|
||||
pBlock->info.groupId = *groupId;
|
||||
}
|
||||
ASSERT(binfo.uid != 0);
|
||||
pBlock->info.groupId = getTableGroupId(pTaskInfo->pTableInfoList, pBlock->info.uid);
|
||||
|
||||
uint32_t status = 0;
|
||||
int32_t code = loadDataBlock(pOperator, pTableScanInfo, pBlock, &status);
|
||||
|
@ -683,10 +678,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) {
|
|||
if (pTableScanInfo->scanTimes < pTableScanInfo->scanInfo.numOfAsc) {
|
||||
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
||||
pTableScanInfo->scanFlag = REPEAT_SCAN;
|
||||
qDebug(
|
||||
"%s start to repeat ascending order scan data SELECT last_row(*),hostname from cpu group by hostname;blocks "
|
||||
"due to query func required",
|
||||
GET_TASKID(pTaskInfo));
|
||||
qDebug("start to repeat ascending order scan data blocks due to query func required, %s", GET_TASKID(pTaskInfo));
|
||||
|
||||
// do prepare for the next round table scan operation
|
||||
tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond);
|
||||
|
@ -713,8 +705,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) {
|
|||
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
||||
pTableScanInfo->scanFlag = REPEAT_SCAN;
|
||||
|
||||
qDebug("%s start to repeat descending order scan data blocks due to query func required",
|
||||
GET_TASKID(pTaskInfo));
|
||||
qDebug("%s start to repeat descending order scan data blocks", GET_TASKID(pTaskInfo));
|
||||
tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond);
|
||||
}
|
||||
}
|
||||
|
@ -727,9 +718,9 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
|||
STableScanInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
// if scan table by table
|
||||
// scan table one by one sequentially
|
||||
if (pInfo->scanMode == TABLE_SCAN__TABLE_ORDER) {
|
||||
int32_t numOfTables = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList);
|
||||
int32_t numOfTables = tableListGetSize(pTaskInfo->pTableInfoList);
|
||||
|
||||
while (1) {
|
||||
SSDataBlock* result = doTableScanGroup(pOperator);
|
||||
|
@ -743,55 +734,65 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, pInfo->currentTable);
|
||||
tsdbSetTableId(pInfo->dataReader, pTableInfo->uid);
|
||||
STableKeyInfo* pTableInfo = tableListGetInfo(pTaskInfo->pTableInfoList, pInfo->currentTable);
|
||||
tsdbSetTableList(pInfo->dataReader, pTableInfo, 1);
|
||||
qDebug("set uid:%" PRIu64 " into scanner, total tables:%d, index:%d %s", pTableInfo->uid, numOfTables,
|
||||
pInfo->currentTable, pTaskInfo->id.str);
|
||||
|
||||
tsdbReaderReset(pInfo->dataReader, &pInfo->cond);
|
||||
pInfo->scanTimes = 0;
|
||||
}
|
||||
}
|
||||
} else { // scan table group by group sequentially
|
||||
if (pInfo->currentGroupId == -1) {
|
||||
if ((++pInfo->currentGroupId) >= tableListGetOutputGroups(pTaskInfo->pTableInfoList)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pInfo->currentGroupId == -1) {
|
||||
pInfo->currentGroupId++;
|
||||
if (pInfo->currentGroupId >= taosArrayGetSize(pTaskInfo->tableqinfoList.pGroupList)) {
|
||||
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||
int32_t num = 0;
|
||||
STableKeyInfo* pList = NULL;
|
||||
tableListGetGroupList(pTaskInfo->pTableInfoList, pInfo->currentGroupId, &pList, &num);
|
||||
ASSERT(pInfo->dataReader == NULL);
|
||||
|
||||
int32_t code = tsdbReaderOpen(pInfo->readHandle.vnode, &pInfo->cond, pList, num,
|
||||
(STsdbReader**)&pInfo->dataReader, GET_TASKID(pTaskInfo));
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
}
|
||||
|
||||
SSDataBlock* result = doTableScanGroup(pOperator);
|
||||
if (result != NULL) {
|
||||
ASSERT(result->info.uid != 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((++pInfo->currentGroupId) >= tableListGetOutputGroups(pTaskInfo->pTableInfoList)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId);
|
||||
tsdbReaderClose(pInfo->dataReader);
|
||||
// reset value for the next group data output
|
||||
pOperator->status = OP_OPENED;
|
||||
pInfo->limitInfo.numOfOutputRows = 0;
|
||||
pInfo->limitInfo.remainOffset = pInfo->limitInfo.limit.offset;
|
||||
|
||||
int32_t code = tsdbReaderOpen(pInfo->readHandle.vnode, &pInfo->cond, tableList, (STsdbReader**)&pInfo->dataReader,
|
||||
GET_TASKID(pTaskInfo));
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
return NULL;
|
||||
int32_t num = 0;
|
||||
STableKeyInfo* pList = NULL;
|
||||
tableListGetGroupList(pTaskInfo->pTableInfoList, pInfo->currentGroupId, &pList, &num);
|
||||
|
||||
tsdbSetTableList(pInfo->dataReader, pList, num);
|
||||
tsdbReaderReset(pInfo->dataReader, &pInfo->cond);
|
||||
pInfo->scanTimes = 0;
|
||||
|
||||
result = doTableScanGroup(pOperator);
|
||||
if (result != NULL) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
SSDataBlock* result = doTableScanGroup(pOperator);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
pInfo->currentGroupId++;
|
||||
if (pInfo->currentGroupId >= taosArrayGetSize(pTaskInfo->tableqinfoList.pGroupList)) {
|
||||
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tsdbReaderReset(pInfo->dataReader, &pInfo->cond);
|
||||
pInfo->scanTimes = 0;
|
||||
|
||||
result = doTableScanGroup(pOperator);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t getTableScannerExecInfo(struct SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) {
|
||||
|
@ -837,7 +838,6 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
|
|||
}
|
||||
|
||||
initLimitInfo(pTableScanNode->scan.node.pLimit, pTableScanNode->scan.node.pSlimit, &pInfo->limitInfo);
|
||||
|
||||
code = initQueryTableDataCond(&pInfo->cond, pTableScanNode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -1001,8 +1001,32 @@ static void destroyBlockDistScanOperatorInfo(void* param) {
|
|||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
||||
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid,
|
||||
SBlockDistScanPhysiNode* pBlockScanNode, SExecTaskInfo* pTaskInfo) {
|
||||
static int32_t initTableblockDistQueryCond(uint64_t uid, SQueryTableDataCond* pCond) {
|
||||
memset(pCond, 0, sizeof(SQueryTableDataCond));
|
||||
|
||||
pCond->order = TSDB_ORDER_ASC;
|
||||
pCond->numOfCols = 1;
|
||||
pCond->colList = taosMemoryCalloc(1, sizeof(SColumnInfo));
|
||||
if (pCond->colList == NULL) {
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pCond->colList->colId = 1;
|
||||
pCond->colList->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pCond->colList->bytes = sizeof(TSKEY);
|
||||
|
||||
pCond->twindows = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX};
|
||||
pCond->suid = uid;
|
||||
pCond->type = TIMEWINDOW_RANGE_CONTAINED;
|
||||
pCond->startVersion = -1;
|
||||
pCond->endVersion = -1;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SOperatorInfo* createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanPhysiNode* pBlockScanNode,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SBlockDistInfo* pInfo = taosMemoryCalloc(1, sizeof(SBlockDistInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
|
@ -1010,9 +1034,24 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* re
|
|||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->pHandle = dataReader;
|
||||
{
|
||||
SQueryTableDataCond cond = {0};
|
||||
|
||||
int32_t code = initTableblockDistQueryCond(pBlockScanNode->suid, &cond);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STableListInfo* pTableListInfo = pTaskInfo->pTableInfoList;
|
||||
size_t num = tableListGetSize(pTableListInfo);
|
||||
void* pList = tableListGetInfo(pTableListInfo, 0);
|
||||
|
||||
tsdbReaderOpen(readHandle->vnode, &cond, pList, num, &pInfo->pHandle, pTaskInfo->id.str);
|
||||
cleanupQueryTableDataCond(&cond);
|
||||
}
|
||||
|
||||
pInfo->readHandle = *readHandle;
|
||||
pInfo->uid = uid;
|
||||
pInfo->uid = pBlockScanNode->suid;
|
||||
pInfo->pResBlock = createResDataBlock(pBlockScanNode->node.pOutputDataBlockDesc);
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
|
@ -1077,39 +1116,58 @@ void resetTableScanInfo(STableScanInfo* pTableScanInfo, STimeWindow* pWin) {
|
|||
pTableScanInfo->cond.twindows = *pWin;
|
||||
pTableScanInfo->scanTimes = 0;
|
||||
pTableScanInfo->currentGroupId = -1;
|
||||
}
|
||||
|
||||
static void freeArray(void* array) { taosArrayDestroy(array); }
|
||||
|
||||
static void resetTableScanOperator(SOperatorInfo* pTableScanOp) {
|
||||
STableScanInfo* pTableScanInfo = pTableScanOp->info;
|
||||
pTableScanInfo->cond.startVersion = -1;
|
||||
pTableScanInfo->cond.endVersion = -1;
|
||||
SArray* gpTbls = pTableScanOp->pTaskInfo->tableqinfoList.pGroupList;
|
||||
SArray* allTbls = pTableScanOp->pTaskInfo->tableqinfoList.pTableList;
|
||||
taosArrayClearP(gpTbls, freeArray);
|
||||
taosArrayPush(gpTbls, &allTbls);
|
||||
STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX};
|
||||
resetTableScanInfo(pTableScanOp->info, &win);
|
||||
tsdbReaderClose(pTableScanInfo->dataReader);
|
||||
pTableScanInfo->dataReader = NULL;
|
||||
}
|
||||
|
||||
static SSDataBlock* readPreVersionData(SOperatorInfo* pTableScanOp, uint64_t tbUid, TSKEY startTs, TSKEY endTs,
|
||||
int64_t maxVersion) {
|
||||
SArray* gpTbls = pTableScanOp->pTaskInfo->tableqinfoList.pGroupList;
|
||||
taosArrayClear(gpTbls);
|
||||
STableKeyInfo tblInfo = {.uid = tbUid, .groupId = 0};
|
||||
SArray* tbls = taosArrayInit(1, sizeof(STableKeyInfo));
|
||||
taosArrayPush(tbls, &tblInfo);
|
||||
taosArrayPush(gpTbls, &tbls);
|
||||
|
||||
STimeWindow win = {.skey = startTs, .ekey = endTs};
|
||||
STableScanInfo* pTableScanInfo = pTableScanOp->info;
|
||||
pTableScanInfo->cond.startVersion = -1;
|
||||
pTableScanInfo->cond.endVersion = maxVersion;
|
||||
resetTableScanInfo(pTableScanOp->info, &win);
|
||||
SSDataBlock* pRes = doTableScan(pTableScanOp);
|
||||
resetTableScanOperator(pTableScanOp);
|
||||
return pRes;
|
||||
STableScanInfo* pTableScanInfo = pTableScanOp->info;
|
||||
SQueryTableDataCond cond = pTableScanInfo->cond;
|
||||
|
||||
cond.startVersion = -1;
|
||||
cond.endVersion = maxVersion;
|
||||
cond.twindows = (STimeWindow){.skey = startTs, .ekey = endTs};
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pTableScanOp->pTaskInfo;
|
||||
|
||||
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
||||
blockDataCleanup(pBlock);
|
||||
|
||||
STsdbReader* pReader = NULL;
|
||||
int32_t code = tsdbReaderOpen(pTableScanInfo->readHandle.vnode, &cond, &tblInfo, 1, (STsdbReader**)&pReader,
|
||||
GET_TASKID(pTaskInfo));
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool hasBlock = tsdbNextDataBlock(pReader);
|
||||
if (hasBlock) {
|
||||
SDataBlockInfo binfo = {0};
|
||||
tsdbRetrieveDataBlockInfo(pReader, &binfo);
|
||||
|
||||
SArray* pCols = tsdbRetrieveDataBlock(pReader, NULL);
|
||||
blockDataEnsureCapacity(pBlock, binfo.rows);
|
||||
|
||||
pBlock->info.window = binfo.window;
|
||||
pBlock->info.uid = binfo.uid;
|
||||
pBlock->info.rows = binfo.rows;
|
||||
|
||||
relocateColumnData(pBlock, pTableScanInfo->matchInfo.pList, pCols, true);
|
||||
doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo);
|
||||
|
||||
pBlock->info.groupId = getTableGroupId(pTaskInfo->pTableInfoList, binfo.uid);
|
||||
}
|
||||
|
||||
tsdbReaderClose(pReader);
|
||||
qDebug("retrieve prev rows:%d, skey:%" PRId64 ", ekey:%" PRId64 " uid:%" PRIu64 ", max ver:%" PRId64
|
||||
", suid:%" PRIu64,
|
||||
pBlock->info.rows, startTs, endTs, tbUid, maxVersion, cond.suid);
|
||||
|
||||
return pBlock->info.rows > 0 ? pBlock : NULL;
|
||||
}
|
||||
|
||||
static uint64_t getGroupIdByCol(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts, int64_t maxVersion) {
|
||||
|
@ -1122,12 +1180,13 @@ static uint64_t getGroupIdByCol(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts,
|
|||
}
|
||||
|
||||
static uint64_t getGroupIdByUid(SStreamScanInfo* pInfo, uint64_t uid) {
|
||||
SHashObj* map = pInfo->pTableScanOp->pTaskInfo->tableqinfoList.map;
|
||||
uint64_t* groupId = taosHashGet(map, &uid, sizeof(int64_t));
|
||||
if (groupId) {
|
||||
return *groupId;
|
||||
}
|
||||
return 0;
|
||||
return getTableGroupId(pInfo->pTableScanOp->pTaskInfo->pTableInfoList, uid);
|
||||
// SHashObj* map = pInfo->pTableScanOp->pTaskInfo->pTableInfoList.map;
|
||||
// uint64_t* groupId = taosHashGet(map, &uid, sizeof(int64_t));
|
||||
// if (groupId) {
|
||||
// return *groupId;
|
||||
// }
|
||||
// return 0;
|
||||
}
|
||||
|
||||
static uint64_t getGroupIdByData(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts, int64_t maxVersion) {
|
||||
|
@ -1300,9 +1359,6 @@ static int32_t generateSessionScanRange(SStreamScanInfo* pInfo, SSDataBlock* pSr
|
|||
SSessionKey startWin = {0};
|
||||
getCurSessionWindow(pInfo->windowSup.pStreamAggSup, startData[i], endData[i], groupId, &startWin);
|
||||
if (IS_INVALID_SESSION_WIN_KEY(startWin)) {
|
||||
// char* tmp = streamStateSessionDump(pInfo->windowSup.pStreamAggSup->pState);
|
||||
// qInfo("%s", tmp);
|
||||
// taosMemoryFree(tmp);
|
||||
// window has been closed.
|
||||
continue;
|
||||
}
|
||||
|
@ -1327,7 +1383,7 @@ static int32_t generateIntervalScanRange(SStreamScanInfo* pInfo, SSDataBlock* pS
|
|||
if (rows == 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t code = blockDataEnsureCapacity(pDestBlock, rows * 2);
|
||||
int32_t code = blockDataEnsureCapacity(pDestBlock, rows);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -1370,39 +1426,33 @@ static int32_t generateIntervalScanRange(SStreamScanInfo* pInfo, SSDataBlock* pS
|
|||
}
|
||||
|
||||
static int32_t generateDeleteResultBlock(SStreamScanInfo* pInfo, SSDataBlock* pSrcBlock, SSDataBlock* pDestBlock) {
|
||||
if (pSrcBlock->info.rows == 0) {
|
||||
blockDataCleanup(pDestBlock);
|
||||
int32_t rows = pSrcBlock->info.rows;
|
||||
if (rows == 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
blockDataCleanup(pDestBlock);
|
||||
int32_t code = blockDataEnsureCapacity(pDestBlock, pSrcBlock->info.rows);
|
||||
int32_t code = blockDataEnsureCapacity(pDestBlock, rows);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
ASSERT(taosArrayGetSize(pSrcBlock->pDataBlock) >= 3);
|
||||
SColumnInfoData* pStartTsCol = taosArrayGet(pSrcBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
||||
TSKEY* startData = (TSKEY*)pStartTsCol->pData;
|
||||
SColumnInfoData* pEndTsCol = taosArrayGet(pSrcBlock->pDataBlock, END_TS_COLUMN_INDEX);
|
||||
TSKEY* endData = (TSKEY*)pEndTsCol->pData;
|
||||
SColumnInfoData* pUidCol = taosArrayGet(pSrcBlock->pDataBlock, UID_COLUMN_INDEX);
|
||||
uint64_t* uidCol = (uint64_t*)pUidCol->pData;
|
||||
|
||||
SColumnInfoData* pDestStartCol = taosArrayGet(pDestBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
||||
SColumnInfoData* pDestEndCol = taosArrayGet(pDestBlock->pDataBlock, END_TS_COLUMN_INDEX);
|
||||
SColumnInfoData* pDestUidCol = taosArrayGet(pDestBlock->pDataBlock, UID_COLUMN_INDEX);
|
||||
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;
|
||||
SColumnInfoData* pSrcStartTsCol = (SColumnInfoData*)taosArrayGet(pSrcBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
||||
SColumnInfoData* pSrcEndTsCol = (SColumnInfoData*)taosArrayGet(pSrcBlock->pDataBlock, END_TS_COLUMN_INDEX);
|
||||
SColumnInfoData* pSrcUidCol = taosArrayGet(pSrcBlock->pDataBlock, UID_COLUMN_INDEX);
|
||||
uint64_t* srcUidData = (uint64_t*)pSrcUidCol->pData;
|
||||
SColumnInfoData* pSrcGpCol = taosArrayGet(pSrcBlock->pDataBlock, GROUPID_COLUMN_INDEX);
|
||||
uint64_t* srcGp = (uint64_t*)pSrcGpCol->pData;
|
||||
ASSERT(pSrcStartTsCol->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
TSKEY* srcStartTsCol = (TSKEY*)pSrcStartTsCol->pData;
|
||||
TSKEY* srcEndTsCol = (TSKEY*)pSrcEndTsCol->pData;
|
||||
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);
|
||||
colDataAppend(pDestStartCol, i, (const char*)(startData + i), false);
|
||||
colDataAppend(pDestEndCol, i, (const char*)(endData + i), false);
|
||||
colDataAppendNULL(pDestUidCol, i);
|
||||
colDataAppend(pDestGpCol, i, (const char*)&groupId, false);
|
||||
colDataAppendNULL(pDestCalStartTsCol, i);
|
||||
colDataAppendNULL(pDestCalEndTsCol, i);
|
||||
pDestBlock->info.rows++;
|
||||
uint64_t srcUid = srcUidData[i];
|
||||
uint64_t groupId = srcGp[i];
|
||||
if (groupId == 0) {
|
||||
groupId = getGroupIdByData(pInfo, srcUid, srcStartTsCol[i], version);
|
||||
}
|
||||
appendOneRowToStreamSpecialBlock(pDestBlock, srcStartTsCol + i, srcEndTsCol + i, srcUidData + i, &groupId, NULL);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1413,6 +1463,8 @@ static int32_t generateScanRange(SStreamScanInfo* pInfo, SSDataBlock* pSrcBlock,
|
|||
code = generateIntervalScanRange(pInfo, pSrcBlock, pDestBlock);
|
||||
} else if (isSessionWindow(pInfo) || isStateWindow(pInfo)) {
|
||||
code = generateSessionScanRange(pInfo, pSrcBlock, pDestBlock);
|
||||
} else {
|
||||
code = generateDeleteResultBlock(pInfo, pSrcBlock, pDestBlock);
|
||||
}
|
||||
pDestBlock->info.type = STREAM_CLEAR;
|
||||
pDestBlock->info.version = pSrcBlock->info.version;
|
||||
|
@ -1549,12 +1601,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
|
|||
pInfo->pRes->info.type = STREAM_NORMAL;
|
||||
pInfo->pRes->info.version = pBlock->info.version;
|
||||
|
||||
uint64_t* groupIdPre = taosHashGet(pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t));
|
||||
if (groupIdPre) {
|
||||
pInfo->pRes->info.groupId = *groupIdPre;
|
||||
} else {
|
||||
pInfo->pRes->info.groupId = 0;
|
||||
}
|
||||
pInfo->pRes->info.groupId = getTableGroupId(pTaskInfo->pTableInfoList, pBlock->info.uid);
|
||||
|
||||
// todo extract method
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->matchInfo.pList); ++i) {
|
||||
|
@ -1699,7 +1746,7 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
#if 0
|
||||
} else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
} else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp);
|
||||
if (pResult && pResult->info.rows > 0) {
|
||||
qDebug("stream scan tsdb return %d rows", pResult->info.rows);
|
||||
|
@ -1850,7 +1897,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
#endif
|
||||
|
||||
size_t total = taosArrayGetSize(pInfo->pBlockLists);
|
||||
// TODO: refactor
|
||||
// TODO: refactor
|
||||
FETCH_NEXT_BLOCK:
|
||||
if (pInfo->blockType == STREAM_INPUT__DATA_BLOCK) {
|
||||
if (pInfo->validBlockIndex >= total) {
|
||||
|
@ -2070,12 +2117,13 @@ FETCH_NEXT_BLOCK:
|
|||
}
|
||||
}
|
||||
|
||||
static SArray* extractTableIdList(const STableListInfo* pTableGroupInfo) {
|
||||
static SArray* extractTableIdList(const STableListInfo* pTableListInfo) {
|
||||
SArray* tableIdList = taosArrayInit(4, sizeof(uint64_t));
|
||||
|
||||
// Transfer the Array of STableKeyInfo into uid list.
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTableGroupInfo->pTableList); ++i) {
|
||||
STableKeyInfo* pkeyInfo = taosArrayGet(pTableGroupInfo->pTableList, i);
|
||||
size_t size = tableListGetSize(pTableListInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
STableKeyInfo* pkeyInfo = tableListGetInfo(pTableListInfo, i);
|
||||
taosArrayPush(tableIdList, &pkeyInfo->uid);
|
||||
}
|
||||
|
||||
|
@ -2287,6 +2335,9 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
int32_t numOfCols = 0;
|
||||
int32_t code =
|
||||
extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
int32_t numOfOutput = taosArrayGetSize(pInfo->matchInfo.pList);
|
||||
SArray* pColIds = taosArrayInit(numOfOutput, sizeof(int16_t));
|
||||
|
@ -2339,12 +2390,16 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
pTSInfo->cond.endVersion = pHandle->version;
|
||||
}
|
||||
|
||||
SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, 0);
|
||||
STableKeyInfo* pList = NULL;
|
||||
int32_t num = 0;
|
||||
tableListGetGroupList(pTaskInfo->pTableInfoList, 0, &pList, &num);
|
||||
|
||||
if (pHandle->initTableReader) {
|
||||
pTSInfo->scanMode = TABLE_SCAN__TABLE_ORDER;
|
||||
pTSInfo->dataReader = NULL;
|
||||
if (tsdbReaderOpen(pHandle->vnode, &pTSInfo->cond, tableList, &pTSInfo->dataReader, NULL) < 0) {
|
||||
if (tsdbReaderOpen(pHandle->vnode, &pTSInfo->cond, pList, num, &pTSInfo->dataReader, NULL) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
destroyTableScanOperatorInfo(pTableScanOp);
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
@ -2370,8 +2425,8 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
|
||||
// set the extract column id to streamHandle
|
||||
tqReaderSetColIdList(pInfo->tqReader, pColIds);
|
||||
SArray* tableIdList = extractTableIdList(&pTaskInfo->tableqinfoList);
|
||||
int32_t code = tqReaderSetTbUidList(pInfo->tqReader, tableIdList);
|
||||
SArray* tableIdList = extractTableIdList(pTaskInfo->pTableInfoList);
|
||||
code = tqReaderSetTbUidList(pInfo->tqReader, tableIdList);
|
||||
if (code != 0) {
|
||||
taosArrayDestroy(tableIdList);
|
||||
goto _error;
|
||||
|
@ -3320,6 +3375,7 @@ static int32_t optSysMergeRslt(SArray* mRslt, SArray* rslt) {
|
|||
optSysIntersection(mRslt, rslt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t optSysSpecialColumn(SNode* cond) {
|
||||
SOperatorNode* pOper = (SOperatorNode*)cond;
|
||||
SColumnNode* pCol = (SColumnNode*)pOper->pLeft;
|
||||
|
@ -3330,6 +3386,7 @@ static int32_t optSysSpecialColumn(SNode* cond) {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t optSysTabFilte(void* arg, SNode* cond, SArray* result) {
|
||||
int ret = -1;
|
||||
if (nodeType(cond) == QUERY_NODE_OPERATOR) {
|
||||
|
@ -3363,6 +3420,7 @@ static int32_t optSysTabFilte(void* arg, SNode* cond, SArray* result) {
|
|||
if (cell == NULL) break;
|
||||
|
||||
SArray* aRslt = taosArrayInit(16, sizeof(int64_t));
|
||||
|
||||
ret = optSysTabFilteImpl(arg, cell->pNode, aRslt);
|
||||
if (ret == 0) {
|
||||
// has index
|
||||
|
@ -3443,7 +3501,7 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) {
|
|||
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, pInfo->readHandle.meta, 0);
|
||||
int32_t ret = metaGetTableEntryByUid(&mr, *uid);
|
||||
ret = metaGetTableEntryByUid(&mr, *uid);
|
||||
if (ret < 0) {
|
||||
metaReaderClear(&mr);
|
||||
continue;
|
||||
|
@ -4066,7 +4124,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
|
|||
SSDataBlock* pRes = pInfo->pRes;
|
||||
blockDataCleanup(pRes);
|
||||
|
||||
int32_t size = taosArrayGetSize(pInfo->pTableList->pTableList);
|
||||
int32_t size = tableListGetSize(pTaskInfo->pTableInfoList);
|
||||
if (size == 0) {
|
||||
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||
return NULL;
|
||||
|
@ -4078,7 +4136,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
|
|||
metaReaderInit(&mr, pInfo->readHandle.meta, 0);
|
||||
|
||||
while (pInfo->curPos < size && count < pOperator->resultInfo.capacity) {
|
||||
STableKeyInfo* item = taosArrayGet(pInfo->pTableList->pTableList, pInfo->curPos);
|
||||
STableKeyInfo* item = tableListGetInfo(pInfo->pTableList, pInfo->curPos);
|
||||
int32_t code = metaGetTableEntryByUid(&mr, item->uid);
|
||||
tDecoderClear(&mr.coder);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -4157,6 +4215,9 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi
|
|||
SExprInfo* pExprInfo = createExprInfo(pPhyNode->pScanPseudoCols, NULL, &numOfExprs);
|
||||
int32_t code =
|
||||
extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfExprs);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -4190,53 +4251,13 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle,
|
||||
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond,
|
||||
const char* idStr) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
if (pHandle == NULL) {
|
||||
qError("invalid handle, in creating operator tree, %s", idStr);
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
int32_t code = getTableList(pHandle->meta, pHandle->vnode, pScanNode, pTagCond, pTagIndexCond, pTableListInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("failed to getTableList, code: %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t st1 = taosGetTimestampUs();
|
||||
qDebug("generate queried table list completed, elapsed time:%.2f ms %s", (st1 - st) / 1000.0, idStr);
|
||||
|
||||
if (taosArrayGetSize(pTableListInfo->pTableList) == 0) {
|
||||
qDebug("no table qualified for query, %s" PRIx64, idStr);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pTableListInfo->needSortTableByGroupId = groupSort;
|
||||
code = generateGroupIdMap(pTableListInfo, pHandle, pGroupTags);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t st2 = taosGetTimestampUs();
|
||||
qDebug("generate group id map completed, elapsed time:%.2f ms %s", (st2 - st1) / 1000.0, idStr);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t createMultipleDataReaders(SQueryTableDataCond* pQueryCond, SReadHandle* pHandle, STableListInfo* pTableListInfo,
|
||||
int32_t tableStartIdx, int32_t tableEndIdx, SArray* arrayReader, const char* idstr) {
|
||||
for (int32_t i = tableStartIdx; i <= tableEndIdx; ++i) {
|
||||
SArray* subTableList = taosArrayInit(1, sizeof(STableKeyInfo));
|
||||
taosArrayPush(subTableList, taosArrayGet(pTableListInfo->pTableList, i));
|
||||
|
||||
STsdbReader* pReader = NULL;
|
||||
tsdbReaderOpen(pHandle->vnode, pQueryCond, subTableList, &pReader, idstr);
|
||||
STableKeyInfo* pList = tableListGetInfo(pTableListInfo, i);
|
||||
STsdbReader* pReader = NULL;
|
||||
tsdbReaderOpen(pHandle->vnode, pQueryCond, pList, 1, &pReader, idstr);
|
||||
taosArrayPush(arrayReader, &pReader);
|
||||
|
||||
taosArrayDestroy(subTableList);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -4246,15 +4267,14 @@ int32_t createMultipleDataReaders2(SQueryTableDataCond* pQueryCond, SReadHandle*
|
|||
STableListInfo* pTableListInfo, int32_t tableStartIdx, int32_t tableEndIdx,
|
||||
STsdbReader** ppReader, const char* idstr) {
|
||||
STsdbReader* pReader = NULL;
|
||||
SArray* subTableList = taosArrayInit(1, sizeof(STableKeyInfo));
|
||||
for (int32_t i = tableStartIdx; i <= tableEndIdx; ++i) {
|
||||
taosArrayPush(subTableList, taosArrayGet(pTableListInfo->pTableList, i));
|
||||
}
|
||||
int32_t code = tsdbReaderOpen(pHandle->vnode, pQueryCond, subTableList, &pReader, idstr);
|
||||
void* pStart = tableListGetInfo(pTableListInfo, tableStartIdx);
|
||||
int32_t num = tableEndIdx - tableStartIdx + 1;
|
||||
|
||||
int32_t code = tsdbReaderOpen(pHandle->vnode, pQueryCond, pStart, num, &pReader, idstr);
|
||||
if (code != 0) {
|
||||
taosArrayDestroy(subTableList);
|
||||
return code;
|
||||
}
|
||||
|
||||
*ppReader = pReader;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -4409,8 +4429,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc
|
|||
|
||||
bool allColumnsHaveAgg = true;
|
||||
SColumnDataAgg** pColAgg = NULL;
|
||||
STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx);
|
||||
tsdbRetrieveDatablockSMA(reader, &pColAgg, &allColumnsHaveAgg);
|
||||
// STsdbReader* reader = pTableScanInfo->pReader; // taosArrayGetP(pTableScanInfo->dataReaders, readerIdx);
|
||||
|
||||
if (allColumnsHaveAgg == true) {
|
||||
int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||
|
@ -4450,7 +4469,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc
|
|||
pCost->totalCheckedRows += pBlock->info.rows;
|
||||
pCost->loadBlocks += 1;
|
||||
|
||||
STsdbReader* reader = pTableScanInfo->pReader; // taosArrayGetP(pTableScanInfo->dataReaders, readerIdx);
|
||||
STsdbReader* reader = pTableScanInfo->pReader;
|
||||
SArray* pCols = tsdbRetrieveDataBlock(reader, NULL);
|
||||
if (pCols == NULL) {
|
||||
return terrno;
|
||||
|
@ -4489,7 +4508,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc
|
|||
typedef struct STableMergeScanSortSourceParam {
|
||||
SOperatorInfo* pOperator;
|
||||
int32_t readerIdx;
|
||||
int64_t uid;
|
||||
uint64_t uid;
|
||||
SSDataBlock* inputBlock;
|
||||
} STableMergeScanSortSourceParam;
|
||||
|
||||
|
@ -4508,11 +4527,9 @@ static SSDataBlock* getTableDataBlockTemp(void* param) {
|
|||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
SArray* subTable = taosArrayInit(1, sizeof(STableKeyInfo));
|
||||
taosArrayPush(subTable, taosArrayGet(pInfo->tableListInfo->pTableList, readIdx + pInfo->tableStartIndex));
|
||||
void* p = tableListGetInfo(pInfo->tableListInfo, readIdx + pInfo->tableStartIndex);
|
||||
SReadHandle* pHandle = &pInfo->readHandle;
|
||||
tsdbReaderOpen(pHandle->vnode, pQueryCond, subTable, &pInfo->pReader, GET_TASKID(pTaskInfo));
|
||||
taosArrayDestroy(subTable);
|
||||
tsdbReaderOpen(pHandle->vnode, pQueryCond, p, 1, &pInfo->pReader, GET_TASKID(pTaskInfo));
|
||||
|
||||
STsdbReader* reader = pInfo->pReader;
|
||||
while (tsdbNextDataBlock(reader)) {
|
||||
|
@ -4536,7 +4553,7 @@ static SSDataBlock* getTableDataBlockTemp(void* param) {
|
|||
pBlock->info.window = binfo.window;
|
||||
pBlock->info.rows = binfo.rows;
|
||||
|
||||
if (tsdbIsAscendingOrder(pInfo->pReader)) {
|
||||
if (pQueryCond->order == TSDB_ORDER_ASC) {
|
||||
pQueryCond->twindows.skey = pBlock->info.window.ekey + 1;
|
||||
} else {
|
||||
pQueryCond->twindows.ekey = pBlock->info.window.skey - 1;
|
||||
|
@ -4553,10 +4570,7 @@ static SSDataBlock* getTableDataBlockTemp(void* param) {
|
|||
continue;
|
||||
}
|
||||
|
||||
uint64_t* groupId = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t));
|
||||
if (groupId) {
|
||||
pBlock->info.groupId = *groupId;
|
||||
}
|
||||
pBlock->info.groupId = getTableGroupId(pOperator->pTaskInfo->pTableInfoList, pBlock->info.uid);
|
||||
|
||||
pOperator->resultInfo.totalRows += pBlock->info.rows; // pTableScanInfo->readRecorder.totalRows;
|
||||
pTableScanInfo->readRecorder.elapsedTime += (taosGetTimestampUs() - st) / 1000.0;
|
||||
|
@ -4613,11 +4627,7 @@ static SSDataBlock* getTableDataBlock2(void* param) {
|
|||
continue;
|
||||
}
|
||||
|
||||
uint64_t* groupId = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t));
|
||||
if (groupId) {
|
||||
pBlock->info.groupId = *groupId;
|
||||
}
|
||||
|
||||
pBlock->info.groupId = getTableGroupId(pOperator->pTaskInfo->pTableInfoList, pBlock->info.uid);
|
||||
pOperator->resultInfo.totalRows = pTableScanInfo->readRecorder.totalRows;
|
||||
pTableScanInfo->readRecorder.elapsedTime += (taosGetTimestampUs() - st) / 1000.0;
|
||||
|
||||
|
@ -4661,6 +4671,7 @@ static SSDataBlock* getTableDataBlock(void* param) {
|
|||
|
||||
uint32_t status = 0;
|
||||
int32_t code = loadDataBlockFromOneTable(pOperator, pTableScanInfo, readerIdx, pBlock, &status);
|
||||
// int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
T_LONG_JMP(pOperator->pTaskInfo->env, code);
|
||||
}
|
||||
|
@ -4670,11 +4681,7 @@ static SSDataBlock* getTableDataBlock(void* param) {
|
|||
continue;
|
||||
}
|
||||
|
||||
uint64_t* groupId = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t));
|
||||
if (groupId) {
|
||||
pBlock->info.groupId = *groupId;
|
||||
}
|
||||
|
||||
pBlock->info.groupId = getTableGroupId(pOperator->pTaskInfo->pTableInfoList, pBlock->info.uid);
|
||||
pOperator->resultInfo.totalRows = pTableScanInfo->readRecorder.totalRows;
|
||||
pTableScanInfo->readRecorder.elapsedTime += (taosGetTimestampUs() - st) / 1000.0;
|
||||
|
||||
|
@ -4711,15 +4718,16 @@ int32_t dumpSQueryTableCond(const SQueryTableDataCond* src, SQueryTableDataCond*
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) {
|
||||
STableMergeScanInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
{
|
||||
size_t tableListSize = taosArrayGetSize(pInfo->tableListInfo->pTableList);
|
||||
size_t numOfTables = tableListGetSize(pInfo->tableListInfo);
|
||||
int32_t i = pInfo->tableStartIndex + 1;
|
||||
for (; i < tableListSize; ++i) {
|
||||
STableKeyInfo* tableKeyInfo = taosArrayGet(pInfo->tableListInfo->pTableList, i);
|
||||
for (; i < numOfTables; ++i) {
|
||||
STableKeyInfo* tableKeyInfo = tableListGetInfo(pInfo->tableListInfo, i);
|
||||
if (tableKeyInfo->groupId != pInfo->groupId) {
|
||||
break;
|
||||
}
|
||||
|
@ -4730,10 +4738,8 @@ int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) {
|
|||
int32_t tableStartIdx = pInfo->tableStartIndex;
|
||||
int32_t tableEndIdx = pInfo->tableEndIndex;
|
||||
|
||||
STableListInfo* tableListInfo = pInfo->tableListInfo;
|
||||
|
||||
// pInfo->dataReaders = taosArrayInit(64, POINTER_BYTES);
|
||||
pInfo->pReader = NULL;
|
||||
|
||||
// todo the total available buffer should be determined by total capacity of buffer of this task.
|
||||
// the additional one is reserved for merge result
|
||||
pInfo->sortBufSize = pInfo->bufPageSize * (tableEndIdx - tableStartIdx + 1 + 1);
|
||||
|
@ -4748,8 +4754,6 @@ int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) {
|
|||
pInfo->queryConds = taosArrayInit(numOfTable, sizeof(SQueryTableDataCond));
|
||||
|
||||
for (int32_t i = 0; i < numOfTable; ++i) {
|
||||
STableKeyInfo* tableKeyInfo = taosArrayGet(pInfo->tableListInfo->pTableList, i + tableStartIdx);
|
||||
|
||||
STableMergeScanSortSourceParam param = {0};
|
||||
param.readerIdx = i;
|
||||
param.pOperator = pOperator;
|
||||
|
@ -4848,7 +4852,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
|||
T_LONG_JMP(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
size_t tableListSize = taosArrayGetSize(pInfo->tableListInfo->pTableList);
|
||||
size_t tableListSize = tableListGetSize(pInfo->tableListInfo);
|
||||
if (!pInfo->hasGroupId) {
|
||||
pInfo->hasGroupId = true;
|
||||
|
||||
|
@ -4857,7 +4861,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
|||
return NULL;
|
||||
}
|
||||
pInfo->tableStartIndex = 0;
|
||||
pInfo->groupId = ((STableKeyInfo*)taosArrayGet(pInfo->tableListInfo->pTableList, pInfo->tableStartIndex))->groupId;
|
||||
pInfo->groupId = ((STableKeyInfo*)tableListGetInfo(pInfo->tableListInfo, pInfo->tableStartIndex))->groupId;
|
||||
startGroupTableMergeScan(pOperator);
|
||||
}
|
||||
|
||||
|
@ -4876,8 +4880,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
|
|||
break;
|
||||
}
|
||||
pInfo->tableStartIndex = pInfo->tableEndIndex + 1;
|
||||
pInfo->groupId =
|
||||
((STableKeyInfo*)taosArrayGet(pInfo->tableListInfo->pTableList, pInfo->tableStartIndex))->groupId;
|
||||
pInfo->groupId = tableListGetInfo(pInfo->tableListInfo, pInfo->tableStartIndex)->groupId;
|
||||
startGroupTableMergeScan(pOperator);
|
||||
}
|
||||
}
|
||||
|
@ -4892,9 +4895,10 @@ void destroyTableMergeScanOperatorInfo(void* param) {
|
|||
int32_t numOfTable = taosArrayGetSize(pTableScanInfo->queryConds);
|
||||
|
||||
for (int32_t i = 0; i < numOfTable; i++) {
|
||||
STableMergeScanSortSourceParam* param = taosArrayGet(pTableScanInfo->sortSourceParams, i);
|
||||
blockDataDestroy(param->inputBlock);
|
||||
STableMergeScanSortSourceParam* p = taosArrayGet(pTableScanInfo->sortSourceParams, i);
|
||||
blockDataDestroy(p->inputBlock);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pTableScanInfo->sortSourceParams);
|
||||
|
||||
tsdbReaderClose(pTableScanInfo->pReader);
|
||||
|
@ -4959,10 +4963,6 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
|||
goto _error;
|
||||
}
|
||||
|
||||
if (pTableScanNode->pGroupTags) {
|
||||
taosArraySort(pTableListInfo->pTableList, compareTableKeyInfoByGid);
|
||||
}
|
||||
|
||||
SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc;
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
|
|
|
@ -1687,7 +1687,9 @@ void initIntervalDownStream(SOperatorInfo* downstream, uint16_t type, SAggSuppor
|
|||
SStreamScanInfo* pScanInfo = downstream->info;
|
||||
pScanInfo->windowSup.parentType = type;
|
||||
pScanInfo->windowSup.pIntervalAggSup = pSup;
|
||||
pScanInfo->pUpdateInfo = updateInfoInitP(pInterval, pTwSup->waterMark);
|
||||
if (!pScanInfo->pUpdateInfo) {
|
||||
pScanInfo->pUpdateInfo = updateInfoInitP(pInterval, pTwSup->waterMark);
|
||||
}
|
||||
pScanInfo->interval = *pInterval;
|
||||
pScanInfo->twAggSup = *pTwSup;
|
||||
}
|
||||
|
@ -5385,6 +5387,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
|||
|
||||
maxTs = TMAX(maxTs, pBlock->info.window.ekey);
|
||||
minTs = TMIN(minTs, pBlock->info.window.skey);
|
||||
|
||||
doStreamIntervalAggImpl(pOperator, pBlock, pBlock->info.groupId, pUpdatedMap);
|
||||
}
|
||||
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs);
|
||||
|
|
|
@ -117,10 +117,29 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
|||
char dnodeIdEnvItem[32] = {0};
|
||||
char thrdPoolSizeEnvItem[32] = {0};
|
||||
snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId);
|
||||
|
||||
float numCpuCores = 4;
|
||||
taosGetCpuCores(&numCpuCores);
|
||||
snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores * 2);
|
||||
char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, NULL};
|
||||
|
||||
char pathTaosdLdLib[512] = {0};
|
||||
size_t taosdLdLibPathLen = sizeof(pathTaosdLdLib);
|
||||
uv_os_getenv("LD_LIBRARY_PATH", pathTaosdLdLib, &taosdLdLibPathLen);
|
||||
|
||||
char udfdPathLdLib[1024] = {0};
|
||||
size_t udfdLdLibPathLen = strlen(tsUdfdLdLibPath);
|
||||
strncpy(udfdPathLdLib, tsUdfdLdLibPath, udfdLdLibPathLen);
|
||||
udfdPathLdLib[udfdLdLibPathLen] = ':';
|
||||
strncpy(udfdPathLdLib + udfdLdLibPathLen + 1, pathTaosdLdLib, sizeof(udfdPathLdLib) - udfdLdLibPathLen);
|
||||
if (udfdLdLibPathLen + taosdLdLibPathLen < 1024) {
|
||||
fnInfo("udfd LD_LIBRARY_PATH: %s", udfdPathLdLib);
|
||||
} else {
|
||||
fnError("can not set correct udfd LD_LIBRARY_PATH");
|
||||
}
|
||||
char ldLibPathEnvItem[1024 + 32] = {0};
|
||||
snprintf(ldLibPathEnvItem, 1024 + 32, "%s=%s", "LD_LIBRARY_PATH", udfdPathLdLib);
|
||||
|
||||
char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, ldLibPathEnvItem, NULL};
|
||||
options.env = envUdfd;
|
||||
|
||||
int err = uv_spawn(&pData->loop, &pData->process, &options);
|
||||
|
|
|
@ -617,8 +617,6 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) {
|
|||
indexError("failed to write data: %s, offset: %d len: %d", v->colVal, v->offset,
|
||||
(int)taosArrayGetSize(v->tableId));
|
||||
} else {
|
||||
indexInfo("success to write data: %s, offset: %d len: %d", v->colVal, v->offset,
|
||||
(int)taosArrayGetSize(v->tableId));
|
||||
}
|
||||
}
|
||||
fstBuilderDestroy(tw->fb);
|
||||
|
|
|
@ -182,7 +182,7 @@ SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const ST
|
|||
SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal);
|
||||
SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName);
|
||||
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
|
||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
|
||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, bool force);
|
||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue);
|
||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SNode* pIndexName,
|
||||
SNode* pRealTable, SNodeList* pCols, SNode* pOptions);
|
||||
|
|
|
@ -120,8 +120,8 @@ priv_level(A) ::= db_name(B) NK_DOT NK_STAR.
|
|||
/************************************************ create/drop/alter dnode *********************************************/
|
||||
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
|
||||
cmd ::= CREATE DNODE dnode_endpoint(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); }
|
||||
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
|
||||
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
|
||||
cmd ::= DROP DNODE NK_INTEGER(A) force_opt(B). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A, B); }
|
||||
cmd ::= DROP DNODE dnode_endpoint(A) force_opt(B). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A, B); }
|
||||
cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, NULL); }
|
||||
cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B) NK_STRING(C). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, &C); }
|
||||
cmd ::= ALTER ALL DNODES NK_STRING(A). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &A, NULL); }
|
||||
|
@ -133,6 +133,11 @@ dnode_endpoint(A) ::= NK_STRING(B).
|
|||
dnode_endpoint(A) ::= NK_ID(B). { A = B; }
|
||||
dnode_endpoint(A) ::= NK_IPTOKEN(B). { A = B; }
|
||||
|
||||
%type force_opt { bool }
|
||||
%destructor force_opt { }
|
||||
force_opt(A) ::= . { A = false; }
|
||||
force_opt(A) ::= FORCE. { A = true; }
|
||||
|
||||
/************************************************ alter local *********************************************************/
|
||||
cmd ::= ALTER LOCAL NK_STRING(A). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, NULL); }
|
||||
cmd ::= ALTER LOCAL NK_STRING(A) NK_STRING(B). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, &B); }
|
||||
|
|
|
@ -1457,7 +1457,7 @@ SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
|
||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, bool force) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropDnodeStmt* pStmt = (SDropDnodeStmt*)nodesMakeNode(QUERY_NODE_DROP_DNODE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
|
@ -1469,6 +1469,7 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
pStmt->force = force;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ static SKeyword keywordTable[] = {
|
|||
{"FLOAT", TK_FLOAT},
|
||||
{"FLUSH", TK_FLUSH},
|
||||
{"FROM", TK_FROM},
|
||||
{"FORCE", TK_FORCE},
|
||||
{"FUNCTION", TK_FUNCTION},
|
||||
{"FUNCTIONS", TK_FUNCTIONS},
|
||||
{"GRANT", TK_GRANT},
|
||||
|
|
|
@ -674,6 +674,10 @@ static bool isSelectFunc(const SNode* pNode) {
|
|||
return (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsSelectFunc(((SFunctionNode*)pNode)->funcId));
|
||||
}
|
||||
|
||||
static bool isWindowPseudoColumnFunc(const SNode* pNode) {
|
||||
return (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsWindowPseudoColumnFunc(((SFunctionNode*)pNode)->funcId));
|
||||
}
|
||||
|
||||
static bool isTimelineFunc(const SNode* pNode) {
|
||||
return (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsTimelineFunc(((SFunctionNode*)pNode)->funcId));
|
||||
}
|
||||
|
@ -1264,10 +1268,7 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
|||
}
|
||||
|
||||
static EDealRes haveVectorFunction(SNode* pNode, void* pContext) {
|
||||
if (isAggFunc(pNode)) {
|
||||
*((bool*)pContext) = true;
|
||||
return DEAL_RES_END;
|
||||
} else if (isIndefiniteRowsFunc(pNode)) {
|
||||
if (isAggFunc(pNode) || isIndefiniteRowsFunc(pNode) || isWindowPseudoColumnFunc(pNode)) {
|
||||
*((bool*)pContext) = true;
|
||||
return DEAL_RES_END;
|
||||
}
|
||||
|
@ -4995,6 +4996,7 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt
|
|||
dropReq.dnodeId = pStmt->dnodeId;
|
||||
strcpy(dropReq.fqdn, pStmt->fqdn);
|
||||
dropReq.port = pStmt->port;
|
||||
dropReq.force = pStmt->force;
|
||||
|
||||
return buildCmdMsg(pCxt, TDMT_MND_DROP_DNODE, (FSerializeFunc)tSerializeSDropDnodeReq, &dropReq);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -87,7 +87,6 @@ TEST_F(ParserInitialDTest, dropConsumerGroup) {
|
|||
|
||||
// todo DROP database
|
||||
|
||||
// todo DROP dnode
|
||||
TEST_F(ParserInitialDTest, dropDnode) {
|
||||
useDb("root", "test");
|
||||
|
||||
|
@ -95,11 +94,15 @@ TEST_F(ParserInitialDTest, dropDnode) {
|
|||
|
||||
auto clearDropDnodeReq = [&]() { memset(&expect, 0, sizeof(SDropDnodeReq)); };
|
||||
|
||||
auto setDropDnodeReqById = [&](int32_t dnodeId) { expect.dnodeId = dnodeId; };
|
||||
auto setDropDnodeReqById = [&](int32_t dnodeId, bool force = false) {
|
||||
expect.dnodeId = dnodeId;
|
||||
expect.force = force;
|
||||
};
|
||||
|
||||
auto setDropDnodeReqByEndpoint = [&](const char* pFqdn, int32_t port) {
|
||||
auto setDropDnodeReqByEndpoint = [&](const char* pFqdn, int32_t port, bool force = false) {
|
||||
strcpy(expect.fqdn, pFqdn);
|
||||
expect.port = port;
|
||||
expect.force = force;
|
||||
};
|
||||
|
||||
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
|
||||
|
@ -110,15 +113,24 @@ TEST_F(ParserInitialDTest, dropDnode) {
|
|||
ASSERT_EQ(req.dnodeId, expect.dnodeId);
|
||||
ASSERT_EQ(std::string(req.fqdn), std::string(expect.fqdn));
|
||||
ASSERT_EQ(req.port, expect.port);
|
||||
ASSERT_EQ(req.force, expect.force);
|
||||
});
|
||||
|
||||
setDropDnodeReqById(1);
|
||||
run("DROP DNODE 1");
|
||||
clearDropDnodeReq();
|
||||
|
||||
setDropDnodeReqById(2, true);
|
||||
run("DROP DNODE 2 FORCE");
|
||||
clearDropDnodeReq();
|
||||
|
||||
setDropDnodeReqByEndpoint("host1", 7030);
|
||||
run("DROP DNODE 'host1:7030'");
|
||||
clearDropDnodeReq();
|
||||
|
||||
setDropDnodeReqByEndpoint("host2", 8030, true);
|
||||
run("DROP DNODE 'host2:8030' FORCE");
|
||||
clearDropDnodeReq();
|
||||
}
|
||||
|
||||
// todo DROP function
|
||||
|
|
|
@ -20,21 +20,15 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "syncInt.h"
|
||||
#include "taosdef.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
#define TIMER_MAX_MS 0x7FFFFFFF
|
||||
#define ENV_TICK_TIMER_MS 1000
|
||||
#define PING_TIMER_MS 5000
|
||||
#define ELECT_TIMER_MS_MIN 5000
|
||||
#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2)
|
||||
#define TIMER_MAX_MS 0x7FFFFFFF
|
||||
#define ENV_TICK_TIMER_MS 1000
|
||||
#define PING_TIMER_MS 5000
|
||||
#define ELECT_TIMER_MS_MIN 2500
|
||||
#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2)
|
||||
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
|
||||
#define HEARTBEAT_TIMER_MS 900
|
||||
#define HEARTBEAT_TIMER_MS 1000
|
||||
|
||||
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
||||
|
||||
|
@ -57,12 +51,12 @@ typedef struct SSyncEnv {
|
|||
|
||||
} SSyncEnv;
|
||||
|
||||
extern SSyncEnv* gSyncEnv;
|
||||
SSyncEnv* syncEnv();
|
||||
|
||||
int32_t syncEnvStart();
|
||||
int32_t syncEnvStop();
|
||||
int32_t syncEnvStartTimer();
|
||||
int32_t syncEnvStopTimer();
|
||||
int64_t syncNodeAdd(SSyncNode* pNode);
|
||||
void syncNodeRemove(int64_t rid);
|
||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
||||
void syncNodeRelease(SSyncNode* pNode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ extern "C" {
|
|||
#include "syncTools.h"
|
||||
#include "tlog.h"
|
||||
#include "ttimer.h"
|
||||
#include "taosdef.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
// clang-format off
|
||||
#define sFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||
|
@ -255,9 +257,6 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, Sync
|
|||
SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode);
|
||||
char* syncNodePeerState2Str(const SSyncNode* pSyncNode);
|
||||
|
||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
||||
void syncNodeRelease(SSyncNode* pNode);
|
||||
|
||||
// raft state change --------------
|
||||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term);
|
||||
void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term);
|
||||
|
@ -302,9 +301,6 @@ bool syncNodeNeedSendAppendEntries(SSyncNode* ths, const SRaftId* pDestId, const
|
|||
int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
|
||||
int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta);
|
||||
|
||||
void syncStartNormal(int64_t rid);
|
||||
void syncStartStandBy(int64_t rid);
|
||||
|
||||
bool syncNodeCanChange(SSyncNode* pSyncNode);
|
||||
bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg);
|
||||
|
||||
|
@ -341,6 +337,8 @@ void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const
|
|||
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
||||
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
||||
|
||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s);
|
||||
|
||||
// for debug --------------
|
||||
void syncNodePrint(SSyncNode* pObj);
|
||||
void syncNodePrint2(char* s, SSyncNode* pObj);
|
||||
|
|
|
@ -13,118 +13,111 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncEnv.h"
|
||||
// #include <ASSERT.h>
|
||||
#include "tref.h"
|
||||
|
||||
SSyncEnv *gSyncEnv = NULL;
|
||||
static SSyncEnv gSyncEnv = {0};
|
||||
static int32_t gNodeRefId = -1;
|
||||
bool gRaftDetailLog = false;
|
||||
static void syncEnvTick(void *param, void *tmrId);
|
||||
|
||||
// local function -----------------
|
||||
static SSyncEnv *doSyncEnvStart();
|
||||
static int32_t doSyncEnvStop(SSyncEnv *pSyncEnv);
|
||||
static int32_t doSyncEnvStartTimer(SSyncEnv *pSyncEnv);
|
||||
static int32_t doSyncEnvStopTimer(SSyncEnv *pSyncEnv);
|
||||
static void syncEnvTick(void *param, void *tmrId);
|
||||
// --------------------------------
|
||||
SSyncEnv *syncEnv() { return &gSyncEnv; }
|
||||
|
||||
bool syncEnvIsStart() {
|
||||
if (gSyncEnv == NULL) {
|
||||
return false;
|
||||
}
|
||||
bool syncIsInit() { return atomic_load_8(&gSyncEnv.isStart); }
|
||||
|
||||
return atomic_load_8(&(gSyncEnv->isStart));
|
||||
}
|
||||
int32_t syncInit() {
|
||||
if (syncIsInit()) return 0;
|
||||
|
||||
int32_t syncEnvStart() {
|
||||
int32_t ret = 0;
|
||||
uint32_t seed = (uint32_t)(taosGetTimestampNs() & 0x00000000FFFFFFFF);
|
||||
taosSeedRand(seed);
|
||||
// gSyncEnv = doSyncEnvStart(gSyncEnv);
|
||||
gSyncEnv = doSyncEnvStart();
|
||||
ASSERT(gSyncEnv != NULL);
|
||||
sTrace("sync env start ok");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncEnvStop() {
|
||||
int32_t ret = doSyncEnvStop(gSyncEnv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncEnvStartTimer() {
|
||||
int32_t ret = doSyncEnvStartTimer(gSyncEnv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncEnvStopTimer() {
|
||||
int32_t ret = doSyncEnvStopTimer(gSyncEnv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// local function -----------------
|
||||
static void syncEnvTick(void *param, void *tmrId) {
|
||||
SSyncEnv *pSyncEnv = (SSyncEnv *)param;
|
||||
if (atomic_load_64(&pSyncEnv->envTickTimerLogicClockUser) <= atomic_load_64(&pSyncEnv->envTickTimerLogicClock)) {
|
||||
++(pSyncEnv->envTickTimerCounter);
|
||||
sTrace("syncEnvTick do ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64
|
||||
", envTickTimerCounter:%" PRIu64
|
||||
", "
|
||||
"envTickTimerMS:%d, tmrId:%p",
|
||||
pSyncEnv->envTickTimerLogicClockUser, pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerCounter,
|
||||
pSyncEnv->envTickTimerMS, tmrId);
|
||||
|
||||
// do something, tick ...
|
||||
taosTmrReset(syncEnvTick, pSyncEnv->envTickTimerMS, pSyncEnv, pSyncEnv->pTimerManager, &pSyncEnv->pEnvTickTimer);
|
||||
} else {
|
||||
sTrace("syncEnvTick pass ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64
|
||||
", envTickTimerCounter:%" PRIu64
|
||||
", "
|
||||
"envTickTimerMS:%d, tmrId:%p",
|
||||
pSyncEnv->envTickTimerLogicClockUser, pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerCounter,
|
||||
pSyncEnv->envTickTimerMS, tmrId);
|
||||
}
|
||||
}
|
||||
|
||||
static SSyncEnv *doSyncEnvStart() {
|
||||
SSyncEnv *pSyncEnv = (SSyncEnv *)taosMemoryMalloc(sizeof(SSyncEnv));
|
||||
ASSERT(pSyncEnv != NULL);
|
||||
memset(pSyncEnv, 0, sizeof(SSyncEnv));
|
||||
|
||||
pSyncEnv->envTickTimerCounter = 0;
|
||||
pSyncEnv->envTickTimerMS = ENV_TICK_TIMER_MS;
|
||||
pSyncEnv->FpEnvTickTimer = syncEnvTick;
|
||||
atomic_store_64(&pSyncEnv->envTickTimerLogicClock, 0);
|
||||
atomic_store_64(&pSyncEnv->envTickTimerLogicClockUser, 0);
|
||||
memset(&gSyncEnv, 0, sizeof(SSyncEnv));
|
||||
gSyncEnv.envTickTimerCounter = 0;
|
||||
gSyncEnv.envTickTimerMS = ENV_TICK_TIMER_MS;
|
||||
gSyncEnv.FpEnvTickTimer = syncEnvTick;
|
||||
atomic_store_64(&gSyncEnv.envTickTimerLogicClock, 0);
|
||||
atomic_store_64(&gSyncEnv.envTickTimerLogicClockUser, 0);
|
||||
|
||||
// start tmr thread
|
||||
pSyncEnv->pTimerManager = taosTmrInit(1000, 50, 10000, "SYNC-ENV");
|
||||
gSyncEnv.pTimerManager = taosTmrInit(1000, 50, 10000, "SYNC-ENV");
|
||||
atomic_store_8(&gSyncEnv.isStart, 1);
|
||||
|
||||
atomic_store_8(&(pSyncEnv->isStart), 1);
|
||||
return pSyncEnv;
|
||||
}
|
||||
|
||||
static int32_t doSyncEnvStop(SSyncEnv *pSyncEnv) {
|
||||
ASSERT(pSyncEnv == gSyncEnv);
|
||||
if (pSyncEnv != NULL) {
|
||||
atomic_store_8(&(pSyncEnv->isStart), 0);
|
||||
taosTmrCleanUp(pSyncEnv->pTimerManager);
|
||||
taosMemoryFree(pSyncEnv);
|
||||
gNodeRefId = taosOpenRef(200, (RefFp)syncNodeClose);
|
||||
if (gNodeRefId < 0) {
|
||||
sError("failed to init node ref");
|
||||
syncCleanUp();
|
||||
return -1;
|
||||
}
|
||||
gSyncEnv = NULL;
|
||||
|
||||
sDebug("sync rsetId:%d is open", gNodeRefId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t doSyncEnvStartTimer(SSyncEnv *pSyncEnv) {
|
||||
int32_t ret = 0;
|
||||
taosTmrReset(pSyncEnv->FpEnvTickTimer, pSyncEnv->envTickTimerMS, pSyncEnv, pSyncEnv->pTimerManager,
|
||||
&pSyncEnv->pEnvTickTimer);
|
||||
atomic_store_64(&pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerLogicClockUser);
|
||||
return ret;
|
||||
void syncCleanUp() {
|
||||
atomic_store_8(&gSyncEnv.isStart, 0);
|
||||
taosTmrCleanUp(gSyncEnv.pTimerManager);
|
||||
memset(&gSyncEnv, 0, sizeof(SSyncEnv));
|
||||
|
||||
if (gNodeRefId != -1) {
|
||||
sDebug("sync rsetId:%d is closed", gNodeRefId);
|
||||
taosCloseRef(gNodeRefId);
|
||||
gNodeRefId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t doSyncEnvStopTimer(SSyncEnv *pSyncEnv) {
|
||||
int64_t syncNodeAdd(SSyncNode *pNode) {
|
||||
pNode->rid = taosAddRef(gNodeRefId, pNode);
|
||||
if (pNode->rid < 0) return -1;
|
||||
|
||||
sDebug("vgId:%d, sync rid:%" PRId64 " is added to rsetId:%d", pNode->vgId, pNode->rid, gNodeRefId);
|
||||
return pNode->rid;
|
||||
}
|
||||
|
||||
void syncNodeRemove(int64_t rid) { taosRemoveRef(gNodeRefId, rid); }
|
||||
|
||||
SSyncNode *syncNodeAcquire(int64_t rid) {
|
||||
SSyncNode *pNode = taosAcquireRef(gNodeRefId, rid);
|
||||
if (pNode == NULL) {
|
||||
sTrace("failed to acquire node from refId:%" PRId64, rid);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
void syncNodeRelease(SSyncNode *pNode) { taosReleaseRef(gNodeRefId, pNode->rid); }
|
||||
|
||||
#if 0
|
||||
void syncEnvStartTimer() {
|
||||
taosTmrReset(gSyncEnv.FpEnvTickTimer, gSyncEnv.envTickTimerMS, &gSyncEnv, gSyncEnv.pTimerManager,
|
||||
&gSyncEnv.pEnvTickTimer);
|
||||
atomic_store_64(&gSyncEnv.envTickTimerLogicClock, gSyncEnv.envTickTimerLogicClockUser);
|
||||
}
|
||||
|
||||
void syncEnvStopTimer() {
|
||||
int32_t ret = 0;
|
||||
atomic_add_fetch_64(&pSyncEnv->envTickTimerLogicClockUser, 1);
|
||||
taosTmrStop(pSyncEnv->pEnvTickTimer);
|
||||
pSyncEnv->pEnvTickTimer = NULL;
|
||||
atomic_add_fetch_64(&gSyncEnv.envTickTimerLogicClockUser, 1);
|
||||
taosTmrStop(gSyncEnv.pEnvTickTimer);
|
||||
gSyncEnv.pEnvTickTimer = NULL;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void syncEnvTick(void *param, void *tmrId) {
|
||||
SSyncEnv *pSyncEnv = param;
|
||||
if (atomic_load_64(&gSyncEnv.envTickTimerLogicClockUser) <= atomic_load_64(&gSyncEnv.envTickTimerLogicClock)) {
|
||||
gSyncEnv.envTickTimerCounter++;
|
||||
sTrace("syncEnvTick do ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64
|
||||
", envTickTimerCounter:%" PRIu64 ", envTickTimerMS:%d, tmrId:%p",
|
||||
gSyncEnv.envTickTimerLogicClockUser, gSyncEnv.envTickTimerLogicClock, gSyncEnv.envTickTimerCounter,
|
||||
gSyncEnv.envTickTimerMS, tmrId);
|
||||
|
||||
// do something, tick ...
|
||||
taosTmrReset(syncEnvTick, gSyncEnv.envTickTimerMS, pSyncEnv, gSyncEnv.pTimerManager, &gSyncEnv.pEnvTickTimer);
|
||||
} else {
|
||||
sTrace("syncEnvTick pass ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64
|
||||
", envTickTimerCounter:%" PRIu64 ", envTickTimerMS:%d, tmrId:%p",
|
||||
gSyncEnv.envTickTimerLogicClockUser, gSyncEnv.envTickTimerLogicClock, gSyncEnv.envTickTimerCounter,
|
||||
gSyncEnv.envTickTimerMS, tmrId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,11 +33,6 @@
|
|||
#include "syncTimeout.h"
|
||||
#include "syncUtil.h"
|
||||
#include "syncVoteMgr.h"
|
||||
#include "tref.h"
|
||||
|
||||
bool gRaftDetailLog = false;
|
||||
|
||||
static int32_t tsNodeRefId = -1;
|
||||
|
||||
// ------ local funciton ---------
|
||||
// enqueue message ----
|
||||
|
@ -47,143 +42,42 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId);
|
|||
static int32_t syncNodeEqNoop(SSyncNode* ths);
|
||||
static int32_t syncNodeAppendNoop(SSyncNode* ths);
|
||||
static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId);
|
||||
static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg);
|
||||
|
||||
// process message ----
|
||||
int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg);
|
||||
int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
|
||||
// ---------------------------------
|
||||
static void syncNodeFreeCb(void* param) {
|
||||
syncNodeClose(param);
|
||||
param = NULL;
|
||||
}
|
||||
|
||||
int32_t syncInit() {
|
||||
int32_t ret = 0;
|
||||
|
||||
if (!syncEnvIsStart()) {
|
||||
tsNodeRefId = taosOpenRef(200, syncNodeFreeCb);
|
||||
if (tsNodeRefId < 0) {
|
||||
sError("failed to init node ref");
|
||||
syncCleanUp();
|
||||
ret = -1;
|
||||
} else {
|
||||
sDebug("sync rsetId:%d is open", tsNodeRefId);
|
||||
ret = syncEnvStart();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void syncCleanUp() {
|
||||
int32_t ret = syncEnvStop();
|
||||
ASSERT(ret == 0);
|
||||
|
||||
if (tsNodeRefId != -1) {
|
||||
sDebug("sync rsetId:%d is closed", tsNodeRefId);
|
||||
taosCloseRef(tsNodeRefId);
|
||||
tsNodeRefId = -1;
|
||||
}
|
||||
}
|
||||
int32_t syncNodeOnPing(SSyncNode* ths, SyncPing* pMsg);
|
||||
int32_t syncNodeOnPingReply(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
|
||||
int64_t syncOpen(SSyncInfo* pSyncInfo) {
|
||||
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo);
|
||||
if (pSyncNode == NULL) {
|
||||
SSyncNode* pNode = syncNodeOpen(pSyncInfo);
|
||||
if (pNode == NULL) {
|
||||
sError("vgId:%d, failed to open sync node", pSyncInfo->vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pSyncNode->rid = taosAddRef(tsNodeRefId, pSyncNode);
|
||||
if (pSyncNode->rid < 0) {
|
||||
syncNodeClose(pSyncNode);
|
||||
pSyncNode = NULL;
|
||||
pNode->rid = syncNodeAdd(pNode);
|
||||
if (pNode->rid < 0) {
|
||||
syncNodeClose(pNode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sDebug("vgId:%d, sync rid:%" PRId64 " is added to rsetId:%d", pSyncInfo->vgId, pSyncNode->rid, tsNodeRefId);
|
||||
return pSyncNode->rid;
|
||||
return pNode->rid;
|
||||
}
|
||||
|
||||
void syncStart(int64_t rid) {
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
SSyncNode* pNode = syncNodeAcquire(rid);
|
||||
if (pNode != NULL) {
|
||||
syncNodeStart(pNode);
|
||||
syncNodeRelease(pNode);
|
||||
}
|
||||
|
||||
if (pSyncNode->pRaftCfg->isStandBy) {
|
||||
syncNodeStartStandBy(pSyncNode);
|
||||
} else {
|
||||
syncNodeStart(pSyncNode);
|
||||
}
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
}
|
||||
|
||||
void syncStartNormal(int64_t rid) {
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
syncNodeStart(pSyncNode);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
}
|
||||
|
||||
void syncStartStandBy(int64_t rid) {
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
syncNodeStartStandBy(pSyncNode);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
}
|
||||
|
||||
void syncStop(int64_t rid) {
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) return;
|
||||
int32_t vgId = pSyncNode->vgId;
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
|
||||
taosRemoveRef(tsNodeRefId, rid);
|
||||
sDebug("vgId:%d, sync rid:%" PRId64 " is removed from rsetId:%d", vgId, rid, tsNodeRefId);
|
||||
}
|
||||
|
||||
int32_t syncSetStandby(int64_t rid) {
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
sError("failed to set standby since accquire ref error, rid:%" PRId64, rid);
|
||||
return -1;
|
||||
SSyncNode* pNode = syncNodeAcquire(rid);
|
||||
if (pNode != NULL) {
|
||||
syncNodeRelease(pNode);
|
||||
syncNodeRemove(rid);
|
||||
}
|
||||
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||
terrno = TSDB_CODE_SYN_IS_LEADER;
|
||||
} else {
|
||||
terrno = TSDB_CODE_SYN_STANDBY_NOT_READY;
|
||||
}
|
||||
sError("failed to set standby since it is not follower, state:%s rid:%" PRId64, syncStr(pSyncNode->state), rid);
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// state change
|
||||
pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER;
|
||||
syncNodeStopHeartbeatTimer(pSyncNode);
|
||||
|
||||
// reset elect timer, long enough
|
||||
int32_t electMS = TIMER_MAX_MS;
|
||||
int32_t ret = syncNodeRestartElectTimer(pSyncNode, electMS);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
pSyncNode->pRaftCfg->isStandBy = 1;
|
||||
raftCfgPersist(pSyncNode->pRaftCfg);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
sInfo("vgId:%d, set to standby", pSyncNode->vgId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg) {
|
||||
|
@ -204,7 +98,7 @@ bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg) {
|
|||
}
|
||||
|
||||
int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
|
@ -213,7 +107,7 @@ int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg
|
|||
int32_t ret = 0;
|
||||
|
||||
if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) {
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR;
|
||||
sError("invalid new config. vgId:%d", pSyncNode->vgId);
|
||||
return -1;
|
||||
|
@ -227,12 +121,12 @@ int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg
|
|||
snprintf(pRpcMsg->pCont, pRpcMsg->contLen, "%s", newconfig);
|
||||
taosMemoryFree(newconfig);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
|
@ -240,7 +134,7 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) {
|
|||
ASSERT(rid == pSyncNode->rid);
|
||||
|
||||
if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) {
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR;
|
||||
sError("invalid new config. vgId:%d", pSyncNode->vgId);
|
||||
return -1;
|
||||
|
@ -259,7 +153,7 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) {
|
|||
taosMemoryFree(newconfig);
|
||||
ret = syncNodePropose(pSyncNode, &rpcMsg, false);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return ret;
|
||||
#else
|
||||
syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg);
|
||||
|
@ -275,13 +169,13 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) {
|
|||
|
||||
syncNodeReplicate(pSyncNode);
|
||||
}
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t syncLeaderTransfer(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
|
@ -289,12 +183,12 @@ int32_t syncLeaderTransfer(int64_t rid) {
|
|||
ASSERT(rid == pSyncNode->rid);
|
||||
|
||||
int32_t ret = syncNodeLeaderTransfer(pSyncNode);
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
|
@ -302,7 +196,7 @@ int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) {
|
|||
ASSERT(rid == pSyncNode->rid);
|
||||
|
||||
int32_t ret = syncNodeLeaderTransferTo(pSyncNode, newLeader);
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -358,7 +252,7 @@ char* syncNodePeerState2Str(const SSyncNode* pSyncNode) {
|
|||
}
|
||||
|
||||
int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
|
@ -382,7 +276,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
|||
logNum, isEmpty);
|
||||
syncNodeEventLog(pSyncNode, logBuf);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -411,7 +305,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
|||
syncNodeEventLog(pSyncNode, logBuf);
|
||||
} while (0);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -424,7 +318,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
|||
lastApplyIndex, pSyncNode->minMatchIndex);
|
||||
syncNodeEventLog(pSyncNode, logBuf);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -433,7 +327,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
|||
snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " candidate, do not delete wal", lastApplyIndex);
|
||||
syncNodeEventLog(pSyncNode, logBuf);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
|
@ -442,7 +336,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
|||
lastApplyIndex);
|
||||
syncNodeEventLog(pSyncNode, logBuf);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -491,12 +385,12 @@ _DEL_WAL:
|
|||
}
|
||||
} while (0);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t syncEndSnapshot(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
|
@ -508,9 +402,9 @@ int32_t syncEndSnapshot(int64_t rid) {
|
|||
SSyncLogStoreData* pData = pSyncNode->pLogStore->data;
|
||||
code = walEndSnapshot(pData->pWal);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, wal snapshot end error since:%s", pSyncNode->vgId, terrstr(terrno));
|
||||
sError("vgId:%d, wal snapshot end error since:%s", pSyncNode->vgId, terrstr());
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return -1;
|
||||
} else {
|
||||
do {
|
||||
|
@ -524,10 +418,24 @@ int32_t syncEndSnapshot(int64_t rid) {
|
|||
}
|
||||
}
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t syncStepDown(int64_t rid, SyncTerm newTerm) {
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
|
||||
syncNodeStepDown(pSyncNode, newTerm);
|
||||
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) {
|
||||
if (pSyncNode->peersNum == 0) {
|
||||
sDebug("only one replica, cannot leader transfer");
|
||||
|
@ -569,19 +477,19 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) {
|
|||
}
|
||||
|
||||
bool syncCanLeaderTransfer(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return false;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
|
||||
if (pSyncNode->replicaNum == 1) {
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -596,7 +504,7 @@ bool syncCanLeaderTransfer(int64_t rid) {
|
|||
}
|
||||
}
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return matchOK;
|
||||
}
|
||||
|
||||
|
@ -606,25 +514,25 @@ int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
|||
}
|
||||
|
||||
ESyncState syncGetMyRole(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return TAOS_SYNC_STATE_ERROR;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
ESyncState state = pSyncNode->state;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return state;
|
||||
}
|
||||
|
||||
bool syncIsReady(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return false;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
bool b = (pSyncNode->state == TAOS_SYNC_STATE_LEADER) && pSyncNode->restoreFinish;
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
||||
// if false, set error code
|
||||
if (false == b) {
|
||||
|
@ -638,14 +546,14 @@ bool syncIsReady(int64_t rid) {
|
|||
}
|
||||
|
||||
bool syncIsRestoreFinish(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return false;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
bool b = pSyncNode->restoreFinish;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -654,7 +562,7 @@ int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapsho
|
|||
return -1;
|
||||
}
|
||||
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -666,7 +574,7 @@ int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapsho
|
|||
if (pEntry != NULL) {
|
||||
syncEntryDestory(pEntry);
|
||||
}
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return -1;
|
||||
}
|
||||
ASSERT(pEntry != NULL);
|
||||
|
@ -677,12 +585,12 @@ int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapsho
|
|||
pSnapshot->lastConfigIndex = syncNodeGetSnapshotConfigIndex(pSyncNode, index);
|
||||
|
||||
syncEntryDestory(pEntry);
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -691,12 +599,12 @@ int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta) {
|
|||
|
||||
sTrace("vgId:%d, get snapshot meta, lastConfigIndex:%" PRId64, pSyncNode->vgId, pSyncNode->pRaftCfg->lastConfigIndex);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -715,7 +623,7 @@ int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct
|
|||
sTrace("vgId:%d, get snapshot meta by index:%" PRId64 " lcindex:%" PRId64, pSyncNode->vgId, snapshotIndex,
|
||||
sMeta->lastConfigIndex);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -741,67 +649,67 @@ const char* syncGetMyRoleStr(int64_t rid) {
|
|||
}
|
||||
|
||||
bool syncRestoreFinish(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return false;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
bool restoreFinish = pSyncNode->restoreFinish;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return restoreFinish;
|
||||
}
|
||||
|
||||
SyncTerm syncGetMyTerm(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return TAOS_SYNC_STATE_ERROR;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
SyncTerm term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return term;
|
||||
}
|
||||
|
||||
SyncIndex syncGetLastIndex(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return SYNC_INDEX_INVALID;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return lastIndex;
|
||||
}
|
||||
|
||||
SyncIndex syncGetCommitIndex(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return SYNC_INDEX_INVALID;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
SyncIndex cmtIndex = pSyncNode->commitIndex;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return cmtIndex;
|
||||
}
|
||||
|
||||
SyncGroupId syncGetVgId(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return TAOS_SYNC_STATE_ERROR;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
SyncGroupId vgId = pSyncNode->vgId;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return vgId;
|
||||
}
|
||||
|
||||
void syncGetEpSet(int64_t rid, SEpSet* pEpSet) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
memset(pEpSet, 0, sizeof(*pEpSet));
|
||||
return;
|
||||
|
@ -817,11 +725,11 @@ void syncGetEpSet(int64_t rid, SEpSet* pEpSet) {
|
|||
pEpSet->inUse = pSyncNode->pRaftCfg->cfg.myIndex;
|
||||
sInfo("vgId:%d, sync get epset in-use:%d", pSyncNode->vgId, pEpSet->inUse);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
}
|
||||
|
||||
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
memset(pEpSet, 0, sizeof(*pEpSet));
|
||||
return;
|
||||
|
@ -840,11 +748,11 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
|||
}
|
||||
sInfo("vgId:%d, sync get retry epset in-use:%d", pSyncNode->vgId, pEpSet->inUse);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
}
|
||||
|
||||
int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return TAOS_SYNC_STATE_ERROR;
|
||||
}
|
||||
|
@ -856,12 +764,12 @@ int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg) {
|
|||
memcpy(msg, &(stub.rpcMsg), sizeof(SRpcMsg));
|
||||
}
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return TAOS_SYNC_STATE_ERROR;
|
||||
}
|
||||
|
@ -874,12 +782,12 @@ int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo)
|
|||
}
|
||||
|
||||
sTrace("vgId:%d, get seq:%" PRIu64 " rpc handle:%p", pSyncNode->vgId, index, pInfo->handle);
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
sTrace("syncSetQ get pSyncNode is NULL, rid:%" PRId64, rid);
|
||||
return;
|
||||
|
@ -887,24 +795,24 @@ void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb) {
|
|||
ASSERT(rid == pSyncNode->rid);
|
||||
pSyncNode->msgcb = msgcb;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
}
|
||||
|
||||
char* sync2SimpleStr(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
sTrace("syncSetRpc get pSyncNode is NULL, rid:%" PRId64, rid);
|
||||
return NULL;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
char* s = syncNode2SimpleStr(pSyncNode);
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void setPingTimerMS(int64_t rid, int32_t pingTimerMS) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -912,22 +820,22 @@ void setPingTimerMS(int64_t rid, int32_t pingTimerMS) {
|
|||
pSyncNode->pingBaseLine = pingTimerMS;
|
||||
pSyncNode->pingTimerMS = pingTimerMS;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
}
|
||||
|
||||
void setElectTimerMS(int64_t rid, int32_t electTimerMS) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
pSyncNode->electBaseLine = electTimerMS;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
}
|
||||
|
||||
void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -935,20 +843,20 @@ void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS) {
|
|||
pSyncNode->hbBaseLine = hbTimerMS;
|
||||
pSyncNode->heartbeatTimerMS = hbTimerMS;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
}
|
||||
|
||||
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
taosReleaseRef(tsNodeRefId, rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
ASSERT(rid == pSyncNode->rid);
|
||||
|
||||
int32_t ret = syncNodePropose(pSyncNode, pMsg, isWeak);
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1070,7 +978,7 @@ int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId de
|
|||
|
||||
int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) {
|
||||
int32_t ret = 0;
|
||||
if (syncEnvIsStart()) {
|
||||
if (syncIsInit()) {
|
||||
SSyncHbTimerData* pData = taosMemoryMalloc(sizeof(SSyncHbTimerData));
|
||||
pData->pSyncNode = pSyncNode;
|
||||
pData->pTimer = pSyncTimer;
|
||||
|
@ -1078,7 +986,7 @@ int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) {
|
|||
pData->logicClock = pSyncTimer->logicClock;
|
||||
|
||||
pSyncTimer->pData = pData;
|
||||
taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS, pData, gSyncEnv->pTimerManager, &pSyncTimer->pTimer);
|
||||
taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS, pData, syncEnv()->pTimerManager, &pSyncTimer->pTimer);
|
||||
} else {
|
||||
sError("vgId:%d, start ctrl hb timer error, sync env is stop", pSyncNode->vgId);
|
||||
}
|
||||
|
@ -1132,7 +1040,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
|||
sError("vgId:%d, failed to open raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
||||
goto _error;
|
||||
}
|
||||
if (pSyncInfo->syncCfg.replicaNum > 0 && pSyncInfo->syncCfg.replicaNum != pSyncNode->pRaftCfg->cfg.replicaNum) {
|
||||
|
||||
if (pSyncInfo->syncCfg.replicaNum > 0 && syncIsConfigChanged(&pSyncNode->pRaftCfg->cfg, &pSyncInfo->syncCfg)) {
|
||||
sInfo("vgId:%d, use sync config from input options and write to cfg file", pSyncNode->vgId);
|
||||
pSyncNode->pRaftCfg->cfg = pSyncInfo->syncCfg;
|
||||
if (raftCfgPersist(pSyncNode->pRaftCfg) != 0) {
|
||||
|
@ -1327,8 +1236,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
|||
}
|
||||
|
||||
// init callback
|
||||
pSyncNode->FpOnPing = syncNodeOnPingCb;
|
||||
pSyncNode->FpOnPingReply = syncNodeOnPingReplyCb;
|
||||
pSyncNode->FpOnPing = syncNodeOnPing;
|
||||
pSyncNode->FpOnPingReply = syncNodeOnPingReply;
|
||||
pSyncNode->FpOnClientRequest = syncNodeOnClientRequest;
|
||||
pSyncNode->FpOnTimeout = syncNodeOnTimer;
|
||||
pSyncNode->FpOnSnapshot = syncNodeOnSnapshot;
|
||||
|
@ -1542,8 +1451,8 @@ int32_t syncNodePingAll(SSyncNode* pSyncNode) {
|
|||
// timer control --------------
|
||||
int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) {
|
||||
int32_t ret = 0;
|
||||
if (syncEnvIsStart()) {
|
||||
taosTmrReset(pSyncNode->FpPingTimerCB, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
||||
if (syncIsInit()) {
|
||||
taosTmrReset(pSyncNode->FpPingTimerCB, pSyncNode->pingTimerMS, pSyncNode, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pPingTimer);
|
||||
atomic_store_64(&pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser);
|
||||
} else {
|
||||
|
@ -1562,7 +1471,7 @@ int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) {
|
|||
|
||||
int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) {
|
||||
int32_t ret = 0;
|
||||
if (syncEnvIsStart()) {
|
||||
if (syncIsInit()) {
|
||||
pSyncNode->electTimerMS = ms;
|
||||
|
||||
SElectTimer* pElectTimer = taosMemoryMalloc(sizeof(SElectTimer));
|
||||
|
@ -1570,7 +1479,7 @@ int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) {
|
|||
pElectTimer->pSyncNode = pSyncNode;
|
||||
pElectTimer->pData = NULL;
|
||||
|
||||
taosTmrReset(pSyncNode->FpElectTimerCB, pSyncNode->electTimerMS, pElectTimer, gSyncEnv->pTimerManager,
|
||||
taosTmrReset(pSyncNode->FpElectTimerCB, pSyncNode->electTimerMS, pElectTimer, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pElectTimer);
|
||||
|
||||
} else {
|
||||
|
@ -1618,8 +1527,8 @@ int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode) {
|
|||
|
||||
static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) {
|
||||
int32_t ret = 0;
|
||||
if (syncEnvIsStart()) {
|
||||
taosTmrReset(pSyncNode->FpHeartbeatTimerCB, pSyncNode->heartbeatTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
||||
if (syncIsInit()) {
|
||||
taosTmrReset(pSyncNode->FpHeartbeatTimerCB, pSyncNode->heartbeatTimerMS, pSyncNode, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pHeartbeatTimer);
|
||||
atomic_store_64(&pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser);
|
||||
} else {
|
||||
|
@ -2095,12 +2004,11 @@ static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg
|
|||
|
||||
void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncIndex lastConfigChangeIndex) {
|
||||
SSyncCfg oldConfig = pSyncNode->pRaftCfg->cfg;
|
||||
#if 1
|
||||
if (!syncIsConfigChanged(&oldConfig, pNewConfig)) {
|
||||
sInfo("vgId:1, sync not reconfig since not changed");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
pSyncNode->pRaftCfg->cfg = *pNewConfig;
|
||||
pSyncNode->pRaftCfg->lastConfigIndex = lastConfigChangeIndex;
|
||||
|
||||
|
@ -2311,17 +2219,6 @@ _END:
|
|||
return;
|
||||
}
|
||||
|
||||
SSyncNode* syncNodeAcquire(int64_t rid) {
|
||||
SSyncNode* pNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pNode == NULL) {
|
||||
sTrace("failed to acquire node from refId:%" PRId64, rid);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
void syncNodeRelease(SSyncNode* pNode) { taosReleaseRef(tsNodeRefId, pNode->rid); }
|
||||
|
||||
// raft state change --------------
|
||||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
|
||||
if (term > pSyncNode->pRaftStore->currentTerm) {
|
||||
|
@ -2772,8 +2669,8 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
|||
}
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
|
||||
if (syncEnvIsStart()) {
|
||||
taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
||||
if (syncIsInit()) {
|
||||
taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pPingTimer);
|
||||
} else {
|
||||
sError("sync env is stop, syncNodeEqPingTimer");
|
||||
|
@ -2793,7 +2690,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
|||
pSyncNode->vgId, pSyncNode);
|
||||
SRpcMsg rpcMsg;
|
||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
if (pSyncNode->FpEqMsg != NULL) {
|
||||
if (pSyncNode->FpEqMsg != NULL && pSyncNode->msgcb != NULL && pSyncNode->msgcb->putToQueueFp != NULL) {
|
||||
int32_t code = pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, sync enqueue elect msg error, code:%d", pSyncNode->vgId, code);
|
||||
|
@ -2818,9 +2715,9 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
|||
|
||||
#if 0
|
||||
// reset timer ms
|
||||
if (syncEnvIsStart() && pSyncNode->electBaseLine > 0) {
|
||||
if (syncIsInit() && pSyncNode->electBaseLine > 0) {
|
||||
pSyncNode->electTimerMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine);
|
||||
taosTmrReset(syncNodeEqElectTimer, pSyncNode->electTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
||||
taosTmrReset(syncNodeEqElectTimer, pSyncNode->electTimerMS, pSyncNode, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pElectTimer);
|
||||
} else {
|
||||
sError("sync env is stop, syncNodeEqElectTimer");
|
||||
|
@ -2855,8 +2752,8 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
|
|||
}
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
|
||||
if (syncEnvIsStart()) {
|
||||
taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
||||
if (syncIsInit()) {
|
||||
taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pHeartbeatTimer);
|
||||
} else {
|
||||
sError("sync env is stop, syncNodeEqHeartbeatTimer");
|
||||
|
@ -2916,8 +2813,8 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
|||
|
||||
syncHeartbeatDestroy(pSyncMsg);
|
||||
|
||||
if (syncEnvIsStart()) {
|
||||
taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS, pData, gSyncEnv->pTimerManager,
|
||||
if (syncIsInit()) {
|
||||
taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS, pData, syncEnv()->pTimerManager,
|
||||
&pSyncTimer->pTimer);
|
||||
} else {
|
||||
sError("sync env is stop, syncNodeEqHeartbeatTimer");
|
||||
|
@ -3003,18 +2900,19 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
|
|||
}
|
||||
|
||||
// on message ----
|
||||
int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) {
|
||||
// log state
|
||||
int32_t syncNodeOnPing(SSyncNode* ths, SyncPing* pMsg) {
|
||||
sTrace("vgId:%d, recv sync-ping", ths->vgId);
|
||||
|
||||
SyncPingReply* pMsgReply = syncPingReplyBuild3(&ths->myRaftId, &pMsg->srcId, ths->vgId);
|
||||
SRpcMsg rpcMsg;
|
||||
syncPingReply2RpcMsg(pMsgReply, &rpcMsg);
|
||||
|
||||
/*
|
||||
// htonl
|
||||
SMsgHead* pHead = rpcMsg.pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
*/
|
||||
// htonl
|
||||
SMsgHead* pHead = rpcMsg.pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
*/
|
||||
|
||||
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||
syncPingReplyDestroy(pMsgReply);
|
||||
|
@ -3022,9 +2920,9 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) {
|
||||
int32_t syncNodeOnPingReply(SSyncNode* ths, SyncPingReply* pMsg) {
|
||||
int32_t ret = 0;
|
||||
syncPingReplyLog2("==syncNodeOnPingReplyCb==", pMsg);
|
||||
sTrace("vgId:%d, recv sync-ping-reply", ths->vgId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -3040,12 +2938,6 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
|||
SRpcMsg rpcMsg;
|
||||
syncHeartbeatReply2RpcMsg(pMsgReply, &rpcMsg);
|
||||
|
||||
#if 1
|
||||
if (pMsg->term >= ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||
syncNodeStepDown(ths, pMsg->term);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_LEADER) {
|
||||
syncNodeResetElectTimer(ths);
|
||||
ths->minMatchIndex = pMsg->minMatchIndex;
|
||||
|
@ -3057,6 +2949,28 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
|||
#endif
|
||||
}
|
||||
|
||||
if (pMsg->term >= ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||
// syncNodeStepDown(ths, pMsg->term);
|
||||
SyncLocalCmd* pSyncMsg = syncLocalCmdBuild(ths->vgId);
|
||||
pSyncMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
|
||||
pSyncMsg->sdNewTerm = pMsg->term;
|
||||
|
||||
SRpcMsg rpcMsgLocalCmd;
|
||||
syncLocalCmd2RpcMsg(pSyncMsg, &rpcMsgLocalCmd);
|
||||
|
||||
if (ths->FpEqMsg != NULL && ths->msgcb != NULL) {
|
||||
int32_t code = ths->FpEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, sync enqueue step-down msg error, code:%d", ths->vgId, code);
|
||||
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
||||
} else {
|
||||
sTrace("vgId:%d, sync enqueue step-down msg, new-term: %" PRIu64, ths->vgId, pSyncMsg->sdNewTerm);
|
||||
}
|
||||
}
|
||||
|
||||
syncLocalCmdDestroy(pSyncMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
// htonl
|
||||
SMsgHead* pHead = rpcMsg.pCont;
|
||||
|
@ -3080,6 +2994,19 @@ int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) {
|
||||
syncLogRecvLocalCmd(ths, pMsg, "");
|
||||
|
||||
if (pMsg->cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
|
||||
syncNodeStepDown(ths, pMsg->sdNewTerm);
|
||||
|
||||
} else {
|
||||
syncNodeErrorLog(ths, "error local cmd");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TLA+ Spec
|
||||
// ClientRequest(i, v) ==
|
||||
// /\ state[i] = Leader
|
||||
|
@ -3375,8 +3302,13 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
|||
pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h);
|
||||
} else {
|
||||
code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, i, &pEntry);
|
||||
ASSERT(code == 0);
|
||||
ASSERT(pEntry != NULL);
|
||||
// ASSERT(code == 0);
|
||||
// ASSERT(pEntry != NULL);
|
||||
if (code != 0 || pEntry == NULL) {
|
||||
syncNodeErrorLog(ths, "get log entry error");
|
||||
sFatal("vgId:%d, get log entry %" PRId64 " error when commit since %s", ths->vgId, i, terrstr());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
|
@ -3737,4 +3669,11 @@ void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* p
|
|||
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);
|
||||
}
|
||||
|
||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
||||
char logBuf[256];
|
||||
snprintf(logBuf, sizeof(logBuf), "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRIu64 "}, %s", pMsg->cmd,
|
||||
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, s);
|
||||
syncNodeEventLog(pSyncNode, logBuf);
|
||||
}
|
|
@ -3095,3 +3095,161 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) {
|
|||
taosMemoryFree(serialized);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
const char* syncLocalCmdGetStr(int32_t cmd) {
|
||||
if (cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
|
||||
return "step-down";
|
||||
}
|
||||
|
||||
return "unknown-local-cmd";
|
||||
}
|
||||
|
||||
SyncLocalCmd* syncLocalCmdBuild(int32_t vgId) {
|
||||
uint32_t bytes = sizeof(SyncLocalCmd);
|
||||
SyncLocalCmd* pMsg = taosMemoryMalloc(bytes);
|
||||
memset(pMsg, 0, bytes);
|
||||
pMsg->bytes = bytes;
|
||||
pMsg->vgId = vgId;
|
||||
pMsg->msgType = TDMT_SYNC_LOCAL_CMD;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncLocalCmdDestroy(SyncLocalCmd* pMsg) {
|
||||
if (pMsg != NULL) {
|
||||
taosMemoryFree(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen) {
|
||||
ASSERT(pMsg->bytes <= bufLen);
|
||||
memcpy(buf, pMsg, pMsg->bytes);
|
||||
}
|
||||
|
||||
void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg) {
|
||||
memcpy(pMsg, buf, len);
|
||||
ASSERT(len == pMsg->bytes);
|
||||
}
|
||||
|
||||
char* syncLocalCmdSerialize2(const SyncLocalCmd* pMsg, uint32_t* len) {
|
||||
char* buf = taosMemoryMalloc(pMsg->bytes);
|
||||
ASSERT(buf != NULL);
|
||||
syncLocalCmdSerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncLocalCmd* syncLocalCmdDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncLocalCmd* pMsg = taosMemoryMalloc(bytes);
|
||||
ASSERT(pMsg != NULL);
|
||||
syncLocalCmdDeserialize(buf, len, pMsg);
|
||||
ASSERT(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncLocalCmd2RpcMsg(const SyncLocalCmd* pMsg, SRpcMsg* pRpcMsg) {
|
||||
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
||||
pRpcMsg->msgType = pMsg->msgType;
|
||||
pRpcMsg->contLen = pMsg->bytes;
|
||||
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
||||
syncLocalCmdSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
}
|
||||
|
||||
void syncLocalCmdFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLocalCmd* pMsg) {
|
||||
syncLocalCmdDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncLocalCmd* syncLocalCmdFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncLocalCmd* pMsg = syncLocalCmdDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
ASSERT(pMsg != NULL);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) {
|
||||
char u64buf[128];
|
||||
cJSON* pRoot = cJSON_CreateObject();
|
||||
|
||||
if (pMsg != NULL) {
|
||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||
|
||||
cJSON* pSrcId = cJSON_CreateObject();
|
||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
|
||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||
{
|
||||
uint64_t u64 = pMsg->srcId.addr;
|
||||
cJSON* pTmp = pSrcId;
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||
}
|
||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||
|
||||
cJSON* pDestId = cJSON_CreateObject();
|
||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
|
||||
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||
{
|
||||
uint64_t u64 = pMsg->destId.addr;
|
||||
cJSON* pTmp = pDestId;
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||
}
|
||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||
|
||||
cJSON_AddNumberToObject(pRoot, "cmd", pMsg->cmd);
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->sdNewTerm);
|
||||
cJSON_AddStringToObject(pRoot, "sd-new-term", u64buf);
|
||||
}
|
||||
|
||||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SyncLocalCmd2Json", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
char* syncLocalCmd2Str(const SyncLocalCmd* pMsg) {
|
||||
cJSON* pJson = syncLocalCmd2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncLocalCmdPrint(const SyncLocalCmd* pMsg) {
|
||||
char* serialized = syncLocalCmd2Str(pMsg);
|
||||
printf("syncLocalCmdPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg) {
|
||||
char* serialized = syncLocalCmd2Str(pMsg);
|
||||
printf("syncLocalCmdPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void syncLocalCmdLog(const SyncLocalCmd* pMsg) {
|
||||
char* serialized = syncLocalCmd2Str(pMsg);
|
||||
sTrace("syncLocalCmdLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void syncLocalCmdLog2(char* s, const SyncLocalCmd* pMsg) {
|
||||
if (gRaftDetailLog) {
|
||||
char* serialized = syncLocalCmd2Str(pMsg);
|
||||
sTrace("syncLocalCmdLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
|
|||
SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore);
|
||||
if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) {
|
||||
char logBuf[128];
|
||||
snprintf(logBuf, sizeof(logBuf), "start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64,
|
||||
snprintf(logBuf, sizeof(logBuf), "maybe start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64,
|
||||
nextIndex, logStartIndex, logEndIndex);
|
||||
syncNodeEventLog(pSyncNode, logBuf);
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
|||
SSyncLogStoreData* pData = ths->pLogStore->data;
|
||||
int32_t code = walEndSnapshot(pData->pWal);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, wal snapshot end error since:%s", ths->vgId, terrstr(terrno));
|
||||
sError("vgId:%d, timer wal snapshot end error since:%s", ths->vgId, terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
do {
|
||||
|
|
|
@ -59,6 +59,7 @@ add_executable(syncRestoreFromSnapshot "")
|
|||
add_executable(syncRaftCfgIndexTest "")
|
||||
add_executable(syncHeartbeatTest "")
|
||||
add_executable(syncHeartbeatReplyTest "")
|
||||
add_executable(syncLocalCmdTest "")
|
||||
|
||||
|
||||
target_sources(syncTest
|
||||
|
@ -305,6 +306,10 @@ target_sources(syncHeartbeatReplyTest
|
|||
PRIVATE
|
||||
"syncHeartbeatReplyTest.cpp"
|
||||
)
|
||||
target_sources(syncLocalCmdTest
|
||||
PRIVATE
|
||||
"syncLocalCmdTest.cpp"
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(syncTest
|
||||
|
@ -612,6 +617,11 @@ target_include_directories(syncHeartbeatReplyTest
|
|||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncLocalCmdTest
|
||||
PUBLIC
|
||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(syncTest
|
||||
|
@ -858,6 +868,10 @@ target_link_libraries(syncHeartbeatReplyTest
|
|||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncLocalCmdTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
|
||||
|
||||
enable_testing()
|
||||
|
|
|
@ -270,7 +270,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
|
|||
pMsg->msgType = 9999;
|
||||
pMsg->contLen = 256;
|
||||
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count,
|
||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count,
|
||||
taosGetTimestampMs());
|
||||
return pMsg;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
|
|||
pMsg->msgType = 9999;
|
||||
pMsg->contLen = 256;
|
||||
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count,
|
||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count,
|
||||
taosGetTimestampMs());
|
||||
return pMsg;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ int main(int argc, char** argv) {
|
|||
init();
|
||||
int32_t ret = syncIOStart((char*)"127.0.0.1", gPorts[myIndex]);
|
||||
assert(ret == 0);
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
char walPath[128];
|
||||
|
|
|
@ -152,7 +152,7 @@ int main(int argc, char **argv) {
|
|||
int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
taosRemoveDir("./wal_test");
|
||||
|
@ -186,7 +186,7 @@ int main(int argc, char **argv) {
|
|||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, pEntry->index, &pEntry);
|
||||
ASSERT(code == 0);
|
||||
|
||||
syncEntryLog2((char *)"==pEntry2==", pEntry2);
|
||||
syncEntryLog2((char *)"==pEntry==", pEntry);
|
||||
|
||||
// step5
|
||||
uint32_t len;
|
||||
|
|
|
@ -81,7 +81,7 @@ int main(int argc, char** argv) {
|
|||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
|
|
|
@ -22,7 +22,7 @@ int main() {
|
|||
|
||||
logTest();
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
|
@ -37,8 +37,6 @@ int main() {
|
|||
taosMsleep(5000);
|
||||
}
|
||||
|
||||
ret = syncEnvStop();
|
||||
assert(ret == 0);
|
||||
|
||||
syncCleanUp();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ int main(int argc, char** argv) {
|
|||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
|
|
|
@ -13,7 +13,7 @@ void print(SHashObj *pNextIndex) {
|
|||
|
||||
SRaftId *pRaftId = (SRaftId *)key;
|
||||
|
||||
printf("key:<" PRIu64 ", %d>, value:%" PRIu64 " \n", pRaftId->addr, pRaftId->vgId, *p);
|
||||
printf("key:<%" PRIu64 ", %d>, value:%" PRIu64 " \n", pRaftId->addr, pRaftId->vgId, *p);
|
||||
p = (uint64_t *)taosHashIterate(pNextIndex, p);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ int main(int argc, char** argv) {
|
|||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
|
@ -91,7 +91,7 @@ int main(int argc, char** argv) {
|
|||
initRaftId(pSyncNode);
|
||||
|
||||
syncNodeClose(pSyncNode);
|
||||
syncEnvStop();
|
||||
syncCleanUp();
|
||||
// syncIOStop();
|
||||
|
||||
// taosCloseLog();
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
void logTest() {
|
||||
sTrace("--- sync log test: trace");
|
||||
sDebug("--- sync log test: debug");
|
||||
sInfo("--- sync log test: info");
|
||||
sWarn("--- sync log test: warn");
|
||||
sError("--- sync log test: error");
|
||||
sFatal("--- sync log test: fatal");
|
||||
}
|
||||
|
||||
SyncLocalCmd *createMsg() {
|
||||
SyncLocalCmd *pMsg = syncLocalCmdBuild(1000);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->sdNewTerm = 123;
|
||||
pMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
syncLocalCmdLog2((char *)"test1:", pMsg);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char *serialized = (char *)taosMemoryMalloc(len);
|
||||
syncLocalCmdSerialize(pMsg, serialized, len);
|
||||
SyncLocalCmd *pMsg2 = syncLocalCmdBuild(1000);
|
||||
syncLocalCmdDeserialize(serialized, len, pMsg2);
|
||||
syncLocalCmdLog2((char *)"test2: syncLocalCmdSerialize -> syncLocalCmdDeserialize ", pMsg2);
|
||||
|
||||
taosMemoryFree(serialized);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
syncLocalCmdDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char *serialized = syncLocalCmdSerialize2(pMsg, &len);
|
||||
SyncLocalCmd *pMsg2 = syncLocalCmdDeserialize2(serialized, len);
|
||||
syncLocalCmdLog2((char *)"test3: syncLocalCmdSerialize3 -> syncLocalCmdDeserialize2 ", pMsg2);
|
||||
|
||||
taosMemoryFree(serialized);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
syncLocalCmdDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncLocalCmd2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncLocalCmd *pMsg2 = (SyncLocalCmd *)taosMemoryMalloc(rpcMsg.contLen);
|
||||
syncLocalCmdFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncLocalCmdLog2((char *)"test4: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg ", pMsg2);
|
||||
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
syncLocalCmdDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncLocalCmd *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncLocalCmd2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncLocalCmd *pMsg2 = syncLocalCmdFromRpcMsg2(&rpcMsg);
|
||||
syncLocalCmdLog2((char *)"test5: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg2 ", pMsg2);
|
||||
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncLocalCmdDestroy(pMsg);
|
||||
syncLocalCmdDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
gRaftDetailLog = true;
|
||||
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -81,7 +81,7 @@ int main(int argc, char** argv) {
|
|||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
|
|
|
@ -81,7 +81,7 @@ int main(int argc, char** argv) {
|
|||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
|
|
|
@ -81,7 +81,7 @@ int main(int argc, char** argv) {
|
|||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
|
|
|
@ -15,7 +15,7 @@ int main(int argc, char** argv) {
|
|||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||
printf("" PRIu64 " -> %s:%d \n", u64, host, port);
|
||||
printf("%" PRIu64 " -> %s:%d \n", u64, host, port);
|
||||
|
||||
} else if (argc == 3) {
|
||||
uint64_t u64;
|
||||
|
|
|
@ -97,8 +97,8 @@ void test1() {
|
|||
sTrace("lastIndex: %" PRId64, lastIndex);
|
||||
sTrace("lastTerm: %" PRIu64, lastTerm);
|
||||
sTrace("syncStartIndex: %" PRId64, syncStartIndex);
|
||||
sTrace("" PRId64 "'s preIndex: %" PRId64, testIndex, preIndex);
|
||||
sTrace("" PRId64 "'s preTerm: %" PRIu64, testIndex, preTerm);
|
||||
sTrace("testIndex: %" PRId64 " preIndex: %" PRId64, testIndex, preIndex);
|
||||
sTrace("testIndex: %" PRId64 " preTerm: %" PRIu64, testIndex, preTerm);
|
||||
|
||||
if (gAssert) {
|
||||
assert(lastIndex == -1);
|
||||
|
@ -170,8 +170,8 @@ void test2() {
|
|||
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
||||
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
||||
|
||||
sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex);
|
||||
sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm);
|
||||
sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex);
|
||||
sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm);
|
||||
|
||||
if (gAssert) {
|
||||
SyncIndex preIndexArr[12] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
|
@ -292,8 +292,8 @@ void test4() {
|
|||
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
||||
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
||||
|
||||
sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex);
|
||||
sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm);
|
||||
sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex);
|
||||
sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm);
|
||||
}
|
||||
|
||||
logStoreDestory(pLogStore);
|
||||
|
@ -354,8 +354,8 @@ void test5() {
|
|||
SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i);
|
||||
SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i);
|
||||
|
||||
sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex);
|
||||
sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm);
|
||||
sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex);
|
||||
sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm);
|
||||
|
||||
if (gAssert) {
|
||||
SyncIndex preIndexArr[12] = {9999, 9999, 9999, 9999, 9999, 9999, 5, 6, 7, 8, 9, 10};
|
||||
|
|
|
@ -145,7 +145,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
|
|||
pMsg->msgType = 9999;
|
||||
pMsg->contLen = 256;
|
||||
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count,
|
||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count,
|
||||
taosGetTimestampMs());
|
||||
return pMsg;
|
||||
}
|
||||
|
|
|
@ -58,18 +58,18 @@ void syncRespMgrGetTest(uint64_t i) {
|
|||
if (ret == 1) {
|
||||
printStub(&stub);
|
||||
} else if (ret == 0) {
|
||||
printf("" PRId64 " notFound \n", i);
|
||||
printf("%" PRId64 " notFound \n", i);
|
||||
}
|
||||
}
|
||||
|
||||
void syncRespMgrGetAndDelTest(uint64_t i) {
|
||||
printf("------syncRespMgrGetAndDelTest-------" PRIu64 "-- \n", i);
|
||||
printf("------syncRespMgrGetAndDelTest-------%" PRIu64 "-- \n", i);
|
||||
SRespStub stub;
|
||||
int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub);
|
||||
if (ret == 1) {
|
||||
printStub(&stub);
|
||||
} else if (ret == 0) {
|
||||
printf("" PRId64 " notFound \n", i);
|
||||
printf("%" PRId64 " notFound \n", i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ int main(int argc, char **argv) {
|
|||
int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
// taosRemoveDir(pWalDir);
|
||||
|
|
|
@ -154,7 +154,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
|
|||
void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb== pFsm:%p", pFsm); }
|
||||
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) {
|
||||
char* s = syncCfg2Str(&(cbMeta.newCfg));
|
||||
char* s = syncCfg2Str(&(cbMeta->newCfg));
|
||||
sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64
|
||||
", newCfg:%s",
|
||||
cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term, s);
|
||||
|
@ -308,7 +308,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
|
|||
pMsg->msgType = TDMT_VND_SUBMIT;
|
||||
pMsg->contLen = 256;
|
||||
pMsg->pCont = rpcMallocCont(pMsg->contLen);
|
||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count,
|
||||
snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count,
|
||||
taosGetTimestampMs());
|
||||
return pMsg;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ int main(int argc, char** argv) {
|
|||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
|
|
|
@ -82,7 +82,7 @@ int main(int argc, char** argv) {
|
|||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
|
|
|
@ -154,7 +154,7 @@ int main(int argc, char **argv) {
|
|||
int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
ret = syncInit();
|
||||
assert(ret == 0);
|
||||
|
||||
taosRemoveDir("./wal_test");
|
||||
|
|
|
@ -42,7 +42,7 @@ TEST_F(TfsTest, 01_Open_Close) {
|
|||
STfs *pTfs = tfsOpen(&dCfg, 1);
|
||||
ASSERT_EQ(pTfs, nullptr);
|
||||
|
||||
taosMkDir(root);
|
||||
taosMulMkDir(root);
|
||||
pTfs = tfsOpen(&dCfg, 1);
|
||||
ASSERT_NE(pTfs, nullptr);
|
||||
|
||||
|
|
|
@ -428,6 +428,7 @@ void transDestoryExHandle(void* handle);
|
|||
int32_t transGetRefMgt();
|
||||
int32_t transGetInstMgt();
|
||||
|
||||
void transHttpEnvDestroy();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,21 +20,52 @@
|
|||
#include "thttp.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
#include "transComm.h"
|
||||
|
||||
// clang-format on
|
||||
|
||||
#define HTTP_RECV_BUF_SIZE 1024
|
||||
|
||||
typedef struct SHttpModule {
|
||||
uv_loop_t* loop;
|
||||
SAsyncPool* asyncPool;
|
||||
TdThread thread;
|
||||
} SHttpModule;
|
||||
|
||||
typedef struct SHttpMsg {
|
||||
queue q;
|
||||
char* server;
|
||||
int32_t port;
|
||||
char* cont;
|
||||
int32_t len;
|
||||
EHttpCompFlag flag;
|
||||
int8_t quit;
|
||||
SHttpModule* http;
|
||||
|
||||
} SHttpMsg;
|
||||
|
||||
typedef struct SHttpClient {
|
||||
uv_connect_t conn;
|
||||
uv_tcp_t tcp;
|
||||
uv_write_t req;
|
||||
uv_buf_t* wbuf;
|
||||
char* rbuf;
|
||||
char* addr;
|
||||
uint16_t port;
|
||||
uv_connect_t conn;
|
||||
uv_tcp_t tcp;
|
||||
uv_write_t req;
|
||||
uv_buf_t* wbuf;
|
||||
char* rbuf;
|
||||
char* addr;
|
||||
uint16_t port;
|
||||
struct sockaddr_in dest;
|
||||
} SHttpClient;
|
||||
|
||||
static TdThreadOnce transHttpInit = PTHREAD_ONCE_INIT;
|
||||
static SHttpModule* thttp = NULL;
|
||||
static void transHttpEnvInit();
|
||||
|
||||
static void httpHandleReq(SHttpMsg* msg);
|
||||
static void httpHandleQuit(SHttpMsg* msg);
|
||||
static int32_t httpSendQuit();
|
||||
|
||||
static int32_t taosSendHttpReportImpl(const char* server, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag);
|
||||
|
||||
static int32_t taosBuildHttpHeader(const char* server, int32_t contLen, char* pHead, int32_t headLen,
|
||||
EHttpCompFlag flag) {
|
||||
if (flag == HTTP_FLAT) {
|
||||
|
@ -53,6 +84,7 @@ static int32_t taosBuildHttpHeader(const char* server, int32_t contLen, char* pH
|
|||
"Content-Length: %d\n\n",
|
||||
server, contLen);
|
||||
} else {
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -126,88 +158,10 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void destroyHttpClient(SHttpClient* cli) {
|
||||
taosMemoryFree(cli->wbuf);
|
||||
taosMemoryFree(cli->rbuf);
|
||||
taosMemoryFree(cli->addr);
|
||||
taosMemoryFree(cli);
|
||||
}
|
||||
static FORCE_INLINE void clientCloseCb(uv_handle_t* handle) {
|
||||
SHttpClient* cli = handle->data;
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
static FORCE_INLINE void clientAllocBuffCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
|
||||
SHttpClient* cli = handle->data;
|
||||
buf->base = cli->rbuf;
|
||||
buf->len = HTTP_RECV_BUF_SIZE;
|
||||
}
|
||||
static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
|
||||
SHttpClient* cli = handle->data;
|
||||
if (nread < 0) {
|
||||
uError("http-report recv error:%s", uv_err_name(nread));
|
||||
} else {
|
||||
uTrace("http-report succ to recv %d bytes", (int32_t)nread);
|
||||
}
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
} else {
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
}
|
||||
static void clientSentCb(uv_write_t* req, int32_t status) {
|
||||
SHttpClient* cli = req->data;
|
||||
if (status != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(status);
|
||||
uError("http-report failed to send data %s", uv_strerror(status));
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
} else {
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
uTrace("http-report succ to send data");
|
||||
}
|
||||
status = uv_read_start((uv_stream_t*)&cli->tcp, clientAllocBuffCb, clientRecvCb);
|
||||
if (status != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(status);
|
||||
uError("http-report failed to recv data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
} else {
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void clientConnCb(uv_connect_t* req, int32_t status) {
|
||||
SHttpClient* cli = req->data;
|
||||
if (status != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(status);
|
||||
uError("http-report failed to conn to server, reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
} else {
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
return;
|
||||
}
|
||||
status = uv_write(&cli->req, (uv_stream_t*)&cli->tcp, cli->wbuf, 2, clientSentCb);
|
||||
if (0 != status) {
|
||||
terrno = TAOS_SYSTEM_ERROR(status);
|
||||
uError("http-report failed to send data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
} else {
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, struct sockaddr_in* dest) {
|
||||
uint32_t ip = taosGetIpv4FromFqdn(server);
|
||||
if (ip == 0xffffffff) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("http-report failed to get http server:%s since %s", server, errno == 0 ? "invalid http server" : terrstr());
|
||||
tError("http-report failed to get http server:%s since %s", server, errno == 0 ? "invalid http server" : terrstr());
|
||||
return -1;
|
||||
}
|
||||
char buf[128] = {0};
|
||||
|
@ -215,27 +169,206 @@ static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port,
|
|||
uv_ip4_addr(buf, port, dest);
|
||||
return 0;
|
||||
}
|
||||
int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag) {
|
||||
struct sockaddr_in dest = {0};
|
||||
if (taosBuildDstAddr(server, port, &dest) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (flag == HTTP_GZIP) {
|
||||
int32_t dstLen = taosCompressHttpRport(pCont, contLen);
|
||||
if (dstLen > 0) {
|
||||
contLen = dstLen;
|
||||
|
||||
static void* httpThread(void* arg) {
|
||||
SHttpModule* http = (SHttpModule*)arg;
|
||||
setThreadName("http-cli-send-thread");
|
||||
uv_run(http->loop, UV_RUN_DEFAULT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void httpDestroyMsg(SHttpMsg* msg) {
|
||||
if (msg == NULL) return;
|
||||
|
||||
taosMemoryFree(msg->server);
|
||||
taosMemoryFree(msg->cont);
|
||||
taosMemoryFree(msg);
|
||||
}
|
||||
static void httpAsyncCb(uv_async_t* handle) {
|
||||
SAsyncItem* item = handle->data;
|
||||
SHttpModule* http = item->pThrd;
|
||||
|
||||
SHttpMsg *msg = NULL, *quitMsg = NULL;
|
||||
|
||||
queue wq;
|
||||
taosThreadMutexLock(&item->mtx);
|
||||
QUEUE_MOVE(&item->qmsg, &wq);
|
||||
taosThreadMutexUnlock(&item->mtx);
|
||||
|
||||
int count = 0;
|
||||
while (!QUEUE_IS_EMPTY(&wq)) {
|
||||
queue* h = QUEUE_HEAD(&wq);
|
||||
QUEUE_REMOVE(h);
|
||||
msg = QUEUE_DATA(h, SHttpMsg, q);
|
||||
if (msg->quit) {
|
||||
quitMsg = msg;
|
||||
} else {
|
||||
flag = HTTP_FLAT;
|
||||
httpHandleReq(msg);
|
||||
}
|
||||
}
|
||||
terrno = 0;
|
||||
if (quitMsg) httpHandleQuit(quitMsg);
|
||||
}
|
||||
|
||||
char header[2048] = {0};
|
||||
int32_t headLen = taosBuildHttpHeader(server, contLen, header, sizeof(header), flag);
|
||||
static FORCE_INLINE void destroyHttpClient(SHttpClient* cli) {
|
||||
taosMemoryFree(cli->wbuf[0].base);
|
||||
taosMemoryFree(cli->wbuf[1].base);
|
||||
taosMemoryFree(cli->wbuf);
|
||||
taosMemoryFree(cli->rbuf);
|
||||
taosMemoryFree(cli->addr);
|
||||
taosMemoryFree(cli);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void clientCloseCb(uv_handle_t* handle) {
|
||||
SHttpClient* cli = handle->data;
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void clientAllocBuffCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
|
||||
SHttpClient* cli = handle->data;
|
||||
buf->base = cli->rbuf;
|
||||
buf->len = HTTP_RECV_BUF_SIZE;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
|
||||
SHttpClient* cli = handle->data;
|
||||
if (nread < 0) {
|
||||
tError("http-report recv error:%s", uv_err_name(nread));
|
||||
} else {
|
||||
tTrace("http-report succ to recv %d bytes", (int32_t)nread);
|
||||
}
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
}
|
||||
static void clientSentCb(uv_write_t* req, int32_t status) {
|
||||
SHttpClient* cli = req->data;
|
||||
if (status != 0) {
|
||||
tError("http-report failed to send data, reason: %s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
tTrace("http-report succ to send data");
|
||||
}
|
||||
status = uv_read_start((uv_stream_t*)&cli->tcp, clientAllocBuffCb, clientRecvCb);
|
||||
if (status != 0) {
|
||||
tError("http-report failed to recv data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void clientConnCb(uv_connect_t* req, int32_t status) {
|
||||
SHttpClient* cli = req->data;
|
||||
if (status != 0) {
|
||||
tError("http-report failed to conn to server, reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
return;
|
||||
}
|
||||
status = uv_write(&cli->req, (uv_stream_t*)&cli->tcp, cli->wbuf, 2, clientSentCb);
|
||||
if (0 != status) {
|
||||
tError("http-report failed to send data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t httpSendQuit() {
|
||||
SHttpMsg* msg = taosMemoryCalloc(1, sizeof(SHttpMsg));
|
||||
msg->quit = 1;
|
||||
|
||||
SHttpModule* load = atomic_load_ptr(&thttp);
|
||||
if (load == NULL) {
|
||||
httpDestroyMsg(msg);
|
||||
tError("http-report already released");
|
||||
return -1;
|
||||
} else {
|
||||
msg->http = load;
|
||||
}
|
||||
transAsyncSend(load->asyncPool, &(msg->q));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t taosSendHttpReportImpl(const char* server, uint16_t port, char* pCont, int32_t contLen,
|
||||
EHttpCompFlag flag) {
|
||||
SHttpMsg* msg = taosMemoryMalloc(sizeof(SHttpMsg));
|
||||
msg->server = strdup(server);
|
||||
msg->port = port;
|
||||
msg->cont = taosMemoryMalloc(contLen);
|
||||
memcpy(msg->cont, pCont, contLen);
|
||||
msg->len = contLen;
|
||||
msg->flag = flag;
|
||||
msg->quit = 0;
|
||||
|
||||
SHttpModule* load = atomic_load_ptr(&thttp);
|
||||
if (load == NULL) {
|
||||
httpDestroyMsg(msg);
|
||||
tError("http-report already released");
|
||||
return -1;
|
||||
} else {
|
||||
msg->http = load;
|
||||
transAsyncSend(load->asyncPool, &(msg->q));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void httpDestroyClientCb(uv_handle_t* handle) {
|
||||
SHttpClient* http = handle->data;
|
||||
destroyHttpClient(http);
|
||||
}
|
||||
static void httpWalkCb(uv_handle_t* handle, void* arg) {
|
||||
// impl later
|
||||
if (!uv_is_closing(handle)) {
|
||||
uv_handle_type type = uv_handle_get_type(handle);
|
||||
if (uv_handle_get_type(handle) == UV_TCP) {
|
||||
uv_close(handle, httpDestroyClientCb);
|
||||
} else {
|
||||
uv_close(handle, NULL);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
static void httpHandleQuit(SHttpMsg* msg) {
|
||||
SHttpModule* http = msg->http;
|
||||
taosMemoryFree(msg);
|
||||
|
||||
uv_walk(http->loop, httpWalkCb, NULL);
|
||||
}
|
||||
static void httpHandleReq(SHttpMsg* msg) {
|
||||
SHttpModule* http = msg->http;
|
||||
|
||||
struct sockaddr_in dest = {0};
|
||||
if (taosBuildDstAddr(msg->server, msg->port, &dest) < 0) {
|
||||
goto END;
|
||||
}
|
||||
if (msg->flag == HTTP_GZIP) {
|
||||
int32_t dstLen = taosCompressHttpRport(msg->cont, msg->len);
|
||||
if (dstLen > 0) {
|
||||
msg->len = dstLen;
|
||||
} else {
|
||||
msg->flag = HTTP_FLAT;
|
||||
}
|
||||
if (dstLen < 0) {
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t len = 2048;
|
||||
char* header = taosMemoryCalloc(1, len);
|
||||
int32_t headLen = taosBuildHttpHeader(msg->server, msg->len, header, len, msg->flag);
|
||||
if (headLen < 0) {
|
||||
taosMemoryFree(header);
|
||||
goto END;
|
||||
}
|
||||
|
||||
uv_buf_t* wb = taosMemoryCalloc(2, sizeof(uv_buf_t));
|
||||
wb[0] = uv_buf_init((char*)header, headLen); // stack var
|
||||
wb[1] = uv_buf_init((char*)pCont, contLen); // heap var
|
||||
wb[0] = uv_buf_init((char*)header, strlen(header)); // heap var
|
||||
wb[1] = uv_buf_init((char*)msg->cont, msg->len); // heap var
|
||||
|
||||
SHttpClient* cli = taosMemoryCalloc(1, sizeof(SHttpClient));
|
||||
cli->conn.data = cli;
|
||||
|
@ -243,41 +376,71 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32
|
|||
cli->req.data = cli;
|
||||
cli->wbuf = wb;
|
||||
cli->rbuf = taosMemoryCalloc(1, HTTP_RECV_BUF_SIZE);
|
||||
cli->addr = tstrdup(server);
|
||||
cli->port = port;
|
||||
cli->addr = msg->server;
|
||||
cli->port = msg->port;
|
||||
cli->dest = dest;
|
||||
|
||||
taosMemoryFree(msg);
|
||||
|
||||
uv_tcp_init(http->loop, &cli->tcp);
|
||||
|
||||
uv_loop_t* loop = taosMemoryMalloc(sizeof(uv_loop_t));
|
||||
int err = uv_loop_init(loop);
|
||||
if (err != 0) {
|
||||
uError("http-report failed to init uv_loop, reason: %s", uv_strerror(err));
|
||||
taosMemoryFree(loop);
|
||||
terrno = TAOS_SYSTEM_ERROR(err);
|
||||
destroyHttpClient(cli);
|
||||
return terrno;
|
||||
}
|
||||
uv_tcp_init(loop, &cli->tcp);
|
||||
// set up timeout to avoid stuck;
|
||||
int32_t fd = taosCreateSocketWithTimeout(5);
|
||||
|
||||
int ret = uv_tcp_open((uv_tcp_t*)&cli->tcp, fd);
|
||||
int ret = uv_tcp_open((uv_tcp_t*)&cli->tcp, fd);
|
||||
if (ret != 0) {
|
||||
uError("http-report failed to open socket, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr, cli->port);
|
||||
tError("http-report failed to open socket, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr, cli->port);
|
||||
destroyHttpClient(cli);
|
||||
uv_stop(loop);
|
||||
terrno = TAOS_SYSTEM_ERROR(ret);
|
||||
} else {
|
||||
ret = uv_tcp_connect(&cli->conn, &cli->tcp, (const struct sockaddr*)&dest, clientConnCb);
|
||||
if (ret != 0) {
|
||||
uError("http-report failed to connect to http-server, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr,
|
||||
cli->port);
|
||||
destroyHttpClient(cli);
|
||||
uv_stop(loop);
|
||||
terrno = TAOS_SYSTEM_ERROR(ret);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
uv_loop_close(loop);
|
||||
taosMemoryFree(loop);
|
||||
return terrno;
|
||||
ret = uv_tcp_connect(&cli->conn, &cli->tcp, (const struct sockaddr*)&cli->dest, clientConnCb);
|
||||
if (ret != 0) {
|
||||
tError("http-report failed to connect to http-server, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr,
|
||||
cli->port);
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
return;
|
||||
|
||||
END:
|
||||
tError("http-report failed to report, reason: %s, addr: %s:%d", terrstr(), msg->server, msg->port);
|
||||
httpDestroyMsg(msg);
|
||||
}
|
||||
|
||||
int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag) {
|
||||
taosThreadOnce(&transHttpInit, transHttpEnvInit);
|
||||
return taosSendHttpReportImpl(server, port, pCont, contLen, flag);
|
||||
}
|
||||
|
||||
static void transHttpEnvInit() {
|
||||
SHttpModule* http = taosMemoryMalloc(sizeof(SHttpModule));
|
||||
|
||||
http->loop = taosMemoryMalloc(sizeof(uv_loop_t));
|
||||
uv_loop_init(http->loop);
|
||||
|
||||
http->asyncPool = transAsyncPoolCreate(http->loop, 1, http, httpAsyncCb);
|
||||
|
||||
int err = taosThreadCreate(&http->thread, NULL, httpThread, (void*)http);
|
||||
if (err != 0) {
|
||||
taosMemoryFree(http->loop);
|
||||
taosMemoryFree(http);
|
||||
http = NULL;
|
||||
}
|
||||
atomic_store_ptr(&thttp, http);
|
||||
}
|
||||
|
||||
void transHttpEnvDestroy() {
|
||||
SHttpModule* load = atomic_load_ptr(&thttp);
|
||||
if (load == NULL) {
|
||||
return;
|
||||
}
|
||||
httpSendQuit();
|
||||
taosThreadJoin(load->thread, NULL);
|
||||
|
||||
TRANS_DESTROY_ASYNC_POOL_MSG(load->asyncPool, SHttpMsg, httpDestroyMsg);
|
||||
transAsyncPoolDestroy(load->asyncPool);
|
||||
uv_loop_close(load->loop);
|
||||
taosMemoryFree(load->loop);
|
||||
taosMemoryFree(load);
|
||||
|
||||
atomic_store_ptr(&thttp, NULL);
|
||||
}
|
||||
|
|
|
@ -172,6 +172,8 @@ int32_t rpcInit() {
|
|||
}
|
||||
void rpcCleanup(void) {
|
||||
transCleanup();
|
||||
transHttpEnvDestroy();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -187,18 +187,8 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) {
|
|||
snprintf(key, sizeof(key), "%s:%d", ip, (int)port); \
|
||||
} while (0)
|
||||
|
||||
#define CONN_HOST_THREAD_IDX1(idx, exh, refId, pThrd) \
|
||||
do { \
|
||||
if (exh == NULL) { \
|
||||
idx = -1; \
|
||||
} else { \
|
||||
ASYNC_CHECK_HANDLE((exh), refId); \
|
||||
pThrd = (SCliThrd*)(exh)->pThrd; \
|
||||
} \
|
||||
} while (0)
|
||||
#define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para))
|
||||
#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL)
|
||||
#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pTransInst))->label)
|
||||
#define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para))
|
||||
#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pTransInst))->label)
|
||||
|
||||
#define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \
|
||||
do { \
|
||||
|
@ -217,6 +207,7 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) {
|
|||
tDebug("msg found, %" PRIu64 "", ahandle); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CONN_GET_NEXT_SENDMSG(conn) \
|
||||
do { \
|
||||
int i = 0; \
|
||||
|
@ -231,21 +222,6 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define CONN_HANDLE_THREAD_QUIT(thrd) \
|
||||
do { \
|
||||
if (thrd->quit) { \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CONN_HANDLE_BROKEN(conn) \
|
||||
do { \
|
||||
if (conn->broken) { \
|
||||
cliHandleExcept(conn); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CONN_SET_PERSIST_BY_APP(conn) \
|
||||
do { \
|
||||
if (conn->status == ConnNormal) { \
|
||||
|
|
|
@ -655,7 +655,7 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) {
|
|||
uv_tcp_init(pObj->loop, cli);
|
||||
|
||||
if (uv_accept(stream, (uv_stream_t*)cli) == 0) {
|
||||
#ifdef WINDOWS
|
||||
#if defined(WINDOWS) || defined(DARWIN)
|
||||
if (pObj->numOfWorkerReady < pObj->numOfThreads) {
|
||||
tError("worker-threads are not ready for all, need %d instead of %d.", pObj->numOfThreads,
|
||||
pObj->numOfWorkerReady);
|
||||
|
@ -779,7 +779,7 @@ static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) {
|
|||
return false;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
#if defined(WINDOWS) || defined(DARWIN)
|
||||
uv_pipe_init(pThrd->loop, pThrd->pipe, 1);
|
||||
#else
|
||||
uv_pipe_init(pThrd->loop, pThrd->pipe, 1);
|
||||
|
@ -799,7 +799,7 @@ static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) {
|
|||
QUEUE_INIT(&pThrd->conn);
|
||||
|
||||
pThrd->asyncPool = transAsyncPoolCreate(pThrd->loop, 5, pThrd, uvWorkerAsyncCb);
|
||||
#ifdef WINDOWS
|
||||
#if defined(WINDOWS) || defined(DARWIN)
|
||||
uv_pipe_connect(&pThrd->connect_req, pThrd->pipe, pipeName, uvOnPipeConnectionCb);
|
||||
#else
|
||||
uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb);
|
||||
|
@ -976,17 +976,18 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
uv_loop_init(srv->loop);
|
||||
|
||||
char pipeName[PATH_MAX];
|
||||
#ifdef WINDOWS
|
||||
#if defined(WINDOWS) || defined(DARWIN)
|
||||
int ret = uv_pipe_init(srv->loop, &srv->pipeListen, 0);
|
||||
if (ret != 0) {
|
||||
tError("failed to init pipe, errmsg: %s", uv_err_name(ret));
|
||||
goto End;
|
||||
}
|
||||
|
||||
#if defined(WINDOWS)
|
||||
snprintf(pipeName, sizeof(pipeName), "\\\\?\\pipe\\trans.rpc.%d-%" PRIu64, taosSafeRand(), GetCurrentProcessId());
|
||||
// char pipeName[PATH_MAX] = {0};
|
||||
// snprintf(pipeName, sizeof(pipeName), "%s%spipe.trans.rpc.%08d-%" PRIu64, tsTempDir, TD_DIRSEP, taosSafeRand(),
|
||||
// taosGetSelfPthreadId());
|
||||
#elif defined(DARWIN)
|
||||
snprintf(pipeName, sizeof(pipeName), "%s%spipe.trans.rpc.%08d-%" PRIu64, tsTempDir, TD_DIRSEP, taosSafeRand(),
|
||||
taosGetSelfPthreadId());
|
||||
#endif
|
||||
|
||||
ret = uv_pipe_bind(&srv->pipeListen, pipeName);
|
||||
if (ret != 0) {
|
||||
|
@ -1036,7 +1037,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
srv->pThreadObj[i] = thrd;
|
||||
|
||||
uv_os_sock_t fds[2];
|
||||
if (uv_socketpair(AF_UNIX, SOCK_STREAM, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) {
|
||||
if (uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
|
@ -1059,8 +1060,8 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
goto End;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (false == taosValidIpAndPort(srv->ip, srv->port)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr());
|
||||
|
|
|
@ -336,3 +336,12 @@ int64_t taosMemorySize(void *ptr) {
|
|||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void taosMemoryTrim(int32_t size) {
|
||||
#if defined(WINDOWS) || defined(DARWIN)
|
||||
// do nothing
|
||||
return;
|
||||
#else
|
||||
malloc_trim(size);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -915,7 +915,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
int32_t olen, vlen, vlen2, vlen3;
|
||||
int32_t code = 0;
|
||||
if (url == NULL || strlen(url) == 0) {
|
||||
uInfo("fail to load apoll url");
|
||||
uInfo("apoll url not load");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ static void taosIncRsetCount(SRefSet *pSet);
|
|||
static void taosDecRsetCount(SRefSet *pSet);
|
||||
static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove);
|
||||
|
||||
int32_t taosOpenRef(int32_t max, void (*fp)(void *)) {
|
||||
int32_t taosOpenRef(int32_t max, RefFp fp) {
|
||||
SRefNode **nodeList;
|
||||
SRefSet *pSet;
|
||||
int64_t *lockedBy;
|
||||
|
|
|
@ -25,7 +25,7 @@ class TDTestCase:
|
|||
'''
|
||||
return
|
||||
|
||||
def init(self, conn, logSql):
|
||||
def init(self, conn, logSql, replicaVarl=1):
|
||||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor())
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue