Skip to content

Commit

Permalink
Bump Seata Client for testing to 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Feb 16, 2024
1 parent 238e570 commit 934b7b3
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,63 @@ weight = 7

Apache ShardingSphere 提供 BASE 事务,集成了 Seata 的实现。

## 前提条件

引入 Maven 依赖,并排除 `io.seata:seata-all` 中过时的 `org.antlr:antlr4-runtime:4.8` 的 Maven 依赖。

```xml
<project>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-transaction-base-seata-at</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>2.0.0</version>
<exclusions>
<exclusion>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
```

始终要求 Seata Server 与 Seata Client 版本匹配。假设存在以下场景,

- ShardingSphere 数据库单元为 `mysql:8.3.0-oraclelinux8` 的 Docker Image
- Seata Server 为 `seataio/seata-server:2.0.0` 的 Docker Image
- Seata Client 为 `io.seata:seata-all:1.7.1` 的 Maven 依赖

则抛出以下 Error Log 是合理行为,说明需要更换 Seata Client 版本以匹配 Seata Server。

```shell
[ERROR] 2024-02-16 19:28:35.520 [AsyncWorker_1_2_2] io.seata.rm.datasource.AsyncWorker - Failed to batch delete undo log
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
...
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
...
Caused by: java.io.IOException: Socket is closed
at com.mysql.cj.protocol.AbstractSocketConnection.getMysqlInput(AbstractSocketConnection.java:72)
...
[ERROR] 2024-02-16 19:28:35.520 [AsyncWorker_1_2_2] io.seata.rm.datasource.AsyncWorker - Failed to rollback JDBC resource after deleting undo log failed
java.sql.SQLException: Connection is closed
at com.zaxxer.hikari.pool.ProxyConnection$ClosedConnection.lambda$getClosedConnection$0(ProxyConnection.java:515)
...
```

## 操作步骤

1. 启动 Seata Server
Expand All @@ -24,31 +81,32 @@ Apache ShardingSphere 提供 BASE 事务,集成了 Seata 的实现。
在每一个分片数据库实例中执创建 `undo_log` 表(以 MySQL 为例)。

```sql
CREATE TABLE IF NOT EXISTS `undo_log`
(
`id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'increment id',
`branch_id` BIGINT(20) NOT NULL COMMENT 'branch transaction id',
`xid` VARCHAR(100) 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 NOT NULL COMMENT 'create datetime',
`log_modified` DATETIME NOT NULL COMMENT 'modify datetime',
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
```

### 修改配置

在 classpath 中增加 `seata.conf` 文件。
在 classpath 的根目录中增加 `seata.conf` 文件, 配置文件格式参考 `io.seata.config.FileConfiguration` 的 JavaDoc

```conf
sharding.transaction.seata.at.enable = true ## 当此值为`true`时,开启 ShardingSphere 的 Seata AT 集成,存在默认值为 `true`
sharding.transaction.seata.tx.timeout = 30 ## 全局事务超时(秒),存在默认值为 `60`
client {
application.id = example ## 应用唯一主键
transaction.service.group = my_test_tx_group ## 所属事务组
transaction.service.group = default_tx_group ## 所属事务组,存在默认值为 `default`
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,65 @@ weight = 7

Apache ShardingSphere provides BASE transactions that integrate the Seata implementation.

## Prerequisites

Introduce Maven dependencies and exclude the outdated Maven dependencies of `org.antlr:antlr4-runtime:4.8` in `io.seata:seata-all`.

```xml
<project>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-transaction-base-seata-at</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>2.0.0</version>
<exclusions>
<exclusion>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
```

It is always required that the Seata Server and Seata Client versions match.
Assume that the following scenario exists,

- ShardingSphere database unit is the Docker Image of `mysql:8.3.0-oraclelinux8`
- Seata Server is the Docker Image of `seataio/seata-server:2.0.0`
- Seata Client is the Maven dependency of `io.seata:seata-all:1.7.1`

It is a reasonable behavior to throw the following Error Log,
indicating that the Seata Client version needs to be changed to match the Seata Server.

```shell
[ERROR] 2024-02-16 15:14:24.172 [AsyncWorker_1_1_2] io.seata.rm.datasource.AsyncWorker - Failed to batch delete undo log
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
...
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
...
Caused by: java.io.IOException: Socket is closed
at com.mysql.cj.protocol.AbstractSocketConnection.getMysqlInput(AbstractSocketConnection.java:72)
... 23 common frames omitted
[ERROR] 2024-02-16 15:14:24.174 [AsyncWorker_1_1_2] io.seata.rm.datasource.AsyncWorker - Failed to rollback JDBC resource after deleting undo log failed
java.sql.SQLException: Connection is closed
at com.zaxxer.hikari.pool.ProxyConnection$ClosedConnection.lambda$getClosedConnection$0(ProxyConnection.java:515)
...
```

## Procedure

1. Start Seata Server
Expand All @@ -24,31 +83,33 @@ Refer to [seata-work-shop](https://github.com/seata/seata-workshop) to download
Create the `undo_log` table in each shard database instance (take MySQL as an example).

```sql
CREATE TABLE IF NOT EXISTS `undo_log`
(
`id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'increment id',
`branch_id` BIGINT(20) NOT NULL COMMENT 'branch transaction id',
`xid` VARCHAR(100) 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 NOT NULL COMMENT 'create datetime',
`log_modified` DATETIME NOT NULL COMMENT 'modify datetime',
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
```

### Modify configuration

Add the `seata.conf` file to the classpath.
Add the `seata.conf` file to the root directory of the classpath.
The configuration file format refers to the JavaDoc of `io.seata.config.FileConfiguration`.

```conf
sharding.transaction.seata.at.enable = true ## When this value is `true`, ShardingSphere's Seata AT integration is enabled, there is a default value of `true`
sharding.transaction.seata.tx.timeout = 30 ## Global transaction timeout in SECONDS, there is a default value of `60`
client {
application.id = example ## Apply the only primary key
transaction.service.group = my_test_tx_group ## The transaction group it belongs to.
transaction.service.group = default_tx_group ## The transaction group it belongs to, there is a default value of `default`
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ transport {
}
service {
#vgroup->rgroup
vgroupMapping.my_test_tx_group = "default"
vgroupMapping.default_tx_group = "default"
#only support single node
default.grouplist = "127.0.0.1:8891"
#degrade current not support
enableDegrade = false
#disable
disable = false
}
Expand All @@ -54,4 +52,7 @@ client {
retry.internal = 10
retry.times = 30
}
tm {
degradeCheck = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ sharding.transaction.seata.tx.timeout = 30

client {
application.id = jdbc-test
transaction.service.group = my_test_tx_group
transaction.service.group = default_tx_group
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<narayana.version>5.12.4.Final</narayana.version>
<jboss-transaction-spi.version>7.6.0.Final</jboss-transaction-spi.version>
<jboss-logging.version>3.2.1.Final</jboss-logging.version>
<seata.version>1.6.1</seata.version>
<seata.version>2.0.0</seata.version>

<netty.version>4.1.106.Final</netty.version>
<bouncycastle.version>1.70</bouncycastle.version>
Expand Down

0 comments on commit 934b7b3

Please sign in to comment.