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: support native-image for seata-client #5476

Merged
merged 39 commits into from Jul 2, 2023

Conversation

wangliang181230
Copy link
Contributor

  • 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.

wangliang181230 and others added 30 commits February 16, 2023 09:50
…eata/*`, and remove the `aot.factories` of the `SeataServicesRuntimeHints`.
2) Optimize `test.yml` .
# Conflicts:
#	changes/en-us/develop.md
#	changes/zh-cn/develop.md
#	core/src/main/java/io/seata/core/protocol/Version.java
#	core/src/test/java/io/seata/core/protocol/VersionTest.java
# Conflicts:
#	.github/workflows/publishes.yml
@wangliang181230 wangliang181230 changed the base branch from 2.x to develop March 30, 2023 07:41
if (!Map.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
return field.get(propertyObj);
}
} catch (NoSuchFieldException e) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

字段未找到时,就用方法获取。
因为在native-image中,有可能未注册fields,但注册了methods,可以通过method获取到配置值。

@wangliang181230 wangliang181230 changed the title feature: First support native-image for seata-client feature: First support native-image for seata-client Mar 31, 2023
@wangliang181230
Copy link
Contributor Author

@slievrly PTAL

Copy link
Member

@slievrly slievrly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@slievrly slievrly changed the title feature: First support native-image for seata-client feature: support native-image for seata-client Apr 21, 2023
Copy link
Member

@xingfudeshi xingfudeshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@slievrly slievrly added this to the 1.7.0 milestone Jun 14, 2023
@slievrly slievrly merged commit 23244cf into apache:develop Jul 2, 2023
7 checks passed
@wangliang181230 wangliang181230 deleted the support-graalvm-native-image branch July 4, 2023 08:28
Comment on lines +103 to +104
return (Configuration)Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{Configuration.class}
, (proxy, method, args) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

针对configuration cache代理这块可以修改为接口的方式使用jdk代理来解决,但是2.0中重构了事务api相关的模块,针对用户发起事务的实例使用了bytebuddy进行了代理,所以我不知道单纯改动configuration cache这个代理为jdk代理是否能解决该问题。
The configuration cache proxy can be modified to use a JDK proxy to address this issue. However, in 2.0, the transaction API-related modules were refactored, and ByteBuddy was used for proxying instances that initiate user transactions. Therefore, I am unsure whether simply changing the configuration cache proxy to a JDK proxy will resolve the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

None yet

5 participants