Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: First support native-image for seata-client #5234

Draft
wants to merge 119 commits into
base: 2.x
Choose a base branch
from

Conversation

wangliang181230
Copy link
Contributor

@wangliang181230 wangliang181230 commented Jan 6, 2023

由于 TCC 的重构,导致此PR有些内容未兼容。需要改造。

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

feature: First support native-image of the seata-client.
新特性:首次针对 native-image 做兼容性改造。


已支持的功能:

  1. AT
  2. XA
  3. TCC
  4. nacos: 注册中心nacos1.4.4测试通过,2.x测试未通过。配置中心暂未测试。
  5. eureka: 使用seata中定义的版本时,测试通过。

暂未支持的功能:

  1. SAGA
  2. 其他可选组件,都未测试。

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

  1. 下载此PR的代码,并执行 mvn clean install -DskipTests,将 jar包 install 到本地仓库。
  2. 下载我的学习用仓库的 seata-support-aot 分支:https://github.com/wangliang181230/study-spring-boot/tree/seata-support-aot
  3. 安装打包native所需环境,参考教程:https://easyj.icu/blog/#/native-image/
  4. 用 IDE 单独打开项目中的 test-compatibility-springboot3-seata 小目录,不是 study-spring-boot 大目录。
  5. 运行命令 mvn clean package -Pnative -e -DskipTests,开始打包 native-image

注意:打包 native-image 非常消耗内存,内存不足时,容易失败,请尽量关闭不需要的软件,释放内存。
运行完成后,/target/ 目录下,会生成一个 exe 文件,后面环境准备好后。

  1. 启动 seata-server
  2. 启动 mysql,并创建数据库:seata_study,再运行以下脚本创建表:
CREATE TABLE `tb_order` (
  `id` bigint NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

CREATE TABLE `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 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 COMMENT='AT transaction mode undo table';
  1. 点击目录下的 startup-exe.bat 文件,启动 native-image
  2. 访问站点根地址 http://localhost:8081/,测试成功情况;
  3. 另外再访问 http://localhost:8081/?test=1,测试 insert 语句完成后,抛异常的情况,观察表 undo_log 中会有一条数据,等10秒后回滚后被删除。
  4. 另外再访问 http://localhost:8081/?test=2,测试 insert 语句 和 tcc.prepare 方法完成后,抛异常的情况,观察表 undo_log 中会有一条数据,等10秒后回滚后被删除。同时,控制台会打印类似 test tcc: rollback...... 字样。
  5. 关闭 exe 进程,启动 startup-exe-by-XA-mode.bat,重复8、9、10步骤,测试 XA 模式。

以上,AT、XA、TCC三种模式,测试成功。

Ⅴ. Special notes for reviews

seata-spring-framework-fake-for-java8 模块,仅为了使aot相关代码在java8可以编译通过。使 seata 的jar包可以同时兼容高低版本的 java.

@codecov-commenter
Copy link

codecov-commenter commented Jan 6, 2023

Codecov Report

Merging #5234 (7d290cd) into 2.x (08f96f5) will decrease coverage by 0.23%.
The diff coverage is 4.65%.

❗ Current head 7d290cd differs from pull request most recent head 2c40a09. Consider uploading reports for the commit 2c40a09 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #5234      +/-   ##
============================================
- Coverage     48.89%   48.66%   -0.23%     
+ Complexity     4223     4164      -59     
============================================
  Files           764      745      -19     
  Lines         26870    26626     -244     
  Branches       3352     3327      -25     
============================================
- Hits          13137    12957     -180     
+ Misses        12353    12274      -79     
- Partials       1380     1395      +15     
Impacted Files Coverage Δ
...src/main/java/io/seata/common/aot/NativeUtils.java 0.00% <0.00%> (ø)
...main/java/io/seata/common/util/ReflectionUtil.java 56.68% <0.00%> (-1.56%) ⬇️
...seata/core/serializer/SerializerServiceLoader.java 0.00% <ø> (ø)
...t/SeataPropertiesBeanRegistrationAotProcessor.java 0.00% <0.00%> (ø)
...ta/spring/annotation/GlobalTransactionScanner.java 28.63% <0.00%> (+10.78%) ⬆️
...on/datasource/SeataAutoDataSourceProxyCreator.java 61.90% <0.00%> (-8.37%) ⬇️
.../main/java/io/seata/config/ConfigurationCache.java 73.33% <100.00%> (-0.75%) ⬇️
...gure/provider/SpringBootConfigurationProvider.java 20.00% <100.00%> (ø)
...on/src/main/java/io/seata/common/util/MapUtil.java 0.00% <0.00%> (-95.24%) ⬇️
...ing/annotation/AspectTransactionalInterceptor.java 0.00% <0.00%> (-81.25%) ⬇️
... and 105 more

…mage

# Conflicts:
#	common/src/main/java/io/seata/common/util/ReflectionUtil.java
#	seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/java/io/seata/spring/boot/autoconfigure/provider/SpringBootConfigurationProvider.java
@wangliang181230 wangliang181230 marked this pull request as ready for review January 29, 2023 12:41
@wangliang181230 wangliang181230 changed the base branch from develop to 2.x January 30, 2023 02:41
@wangliang181230 wangliang181230 added this to the 2.0.0 milestone Jan 30, 2023
@wangliang181230 wangliang181230 marked this pull request as draft February 7, 2023 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants