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

optimize: Refactoring the code of TCC mode #3730

Merged
merged 52 commits into from
Jun 1, 2021

Conversation

wangliang181230
Copy link
Contributor

@wangliang181230 wangliang181230 commented May 14, 2021

Ⅰ. Describe what this PR did

optimize: Refactoring the code of TCC mode.
优化:重构TCC模式相关的部分代码。

Ⅱ. Does this pull request fix one issue?

none

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

none

Ⅳ. Describe how to verify it

Verify it by the unit test.

Ⅴ. Special notes for reviews

改造内容如下:

一、移除已不再使用的代码:

  1. ActionInterceptorHandler.proceed(...)方法,返回Map没有什么意义,较老的代码了,现简化为直接返回business的result。对应的常量也删除掉。
  2. 移除已不再使用的BusinessActivityContext类。

二、封装或转移部分代码并优化逻辑:

  1. “根据BusinessActionContextParameter注解的配置读取参数值并存入context 的功能封装到ActionContextUtil.loadParamByAnnotationAndPutToContext(...)方法中,供多处共同调用,减少重复代码。
    同时该工具方法的逻辑也进一步优化,避免一些不应该抛出的异常。
    如:1)避免“使用index属性时,可能抛出的数组越界”的异常;
    2)避免List类型强转失败的异常,只打印一个warn日志。
  2. ActionContextUtil.getAllField方法,转移到ReflectionUtil工具类中,并优化添加了缓存功能。

三、BUG修复:

  1. 修复了TccActionInterceptor中的一个NPE的BUG,虽然目前的应用不会命中这个BUG,但就该类的逻辑来说,是一个BUG。
  2. 修复了嵌套调用TCC接口时,ActionContext丢失的问题。

四、其他优化:

  1. BusinessActionUtil.addContext方法的逻辑优化,存入的数据转为JSON数据;同时添加方便二阶段获取该参数值的方法(可自定义想要转换成的类型,而不再由seata自动转成Map);
  2. 注解BusinessActionContextParameter中,添加value属性,同义于paramName
  3. 其他还有一些添加注释内容、代码简化等的调整。

@wangliang181230
Copy link
Contributor Author

@tanzzj @long187 PTAL

@codecov-commenter
Copy link

codecov-commenter commented May 14, 2021

Codecov Report

Merging #3730 (d6a6294) into develop (17d298c) will increase coverage by 0.02%.
The diff coverage is 25.39%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #3730      +/-   ##
=============================================
+ Coverage      40.84%   40.86%   +0.02%     
- Complexity      2945     2956      +11     
=============================================
  Files            663      662       -1     
  Lines          22260    22310      +50     
  Branches        2755     2777      +22     
=============================================
+ Hits            9091     9116      +25     
- Misses         12326    12347      +21     
- Partials         843      847       +4     
Impacted Files Coverage Δ
...ommon/src/main/java/io/seata/common/Constants.java 100.00% <ø> (ø)
.../src/main/java/io/seata/common/util/BeanUtils.java 67.12% <ø> (+1.78%) ⬆️
...java/io/seata/spring/tcc/TccActionInterceptor.java 13.72% <0.00%> (+0.51%) ⬆️
...src/main/java/io/seata/rm/tcc/TCCFenceHandler.java 0.00% <0.00%> (ø)
.../main/java/io/seata/rm/tcc/TCCResourceManager.java 0.00% <0.00%> (ø)
...ava/io/seata/rm/tcc/api/BusinessActionContext.java 0.00% <0.00%> (ø)
...io/seata/rm/tcc/api/BusinessActionContextUtil.java 0.00% <0.00%> (ø)
...in/java/io/seata/rm/tcc/config/TCCFenceConfig.java 0.00% <0.00%> (ø)
.../rm/tcc/remoting/parser/DefaultRemotingParser.java 0.00% <0.00%> (ø)
...eata/rm/tcc/store/db/TCCFenceStoreDataBaseDAO.java 0.00% <0.00%> (ø)
... and 4 more

@caohdgege caohdgege added the mode: TCC TCC transaction mode label May 14, 2021
@wangliang181230 wangliang181230 added this to the 1.5.0 milestone May 14, 2021
Copy link
Contributor

@tanzzj tanzzj left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@caohdgege caohdgege left a comment

Choose a reason for hiding this comment

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

LTGM for @tanzzj

Copy link
Contributor

@tanzzj tanzzj left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

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

LGTM

@funky-eyes funky-eyes merged commit 8f62e9c into apache:develop Jun 1, 2021
@wangliang181230 wangliang181230 deleted the optimize/refactor/TCC branch June 11, 2021 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mode: TCC TCC transaction mode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants