diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index c24280170f2779..587ba2c858f218 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -30,6 +30,7 @@ 1. Proxy Native: Support local transactions of ClickHouse under GraalVM Native Image - [#33801](https://github.com/apache/shardingsphere/pull/33801) 1. Doc: Adds documentation for ClickHouse support - [#33779](https://github.com/apache/shardingsphere/pull/33779) 1. Doc: Removes use of `iceberg.mr.schema.auto.conversion` from documentation due to HIVE-26507 - [#33828](https://github.com/apache/shardingsphere/pull/33828) +1. Kernel: Bump the minimum Seata Client version for Seata AT integration to 2.2.0 - [#33872](https://github.com/apache/shardingsphere/pull/33872) ### Bug Fixes diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/special-api/transaction/seata.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/special-api/transaction/seata.cn.md index 4dfe1068fee6fc..d6fabee88a892f 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/special-api/transaction/seata.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/special-api/transaction/seata.cn.md @@ -9,7 +9,7 @@ Apache ShardingSphere 提供 BASE 事务,集成了 Seata 的实现。本文所 ## 前提条件 -ShardingSphere 的 Seata 集成仅在 `apache/incubator-seata:v2.1.0` 或更高版本可用。 +ShardingSphere 的 Seata 集成仅在 `apache/incubator-seata:v2.2.0` 或更高版本可用。 对于 `org.apache.seata:seata-all` Maven 模块对应的 Seata Client,此限制同时作用于 HotSpot VM 和 GraalVM Native Image。 引入 Maven 依赖,并排除 `org.apache.seata:seata-all` 中过时的 `org.antlr:antlr4-runtime:4.8` 的 Maven 依赖。 @@ -29,7 +29,7 @@ ShardingSphere 的 Seata 集成仅在 `apache/incubator-seata:v2.1.0` 或更高 org.apache.seata seata-all - 2.1.0 + 2.2.0 org.antlr @@ -42,47 +42,17 @@ ShardingSphere 的 Seata 集成仅在 `apache/incubator-seata:v2.1.0` 或更高 ``` 受 Calcite 的影响,ShardingSphere JDBC 使用的 `commons-lang:commons-lang` 和 `org.apache.commons:commons-pool2` 与 Seata Client 存在依赖冲突, -需用户根据实际情景考虑是否需要解决依赖冲突。 +需用户根据实际情景考虑是否需要解决依赖冲突。如果不解决依赖冲突,Maven 等构建工具会在 classpath 随机使用一个冲突依赖的版本。 使用 ShardingSphere 的 Seata 集成模块时,ShardingSphere 连接的数据库实例应同时实现 ShardingSphere 的方言解析支持与 Seata AT 模式的方言解析支持。 这类数据库包括但不限于 `mysql`,`gvenzl/oracle-free`,`gvenzl/oracle-xe`,`postgres`,`mcr.microsoft.com/mssql/server` 等 Docker Image。 -## 操作步骤 +### `undo_log` 表限制 -1. 启动 Seata Server -2. 创建日志表 -3. 添加 Seata 配置 +在每一个 ShardingSphere 涉及的真实数据库实例中均需要创建 `undo_log` 表。 +每种数据库的 SQL 的内容以 https://github.com/apache/incubator-seata/tree/v2.2.0/script/client/at/db 内对应的数据库为准。 -## 配置示例 - -### 启动 Seata Server - -按照如下任一链接的步骤,下载并启动 Seata 服务器。 -合理的启动方式应通过 Docker Hub 中的 `apache/seata-server` 的 Docker Image 来实例化 Seata 服务器。 - -- https://hub.docker.com/r/apache/seata-server - -### 创建 undo_log 表 - -在每一个 ShardingSphere 涉及的真实数据库实例中创建 `undo_log` 表。 -SQL 的内容以 https://github.com/apache/incubator-seata/tree/v2.1.0/script/client/at/db 内对应的数据库为准。 -以下内容以 MySQL 为例。 -```sql -CREATE TABLE IF NOT EXISTS `undo_log` -( - `branch_id` BIGINT NOT NULL COMMENT 'branch transaction id', - `xid` VARCHAR(128) NOT NULL COMMENT 'global transaction id', - `context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization', - `rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info', - `log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status', - `log_created` DATETIME(6) NOT NULL COMMENT 'create datetime', - `log_modified` DATETIME(6) NOT NULL COMMENT 'modify datetime', - UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`) - ) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT ='AT transaction mode undo table'; -ALTER TABLE `undo_log` ADD INDEX `ix_log_created` (`log_created`); -``` - -### 修改配置 +### 相关配置 在自有项目的 ShardingSphere 的 YAML 配置文件写入如下内容,参考 [分布式事务](/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/transaction)。 若初始化 ShardingSphere JDBC DataSource 时使用的是 Java API,参考 [分布式事务](/cn/user-manual/shardingsphere-jdbc/java-api/rules/transaction)。 @@ -93,8 +63,8 @@ transaction: providerType: Seata ``` -在 classpath 的根目录中增加 `seata.conf` 文件, -配置文件格式参考 `org.apache.seata.config.FileConfiguration` 的 [JavaDoc](https://github.com/apache/incubator-seata/blob/v2.1.0/config/seata-config-core/src/main/java/org/apache/seata/config/FileConfiguration.java)。 +在 classpath 的根目录中增加 `seata.conf` 文件, +配置文件格式参考 `org.apache.seata.config.FileConfiguration` 的 [JavaDoc](https://github.com/apache/incubator-seata/blob/v2.2.0/config/seata-config-core/src/main/java/org/apache/seata/config/FileConfiguration.java)。 `seata.conf` 存在四个属性, @@ -102,7 +72,7 @@ transaction: 2. `shardingsphere.transaction.seata.tx.timeout`,全局事务超时(秒)。存在默认值为 `60` 3. `client.application.id`,应用唯一主键,用于设置 Seata Transaction Manager Client 和 Seata Resource Manager Client 的 `applicationId` 4. `client.transaction.service.group`,所属事务组, 用于设置 Seata Transaction Manager Client 和 Seata Resource Manager Client 的 `transactionServiceGroup`。 -存在默认值为 `default` + 存在默认值为 `default` 一个完全配置的 `seata.conf` 如下, @@ -117,7 +87,7 @@ client { ``` 一个最小配置的 `seata.conf` 如下。 -由 ShardingSphere 管理的 `seata.conf` 中, `client.transaction.service.group` 的默认值设置为 `default` 是出于历史原因。 +由 ShardingSphere 管理的 `seata.conf` 中, `client.transaction.service.group` 的默认值为 `default` 是出于历史原因。 假设用户使用的 Seata Server 和 Seata Client 的 `registry.conf` 中,`registry.type` 和 `config.type` 均为 `file`, 则对于 `registry.conf` 的 `config.file.name` 配置的 `.conf` 文件中,事务分组名在 `apache/incubator-seata:v1.5.1` 及之后默认值为 `default_tx_group`, 在 `apache/incubator-seata:v1.5.1` 之前则为 `my_test_tx_group`。 @@ -128,6 +98,216 @@ client.application.id = example 根据实际场景修改 Seata 的 `registry.conf` 文件。 +## 配置示例 + +### 启动 Seata Server 和 MySQL Server + +编写 Docker Compose 文件来启动 Seata Server 和 MySQL Server。 + +```yaml +services: + apache-seata-server: + image: apache/seata-server:2.2.0 + ports: + - "8091:8091" + mysql: + image: mysql:9.1.0 + environment: + MYSQL_ROOT_PASSWORD: example + volumes: + - ./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d + ports: + - "3306:3306" +``` + +`./docker-entrypoint-initdb.d` 文件夹包含文件为 `init.sh`,内容如下, + +```shell +#!/bin/bash +set -e + +mysql -uroot -p"$MYSQL_ROOT_PASSWORD" <{0..2}.t_order + keyGenerateStrategy: + column: order_id + keyGeneratorName: snowflake + defaultDatabaseStrategy: + standard: + shardingColumn: user_id + shardingAlgorithmName: inline + shardingAlgorithms: + inline: + type: INLINE + props: + algorithm-expression: ds_${user_id % 2} + keyGenerators: + snowflake: + type: SNOWFLAKE +transaction: + defaultType: BASE + providerType: Seata +``` + +创建 ShardingSphere 的数据源,并在所有数据节点创建真实表, + +```java +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +@SuppressWarnings("SqlNoDataSourceInspection") +public class ExampleTest { + void test() throws SQLException { + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml"); + config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); + try (HikariDataSource dataSource = new HikariDataSource(config); + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.execute(""" + CREATE TABLE IF NOT EXISTS t_order ( + order_id BIGINT NOT NULL AUTO_INCREMENT, + order_type INT(11), + user_id INT NOT NULL, + address_id BIGINT NOT NULL, + status VARCHAR(50), + PRIMARY KEY (order_id) + )"""); + } + } +} +``` + +### 享受集成 + +在 ShardingSphere 的数据源上可开始享受集成, + +```java +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import java.sql.Connection; +import java.sql.SQLException; +@SuppressWarnings({"SqlNoDataSourceInspection", "AssertWithSideEffects"}) +public class ExampleTest { + void test() throws SQLException { + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml"); + config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); + try (HikariDataSource dataSource = new HikariDataSource(config)) { + try (Connection conn = dataSource.getConnection()) { + try { + conn.setAutoCommit(false); + conn.createStatement().executeUpdate("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (2024, 1, 2024, 'INSERT_TEST')"); + conn.createStatement().executeUpdate("INSERT INTO t_order_does_not_exist (test_id_does_not_exist) VALUES (2024)"); + conn.commit(); + } catch (final SQLException ignored) { + conn.rollback(); + } finally { + conn.setAutoCommit(true); + } + } + try (Connection conn = dataSource.getConnection()) { + assert !conn.createStatement().executeQuery("SELECT * FROM t_order_item WHERE user_id = 2024").next(); + } + } + } +} +``` + ## 使用限制 ShardingSphere 的 Seata 集成不支持隔离级别。 @@ -137,7 +317,7 @@ ShardingSphere 的 Seata 集成将获取到的 Seata 全局事务置入线程的 这意味着用户在使用 ShardingSphere 的 Seata 集成时,用户应避免使用 `org.apache.seata:seata-all` 的 Java API, 除非用户正在混合使用 ShardingSphere 的 Seata 集成与 Seata Client 的 TCC 模式特性。 -针对 ShardingSphere 数据源,讨论 6 种情况, +针对 ShardingSphere 数据源,讨论 7 种情况, 1. 手动获取从 ShardingSphere 数据源创建的 `java.sql.Connection` 实例,并手动调用 `setAutoCommit()`, `commit()` 和 `rollback()` 方法, 这是被允许的。 @@ -148,9 +328,13 @@ ShardingSphere 的 Seata 集成将获取到的 Seata 全局事务置入线程的 4. 在函数上使用 Spring Framework 的 `org.springframework.transaction.annotation.Transactional` 注解,这是被允许的。 -5. 在函数上使用 `org.apache.seata.spring.annotation.GlobalTransactional` 注解,这是**不被允许的**。 +5. 手动获取从 `org.springframework.transaction.PlatformTransactionManager` 实例创建的 `org.springframework.transaction.support.TransactionTemplate` 实例, +并使用 `org.springframework.transaction.support.TransactionTemplate#execute(org.springframework.transaction.support.TransactionCallback)`, +这是被允许的。 + +6. 在函数上使用 `org.apache.seata.spring.annotation.GlobalTransactional` 注解,这是**不被允许的**。 -6. 手动从 `org.apache.seata.tm.api.GlobalTransactionContext ` 创建 `org.apache.seata.tm.api.GlobalTransaction` 实例, +7. 手动从 `org.apache.seata.tm.api.GlobalTransactionContext ` 创建 `org.apache.seata.tm.api.GlobalTransaction` 实例, 调用 `org.apache.seata.tm.api.GlobalTransaction` 实例的 `begin()`, `commit()` 和 `rollback()` 方法,这是**不被允许的**。 在使用 Spring Boot 的实际情景中, @@ -173,7 +357,7 @@ ShardingSphere 的 Seata 集成将获取到的 Seata 全局事务置入线程的 org.apache.seata seata-spring-boot-starter - 2.1.0 + 2.2.0 org.antlr @@ -378,7 +562,7 @@ public class CustomWebMvcConfigurer implements WebMvcConfigurer { 3. 微服务实例 `a-service` 和 `b-service` 均为 Spring Boot 微服务,但使用的 API 网关中间件阻断了所有包含 `TX_XID` 的 HTTP Header 的 HTTP 请求。 用户需要考虑更改把 XID 通过服务调用传递到微服务实例 `a-service` 使用的 HTTP Header,或使用 RPC 框架把 XID 通过服务调用传递到微服务实例 `a-service`。 -参考 https://github.com/apache/incubator-seata/tree/v2.1.0/integration 。 +参考 https://github.com/apache/incubator-seata/tree/v2.2.0/integration 。 4. 微服务实例 `a-service` 和 `b-service` 均为 Quarkus,Micronaut Framework 和 Helidon 等微服务。 此情况下无法使用 Spring WebMVC HandlerInterceptor。 diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/special-api/transaction/seata.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/special-api/transaction/seata.en.md index 79fbf300d9f1b8..fc3d6f5c46b48d 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/special-api/transaction/seata.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/special-api/transaction/seata.en.md @@ -10,7 +10,7 @@ All references to Seata integration in this article refer to Seata AT mode. ## Prerequisites -ShardingSphere's Seata integration is only available in `apache/incubator-seata:v2.1.0` or higher. +ShardingSphere's Seata integration is only available in `apache/incubator-seata:v2.2.0` or higher. For Seata Client corresponding to the `org.apache.seata:seata-all` Maven module, this limitation applies to both HotSpot VM and GraalVM Native Image. Introduce Maven dependencies and exclude the outdated Maven dependency of `org.antlr:antlr4-runtime:4.8` in `org.apache.seata:seata-all`. @@ -28,88 +28,63 @@ Introduce Maven dependencies and exclude the outdated Maven dependency of `org.a ${shardingsphere.version} - org.apache.seata - seata-all - 2.1.0 - + org.apache.seata + seata-all + 2.2.0 + org.antlr antlr4-runtime - + ``` -Affected by Calcite, -`commons-lang:commons-lang` and `org.apache.commons:commons-pool2` used by ShardingSphere JDBC have dependency conflicts with Seata Client. -Users need to consider whether to resolve dependency conflicts based on actual scenarios. +Affected by Calcite, `commons-lang:commons-lang` and `org.apache.commons:commons-pool2` used by ShardingSphere JDBC have dependency conflicts with Seata Client. +Users need to consider whether to resolve dependency conflicts based on actual scenarios. +If dependency conflicts are not resolved, +build tools such as Maven will randomly use a version of the conflicting dependency in the classpath. When using ShardingSphere's Seata integration module, -the database instance connected to ShardingSphere should implement both ShardingSphere's dialect parsing support and Seata AT mode's dialect parsing support. -Such databases include but are not limited to `mysql`, `gvenzl/oracle-free`, `gvenzl/oracle-xe`, `postgres`, `mcr.microsoft.com/mssql/server` and other Docker Images. +the database instance connected to ShardingSphere should implement both ShardingSphere's dialect parsing support and Seata AT mode's dialect parsing support. +This type of database includes but is not limited to `mysql`, `gvenzl/oracle-free`, `gvenzl/oracle-xe`, `postgres`, +`mcr.microsoft.com/mssql/server` and other Docker Images. -## Procedure +### `undo_log` table restrictions -1. Start Seata Server -2. Create the log table -3. Add the Seata configuration +In each real database instance involved in ShardingSphere, an `undo_log` table needs to be created. +The SQL content of each database is based on the corresponding database in https://github.com/apache/incubator-seata/tree/v2.2.0/script/client/at/db . -## Sample - -### Start Seata Server - -Follow the steps in one of the links below to download and start Seata Server. - -The proper way to start Seata Server is to instantiate it through the Docker Image of `apache/seata-server` in Docker Hub. - -- https://hub.docker.com/r/apache/seata-server - -### Create undo_log table - -Create the `undo_log` table in each real database instance involved in ShardingSphere. -The SQL content is based on the corresponding database in https://github.com/apache/incubator-seata/tree/v2.1.0/script/client/at/db . -The following content takes MySQL as an example. -```sql -CREATE TABLE IF NOT EXISTS `undo_log` -( - `branch_id` BIGINT NOT NULL COMMENT 'branch transaction id', - `xid` VARCHAR(128) NOT NULL COMMENT 'global transaction id', - `context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization', - `rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info', - `log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status', - `log_created` DATETIME(6) NOT NULL COMMENT 'create datetime', - `log_modified` DATETIME(6) NOT NULL COMMENT 'modify datetime', - UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`) - ) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT ='AT transaction mode undo table'; -ALTER TABLE `undo_log` ADD INDEX `ix_log_created` (`log_created`); -``` - -### Modify configuration +### Related configuration Write the following content in the YAML configuration file of ShardingSphere of your own project, refer to [Distributed Transaction](/en/user-manual/shardingsphere-jdbc/yaml-config/rules/transaction). - If Java API is used when initializing ShardingSphere JDBC DataSource, refer to [Distributed Transaction](/en/user-manual/shardingsphere-jdbc/java-api/rules/transaction). ```yaml transaction: - defaultType: BASE - providerType: Seata + defaultType: BASE + providerType: Seata ``` Add the `seata.conf` file to the root directory of the classpath. -The configuration file format refers to the [JavaDoc](https://github.com/apache/incubator-seata/blob/v2.1.0/config/seata-config-core/src/main/java/org/apache/seata/config/FileConfiguration.java) of `org.apache.seata.config.FileConfiguration`. +For the configuration file format, refer to the [JavaDoc](https://github.com/apache/incubator-seata/blob/v2.2.0/config/seata-config-core/src/main/java/org/apache/seata/config/FileConfiguration.java) of `org.apache.seata.config.FileConfiguration`. + +`seata.conf` has four properties, -There are four properties in `seata.conf`, +1. `shardingsphere.transaction.seata.at.enable`, when this value is `true`, enable ShardingSphere's Seata AT integration. +The default value is `true` -1. `shardingsphere.transaction.seata.at.enable`, when this value is `true`, enable ShardingSphere's Seata AT integration. The default value is `true` 2. `shardingsphere.transaction.seata.tx.timeout`, global transaction timeout (seconds). The default value is `60` -3. `client.application.id`, application unique primary key, used to set `applicationId` of Seata Transaction Manager Client and Seata Resource Manager Client -4. `client.transaction.service.group`, transaction group, used to set `transactionServiceGroup` of Seata Transaction Manager Client and Seata Resource Manager Client. -The default value is `default` + +3. `client.application.id`, application unique primary key, +used to set `applicationId` of Seata Transaction Manager Client and Seata Resource Manager Client + +4. `client.transaction.service.group`, transaction group, +used to set `transactionServiceGroup` of Seata Transaction Manager Client and Seata Resource Manager Client. The default value is `default` A fully configured `seata.conf` is as follows, @@ -124,17 +99,228 @@ client { ``` A minimally configured `seata.conf` is as follows. -In `seata.conf` managed by ShardingSphere, the default value of `client.transaction.service.group` is set to `default` for historical reasons. -Assuming that in the `registry.conf` of Seata Server and Seata Client used by the user, `registry.type` and `config.type` are both `file`, -then for the `.conf` file configured by `config.file.name` of `registry.conf`, -the default transaction group name is `default_tx_group` in `apache/incubator-seata:v1.5.1` and later, +In `seata.conf` managed by ShardingSphere, the default value of `client.transaction.service.group` is `default` for historical reasons. +Assuming that `registry.type` and `config.type` are both `file` in `registry.conf` of Seata Server and Seata Client used by the user, +then for `registry.file.name` of `registry.conf`, +the transaction group name in the `.conf` file configured by `config.file.name` is `default_tx_group` in `apache/incubator-seata:v1.5.1` and later, and `my_test_tx_group` before `apache/incubator-seata:v1.5.1`. ```conf client.application.id = example ``` -Modify the `registry.conf` file of Seata as required. +Modify Seata's `registry.conf` file according to the actual scenario. + +## Configuration Example + +### Start Seata Server and MySQL Server + +Write Docker Compose file to start Seata Server and MySQL Server. + +```yaml +services: + apache-seata-server: + image: apache/seata-server:2.2.0 + ports: + - "8091:8091" + mysql: + image: mysql:9.1.0 + environment: + MYSQL_ROOT_PASSWORD: example + volumes: + - ./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d + ports: + - "3306:3306" +``` + +The `./docker-entrypoint-initdb.d` folder contains the file `init.sh`, the content is as follows, + +```shell +#!/bin/bash +set -e + +mysql -uroot -p"$MYSQL_ROOT_PASSWORD" <{0..2}.t_order + keyGenerateStrategy: + column: order_id + keyGeneratorName: snowflake + defaultDatabaseStrategy: + standard: + shardingColumn: user_id + shardingAlgorithmName: inline + shardingAlgorithms: + inline: + type: INLINE + props: + algorithm-expression: ds_${user_id % 2} + keyGenerators: + snowflake: + type: SNOWFLAKE +transaction: + defaultType: BASE + providerType: Seata +``` + +Create ShardingSphere data source and create real tables in all data nodes. + +```java +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +@SuppressWarnings("SqlNoDataSourceInspection") +public class ExampleTest { + void test() throws SQLException { + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml"); + config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); + try (HikariDataSource dataSource = new HikariDataSource(config); + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.execute(""" + CREATE TABLE IF NOT EXISTS t_order ( + order_id BIGINT NOT NULL AUTO_INCREMENT, + order_type INT(11), + user_id INT NOT NULL, + address_id BIGINT NOT NULL, + status VARCHAR(50), + PRIMARY KEY (order_id) + )"""); + } + } +} +``` + +### Enjoy integration + +You can start enjoying integration on ShardingSphere’s data source. + +```java +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import java.sql.Connection; +import java.sql.SQLException; +@SuppressWarnings({"SqlNoDataSourceInspection", "AssertWithSideEffects"}) +public class ExampleTest { + void test() throws SQLException { + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml"); + config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); + try (HikariDataSource dataSource = new HikariDataSource(config)) { + try (Connection conn = dataSource.getConnection()) { + try { + conn.setAutoCommit(false); + conn.createStatement().executeUpdate("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (2024, 1, 2024, 'INSERT_TEST')"); + conn.createStatement().executeUpdate("INSERT INTO t_order_does_not_exist (test_id_does_not_exist) VALUES (2024)"); + conn.commit(); + } catch (final SQLException ignored) { + conn.rollback(); + } finally { + conn.setAutoCommit(true); + } + } + try (Connection conn = dataSource.getConnection()) { + assert !conn.createStatement().executeQuery("SELECT * FROM t_order_item WHERE user_id = 2024").next(); + } + } + } +} +``` ## Usage restrictions @@ -145,21 +331,27 @@ And `org.apache.seata.spring.annotation.GlobalTransactionScanner` uses Dynamic P This means that when using ShardingSphere's Seata integration, users should avoid using the Java API of `org.apache.seata:seata-all`, unless the user is mixing ShardingSphere's Seata integration with the TCC mode feature of Seata Client. -For ShardingSphere data source, discuss 6 situations, +For ShardingSphere data source, 7 situations are discussed. + +1. Manually obtain the `java.sql.Connection` instance created from the ShardingSphere data source and manually call the `setAutoCommit()`, `commit()` and `rollback()` methods. +This is allowed. -1. Manually obtain the `java.sql.Connection` instance created from the ShardingSphere data source, -and manually calling the `setAutoCommit()`, `commit()` and `rollback()` methods is allowed. +2. Use the `javax.transaction.Transactional` annotation of Jakarta EE 8 on the function. This is allowed. -2. Using the Jakarta EE 8 `javax.transaction.Transactional` annotation on the function is allowed. +3. Use the `jakarta.transaction.Transactional` annotation of Jakarta EE 9/10 on the function. This is allowed. -3. Using Jakarta EE 9/10’s `jakarta.transaction.Transactional` annotation on functions is allowed. +4. Use the `org.springframework.transaction.annotation.Transactional` annotation of Spring Framework on the function. +This is allowed. -4. Using Spring Framework’s `org.springframework.transaction.annotation.Transactional` annotation on functions is allowed. +5. Manually obtain an `org.springframework.transaction.support.TransactionTemplate` instance created from an `org.springframework.transaction.PlatformTransactionManager` instance, + and use `org.springframework.transaction.support.TransactionTemplate#execute(org.springframework.transaction.support.TransactionCallback)`, + which is allowed. -5. Using the `org.apache.seata.spring.annotation.GlobalTransactional` annotation on the function is **not allowed**. +6. Use the `org.apache.seata.spring.annotation.GlobalTransactional` annotation on a function, which is **not allowed**. -6. Manually create `org.apache.seata.tm.api.GlobalTransaction` instance from `org.apache.seata.tm.api.GlobalTransactionContext`, -calling the `begin()`, `commit()` and `rollback()` methods of an `org.apache.seata.tm.api.GlobalTransaction` instance is **not allowed**. +7. Manually create an `org.apache.seata.tm.api.GlobalTransaction` instance from an `org.apache.seata.tm.api.GlobalTransactionContext`, + and call the `begin()`, `commit()`, and `rollback()` methods of the `org.apache.seata.tm.api.GlobalTransaction` instance, + which is **not allowed**. In actual scenarios where Spring Boot is used, `com.alibaba.cloud:spring-cloud-starter-alibaba-seata` and `org.apache.seata:seata-spring-boot-starter` are often transitively imported by other Maven dependencies. @@ -182,7 +374,7 @@ A possible dependency relationship is as follows. org.apache.seata seata-spring-boot-starter - 2.1.0 + 2.2.0 org.antlr @@ -402,7 +594,7 @@ the changes to the MySQL database instances `a-mysql` and `b-mysql` in the busin but the API gateway middleware used blocks all HTTP requests containing the HTTP Header of `TX_XID`. The user needs to consider changing the HTTP Header used to pass XID to the microservice instance `a-service` through service calls, or use the RPC framework to pass XID to the microservice instance `a-service` through service calls. -Refer to https://github.com/apache/incubator-seata/tree/v2.1.0/integration . +Refer to https://github.com/apache/incubator-seata/tree/v2.2.0/integration . 4. The microservice instances `a-service` and `b-service` are both microservices such as Quarkus, Micronaut Framework and Helidon. In this case, Spring WebMVC HandlerInterceptor cannot be used. diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.alibaba/druid/1.2.7/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.alibaba/druid/1.2.20/reflect-config.json similarity index 100% rename from infra/reachability-metadata/src/main/resources/META-INF/native-image/com.alibaba/druid/1.2.7/reflect-config.json rename to infra/reachability-metadata/src/main/resources/META-INF/native-image/com.alibaba/druid/1.2.20/reflect-config.json diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.alibaba/druid/1.2.7/resource-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.alibaba/druid/1.2.20/resource-config.json similarity index 100% rename from infra/reachability-metadata/src/main/resources/META-INF/native-image/com.alibaba/druid/1.2.7/resource-config.json rename to infra/reachability-metadata/src/main/resources/META-INF/native-image/com.alibaba/druid/1.2.20/resource-config.json diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.1.0/proxy-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.2.0/proxy-config.json similarity index 100% rename from infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.1.0/proxy-config.json rename to infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.2.0/proxy-config.json diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.1.0/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.2.0/reflect-config.json similarity index 95% rename from infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.1.0/reflect-config.json rename to infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.2.0/reflect-config.json index 7a99148da23530..32508ed4a02514 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.1.0/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.2.0/reflect-config.json @@ -28,7 +28,7 @@ "name":"io.seata.core.rpc.hook.RpcHook" }, { - "condition":{"typeReachable":"org.apache.seata.core.serializer.SerializerServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, "name":"io.seata.core.serializer.Serializer" }, { @@ -94,7 +94,7 @@ "name":"org.apache.seata.config.Configuration" }, { - "condition":{"typeReachable":"org.apache.seata.config.ConfigurationCache$$Lambda/0x00007fea13cd9cb0"}, + "condition":{"typeReachable":"org.apache.seata.config.ConfigurationCache$$Lambda/0x00007fda3bd03530"}, "name":"org.apache.seata.config.Configuration" }, { @@ -156,11 +156,11 @@ }, { "condition":{"typeReachable":"org.apache.seata.core.rpc.netty.NettyClientBootstrap$1"}, - "name":"org.apache.seata.core.rpc.netty.v1.ProtocolV1Decoder" + "name":"org.apache.seata.core.rpc.netty.v1.ProtocolDecoderV1" }, { "condition":{"typeReachable":"org.apache.seata.core.rpc.netty.NettyClientBootstrap$1"}, - "name":"org.apache.seata.core.rpc.netty.v1.ProtocolV1Encoder" + "name":"org.apache.seata.core.rpc.netty.v1.ProtocolEncoderV1" }, { "condition":{"typeReachable":"org.apache.seata.discovery.registry.RegistryFactory"}, @@ -187,6 +187,10 @@ "condition":{"typeReachable":"org.apache.seata.discovery.registry.RegistryFactory"}, "name":"org.apache.seata.discovery.registry.nacos.NacosRegistryProvider" }, +{ + "condition":{"typeReachable":"org.apache.seata.discovery.registry.RegistryFactory"}, + "name":"org.apache.seata.discovery.registry.namingserver.NamingserverRegistryProvider" +}, { "condition":{"typeReachable":"org.apache.seata.discovery.registry.RegistryFactory"}, "name":"org.apache.seata.discovery.registry.raft.RaftRegistryProvider" @@ -281,7 +285,7 @@ "name":"org.apache.seata.rm.datasource.sql.struct.Field" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fea13db8000"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fda3bdf6300"}, "name":"org.apache.seata.rm.datasource.sql.struct.Field" }, { @@ -306,7 +310,7 @@ "name":"org.apache.seata.rm.datasource.sql.struct.Field" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fea13d17d98"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fda3bde4000"}, "name":"org.apache.seata.rm.datasource.sql.struct.Field" }, { @@ -350,7 +354,7 @@ "name":"org.apache.seata.rm.datasource.sql.struct.Row" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fea13db8000"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fda3bdf6300"}, "name":"org.apache.seata.rm.datasource.sql.struct.Row" }, { @@ -375,7 +379,7 @@ "name":"org.apache.seata.rm.datasource.sql.struct.Row" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fea13d17d98"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fda3bde4000"}, "name":"org.apache.seata.rm.datasource.sql.struct.Row" }, { @@ -407,7 +411,7 @@ "name":"org.apache.seata.rm.datasource.sql.struct.TableRecords" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fea13db8000"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fda3bdf6300"}, "name":"org.apache.seata.rm.datasource.sql.struct.TableRecords" }, { @@ -432,7 +436,7 @@ "name":"org.apache.seata.rm.datasource.sql.struct.TableRecords" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fea13d17d98"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fda3bde4000"}, "name":"org.apache.seata.rm.datasource.sql.struct.TableRecords" }, { @@ -508,7 +512,7 @@ "name":"org.apache.seata.rm.datasource.undo.BranchUndoLog" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fea13db8000"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fda3bdf6300"}, "name":"org.apache.seata.rm.datasource.undo.BranchUndoLog" }, { @@ -533,7 +537,7 @@ "name":"org.apache.seata.rm.datasource.undo.BranchUndoLog" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fea13d17d98"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fda3bde4000"}, "name":"org.apache.seata.rm.datasource.undo.BranchUndoLog" }, { @@ -565,7 +569,7 @@ "name":"org.apache.seata.rm.datasource.undo.SQLUndoLog" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fea13db8000"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.ConnectionProxy$$Lambda/0x00007fda3bdf6300"}, "name":"org.apache.seata.rm.datasource.undo.SQLUndoLog" }, { @@ -590,7 +594,7 @@ "name":"org.apache.seata.rm.datasource.undo.SQLUndoLog" }, { - "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fea13d17d98"}, + "condition":{"typeReachable":"org.apache.seata.rm.datasource.exec.AbstractDMLBaseExecutor$$Lambda/0x00007fda3bde4000"}, "name":"org.apache.seata.rm.datasource.undo.SQLUndoLog" }, { @@ -718,17 +722,21 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.seata.core.serializer.SerializerServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, "name":"org.apache.seata.serializer.hessian.HessianSerializer" }, { - "condition":{"typeReachable":"org.apache.seata.core.serializer.SerializerServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, "name":"org.apache.seata.serializer.kryo.KryoSerializer" }, { - "condition":{"typeReachable":"org.apache.seata.core.serializer.SerializerServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.util.ReflectionUtil"}, + "name":"org.apache.seata.serializer.protobuf.ProtobufSerializer" +}, +{ + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, "name":"org.apache.seata.serializer.seata.SeataSerializer", - "methods":[{"name":"","parameterTypes":[] }] + "methods":[{"name":"","parameterTypes":["java.lang.Byte"] }] }, { "condition":{"typeReachable":"org.apache.seata.rm.datasource.PreparedStatementProxy"}, @@ -824,7 +832,7 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader"}, "name":"io.seata.config.file.FileConfig" } ] diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.1.0/resource-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.2.0/resource-config.json similarity index 95% rename from infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.1.0/resource-config.json rename to infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.2.0/resource-config.json index 44a5a1bdb11bcf..2eafff6c810a81 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.1.0/resource-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.seata/seata-all/2.2.0/resource-config.json @@ -1,9 +1,6 @@ { "resources":{ "includes":[{ - "condition":{"typeReachable":"org.apache.seata.sqlparser.druid.DruidDbTypeParserImpl"}, - "pattern":"\\QMETA-INF/druid-driver.properties\\E" - }, { "condition":{"typeReachable":"org.apache.seata.config.ConfigurationFactory"}, "pattern":"\\QMETA-INF/seata/io.seata.config.ConfigurationProvider\\E" }, { @@ -16,7 +13,7 @@ "condition":{"typeReachable":"org.apache.seata.rm.DefaultResourceManager"}, "pattern":"\\QMETA-INF/seata/io.seata.core.model.ResourceManager\\E" }, { - "condition":{"typeReachable":"org.apache.seata.core.serializer.SerializerServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, "pattern":"\\QMETA-INF/seata/io.seata.core.serializer.Serializer\\E" }, { "condition":{"typeReachable":"org.apache.seata.discovery.registry.RegistryFactory"}, @@ -49,7 +46,7 @@ "condition":{"typeReachable":"org.apache.seata.core.rpc.netty.AbstractNettyRemoting"}, "pattern":"\\QMETA-INF/seata/org.apache.seata.core.rpc.hook.RpcHook\\E" }, { - "condition":{"typeReachable":"org.apache.seata.core.serializer.SerializerServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, "pattern":"\\QMETA-INF/seata/org.apache.seata.core.serializer.Serializer\\E" }, { "condition":{"typeReachable":"org.apache.seata.discovery.registry.RegistryFactory"}, @@ -100,7 +97,7 @@ "condition":{"typeReachable":"org.apache.seata.rm.DefaultResourceManager"}, "pattern":"\\QMETA-INF/services/io.seata.core.model.ResourceManager\\E" }, { - "condition":{"typeReachable":"org.apache.seata.core.serializer.SerializerServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, "pattern":"\\QMETA-INF/services/io.seata.core.serializer.Serializer\\E" }, { "condition":{"typeReachable":"org.apache.seata.discovery.registry.RegistryFactory"}, @@ -133,7 +130,7 @@ "condition":{"typeReachable":"org.apache.seata.core.rpc.netty.AbstractNettyRemoting"}, "pattern":"\\QMETA-INF/services/org.apache.seata.core.rpc.hook.RpcHook\\E" }, { - "condition":{"typeReachable":"org.apache.seata.core.serializer.SerializerServiceLoader"}, + "condition":{"typeReachable":"org.apache.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader"}, "pattern":"\\QMETA-INF/services/org.apache.seata.core.serializer.Serializer\\E" }, { "condition":{"typeReachable":"org.apache.seata.discovery.registry.RegistryFactory"}, diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json index 3988f03fe69836..5c118e143e0d13 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json @@ -16,7 +16,7 @@ "name":"[Lcom.github.dockerjava.api.model.VolumesFrom;" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f1137caca88"}, + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f191bcb0000"}, "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" }, { @@ -2080,7 +2080,7 @@ "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.listener.DatabaseMetaDataChangedListener$$Lambda/0x00007f1137b2dc80"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.listener.DatabaseMetaDataChangedListener$$Lambda/0x00007f191bb2bb50"}, "name":"org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.MetaDataChangedSubscriber" }, { @@ -2278,7 +2278,7 @@ "name":"org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyServerConfiguration", "allDeclaredFields":true, "queryAllPublicMethods":true, - "methods":[{"name":"","parameterTypes":[] }, {"name":"setAuthority","parameterTypes":["org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration"] }, {"name":"setMode","parameterTypes":["org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlModeConfiguration"] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }] + "methods":[{"name":"","parameterTypes":[] }, {"name":"setAuthority","parameterTypes":["org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration"] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }] }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"}, @@ -3649,5 +3649,10 @@ { "condition":{"typeReachable":"org.apache.shardingsphere.proxy.initializer.BootstrapInitializer"}, "name":"org.apache.shardingsphere.transaction.yaml.config.YamlTransactionRuleConfigurationCustomizer" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine"}, + "name":"sun.security.provider.SecureRandom", + "methods":[{"name":"","parameterTypes":[] }, {"name":"","parameterTypes":["java.security.SecureRandomParameters"] }] } ] \ No newline at end of file diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json index 4355d10bc0b257..c817be4b3c3ef1 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json @@ -79,7 +79,7 @@ "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager"}, "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f1137b39f20"}, + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f191bb3ad18"}, "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"}, @@ -244,7 +244,7 @@ "condition":{"typeReachable":"org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandlerFactory"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.executor.checker.SQLExecutionChecker\\E" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor"}, + "condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.executor.sql.hook.SQLExecutionHook\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.sql.prepare.AbstractExecutionPrepareEngine"}, diff --git a/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/fixture/MockSeataServer.java b/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/fixture/MockSeataServer.java index a7d32ee88fcffd..b8cc9655f439ce 100644 --- a/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/fixture/MockSeataServer.java +++ b/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/fixture/MockSeataServer.java @@ -26,11 +26,11 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; -import org.apache.seata.core.rpc.netty.v1.ProtocolV1Decoder; -import org.apache.seata.core.rpc.netty.v1.ProtocolV1Encoder; import lombok.Getter; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; +import org.apache.seata.core.rpc.netty.v1.ProtocolDecoderV1; +import org.apache.seata.core.rpc.netty.v1.ProtocolEncoderV1; import java.util.concurrent.atomic.AtomicBoolean; @@ -77,8 +77,8 @@ public void start() { @Override public void initChannel(final SocketChannel socketChannel) { socketChannel.pipeline() - .addLast(new ProtocolV1Decoder()) - .addLast(new ProtocolV1Encoder()) + .addLast(new ProtocolDecoderV1()) + .addLast(new ProtocolEncoderV1()) .addLast(messageHandler); } }); diff --git a/kernel/transaction/type/base/seata-at/src/test/resources/file.conf b/kernel/transaction/type/base/seata-at/src/test/resources/file.conf index 0a3731adf57055..783e7d901e2ff9 100644 --- a/kernel/transaction/type/base/seata-at/src/test/resources/file.conf +++ b/kernel/transaction/type/base/seata-at/src/test/resources/file.conf @@ -15,44 +15,7 @@ # limitations under the License. # -transport { - # tcp udt unix-domain-socket - type = "TCP" - #NIO NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - #thread factory for netty - thread-factory { - boss-thread-prefix = "NettyBoss" - worker-thread-prefix = "NettyServerNIOWorker" - server-executor-thread-prefix = "NettyServerBizHandler" - share-boss-worker = false - client-selector-thread-prefix = "NettyClientSelector" - client-selector-thread-size = 1 - client-worker-thread-prefix = "NettyClientWorkerThread" - # netty boss thread size,will not be used for UDT - boss-thread-size = 1 - #auto default pin or 8 - worker-thread-size = 8 - } -} service { - #vgroup->rgroup vgroupMapping.default_tx_group = "default" - #only support single node default.grouplist = "127.0.0.1:8891" - #disable - disable = false -} - -client { - async.commit.buffer.limit = 10000 - lock { - retry.internal = 10 - retry.times = 30 - } - tm { - degradeCheck = false - } } diff --git a/kernel/transaction/type/base/seata-at/src/test/resources/logback-test.xml b/kernel/transaction/type/base/seata-at/src/test/resources/logback-test.xml index d17f7efbfaf308..c077d990130c29 100644 --- a/kernel/transaction/type/base/seata-at/src/test/resources/logback-test.xml +++ b/kernel/transaction/type/base/seata-at/src/test/resources/logback-test.xml @@ -26,7 +26,6 @@ - diff --git a/kernel/transaction/type/base/seata-at/src/test/resources/registry.conf b/kernel/transaction/type/base/seata-at/src/test/resources/registry.conf index 2ed8a6903a08b8..6801e320a70343 100644 --- a/kernel/transaction/type/base/seata-at/src/test/resources/registry.conf +++ b/kernel/transaction/type/base/seata-at/src/test/resources/registry.conf @@ -16,38 +16,13 @@ # registry { - # file 、eureka、redis、zk type = "file" - - eureka { - serviceUrl = "http://localhost:1001/eureka" - application = "default" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - } - zk { - cluster = "default" - serverAddr = "127.0.0.1:2181" - session.timeout = 6000 - connect.timeout = 2000 - } file { name = "file.conf" } } - config { - # file、zk type = "file" - - zk { - serverAddr = "127.0.0.1:2181" - session.timeout = 6000 - connect.timeout = 2000 - } file { name = "file.conf" } diff --git a/pom.xml b/pom.xml index b5c5a366841d6a..ab62d5b2e5ecc9 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ 5.12.7.Final 7.6.1.Final 3.2.1.Final - 2.1.0 + 2.2.0 4.1.112.Final 1.78.1 diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java index d30d320ec7ef9a..33b8965aa7bdec 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java @@ -19,7 +19,7 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import org.apache.http.HttpStatus; +import org.apache.hc.core5.http.HttpStatus; import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.test.natived.commons.TestShardingService; import org.junit.jupiter.api.AfterAll; @@ -46,7 +46,7 @@ class SeataTest { @SuppressWarnings("resource") @Container - public static final GenericContainer CONTAINER = new GenericContainer<>("apache/seata-server:2.1.0") + public static final GenericContainer CONTAINER = new GenericContainer<>("apache/seata-server:2.2.0") .withExposedPorts(7091, 8091) .waitingFor(Wait.forHttp("/health") .forPort(7091) diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/features/ShardingTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java similarity index 98% rename from test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/features/ShardingTest.java rename to test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java index 3b318ea4f55019..f5a767f76db62e 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/features/ShardingTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.test.natived.proxy.features; +package org.apache.shardingsphere.test.natived.proxy.databases; import com.mysql.cj.jdbc.exceptions.CommunicationsException; import com.zaxxer.hikari.HikariConfig; @@ -43,7 +43,7 @@ @SuppressWarnings({"SqlNoDataSourceInspection", "SameParameterValue", "resource"}) @EnabledInNativeImage @Testcontainers -class ShardingTest { +class MySQLTest { @Container public static final GenericContainer MYSQL_CONTAINER = new GenericContainer<>("mysql:9.1.0-oraclelinux9") @@ -68,7 +68,7 @@ static void beforeAll() throws SQLException { statement.executeUpdate("CREATE DATABASE demo_ds_1"); statement.executeUpdate("CREATE DATABASE demo_ds_2"); } - String absolutePath = Paths.get("src/test/resources/test-native/yaml/proxy/features/sharding").toAbsolutePath().toString(); + String absolutePath = Paths.get("src/test/resources/test-native/yaml/proxy/databases/mysql").toAbsolutePath().toString(); proxyTestingServer = new ProxyTestingServer(absolutePath); Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptionsMatching(e -> e instanceof CommunicationsException).until(() -> { openConnection("root", "root", "jdbc:mysql://127.0.0.1:" + proxyTestingServer.getProxyPort()).close(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/PostgresTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/PostgresTest.java index 4e5413aba1a953..2edcbf361bf71a 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/PostgresTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/PostgresTest.java @@ -26,7 +26,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledInNativeImage; -import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; @@ -39,15 +39,13 @@ import java.time.Duration; import java.util.Properties; -@SuppressWarnings({"SqlNoDataSourceInspection", "SameParameterValue", "resource"}) +@SuppressWarnings("SqlNoDataSourceInspection") @EnabledInNativeImage @Testcontainers class PostgresTest { @Container - public static final GenericContainer POSTGRES_CONTAINER = new GenericContainer<>("postgres:17.1-bookworm") - .withEnv("POSTGRES_PASSWORD", "yourStrongPassword123!") - .withExposedPorts(5432); + public static final PostgreSQLContainer POSTGRES_CONTAINER = new PostgreSQLContainer<>("postgres:17.1-bookworm"); private static ProxyTestingServer proxyTestingServer; @@ -56,12 +54,12 @@ class PostgresTest { @BeforeAll static void beforeAll() throws SQLException { Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(() -> { - openConnection("postgres", "yourStrongPassword123!", "jdbc:postgresql://127.0.0.1:" + POSTGRES_CONTAINER.getMappedPort(5432) + "/") + openConnection("test", "test", "jdbc:postgresql://127.0.0.1:" + POSTGRES_CONTAINER.getMappedPort(5432) + "/") .close(); return true; }); try ( - Connection connection = openConnection("postgres", "yourStrongPassword123!", "jdbc:postgresql://127.0.0.1:" + POSTGRES_CONTAINER.getMappedPort(5432) + "/"); + Connection connection = openConnection("test", "test", "jdbc:postgresql://127.0.0.1:" + POSTGRES_CONTAINER.getMappedPort(5432) + "/"); Statement statement = connection.createStatement()) { statement.executeUpdate("CREATE DATABASE demo_ds_0"); statement.executeUpdate("CREATE DATABASE demo_ds_1"); @@ -99,16 +97,16 @@ void assertShardingInLocalTransactions() throws SQLException { Statement statement = connection.createStatement()) { statement.execute("REGISTER STORAGE UNIT ds_0 (\n" + " URL=\"jdbc:postgresql://127.0.0.1:" + POSTGRES_CONTAINER.getMappedPort(5432) + "/demo_ds_0\",\n" - + " USER=\"postgres\",\n" - + " PASSWORD=\"yourStrongPassword123!\"\n" + + " USER=\"test\",\n" + + " PASSWORD=\"test\"\n" + "),ds_1 (\n" + " URL=\"jdbc:postgresql://127.0.0.1:" + POSTGRES_CONTAINER.getMappedPort(5432) + "/demo_ds_1\",\n" - + " USER=\"postgres\",\n" - + " PASSWORD=\"yourStrongPassword123!\"\n" + + " USER=\"test\",\n" + + " PASSWORD=\"test\"\n" + "),ds_2 (\n" + " URL=\"jdbc:postgresql://127.0.0.1:" + POSTGRES_CONTAINER.getMappedPort(5432) + "/demo_ds_2\",\n" - + " USER=\"postgres\",\n" - + " PASSWORD=\"yourStrongPassword123!\"\n" + + " USER=\"test\",\n" + + " PASSWORD=\"test\"\n" + ")"); statement.execute("CREATE DEFAULT SHARDING DATABASE STRATEGY (\n" + " TYPE=\"standard\", \n" diff --git a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json index 44c372fa4dd88f..6ac73f1ee1181a 100644 --- a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json +++ b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json @@ -10,8 +10,8 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.proxy.features.ShardingTest"}, - "name":"org.apache.shardingsphere.test.natived.proxy.features.ShardingTest", + "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.proxy.databases.MySQLTest"}, + "name":"org.apache.shardingsphere.test.natived.proxy.databases.MySQLTest", "allDeclaredConstructors": true, "allDeclaredMethods": true, "allPublicMethods": true, diff --git a/test/native/src/test/resources/logback-test.xml b/test/native/src/test/resources/logback-test.xml index 5367fd2b1a339e..7eaf3a36e3528a 100644 --- a/test/native/src/test/resources/logback-test.xml +++ b/test/native/src/test/resources/logback-test.xml @@ -26,7 +26,6 @@ - diff --git a/test/native/src/test/resources/seata-script-client-conf-file.conf b/test/native/src/test/resources/seata-script-client-conf-file.conf index 28a355c0ca7d41..f5700207f5b07d 100644 --- a/test/native/src/test/resources/seata-script-client-conf-file.conf +++ b/test/native/src/test/resources/seata-script-client-conf-file.conf @@ -20,3 +20,9 @@ service { vgroupMapping.default_tx_group = "default" } +# TODO This is not a reasonable configuration, just affected by https://github.com/apache/incubator-seata/pull/6661. Pending investigation. +client { + rm { + tableMetaCheckEnable = "false" + } +} diff --git a/test/native/src/test/resources/test-native/yaml/proxy/features/sharding/global.yaml b/test/native/src/test/resources/test-native/yaml/proxy/databases/mysql/global.yaml similarity index 92% rename from test/native/src/test/resources/test-native/yaml/proxy/features/sharding/global.yaml rename to test/native/src/test/resources/test-native/yaml/proxy/databases/mysql/global.yaml index 5572ece5c27875..28b6e40b4da2cd 100644 --- a/test/native/src/test/resources/test-native/yaml/proxy/features/sharding/global.yaml +++ b/test/native/src/test/resources/test-native/yaml/proxy/databases/mysql/global.yaml @@ -15,10 +15,6 @@ # limitations under the License. # -mode: - type: Standalone - repository: - type: JDBC authority: users: - user: root@% @@ -26,5 +22,4 @@ authority: privilege: type: ALL_PERMITTED props: - sql-show: false proxy-frontend-database-protocol-type: MySQL diff --git a/test/native/src/test/resources/test-native/yaml/proxy/databases/postgresql/global.yaml b/test/native/src/test/resources/test-native/yaml/proxy/databases/postgresql/global.yaml index 164a86b1095633..f55539936ebe20 100644 --- a/test/native/src/test/resources/test-native/yaml/proxy/databases/postgresql/global.yaml +++ b/test/native/src/test/resources/test-native/yaml/proxy/databases/postgresql/global.yaml @@ -15,10 +15,6 @@ # limitations under the License. # -mode: - type: Standalone - repository: - type: JDBC authority: users: - user: root@% @@ -26,5 +22,4 @@ authority: privilege: type: ALL_PERMITTED props: - sql-show: false proxy-frontend-database-protocol-type: PostgreSQL